Nenue@80: -- Veneer Nenue@84: -- WorldState.lua Nenue@80: -- Created: 10/7/2016 10:55 PM Nenue@80: -- %file-revision% Nick@113: -- An extensible panel group for HUD values Nenue@80: Nenue@97: local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop Nenue@87: local WorldStateBlockMixin = {} Nenue@87: VeneerOrderHallMixin = { Nenue@87: anchorPoint = 'TOP', Nenue@90: anchorFrom = 'TOP', Nick@113: anchorPriority = 1, Nenue@90: anchorX = 0, Nenue@90: anchorY = 0, Nenue@90: addonTrigger = 'Blizzard_OrderHallUI', Nenue@90: addonFrame = 'OrderHallCommandBar', Nenue@87: } Nenue@97: Nenue@81: VeneerWorldStateMixin = { Nenue@82: maxHeight = 0, Nenue@87: detectedFrames = {}, Nenue@87: anchorPoint = 'TOP', Nick@113: modules = {} Nenue@81: } Nenue@80: Nenue@87: function VeneerWorldStateMixin:Reset() Nenue@87: for i, frame in ipairs(self.modules) do Nenue@87: if frame.Reset then Nenue@87: frame:Reset() Nenue@87: end Nenue@87: end Nenue@87: self:Update() Nenue@87: end Nenue@87: Nenue@80: function VeneerWorldStateMixin:Setup() Nenue@80: --DEFAULT_CHAT_FRAME:AddMessage('Loaded') Nenue@84: print('|cFFFFFF00'..self:GetName()..'|r:Setup()') Nenue@81: Nenue@81: for i, frame in ipairs(self.modules) do Nenue@84: print('--'.. frame:GetName()..' exists') Nenue@81: if frame.Setup then Nenue@84: print('--'.. frame:GetName()..':Setup()') Nenue@81: frame:Setup() Nenue@81: end Nenue@82: Nenue@87: Nenue@87: for k,v in pairs(WorldStateBlockMixin) do Nenue@87: if not frame[k] then Nenue@87: frame[k] = v Nenue@87: if k:match('^On') then Nenue@87: frame:SetScript(k, v) Nenue@87: end Nenue@82: end Nenue@87: end Nenue@82: Nenue@81: end Nenue@84: self:UnregisterEvent('PLAYER_LOGIN') Nenue@80: end Nenue@80: Nenue@82: function VeneerWorldStateMixin:SetOrderHallUIMods() Nenue@87: print('|cFFFF4400remove me', debugstack()) Nenue@80: end Nenue@84: Nenue@84: Nenue@84: function VeneerWorldStateMixin:OnLoad () Nenue@87: self.modules = {self:GetChildren()} Nenue@84: print('|cFFFFFF00'..self:GetName()..'|r!') Nenue@84: self:RegisterEvent('PLAYER_ENTERING_WORLD') Nenue@84: self:RegisterEvent('PLAYER_REGEN_ENABLED') Nenue@84: self:RegisterEvent('PLAYER_REGEN_DISABLED') Nick@113: Veneer:AddHandler(self, self.anchorPoint, self.anchorPriority) Nenue@87: SLASH_VENEERWORLDSTATE1 = "/vws" Nenue@87: SLASH_VENEERWORLDSTATE2 = "/worldstate" Nenue@87: SlashCmdList.VENEERWORLDSTATE = function() Nenue@87: self:Reset() Nenue@87: end Nenue@84: end Nenue@84: Nenue@80: function VeneerWorldStateMixin:OnEvent(event, arg) Nenue@80: print(event, arg) Nenue@90: if event == 'PLAYER_ENTERING_WORLD' then Nenue@80: self:Update() Nenue@81: elseif event == 'PLAYER_REGEN_ENABLED' then Nick@108: self:Update(true) Nenue@81: elseif event == 'PLAYER_REGEN_DISABLED' then Nick@108: self:Update(true) Nenue@80: end Nenue@80: end Nenue@80: Nenue@88: function VeneerWorldStateMixin:Update(isBatchUpdate) Nenue@80: print('|cFFFFFF00All:Update()|r') Nick@111: local canShow = false Nenue@88: for index, frame in ipairs(self.modules) do Nenue@82: if frame.Update then Nenue@88: print(' '..index..' |cFFFF00FFUpdate:|r '.. frame:GetName()) Nenue@88: frame:Update(isBatchUpdate) Nenue@88: print(' ', frame:IsVisible(), frame:IsShown()) Nick@111: if frame:IsShown() then Nick@111: canShow = true Nick@111: end Nick@111: Nenue@82: end Nenue@82: end Nick@111: self:SetShown(canShow) Nenue@82: end Nenue@82: Nick@108: function VeneerWorldStateMixin:OnShow() Nick@108: print('OnShow()', debugstack()) Nick@108: end Nick@108: Nenue@87: function VeneerWorldStateMixin:Reanchor(isUpdate) Nenue@88: print(' |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks') Nenue@81: self.maxHeight = 0 Nenue@89: local lastFrame Nenue@81: for i, frame in ipairs(self.modules) do Nick@108: print(' '..frame:GetName()..':',frame:IsShown(), frame:GetHeight()) Nick@108: if frame:IsShown() then Nenue@89: if lastFrame then Nenue@89: frame:SetPoint('TOP', lastFrame, 'BOTTOM') Nenue@89: else Nenue@89: frame:SetPoint('TOP', self, 'TOP') Nenue@89: end Nenue@89: Nenue@89: self.maxHeight = self.maxHeight + frame:GetHeight() Nenue@89: lastFrame = frame Nenue@80: end Nenue@80: end Nick@108: if (self.maxHeight == 0) or InCombatLockdown() then Nick@108: print (' hiding; combat =', InCombatLockdown()) Nick@108: self:SetShown(false) Nenue@82: else Nenue@87: print (' height update:', self.maxHeight) Nenue@82: self:SetHeight(self.maxHeight) Nick@108: self:SetShown(true) Nenue@82: end Nenue@82: Nenue@87: if not isUpdate then Nenue@87: Veneer:InternalReanchor(self, print) Nenue@87: end Nenue@93: Nenue@93: WorldStateAlwaysUpFrame:ClearAllPoints() Nenue@93: WorldStateAlwaysUpFrame:SetPoint('TOP', self, 'BOTTOM', 0, 0) Nenue@80: end Nenue@80: Nenue@80: Nenue@80: Nenue@84: function VeneerWorldStateMixin:OnMouseDown() Nenue@80: end Nenue@80: Nick@114: --- Order Hall mod Nick@114: local requiresUpdate Nick@114: local ocb Nenue@87: function VeneerOrderHallMixin:Setup() Nenue@87: print('|cFFFFFF00'..self:GetName()..':Setup()') Nick@114: ocb = OrderHallCommandBar Nick@114: hooksecurefunc(ocb, 'RefreshCategories', function() Nick@114: requiresUpdate = true Nick@114: end) Nick@114: hooksecurefunc(ocb, 'RefreshCurrency', Nick@114: function() Nick@114: requiresUpdate = true Nick@114: end) Nick@114: hooksecurefunc(ocb, 'SetShown', function(isShown) Nick@114: self:SetShown(isShown) Nick@114: end) Nick@114: hooksecurefunc(ocb, 'RefreshAll', function() Nick@114: self:Update() Nick@114: end) Nick@113: Nick@114: ocb:ClearAllPoints() Nick@114: ocb:SetAllPoints(self) Nick@114: Nick@114: Nick@114: ocb.WorldMapButton:Hide() Nick@114: ocb.AreaName:Hide() Nick@114: Nick@114: ocb.Currency:SetFontObject(VeneerHeaderFont) Nick@114: ocb.Currency:ClearAllPoints() Nick@114: ocb.Currency:SetPoint('BOTTOMLEFT', ocb.ClassIcon, 'BOTTOMRIGHT', 15, 0) Nick@114: Nick@114: ocb.CurrencyIcon:ClearAllPoints() Nick@114: ocb.CurrencyIcon:SetPoint('TOP', ocb.ClassIcon, 'TOPRIGHT') Nick@114: Nick@114: ocb.Background:SetColorTexture(0,0,0,0.5) Nick@114: Nick@114: -- frame that calls up the resources tooltip Nick@114: ocb.CurrencyHitTest:SetPoint('LEFT', ocb.CurrencyIcon, 'LEFT') Nick@114: ocb.CurrencyHitTest:SetPoint('RIGHT', ocb.Currency, 'RIGHT') Nick@114: Nick@114: Nick@114: self:SetSize(700, 23) Nick@114: self:SetShown(ocb:IsShown()) Nick@114: end Nick@114: Nick@114: function VeneerOrderHallMixin:OnUpdate() Nick@114: if requiresUpdate then Nick@114: self:Update() Nick@114: end Nick@114: Nenue@88: end Nenue@88: Nenue@90: function VeneerOrderHallMixin:OnLoad() Nick@108: Veneer:AddHandler(self, 'TOP', 1) Nick@113: self:EnableMouse(false) Nenue@90: end Nenue@90: Nenue@88: Nenue@88: function VeneerOrderHallMixin:OnShow() Nick@114: if ocb then Nick@114: --self:Print('|cFF00AAFF'..self:GetName()..'|r:OnShow()', ocb:IsShown(), self:IsShown()) Nenue@90: self:Update() Nenue@90: end Nenue@87: end Nenue@87: Nenue@87: function VeneerOrderHallMixin:Update() Nick@114: self:SetShown(ocb:IsShown()) Nick@114: local lastFrame Nick@114: local categoriesWidth = 0 Nick@113: local troops = OrderHallCommandBar.TroopSummary Nick@113: if troops then Nick@113: for _, category in ipairs(troops) do Nick@114: category.Count:SetFontObject(VeneerHeaderFont) Nick@114: category.Count:SetTextColor(1,1,1,1) Nick@113: category.Count:ClearAllPoints() Nick@113: category.Count:SetPoint('BOTTOMRIGHT', category.Icon, 'BOTTOMRIGHT', -1, 1) Nick@114: Nick@114: category:ClearAllPoints() Nick@114: if lastFrame then Nick@114: lastFrame:SetPoint('TOPRIGHT', category, 'TOPLEFT', 0, 0) Nick@114: end Nick@114: category:SetSize(category.TroopPortraitCover:GetSize()) Nick@114: Nick@114: lastFrame = category Nick@114: categoriesWidth = categoriesWidth + category:GetWidth() Nick@114: end Nick@114: Nick@114: if lastFrame then Nick@114: lastFrame:SetPoint('TOPRIGHT', ocb, 'TOPRIGHT', 0, 0) Nick@113: end Nick@114: Nick@113: end Nick@114: self:SetWidth(ocb.ClassIcon:GetWidth() + 15 + ocb.Currency:GetWidth() + ocb.CurrencyIcon:GetWidth() + categoriesWidth) Nick@114: requiresUpdate = nil Nick@114: --print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown()) Nick@114: --print(debugstack(6)) Nenue@98: Veneer:DynamicReanchor() Nenue@87: end Nenue@87: Nenue@80: Nenue@87: Nenue@87: do Nenue@87: function WorldStateBlockMixin:ShowPanel() Nenue@87: print('|cFF0088FF'..self:GetName()..':ShowPanel()') Nenue@87: self:SetShown(true) Nenue@93: self:SetAlpha(1) Nenue@87: VeneerWorldState:Show() Nenue@87: end Nenue@87: function WorldStateBlockMixin:HidePanel() Nenue@87: print('|cFF0088FF'..self:GetName()..':HidePanel()') Nenue@87: self:SetShown(false) Nenue@87: VeneerWorldState:Reanchor() Nenue@87: end Nenue@87: Nenue@87: function WorldStateBlockMixin:OnSizeChanged () Nenue@87: local h = self:GetHeight() Nenue@87: if h > VeneerWorldState.maxHeight then Nenue@87: VeneerWorldState.maxHeight = h Nenue@87: VeneerWorldState:SetHeight(h) Nenue@87: print('updating max height:', h) Nenue@87: elseif h < VeneerWorldState.maxHeight then Nenue@87: VeneerWorldState:Reanchor() Nenue@87: end Nenue@87: end Nenue@87: function WorldStateBlockMixin:OnHide () Nenue@87: print('|cFF0088FF'..self:GetName()..':OnHide()') Nenue@87: VeneerWorldState:Reanchor() Nenue@87: end Nenue@87: function WorldStateBlockMixin:OnShow () Nenue@87: self.timeLived = 0 Nenue@87: print('|cFF0088FF'..self:GetName()..':OnShow()') Nenue@87: VeneerWorldState:Reanchor() Nenue@87: end Nenue@87: function WorldStateBlockMixin:Setup() Nenue@87: print('|cFF0088FF'..self:GetName()..':Setup()|r -- nop') Nenue@88: self:Update() Nenue@87: end Nenue@87: function WorldStateBlockMixin:Reset() Nenue@87: print('|cFF0088FF'..self:GetName()..':Reset()') Nenue@87: self.keepOpen = true Nenue@87: self:Setup() Nenue@87: end Nenue@93: end Nenue@93: Nick@113: