comparison Modules/Currency.lua @ 115:8c94bee4fdfc

- AddHandler simplified - Centralized combat start/stop hooks - WorldState removed
author Nenue
date Tue, 28 Mar 2017 07:02:26 -0400
parents 6748c98a6c6c
children ddfe19d70a34
comparison
equal deleted inserted replaced
114:6748c98a6c6c 115:8c94bee4fdfc
5 -- Time: 7:07 PM 5 -- Time: 7:07 PM
6 -- To change this template use File | Settings | File Templates. 6 -- To change this template use File | Settings | File Templates.
7 -- 7 --
8 8
9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop 9 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
10 local profileUpdate, needsUpdate
10 11
11 local zoneEvents = { 12 local zoneEvents = {
12 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED" 13 "ZONE_CHANGED_NEW_AREA", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED"
13 } 14 }
14 local currencyEvents = { 15 local currencyEvents = {
29 }, 30 },
30 ["Blood of Sargeras"] = { 31 ["Blood of Sargeras"] = {
31 itemID = 124124, 32 itemID = 124124,
32 } 33 }
33 } 34 }
34 local items = {} 35 local items, currencies = {}, {}
35 36
36 37
37 VeneerWorldStateCurrencyMixin = { Blocks = {} } 38 VeneerCurrencyMixin = {
38 VeneerWorldStateCurrencyBlockMixin = {} 39 Blocks = {},
39 local module = VeneerWorldStateCurrencyMixin 40 HideCombat = true,
40 local block = VeneerWorldStateCurrencyBlockMixin 41 EventList = {'PLAYER_ENTERING_WORLD'},
42 moduleName = 'Currency Watch',
43 anchorPoint = 'TOP',
44 }
45 VeneerCurrencyBlockMixin = {}
46 local module = VeneerCurrencyMixin
47 local block = VeneerCurrencyBlockMixin
41 48
42 49
43 50
44 local function RegisterEvents (frame, events) 51 local function RegisterEvents (frame, events)
45 for _, event in ipairs(events) do 52 for _, event in ipairs(events) do
47 frame:RegisterEvent(event) 54 frame:RegisterEvent(event)
48 end 55 end
49 end 56 end
50 57
51 function module:OnLoad () 58 function module:OnLoad ()
52 self:RegisterEvent("PLAYER_ENTERING_WORLD"); 59 Veneer:AddHandler(self)
53 self:RegisterEvent('PLAYER_REGEN_ENABLED')
54 self:RegisterEvent('PLAYER_REGEN_DISABLED')
55 60
56 for name, info in pairs(blocks) do 61 for name, info in pairs(blocks) do
57 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') 62 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate')
58 frame.name = name 63 frame.name = name
59 for k,v in pairs(info) do 64 for k,v in pairs(info) do
136 for j = 1, numSlots do 141 for j = 1, numSlots do
137 local itemID = GetContainerItemID(i, j) 142 local itemID = GetContainerItemID(i, j)
138 local texture, count = GetContainerItemInfo(i,j) 143 local texture, count = GetContainerItemInfo(i,j)
139 if items[itemID] then 144 if items[itemID] then
140 items[itemID].count = items[itemID].count + (count or 1) 145 items[itemID].count = items[itemID].count + (count or 1)
141 items[itemID].texture = texture 146 if not items[itemID].texture then
142 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t') 147 items[itemID].texture = texture
143 items[itemID].frame.Icon:SetTexture(texture) 148 print('tracked currency tally', items[itemID].count, '|T'..texture..':16:16|t')
144 end 149 items[itemID].frame.Icon:SetTexture(texture)
145 end 150 end
146 end 151 end
147 152 end
148 for itemID, info in pairs(items) do 153 end
149 end 154
155
150 156
151 local lastBlock 157 local lastBlock
152 local totalWidth = 0 158 local totalWidth = 0
153 for _, block in ipairs(self.Blocks) do 159 for _, block in ipairs(self.Blocks) do
154 local blockIsShown = block:Update() or false 160 local blockIsShown = block:Update() or false
168 block:SetHeight(24) 174 block:SetHeight(24)
169 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4) 175 block:SetWidth(block.Icon:GetWidth() + block.Label:GetWidth()+4)
170 totalWidth = totalWidth + block:GetWidth() 176 totalWidth = totalWidth + block:GetWidth()
171 end 177 end
172 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize()) 178 print(block:IsShown(), '|cFF0088FF'..block.name..'|r', block:GetSize())
173 179 end
174 end 180
175 181 self:UpdateProfile()
176 self:SetWidth(totalWidth) 182 self:SetWidth(totalWidth)
177 183
178 self.needsUpdate = nil 184 needsUpdate = nil
179 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize()) 185 print(self:IsShown(), '|cFF00FF88'..self:GetName()..'|r', self:GetSize())
180 self:SetShown(canShow) 186 self:SetShown(canShow)
181 VeneerWorldState:Reanchor(true) 187 Veneer:DynamicReanchor()
188 end
189
190 function module:UpdateProfile()
191 if not self.profile then
192 profileUpdate = true
193 return
194 end
195
196 for itemID, info in pairs(items) do
197 self.profile.Items = self.profile.Items or {}
198 self.profile.Items[itemID] = info
199 end
182 end 200 end
183 201
184 function module:OnUpdate() 202 function module:OnUpdate()
185 if self.needsUpdate then 203 if needsUpdate then
186 self:Update() 204 self:Update()
187 end 205 elseif profileUpdate then
206 self:UpdateProfile()
207 end
208
188 end 209 end
189 210
190 function block:OnEnter() 211 function block:OnEnter()
191 if not InCombatLockdown() then 212 if not InCombatLockdown() then
192 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT"); 213 GameTooltip:SetOwner(self, "ANCHOR_BOTTOMRIGHT");