Repository navigation
Expand file tree
/
Copy pathBrokerBar.lua
More file actions
1990 lines (1790 loc) · 77.9 KB
/
Copy pathBrokerBar.lua
File metadata and controls
1990 lines (1790 loc) · 77.9 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 AbstractBar = LibStub("AceAddon-3.0"):GetAddon("AbstractBar")
local BrokerBar = AbstractBar:NewModule("BrokerBar", "AceEvent-3.0")
local LDB = LibStub("LibDataBroker-1.1")
local LSM = LibStub("LibSharedMedia-3.0")
-- Masque support removed
-- No framework dependencies needed
-- Make BrokerBar globally accessible for broker files
_G.BrokerBar = BrokerBar
-- Update all bar widgets' fonts when the global font changes
function BrokerBar:UpdateAllFonts()
for barID, bar in pairs(bars) do
self:UpdateBarLayout(barID)
end
end
-- ============================================================================
-- 1. LOCAL VARIABLES & DATA CACHES
-- ============================================================================
local bars = {}
local widgets = {}
-- Masque removed
-- Layout Cache
local layoutCache = {
LEFT = {},
CENTER = {},
RIGHT = {}
}
-- Interactive Frame References
local friendsFrame, guildFrame, volFrame
local scrollChild, gScrollChild
local guildMotD, listSeparator
local friendTitle, friendFooter, guildTitle, guildFooter
local headerRefs, guildHeaderRefs = {}, {}
-- Module Object References
local friendObj, guildObj, diffObj, clockObj, sysObj, goldObj, bagObj, duraObj, locObj, tokenObj, volObj, ilvlObj, crestsObj, statPriorityObj
-- Data Cache
local lastState = {
timeH = -1, timeM = -1, fps = -1, ms = -1,
bagFree = -1, bagTotal = -1, gold = -1, dura = -1,
friends = -1, guild = -1, zone = nil, diffID = -1,
diffPlayers = -1, vol = -1, token = -1, ilvl = -1
}
-- Combat state tracking
local pendingLayoutUpdates = {}
-- Re-entrancy protection for UpdateBarLayout
local inUpdateBarLayout = {}
-- Mappings
local LABEL_MAP_FULL = {
AbstractDiff = "Difficulty", AbstractVolume = "Volume", AbstractDura = "Durability",
AbstractClock = "Clock", AbstractBags = "Bags", AbstractFriends = "Friends",
AbstractGold = "Gold", AbstractGuild = "Guild", AbstractLocation = "Location",
AbstractSystem = "System", AbstractToken = "Token", AbstractILvl = "Item Level",
AbstractTimePlayed = "Abstract Time Played", AbstractCrests = "Crests",
AbstractCatalyst = "Catalyst", AbstractDelves = "Delves", AbstractMPlusTeleports = "M+ Teleports",
AbstractQuickActions = "Quick Actions", AbstractStatPriority = "Abstract Stat Priority"
}
local LABEL_MAP_SHORT = {
AbstractDiff = "Diff", AbstractVolume = "Vol", AbstractDura = "Dura",
AbstractClock = "Time", AbstractBags = "Bags", AbstractFriends = "Frnd",
AbstractGold = "Gold", AbstractGuild = "Gld", AbstractLocation = "Loc",
AbstractSystem = "Sys", AbstractToken = "Tok", AbstractILvl = "iLvL",
AbstractTimePlayed = "Played", AbstractCrests = "Crsts",
AbstractCatalyst = "Cat", AbstractDelves = "Dlv", AbstractMPlusTeleports = "M+ Ports",
AbstractQuickActions = "R E L A", AbstractStatPriority = "Stats"
}
local SHORTEN_REPLACEMENTS = {
["Heroic"] = "H", ["Mythic"] = "M", ["Normal"] = "N", ["Finder"] = "LFR",
["Player"] = "P", ["Timewalking"] = "TW", ["Follower"] = "F", ["Tier"] = "T",
["Story"] = "S", ["Delve"] = "D", ["Keystone"] = "+", ["%("] = "", ["%)"] = "",
}
classTokenLookup = {}
if _G.FillLocalizedClassList then
local temp = {}
FillLocalizedClassList(temp, false)
for token, name in pairs(temp) do
classTokenLookup[name] = token
end
wipe(temp)
FillLocalizedClassList(temp, true)
for token, name in pairs(temp) do
classTokenLookup[name] = token
end
end
-- SKINS DEFINITIONS
local SKINS = {
["Abstract"] = {
backdrop = {
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = nil,
tile = false, tileSize = 0, edgeSize = 0,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
},
borderAlpha = 0
},
["Blizzard"] = {
backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
},
borderAlpha = 1
},
["Glass"] = {
backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = 1, right = 1, top = 1, bottom = 1 }
},
borderAlpha = 0.4
},
["Flat"] = {
backdrop = {
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false, tileSize = 0, edgeSize = 1,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
},
borderAlpha = 1
},
["Transparent"] = {
backdrop = {
bgFile = nil,
edgeFile = nil,
tile = false, tileSize = 0, edgeSize = 0,
insets = { left = 0, right = 0, top = 0, bottom = 0 }
},
borderAlpha = 0
},
["Outline"] = {
backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 }
},
borderAlpha = 1
},
["Tooltip"] = {
backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 16,
insets = { left = 4, right = 4, top = 4, bottom = 4 }
},
borderAlpha = 1
}
}
-- ============================================================================
-- 2. DATABASE DEFAULTS
-- ============================================================================
local defaults = {
profile = {
locked = false,
font = "Friz Quadrata TT",
fontSize = 12,
fontColor = {r = 1, g = 1, b = 1},
useClassColor = false,
useStandardTime = true,
spacing = 15,
goldSortBy = "name",
goldDeleteSelection = nil,
goldData = {},
tokenHistory = {},
brokers = {}, -- Initialize empty brokers table
lastVolume = 1, -- PERSISTENT VOLUME STORAGE
barSkin = "Abstract",
bars = {
["MainBar"] = {
enabled = true,
fullWidth = true,
width = 600,
height = 24,
scale = 1.0,
alpha = 0.6,
useThemeColor = true,
color = {r = 0.1, g = 0.1, b = 0.1},
skin = "Transparent",
padding = 10,
point = "TOP",
x = 0, y = 0,
font = "Expressway",
},
},
}
}
local function ShortenValue(text)
if not text or text == "" then
return ""
end
if tostring(text):find("|TInterface") then
return text
end
local short = tostring(text)
for k, v in pairs(SHORTEN_REPLACEMENTS) do
short = short:gsub(k, v)
end
if strlenutf8(short) > 60 then
short = short:sub(1, 60)
end
return short
end
-- Make helper functions global for broker files
function GetColor()
-- FIX: Ensure DB is loaded if Helper is called early
if not BrokerBar.db then return 1, 1, 1 end
local db = BrokerBar.db.profile
-- Check useClassColor setting first
if db.useClassColor then
local _, class = UnitClass("player")
local color = (CUSTOM_CLASS_COLORS or RAID_CLASS_COLORS)[class]
return color.r, color.g, color.b
end
-- Fallback to custom font color
return db.fontColor.r, db.fontColor.g, db.fontColor.b
end
function FormatTimeDisplay(h, m, standard)
if standard then
local suffix = (h >= 12) and " PM" or " AM"
local hour = h % 12
if hour == 0 then
hour = 12
end
return string.format("%d:%02d%s", hour, m, suffix)
else
return string.format("%02d:%02d", h, m)
end
end
function FormatSeconds(seconds)
if not seconds or seconds <= 0 then
return "Now"
end
local days = math.floor(seconds / 86400)
local hours = math.floor((seconds % 86400) / 3600)
local mins = math.floor((seconds % 3600) / 60)
if days > 0 then
return string.format("%dd %dh %dm", days, hours, mins)
else
return string.format("%dh %dm", hours, mins)
end
end
-- Helper to format numbers with commas (e.g., 1,234,567)
function FormatWithCommas(amount)
local formatted = tostring(amount)
while true do
formatted, k = formatted:gsub("^(%d+)(%d%d%d)", '%1,%2')
if k == 0 then break end
end
return formatted
end
function FormatMoney(amount)
if not amount then
return "0c"
end
local gold = math.floor(amount / 10000)
local silver = math.floor((amount % 10000) / 100)
local copper = amount % 100
local str = ""
if gold > 0 then
str = str .. string.format("%s|TInterface\\MoneyFrame\\UI-GoldIcon:12:12:2:0|t ", FormatWithCommas(gold))
end
if silver > 0 or gold > 0 then
str = str .. string.format("%02d|TInterface\\MoneyFrame\\UI-SilverIcon:12:12:2:0|t ", silver)
end
str = str .. string.format("%02d|TInterface\\MoneyFrame\\UI-CopperIcon:12:12:2:0|t ", copper)
return str
end
function FormatTokenPrice(amount)
if not amount then
return "N/A"
end
local gold = math.floor(amount / 10000)
return string.format("%s|TInterface\\MoneyFrame\\UI-GoldIcon:12:12:2:0|t", FormatWithCommas(gold))
end
function ApplyTooltipStyle(tip)
if not tip then return end
-- Don't style tooltips with embedded content to avoid taint
if tip.ItemTooltip and tip.ItemTooltip:IsShown() then
return
end
-- Hide default Blizzard tooltip borders
if tip.NineSlice then
tip.NineSlice:SetAlpha(0)
end
if tip.TopOverlay then
tip.TopOverlay:SetAlpha(0)
end
if tip.BottomOverlay then
tip.BottomOverlay:SetAlpha(0)
end
-- Apply simple dark backdrop for tooltips
if tip.SetBackdrop then
tip:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8X8",
edgeFile = "Interface\\Buttons\\WHITE8X8",
tile = false,
tileSize = 0,
edgeSize = 2,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
-- Dark tooltip background
tip:SetBackdropColor(0.05, 0.05, 0.05, 0.95)
tip:SetBackdropBorderColor(0, 0, 0, 1)
end
-- Use pcall to safely apply styling without causing taint
local success = pcall(function()
local db = BrokerBar.db.profile
local fontPath, fontSize, fontFlags
-- Use user's Global Font setting
fontPath = LSM:Fetch("font", db.font) or "Fonts\\FRIZQT__.ttf"
fontSize = db.fontSize + 2 -- Slightly larger for tooltip header
fontFlags = "OUTLINE"
local name = tip:GetName()
if not name then return end
if _G[name.."TextLeft1"] then
_G[name.."TextLeft1"]:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
end
if _G[name.."TextRight1"] then
_G[name.."TextRight1"]:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
end
-- Use user's Global Font setting for body text
fontPath = LSM:Fetch("font", db.font) or "Fonts\\FRIZQT__.ttf"
fontSize = db.fontSize
fontFlags = "OUTLINE"
local numLines = tip:NumLines()
if numLines then
for i = 2, numLines do
local l, r = _G[name.."TextLeft"..i], _G[name.."TextRight"..i]
if l then
l:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
end
if r then
r:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
end
end
end
end)
-- Silently fail if styling causes issues (e.g., with embedded item tooltips)
end
function SmartAnchor(tooltip, owner)
tooltip:ClearAllPoints()
local bottom = owner:GetBottom()
local sH = GetScreenHeight()
-- Vertical positioning (above or below based on screen position)
local vP, rP, yO
if bottom and bottom > sH/2 then
vP, rP, yO = "TOP", "BOTTOM", -2
else
vP, rP, yO = "BOTTOM", "TOP", 2
end
-- Horizontal positioning based on broker's section alignment
-- This avoids taint from tooltip:GetWidth() calls
local align = owner.brokerAlign or "CENTER"
if align == "LEFT" then
-- Broker on left side - tooltip expands to the right
tooltip:SetPoint(vP.."LEFT", owner, rP.."LEFT", 0, yO)
elseif align == "RIGHT" then
-- Broker on right side - tooltip expands to the left
tooltip:SetPoint(vP.."RIGHT", owner, rP.."RIGHT", 0, yO)
else
-- Center brokers - tooltip centers on button
tooltip:SetPoint(vP, owner, rP, 0, yO)
end
end
-- HELPER: DIFFICULTY STRING LOGIC
function GetDifficultyLabel()
local _, instanceType, difficultyID, _, _, _, _, _, instanceGroupSize = GetInstanceInfo()
if instanceType == "none" then return "World" end
if instanceType == "pvp" or instanceType == "arena" then return "BG" end
-- Dungeons & Raids
-- Timewalking (24 = Dungeon, 33 = Raid)
if difficultyID == 24 or difficultyID == 33 then return "TW" end
-- Legacy Raids
if difficultyID == 3 then return "N10" end
if difficultyID == 4 then return "N25" end
if difficultyID == 5 then return "H10" end
if difficultyID == 6 then return "H25" end
-- Standard Dungeons
if difficultyID == 1 then return "N" end
if difficultyID == 2 then return "H" end
if difficultyID == 23 then return "M0" end
if difficultyID == 8 then return "M+" end
-- Follower Dungeons (Check ID or Fallback Name)
if difficultyID == 205 then return "F" end
-- Raids
if difficultyID == 7 or difficultyID == 17 then return "LFR" end
if difficultyID == 16 then return "M20" end -- Mythic Raid fixed
-- Flex Raids (Normal 14, Heroic 15)
if difficultyID == 14 then
local num = GetNumGroupMembers()
if num == 0 then num = 1 end
return "N"..num
end
if difficultyID == 15 then
local num = GetNumGroupMembers()
if num == 0 then num = 1 end
return "H"..num
end
-- Fallback for Delves (Check Name)
local diffName = select(4, GetInstanceInfo())
if diffName then
if diffName:find("Delve") then return "D" end
if diffName:find("Follower") then return "F" end
end
return diffName or ""
end
-- ============================================================================
-- 4. INTERACTIVE FRAMES (Friends, Guild, Volume)
-- ============================================================================
-- NOTE: These functions have been moved to individual broker files in Modules/Brokers/
-- The broker files now handle their own frame creation and update logic
-- ============================================================================
-- 5. BROKER OBJECTS (LDB)
-- ============================================================================
function BrokerBar:InitializeBrokers()
-- Brokers are now loaded from separate files in Modules/Brokers/
-- Get references to the data objects created by those files
friendObj = LDB:GetDataObjectByName("AbstractFriends")
guildObj = LDB:GetDataObjectByName("AbstractGuild")
goldObj = LDB:GetDataObjectByName("AbstractGold")
sysObj = LDB:GetDataObjectByName("AbstractSystem")
bagObj = LDB:GetDataObjectByName("AbstractBags")
tokenObj = LDB:GetDataObjectByName("AbstractToken")
volObj = LDB:GetDataObjectByName("AbstractVolume")
duraObj = LDB:GetDataObjectByName("AbstractDura")
locObj = LDB:GetDataObjectByName("AbstractLocation")
diffObj = LDB:GetDataObjectByName("AbstractDiff")
ilvlObj = LDB:GetDataObjectByName("AbstractILvl")
clockObj = LDB:GetDataObjectByName("AbstractClock")
crestsObj = LDB:GetDataObjectByName("AbstractCrests")
statPriorityObj = LDB:GetDataObjectByName("AbstractStatPriority")
end
-- ============================================================================
-- 6. UPDATE ENGINE
-- ============================================================================
function BrokerBar:UpdateAllModules()
-- CLOCK
local h, m = tonumber(date("%H")), tonumber(date("%M"))
if h ~= lastState.timeH or m ~= lastState.timeM then
lastState.timeH, lastState.timeM = h, m
clockObj.text = FormatTimeDisplay(h, m, self.db.profile.useStandardTime)
end
-- SYSTEM (FPS/MS) - Color Logic for Bar Text
-- Add tolerance to prevent updates on minor fluctuations (reduces string allocations)
local _, _, _, world = GetNetStats()
local fps = math.floor(GetFramerate())
local fpsChanged = not lastState.fps or math.abs(fps - lastState.fps) >= 2
local msChanged = not lastState.ms or math.abs(world - lastState.ms) >= 5
if fpsChanged or msChanged then
lastState.fps, lastState.ms = fps, world
-- Custom FPS Colors: Red < 20, Orange < 40, Yellow < 60, Green >= 60
local color = "ff33ff33" -- Green (Default)
if fps < 20 then color = "ffde1818" -- Red
elseif fps < 40 then color = "ffff7d0a" -- Orange
elseif fps < 60 then color = "ffffd200" -- Yellow
end
-- Custom MS Colors: Green < 100, Yellow < 200, Red >= 200
local msColor = "ff33ff33" -- Green (Default)
if world >= 200 then msColor = "ffde1818" -- Red
elseif world >= 100 then msColor = "ffffd200" -- Yellow
end
sysObj.text = string.format("FPS: |c%s%d|r MS: |c%s%d|r", color, fps, msColor, world)
end
-- Note: Bags count moved to UpdateBagCount() called by BAG_UPDATE event
-- Note: Gold display moved to UpdateGoldDisplay() called by PLAYER_MONEY event
-- Note: Token price moved to UpdateTokenDisplay() called by TOKEN_MARKET_PRICE_UPDATED event
-- Note: Counts (Guild, Friends, Durability) moved to event-driven update functions
-- Note: Location moved to UpdateLocation() called by ZONE_CHANGED event
-- DIFFICULTY & FLEX
local diff = GetDifficultyLabel()
local num = GetNumGroupMembers()
if diff ~= lastState.diffID or num ~= lastState.diffPlayers then
lastState.diffID = diff
lastState.diffPlayers = num
diffObj.text = diff
end
-- ITEM LEVEL
local avgIlvl, equippedIlvl = GetAverageItemLevel()
equippedIlvl = math.floor(equippedIlvl or 0)
if equippedIlvl ~= lastState.ilvl then
lastState.ilvl = equippedIlvl
ilvlObj.text = tostring(equippedIlvl)
end
-- VOLUME - FIXED: Always Whole Number Formatting
local v = math.floor((tonumber(GetCVar("Sound_MasterVolume")) or 0) * 100)
if v ~= lastState.vol then
lastState.vol = v
volObj.text = string.format("%d%%", v) -- Force integer display
end
end
-- Event-driven update functions to avoid expensive polling
function BrokerBar:UpdateFriendsCount()
if not friendObj then return end
-- Count only online WoW Retail friends
local wowOnline = 0
local numBNet = BNGetNumFriends() or 0
for i = 1, numBNet do
local info = C_BattleNet.GetFriendAccountInfo(i)
if info and info.gameAccountInfo and info.gameAccountInfo.isOnline then
local g = info.gameAccountInfo
if (g.clientProgram == BNET_CLIENT_WOW) and (g.wowProjectID == 1) then
wowOnline = wowOnline + 1
end
end
end
-- Always update if not initialized, or if value changed
if not lastState.friends or wowOnline ~= lastState.friends then
lastState.friends = wowOnline
friendObj.text = tostring(wowOnline)
end
end
function BrokerBar:UpdateDurability()
if not duraObj then return end
local low = 100
for i = 1, 18 do
local c, m = GetInventoryItemDurability(i)
if c and m then
local p = (c/m)*100
if p < low then low = p end
end
end
low = math.floor(low)
-- Always update if not initialized, or if value changed
if not lastState.dura or low ~= lastState.dura then
lastState.dura = low
duraObj.text = low.."%"
end
end
function BrokerBar:UpdateGuildCount()
if not guildObj then return end
local _, online = GetNumGuildMembers()
-- Always update if not initialized, or if value changed
if not lastState.guild or online ~= lastState.guild then
lastState.guild = online
guildObj.text = tostring(online or 0)
end
end
function BrokerBar:UpdateBagCount()
if not bagObj then return end
local free, total = 0, 0
for i = 0, 5 do
local s = C_Container.GetContainerNumSlots(i)
if s > 0 then
free = free + C_Container.GetContainerNumFreeSlots(i)
total = total + s
end
end
-- Always update if not initialized, or if values changed
if not lastState.bagFree or free ~= lastState.bagFree or total ~= lastState.bagTotal then
lastState.bagFree, lastState.bagTotal = free, total
bagObj.text = (total-free).."/"..total
end
end
function BrokerBar:UpdateLocation()
if not locObj then return end
local config = self:GetSafeConfig("AbstractLocation")
local z = GetZoneText() or "Unknown"
local sz = GetSubZoneText() or ""
-- Build the text based on config
local text = z
if config.showSubZone and sz ~= "" and sz ~= z then
text = z .. ": " .. sz
end
-- Always update if lastState.zone is not set (initialization), or if zone/subzone changed
if not lastState.zone or text ~= lastState.zone then
lastState.zone = text
locObj.text = text
end
end
-- ============================================================================
-- 7. FRAME & LAYOUT LOGIC
-- ============================================================================
local function SortByOrder(a, b)
local db = BrokerBar.db.profile.brokers
if not db then return false end
return (db[a] and db[a].order or 0) < (db[b] and db[b].order or 0)
end
function BrokerBar:GetSafeConfig(name)
-- Ensure brokers table exists
if not self.db.profile.brokers then
self.db.profile.brokers = {}
end
if not self.db.profile.brokers[name] then
-- Default enabled brokers (only these are shown by default)
local defaultEnabledBrokers = {
["AbstractVolume"] = true,
["AbstractLocation"] = true,
["AbstractGold"] = true,
["AbstractDiff"] = true,
["AbstractSystem"] = true,
["AbstractClock"] = true,
}
-- Default alignments for each broker
local defaultAlignments = {
["AbstractVolume"] = "RIGHT",
["AbstractLocation"] = "RIGHT",
["AbstractDiff"] = "RIGHT",
["AbstractSystem"] = "LEFT",
["AbstractGold"] = "LEFT",
["AbstractClock"] = "CENTER",
}
-- Default order values for positioning (lower = leftmost in their alignment group)
local defaultOrders = {
["AbstractSystem"] = 10, -- LEFT side, first
["AbstractGold"] = 20, -- LEFT side, second
["AbstractClock"] = 30, -- CENTER
["AbstractDiff"] = 60, -- RIGHT side, first (leftmost)
["AbstractLocation"] = 50, -- RIGHT side, second
["AbstractVolume"] = 40, -- RIGHT side, third (rightmost)
}
-- Check if this broker should be enabled by default
local defaultBar = defaultEnabledBrokers[name] and "MainBar" or "None"
local defaultAlign = defaultAlignments[name] or "CENTER"
local defaultOrder = defaultOrders[name] or 100
-- Special case: Location should show coordinates by default
local defaultShowCoords = (name == "AbstractLocation")
local defaultShowSubZone = (name == "AbstractLocation") and false or nil
-- Special case: Volume should default to 5% step size
local defaultVolumeStep = (name == "AbstractVolume") and 0.05 or nil
self.db.profile.brokers[name] = {
bar = defaultBar,
align = defaultAlign,
order = defaultOrder,
showIcon = true,
showText = true,
showLabel = false,
showCoords = defaultShowCoords,
showSubZone = defaultShowSubZone,
volumeStep = defaultVolumeStep
}
end
return self.db.profile.brokers[name]
end
function BrokerBar:UpdateBarLayout(barID)
local bar = bars[barID]
local db = self.db.profile.bars[barID]
if not bar or not db then return end
-- If in combat, defer layout update to avoid taint
if InCombatLockdown() then
pendingLayoutUpdates[barID] = true
return
end
-- Ensure bar has proper size before positioning widgets
local barWidth, barHeight = bar:GetSize()
if barWidth == 0 or barHeight == 0 then
-- Bar hasn't been sized yet, apply settings first
self:ApplyBarSettings(barID)
return -- ApplyBarSettings will call UpdateBarLayout again
end
-- Prevent re-entrant calls that can cause duplicates in layoutCache
-- IMPORTANT: Must be AFTER early returns to avoid permanently locking the update
if inUpdateBarLayout[barID] then return end
inUpdateBarLayout[barID] = true
wipe(layoutCache.LEFT)
wipe(layoutCache.CENTER)
wipe(layoutCache.RIGHT)
local brokersForThisBar = {}
for name, w in pairs(widgets) do
local config = self:GetSafeConfig(name)
if config and config.bar == barID then
table.insert(layoutCache[config.align or "CENTER"], name)
table.insert(brokersForThisBar, name)
w:Show()
elseif config and config.bar == "None" then
-- Only hide widgets explicitly set to "None", don't hide widgets assigned to other bars
w:Hide()
end
end
-- Use user's Global Font setting
local fontPath = LSM:Fetch("font", self.db.profile.font) or "Fonts\\FRIZQT__.ttf"
local fontSize = self.db.profile.fontSize
local fontFlags = "OUTLINE"
local r, g, b = GetColor()
for align, list in pairs(layoutCache) do
table.sort(list, SortByOrder)
local lastWidget = nil
local first = true
local totalW = 0
-- Center Calculation
if align == "CENTER" then
for _, name in ipairs(list) do
local w = widgets[name]
local obj = LDB:GetDataObjectByName(name)
-- Special width for Actions broker
if name == "AbstractQuickActions" then
totalW = totalW + 86 + self.db.profile.spacing
else
-- FIXED TEXT CONSTRUCTION FOR WIDTH CALC
local bCfg = self:GetSafeConfig(name)
local map = bCfg.useShortLabel and LABEL_MAP_SHORT or LABEL_MAP_FULL
local labelPart = bCfg.showLabel and (map[name] or obj.label or name) or ""
local rawText = tostring(obj.text or "")
local textValue = rawText
if name ~= "AbstractLocation" and name ~= "AbstractCrests" and name ~= "AbstractDelves" then
textValue = ShortenValue(rawText)
end
if name == "AbstractLocation" and bCfg.showCoords then
textValue = textValue .. " (00, 00)" -- Placeholder for sizing
end
local displayString = (labelPart ~= "" and labelPart .. ": " or "") .. (bCfg.showText and textValue or "")
w.text:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
w.text:SetText(displayString)
local iconSize = (db.height or 24) * 0.85
totalW = totalW + w.text:GetStringWidth() + (bCfg.showIcon and (iconSize + 4) or 4) + self.db.profile.spacing
end
end
totalW = totalW - self.db.profile.spacing
end
for _, name in ipairs(list) do
local w, obj, bCfg = widgets[name], LDB:GetDataObjectByName(name), self:GetSafeConfig(name)
w:SetParent(bar)
w:SetFrameLevel(bar:GetFrameLevel() + 1) -- Ensure widgets are above the bar's background
w:ClearAllPoints()
-- Special handling for Actions broker
if name == "AbstractQuickActions" then
w:SetSize(86, db.height)
-- Update button fonts to match theme
for _, ab in ipairs(w.actionButtons or {}) do
ab:SetHeight(db.height - 4)
ab.text:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
ab.text:SetTextColor(r, g, b)
end
-- Position the widget
w.brokerAlign = align
if align == "LEFT" then
w:SetPoint("LEFT", lastWidget or bar, lastWidget and "RIGHT" or "LEFT", lastWidget and self.db.profile.spacing or 10, 0)
elseif align == "RIGHT" then
w:SetPoint("RIGHT", lastWidget or bar, lastWidget and "LEFT" or "RIGHT", lastWidget and -self.db.profile.spacing or -10, 0)
else
if first then
w:SetPoint("LEFT", bar, "CENTER", -(totalW/2), 0)
else
w:SetPoint("LEFT", lastWidget, "RIGHT", self.db.profile.spacing, 0)
end
end
lastWidget = w
first = false
else
-- Normal broker handling
w.text:SetTextColor(r,g,b)
local rawText = tostring(obj.text or "")
local map = bCfg.useShortLabel and LABEL_MAP_SHORT or LABEL_MAP_FULL
local labelPart = bCfg.showLabel and (map[name] or obj.label or name) or ""
local textValue = rawText
-- LOCATION LOGIC (DECIMALS & TRUNCATION BYPASS)
if name == "AbstractLocation" then
if bCfg.showCoords then
local m = C_Map.GetBestMapForUnit("player")
if m then
local p = C_Map.GetPlayerMapPosition(m, "player")
if p then
local decimals = bCfg.coordDecimals or 0
if decimals == 0 then
textValue = textValue .. string.format(" (%d, %d)", p.x*100, p.y*100)
elseif decimals == 1 then
textValue = textValue .. string.format(" (%.1f, %.1f)", p.x*100, p.y*100)
else -- 2 decimals
textValue = textValue .. string.format(" (%.2f, %.2f)", p.x*100, p.y*100)
end
end
end
end
-- No ShortenValue() call for location, showing full zone name
else
-- Skip ShortenValue for Crests and Delves to preserve formatting
if name ~= "AbstractCrests" and name ~= "AbstractDelves" then
textValue = ShortenValue(rawText)
end
end
local displayString = (labelPart ~= "" and labelPart .. ": " or "") .. (bCfg.showText and textValue or "")
w.text:SetText(displayString)
-- FORCE GLOBAL FONT FOR ALL WIDGETS
w.text:SetFont(fontPath, fontSize, fontFlags or "OUTLINE")
local iconSize = (db.height or 24) * 0.85
if bCfg.showIcon and obj.icon then
w.icon:SetTexture(obj.icon)
w.icon:SetSize(iconSize, iconSize)
w.icon:Show()
w.icon:SetPoint("LEFT", w, "LEFT", 2, 0)
w.text:SetPoint("LEFT", w.icon, "RIGHT", 4, 0)
else
w.icon:Hide()
w.text:SetPoint("LEFT", w, "LEFT", 2, 0)
end
local contentWidth = w.text:GetStringWidth() + (bCfg.showIcon and (iconSize + 4) or 4)
w:SetSize(contentWidth, db.height)
-- Store alignment on button for SmartAnchor to use
w.brokerAlign = align
if align == "LEFT" then
w:SetPoint("LEFT", lastWidget or bar, lastWidget and "RIGHT" or "LEFT", lastWidget and self.db.profile.spacing or 10, 0)
elseif align == "RIGHT" then
w:SetPoint("RIGHT", lastWidget or bar, lastWidget and "LEFT" or "RIGHT", lastWidget and -self.db.profile.spacing or -10, 0)
else
if first then
w:SetPoint("LEFT", bar, "CENTER", -(totalW/2), 0)
else
w:SetPoint("LEFT", lastWidget, "RIGHT", self.db.profile.spacing, 0)
end
end
lastWidget = w
first = false
end
end
end
-- Clear re-entrancy flag
inUpdateBarLayout[barID] = nil
end
function BrokerBar:CreateBarFrame(id)
local f = CreateFrame("Frame", "AbstractBar_"..id, UIParent, "BackdropTemplate")
f:SetMovable(true)
f:SetClampedToScreen(true)
f.bg = f:CreateTexture(nil, "BACKGROUND")
f.bg:SetAllPoints()
-- Simple drag functionality
f:EnableMouse(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", function(self)
if not BrokerBar.db.profile.locked then
self:StartMoving()
end
end)
f:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
local point, _, _, x, y = self:GetPoint()
local db = BrokerBar.db.profile.bars[id]
if db then
db.point = point or "CENTER"
db.x = x or 0
db.y = y or 0
end
end)
-- Right-click to open options
f:SetScript("OnMouseUp", function(self, button)
if button == "RightButton" then
local AbstractBar = LibStub("AceAddon-3.0"):GetAddon("AbstractBar")
if AbstractBar and AbstractBar.OpenConfig then
AbstractBar:OpenConfig()
end
end
end)
bars[id] = f
end
function BrokerBar:ApplyBarSettings(barID)
local f, db = bars[barID], self.db.profile.bars[barID]
if not f or not db then return end
local skin = SKINS[db.skin == "Global" and self.db.profile.barSkin or db.skin] or SKINS["Abstract"]
f:SetScale(db.scale or 1.0)
f:ClearAllPoints()
if db.fullWidth then
f:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 0, db.y or 0)
f:SetPoint("TOPRIGHT", UIParent, "TOPRIGHT", 0, db.y or 0)
else
f:SetSize(db.width or 400, db.height or 24)
f:SetPoint(db.point or "CENTER", UIParent, db.point or "CENTER", db.x or 0, db.y or 0)
end
f:SetHeight(db.height or 24)
f.bg:SetTexture(LSM:Fetch("statusbar", db.texture or "Flat"))
-- Use default dark color if useThemeColor is enabled, otherwise use saved color
local r, g, b, alpha
if db.useThemeColor then
-- Default dark theme color
r, g, b, alpha = 0.1, 0.1, 0.1, 0.8
else
-- Get color from db or use defaults
if type(db.color) == "table" and (db.color.r or db.color[1]) then
r = tonumber(db.color.r or db.color[1])
g = tonumber(db.color.g or db.color[2])
b = tonumber(db.color.b or db.color[3])
else
r, g, b = nil, nil, nil
end
alpha = db.alpha or 0.6
end
-- Final validation: ensure all values are valid numbers
r = tonumber(r) or 0.1
g = tonumber(g) or 0.1