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: Nenue@87: function VeneerOrderHallMixin:Setup() Nenue@87: print('|cFFFFFF00'..self:GetName()..':Setup()') Nenue@88: self:SetParent(OrderHallCommandBar) Nick@113: self:RegisterEvent("UNIT_AURA"); Nick@113: self:RegisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED") Nick@113: self:RegisterEvent("GARRISON_FOLLOWER_ADDED") Nick@113: self:RegisterEvent("GARRISON_FOLLOWER_REMOVED") Nick@113: Nenue@88: self:SetShown(true) 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: function VeneerOrderHallMixin:OnEvent(event, ...) Nenue@88: Nenue@88: print('|cFF00AAFF'..self:GetName()..'|r:'.. event, ...) Nenue@88: self:Update() Nenue@88: end Nenue@88: Nenue@88: function VeneerOrderHallMixin:OnShow() Nenue@90: if OrderHallCommandBar then Nenue@90: print('|cFF00AAFF'..self:GetName()..'|r:OnShow()', OrderHallCommandBar:IsShown(), self:IsShown()) Nenue@90: self:Update() Nenue@90: end Nenue@99: Veneer:DynamicReanchor() Nenue@88: end Nenue@88: Nenue@88: function VeneerOrderHallMixin:OnHide() Nenue@90: if OrderHallCommandBar then Nenue@90: print('|cFF00AAFF'..self:GetName()..'|r:OnHide()', OrderHallCommandBar:IsShown(), self:IsShown()) Nenue@90: end Nenue@88: Veneer:Reanchor() Nenue@87: end Nenue@87: Nenue@87: function VeneerOrderHallMixin:Update() Nenue@87: if not OrderHallCommandBar then Nenue@87: print('|cFFFF4400'..self:GetName()..' updater called without target') Nenue@87: return Nenue@87: end Nenue@87: Nenue@87: OrderHallCommandBar:ClearAllPoints() Nick@108: OrderHallCommandBar:SetAllPoints(self) Nick@112: Nenue@87: OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5) Nenue@87: OrderHallCommandBar.WorldMapButton:Hide() Nenue@87: OrderHallCommandBar:EnableMouse(false) Nick@113: self:SetSize(700, 22) Nick@113: Nick@113: local troops = OrderHallCommandBar.TroopSummary Nick@113: if troops then Nick@113: for _, category in ipairs(troops) do Nick@113: category.Count:SetFontObject(VeneerNumberFont) Nick@113: category.Count:ClearAllPoints() Nick@113: category.Count:SetPoint('BOTTOMRIGHT', category.Icon, 'BOTTOMRIGHT', -1, 1) Nick@113: end Nick@113: end Nick@113: Nick@112: Nenue@87: Nenue@88: print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown()) Nenue@88: 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: