-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathOmniBar.lua
1635 lines (1421 loc) · 47.7 KB
/
OmniBar.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
-- OmniBar by Jordon
local addonName, addon = ...
local COMBATLOG_FILTER_STRING_UNKNOWN_UNITS = COMBATLOG_FILTER_STRING_UNKNOWN_UNITS
local COMBATLOG_OBJECT_REACTION_HOSTILE = COMBATLOG_OBJECT_REACTION_HOSTILE
local COMBATLOG_OBJECT_TYPE_PLAYER = COMBATLOG_OBJECT_TYPE_PLAYER
local C_Timer_After = C_Timer.After
local CanInspect = CanInspect
local ClearInspectPlayer = ClearInspectPlayer
local CombatLogGetCurrentEventInfo = CombatLogGetCurrentEventInfo
local CreateFrame = CreateFrame
local DEFAULT_CHAT_FRAME = DEFAULT_CHAT_FRAME
local GetArenaOpponentSpec = GetArenaOpponentSpec
local GetBattlefieldScore = GetBattlefieldScore
local GetClassInfo = GetClassInfo
local GetInspectSpecialization = GetInspectSpecialization
local GetNumBattlefieldScores = GetNumBattlefieldScores
local GetNumGroupMembers = GetNumGroupMembers
local GetNumSpecializationsForClassID = GetNumSpecializationsForClassID
local GetPlayerInfoByGUID = GetPlayerInfoByGUID
local GetRaidRosterInfo = GetRaidRosterInfo
local GetServerTime = GetServerTime
local GetSpecialization = GetSpecialization
local GetSpecializationInfo = GetSpecializationInfo
local GetSpecializationInfoByID = GetSpecializationInfoByID
local GetSpecializationInfoForClassID = GetSpecializationInfoForClassID
local GetSpellInfo = C_Spell and C_Spell.GetSpellInfo or GetSpellInfo
local GetSpellTexture = C_Spell and C_Spell.GetSpellTexture or GetSpellTexture
local GetTime = GetTime
local GetUnitName = GetUnitName
local GetZonePVPInfo = GetZonePVPInfo
local InCombatLockdown = InCombatLockdown
local InterfaceOptionsFrame_OpenToCategory = InterfaceOptionsFrame_OpenToCategory
local IsInGroup = IsInGroup
local IsInGuild = IsInGuild
local IsInInstance = IsInInstance
local IsInRaid = IsInRaid
local IsRatedBattleground = C_PvP.IsRatedBattleground
local LE_PARTY_CATEGORY_INSTANCE = LE_PARTY_CATEGORY_INSTANCE
local LibStub = LibStub
local MAX_CLASSES = MAX_CLASSES
local NotifyInspect = NotifyInspect
local SlashCmdList = SlashCmdList
local UIParent = UIParent
local UNITNAME_SUMMON_TITLE1 = UNITNAME_SUMMON_TITLE1
local UNITNAME_SUMMON_TITLE2 = UNITNAME_SUMMON_TITLE2
local UNITNAME_SUMMON_TITLE3 = UNITNAME_SUMMON_TITLE3
local UnitClass = UnitClass
local UnitExists = UnitExists
local UnitGUID = UnitGUID
local UnitInParty = UnitInParty
local UnitInRaid = UnitInRaid
local UnitIsPlayer = UnitIsPlayer
local UnitIsPossessed = UnitIsPossessed
local UnitIsUnit = UnitIsUnit
local UnitReaction = UnitReaction
local WOW_PROJECT_CLASSIC = WOW_PROJECT_CLASSIC
local WOW_PROJECT_ID = WOW_PROJECT_ID
local WOW_PROJECT_MAINLINE = WOW_PROJECT_MAINLINE
local bit_band = bit.band
local date = date
local tinsert = tinsert
local wipe = wipe
local tContains = tContains
local function GetSpellName(id)
if C_Spell and C_Spell.GetSpellName then
return C_Spell.GetSpellName(id)
else
return GetSpellInfo(id)
end
end
OmniBar = LibStub("AceAddon-3.0"):NewAddon("OmniBar", "AceEvent-3.0", "AceComm-3.0", "AceSerializer-3.0")
local L = LibStub("AceLocale-3.0"):GetLocale("OmniBar")
-- Apply cooldown adjustments
for k,v in pairs(addon.Cooldowns) do
if v.duration and type(v.duration) == "number" then
local adjust = v.adjust or 0
if type(adjust) == "table" then
adjust = adjust.default or 0 -- use default for now
end
addon.Cooldowns[k].duration = v.duration + adjust
end
end
local CLASS_ORDER = {
["GENERAL"] = 0,
["DEMONHUNTER"] = 1,
["DEATHKNIGHT"] = 2,
["PALADIN"] = 3,
["WARRIOR"] = 4,
["DRUID"] = 5,
["PRIEST"] = 6,
["WARLOCK"] = 7,
["SHAMAN"] = 8,
["HUNTER"] = 9,
["MAGE"] = 10,
["ROGUE"] = 11,
["MONK"] = 12,
["EVOKER"] = 13,
}
local MAX_ARENA_SIZE = addon.MAX_ARENA_SIZE or 0
local PLAYER_NAME = GetUnitName("player")
local DEFAULTS = {
adaptive = false,
align = "CENTER",
arena = true,
battleground = true,
border = true,
center = false,
columns = 8,
cooldownCount = true,
glow = true,
growUpward = true,
highlightFocus = false,
highlightTarget = true,
locked = false,
maxIcons = 32,
multiple = true,
names = false,
padding = 2,
ratedBattleground = true,
scenario = true,
showUnused = false,
size = 40,
swipeAlpha = 0.65,
tooltips = true,
trackUnit = "ENEMY",
unusedAlpha = 0.45,
world = true,
}
local DB_VERSION = 4
local MAX_DUPLICATE_ICONS = 5
local BASE_ICON_SIZE = 36
function OmniBar:Print(message)
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99OmniBar|r: " .. message)
end
function OmniBar:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("OmniBarDB", {
global = { version = DB_VERSION, cooldowns = {} },
profile = { bars = {} }
}, true)
self.cooldowns = addon.Cooldowns
self.bars = {}
self.specs = {}
self.spellCasts = {}
self.db.RegisterCallback(self, "OnProfileChanged", "OnEnable")
self.db.RegisterCallback(self, "OnProfileCopied", "OnEnable")
self.db.RegisterCallback(self, "OnProfileReset", "OnEnable")
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:RegisterEvent("GROUP_ROSTER_UPDATE", "GetSpecs")
self:RegisterComm("OmniBarSpell", function(_, payload, _, sender)
if (not UnitExists(sender)) or sender == PLAYER_NAME then return end
local success, event, sourceGUID, sourceName, sourceFlags, spellID, serverTime = self:Deserialize(payload)
if (not success) then return end
self:AddSpellCast(event, sourceGUID, sourceName, sourceFlags, spellID, serverTime)
end)
-- Set version
local version, major, minor = C_AddOns.GetAddOnMetadata(addonName, "Version") or "", 0, 0
if version:sub(1, 1) == "@" then
version = "Development"
else
major, minor = version:match("v(%d+)%.?(%d*)")
end
self.version = setmetatable({
string = version,
major = tonumber(major),
minor = tonumber(minor) or 0,
}, {
__tostring = function()
return version
end
})
-- Check if update available
if self.version.major > 0 then
self:RegisterComm("OmniBarVersion", "ReceiveVersion")
self:RegisterEvent("ZONE_CHANGED_NEW_AREA", "SendVersion")
C_Timer_After(10, function()
self:SendVersion()
if IsInGuild() then self:SendVersion("GUILD") end
self:SendVersion("YELL")
end)
end
-- Remove invalid custom cooldowns
for k,v in pairs(self.db.global.cooldowns) do
if (not GetSpellInfo(k)) then
self.db.global.cooldowns[k] = nil
end
end
-- Populate cooldowns with spell names and icons
for spellId,_ in pairs(self.cooldowns) do
local name, icon
if C_Spell and C_Spell.GetSpellInfo then
local spellInfo = C_Spell.GetSpellInfo(spellId)
name = spellInfo and spellInfo.name
icon = spellInfo and spellInfo.iconID
else
name, _, icon = GetSpellInfo(spellId)
end
self.cooldowns[spellId].icon = self.cooldowns[spellId].icon or icon
self.cooldowns[spellId].name = name
end
self:SetupOptions()
end
local function GetDefaultCommChannel()
if IsInRaid() then
return IsInRaid(LE_PARTY_CATEGORY_INSTANCE) and "INSTANCE_CHAT" or "RAID"
elseif IsInGroup() then
return IsInGroup(LE_PARTY_CATEGORY_INSTANCE) and "INSTANCE_CHAT" or "PARTY"
elseif IsInGuild() then
return "GUILD"
else
return "YELL"
end
end
function OmniBar:ReceiveVersion(_, payload, _, sender)
self.sender = sender
if (not payload) or type(payload) ~= "string" then return end
local major, minor = payload:match("v(%d+)%.?(%d*)")
major = tonumber(major)
minor = tonumber(minor) or 0
if (not major) or (not minor) then return end
if major < self.version.major then return end
if major == self.version.major and minor <= self.version.minor then return end
if (not self.outdatedSender) or self.outdatedSender == sender then
self.outdatedSender = sender
return
end
if self.nextWarn and self.nextWarn > GetTime() then return end
self.nextWarn = GetTime() + 1800
self:Print(L.UPDATE_AVAILABLE)
self.outdatedSender = nil
end
function OmniBar:SendVersion(distribution)
if (not self.version) or self.version.major == 0 then return end
self:SendCommMessage("OmniBarVersion", self.version.string, distribution or GetDefaultCommChannel())
end
function OmniBar:OnEnable()
wipe(self.specs)
wipe(self.spellCasts)
self.index = 1
for i = #self.bars, 1, -1 do
self:Delete(self.bars[i].key, true)
table.remove(self.bars, i)
end
for key,_ in pairs(self.db.profile.bars) do
self:Initialize(key)
self.index = self.index + 1
end
-- Create a default bar if none exist
if self.index == 1 then
self:Initialize("OmniBar1", "OmniBar")
self.index = 2
end
for key,_ in pairs(self.db.profile.bars) do
self:AddBarToOptions(key)
end
self:Refresh(true)
end
function OmniBar:Decode(encoded)
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local decoded = LibDeflate:DecodeForPrint(encoded)
if (not decoded) then return self:ImportError("DecodeForPrint") end
local decompressed = LibDeflate:DecompressZlib(decoded)
if (not decompressed) then return self:ImportError("DecompressZlib") end
local success, deserialized = self:Deserialize(decompressed)
if (not success) then return self:ImportError("Deserialize") end
return deserialized
end
function OmniBar:ExportProfile()
local LibDeflate = LibStub:GetLibrary("LibDeflate")
local data = {
profile = self.db.profile,
customSpells = self.db.global.cooldowns,
version = 1
}
local serialized = self:Serialize(data)
if (not serialized) then return end
local compressed = LibDeflate:CompressZlib(serialized)
if (not compressed) then return end
return LibDeflate:EncodeForPrint(compressed)
end
function OmniBar:ImportError(message)
if (not message) or self.import.editBox.editBox:GetNumLetters() == 0 then
self.import.statustext:SetTextColor(1, 0.82, 0)
self.import:SetStatusText(L["Paste a code to import an OmniBar profile."])
else
self.import.statustext:SetTextColor(1, 0, 0)
self.import:SetStatusText(L["Import failed (%s)"]:format(message))
end
self.import.button:SetDisabled(true)
end
function OmniBar:ImportProfile(data)
if (data.version ~= 1) then return self:ImportError(L["Invalid version"]) end
local profile = L["Imported (%s)"]:format(date())
self.db.profiles[profile] = data.profile
self.db:SetProfile(profile)
-- merge custom spells
for k,v in pairs(data.customSpells) do
self.db.global.cooldowns[k] = nil
self.options.args.customSpells.args.spellId.set(nil, k, v)
end
self:OnEnable()
LibStub("AceConfigRegistry-3.0"):NotifyChange("OmniBar")
return true
end
function OmniBar:ShowExport()
self.export.editBox:SetText(self:ExportProfile())
self.export:Show()
self.export.editBox:SetFocus()
self.export.editBox:HighlightText()
-- self.export.editBox:HighlightText(0, self.export.editBox.editBox:GetNumLetters())
end
function OmniBar:ShowImport()
self.import.editBox:SetText("")
self:ImportError()
self.import:Show()
self.import.button:SetDisabled(true)
self.import.editBox:SetFocus()
end
function OmniBar:Delete(key, keepProfile)
local bar = _G[key]
if (not bar) then return end
bar:UnregisterEvent("PLAYER_ENTERING_WORLD")
bar:UnregisterEvent("ZONE_CHANGED_NEW_AREA")
bar:UnregisterEvent("PLAYER_TARGET_CHANGED")
bar:UnregisterEvent("PLAYER_REGEN_DISABLED")
bar:UnregisterEvent("GROUP_ROSTER_UPDATE")
bar:UnregisterEvent("UPDATE_BATTLEFIELD_SCORE")
if WOW_PROJECT_ID ~= WOW_PROJECT_CLASSIC then
bar:UnregisterEvent("PLAYER_FOCUS_CHANGED")
bar:UnregisterEvent("ARENA_OPPONENT_UPDATE")
end
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
bar:UnregisterEvent("ARENA_PREP_OPPONENT_SPECIALIZATIONS")
bar:UnregisterEvent("UPDATE_BATTLEFIELD_STATUS")
bar:UnregisterEvent("PVP_MATCH_ACTIVE")
end
bar:Hide()
if (not keepProfile) then self.db.profile.bars[key] = nil end
self.options.args.bars.args[key] = nil
LibStub("AceConfigRegistry-3.0"):NotifyChange("OmniBar")
end
OmniBar.BackupCooldowns = {}
function OmniBar:CopyCooldown(cooldown)
local copy = {}
for _,v in pairs({"class", "charges", "parent", "name", "icon"}) do
if cooldown[v] then
copy[v] = cooldown[v]
end
end
if cooldown.duration then
if type(cooldown.duration) == "table" then
copy.duration = {}
for k, v in pairs(cooldown.duration) do
copy.duration[k] = v
end
else
copy.duration = { default = cooldown.duration }
end
end
if cooldown.specID then
copy.specID = {}
for i = 1, #cooldown.specID do
table.insert(copy.specID, cooldown.specID[i])
end
end
return copy
end
-- create a lookup table since CombatLogGetCurrentEventInfo() returns 0 for spellId
local SPELL_ID_BY_NAME
if WOW_PROJECT_ID == WOW_PROJECT_CLASSIC then
SPELL_ID_BY_NAME = {}
for id, value in pairs(addon.Cooldowns) do
if (not value.parent) then SPELL_ID_BY_NAME[GetSpellName(id)] = id end
end
end
function OmniBar:AddCustomSpells()
-- Restore any overrides
for k,v in pairs(self.BackupCooldowns) do
addon.Cooldowns[k] = self:CopyCooldown(v)
end
-- Add custom spells
for k,v in pairs(self.db.global.cooldowns) do
local name, _, icon
if C_Spell and C_Spell.GetSpellInfo then
local spellInfo = C_Spell.GetSpellInfo(k)
name = spellInfo and spellInfo.name
icon = spellInfo and spellInfo.iconID
else
name, _, icon = GetSpellInfo(k)
end
if name then
-- Backup if we are going to override
if addon.Cooldowns[k] and (not addon.Cooldowns[k].custom) and (not self.BackupCooldowns[k]) then
self.BackupCooldowns[k] = self:CopyCooldown(addon.Cooldowns[k])
end
addon.Cooldowns[k] = v
addon.Cooldowns[k].icon = addon.Cooldowns[k].icon or icon
addon.Cooldowns[k].name = name
if SPELL_ID_BY_NAME then SPELL_ID_BY_NAME[name] = k end
else
self.db.global.cooldowns[k] = nil
end
end
end
local function OmniBar_IsAdaptive(self)
if self.settings.adaptive then return true end
-- force adaptive in arena since enemies are finite and known
if self.zone == "arena" then return true end
-- everything but all enemies are known, so force adaptive
if self.settings.trackUnit ~= "ENEMY" then return true end
end
function OmniBar_SpellCast(self, event, name, spellID)
if self.disabled then return end
-- if GetZonePVPInfo() == "sanctuary" then return end
OmniBar_AddIcon(self, self.spellCasts[name][spellID])
end
function OmniBar:Initialize(key, name)
if (not self.db.profile.bars[key]) then
self.db.profile.bars[key] = { name = name }
for a,b in pairs(DEFAULTS) do
self.db.profile.bars[key][a] = b
end
end
self:AddCustomSpells()
local f = _G[key] or CreateFrame("Frame", key, UIParent, "OmniBarTemplate")
f:Show()
f.settings = self.db.profile.bars[key]
f.settings.align = f.settings.align or "CENTER"
f.settings.maxIcons = f.settings.maxIcons or DEFAULTS.maxIcons
f.key = key
f.icons = {}
f.active = {}
f.detected = {}
f.spellCasts = self.spellCasts
f.specs = self.specs
f.BASE_ICON_SIZE = BASE_ICON_SIZE
f.numIcons = 0
f:RegisterForDrag("LeftButton")
f.anchor.text:SetText(f.settings.name)
-- Upgrade units
f.settings.units = nil
if (not f.settings.trackUnit) then f.settings.trackUnit = "ENEMY" end
-- Remove invalid spells
if f.settings.spells then
for k,_ in pairs(f.settings.spells) do
if (not addon.Cooldowns[k]) or addon.Cooldowns[k].parent then f.settings.spells[k] = nil end
end
end
f.adaptive = OmniBar_IsAdaptive(f)
-- Upgrade custom spells
for k,v in pairs(f.settings) do
local spellID = tonumber(k:match("^spell(%d+)"))
if spellID then
if (not f.settings.spells) then
f.settings.spells = {}
if (not f.settings.noDefault) then
for k,v in pairs(addon.Cooldowns) do
if v.default then f.settings.spells[k] = true end
end
end
end
f.settings.spells[spellID] = v
f.settings[k] = nil
end
end
f.settings.noDefault = nil
-- Load the settings
OmniBar_LoadSettings(f)
-- Create the icons
for spellID,_ in pairs(addon.Cooldowns) do
if OmniBar_IsSpellEnabled(f, spellID) then
OmniBar_CreateIcon(f)
end
end
-- Create the duplicate icons
for i = 1, MAX_DUPLICATE_ICONS do
OmniBar_CreateIcon(f)
end
OmniBar_ShowAnchor(f)
OmniBar_ResetIcons(f)
OmniBar_UpdateIcons(f)
OmniBar_Center(f)
f.OnEvent = OmniBar_OnEvent
f:RegisterEvent("PLAYER_ENTERING_WORLD", "OnEvent")
f:RegisterEvent("ZONE_CHANGED_NEW_AREA", "OnEvent")
f:RegisterEvent("PLAYER_TARGET_CHANGED", "OnEvent")
f:RegisterEvent("PLAYER_REGEN_DISABLED", "OnEvent")
f:RegisterEvent("GROUP_ROSTER_UPDATE", "OnEvent")
if WOW_PROJECT_ID ~= WOW_PROJECT_CLASSIC then
f:RegisterEvent("PLAYER_FOCUS_CHANGED", "OnEvent")
f:RegisterEvent("ARENA_OPPONENT_UPDATE", "OnEvent")
end
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
f:RegisterEvent("ARENA_PREP_OPPONENT_SPECIALIZATIONS", "OnEvent")
f:RegisterEvent("UPDATE_BATTLEFIELD_STATUS", "OnEvent")
f:RegisterEvent("PVP_MATCH_ACTIVE", "OnEvent")
end
f:RegisterEvent("UPDATE_BATTLEFIELD_SCORE", "OnEvent")
table.insert(self.bars, f)
end
function OmniBar:Create()
while true do
local key = "OmniBar"..self.index
self.index = self.index + 1
if (not self.db.profile.bars[key]) then
self:Initialize(key, "OmniBar " .. (self.index - 1))
self:AddBarToOptions(key, true)
self:OnEnable()
return
end
end
end
function OmniBar:Refresh(full)
self:GetSpecs()
for key,_ in pairs(self.db.profile.bars) do
local f = _G[key]
if f then
f.container:SetScale(f.settings.size/BASE_ICON_SIZE)
if full then
f.adaptive = OmniBar_IsAdaptive(f)
OmniBar_OnEvent(f, "PLAYER_ENTERING_WORLD")
OmniBar_OnEvent(f, "PLAYER_TARGET_CHANGED")
OmniBar_OnEvent(f, "PLAYER_FOCUS_CHANGED")
OmniBar_OnEvent(f, "GROUP_ROSTER_UPDATE")
else
OmniBar_LoadPosition(f)
OmniBar_UpdateIcons(f)
OmniBar_Center(f)
end
end
end
end
local Masque = LibStub and LibStub("Masque", true)
-- create a lookup table to translate spec names into IDs
local SPEC_ID_BY_NAME = {}
if WOW_PROJECT_ID == WOW_PROJECT_MAINLINE then
for classID = 1, MAX_CLASSES do
local _, classToken = GetClassInfo(classID)
SPEC_ID_BY_NAME[classToken] = {}
for i = 1, GetNumSpecializationsForClassID(classID) do
local id, name = GetSpecializationInfoForClassID(classID, i)
SPEC_ID_BY_NAME[classToken][name] = id
end
end
end
local function UnitIsHostile(unit)
if (not unit) then return end
if UnitIsUnit("player", unit) then return end
local reaction = UnitReaction("player", unit)
if (not reaction) then return end -- out of range
return UnitIsPlayer(unit) and reaction < 4 and (not UnitIsPossessed(unit))
end
function OmniBar_ShowAnchor(self)
if self.disabled or self.settings.locked or #self.active > 0 then
self.anchor:Hide()
else
local width = self.anchor.text:GetWidth() + 29
self.anchor:SetSize(width, 30)
self.anchor:Show()
end
end
function OmniBar_CreateIcon(self)
if InCombatLockdown() then return end
self.numIcons = self.numIcons + 1
local name = self:GetName()
local key = name.."Icon"..self.numIcons
local f = _G[key] or CreateFrame("Button", key, _G[name.."Icons"], "OmniBarButtonTemplate")
table.insert(self.icons, f)
end
local function SpellBelongsToSpec(spellID, specID)
if (not specID) then return true end
if (not addon.Cooldowns[spellID].specID) then return true end
for i = 1, #addon.Cooldowns[spellID].specID do
if addon.Cooldowns[spellID].specID[i] == specID then return true end
end
end
function OmniBar_AddIconsByClass(self, class, sourceGUID, specID)
for spellID, spell in pairs(addon.Cooldowns) do
if OmniBar_IsSpellEnabled(self, spellID) and
(spell.class == "GENERAL" or (spell.class == class and SpellBelongsToSpec(spellID, specID)))
then
OmniBar_AddIcon(self, { spellID = spellID, sourceGUID = sourceGUID, specID = specID })
end
end
end
local function IconIsUnit(iconGUID, guid)
if (not guid) then return end
if type(iconGUID) == "number" then
-- arena target
return UnitGUID("arena" .. iconGUID) == guid
end
return iconGUID == guid
end
local function OmniBar_StartAnimation(self, icon)
if (not self.settings.glow) then return end
icon.flashAnim:Play()
icon.newitemglowAnim:Play()
end
local function OmniBar_StopAnimation(self, icon)
if icon.flashAnim:IsPlaying() then icon.flashAnim:Stop() end
if icon.newitemglowAnim:IsPlaying() then icon.newitemglowAnim:Stop() end
end
function OmniBar_UpdateBorder(self, icon)
local border
local guid = icon.sourceGUID
local name = icon.sourceName
if guid or name then
if self.settings.highlightFocus and
self.settings.trackUnit == "ENEMY" and
(IconIsUnit(guid, UnitGUID("focus")) or name == GetUnitName("focus", true)) and
UnitIsPlayer("focus")
then
icon.FocusTexture:SetAlpha(1)
border = true
else
icon.FocusTexture:SetAlpha(0)
end
if self.settings.highlightTarget and
self.settings.trackUnit == "ENEMY" and
(IconIsUnit(guid, UnitGUID("target")) or name == GetUnitName("target", true)) and
UnitIsPlayer("target")
then
icon.FocusTexture:SetAlpha(0)
icon.TargetTexture:SetAlpha(1)
border = true
else
icon.TargetTexture:SetAlpha(0)
end
else
local _, class = UnitClass("focus")
if self.settings.highlightFocus and
self.settings.trackUnit == "ENEMY" and
class and (class == icon.class or icon.class == "GENERAL") and
UnitIsPlayer("focus")
then
icon.FocusTexture:SetAlpha(1)
border = true
else
icon.FocusTexture:SetAlpha(0)
end
_, class = UnitClass("target")
if self.settings.highlightTarget and
self.settings.trackUnit == "ENEMY" and
class and (class == icon.class or icon.class == "GENERAL") and
UnitIsPlayer("target")
then
icon.FocusTexture:SetAlpha(0)
icon.TargetTexture:SetAlpha(1)
border = true
else
icon.TargetTexture:SetAlpha(0)
end
end
-- Set dim
icon:SetAlpha(self.settings.unusedAlpha and
icon.cooldown:GetCooldownTimes() == 0 and
(not border) and
self.settings.unusedAlpha or 1)
end
function OmniBar_UpdateAllBorders(self)
for i = 1, #self.active do
OmniBar_UpdateBorder(self, self.active[i])
end
end
function OmniBar_SetZone(self, refresh)
local disabled = self.disabled
local _, zone = IsInInstance()
-- if zone == "none" then
-- SetMapToCurrentZone()
-- zone = GetCurrentMapAreaID()
-- end
self.zone = zone
self.rated = IsRatedBattleground and IsRatedBattleground()
self.disabled = (zone == "arena" and (not self.settings.arena)) or
(self.rated and (not self.settings.ratedBattleground)) or
(zone == "pvp" and (not self.settings.battleground) and (not self.rated)) or
(zone == "scenario" and (not self.settings.scenario)) or
(zone ~= "arena" and zone ~= "pvp" and zone ~= "scenario" and (not self.settings.world))
self.adaptive = OmniBar_IsAdaptive(self)
if refresh or disabled ~= self.disabled then
OmniBar_LoadPosition(self)
OmniBar_ResetIcons(self)
OmniBar_UpdateIcons(self)
OmniBar_ShowAnchor(self)
if zone == "arena" and (not self.disabled) then
wipe(self.detected)
wipe(self.specs)
wipe(self.spellCasts)
OmniBar_OnEvent(self, "ARENA_OPPONENT_UPDATE")
end
end
end
local UNITNAME_SUMMON_TITLES = {
UNITNAME_SUMMON_TITLE1,
UNITNAME_SUMMON_TITLE2,
UNITNAME_SUMMON_TITLE3,
}
local tooltip = CreateFrame("GameTooltip", "OmniBarPetTooltip", nil, "GameTooltipTemplate")
local tooltipText = OmniBarPetTooltipTextLeft2
local function UnitOwnerName(guid)
if (not guid) then return end
for i = 1, 3 do
_G["UNITNAME_SUMMON_TITLE" .. i] = "OmniBar %s"
end
tooltip:SetOwner(UIParent, "ANCHOR_NONE")
tooltip:SetHyperlink("unit:" .. guid)
local name = tooltipText:GetText()
for i = 1, 3 do
_G["UNITNAME_SUMMON_TITLE" .. i] = UNITNAME_SUMMON_TITLES[i]
end
if (not name) then return end
local owner = name:match("OmniBar (.+)")
if owner then return owner end
end
local function IsSourceHostile(sourceFlags)
local band = bit_band(sourceFlags, COMBATLOG_OBJECT_REACTION_HOSTILE)
if UnitIsPossessed("player") and band == 0 then return true end
return band == COMBATLOG_OBJECT_REACTION_HOSTILE
end
local function GetCooldownDuration(cooldown, specID)
if (not cooldown.duration) then return end
if type(cooldown.duration) == "table" then
if specID and cooldown.duration[specID] then
return cooldown.duration[specID]
else
return cooldown.duration.default
end
else
return cooldown.duration
end
end
function OmniBar:AddSpellCast(event, sourceGUID, sourceName, sourceFlags, spellID, serverTime, customDuration)
local isLocal = (not serverTime)
serverTime = serverTime or GetServerTime()
-- activate shared cooldowns
if (not customDuration) then
for i = 1, #addon.Shared do
local shared = addon.Shared[i]
if (shared.triggers and tContains(shared.triggers, spellID)) or tContains(shared.spells, spellID) then
for i = 1, #shared.spells do
if spellID ~= shared.spells[i] then
local amount = shared.amount
-- use default until we add spec detection
if type(amount) == "table" then amount = shared.amount.default end
if addon.Cooldowns[shared.spells[i]] and (not addon.Cooldowns[shared.spells[i]].parent) then
self:AddSpellCast(
event,
sourceGUID,
sourceName,
sourceFlags,
shared.spells[i],
nil, -- set to `serverTime` to disable sync
amount
)
end
end
end
end
end
end
if (not addon.Resets[spellID]) and (not addon.Cooldowns[spellID]) then return end
-- unset unknown sourceName
sourceName = sourceName == COMBATLOG_FILTER_STRING_UNKNOWN_UNITS and nil or sourceName
-- if it's a pet associate with owner
local ownerName = UnitOwnerName(sourceGUID)
local name = ownerName or sourceName
if (not name) then return end
if addon.Resets[spellID] and self.spellCasts[name] and event == "SPELL_CAST_SUCCESS" then
for i = 1, #addon.Resets[spellID] do
local reset = addon.Resets[spellID][i]
if type(reset) == "table" and reset.amount then
if self.spellCasts[name][reset.spellID] then
self.spellCasts[name][reset.spellID].duration = self.spellCasts[name][reset.spellID].duration - reset.amount
if self.spellCasts[name][reset.spellID].duration < 1 then
self.spellCasts[name][reset.spellID] = nil
end
end
else
if type(reset) == "table" then reset = reset.spellID end
self.spellCasts[name][reset] = nil
end
end
self:SendMessage("OmniBar_ResetSpellCast", name, spellID)
end
if (not addon.Cooldowns[spellID]) then return end
local now = GetTime()
local charges = addon.Cooldowns[spellID].charges
local duration = customDuration or GetCooldownDuration(addon.Cooldowns[spellID])
-- make sure spellID is parent
spellID = addon.Cooldowns[spellID].parent or spellID
-- make sure we aren't adding a duplicate,
-- and if it is a shared cooldown make sure we don't overwrite
if self.spellCasts[name] and
self.spellCasts[name][spellID] and
(customDuration or self.spellCasts[name][spellID].serverTime == serverTime)
then
return
end
-- only track players and their pets
if (not ownerName) and bit_band(sourceFlags, COMBATLOG_OBJECT_TYPE_PLAYER) == 0 then return end
-- child doesn't have custom charges, use parent
if (not charges) then
charges = addon.Cooldowns[spellID].charges
end
-- child doesn't have a custom duration, use parent
if (not duration) then
duration = GetCooldownDuration(addon.Cooldowns[spellID])
end
-- combat log is clamped in classic, so make sure our raid members detect the cast
-- if WOW_PROJECT_ID ~= WOW_PROJECT_MAINLINE and isLocal then
-- self:AlertGroup(event, sourceGUID, sourceName, sourceFlags, spellID, serverTime)
-- end
self.spellCasts[name] = self.spellCasts[name] or {}
self.spellCasts[name][spellID] = {
charges = charges,
duration = duration,
event = event,
expires = now + duration,
ownerName = ownerName,
serverTime = serverTime,
sourceFlags = sourceFlags,
sourceGUID = sourceGUID,
sourceName = sourceName,
spellID = spellID,
spellName = GetSpellName(spellID),
timestamp = now,
}
self:SendMessage("OmniBar_SpellCast", name, spellID)
end
function OmniBar:AlertGroup(...)
if (not IsInGroup()) or GetNumGroupMembers() > 5 then return end
local event, sourceGUID, sourceName, sourceFlags, spellID, serverTime = ...
self:SendCommMessage("OmniBarSpell", self:Serialize(...), GetDefaultCommChannel(), nil, "ALERT")
end
-- Needed to track PvP trinkets and possibly other spells that do not show up in COMBAT_LOG_EVENT_UNFILTERED
function OmniBar:UNIT_SPELLCAST_SUCCEEDED(event, unit, _, spellID)
if (not addon.Cooldowns[spellID]) then return end
local sourceFlags = 0
if UnitReaction("player", unit) < 4 then
sourceFlags = sourceFlags + COMBATLOG_OBJECT_REACTION_HOSTILE
end
if UnitIsPlayer(unit) then
sourceFlags = sourceFlags + COMBATLOG_OBJECT_TYPE_PLAYER
end
self:AddSpellCast(event, UnitGUID(unit), GetUnitName(unit, true), sourceFlags, spellID)
end
function OmniBar:COMBAT_LOG_EVENT_UNFILTERED()
local _, event, _, sourceGUID, sourceName, sourceFlags, _,_,_,_,_, spellID, spellName = CombatLogGetCurrentEventInfo()
if (event == "SPELL_CAST_SUCCESS" or event == "SPELL_AURA_APPLIED") then
if spellID == 0 and SPELL_ID_BY_NAME then spellID = SPELL_ID_BY_NAME[spellName] end
self:AddSpellCast(event, sourceGUID, sourceName, sourceFlags, spellID)
end
end
function OmniBar_Refresh(self)
OmniBar_ResetIcons(self)
OmniBar_ReplaySpellCasts(self)
end
function OmniBar_OnEvent(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
OmniBar_SetZone(self, true)
OmniBar_OnEvent(self, "ARENA_PREP_OPPONENT_SPECIALIZATIONS")
elseif event == "ZONE_CHANGED_NEW_AREA" then
OmniBar_SetZone(self, true)
elseif event == "UPDATE_BATTLEFIELD_STATUS" then -- IsRatedBattleground() doesn't return valid response until this event
if self.disabled or self.zone ~= "pvp" then return end
if (not self.rated) and IsRatedBattleground() then OmniBar_SetZone(self) end
elseif event == "UPDATE_BATTLEFIELD_SCORE" then
for i = 1, GetNumBattlefieldScores() do
local name, _,_,_,_,_,_,_, classToken, _,_,_,_,_,_, talentSpec = GetBattlefieldScore(i)
if name and SPEC_ID_BY_NAME[classToken] and SPEC_ID_BY_NAME[classToken][talentSpec] then
if (not self.specs[name]) then