From f9856c1046df9a1070957ad2b39a42cb65468f5e Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 16:13:39 -0700 Subject: [PATCH] feat: implement GameTooltip methods with real item/spell/aura data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace empty stub GameTooltip methods with working implementations: - SetInventoryItem(unit, slot): populates tooltip with equipped item name and quality-colored text via GetInventoryItemLink + GetItemInfo - SetBagItem(bag, slot): populates from GetContainerItemInfo + GetItemInfo - SetSpellByID(spellId): populates with spell name/rank from GetSpellInfo - SetAction(slot): delegates to SetSpellByID or item lookup via GetActionInfo - SetUnitBuff/SetUnitDebuff: populates from UnitBuff/UnitDebuff data - SetHyperlink: parses item: and spell: links to populate name - GetItem/GetSpell: now return real item/spell data when tooltip is populated Also fix GetCVar/SetCVar conflict — remove Lua-side overrides that were shadowing the C-side implementations (which return real screen dimensions and sensible defaults for common CVars). --- src/addons/lua_engine.cpp | 118 +++++++++++++++++++++++++++++++++----- 1 file changed, 104 insertions(+), 14 deletions(-) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index 944be318..e2505c4e 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -4568,18 +4568,111 @@ void LuaEngine::registerCoreAPI() { "function GameTooltip:AddLine(text, r, g, b, wrap) table.insert(self.__lines, {text=text or '',r=r,g=g,b=b}) end\n" "function GameTooltip:AddDoubleLine(l, r, lr, lg, lb, rr, rg, rb) table.insert(self.__lines, {text=(l or '')..' '..(r or '')}) end\n" "function GameTooltip:SetText(text, r, g, b) self.__lines = {{text=text or '',r=r,g=g,b=b}} end\n" - "function GameTooltip:GetItem() return nil end\n" - "function GameTooltip:GetSpell() return nil end\n" + "function GameTooltip:GetItem()\n" + " if self.__itemId and self.__itemId > 0 then\n" + " local name = GetItemInfo(self.__itemId)\n" + " return name, '|cffffffff|Hitem:'..self.__itemId..':0|h['..tostring(name)..']|h|r'\n" + " end\n" + " return nil\n" + "end\n" + "function GameTooltip:GetSpell()\n" + " if self.__spellId and self.__spellId > 0 then\n" + " local name = GetSpellInfo(self.__spellId)\n" + " return name, nil, self.__spellId\n" + " end\n" + " return nil\n" + "end\n" "function GameTooltip:GetUnit() return nil end\n" "function GameTooltip:NumLines() return #self.__lines end\n" "function GameTooltip:GetText() return self.__lines[1] and self.__lines[1].text or '' end\n" - "function GameTooltip:SetUnitBuff(...) end\n" - "function GameTooltip:SetUnitDebuff(...) end\n" - "function GameTooltip:SetHyperlink(...) end\n" - "function GameTooltip:SetInventoryItem(...) end\n" - "function GameTooltip:SetBagItem(...) end\n" - "function GameTooltip:SetSpellByID(...) end\n" - "function GameTooltip:SetAction(...) end\n" + "function GameTooltip:SetUnitBuff(unit, index, filter)\n" + " self:ClearLines()\n" + " local name, rank, icon, count, debuffType, duration, expTime, caster, steal, consolidate, spellId = UnitBuff(unit, index, filter)\n" + " if name then\n" + " self:SetText(name, 1, 1, 1)\n" + " if duration and duration > 0 then\n" + " self:AddLine(string.format('%.0f sec remaining', expTime - GetTime()), 1, 1, 1)\n" + " end\n" + " self.__spellId = spellId\n" + " end\n" + "end\n" + "function GameTooltip:SetUnitDebuff(unit, index, filter)\n" + " self:ClearLines()\n" + " local name, rank, icon, count, debuffType, duration, expTime, caster, steal, consolidate, spellId = UnitDebuff(unit, index, filter)\n" + " if name then\n" + " self:SetText(name, 1, 0, 0)\n" + " if debuffType then self:AddLine(debuffType, 0.5, 0.5, 0.5) end\n" + " self.__spellId = spellId\n" + " end\n" + "end\n" + "function GameTooltip:SetHyperlink(link)\n" + " self:ClearLines()\n" + " if not link then return end\n" + " local id = link:match('item:(%d+)')\n" + " if id then\n" + " local name, _, quality = GetItemInfo(tonumber(id))\n" + " if name then self:SetText(name, 1, 1, 1) end\n" + " return\n" + " end\n" + " id = link:match('spell:(%d+)')\n" + " if id then\n" + " local name = GetSpellInfo(tonumber(id))\n" + " if name then self:SetText(name, 1, 1, 1) end\n" + " end\n" + "end\n" + "function GameTooltip:SetInventoryItem(unit, slot)\n" + " self:ClearLines()\n" + " if unit ~= 'player' then return false, false, 0 end\n" + " local link = GetInventoryItemLink(unit, slot)\n" + " if not link then return false, false, 0 end\n" + " local id = link:match('item:(%d+)')\n" + " if not id then return false, false, 0 end\n" + " local name, itemLink, quality, iLevel, reqLevel, class, subclass = GetItemInfo(tonumber(id))\n" + " if name then\n" + " local colors = {[0]={0.62,0.62,0.62},[1]={1,1,1},[2]={0.12,1,0},[3]={0,0.44,0.87},[4]={0.64,0.21,0.93},[5]={1,0.5,0},[6]={0.9,0.8,0.5}}\n" + " local c = colors[quality or 1] or {1,1,1}\n" + " self:SetText(name, c[1], c[2], c[3])\n" + " if class and class ~= '' then self:AddLine(class, 1, 1, 1) end\n" + " self.__itemId = tonumber(id)\n" + " end\n" + " return true, false, 0\n" + "end\n" + "function GameTooltip:SetBagItem(bag, slot)\n" + " self:ClearLines()\n" + " local tex, count, locked, quality, readable, lootable, link = GetContainerItemInfo(bag, slot)\n" + " if not link then return end\n" + " local id = link:match('item:(%d+)')\n" + " if not id then return end\n" + " local name, itemLink, q = GetItemInfo(tonumber(id))\n" + " if name then\n" + " local colors = {[0]={0.62,0.62,0.62},[1]={1,1,1},[2]={0.12,1,0},[3]={0,0.44,0.87},[4]={0.64,0.21,0.93},[5]={1,0.5,0}}\n" + " local c = colors[q or 1] or {1,1,1}\n" + " self:SetText(name, c[1], c[2], c[3])\n" + " if count and count > 1 then self:AddLine('Count: '..count, 1, 1, 1) end\n" + " self.__itemId = tonumber(id)\n" + " end\n" + "end\n" + "function GameTooltip:SetSpellByID(spellId)\n" + " self:ClearLines()\n" + " if not spellId or spellId == 0 then return end\n" + " local name, rank, icon = GetSpellInfo(spellId)\n" + " if name then\n" + " self:SetText(name, 1, 1, 1)\n" + " if rank and rank ~= '' then self:AddLine(rank, 0.5, 0.5, 0.5) end\n" + " self.__spellId = spellId\n" + " end\n" + "end\n" + "function GameTooltip:SetAction(slot)\n" + " self:ClearLines()\n" + " if not slot then return end\n" + " local actionType, id = GetActionInfo(slot)\n" + " if actionType == 'spell' and id and id > 0 then\n" + " self:SetSpellByID(id)\n" + " elseif actionType == 'item' and id and id > 0 then\n" + " local name, _, quality = GetItemInfo(id)\n" + " if name then self:SetText(name, 1, 1, 1) end\n" + " end\n" + "end\n" "function GameTooltip:FadeOut() end\n" "function GameTooltip:SetFrameStrata(...) end\n" "function GameTooltip:SetClampedToScreen(...) end\n" @@ -4595,11 +4688,8 @@ void LuaEngine::registerCoreAPI() { "function securecall(fn, ...) if type(fn)=='function' then return fn(...) end end\n" "function issecurevariable(...) return false end\n" "function issecure() return false end\n" - // CVar stubs (many addons check settings) - "local _cvars = {}\n" - "function GetCVar(name) return _cvars[name] or '0' end\n" - "function GetCVarBool(name) return _cvars[name] == '1' end\n" - "function SetCVar(name, value) _cvars[name] = tostring(value) end\n" + // GetCVarBool wraps C-side GetCVar (registered in table) for boolean queries + "function GetCVarBool(name) return GetCVar(name) == '1' end\n" // Misc compatibility stubs // GetScreenWidth, GetScreenHeight, GetNumLootItems are now C functions // GetFramerate is now a C function