diff --git a/Modules/Talents.lua b/Modules/Talents.lua deleted file mode 100644 index c3fdd3e..0000000 --- a/Modules/Talents.lua +++ /dev/null @@ -1,298 +0,0 @@ -local mod = StarTip:NewModule("Talents", "AceTimer-3.0", "AceEvent-3.0") -mod.name = "Talents" -mod.toggled = true -mod.defaultOff = true -local text = StarTip:GetModule("UnitTooltip") -local _G = _G -local GameTooltip = _G.GameTooltip -local StarTip = _G.StarTip -local self = mod -local GameTooltip = _G.GameTooltip -local UnitIsUnit = _G.UnitIsUnit -local GetNumTalentTabs = _G.GetNumTalentTabs -local GetTalentTabInfo = _G.GetTalentTabInfo -local UnitExists = _G.UnitExists -local UnitIsPlayer = _G.UnitIsPlayer -local UnitName = _G.UnitName -local unitLocation -local unitName -local unitGuild -local expired -local expireTimer -local EXPIRE_TIME = 1 -local linesToAdd = {} -local linesToAddR = {} -local linesToAddG = {} -local linesToAddB = {} -local linesToAddRight = {} -local linesToAddRightR = {} -local linesToAddRightG = {} -local linesToAddRightB = {} -local TalentQuery = LibStub:GetLibrary("LibTalentQuery-1.0", true) -local spec = setmetatable({}, {__mode='v'}) -mod.spec = spec -local timer, talentTimer -local dw = StarTip:GetModule("DeadlyAnnounce", true) - -local options = { - onctrl = { - name = "Clear on Ctrl", - desc = "Whether to clear talents cache or not when pressing down CTRL.", - type = "toggle", - get = function() - return mod.db.profile.onctrl - end, - set = function(info, v) - mod.db.profile.onctrl = v - end, - order = 5 - } -} - -local talentTrees = { - ["Druid"] = {"Balance", "Feral Combat", "Restoration"}, - ["Hunter"] = {"Beast Mastery", "Marksmanship", "Survival"}, - ["Mage"] = {"Arcane", "Fire", "Frost"}, - ["Paladin"] = {"Holy", "Protection", "Retribution"}, - ["Priest"] = {"Discipline", "Holy", "Shadow"}, - ["Rogue"] = {"Assassination", "Combat", "Subtlety"}, - ["Shaman"] = {"Elemental", "Enhancement", "Restoration"}, - ["Warlock"] = {"Affliction", "Demonology", "Destruction"}, - ["Warrior"] = {"Arms", "Fury", "Protection"}, -} - -local indexOf = function(t, val) - for i=1, #t do - if t[i] == val then - return i - end - end -end - -local indicesOf = function(t, val) - local a = {} - for i=1, #t do - if t[i] == val then - tinsert(a, i) - end - end - return unpack(a) -end - -function mod:TalentQuery_Ready(e, name, realm) - if not TalentQuery then return end - local nameRealm = name .. (realm or '') - local isnotplayer = (name ~= UnitName("player")) - if not spec[nameRealm] then - spec[nameRealm] = {[4]=NONE} - local highPoints = {} - local specNames = {} - local group = GetActiveTalentGroup(isnotplayer) - for tab = 1, GetNumTalentTabs(isnotplayer) do - local treename, _, pointsspent = GetTalentTabInfo(tab, isnotplayer, nil, group) - highPoints[tab] = pointsspent - spec[nameRealm][tab] = pointsspent - specNames[tab] = treename - end - if highPoints[1] == nil or highPoints[2] == nil or highPoints[3] == nil then spec[nameRealm] = nil return end - table.sort(highPoints, function(a,b) return a>b end) - local first, second = select(1, indicesOf(spec[nameRealm], highPoints[1])), select(2, indicesOf(spec[nameRealm], highPoints[1])) - if highPoints[1] > 0 and highPoints[2] > 0 and highPoints[1] - highPoints[2] <= 5 and highPoints[1] ~= highPoints[2] then - spec[nameRealm][4] = specNames[indexOf(spec[nameRealm], highPoints[1])] .. "/" .. specNames[indexOf(spec[nameRealm], highPoints[2])] - elseif highPoints[1] > 0 and first and second then - spec[nameRealm][4] = specNames[first] .. "/" .. specNames[second] - elseif highPoints[1] > 0 then - spec[nameRealm][4] = specNames[indexOf(spec[nameRealm], highPoints[1])] - end - end -end - -function expireQuery() - expired = true - self:CancelTimer(expireTimer) - expireTimer = nil -end - -local updateTalents = function() - if dw and dw.shown then return end - - if not UnitExists("mouseover") or not UnitIsPlayer("mouseover") then - self:CancelTimer(talentTimer) - self:CancelTimer(expireTimer) - expireTimer = nil - talentTimer = nil - return - end - if expired then - --TalentQuery:NotifyInspect("player") - --TalentQuery.frame:Hide() - TalentQuery:Query("mouseover") - expireTimer = self:ScheduleTimer(expireQuery, EXPIRE_TIME) - expired = nil - return - end - local nameRealm = select(1, UnitName("mouseover")) .. (select(2, UnitName("mouseover")) or '') - if spec[nameRealm] and spec[nameRealm][4] and spec[nameRealm][1] and spec[nameRealm][2] and spec[nameRealm][3] then - local specText = mod:SpecText(select(1, UnitName("mouseover")), select(2, UnitName("mouseover"))) - local lineNum - if (text.NUM_LINES or 0xdeadbeef) < GameTooltip:NumLines() then -- sometimes the text module hasn't initialized before this test - lineNum = text.NUM_LINES + 1 - local j = 0 - for i = lineNum, GameTooltip:NumLines() do - local left = mod.leftLines[i] - j = j + 1 - linesToAdd[j] = left:GetText() - local r, g, b = left:GetTextColor() - linesToAddR[j] = r - linesToAddG[j] = g - linesToAddB[j] = b - local right = mod.rightLines[i] - if right:IsShown() then - linesToAddRight[j] = right:GetText() - local r, g, b = right:GetTextColor() - linesToAddRightR[j] = r - linesToAddRightG[j] = g - linesToAddRightB[j] = b - end - end - else - lineNum = GameTooltip:NumLines() + 1 - end - - GameTooltip:AddDoubleLine(' ', ' ') - - local left = mod.leftLines[lineNum] - local right = mod.rightLines[lineNum] - left:SetText("Talents:") - right:SetText(specText) - if not right:IsShown() then - right:Show() - end - left:SetTextColor(text.db.profile.color.r, text.db.profile.color.g, text.db.profile.color.b) - right:SetTextColor(text.db.profile.color.r, text.db.profile.color.g, text.db.profile.color.b) - - for i=1, #linesToAdd do - local left = mod.leftLines[i + lineNum] - left:SetText(linesToAdd[i]) - left:SetTextColor(linesToAddR[i], linesToAddG[i], linesToAddB[i]) - if linesToAddRight[i] then - local right = mod.rightLines[i + lineNum] - right:SetText(linesToAddRight[i]) - right:SetTextColor(linesToAddRightR[i], linesToAddRightG[i], linesToAddRightB[i]) - end - linesToAdd[i] = nil - linesToAddR[i] = nil - linesToAddG[i] = nil - linesToAddB[i] = nil - linesToAddRight[i] = nil - linesToAddRightR[i] = nil - linesToAddRightG[i] = nil - linesToAddRightB[i] = nil - end - - self:CancelTimer(talentTimer) - talentTimer = nil - if expireTimer then - mod:CancelTimer(expireTimer) - expireTimer = nil - end - if spec[nameRealm][1] == 0 and spec[nameRealm][2] == 0 and spec[nameRealm][3] == 0 then - spec[nameRealm] = nil - end - GameTooltip:Hide() - GameTooltip:Show() - elseif spec[nameRealm] then - spec[nameRealm] = nil - end -end - -function mod:OnInitialize() - self.db = StarTip.db:RegisterNamespace(self:GetName(), {profile = {onctrl = true}}) - self.leftLines = StarTip.leftLines - self.rightLines = StarTip.rightLines -end - -function mod:OnEnable() - if TalentQuery then TalentQuery.RegisterCallback(self, "TalentQuery_Ready") end -end - -function mod:OnDisable() - if TalentQuery then TalentQuery.UnregisterCallback(self, "TalentQuery_Ready") end -end - -function mod:GetOptions() - return options -end - -function mod:SetUnit() - if not TalentQuery or not UnitIsPlayer("mouseover") then return end - - if dw and dw.shown then - return - end - - for i = 1, GameTooltip:NumLines() do - if StarTip.leftLines[i]:GetText() == "Talents:" then - self.oldLine = i - end - end - - if UnitIsUnit("mouseover", "player") then - self:TalentQuery_Ready(_, UnitName("player")) - else - --TalentQuery:NotifyInspect("mouseover") - TalentQuery:Query("mouseover") - talentTimer = talentTimer or self:ScheduleRepeatingTimer(updateTalents, 0) - if expireTimer then - self:CancelTimer(expireTimer) - expireTimer = nil - end - expireTimer = self:ScheduleTimer(expireQuery, EXPIRE_TIME) - if IsControlKeyDown() then - local nameRealm = select(1, UnitName("mouseover")) .. (select(2, UnitName("mouseover")) or '') - spec[nameRealm] = nil - end - end -end - -function mod:OnHide() - if talentTimer then - self:CancelTimer(talentTimer) - talentTimer = nil - end - if expireTimer then - self:CancelTimer(expireTimer) - expireTimer = nil - end -end - -function mod:MODIFIER_STATE_CHANGED(ev, modifier, up, ...) - local mod = (modifier == "LCTRL" or modifier == "RCTRL") and "LCTRL" - - if mod ~= "LCTRL" or not self:IsEnabled() then - return - end - - if self.db.profile.onctrl and UnitIsPlayer("mouseover") then - StarTip.del(spec) - - local nameRealm = self:NameRealm() - local specText = self:SpecText(nameRealm) - for i = 1, GameTooltip:NumLines() do - if StarTip.leftLines[i]:GetText() == "Talents:" and specText ~= "" then - StarTip.rightLines[i]:SetText("Reload") - end - end - spec = setmetatable(StarTip.new(), {__mode='v'}) - end -end - -function mod:NameRealm() - return select(1, (UnitName("mouseover")) or "") .. (select(2, UnitName("mouseover")) or "") -end - -function mod:SpecText(nameRealm) - if not spec[nameRealm] then return "" end - return ('%s (%d/%d/%d)'):format(spec[nameRealm][4], spec[nameRealm][1], spec[nameRealm][2], spec[nameRealm][3]) -end - diff --git a/Modules/UnitTooltip.lua b/Modules/UnitTooltip.lua index 0bdf094..6892397 100644 --- a/Modules/UnitTooltip.lua +++ b/Modules/UnitTooltip.lua @@ -94,7 +94,7 @@ if UnitIsPlayer(unit) then else r, g, b = UnitSelectionColor(unit) end -return GetColorCode(UnitName(unit), r, g, b) +return Colorize(UnitName(unit), r, g, b) ]], right = nil, bold = true, @@ -119,7 +119,7 @@ else end local name = UnitName(unit) if name == select(1, UnitName("player")) then name = "<<YOU>>" end -return name and GetColorCode(name, r, g, b) or "None" +return name and Colorize(name, r, g, b) or "None" ]], rightUpdating = true, update = 1000, @@ -194,7 +194,7 @@ if UnitIsPlayer(unit) then else r, g, b = 1, 1, 1 end -return GetColorCode(UnitClass(unit), r, g, b) +return Colorize(UnitClass(unit), r, g, b) ]], enabled = true, }, @@ -237,9 +237,9 @@ health, maxHealth = UnitHealth(unit), UnitHealthMax(unit) r, g, b = HPColor(health, maxHealth) value = "Unknown" if maxHealth == 100 then - value = GetColorCode(health .. "%", r, g, b) + value = Colorize(health .. "%", r, g, b) elseif maxHealth ~= 0 then - value = GetColorCode(format("%s/%s (%d%%)", short(health), short(maxHealth), health/maxHealth*100), r, g, b) + value = Colorize(format("%s/%s (%d%%)", short(health), short(maxHealth), health/maxHealth*100), r, g, b) end return value ]], @@ -258,9 +258,9 @@ maxMana = UnitManaMax(unit) r, g, b = PowerColor(nil, unit) value = "Unknown" if maxMana == 100 then - value = GetColorCode(tostring(mana), r, g, b) + value = Colorize(tostring(mana), r, g, b) elseif maxMana ~= 0 then - value = GetColorCode(format("%s/%s (%d%%)", short(mana), short(maxMana), mana/maxMana*100), r, g, b) + value = Colorize(format("%s/%s (%d%%)", short(mana), short(maxMana), mana/maxMana*100), r, g, b) end return value ]], @@ -298,7 +298,7 @@ if mem then if num < 1 then num = 1 end if num > 100 then num = 100 end local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3] - return GetColorCode(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b) + return Colorize(format("%s (%.2f%%)", memshort(mem), memperc), r, g, b) end ]], rightUpdating = true, @@ -315,7 +315,7 @@ if cpu then if num < 1 then num = 1 end if num > 100 then num = 100 end local r, g, b = gradient[num][1], gradient[num][2], gradient[num][3] - return GetColorCode(format("%s (%.2f%%)", timeshort(cpu), cpuperc), r, g, b) + return Colorize(format("%s (%.2f%%)", timeshort(cpu), cpuperc), r, g, b) end ]], rightUpdating = true, @@ -337,6 +337,16 @@ end enabled = true, update = 1000 }, + [18] = { + name = "Talents", + left = "return 'Talents:'", + right = [[ +return SpecText(unit) +]], + rightUpdating = true, + enabled = true, + update = 1000 + } } local options = {} @@ -419,14 +429,18 @@ local widgetsToDraw = {} local function updateWidget(widget) tinsert(widgetsToDraw, widget) if mod.db.profile.refreshRate == 0 then - draw() + draw(UnitExists(StarTip.unit)) end end do local fontsList = LSM:List("font") local widget, fontString - function draw() + function draw(show) + if StarTip.fading then + table.wipe(widgetsToDraw) + return + end for i, widget in ipairs(widgetsToDraw) do if not widget.fontString then break end local fontString = widget.fontString @@ -451,6 +465,9 @@ do end end table.wipe(widgetsToDraw) + if UnitExists(StarTip.unit) then + GameTooltip:Show() + end end end @@ -700,6 +717,7 @@ function mod:RebuildOpts() desc = "Move this line up by one", type = "execute", func = function() + StarTip:Print("up", i) if i == 1 then return end local tmp = self.db.profile.lines[i - 1] if not v.left then v.left = "" end @@ -721,6 +739,7 @@ function mod:RebuildOpts() func = function() if i == #self.db.profile.lines then return end local tmp = self.db.profile.lines[i + 1] + if tmp.deleted then return end if not v.left then v.left = "" end if not v.right then v.right = "" end if not tmp.left then tmp.left = "" end @@ -751,9 +770,19 @@ function mod:RebuildOpts() type = "execute", func = function() local name = v.name - table.wipe(self.db.profile.lines[i]) - v.name = name - v.deleted = true + local delete = true + for i, line in ipairs(defaultLines) do + if line.name == name then + delete = false + end + end + tremove(self.db.profile.lines, i) + if not delete then + wipe(v) + v.deleted = true + v.name = name + tinsert(self.db.profile.lines, v) + end StarTip:RebuildOpts() self:CreateLines() end, @@ -777,9 +806,9 @@ function mod:RebuildOpts() end self:CreateLines() end, - validate = function(info, str) + --[[validate = function(info, str) return mod.evaluator:Validate(environment, str) - end, + end,]] multiline = true, width = "full", order = 10 @@ -797,48 +826,10 @@ function mod:RebuildOpts() end self:CreateLines() end, - validate = function(info, str) - return mod.evaluator:Validate(environment, str) - end, multiline = true, width = "full", order = 11 }, - --[[ - colorLeft = { - name = "Left Color", - type = "input", - desc = "Color for left segment", - get = function() return v.colorLeft end, - set = function(info, val) - v.colorLeft = val - v.colorLeftDirty = true - self:CreateLines() - end, - validate = function(info, str) - return mod.evaluator:Validate(environment, str) - end, - multiline = true, - width = "full", - order = 12 - }, - colorRight = { - name = "Right Color", - type = "input", - desc = "Color for right segment", - get = function() return v.colorRight end, - set = function(info, val) - v.colorRight = val - v.colorRightDirty = true - self:CreateLines() - end, - validate = function(info, str) - return mod.evaluator:Validate(environment, str) - end, - multiline = true, - width = "full", - order = 13 - },]] marquee = { name = "Enhanced Settings", type = "group", @@ -1000,14 +991,14 @@ function mod:RebuildOpts() } } end - if v.desc then + --[[if v.desc then options["line" .. i].args.desc = { name = v.desc, type = "header", order = 1 } - end + end]] end end diff --git a/StarTip.lua b/StarTip.lua index 185a014..7b4676b 100644 --- a/StarTip.lua +++ b/StarTip.lua @@ -402,6 +402,16 @@ Update() }, } +local checkTooltipAlphaFrame +local checkTooltipAlpha = function() + if GameTooltip:GetAlpha() < 1 then + StarTip.fading = true + checkTooltipAlphaFrame:SetScript("OnUpdate", nil) + end +end + +checkTooltipAlphaFrame = CreateFrame("Frame") + function StarTip:OnInitialize() self.db = LibStub("AceDB-3.0"):New("StarTipDB", defaults, "Default") @@ -559,6 +569,7 @@ function StarTip:OpenConfig() end function StarTip.OnTooltipSetUnit() + StarTip.fading = false local unit = GameTooltip:GetUnit() StarTip.unit = "mouseover" if not UnitExists("mouseover") then @@ -595,6 +606,7 @@ function StarTip.OnTooltipSetUnit() end end StarTip.justSetUnit = nil + checkTooltipAlphaFrame:SetScript("OnUpdate", checkTooltipAlpha) end function StarTip.OnTooltipSetItem(self, ...)