comparison Modules/PaperDoll.lua @ 65:4fe16cb3f5d6

- paper doll item levels
author Nenue
date Wed, 17 Aug 2016 18:01:42 -0400
parents ba9c13261bb2
children 6ccacc927ef6
comparison
equal deleted inserted replaced
64:ba9c13261bb2 65:4fe16cb3f5d6
1 -- Veneer 1 -- Veneer
2 -- PaperDoll.lua 2 -- PaperDoll.lua
3 -- Created: 8/16/2016 8:18 AM 3 -- Created: 8/16/2016 8:18 AM
4 -- %file-revision% 4 -- %file-revision%
5 -- 5 -- Displays item levels by equipment slots
6 -- Requires tooltip scraping to obtain these numbers, meaning any currently active tooltip will be cleared.
6 7
7 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent) 8 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent)
8 local vn, print = LibStub("LibKraken").register(VeneerController, plugin) 9 local vn, print = LibStub("LibKraken").register(VeneerController, plugin)
9 10
10 local slot_anchors = { 11 local slot_anchors = {
50 } 51 }
51 local ticker 52 local ticker
52 local vnslot = {} 53 local vnslot = {}
53 local pendingSlots = {} 54 local pendingSlots = {}
54 55
56
57
55 local UpdateVeneer = function(itemslot, frame) 58 local UpdateVeneer = function(itemslot, frame)
56 local slot = itemslot:GetID() 59 local slot = itemslot:GetID()
57 if itemslot.hasItem then 60 if itemslot.hasItem then
58 frame.link = GetInventoryItemLink('player', slot) 61 frame.link = GetInventoryItemLink('player', slot)
59 --print(frame.link) 62 --print(frame.link)
60 local name, link, something, ilevel = GetItemInfo(frame.link) 63 local name, link, something, ilevel = GetItemInfo(frame.link)
61 frame.label:SetText(ilevel) 64 frame.label:SetText(ilevel)
62 -- todo: test GetExtendedItemInfo() 65 -- todo: test GetExtendedItemInfo()
63 66
64 local lastOwner = GameTooltip:GetOwner()
65 print(lastOwner)
66
67 GameTooltip:SetOwner(plugin) 67 GameTooltip:SetOwner(plugin)
68 GameTooltip:SetInventoryItem('player', slot) 68 GameTooltip:SetInventoryItem('player', slot)
69 GameTooltip:Hide()
69 70
70 for i = 1, 3 do 71 for i = 1, 3 do
71 local gname = 'gem'..i 72 local gname = 'gem'..i
72 if frame[gname] then 73 if frame[gname] then
73 frame.gemslot[i] = frame.gemslot[i] or frame:CreateTexture(nil, 'ARTWORK') 74 frame.gemslot[i] = frame.gemslot[i] or frame:CreateTexture(nil, 'ARTWORK')
95 local frame = tremove(pendingSlots) 96 local frame = tremove(pendingSlots)
96 if frame and frame:IsVisible() then 97 if frame and frame:IsVisible() then
97 print('updating', frame:GetName()) 98 print('updating', frame:GetName())
98 UpdateVeneer(frame:GetParent(), frame) 99 UpdateVeneer(frame:GetParent(), frame)
99 else 100 else
101
100 ticker:Cancel() 102 ticker:Cancel()
101 ticker = nil 103 ticker = nil
102 end 104 end
103 105
104 end 106 end
146 ticker = C_Timer.NewTicker(0, UpdateNext) 148 ticker = C_Timer.NewTicker(0, UpdateNext)
147 end 149 end
148 end 150 end
149 151
150 152
151 plugin.event = function(self, event, flag, slot) 153 plugin.event = function(self, event, ...)
152 print(self, event, flag, slot) 154 print(self, event, flag, slot)
153 155
156 if event == 'PLAYER_EQUIPMENT_CHANGED' then
157 local slot, hasItem = ...
158 if vnslot[slot] then
159 UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot])
160 plugin.ticker()
161 end
154 162
155 plugin.ticker() 163 end
164
156 end 165 end
157 plugin:SetScript('OnEvent', plugin.event) 166 plugin:SetScript('OnEvent', plugin.event)
158 plugin:RegisterUnitEvent('UNIT_INVENTORY_CHANGED', 'player') 167 plugin:RegisterEvent('PLAYER_EQUIPMENT_CHANGED')
159 168
160 hooksecurefunc("ToggleCharacter", UpdateAll) 169 hooksecurefunc("ToggleCharacter", function()
170 if PaperDollFrame:IsVisible() then
171 UpdateAll()
172 end
173 end)
161 hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update) 174 hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
162 175
163 hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot) 176 hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot)
164 if self:GetOwner() == plugin then 177 if self:GetOwner() == plugin then
165 if unit == 'player' and vnslot[slot] then 178 if unit == 'player' and vnslot[slot] then
166 vnslot[slot].label:SetText(GameTooltipTextLeft3:GetText():match('%d+')) 179
180 local text = GameTooltipTextLeft3:GetText():match('Item Level (%d+)')
181 if not text then
182 text = GameTooltipTextLeft2:GetText():match('Item Level (%d+)')
183 end
184 vnslot[slot].label:SetText(text or '???')
167 end 185 end
168 end 186 end
169 end) 187 end)
170 188