Mercurial > wow > buffalo2
comparison Modules/WorldState.lua @ 87:27db212af783
- polished position management code; goes something like:
- core:Reanchor() to soft fix all anchors
- module:Reanchor() or core:InternalReanchor(module) to position a specific set of neighboring frames
| author | Nenue |
|---|---|
| date | Wed, 19 Oct 2016 16:51:17 -0400 |
| parents | 1196b8175674 |
| children | b107b4df7eb6 |
comparison
equal
deleted
inserted
replaced
| 86:48182978d1c6 | 87:27db212af783 |
|---|---|
| 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 -- |
| 6 | 6 |
| 7 VeneerWorldStateCurrencyMixin = {} | 7 local WorldStateBlockMixin = {} |
| 8 VeneerOrderHallMixin = { | |
| 9 anchorPoint = 'TOP', | |
| 10 } | |
| 11 VeneerWorldStateCurrencyMixin = { | |
| 12 } | |
| 8 VeneerWorldStateProgressMixin = { | 13 VeneerWorldStateProgressMixin = { |
| 9 keepOpen = true | 14 keepOpen = true |
| 10 } | 15 } |
| 11 VeneerWorldStateMixin = { | 16 VeneerWorldStateMixin = { |
| 12 maxHeight = 0, | 17 maxHeight = 0, |
| 13 detectedFrames = {} | 18 detectedFrames = {}, |
| 19 anchorPoint = 'TOP', | |
| 14 } | 20 } |
| 15 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop | 21 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop |
| 22 | |
| 23 function VeneerWorldStateMixin:Reset() | |
| 24 for i, frame in ipairs(self.modules) do | |
| 25 if frame.Reset then | |
| 26 frame:Reset() | |
| 27 end | |
| 28 end | |
| 29 self:Update() | |
| 30 end | |
| 16 | 31 |
| 17 function VeneerWorldStateMixin:Setup() | 32 function VeneerWorldStateMixin:Setup() |
| 18 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') | 33 --DEFAULT_CHAT_FRAME:AddMessage('Loaded') |
| 19 print('|cFFFFFF00'..self:GetName()..'|r:Setup()') | 34 print('|cFFFFFF00'..self:GetName()..'|r:Setup()') |
| 20 | 35 |
| 24 if frame.Setup then | 39 if frame.Setup then |
| 25 print('--'.. frame:GetName()..':Setup()') | 40 print('--'.. frame:GetName()..':Setup()') |
| 26 frame:Setup() | 41 frame:Setup() |
| 27 end | 42 end |
| 28 | 43 |
| 29 frame:SetScript('OnSizeChanged', function() | 44 |
| 30 local h = frame:GetHeight() | 45 for k,v in pairs(WorldStateBlockMixin) do |
| 31 if h > self.maxHeight then | 46 if not frame[k] then |
| 32 self.maxHeight = h | 47 frame[k] = v |
| 33 self:SetHeight(h) | 48 if k:match('^On') then |
| 34 print('updating max height:', h) | 49 frame:SetScript(k, v) |
| 35 elseif h < self.maxHeight then | 50 end |
| 36 self:UpdateSize() | 51 end |
| 37 end | 52 end |
| 38 end) | 53 |
| 39 frame:SetScript('OnHide', function() | 54 end |
| 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') | 55 self:UnregisterEvent('PLAYER_LOGIN') |
| 60 end | 56 end |
| 61 | 57 |
| 62 function VeneerWorldStateMixin:SetOrderHallUIMods() | 58 function VeneerWorldStateMixin:SetOrderHallUIMods() |
| 63 if OrderHallCommandBar then | 59 print('|cFFFF4400remove me', debugstack()) |
| 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 | 60 end |
| 97 | 61 |
| 98 | 62 |
| 99 function VeneerWorldStateMixin:OnLoad () | 63 function VeneerWorldStateMixin:OnLoad () |
| 64 self.modules = {self:GetChildren()} | |
| 100 print('|cFFFFFF00'..self:GetName()..'|r!') | 65 print('|cFFFFFF00'..self:GetName()..'|r!') |
| 101 self:RegisterEvent('PLAYER_LOGIN') | |
| 102 self:RegisterEvent('ADDON_LOADED') | |
| 103 self:RegisterEvent('ARTIFACT_UPDATE') | 66 self:RegisterEvent('ARTIFACT_UPDATE') |
| 104 self:RegisterEvent('ARTIFACT_XP_UPDATE') | 67 self:RegisterEvent('ARTIFACT_XP_UPDATE') |
| 105 self:RegisterEvent('PLAYER_ENTERING_WORLD') | 68 self:RegisterEvent('PLAYER_ENTERING_WORLD') |
| 106 self:RegisterEvent('PLAYER_REGEN_ENABLED') | 69 self:RegisterEvent('PLAYER_REGEN_ENABLED') |
| 107 self:RegisterEvent('PLAYER_REGEN_DISABLED') | 70 self:RegisterEvent('PLAYER_REGEN_DISABLED') |
| 71 self:RegisterEvent('ZONE_CHANGED_NEW_AREA') | |
| 72 self:RegisterEvent('ADDON_LOADED') | |
| 73 Veneer:AddHandler(self, self.anchorPoint, true) | |
| 74 SLASH_VENEERWORLDSTATE1 = "/vws" | |
| 75 SLASH_VENEERWORLDSTATE2 = "/worldstate" | |
| 76 SlashCmdList.VENEERWORLDSTATE = function() | |
| 77 self:Reset() | |
| 78 end | |
| 108 end | 79 end |
| 109 | 80 |
| 110 function VeneerWorldStateMixin:OnEvent(event, arg) | 81 function VeneerWorldStateMixin:OnEvent(event, arg) |
| 111 print(event, arg) | 82 print(event, arg) |
| 112 | 83 |
| 113 if event == 'PLAYER_LOGIN' then | 84 if event == 'PLAYER_LOGIN' then |
| 114 if IsLoggedIn() and not self.initialized then | 85 if IsLoggedIn() and not self.initialized then |
| 115 self.initialized = true | 86 self.initialized = true |
| 116 self:Setup() | 87 self:Setup() |
| 117 end | 88 end |
| 118 elseif event == 'ADDON_LOADED' then | 89 elseif event == 'ZONE_CHANGED_NEW_AREA' or event == 'ADDON_LOADED' then |
| 119 if self.initialized and IsAddOnLoaded('Blizzard_OrderHallUI') then | 90 if OrderHallCommandBar then |
| 120 self:SetOrderHallUIMods() | 91 self:UnregisterEvent('ZONE_CHANGED_NEW_AREA') |
| 92 self:UnregisterEvent('ADDON_LOADED') | |
| 93 Veneer:AddHandler(VeneerOrderHallHandler, 'TOP', true) | |
| 121 end | 94 end |
| 122 elseif event == 'PLAYER_ENTERING_WORLD' then | 95 elseif event == 'PLAYER_ENTERING_WORLD' then |
| 123 self:Update() | 96 self:Update() |
| 124 elseif event == 'PLAYER_REGEN_ENABLED' then | 97 elseif event == 'PLAYER_REGEN_ENABLED' then |
| 125 self:SetShown(true) | 98 self:SetShown(true) |
| 127 self:SetShown(false) | 100 self:SetShown(false) |
| 128 end | 101 end |
| 129 end | 102 end |
| 130 | 103 |
| 131 function VeneerWorldStateMixin:Update() | 104 function VeneerWorldStateMixin:Update() |
| 132 self.modules = {self:GetChildren()} | |
| 133 print('|cFFFFFF00All:Update()|r') | 105 print('|cFFFFFF00All:Update()|r') |
| 134 print(self:GetChildren()) | |
| 135 for i, frame in ipairs(self.modules) do | 106 for i, frame in ipairs(self.modules) do |
| 136 if frame.Update then | 107 if frame.Update then |
| 137 print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') | 108 print(' |cFFFF00FF'.. frame:GetName() .. ':Update()') |
| 138 frame:Update() | 109 frame:Update() |
| 139 end | 110 end |
| 140 end | 111 end |
| 141 self:SetOrderHallUIMods() | 112 end |
| 142 end | 113 |
| 143 | 114 function VeneerWorldStateMixin:Reanchor(isUpdate) |
| 144 function VeneerWorldStateMixin:UpdateSize() | 115 print('|cFFFFFF00'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') |
| 145 print('|cFFFFFF00All:UpdateSize()|r') | |
| 146 print(self:GetChildren()) | |
| 147 self.modules = {self:GetChildren()} | |
| 148 self.maxHeight = 0 | 116 self.maxHeight = 0 |
| 149 for i, frame in ipairs(self.modules) do | 117 for i, frame in ipairs(self.modules) do |
| 150 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) | 118 print(' '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight()) |
| 151 if frame:IsShown() then | 119 if frame:IsShown() then |
| 152 self.maxHeight = max(self.maxHeight, frame:GetHeight()) | 120 self.maxHeight = max(self.maxHeight, frame:GetHeight()) |
| 153 end | 121 end |
| 154 end | 122 end |
| 155 if self.maxHeight == 0 then | 123 if self.maxHeight == 0 then |
| 156 print ('height zero') | 124 print (' hiding because there are no blocks') |
| 157 self:Hide() | 125 self:Hide() |
| 158 else | 126 else |
| 159 self:Show() | 127 self:Show() |
| 160 print ('height update:', self.maxHeight) | 128 print (' height update:', self.maxHeight) |
| 161 self:SetHeight(self.maxHeight) | 129 self:SetHeight(self.maxHeight) |
| 162 end | 130 end |
| 163 | 131 |
| 132 if not isUpdate then | |
| 133 Veneer:InternalReanchor(self, print) | |
| 134 end | |
| 164 end | 135 end |
| 165 | 136 |
| 166 | 137 |
| 167 | 138 |
| 168 function VeneerWorldStateMixin:OnMouseDown() | 139 function VeneerWorldStateMixin:OnMouseDown() |
| 140 end | |
| 141 | |
| 142 function VeneerOrderHallMixin:Setup() | |
| 143 print('|cFFFFFF00'..self:GetName()..':Setup()') | |
| 144 hooksecurefunc(OrderHallCommandBar,'Show', function() | |
| 145 self:Update() | |
| 146 end) | |
| 147 hooksecurefunc(OrderHallCommandBar,'Hide', function() | |
| 148 self:Update() | |
| 149 end) | |
| 150 end | |
| 151 | |
| 152 function VeneerOrderHallMixin:Update() | |
| 153 | |
| 154 if not OrderHallCommandBar then | |
| 155 print('|cFFFF4400'..self:GetName()..' updater called without target') | |
| 156 return | |
| 157 end | |
| 158 | |
| 159 print('|cFF0044FF'..self:GetName()..' update') | |
| 160 OrderHallCommandBar:ClearAllPoints() | |
| 161 OrderHallCommandBar:SetPoint('TOP', self, 'TOP') | |
| 162 OrderHallCommandBar:SetWidth(600) | |
| 163 OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) | |
| 164 OrderHallCommandBar.WorldMapButton:Hide() | |
| 165 OrderHallCommandBar:EnableMouse(false) | |
| 166 | |
| 167 self:SetSize(OrderHallCommandBar:GetSize()) | |
| 169 end | 168 end |
| 170 | 169 |
| 171 function VeneerWorldStateCurrencyMixin:OnLoad () | 170 function VeneerWorldStateCurrencyMixin:OnLoad () |
| 172 | 171 |
| 173 self:RegisterEvent("PLAYER_ENTERING_WORLD"); | 172 self:RegisterEvent("PLAYER_ENTERING_WORLD"); |
| 201 | 200 |
| 202 | 201 |
| 203 end | 202 end |
| 204 | 203 |
| 205 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) | 204 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast) |
| 205 self.timeLived = (self.timeLived or 0) + sinceLast | |
| 206 if self.keepOpen then | 206 if self.keepOpen then |
| 207 return | 207 return |
| 208 end | 208 end |
| 209 | |
| 210 self.timeLived = (self.timeLived or 0) + sinceLast | |
| 211 if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then | 209 if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then |
| 212 if not self.timeOut then | 210 if not self.timeOut then |
| 213 self.timeOut = true | 211 self.timeOut = true |
| 214 self.TimedFadeOut:Play() | 212 self.TimedFadeOut:Play() |
| 215 end | 213 end |
| 237 | 235 |
| 238 end | 236 end |
| 239 | 237 |
| 240 function VeneerWorldStateProgressMixin:Setup() | 238 function VeneerWorldStateProgressMixin:Setup() |
| 241 self:UpdateXPGain() | 239 self:UpdateXPGain() |
| 242 | |
| 243 if self.canGainXP then | 240 if self.canGainXP then |
| 244 self.mode = 'xp' | 241 self.mode = 'xp' |
| 245 else | 242 else |
| 246 self.mode = 'artifact' | 243 self.mode = 'artifact' |
| 247 end | 244 end |
| 281 end | 278 end |
| 282 end | 279 end |
| 283 | 280 |
| 284 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo | 281 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo |
| 285 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank | 282 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank |
| 283 | |
| 284 function VeneerWorldStateProgressMixin:AnimateProgress(progressChange) | |
| 285 | |
| 286 local progressWidth = self:GetWidth() * progressChange | |
| 287 | |
| 288 print(' Render change:', progressChange, progressWidth) | |
| 289 self.ProgressAdded:Show() | |
| 290 self.ProgressAdded:ClearAllPoints() | |
| 291 self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) | |
| 292 self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (progressWidth), 0) | |
| 293 | |
| 294 | |
| 295 self.ProgressFlash.translation:SetOffset(progressWidth, 0) | |
| 296 self.ProgressFlash:Play() | |
| 297 end | |
| 298 | |
| 286 function VeneerWorldStateProgressMixin:Update() | 299 function VeneerWorldStateProgressMixin:Update() |
| 287 local hasNewInfo = false | 300 local hasNewInfo = false |
| 288 local progressChange = false | 301 local progressChange = false |
| 289 print(' current mode:', self.mode) | 302 print(' current mode:', self.mode) |
| 290 | 303 |
| 363 print(self.ProgressBG:GetWidth()) | 376 print(self.ProgressBG:GetWidth()) |
| 364 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) | 377 print(' Percent:', floor(self.progressPercent*100)/100, 'BarLength:', floor(self:GetWidth()* self.progressPercent), 'NewInfo:', hasNewInfo, 'IsShown:', self:IsShown()) |
| 365 | 378 |
| 366 | 379 |
| 367 if progressChange then | 380 if progressChange then |
| 368 print(' Render change:', progressChange) | 381 self:AnimateProgress(progressChange) |
| 369 self.ProgressAdded:Show() | |
| 370 self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (self:GetWidth() * progressChange), 0) | |
| 371 self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0) | |
| 372 self.ProgressFlash:Play() | |
| 373 end | 382 end |
| 374 | 383 |
| 375 | 384 |
| 376 if self.progressPercent > 0 then | 385 if self.progressPercent > 0 then |
| 377 self.ProgressBar:Show() | 386 self.ProgressBar:Show() |
| 398 | 407 |
| 399 function VeneerWorldStateProgressMixin:OnMouseDown(button) | 408 function VeneerWorldStateProgressMixin:OnMouseDown(button) |
| 400 if button == 'RightButton' then | 409 if button == 'RightButton' then |
| 401 if self.keepOpen then | 410 if self.keepOpen then |
| 402 self.keepOpen = nil | 411 self.keepOpen = nil |
| 412 self.timeLived = 1000 | |
| 403 else | 413 else |
| 404 self.keepOpen = true | 414 self.keepOpen = true |
| 405 end | 415 end |
| 406 print('keepOpen =', self.keepOpen) | 416 print('keepOpen =', self.keepOpen) |
| 407 else | 417 else |
| 423 self.TransitionFadeIn:Stop() | 433 self.TransitionFadeIn:Stop() |
| 424 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()') | 434 print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()') |
| 425 self.modeChanged = true | 435 self.modeChanged = true |
| 426 self.TransitionFadeOut:Play() | 436 self.TransitionFadeOut:Play() |
| 427 end | 437 end |
| 438 | |
| 439 do | |
| 440 function WorldStateBlockMixin:ShowPanel() | |
| 441 print('|cFF0088FF'..self:GetName()..':ShowPanel()') | |
| 442 self:SetShown(true) | |
| 443 VeneerWorldState:Show() | |
| 444 end | |
| 445 function WorldStateBlockMixin:HidePanel() | |
| 446 print('|cFF0088FF'..self:GetName()..':HidePanel()') | |
| 447 self:SetShown(false) | |
| 448 VeneerWorldState:Reanchor() | |
| 449 end | |
| 450 | |
| 451 function WorldStateBlockMixin:OnSizeChanged () | |
| 452 local h = self:GetHeight() | |
| 453 if h > VeneerWorldState.maxHeight then | |
| 454 VeneerWorldState.maxHeight = h | |
| 455 VeneerWorldState:SetHeight(h) | |
| 456 print('updating max height:', h) | |
| 457 elseif h < VeneerWorldState.maxHeight then | |
| 458 VeneerWorldState:Reanchor() | |
| 459 end | |
| 460 end | |
| 461 function WorldStateBlockMixin:OnHide () | |
| 462 print('|cFF0088FF'..self:GetName()..':OnHide()') | |
| 463 VeneerWorldState:Reanchor() | |
| 464 end | |
| 465 function WorldStateBlockMixin:OnShow () | |
| 466 self.timeLived = 0 | |
| 467 print('|cFF0088FF'..self:GetName()..':OnShow()') | |
| 468 VeneerWorldState:Reanchor() | |
| 469 end | |
| 470 function WorldStateBlockMixin:Setup() | |
| 471 print('|cFF0088FF'..self:GetName()..':Setup()|r -- nop') | |
| 472 end | |
| 473 function WorldStateBlockMixin:Reset() | |
| 474 print('|cFF0088FF'..self:GetName()..':Reset()') | |
| 475 self.keepOpen = true | |
| 476 self:Setup() | |
| 477 end | |
| 478 end |
