Mercurial > wow > buffalo2
comparison Modules/Currency.lua @ 125:3f4794dca91b
template load order and Script handlers linkage
author | Nenue |
---|---|
date | Sun, 15 Oct 2017 16:47:22 -0400 |
parents | b3c0258b419d |
children | 3de635cda288 |
comparison
equal
deleted
inserted
replaced
124:07fe8fae8ca8 | 125:3f4794dca91b |
---|---|
4 -- Date: 3/25/2017 | 4 -- Date: 3/25/2017 |
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('Currency', ...) end or nop |
10 local profileUpdate, needsUpdate | 10 local profileUpdate, needsUpdate |
11 | 11 |
12 | 12 |
13 local itemBlock = {} | 13 local itemBlock = {} |
14 local currencyBlock = {} | 14 local currencyBlock = {} |
28 ["Ancient Mana"] = { | 28 ["Ancient Mana"] = { |
29 currencyID = 1155, | 29 currencyID = 1155, |
30 showMax = true, | 30 showMax = true, |
31 zones = { | 31 zones = { |
32 ['Suramar'] = true, | 32 ['Suramar'] = true, |
33 ["Sashj'tar Ruins"] = true, | |
34 ["Faronaar Ruins"] = true, | |
35 ["Halls of the Eclipse"] = true, | |
36 ["Shal'aran"] = true, | |
37 ["The Fel Breach"] = true, | |
38 }, | 33 }, |
39 }, | 34 }, |
40 ["Blood of Sargeras"] = { | 35 ["Blood of Sargeras"] = { |
41 itemID = 124124, | 36 itemID = 124124, |
42 }, | 37 }, |
43 ["Legionfall War Supplies"] = { | 38 ["Legionfall War Supplies"] = { |
44 currencyID = 1342, | 39 currencyID = 1342, |
40 zones = { | |
41 ["The Broken Shore"] = true | |
42 } | |
45 }, | 43 }, |
46 ["Nethershard"] = { | 44 ["Nethershard"] = { |
47 currencyID = 1226, | 45 currencyID = 1226, |
46 zones = { | |
47 ["The Broken Shore"] = true | |
48 } | |
48 }, | 49 }, |
49 ["Veiled Argunite"] = { | 50 ["Veiled Argunite"] = { |
50 currencyID = 1508, | 51 currencyID = 1508, |
51 }, | 52 zones = { |
52 ["Argus Waystone"] = { | 53 ["Antoran Wastes"] = true, |
53 currencyID = 1506, | 54 ["Krokuun"] = true, |
54 } | 55 ["MacAree"] = true, |
56 } | |
57 }, | |
55 } | 58 } |
56 local items, currencies = {}, {} | 59 local items, currencies = {}, {} |
57 | 60 |
58 | 61 |
59 VeneerCurrencyMixin = { | 62 VeneerCurrencyMixin = { |
75 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event) | 78 print('|cFFFF0088'..(frame.name or frame:GetName())..'|r', 'listening to', event) |
76 frame:RegisterEvent(event) | 79 frame:RegisterEvent(event) |
77 end | 80 end |
78 end | 81 end |
79 | 82 |
83 function module:Setup() | |
84 self:Update() | |
85 end | |
86 | |
80 function module:OnLoad () | 87 function module:OnLoad () |
81 Veneer:AddHandler(self) | 88 Veneer:AddHandler(self) |
82 | 89 |
83 for name, info in pairs(blocks) do | 90 for name, info in pairs(blocks) do |
84 local frame = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') | 91 local block = CreateFrame('Frame', nil, self, 'VeneerCurrencyTemplate') |
85 frame.name = name | 92 block.name = name |
86 for k,v in pairs(info) do | 93 for k,v in pairs(info) do |
87 print(name, k, '=', v) | 94 print(name, k, '=', v) |
88 frame[k] = v | 95 block[k] = v |
89 end | 96 end |
90 | 97 |
91 frame.debug = function(...) | 98 block.debug = function(...) |
92 print('|cFF0088FF<'..frame.name..'>|r', ...) | 99 print('|cFF0088FF<'..block.name..'>|r', ...) |
93 end | 100 end |
94 frame.id = info.itemID or info.currencyID | 101 block.id = info.itemID or info.currencyID |
95 | 102 |
96 | 103 |
97 if info.itemID then | 104 if info.itemID then |
98 local itemID = info.itemID | 105 local itemID = info.itemID |
99 items[itemID] = { | 106 items[itemID] = { |
100 count = 0, | 107 count = 0, |
101 frame = frame | 108 frame = block |
102 } | 109 } |
103 frame.Update = itemBlock.Update | 110 block.Update = itemBlock.Update |
104 RegisterEvents(self, itemEvents) | 111 RegisterEvents(self, itemEvents) |
105 elseif info.currencyID then | 112 elseif info.currencyID then |
106 local currencyID = info.currencyID | 113 local currencyID = info.currencyID |
107 frame.Update = currencyBlock.Update | 114 block.Update = currencyBlock.Update |
108 RegisterEvents(frame, currencyEvents) | 115 RegisterEvents(block, currencyEvents) |
109 end | 116 end |
110 | 117 |
111 | 118 |
112 | 119 |
113 if info.zones then | 120 if info.zones then |
114 RegisterEvents(frame, zoneEvents) | 121 RegisterEvents(block, zoneEvents) |
115 local zones = info.zones | 122 local zones = info.zones |
116 local of = frame.Update | 123 local of = block.Update |
117 frame.Update = function(block) | 124 function block:Update(zone, subZone) |
118 frame.debug('Update [Zone]') | 125 block.debug('Update [Zone]', zone, subZone) |
119 local zone = self.zoneText | 126 local canShow = ((zone and self.zones[zone]) or (subZone and self.zones[subZone])) and true or false |
120 local canShow = (zone and block.zones[zone]) and true or false | |
121 if of then | 127 if of then |
122 canShow = canShow and of(frame) | 128 canShow = canShow and of(self) |
123 end | 129 end |
124 return canShow | 130 return canShow |
125 end | 131 end |
126 end | 132 end |
127 end | 133 end |
142 | 148 |
143 | 149 |
144 for itemID in pairs(items) do | 150 for itemID in pairs(items) do |
145 items[itemID].count = 0 | 151 items[itemID].count = 0 |
146 end | 152 end |
147 self.zoneText = GetRealZoneText() | 153 self.realZoneText = GetRealZoneText() |
154 self.subZoneText = GetSubZoneText() | |
148 local canShow = false | 155 local canShow = false |
149 | 156 |
150 for i = 0, NUM_BAG_SLOTS do | 157 for i = 0, NUM_BAG_SLOTS do |
151 local numSlots = GetContainerNumSlots(i) | 158 local numSlots = GetContainerNumSlots(i) |
152 for j = 1, numSlots do | 159 for j = 1, numSlots do |
166 | 173 |
167 | 174 |
168 local lastBlock | 175 local lastBlock |
169 local totalWidth = 0 | 176 local totalWidth = 0 |
170 for _, block in ipairs(self.Blocks) do | 177 for _, block in ipairs(self.Blocks) do |
171 local blockIsShown = block:Update() or false | 178 local blockIsShown = block:Update(self.realZoneText, self.subZoneText) or false |
172 block:SetShown(blockIsShown) | 179 block:SetShown(blockIsShown) |
173 canShow = canShow or blockIsShown | 180 canShow = canShow or blockIsShown |
174 | 181 |
175 | 182 |
176 if block:IsShown() then | 183 if blockIsShown then |
177 block:ClearAllPoints() | 184 block:ClearAllPoints() |
178 if lastBlock then | 185 if lastBlock then |
179 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT') | 186 block:SetPoint('TOPLEFT', lastBlock, 'TOPRIGHT') |
180 else | 187 else |
181 block:SetPoint('TOPLEFT', self, 'TOPLEFT') | 188 block:SetPoint('TOPLEFT', self, 'TOPLEFT') |
210 end | 217 end |
211 end | 218 end |
212 | 219 |
213 function module:OnUpdate() | 220 function module:OnUpdate() |
214 if needsUpdate then | 221 if needsUpdate then |
215 self:Update() | 222 self:Update(GetRealZoneText(), GetSubZoneText()) |
216 elseif profileUpdate then | 223 elseif profileUpdate then |
217 self:UpdateProfile() | 224 self:UpdateProfile() |
218 end | 225 end |
219 | 226 |
220 end | 227 end |
236 end | 243 end |
237 end | 244 end |
238 | 245 |
239 function block:OnEvent(event, ...) | 246 function block:OnEvent(event, ...) |
240 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) | 247 print('|cFF0088FF<'..self.name..'>|r', 'OnEvent', event, ...) |
241 self:Update() | 248 |
249 self:Update(GetRealZoneText(), GetSubZoneText()) | |
242 end | 250 end |
243 | 251 |
244 function block:Setup() | 252 function block:Setup() |
245 | 253 |
246 end | 254 end |
247 function itemBlock:Update() | 255 function itemBlock:Update(zone, subZone) |
248 self.debug('Update [Item]') | 256 self.debug('Update [Item]', zone, subZone) |
249 if items[self.itemID].count >= 1 then | 257 if items[self.itemID].count >= 1 then |
250 self.Icon:SetTexture(GetItemIcon(self.id)) | 258 self.Icon:SetTexture(GetItemIcon(self.id)) |
251 self.Label:SetFormattedText("%d", items[self.id].count) | 259 self.Label:SetFormattedText("%d", items[self.id].count) |
252 return true | 260 return true |
253 end | 261 end |
254 end | 262 return false |
255 | 263 end |
256 function currencyBlock:Update() | 264 |
257 self.debug('Update [Currency]') | 265 function currencyBlock:Update(zone, subZone) |
266 self.debug('Update [Currency]', zone, subZone) | |
258 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id) | 267 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(self.id) |
259 | 268 |
260 self.Icon:SetTexture(texture) | 269 self.Icon:SetTexture(texture) |
261 if self.showMax then | 270 if self.showMax then |
262 self.Label:SetFormattedText("%d / %d", earned, totalMax) | 271 self.Label:SetFormattedText("%d / %d", earned, totalMax) |