Mercurial > wow > buffalo2
comparison Modules/WorldState.lua @ 84:16b300d96724
rewritten using mixin attributes
author | Nenue |
---|---|
date | Tue, 18 Oct 2016 13:07:21 -0400 |
parents | Modules/OrderHall.lua@4ec4fd89fced |
children | 1196b8175674 |
comparison
equal
deleted
inserted
replaced
83:4ec4fd89fced | 84:16b300d96724 |
---|---|
1 -- Veneer | |
2 -- WorldState.lua | |
3 -- Created: 10/7/2016 10:55 PM | |
4 -- %file-revision% | |
5 -- | |
6 | |
7 VeneerWorldStateCurrencyMixin = {} | |
8 VeneerWorldStateProgressMixin = { | |
9 keepOpen = true | |
10 } | |
11 VeneerWorldStateMixin = { | |
12 maxHeight = 0, | |
13 detectedFrames = {} | |
14 } | |
15 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | |
16 | |
17 function VeneerWorldStateMixin:Setup() | |
18 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') | |
19 print('|cFFFFFF00'..self:GetName()..'|r:Setup()') | |
20 | |
21 self.modules = self.modules or {self:GetChildren()} | |
22 for i, frame in ipairs(self.modules) do | |
23 print('--'.. frame:GetName()..' exists') | |
24 if frame.Setup then | |
25 print('--'.. frame:GetName()..':Setup()') | |
26 frame:Setup() | |
27 end | |
28 | |
29 frame:SetScript('OnSizeChanged', function() | |
30 local h = frame:GetHeight() | |
31 if h > self.maxHeight then | |
32 self.maxHeight = h | |
33 self:SetHeight(h) | |
34 print('updating max height:', h) | |
35 elseif h < self.maxHeight then | |
36 self:UpdateSize() | |
37 end | |
38 end) | |
39 frame:SetScript('OnHide', function() | |
40 print('|cFF0088FF'..frame:GetName()..':OnHide()') | |
41 self:UpdateSize() | |
42 end) | |
43 frame:SetScript('OnShow', function() | |
44 frame.timeLived = 0 | |
45 print('|cFF0088FF'..frame:GetName()..':OnShow()') | |
46 self:UpdateSize() | |
47 end) | |
48 | |
49 function frame.ShowPanel(frame) | |
50 frame:SetShown(true) | |
51 self:Show() | |
52 end | |
53 function frame.HidePanel(frame) | |
54 frame:SetShown(false) | |
55 self:UpdateSize() | |
56 end | |
57 end | |
58 self:SetOrderHallUIMods() | |
59 self:UnregisterEvent('PLAYER_LOGIN') | |
60 end | |
61 | |
62 function VeneerWorldStateMixin:SetOrderHallUIMods() | |
63 if OrderHallCommandBar then | |
64 if not self.detectedFrames[OrderHallCommandBar] then | |
65 self.detectedFrames[OrderHallCommandBar] = true | |
66 hooksecurefunc(OrderHallCommandBar,'Show', function() | |
67 self:SetOrderHallUIMods() | |
68 end) | |
69 hooksecurefunc(OrderHallCommandBar,'Hide', function() | |
70 self:SetOrderHallUIMods() | |
71 self:UpdateSize() | |
72 end) | |
73 end | |
74 | |
75 | |
76 OrderHallCommandBar:ClearAllPoints() | |
77 OrderHallCommandBar:SetPoint('TOP') | |
78 OrderHallCommandBar:SetWidth(600) | |
79 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | |
80 OrderHallCommandBar.WorldMapButton:Hide() | |
81 OrderHallCommandBar:EnableMouse(false) | |
82 | |
83 if OrderHallCommandBar:IsVisible() then | |
84 self:SetPoint('TOP', OrderHallCommandBar, 'BOTTOM') | |
85 print('anchoring to CommandBar') | |
86 else | |
87 self:SetPoint('TOP', UIParent, 'TOP') | |
88 print('anchoring to UIParent') | |
89 end | |
90 | |
91 self:UnregisterEvent('ADDON_LOADED') | |
92 else | |
93 self:SetPoint('TOP', UIParent, 'TOP') | |
94 print('anchoring to UIParent') | |
95 end | |
96 end | |
97 | |
98 | |
99 function VeneerWorldStateMixin:OnLoad () | |
100 print('|cFFFFFF00'..self:GetName()..'|r!') | |
101 self:RegisterEvent('PLAYER_LOGIN') | |
102 self:RegisterEvent('ADDON_LOADED') | |
103 self:RegisterEvent('ARTIFACT_UPDATE') | |
104 self:RegisterEvent('ARTIFACT_XP_UPDATE') | |
105 self:RegisterEvent('PLAYER_ENTERING_WORLD') | |
106 self:RegisterEvent('PLAYER_REGEN_ENABLED') | |
107 self:RegisterEvent('PLAYER_REGEN_DISABLED') | |
108 end | |
109 | |
110 function VeneerWorldStateMixin:OnEvent(event, arg) | |
111 print(event, arg) | |
112 | |
113 if event == 'PLAYER_LOGIN' then | |
114 if IsLoggedIn() and not self.initialized then | |
115 self.initialized = true | |
116 self:Setup() | |
117 end | |
118 elseif event == 'ADDON_LOADED' then | |
119 if self.initialized and IsAddOnLoaded('Blizzard_OrderHallUI') then | |
120 self:SetOrderHallUIMods() | |
121 end | |
122 elseif event == 'PLAYER_ENTERING_WORLD' then | |
123 self:Update() | |
124 elseif event == 'PLAYER_REGEN_ENABLED' then | |
125 self:SetShown(true) | |
126 elseif event == 'PLAYER_REGEN_DISABLED' then | |
127 self:SetShown(false) | |
128 end | |
129 end | |
130 | |
131 function VeneerWorldStateMixin:Update() | |
132 self.modules = {self:GetChildren()} | |
133 print('|cFFFFFF00All:Update()|r') | |
134 print(self:GetChildren()) | |
135 for i, frame in ipairs(self.modules) do | |
136 if frame.Update then | |
137 print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') | |
138 frame:Update() | |
139 end | |
140 end | |
141 self:SetOrderHallUIMods() | |
142 end | |
143 | |
144 function VeneerWorldStateMixin:UpdateSize() | |
145 print('|cFFFFFF00All:UpdateSize()|r') | |
146 print(self:GetChildren()) | |
147 self.modules = {self:GetChildren()} | |
148 self.maxHeight = 0 | |
149 for i, frame in ipairs(self.modules) do | |
150 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) | |
151 if frame:IsShown() then | |
152 self.maxHeight = max(self.maxHeight, frame:GetHeight()) | |
153 end | |
154 end | |
155 if self.maxHeight == 0 then | |
156 print ('height zero') | |
157 self:Hide() | |
158 else | |
159 self:Show() | |
160 print ('height update:', self.maxHeight) | |
161 self:SetHeight(self.maxHeight) | |
162 end | |
163 | |
164 end | |
165 | |
166 | |
167 | |
168 function VeneerWorldStateMixin:OnMouseDown() | |
169 end | |
170 | |
171 function VeneerWorldStateCurrencyMixin:OnLoad () | |
172 | |
173 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | |
174 self:RegisterEvent("ZONE_CHANGED"); | |
175 self:RegisterEvent("ZONE_CHANGED_INDOORS"); | |
176 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); | |
177 self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') | |
178 self:RegisterEvent('CHAT_MSG_CURRENCY') | |
179 | |
180 end | |
181 | |
182 function VeneerWorldStateCurrencyMixin:OnEvent (event, arg) | |
183 self:Update() | |
184 end | |
185 | |
186 | |
187 function VeneerWorldStateCurrencyMixin:Update() | |
188 | |
189 print(' Zone:', GetZoneText()) | |
190 if GetZoneText() == 'Suramar' then | |
191 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(1155) | |
192 | |
193 self.Icon:SetTexture(texture) | |
194 self.Label:SetFormattedText("%d / %d", earned, totalMax) | |
195 self:Show() | |
196 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) | |
197 self:SetSize(200,16) | |
198 else | |
199 self:Hide() | |
200 end | |
201 | |
202 | |
203 end | |
204 | |
205 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) | |
206 if self.keepOpen then | |
207 return | |
208 end | |
209 | |
210 self.timeLived = (self.timeLived or 0) + sinceLast | |
211 if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then | |
212 if not self.timeOut then | |
213 self.timeOut = true | |
214 self.TimedFadeOut:Play() | |
215 end | |
216 end | |
217 end | |
218 | |
219 | |
220 function VeneerWorldStateProgressMixin:OnLoad() | |
221 self:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') | |
222 | |
223 self:RegisterEvent("PLAYER_XP_UPDATE"); | |
224 self:RegisterEvent("UPDATE_EXHAUSTION"); | |
225 self:RegisterEvent("PLAYER_LEVEL_UP"); | |
226 self:RegisterEvent("PLAYER_UPDATE_RESTING"); | |
227 | |
228 self:RegisterEvent("ARTIFACT_UPDATE"); | |
229 self:RegisterEvent("ARTIFACT_XP_UPDATE"); | |
230 self:RegisterEvent("ARTIFACT_CLOSE"); | |
231 self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE"); | |
232 | |
233 self.progressPercent = 0 | |
234 self.progressAmount = 0 | |
235 self.progressMax = 1 | |
236 self.progressOverflow = 0 | |
237 | |
238 end | |
239 | |
240 function VeneerWorldStateProgressMixin:Setup() | |
241 self:UpdateXPGain() | |
242 | |
243 if self.canGainXP then | |
244 self.mode = 'xp' | |
245 else | |
246 self.mode = 'artifact' | |
247 end | |
248 print('setup mode:', self.mode) | |
249 end | |
250 | |
251 function VeneerWorldStateProgressMixin:OnEvent(event, ...) | |
252 local lastMode = self.mode | |
253 if event == 'PLAYER_LEVEL_UP' or event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then | |
254 self:UpdateXPGain() | |
255 elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then | |
256 self.mode = 'artifact' | |
257 | |
258 elseif event == 'PLAYER_EQUIPMENT_CHANGED' then | |
259 local slot, hasEquip = ... | |
260 if slot == 16 then | |
261 self.mode = 'artifact' | |
262 lastMode = nil | |
263 end | |
264 elseif event == 'PLAYER_XP_UPDATE' or event == 'PLAYER_LEVEL_UP' then | |
265 print('forcing to XP mode') | |
266 self.mode = 'xp' | |
267 end | |
268 self.modeChanged = (lastMode ~= self.mode) | |
269 if self.modeChanged and self:IsVisible() then | |
270 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()', event, ...) | |
271 self:AnimateMode() | |
272 else | |
273 print('|cFFFFFF00'..self:GetName()..':Update()', event, ...) | |
274 self:Update() | |
275 end | |
276 end | |
277 function VeneerWorldStateProgressMixin:UpdateXPGain() | |
278 self.canGainXP = (UnitLevel('player') < GetMaxPlayerLevel()) and (not IsXPUserDisabled()) | |
279 if not self.canGainXP then | |
280 self.ProgressBar:SetColorTexture(0.75,0.75,0.75) | |
281 end | |
282 end | |
283 | |
284 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | |
285 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | |
286 function VeneerWorldStateProgressMixin:Update() | |
287 local hasNewInfo = false | |
288 local progressChange = false | |
289 print(' current mode:', self.mode) | |
290 | |
291 | |
292 if self.mode == 'xp' then | |
293 local xp = UnitXP('player') | |
294 local xpMax = UnitXPMax('player') | |
295 local bonusXP = GetXPExhaustion() | |
296 if xp then | |
297 self.progressPercent = xp / xpMax | |
298 end | |
299 | |
300 self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax | |
301 | |
302 if bonusXP then | |
303 self.ProgressBar:SetColorTexture(0, 0.5,1) | |
304 self.OverflowBar:Show() | |
305 self.OverflowBar:ClearAllPoints() | |
306 self.OverflowBar:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', 0, 0) | |
307 | |
308 else | |
309 self.ProgressBar:SetColorTexture(0.5,0,1) | |
310 end | |
311 hasNewInfo = (self.progressAmount ~= xp) | |
312 | |
313 progressChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) | |
314 | |
315 self.progressOverFlow = bonusXP | |
316 self.progressAmount = xp | |
317 self.progressMax = xpMax | |
318 elseif self.mode == 'artifact' then | |
319 | |
320 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() | |
321 print(' C_AUI:', itemID, altItemID, name, icon, totalXP, pointsSpent) | |
322 | |
323 if itemID then | |
324 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 | |
325 hasNewInfo = (self.progressAmount ~= totalXP) | |
326 progressChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) | |
327 | |
328 if totalXP > nextRankCost then | |
329 self.progressPercent = 1 | |
330 self.progressPercent = totalXP / nextRankCost | |
331 end | |
332 | |
333 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | |
334 | |
335 self.ProgressBar:SetColorTexture(1,0.5,0,1) | |
336 self.OverflowBar:Hide() | |
337 | |
338 self.progressOverFlow = 0 | |
339 self.progressAmount = totalXP | |
340 self.progressMax = nextRankCost | |
341 else | |
342 self.progressAmount = 0 | |
343 self.progressMax = 1 | |
344 self.progressText = '' | |
345 end | |
346 end | |
347 | |
348 if self.mode then | |
349 self:SetSize(600,16) | |
350 if hasNewInfo then | |
351 self.timeOut = nil | |
352 self.timeLived = 0 | |
353 if self.TransitionFadeOut:IsPlaying() then | |
354 self.TransitionFadeOut:Stop() | |
355 self:SetAlpha(1) | |
356 end | |
357 if not self:IsVisible() then | |
358 self.TransitionFadeIn:Play() | |
359 else | |
360 self:ShowPanel() | |
361 end | |
362 | |
363 end | |
364 | |
365 --print(self.ProgressBG:GetWidth()) | |
366 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) | |
367 | |
368 | |
369 if progressChange then | |
370 print(' Render change:', progressChange) | |
371 self.ProgressAdded:Show() | |
372 self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (self:GetWidth() * progressChange), 0) | |
373 self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) | |
374 self.ProgressFlash:Play() | |
375 end | |
376 | |
377 | |
378 if self.progressPercent > 0 then | |
379 self.ProgressBar:Show() | |
380 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) | |
381 self.Label:SetText(self.progressText) | |
382 | |
383 self.progressLeft = self.progressMax - self.progressAmount | |
384 if self.progressOverflow >= self.progressLeft then | |
385 | |
386 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', (self.progressOverflow / self.progressMax) * self:GetWidth(), 0) | |
387 else | |
388 self.OverflowBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPRIGHT', 0, 0) | |
389 end | |
390 | |
391 else | |
392 self.ProgressBar:Hide() | |
393 end | |
394 else | |
395 --self:HidePanel() | |
396 end | |
397 | |
398 self.modeChanged = nil | |
399 end | |
400 | |
401 function VeneerWorldStateProgressMixin:OnMouseDown(button) | |
402 if button == 'RightButton' then | |
403 if self.keepOpen then | |
404 self.keepOpen = nil | |
405 else | |
406 self.keepOpen = true | |
407 end | |
408 print('keepOpen =', self.keepOpen) | |
409 else | |
410 if self.mode == 'xp' then | |
411 self.mode = 'artifact' | |
412 else | |
413 self.mode = 'xp' | |
414 end | |
415 self:AnimateMode() | |
416 end | |
417 | |
418 end | |
419 | |
420 function VeneerWorldStateProgressMixin:AnimateMode() | |
421 | |
422 self.TransitionFadeIn:Stop() | |
423 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()') | |
424 self.modeChanged = true | |
425 self.TransitionFadeOut:Play() | |
426 end |