From ab8f42bc0b4c5884496fe32034d4d87a652523b4 Mon Sep 17 00:00:00 2001 From: Scott Sibley Date: Fri, 29 Jul 2011 07:20:33 -0500 Subject: [PATCH] * Keep a collection of widgets at LibCore's level. * Further work done to IntersectUpdate code. It's still unfinished. * Script environments will be given a `unit` as always. You can now specify 'unitOverride' to force a specific unit, which will reflect within the runnable and within dog tags. --- Modules/Bars/Bars.lua | 6 +++- Modules/Histograms/Histograms.lua | 11 +++--- Modules/UnitTooltip/UnitTooltip.lua | 63 ++++++++++++++++++++++------------- 3 files changed, 51 insertions(+), 29 deletions(-) diff --git a/Modules/Bars/Bars.lua b/Modules/Bars/Bars.lua index b600a0c..5ab00fd 100644 --- a/Modules/Bars/Bars.lua +++ b/Modules/Bars/Bars.lua @@ -198,7 +198,10 @@ local optionsDefaults = { local intersectTimer local intersectUpdate = function() - WidgetBar.IntersectUpdate(mod.bars or {}) + for i, w in ipairs(widgets) do + assert(type(w.IntersectUpdate) == "function", "widget.IntersectUpdate should be a function.") + w:IntersectUpdate() + end end @@ -289,6 +292,7 @@ local function createBars() if not widget then local bar = new(v.parent) widget = WidgetBar:New(StarTip.core, v.name, copy(v), v.row or 0, v.col or 0, v.layer or 1, StarTip.db.profile.errorLevel, updateBar, bar) + tinsert(widgets, widget) bar:SetStatusBarTexture(LSM:Fetch("statusbar", v.texture1)) bar:ClearAllPoints() if widget.orientation == WidgetBar.ORIENTATION_VERTICAL then diff --git a/Modules/Histograms/Histograms.lua b/Modules/Histograms/Histograms.lua index 1a4b83c..15c87b7 100644 --- a/Modules/Histograms/Histograms.lua +++ b/Modules/Histograms/Histograms.lua @@ -154,7 +154,8 @@ local defaults = { profile = { classColors = true, histograms = {}, - intersect = true + intersect = true, + intersectRate = 500 } } @@ -198,8 +199,8 @@ local optionsDefaults = { } local intersectUpdate = function() - if type(mod.histograms) == "table" then - WidgetHistogram.IntersectUpdate(mod.histograms) + for i, w in ipairs(widgets) do + w:IntersectUpdate() end end @@ -293,6 +294,7 @@ local function createHistograms() if not mod.histograms then mod.histograms = {} end if not widget then widget = WidgetHistogram:New(StarTip.core, v.name, v, v.row or 0, v.col or 0, 0, StarTip.db.profile.errorLevel, updateHistogram) + tinsert(widgets, widget) widget.persistent = v.persistent newWidget = true for i = 0, v.width - 1 do @@ -381,7 +383,8 @@ end function mod:OnEnable() StarTip:SetOptionsDisabled(options, false) if StarTip.db.profile.intersectRate > 0 then - self.intersectTimer = self.intersectTimer or LibTimer:New("Texts.intersectTimer", self.db.profile.intersectRate or 200, true, intersectUpdate) + self.intersectTimer = self.intersectTimer or LibTimer:New("Texts.intersectTimer", self.db.profile.intersectRate or 500, true, intersectUpdate) + self.intersectTimer:Start() end self:ClearHistograms() self:CreateHistograms() diff --git a/Modules/UnitTooltip/UnitTooltip.lua b/Modules/UnitTooltip/UnitTooltip.lua index 0d832e6..b6c5d8f 100644 --- a/Modules/UnitTooltip/UnitTooltip.lua +++ b/Modules/UnitTooltip/UnitTooltip.lua @@ -103,24 +103,39 @@ return texture .. Colorize((Name(unit, true) or Name(unit)) .. afk , r, g, b) name = "Target", left = 'return L["Target:"]', right = [[ -if not UnitExists(unit) then return lastTarget or "None" end +-- Here's an example of how to deal with DogTag support. +-- Note that you have to consider which quote characters +-- you are using to contain the entire dog tag within, +-- as opposed what you're using inside. Here I'm using `'` surrounding +-- everything, and I'm using `"` within the dog tag itself. +-- Also, each new line inside a string should end with a '\'. +-- Also note; you'll have to "escape" where you wish to enter a '\' character +-- inside your dog tag. Do that by repeating the '\' character. +-- Example: return "\\ FOO \\" +-- Would print "\ FOO \" +if not UnitExists(unit) then return L["None"] end + +local dt = '\ +[IsPlayer and "":ClassColor or Color(Name, %f, %f, %f) \ +(if PvP then \ + "++":Red \ +end)]' + local r, g, b -local unit = (unit or "mouseover") .. "target" if UnitIsPlayer(unit) then r, g, b = ClassColor(unit) else r, g, b = UnitSelectionColor(unit) end -local name = UnitName(unit) -local name2 = UnitName("player") -if name == name2 and Realm(unit) == Realm("player") then name = "<>" end -local str = name and Colorize(name, r, g, b) or "None" -lastTarget = str -return str + +return dt:format(r, g, b) ]], + unitOverride = "mouseovertarget", rightUpdating = true, - update = 1000, - enabled = true + leftUpdating = true, + update = 500, + enabled = true, + dogtag = true }, [3] = { name = L["Guild"], @@ -144,7 +159,7 @@ end }, [5] = { name = L["Realm"], - left = 'return L["Realm:"]', + left = 'if Realm(unit) then return L["Realm:"] end', right = [[ return Realm(unit) ]], @@ -465,18 +480,6 @@ return select(2, GetRole(unit)) [22] = { name = "Avg Item Level", left = [[ -local mod = _G.StarTip:GetModule("UnitTooltip") -if mod then - for i = 1, #mod.db.profile.lines do - local line = mod.db.profile.lines[i] - if line and line.name == "Avg Item Level" and line.default then - line.deleted = true - mod:ClearLines() - mod:CreateLines() - break - end - end -end if not UnitExists(unit) then return "" end return "Item Level:" ]], @@ -990,7 +993,7 @@ function mod:CreateLines() v.rightObj.y = nil end local left, right = '', '' - environment.unit = StarTip.unit + environment.unit = v.leftObj and v.leftObj.unitOverride or StarTip.unit or "mouseover" if v.right then if v.rightObj then environment.self = v.rightObj @@ -1304,6 +1307,18 @@ function mod:RebuildOpts() end, order = 11 }, + unitOverride = { + name = L["Unit Override"], + desc = L["There's a default unit provided to each run environment, and you access it with 'unit' in your script. These \"units\" include 'mouseover', 'target', 'party1', etc... Here you can override that unit specifier."], + type = "input", + get = function() return v.unitOverride end, + set = function(info, val) + v.unitOverride = val + v.unitOverrideDirty = true + self:CreateLines() + end, + order = 12 + }, --[[ wordwrap = { name = L["Word Wrap"], -- 1.7.9.5