-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathIceHUD.lua
850 lines (738 loc) · 24.6 KB
/
IceHUD.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
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
local L = LibStub("AceLocale-3.0"):GetLocale("IceHUD", false)
IceHUD = LibStub("AceAddon-3.0"):NewAddon("IceHUD", "AceConsole-3.0", "AceHook-3.0")
local IceHUD = IceHUD
local SML = LibStub("LibSharedMedia-3.0")
local ACR = LibStub("AceConfigRegistry-3.0")
local ConfigDialog = LibStub("AceConfigDialog-3.0")
local icon = LibStub("LibDBIcon-1.0", true)
local pendingModuleLoads = {}
local bReadyToRegisterModules = false
local LoadAddOn = C_AddOns and C_AddOns.LoadAddOn or LoadAddOn
IceHUD.UnitAura = UnitAura
if not IceHUD.UnitAura then
IceHUD.UnitAura = function(unitToken, index, filter)
local auraData = C_UnitAuras.GetAuraDataByIndex(unitToken, index, filter)
if not auraData then
return nil
end
return AuraUtil.UnpackAuraData(auraData)
end
end
IceHUD.CurrTagVersion = 3
IceHUD.debugging = false
IceHUD.WowVer = select(4, GetBuildInfo())
IceHUD.WowMain = not WOW_PROJECT_ID or WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
if GetClassicExpansionLevel then
IceHUD.WowClassic = GetClassicExpansionLevel() == 0
IceHUD.WowClassicBC = GetClassicExpansionLevel() == 1
IceHUD.WowClassicWrath = GetClassicExpansionLevel() == 2
IceHUD.WowClassicCataclysm = GetClassicExpansionLevel() == 3
else
IceHUD.WowClassic = WOW_PROJECT_ID and WOW_PROJECT_ID == WOW_PROJECT_CLASSIC
IceHUD.WowClassicBC = false
IceHUD.WowClassicWrath = false
IceHUD.WowClassicCataclysm = false
if WOW_PROJECT_ID and WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC then
if not LE_EXPANSION_LEVEL_CURRENT or LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_BURNING_CRUSADE then
IceHUD.WowClassicBC = true
elseif LE_EXPANSION_LEVEL_CURRENT == LE_EXPANSION_WRATH_OF_THE_LICH_KING then
IceHUD.WowClassicWrath = true
end
elseif WOW_PROJECT_WRATH_CLASSIC and WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC then
IceHUD.WowClassicWrath = true
elseif WOW_PROJECT_CATACLYSM_CLASSIC and WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC then
IceHUD.WowClassicCataclysm = true
end
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
local GetSpellName = GetSpellInfo
if C_Spell and C_Spell.GetSpellName then
GetSpellName = C_Spell.GetSpellName
end
-- compatibility/feature flags
IceHUD.CanShowTargetCasting = not IceHUD.WowClassic or LibClassicCasterino or (IceHUD.WowClassic and IceHUD.WowVer >= 11500)
IceHUD.GetPlayerAuraBySpellID = _G["C_UnitAuras"] and C_UnitAuras.GetPlayerAuraBySpellID
IceHUD.SpellFunctionsReturnRank = IceHUD.WowMain and IceHUD.WowVer < 80000
IceHUD.EventExistsPlayerPetChanged = IceHUD.WowMain and IceHUD.WowVer < 80000
IceHUD.EventExistsPetBarChanged = IceHUD.WowMain and IceHUD.WowVer < 80000
IceHUD.EventExistsPlayerComboPoints = IceHUD.WowMain and IceHUD.WowVer < 30000
IceHUD.EventExistsUnitComboPoints = IceHUD.WowMain and IceHUD.WowVer < 70000
IceHUD.EventExistsUnitMaxPower = IceHUD.WowMain and IceHUD.WowVer >= 40000
IceHUD.EventExistsGroupRosterUpdate = IceHUD.WowVer >= 50000 or not IceHUD.WowMain
IceHUD.EventExistsUnitDynamicFlags = IceHUD.WowMain and IceHUD.WowVer < 80000
IceHUD.EventExistsUnitHealthFrequent = not IceHUD.WowMain or (IceHUD.WowVer >= 40000 and IceHUD.WowVer < 90000)
IceHUD.PerPowerEventsExist = IceHUD.WowMain and IceHUD.WowVer < 40000
IceHUD.PerTargetComboPoints = IceHUD.WowVer < 60000
IceHUD.CanTrackOtherUnitBuffs = not IceHUD.WowClassic or IceHUD.WowVer >= 11500
IceHUD.CanTrackGCD = not IceHUD.WowClassic or IceHUD.WowVer >= 11500
IceHUD.GetSpellInfoReturnsFunnel = IceHUD.WowMain and IceHUD.WowVer < 60000
IceHUD.CanHookDestroyTotem = IceHUD.WowClassic or IceHUD.WowClassicBC or IceHUD.WowClassicWrath or IceHUD.WowClassicCataclysm
IceHUD.ShouldUpdateTargetHealthEveryTick = (IceHUD.WowClassic or IceHUD.WowClassicBC) and GetCVarBool("predictedHealth")
IceHUD.UsesUIPanelButtonTemplate = IceHUD.WowVer >= 50000 or not IceHUD.WowMain
IceHUD.EventExistsSpellcastInterruptible = IceHUD.WowVer >= 30200 and not IceHUD.WowClassicWrath
IceHUD.DeathKnightUnholyFrostRunesSwapped = IceHUD.WowVer < 70300 and not IceHUD.WowClassicWrath and not IceHUD.WowClassicCataclysm
IceHUD.SupportsHealPrediction = IceHUD.WowVer >= 40000 or IceHUD.WowClassicWrath
IceHUD.UnitGroupRolesReturnsRoleString = IceHUD.WowVer >= 40000 or IceHUD.WowClassicWrath
IceHUD.ShellGameSpellID = 271571
IceHUD.HasShellGame = GetSpellName(IceHUD.ShellGameSpellID)
IceHUD.CatalogingSpellIDs = {366290, 372817, 385025, 385635, 386070, 386504, 400043, 403115}
IceHUD.HasCataloging = GetSpellName(366290)
IceHUD.UnitPowerEvent = "UNIT_POWER_UPDATE"
IceHUD.validBarList = { "Bar", "HiBar", "RoundBar", "ColorBar", "RivetBar", "RivetBar2", "CleanCurves", "GlowArc",
"BloodGlaives", "ArcHUD", "FangRune", "DHUD", "CleanCurvesOut", "CleanTank", "PillTank", "GemTank" }
IceHUD.validCustomModules = {Bar="Buff/Debuff watcher", Counter="Buff/Debuff stack counter", CD="Cooldown bar", Health="Health bar", Mana="Mana bar", CounterBar="Stack count bar"}
--@debug@
IceHUD.optionsLoaded = true
--@end-debug@
local function deepcopy(object)
local lookup_table = {}
local function _copy(object)
if type(object) ~= "table" then
return object
elseif lookup_table[object] then
return lookup_table[object]
end
local new_table = {}
lookup_table[object] = new_table
for index, value in pairs(object) do
new_table[_copy(index)] = _copy(value)
end
return setmetatable(new_table, getmetatable(object))
end
return _copy(object)
end
IceHUD.deepcopy = deepcopy
function IceHUD:removeDefaults(db, defaults, blocker)
-- remove all metatables from the db, so we don't accidentally create new sub-tables through them
setmetatable(db, nil)
-- loop through the defaults and remove their content
for k,v in pairs(defaults) do
if type(v) == "table" and type(db[k]) == "table" then
-- if a blocker was set, dive into it, to allow multi-level defaults
self:removeDefaults(db[k], v, blocker and blocker[k])
if next(db[k]) == nil then
db[k] = nil
end
else
-- check if the current value matches the default, and that its not blocked by another defaults table
if db[k] == defaults[k] and (not blocker or blocker[k] == nil) then
db[k] = nil
end
end
end
end
function IceHUD:populateDefaults(db, defaults, blocker)
-- remove all metatables from the db, so we don't accidentally create new sub-tables through them
setmetatable(db, nil)
-- loop through the defaults and add their content
for k,v in pairs(defaults) do
if type(v) == "table" and type(db[k]) == "table" then
-- if a blocker was set, dive into it, to allow multi-level defaults
self:populateDefaults(db[k], v, blocker and blocker[k])
else
-- check if the current value matches the default, and that its not blocked by another defaults table
if db[k] == nil then
db[k] = defaults[k]
end
end
end
end
IceHUD.Location = "Interface\\AddOns\\IceHUD"
StaticPopupDialogs["ICEHUD_CUSTOM_BAR_CREATED"] =
{
text = L["A custom bar has been created and can be configured through Module Settings => MyCustomBar. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_CUSTOM_COUNTER_CREATED"] =
{
text = L["A custom counter has been created and can be configured through Module Settings => MyCustomCounter. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_CUSTOM_COUNTER_BAR_CREATED"] =
{
text = L["A custom counter bar has been created and can be configured through Module Settings => MyCustomCounterBar. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_CUSTOM_CD_CREATED"] =
{
text = L["A custom cooldown bar has been created and can be configured through Module Settings => MyCustomCD. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_CUSTOM_HEALTH_CREATED"] =
{
text = L["A custom health bar has been created and can be configured through Module Settings => MyCustomHealth. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_CUSTOM_MANA_CREATED"] =
{
text = L["A custom mana bar has been created and can be configured through Module Settings => MyCustomMana. It is highly recommended that you change the bar name of this module so that it's easier to identify."],
button1 = OKAY,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
}
StaticPopupDialogs["ICEHUD_DELETE_CUSTOM_MODULE"] =
{
text = L["Are you sure you want to delete this module? This will remove all settings associated with it and cannot be un-done."],
button1 = YES,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 0,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
OnAccept = function(self)
IceHUD.IceCore:DeleteDynamicModule(self.data)
self.data = nil
end,
}
StaticPopupDialogs["ICEHUD_CHANGED_DOGTAG"] = {
text = L["This option requires the UI to be reloaded. Do you wish to reload it now?"],
button1 = YES,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
OnAccept = function()
ReloadUI()
end,
button2 = NO,
timeout = 0,
whileDead = 1,
hideOnEscape = 0
}
StaticPopupDialogs["ICEHUD_CHANGED_PROFILE_COMBAT"] = {
text = L["You have changed IceHUD profiles while in combat. This can cause problems due to Blizzard's secure frame policy. You may need to reload your UI to repair IceHUD."],
button1 = OKAY,
OnShow = function(self)
self:SetFrameStrata("TOOLTIP")
end,
OnHide = function(self)
self:SetFrameStrata("DIALOG")
end,
timeout = 0,
whileDead = 1,
hideOnEscape = 0
}
function IceHUD:OnInitialize()
self:SetDebugging(false)
self:Debug("IceHUD:OnInitialize()")
self.IceCore = IceCore:new()
self:RegisterPendingModules()
self.IceCore:SetupDefaults()
bReadyToRegisterModules = true
self.db = LibStub("AceDB-3.0"):New("IceCoreDB", self.IceCore.defaults, true)
if not self.db or not self.db.global or not self.db.profile then
print(L["Error: IceHUD database not loaded correctly. Please exit out of WoW and delete the database file (IceHUD.lua) found in: \\World of Warcraft\\WTF\\Account\\<Account Name>>\\SavedVariables\\"])
return
end
self.db.RegisterCallback(self, "OnProfileShutdown", "PreProfileChanged")
self.db.RegisterCallback(self, "OnProfileChanged", "PostProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "ProfileReset")
self.db.RegisterCallback(self, "OnProfileCopied", "ProfileCopied")
self:NotifyNewDb()
ConfigDialog:SetDefaultSize("IceHUD", 750, 650)
self:RegisterChatCommand("icehud", function()
if not UnitAffectingCombat("player") then
IceHUD:OpenConfig()
else
DEFAULT_CHAT_FRAME:AddMessage(L["|cff8888ffIceHUD|r: Combat lockdown restriction. Leave combat and try again."])
end
end)
self:RegisterChatCommand("rl", function() ReloadUI() end)
-- hack to allow /icehudcl to continue to function by loading the LoD options module and then re-calling the command
--[===[@non-debug@
self:RegisterChatCommand("icehudcl", function(arg)
self:UnregisterChatCommand("icehudcl")
self:LoadOptions()
LibStub("AceConfigCmd-3.0"):HandleCommand("icehudcl", "IceHUD", arg)
end)
--@end-non-debug@]===]
self:SyncSettingsVersions()
self:InitLDB()
if SML then
SML.RegisterCallback(self, "LibSharedMedia_Registered", "UpdateMedia")
end
end
function IceHUD:NotifyNewDb()
self.IceCore.accountSettings = self.db.global
self.IceCore.settings = self.db.profile
self.IceCore:SetModuleDatabases()
self.IceCore:CheckDisplayUpdateMessage()
end
function IceHUD:NotifyOptionsChange()
if ACR then
ACR:NotifyChange("IceHUD")
end
end
function IceHUD:OnEnable(isFirst)
-- if isFirst then
self:SetDebugging(self.IceCore:GetDebug())
self.debugFrame = ChatFrame1
-- end
self:Debug("IceHUD:OnEnable()")
if self.db.profile.enable then
self.IceCore:Enable()
end
-- Add dual-spec support
local LibDualSpec = LibStub('LibDualSpec-1.0', true)
if LibDualSpec then
LibDualSpec:EnhanceDatabase(self.db, "IceHUD")
end
--@debug@
IceHUD_Options:OnLoad()
--@end-debug@
end
-- add settings changes/updates here so that existing users don't lose their settings
function IceHUD:SyncSettingsVersions()
if not self.IceCore.settings.updatedOocNotFull then
self.IceCore.settings.updatedOocNotFull = true
self.IceCore.settings.alphaNotFull = self.IceCore.settings.alphaTarget
self.IceCore.settings.alphaNotFullbg = self.IceCore.settings.alphaTargetbg
end
end
function IceHUD:InitLDB()
local LDB = LibStub and LibStub("LibDataBroker-1.1", true)
if (LDB) then
local ldbButton = LDB:NewDataObject("IceHUD", {
type = "launcher",
text = L["IceHUD"],
label = L["IceHUD"],
icon = "Interface\\Icons\\Spell_Frost_Frost",
OnClick = function(button, msg)
if not UnitAffectingCombat("player") then
IceHUD:OpenConfig()
else
DEFAULT_CHAT_FRAME:AddMessage(L["|cff8888ffIceHUD|r: Combat lockdown restriction. Leave combat and try again."])
end
end,
})
if icon then
icon:Register("IceHUD", ldbButton, self.db.profile.minimap)
end
if ldbButton then
function ldbButton:OnTooltipShow()
self:AddLine(L["IceHUD"] .. " @project-version@")
self:AddLine(L["Click to open IceHUD options."], 1, 1, 1)
end
end
end
end
-- blizzard interface options
local blizOptionsPanel = CreateFrame("FRAME", "IceHUDConfigPanel", UIParent)
blizOptionsPanel.name = "IceHUD"
blizOptionsPanel.button = CreateFrame("BUTTON", "IceHUDOpenConfigButton", blizOptionsPanel, IceHUD.UsesUIPanelButtonTemplate and "UIPanelButtonTemplate" or "UIPanelButtonTemplate2")
blizOptionsPanel.button:SetText("Open IceHUD configuration")
blizOptionsPanel.button:SetWidth(240)
blizOptionsPanel.button:SetHeight(30)
blizOptionsPanel.button:SetScript("OnClick", function(self) HideUIPanel(InterfaceOptionsFrame) HideUIPanel(GameMenuFrame) IceHUD:OpenConfig() end)
blizOptionsPanel.button:SetPoint('TOPLEFT', blizOptionsPanel, 'TOPLEFT', 20, -20)
if InterfaceOptions_AddCategory then
InterfaceOptions_AddCategory(blizOptionsPanel)
elseif Settings then
local category = Settings.RegisterCanvasLayoutCategory(blizOptionsPanel, "IceHUD")
Settings.RegisterAddOnCategory(category)
end
function IceHUD:OpenConfig()
if not ConfigDialog then return end
if not self:LoadOptions() then
return
end
if ConfigDialog.OpenFrames["IceHUD"] ~= nil then
ConfigDialog:Close("IceHUD")
else
ConfigDialog:Open("IceHUD")
end
end
function IceHUD:LoadOptions()
if not self.optionsLoaded then
local loaded, reason = LoadAddOn("IceHUD_Options")
if not loaded then
print("Failed to load options module. Reason: " .. reason)
return false
else
self.optionsLoaded = true
end
end
return true
end
function IceHUD:Debug(...)
if self.debugging then
local msg = ""
for n=1,select('#', ...) do
msg = msg .. tostring(select(n, ...)) .. " "
end
if self.debugFrame then
self.debugFrame:AddMessage(msg)
else
print(msg)
end
end
end
function IceHUD:SetDebugging(bIsDebugging)
self.debugging = bIsDebugging
end
-- rounding stuff
function IceHUD:MathRound(num, idp)
if not num then
return nil
end
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function IceHUD:GetBuffCount(unit, ability, onlyMine, matchByName)
return IceHUD:GetAuraCount("HELPFUL", unit, ability, onlyMine, matchByName)
end
function IceHUD:GetDebuffCount(unit, ability, onlyMine, matchByName)
return IceHUD:GetAuraCount("HARMFUL", unit, ability, onlyMine, matchByName)
end
function IceHUD:GetAuraCount(auraType, unit, ability, onlyMine, matchByName)
if not unit or not ability then
return 0, nil
end
if unit == "main hand weapon" or unit == "off hand weapon" then
local hasMainHandEnchant, mainHandExpiration, mainHandCharges, mainHandEnchantID, hasOffHandEnchant, offHandExpiration, offHandCharges, offHandEnchantID
= GetWeaponEnchantInfo()
if unit == "main hand weapon" and hasMainHandEnchant then
return mainHandCharges, nil
elseif unit == "off hand weapon" and hasOffHandEnchant then
return offHandCharges, nil
end
return 0, nil
end
-- Support for Spell IDs
if (IceHUD.GetPlayerAuraBySpellID and tonumber(ability) ~= nil) then
local aura = C_UnitAuras.GetPlayerAuraBySpellID(ability)
if aura ~= nil then
return aura.applications, nil
else
return 0, nil
end
end
local i = 1
local name, _, texture, applications
if IceHUD.SpellFunctionsReturnRank then
name, _, texture, applications = IceHUD.UnitAura(unit, i, auraType..(onlyMine and "|PLAYER" or ""))
else
name, texture, applications = IceHUD.UnitAura(unit, i, auraType..(onlyMine and "|PLAYER" or ""))
end
while name do
if (not matchByName and string.match(texture:upper(), ability:upper()))
or (matchByName and string.match(name:upper(), ability:upper())) then
return applications, i
end
i = i + 1
if IceHUD.SpellFunctionsReturnRank then
name, _, texture, applications = IceHUD.UnitAura(unit, i, auraType..(onlyMine and "|PLAYER" or ""))
else
name, texture, applications = IceHUD.UnitAura(unit, i, auraType..(onlyMine and "|PLAYER" or ""))
end
end
return 0, nil
end
do
local retval = {}
function IceHUD:HasBuffs(unit, spellIDs, filter)
for i=1, #spellIDs do
retval[i] = false
end
local i = 1
local name, _, texture, applications, _, _, _, _, _, _, auraID
if IceHUD.SpellFunctionsReturnRank then
name, _, texture, applications, _, _, _, _, _, _, auraID = IceHUD.UnitAura(unit, i, filter)
else
name, texture, applications, _, _, _, _, _, _, auraID = IceHUD.UnitAura(unit, i, filter)
end
while name do
for i=1, #spellIDs do
if spellIDs[i] == auraID then
retval[i] = applications == 0 and true or applications
break
end
end
i = i + 1
if IceHUD.SpellFunctionsReturnRank then
name, _, texture, applications, _, _, _, _, _, _, auraID = IceHUD.UnitAura(unit, i, filter)
else
name, texture, applications, _, _, _, _, _, _, auraID = IceHUD.UnitAura(unit, i, filter)
end
end
return retval
end
function IceHUD:HasDebuffs(unit, spellIDs, filter)
return IceHUD:HasBuffs(unit, spellIDs, filter and filter.."|HARMFUL" or "HARMFUL")
end
function IceHUD:HasAnyBuff(unit, spellIDs, filter)
local buffs = IceHUD:HasBuffs(unit, spellIDs, filter)
for i=1, #buffs do
if buffs[i] then
return true
end
end
return false
end
function IceHUD:HasAnyDebuff(unit, spellIDs, filter)
local debuffs = IceHUD:HasDebuffs(unit, spellIDs, filter)
for i=1, #debuffs do
if debuffs[i] then
return true
end
end
return false
end
end
function IceHUD:OnDisable()
IceHUD.IceCore:Disable()
end
function IceHUD:PreProfileChanged(db)
if UnitAffectingCombat("player") then
StaticPopup_Show("ICEHUD_CHANGED_PROFILE_COMBAT")
end
self.IceCore:Disable()
end
function IceHUD:PostProfileChanged(db, newProfile)
self:NotifyNewDb()
if self.db.profile.enable then
self.IceCore:Enable()
end
end
function IceHUD:ProfileReset()
ReloadUI()
end
function IceHUD:ProfileCopied()
ReloadUI()
end
function IceHUD:Clamp(value, min, max)
if value < min then
value = min
elseif value > max then
value = max
elseif value ~= value or not (value >= min and value <= max) then -- check for nan...
value = min
end
return value
end
function IceHUD:ShouldSwapToVehicle(...)
local arg1, arg2 = ...
if (arg1 == "player") then
if (arg2) then
return true
end
end
if (UnitHasVehicleUI("player")) then
return true
end
end
function IceHUD:xor(val1, val2)
return val1 and not val2 or val2 and not val1
end
function IceHUD:GetSelectValue(info, val)
for k,v in pairs(info.option.values) do
if v == val then
return k
end
end
return 1
end
function IceHUD:Register(element)
assert(element, "Trying to register a nil module")
if not bReadyToRegisterModules then
pendingModuleLoads[#pendingModuleLoads+1] = element
else
self.IceCore:Register(element)
end
end
function IceHUD:RegisterPendingModules()
for i=1, #pendingModuleLoads do
self.IceCore:Register(pendingModuleLoads[i])
end
pendingModuleLoads = {}
end
function IceHUD:UpdateMedia(event, mediatype, key)
if not self.db.profile or not self.IceCore.enabled then
return
end
if mediatype == "font" then
if key == self.db.profile.fontFamily then
IceHUD.IceCore:SetFontFamily(key)
end
elseif mediatype == "statusbar" then
if self.TargetOfTarget and self.TargetOfTarget.moduleSettings.enabled and key == self.TargetOfTarget.moduleSettings.texture then
self.TargetOfTarget:Redraw()
end
end
end
function IceHUD:CreateCustomModuleAndNotify(moduleKey, settings)
local newMod = nil
local popupMsg
if moduleKey == "Bar" then -- custom bar
newMod = IceCustomBar:new()
popupMsg = "ICEHUD_CUSTOM_BAR_CREATED"
elseif moduleKey == "Counter" then -- custom counter
newMod = IceCustomCount:new()
popupMsg = "ICEHUD_CUSTOM_COUNTER_CREATED"
elseif moduleKey == "CounterBar" then -- custom counter bar
newMod = IceCustomCounterBar:new()
popupMsg = "ICEHUD_CUSTOM_COUNTER_BAR_CREATED"
elseif moduleKey == "CD" then -- cooldown bar
newMod = IceCustomCDBar:new()
popupMsg = "ICEHUD_CUSTOM_CD_CREATED"
elseif moduleKey == "Health" then -- custom health bar
newMod = IceCustomHealth:new()
popupMsg = "ICEHUD_CUSTOM_HEALTH_CREATED"
elseif moduleKey == "Mana" then -- custom mana bar
newMod = IceCustomMana:new()
popupMsg = "ICEHUD_CUSTOM_MANA_CREATED"
end
if newMod ~= nil then
IceHUD.IceCore:AddNewDynamicModule(newMod, settings)
ConfigDialog:SelectGroup("IceHUD", "modules", newMod.elementName)
StaticPopup_Show(popupMsg)
end
end
local function CheckLFGMode(mode)
return (mode ~= nil and mode ~= "abandonedInDungeon" and mode ~= "queued")
end
function IceHUD:GetIsInLFGGroup()
if not GetLFGMode then
return false
end
local mode, submode
if LE_LFG_CATEGORY_LFD then
mode, submode = GetLFGMode(LE_LFG_CATEGORY_LFD)
else
mode, submode = GetLFGMode()
end
local IsInLFGGroup = CheckLFGMode(mode)
if not LE_LFG_CATEGORY_LFD then
return IsInLFGGroup
end
if not IsInLFGGroup then
mode, submode = GetLFGMode(LE_LFG_CATEGORY_RF)
IsInLFGGroup = CheckLFGMode(mode)
end
if not IsInLFGGroup then
mode, submode = GetLFGMode(LE_LFG_CATEGORY_SCENARIO)
IsInLFGGroup = CheckLFGMode(mode)
end
if not IsInLFGGroup then
mode, submode = GetLFGMode(LE_LFG_CATEGORY_LFR)
IsInLFGGroup = CheckLFGMode(mode)
end
return IsInLFGGroup
end
function IceHUD:OutOfCombatWrapper(func)
return function(...)
return IceHUD:RunOnLeaveCombat(func, ...)
end
end
do
local in_combat = false
local in_lockdown = false
local actions_to_perform = {}
local pool = setmetatable({}, {__mode='k'})
function IceHUD:PLAYER_REGEN_ENABLED()
in_combat = false
in_lockdown = false
for i, t in ipairs(actions_to_perform) do
t.f(unpack(t, 1, t.n))
actions_to_perform[i] = nil
wipe(t)
pool[t] = true
end
end
function IceHUD:PLAYER_REGEN_DISABLED()
in_combat = true
end
function IceHUD:RunOnLeaveCombat(func, ...)
if not in_combat then
-- out of combat, call right away and return
func(...)
return
end
if not in_lockdown then
in_lockdown = InCombatLockdown() -- still in PLAYER_REGEN_DISABLED
if not in_lockdown then
func(...)
return
end
end
local t = next(pool) or {}
pool[t] = nil
t.f = func
local n = select('#', ...)
t.n = n
for i = 1, n do
t[i] = select(i, ...)
end
actions_to_perform[#actions_to_perform+1] = t
end
end