annotate Modules/PaperDoll.lua @ 66:6ccacc927ef6

- paperdoll scan timing changed to PLAYER_ENTERING_WORLD and PLAYER_EQUIPMENT_CHANGED
author Nenue
date Fri, 19 Aug 2016 09:28:38 -0400
parents 4fe16cb3f5d6
children 6f8661094643
rev   line source
Nenue@62 1 -- Veneer
Nenue@62 2 -- PaperDoll.lua
Nenue@62 3 -- Created: 8/16/2016 8:18 AM
Nenue@62 4 -- %file-revision%
Nenue@65 5 -- Displays item levels by equipment slots
Nenue@65 6 -- Requires tooltip scraping to obtain these numbers, meaning any currently active tooltip will be cleared.
Nenue@62 7
Nenue@62 8 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent)
Nenue@62 9 local vn, print = LibStub("LibKraken").register(VeneerController, plugin)
Nenue@62 10
Nenue@64 11 local slot_anchors = {
Nenue@64 12 [1] = 'TOPLEFT',
Nenue@64 13 [2] = 'TOPLEFT',
Nenue@64 14 [3] = 'TOPLEFT',
Nenue@64 15 [15] = 'TOPLEFT',
Nenue@64 16 [5] = 'TOPLEFT',
Nenue@64 17 [9] = 'TOPLEFT',
Nenue@62 18
Nenue@64 19 [10] = 'TOPRIGHT',
Nenue@64 20 [6] = 'TOPRIGHT',
Nenue@64 21 [7] = 'TOPRIGHT',
Nenue@64 22 [8] = 'TOPRIGHT',
Nenue@64 23 [11] = 'TOPRIGHT',
Nenue@64 24 [12] = 'TOPRIGHT',
Nenue@64 25 [13] = 'TOPRIGHT',
Nenue@64 26 [14] = 'TOPRIGHT',
Nenue@64 27
Nenue@64 28 [16] = 'BOTTOMRIGHT',
Nenue@64 29 [17] = 'BOTTOMLEFT',
Nenue@64 30 }
Nenue@64 31
Nenue@64 32 local slot_relative = {
Nenue@64 33 [1] = 'TOPRIGHT',
Nenue@64 34 [2] = 'TOPRIGHT',
Nenue@64 35 [3] = 'TOPRIGHT',
Nenue@64 36 [15] = 'TOPRIGHT',
Nenue@64 37 [5] = 'TOPRIGHT',
Nenue@64 38 [9] = 'TOPRIGHT',
Nenue@64 39
Nenue@64 40 [10] = 'TOPLEFT',
Nenue@64 41 [6] = 'TOPLEFT',
Nenue@64 42 [7] = 'TOPLEFT',
Nenue@64 43 [8] = 'TOPLEFT',
Nenue@64 44 [11] = 'TOPLEFT',
Nenue@64 45 [12] = 'TOPLEFT',
Nenue@64 46 [13] = 'TOPLEFT',
Nenue@64 47 [14] = 'TOPLEFT',
Nenue@64 48
Nenue@64 49 [16] = 'TOPRIGHT',
Nenue@64 50 [17] = 'TOPLEFT',
Nenue@64 51 }
Nenue@64 52 local ticker
Nenue@64 53 local vnslot = {}
Nenue@64 54 local pendingSlots = {}
Nenue@64 55
Nenue@65 56
Nenue@65 57
Nenue@64 58 local UpdateVeneer = function(itemslot, frame)
Nenue@64 59 local slot = itemslot:GetID()
Nenue@64 60 if itemslot.hasItem then
Nenue@62 61 frame.link = GetInventoryItemLink('player', slot)
Nenue@64 62 --print(frame.link)
Nenue@64 63 local name, link, something, ilevel = GetItemInfo(frame.link)
Nenue@64 64 frame.label:SetText(ilevel)
Nenue@62 65 -- todo: test GetExtendedItemInfo()
Nenue@62 66
Nenue@64 67 GameTooltip:SetOwner(plugin)
Nenue@64 68 GameTooltip:SetInventoryItem('player', slot)
Nenue@65 69 GameTooltip:Hide()
Nenue@64 70
Nenue@62 71 for i = 1, 3 do
Nenue@62 72 local gname = 'gem'..i
Nenue@62 73 if frame[gname] then
Nenue@62 74 frame.gemslot[i] = frame.gemslot[i] or frame:CreateTexture(nil, 'ARTWORK')
Nenue@62 75 print(frame[gname])
Nenue@62 76 end
Nenue@62 77 end
Nenue@62 78 frame:Show()
Nenue@62 79 else
Nenue@62 80 frame:Hide()
Nenue@62 81 end
Nenue@62 82 end
Nenue@62 83
Nenue@64 84 local UpdateAll = function()
Nenue@64 85 for index, frame in pairs(vnslot) do
Nenue@64 86 if frame:IsVisible() then
Nenue@64 87 print('forcing', index, frame:GetName())
Nenue@64 88 tinsert(pendingSlots, frame)
Nenue@64 89 end
Nenue@64 90 end
Nenue@64 91 plugin.ticker()
Nenue@62 92 end
Nenue@62 93
Nenue@64 94 local UpdateNext = function()
Nenue@64 95
Nenue@64 96 local frame = tremove(pendingSlots)
Nenue@64 97 if frame and frame:IsVisible() then
Nenue@64 98 print('updating', frame:GetName())
Nenue@64 99 UpdateVeneer(frame:GetParent(), frame)
Nenue@64 100 else
Nenue@65 101
Nenue@64 102 ticker:Cancel()
Nenue@64 103 ticker = nil
Nenue@64 104 end
Nenue@64 105
Nenue@64 106 end
Nenue@64 107
Nenue@64 108 -- PaperDollFrame is separate from InspectUI handlers
Nenue@64 109 local PaperDollItemSlotButton_Update = function(self)
Nenue@64 110 local name = self:GetName()
Nenue@64 111 local slot = self:GetID()
Nenue@64 112 if not slot_anchors[slot] then
Nenue@64 113 return
Nenue@64 114 end
Nenue@64 115
Nenue@64 116
Nenue@64 117 local frame = _G[name .. 'Veneer']
Nenue@64 118
Nenue@64 119 if not frame then
Nenue@64 120
Nenue@64 121 frame = CreateFrame('Frame', name..'Veneer', self)
Nenue@64 122 vnslot[slot] = frame
Nenue@64 123
Nenue@64 124 frame.label = frame:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFont')
Nenue@64 125 frame.gemslot = {}
Nenue@64 126
Nenue@64 127 local anchor, relative, x, y = slot_anchors[slot], slot_relative[slot], 8, -4
Nenue@64 128 if anchor:match('RIGHT') then
Nenue@64 129 x = -x
Nenue@64 130 end
Nenue@64 131 if anchor:match('BOTTOM') then
Nenue@64 132 y = 4
Nenue@64 133 end
Nenue@64 134
Nenue@64 135
Nenue@64 136 frame:SetPoint(anchor, self, relative, x, y)
Nenue@64 137 frame:SetSize(200,24)
Nenue@64 138 frame.label:ClearAllPoints()
Nenue@64 139 frame.label:SetPoint(slot_anchors[slot], frame, slot_anchors[slot])
Nenue@64 140
Nenue@64 141 tinsert(pendingSlots, frame)
Nenue@64 142 end
Nenue@66 143
Nenue@66 144 plugin.ticker()
Nenue@64 145 end
Nenue@64 146
Nenue@64 147
Nenue@64 148 plugin.ticker = function()
Nenue@64 149 if (not ticker) and #pendingSlots >= 1 then
Nenue@64 150 ticker = C_Timer.NewTicker(0, UpdateNext)
Nenue@64 151 end
Nenue@64 152 end
Nenue@64 153
Nenue@64 154
Nenue@65 155 plugin.event = function(self, event, ...)
Nenue@64 156 print(self, event, flag, slot)
Nenue@64 157
Nenue@65 158 if event == 'PLAYER_EQUIPMENT_CHANGED' then
Nenue@65 159 local slot, hasItem = ...
Nenue@65 160 if vnslot[slot] then
Nenue@65 161 UpdateVeneer(vnslot[slot]:GetParent(), vnslot[slot])
Nenue@65 162 plugin.ticker()
Nenue@65 163 end
Nenue@64 164
Nenue@66 165 elseif event == 'PLAYER_ENTERING_WORLD' then
Nenue@66 166 UpdateAll()
Nenue@66 167
Nenue@65 168 end
Nenue@65 169
Nenue@64 170 end
Nenue@66 171
Nenue@64 172 plugin:SetScript('OnEvent', plugin.event)
Nenue@65 173 plugin:RegisterEvent('PLAYER_EQUIPMENT_CHANGED')
Nenue@66 174 plugin:RegisterEvent('PLAYER_ENTERING_WORLD')
Nenue@64 175
Nenue@66 176
Nenue@64 177 hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
Nenue@64 178
Nenue@64 179 hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot)
Nenue@64 180 if self:GetOwner() == plugin then
Nenue@64 181 if unit == 'player' and vnslot[slot] then
Nenue@65 182
Nenue@66 183 local text
Nenue@66 184 for i = 1, 3 do
Nenue@66 185 text = _G['GameTooltipTextLeft'..i]:GetText()
Nenue@66 186 text = text:match('Item Level (%d+)')
Nenue@66 187 if text then
Nenue@66 188 break
Nenue@66 189 end
Nenue@65 190 end
Nenue@65 191 vnslot[slot].label:SetText(text or '???')
Nenue@64 192 end
Nenue@64 193 end
Nenue@64 194 end)
Nenue@64 195