annotate Modules/PaperDoll.lua @ 64:ba9c13261bb2

- parametrize buff button customizations
author Nenue
date Wed, 17 Aug 2016 15:26:54 -0400
parents ef4116179e2f
children 4fe16cb3f5d6
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@62 5 --
Nenue@62 6
Nenue@62 7 local plugin = CreateFrame('Frame', 'VeneerPaper', UIParent)
Nenue@62 8 local vn, print = LibStub("LibKraken").register(VeneerController, plugin)
Nenue@62 9
Nenue@64 10 local slot_anchors = {
Nenue@64 11 [1] = 'TOPLEFT',
Nenue@64 12 [2] = 'TOPLEFT',
Nenue@64 13 [3] = 'TOPLEFT',
Nenue@64 14 [15] = 'TOPLEFT',
Nenue@64 15 [5] = 'TOPLEFT',
Nenue@64 16 [9] = 'TOPLEFT',
Nenue@62 17
Nenue@64 18 [10] = 'TOPRIGHT',
Nenue@64 19 [6] = 'TOPRIGHT',
Nenue@64 20 [7] = 'TOPRIGHT',
Nenue@64 21 [8] = 'TOPRIGHT',
Nenue@64 22 [11] = 'TOPRIGHT',
Nenue@64 23 [12] = 'TOPRIGHT',
Nenue@64 24 [13] = 'TOPRIGHT',
Nenue@64 25 [14] = 'TOPRIGHT',
Nenue@64 26
Nenue@64 27 [16] = 'BOTTOMRIGHT',
Nenue@64 28 [17] = 'BOTTOMLEFT',
Nenue@64 29 }
Nenue@64 30
Nenue@64 31 local slot_relative = {
Nenue@64 32 [1] = 'TOPRIGHT',
Nenue@64 33 [2] = 'TOPRIGHT',
Nenue@64 34 [3] = 'TOPRIGHT',
Nenue@64 35 [15] = 'TOPRIGHT',
Nenue@64 36 [5] = 'TOPRIGHT',
Nenue@64 37 [9] = 'TOPRIGHT',
Nenue@64 38
Nenue@64 39 [10] = 'TOPLEFT',
Nenue@64 40 [6] = 'TOPLEFT',
Nenue@64 41 [7] = 'TOPLEFT',
Nenue@64 42 [8] = 'TOPLEFT',
Nenue@64 43 [11] = 'TOPLEFT',
Nenue@64 44 [12] = 'TOPLEFT',
Nenue@64 45 [13] = 'TOPLEFT',
Nenue@64 46 [14] = 'TOPLEFT',
Nenue@64 47
Nenue@64 48 [16] = 'TOPRIGHT',
Nenue@64 49 [17] = 'TOPLEFT',
Nenue@64 50 }
Nenue@64 51 local ticker
Nenue@64 52 local vnslot = {}
Nenue@64 53 local pendingSlots = {}
Nenue@64 54
Nenue@64 55 local UpdateVeneer = function(itemslot, frame)
Nenue@64 56 local slot = itemslot:GetID()
Nenue@64 57 if itemslot.hasItem then
Nenue@62 58 frame.link = GetInventoryItemLink('player', slot)
Nenue@64 59 --print(frame.link)
Nenue@64 60 local name, link, something, ilevel = GetItemInfo(frame.link)
Nenue@64 61 frame.label:SetText(ilevel)
Nenue@62 62 -- todo: test GetExtendedItemInfo()
Nenue@62 63
Nenue@64 64 local lastOwner = GameTooltip:GetOwner()
Nenue@64 65 print(lastOwner)
Nenue@64 66
Nenue@64 67 GameTooltip:SetOwner(plugin)
Nenue@64 68 GameTooltip:SetInventoryItem('player', slot)
Nenue@64 69
Nenue@62 70 for i = 1, 3 do
Nenue@62 71 local gname = 'gem'..i
Nenue@62 72 if frame[gname] then
Nenue@62 73 frame.gemslot[i] = frame.gemslot[i] or frame:CreateTexture(nil, 'ARTWORK')
Nenue@62 74 print(frame[gname])
Nenue@62 75 end
Nenue@62 76 end
Nenue@62 77 frame:Show()
Nenue@62 78 else
Nenue@62 79 frame:Hide()
Nenue@62 80 end
Nenue@62 81 end
Nenue@62 82
Nenue@64 83 local UpdateAll = function()
Nenue@64 84 for index, frame in pairs(vnslot) do
Nenue@64 85 if frame:IsVisible() then
Nenue@64 86 print('forcing', index, frame:GetName())
Nenue@64 87 tinsert(pendingSlots, frame)
Nenue@64 88 end
Nenue@64 89 end
Nenue@64 90 plugin.ticker()
Nenue@62 91 end
Nenue@62 92
Nenue@64 93 local UpdateNext = function()
Nenue@64 94
Nenue@64 95 local frame = tremove(pendingSlots)
Nenue@64 96 if frame and frame:IsVisible() then
Nenue@64 97 print('updating', frame:GetName())
Nenue@64 98 UpdateVeneer(frame:GetParent(), frame)
Nenue@64 99 else
Nenue@64 100 ticker:Cancel()
Nenue@64 101 ticker = nil
Nenue@64 102 end
Nenue@64 103
Nenue@64 104 end
Nenue@64 105
Nenue@64 106 -- PaperDollFrame is separate from InspectUI handlers
Nenue@64 107 local PaperDollItemSlotButton_Update = function(self)
Nenue@64 108 local name = self:GetName()
Nenue@64 109 local slot = self:GetID()
Nenue@64 110 if not slot_anchors[slot] then
Nenue@64 111 return
Nenue@64 112 end
Nenue@64 113
Nenue@64 114
Nenue@64 115 local frame = _G[name .. 'Veneer']
Nenue@64 116
Nenue@64 117 if not frame then
Nenue@64 118
Nenue@64 119 frame = CreateFrame('Frame', name..'Veneer', self)
Nenue@64 120 vnslot[slot] = frame
Nenue@64 121
Nenue@64 122 frame.label = frame:CreateFontString(nil, 'OVERLAY', 'VeneerNumberFont')
Nenue@64 123 frame.gemslot = {}
Nenue@64 124
Nenue@64 125 local anchor, relative, x, y = slot_anchors[slot], slot_relative[slot], 8, -4
Nenue@64 126 if anchor:match('RIGHT') then
Nenue@64 127 x = -x
Nenue@64 128 end
Nenue@64 129 if anchor:match('BOTTOM') then
Nenue@64 130 y = 4
Nenue@64 131 end
Nenue@64 132
Nenue@64 133
Nenue@64 134 frame:SetPoint(anchor, self, relative, x, y)
Nenue@64 135 frame:SetSize(200,24)
Nenue@64 136 frame.label:ClearAllPoints()
Nenue@64 137 frame.label:SetPoint(slot_anchors[slot], frame, slot_anchors[slot])
Nenue@64 138
Nenue@64 139 tinsert(pendingSlots, frame)
Nenue@64 140 end
Nenue@64 141 end
Nenue@64 142
Nenue@64 143
Nenue@64 144 plugin.ticker = function()
Nenue@64 145 if (not ticker) and #pendingSlots >= 1 then
Nenue@64 146 ticker = C_Timer.NewTicker(0, UpdateNext)
Nenue@64 147 end
Nenue@64 148 end
Nenue@64 149
Nenue@64 150
Nenue@64 151 plugin.event = function(self, event, flag, slot)
Nenue@64 152 print(self, event, flag, slot)
Nenue@64 153
Nenue@64 154
Nenue@64 155 plugin.ticker()
Nenue@64 156 end
Nenue@64 157 plugin:SetScript('OnEvent', plugin.event)
Nenue@64 158 plugin:RegisterUnitEvent('UNIT_INVENTORY_CHANGED', 'player')
Nenue@64 159
Nenue@64 160 hooksecurefunc("ToggleCharacter", UpdateAll)
Nenue@64 161 hooksecurefunc("PaperDollItemSlotButton_Update", PaperDollItemSlotButton_Update)
Nenue@64 162
Nenue@64 163 hooksecurefunc(GameTooltip, "SetInventoryItem", function(self, unit, slot)
Nenue@64 164 if self:GetOwner() == plugin then
Nenue@64 165 if unit == 'player' and vnslot[slot] then
Nenue@64 166 vnslot[slot].label:SetText(GameTooltipTextLeft3:GetText():match('%d+'))
Nenue@64 167 end
Nenue@64 168 end
Nenue@64 169 end)
Nenue@64 170