/Tukui/modules/blizzard/mirror.lua
Lua | 161 lines | 121 code | 37 blank | 3 comment | 12 complexity | e3ac9ec888e7e0a27635d26ef8d7809a MD5 | raw file
1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales 2 3--------------------------------------------------------------------- 4-- original by haste, edited for tukui :) 5--------------------------------------------------------------------- 6 7local _, settings = ... 8 9local _DEFAULTS = { 10 width = T.Scale(220), 11 height = T.Scale(18), 12 texture = C["media"].normTex, 13 14 position = { 15 ["BREATH"] = 'TOP#UIParent#TOP#0#-96'; 16 ["EXHAUSTION"] = 'TOP#UIParent#TOP#0#-119'; 17 ["FEIGNDEATH"] = 'TOP#UIParent#TOP#0#-142'; 18 }; 19 20 colors = { 21 EXHAUSTION = {1, .9, 0}; 22 BREATH = {0.31, 0.45, 0.63}; 23 DEATH = {1, .7, 0}; 24 FEIGNDEATH = {1, .7, 0}; 25 }; 26} 27 28do 29 settings = setmetatable(settings, {__index = _DEFAULTS}) 30 for k,v in next, settings do 31 if(type(v) == 'table') then 32 settings[k] = setmetatable(settings[k], {__index = _DEFAULTS[k]}) 33 end 34 end 35end 36 37local Spawn, PauseAll 38do 39 local barPool = {} 40 41 local loadPosition = function(self) 42 local pos = settings.position[self.type] 43 local p1, frame, p2, x, y = strsplit("#", pos) 44 45 return self:Point(p1, frame, p2, x, y) 46 end 47 48 local OnUpdate = function(self, elapsed) 49 if(self.paused) then return end 50 51 self:SetValue(GetMirrorTimerProgress(self.type) / 1e3) 52 end 53 54 local Start = function(self, value, maxvalue, scale, paused, text) 55 if(paused > 0) then 56 self.paused = 1 57 elseif(self.paused) then 58 self.paused = nil 59 end 60 61 self.text:SetText(text) 62 63 self:SetMinMaxValues(0, maxvalue / 1e3) 64 self:SetValue(value / 1e3) 65 66 if(not self:IsShown()) then self:Show() end 67 end 68 69 function Spawn(type) 70 if(barPool[type]) then return barPool[type] end 71 local frame = CreateFrame('StatusBar', nil, UIParent) 72 73 frame:SetScript("OnUpdate", OnUpdate) 74 75 local r, g, b = unpack(settings.colors[type]) 76 77 local bg = frame:CreateTexture(nil, 'BACKGROUND') 78 bg:SetAllPoints(frame) 79 bg:SetTexture(settings.texture) 80 bg:SetVertexColor(r * .5, g * .5, b * .5) 81 82 local border = CreateFrame("Frame", nil, frame) 83 border:Point("TOPLEFT", frame, -2, 2) 84 border:Point("BOTTOMRIGHT", frame, 2, -2) 85 border:SetTemplate("Default") 86 border:SetFrameLevel(0) 87 88 local text = frame:CreateFontString(nil, 'OVERLAY') 89 text:SetFont(C.media.pixelfont, C["datatext"].fontsize, "MONOCHROMEOUTLINE") 90 91 text:SetJustifyH'CENTER' 92 text:SetTextColor(1, 1, 1) 93 94 text:SetPoint('LEFT', frame) 95 text:SetPoint('RIGHT', frame) 96 text:SetPoint('TOP', frame) 97 text:SetPoint('BOTTOM', frame) 98 99 frame:SetSize(settings.width, settings.height) 100 101 frame:SetStatusBarTexture(settings.texture) 102 frame:SetStatusBarColor(r, g, b) 103 104 frame.type = type 105 frame.text = text 106 107 frame.Start = Start 108 frame.Stop = Stop 109 110 loadPosition(frame) 111 112 barPool[type] = frame 113 return frame 114 end 115 116 function PauseAll(val) 117 for _, bar in next, barPool do 118 bar.paused = val 119 end 120 end 121end 122 123local frame = CreateFrame'Frame' 124frame:SetScript('OnEvent', function(self, event, ...) 125 return self[event](self, ...) 126end) 127 128function frame:ADDON_LOADED(addon) 129 if(addon == 'Tukui') then 130 UIParent:UnregisterEvent'MIRROR_TIMER_START' 131 132 self:UnregisterEvent'ADDON_LOADED' 133 self.ADDON_LOADED = nil 134 end 135end 136frame:RegisterEvent'ADDON_LOADED' 137 138function frame:PLAYER_ENTERING_WORLD() 139 for i=1, MIRRORTIMER_NUMTIMERS do 140 local type, value, maxvalue, scale, paused, text = GetMirrorTimerInfo(i) 141 if(type ~= 'UNKNOWN') then 142 Spawn(type):Start(value, maxvalue, scale, paused, text) 143 end 144 end 145end 146frame:RegisterEvent'PLAYER_ENTERING_WORLD' 147 148function frame:MIRROR_TIMER_START(type, value, maxvalue, scale, paused, text) 149 return Spawn(type):Start(value, maxvalue, scale, paused, text) 150end 151frame:RegisterEvent'MIRROR_TIMER_START' 152 153function frame:MIRROR_TIMER_STOP(type) 154 return Spawn(type):Hide() 155end 156frame:RegisterEvent'MIRROR_TIMER_STOP' 157 158function frame:MIRROR_TIMER_PAUSE(duration) 159 return PauseAll((duration > 0 and duration) or nil) 160end 161frame:RegisterEvent'MIRROR_TIMER_PAUSE'