vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -- ArcaneBar |
2 | -- Adds a second casting bar to the player frame. |
||
3 | -- |
||
4 | -- By: Zlixar |
||
5 | -- |
||
6 | -- Adds a second casting bar to the player frame. |
||
7 | -- |
||
8 | -- Modified by Nymbia for Nymbia's Perl Unitframes |
||
9 | |||
10 | ----------------------------- |
||
11 | -- Configuration Functions -- |
||
12 | ----------------------------- |
||
13 | |||
14 | -- Registers frame to spellcast events. |
||
15 | |||
16 | local XPerl_ArcaneBar_Colors = { |
||
17 | main = {r = 1.0, g = 0.7, b = 0.0}, |
||
18 | channel = {r = 0.0, g = 1.0, b = 0.0}, |
||
19 | success = {r = 0.0, g = 1.0, b = 0.0}, |
||
20 | failure = {r = 1.0, g = 0.0, b = 0.0} |
||
21 | } |
||
22 | |||
23 | local events = {"SPELLCAST_START", "SPELLCAST_STOP", "SPELLCAST_FAILED", "SPELLCAST_INTERRUPTED", |
||
24 | "SPELLCAST_DELAYED", "SPELLCAST_CHANNEL_START", "SPELLCAST_CHANNEL_UPDATE"} |
||
25 | |||
26 | function XPerl_ArcaneBar_Register(frame) |
||
27 | for i,event in pairs(events) do |
||
28 | frame:RegisterEvent(event) |
||
29 | end |
||
30 | frame:SetScript("OnUpdate", XPerl_ArcaneBar_OnUpdate) |
||
31 | end |
||
32 | |||
33 | -- Unregisters from spellcast events. |
||
34 | function XPerl_ArcaneBar_Unregister(frame) |
||
35 | for i,event in pairs(events) do |
||
36 | frame:UnregisterEvent(event) |
||
37 | end |
||
38 | frame:SetScript("OnUpdate", nil) |
||
39 | end |
||
40 | |||
41 | -- XPerl_ArcaneBar_EnableToggle |
||
42 | function XPerl_ArcaneBar_EnableToggle(value) |
||
43 | if (value == 1) then |
||
44 | if (XPerl_ArcaneBarFrame.Enabled ~= 1) then |
||
45 | XPerl_ArcaneBar_Register(XPerl_ArcaneBarFrame) |
||
46 | XPerl_ArcaneBarFrame.Enabled = 1 |
||
47 | end |
||
48 | else |
||
49 | if (XPerl_ArcaneBarFrame.Enabled == 1) then |
||
50 | XPerl_ArcaneBar_Unregister(XPerl_ArcaneBarFrame) |
||
51 | XPerl_ArcaneBarFrame.Enabled = 0 |
||
52 | XPerl_ArcaneBarFrame:Hide() |
||
53 | end |
||
54 | end |
||
55 | end |
||
56 | |||
57 | -- XPerl_ArcaneBar_OverrideToggle |
||
58 | function XPerl_ArcaneBar_OverrideToggle(value) |
||
59 | if (value == 1) then |
||
60 | if (XPerl_ArcaneBarFrame.Overrided ~= 1) then |
||
61 | XPerl_ArcaneBar_Unregister(CastingBarFrame) |
||
62 | XPerl_ArcaneBarFrame.Overrided = 1 |
||
63 | end |
||
64 | else |
||
65 | if (XPerl_ArcaneBarFrame.Overrided == 1) then |
||
66 | XPerl_ArcaneBar_Register(CastingBarFrame) |
||
67 | XPerl_ArcaneBarFrame.Overrided = 0 |
||
68 | end |
||
69 | end |
||
70 | end |
||
71 | |||
72 | -------------------------------------------------- |
||
73 | -- |
||
74 | -- Event/Update Handlers |
||
75 | -- |
||
76 | -------------------------------------------------- |
||
77 | |||
78 | -- XPerl_ArcaneBar_OnEvent |
||
79 | function XPerl_ArcaneBar_OnEvent() |
||
80 | if ( event == "SPELLCAST_START" ) then |
||
81 | XPerl_ArcaneBar:SetStatusBarColor(XPerl_ArcaneBar_Colors.main.r, XPerl_ArcaneBar_Colors.main.g, XPerl_ArcaneBar_Colors.main.b, XPerlConfig.Transparency) |
||
82 | XPerl_ArcaneBarSpark:Show() |
||
83 | this.startTime = GetTime() |
||
84 | this.maxValue = this.startTime + (arg2 / 1000) |
||
85 | XPerl_ArcaneBar:SetMinMaxValues(this.startTime, this.maxValue) |
||
86 | XPerl_ArcaneBar:SetValue(this.startTime) |
||
87 | this:SetAlpha(0.8) |
||
88 | this.holdTime = 0 |
||
89 | this.casting = 1 |
||
90 | this.fadeOut = nil |
||
91 | this:Show() |
||
92 | this.delaySum = 0 |
||
93 | if XPerlConfig.CastTime==1 then XPerl_ArcaneBar_CastTime:Show(); else XPerl_ArcaneBar_CastTime:Hide(); end |
||
94 | this.mode = "casting" |
||
95 | elseif ( event == "SPELLCAST_STOP" ) then |
||
96 | this.delaySum = 0 |
||
97 | this.sign = "+" |
||
98 | if (not this.casting) then |
||
99 | XPerl_ArcaneBar_CastTime:Hide() |
||
100 | end |
||
101 | if ( not this:IsVisible() ) then |
||
102 | this:Hide() |
||
103 | end |
||
104 | if ( this:IsShown() ) then |
||
105 | XPerl_ArcaneBar:SetValue(this.maxValue) |
||
106 | XPerl_ArcaneBar:SetStatusBarColor(XPerl_ArcaneBar_Colors.success.r, XPerl_ArcaneBar_Colors.success.g, XPerl_ArcaneBar_Colors.success.b, XPerlConfig.Transparency) |
||
107 | XPerl_ArcaneBarSpark:Hide() |
||
108 | XPerl_ArcaneBarFlash:SetAlpha(0.0) |
||
109 | XPerl_ArcaneBarFlash:Show() |
||
110 | this.casting = nil |
||
111 | this.flash = 1 |
||
112 | this.fadeOut = 1 |
||
113 | |||
114 | this.mode = "flash" |
||
115 | end |
||
116 | elseif ( event == "SPELLCAST_FAILED" or event == "SPELLCAST_INTERRUPTED" ) then |
||
117 | if ( this:IsShown() ) then |
||
118 | XPerl_ArcaneBar:SetValue(this.maxValue) |
||
119 | XPerl_ArcaneBar:SetStatusBarColor(XPerl_ArcaneBar_Colors.failure.r, XPerl_ArcaneBar_Colors.failure.g, XPerl_ArcaneBar_Colors.failure.b, XPerlConfig.Transparency) |
||
120 | XPerl_ArcaneBarSpark:Hide() |
||
121 | this.casting = nil |
||
122 | this.fadeOut = 1 |
||
123 | this.holdTime = GetTime() + CASTING_BAR_HOLD_TIME |
||
124 | end |
||
125 | elseif ( event == "SPELLCAST_DELAYED" ) then |
||
126 | if( this:IsShown() ) then |
||
127 | if arg1 then |
||
128 | this.startTime = this.startTime + (arg1 / 1000) |
||
129 | this.maxValue = this.maxValue + (arg1 / 1000) |
||
130 | this.delaySum = this.delaySum + arg1 |
||
131 | XPerl_ArcaneBar:SetMinMaxValues(this.startTime, this.maxValue) |
||
132 | end |
||
133 | end |
||
134 | elseif ( event == "SPELLCAST_CHANNEL_START" ) then |
||
135 | XPerl_ArcaneBar:SetStatusBarColor(XPerl_ArcaneBar_Colors.channel.r, XPerl_ArcaneBar_Colors.channel.g, XPerl_ArcaneBar_Colors.channel.b, XPerlConfig.Transparency) |
||
136 | XPerl_ArcaneBarSpark:Show() |
||
137 | this.maxValue = 1 |
||
138 | this.startTime = GetTime() |
||
139 | this.endTime = this.startTime + (arg1 / 1000) |
||
140 | this.duration = arg1 / 1000 |
||
141 | XPerl_ArcaneBar:SetMinMaxValues(this.startTime, this.endTime) |
||
142 | XPerl_ArcaneBar:SetValue(this.endTime) |
||
143 | this:SetAlpha(1.0) |
||
144 | this.holdTime = 0 |
||
145 | this.casting = nil |
||
146 | this.channeling = 1 |
||
147 | this.fadeOut = nil |
||
148 | this:Show() |
||
149 | this.delaySum = 0 |
||
150 | if XPerlConfig.CastTime==1 then XPerl_ArcaneBar_CastTime:Show(); else XPerl_ArcaneBar_CastTime:Hide(); end |
||
151 | |||
152 | elseif ( event == "SPELLCAST_CHANNEL_UPDATE" ) then |
||
153 | if ( arg1 == 0 ) then |
||
154 | this.channeling = nil |
||
155 | this.delaySum = 0 |
||
156 | XPerl_ArcaneBar_CastTime:Hide() |
||
157 | elseif ( this:IsShown() ) then |
||
158 | local origDuration = this.endTime - this.startTime |
||
159 | local elapsedTime = GetTime() - this.startTime |
||
160 | local losttime = origDuration*1000 - elapsedTime*1000 - arg1 |
||
161 | this.delaySum = this.delaySum + losttime |
||
162 | this.startTime = this.endTime - origDuration |
||
163 | this.endTime = GetTime() + (arg1 / 1000) |
||
164 | XPerl_ArcaneBar:SetMinMaxValues(this.startTime, this.endTime) |
||
165 | |||
166 | end |
||
167 | else |
||
168 | this.delaySum = 0 |
||
169 | this.sign = "+" |
||
170 | XPerl_ArcaneBar_CastTime:Hide() |
||
171 | end |
||
172 | end |
||
173 | |||
174 | -- XPerl_ArcaneBar_OnUpdate |
||
175 | function XPerl_ArcaneBar_OnUpdate() |
||
176 | if (not XPerl_ArcaneBar:IsShown()) then |
||
177 | XPerl_ArcaneBar_CastTime:Hide() |
||
178 | end |
||
179 | local current_time = this.maxValue - GetTime() |
||
180 | if (this.channeling) then |
||
181 | current_time = this.endTime - GetTime() |
||
182 | end |
||
183 | |||
184 | |||
185 | local text = string.sub(math.max(current_time,0)+0.001,1,4) |
||
186 | if (this.delaySum and this.delaySum ~= 0) then |
||
187 | local delay = string.sub(math.max(this.delaySum/1000, 0)+0.001,1,4) |
||
188 | |||
189 | if (this.channeling == 1) then |
||
190 | this.sign = "-" |
||
191 | else |
||
192 | this.sign = "+" |
||
193 | end |
||
194 | text = "|cffcc0000"..this.sign..delay.."|r "..text |
||
195 | end |
||
196 | XPerl_ArcaneBar_CastTime:SetText(text) |
||
197 | |||
198 | |||
199 | if ( this.casting ) then |
||
200 | local status = GetTime() |
||
201 | if ( status > this.maxValue ) then |
||
202 | status = this.maxValue |
||
203 | end |
||
204 | XPerl_ArcaneBar:SetValue(status) |
||
205 | XPerl_ArcaneBarFlash:Hide() |
||
206 | local sparkPosition = ((status - this.startTime) / (this.maxValue - this.startTime)) * 154 |
||
207 | if ( sparkPosition < 0 ) then |
||
208 | sparkPosition = 0 |
||
209 | end |
||
210 | XPerl_ArcaneBarSpark:SetPoint("CENTER", "XPerl_ArcaneBar", "LEFT", sparkPosition, 0) |
||
211 | elseif ( this.channeling ) then |
||
212 | local time = GetTime() |
||
213 | if ( time > this.endTime ) then |
||
214 | time = this.endTime |
||
215 | end |
||
216 | if ( time == this.endTime ) then |
||
217 | this.channeling = nil |
||
218 | this.fadeOut = 1 |
||
219 | return |
||
220 | end |
||
221 | local barValue = this.startTime + (this.endTime - time) |
||
222 | XPerl_ArcaneBar:SetValue( barValue ) |
||
223 | XPerl_ArcaneBarFlash:Hide() |
||
224 | local sparkPosition = ((barValue - this.startTime) / (this.endTime - this.startTime)) * 154 |
||
225 | XPerl_ArcaneBarSpark:SetPoint("CENTER", "XPerl_ArcaneBar", "LEFT", sparkPosition, 0) |
||
226 | elseif ( GetTime() < this.holdTime ) then |
||
227 | return |
||
228 | elseif ( this.flash ) then |
||
229 | local alpha = XPerl_ArcaneBarFlash:GetAlpha() + CASTING_BAR_FLASH_STEP |
||
230 | if ( alpha < 1 ) then |
||
231 | XPerl_ArcaneBarFlash:SetAlpha(alpha) |
||
232 | else |
||
233 | this.flash = nil |
||
234 | end |
||
235 | elseif ( this.fadeOut ) then |
||
236 | local alpha = this:GetAlpha() - CASTING_BAR_ALPHA_STEP |
||
237 | if ( alpha > 0 ) then |
||
238 | this:SetAlpha(alpha) |
||
239 | else |
||
240 | this.fadeOut = nil |
||
241 | this:Hide() |
||
242 | end |
||
243 | end |
||
244 | end |
||
245 | |||
246 | -- XPerl_ArcaneBar_OnLoad |
||
247 | function XPerl_ArcaneBar_OnLoad() |
||
248 | XPerl_ArcaneBar:SetFrameLevel(XPerl_Player_NameFrame:GetFrameLevel() + 1) |
||
249 | --XPerl_Player_Name:SetFrameLevel(XPerl_Player_NameFrame:GetFrameLevel() + 2) |
||
250 | XPerl_ArcaneBarFlashTex:SetTexture("Interface\\AddOns\\XPerl\\Images\\XPerl_ArcaneBarFlash") |
||
251 | XPerl_ArcaneBarTex:SetTexture("Interface\\AddOns\\XPerl\\Images\\XPerl_StatusBar") |
||
252 | this.casting = nil |
||
253 | this.holdTime = 0 |
||
254 | this.Enabled = 0 |
||
255 | this.Overrided = 0 |
||
256 | end |
||
257 | |||
258 | -- XPerl_ArcaneBar_Set |
||
259 | function XPerl_ArcaneBar_Set() |
||
260 | if (XPerl_ArcaneBarFrame) then |
||
261 | if (XPerlConfig.ArcaneBar == 0) then |
||
262 | XPerl_ArcaneBar_EnableToggle(0) |
||
263 | else |
||
264 | XPerl_ArcaneBar_EnableToggle(1) |
||
265 | end |
||
266 | |||
267 | if (XPerlConfig.OldCastBar == 0) then |
||
268 | XPerl_ArcaneBar_OverrideToggle(1) |
||
269 | else |
||
270 | XPerl_ArcaneBar_OverrideToggle(0) |
||
271 | end |
||
272 | end |
||
273 | end |