Files

605 lines
29 KiB
Lua

-- OctoTextSize: addon-local factory; Blizzard CreateFrame is unchanged.
local CreateFrame = OctoTextSize and OctoTextSize.WrapFactory(CreateFrame) or CreateFrame
-- Native 70334 widgets over Octo's source-owned transmog service. This does
-- not replace the modern C_TransmogOutfitInfo provider with invented data.
local T = OctoTransmog
local state = {slot=nil, equipped=nil, available={}, complete=false, loading=false,
selected=nil, page=1, status={}, statusEquipment={},
statusReady=false, statusOutstanding=0,
statusRequestEquipment={}, pending=nil,
listFlight=nil, queuedSlot=nil, previewKey=nil}
T.state = state
local function itemLink(id) return "item:" .. id .. ":0:0:0:0:0:0:0" end
local function itemInfo(id)
local get = C_Item and C_Item.GetItemInfo or GetItemInfo
if type(get) ~= "function" then return nil, nil end
local name, _, _, _, _, _, _, _, _, icon = get(id)
if not icon and C_Item and C_Item.GetItemIconByID then icon = C_Item.GetItemIconByID(id) end
return name, icon
end
local function equippedID(slot)
return T.ItemID(GetInventoryItemLink("player", slot))
end
local function itemInvType(id)
local get = C_Item and C_Item.GetItemInfoInstant or GetItemInfoInstant
if type(get) ~= "function" then return nil end
local _, _, _, equipLoc = get(id)
return T.inventoryType[equipLoc]
end
local function send(payload)
if not C_ChatInfo or type(C_ChatInfo.SendAddonMessage) ~= "function" then return false end
local result = C_ChatInfo.SendAddonMessage(T.prefix, payload, "WHISPER", UnitName("player"))
-- 70334 returns SendAddonMessageResult (Success = 0). Every numeric error
-- is truthy in Lua, including throttles for messages never sent.
return result == 0 or result == true
end
T.Send = send
local function equipmentSnapshot()
local result={}
for _,slot in ipairs(T.slots) do result[slot.client]=equippedID(slot.client) end
return result
end
local function requestStatus()
state.status={};state.statusEquipment={};state.statusReady=false
local equipment=equipmentSnapshot()
if send("GetTransmogStatus")==false then return false end
-- Source status replies have no request ID. Drain older replies before
-- accepting the latest snapshot after an equipment change.
state.statusOutstanding=state.statusOutstanding+1
state.statusRequestEquipment=equipment
return true
end
-- Blizzard's own portrait window (ButtonFrameTemplate), like the stock vendor
-- and dressing-room panels: NPC portrait, title bar, close button, insets.
local frame = CreateFrame("Frame", "OctoTransmogFrame", UIParent, "ButtonFrameTemplate")
T.frame = frame
frame:SetSize(720, 520)
frame:SetPoint("CENTER", 0, 40)
frame:SetToplevel(true)
frame:SetClampedToScreen(true)
frame:EnableMouse(true)
frame:SetMovable(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
if frame.SetTitle then frame:SetTitle("Transmogrify") end
frame:Hide()
-- Keep addon keys on the visible window. Inserting a handler into the sorted
-- game-menu list marks the stock casting callback read on every Escape.
local function makeKeyListener(consumeEscape)
local listener = CreateFrame("Frame", nil, frame, "InsecureKeyboardInputPropagatorTemplate")
listener:Hide()
listener:EnableKeyboard(true)
listener:SetScript("OnKeyDown", function(self, key)
local dismiss = (key == "ESCAPE" or GetBindingFromClick(key) == "TOGGLEGAMEMENU")
and not StaticPopup_IsAnyDialogShown() and not GetCurrentKeyBoardFocus()
and not (GameMenuFrame and GameMenuFrame:IsShown())
and not (EditModeManagerFrame and EditModeManagerFrame:IsShown())
and not SpellIsTargeting() and not (PlayerCastingBarFrame and PlayerCastingBarFrame:IsVisible())
if consumeEscape and not InCombatLockdown() then self:SetPropagateKeyboardInput(not dismiss) end
if dismiss then frame:Hide() end
end)
return listener
end
local escapeKeys = makeKeyListener(true)
local combatKeys = makeKeyListener(false)
local function armEscapeKeys()
local combat = not not InCombatLockdown()
if not combat then escapeKeys:SetPropagateKeyboardInput(true) end
escapeKeys:SetShown(not combat)
-- This listener keeps the template's fixed pass-through during lockdown.
combatKeys:SetShown(combat)
end
escapeKeys:RegisterEvent("PLAYER_REGEN_DISABLED")
escapeKeys:RegisterEvent("PLAYER_REGEN_ENABLED")
escapeKeys:SetScript("OnEvent", function() if frame:IsShown() then armEscapeKeys() end end)
local function label(parent, font, text, point, x, y)
local value = parent:CreateFontString(nil,"OVERLAY",font)
value:SetPoint(point,parent,point,x,y)
value:SetText(text)
return value
end
-- Left: the character on the class dressing-room background, with the
-- equipped slots around it as on the paper doll.
local modelInset = type(frame.Inset) == "table" and frame.Inset or CreateFrame("Frame", nil, frame, "InsetFrameTemplate")
modelInset:ClearAllPoints()
modelInset:SetPoint("TOPLEFT", frame, "TOPLEFT", 6, -60)
modelInset:SetPoint("BOTTOMRIGHT", frame, "BOTTOMLEFT", 346, 30)
-- ARTWORK: the inset draws its own background on BACKGROUND above lower sublevels.
local backdrop = modelInset:CreateTexture(nil, "ARTWORK", nil, -8)
backdrop:SetPoint("TOPLEFT", 3, -3);backdrop:SetPoint("BOTTOMRIGHT", -3, 3)
local function paintBackdrop()
if not UnitClass then return end
local _, class = UnitClass("player")
if class and backdrop.SetAtlas then backdrop:SetAtlas("dressingroom-background-" .. string.lower(class)) end
end
local model = CreateFrame("DressUpModel", nil, modelInset)
model:SetPoint("TOPLEFT", 50, -8);model:SetPoint("BOTTOMRIGHT", -50, 56)
local previewText = label(modelInset, "GameFontHighlightSmall", "Preview", "BOTTOM", 0, 8)
previewText:SetWidth(320);previewText:SetJustifyH("CENTER")
-- Right: the server-approved looks for the selected slot.
local listInset = CreateFrame("Frame", nil, frame, "InsetFrameTemplate")
listInset:SetPoint("TOPLEFT", modelInset, "TOPRIGHT", 6, 0)
listInset:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -6, 30)
local selection = label(listInset, "GameFontNormal", "Select an equipped slot.", "TOPLEFT", 12, -12)
selection:SetWidth(250);selection:SetJustifyH("LEFT");selection:SetWordWrap(false)
local info = label(listInset, "GameFontHighlightSmall", "Visit Herrina to browse your unlocked looks.", "BOTTOMLEFT", 12, 38)
info:SetWidth(330);info:SetJustifyH("LEFT")
local pageLabel = label(listInset, "GameFontHighlightSmall", "", "BOTTOM", 0, 14)
local balance = label(frame, "GameFontHighlight", "", "BOTTOMLEFT", 14, 8)
local function button(text,w,h,parent)
local b=CreateFrame("Button",nil,parent or frame,"UIPanelButtonTemplate")
b:SetSize(w,h);b:SetText(text)
return b
end
local apply=button("Apply appearance",140,22);apply:SetPoint("BOTTOMRIGHT",-6,4)
local reset=button("Reset",90,22);reset:SetPoint("RIGHT",apply,"LEFT",-2,0)
local refreshButton=button("Refresh",72,20,listInset);refreshButton:SetPoint("TOPRIGHT",-8,-8)
local function pager(name, x)
local b=CreateFrame("Button",nil,listInset)
b:SetSize(28,28);b:SetPoint("BOTTOM",x,6)
b:SetNormalTexture("Interface\\Buttons\\UI-SpellbookIcon-"..name.."Page-Up")
b:SetPushedTexture("Interface\\Buttons\\UI-SpellbookIcon-"..name.."Page-Down")
b:SetDisabledTexture("Interface\\Buttons\\UI-SpellbookIcon-"..name.."Page-Disabled")
b:SetHighlightTexture("Interface\\Buttons\\UI-Common-MouseHilight","ADD")
return b
end
local previousPage=pager("Prev",-70)
local nextPage=pager("Next",70)
-- Paper-doll order around the model; 70334's intrinsic ItemButton carries the
-- icon, border and slot art (there is no ItemButtonTemplate in this client).
local SLOT_NAMES={[1]="HEADSLOT",[3]="SHOULDERSLOT",[4]="SHIRTSLOT",[5]="CHESTSLOT",[6]="WAISTSLOT",
[7]="LEGSSLOT",[8]="FEETSLOT",[9]="WRISTSLOT",[10]="HANDSSLOT",[15]="BACKSLOT",[16]="MAINHANDSLOT",
[17]="SECONDARYHANDSLOT",[18]="RANGEDSLOT",[19]="TABARDSLOT"}
local LAYOUT={[1]={"L",0},[3]={"L",1},[15]={"L",2},[5]={"L",3},[4]={"L",4},[19]={"L",5},[9]={"L",6},
[10]={"R",0},[6]={"R",1},[7]={"R",2},[8]={"R",3},[16]={"B",-1},[17]={"B",0},[18]={"B",1}}
local slotButtons={}
for index, slot in ipairs(T.slots) do
local b=CreateFrame("ItemButton",nil,modelInset)
b:SetSize(37,37)
local side,pos=LAYOUT[slot.client][1],LAYOUT[slot.client][2]
if side=="L" then b:SetPoint("TOPLEFT",8,-10-pos*42)
elseif side=="R" then b:SetPoint("TOPRIGHT",-8,-10-pos*42)
else b:SetPoint("BOTTOM",pos*44,24) end
local empty
if GetInventorySlotInfo then empty=select(2,GetInventorySlotInfo(SLOT_NAMES[slot.client])) end
b.emptyTexture=empty
local chosen=b:CreateTexture(nil,"OVERLAY")
chosen:SetTexture("Interface\\Buttons\\CheckButtonHilight");chosen:SetBlendMode("ADD")
chosen:SetAllPoints();chosen:Hide()
b.chosen=chosen
b.slot=slot
b:SetScript("OnClick",function(self) T.SelectSlot(self.slot.client) end)
b:SetScript("OnEnter",function(self)
GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
if GetInventoryItemLink("player",self.slot.client) then GameTooltip:SetInventoryItem("player",self.slot.client)
else GameTooltip:SetText(self.slot.name) end
GameTooltip:Show()
end)
b:SetScript("OnLeave",function()GameTooltip:Hide()end)
slotButtons[index]=b
end
local cards={}
for index=1,12 do
local card=CreateFrame("Button",nil,listInset)
local column=(index-1)%2
local row=math.floor((index-1)/2)
card:SetSize(170,44)
card:SetPoint("TOPLEFT",10+column*176,-40-row*48)
local icon=CreateFrame("ItemButton",nil,card)
icon:SetSize(40,40);icon:SetPoint("LEFT",0,0);icon:EnableMouse(false)
local title=card:CreateFontString(nil,"OVERLAY","GameFontNormalSmall")
title:SetPoint("LEFT",icon,"RIGHT",6,0);title:SetPoint("RIGHT",card,"RIGHT",-2,0)
title:SetHeight(40);title:SetJustifyH("LEFT");title:SetJustifyV("MIDDLE")
local chosen=card:CreateTexture(nil,"BACKGROUND")
chosen:SetAllPoints();chosen:SetColorTexture(1,0.82,0,0.18);chosen:Hide()
local hover=card:CreateTexture(nil,"HIGHLIGHT")
hover:SetAllPoints();hover:SetColorTexture(1,1,1,0.08)
card.icon,card.title,card.chosen=icon,title,chosen
card:SetScript("OnClick",function(self)
if not self.itemID or not state.complete or state.pending then return end
state.selected=self.itemID
T.Refresh()
end)
card:SetScript("OnEnter",function(self)
if not self.itemID then return end
GameTooltip:SetOwner(self,"ANCHOR_RIGHT")
GameTooltip:SetHyperlink(itemLink(self.itemID))
GameTooltip:Show()
end)
card:SetScript("OnLeave",function()GameTooltip:Hide()end)
cards[index]=card
end
local function status(text) info:SetText(text or "") end
local function coinCount()
-- Source Player::GetItemCount uses inBankAlso=false before spending a coin.
if type(GetItemCount)=="function" then return GetItemCount(T.coinID) end
if C_Item and type(C_Item.GetItemCount)=="function" then return C_Item.GetItemCount(T.coinID) end
end
local function hasAvailable(id)
for _,value in ipairs(state.available) do if value==id then return true end end
return false
end
local function refreshPreview()
if not frame:IsShown() then return end
local active=state.slot and state.status[state.slot] or 0
local key=tostring(state.slot)..":"..tostring(state.equipped)..":"..
tostring(state.selected)..":"..tostring(active)
if state.previewKey==key or state.previewKey=="loading:"..key then return end
state.previewKey=key
model:SetUnit("player")
model:SetFacing(0.61)
if not state.selected then
previewText:SetText("Current appearance")
return
end
if not itemInfo(state.selected) then
if C_Item and type(C_Item.RequestLoadItemDataByID)=="function" then
C_Item.RequestLoadItemDataByID(state.selected)
end
state.previewKey="loading:"..key
previewText:SetText("Preview unavailable: item data is loading")
return
end
-- In 70334 a numeric TryOn argument is a modified appearance ID. Octo's
-- list contains source item IDs, so always pass an item link string.
local hand=state.slot==17 and "OFFHAND" or nil
local ok,reason=pcall(model.TryOn,model,itemLink(state.selected),hand)
if not ok or not Enum or not Enum.ItemTryOnReason or
reason~=Enum.ItemTryOnReason.Success then
previewText:SetText("Preview unavailable for this item")
else previewText:SetText("Preview only — no Fashion Coin spent") end
end
function T.Refresh()
local coins=coinCount()
local _,coinIcon=itemInfo(T.coinID)
balance:SetText((coinIcon and ("|T"..coinIcon..":16:16:0:0|t ") or "").."Fashion Coins: "..(coins and tostring(coins) or "—").." |cffa0a0a0(one per change)|r")
for _,b in ipairs(slotButtons) do
local owned=equippedID(b.slot.client)
local look=state.status[b.slot.client]
local shown=look and look>0 and select(2,itemInfo(look)) or (owned and GetInventoryItemTexture and GetInventoryItemTexture("player",b.slot.client))
if b.SetItemButtonTexture then b:SetItemButtonTexture(shown or b.emptyTexture)
elseif type(b.icon)=="table" then b.icon:SetTexture(shown or b.emptyTexture) end
if type(b.IconBorder)=="table" then
-- Transmogrified slots get the stock transmog pink border.
b.IconBorder:SetShown(look and look>0 or false)
b.IconBorder:SetVertexColor(1,0.5,1)
end
if b.chosen then b.chosen:SetShown(b.slot.client==state.slot) end
if owned then b:Enable() else b:Disable() end
end
local current=state.slot and T.slotByClient[state.slot]
local active=current and state.status[current.client] or 0
local selectedName=state.selected and itemInfo(state.selected)
selection:SetText(current and (current.name.." • "..(state.selected and
(selectedName or "Item "..state.selected) or (active and active>0 and "Current look: "..active or "Select a look"))) or
"Select an equipped slot.")
local pages=math.max(1,math.ceil(#state.available/12))
if state.page>pages then state.page=pages end
pageLabel:SetText("Page "..state.page.." / "..pages)
if state.page>1 then previousPage:Enable() else previousPage:Disable() end
if state.page<pages then nextPage:Enable() else nextPage:Disable() end
for index,card in ipairs(cards) do
local id=state.available[(state.page-1)*12+index]
card.itemID=id
if id then
local name,icon=itemInfo(id)
local texture=icon or "Interface\\Icons\\INV_Misc_QuestionMark"
if card.icon.SetItemButtonTexture then card.icon:SetItemButtonTexture(texture)
elseif type(card.icon.icon)=="table" then card.icon.icon:SetTexture(texture) end
card.title:SetText(name or ("Item "..id))
local quality=C_Item and C_Item.GetItemQualityByID and C_Item.GetItemQualityByID(id)
local color=quality and ITEM_QUALITY_COLORS and ITEM_QUALITY_COLORS[quality]
if color and card.title.SetTextColor then card.title:SetTextColor(color.r,color.g,color.b)
elseif card.title.SetTextColor then card.title:SetTextColor(1,0.82,0) end
if quality and card.icon.SetItemButtonQuality then card.icon:SetItemButtonQuality(quality,id) end
card.chosen:SetShown(id==state.selected)
card:Show()
else card:Hide() end
end
if state.selected and state.complete and not state.pending and
(not coins or coins>0) and hasAvailable(state.selected) and
state.equipped==equippedID(state.slot) then apply:Enable()
else apply:Disable() end
-- Reset has no coin or appearance-list dependency on the Source server.
if active and active>0 and state.statusReady and not state.pending and
state.statusEquipment[state.slot]==state.equipped and
state.equipped==equippedID(state.slot) then reset:Enable()
else reset:Disable() end
refreshPreview()
end
local function startListRequest(clientSlot)
if state.listFlight then return end
local equipped=equippedID(clientSlot)
if not equipped then return end
-- Source parses this compatibility hint but does not use it for the
-- appearance list. Missing local item metadata must not block the query.
local invType=itemInvType(equipped) or 0
local flight={slot=clientSlot,equipped=equipped,started=false,ids={},total=nil,
timedOut=false,invalid=false}
state.listFlight=flight
state.loading=true
status("Loading server-approved appearances…")
if send("GetAvailableTransmogsItemIDs:"..clientSlot..":"..invType..":"..equipped)==false then
state.listFlight=nil
state.loading=false
status("Could not request appearances. Try again near a Fashionista.")
T.Refresh()
return
end
C_Timer.After(15,function()
if state.listFlight==flight then
-- Replies have no request ID. Keep this flight until its terminal
-- end/error; a timed-out list can never approve a later selection.
flight.timedOut=true
state.loading=false;state.available={};state.complete=false
status("The server list did not finish. Wait for its reply or /reload before retrying.")
T.Refresh()
end
end)
end
local function finishListFlight()
state.listFlight=nil
local queued=state.queuedSlot
state.queuedSlot=nil
if queued and frame:IsShown() and state.slot==queued and equippedID(queued) then
startListRequest(queued)
end
end
function T.SelectSlot(clientSlot)
local slot=T.slotByClient[clientSlot]
if not slot then return end
state.slot=clientSlot
state.equipped=equippedID(clientSlot)
state.available={};state.selected=nil;state.page=1
state.complete=false;state.loading=false;state.previewKey=nil
T.Refresh()
if not state.equipped then
state.queuedSlot=nil
status("Equip an item in this slot first.")
return
end
if state.listFlight then
state.queuedSlot=clientSlot
state.loading=not state.listFlight.timedOut
status(state.listFlight.timedOut and
"The previous list did not finish. Wait for its reply or /reload." or
"Waiting for the previous appearance list to finish…")
return
end
startListRequest(clientSlot)
end
refreshButton:SetScript("OnClick",function()
requestStatus()
if state.slot then T.SelectSlot(state.slot) end
end)
previousPage:SetScript("OnClick",function()state.page=math.max(1,state.page-1);T.Refresh()end)
nextPage:SetScript("OnClick",function()state.page=state.page+1;T.Refresh()end)
local errors={
[1]="No equipped item in this slot.",[2]="Invalid equipment slot.",
[3]="Appearance not unlocked.",[4]="Source item unavailable.",
[5]="Appearance is incompatible with this item.",[11]="A Fashion Coin is required.",
}
local function startPending(action,id)
local slot=T.slotByClient[state.slot]
if not slot or state.pending or
state.equipped~=equippedID(slot.client) then return end
if action=="Transmog" then
if not state.complete or not id or state.selected~=id or
not hasAvailable(id) then return end
if coinCount()==0 then
status("A Fashion Coin in your bags is required.")
T.Refresh()
return
end
elseif action=="Reset" then
if not state.statusReady or not state.status[slot.client] or
state.status[slot.client]==0 or
state.statusEquipment[slot.client]~=state.equipped then return end
else return end
state.pending={action=action,slot=slot.client,equipped=state.equipped,
sourceItemID=id,timedOut=false}
T.Refresh()
status("Waiting for Octo's transmog result…")
local message
if action=="Transmog" then message="DoTransmog:"..slot.server..":"..id..":"..slot.client
else message="ResetTransmog:"..slot.server..":"..slot.client end
if send(message)==false then
state.pending=nil
status("Could not send the transmog request. No change was made.")
T.Refresh()
return
end
local pending=state.pending
C_Timer.After(10,function()
if state.pending==pending then
-- Results have no request ID. Keep the flight reserved so a late
-- result cannot be mistaken for a second spend/reset request.
pending.timedOut=true
status("Octo has not confirmed this change. Wait for its result or /reload.")
T.Refresh()
end
end)
end
local function equippedGUID(slot)
if ItemLocation and C_Item and C_Item.GetItemGUID and equippedID(slot) then
return C_Item.GetItemGUID(ItemLocation:CreateFromEquipmentSlot(slot))
end
end
StaticPopupDialogs.OCTO_TRANSMOG_CONFIRM={
text="Spend one Fashion Coin to apply this appearance?",
button1=YES,button2=NO,timeout=0,whileDead=false,hideOnEscape=true,
OnAccept=function(_,target)
if type(target) ~= "table" then return end
if state.slot ~= target.slot or equippedID(target.slot) ~= target.itemID or
equippedGUID(target.slot) ~= target.guid or state.selected ~= target.appearance then
status("Your item or appearance changed. Select it and confirm again.")
return
end
startPending("Transmog",target.appearance)
end,
}
apply:SetScript("OnClick",function()
if state.selected and hasAvailable(state.selected) then
StaticPopup_Show("OCTO_TRANSMOG_CONFIRM",nil,nil,{
slot=state.slot,itemID=state.equipped,guid=equippedGUID(state.slot),
appearance=state.selected,
})
end
end)
reset:SetScript("OnClick",function()startPending("Reset")end)
local events=CreateFrame("Frame")
for _,event in ipairs({"CHAT_MSG_ADDON","GOSSIP_SHOW","GOSSIP_CLOSED",
"PLAYER_ENTERING_WORLD","UNIT_INVENTORY_CHANGED",
"GET_ITEM_INFO_RECEIVED","BAG_UPDATE_DELAYED"}) do events:RegisterEvent(event) end
if C_ChatInfo and C_ChatInfo.RegisterAddonMessagePrefix then
C_ChatInfo.RegisterAddonMessagePrefix(T.prefix)
end
local openedByGossip=false
local function gossipTrigger()
local guid=UnitGUID("npc")
local entry=guid and tonumber(string.match(guid,"^Creature%-[^%-]+%-[^%-]+%-[^%-]+%-[^%-]+%-(%d+)%-"))
local name=UnitName("npc")
if entry==51291 or name=="Herrina" or name=="Felicia" then return true end
local ok,text
if C_GossipInfo and type(C_GossipInfo.GetText)=="function" then
ok,text=pcall(C_GossipInfo.GetText)
elseif type(GetGossipText)=="function" then
ok,text=pcall(GetGossipText)
end
return ok and text=="TRANSMOG_TRIGGER"
end
events:SetScript("OnEvent",function(_,event,prefix,message,distribution,sender)
if event=="PLAYER_ENTERING_WORLD" then
frame:Hide();state.status={};state.statusEquipment={}
state.statusReady=false;state.statusOutstanding=0
state.statusRequestEquipment={};state.pending=nil
state.listFlight=nil;state.queuedSlot=nil;state.previewKey=nil
elseif event=="GOSSIP_SHOW" then
if gossipTrigger() then openedByGossip=true;frame:Show() end
elseif event=="GOSSIP_CLOSED" then
if openedByGossip then frame:Hide();openedByGossip=false end
elseif event=="UNIT_INVENTORY_CHANGED" then
if prefix=="player" and frame:IsShown() then
if state.statusReady or state.statusOutstanding>0 then
local anchor=state.statusReady and state.statusEquipment or
state.statusRequestEquipment
for _,slot in ipairs(T.slots) do
if anchor[slot.client]~=equippedID(slot.client) then
requestStatus();break
end
end
end
if state.slot and state.equipped~=equippedID(state.slot) then T.SelectSlot(state.slot)
else T.Refresh() end
end
elseif event=="GET_ITEM_INFO_RECEIVED" or event=="BAG_UPDATE_DELAYED" then
if frame:IsShown() then
if event=="GET_ITEM_INFO_RECEIVED" then state.previewKey=nil end
T.Refresh()
end
elseif event=="CHAT_MSG_ADDON" then
if prefix~=T.prefix or distribution~="GUILD" or
(sender and sender~=UnitName("player")) then return end
local reply=T.Parse(message)
if not reply then return end
if reply.kind=="status" then
if state.statusOutstanding==0 then return end
state.statusOutstanding=state.statusOutstanding-1
if state.statusOutstanding>0 then return end
local equipment=equipmentSnapshot()
for _,slot in ipairs(T.slots) do
if state.statusRequestEquipment[slot.client]~=equipment[slot.client] then
requestStatus();T.Refresh();return
end
end
state.status=reply.rows;state.statusEquipment=equipment
if T.RememberStatus then T.RememberStatus(reply.rows) end
state.statusReady=true;T.Refresh()
elseif reply.kind=="start" or reply.kind=="items" or reply.kind=="end" then
local flight=state.listFlight
if not flight or reply.slot~=flight.slot then return end
if reply.kind=="start" then
if flight.started then flight.invalid=true;return end
flight.started=true;flight.total=reply.total
if not state.queuedSlot and state.slot==flight.slot then
state.available={};state.complete=false;T.Refresh()
end
elseif reply.kind=="items" then
if not flight.started or reply.total~=flight.total then
flight.invalid=true;return
end
if #flight.ids+#reply.ids>5000 then flight.invalid=true;return end
for _,id in ipairs(reply.ids) do flight.ids[#flight.ids+1]=id end
elseif flight.started then
local current=frame:IsShown() and state.slot==flight.slot and
state.equipped==flight.equipped and
equippedID(flight.slot)==flight.equipped
local accepted=current and not state.queuedSlot and not flight.invalid and
not flight.timedOut and reply.total==flight.total
state.loading=false
if accepted then
state.available=flight.ids;state.complete=true
status(#state.available.." server-approved appearances")
elseif current and not state.queuedSlot then
state.available={};state.complete=false
status("The appearance list was incomplete. Refresh before applying a look.")
end
finishListFlight()
T.Refresh()
end
elseif reply.kind=="result" and state.pending and
reply.slot==state.pending.slot and reply.action==state.pending.action then
state.pending=nil
if reply.code==0 then
status(reply.action=="Reset" and "Appearance reset." or "Appearance applied.")
requestStatus()
if frame:IsShown() and state.slot then T.SelectSlot(state.slot)
else state.complete=false;state.available={};state.selected=nil end
else status(errors[reply.code] or ("Octo declined the change ("..reply.code..")."));T.Refresh() end
elseif reply.kind=="error" then
if state.listFlight then
state.loading=false;state.complete=false;state.available={}
finishListFlight()
if not state.listFlight then status(reply.text) end
T.Refresh()
end
end
end
end)
frame:SetScript("OnShow",function()
armEscapeKeys()
paintBackdrop()
if frame.SetPortraitToUnit and UnitExists and UnitExists("npc") then frame:SetPortraitToUnit("npc")
elseif frame.SetPortraitToAsset then frame:SetPortraitToAsset("Interface\\Icons\\INV_Chest_Cloth_17") end
requestStatus()
if not state.slot or not equippedID(state.slot) then
for _,slot in ipairs(T.slots) do
if equippedID(slot.client) then state.slot=slot.client;break end
end
end
if state.slot then T.SelectSlot(state.slot) else T.Refresh() end
end)
frame:SetScript("OnHide",function()
StaticPopup_Hide("OCTO_TRANSMOG_CONFIRM");GameTooltip:Hide()
-- Keep an untagged action result reserved even while this window is shut.
state.loading=false;state.complete=false
state.queuedSlot=nil;state.previewKey=nil
end)
SLASH_OCTOTRANSMOG1="/transmog"
SlashCmdList.OCTOTRANSMOG=function()
openedByGossip=false
if frame:IsShown() then frame:Hide() else frame:Show() end
end