-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmirror.lua
151 lines (117 loc) · 3.41 KB
/
mirror.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
local _, settings = ...
local _DEFAULTS = {
width = 220,
height = 18,
texture = [[Interface\AddOns\oMirrorBars\textures\statusbar]],
position = {
["BREATH"] = 'TOP#UIParent#TOP#0#-96';
["EXHAUSTION"] = 'TOP#UIParent#TOP#0#-119';
["FEIGNDEATH"] = 'TOP#UIParent#TOP#0#-142';
};
colors = {
EXHAUSTION = {1, .9, 0};
BREATH = {0, .5, 1};
DEATH = {1, .7, 0};
FEIGNDEATH = {1, .7, 0};
};
}
do
settings = setmetatable(settings, {__index = _DEFAULTS})
for k,v in next, settings do
if(type(v) == 'table') then
settings[k] = setmetatable(settings[k], {__index = _DEFAULTS[k]})
end
end
end
local Spawn, PauseAll
do
local barPool = {}
local loadPosition = function(self)
local pos = settings.position[self.type]
local p1, frame, p2, x, y = strsplit("#", pos)
return self:SetPoint(p1, frame, p2, x, y)
end
local OnUpdate = function(self, elapsed)
if(self.paused) then return end
self:SetValue(GetMirrorTimerProgress(self.type) / 1e3)
end
local Start = function(self, value, maxvalue, scale, paused, text)
if(paused > 0) then
self.paused = 1
elseif(self.paused) then
self.paused = nil
end
self.text:SetText(text)
self:SetMinMaxValues(0, maxvalue / 1e3)
self:SetValue(value / 1e3)
if(not self:IsShown()) then self:Show() end
end
function Spawn(type)
if(barPool[type]) then return barPool[type] end
local frame = CreateFrame('StatusBar', nil, UIParent)
frame:SetScript("OnUpdate", OnUpdate)
local r, g, b = unpack(settings.colors[type])
local bg = frame:CreateTexture(nil, 'BACKGROUND')
bg:SetAllPoints(frame)
bg:SetTexture(settings.texture)
bg:SetVertexColor(r * .5, g * .5, b * .5)
local text = frame:CreateFontString(nil, 'OVERLAY')
text:SetFont(GameFontNormalSmall:GetFont(), 11)
text:SetShadowOffset(.8, -.8)
text:SetShadowColor(0, 0, 0, 1)
text:SetJustifyH'CENTER'
text:SetTextColor(1, 1, 1)
text:SetPoint('LEFT', frame)
text:SetPoint('RIGHT', frame)
text:SetPoint('TOP', frame, 0, -3)
text:SetPoint('BOTTOM', frame)
frame:SetSize(settings.width, settings.height)
frame:SetStatusBarTexture(settings.texture)
frame:SetStatusBarColor(r, g, b)
frame.type = type
frame.text = text
frame.Start = Start
frame.Stop = Stop
loadPosition(frame)
barPool[type] = frame
return frame
end
function PauseAll(val)
for _, bar in next, barPool do
bar.paused = val
end
end
end
local frame = CreateFrame'Frame'
frame:SetScript('OnEvent', function(self, event, ...)
return self[event](self, ...)
end)
function frame:ADDON_LOADED(addon)
if(addon == 'oMirrorBars') then
UIParent:UnregisterEvent'MIRROR_TIMER_START'
self:UnregisterEvent'ADDON_LOADED'
self.ADDON_LOADED = nil
end
end
frame:RegisterEvent'ADDON_LOADED'
function frame:PLAYER_ENTERING_WORLD()
for i=1, MIRRORTIMER_NUMTIMERS do
local type, value, maxvalue, scale, paused, text = GetMirrorTimerInfo(i)
if(type ~= 'UNKNOWN') then
Spawn(type):Start(value, maxvalue, scale, paused, text)
end
end
end
frame:RegisterEvent'PLAYER_ENTERING_WORLD'
function frame:MIRROR_TIMER_START(type, value, maxvalue, scale, paused, text)
return Spawn(type):Start(value, maxvalue, scale, paused, text)
end
frame:RegisterEvent'MIRROR_TIMER_START'
function frame:MIRROR_TIMER_STOP(type)
return Spawn(type):Hide()
end
frame:RegisterEvent'MIRROR_TIMER_STOP'
function frame:MIRROR_TIMER_PAUSE(duration)
return PauseAll((duration > 0 and duration) or nil)
end
frame:RegisterEvent'MIRROR_TIMER_PAUSE'