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