forked from vendethiel/GladiusEx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGladiusEx.lua
executable file
·1714 lines (1457 loc) · 50.8 KB
/
GladiusEx.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
GladiusEx = LibStub("AceAddon-3.0"):NewAddon("GladiusEx", "AceEvent-3.0")
GladiusEx.IS_RETAIL = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE
GladiusEx.IS_TBCC = WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC
GladiusEx.IS_WOTLKC = WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC
GladiusEx.IS_CLASSIC = GladiusEx.IS_TBCC or GladiusEx.IS_WOTLKC
local LGIST = GladiusEx.IS_RETAIL and LibStub:GetLibrary("LibGroupInSpecT-1.1")
local L = LibStub("AceLocale-3.0"):GetLocale("GladiusEx")
local RC = LibStub("LibRangeCheck-2.0")
local LSM = LibStub("LibSharedMedia-3.0")
local fn = LibStub("LibFunctional-1.0")
-- upvalues
local select, type, pairs, tonumber, wipe = select, type, pairs, tonumber, wipe
local strfind, strmatch = string.find, string.match
local max, abs, floor, ceil = math.max, math.abs, math.floor, math.ceil
local UnitIsDeadOrGhost, UnitGUID, UnitExists = UnitIsDeadOrGhost, UnitGUID, UnitExists
local InCombatLockdown = InCombatLockdown
local GetNumGroupMembers = GetNumArenaOpponents, GetNumArenaOpponentSpecs, GetNumGroupMembers
local arena_units = {
["arena1"] = true,
["arena2"] = true,
["arena3"] = true,
["arena4"] = true,
["arena5"] = true
}
local party_units = {
["player"] = true,
["party1"] = true,
["party2"] = true,
["party3"] = true,
["party4"] = true
}
GladiusEx.party_units = party_units
GladiusEx.arena_units = arena_units
local anchor_width = 260
local anchor_height = 40
local STATE_NORMAL = 0
local STATE_DEAD = 1
local STATE_STEALTH = 2
local RANGE_UPDATE_INTERVAL = 1 / 5
-- debugging output
local log_frame
local log_table
local logging = false
local function log(...)
if not GladiusEx:IsDebugging() then return end
if not log_frame then
log_frame = CreateFrame("ScrollingMessageFrame", "GladiusExLogFrame")
log_frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 10, -50)
log_frame:SetFrameStrata("LOW")
log_frame:SetScript("OnMouseWheel", FloatingChatFrame_OnMouseScroll)
log_frame:EnableMouseWheel(true)
log_frame:SetSize(500, 500)
log_frame:SetFont(STANDARD_TEXT_FONT, 9, "NONE")
log_frame:SetShadowColor(0, 0, 0, 1)
log_frame:SetShadowOffset(1, -1)
log_frame:SetFading(false)
log_frame:SetJustifyH("LEFT")
log_frame:SetIndentedWordWrap(true)
log_frame:SetMaxLines(10000)
log_frame:SetBackdropColor(1, 1, 1, 0.2)
log_frame.starttime = GetTime()
log_frame:SetScale(1)
end
local p = ...
if p == "ENABLE LOGGING" then
GladiusEx.db.base.log = GladiusEx.db.base.log or {}
log_table = { date("%c", time()) }
table.insert(GladiusEx.db.base.log, log_table)
logging = true
log_frame.starttime = GetTime()
elseif p == "DISABLE LOGGING" then
logging = false
end
local msg = string.format("[%.1f] %s", GetTime() - log_frame.starttime, strjoin(" ", tostringall(...)))
if logging then
table.insert(log_table, msg)
end
log_frame:AddMessage(msg)
end
function GladiusEx:IsDebugging()
return self.db.base.debug
end
function GladiusEx:SetDebugging(enabled)
self.db.base.debug = enabled
end
function GladiusEx:Log(...)
log(...)
end
function GladiusEx:Debug(...)
print("|cff33ff99GladiusEx|r:", ...)
end
function GladiusEx:Print(...)
print("|cff33ff99GladiusEx|r:", ...)
end
-- Module prototype
local modulePrototype = {}
function modulePrototype:GetAttachType()
return "Widget"
end
function modulePrototype:GetFrames(unit)
if self.frame and self.frame[unit] then
return { self.frame[unit] }
end
end
function modulePrototype:GetOtherAttachPoints(unit)
return GladiusEx:GetAttachPoints(unit, self)
end
function modulePrototype:InitializeDB(name, defaults)
local dbi = GladiusEx.dbi:RegisterNamespace(name, { profile = defaults })
dbi.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
dbi.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
dbi.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
return dbi
end
function modulePrototype:OnInitialize()
self.dbi_arena = self:InitializeDB(self:GetName(), self.defaults_arena)
self.dbi_party = self:InitializeDB("party_" .. self:GetName(), self.defaults_party)
self.db = setmetatable({}, {
__index = function(t, k)
local v
k = strmatch(k, "^(.+)target$") or strmatch(k, "^(.+)pet(.+)$") or k
if k == "target" or k == "pet" or k == "party" or GladiusEx:IsPartyUnit(k) then
v = self.dbi_party.profile
elseif k == "arena" or GladiusEx:IsArenaUnit(k) then
v = self.dbi_arena.profile
else
error("Bad module DB usage: not an unit (" .. tostring(k) .. ")", 2)
end
rawset(t, k, v)
return v
end
})
end
function modulePrototype:OnProfileChanged()
wipe(self.db)
end
function modulePrototype:IsUnitEnabled(unit)
return GladiusEx:IsModuleEnabled(unit, self:GetName())
end
GladiusEx:SetDefaultModulePrototype(modulePrototype)
GladiusEx:SetDefaultModuleLibraries("AceEvent-3.0")
GladiusEx:SetDefaultModuleState(false)
function GladiusEx:NewGladiusExModule(name, defaults_arena, defaults_party, ...)
local module = self:NewModule(name, ...)
module.super = modulePrototype
module.defaults_arena = defaults_arena
module.defaults_party = defaults_party or defaults_arena
return module
end
function GladiusEx:GetAttachPoints(unit, skip)
-- get module list for frame anchor
local t = { ["Frame"] = L["Frame"] }
for name, m in GladiusEx:IterateModules() do
if m ~= skip and self:IsModuleEnabled(unit, name) then
local points = m.GetModuleAttachPoints and m:GetModuleAttachPoints(unit)
if points then
for point, name in pairs(points) do
t[point] = name
end
end
end
end
return t
end
function GladiusEx:GetAttachFrame(unit, point, nodefault)
-- get parent frame
if point == "Frame" then
return self.buttons[unit]
else
for name, m in self:IterateModules() do
if self:IsModuleEnabled(unit, name) then
local points = m.GetModuleAttachPoints and m:GetModuleAttachPoints(unit)
if points and points[point] then
local f = m:GetModuleAttachFrame(unit, point)
return f or (not nodefault and self.buttons[unit])
end
end
end
end
-- default to frame
return not nodefault and self.buttons[unit]
end
function GladiusEx:OnInitialize()
-- init db+
self.dbi = LibStub("AceDB-3.0"):New("GladiusExDB", self.defaults, true)
self.dbi_arena = self.dbi:RegisterNamespace("arena", { profile = self.defaults_arena })
self.dbi_party = self.dbi:RegisterNamespace("party", { profile = self.defaults_party })
self.db = setmetatable({}, {
__index = function(t, k)
local v
if k == "party" or GladiusEx:IsPartyUnit(k) then
v = self.dbi_party.profile
elseif k == "arena" or GladiusEx:IsArenaUnit(k) then
v = self.dbi_arena.profile
elseif k == "base" then
v = self.dbi.profile
else
error("Bad DB usage: not an unit (" .. tostring(k) .. ")", 2)
end
rawset(t, k, v)
return v
end
})
-- libsharedmedia
LSM:Register("statusbar", "Minimalist (GladiusEx)", [[Interface\Addons\GladiusEx\media\Minimalist]])
LSM:Register("statusbar", "Wglass (GladiusEx)", [[Interface\Addons\GladiusEx\media\Wglass]])
LSM:Register("font", "Designosaur (GladiusEx)", [[Interface\Addons\GladiusEx\media\Designosaur-Regular.ttf]])
LSM:Register("font", "Designosaur Italic (GladiusEx)", [[Interface\Addons\GladiusEx\media\Designosaur-Italic.ttf]])
-- test environment
self.test = false
self.testing = setmetatable({}, {
__index = function(t, k)
if not self.db.base.testUnits[k] then k = "arena1" end
return self.db.base.testUnits[k]
end
})
-- buttons
self.buttons = {}
-- debugging code for finding unused locale strings
--[[
setmetatable(L, {})
local myl = fn.clone(L)
local myl_count = fn.clone(L)
for k in pairs(myl_count) do
myl_count[k] = 0
end
wipe(L)
setmetatable(L, {
__index = function(self, k, v)
myl_count[k] = myl_count[k] + 1
return "!" .. tostring(myl[k])
end
})
function GladiusEx:PrintUnused()
local l = {}
for k, v in pairs(myl_count) do
if v == 0 then
tinsert(l, k)
end
end
l = fn.filter(l, function(k)
if k:match("Tag$") or k:match(":short$") then
return false
end
return true
end)
l = fn.sort(l)
print(table.concat(l, "\n"))
end
]]
end
function GladiusEx:IsModuleEnabled(unit, name)
return self.db[unit].modules[name]
end
function GladiusEx:CheckEnableDisableModule(name)
local mod = self:GetModule(name)
-- hide module if it is being disabled
if mod:IsEnabled() and mod.Reset then
if not self:IsModuleEnabled("party", name) then
for unit, button in pairs(self.buttons) do
if self:IsPartyUnit(unit) then
mod:Reset(unit)
end
end
end
if not self:IsModuleEnabled("arena", name) then
for unit, button in pairs(self.buttons) do
if self:IsArenaUnit(unit) then
mod:Reset(unit)
end
end
end
end
if self:IsModuleEnabled("party", name) or self:IsModuleEnabled("arena", name) then
self:EnableModule(name)
else
self:DisableModule(name)
end
end
function GladiusEx:EnableModules()
for module_name in self:IterateModules() do
self:CheckEnableDisableModule(module_name)
end
end
function GladiusEx:OnEnable()
-- create frames
-- anchor & background
self.party_parent = CreateFrame("Frame", "GladiusExPartyFrame", UIParent)
self.arena_parent = CreateFrame("Frame", "GladiusExArenaFrame", UIParent)
self.party_parent:Hide()
self.arena_parent:Hide()
self.arena_anchor, self.arena_background = self:CreateAnchor("arena")
self.party_anchor, self.party_background = self:CreateAnchor("party")
-- update roster
self:UpdateAllGUIDs()
-- update range checkers
self:UpdateRangeCheckers()
-- enable modules
self:EnableModules()
-- init options
self:SetupOptions()
-- register the appropriate events
self:RegisterEvent("PLAYER_ENTERING_WORLD")
self:RegisterEvent("ARENA_OPPONENT_UPDATE")
if GladiusEx.IS_RETAIL then
self:RegisterEvent("ARENA_PREP_OPPONENT_SPECIALIZATIONS")
else
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("UNIT_SPELLCAST_START")
self:RegisterEvent("UNIT_SPELLCAST_CHANNEL_START")
self:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
end
self:RegisterEvent("UNIT_NAME_UPDATE")
self:RegisterEvent("UNIT_HEALTH")
self:RegisterEvent("UNIT_MAXHEALTH", "UNIT_HEALTH")
self:RegisterEvent("GROUP_ROSTER_UPDATE")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterEvent("UNIT_PET", "UpdateUnitGUID")
self:RegisterEvent("UNIT_PORTRAIT_UPDATE", "UpdateUnitGUID")
if LGIST then
LGIST.RegisterCallback(self, "GroupInSpecT_Update")
end
RC.RegisterCallback(self, RC.CHECKERS_CHANGED, "UpdateRangeCheckers")
self.dbi.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.dbi.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.dbi.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
end
local first_run = false
function GladiusEx:CheckFirstRun()
if first_run then return end
first_run = true
-- display help message
if (not self.db.base.locked and not self.db.arena.x["arena1"] and not self.db.arena.y["arena1"] and not self.db.arena.x["anchor_arena"] and not self.db.arena.y["anchor_arena"]) then
self:Print(L["Welcome to GladiusEx!"])
self:Print(L["First run has been detected, displaying test frame"])
self:Print(L["Valid slash commands are:"])
self:Print("/gex ui")
self:Print("/gex test 2-5")
self:Print("/gex show")
self:Print("/gex hide")
self:Print("/gex reset")
self:Print(L["** If this is not your first run please lock or move the frame to prevent this from happening **"])
self:SetTesting(3)
elseif self:IsDebugging() then
self:SetTesting(3)
end
end
function GladiusEx:OnDisable()
self:UnregisterAllEvents()
LGIST.UnregisterAllEvents(self)
self.dbi.UnregisterAllEvents(self)
self:HideFrames()
end
function GladiusEx:OnProfileChanged(event, database, newProfileKey)
-- update frame and modules on profile change
wipe(self.db)
self:SetupOptions()
self:EnableModules()
self:UpdateFrames()
-- make sure that party is shown/hidden if its enabled state changed in the new profile
if GladiusEx:IsArenaShown() then
GladiusEx:HideFrames()
GladiusEx:ShowFrames()
end
end
function GladiusEx:SetTesting(count)
self.test = count
self:UpdateFrames()
if count then
self:ShowFrames()
else
self:HideFrames()
end
end
function GladiusEx:IsTesting(unit)
if not self.test then
return false
elseif unit then
return not UnitExists(unit)
else
return self.test
end
end
function GladiusEx:GetArenaSize(minVal)
if self:IsTesting() then
log("GetArenaSize => testing")
return self:IsTesting()
end
local widget_number = 0
if GladiusEx.IS_CLASSIC and not self:IsTesting() and IsActiveBattlefieldArena() then
for _, widget in pairs(C_UIWidgetManager.GetAllWidgetsBySetID(1)) do
local text = C_UIWidgetManager.GetIconAndTextWidgetVisualizationInfo(widget.widgetID).text
local n = tonumber(string.match(text, "%d"))
if n > widget_number then
widget_number = n
end
end
end
-- try to guess the current arena size
local guess =
max(
minVal or 0,
2,
widget_number,
GetNumArenaOpponents(),
GladiusEx.Data.GetNumArenaOpponentSpecs() and GladiusEx.Data.GetNumArenaOpponentSpecs() or 0,
GetNumGroupMembers(LE_PARTY_CATEGORY_HOME),
GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE)
)
log(
"GetArenaSize",
minVal,
GetNumArenaOpponents(),
GladiusEx.Data.GetNumArenaOpponentSpecs() and GladiusEx.Data.GetNumArenaOpponentSpecs() or 0,
GetNumGroupMembers(LE_PARTY_CATEGORY_HOME),
GetNumGroupMembers(LE_PARTY_CATEGORY_INSTANCE),
" => ",
guess
)
-- In Retail, Solo Shuffle sometimes returns 4
if guess == 4 then
guess = 3
end
return guess
end
function GladiusEx:UpdatePartyFrames()
if InCombatLockdown() then
self:QueueUpdate()
return
end
local group_members = self.arena_size
log("UpdatePartyFrames", group_members)
self:UpdateAnchor("party")
for i = 1, 5 do
local unit = i == 1 and "player" or ("party" .. (i - 1))
if group_members >= i then
self:UpdateUnit(unit)
self:UpdateUnitState(unit, false)
self:ShowUnit(unit)
if not self:IsTesting() and not UnitExists(unit) then
self:SoftHideUnit(unit)
end
-- test environment
if self:IsTesting(unit) then
self:TestUnit(unit)
else
self:RefreshUnit(unit)
end
else
self:HideUnit(unit)
end
end
if self.db.base.hideSelf then
self:HideUnit("player")
end
self:UpdateBackground("party")
end
function GladiusEx:UpdateArenaFrames()
if InCombatLockdown() then
self:QueueUpdate()
return
end
local numOpps = self.arena_size
log("UpdateArenaFrames:", numOpps, GetNumArenaOpponents(), GetNumArenaOpponentSpecs and GetNumArenaOpponentSpecs() or 0)
self:UpdateAnchor("arena")
for i = 1, 5 do
local unit = "arena" .. i
if numOpps >= i then
self:UpdateUnit(unit)
self:UpdateUnitState(unit, self.buttons[unit].unit_state == STATE_STEALTH)
self:ShowUnit(unit)
-- test environment
if self:IsTesting(unit) then
self:TestUnit(unit)
else
self:RefreshUnit(unit)
end
else
self:HideUnit(unit)
end
end
self:UpdateBackground("arena")
end
function GladiusEx:UpdateFrames()
log("UpdateFrames")
if not self:IsPartyShown() and not self:IsArenaShown() then return end
if not self.arena_size then
self:CheckArenaSize()
return -- CheckArenaSize will call us back
end
self:UpdatePartyFrames()
self:UpdateArenaFrames()
if not InCombatLockdown() then
self:ClearUpdateQueue()
end
end
function GladiusEx:CheckArenaSize(unit)
local min_size = 0
if unit then
min_size = self:GetUnitIndex(unit)
end
local size = self:GetArenaSize(min_size)
log("CheckArenaSize", unit, unit and UnitName(unit) or "none", min_size, size)
if self.arena_size ~= size then
log("Arena size change detected", self.arena_size, " => ", size)
self.arena_size = size
self:UpdateFrames()
return true
end
end
function GladiusEx:ShowFrames()
if InCombatLockdown() then
self:QueueUpdate()
end
local function show_anchor(anchor_type)
if self.db[anchor_type].groupButtons then
local anchor, background = self:GetAnchorFrames(anchor_type)
background:Show()
if not self.db.base.locked then
anchor:Show()
end
end
end
if self.db.base.showArena then
show_anchor("arena")
self.arena_parent:Show()
end
if self.db.base.showParty then
show_anchor("party")
self.party_parent:Show()
end
local updated = self:CheckArenaSize()
if not updated then
-- refresh buttons
for unit in pairs(self.buttons) do
self:RefreshUnit(unit)
end
end
end
function GladiusEx:HideFrames()
if InCombatLockdown() then
self:QueueUpdate()
end
-- hide frames instead of just setting alpha to 0
for unit, button in pairs(self.buttons) do
-- reset spec data
button.class = nil
button.specID = nil
button.unit_state = nil
button.covenant = nil
-- hide frame
self:HideUnit(unit)
end
self.arena_parent:Hide()
self.party_parent:Hide()
self.arena_size = 0
end
function GladiusEx:IsPartyShown()
return self.party_parent:IsShown()
end
function GladiusEx:IsArenaShown()
return self.arena_parent:IsShown()
end
function GladiusEx:PLAYER_ENTERING_WORLD()
local instanceType = select(2, IsInInstance())
-- check if we are entering or leaving an arena
if instanceType == "arena" then
self:SetTesting(false)
-- self:ShowFrames()
self:ARENA_PREP_OPPONENT_SPECIALIZATIONS()
log("ENABLE LOGGING")
else
self:CheckFirstRun()
if not self:IsTesting() then
self:HideFrames()
end
if logging then log("DISABLE LOGGING") end
end
end
function GladiusEx:ARENA_PREP_OPPONENT_SPECIALIZATIONS()
if InCombatLockdown() then
return -- Combat doesnt end immediately when solo shuffle round ends so this would trigger a lua error if ran on the first events.
end
self:CheckArenaSize()
self:ShowFrames()
local numOpps = GladiusEx.Data.CountArenaOpponents()
for i = 1, numOpps do
local specID = GladiusEx.Data.GetArenaOpponentSpec(i)
local unitid = "arena" .. i
if (GladiusEx.IS_RETAIL and specID and specID > 0) or GladiusEx.IS_CLASSIC then
self:ShowUnit(unitid)
self:UpdateUnit(unitid)
-- update spec after UpdateUnit so that it can (maybe) create button
self:UpdateUnitSpecialization(unitid, specID)
self:UpdateUnitState(unitid, true)
self:RefreshUnit(unitid)
end
end
self:UpdateFrames()
end
function GladiusEx:UpdateUnitSpecialization(unit, specID)
if not self.buttons[unit] then
return
end
if not specID or specID < 1 then
return
end
local _, _, _, _, _, class = GladiusEx.Data.GetSpecializationInfoByID(specID)
specID = (specID and specID > 0) and specID or nil
if self.buttons[unit].specID ~= specID then
self.buttons[unit].class = class
self.buttons[unit].specID = specID
-- TODO safer to reset covenant?
self:SendMessage("GLADIUS_SPEC_UPDATE", unit)
end
end
function GladiusEx:CheckOpponentSpecialization(unit)
local id = strmatch(unit, "^arena(%d+)$")
if id then
local specID = GladiusEx.Data.GetArenaOpponentSpec(tonumber(id))
if GladiusEx.IS_CLASSIC and not specID then
specID = self:FindSpecByAuras(unit)
end
self:UpdateUnitSpecialization(unit, specID)
end
end
function GladiusEx:FindSpecByAuras(unit)
for i = 1, 40 do
local n, _, _, _, _, _, unitCaster, _, _, spellID = UnitAura(unit, i, "HELPFUL")
if n == nil then
break
end
if unitCaster ~= nil then
local unitPet = string.gsub(unit, "pet", "")
unitPet = unitPet == "" and "player" or unitPet
if UnitIsUnit(unitPet, unitCaster) then
local specID = GladiusEx.Data.SpecBuffs[spellID]
if specID then
return specID
end
end
end
end
end
function GladiusEx:FindSpecBySpell(unit, spellID, spellName)
return GladiusEx.Data.SpecSpells[spellID] or GladiusEx.Data.SpecSpells[spellName]
end
function GladiusEx:UNIT_AURA(event, unit)
if not self.buttons[unit] or self.buttons[unit].specID then
return
end
local specID = self:FindSpecByAuras(unit)
if not specID then
return
end
self:UpdateUnitSpecialization(unit, specID)
end
function GladiusEx:UNIT_SPELLCAST_START(event, unit)
if not self.buttons[unit] or self.buttons[unit].specID then
return
end
local spellName, _, _, _, _, _, _, _, spellID = UnitCastingInfo(unit)
local specID = self:FindSpecBySpell(unit, spellID, spellName)
if not specID then
return
end
self:UpdateUnitSpecialization(unit, specID)
end
function GladiusEx:UNIT_SPELLCAST_CHANNEL_START(event, unit)
if not self.buttons[unit] or self.buttons[unit].specID then
return
end
local spellName, _, _, _, _, _, _, _, spellID = UnitChannelInfo(unit)
local specID = self:FindSpecBySpell(unit, spellID, spellName)
if not specID then
return
end
self:UpdateUnitSpecialization(unit, specID)
end
function GladiusEx:UNIT_SPELLCAST_SUCCEEDED(event, unit, castGUID, spellID)
if not self.buttons[unit] or self.buttons[unit].specID then
return
end
local specID = self:FindSpecBySpell(unit, spellID)
if not specID then
return
end
self:UpdateUnitSpecialization(unit, specID)
end
function GladiusEx:ARENA_OPPONENT_UPDATE(event, unit, type)
log("ARENA_OPPONENT_UPDATE", unit, type)
-- ignore pets
if not self:IsArenaUnit(unit) then return end
if type == "seen" then
self:ShowUnit(unit)
self:CheckOpponentSpecialization(unit)
self:UpdateUnitState(unit, false)
self:CheckArenaSize(unit)
elseif type == "unseen" or type == "destroyed" then
self:UpdateUnitState(unit, true)
elseif type == "cleared" then
if not self:IsTesting() then
self:SoftHideUnit(unit)
end
end
self:RefreshUnit(unit)
end
function GladiusEx:GROUP_ROSTER_UPDATE()
if self:IsArenaShown() or self:IsPartyShown() then
self:UpdateAllGUIDs()
local u = self:CheckArenaSize()
if not u and self:IsPartyShown() then
self:UpdatePartyFrames()
end
end
end
function GladiusEx:QueueUpdate()
self.update_pending = true
log("Update Queued")
end
function GladiusEx:IsUpdatePending()
return self.update_pending
end
function GladiusEx:ClearUpdateQueue()
self.update_pending = false
end
function GladiusEx:PLAYER_REGEN_ENABLED()
if self:IsUpdatePending() then
self:UpdateFrames()
end
end
function GladiusEx:UNIT_NAME_UPDATE(event, unit)
if not self:IsHandledUnit(unit) then return end
self:UpdateUnitGUID(event, unit)
self:CheckArenaSize(unit)
self:UpdateUnitState(unit)
self:RefreshUnit(unit)
end
local guid_to_unitid = {}
function GladiusEx:GetUnitIdByGUID(guid)
return guid_to_unitid[guid]
end
function GladiusEx:UpdateAllGUIDs()
for unit in pairs(party_units) do self:UpdateUnitGUID("UpdateAllGUIDs", unit) end
for unit in pairs(arena_units) do self:UpdateUnitGUID("UpdateAllGUIDs", unit) end
end
function GladiusEx:UpdateUnitGUID(event, unit)
if self:IsHandledUnit(unit) then
-- find and delete old reference to that unit
for guid, unitid in pairs(guid_to_unitid) do
if unitid == unit then
guid_to_unitid[guid] = nil
break
end
end
-- add guid
local guid = UnitGUID(unit)
if guid then
guid_to_unitid[guid] = unit
end
end
end
function GladiusEx:UNIT_HEALTH(event, unit)
if not self.buttons[unit] then return end
self:UpdateUnitState(unit, false)
end
local range_check
function GladiusEx:UpdateRangeCheckers()
range_check = RC:GetSmartMinChecker(40)
end
local function FrameRangeChecker_OnUpdate(f, elapsed)
f.elapsed = f.elapsed + elapsed
if f.elapsed >= RANGE_UPDATE_INTERVAL then
f.elapsed = 0
local unit = f.unit
if GladiusEx:IsTesting(unit) then
f:SetAlpha(1)
end
if not UnitExists(unit) then
-- should probably remove the OnUpdate handler here
return
end
if range_check(unit) then
f:SetAlpha(1)
else
f:SetAlpha(GladiusEx.db[unit].oorAlpha)
end
end
end
function GladiusEx:UpdateUnitState(unit, stealth)
if not self.buttons[unit] then return end
if UnitIsDeadOrGhost(unit) then
self.buttons[unit].unit_state = STATE_DEAD
self.buttons[unit]:SetScript("OnUpdate", nil)
self.buttons[unit]:SetAlpha(self.db[unit].deadAlpha)
elseif stealth then
self.buttons[unit].unit_state = STATE_STEALTH
self.buttons[unit]:SetScript("OnUpdate", nil)
self.buttons[unit]:SetAlpha(self.db[unit].stealthAlpha)
else
self.buttons[unit].unit_state = STATE_NORMAL
self.buttons[unit]:SetScript("OnUpdate", FrameRangeChecker_OnUpdate)
FrameRangeChecker_OnUpdate(self.buttons[unit], RANGE_UPDATE_INTERVAL + 1)
end
end
function GladiusEx:GroupInSpecT_Update(event, guid, unit, info)
for u, _ in pairs(party_units) do
if UnitGUID(u) == guid then
self:UpdateUnitSpecialization(u, info.global_spec_id)
break
end
end
end
function GladiusEx:CheckUnitSpecialization(unit)
if not LGIST or not LGIST.GetCachedInfo then
return
end
local info = LGIST:GetCachedInfo(UnitGUID(unit))
if info then
self:UpdateUnitSpecialization(unit, info.global_spec_id)
else
LGIST:Rescan(UnitGUID(unit))
end
end
function GladiusEx:IsHandledUnit(unit)
return arena_units[unit] or party_units[unit]
end
function GladiusEx:IsArenaUnit(unit)
return arena_units[unit]
end
function GladiusEx:IsPartyUnit(unit)
return party_units[unit]
end
function GladiusEx:TestUnit(unit)
if not self:IsHandledUnit(unit) then return end
-- test modules
for n, m in self:IterateModules() do
if self:IsModuleEnabled(unit, n) and m.Test then
m:Test(unit)
end
end
-- lower secure frame in test mode so we can move the frame