Files

150 lines
6.4 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Character window and tooltips for SELF transmogs, as on Octo.
-- The server names the real look item only in TW_TRANSMOG status (answered at the
-- transmogrifier). The client's applied appearance can be a same-display stand-in
-- (e.g. Dark Iron Shoulders for Withered Bark Pauldrons), so each status is kept per
-- character, bound to the equipped item and the applied appearance it was seen with,
-- and is ignored as soon as either changes. No Blizzard state is written.
local T = OctoTransmog
local layers = setmetatable({}, {__mode = "k"})
local function location(slot)
if not (C_Item and ItemLocation) then return nil end
local loc = ItemLocation:CreateFromEquipmentSlot(slot)
if loc and C_Item.DoesItemExist(loc) then return loc end
end
-- Applied appearance source, or nil when the slot shows its own item.
local function appliedSource(slot)
local loc = location(slot)
if not loc or not C_Item.GetCurrentItemTransmogInfo then return nil end
local ok, current = pcall(C_Item.GetCurrentItemTransmogInfo, loc)
local source = ok and current and current.appearanceID
if not source or source <= 0 then return nil end
local okBase, base = pcall(C_Item.GetBaseItemTransmogInfo, loc)
if okBase and base and base.appearanceID == source then return nil end
return source
end
local function equippedItem(slot)
return GetInventoryItemID and GetInventoryItemID("player", slot)
end
-- Real look item for a slot: the server status when it still matches, else the
-- applied appearance's own item.
local function lookItem(slot, source)
local saved = OctoTransmogLooks and OctoTransmogLooks[slot]
if saved and saved.item == equippedItem(slot) and saved.applied == source then return saved.look end
local info = C_TransmogCollection.GetSourceInfo(source)
return info and info.itemID
end
function T.RememberStatus(rows)
OctoTransmogLooks = OctoTransmogLooks or {}
for _, slot in ipairs(T.slots) do
local c = slot.client
local look, source = rows[c], appliedSource(c)
if look and look > 0 and source then
OctoTransmogLooks[c] = {item = equippedItem(c), look = look, applied = source}
else
OctoTransmogLooks[c] = nil
end
end
end
local function appliedIcon(slot)
local source = appliedSource(slot)
if not source then return nil end
local item = lookItem(slot, source)
local icons = GWSourceItemIcons
local turtle = item and icons and icons.TextureForItem and icons.TextureForItem(item)
return turtle or C_TransmogCollection.GetSourceIcon(source)
end
local function refresh(button)
if not button or not button.GetID or not button.icon or button:IsForbidden() then return end
local slot = button:GetID()
if not slot or slot < 1 or slot > 19 then return end
local icon = appliedIcon(slot)
local art = layers[button]
if not icon then if art then art:Hide() end return end
if not art then
if InCombatLockdown() then return end
art = button:CreateTexture(nil, "BORDER", nil, 2)
art:SetAllPoints(button.icon)
layers[button] = art
end
art:SetTexture(icon)
art:SetVertexColor(button.icon:GetVertexColor())
art:SetDesaturated(button.icon:IsDesaturated())
art:SetShown(button.icon:IsShown())
end
if PaperDollItemSlotButton_Update then
hooksecurefunc("PaperDollItemSlotButton_Update", refresh)
end
-- "Transmogrified to:" names the stand-in; show the real look item's name instead.
local heading = TRANSMOGRIFIED_HEADER or "Transmogrified to:"
local function fixTooltip(tooltip, data)
if not (data and data.guid and tooltip and tooltip.GetName and tooltip:GetName()) then return end
for slot = 1, 19 do
local loc = location(slot)
if loc and C_Item.GetItemGUID(loc) == data.guid then
local source = appliedSource(slot)
local look = source and lookItem(slot, source)
local info = source and C_TransmogCollection.GetSourceInfo(source)
if not look or not info or look == info.itemID then return end
local name = C_Item.GetItemNameByID(look)
if not name then return end
for i = 1, tooltip:NumLines() do
local left = _G[tooltip:GetName() .. "TextLeft" .. i]
local text = left and left:GetText()
if text and text:find(heading, 1, true) then
local nextLine = _G[tooltip:GetName() .. "TextLeft" .. (i + 1)]
if text:find("\n", 1, true) then
left:SetText((text:gsub("\n.*$", "\n" .. name)))
elseif nextLine then
nextLine:SetText(name)
end
return
end
end
return
end
end
end
if TooltipDataProcessor and Enum and Enum.TooltipDataType then
TooltipDataProcessor.AddTooltipPostCall(Enum.TooltipDataType.Item, fixTooltip)
end
-- Octo players inspecting us ask our client (INSShowTransmogs, relayed by the server).
-- The gateway hands us the asker's name; we answer start + one row per transmogged slot,
-- "<asker>;INSTransmogs;<slot>;<look item>;<equipped item>", as the Octo client does.
local ASK, ANSWER = "OctoTmogAsk", "OctoTmogAns"
local function answer(asker)
local me = UnitName("player")
local function send(text)
C_ChatInfo.SendAddonMessage(ANSWER, asker .. ";INSTransmogs;" .. text, "WHISPER", me)
end
send("start;0;0")
for slot = 1, 19 do
local source = appliedSource(slot)
local look, item = source and lookItem(slot, source), equippedItem(slot)
if look and item and look > 0 then send(slot .. ";" .. look .. ";" .. item) end
end
end
if C_ChatInfo and C_ChatInfo.RegisterAddonMessagePrefix then
C_ChatInfo.RegisterAddonMessagePrefix(ASK)
C_ChatInfo.RegisterAddonMessagePrefix(ANSWER)
local listener = CreateFrame("Frame")
listener:RegisterEvent("CHAT_MSG_ADDON")
listener:SetScript("OnEvent", function(_, _, prefix, text, channel, sender)
if prefix ~= ASK or type(text) ~= "string" or not text:match("^[^;<>|%s]+$") then return end
local me = UnitName("player")
if not me or (sender ~= me and not (sender or ""):find("^" .. me .. "%-")) then return end
answer(text)
end)
end