comparison Turok/Modules/Timer/Progressbar.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/15/2016 6:38 PM
6 local T, _G = Turok, _G
7 local GetTime, PlaySoundFile, format = GetTime, PlaySoundFile, string.format
8 local unpack, tconcat = unpack, table.concat
9 local ACTIVE, PASSIVE, HIDDEN = 2, 1, 0
10 local mod = T.modules.TimerControl
11 --@debug@
12 local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool
13 local print = function(...)
14 if _G.Devian and _G.DevianDB.workspace ~= 1 then
15 _G.print('Progressbar', ...)
16 end
17 end
18 print('Peep!', ...)
19 --@end-debug@
20 local GetPrint = function(trace)
21 if trace then
22 return print
23 else
24 return function() end
25 end
26 end
27 T.defaults.spirit.progressbar = {
28 combatFade = true,
29 alpha = 1,
30 alpha_ooc = 0,
31 alpha_ooc_passive = 0,
32 alpha_ooc_active = 1,
33
34 width = 200, height = 24,
35 parent = 1,
36 anchor = 'CENTER', anchorTo = 'CENTER',
37 setAllPoints = true,
38 strata = 'MEDIUM',
39
40 foreground_color = {1,0.5,0,0.5},
41 foreground_blend = 'ADD',
42 foreground_texture = [[Interface\Addons\Turok\Media\statusbar\Minimalist.tga]],
43 background_color = {1,1,1,0.5},
44 background_blend = 'BLEND',
45 padding = 3,
46 spacing = 1,
47 foreground_inset= 0,
48 icon = {
49 embedded = true,
50 alpha = 1,
51 alpha_ooc = 1,
52 size = 24,
53 x = -6, y = 0,
54 anchor = 'RIGHT', anchorTo = 'LEFT',
55 parent = 1,
56 },
57
58 -- text
59 color = {0,0,0,.5},
60 }
61
62 local p = mod.prototype.display.progressbar
63 p.type='display'
64
65 p.inherits = 'TurokProgressbarTemplate'
66 p.cvars = {}
67
68 --- Load-time config retrieval
69 p.Init = function (self)
70 local print = GetPrint(self.trace)
71
72 print(' ', self:GetName(),'<- Progressbar.Load')
73 print(' ', self:GetHeight())
74
75 if self.cvars.hideIcon then
76 self.enableIcon = false
77 print('Icon hidden')
78 else
79 self.icon:Hide()
80 if self.cvars.icon then
81 print('Icon data:')
82 for k,v in pairs(self.cvars.icon) do
83 print(' ', k, '=', v)
84 end
85 print(cWord(' icon=')..cText(self.itemIcon or self.spellIcon))
86 self.icon:SetTexture(self.itemIcon or self.spellIcon)
87 self.icon:ClearAllPoints()
88 T.SetTextureLayout(self.icon, self.cvars.icon)
89 self.enableIcon = true
90 self.icon:Show()
91 end
92
93 end
94
95 T.SetStatusTextures(self, self.cvars)
96
97 _G.print('Update', self.background:GetWidth(), self.background:GetHeight())
98 _G.print('Update', self.foreground:GetWidth(), self.foreground:GetHeight())
99 end
100
101
102 --- Negotiate the config differences between different display states
103 -- Hidden - display is or should (via fade-out) be hidden
104 -- Passive - display is visible, but no timing information is processed
105 -- Active - display is visible and counting time; on expiration, it will downgrade itself to passive or hidden
106 p.SetState = function(self, newState, forcePrevious)
107 local print = GetPrint(self.trace)
108
109 local previous = self.displayState
110 self.prevState = forcePrevious and forcePrevious or previous
111 self.displayState = newState
112
113 local newState, previous = self.displayState, self.prevState
114 --- Transition
115 if newState ~= previous then
116 print(cText(' Transition:'), cWord(self.spellName))
117 if newState == HIDDEN then
118 print(cText(' to HIDDEN'))
119 -- to HIDDEN
120 if previous then
121 -- has to have been ACTIVE or PASSIVE at this point
122 self.Intro:Stop()
123 if self.event then
124 self.Outro:Play()
125 else
126 self:Hide()
127 end
128 end
129 -- want to end here if HIDDEN from nil
130 else
131 -- to ACTIVE or PASSIVE
132 self.Outro:Stop() -- stop any running outro
133
134
135 if newState == ACTIVE then
136
137 -- and is ACTIVE
138 self:Show()
139 end
140
141 print(cText(' from'), cNum(previous))
142 if previous and previous ~= HIDDEN then
143 -- from visible
144 if self.event then
145 self.refresh = true
146 self.Retro:Play()
147 end
148 else
149 if self.event then
150 self.Intro:Play()
151 else
152 self:Show()
153 end
154 end
155 end
156 else
157 if newState == ACTIVE then
158 print(cText(''))
159 -- and is ACTIVE
160 end
161
162 if self.event and newState ~= HIDDEN then
163 self.refresh = true
164 self.Retro:Play()
165 end
166 end
167
168 if newState ~= HIDDEN then
169 print(cText(' CVars:'))
170 local c = (newState == ACTIVE) and self.cvars.active or self.cvars.passive
171 if self.icon and c.icon then
172 print(cText(' '), cWord('desat=')..cBool(c.icon.desaturated), cWord('color=')..cNum(tconcat(c.icon.color, ', ')))
173 self.icon:SetVertexColor(unpack(c.icon.color))
174 self.icon:SetDesaturated(c.icon.desaturated)
175 end
176 local c
177 if newState == ACTIVE then
178 self.fillState = 1
179 c = self.cvars.active
180 else
181 self.fillState = 2
182 c = self.cvars.passive
183 end
184
185 if self.icon and c.icon then
186 print(cText(' '), cWord('desat=')..cBool(c.icon.desaturated), cWord('color=')..cNum(tconcat(c.icon.color, ', ')))
187 self.icon:SetVertexColor(unpack(c.icon.color))
188 self.icon:SetDesaturated(c.icon.desaturated)
189 end
190
191 self:UpdateAlpha(T.inCombat)
192 end
193 end
194
195 p.Update = function (self)
196 local print = GetPrint(self.trace)
197
198 -- Trigger business
199 -- Passive or Hidden, evaluate once
200 if self.displayState == 0 and self.prevState ~= 0 then
201 self.prevState = self.displayState -- quietly advance state
202 self.percent = 0
203 self.valueFull = 0
204 self.value = 0
205 self:SetText()
206 self:SetProgress(self.percent)
207 print('go LOW')
208 elseif self.displayState == 1 and self.prevState ~= 1 then
209 self.prevState = self.displayState -- quietly advance state
210 self.valueFull = 0
211 self.value = 0
212 self.percent = 1
213 self:SetText()
214 self:SetProgress(self.fill_inverse and 0 or 1)
215 print('go PASSIVE', self.percent, self.duration, self.start, self.expires)
216 elseif self.displayState == 2 then
217 if self.prevState ~= 2 or self.refresh then
218 self.prevState = self.displayState -- quietly advance state
219 self.refresh = nil
220 end
221 -- prevState is set externally
222 local time = GetTime()
223 if self.expires <= time and self.charges == self.maxCharges then
224 self.percent = 1
225 self.duration = 0
226 self.expires = 0
227 self.start= 0
228 self.valueFull = self.duration
229 self.value = self.duration
230 self.elapsed = self.duration
231 self.remaining = 0
232 self:SetState(self.cvars.persist and self.flags.passive or self.flags.hidden)
233 else
234 self.valueFull = self.expires - time
235 self.percent = self.valueFull / self.duration
236 self.elapsed = time - self.start
237 self.remaining = self.duration - time
238
239 self.value = floor(self.valueFull)
240 end
241
242 --PlaySoundFile(self.cvars.sound_active)
243 self:SetText()
244 self:SetProgress(self.percent)
245 end
246 end