-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathHealersMate.lua
1686 lines (1523 loc) · 58.3 KB
/
HealersMate.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
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SLASH_HEALERSMATE1 = "/healersmate"
SLASH_HEALERSMATE2 = "/hm"
SlashCmdList["HEALERSMATE"] = function(args)
if args == "reset" then
for _, group in pairs(HealersMate.UnitFrameGroups) do
local gc = group:GetContainer()
gc:ClearAllPoints()
gc:SetPoint(HMUtil.GetCenterScreenPoint(gc:GetWidth(), gc:GetHeight()))
end
HealersMateSettings.HM_SettingsContainer:ClearAllPoints()
HealersMateSettings.HM_SettingsContainer:SetPoint("CENTER", 0, 0)
DEFAULT_CHAT_FRAME:AddMessage("Reset all frame positions.")
elseif args == "check" then
HealersMate.CheckGroup()
elseif args == "update" then
for _, ui in pairs(HealersMate.AllUnitFrames) do
ui:SizeElements()
ui:UpdateAll()
end
for _, group in pairs(HealersMate.UnitFrameGroups) do
group:ApplyProfile()
group:UpdateUIPositions()
end
elseif args == "testui" then
HMOptions.TestUI = not HMOptions.TestUI
HealersMate.TestUI = HMOptions.TestUI
if HMOptions.TestUI then
for _, ui in pairs(HealersMate.AllUnitFrames) do
ui.fakeStats = ui.GenerateFakeStats()
ui:Show()
end
end
HealersMate.CheckGroup()
if not HMOptions.TestUI and HMUnitProxy then
for _, type in ipairs(HMUnitProxy.CustomUnitTypes) do
HMUnitProxy.UpdateUnitTypeFrames(type)
end
end
DEFAULT_CHAT_FRAME:AddMessage("UI Testing is now "..(not HMOptions.TestUI and
HMUtil.Colorize("off", 1, 0.6, 0.6) or HMUtil.Colorize("on", 0.6, 1, 0.6))..".")
elseif args == "toggle" then
HMOptions.Hidden = not HMOptions.Hidden
HealersMate.CheckGroup()
DEFAULT_CHAT_FRAME:AddMessage("The HealersMate UI is now "..(HMOptions.Hidden and
HMUtil.Colorize("hidden", 1, 0.6, 0.6) or HMUtil.Colorize("shown", 0.6, 1, 0.6))..".")
elseif args == "show" then
HMOptions.Hidden = false
HealersMate.CheckGroup()
DEFAULT_CHAT_FRAME:AddMessage("The HealersMate UI is now "..(HMOptions.Hidden and
HMUtil.Colorize("hidden", 1, 0.6, 0.6) or HMUtil.Colorize("shown", 0.6, 1, 0.6))..".")
elseif args == "hide" then
HMOptions.Hidden = true
HealersMate.CheckGroup()
DEFAULT_CHAT_FRAME:AddMessage("The HealersMate UI is now "..(HMOptions.Hidden and
HMUtil.Colorize("hidden", 1, 0.6, 0.6) or HMUtil.Colorize("shown", 0.6, 1, 0.6))..".")
elseif args == "silent" then
HMOnLoadInfoDisabled = not HMOnLoadInfoDisabled
DEFAULT_CHAT_FRAME:AddMessage("Load message is now "..(HMOnLoadInfoDisabled and
HMUtil.Colorize("off", 1, 0.6, 0.6) or HMUtil.Colorize("on", 0.6, 1, 0.6))..".")
elseif args == "help" or args == "?" then
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm", 0, 0.8, 0).." -- Opens the addon configuration")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm reset", 0, 0.8, 0).." -- Resets all heal frame positions")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm testui", 0, 0.8, 0)..
" -- Toggles fake players to see how the UI would look")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm toggle", 0, 0.8, 0).." -- Shows/hides the UI")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm show", 0, 0.8, 0).." -- Shows the UI")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm hide", 0, 0.8, 0).." -- Hides the UI")
DEFAULT_CHAT_FRAME:AddMessage(HMUtil.Colorize("/hm silent", 0, 0.8, 0).." -- Turns off/on message when addon loads")
elseif args == "" then
local container = HealersMateSettings.HM_SettingsContainer
if container then
if container:IsVisible() then
container:Hide()
else
container:Show()
end
else
DEFAULT_CHAT_FRAME:AddMessage("HM_SettingsContainer frame not found.")
end
else
DEFAULT_CHAT_FRAME:AddMessage("Unknown subcommand. See usage with /hm help")
end
end
HealersMateLib = AceLibrary("AceAddon-2.0"):new("AceEvent-2.0")
HealersMate = {}
local _G = getfenv(0)
setmetatable(HealersMate, {__index = getfenv(1)})
setfenv(1, HealersMate)
VERSION = "2.0.0-alpha5.1"
TestUI = false
Banzai = AceLibrary("Banzai-1.0")
HealComm = AceLibrary("HealComm-1.0")
GuidRoster = HMGuidRoster -- Will be nil if SuperWoW isn't present
local util = HMUtil
local colorize = util.Colorize
local GetKeyModifier = util.GetKeyModifier
local GetClass = util.GetClass
local GetPowerType = util.GetPowerType
local GetColoredRoleText = util.GetColoredRoleText
local UseItem = util.UseItem
local GetItemCount = util.GetItemCount
PartyUnits = util.PartyUnits
PetUnits = util.PetUnits
TargetUnits = util.TargetUnits
RaidUnits = util.RaidUnits
RaidPetUnits = util.RaidPetUnits
AllUnits = util.AllUnits
AllUnitsSet = util.AllUnitsSet
AllCustomUnits = util.CustomUnits
AllCustomUnitsSet = util.CustomUnitsSet
if HMUnitProxy then
HMUnitProxy.ImportFunctions(HealersMate)
end
-- TODO: Actually use this
UIGroupInfo = {}
UIGroupInfo["Party"] = {
units = PartyUnits,
environment = "party",
enableCondition = function()
return true
end}
UIGroupInfo["Pets"] = {
units = PetUnits,
environment = "party",
enableCondition = function()
return true
end
}
UIGroupInfo["Raid"] = {
units = RaidUnits,
environment = "raid",
enableCondition = function()
return true
end
}
UIGroupInfo["Raid Pets"] = {
units = RaidPetUnits,
environment = "raid",
enableCondition = function()
return true
end
}
UIGroupInfo["Target"] = {
units = TargetUnits,
environment = "all",
enableCondition = function()
return true
end
}
-- Relic of previous versions, may be removed
PreviousHealth = {} --This is used to determine if the player gained or lost health, used in the scrolling combat text functions
for _, unit in ipairs(AllUnits) do
PreviousHealth[unit] = -1
end
ReadableButtonMap = {
["LeftButton"] = "Left",
["MiddleButton"] = "Middle",
["RightButton"] = "Right",
["Button4"] = "Button 4",
["Button5"] = "Button 5"
}
ResurrectionSpells = {
["PRIEST"] = "Resurrection",
["PALADIN"] = "Redemption",
["SHAMAN"] = "Ancestral Spirit",
["DRUID"] = "Rebirth"
}
local hmBarsPath = util.GetAssetsPath().."textures\\bars\\"
BarStyles = {
["Blizzard"] = "Interface\\TargetingFrame\\UI-StatusBar",
["Blizzard Smooth"] = hmBarsPath.."Blizzard-Smooth",
["Blizzard Raid"] = hmBarsPath.."Blizzard-Raid",
["Blizzard Raid Sideless"] = hmBarsPath.."Blizzard-Raid-Sideless",
["HealersMate"] = hmBarsPath.."HealersMate",
["HealersMate Borderless"] = hmBarsPath.."HealersMate-Borderless",
["HealersMate Shineless"] = hmBarsPath.."HealersMate-Shineless",
["HealersMate Shineless Borderless"] = hmBarsPath.."HealersMate-Shineless-Borderless"
}
GameTooltip = CreateFrame("GameTooltip", "HMGameTooltip", UIParent, "GameTooltipTemplate")
CurrentlyHeldButton = nil
SpellsTooltip = CreateFrame("GameTooltip", "HMSpellsTooltip", UIParent, "GameTooltipTemplate")
SpellsTooltipOwner = nil
SpellsTooltipPowerBar = nil
do
local manaBar = CreateFrame("StatusBar", "HMSpellsTooltipManaBar", SpellsTooltip)
SpellsTooltipPowerBar = manaBar
manaBar:SetStatusBarTexture(BarStyles["HealersMate"])
manaBar:SetMinMaxValues(0, 1)
manaBar:SetWidth(100)
manaBar:SetHeight(12)
manaBar:SetPoint("TOPRIGHT", SpellsTooltip, "TOPRIGHT", -10, -12)
local bg = manaBar:CreateTexture(nil, "BACKGROUND")
manaBar.background = bg
bg:SetAllPoints(true)
bg:SetTexture(0.3, 0.3, 0.3, 0.8)
local text = manaBar:CreateFontString(nil, "ARTWORK", "GameFontNormal")
manaBar.text = text
text:SetWidth(manaBar:GetWidth())
text:SetHeight(manaBar:GetHeight())
text:SetPoint("CENTER", manaBar, "CENTER")
text:SetFont("Fonts\\FRIZQT__.TTF", 9, "OUTLINE")
text:SetShadowOffset(0, 0)
text:SetJustifyH("CENTER")
text:SetJustifyV("CENTER")
end
-- An unmapped array of all unit frames
AllUnitFrames = {}
-- A map of units to an array of unit frames associated with the unit
HMUnitFrames = {}
-- Key: Unit frame group name | Value: The group
UnitFrameGroups = {}
CustomUnitGUIDMap = HMUnitProxy and HMUnitProxy.CustomUnitGUIDMap or {}
GUIDCustomUnitMap = HMUnitProxy and HMUnitProxy.GUIDCustomUnitMap or {}
CurrentlyInRaid = false
AssignedRoles = nil
-- Returns the array of unit frames of the unit
function GetUnitFrames(unit)
return HMUnitFrames[unit]
end
-- A temporary dummy function while the addon initializes. See below for the real iterator.
function UnitFrames(unit)
return function() end
end
local function OpenUnitFramesIterator()
-- UnitFrames function definition.
-- Returns an iterator for the unit frames of the unit.
-- These iterators have a serious problem in that they do not support concurrent iteration.
if util.IsSuperWowPresent() then
local EMPTY_UIS = {}
local HMUnitFrames = HMUnitFrames
local GuidUnitMap = HMGuidRoster.GuidUnitMap
local iterTable = {} -- The table reused for iteration over GUID units
local uis
local i = 0
local len = 0
local iterFunc = function()
i = i + 1
if i <= len then
return uis[i]
end
end
function UnitFrames(unit)
if i < len then
hmprint("Collision: "..i.."/"..len)
end
if GuidUnitMap[unit] then -- If a GUID is provided, ALL UIs associated with that GUID will be iterated
uis = iterTable
for i = 1, table.getn(uis) do
uis[i] = nil
end
table.setn(uis, 0)
for _, unit in pairs(GuidUnitMap[unit]) do
for _, frame in ipairs(HMUnitFrames[unit]) do
table.insert(uis, frame)
end
end
else
uis = HMUnitFrames[unit] or EMPTY_UIS
end
len = table.getn(uis)
i = 0
return iterFunc
end
else -- Optimized version for vanilla
local HMUnitFrames = HMUnitFrames
local uis
local i = 0
local len = 0
local iterFunc = function()
i = i + 1
if i <= len then
return uis[i]
end
end
function UnitFrames(unit)
i = 0
uis = HMUnitFrames[unit]
len = table.getn(uis)
return iterFunc
end
end
end
--This is just to respond to events "EventHandlerFrame" never appears on the screen
local EventHandlerFrame = CreateFrame("Frame", "HMEventHandlerFrame", UIParent)
EventHandlerFrame:RegisterEvent("ADDON_LOADED"); -- This triggers once for every addon that was loaded after this addon
EventHandlerFrame:RegisterEvent("PLAYER_LOGOUT"); -- Fired when about to log out
EventHandlerFrame:RegisterEvent("PLAYER_QUITING"); -- Fired when a player has the quit option on screen
EventHandlerFrame:RegisterEvent("UNIT_HEALTH") --“UNIT_HEALTH” fires when a unit’s health changes
EventHandlerFrame:RegisterEvent("UNIT_MAXHEALTH")
EventHandlerFrame:RegisterEvent("UNIT_AURA") -- Register for the "UNIT_AURA" event to update buffs and debuffs
EventHandlerFrame:RegisterEvent("PLAYER_ENTERING_WORLD") -- Fired when the player enters the world, reloads the UI, or zones between map instances. Basically, it triggers whenever a loading screen appears2. This includes logging in, respawning at a graveyard, entering/leaving an instance, and other situations where a loading screen is presented.
EventHandlerFrame:RegisterEvent("PARTY_MEMBERS_CHANGED") -- Fired when someone joins or leaves the group
EventHandlerFrame:RegisterEvent("PLAYER_TARGET_CHANGED")
EventHandlerFrame:RegisterEvent("RAID_ROSTER_UPDATE")
EventHandlerFrame:RegisterEvent("UNIT_PET")
EventHandlerFrame:RegisterEvent("PLAYER_PET_CHANGED")
EventHandlerFrame:RegisterEvent("SPELLS_CHANGED")
EventHandlerFrame:RegisterEvent("RAID_TARGET_UPDATE")
EventHandlerFrame:RegisterEvent("UNIT_MANA")
EventHandlerFrame:RegisterEvent("UNIT_DISPLAYPOWER")
EventHandlerFrame:RegisterEvent("UNIT_RAGE")
EventHandlerFrame:RegisterEvent("UNIT_ENERGY")
EventHandlerFrame:RegisterEvent("UNIT_FOCUS")
EventHandlerFrame:RegisterEvent("UNIT_MAXMANA")
local lastModifier = "None"
EventHandlerFrame:SetScript("OnUpdate", function()
local modifier = GetKeyModifier()
if lastModifier ~= modifier then
lastModifier = modifier
if SpellsTooltip:IsVisible() then
ReapplySpellsTooltip()
end
end
end)
function Debug(msg)
DEFAULT_CHAT_FRAME:AddMessage(msg)
end
function GetSpells()
return HMSpells["Friendly"]
end
function GetHostileSpells()
return HMSpells["Hostile"]
end
function UpdateUnitFrameGroups()
for _, group in pairs(UnitFrameGroups) do
group:UpdateUIPositions()
end
end
local ScanningTooltip = CreateFrame("GameTooltip", "HMScanningTooltip", nil, "GameTooltipTemplate");
ScanningTooltip:SetOwner(WorldFrame, "ANCHOR_NONE");
-- Allow tooltip SetX() methods to dynamically add new lines based on these
ScanningTooltip:AddFontStrings(
ScanningTooltip:CreateFontString( "$parentTextLeft1", nil, "GameTooltipText" ),
ScanningTooltip:CreateFontString( "$parentTextRight1", nil, "GameTooltipText" ) );
-- Thanks ChatGPT
function ExtractSpellRank(spellname)
-- Find the starting position of "Rank "
local start_pos = string.find(spellname, "Rank ")
-- Check if "Rank " was found
if start_pos then
-- Adjust start_pos to point to the first digit
--start_pos = start_pos + 5 -- Move past "Rank "
-- Find the ending parenthesis
local end_pos = string.find(spellname, ")", start_pos)
-- Extract the number substring
if end_pos then
local number_str = string.sub(spellname, start_pos, end_pos - 1)
--local number = tonumber(number_str) -- Convert to a number
return number_str
end
end
return nil
end
-- Thanks again ChatGPT
local tooltipResources = {"Mana", "Rage", "Energy"}
function ExtractResourceCost(costText)
-- First extract resource type
local resource
for _, r in ipairs(tooltipResources) do
if string.find(costText, r) then
resource = string.lower(r)
break
end
end
-- No resource found, this spell is probably free
if not resource then
return 0
end
-- Find the position where non-digit characters start
local num_end = string.find(costText, "%D")
-- If a non-digit character is found, extract the number
if num_end then
-- Extract the number substring from the start to the position before the non-digit character
local number_str = string.sub(costText, 1, num_end - 1)
-- Convert the substring to a number
local number = tonumber(number_str)
-- Print the result
return number, resource
else
-- If no non-digit character is found, the entire string is a number
local number = tonumber(costText)
return number, resource
end
end
function GetSpellID(spellname)
local id = 1;
local matchingSpells = {}
local spellRank = ExtractSpellRank(spellname)
if spellRank ~= nil then
spellname = string.gsub(spellname, "%b()", "")
end
for i = 1, GetNumSpellTabs() do
local _, _, _, numSpells = GetSpellTabInfo(i);
for j = 1, numSpells do
local spellName, rank, realID = GetSpellName(id, "spell");
if spellName == spellname then
if rank == spellRank then -- If the rank is specified, then we can check if this is the right spell
return id
else
table.insert(matchingSpells, id)
end
end
id = id + 1;
end
end
return matchingSpells[table.getn(matchingSpells)]
end
-- Returns the numerical cost and the resource name; "unknown" if the spell is unknown; 0 if the spell is free
function GetResourceCost(spellName)
ScanningTooltip:SetOwner(UIParent, "ANCHOR_NONE");
local spellID, bookType
if GetSpellSlotTypeIdForName then -- Nampower 2.6.0 function
spellID, bookType = GetSpellSlotTypeIdForName(spellName)
if bookType == "unknown" then
return "unknown"
end
if bookType ~= "spell" then
return 0
end
else
spellID = GetSpellID(spellName)
end
if not spellID then
return "unknown"
end
ScanningTooltip:SetSpell(spellID, "spell")
local leftText = getglobal("HMScanningTooltipTextLeft"..2)
if leftText:GetText() then
return ExtractResourceCost(leftText:GetText())
end
return 0
end
-- Returns the aura's name and its school type
function GetAuraInfo(unit, type, index)
-- Make these texts blank since they don't clear otherwise
local leftText = getglobal("HMScanningTooltipTextLeft1")
leftText:SetText("")
local rightText = getglobal("HMScanningTooltipTextRight1")
rightText:SetText("")
if type == "Buff" then
ScanningTooltip:SetUnitBuff(unit, index)
else
ScanningTooltip:SetUnitDebuff(unit, index)
end
return leftText:GetText() or "", rightText:GetText() or ""
end
function ApplySpellsTooltip(attachTo, unit)
if not HMOptions.SpellsTooltip.Enabled then
return
end
local spellList = {}
local modifier = GetKeyModifier()
local settings = HealersMateSettings
local spells = UnitCanAttack("player", unit) and GetHostileSpells() or GetSpells()
local deadFriend = util.IsDeadFriend(unit)
local selfClass = GetClass("player")
local canResurrect = HMOptions.AutoResurrect and deadFriend and ResurrectionSpells[selfClass]
-- Holy Champion Texture: Interface\\Icons\\Spell_Holy_ProclaimChampion_02
local canReviveChampion = canResurrect and GetSpellID("Revive Champion") and
HMUnit.Get(unit):HasBuffIDOrName(45568, "Holy Champion") and UnitAffectingCombat("player")
for _, btn in ipairs(settings.CustomButtonOrder) do
if canResurrect then -- Show all spells (except special binds) as the resurrection spell
local kv = {}
local readableButton = settings.CustomButtonNames[btn] or ReadableButtonMap[btn]
kv[readableButton] = canReviveChampion and "Revive Champion" or ResurrectionSpells[selfClass]
if SpecialBinds[string.upper(spells[modifier][btn] or "")] then
kv[readableButton] = spells[modifier][btn]
end
table.insert(spellList, kv)
else
if spells[modifier][btn] or (settings.ShowEmptySpells and not settings.IgnoredEmptySpells[btn]) then
local kv = {}
local readableButton = settings.CustomButtonNames[btn] or ReadableButtonMap[btn]
kv[readableButton] = spells[modifier][btn] or "Unbound"
table.insert(spellList, kv)
end
end
end
ShowSpellsTooltip(attachTo, spellList, attachTo)
end
function IsValidMacro(name)
return GetMacroIndexByName(name) ~= 0
end
function RunMacro(name, target)
if not IsValidMacro(name) then
return
end
if target then
_G.HM_MacroTarget = target
end
local _, _, body = GetMacroInfo(GetMacroIndexByName(name))
local commands = util.SplitString(body, "\n")
for i = 1, table.getn(commands) do
ChatFrameEditBox:SetText(commands[i])
ChatEdit_SendText(ChatFrameEditBox)
end
if target then
_G.HM_MacroTarget = nil
end
end
local ITEM_PREFIX = "Item: "
local MACRO_PREFIX = "Macro: "
local lowToHighColors = {
{1, 0, 0},
{1, 0.9, 0},
{0.35, 1, 0.35}
}
local tooltipPowerColors = {
["mana"] = {0.5, 0.7, 1}, -- Not the accurate color, but more readable
["rage"] = {1, 0, 0},
["energy"] = {1, 1, 0}
}
function ShowSpellsTooltip(attachTo, spells, owner)
SpellsTooltipOwner = owner
SpellsTooltip:SetOwner(attachTo, "ANCHOR_RIGHT")
SpellsTooltip:SetPoint("RIGHT", attachTo, "LEFT", 0, 0)
local options = HMOptions.SpellsTooltip
local currentPower = UnitMana("player")
local maxPower = UnitManaMax("player")
local powerType = GetPowerType("player")
local powerColor = tooltipPowerColors[powerType]
local powerText = ""
local showPowerBar = options.ShowPowerBar
if options.ShowPowerAs == "Power" then
powerText = tostring(currentPower)
elseif options.ShowPowerAs == "Power/Max Power" then
powerText = currentPower.."/"..maxPower
elseif options.ShowPowerAs == "Power %" then
powerText = util.RoundNumber((currentPower / maxPower) * 100).."%"
end
if showPowerBar then
local color = util.InterpolateColors(lowToHighColors, (currentPower / maxPower))
powerText = colorize(powerText, color)
SpellsTooltipPowerBar:SetStatusBarColor(powerColor[1], powerColor[2], powerColor[3])
SpellsTooltipPowerBar:SetValue(currentPower / maxPower)
SpellsTooltipPowerBar.text:SetText(powerText)
else
powerText = colorize(powerText, powerColor)
end
local modifier = util.GetKeyModifierTypeByID(1 + (options.AbbreviatedKeys and 2 or 0) + (options.ColoredKeys and 1 or 0))
SpellsTooltip:AddDoubleLine(modifier, showPowerBar and " " or powerText, 1, 1, 1)
for _, kv in ipairs(spells) do
for button, spell in pairs(kv) do
local leftText = colorize(button, 1, 1, 0.5)
local rightText
if spell == "Unbound" then
leftText = colorize(button, 0.6, 0.6, 0.6)
rightText = colorize("Unbound", 0.6, 0.6, 0.6)
elseif util.StartsWith(spell, ITEM_PREFIX) then
local item = string.sub(spell, string.len(ITEM_PREFIX) + 1)
local itemCount = GetItemCount(item)
local castsColor = {0.6, 1, 0.6}
if itemCount == 0 then
castsColor = {1, 0.5, 0.5}
elseif itemCount == 1 then
castsColor = {1, 1, 0}
end
rightText = colorize(item, 1, 1, 1)..colorize(" ("..itemCount..")", castsColor)
elseif util.StartsWith(spell, MACRO_PREFIX) then
local macro = string.sub(spell, string.len(MACRO_PREFIX) + 1)
if IsValidMacro(macro) then
rightText = colorize(macro, 1, 0.6, 1)
else
rightText = colorize(macro.." (Invalid Macro)", 1, 0.4, 0.4)
end
elseif SpecialBinds[string.upper(spell)] then
rightText = spell
else -- There is a bound spell
local cost, resource = GetResourceCost(spell)
if cost == "unknown" then
leftText = colorize(button, 1, 0.4, 0.4)
rightText = colorize(spell.." (Unknown)", 1, 0.4, 0.4)
elseif cost == 0 then -- The spell is free, so no fancy text
rightText = spell
else
local resourceColor = tooltipPowerColors[resource]
local casts = math.floor(currentPower / cost)
if resource ~= powerType then -- A druid can't cast a spell that requires a different power type
casts = 0
end
local r, g, b = 0.6, 1, 0.6
if casts == 0 then
r, g, b = 1, 0.5, 0.5
elseif casts <= options.CriticalCastsLevel then
r, g, b = 1, 1, 0
end
local costText
if powerType == "mana" and resource == powerType then
if options.ShowManaCost then
costText = cost
end
if options.ShowManaPercentCost then
costText = (costText and (costText.." ") or "")..util.RoundNumber((cost / maxPower) * 100, 1).."%"
end
else
costText = cost
end
rightText = spell
if casts == 0 then
rightText = colorize(util.StripColors(rightText), 0.5, 0.5, 0.5)
end
if costText then
rightText = rightText.." "..colorize(costText, resourceColor)
end
if casts <= options.HideCastsAbove then
rightText = rightText..colorize(" ("..casts..")", r, g, b)
end
end
end
-- Gray out spells that are not held down
if CurrentlyHeldButton and button ~= CurrentlyHeldButton then
leftText = colorize(util.StripColors(leftText), 0.3, 0.3, 0.3)
rightText = colorize(util.StripColors(rightText), 0.3, 0.3, 0.3)
end
SpellsTooltip:AddDoubleLine(leftText, rightText)
end
end
--local leftTexts = {spellsTooltipTextLeft1, spellsTooltipTextLeft2, spellsTooltipTextLeft3,
-- spellsTooltipTextLeft4, spellsTooltipTextLeft5, spellsTooltipTextLeft6}
--spellsTooltipTextLeft1:SetFont("Fonts\\FRIZQT__.TTF", 12, "GameFontNormal")
--spellsTooltipTextRight1:SetFont("Fonts\\FRIZQT__.TTF", 12, "GameFontNormal")
SpellsTooltip:Show()
end
function HideSpellsTooltip()
SpellsTooltip:Hide()
SpellsTooltipOwner = nil
end
function ReapplySpellsTooltip()
if SpellsTooltipOwner ~= nil then
local prevOwner = SpellsTooltipOwner
HideSpellsTooltip()
prevOwner:GetScript("OnEnter")()
end
end
function UpdateAllIncomingHealing()
if HMHealPredict then
for _, ui in ipairs(AllUnitFrames) do
if HMOptions.UseHealPredictions then
local _, guid = UnitExists(ui:GetUnit())
ui:SetIncomingHealing(HMHealPredict.GetIncomingHealing(guid))
else
ui:SetIncomingHealing(0)
end
end
else
for _, ui in ipairs(AllUnitFrames) do
if HMOptions.UseHealPredictions then
ui:UpdateIncomingHealing()
else
ui:SetIncomingHealing(0)
end
end
end
end
function UpdateAllOutlines()
for _, ui in ipairs(AllUnitFrames) do
ui:UpdateOutline()
end
end
function CreateUnitFrameGroup(groupName, environment, units, petGroup, profile, sortByRole)
if UnitFrameGroups[groupName] then
error("[HealersMate] Tried to create a unit frame group using existing name! \""..groupName.."\"")
return
end
local uiGroup = HMUnitFrameGroup:New(groupName, environment, units, petGroup, profile, sortByRole)
for _, unit in ipairs(units) do
local ui = HMUnitFrame:New(unit, AllCustomUnitsSet[unit] ~= nil)
if not HMUnitFrames[unit] then
HMUnitFrames[unit] = {}
end
table.insert(HMUnitFrames[unit], ui)
table.insert(AllUnitFrames, ui)
uiGroup:AddUI(ui)
if unit ~= "target" then
ui:Hide()
end
end
UnitFrameGroups[groupName] = uiGroup
return uiGroup
end
local function initUnitFrames()
local getSelectedProfile = HealersMateSettings.GetSelectedProfile
CreateUnitFrameGroup("Party", "party", PartyUnits, false, getSelectedProfile("Party"))
CreateUnitFrameGroup("Pets", "party", PetUnits, true, getSelectedProfile("Pets"))
CreateUnitFrameGroup("Raid", "raid", RaidUnits, false, getSelectedProfile("Raid"))
CreateUnitFrameGroup("Raid Pets", "raid", RaidPetUnits, true, getSelectedProfile("Raid Pets"))
CreateUnitFrameGroup("Target", "all", TargetUnits, false, getSelectedProfile("Target"), false)
if util.IsSuperWowPresent() then
CreateUnitFrameGroup("Focus", "all", HMUnitProxy.CustomUnitsMap["focus"], false, getSelectedProfile("Focus"), false)
end
UnitFrameGroups["Target"].ShowCondition = function(self)
local friendly = not UnitCanAttack("player", "target")
return (HMOptions.AlwaysShowTargetFrame or (UnitExists("target") and
(friendly and HMOptions.ShowTargets.Friendly) or (not friendly and HMOptions.ShowTargets.Hostile)))
and not HMOptions.Hidden
end
OpenUnitFramesIterator()
end
function EventAddonLoaded()
local freshInstall = false
if HMSpells == nil then
freshInstall = true
local HMSpells = {}
HMSpells["Friendly"] = {}
HMSpells["Hostile"] = {}
setglobal("HMSpells", HMSpells)
end
for _, spells in pairs(HMSpells) do
for _, modifier in ipairs(util.GetKeyModifiers()) do
if not spells[modifier] then
spells[modifier] = {}
end
end
end
if util.IsSuperWowPresent() then
-- In case other addons override unit functions, we want to make sure we're using their functions
HMUnitProxy.CreateUnitProxies()
-- Do it again after all addons have loaded
local frame = CreateFrame("Frame")
local reapply = GetTime() + 0.1
frame:SetScript("OnUpdate", function()
if GetTime() > reapply then
HMUnitProxy.CreateUnitProxies()
frame:SetScript("OnUpdate", nil)
end
end)
end
if not _G.HMRoleCache then
_G.HMRoleCache = {}
end
if not _G.HMRoleCache[GetRealmName()] then
_G.HMRoleCache[GetRealmName()] = {}
end
AssignedRoles = _G.HMRoleCache[GetRealmName()]
PruneAssignedRoles()
if util.IsSuperWowPresent() then
HMUnit.UpdateGuidCaches()
-- SuperWoW currently does not currently allow us to receive events for units that aren't part of normal units, so
-- we're manually updating
local customUnitUpdater = CreateFrame("Frame", "HMCustomUnitUpdater")
local nextUpdate = GetTime() + 0.25
customUnitUpdater:SetScript("OnUpdate", function()
if GetTime() > nextUpdate then
nextUpdate = GetTime() + 0.25
for unit, guid in pairs(CustomUnitGUIDMap) do
HMUnit.Get(unit):UpdateAuras()
for ui in UnitFrames(unit) do
ui:UpdateHealth()
ui:UpdatePower()
ui:UpdateAuras()
end
end
end
end)
else
HMUnit.CreateCaches()
end
HealersMateSettings.UpdateTrackedDebuffTypes()
HMProfileManager.InitializeDefaultProfiles()
HealersMateSettings.SetDefaults()
do
if HMOptions.Scripts.OnLoad then
local scriptString = "local GetProfile = HMProfileManager.GetProfile "..
"local CreateProfile = HMProfileManager.CreateProfile "..HMOptions.Scripts.OnLoad
local script = loadstring(scriptString)
local ok, result = pcall(script)
if not ok then
DEFAULT_CHAT_FRAME:AddMessage(colorize("[HealersMate] ", 1, 0.4, 0.4)..colorize("ERROR: ", 1, 0.2, 0.2)
..colorize("The Load Script produced an error! If this causes HealersMate to fail to load, "..
"you will need to manually edit the script in your game files.", 1, 0.4, 0.4))
DEFAULT_CHAT_FRAME:AddMessage(colorize("OnLoad Script Error: "..tostring(result), 1, 0, 0))
end
end
end
HealersMateSettings.InitSettings()
if HMHealPredict then
HMHealPredict.OnLoad()
HMHealPredict.HookUpdates(function(guid, incomingHealing, incomingDirectHealing)
if not HMOptions.UseHealPredictions then
return
end
local units = GuidRoster.GetUnits(guid)
if not units then
return
end
for _, unit in ipairs(units) do
for ui in UnitFrames(unit) do
ui:SetIncomingHealing(incomingHealing, incomingDirectHealing)
end
end
end)
else
local roster = AceLibrary("RosterLib-2.0")
HealersMateLib:RegisterEvent("HealComm_Healupdate", function(name)
if not HMOptions.UseHealPredictions then
return
end
local unit = roster:GetUnitIDFromName(name)
if unit then
for ui in UnitFrames(unit) do
ui:UpdateIncomingHealing()
end
end
if UnitName("target") == name then
for ui in UnitFrames("target") do
ui:UpdateIncomingHealing()
end
end
end)
HealersMateLib:RegisterEvent("HealComm_Ressupdate", function(name)
local unit = roster:GetUnitIDFromName(name)
if unit then
for ui in UnitFrames(unit) do
ui:UpdateHealth()
end
end
if UnitName("target") == name then
for ui in UnitFrames("target") do
ui:UpdateHealth()
end
end
end)
end
TestUI = HMOptions.TestUI
if TestUI then
DEFAULT_CHAT_FRAME:AddMessage(colorize("[HealersMate] UI Testing is enabled. Use /hm testui to disable.", 1, 0.6, 0.6))
end
initUnitFrames()
StartDistanceScanner()
HealersMateLib:RegisterEvent("Banzai_UnitGainedAggro", function(unit)
if HMGuidRoster then
unit = HMGuidRoster.GetUnitGuid(unit)
end
for ui in UnitFrames(unit) do
ui:UpdateOutline()
end
end)
HealersMateLib:RegisterEvent("Banzai_UnitLostAggro", function(unit)
if HMGuidRoster then
unit = HMGuidRoster.GetUnitGuid(unit)
end
for ui in UnitFrames(unit) do
ui:UpdateOutline()
end
end)
if HMOnLoadInfoDisabled == nil then
HMOnLoadInfoDisabled = false
end
do
local INFO_SEND_TIME = GetTime() + 0.5
local infoFrame = CreateFrame("Frame")
infoFrame:SetScript("OnUpdate", function()
if GetTime() < INFO_SEND_TIME then
return
end
infoFrame:SetScript("OnUpdate", nil)
if not HMOnLoadInfoDisabled then
DEFAULT_CHAT_FRAME:AddMessage(colorize("[HealersMate] Use ", 0.5, 1, 0.5)..colorize("/hm help", 0, 1, 0)
..colorize(" to see commands.", 0.5, 1, 0.5))
end
if not util.IsSuperWowPresent() and util.IsNampowerPresent() then
DEFAULT_CHAT_FRAME:AddMessage(colorize("[HealersMate] ", 1, 0.4, 0.4)..colorize("WARNING: ", 1, 0.2, 0.2)
..colorize("You are using Nampower without SuperWoW, which will cause heal predictions to be wildly inaccurate "..
"for you and your raid members! It is highly recommended to install SuperWoW.", 1, 0.4, 0.4))
end
if util.IsSuperWowPresent() and not HealComm:IsEventRegistered("UNIT_CASTEVENT") then
DEFAULT_CHAT_FRAME:AddMessage(colorize("[HealersMate] ", 1, 0.4, 0.4)..colorize("WARNING: ", 1, 0.2, 0.2)
..colorize("You have another addon that uses a HealComm version that is incompatible with SuperWoW! "..
"This will cause wildly inaccurate heal predictions to be shown to your raid members. It is "..
"recommended to either unload the offending addon or copy HealersMate's HealComm "..
"into the other addon.", 1, 0.4, 0.4))
end
end)
end
-- Create default bindings for new characters
if freshInstall then
local class = GetClass("player")
local spells = GetSpells()
local hostileSpells = GetHostileSpells()
if class == "PRIEST" then
spells["None"]["LeftButton"] = "Power Word: Shield"
spells["None"]["MiddleButton"] = "Renew"
spells["None"]["RightButton"] = "Lesser Heal"
spells["Shift"]["LeftButton"] = "Target"
spells["Shift"]["RightButton"] = "Context"
spells["Control"]["RightButton"] = "Dispel Magic"
hostileSpells["None"]["RightButton"] = "Dispel Magic"
elseif class == "DRUID" then
spells["None"]["LeftButton"] = "Rejuvenation"
spells["None"]["RightButton"] = "Healing Touch"
spells["Shift"]["LeftButton"] = "Target"
spells["Shift"]["MiddleButton"] = "Role"
spells["Shift"]["RightButton"] = "Context"
spells["Control"]["RightButton"] = "Remove Curse"
elseif class == "PALADIN" then
spells["None"]["LeftButton"] = "Flash of Light"
spells["None"]["RightButton"] = "Holy Light"
spells["Shift"]["LeftButton"] = "Target"
spells["Shift"]["MiddleButton"] = "Role"
spells["Shift"]["RightButton"] = "Context"
spells["Control"]["RightButton"] = "Cleanse"
elseif class == "SHAMAN" then
spells["None"]["LeftButton"] = "Healing Wave"