diff 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
line wrap: on
line diff
--- a/Modules/WorldState.lua	Tue Oct 18 19:53:24 2016 -0400
+++ b/Modules/WorldState.lua	Wed Oct 19 16:51:17 2016 -0400
@@ -4,16 +4,31 @@
 -- %file-revision%
 --
 
-VeneerWorldStateCurrencyMixin = {}
+local WorldStateBlockMixin = {}
+VeneerOrderHallMixin = {
+  anchorPoint = 'TOP',
+}
+VeneerWorldStateCurrencyMixin = {
+}
 VeneerWorldStateProgressMixin = {
   keepOpen = true
 }
 VeneerWorldStateMixin = {
   maxHeight = 0,
-  detectedFrames = {}
+  detectedFrames = {},
+  anchorPoint = 'TOP',
 }
 local print = DEVIAN_WORKSPACE and function(...) print('VnWorldState', ...) end or nop
 
+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()')
@@ -26,85 +41,41 @@
       frame:Setup()
     end
 
-    frame:SetScript('OnSizeChanged', function()
-      local h = frame:GetHeight()
-      if h > self.maxHeight then
-        self.maxHeight = h
-        self:SetHeight(h)
-        print('updating max height:', h)
-      elseif h < self.maxHeight then
-        self:UpdateSize()
+
+    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)
-    frame:SetScript('OnHide', function()
-      print('|cFF0088FF'..frame:GetName()..':OnHide()')
-      self:UpdateSize()
-    end)
-    frame:SetScript('OnShow', function()
-      frame.timeLived = 0
-      print('|cFF0088FF'..frame:GetName()..':OnShow()')
-      self:UpdateSize()
-    end)
+    end
 
-    function frame.ShowPanel(frame)
-      frame:SetShown(true)
-      self:Show()
-    end
-    function frame.HidePanel(frame)
-      frame:SetShown(false)
-      self:UpdateSize()
-    end
   end
-  self:SetOrderHallUIMods()
   self:UnregisterEvent('PLAYER_LOGIN')
 end
 
 function VeneerWorldStateMixin:SetOrderHallUIMods()
-  if OrderHallCommandBar then
-    if not self.detectedFrames[OrderHallCommandBar] then
-      self.detectedFrames[OrderHallCommandBar] = true
-      hooksecurefunc(OrderHallCommandBar,'Show', function()
-        self:SetOrderHallUIMods()
-      end)
-      hooksecurefunc(OrderHallCommandBar,'Hide', function()
-        self:SetOrderHallUIMods()
-        self:UpdateSize()
-      end)
-    end
-
-
-    OrderHallCommandBar:ClearAllPoints()
-    OrderHallCommandBar:SetPoint('TOP')
-    OrderHallCommandBar:SetWidth(600)
-    OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5)
-    OrderHallCommandBar.WorldMapButton:Hide()
-    OrderHallCommandBar:EnableMouse(false)
-
-    if OrderHallCommandBar:IsVisible() then
-      self:SetPoint('TOP', OrderHallCommandBar, 'BOTTOM')
-      print('anchoring to CommandBar')
-    else
-      self:SetPoint('TOP', UIParent, 'TOP')
-      print('anchoring to UIParent')
-    end
-
-    self:UnregisterEvent('ADDON_LOADED')
-  else
-    self:SetPoint('TOP', UIParent, 'TOP')
-    print('anchoring to UIParent')
-  end
+  print('|cFFFF4400remove me', debugstack())
 end
 
 
 function VeneerWorldStateMixin:OnLoad ()
+  self.modules = {self:GetChildren()}
   print('|cFFFFFF00'..self:GetName()..'|r!')
-  self:RegisterEvent('PLAYER_LOGIN')
-  self:RegisterEvent('ADDON_LOADED')
   self:RegisterEvent('ARTIFACT_UPDATE')
   self:RegisterEvent('ARTIFACT_XP_UPDATE')
   self:RegisterEvent('PLAYER_ENTERING_WORLD')
   self:RegisterEvent('PLAYER_REGEN_ENABLED')
   self:RegisterEvent('PLAYER_REGEN_DISABLED')
+  self:RegisterEvent('ZONE_CHANGED_NEW_AREA')
+  self:RegisterEvent('ADDON_LOADED')
+  Veneer:AddHandler(self, self.anchorPoint, true)
+  SLASH_VENEERWORLDSTATE1 = "/vws"
+  SLASH_VENEERWORLDSTATE2 = "/worldstate"
+  SlashCmdList.VENEERWORLDSTATE = function()
+    self:Reset()
+  end
 end
 
 function VeneerWorldStateMixin:OnEvent(event, arg)
@@ -115,9 +86,11 @@
       self.initialized = true
       self:Setup()
     end
-  elseif event == 'ADDON_LOADED' then
-    if self.initialized and IsAddOnLoaded('Blizzard_OrderHallUI') then
-      self:SetOrderHallUIMods()
+  elseif event == 'ZONE_CHANGED_NEW_AREA' or event == 'ADDON_LOADED' then
+    if OrderHallCommandBar then
+      self:UnregisterEvent('ZONE_CHANGED_NEW_AREA')
+      self:UnregisterEvent('ADDON_LOADED')
+      Veneer:AddHandler(VeneerOrderHallHandler, 'TOP', true)
     end
   elseif event == 'PLAYER_ENTERING_WORLD' then
     self:Update()
@@ -129,22 +102,17 @@
 end
 
 function VeneerWorldStateMixin:Update()
-  self.modules = {self:GetChildren()}
   print('|cFFFFFF00All:Update()|r')
