-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathIceCastBar.lua
786 lines (647 loc) · 24.5 KB
/
IceCastBar.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false)
IceCastBar = IceCore_CreateClass(IceBarElement)
local IceHUD = _G.IceHUD
IceCastBar.Actions = { None = 0, Cast = 1, Channel = 2, Instant = 3, Success = 4, Failure = 5, ReverseChannel = 6 }
IceCastBar.prototype.action = nil
IceCastBar.prototype.actionStartTime = nil
IceCastBar.prototype.actionDuration = nil
IceCastBar.prototype.actionMessage = nil
IceCastBar.prototype.unit = nil
IceCastBar.prototype.current = nil
local SPELL_POWER_MANA = SPELL_POWER_MANA
if Enum and Enum.PowerType then
SPELL_POWER_MANA = Enum.PowerType.Mana
end
local UnitCastingInfo, UnitChannelInfo = UnitCastingInfo, UnitChannelInfo
if not UnitCastingInfo then
UnitCastingInfo = CastingInfo
UnitChannelInfo = ChannelInfo
end
local GetSpellName = GetSpellInfo
if C_Spell and C_Spell.GetSpellName then
GetSpellName = C_Spell.GetSpellName
end
local GetSpellInfo = GetSpellInfo
if not GetSpellInfo and C_Spell and C_Spell.GetSpellInfo then
GetSpellInfo = function(spellID)
if not spellID then
return nil
end
local spellInfo = C_Spell.GetSpellInfo(spellID)
if spellInfo then
return spellInfo.name, nil, spellInfo.iconID, spellInfo.castTime, spellInfo.minRange, spellInfo.maxRange, spellInfo.spellID, spellInfo.originalIconID
end
end
end
-- Fulzamoth 2019-09-27 : Use LibClassicCasterino if it's there so we can use TargetCast
-- module in Classic WoW
if IceHUD.WowClassic then
LibClassicCasterino = LibStub("LibClassicCasterino", true)
if LibClassicCasterino then
UnitCastingInfo = function(unit)
return LibClassicCasterino:UnitCastingInfo(unit)
end
UnitChannelInfo = function(unit)
return LibClassicCasterino:UnitChannelInfo(unit)
end
end
end
-- end Fulzamoth change
local AuraIconWidth = 20
local AuraIconHeight = 20
-- Constructor --
function IceCastBar.prototype:init(name)
IceCastBar.super.prototype.init(self, name)
self:SetDefaultColor("CastCasting", 242, 242, 10)
self:SetDefaultColor("CastChanneling", 242, 242, 10)
self:SetDefaultColor("CastSuccess", 242, 242, 70)
self:SetDefaultColor("CastFail", 1, 0, 0)
if GetUnitEmpowerMinHoldTime then
self:SetDefaultColor("EmpowerStage0", 165, 165, 165)
self:SetDefaultColor("EmpowerStage1", 242, 42, 10)
self:SetDefaultColor("EmpowerStage2", 242, 142, 10)
self:SetDefaultColor("EmpowerStage3", 242, 242, 10)
self:SetDefaultColor("EmpowerStage4", 242, 242, 242)
end
self.unit = "player"
self.delay = 0
self.action = IceCastBar.Actions.None
end
-- 'Public' methods -----------------------------------------------------------
function IceCastBar.prototype:Enable(core)
IceCastBar.super.prototype.Enable(self, core)
-- Fulzamoth 2019-09-27 : LibClassicCasterino support
-- Setup callback to the library, and route events to
-- IceHUD's handler functions.
if LibClassicCasterino then
local CastbarEventHandler = function(event, ...) -- unitTarget, castGUID, spellID
if (event == "UNIT_SPELLCAST_START") then
return IceCastBar.prototype.SpellCastStart(self, event, ...)
elseif (event == "UNIT_SPELLCAST_DELAYED") then
return IceCastBar.prototype.SpellCastDelayed(self, event, ...)
elseif (event == "UNIT_SPELLCAST_STOP") then
return IceCastBar.prototype.SpellCastStop(self, event, ...)
elseif (event == "UNIT_SPELLCAST_FAILED") then
return IceCastBar.prototype.SpellCastFailed(self, event, ...)
elseif (event == "UNIT_SPELLCAST_INTERRUPTED") then
return IceCastBar.prototype.SpellCastInterrupted(self, event, ...)
elseif (event == "UNIT_SPELLCAST_CHANNEL_START") then
return IceCastBar.prototype.SpellCastChannelStart(self, event, ...)
elseif (event == "UNIT_SPELLCAST_CHANNEL_UPDATE") then
return IceCastBar.prototype.SpellCastChannelUpdate(self, event, ...)
elseif (event == "UNIT_SPELLCAST_CHANNEL_STOP") then
return IceCastBar.prototype.SpellCastChannelStop(self, event, ...)
end
end
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_START", CastbarEventHandler)
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_DELAYED", CastbarEventHandler) -- only for player
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_STOP", CastbarEventHandler)
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_FAILED", CastbarEventHandler)
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_INTERRUPTED", CastbarEventHandler)
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_CHANNEL_START", CastbarEventHandler)
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_CHANNEL_UPDATE", CastbarEventHandler) -- only for player
LibClassicCasterino.RegisterCallback(self,"UNIT_SPELLCAST_CHANNEL_STOP", CastbarEventHandler)
else -- No LibClassicCasterino, or we're not on Classic, so use IceHUD's normal event handlers.
self:RegisterEvent("UNIT_SPELLCAST_SENT", "SpellCastSent") -- "player", spell, rank, target
self:RegisterEvent("CURRENT_SPELL_CAST_CHANGED", "SpellCastChanged")
self:RegisterEvent("UNIT_SPELLCAST_START", "SpellCastStart") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_STOP", "SpellCastStop") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_FAILED", "SpellCastFailed") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_INTERRUPTED", "SpellCastInterrupted") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_DELAYED", "SpellCastDelayed") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED", "SpellCastSucceeded") -- "player", spell, rank
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START", "SpellCastChannelStart") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_UPDATE", "SpellCastChannelUpdate") -- unit, spell, rank
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_STOP", "SpellCastChannelStop") -- unit, spell, rank
if GetUnitEmpowerHoldAtMaxTime then
self:RegisterEvent("UNIT_SPELLCAST_EMPOWER_START", "SpellCastChannelStart")
self:RegisterEvent("UNIT_SPELLCAST_EMPOWER_UPDATE", "SpellCastChannelUpdate")
self:RegisterEvent("UNIT_SPELLCAST_EMPOWER_STOP", "SpellCastChannelStop")
end
end
self:Show(false)
end
function IceCastBar.prototype:GetDefaultSettings()
local settings = IceCastBar.super.prototype.GetDefaultSettings(self)
settings["showSpellRank"] = true
settings["showCastTime"] = true
settings["displayAuraIcon"] = false
settings["auraIconXOffset"] = 40
settings["auraIconYOffset"] = 0
settings["auraIconScale"] = 1
settings["reverseChannel"] = true
return settings
end
function IceCastBar.prototype:GetOptions()
local opts = IceCastBar.super.prototype.GetOptions(self)
opts["showCastTime"] =
{
type = 'toggle',
name = L["Show spell cast time"],
desc = L["Whether or not to show the remaining cast time of a spell being cast."],
get = function()
return self.moduleSettings.showCastTime
end,
set = function(info, value)
self.moduleSettings.showCastTime = value
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 39.998
}
if IceHUD.SpellFunctionsReturnRank then
opts["showSpellRank"] =
{
type = 'toggle',
name = L["Show spell rank"],
desc = L["Whether or not to show the rank of a spell being cast."],
get = function()
return self.moduleSettings.showSpellRank
end,
set = function(info, value)
self.moduleSettings.showSpellRank = value
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 39.999
}
end
opts["iconSettings"] = {
type = 'group',
name = "|c"..self.configColor..L["Icon Settings"].."|r",
args = {
displayAuraIcon = {
type = 'toggle',
name = L["Display aura icon"],
desc = L["Whether or not to display an icon for the aura that this bar is tracking"],
get = function()
return self.moduleSettings.displayAuraIcon
end,
set = function(info, v)
self.moduleSettings.displayAuraIcon = v
if self.barFrame.icon then
if v then
self.barFrame.icon:Show()
else
self.barFrame.icon:Hide()
end
end
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 51,
},
auraIconXOffset = {
type = 'range',
min = -250,
max = 250,
step = 1,
name = L["Aura icon horizontal offset"],
desc = L["Adjust the horizontal position of the aura icon"],
get = function()
return self.moduleSettings.auraIconXOffset
end,
set = function(info, v)
self.moduleSettings.auraIconXOffset = v
self:PositionIcons()
end,
disabled = function()
return not self.moduleSettings.enabled or not self.moduleSettings.displayAuraIcon
end,
order = 52,
},
auraIconYOffset = {
type = 'range',
min = -250,
max = 250,
step = 1,
name = L["Aura icon vertical offset"],
desc = L["Adjust the vertical position of the aura icon"],
get = function()
return self.moduleSettings.auraIconYOffset
end,
set = function(info, v)
self.moduleSettings.auraIconYOffset = v
self:PositionIcons()
end,
disabled = function()
return not self.moduleSettings.enabled or not self.moduleSettings.displayAuraIcon
end,
order = 53,
},
auraIconScale = {
type = 'range',
min = 0.1,
max = 3.0,
step = 0.05,
name = L["Aura icon scale"],
desc = L["Adjusts the size of the aura icon for this bar"],
get = function()
return self.moduleSettings.auraIconScale
end,
set = function(info, v)
self.moduleSettings.auraIconScale = v
self:PositionIcons()
end,
disabled = function()
return not self.moduleSettings.enabled or not self.moduleSettings.displayAuraIcon
end,
order = 54,
},
},
}
opts["reverseChannel"] = {
type = 'toggle',
name = L["Reverse channeling"],
desc = L["Whether or not to reverse the direction of the cast bar when a spell is being channeled. For example, if a normal cast causes this bar to fill up, then checking this option will cause a channeled spell to empty the bar instead."],
get = function()
return self.moduleSettings.reverseChannel
end,
set = function(info, v)
self.moduleSettings.reverseChannel = v
end,
disabled = function()
return not self.moduleSettings.enabled
end,
order = 32.5,
}
return opts
end
function IceCastBar.prototype:IsFull(scale)
local retval = IceCastBar.super.prototype.IsFull(self, scale)
if retval then
if self.action and self.action ~= IceCastBar.Actions.None then
return false
end
end
return retval
end
-- 'Protected' methods --------------------------------------------------------
-- OVERRIDE
function IceCastBar.prototype:CreateFrame()
IceCastBar.super.prototype.CreateFrame(self)
self.frame.bottomUpperText:SetWidth(self.settings.gap + 30)
if not self.barFrame.icon then
self.barFrame.icon = self.masterFrame:CreateTexture(nil, "OVERLAY")
-- default texture so that 'config mode' can work without activating the bar first
self.barFrame.icon:SetTexture("Interface\\Icons\\Spell_Frost_Frost")
-- this cuts off the border around the buff icon
self.barFrame.icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
end
self:PositionIcons()
end
function IceCastBar.prototype:PositionIcons()
if not self.barFrame or not self.barFrame.icon then
return
end
self.barFrame.icon:ClearAllPoints()
self.barFrame.icon:SetPoint("TOPLEFT", self.frame, "TOPLEFT", self.moduleSettings.auraIconXOffset, self.moduleSettings.auraIconYOffset)
self.barFrame.icon:SetWidth(AuraIconWidth * self.moduleSettings.auraIconScale)
self.barFrame.icon:SetHeight(AuraIconHeight * self.moduleSettings.auraIconScale)
end
function IceCastBar.prototype:GetRemainingCastTime()
return self.actionStartTime + self.actionDuration - GetTime()
end
function IceCastBar.prototype:GetCurrentCastDurationMs()
return (GetTime() - (self.actionStartTime or GetTime())) * 1000
end
-- OnUpdate handler
function IceCastBar.prototype:MyOnUpdate()
-- safety catch
if (self.action == IceCastBar.Actions.None) then
--IceHUD:Debug("Stopping action ", self.action)
self:StopBar()
return
end
self:Update()
self:SetTextAlpha()
-- handle casting and channeling
if (self.action == IceCastBar.Actions.Cast or self.action == IceCastBar.Actions.Channel or self.action == IceCastBar.Actions.ReverseChannel) then
local remainingTime = self:GetRemainingCastTime()
local scale = 1 - (self.actionDuration ~= 0 and remainingTime / self.actionDuration or 0)
if self.action == IceCastBar.Actions.ReverseChannel then
scale = self.actionDuration ~= 0 and remainingTime / self.actionDuration or 0
end
self:UpdateBar(IceHUD:Clamp(scale, 0, 1), self:GetCurrentCastingColor())
if (remainingTime <= 0) then
self:StopBar()
end
local timeString = self.moduleSettings.showCastTime and string.format("%.1fs ", remainingTime) or ""
local empowerString = self.NumStages ~= nil and (L["Stage %d"]):format(self:GetCurrentStage()) or ""
local line1 = timeString .. (self.actionMessage or "")
if self.moduleSettings.empowerStageTextDisplay == "TOPLINE" then
line1 = line1 .. " " .. empowerString
end
if self.moduleSettings.empowerStageTextDisplay == "BOTTOMLINE" then
self:SetBottomText2(empowerString)
end
self:SetBottomText1(line1)
return
end
-- stop bar if casting or channeling is done (in theory this should not be needed)
if (self.action == IceCastBar.Actions.Cast or self.action == IceCastBar.Actions.Channel or self.action == IceCastBar.Actions.ReverseChannel) then
self:StopBar()
return
end
-- handle bar flashes
if (self.action == IceCastBar.Actions.Instant or
self.action == IceCastBar.Actions.Success or
self.action == IceCastBar.Actions.Failure)
then
local scale
if self.actionStartTime then
scale = GetTime() - self.actionStartTime
end
if scale and (scale > 1) then
self:StopBar()
return
end
self:UpdateBar(1, self:GetCurrentCastingColor())
if scale then
if (self.action == IceCastBar.Actions.Failure) then
self:FlashBar("CastFail", 1-scale, self.actionMessage, "CastFail")
else
self:FlashBar("CastSuccess", 1-scale, self.actionMessage)
end
end
return
end
-- something went wrong
IceHUD:Debug("OnUpdate error ", self.action, " -- ", self.actionStartTime, self.actionDuration, self.actionMessage)
self:StopBar()
end
function IceCastBar.prototype:GetStageDuration(stage)
if not GetUnitEmpowerMinHoldTime then
return 0
end
if stage == 0 then
return GetUnitEmpowerMinHoldTime(self.unit)
end
return GetUnitEmpowerStageDuration(self.unit, stage);
end
function IceCastBar.prototype:GetDurationUpToStage(stage)
if stage == nil or stage < 0 then
return 0
end
local total = 0
for i=0,stage-1 do
total = total + self:GetStageDuration(i)
end
return total
end
function IceCastBar.prototype:GetCurrentStage()
if not GetUnitEmpowerMinHoldTime then
return 0
end
local castDuration = self:GetCurrentCastDurationMs()
for i=1,self.NumStages do
if castDuration < self:GetDurationUpToStage(i) then
return i - 1
end
end
return self.NumStages
end
function IceCastBar.prototype:IsCastingEmpowerSpell()
return self.NumStages ~= nil
end
function IceCastBar.prototype:GetCurrentCastingColor()
if self:IsCastingEmpowerSpell() then
return ("EmpowerStage%d"):format(self:GetCurrentStage())
end
if self.action == IceCastBar.Actions.Channel or self.action == IceCastBar.Actions.ReverseChannel then
return "CastChanneling"
end
return "CastCasting"
end
function IceCastBar.prototype:FlashBar(color, alpha, text, textColor)
if self.moduleSettings.flashInstants == "Never" then
return
end
if alpha then
self.frame:SetAlpha(alpha)
end
local r, g, b = self.settings.backgroundColor.r, self.settings.backgroundColor.g, self.settings.backgroundColor.b
if (self.settings.backgroundToggle) then
r, g, b = self:GetColor(color)
end
self.frame.bg:SetVertexColor(r, g, b, 0.3)
self.barFrame.bar:SetVertexColor(self:GetColor(color, 0.8))
self:SetScale(1)
self:SetBottomText1(text, textColor or "Text")
end
function IceCastBar.prototype:StartBar(action, message, spellId)
local spell, rank, displayName, icon, startTime, endTime, isTradeSkill, numStages
if IceHUD.SpellFunctionsReturnRank then
spell, rank, displayName, icon, startTime, endTime, isTradeSkill = UnitCastingInfo(self.unit)
else
spell, displayName, icon, startTime, endTime, isTradeSkill = UnitCastingInfo(self.unit)
end
if not (spell) then
if IceHUD.SpellFunctionsReturnRank then
spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(self.unit)
else
spell, displayName, icon, startTime, endTime, isTradeSkill, _, _, _, numStages = UnitChannelInfo(self.unit)
end
end
if spellId and not spell then
spell, rank, icon = GetSpellInfo(spellId)
end
local isChargeSpell = numStages and numStages > 0
if isChargeSpell then
self.NumStages = numStages
endTime = endTime + GetUnitEmpowerHoldAtMaxTime(self.unit)
action = IceCastBar.Actions.ReverseChannel
else
self.NumStages = nil
end
if self.moduleSettings.reverseChannel then
if action == IceCastBar.Actions.Channel then
action = IceCastBar.Actions.ReverseChannel
elseif action == IceCastBar.Actions.ReverseChannel then
action = IceCastBar.Actions.Channel
end
end
-- Fulzamoth 2019-09-27 : LibClassicCasterino won't return spell info on target's failed or interrupted cast
if LibClassicCasterino and not spell then
self:StopBar()
elseif not spell then
return
end
if icon ~= nil then
self.barFrame.icon:SetTexture(icon)
end
if IceHUD.IceCore:IsInConfigMode() or self.moduleSettings.displayAuraIcon then
self.barFrame.icon:Show()
else
self.barFrame.icon:Hide()
end
self.action = action
self.actionStartTime = GetTime()
self.actionMessage = message
if (startTime and endTime) then
self.actionDuration = (endTime - startTime) / 1000
-- set start time here in case we start to monitor a cast that is underway already
self.actionStartTime = startTime / 1000
else
self.actionDuration = 1 -- instants/failures
end
if not (message) and spell then
self.actionMessage = spell .. (self.moduleSettings.showSpellRank and self:GetShortRank(rank) or "")
end
self:Show(true)
self:ConditionalSetupUpdate()
end
function IceCastBar.prototype:StopBar()
self.action = IceCastBar.Actions.None
self.actionStartTime = nil
self.actionDuration = nil
self:SetBottomText1()
self:SetBottomText2()
self:SetScale(0)
self:Show(false)
end
function IceCastBar.prototype:GetShortRank(rank)
if IceHUD.SpellFunctionsReturnRank and rank then
local _, _, sRank = string.find(rank, "(%d+)")
if (sRank) then
return " (" .. sRank .. ")"
end
end
return ""
end
-------------------------------------------------------------------------------
-- NORMAL SPELLS --
-------------------------------------------------------------------------------
function IceCastBar.prototype:SpellCastSent(event, unit, target, castGuid, spellId)
if (unit ~= self.unit) then return end
IceHUD:Debug("SpellCastSent", unit, target, castGuid, spellId)
end
function IceCastBar.prototype:SpellCastChanged(event, cancelled)
IceHUD:Debug("SpellCastChanged", cancelled)
end
function IceCastBar.prototype:SpellCastStart(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
IceHUD:Debug("SpellCastStart", unit, castGuid, spellId)
--UnitCastingInfo(unit)
self:StartBar(IceCastBar.Actions.Cast, nil, spellId)
self.current = castGuid
end
function IceCastBar.prototype:SpellCastStop(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
IceHUD:Debug("SpellCastStop", unit, castGuid, spellId)
-- ignore if not coming from current spell
if (self.current and castGuid and self.current ~= castGuid) then
return
end
if (self.action ~= IceCastBar.Actions.Success and
self.action ~= IceCastBar.Actions.Failure and
self.action ~= IceCastBar.Actions.Channel and
self.action ~= IceCastBar.Actions.ReverseChannel)
then
self:StopBar()
end
self.current = nil
end
function IceCastBar.prototype:SpellCastFailed(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
IceHUD:Debug("SpellCastFailed", unit, castGuid, spellId)
-- ignore if not coming from current spell
if (self.current and castGuid and self.current ~= castGuid) then
return
end
-- channeled spells will call ChannelStop, not cast failed
if self.action == IceCastBar.Actions.Channel or self.action == IceCastBar.Actions.ReverseChannel then
return
end
self.current = nil
-- determine if we want to show failed casts
if (self.moduleSettings.flashFailures == "Never") then
return
elseif (self.moduleSettings.flashFailures == "Caster") then
if (UnitPowerType("player") ~= SPELL_POWER_MANA) then
return
end
end
self:StartBar(IceCastBar.Actions.Failure, "Failed", nil, spellId)
end
function IceCastBar.prototype:SpellCastInterrupted(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
IceHUD:Debug("SpellCastInterrupted", unit, castGuid, spellId)
-- ignore if not coming from current spell
if (self.current and castGuid and self.current ~= castGuid) then
return
end
self.current = nil
self:StartBar(IceCastBar.Actions.Failure, "Interrupted", spellId)
end
function IceCastBar.prototype:SpellCastDelayed(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
--IceHUD:Debug("SpellCastDelayed", unit, UnitCastingInfo(unit))
local endTime = select(IceHUD.SpellFunctionsReturnRank and 6 or 5, UnitCastingInfo(self.unit))
if (endTime and self.actionStartTime) then
-- apparently this check is needed, got nils during a horrible lag spike
self.actionDuration = endTime/1000 - self.actionStartTime
end
end
function IceCastBar.prototype:SpellCastSucceeded(event, unit, castGuid, spellId)
if (unit ~= self.unit) then return end
--IceHUD:Debug("SpellCastSucceeded", unit, castGuid, spellId)
-- never show on channeled (why on earth does this event even fire when channeling starts?)
if (self.action == IceCastBar.Actions.Channel or self.action == IceCastBar.Actions.ReverseChannel) then
return
end
-- ignore if not coming from current spell
if (self.current and self.current ~= castGuid) then
return
end
local spell = GetSpellName(spellId)
-- show after normal successfull cast
if (self.action == IceCastBar.Actions.Cast) then
self:StartBar(IceCastBar.Actions.Success, spell, spellId)
return
end
-- determine if we want to show instant casts
if (self.moduleSettings.flashInstants == "Never") then
return
elseif (self.moduleSettings.flashInstants == "Caster") then
if (UnitPowerType("player") ~= SPELL_POWER_MANA) then
return
end
end
-- handle special spells that are used for quests or other things that don't apply to the player
if self.unit == "player" and not IsPlayerSpell(spellId) then
return
end
self:StartBar(IceCastBar.Actions.Success, spell, spellId)
end
-------------------------------------------------------------------------------
-- CHANNELING SPELLS --
-------------------------------------------------------------------------------
function IceCastBar.prototype:SpellCastChannelStart(event, unit)
if (unit ~= self.unit) then return end
--IceHUD:Debug("SpellCastChannelStart", unit)
self:StartBar(IceCastBar.Actions.Channel)
end
function IceCastBar.prototype:SpellCastChannelUpdate(event, unit)
if (unit ~= self.unit or not self.actionStartTime) then return end
--IceHUD:Debug("SpellCastChannelUpdate", unit, UnitChannelInfo(unit))
local spell, rank, displayName, icon, startTime, endTime
if IceHUD.SpellFunctionsReturnRank then
spell, rank, displayName, icon, startTime, endTime = UnitChannelInfo(unit)
else
spell, displayName, icon, startTime, endTime = UnitChannelInfo(unit)
end
if not spell then
self.actionDuration = 0
else
self.actionDuration = endTime/1000 - self.actionStartTime
end
end
function IceCastBar.prototype:SpellCastChannelStop(event, unit)
if (unit ~= self.unit) then return end
--IceHUD:Debug("SpellCastChannelStop", unit)
self:StopBar()
end