view 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
line wrap: on
line source
-- Veneer
-- WorldState.lua
-- Created: 10/7/2016 10:55 PM
-- %file-revision%
-- An extensible panel group for HUD values

local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
local WorldStateBlockMixin = {}
VeneerOrderHallMixin = {
  anchorPoint = 'TOP',
  anchorFrom = 'TOP',
  anchorPriority = 1,
  anchorX = 0,
  anchorY = 0,
  addonTrigger = 'Blizzard_OrderHallUI',
  addonFrame = 'OrderHallCommandBar',
}

VeneerWorldStateMixin = {
  maxHeight = 0,
  detectedFrames = {},
  anchorPoint = 'TOP',
  modules = {}
}

function VeneerWorldStateMixin:Reset()
  for i, frame in ipairs(self.modules) do
    if frame.Reset then
      frame:Reset()
    end
  end
  self:Update()
end

function VeneerWorldStateMixin:Setup()
  --DEFAULT_CHAT_FRAME:AddMessage('Loaded')
  print('|cFFFFFF00'..self:GetName()..'|r:Setup()')

  for i, frame in ipairs(self.modules) do
    print('--'.. frame:GetName()..' exists')
    if frame.Setup then
      print('--'.. frame:GetName()..':Setup()')
      frame:Setup()
    end


    for k,v in pairs(WorldStateBlockMixin) do
      if not frame[k] then
        frame[k] = v
        if k:match('^On') then
          frame:SetScript(k, v)
        end
      end
    end

  end
  self:UnregisterEvent('PLAYER_LOGIN')
end

function VeneerWorldStateMixin:SetOrderHallUIMods()
  print('|cFFFF4400remove me', debugstack())
end


function VeneerWorldStateMixin:OnLoad ()
  self.modules = {self:GetChildren()}
  print('|cFFFFFF00'..self:GetName()..'|r!')
  self:RegisterEvent('PLAYER_ENTERING_WORLD')
  self:RegisterEvent('PLAYER_REGEN_ENABLED')
  self:RegisterEvent('PLAYER_REGEN_DISABLED')
  Veneer:AddHandler(self, self.anchorPoint, self.anchorPriority)
  SLASH_VENEERWORLDSTATE1 = "/vws"
  SLASH_VENEERWORLDSTATE2 = "/worldstate"
  SlashCmdList.VENEERWORLDSTATE = function()
    self:Reset()
  end
end

function VeneerWorldStateMixin:OnEvent(event, arg)
  print(event, arg)
  if event == 'PLAYER_ENTERING_WORLD' then
    self:Update()
  elseif event == 'PLAYER_REGEN_ENABLED' then
    self:Update(true)
  elseif event == 'PLAYER_REGEN_DISABLED' then
    self:Update(true)
  end
end

function VeneerWorldStateMixin:Update(isBatchUpdate)
  print('|cFFFFFF00All:Update()|r')
  local canShow = false
  for index, frame in ipairs(self.modules) do
    if frame.Update then
      print('  '..index..' |cFFFF00FFUpdate:|r '.. frame:GetName())
      frame:Update(isBatchUpdate)
      print('    ', frame:IsVisible(), frame:IsShown())
      if frame:IsShown() then
        canShow = true
      end

    end
  end
  self:SetShown(canShow)
end

function VeneerWorldStateMixin:OnShow()
  print('OnShow()', debugstack())
end

