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