-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUltraHardcoreLeaderboard.lua
More file actions
1006 lines (892 loc) · 37.2 KB
/
Copy pathUltraHardcoreLeaderboard.lua
File metadata and controls
1006 lines (892 loc) · 37.2 KB
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
local PREFIX = "UHLB"
local FRAME, SCROLL, SCROLL_CHILD, HEADER
local addon = LibStub("AceAddon-3.0"):NewAddon("UltraHardcoreLeaderboard", "AceComm-3.0")
addon.seen = addon.seen or {}
local seen = addon.seen
local addonIcon = LibStub("LibDBIcon-1.0")
local addonLDB = LibStub("LibDataBroker-1.1"):NewDataObject("UltraHardcoreLeaderboard", {
type = "data source",
text = "UltraHardcore Leaderboard",
icon = "Interface\\AddOns\\UltraHardcoreLeaderboard\\Images\\UltraHardcoreLeaderbaordIcon",
OnClick = function(self, btn)
if btn == "LeftButton" then
if FRAME:IsShown() then
FRAME:Hide()
else
FRAME:Show()
FRAME.RefreshLeaderboardUI(true)
end
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then
return
end
tooltip:AddLine("|cffffffffUltra Hardcore Leaderboard|r\n\nLeft-click to open the leaderboard", nil, nil, nil, nil)
end,
})
function addon:OnInitialize()
self.db = LibStub("AceDB-3.0"):New("UltraHardcoreLeaderboardDB", {
profile = {
minimap = {
hide = false,
},
welcomeMessageShown = false,
restrictToGuild = true, -- New setting for guild restriction toggle
},
})
addonIcon:Register("UltraHardcoreLeaderboard", addonLDB, self.db.profile.minimap)
self:RegisterComm("UHLB", "OnCommReceived")
end
local settingsCheckboxOptions = {
{ id = 1, name = "UHC Player Frame", dbSettingsValueName = "hidePlayerFrame" },
{ id = 2, name = "Hide Minimap", dbSettingsValueName = "hideMinimap" },
--{ id = 3, name = "Use Custom Buff Frame", dbSettingsValueName = "hideBuffFrame" },
{ id = 4, name = "Hide Target Frame", dbSettingsValueName = "hideTargetFrame" },
{ id = 5, name = "Hide Target Tooltips", dbSettingsValueName = "hideTargetTooltip" },
{ id = 6, name = "Death Indicator (Tunnel Vision)", dbSettingsValueName = "showTunnelVision" },
{ id = 7, name = "Tunnel Vision Covers Everything", dbSettingsValueName = "tunnelVisionMaxStrata" },
--{ id = 8, name = "Hide Quest UI", dbSettingsValueName = "hideQuestFrame" },
{ id = 9, name = "Show Dazed Effect", dbSettingsValueName = "showDazedEffect" },
{ id = 10, name = "Show Crit Screen Shift Effect", dbSettingsValueName = "showCritScreenMoveEffect" },
{ id = 11, name = "Hide Action Bars when not resting", dbSettingsValueName = "hideActionBars" },
{ id = 12, name = "UHC Party Frames", dbSettingsValueName = "hideGroupHealth" },
{ id = 13, name = "Pets Die Permanently", dbSettingsValueName = "petsDiePermanently" },
--{ id = 14, name = "Show Full Health Indicator", dbSettingsValueName = "showFullHealthIndicator" },
{ id = 15, name = "Disable Nameplates", dbSettingsValueName = "disableNameplateHealth" },
{ id = 16, name = "Show Incoming Damage Effect", dbSettingsValueName = "showIncomingDamageEffect" },
{ id = 17, name = "Breath Indicator", dbSettingsValueName = "hideBreathIndicator" },
{ id = 18, name = "Show Incoming Healing Effect", dbSettingsValueName = "showHealingIndicator" },
{ id = 19, name = "First Person Camera", dbSettingsValueName = "setFirstPersonCamera"}
}
function GetPresetAndTooltip(playerName) -- Made global for achievements addon
local presetNames = { "Lite", "Recommended", "Ultra", "Experimental" }
local presets = {
{ -- Lite
hidePlayerFrame = true,
showTunnelVision = true,
},
{ -- Recommended
hidePlayerFrame = true,
showTunnelVision = true,
hideTargetFrame = true,
hideTargetTooltip = true,
disableNameplateHealth = true,
showDazedEffect = true,
hideGroupHealth = true,
hideMinimap = true,
},
{ -- Ultra
hidePlayerFrame = true,
showTunnelVision = true,
hideTargetFrame = true,
hideTargetTooltip = true,
disableNameplateHealth = true,
showDazedEffect = true,
hideGroupHealth = true,
hideMinimap = true,
petsDiePermanently = true,
hideActionBars = true,
tunnelVisionMaxStrata = true,
},
{ -- Experimental
hidePlayerFrame = true,
showTunnelVision = true,
hideTargetFrame = true,
hideTargetTooltip = true,
disableNameplateHealth = true,
showDazedEffect = true,
hideGroupHealth = true,
hideMinimap = true,
petsDiePermanently = true,
hideActionBars = true,
tunnelVisionMaxStrata = true,
hideBreathIndicator = true,
showCritScreenMoveEffect = true,
showIncomingDamageEffect = true,
showHealingIndicator = true,
setFirstPersonCamera = true,
}
}
-- Build the player's known settings table (true means explicitly enabled)
local settings = nil
if playerName == UnitName("player") and UltraHardcoreDB then
local guid = UnitGUID("player")
if guid and UltraHardcoreDB.characterSettings and UltraHardcoreDB.characterSettings[guid] then
settings = UltraHardcoreDB.characterSettings[guid]
elseif UltraHardcoreDB.GLOBAL_SETTINGS then
-- backward compat until everyone has migrated
settings = UltraHardcoreDB.GLOBAL_SETTINGS
end
elseif seen[playerName] and seen[playerName].customSettings then
settings = {}
for _, settingId in ipairs(seen[playerName].customSettings) do
local id = tonumber(settingId)
for _, option in ipairs(settingsCheckboxOptions) do
if option.id == id then
settings[option.dbSettingsValueName] = true
break
end
end
end
end
local cache = UltraHardcoreLeaderboardDB and UltraHardcoreLeaderboardDB.cache
cache = cache and cache[playerName]
if not settings and cache then
-- 1) Prefer exact customSettings from cache if present
if type(cache.customSettings) == "table" and next(cache.customSettings) ~= nil then
settings = {}
for _, settingId in ipairs(cache.customSettings) do
local id = tonumber(settingId)
for _, option in ipairs(settingsCheckboxOptions) do
if option.id == id then
settings[option.dbSettingsValueName] = true
break
end
end
end
end
-- 2) If still nothing, normalize the preset string and map to your preset tiers
if (not settings) or (next(settings) == nil) then
local p = cache.preset
if type(p) == "string" then
-- normalize: lowercase, strip spaces and punctuation (handles "Lite +", "Lite+", "lite-plus", etc.)
local norm = p:lower():gsub("%s+", ""):gsub("%p", "")
local idx
if norm:find("^lite") then
idx = 1
elseif norm:find("^recommended") or norm == "rec" then
idx = 2
elseif norm:find("^ultra") or norm == "ult" then
idx = 3
elseif norm:find("^experimental") or norm == "exp" then
idx = 4
end
if idx then
settings = presets[idx] -- use the default toggles for that tier
end
end
end
-- 3) Ensure the outward-facing preset name reflects cache if we fell back
if settings and (not preset or preset == "Custom") and type(cache.preset) == "string" then
preset = cache.preset -- e.g., "Lite +"
end
end
-- Determine preset for leaderboard column
local function trueKeys(t)
local s = {}
if t then for k, v in pairs(t) do if v == true then s[k] = true end end end
return s
end
local function hasAll(have, need)
for k in pairs(need) do if not have[k] then return false end end
return true
end
local function hasAny(have, subset)
for k in pairs(subset) do if have[k] then return true end end
return false
end
-- Tier sets (cumulative)
local L = trueKeys(presets[1]) -- Lite
local R = trueKeys(presets[2]) -- Recommended (includes Lite)
local U = trueKeys(presets[3]) -- Ultra (includes Recommended)
local E = trueKeys(presets[4]) -- Experimental (includes Ultra)
-- Exclusive deltas (new options introduced at each tier)
local R_only = {}; for k in pairs(R) do if not L[k] then R_only[k] = true end end
local U_only = {}; for k in pairs(U) do if not R[k] then U_only[k] = true end end
local E_only = {}; for k in pairs(E) do if not U[k] then E_only[k] = true end end
-- Player's enabled set (restricted to known tier keys)
local player = {}
if settings then
for k in pairs(L) do if settings[k] == true then player[k] = true end end
for k in pairs(R_only) do if settings[k] == true then player[k] = true end end
for k in pairs(U_only) do if settings[k] == true then player[k] = true end end
for k in pairs(E_only) do if settings[k] == true then player[k] = true end end
end
local preset
if not settings then
-- fallback to what you already store remotely when no local settings
preset = seen[playerName] and seen[playerName].preset or "Custom"
else
if hasAll(player, E) then
-- full Experimental (top tier; nothing above it to be partial)
preset = "Experimental"
elseif hasAll(player, U) then
-- full Ultra; add "+" if any Experimental-only entries are toggled
preset = hasAny(player, E_only) and "Ultra +" or "Ultra"
elseif hasAll(player, R) then
-- full Recommended; add "+" if any Ultra-only entries are toggled
preset = hasAny(player, U_only) and "Recommended +" or "Recommended"
elseif hasAll(player, L) then
-- full Lite; add "+" if any options from higher tiers are toggled
preset = (hasAny(player, R_only) or hasAny(player, U_only) or hasAny(player, E_only)) and "Lite +" or "Lite"
else
-- didn't fully satisfy Lite
preset = "Custom"
end
end
local tooltipText = {}
table.insert(tooltipText, "|cffffd100Settings Enabled|r")
table.insert(tooltipText, " ")
local RED = "|cfff44336"
local WHITE = "|cffffffff"
local GRAY = "|cff414141"
local END = "|r"
local nameByKey = {}
for _, opt in ipairs(settingsCheckboxOptions) do
nameByKey[opt.dbSettingsValueName] = opt.name
end
-- Helper: take only the 'true' keys from a preset table
local function enabledSet(t)
local s = {}
if t then
for k, v in pairs(t) do
if v == true then s[k] = true end
end
end
return s
end
local L = enabledSet(presets[1])
local R = enabledSet(presets[2])
local U = enabledSet(presets[3])
local E = enabledSet(presets[4])
local L_only = L
local R_only = {}
for k in pairs(R) do if not L[k] then R_only[k] = true end end
local U_only = {}
for k in pairs(U) do if not R[k] then U_only[k] = true end end
local E_only = {}
for k in pairs(E) do if not U[k] then E_only[k] = true end end
local sections = {
{ title = "Lite", keys = L_only },
{ title = "Recommended", keys = R_only },
{ title = "Ultra", keys = U_only },
{ title = "Experimental", keys = E_only },
}
for i, sec in ipairs(sections) do
table.insert(tooltipText, RED .. sec.title .. END)
local hadAny = false
for _, opt in ipairs(settingsCheckboxOptions) do
local key = opt.dbSettingsValueName
if sec.keys[key] then
hadAny = true
local enabled = (settings and settings[key] == true)
table.insert(tooltipText, (enabled and WHITE or GRAY) .. (nameByKey[key] or key) .. END)
end
end
if not hadAny then
table.insert(tooltipText, GRAY .. "(none)" .. END)
end
if i < #sections then table.insert(tooltipText, " ") end
end
return preset, table.concat(tooltipText, "\n")
end
function UHCLB_GetLocalSettingsIdList()
local ids = {}
if UltraHardcoreDB and settingsCheckboxOptions then
local guid = UnitGUID("player")
local s = (guid and UltraHardcoreDB.characterSettings and UltraHardcoreDB.characterSettings[guid])
or UltraHardcoreDB.GLOBAL_SETTINGS
if s then
for _, opt in ipairs(settingsCheckboxOptions) do
if s[opt.dbSettingsValueName] then
table.insert(ids, opt.id)
end
end
end
end
return ids
end
local function FormatNumber(num)
if num >= 1000 then
return string.format("%.1fk", num / 1000)
end
return tostring(num)
end
function addon:OnCommReceived(prefix, msg, dist, sender)
local net = self:GetModule("Network", true)
if net and net.OnCommReceived then
net:OnCommReceived(prefix, msg, dist, sender)
end
end
function SendAnnounce()
local net = addon:GetModule("Network", true)
if net and net.SendDelta then
net:SendDelta()
end
if FRAME and FRAME:IsShown() then
FRAME.RefreshLeaderboardUI()
end
end
local function StartAnnounceTicker()
C_Timer.NewTicker(60, SendAnnounce)
end
function addon:RefreshUIIfVisible()
if FRAME and FRAME:IsShown() then
FRAME.RefreshLeaderboardUI()
end
end
local ev = CreateFrame("Frame")
ev:RegisterEvent("PLAYER_LOGIN")
ev:RegisterEvent("PLAYER_LEVEL_UP")
ev:RegisterEvent("PLAYER_DEAD")
ev:RegisterEvent("PLAYER_LOGOUT")
ev:RegisterEvent("MODIFIER_STATE_CHANGED")
ev:SetScript("OnEvent", function(_, e, key, state)
if e == "PLAYER_LOGIN" then
-- Initialize cache
local cache = addon:GetModule("Cache", true)
if cache and cache.Init then cache:Init() end
-- Show welcome message on first login
C_Timer.After(1, function()
addon:ShowWelcomeMessage()
end)
-- Announce 3 seconds after login and every 60 seconds
C_Timer.After(3, SendAnnounce)
StartAnnounceTicker()
-- Ask a few peers for their recent cache
local net = addon:GetModule("Network", true)
if net and net.SendSnapReq then
C_Timer.After(5, function()
net:SendSnapReq()
end)
end
elseif e == "PLAYER_LOGOUT" then
local net = addon:GetModule("Network", true)
if net and net.SendOfflineDelta then
net:SendOfflineDelta()
end
elseif e == "MODIFIER_STATE_CHANGED" then
local net = addon:GetModule("Network", true)
if key == "LALT" and FRAME and FRAME:IsShown() and net and net:IsDebug() then
FRAME.RefreshLeaderboardUI()
end
elseif e == "PLAYER_DEAD" then
local net = addon:GetModule("Network", true)
if net and net.MarkDeadAndSend then
net:MarkDeadAndSend()
end
return
else
-- Coalesce other events into a short delay
C_Timer.After(2, SendAnnounce)
end
end)
function addon:OnDisable()
ev:UnregisterAllEvents()
end
-- Function to show welcome message popup on first login
function addon:ShowWelcomeMessage()
if not self.db.profile.welcomeMessageShown then
-- Create a simple popup dialog
StaticPopup_Show("UltraHardcore Leaderboard Message")
-- Mark as shown
self.db.profile.welcomeMessageShown = true
end
end
-- Define the welcome message popup
StaticPopupDialogs["UltraHardcore Leaderboard Message"] = {
text = "The Ultra Hardcore Leaderboard no longer tracks your achievements. That has been made into a plugin for Ultra Hardcore and is a separate addon. You can find it at \n\n https://www.curseforge.com/wow/addons/hardcore-achievements",
button1 = "Got it!",
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
OnAccept = function()
-- Popup automatically closes
end,
}
C_Timer.NewTicker(60, function()
local now = (GetServerTime and GetServerTime()) or time()
for name, row in pairs(seen) do
if (now - (row.last or 0)) > 600 then
seen[name] = nil
end
end
if addon.RefreshUIIfVisible then
addon:RefreshUIIfVisible()
end
end)
local function UHLB_ShouldShowLVersion()
return IsLeftAltKeyDown()
end
local ROW_HEIGHT = 18
local VISIBLE_ROWS = 18
local COLS = {
{ key = "name", title = "Player Name", width = 100, align = "CENTER" },
{ key = "level", title = "Lvl", width = 50, align = "CENTER" },
{ key = "class", title = "Class", width = 60, align = "CENTER" },
{ key = "preset", title = "Preset", width = 100, align = "CENTER" },
{ key = "lowestHealth", title = "Lowest HP", width = 90, align = "CENTER" },
{ key = "elitesSlain", title = "Elites", width = 60, align = "CENTER" },
{ key = "enemiesSlain", title = "Enemies", width = 80, align = "CENTER" },
{ key = "achievements", title = "Achievements", width = 110, align = "CENTER" },
{ key = "seen", title = "Updated", width = 80, align = "CENTER" },
{ key = "version", title = "Version", width = 70, align = "CENTER" },
}
local sortState = {
key = nil,
asc = true
}
local function isDead(e)
return e and e.dead == true
end
local function valueForSort(e, key)
if key == "seen" then
return tonumber(e.lastSeenSec) or math.huge
elseif key == "name" or key == "class" or key == "preset" or key == "version" then
return tostring(e[key] or ""):lower()
elseif key == "online" then
return e.online and 1 or 0
elseif key == "achievements" then
return tonumber(e.achievementsCompleted) or 0
else
return tonumber(e[key]) or 0
end
end
local function DefaultCompare(a, b)
-- 0) Dead (0% lowest HP) always at the bottom
-- local ad, bd = isDead(a), isDead(b)
-- if ad ~= bd then
-- return not ad
-- end
-- 1) Online first (true > false)
local ao = a.online and 1 or 0
local bo = b.online and 1 or 0
if ao ~= bo then
return ao > bo
end
-- 2) Level (higher first)
if a.level ~= b.level then
return (a.level or 0) > (b.level or 0)
end
-- 3) Name (A → Z, case-insensitive)
local an = tostring(a.name or ""):lower()
local bn = tostring(b.name or ""):lower()
if an ~= bn then
return an < bn
end
-- 4) Last seen (more recent first: smaller seconds-since → higher rank)
local aLast = a.lastSeenSec or math.huge
local bLast = b.lastSeenSec or math.huge
return aLast < bLast
end
local function ApplySort(entries)
if sortState.key then
local key, asc = sortState.key, sortState.asc
table.sort(entries, function(a, b)
-- Dead-bottom rule still applies even for header sorts
-- local ad, bd = isDead(a), isDead(b)
-- if ad ~= bd then
-- return not ad
-- end
local va, vb = valueForSort(a, key), valueForSort(b, key)
if va == vb then
-- stable-ish tiebreakers: Level desc, then Name asc
if (a.level or 0) ~= (b.level or 0) then
return (a.level or 0) > (b.level or 0)
end
return tostring(a.name or ""):lower() < tostring(b.name or ""):lower()
end
if asc then
return va < vb
else
return va > vb
end
end)
else
table.sort(entries, DefaultCompare)
end
end
local function UpdateHeaderArrows()
if not HEADER then
return
end
for i, col in ipairs(COLS) do
local txt = col.title
if sortState.key == col.key then
--txt = txt .. (sortState.asc and " |TInterface\\MainMenuBar\\glues-characterSelect-icon-arrowUp-small-ScrollUpButton-Up:30:25|t" or " |TInterface\\MainMenuBar\\UI-MainMenu-ScrollDownButton-Up:30:25|t")
txt = txt .. (sortState.asc and " |TInterface\\Buttons\\arrow-up-down:30:25|t" or " |TInterface\\Buttons\\arrow-down-down:30:25|t")
end
HEADER[i]:SetText(txt)
end
end
local UHLB_ContextMenu
local UHLB_ContextTarget
local function UHLB_IsInviteDisabled(name)
if not name or name == UnitName("player") or (IsInGroup() and not (UnitIsGroupLeader("player") or (IsInRaid() and UnitIsGroupAssistant("player")))) then return true end
return false
end
UHLB_ContextMenu = CreateFrame("Frame", "UHLB_ContextMenu", UIParent, "UIDropDownMenuTemplate")
-- Bind initializer: builds Whisper / Invite menu for the current UHLB_ContextTarget
UIDropDownMenu_Initialize(UHLB_ContextMenu, function(self, level, menuList)
local info = UIDropDownMenu_CreateInfo()
if (level or 1) == 1 then
-- Title (player name)
info = UIDropDownMenu_CreateInfo()
info.text = UHLB_ContextTarget or "Player"
info.isTitle = true
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
-- Whisper
info = UIDropDownMenu_CreateInfo()
info.text = "Whisper"
info.notCheckable = true
info.func = function()
if UHLB_ContextTarget then
if ChatFrame_OpenChat then
ChatFrame_OpenChat("/w " .. UHLB_ContextTarget .. " ")
end
end
CloseDropDownMenus()
end
UIDropDownMenu_AddButton(info, level)
-- Invite
info = UIDropDownMenu_CreateInfo()
info.text = "Invite to Group"
info.notCheckable = true
info.disabled = UHLB_IsInviteDisabled(UHLB_ContextTarget)
info.func = function()
if UHLB_ContextTarget then
if C_PartyInfo and C_PartyInfo.InviteUnit then
C_PartyInfo.InviteUnit(UHLB_ContextTarget)
else
InviteUnit(UHLB_ContextTarget)
end
end
CloseDropDownMenus()
end
UIDropDownMenu_AddButton(info, level)
-- Cancel
info = UIDropDownMenu_CreateInfo()
info.text = "Cancel"
info.notCheckable = true
UIDropDownMenu_AddButton(info, level)
end
end, "MENU")
-- Helper to show the menu at the cursor
local function UHLB_ShowContextMenuFor(name)
if not name or name == "" then return end
UHLB_ContextTarget = name
ToggleDropDownMenu(1, nil, UHLB_ContextMenu, "cursor", 3, -3)
end
local function CreateMainFrame()
local f = CreateFrame("Frame", "UHLB_LeaderboardFrame", UIParent, "BasicFrameTemplateWithInset")
f:SetFrameStrata("HIGH")
f:SetSize(940, 420)
f:SetPoint("CENTER")
f:Hide()
f:SetMovable(true)
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
f.title = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
f.title:SetPoint("CENTER", f.TitleBg, "CENTER")
-- Set initial title based on restriction setting
if addon.db.profile.restrictToGuild then
f.title:SetText("|cfff44336Ultra Hardcore — Guild Live Leaderboard|r")
else
f.title:SetText("|cfff44336Ultra Hardcore — Realm Live Leaderboard|r")
end
local totalWidth = 0
for _, col in ipairs(COLS) do
totalWidth = totalWidth + col.width + 10
end
totalWidth = totalWidth - 10
local header = CreateFrame("Frame", nil, f)
header:SetPoint("TOPLEFT", f, "TOPLEFT", 10, -28)
header:SetSize(totalWidth, 20)
HEADER = {}
local x = 0
for i, col in ipairs(COLS) do
local fs = header:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
fs:SetPoint("LEFT", header, "LEFT", x, 0)
fs:SetSize(col.width, 20)
fs:SetJustifyH(col.align or "CENTER")
fs:SetJustifyV("MIDDLE")
fs:SetText(col.title)
fs:EnableMouse(true)
fs:SetScript("OnMouseUp", function(_, button)
if button ~= "LeftButton" then return end
if sortState.key == col.key then
sortState.asc = not sortState.asc
else
sortState.key = col.key
-- Simple convention: numbers default desc for first click, strings asc
local numeric = (col.key ~= "name" and col.key ~= "class" and col.key ~= "preset" and col.key ~= "version" and col.key ~= "seen")
sortState.asc = not numeric
end
UpdateHeaderArrows()
f.RefreshLeaderboardUI()
end)
HEADER[i] = fs
x = x + col.width + 10
end
local scroll = CreateFrame("ScrollFrame", nil, f, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", header, "BOTTOMLEFT", 0, -6)
scroll:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -34, 36)
SCROLL = scroll
local child = CreateFrame("Frame", nil, scroll)
child:SetSize(totalWidth, 1)
scroll:SetScrollChild(child)
SCROLL_CHILD = child
leaderboardRows = {}
for i = 1, VISIBLE_ROWS + 2 do
local row = CreateFrame("Frame", nil, child)
row:SetPoint("TOPLEFT", child, "TOPLEFT", 0, -((i-1) * ROW_HEIGHT))
row:SetSize(totalWidth, ROW_HEIGHT)
row:EnableMouse(true)
row.cols = {}
local xOffset = 0
for j, col in ipairs(COLS) do
local fs = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
fs:SetPoint("TOPLEFT", row, "TOPLEFT", xOffset, 0)
fs:SetWidth(col.width)
fs:SetHeight(ROW_HEIGHT)
fs:SetJustifyH(COLS[j].align or "CENTER")
fs:SetJustifyV("MIDDLE")
row.cols[j] = fs
xOffset = xOffset + col.width + 10
end
row:Hide()
row.highlight = row:CreateTexture(nil, "BACKGROUND")
row.highlight:SetAllPoints(row)
row.highlight:SetColorTexture(0.95, 0.26, 0.21, 0.25)
row.highlight:Hide()
row:SetScript("OnMouseUp", function(self, button)
if button == "RightButton" and self.name and self.online then
UHLB_ShowContextMenuFor(self.name)
elseif button == "LeftButton" and self.name then
CloseDropDownMenus()
end
end)
row:SetScript("OnEnter", function(self)
if self.online then
self.highlight:SetColorTexture(0.95, 0.26, 0.21, 0.25)
else
self.highlight:SetColorTexture(0.60, 0.60, 0.60, 0.25)
end
self.highlight:Show()
if self.name and self.tooltipText then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT", 36, self:GetHeight() * -1)
GameTooltip:SetText(self.name, 1, 1, 1)
GameTooltip:AddLine(self.tooltipText, 1, 1, 1, true)
GameTooltip:Show()
end
end)
row:SetScript("OnLeave", function(self)
self.highlight:Hide()
GameTooltip:Hide()
end)
leaderboardRows[i] = row
end
-- Add guild restriction checkbox
local guildCheckbox = CreateFrame("CheckButton", nil, f, "UICheckButtonTemplate")
guildCheckbox:SetPoint("BOTTOMLEFT", f, "BOTTOMLEFT", 10, 8)
guildCheckbox:SetSize(20, 20)
guildCheckbox:SetChecked(addon.db.profile.restrictToGuild)
local guildCheckboxLabel = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
guildCheckboxLabel:SetPoint("LEFT", guildCheckbox, "RIGHT", 5, 0)
guildCheckboxLabel:SetText("Restrict to Guild")
guildCheckbox:SetScript("OnClick", function(self)
addon.db.profile.restrictToGuild = self:GetChecked()
-- Update title based on restriction setting
if addon.db.profile.restrictToGuild then
f.title:SetText("|cfff44336Ultra Hardcore — Guild Live Leaderboard|r")
else
f.title:SetText("|cfff44336Ultra Hardcore — Realm Live Leaderboard|r")
end
f.RefreshLeaderboardUI()
end)
local hint = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
hint:SetPoint("CENTER", f, "BOTTOM", 0, 20)
hint:SetJustifyH("CENTER")
hint:SetJustifyV("MIDDLE")
hint:SetText("|cffbbbbbbData may take up to 60 seconds to fully propagate after logging in|r")
-- Player count label in bottom right corner
local playerCountLabel = f:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
playerCountLabel:SetPoint("BOTTOMRIGHT", f, "BOTTOMRIGHT", -15, 14)
playerCountLabel:SetJustifyH("RIGHT")
playerCountLabel:SetJustifyV("MIDDLE")
playerCountLabel:SetText("Players online: 0/0")
f.CloseButton:SetScript("OnClick", function() f:Hide() end)
function f.RefreshLeaderboardUI(levelSort)
local data = addon:GetModule("Data", true)
local rows = data and data:BuildRowsForUI(seen) or {}
local entries = {}
local net = addon:GetModule("Network", true)
for _, r in ipairs(rows) do
local preset, tooltipText = GetPresetAndTooltip(r.name)
local shownVersion
if IsLeftAltKeyDown() and net and net:IsDebug() then
local sv = seen[r.name]
shownVersion = (sv and sv.LVersion) or r.version
else
shownVersion = r.version
end
table.insert(entries, {
name = r.name,
level = r.level,
class = r.class,
lowestHealth = r.lowestHealth,
elitesSlain = r.elitesSlain,
enemiesSlain = r.enemiesSlain,
achievementsCompleted = r.achievementsCompleted,
achievementsTotal = r.achievementsTotal,
preset = preset,
seen = r.lastSeenText,
version = shownVersion,
tooltipText = tooltipText,
online = r.online,
lastSeenSec = r.lastSeenSec,
dead = r.dead,
guild = r.guild,
})
end
ApplySort(entries)
-- Count online and total players
local onlineCount = 0
local totalCount = #entries
for _, e in ipairs(entries) do
if e.online then
onlineCount = onlineCount + 1
end
end
-- Update player count label
playerCountLabel:SetText(string.format("Players online: %d/%d", onlineCount, totalCount))
for _, row in ipairs(leaderboardRows) do row:Hide() end
local totalHeight = #entries * ROW_HEIGHT
SCROLL_CHILD:SetHeight(math.max(totalHeight, VISIBLE_ROWS * ROW_HEIGHT))
for i, e in ipairs(entries) do
local row = leaderboardRows[i]
if not row then
row = CreateFrame("Frame", nil, SCROLL_CHILD)
row:SetPoint("TOPLEFT", SCROLL_CHILD, "TOPLEFT", 0, -((i-1) * ROW_HEIGHT))
row:SetSize(totalWidth, ROW_HEIGHT)
row:EnableMouse(true)
row.highlight = row:CreateTexture(nil, "BACKGROUND")
row.highlight:SetAllPoints(row)
row.highlight:SetColorTexture(0.95, 0.26, 0.21, 0.25)
row.highlight:Hide()
row.cols = {}
local xOffset = 0
for j, col in ipairs(COLS) do
local fs = row:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
fs:SetPoint("TOPLEFT", row, "TOPLEFT", xOffset, 0)
fs:SetWidth(col.width)
fs:SetHeight(ROW_HEIGHT)
fs:SetJustifyH(COLS[j].align or "CENTER")
fs:SetJustifyV("MIDDLE")
row.cols[j] = fs
xOffset = xOffset + col.width + 10
end
-- Add a hidden background highlight
row.highlight = row:CreateTexture(nil, "BACKGROUND")
row.highlight:SetAllPoints(row)
row.highlight:SetColorTexture(0.95, 0.26, 0.21, 0.25)
row.highlight:Hide()
row:SetScript("OnMouseUp", function(self, button)
if button == "RightButton" and self.name and self.online then
UHLB_ShowContextMenuFor(self.name)
elseif button == "LeftButton" and self.name then
CloseDropDownMenus()
end
end)
row:SetScript("OnEnter", function(self)
if self.online then
self.highlight:SetColorTexture(0.95, 0.26, 0.21, 0.25)
else
self.highlight:SetColorTexture(0.60, 0.60, 0.60, 0.25)
end
self.highlight:Show()
if self.name and self.tooltipText then
GameTooltip:SetOwner(self, "ANCHOR_RIGHT", 36, self:GetHeight() * -1)
GameTooltip:SetText(self.name, 1, 1, 1)
GameTooltip:AddLine(self.tooltipText, 1, 1, 1, true)
GameTooltip:Show()
end
end)
row:SetScript("OnLeave", function(self)
self.highlight:Hide()
GameTooltip:Hide()
end)
leaderboardRows[i] = row
end
local base = e.name
local maxChars = 18
if string.len(base) > maxChars then
base = string.sub(base, 1, maxChars - 2) .. "."
end
-- Prefix a skull icon for dead players using an inline texture
if isDead(e) then
local skull = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_8:12:12:0:0|t "
base = skull .. base
end
row.cols[1]:SetText(base)
row.cols[2]:SetText(e.level)
row.cols[3]:SetText(e.class)
row.cols[4]:SetText(e.preset)
row.cols[5]:SetText(e.lowestHealth .. "%")
row.cols[6]:SetText(e.elitesSlain)
row.cols[7]:SetText(e.enemiesSlain)
row.cols[8]:SetText(string.format("%d/%d", e.achievementsCompleted or 0, e.achievementsTotal or 0))
row.cols[9]:SetText(e.seen)
row.cols[10]:SetText(e.version)
row.name = e.name
row.tooltipText = e.tooltipText
row.online = e.online and true or false
if not row.online then row.highlight:Hide() end
local isOffline = not row.online
-- Default colors for all columns
local r,g,b = isOffline and 0.65 or 1, isOffline and 0.65 or 1, isOffline and 0.65 or 1
-- Special colors for dead players
if isDead(e) then
r, g, b = 0.95, 0.26, 0.21 -- Red for dead players
end
-- Color all columns with default colors
for _, fs in ipairs(row.cols) do
fs:SetTextColor(r, g, b)
end
-- Special coloring for player name (first column) - guild members in global view
if isGlobalView and isGuildMember then
row.cols[1]:SetTextColor(0.4, 0.8, 0.4) -- Light green for guild member names in global view
end
row:SetAlpha(isOffline and 0.75 or 1)
row:Show()
end
SCROLL:UpdateScrollChildRect()
end
return f
end
C_Timer.After(1, function()
if not FRAME then FRAME = CreateMainFrame() end
end)
------------------------------------------------------------
-- Slash command to toggle
------------------------------------------------------------
SLASH_UHLB1 = "/uhlb"
SLASH_UHLB2 = "/uhclb" -- old alias kept
SlashCmdList.UHLB = function(msg)
msg = (msg or ""):lower():match("^%s*(.-)%s*$")
-- default: toggle the UI
if msg == "" or msg == "toggle" then
if not FRAME then FRAME = CreateMainFrame() end
if FRAME:IsShown() then
FRAME:Hide()
else
FRAME:Show()
FRAME.RefreshLeaderboardUI(true)
end
return
end
-- debug toggle
if msg == "debug" then
local net = addon and addon:GetModule("Network", true)
if net then
net:SetDebug(not net:IsDebug())