function VeneerWorldStateMixin:Reanchor(isUpdate)
  print('  |cFF0088FF'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks')
  self.maxHeight = 0
  local lastFrame
  for i, frame in ipairs(self.modules) do
    print('  '..frame:GetName()..':',frame:IsShown(), frame:GetHeight())
    if frame:IsShown() then
      if lastFrame then
        frame:SetPoint('TOP', lastFrame, 'BOTTOM')
      else
        frame:SetPoint('TOP', self, 'TOP')
      end

      self.maxHeight = self.maxHeight + frame:GetHeight()
      lastFrame = frame
    end
  end
  if (self.maxHeight == 0) or InCombatLockdown() then
    print ('  hiding; combat =', InCombatLockdown())
    self:SetShown(false)
  else
    print ('  height update:', self.maxHeight)
    self:SetHeight(self.maxHeight)
    self:SetShown(true)
  end

  if not isUpdate then
    Veneer:InternalReanchor(self, print)
  end

  WorldStateAlwaysUpFrame:ClearAllPoints()
  WorldStateAlwaysUpFrame:SetPoint('TOP', self, 'BOTTOM', 0, 0)
end



function VeneerWorldStateMixin:OnMouseDown()
end

function VeneerOrderHallMixin:Setup()
  print('|cFFFFFF00'..self:GetName()..':Setup()')
  self:SetParent(OrderHallCommandBar)
  self:RegisterEvent("UNIT_AURA");
  self:RegisterEvent("GARRISON_FOLLOWER_CATEGORIES_UPDATED")
  self:RegisterEvent("GARRISON_FOLLOWER_ADDED")
  self:RegisterEvent("GARRISON_FOLLOWER_REMOVED")

  self:SetShown(true)
end

function VeneerOrderHallMixin:OnLoad()
  Veneer:AddHandler(self, 'TOP', 1)
  self:EnableMouse(false)
end

function VeneerOrderHallMixin:OnEvent(event, ...)

  print('|cFF00AAFF'..self:GetName()..'|r:'.. event, ...)
  self:Update()
end

function VeneerOrderHallMixin:OnShow()
  if OrderHallCommandBar then
    print('|cFF00AAFF'..self:GetName()..'|r:OnShow()', OrderHallCommandBar:IsShown(), self:IsShown())
    self:Update()
  end
  Veneer:DynamicReanchor()
end

function VeneerOrderHallMixin:OnHide()
  if OrderHallCommandBar then
    print('|cFF00AAFF'..self:GetName()..'|r:OnHide()', OrderHallCommandBar:IsShown(), self:IsShown())
  end
  Veneer:Reanchor()
end

function VeneerOrderHallMixin:Update()
  if not OrderHallCommandBar then
    print('|cFFFF4400'..self:GetName()..' updater called without target')
    return
  end

  OrderHallCommandBar:ClearAllPoints()
  OrderHallCommandBar:SetAllPoints(self)

  OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5)
  OrderHallCommandBar.WorldMapButton:Hide()
  OrderHallCommandBar:EnableMouse(false)
  self:SetSize(700, 22)

  local troops = OrderHallCommandBar.TroopSummary
  if troops then
    for _, category in ipairs(troops) do
      category.Count:SetFontObject(VeneerNumberFont)
      category.Count:ClearAllPoints()
      category.Count:SetPoint('BOTTOMRIGHT', category.Icon, 'BOTTOMRIGHT', -1, 1)
    end
  end
  


  print('|cFF00AAFF'..self:GetName()..'|r:Update()', OrderHallCommandBar:IsVisible(), self:IsShown())
  print(debugstack(6))
  Veneer:DynamicReanchor()
end



do
  function WorldStateBlockMixin:ShowPanel()
    print('|cFF0088FF'..self:GetName()..':ShowPanel()')
    self:SetShown(true)
    self:SetAlpha(1)
    VeneerWorldState:Show()
  end
  function WorldStateBlockMixin:HidePanel()
    print('|cFF0088FF'..self:GetName()..':HidePanel()')
    self:SetShown(false)
    VeneerWorldState:Reanchor()
  end

  function WorldStateBlockMixin:OnSizeChanged ()
    local h = self:GetHeight()
    if h > VeneerWorldState.maxHeight then
      VeneerWorldState.maxHeight = h
      VeneerWorldState:SetHeight(h)
      print('updating max height:', h)
    elseif h < VeneerWorldState.maxHeight then
      VeneerWorldState:Reanchor()
    end
  end
  function WorldStateBlockMixin:OnHide ()
    print('|cFF0088FF'..self:GetName()..':OnHide()')
    VeneerWorldState:Reanchor()
  end
  function WorldStateBlockMixin:OnShow ()
    self.timeLived = 0
    print('|cFF0088FF'..self:GetName()..':OnShow()')
    VeneerWorldState:Reanchor()
  end
  function WorldStateBlockMixin:Setup()
    print('|cFF0088FF'..self:GetName()..':Setup()|r -- nop')
    self:Update()
  end
  function WorldStateBlockMixin:Reset()
    print('|cFF0088FF'..self:GetName()..':Reset()')
    self.keepOpen = true
    self:Setup()
  end
end