Mercurial > wow > buffalo2
comparison Modules/WorldState.lua @ 113:2105b6e5095f
- Added Blood of Sargeras to currency list
- Fixed panel ordering issues when a module is loaded on the fly.
author | Nick@Zahhak |
---|---|
date | Sun, 26 Mar 2017 06:25:18 -0400 |
parents | 7c77fde36287 |
children | 6748c98a6c6c |
comparison
equal
deleted
inserted
replaced
112:7c77fde36287 | 113:2105b6e5095f |
---|---|
1 -- Veneer | 1 -- Veneer |
2 -- WorldState.lua | 2 -- WorldState.lua |
3 -- Created: 10/7/2016 10:55 PM | 3 -- Created: 10/7/2016 10:55 PM |
4 -- %file-revision% | 4 -- %file-revision% |
5 -- | 5 -- An extensible panel group for HUD values |
6 | 6 |
7 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | 7 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop |
8 local WorldStateBlockMixin = {} | 8 local WorldStateBlockMixin = {} |
9 VeneerOrderHallMixin = { | 9 VeneerOrderHallMixin = { |
10 anchorPoint = 'TOP', | 10 anchorPoint = 'TOP', |
11 anchorFrom = 'TOP', | 11 anchorFrom = 'TOP', |
12 anchorPriority = 1, | |
12 anchorX = 0, | 13 anchorX = 0, |
13 anchorY = 0, | 14 anchorY = 0, |
14 addonTrigger = 'Blizzard_OrderHallUI', | 15 addonTrigger = 'Blizzard_OrderHallUI', |
15 addonFrame = 'OrderHallCommandBar', | 16 addonFrame = 'OrderHallCommandBar', |
16 } | 17 } |
17 | 18 |
18 VeneerWorldStateHeadsUpMixin = { | |
19 } | |
20 | |
21 VeneerWorldStateCurrencyMixin = { | |
22 } | |
23 VeneerWorldStateProgressMixin = { | |
24 keepOpen = true, | |
25 } | |
26 VeneerWorldStateMixin = { | 19 VeneerWorldStateMixin = { |
27 maxHeight = 0, | 20 maxHeight = 0, |
28 detectedFrames = {}, | 21 detectedFrames = {}, |
29 anchorPoint = 'TOP', | 22 anchorPoint = 'TOP', |
23 modules = {} | |
30 } | 24 } |
31 | 25 |
32 function VeneerWorldStateMixin:Reset() | 26 function VeneerWorldStateMixin:Reset() |
33 for i, frame in ipairs(self.modules) do | 27 for i, frame in ipairs(self.modules) do |
34 if frame.Reset then | 28 if frame.Reset then |
40 | 34 |
41 function VeneerWorldStateMixin:Setup() | 35 function VeneerWorldStateMixin:Setup() |
42 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') | 36 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') |
43 print('|cFFFFFF00'..self:GetName()..'|r:Setup()') | 37 print('|cFFFFFF00'..self:GetName()..'|r:Setup()') |
44 | 38 |
45 self.modules = self.modules or {self:GetChildren()} | |
46 for i, frame in ipairs(self.modules) do | 39 for i, frame in ipairs(self.modules) do |
47 print('--'.. frame:GetName()..' exists') | 40 print('--'.. frame:GetName()..' exists') |
48 if frame.Setup then | 41 if frame.Setup then |
49 print('--'.. frame:GetName()..':Setup()') | 42 print('--'.. frame:GetName()..':Setup()') |
50 frame:Setup() | 43 frame:Setup() |
73 self.modules = {self:GetChildren()} | 66 self.modules = {self:GetChildren()} |
74 print('|cFFFFFF00'..self:GetName()..'|r!') | 67 print('|cFFFFFF00'..self:GetName()..'|r!') |
75 self:RegisterEvent('PLAYER_ENTERING_WORLD') | 68 self:RegisterEvent('PLAYER_ENTERING_WORLD') |
76 self:RegisterEvent('PLAYER_REGEN_ENABLED') | 69 self:RegisterEvent('PLAYER_REGEN_ENABLED') |
77 self:RegisterEvent('PLAYER_REGEN_DISABLED') | 70 self:RegisterEvent('PLAYER_REGEN_DISABLED') |
78 Veneer:AddHandler(self, self.anchorPoint, 2) | 71 Veneer:AddHandler(self, self.anchorPoint, self.anchorPriority) |
79 SLASH_VENEERWORLDSTATE1 = "/vws" | 72 SLASH_VENEERWORLDSTATE1 = "/vws" |
80 SLASH_VENEERWORLDSTATE2 = "/worldstate" | 73 SLASH_VENEERWORLDSTATE2 = "/worldstate" |
81 SlashCmdList.VENEERWORLDSTATE = function() | 74 SlashCmdList.VENEERWORLDSTATE = function() |
82 self:Reset() | 75 self:Reset() |
83 end | 76 end |
155 end | 148 end |
156 | 149 |
157 function VeneerOrderHallMixin:Setup() | 150 function VeneerOrderHallMixin:Setup() |
158 print('|cFFFFFF00'..self:GetName()..':Setup()') | 151 print('|cFFFFFF00'..self:GetName()..':Setup()') |
159 self:SetParent(OrderHallCommandBar) | 152 self:SetParent(OrderHallCommandBar) |
160 self:RegisterEvent("ZONE_CHANGED"); | 153 self:RegisterEvent("UNIT_AURA"); |
161 self:RegisterEvent("ZONE_CHANGED_INDOORS"); | 154 self:RegisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED") |
162 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); | 155 self:RegisterEvent("GARRISON_FOLLOWER_ADDED") |
156 self:RegisterEvent("GARRISON_FOLLOWER_REMOVED") | |
157 | |
163 self:SetShown(true) | 158 self:SetShown(true) |
164 end | 159 end |
165 | 160 |
166 function VeneerOrderHallMixin:OnLoad() | 161 function VeneerOrderHallMixin:OnLoad() |
167 Veneer:AddHandler(self, 'TOP', 1) | 162 Veneer:AddHandler(self, 'TOP', 1) |
163 self:EnableMouse(false) | |
168 end | 164 end |
169 | 165 |
170 function VeneerOrderHallMixin:OnEvent(event, ...) | 166 function VeneerOrderHallMixin:OnEvent(event, ...) |
171 | 167 |
172 print('|cFF00AAFF'..self:GetName()..'|r:'.. event, ...) | 168 print('|cFF00AAFF'..self:GetName()..'|r:'.. event, ...) |
187 end | 183 end |
188 Veneer:Reanchor() | 184 Veneer:Reanchor() |
189 end | 185 end |
190 | 186 |
191 function VeneerOrderHallMixin:Update() | 187 function VeneerOrderHallMixin:Update() |
192 | |
193 if not OrderHallCommandBar then | 188 if not OrderHallCommandBar then |
194 print('|cFFFF4400'..self:GetName()..' updater called without target') | 189 print('|cFFFF4400'..self:GetName()..' updater called without target') |
195 return | 190 return |
196 end | 191 end |
197 | 192 |
199 OrderHallCommandBar:SetAllPoints(self) | 194 OrderHallCommandBar:SetAllPoints(self) |
200 | 195 |
201 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | 196 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) |
202 OrderHallCommandBar.WorldMapButton:Hide() | 197 OrderHallCommandBar.WorldMapButton:Hide() |
203 OrderHallCommandBar:EnableMouse(false) | 198 OrderHallCommandBar:EnableMouse(false) |
204 self:SetSize(700, 24) | 199 self:SetSize(700, 22) |
200 | |
201 local troops = OrderHallCommandBar.TroopSummary | |
202 if troops then | |
203 for _, category in ipairs(troops) do | |
204 category.Count:SetFontObject(VeneerNumberFont) | |
205 category.Count:ClearAllPoints() | |
206 category.Count:SetPoint('BOTTOMRIGHT', category.Icon, 'BOTTOMRIGHT', -1, 1) | |
207 end | |
208 end | |
209 | |
205 | 210 |
206 | 211 |
207 print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown()) | 212 print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown()) |
208 print(debugstack(6)) | 213 print(debugstack(6)) |
209 Veneer:DynamicReanchor() | 214 Veneer:DynamicReanchor() |
210 end | 215 end |
211 | 216 |
212 function VeneerWorldStateCurrencyMixin:OnLoad () | 217 |
213 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | |
214 self:RegisterEvent("ZONE_CHANGED"); | |
215 self:RegisterEvent("ZONE_CHANGED_INDOORS"); | |
216 self:RegisterEvent("ZONE_CHANGED_NEW_AREA"); | |
217 self:RegisterEvent('CURRENCY_DISPLAY_UPDATE') | |
218 self:RegisterEvent('CHAT_MSG_CURRENCY') | |
219 end | |
220 | |
221 function VeneerWorldStateCurrencyMixin:OnEvent (event, arg) | |
222 self:Update() | |
223 end | |
224 local zoneCurrency = { | |
225 ['Suramar'] = 1155, | |
226 ["Sashj'tar Ruins"] = 1155, | |
227 ["Faronaar Ruins"] = 1155 | |
228 } | |
229 local zoneBountyInfo = { | |
230 ['Suramar'] = 1859, | |
231 ["Sashj'tar Ruins"] = 1859, | |
232 ["Faronaar Ruins"] = 1859, | |
233 | |
234 ['Azsuna'] = 1900, | |
235 } | |
236 local globalBountyInfo = { | |
237 } | |
238 function VeneerWorldStateCurrencyMixin:Update(isBatchUpdate) | |
239 local zoneText = GetRealZoneText() | |
240 local canShow = false | |
241 if zoneText then | |
242 local currency = zoneCurrency[zoneText] | |
243 if currency then | |
244 local name, earned, texture, earnedThisWeek, weeklyMax, totalMax = GetCurrencyInfo(zoneCurrency[zoneText]) | |
245 self.Icon:SetTexture(texture) | |
246 self.Label:SetFormattedText("%d / %d", earned, totalMax) | |
247 self:SetWidth(self.Icon:GetWidth() + self.Label:GetStringWidth() + 6) | |
248 canShow = true | |
249 end | |
250 else | |
251 end | |
252 self:SetShown(canShow) | |
253 VeneerWorldState:Reanchor(true) | |
254 end | |
255 | |
256 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) | |
257 self.timeLived = (self.timeLived or 0) + sinceLast | |
258 if self.keepOpen then | |
259 return | |
260 end | |
261 if self.timeLived >= 3 and not self.TimedFadeOut:IsPlaying() then | |
262 self.TimedFadeOut:Play() | |
263 end | |
264 end | |
265 | |
266 function VeneerWorldStateProgressMixin:OnLoad() | |
267 self:RegisterEvent('PLAYER_EQUIPMENT_CHANGED') | |
268 | |
269 self:RegisterEvent("PLAYER_XP_UPDATE"); | |
270 self:RegisterEvent("UPDATE_EXHAUSTION"); | |
271 self:RegisterEvent("PLAYER_LEVEL_UP"); | |
272 self:RegisterEvent("PLAYER_UPDATE_RESTING"); | |
273 | |
274 self:RegisterEvent("ARTIFACT_UPDATE"); | |
275 self:RegisterEvent("ARTIFACT_XP_UPDATE"); | |
276 self:RegisterEvent("ARTIFACT_CLOSE"); | |
277 self:RegisterEvent("ARTIFACT_MAX_RANKS_UPDATE"); | |
278 | |
279 self.progressPercent = 0 | |
280 self.progressAmount = 0 | |
281 self.progressMax = 1 | |
282 self.progressOverflow = 0 | |
283 | |
284 end | |
285 | |
286 function VeneerWorldStateProgressMixin:Setup() | |
287 self:UpdateXPGain() | |
288 if self.canGainXP then | |
289 self.mode = 'xp' | |
290 else | |
291 self.mode = 'artifact' | |
292 end | |
293 print('setup mode:', self.mode) | |
294 end | |
295 | |
296 function VeneerWorldStateProgressMixin:OnEvent(event, ...) | |
297 local lastMode = self.mode | |
298 if event == 'PLAYER_LEVEL_UP' or event == 'ENABLE_XP_GAIN' or event == 'DISABLE_XP_GAIN' then | |
299 self:UpdateXPGain() | |
300 elseif event == 'ARTIFACT_XP_UPDATE' or event == 'ARTIFACT_UPDATE' then | |
301 self.mode = 'artifact' | |
302 | |
303 elseif event == 'PLAYER_EQUIPMENT_CHANGED' then | |
304 local slot, hasEquip = ... | |
305 if slot == 16 then | |
306 self.mode = 'artifact' | |
307 lastMode = nil | |
308 end | |
309 elseif event == 'PLAYER_XP_UPDATE' or event == 'PLAYER_LEVEL_UP' then | |
310 print('forcing to XP mode') | |
311 self.mode = 'xp' | |
312 end | |
313 self.modeChanged = (lastMode ~= self.mode) | |
314 if self.modeChanged and self:IsVisible() then | |
315 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()', event, ...) | |
316 self:AnimateMode() | |
317 else | |
318 print('|cFFFFFF00'..self:GetName()..':Update()', event, ...) | |
319 self:Update() | |
320 end | |
321 end | |
322 function VeneerWorldStateProgressMixin:UpdateXPGain() | |
323 self.canGainXP = (UnitLevel('player') < GetMaxPlayerLevel()) and (not IsXPUserDisabled()) | |
324 if not self.canGainXP then | |
325 self.ProgressBar:SetColorTexture(0.75,0.75,0.75) | |
326 end | |
327 end | |
328 | |
329 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | |
330 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | |
331 | |
332 | |
333 local progressHandlers = { | |
334 xp = function(self) | |
335 local hasNewInfo, showChange = false, false | |
336 local xp = UnitXP('player') | |
337 local xpMax = UnitXPMax('player') | |
338 local bonusXP = GetXPExhaustion() | |
339 if xp then | |
340 self.progressPercent = xp / xpMax | |
341 end | |
342 self.progressText = '|cFFFFCC00' .. UnitLevel('player') .. '|r ' .. xp .. '/' .. xpMax | |
343 if bonusXP then | |
344 self.progressOverflow = min(1,(bonusXP / xpMax)) | |
345 self.OverflowBar:SetColorTexture(0.5, 0.5,0.5, 0.25) | |
346 self.OverflowBar:SetPoint('LEFT', self.ProgressBar, 'LEFT') | |
347 else | |
348 self.progressOverflow = nil | |
349 end | |
350 self.ProgressBar:SetColorTexture(0, 0.5,1,1) | |
351 self.OverflowAnchor = self.ProgressBar | |
352 self.hasNewInfo = (self.progressAmount ~= xp) | |
353 showChange = (hasNewInfo and not self.modeChanged) and ((xp - self.progressAmount) / xpMax) | |
354 | |
355 self.progressAmount = xp | |
356 self.progressMax = xpMax | |
357 return hasNewInfo, showChange | |
358 end, | |
359 artifact = function(self) | |
360 local hasNewInfo, showChange = false, false | |
361 local itemID, altItemID, name, icon, totalXP, pointsSpent = GetEquippedArtifactInfo() | |
362 if itemID then | |
363 local nextRankCost = GetCostForPointAtRank(pointsSpent) or 0 | |
364 print(' API:', itemID, name, 'XP:', totalXP, 'Points:', pointsSpent, 'Next:', nextRankCost) | |
365 hasNewInfo = (self.progressAmount ~= totalXP) | |
366 showChange = (hasNewInfo and not self.modeChanged) and (((totalXP - self.progressAmount) / nextRankCost)) | |
367 | |
368 if totalXP > nextRankCost then | |
369 self.progressPercent = 1 | |
370 else | |
371 self.progressPercent = totalXP / nextRankCost | |
372 end | |
373 | |
374 self.progressText = name .. ' ('..pointsSpent .. '): '.. totalXP .. ' / ' .. nextRankCost | |
375 | |
376 self.ProgressBar:SetColorTexture(1,0.5,0,1) | |
377 self.OverflowBar:Hide() | |
378 | |
379 if totalXP > nextRankCost then | |
380 self.progressText = self.progressText .. ' Level Up!' | |
381 self.progressOverflow = (totalXP - nextRankCost) / nextRankCost | |
382 self.OverflowBar:SetPoint('LEFT', self.ProgressBG, 'LEFT') | |
383 self.OverflowAnchor = self.OverflawBar | |
384 else | |
385 self.progressOverflow = nil | |
386 self.OverflowAnchor = self.ProgressBar | |
387 end | |
388 | |
389 self.progressAmount = totalXP | |
390 self.progressMax = nextRankCost | |
391 else | |
392 self.progressOverflow = nil | |
393 self.progressAmount = 0 | |
394 self.progressMax = 1 | |
395 self.progressText = '' | |
396 end | |
397 return hasNewInfo, showChange | |
398 end | |
399 } | |
400 | |
401 function VeneerWorldStateProgressMixin:Update(isBatchUpdate) | |
402 | |
403 local progressChange = false | |
404 print(' current mode:', self.mode, 'vis:', self:IsVisible()) | |
405 if (not self.mode) or (not progressHandlers[self.mode]) then | |
406 self:HidePanel() | |
407 return | |
408 end | |
409 | |
410 local hasNewInfo, showProgress = progressHandlers[self.mode](self) | |
411 self:SetSize(600,16) | |
412 if hasNewInfo then | |
413 self.timeOut = nil | |
414 self.timeLived = 0 | |
415 end | |
416 | |
417 | |
418 if not self:IsVisible() then | |
419 self.TransitionFadeIn:Play() | |
420 else | |
421 self:ShowPanel() | |
422 end | |
423 | |
424 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'new:', hasNewInfo, 'shown:', self:IsShown()) | |
425 print(' Metrics:', self:IsVisible(), self:GetWidth(), self.ProgressBG:GetWidth()) | |
426 if self.progressPercent > 0 then | |
427 self.ProgressBar:Show() | |
428 self.ProgressBar:SetPoint('TOPRIGHT', self.ProgressBG, 'TOPLEFT', self:GetWidth()* self.progressPercent , 0) | |
429 self.Label:SetText(self.progressText) | |
430 | |
431 self.ProgressSpark:ClearAllPoints() | |
432 if self.progressOverflow then | |
433 print(' Overflow:', self.progressOverflow) | |
434 self.OverflowBar:Show() | |
435 self.OverflowBar:SetWidth(self.progressOverflow * self:GetWidth(), 0) | |
436 else | |
437 self.OverflowBar:Hide() | |
438 end | |
439 self.ProgressSpark:SetPoint('CENTER', self.OverflowAnchor, 'RIGHT', 0, 0) | |
440 | |
441 else | |
442 self.ProgressBar:Hide() | |
443 end | |
444 | |
445 if self.progressOverflow and (self.progressOverflow >= self.progressPercent) then | |
446 self.OverflowBar:SetDrawLayer('ARTWORK', 1) | |
447 self.ProgressBar:SetDrawLayer('ARTWORK', 2) | |
448 else | |
449 self.OverflowBar:SetDrawLayer('ARTWORK', 2) | |
450 self.ProgressBar:SetDrawLayer('ARTWORK', 1) | |
451 end | |
452 | |
453 if progressChange then | |
454 self:AnimateProgress(progressChange) | |
455 end | |
456 | |
457 self.modeChanged = nil | |
458 end | |
459 | |
460 | |
461 function VeneerWorldStateProgressMixin:AnimateProgress(progressChange) | |
462 | |
463 | |
464 local changeAnchor = (self.progressOverflow and self.OverflowBar) or self.ProgressBar | |
465 local progressWidth = self:GetWidth() * min(progressChange, changeAnchor:GetWidth()) | |
466 | |
467 self.ProgressAdded:Show() | |
468 self.ProgressAdded:ClearAllPoints() | |
469 self.ProgressAdded:SetPoint('TOPRIGHT', changeAnchor, 'TOPRIGHT', 0, 0) | |
470 self.ProgressAdded:SetPoint('BOTTOMLEFT', changeAnchor, 'BOTTOMRIGHT', - (progressWidth), 0) | |
471 | |
472 print(' Render change:', progressWidth, changeAnchor) | |
473 self.ProgressFlash.translation:SetOffset(progressWidth, 0) | |
474 self.ProgressFlash:Play() | |
475 end | |
476 | |
477 function VeneerWorldStateProgressMixin:OnMouseDown(button) | |
478 if button == 'RightButton' then | |
479 if self.keepOpen then | |
480 self.keepOpen = nil | |
481 self.timeLived = 1000 | |
482 else | |
483 self.keepOpen = true | |
484 | |
485 self.modeChanged = true | |
486 end | |
487 print('keepOpen =', self.keepOpen) | |
488 self:Update() | |
489 else | |
490 | |
491 if self.mode == 'xp' then | |
492 self.mode = 'artifact' | |
493 else | |
494 if not self.canGainXP then | |
495 return | |
496 end | |
497 self.mode = 'xp' | |
498 end | |
499 print('|cFFFF4400Change mode:', self.mode) | |
500 | |
501 | |
502 self:AnimateMode() | |
503 end | |
504 | |
505 end | |
506 | |
507 function VeneerWorldStateProgressMixin:AnimateMode() | |
508 | |
509 self.TransitionFadeIn:Stop() | |
510 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()') | |
511 self.modeChanged = true | |
512 self.TransitionFadeOut:Play() | |
513 end | |
514 | 218 |
515 do | 219 do |
516 function WorldStateBlockMixin:ShowPanel() | 220 function WorldStateBlockMixin:ShowPanel() |
517 print('|cFF0088FF'..self:GetName()..':ShowPanel()') | 221 print('|cFF0088FF'..self:GetName()..':ShowPanel()') |
518 self:SetShown(true) | 222 self:SetShown(true) |
553 self.keepOpen = true | 257 self.keepOpen = true |
554 self:Setup() | 258 self:Setup() |
555 end | 259 end |
556 end | 260 end |
557 | 261 |
262 |