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