Nenue@6: --- ${PACKAGE_NAME} Nenue@6: -- @file-author@ Nenue@6: -- @project-revision@ @project-hash@ Nenue@6: -- @file-revision@ @file-hash@ Nenue@6: -- Created: 1/15/2016 6:31 PM Nenue@6: local T, _G = Turok, _G Nenue@6: local mod = T.modules.TimerControl Nenue@6: local GetTime, floor, unpack, tconcat = GetTime, floor, unpack, table.concat Nenue@6: local HIDDEN, PASSIVE, ACTIVE = 0, 1,2 Nenue@6: --@debug@ Nenue@6: local cType, cText, cNum, cWord, cKey, cPink, cBool = cType, cText, cNum, cWord, cKey, cPink, cBool Nenue@6: local print = function(...) Nenue@6: if _G.Devian and _G.DevianDB.workspace ~= 1 then Nenue@6: _G.print('Icon', ...) Nenue@6: end Nenue@6: end Nenue@6: --@end-debug@ Nenue@6: local GetPrint = function(trace) Nenue@6: if trace then Nenue@6: return print Nenue@6: else Nenue@6: return function() end Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: T.defaults.spirit.icon = { Nenue@6: combatFade = true, Nenue@6: alpha = 1, Nenue@6: alpha_passive = 1, Nenue@6: alpha_active = 1, Nenue@6: alpha_ooc_passive = 0, Nenue@6: alpha_ooc_active = 1, Nenue@6: alpha_ooc = 0.25, Nenue@6: size = 48, Nenue@6: container = 'default', Nenue@6: strata = 'LOW', Nenue@6: fade_in_time = 0.2, Nenue@6: fade_out_time = 0.3, Nenue@6: anchor = 'BOTTOM', anchorTo = 'BOTTOM', Nenue@6: parent = 1, Nenue@6: size = 48, Nenue@6: width = 48, height = 48, Nenue@6: x = 0, Nenue@6: y = 0, Nenue@6: strata = 'MEDIUM', Nenue@6: padding = 3, Nenue@6: spacing = 1, Nenue@6: foreground_inset= 0, Nenue@6: } Nenue@6: Nenue@6: local p = mod.prototype.display.icon Nenue@6: Nenue@6: p.type='display' Nenue@6: p.inherits = 'TurokIconTemplate' Nenue@6: Nenue@6: --- if config flags need to overrided Nenue@6: p.cvars = { Nenue@6: enableIcon = true Nenue@6: } Nenue@6: --- Negotiate the config differences between different display states Nenue@6: -- Hidden - display is or should (via fade-out) be hidden Nenue@6: -- Passive - display is visible, but no timing information is processed Nenue@6: -- Active - display is visible and counting time; on expiration, it will downgrade itself to passive or hidden Nenue@6: p.Init = function(self) Nenue@6: local print = GetPrint(self.trace) Nenue@6: Nenue@6: print('display.Icon.Load') Nenue@6: local c = self.cvars Nenue@6: if c.type == 'aura' then Nenue@6: self.spiral:SetReverse(true) Nenue@6: else Nenue@6: self.spiral:SetReverse(false) Nenue@6: end Nenue@6: Nenue@6: if not self.icon:IsShown() then Nenue@6: self.icon:Show() Nenue@6: end Nenue@6: print('icon texture=', self.spellIcon or self.itemIcon) Nenue@6: self.icon:SetTexture(self.spellIcon or self.itemIcon) Nenue@6: end Nenue@6: Nenue@9: local function Icon_UpdateCooldown(self) Nenue@9: self.spiral:Show() Nenue@9: self.spiral:SetCooldown(self.charges and self.chargeStart or (self.override and self.override_start or self.start), self.charges and self.chargeDuration or (self.override and self.override_duration or self.duration)) Nenue@9: print('spiral:Play() new', self.charges and self.chargeStart or self.start, self.charges and self.chargeDuration or self.duration) Nenue@9: end Nenue@6: Nenue@6: --- Advances the display state, applying any visual transitions as necessary; Nenue@6: -- @param self frame object Nenue@6: -- @param newState state value; 1 for inactive, 2 for untimed active, 3 for timed active Nenue@6: -- @param forcePrevious force the frame's lastState to this value to block off OnUpdate difference tests Nenue@6: -- even if forced, the actual history value will still be used for method scope Nenue@6: p.SetState = function(self, newState, forcePrevious) Nenue@6: Nenue@6: --print(cWord(self:GetName()), 'state change issued:', cNum(state), cType(previous)) Nenue@6: Nenue@6: local previous = self.displayState Nenue@6: self.prevState = forcePrevious and forcePrevious or previous Nenue@6: self.displayState = newState Nenue@6: print('SetState', cNum(newState), '(from '..cType(previous)..')', cText(self.timerName)) Nenue@6: --_G.print('Prototype.'..self.cvars.type, 'SetState', cNum(newState), '(from '..cType(previous)..')', cText(self.timerName)) Nenue@6: Nenue@6: --- Change transitions Nenue@6: if newState ~= previous then Nenue@6: print(cText(' Transition')) Nenue@6: if newState == HIDDEN then Nenue@6: print(cText(' to HIDDEN')) Nenue@6: -- to HIDDEN Nenue@6: if previous then Nenue@6: -- has to have been ACTIVE or PASSIVE at this point Nenue@6: if previous == ACTIVE then Nenue@6: print(' from ACTIVE') Nenue@6: self.spiral:StopAnimating() Nenue@6: else Nenue@6: print(' from PASSIVE') Nenue@6: end Nenue@6: Nenue@6: self.Intro:Stop() Nenue@6: if self.event then Nenue@6: print(' set by event script') Nenue@6: self.Outro:Play() Nenue@6: else Nenue@6: print(' non-event source') Nenue@6: self:Hide() Nenue@6: end Nenue@6: end Nenue@6: -- want to end here if HIDDEN from nil Nenue@6: else Nenue@6: -- to ACTIVE or PASSIVE Nenue@6: self.Outro:Stop() -- stop any running outro Nenue@6: Nenue@6: Nenue@6: if newState == ACTIVE then Nenue@6: Nenue@6: -- and is ACTIVE Nenue@6: self:Show() Nenue@9: Icon_UpdateCooldown(self) Nenue@6: end Nenue@6: Nenue@6: if previous and previous ~= HIDDEN then Nenue@6: print(cText(' from vis')) Nenue@6: -- from visible Nenue@6: if self.event then Nenue@6: self.refresh = true Nenue@6: end Nenue@6: else Nenue@6: print(cText(' from non-vis')) Nenue@6: if self.event then Nenue@6: self.Intro:Play() Nenue@6: else Nenue@6: self:Show() Nenue@6: end Nenue@6: end Nenue@6: end Nenue@6: else Nenue@6: --- No-change transitions Nenue@6: if newState == ACTIVE then Nenue@6: -- ACTIVE to ACTIVE Nenue@9: Icon_UpdateCooldown(self) Nenue@6: else Nenue@6: print(cPink('stopping spiral')) Nenue@6: self.spiral:Hide() Nenue@6: end Nenue@6: Nenue@6: -- non-HIDDEN to non-HIDDEN and not a dry fire Nenue@6: if self.event and newState ~= HIDDEN then Nenue@6: self.refresh = true Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: if newState ~= HIDDEN then Nenue@6: print(cText(' CVars:')) Nenue@6: local c Nenue@6: if newState == ACTIVE then Nenue@9: if self.override then Nenue@9: c = self.cvars.override Nenue@9: print('apply override profile') Nenue@9: else Nenue@9: print('apply active profile') Nenue@9: c = self.cvars.active Nenue@9: end Nenue@9: Nenue@6: self.fillState = 1 Nenue@6: else Nenue@6: print('apply passive profile') Nenue@6: c = self.cvars.passive Nenue@6: self.fillState = 2 Nenue@6: end Nenue@6: Nenue@6: if self.icon and c.icon then Nenue@6: Nenue@6: print(cText(' '), cWord('desat=')..cBool(c.icon.desaturated), cWord('color=')..cNum(tconcat(c.icon.color, ', '))) Nenue@6: self.icon:SetVertexColor(unpack(c.icon.color)) Nenue@6: self.icon:SetDesaturated(c.icon.desaturated) Nenue@6: end Nenue@6: self:UpdateAlpha(T.inCombat, self.displayState, self.fillState) Nenue@6: end Nenue@6: end Nenue@6: Nenue@6: p.Update = function(self) Nenue@6: Nenue@6: if self.displayState == 0 and self.prevState ~= 0 then Nenue@6: print('flip to', self.displayState) Nenue@6: self.prevState = self.displayState -- quietly advance state Nenue@6: self.percent = 1 Nenue@6: self.valueFull = 0 Nenue@6: self.value = 0 Nenue@6: self:SetText() Nenue@6: elseif self.displayState == 1 and self.prevState ~= 1 then Nenue@6: print('flip to', self.displayState) Nenue@6: self.prevState = self.displayState -- quietly advance state Nenue@6: self.valueFull = 0 Nenue@6: self.value = 0 Nenue@6: self.percent = 1 Nenue@6: self:SetText() Nenue@6: print(self.percent, self.duration, self.start, self.expires) Nenue@6: elseif self.displayState == 2 then Nenue@6: if self.prevState ~= 2 or self.refresh then Nenue@6: print('flipped to', self.displayState) Nenue@6: self.prevState = self.displayState -- quietly advance state Nenue@6: self.refresh = nil Nenue@6: end Nenue@6: -- prevState is set externally Nenue@6: local time = GetTime() Nenue@6: if self.expires <= time and self.charges == self.maxCharges then Nenue@9: print(self.cvars.type, 'timer expired, set to', (self.cvars.persist and self.flags.passive or self.flags.hidden)) Nenue@6: self.percent = 1 Nenue@6: self.duration = 0 Nenue@6: self.expires = 0 Nenue@6: self.start= 0 Nenue@6: self.valueFull = self.duration Nenue@6: self.value = self.duration Nenue@6: self.elapsed = self.duration Nenue@6: self.remaining = 0 Nenue@6: self:SetState(self.cvars.persist and self.flags.passive or self.flags.hidden) Nenue@6: else Nenue@9: -- unit_aura is too ambiguous Nenue@9: if self.override and self.override_expires < time then Nenue@9: self.override = nil Nenue@9: self:SetState(self.flags.active) Nenue@9: end Nenue@9: Nenue@9: if self.override then Nenue@9: self.valueFull = self.override_start + self.override_duration - time Nenue@9: self.percent = (time - self.override_start) / self.override_duration Nenue@9: elseif self.charges and self.charges < self.charges_max then Nenue@9: self.valueFull = self.charge_expires - time Nenue@9: self.percent = (time - self.charge_start) / self.charge_duration Nenue@9: else Nenue@9: self.valueFull = self.expires - time Nenue@9: self.percent = (time - self.start) / self.duration Nenue@9: end Nenue@9: Nenue@6: self.elapsed = time - self.start Nenue@6: self.remaining = self.duration - time Nenue@6: Nenue@6: self.value = floor(self.valueFull) Nenue@6: end Nenue@6: Nenue@6: --PlaySoundFile(self.cvars.sound_active) Nenue@6: self:SetText() Nenue@6: end Nenue@6: end