Repository navigation
Expand file tree
/
Copy pathModules.lua
More file actions
2914 lines (2742 loc) · 126 KB
/
Copy pathModules.lua
File metadata and controls
2914 lines (2742 loc) · 126 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 ADDON, ns = ...
local L = ns.L
-- Modules.lua: every data block (gold, bags, FPS, ...) is defined here.
--
-- HOW TO ADD A BLOCK
-- Call ns:RegisterModule(key, def). `key` is the unique internal id (also used in
-- saved variables, so never rename it once released). `def` is a table with:
--
-- label Locale key of the block's name: L[label] is the display name,
-- so add the key to the Locales files (e.g. label = "GOLD" -> L.GOLD).
-- icon Icon texture path, shown when the "Show icon" option is checked.
-- getIcon(cfg) Optional. Returns an icon that changes at runtime; overrides `icon`.
-- events Optional. List of WoW events that trigger an update.
-- interval Optional. Periodic update, in seconds (only while the block is shown,
-- or while it is hidden because empty, so it can come back).
-- update(cfg) Required. Returns the text to display and an optional level:
-- 1 = good (GOOD), 2 = warning (WARN), 3 = bad (BAD).
-- The level only colors the text if the user enabled "Colorize".
-- Returning nil shows "N/A" (L.NA). Errors are caught and printed once.
-- (Core also passes the block key as a 2nd argument.)
-- tooltip(tt, cfg) Optional. Adds lines to the tooltip `tt` (GameTooltip). The block
-- name, click hint and "right-click: settings" lines are added for you.
-- customTooltip(frame, cfg) Optional. Takes over the whole tooltip (anchor, Show()...);
-- `tooltip` and `clickHint` are then ignored.
-- isEmpty(cfg) Optional. Returns true when there is nothing to show; the block then
-- hides itself if the user enabled "Hide when empty" (cfg.hideEmpty).
-- Defining it is what makes that option available for the block.
-- secureMacro Optional. Macro text run by a secure button on left-click. Use it to
-- open game windows (bags, map, ...) without "tainting" Blizzard's UI.
-- onClick(frame, button, cfg) Optional. Plain Lua click handler, for things that do
-- not need a secure button. Right-click is reserved for block settings.
-- onWheel(delta, cfg) Optional. Mouse wheel handler (delta > 0 = wheel up). Only
-- active while blocks are locked.
-- clickHint Optional. Line shown at the bottom of the tooltip ("Click: ...").
-- request() Optional. Asks the server for fresh data (e.g. guild roster).
-- Called 5 s after login, then every `requestInterval` seconds
-- (default 60), only while the block is enabled. The answer comes back
-- as an event, so list that event in `events`.
-- defaultEnabled Set to false for a block that is hidden by default.
-- progress(cfg) Optional. Returns 0..1: enables the "progress bar" option (the
-- block's background fills accordingly).
-- thresholds Optional. { warn, bad, low, min, max, step }: default orange / red
-- thresholds (low = true when LOW values are bad); the player can
-- change them per block. Use Threshold(cfg, value, def) in update.
-- options Optional. Settings shown in the Behaviour tab for this block only:
-- list of { kind = "check" | "dropdown" | "slider" | "number" |
-- "text" | "color", field, label, tip (locale keys), values (for
-- dropdowns: { key, label }), min / max / step, shown(cfg) }.
-- defaults Optional. Default settings for this block (e.g. progressBar = true).
-- forced Optional. Settings always applied (e.g. a spacer never has an icon).
-- chatText(cfg) Optional. Plain text for "copy to chat" (Shift + click by default).
-- extraAction Optional. { key, label, run(cfg) }: an extra choice for the
-- Shift / middle click actions (e.g. coordinates: place a map pin).
-- alertOnShow Optional. Flash the block when it appears (new mail, whisper...).
--
-- Minimal example (a block showing the player's level):
--
-- ns:RegisterModule("level", {
-- label = "LEVEL", -- needs L.LEVEL in the Locales
-- icon = "Interface\\Icons\\INV_Misc_Note_01",
-- events = { "PLAYER_LEVEL_UP" },
-- update = function(cfg)
-- return tostring(UnitLevel("player")), GOOD
-- end,
-- })
local GOOD, WARN, BAD = 1, 2, 3
-- Streamer mode: a name, realm or amount that must not show on a stream
local function Masked(text)
if ns:IsStreamer() then return ns.HIDDEN end
return text
end
-- Item info: modern C_Item API, classic global as fallback
local GetItemInfoFn = (C_Item and C_Item.GetItemInfo) or function() end
---------------------------------------------------------------------------
-- Session tracking: FPS and experience, recorded even while the blocks are hidden
---------------------------------------------------------------------------
local session = {
start = GetTime(),
fps = { sum = 0, count = 0 },
xpGained = 0,
}
local ignoreFPSUntil = GetTime() + 10 -- loading screens skew the FPS numbers
-- "1 hr 5 min" style duration (game API if available, else "1h 05m")
local function FormatDuration(seconds)
seconds = math.max(0, math.floor(seconds or 0))
if SecondsToTime then return SecondsToTime(seconds) end
return ("%dh %02dm"):format(math.floor(seconds / 3600), math.floor(seconds % 3600 / 60))
end
-- Records XP gained this session (handles level-ups, where the XP bar resets)
local tracker = CreateFrame("Frame")
tracker:RegisterEvent("PLAYER_ENTERING_WORLD")
tracker:RegisterEvent("PLAYER_XP_UPDATE")
tracker:SetScript("OnEvent", function(_, event)
if event == "PLAYER_ENTERING_WORLD" then
ignoreFPSUntil = GetTime() + 5
session.lastXP, session.lastXPMax = UnitXP("player"), UnitXPMax("player")
else
local cur, max = UnitXP("player"), UnitXPMax("player")
local last, lastMax = session.lastXP, session.lastXPMax
if last then
-- level gained: rest of the previous level + start of the new one
local gained = cur >= last and (cur - last) or ((lastMax or last) - last + cur)
session.xpGained = session.xpGained + gained
end
session.lastXP, session.lastXPMax = cur, max
end
end)
-- History for the tooltip graphs: one point every 5 seconds, last 5 minutes
local GRAPH_POINTS, GRAPH_STEP = 60, 5
local history = { fps = {}, latency = {} }
local fpsBucket = { sum = 0, count = 0 }
local function PushHistory(list, value)
table.insert(list, value)
if #list > GRAPH_POINTS then table.remove(list, 1) end
end
-- Samples FPS once per second for the session average / min / max (and the graph)
C_Timer.NewTicker(1, function()
if GetTime() < ignoreFPSUntil then return end
local fps = GetFramerate()
if not fps or fps <= 0 then return end
local f = session.fps
f.sum, f.count = f.sum + fps, f.count + 1
f.min = f.min and math.min(f.min, fps) or fps
f.max = f.max and math.max(f.max, fps) or fps
fpsBucket.sum, fpsBucket.count = fpsBucket.sum + fps, fpsBucket.count + 1
if fpsBucket.count >= GRAPH_STEP then
PushHistory(history.fps, fpsBucket.sum / fpsBucket.count)
fpsBucket.sum, fpsBucket.count = 0, 0
end
end)
-- Samples the world latency every 5 seconds for its graph
C_Timer.NewTicker(GRAPH_STEP, function()
local _, _, _, world = GetNetStats()
if world and world > 0 then PushHistory(history.latency, world) end
end)
-- Small bar graph drawn inside the tooltip, under a title line. Space is reserved
-- with blank lines, then a frame with one bar per point is laid over them.
local GRAPH_W, GRAPH_H = 200, 34
local graph
local function AddGraph(tt, title, values, levelOf)
if #values < 2 or not tt.GetName or not tt:GetName() then return end
tt:AddLine(" ")
tt:AddLine(title, 0.8, 0.8, 0.8)
local first = tt:NumLines() + 1
for _ = 1, 3 do tt:AddLine(" ") end
local line = _G[tt:GetName() .. "TextLeft" .. first]
if not line then return end
if not graph then
graph = CreateFrame("Frame", nil, tt)
graph.bars = {}
-- the graph belongs to one tooltip display only
tt:HookScript("OnHide", function() graph:Hide() end)
tt:HookScript("OnTooltipCleared", function(self)
graph:Hide()
if graph.widened and self.SetMinimumWidth then
self:SetMinimumWidth(0)
graph.widened = nil
end
end)
end
graph:SetParent(tt)
graph:ClearAllPoints()
graph:SetPoint("TOPLEFT", line, "TOPLEFT", 0, -2)
graph:SetSize(GRAPH_W, GRAPH_H)
if tt.SetMinimumWidth then
tt:SetMinimumWidth(GRAPH_W + 24)
graph.widened = true
end
local maxV = 1
for _, v in ipairs(values) do maxV = math.max(maxV, v) end
local barW = GRAPH_W / GRAPH_POINTS
for i = 1, GRAPH_POINTS do
local bar = graph.bars[i]
if not bar then
bar = graph:CreateTexture(nil, "ARTWORK")
graph.bars[i] = bar
end
local v = values[#values - GRAPH_POINTS + i]
if v then
local hex = ns.LEVEL_COLORS[levelOf(v)] or "ffffff"
bar:SetColorTexture(tonumber(hex:sub(1, 2), 16) / 255, tonumber(hex:sub(3, 4), 16) / 255,
tonumber(hex:sub(5, 6), 16) / 255, 0.85)
bar:ClearAllPoints()
bar:SetSize(math.max(1, barW - 1), math.max(1, v / maxV * GRAPH_H))
bar:SetPoint("BOTTOMLEFT", graph, "BOTTOMLEFT", (i - 1) * barW, 0)
bar:Show()
else
bar:Hide()
end
end
graph:Show()
end
-- Game frame rate cap (0 or disabled = unlimited). pcall: the CVar may not exist on every client
local function FPSCap(useVar, valueVar)
local ok, use = pcall(GetCVar, useVar)
local ok2, value = pcall(GetCVar, valueVar)
value = ok2 and tonumber(value)
if (ok and use == "0") or not value or value <= 0 then return L.TT_UNLIMITED end
return L.FPS_FORMAT:format(value)
end
-- r, g, b of a class ("WARRIOR"...). Modern C_ClassColor API, else the classic RAID_CLASS_COLORS table; white if unknown
-- (soft or bright with the rest of the colors: ns:ClassColorRGB, Core.lua)
local function ClassColor(class)
local r, g, b = ns:ClassColorRGB(class)
if r then return r, g, b end
return 1, 1, 1
end
-- value / max as a percentage, safe against max = 0
local function Percent(value, max)
if not max or max == 0 then return 0 end
return value / max * 100
end
-- Color code ("|cffRRGGBB") for a level (GOOD / WARN / BAD); close it with "|r"
-- Level (GOOD / WARN / BAD) of a value against thresholds. `def` holds the
-- module's defaults { warn, bad, low } (low = true when LOW values are bad); the
-- player can override them per block (cfg.warnAt / cfg.badAt, Behaviour tab).
local function Threshold(cfg, value, def)
local warn = (cfg and cfg.warnAt) or def.warn
local bad = (cfg and cfg.badAt) or def.bad
if def.low then
if value <= bad then return BAD end
if value <= warn then return WARN end
else
if value >= bad then return BAD end
if value >= warn then return WARN end
end
return GOOD
end
-- Default thresholds (min / max / step size the sliders in the options)
local THRESHOLDS = {
bags = { warn = 8, bad = 2, low = true, min = 0, max = 40, step = 1 },
durability = { warn = 50, bad = 20, low = true, min = 0, max = 100, step = 5 },
fps = { warn = 45, bad = 25, low = true, min = 5, max = 144, step = 1 },
latency = { warn = 100, bad = 250, low = false, min = 20, max = 1000, step = 10 },
ammo = { warn = 200, bad = 50, low = true, min = 0, max = 1000, step = 10 },
}
local function LevelColor(level)
return "|cff" .. (ns.LEVEL_COLORS[level] or "ffffff")
end
---------------------------------------------------------------------------
-- Gold
---------------------------------------------------------------------------
local COIN_ICONS = {
gold = "Interface\\MoneyFrame\\UI-GoldIcon",
silver = "Interface\\MoneyFrame\\UI-SilverIcon",
copper = "Interface\\MoneyFrame\\UI-CopperIcon",
}
-- Money as text with coin icons. Uses the game's C_CurrencyInfo API, else our own
-- formatting. Also used by other files (ns.FormatMoney)
function ns.FormatMoney(money, size)
size = size or 12
if C_CurrencyInfo and C_CurrencyInfo.GetCoinTextureString then
local ok, text = pcall(C_CurrencyInfo.GetCoinTextureString, money, size)
if ok and text then return text end
end
local gold = math.floor(money / 10000)
local silver = math.floor((money % 10000) / 100)
local copper = money % 100
local function Icon(file) return ("|T%s:%d:%d:2:0|t"):format(file, size, size) end
local parts = {}
if gold > 0 then
table.insert(parts, (BreakUpLargeNumbers and BreakUpLargeNumbers(gold) or gold) .. Icon(COIN_ICONS.gold))
end
if gold > 0 or silver > 0 then
table.insert(parts, silver .. Icon(COIN_ICONS.silver))
end
table.insert(parts, copper .. Icon(COIN_ICONS.copper))
return table.concat(parts, " ")
end
-- Gold amount as the block's options say:
-- goldFormat "full" (gold, silver, copper), "goldSilver", "gold" (gold pieces only)
-- or "short" (12.3k gold)
-- goldIcons coin icons (default), or colored letters (g s c / po pa pc)
-- goldRound rounded to the nearest shown unit instead of cut off
-- goldSeparator thousands separator (default)
local COIN_COLORS = { gold = "ffd100", silver = "c7c7cf", copper = "eda55f" }
local function FormatGold(money, cfg)
cfg = cfg or {}
local format = cfg.goldFormat or "full"
local size = cfg.fontSize or 12
local function Unit(kind)
-- coin icons, or letters (black and white styles: the icons cannot turn grey)
if cfg.goldIcons ~= false and not cfg.monochrome then return ("|T%s:%d:%d:2:0|t"):format(COIN_ICONS[kind], size, size) end
return "|cff" .. COIN_COLORS[kind] .. L["COIN_" .. kind:upper()] .. "|r"
end
local function Number(n)
if cfg.goldSeparator ~= false and BreakUpLargeNumbers then return BreakUpLargeNumbers(n) end
return tostring(n)
end
local round = cfg.goldRound and 0.5 or 0
if format == "short" then
local gold = money / 10000
if gold >= 1000000 then return ("%.1fM"):format(gold / 1000000) .. Unit("gold") end
if gold >= 1000 then return ("%.1fk"):format(gold / 1000) .. Unit("gold") end
format = "gold"
end
if format == "gold" then return Number(math.floor(money / 10000 + round)) .. Unit("gold") end
if format == "goldSilver" then money = math.floor(money / 100 + round) * 100 end
local gold = math.floor(money / 10000)
local silver = math.floor((money % 10000) / 100)
local copper = money % 100
local parts = {}
if gold > 0 then table.insert(parts, Number(gold) .. Unit("gold")) end
if format == "goldSilver" then
if silver > 0 or gold == 0 then table.insert(parts, silver .. Unit("silver")) end
else
if gold > 0 or silver > 0 then table.insert(parts, silver .. Unit("silver")) end
table.insert(parts, copper .. Unit("copper"))
end
return table.concat(parts, " ")
end
-- Signed amount with colored + / - (tooltip lines)
local function SignedMoney(diff)
local sign = diff >= 0 and "|cff4dff4d+|r " or "|cffff4d4d-|r "
return sign .. ns.FormatMoney(math.abs(diff))
end
ns:RegisterModule("gold", {
label = "GOLD",
icon = COIN_ICONS.gold,
events = { "PLAYER_MONEY" },
update = function(cfg)
if ns:IsStreamer() then return ns.HIDDEN end
return FormatGold(GetMoney() or 0, cfg)
end,
-- Shift + click "copy to chat": plain text, without coin textures
chatText = function()
if ns:IsStreamer() then return ns.HIDDEN end
local money = GetMoney() or 0
return L.CHAT_MONEY:format(math.floor(money / 10000), math.floor(money % 10000 / 100), money % 100)
end,
defaults = { goldIcons = true, goldRound = false, goldSeparator = true },
options = {
{ kind = "dropdown", field = "goldFormat", tab = "text", label = "GOLD_FORMAT", tip = "TIP_GOLD_FORMAT",
values = { { key = "full", label = "GOLD_FULL" }, { key = "goldSilver", label = "GOLD_SILVER" },
{ key = "gold", label = "GOLD_ONLY" }, { key = "short", label = "GOLD_SHORT" } } },
{ kind = "check", field = "goldIcons", tab = "text", label = "GOLD_ICONS", tip = "TIP_GOLD_ICONS" },
{ kind = "check", field = "goldRound", tab = "text", label = "GOLD_ROUND", tip = "TIP_GOLD_ROUND",
shown = function(cfg) return cfg.goldFormat == "gold" or cfg.goldFormat == "goldSilver" end },
{ kind = "check", field = "goldSeparator", tab = "text", label = "GOLD_SEPARATOR", tip = "TIP_GOLD_SEPARATOR" },
},
tooltip = function(tt)
if ns:IsStreamer() then
tt:AddLine(L.STREAMER_TOOLTIP, 0.8, 0.8, 0.8, true)
return
end
local money = GetMoney() or 0
local diff = money - (ns.sessionMoney or money)
tt:AddDoubleLine(L.TT_SESSION, SignedMoney(diff), 1, 1, 1, 1, 1, 1)
local hours = (GetTime() - session.start) / 3600
if hours >= 0.1 and diff ~= 0 then
tt:AddDoubleLine(L.TT_GOLD_HOUR, SignedMoney(math.floor(diff / hours)), 1, 1, 1, 1, 1, 1)
end
-- last 7 days for this character (net gain or loss per day), newest first
local days = ns.sv.goldHistory and ns.sv.goldHistory[ns.charKey]
if days then
local list = {}
for day, net in pairs(days) do table.insert(list, { day = day, net = net }) end
table.sort(list, function(a, b) return a.day > b.day end)
if #list > 0 then
tt:AddLine(" ")
tt:AddLine(L.TT_GOLD_HISTORY, 1, 0.82, 0)
for i = 1, math.min(7, #list) do
local m, d = list[i].day:match("%d+-(%d+)-(%d+)")
tt:AddDoubleLine(d and (d .. "/" .. m) or list[i].day, SignedMoney(list[i].net), 1, 1, 1, 1, 1, 1)
end
end
end
local chars, total = {}, 0
for name, data in pairs(ns.sv.chars) do
table.insert(chars, { name = name, money = data.money or 0, class = data.class })
total = total + (data.money or 0)
end
if #chars > 1 then
table.sort(chars, function(a, b) return a.money > b.money end)
tt:AddLine(" ")
tt:AddLine(L.TT_CHARACTERS, 1, 0.82, 0)
for _, c in ipairs(chars) do
local r, g, b = ClassColor(c.class)
tt:AddDoubleLine(ns.ShortCharName(c.name), ns.FormatMoney(c.money), r, g, b, 1, 1, 1)
end
tt:AddDoubleLine(L.TT_TOTAL, ns.FormatMoney(total), 1, 0.82, 0, 1, 1, 1)
tt:AddLine(L.GOLD_FORGET_HINT, 0.6, 0.6, 0.6)
end
end,
secureMacro = "/run ToggleAllBags()",
clickHint = L.HINT_BAGS,
})
---------------------------------------------------------------------------
-- Bags
---------------------------------------------------------------------------
-- Index of the last equipped bag (0 = backpack); the global's name differs between clients
local function LastBag()
return NUM_TOTAL_EQUIPPED_BAG_SLOTS or NUM_BAG_SLOTS or 4
end
ns:RegisterModule("bags", {
label = "BAGS",
icon = "Interface\\Icons\\INV_Misc_Bag_08",
events = { "BAG_UPDATE_DELAYED" },
update = function(cfg)
local free, total = 0, 0
for bag = 0, LastBag() do
local slots = C_Container.GetContainerNumSlots(bag) or 0
if slots > 0 then
total = total + slots
free = free + (C_Container.GetContainerNumFreeSlots(bag) or 0)
end
end
local level = Threshold(cfg, free, THRESHOLDS.bags)
local mode = cfg and cfg.bagsFormat or "freeTotal"
if mode == "free" then return tostring(free), level end
if mode == "usedTotal" then return L.BAGS_FORMAT:format(total - free, total), level end
return L.BAGS_FORMAT:format(free, total), level
end,
defaults = { bagsFormat = "freeTotal" },
options = {
{ kind = "dropdown", field = "bagsFormat", tab = "text", label = "BAGS_SHOWN", tip = "TIP_BAGS_SHOWN",
values = { { key = "freeTotal", label = "BAGS_FREE_TOTAL" }, { key = "free", label = "BAGS_FREE" },
{ key = "usedTotal", label = "BAGS_USED_TOTAL" } } },
},
thresholds = THRESHOLDS.bags,
-- progress bar: how full the bags are
progress = function()
local free, total = 0, 0
for bag = 0, LastBag() do
local slots = C_Container.GetContainerNumSlots(bag) or 0
total = total + slots
if slots > 0 then free = free + (C_Container.GetContainerNumFreeSlots(bag) or 0) end
end
return total > 0 and (total - free) / total or 0
end,
tooltip = function(tt)
local junk = 0
for bag = 0, LastBag() do
local slots = C_Container.GetContainerNumSlots(bag) or 0
if slots > 0 then
local free = C_Container.GetContainerNumFreeSlots(bag) or 0
local name = C_Container.GetBagName and C_Container.GetBagName(bag)
name = name or (bag == 0 and L.TT_BACKPACK or L.TT_BAG:format(bag))
tt:AddDoubleLine(name, L.BAGS_FORMAT:format(free, slots), 1, 1, 1, 1, 1, 1)
-- junk (grey items) sell value; the price is only known once the item is cached
for slot = 1, slots do
local info = C_Container.GetContainerItemInfo and C_Container.GetContainerItemInfo(bag, slot)
if info and info.quality == 0 and info.itemID then
local price = select(11, GetItemInfoFn(info.itemID))
if price then junk = junk + price * (info.stackCount or 1) end
end
end
end
end
if junk > 0 then
tt:AddLine(" ")
tt:AddDoubleLine(L.TT_JUNK, ns.FormatMoney(junk), 0.62, 0.62, 0.62, 1, 1, 1)
end
end,
secureMacro = "/run ToggleAllBags()",
clickHint = L.HINT_BAGS,
})
---------------------------------------------------------------------------
-- Durability (the lowest equipped item is shown)
---------------------------------------------------------------------------
local function DurabilityLevel(pct, cfg)
return Threshold(cfg, pct, THRESHOLDS.durability)
end
-- Lowest durability of the equipped items, in % (nil when nothing has durability)
local function LowestDurability()
local lowest
for slot = 1, 19 do
local cur, max = GetInventoryItemDurability(slot)
if cur and max and max > 0 then
local pct = Percent(cur, max)
if not lowest or pct < lowest then lowest = pct end
end
end
return lowest
end
-- Average durability of the equipped items that have one (percent), or nil
local function AverageDurability()
local sum, count = 0, 0
for slot = 1, 19 do
local cur, max = GetInventoryItemDurability(slot)
if cur and max and max > 0 then
sum, count = sum + Percent(cur, max), count + 1
end
end
return count > 0 and sum / count or nil
end
-- The durability the block shows: the most worn item (default) or the average
local function ShownDurability(cfg)
if cfg and cfg.durabilityMode == "average" then return AverageDurability() end
return LowestDurability()
end
-- Repair cost of the equipped items, in copper, or nil when this client gives no way to
-- read it. The game gives the cost with each item's tooltip: modern tooltip data first,
-- then a hidden tooltip (older API, 3rd return value of SetInventoryItem).
local repairScanner
local function RepairCost()
local total, known = 0, false
for slot = 1, 19 do
local cost
if C_TooltipInfo and C_TooltipInfo.GetInventoryItem then
local ok, data = pcall(C_TooltipInfo.GetInventoryItem, "player", slot)
if ok and type(data) == "table" and type(data.repairCost) == "number" then cost = data.repairCost end
end
if cost == nil then
if not repairScanner then
repairScanner = CreateFrame("GameTooltip", "TesseraRepairScanner", nil, "GameTooltipTemplate")
end
repairScanner:SetOwner(WorldFrame, "ANCHOR_NONE")
local ok, hasItem, _, c = pcall(repairScanner.SetInventoryItem, repairScanner, "player", slot)
if ok and hasItem and type(c) == "number" then cost = c end
repairScanner:Hide()
end
if cost then
known = true
total = total + cost
end
end
return known and total or nil
end
ns:RegisterModule("durability", {
label = "DURABILITY",
icon = "Interface\\Icons\\Trade_BlackSmithing",
events = { "UPDATE_INVENTORY_DURABILITY", "PLAYER_EQUIPMENT_CHANGED" },
update = function(cfg)
local pct = ShownDurability(cfg)
if not pct then return nil end
return ("%d%%"):format(math.floor(pct + 0.5)), DurabilityLevel(pct, cfg)
end,
defaults = { durabilityMode = "lowest" },
options = {
{ kind = "dropdown", field = "durabilityMode", tab = "text", label = "DURABILITY_SHOWN", tip = "TIP_DURABILITY_SHOWN",
values = { { key = "lowest", label = "DURABILITY_LOWEST" }, { key = "average", label = "DURABILITY_AVERAGE" } } },
},
thresholds = THRESHOLDS.durability,
progress = function(cfg)
local lowest = ShownDurability(cfg)
return lowest and lowest / 100 or nil
end,
tooltip = function(tt, cfg)
for slot = 1, 19 do
local cur, max = GetInventoryItemDurability(slot)
if cur and max and max > 0 then
local pct = Percent(cur, max)
local ok, link = pcall(GetInventoryItemLink, "player", slot)
link = ok and link or "?"
tt:AddDoubleLine(link, LevelColor(DurabilityLevel(pct, cfg)) .. ("%d%%"):format(math.floor(pct + 0.5)) .. "|r")
end
end
local cost = RepairCost()
if cost and cost > 0 then
tt:AddLine(" ")
tt:AddDoubleLine(L.TT_REPAIR_COST, ns.FormatMoney(cost), 1, 1, 1, 1, 1, 1)
end
end,
secureMacro = "/click CharacterMicroButton",
clickHint = L.HINT_CHARACTER,
})
---------------------------------------------------------------------------
-- FPS and latency
---------------------------------------------------------------------------
ns:RegisterModule("fps", {
label = "FPS",
icon = "Interface\\Icons\\Ability_Rogue_Sprint",
interval = 1,
update = function(cfg)
local fps = GetFramerate() or 0
local text = (cfg and cfg.showUnit == false) and ("%.0f"):format(fps) or L.FPS_FORMAT:format(fps)
return text, Threshold(cfg, fps, THRESHOLDS.fps)
end,
defaults = { showUnit = true },
options = { { kind = "check", field = "showUnit", tab = "text", label = "SHOW_UNIT", tip = "TIP_SHOW_UNIT" } },
thresholds = THRESHOLDS.fps,
tooltip = function(tt, cfg)
local f = session.fps
tt:AddDoubleLine(L.TT_FPS_NOW, L.FPS_FORMAT:format(GetFramerate() or 0), 1, 1, 1, 1, 1, 1)
if f.count > 0 then
tt:AddDoubleLine(L.TT_FPS_AVG, L.FPS_FORMAT:format(f.sum / f.count), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_FPS_MIN, L.FPS_FORMAT:format(f.min), 1, 1, 1, 1, 0.3, 0.3)
tt:AddDoubleLine(L.TT_FPS_MAX, L.FPS_FORMAT:format(f.max), 1, 1, 1, 0.3, 1, 0.3)
end
tt:AddLine(" ")
tt:AddDoubleLine(L.TT_FPS_CAP, FPSCap("useMaxFPS", "maxFPS"), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_FPS_CAP_BG, FPSCap("useMaxFPSBk", "maxFPSBk"), 1, 1, 1, 1, 1, 1)
if GetPhysicalScreenSize then
local w, h = GetPhysicalScreenSize()
if w and h then tt:AddDoubleLine(L.TT_RESOLUTION, ("%d x %d"):format(w, h), 1, 1, 1, 1, 1, 1) end
end
AddGraph(tt, L.TT_GRAPH_FPS, history.fps, function(v) return Threshold(cfg, v, THRESHOLDS.fps) end)
end,
})
-- GOOD under 100 ms, WARN under 250 ms, BAD above
local function LatencyLevel(ms, cfg)
return Threshold(cfg, ms, THRESHOLDS.latency)
end
ns:RegisterModule("latency", {
label = "LATENCY",
icon = "Interface\\Icons\\Spell_Nature_Lightning",
interval = 5,
update = function(cfg)
local _, _, home, world = GetNetStats()
home, world = home or 0, world or 0
local function Ms(v)
if cfg and cfg.showUnit == false then return tostring(v) end
return L.LATENCY_FORMAT:format(v)
end
local source = cfg and cfg.latencySource or "world"
if source == "home" then return Ms(home), LatencyLevel(home, cfg) end
if source == "both" then
return Ms(home) .. " / " .. Ms(world), LatencyLevel(math.max(home, world), cfg)
end
return Ms(world), LatencyLevel(world, cfg)
end,
defaults = { showUnit = true, latencySource = "world" },
options = {
{ kind = "dropdown", field = "latencySource", tab = "text", label = "LATENCY_SHOWN", tip = "TIP_LATENCY_SHOWN",
values = { { key = "world", label = "TT_WORLD" }, { key = "home", label = "TT_HOME" },
{ key = "both", label = "LATENCY_BOTH" } } },
{ kind = "check", field = "showUnit", tab = "text", label = "SHOW_UNIT", tip = "TIP_SHOW_UNIT" },
},
thresholds = THRESHOLDS.latency,
tooltip = function(tt, cfg)
local bwIn, bwOut, home, world = GetNetStats()
tt:AddDoubleLine(L.TT_HOME, LevelColor(LatencyLevel(home or 0, cfg)) .. L.LATENCY_FORMAT:format(home or 0) .. "|r",
1, 1, 1)
tt:AddDoubleLine(L.TT_WORLD, LevelColor(LatencyLevel(world or 0, cfg)) .. L.LATENCY_FORMAT:format(world or 0)
.. "|r", 1, 1, 1)
tt:AddDoubleLine(L.TT_BANDWIDTH_IN, L.BANDWIDTH_FORMAT:format(bwIn or 0), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_BANDWIDTH_OUT, L.BANDWIDTH_FORMAT:format(bwOut or 0), 1, 1, 1, 1, 1, 1)
AddGraph(tt, L.TT_GRAPH_LATENCY, history.latency, function(v) return LatencyLevel(v, cfg) end)
end,
})
---------------------------------------------------------------------------
-- Local time and server time
---------------------------------------------------------------------------
-- "HH:MM" (24 h) or "H:MM AM/PM" (12 h), per the block's "24-hour clock" option,
-- with ":SS" when the block shows the seconds
local function FormatClock(h, m, cfg, sec)
h, m = h or 0, m or 0
local seconds = (cfg and cfg.showSeconds and sec) and (":%02d"):format(sec) or ""
if cfg and cfg.clock24 == false then
local suffix = h >= 12 and "PM" or "AM"
h = h % 12
if h == 0 then h = 12 end
return ("%d:%02d%s %s"):format(h, m, seconds, suffix)
end
return ("%02d:%02d%s"):format(h, m, seconds)
end
-- Local time of the computer
local function LocalTime(cfg)
local t = date("*t")
return FormatClock(t.hour, t.min, cfg, t.sec)
end
-- Server (realm) time; the game gives hours and minutes only: the seconds come from
-- the server's clock (time zones are whole minutes, so its seconds are the realm's)
local function ServerTime(cfg)
local h, m = GetGameTime()
local now = GetServerTime and GetServerTime() or time()
return FormatClock(h, m, cfg, now % 60)
end
local CLOCK_OPTION = { kind = "check", field = "clock24", tab = "text", label = "CLOCK_24", tip = "TIP_CLOCK_24" }
local SECONDS_OPTION = { kind = "check", field = "showSeconds", tab = "text", label = "SHOW_SECONDS", tip = "TIP_SHOW_SECONDS" }
-- Tooltip shared by both time blocks
local function TimeTooltip(tt, cfg)
tt:AddDoubleLine(L.TT_LOCAL_TIME, LocalTime(cfg), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_SERVER_TIME, ServerTime(cfg), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_SESSION_TIME, FormatDuration(GetTime() - session.start), 1, 1, 1, 1, 1, 1)
tt:AddLine(date("%d/%m/%Y"), 0.8, 0.8, 0.8)
end
-- Does WoW's own clock show local time? (otherwise it shows server time)
-- Modern C_CVar API first, classic GetCVar global as fallback
local function WowClockIsLocal()
local v = (C_CVar and C_CVar.GetCVar and C_CVar.GetCVar("timeMgrUseLocalTime"))
or (GetCVar and GetCVar("timeMgrUseLocalTime"))
return v == "1"
end
-- Which time the "time" block shows: "server", "local", or "auto" = the one
-- WoW's clock does not already show
local function ShowsServerTime(cfg)
local source = cfg and cfg.timeSource or "auto"
if source == "server" then return true end
if source == "local" then return false end
return WowClockIsLocal()
end
ns.ShowsServerTime = ShowsServerTime
ns:RegisterModule("time", {
label = "TIME",
icon = "Interface\\Icons\\INV_Misc_PocketWatch_01",
interval = 1,
update = function(cfg)
if ShowsServerTime(cfg) then return ServerTime(cfg) end
return LocalTime(cfg)
end,
options = {
{ kind = "dropdown", field = "timeSource", tab = "text", label = "TIME_SOURCE", tip = "TIP_TIME_SOURCE",
values = { { key = "auto", label = "TIME_AUTO" }, { key = "local", label = "TT_LOCAL_TIME" },
{ key = "server", label = "TT_SERVER_TIME" } } },
CLOCK_OPTION,
SECONDS_OPTION,
},
defaults = { showSeconds = false },
tooltip = TimeTooltip,
secureMacro = "/run if ToggleCalendar then ToggleCalendar() end",
clickHint = L.HINT_CALENDAR,
})
ns:RegisterModule("serverTime", {
label = "SERVER_TIME",
icon = "Interface\\Icons\\INV_Misc_PocketWatch_02",
interval = 1,
defaultEnabled = false,
update = ServerTime,
options = { CLOCK_OPTION, SECONDS_OPTION },
defaults = { showSeconds = false },
tooltip = TimeTooltip,
secureMacro = "/run if ToggleCalendar then ToggleCalendar() end",
clickHint = L.HINT_CALENDAR,
})
---------------------------------------------------------------------------
-- Date
---------------------------------------------------------------------------
-- Full day and month names come from the game's own texts (translated in every
-- language); short names from Tessera's (a list per language, e.g. "Jan,Feb,..."),
-- since cutting a name gives wrong abbreviations in some languages.
local WEEKDAYS = { "SUNDAY", "MONDAY", "TUESDAY", "WEDNESDAY", "THURSDAY", "FRIDAY", "SATURDAY" }
local MONTHS = { "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER",
"OCTOBER", "NOVEMBER", "DECEMBER" }
local function ShortNames(list)
local names = {}
for name in (list or ""):gmatch("[^,]+") do table.insert(names, name) end
return names
end
local SHORT_DAYS, SHORT_MONTHS = ShortNames(L.DATE_DAYS_SHORT), ShortNames(L.DATE_MONTHS_SHORT)
local function TitleCase(s)
return (s:gsub("^%l", string.upper))
end
-- Today's date, local or server ("realm") one: { year, month, day, wday } (wday 1 = Sunday)
local function Today(server)
if server then
local get = C_DateAndTime and C_DateAndTime.GetCurrentCalendarTime
local ok, t = pcall(function() return get and get() end)
if ok and type(t) == "table" and t.monthDay then
return { year = t.year, month = t.month, day = t.monthDay, wday = t.weekday }
end
end
local t = date("*t")
return { year = t.year, month = t.month, day = t.day, wday = t.wday }
end
-- Formats a date: short "Thu 15 Oct", long "Thursday 15 October", dmy "15/10/2026", dm
-- "15/10", mdy "10/15/2026", iso "2026-10-15" (the order of the named formats is a text
-- of each language: {wd} day name, {d} day, {mon} month name, {y} year)
local function FormatDate(t, format)
if format == "dmy" then return ("%02d/%02d/%d"):format(t.day, t.month, t.year) end
if format == "dm" then return ("%02d/%02d"):format(t.day, t.month) end
if format == "mdy" then return ("%02d/%02d/%d"):format(t.month, t.day, t.year) end
if format == "iso" then return ("%d-%02d-%02d"):format(t.year, t.month, t.day) end
local wd, mon, pattern
if format == "long" then
wd = _G["WEEKDAY_" .. (WEEKDAYS[t.wday] or "")] or WEEKDAYS[t.wday] or "?"
mon = _G["FULLDATE_MONTH_" .. (MONTHS[t.month] or "")] or MONTHS[t.month] or "?"
pattern = L.DATE_PATTERN_LONG
else
wd, mon, pattern = SHORT_DAYS[t.wday] or "?", SHORT_MONTHS[t.month] or "?", L.DATE_PATTERN_SHORT
end
local text = pattern:gsub("{(%a+)}", { wd = wd, d = tostring(t.day), mon = mon, y = tostring(t.year) })
return TitleCase(text)
end
ns.FormatDate = FormatDate
local function SameDay(a, b)
return a.year == b.year and a.month == b.month and a.day == b.day
end
ns:RegisterModule("date", {
label = "DATE",
icon = "Interface\\Icons\\INV_Scroll_05",
interval = 30,
defaultEnabled = false,
defaults = { dateFormat = "short", dateSource = "local" },
update = function(cfg)
return FormatDate(Today(cfg.dateSource == "server"), cfg.dateFormat)
end,
options = {
{ kind = "dropdown", field = "dateFormat", tab = "text", label = "DATE_FORMAT", tip = "TIP_DATE_FORMAT",
values = { { key = "short", label = "DATE_FMT_SHORT" }, { key = "long", label = "DATE_FMT_LONG" },
{ key = "dmy", label = "DATE_FMT_DMY" }, { key = "dm", label = "DATE_FMT_DM" },
{ key = "mdy", label = "DATE_FMT_MDY" }, { key = "iso", label = "DATE_FMT_ISO" } } },
{ kind = "dropdown", field = "dateSource", tab = "text", label = "DATE_SOURCE", tip = "TIP_DATE_SOURCE",
values = { { key = "local", label = "TT_LOCAL_DATE" }, { key = "server", label = "TT_SERVER_DATE" } } },
},
tooltip = function(tt)
local here, realm = Today(false), Today(true)
tt:AddDoubleLine(L.TT_LOCAL_DATE, FormatDate(here, "long"), 1, 1, 1, 1, 1, 1)
if not SameDay(here, realm) then
tt:AddDoubleLine(L.TT_SERVER_DATE, FormatDate(realm, "long"), 1, 1, 1, 1, 1, 1)
end
end,
secureMacro = "/run if ToggleCalendar then ToggleCalendar() end",
clickHint = L.HINT_CALENDAR,
})
---------------------------------------------------------------------------
-- Experience
---------------------------------------------------------------------------
-- True at max level. Uses the modern API if present, else "no XP bar" means max level
local function AtMaxLevel()
local level = UnitLevel("player")
if IsLevelAtEffectiveMaxLevel then return IsLevelAtEffectiveMaxLevel(level) end
local max = UnitXPMax("player")
return not max or max == 0
end
ns:RegisterModule("xp", {
label = "XP",
icon = "Interface\\Icons\\Spell_Holy_SurgeOfLight",
events = { "PLAYER_XP_UPDATE", "UPDATE_EXHAUSTION", "PLAYER_LEVEL_UP" },
defaultEnabled = false,
defaults = { progressBar = true, xpFormat = "percent", xpRested = true },
progress = function()
if AtMaxLevel() then return nil end
local max = UnitXPMax("player")
return max and max > 0 and UnitXP("player") / max or nil
end,
update = function(cfg)
if AtMaxLevel() then return L.MAX_LEVEL end
local cur, max = UnitXP("player"), UnitXPMax("player")
local fmt = BreakUpLargeNumbers or tostring
local mode = cfg and cfg.xpFormat or "percent"
local text
if mode == "values" then
text = ("%s / %s"):format(fmt(cur), fmt(max))
elseif mode == "remaining" then
text = L.XP_TO_GO:format(fmt(max - cur))
else
text = ("%.1f%%"):format(Percent(cur, max))
end
local rested = GetXPExhaustion()
if rested and rested > 0 and not (cfg and cfg.xpRested == false) then
text = text .. (" |cff4da6ff+%.0f%%|r"):format(Percent(rested, max))
end
return text
end,
options = {
{ kind = "dropdown", field = "xpFormat", tab = "text", label = "XP_SHOWN", tip = "TIP_XP_SHOWN",
values = { { key = "percent", label = "XP_PERCENT" }, { key = "values", label = "XP_VALUES" },
{ key = "remaining", label = "XP_REMAINING" } } },
{ kind = "check", field = "xpRested", tab = "text", label = "XP_RESTED", tip = "TIP_XP_RESTED" },
},
tooltip = function(tt)
tt:AddLine(L.TT_LEVEL:format(UnitLevel("player")), 1, 1, 1)
if AtMaxLevel() then return end
local cur, max = UnitXP("player"), UnitXPMax("player")
local fmt = BreakUpLargeNumbers or tostring
tt:AddDoubleLine(L.TT_XP_CURRENT, ("%s / %s"):format(fmt(cur), fmt(max)), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_XP_REMAINING, fmt(max - cur), 1, 1, 1, 1, 1, 1)
local rested = GetXPExhaustion()
if rested and rested > 0 then
tt:AddDoubleLine(L.TT_XP_RESTED, fmt(rested), 1, 1, 1, 0.3, 0.65, 1)
end
local elapsed = GetTime() - session.start
if session.xpGained > 0 then
tt:AddLine(" ")
tt:AddDoubleLine(L.TT_XP_SESSION, fmt(session.xpGained), 1, 1, 1, 1, 1, 1)
if elapsed >= 60 then
local perSecond = session.xpGained / elapsed
tt:AddDoubleLine(L.TT_XP_HOUR, fmt(math.floor(perSecond * 3600)), 1, 1, 1, 1, 1, 1)
tt:AddDoubleLine(L.TT_XP_TO_LEVEL, FormatDuration((max - cur) / perSecond), 1, 1, 1, 1, 0.82, 0)
end
end
end,
})
---------------------------------------------------------------------------
-- Coordinates and zone
---------------------------------------------------------------------------
ns:RegisterModule("coords", {
label = "COORDS",
icon = "Interface\\Icons\\INV_Misc_Map_01",
interval = 0.25,
defaultEnabled = false,
update = function(cfg)
local mapID = C_Map.GetBestMapForUnit("player")
if not mapID then return nil end
local pos = C_Map.GetPlayerMapPosition(mapID, "player")
if not pos then return nil end
local x, y = pos:GetXY()
if not x or (x == 0 and y == 0) then return nil end
local d = math.max(0, math.min(2, math.floor(tonumber(cfg and cfg.coordDecimals) or 1)))
local f = "%." .. d .. "f"
return (f .. ", " .. f):format(x * 100, y * 100)
end,
options = {
{ kind = "slider", field = "coordDecimals", tab = "text", label = "COORD_DECIMALS", tip = "TIP_COORD_DECIMALS",
min = 0, max = 2, step = 1, default = 1 },
},
tooltip = function(tt)
local mapID = C_Map.GetBestMapForUnit("player")
local info = mapID and C_Map.GetMapInfo(mapID)
if info then tt:AddLine(info.name, 1, 1, 1) end
local sub = GetSubZoneText()
if sub and sub ~= "" then tt:AddDoubleLine(L.TT_SUBZONE, sub, 0.8, 0.8, 0.8, 1, 1, 1) end
end,
secureMacro = "/run ToggleWorldMap()",
clickHint = L.HINT_MAP,
-- "Zone (x, y)" for Shift + click "copy to chat"
chatText = function()
local mapID = C_Map.GetBestMapForUnit("player")
local pos = mapID and C_Map.GetPlayerMapPosition(mapID, "player")
if not pos then return nil end
local x, y = pos:GetXY()
local zone = GetRealZoneText and GetRealZoneText() or GetZoneText()
return ("%s (%.1f, %.1f)"):format(zone or "", x * 100, y * 100)
end,
-- extra click action: place a map pin on the player's position (middle click by default)
extraAction = {
key = "waypoint", label = "ACTION_WAYPOINT",
run = function()
local mapID = C_Map.GetBestMapForUnit("player")
local pos = mapID and C_Map.GetPlayerMapPosition(mapID, "player")
if not (pos and C_Map.SetUserWaypoint and UiMapPoint) then return end
local x, y = pos:GetXY()
C_Map.SetUserWaypoint(UiMapPoint.CreateFromCoordinates(mapID, x, y))
if C_SuperTrack and C_SuperTrack.SetSuperTrackedUserWaypoint then
C_SuperTrack.SetSuperTrackedUserWaypoint(true)
end
end,
},
defaults = { middleClick = "waypoint", coordDecimals = 1 },
})
-- Tooltip shared by the zone and subzone blocks
local function ZoneTooltip(tt)
tt:AddDoubleLine(L.ZONE, GetRealZoneText() or "", 0.8, 0.8, 0.8, 1, 1, 1)
local sub = GetSubZoneText()
if sub and sub ~= "" then tt:AddDoubleLine(L.TT_SUBZONE, sub, 0.8, 0.8, 0.8, 1, 1, 1) end
end
ns:RegisterModule("zone", {
label = "ZONE",
icon = "Interface\\Icons\\Ability_Hunter_Pathfinding",
events = { "ZONE_CHANGED", "ZONE_CHANGED_INDOORS", "ZONE_CHANGED_NEW_AREA" },
defaultEnabled = false,
-- main zone (e.g. Stormwind), without the subzone
update = function()
local text = GetRealZoneText and GetRealZoneText() or GetZoneText()
return text ~= "" and text or nil
end,
tooltip = ZoneTooltip,