annotate Turok/Modules/Timer/Container.lua @ 9:9400a0ff8540

Ugh Timer: - container update directionality - talent update iterates over a non-volatile table to carry out updates - index management steps organized - talentRow status implemented, returns the spell associated with the talent chosen from that row CombatLog: - sort out font controls and unbork arguments
author Nenue
date Sun, 21 Feb 2016 13:08:30 -0500
parents a9b8b0866ece
children
rev   line source
Nenue@6 1 --- ${PACKAGE_NAME}
Nenue@6 2 -- @file-author@
Nenue@6 3 -- @project-revision@ @project-hash@
Nenue@6 4 -- @file-revision@ @file-hash@
Nenue@6 5 -- Created: 1/16/2016 12:20 AM
Nenue@6 6 local _G, CreateFrame = _G, CreateFrame
Nenue@6 7 local T, tinsert, UIParent = _G.Turok, table.insert, _G.UIParent
Nenue@6 8 local mod = T.modules.TimerControl
Nenue@6 9 local db, CollectorTray
Nenue@6 10
Nenue@6 11 local pairs, ipairs, gsub, sub, setmetatable = pairs, ipairs, string.gsub, string.sub, setmetatable
Nenue@6 12 local INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2 =
Nenue@6 13 INVTYPE_FINGER, INVSLOT_FINGER1, INVSLOT_FINGER2, INVTYPE_TRINKET, INVSLOT_TRINKET1, INVSLOT_TRINKET2
Nenue@6 14 --@debug@
Nenue@6 15 local DEBUG = true
Nenue@6 16 --@end-debug@
Nenue@6 17 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
Nenue@6 18 local print = function(...)
Nenue@6 19 if not DEBUG then return end
Nenue@6 20 if _G.Devian and _G.DevianDB.workspace ~= 1 then
Nenue@6 21 _G.print('TimerContainer', ...)
Nenue@6 22 end
Nenue@6 23 end
Nenue@6 24
Nenue@6 25 --- defaults
Nenue@6 26 local Containers = {}
Nenue@6 27
Nenue@6 28 --- manages collections of timer displays
Nenue@6 29 local TimerContainer_Init = function(frame, cvars)
Nenue@6 30
Nenue@6 31 frame.num_timers = 0
Nenue@6 32 frame.anchor = cvars.anchor
Nenue@6 33 frame.parent = cvars.parent
Nenue@6 34 frame.anchorTo = cvars.anchorTo
Nenue@6 35 frame.x = cvars.x
Nenue@6 36 frame.y = cvars.y
Nenue@6 37 frame.name = cvars.name
Nenue@6 38 frame.padding = cvars.padding
Nenue@6 39 frame.spacing = cvars.spacing
Nenue@6 40 frame.width = cvars.width
Nenue@6 41 frame.height = cvars.height
Nenue@6 42 frame.timers = {}
Nenue@6 43 frame.childAnchor = cvars.childAnchor
Nenue@6 44 frame.childAnchorTo = cvars.childAnchorTo
Nenue@6 45
Nenue@6 46 frame:ClearAllPoints()
Nenue@6 47 frame:SetPoint(cvars.anchor, cvars.parent, cvars.anchorTo, cvars.x, cvars.y)
Nenue@6 48 frame:SetSize(cvars.width, cvars.height) -- initial values
Nenue@6 49 frame.NameText:SetText(frame.name)
Nenue@6 50 end
Nenue@6 51
Nenue@6 52 local TimerContainer_Add = function(frame, timer)
Nenue@6 53 if timer.containerHandle then
Nenue@6 54 print('stop now')
Nenue@6 55 return
Nenue@6 56 end
Nenue@6 57 timer.containerHandle = 1
Nenue@6 58
Nenue@6 59 print('adding', timer.timerName, 'to', frame.name)
Nenue@6 60 local handle = frame.num_timers + 1
Nenue@6 61 -- if the timer is ordered, start from the top and shift each item upward until they are no longer
Nenue@6 62 -- above the
Nenue@6 63 print('resulting handle:', handle)
Nenue@6 64 print(#frame.timers)
Nenue@6 65
Nenue@6 66 frame.num_timers = frame.num_timers + 1
Nenue@6 67
Nenue@6 68 tinsert(frame.timers, timer)
Nenue@6 69 timer.containerHandle = #frame.timers
Nenue@6 70 --frame.timers[handle] = timer
Nenue@6 71 end
Nenue@6 72
Nenue@6 73 local TimerContainer_Unlock = function(frame)
Nenue@6 74
Nenue@6 75 end
Nenue@6 76
Nenue@6 77 local TimerContainer_Update = function(frame)
Nenue@6 78 local frameCount, hiddenCount = 0, 0
Nenue@6 79 local w = frame.padding
Nenue@6 80 local translation_points = {}
Nenue@6 81 local dx, dy = 0, 0 -- net change in container dimensions
Nenue@6 82 for k, spirit in pairs(frame.timers) do
Nenue@6 83 hiddenCount = hiddenCount + 1
Nenue@6 84 if spirit:IsVisible() and not(spirit.trash or spirit.cvars.absolute) then
Nenue@6 85 frameCount = frameCount + 1
Nenue@6 86 spirit.index = frameCount
Nenue@6 87 print(' -', cNum(hiddenCount), cNum(frameCount), cKey(spirit:GetName()))
Nenue@6 88 --tinsert(frame.timers, spirit)
Nenue@6 89 spirit:ClearAllPoints()
Nenue@6 90 local tx = w
Nenue@6 91 local ty = 0
Nenue@6 92 if spirit.cvars.relative then
Nenue@6 93 tx = tx + spirit.cvars.x
Nenue@6 94 ty = ty + spirit.cvars.y
Nenue@6 95 else
Nenue@6 96 w = w + spirit:GetWidth() + frame.spacing
Nenue@6 97 end
Nenue@6 98 translation_points[k] = {
Nenue@6 99 x = spirit.cvars.x, y = spirit.cvars.y,
Nenue@6 100 dx = tx - spirit.cvars.x, dy = ty - spirit.cvars.y
Nenue@6 101 }
Nenue@6 102 end
Nenue@6 103
Nenue@6 104 --- track the size of in/outbound frames
Nenue@6 105 if not spirit.collected then
Nenue@6 106 if spirit.trash then
Nenue@6 107 dx = dx - spirit.width
Nenue@6 108 elseif spirit.add then
Nenue@6 109 dx = dx + spirit.width
Nenue@6 110 end
Nenue@6 111 spirit.collected = true
Nenue@6 112 end
Nenue@6 113 end
Nenue@6 114 print(cText(' dx:'), cNum(dx))
Nenue@6 115
Nenue@6 116
Nenue@6 117 frame.width = frame.width + dx
Nenue@6 118 frame:SetWidth(frame.width)
Nenue@6 119 local ddX = dx / frameCount
Nenue@6 120
Nenue@6 121 for id, a in pairs(translation_points) do
Nenue@6 122 local spirit = frame.timers[id]
Nenue@6 123
Nenue@6 124
Nenue@6 125 spirit.slide.t1:SetOffset(a.dx, a.dy)
Nenue@6 126 spirit.slide:SetScript('OnFinished', function()
Nenue@6 127 spirit.cvars.x = a.x + a.dx
Nenue@6 128 spirit.cvars.y = a.y + a.dy
Nenue@6 129 spirit:SetPoint(frame.childAnchor, frame, frame.childAnchorTo, spirit.cvars.x, spirit.cvars.y)
Nenue@6 130 end)
Nenue@6 131 spirit.slide:Play()
Nenue@6 132 end
Nenue@6 133 end
Nenue@6 134
Nenue@6 135 --- Updates the appropriate containers' object positions
Nenue@6 136 function mod.Report(self)
Nenue@6 137 if not self.container then
Nenue@6 138 self.container = 'default'
Nenue@6 139 print('reporting to default container')
Nenue@6 140 else
Nenue@6 141 print('reporting to container', self.container)
Nenue@6 142 end
Nenue@6 143
Nenue@6 144 if not Containers[self.container] then
Nenue@6 145 print('need to create')
Nenue@6 146 Containers[self.container] = CreateFrame('Frame', 'TkCollectorFrame'..self.container, UIParent, 'TkContainerTemplate')
Nenue@6 147 TimerContainer_Init(Containers[self.container], mod.db.containers[self.container] or mod.db.containers)
Nenue@6 148 end
Nenue@6 149
Nenue@6 150 if not self.containerHandle then
Nenue@6 151 TimerContainer_Add(Containers[self.container], self)
Nenue@6 152 else
Nenue@6 153 print(self.timerName, 'has a container assigned')
Nenue@6 154 end
Nenue@6 155 TimerContainer_Update(Containers[self.container])
Nenue@6 156 end