Mercurial > wow > turok
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Turok/Modules/Timer/Progressbar.lua Sun Feb 21 08:32:53 2016 -0500 @@ -0,0 +1,246 @@ +--- ${PACKAGE_NAME} +-- @file-author@ +-- @project-revision@ @project-hash@ +-- @file-revision@ @file-hash@ +-- Created: 1/15/2016 6:38 PM +local T, _G = Turok, _G +local GetTime, PlaySoundFile, format = GetTime, PlaySoundFile, string.format +local unpack, tconcat = unpack, table.concat +local ACTIVE, PASSIVE, HIDDEN = 2, 1, 0 +local mod = T.modules.TimerControl +--@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('Progressbar', ...) + end +end +print('Peep!', ...) +--@end-debug@ +local GetPrint = function(trace) + if trace then + return print + else + return function() end + end +end +T.defaults.spirit.progressbar = { + combatFade = true, + alpha = 1, + alpha_ooc = 0, + alpha_ooc_passive = 0, + alpha_ooc_active = 1, + + width = 200, height = 24, + parent = 1, + anchor = 'CENTER', anchorTo = 'CENTER', + setAllPoints = true, + strata = 'MEDIUM', + + foreground_color = {1,0.5,0,0.5}, + foreground_blend = 'ADD', + foreground_texture = [[Interface\Addons\Turok\Media\statusbar\Minimalist.tga]], + background_color = {1,1,1,0.5}, + background_blend = 'BLEND', + padding = 3, + spacing = 1, + foreground_inset= 0, + icon = { + embedded = true, + alpha = 1, + alpha_ooc = 1, + size = 24, + x = -6, y = 0, + anchor = 'RIGHT', anchorTo = 'LEFT', + parent = 1, + }, + + -- text + color = {0,0,0,.5}, +} + +local p = mod.prototype.display.progressbar +p.type='display' + +p.inherits = 'TurokProgressbarTemplate' +p.cvars = {} + +--- Load-time config retrieval +p.Init = function (self) + local print = GetPrint(self.trace) + + print(' ', self:GetName(),'<- Progressbar.Load') + print(' ', self:GetHeight()) + + if self.cvars.hideIcon then + self.enableIcon = false + print('Icon hidden') + else + self.icon:Hide() + if self.cvars.icon then + print('Icon data:') + for k,v in pairs(self.cvars.icon) do + print(' ', k, '=', v) + end + print(cWord(' icon=')..cText(self.itemIcon or self.spellIcon)) + self.icon:SetTexture(self.itemIcon or self.spellIcon) + self.icon:ClearAllPoints() + T.SetTextureLayout(self.icon, self.cvars.icon) + self.enableIcon = true + self.icon:Show() + end + + end + + T.SetStatusTextures(self, self.cvars) + + _G.print('Update', self.background:GetWidth(), self.background:GetHeight()) + _G.print('Update', self.foreground:GetWidth(), self.foreground:GetHeight()) +end + + +--- 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.SetState = function(self, newState, forcePrevious) + local print = GetPrint(self.trace) + + local previous = self.displayState + self.prevState = forcePrevious and forcePrevious or previous + self.displayState = newState + + local newState, previous = self.displayState, self.prevState + --- Transition + if newState ~= previous then + print(cText(' Transition:'), cWord(self.spellName)) + if newState == HIDDEN then + print(cText(' to HIDDEN')) + -- to HIDDEN + if previous then + -- has to have been ACTIVE or PASSIVE at this point + self.Intro:Stop() + if self.event then + self.Outro:Play() + else + 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() + end + + print(cText(' from'), cNum(previous)) + if previous and previous ~= HIDDEN then + -- from visible + if self.event then + self.refresh = true + self.Retro:Play() + end + else + if self.event then + self.Intro:Play() + else + self:Show() + end + end + end + else + if newState == ACTIVE then + print(cText('')) + -- and is ACTIVE + end + + if self.event and newState ~= HIDDEN then + self.refresh = true + self.Retro:Play() + end + end + + if newState ~= HIDDEN then + print(cText(' CVars:')) + local c = (newState == ACTIVE) and self.cvars.active or self.cvars.passive + 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 + local c + if newState == ACTIVE then + self.fillState = 1 + c = self.cvars.active + else + self.fillState = 2 + c = self.cvars.passive + 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) + end +end + +p.Update = function (self) + local print = GetPrint(self.trace) + + -- Trigger business + -- Passive or Hidden, evaluate once + if self.displayState == 0 and self.prevState ~= 0 then + self.prevState = self.displayState -- quietly advance state + self.percent = 0 + self.valueFull = 0 + self.value = 0 + self:SetText() + self:SetProgress(self.percent) + print('go LOW') + elseif self.displayState == 1 and self.prevState ~= 1 then + self.prevState = self.displayState -- quietly advance state + self.valueFull = 0 + self.value = 0 + self.percent = 1 + self:SetText() + self:SetProgress(self.fill_inverse and 0 or 1) + print('go PASSIVE', self.percent, self.duration, self.start, self.expires) + elseif self.displayState == 2 then + if self.prevState ~= 2 or self.refresh then + 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 + 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.valueFull = self.expires - time + self.percent = self.valueFull / self.duration + self.elapsed = time - self.start + self.remaining = self.duration - time + + self.value = floor(self.valueFull) + end + + --PlaySoundFile(self.cvars.sound_active) + self:SetText() + self:SetProgress(self.percent) + end +end \ No newline at end of file