vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | local module = ArcHUD:NewModule("MirrorTimer") |
2 | module.unit = "player" |
||
3 | module.defaults = { |
||
4 | Enabled = true, |
||
5 | Outline = true, |
||
6 | ShowSpell = true, |
||
7 | Side = 1, |
||
8 | Level = -1, |
||
9 | } |
||
10 | module.options = { |
||
11 | {name = "ShowSpell", text = "SHOWSPELL", tooltip = "SHOWSPELL"}, |
||
12 | attach = true, |
||
13 | } |
||
14 | module.localized = true |
||
15 | module.disableEvents = { |
||
16 | {frame = "MirrorTimer1", hide = TRUE, events = {"MIRROR_TIMER_PAUSE", "MIRROR_TIMER_STOP", "PLAYER_ENTERING_WORLD"}}, |
||
17 | {frame = "MirrorTimer2", hide = TRUE, events = {"MIRROR_TIMER_PAUSE", "MIRROR_TIMER_STOP", "PLAYER_ENTERING_WORLD"}}, |
||
18 | {frame = "MirrorTimer3", hide = TRUE, events = {"MIRROR_TIMER_PAUSE", "MIRROR_TIMER_STOP", "PLAYER_ENTERING_WORLD"}}, |
||
19 | {frame = "UIParent", hide = FALSE, events = {"MIRROR_TIMER_START"}}, |
||
20 | } |
||
21 | |||
22 | function module:Initialize() |
||
23 | -- Setup the frame we need |
||
24 | self.f = self:CreateRing(true, ArcHUDFrame) |
||
25 | self.f:SetAlpha(0) |
||
26 | |||
27 | self.Text = {} |
||
28 | self.Text[1] = self:CreateFontString(self.f, "BACKGROUND", {140, 16}, 14, "CENTER", {1.0, 1.0, 1.0}, {"BOTTOM", "ArcHUDFrameCombo", "TOP", 0, 96}) |
||
29 | self.Text[2] = self:CreateFontString(self.f, "BACKGROUND", {140, 16}, 14, "CENTER", {1.0, 1.0, 1.0}, {"TOPLEFT", self.Text[1], "BOTTOMLEFT", 0, 0}) |
||
30 | self.Text[3] = self:CreateFontString(self.f, "BACKGROUND", {140, 16}, 14, "CENTER", {1.0, 1.0, 1.0}, {"TOPLEFT", self.Text[2], "BOTTOMLEFT", 0, 0}) |
||
31 | |||
32 | -- Override Update timer |
||
33 | self:RegisterMetro(self.name .. "Update", self.UpdateTimers, 0.05, self) |
||
34 | end |
||
35 | |||
36 | function module:Update() |
||
37 | if(self.db.profile.ShowSpell) then |
||
38 | for i=1,3 do |
||
39 | self.Text[i]:Show() |
||
40 | end |
||
41 | else |
||
42 | for i=1,3 do |
||
43 | self.Text[i]:Hide() |
||
44 | end |
||
45 | end |
||
46 | |||
47 | if(self.db.profile.Outline) then |
||
48 | self.f.BG:Show() |
||
49 | else |
||
50 | self.f.BG:Hide() |
||
51 | end |
||
52 | |||
53 | -- Clear all points for the ring |
||
54 | self.f:ClearAllPoints() |
||
55 | if(self.db.profile.Side == 1) then |
||
56 | -- Attach to left side |
||
57 | self.f:SetPoint("TOPLEFT", self.parent:GetModule("Anchors").Left, "TOPLEFT", self.db.profile.Level * -15, 0) |
||
58 | self.f.BG:SetReversed(false) |
||
59 | self.f:SetReversed(false) |
||
60 | else |
||
61 | -- Attach to right side |
||
62 | self.f:SetPoint("TOPRIGHT", self.parent:GetModule("Anchors").Right, "TOPRIGHT", self.db.profile.Level * 15, 0) |
||
63 | self.f.BG:SetReversed(true) |
||
64 | self.f:SetReversed(true) |
||
65 | end |
||
66 | self.f.BG:SetAngle(180) |
||
67 | end |
||
68 | |||
69 | function module:Enable() |
||
70 | self.f.fadeIn = 0.25 |
||
71 | self.f.fadeOut = 2 |
||
72 | |||
73 | self.f.dirty = true |
||
74 | |||
75 | -- Register the events we will use |
||
76 | self:RegisterEvent("MIRROR_TIMER_START") |
||
77 | self:RegisterEvent("MIRROR_TIMER_PAUSE") |
||
78 | self:RegisterEvent("MIRROR_TIMER_STOP") |
||
79 | self:RegisterEvent("PLAYER_ENTERING_WORLD") |
||
80 | |||
81 | -- Activate the timers |
||
82 | self:StartMetro(self.name .. "Update") |
||
83 | self:StartMetro(self.name .. "Alpha") |
||
84 | self:StartMetro(self.name .. "Fade") |
||
85 | |||
86 | if(not self.timers) then |
||
87 | self.timers = {count = 0} |
||
88 | self.timer = 0 |
||
89 | end |
||
90 | |||
91 | self.f:Show() |
||
92 | end |
||
93 | |||
94 | function module:UpdateTimers(elapsed) |
||
95 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
96 | if(self.timers[i] and not self.timers[i].paused) then |
||
97 | self.timers[i].value = self.timers[i].value + self.timers[i].scale * elapsed*1000 |
||
98 | if(self.timers[i].value > self.timers[i].maxvalue) then |
||
99 | self.timers[i].value = self.timers[i].maxvalue |
||
100 | end |
||
101 | --self:Msg("Updating timer %d: %d time elapsed, value now: %d", i, elapsed*1000, self.timers[i].value) |
||
102 | if(self.timer == i) then |
||
103 | self.f:SetMax(self.timers[i].maxvalue) |
||
104 | self.f:SetValue(self.timers[i].value) |
||
105 | end |
||
106 | local texttime = "" |
||
107 | local time_remaining = self.timers[i].value |
||
108 | if((time_remaining/1000) > 60) then |
||
109 | local minutes = math.floor(time_remaining/60000) |
||
110 | local seconds = math.floor(((time_remaining/60000) - minutes) * 60) |
||
111 | if(seconds < 10) then |
||
112 | texttime = minutes..":0"..seconds |
||
113 | else |
||
114 | texttime = minutes..":"..seconds |
||
115 | end |
||
116 | else |
||
117 | local intlength = string.len(string.format("%u",time_remaining/1000)) |
||
118 | texttime = strsub(string.format("%f",time_remaining/1000),1,intlength+2) |
||
119 | end |
||
120 | self.Text[i]:SetText(self.timers[i].label..": "..texttime) |
||
121 | else |
||
122 | self.Text[i]:SetText("") |
||
123 | end |
||
124 | end |
||
125 | end |
||
126 | |||
127 | function module:MIRROR_TIMER_START() |
||
128 | -- Find a free timer table |
||
129 | local updTimer, newTimer |
||
130 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
131 | if(self.timers[i] and self.timers[i].timer == arg1) then |
||
132 | updTimer = i |
||
133 | break |
||
134 | end |
||
135 | end |
||
136 | if(not updTimer) then |
||
137 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
138 | if(not self.timers[i]) then |
||
139 | newTimer = i |
||
140 | break |
||
141 | end |
||
142 | end |
||
143 | end |
||
144 | |||
145 | if(newTimer) then |
||
146 | -- Add timer to table |
||
147 | self.timers[newTimer] = { |
||
148 | timer = arg1, |
||
149 | value = arg2, |
||
150 | maxvalue = arg3, |
||
151 | scale = arg4, |
||
152 | paused = (arg5 > 0 and arg5 or nil), |
||
153 | label = arg6, |
||
154 | } |
||
155 | -- Switch ring color to the new timer |
||
156 | self.f:UpdateColor(MirrorTimerColors[arg1]) |
||
157 | self.timer = newTimer |
||
158 | self.timers.count = self.timers.count + 1 |
||
159 | --self:Msg("Adding new timer %d: %s, %d, %d, %d, %d, %s", newTimer, arg1, arg2, arg3, arg4, arg5, arg6) |
||
160 | elseif(updTimer) then |
||
161 | -- Update existing timer |
||
162 | self.timers[updTimer] = { |
||
163 | timer = arg1, |
||
164 | value = arg2, |
||
165 | maxvalue = arg3, |
||
166 | scale = arg4, |
||
167 | paused = (arg5 > 0 and arg5 or nil), |
||
168 | label = arg6, |
||
169 | } |
||
170 | --self:Msg("Updating timer %d: %s, %d, %d, %d, %d, %s", updTimer, arg1, arg2, arg3, arg4, arg5, arg6) |
||
171 | end |
||
172 | if(ArcHUD.db.profile.FadeIC > ArcHUD.db.profile.FadeOOC) then |
||
173 | self.f:SetRingAlpha(ArcHUD.db.profile.FadeIC) |
||
174 | else |
||
175 | self.f:SetRingAlpha(ArcHUD.db.profile.FadeOOC) |
||
176 | end |
||
177 | end |
||
178 | |||
179 | function module:MIRROR_TIMER_PAUSE() |
||
180 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
181 | if(self.timers[i]) then |
||
182 | self.timers[i].paused = (arg1 > 0 and 1 or nil) |
||
183 | end |
||
184 | end |
||
185 | end |
||
186 | |||
187 | function module:MIRROR_TIMER_STOP() |
||
188 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
189 | if(self.timers[i] and self.timers[i].timer == arg1) then |
||
190 | if(self.timers[i+1]) then |
||
191 | self.timers[i] = self.timers[i+1] |
||
192 | self.timers[i+1] = nil |
||
193 | else |
||
194 | self.timers[i] = nil |
||
195 | end |
||
196 | self.timers.count = self.timers.count - 1 |
||
197 | --self:Msg("Stopping timer %d: %s", i, arg1) |
||
198 | end |
||
199 | end |
||
200 | if(self.timers.count == 0) then |
||
201 | --self:Msg("No timers left, hiding") |
||
202 | self.f:SetRingAlpha(0) |
||
203 | else |
||
204 | if(not self.timers[self.timer]) then |
||
205 | for i=MIRRORTIMER_NUMTIMERS,1,-1 do |
||
206 | if(self.timers[i]) then |
||
207 | self.timer = i |
||
208 | self.f:UpdateColor(MirrorTimerColors[self.timers[i].timer]) |
||
209 | break |
||
210 | end |
||
211 | end |
||
212 | end |
||
213 | end |
||
214 | end |
||
215 | |||
216 | function module:PLAYER_ENTERING_WORLD() |
||
217 | for i=1,MIRRORTIMER_NUMTIMERS do |
||
218 | self.timers[i] = nil |
||
219 | end |
||
220 | self.timers.count = 0 |
||
221 | self.f:SetRingAlpha(0) |
||
222 | end |