-  print(self:GetChildren())
   for i, frame in ipairs(self.modules) do
     if frame.Update then
       print('  |cFFFF00FF'.. frame:GetName() .. ':Update()')
       frame:Update()
     end
   end
-  self:SetOrderHallUIMods()
 end
 
-function VeneerWorldStateMixin:UpdateSize()
-  print('|cFFFFFF00All:UpdateSize()|r')
-  print(self:GetChildren())
-  self.modules = {self:GetChildren()}
+function VeneerWorldStateMixin:Reanchor(isUpdate)
+  print('|cFFFFFF00'..self:GetName()..':Reanchor()|r', #self.modules, 'blocks')
   self.maxHeight = 0
   for i, frame in ipairs(self.modules) do
     print('  '..frame:GetName()..':',frame:IsShown(), frame:IsVisible(), frame:GetHeight())
@@ -153,14 +121,17 @@
     end
   end
   if self.maxHeight == 0 then
-    print ('height zero')
+    print ('  hiding because there are no blocks')
     self:Hide()
   else
     self:Show()
-    print ('height update:', self.maxHeight)
+    print ('  height update:', self.maxHeight)
     self:SetHeight(self.maxHeight)
   end
 
+  if not isUpdate then
+    Veneer:InternalReanchor(self, print)
+  end
 end
 
 
@@ -168,6 +139,34 @@
 function VeneerWorldStateMixin:OnMouseDown()
 end
 
+function VeneerOrderHallMixin:Setup()
+  print('|cFFFFFF00'..self:GetName()..':Setup()')
+  hooksecurefunc(OrderHallCommandBar,'Show', function()
+    self:Update()
+  end)
+  hooksecurefunc(OrderHallCommandBar,'Hide', function()
+    self:Update()
+  end)
+end
+
+function VeneerOrderHallMixin:Update()
+
+  if not OrderHallCommandBar then
+    print('|cFFFF4400'..self:GetName()..' updater called without target')
+    return
+  end
+
+  print('|cFF0044FF'..self:GetName()..' update')
+  OrderHallCommandBar:ClearAllPoints()
+  OrderHallCommandBar:SetPoint('TOP', self, 'TOP')
+  OrderHallCommandBar:SetWidth(600)
+  OrderHallCommandBar.Background:SetColorTexture(0,0,0,0.5)
+  OrderHallCommandBar.WorldMapButton:Hide()
+  OrderHallCommandBar:EnableMouse(false)
+
+  self:SetSize(OrderHallCommandBar:GetSize())
+end
+
 function VeneerWorldStateCurrencyMixin:OnLoad ()
 
   self:RegisterEvent("PLAYER_ENTERING_WORLD");
@@ -203,11 +202,10 @@
 end
 
 function VeneerWorldStateProgressMixin:OnUpdate(sinceLast)
+  self.timeLived = (self.timeLived or 0) + sinceLast
   if self.keepOpen then
     return
   end
-
-  self.timeLived = (self.timeLived or 0) + sinceLast
   if self.timeLived >= 3 and not self.TransitionFadeOut:IsPlaying() then
     if not self.timeOut then
       self.timeOut = true
@@ -239,7 +237,6 @@
 
 function VeneerWorldStateProgressMixin:Setup()
   self:UpdateXPGain()
-
   if self.canGainXP then
     self.mode = 'xp'
   else
@@ -283,6 +280,22 @@
 
 local GetEquippedArtifactInfo = _G.C_ArtifactUI.GetEquippedArtifactInfo
 local GetCostForPointAtRank = _G.C_ArtifactUI.GetCostForPointAtRank
+
+function VeneerWorldStateProgressMixin:AnimateProgress(progressChange)
+
+  local progressWidth = self:GetWidth() * progressChange
+
+  print('  Render change:', progressChange, progressWidth)
+  self.ProgressAdded:Show()
+  self.ProgressAdded:ClearAllPoints()
+  self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0)
+  self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (progressWidth), 0)
+
+
+  self.ProgressFlash.translation:SetOffset(progressWidth, 0)
+  self.ProgressFlash:Play()
+end
+
 function VeneerWorldStateProgressMixin:Update()
   local hasNewInfo = false
   local progressChange = false
@@ -365,11 +378,7 @@
 
 
     if progressChange then
-      print('  Render change:', progressChange)
-      self.ProgressAdded:Show()
-      self.ProgressAdded:SetPoint('BOTTOMLEFT', self.ProgressBar, 'BOTTOMRIGHT', - (self:GetWidth() * progressChange), 0)
-      self.ProgressAdded:SetPoint('TOPRIGHT', self.ProgressBar, 'TOPRIGHT', 0, 0)
-      self.ProgressFlash:Play()
+      self:AnimateProgress(progressChange)
     end
 
 
@@ -400,6 +409,7 @@
   if button == 'RightButton' then
     if self.keepOpen then
       self.keepOpen = nil
+      self.timeLived = 1000
     else
       self.keepOpen = true
     end
@@ -424,4 +434,45 @@
   print('|cFF88FF00'..self:GetName()..'.TransitionFadeOut:Play()')
   self.modeChanged = true
   self.TransitionFadeOut:Play()
+end
+
+do
+  function WorldStateBlockMixin:ShowPanel()
+    print('|cFF0088FF'..self:GetName()..':ShowPanel()')
+    self:SetShown(true)
+    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')
+  end
+  function WorldStateBlockMixin:Reset()
+    print('|cFF0088FF'..self:GetName()..':Reset()')
+    self.keepOpen = true
+    self:Setup()
+  end
 end
\ No newline at end of file