comparison Modules/PaperDoll.lua @ 64:ba9c13261bb2

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