diff Turok/Modules/Timer/Container.lua @ 6:a9b8b0866ece

clear out log jam
author Nenue
date Sun, 21 Feb 2016 08:32:53 -0500
parents
children 9400a0ff8540
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Turok/Modules/Timer/Container.lua	Sun Feb 21 08:32:53 2016 -0500
@@ -0,0 +1,157 @@
+--- ${PACKAGE_NAME}
+-- @file-author@
+-- @project-revision@ @project-hash@
+-- @file-revision@ @file-hash@
+-- Created: 1/16/2016 12:20 AM
+local _G, CreateFrame = _G, CreateFrame
+local T, tinsert, UIParent = _G.Turok, table.insert, _G.UIParent
+local mod = T.modules.TimerControl
+local db, CollectorTray
+
+local pairs, ipairs, gsub, sub, setmetatable = pairs, ipairs, string.gsub, string.sub, setmetatable
+local INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 =
+INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2
+--@debug@
+local DEBUG = true
+--@end-debug@
+local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
+local print = function(...)
+  if not DEBUG then return end
+  if _G.Devian and _G.DevianDB.workspace ~= 1 then
+    _G.print('TimerContainer', ...)
+  end
+end
+print('Peep!', ...)
+
+--- defaults
+local Containers = {}
+
+--- manages collections of timer displays
+local TimerContainer_Init = function(frame, cvars)
+
+  frame.num_timers = 0
+  frame.anchor = cvars.anchor
+  frame.parent = cvars.parent
+  frame.anchorTo = cvars.anchorTo
+  frame.x = cvars.x
+  frame.y = cvars.y
+  frame.name = cvars.name
+  frame.padding = cvars.padding
+  frame.spacing = cvars.spacing
+  frame.width = cvars.width
+  frame.height = cvars.height
+  frame.timers = {}
+  frame.childAnchor = cvars.childAnchor
+  frame.childAnchorTo = cvars.childAnchorTo
+
+  frame:ClearAllPoints()
+  frame:SetPoint(cvars.anchor, cvars.parent, cvars.anchorTo, cvars.x, cvars.y)
+  frame:SetSize(cvars.width, cvars.height) -- initial values
+  frame.NameText:SetText(frame.name)
+end
+
+local TimerContainer_Add = function(frame, timer)
+  if timer.containerHandle then
+    print('stop now')
+    return
+  end
+  timer.containerHandle = 1
+
+  print('adding', timer.timerName, 'to', frame.name)
+  local handle = frame.num_timers + 1
+  -- if the timer is ordered, start from the top and shift each item upward until they are no longer
+  -- above the
+  print('resulting handle:', handle)
+  print(#frame.timers)
+
+  frame.num_timers = frame.num_timers + 1
+
+  tinsert(frame.timers, timer)
+  timer.containerHandle = #frame.timers
+  --frame.timers[handle] = timer
+end
+
+local TimerContainer_Unlock = function(frame)
+
+end
+
+local TimerContainer_Update = function(frame)
+  local frameCount, hiddenCount = 0, 0
+  local w = frame.padding
+  local translation_points = {}
+  local dx, dy = 0, 0 -- net change in container dimensions
+  for k, spirit in pairs(frame.timers) do
+    hiddenCount = hiddenCount + 1
+    if spirit:IsVisible() and not(spirit.trash or spirit.cvars.absolute) then
+      frameCount = frameCount + 1
+      spirit.index = frameCount
+      print('  -', cNum(hiddenCount), cNum(frameCount), cKey(spirit:GetName()))
+      --tinsert(frame.timers, spirit)
+      spirit:ClearAllPoints()
+      local tx = w
+      local ty = 0
+      if spirit.cvars.relative then
+        tx = tx + spirit.cvars.x
+        ty = ty + spirit.cvars.y
+      else
+        w = w + spirit:GetWidth() + frame.spacing
+      end
+      translation_points[k] = {
+        x = spirit.cvars.x, y = spirit.cvars.y,
+        dx = tx - spirit.cvars.x, dy = ty - spirit.cvars.y
+      }
+    end
+
+    --- track the size of in/outbound frames
+    if not spirit.collected then
+      if spirit.trash then
+        dx = dx - spirit.width
+      elseif spirit.add then
+        dx = dx + spirit.width
+      end
+      spirit.collected = true
+    end
+  end
+  print(cText('  dx:'), cNum(dx))
+
+
+  frame.width = frame.width + dx
+  frame:SetWidth(frame.width)
+  local ddX = dx / frameCount
+
+  for id, a in pairs(translation_points) do
+    local spirit = frame.timers[id]
+
+
+    spirit.slide.t1:SetOffset(a.dx, a.dy)
+    spirit.slide:SetScript('OnFinished', function()
+      spirit.cvars.x = a.x + a.dx
+      spirit.cvars.y = a.y + a.dy
+      spirit:SetPoint(frame.childAnchor, frame, frame.childAnchorTo, spirit.cvars.x, spirit.cvars.y)
+    end)
+    spirit.slide:Play()
+  end
+end
+
+--- Updates the appropriate containers' object positions
+function mod.Report(self)
+    if not self.container then
+      self.container = 'default'
+      print('reporting to default container')
+    else
+      print('reporting to container', self.container)
+    end
+
+    if not Containers[self.container] then
+      print('need to create')
+      Containers[self.container] = CreateFrame('Frame', 'TkCollectorFrame'..self.container, UIParent, 'TkContainerTemplate')
+      TimerContainer_Init(Containers[self.container], mod.db.containers[self.container] or mod.db.containers)
+    end
+
+    if not self.containerHandle then
+      TimerContainer_Add(Containers[self.container], self)
+    else
+      print(self.timerName, 'has a container assigned')
+    end
+    TimerContainer_Update(Containers[self.container])
+end
\ No newline at end of file