diff --git a/.pkgmeta b/.pkgmeta index 426410c..1be60cd 100644 --- a/.pkgmeta +++ b/.pkgmeta @@ -1,15 +1,47 @@ externals: - Libs/LibStub: svn://svn.wowace.com/wow/libstub/mainline/trunk + Libs/LibStub: + url: svn://svn.wowace.com/wow/libstub/mainline/trunk + tag: latest Libs/CallbackHandler-1.0: svn://svn.wowace.com/wow/callbackhandler/mainline/tags/1.0.3/CallbackHandler-1.0 - Libs/AceAddon-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0 - Libs/AceHook-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceHook-3.0 - Libs/AceTimer-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceTimer-3.0 - Libs/AceConfig-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConfig-3.0 - Libs/AceConsole-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConsole-3.0 - Libs/AceDB-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0 - Libs/AceEvent-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0 - Libs/AceGUI-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0 - Libs/AceLocale-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0 - Libs/AceDBOptions-3.0: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDBOptions-3.0 - Libs/LibSharedMedia-3.0: svn://svn.wowace.com/wow/libsharedmedia-3-0/mainline/trunk - Libs/LibTalentQuery-1.0: svn://svn.wowace.com/wow/libtalentquery-1-0/mainline/trunk \ No newline at end of file + Libs/AceAddon-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceAddon-3.0 + tag: latest + Libs/AceHook-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceHook-3.0 + tag: latest + Libs/AceTimer-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceTimer-3.0 + tag: latest + Libs/AceConfig-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConfig-3.0 + tag: latest + Libs/AceConsole-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceConsole-3.0 + tag: latest + Libs/AceDB-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDB-3.0 + tag: latest + Libs/AceEvent-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceEvent-3.0 + tag: latest + Libs/AceGUI-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceGUI-3.0 + tag: latest + Libs/AceLocale-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceLocale-3.0 + tag: latest + Libs/AceDBOptions-3.0: + url: svn://svn.wowace.com/wow/ace3/mainline/trunk/AceDBOptions-3.0 + tag: latest + Libs/LibSharedMedia-3.0: + url: svn://svn.wowace.com/wow/libsharedmedia-3-0/mainline/trunk + tag: latest + Libs/LibTalentQuery-1.0: + url: svn://svn.wowace.com/wow/libtalentquery-1-0/mainline/trunk + tag: latest + Libs/LibQTip-1.0: + url: svn://svn.wowace.com/wow/libqtip-1-0/mainline/trunk + tag: latest + Libs/LibDBroker-1.0: + url: git://github.com/tekkub/libdatabroker-1-1.git + tag: v1.1.4 diff --git a/Modules/Text.lua b/Modules/Text.lua index 3507021..56d1cb1 100644 --- a/Modules/Text.lua +++ b/Modules/Text.lua @@ -52,7 +52,14 @@ end local executeCode = function(tag, code) if not code then return end - return assert(loadstring(code, tag))(xpcall, errorhandler) + local runnable, err = loadstring(code, tag) + + if not runnable then + StarTip:Print(err) + return "" + end + + return runnable(xpcall, errorhandler) end -- Thanks to ckknight for this @@ -71,20 +78,12 @@ mod.short = function(value) return value end -local powers = { +mod.powers = { ["WARRIOR"] = "Rage:", ["ROGUE"] = "Energy:", + ["DEATHKNIGHT"] = "Rune Power" } -powers = setmetatable(powers, {__index=function(self,key) - if type(key) == nil then return nil end - if rawget(self,key) then - return self[key] - else - return "Mana:" - end -end}) - mod.unitHasAura = function(aura) local i = 1 while true do @@ -105,6 +104,7 @@ local function updateLines() if v.updating and v.right and self.db.profile[v.db] then local left = executeCode(v.name, v.left) local right, c = executeCode(v.name, v.right) + StarTip:del(c) if left and right then for i = 1, self.NUM_LINES do if mod.leftLines[i]:GetText() == left then @@ -130,7 +130,7 @@ local c if UnitIsPlayer("mouseover") then c = RAID_CLASS_COLORS[select(2, UnitClass("mouseover"))] else - c = {} + c = StarTip:new() c.r, c.g, c.b = UnitSelectionColor("mouseover") end return text.unitName, c @@ -147,13 +147,13 @@ if UnitExists("mouseovertarget") then if UnitIsPlayer("mouseovertarget") then c = RAID_CLASS_COLORS[select(2, UnitClass("mouseovertarget"))] else - c = {} + c = StarTip:new() c.r, c.g, c.b = UnitSelectionColor("mouseovertarget") end local name = UnitName("mouseovertarget") return name, c else - return "None", {r=1, g=1, b=1} + return "None", StarTip:newDict("r", 1, "g", 1, "b", 1) end ]], updating = true @@ -188,12 +188,11 @@ return select(2, UnitName("mouseover")) name = "Level", left = 'return "Level:"', right = [[ -local classifications = { - worldboss = "Boss", - rareelite = "+ Rare", - elite = "+", - rare = "Rare" -} +local classifications = StarTip.newDict( + "worldboss", "Boss", + "rareelite", "+ Rare", + "elite", "+", + "rare", "Rare") local lvl = UnitLevel("mouseover") local class = UnitClassification("mouseover") @@ -206,6 +205,8 @@ if classifications[class] then lvl = lvl .. classifications[class] end +StarTip:del(classifications) + return lvl ]], updating = false @@ -283,34 +284,21 @@ return value [12] = { name = "Mana", left = [[ -local powers = { - ["WARRIOR"] = "Rage:", - ["ROGUE"] = "Energy:", -} - -powers = setmetatable(powers, {__index=function(self,key) - if type(key) == nil then return nil end - if rawget(self,key) then - return self[key] - else - return "Mana:" - end -end}) +local text = StarTip:GetModule("Text") local class = select(2, UnitClass("mouseover")) -return powers[class] +return text.powers[class] or "Mana:" ]], right = [[ local text = StarTip:GetModule("Text") local mana = UnitMana("mouseover") local maxMana = UnitManaMax("mouseover") -local value if maxMana == 100 then value = mana elseif maxMana ~= 0 then value = format("%s/%s (%d%%)", text.short(mana), text.short(maxMana), mana/maxMana*100) end -return value +return value ]], updating = true }, @@ -327,22 +315,6 @@ return text.unitLocation local options = {} ---[[do - local lnum = 1 - for i, v in ipairs(lines) do - options[v.db] = { - name = v.name, - desc = "Toggle showing this line", - type = "toggle", - set = function(info, val) self.db.profile[v.db] = val end, - get = function() return self.db.profile[v.db] end, - order = 5 + lnum - } - lnum = lnum + 1 - defaults.profile[v.db] = true - end -end]] - function mod:OnInitialize() self.db = StarTip.db:RegisterNamespace(self:GetName(), defaults) if self.db.profile.empty then @@ -415,22 +387,13 @@ function mod:CreateLines() end end end + StarTip:del(c) --end end self.NUM_LINES = lineNum end}) end -function validateCode(code) - local ret, err = loadstring(code, "validate") - if not ret then - StarTip:Print(("Code failed to execute. Error message: %s"):format(err or "")) - return false - end - StarTip:Print(("Code executed without error. Return value: %s"):format(ret or "")) - return true -end - function mod:RebuildOpts() options = { add = { @@ -473,7 +436,16 @@ function mod:RebuildOpts() desc = "Left text code", get = function() return v.left end, set = function(info, val) v.left = val end, - validate = validateCode, + validate = function() + local ret, err = loadstring(v.left or "", "validate") + if not ret then + StarTip:Print(("Code failed to execute. Error message: %s"):format(err or "")) + return false + end + StarTip:Print(("Code executed without error. Return value: %s"):format(ret(xpcall, errorhandler) or "")) + return true + + end, multiline = true, width = "full", order = 1 @@ -484,7 +456,16 @@ function mod:RebuildOpts() desc = "Right text code", get = function() return v.right end, set = function(info, val) v.right = val end, - validate = validateCode, + validate = function() + local ret, err = loadstring(v.right or "", "validate") + if not ret then + local text = ("Code failed to execute. Error message: %s"):format(err or "") + StarTip:Print(text) + return text + end + StarTip:Print(("Code executed without error. Return value: %s"):format(ret(xpcall, errorhandler) or "")) + return true + end, multiline = true, width = "full", order = 2 diff --git a/StarTip.lua b/StarTip.lua index f942b22..d4209e8 100644 --- a/StarTip.lua +++ b/StarTip.lua @@ -1,13 +1,24 @@ -StarTip = LibStub("AceAddon-3.0"):NewAddon("StarTip", "AceConsole-3.0", "AceHook-3.0") +StarTip = LibStub("AceAddon-3.0"):NewAddon("StarTip", "AceConsole-3.0", "AceHook-3.0", "AceEvent-3.0") +local LibQTip = LibStub('LibQTip-1.0') +local LibDBIcon = LibStub("LibDBIcon-1.0") +local LSM = _G.LibStub("LibSharedMedia-3.0") +local LDB = LibStub:GetLibrary("LibDataBroker-1.1") local AceConfigDialog = LibStub("AceConfigDialog-3.0") local _G = _G local GameTooltip = _G.GameTooltip local ipairs, pairs = _G.ipairs, _G.pairs -local LSM = _G.LibStub("LibSharedMedia-3.0") + +local LDB = LibStub("LibDataBroker-1.1"):NewDataObject("StarTip", { + type = "data source", + text = "StarTip", + icon = "Interface\\Icons\\INV_Chest_Cloth_17", + OnClick = function() StarTip:OpenConfig() end +}) local defaults = { profile = { - modules = {} + modules = {}, + minimap = {hide=true} } } @@ -19,10 +30,78 @@ local options = { desc = "Modules", type = "group", args = {} + }, + settings = { + name = "Settings", + desc = "Settings", + type = "group", + args = { + minimap = { + name = "Minimap", + desc = "Toggle showing minimap button", + type = "toggle", + get = function() + return not StarTip.db.profile.minimap.hide + end, + set = function(info, v) + StarTip.db.profile.minimap.hide = not v + if not v then + LibDBIcon:Hide("StarTipLDB") + else + LibDBIcon:Show("StarTipLDB") + end + end, + order = 1 + } + } } } } +do + local pool = setmetatable({},{__mode='k'}) + + function StarTip:new(...) + local t = next(pool) + if t then + pool[t] = nil + for i=1, select("#", ...) do + t[i] = select(i, ...) + end + else + t = {...} + end + t.__starref__ = true + return t + end + function StarTip:newDict(...) + local t = next(pool) + if t then + pool[t] = nil + else + t = {} + end + for i=1, select("#", ...), 2 do + t[select(i, ...)] = select(i+1, ...) + end + t.__starref__ = true + return t + end + function StarTip:del(...) + for i=1, select("#", ...) do + local t = select(i, ...) + if (t and type(t) ~= table) or t == nil then break end + for k, v in pairs(t) do + if type(k) == "table" then + if t.__starref__ then StarTip:del(k) end + t.__starref__ = nil + end + t[k] = nil + end + pool[t] = true + end + end +end StarTip:SetDefaultModuleState(false) function StarTip:OnInitialize() @@ -31,7 +110,9 @@ function StarTip:OnInitialize() LibStub("AceConfig-3.0"):RegisterOptionsTable("StarTip", options) self:RegisterChatCommand("startip", "OpenConfig") - + AceConfigDialog:AddToBlizOptions("StarTip") + LibDBIcon:Register("StarTipLDB", LDB, self.db.profile.minimap) + self.leftLines = {} self.rightLines = {} for i = 1, 50 do @@ -41,9 +122,16 @@ function StarTip:OnInitialize() end GameTooltip:Show() GameTooltip:Hide() + end function StarTip:OnEnable() + if self.db.profile.minimap.hide then + LibDBIcon:Hide("StarTipLDB") + else + LibDBIcon:Show("StarTipLDB") + end + GameTooltip:HookScript("OnTooltipSetUnit", self.OnTooltipSetUnit) GameTooltip:HookScript("OnTooltipSetItem", self.OnTooltipSetItem) GameTooltip:HookScript("OnTooltipSetSpell", self.OnTooltipSetSpell) @@ -55,11 +143,12 @@ function StarTip:OnEnable() v:Enable() end end - + self:RebuildOpts() end function StarTip:OnDisable() + LibDBIcon:Hide("StarTipLDB") self:Unhook(GameTooltip, "OnTooltipSetUnit") self:Unhook(GameTooltip, "OnTooltipSetItem") self:Unhook(GameTooltip, "OnTooltipSetSpell") @@ -136,10 +225,10 @@ function StarTip.OnTooltipSetUnit() end end -function StarTip.OnTooltipSetItem(...) +function StarTip.OnTooltipSetItem(self, ...) if not StarTip.justSetItem then for k, v in StarTip:IterateModules() do - if v.SetItem and v:IsEnabled() then v:SetItem() end + if v.SetItem and v:IsEnabled() then v:SetItem(...) end end end end @@ -147,7 +236,7 @@ end function StarTip.OnTooltipSetSpell(...) if not StarTip.justSetSpell then for k, v in StarTip:IterateModules() do - if v.SetSpell and v:IsEnabled() then v:SetSpell() end + if v.SetSpell and v:IsEnabled() then v:SetSpell(...) end end end end @@ -155,19 +244,37 @@ end function StarTip:OnTooltipHide(...) if not self.justHide then for k, v in self:IterateModules() do - if v.OnHide and v:IsEnabled() then v:OnHide() end + if v.OnHide and v:IsEnabled() then v:OnHide(...) end end end self.hooks[GameTooltip].OnHide(...) + + LibQTip:Release(self.tooltip) + self.tooltip = nil + end function StarTip:OnTooltipShow(...) if not self.justShow then for k, v in self:IterateModules() do - if v.OnShow and v:IsEnabled() then v:OnShow() end + if v.OnShow and v:IsEnabled() then v:OnShow(...) end end end - self.hooks[GameTooltip].OnShow(...) + -- Acquire a tooltip with 3 columns, respectively aligned to left, center and right + local tooltip = LibQTip:Acquire("GameTooltip", 3, "LEFT", "CENTER", "RIGHT") + StarTip.tooltip = tooltip + + -- Add an header filling only the first two columns + tooltip:AddHeader('Anchor', 'Tooltip') + + -- Add an new line, using all columns + tooltip:AddLine('Hello', 'World', '!') + + -- Use smart anchoring code to anchor the tooltip to our frame + tooltip:SmartAnchorTo(_G.GameTooltip) + + -- Show it, et voil? + self.hooks[GameTooltip].OnShow(...) end function StarTip:GetLSMIndexByName(category, name) @@ -186,4 +293,4 @@ function StarTip:SetOptionsDisabled(t, bool) self:SetOptionsDisabled(v.args, bool) end end -end +end \ No newline at end of file diff --git a/StarTip.toc b/StarTip.toc index 2a03dcc..e04747f 100644 --- a/StarTip.toc +++ b/StarTip.toc @@ -10,10 +10,6 @@ ## OptionalDeps: Ace3, LibTalentQuery-1.0, LibMobHealth-4.0, TalentGuess-1.0 ## SavedVariables: StarTipDB -Libs\LibStub\LibStub.lua -Libs\CallbackHandler-1.0\CallbackHandler-1.0.lua -Libs\TalentGuess-1.0\TalentGuess-1.0.xml - embeds.xml Localization\enUS.lua diff --git a/embeds.xml b/embeds.xml index c465e4a..ad94d63 100644 --- a/embeds.xml +++ b/embeds.xml @@ -16,5 +16,8 @@ <Include file="Libs\LibSharedMedia-3.0\lib.xml"/> <Include file="Libs\LibMobHealth-4.0\lib.xml"/> <Script file="Libs\LibTalentQuery-1.0\LibTalentQuery-1.0.lua"/> +<Script file="libs\LibQTip-1.0\LibQTip-1.0.lua"/> +<Script file="LIbs\LibDatabroker-1.1\LibDatabroker-1.1.lua"/> +<Script file="Libs\LibDBIcon-1.0\LibDBIcon-1.0.lua"/> </Ui>