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