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