-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathbmHotbarClass.lua
More file actions
1136 lines (987 loc) · 48.4 KB
/
bmHotbarClass.lua
File metadata and controls
1136 lines (987 loc) · 48.4 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 mq = require('mq')
local Set = require('mq.Set')
local btnUtils = require('lib.buttonUtils')
local BMButtonHandlers = require('bmButtonHandlers')
local themes = require('extras.themes')
local WINDOW_SETTINGS_ICON_SIZE = 22
local editTabPopup = "edit_tab_popup"
---@class BMHotbarClass
local BMHotbarClass = {}
BMHotbarClass.__index = BMHotbarClass
BMHotbarClass.id = 1
BMHotbarClass.openGUI = true
BMHotbarClass.shouldDrawGUI = true
BMHotbarClass.setupComplete = false
BMHotbarClass.lastWindowX = 0
BMHotbarClass.lastWindowY = 0
BMHotbarClass.lastButtonPageHeight = 0
BMHotbarClass.lastButtonPageWidth = 0
BMHotbarClass.lastWindowHeight = 0
BMHotbarClass.lastWindowWidth = 0
BMHotbarClass.buttonSizeDirty = false
BMHotbarClass.visibleButtonCount = 0
BMHotbarClass.cachedCols = 0
BMHotbarClass.cachedRows = 0
BMHotbarClass.highestRenderTime = 0
BMHotbarClass.importObjectPopupOpen = false
BMHotbarClass.validDecode = false
BMHotbarClass.importText = ""
BMHotbarClass.decodedObject = {}
BMHotbarClass.newSetName = ""
BMHotbarClass.currentSelectedSet = 0
BMHotbarClass.lastFrameTime = 0
BMHotbarClass.importTextChanged = false
BMHotbarClass.updateWindowPosSize = false
BMHotbarClass.newWidth = 0
BMHotbarClass.newHeight = 0
BMHotbarClass.newX = 0
BMHotbarClass.newY = 0
BMHotbarClass.searchText = ""
BMHotbarClass.currentDnDData = nil
BMHotbarClass.alphaMenu = {
{ name = "A-D", filter = function(i) return i >= "A" and i <= "D" end, items = {}, },
{ name = "E-H", filter = function(i) return i >= "E" and i <= "H" end, items = {}, },
{ name = "I-L", filter = function(i) return i >= "I" and i <= "L" end, items = {}, },
{ name = "M-P", filter = function(i) return i >= "M" and i <= "P" end, items = {}, },
{ name = "Q-T", filter = function(i) return i >= "Q" and i <= "T" end, items = {}, },
{ name = "U-X", filter = function(i) return i >= "U" and i <= "X" end, items = {}, },
{ name = "Y-Z", filter = function(i) return i >= "Y" and i <= "Z" end, items = {}, },
{ name = "0-9", filter = function(i) return i >= "0" and i <= "9" end, items = {}, },
{ name = "Other", filter = function(i) return true end, items = {}, }, }
function BMHotbarClass.new(id, createFresh)
local newBMHotbar = setmetatable({ id = id, }, BMHotbarClass)
if createFresh then
BMSettings:GetCharConfig().Windows[id] = {
Visible = true,
Sets = {},
Locked = false,
HideTitleBar = false,
CompactMode = false,
AdvTooltips = true,
ShowSearch = false,
PerCharacterPositioning = false,
}
-- if this character doesn't have the sections in the config, create them
newBMHotbar.updateWindowPosSize = true
newBMHotbar.newWidth = 1000
newBMHotbar.newHeight = 150
newBMHotbar.newX = 500
newBMHotbar.newY = 500
BMSettings:SaveSettings(true)
end
BMSettings:GetCharConfig().Windows[id].Sets = BMSettings:GetCharConfig().Windows[id].Sets or {}
return newBMHotbar
end
function BMHotbarClass:SetVisible(bVisible)
BMSettings:GetCharacterWindow(self.id).Visible = bVisible
self.openGUI = bVisible
BMSettings:SaveSettings(true)
end
function BMHotbarClass:ToggleVisible()
BMSettings:GetCharacterWindow(self.id).Visible = not BMSettings:GetCharacterWindow(self.id).Visible
self.openGUI = BMSettings:GetCharacterWindow(self.id).Visible
BMSettings:SaveSettings(true)
end
function BMHotbarClass:IsVisible()
return BMSettings:GetCharacterWindow(self.id).Visible
end
function BMHotbarClass:PerCharacterPositioning()
return BMSettings:GetCharacterWindow(self.id).PerCharacterPositioning
end
---@return integer, integer
function BMHotbarClass:StartTheme()
local theme = BMSettings:GetSettings().Themes and BMSettings:GetSettings().Themes[self.id] or nil
if not theme then
theme = BMSettings.Globals.CustomThemes and
BMSettings.Globals.CustomThemes[BMSettings:GetCharacterWindow(self.id).Theme] or nil
end
if not theme then
theme = themes[BMSettings:GetCharacterWindow(self.id).Theme or ""] or nil
end
local themeColorPop = 0
local themeStylePop = 0
if theme ~= nil then
for n, t in pairs(theme) do
if t.color then
ImGui.PushStyleColor(ImGuiCol[t.element], t.color.r, t.color.g, t.color.b, t.color.a)
themeColorPop = themeColorPop + 1
elseif t.stylevar then
ImGui.PushStyleVar(ImGuiStyleVar[t.stylevar], t.value)
themeStylePop = themeStylePop + 1
else
if type(t) == 'table' then
if t['Dynamic_Color'] then
local ret, colors = btnUtils.EvaluateLua(t['Dynamic_Color'])
if ret then
---@diagnostic disable-next-line: param-type-mismatch
ImGui.PushStyleColor(ImGuiCol[n], colors)
themeColorPop = themeColorPop + 1
end
elseif t['Dynamic_Var'] then
local ret, var = btnUtils.EvaluateLua(t['Dynamic_Var'])
if ret then
if type(var) == 'table' then
---@diagnostic disable-next-line: param-type-mismatch, deprecated
ImGui.PushStyleVar(ImGuiStyleVar[n], unpack(var))
else
---@diagnostic disable-next-line: param-type-mismatch
ImGui.PushStyleVar(ImGuiStyleVar[n], var)
end
themeStylePop = themeStylePop + 1
end
elseif #t == 4 then
local colors = btnUtils.shallowcopy(t)
for i = 1, 4 do
if type(colors[i]) == 'string' then
local ret, color = btnUtils.EvaluateLua(colors[i])
if ret then
colors[i] = color
end
end
end
---@diagnostic disable-next-line: param-type-mismatch, deprecated
ImGui.PushStyleColor(ImGuiCol[n], unpack(colors))
themeColorPop = themeColorPop + 1
else
---@diagnostic disable-next-line: param-type-mismatch, deprecated
ImGui.PushStyleVar(ImGuiStyleVar[n], unpack(t))
themeStylePop = themeStylePop + 1
end
end
end
end
end
return themeColorPop, themeStylePop
end
---@param themeColorPop integer
---@param themeStylePop integer
function BMHotbarClass:EndTheme(themeColorPop, themeStylePop)
if themeColorPop > 0 then
ImGui.PopStyleColor(themeColorPop)
end
if themeStylePop > 0 then
ImGui.PopStyleVar(themeStylePop)
end
end
function BMHotbarClass:RenderHotbar(flags)
if not self:IsVisible() then return end
if self.updateWindowPosSize then
btnUtils.Debug("Setting new(%d: %s) pos: %d, %d and size: %d, %d", self.id, tostring(self), self.newX, self.newY,
self.newWidth, self.newHeight)
self.updateWindowPosSize = false
ImGui.SetNextWindowSize(self.newWidth, self.newHeight)
ImGui.SetNextWindowPos(self.newX, self.newY)
self.lastButtonPageHeight = self.newHeight
self.lastButtonPageWidth = self.newWidth
self.lastWindowX = self.newX
self.lastWindowY = self.newY
end
local colorPop, stylePop = self:StartTheme()
local renderName = string.format('Button Master - %d', self.id)
if self:PerCharacterPositioning() then
renderName = renderName .. "##" .. mq.TLO.EverQuest.Server() .. "_" .. mq.TLO.Me.Name()
end
ImGui.PushID("##MainWindow_" .. tostring(self.id))
self.openGUI, self.shouldDrawGUI = ImGui.Begin(renderName, self.openGUI,
bit32.bor(flags))
if not ImGui.IsMouseDown(ImGuiMouseButton.Left) then
self.lastWindowX, self.lastWindowY = ImGui.GetWindowPos()
self.lastWindowHeight = ImGui.GetWindowHeight()
self.lastWindowWidth = ImGui.GetWindowWidth()
end
if self.openGUI and self.shouldDrawGUI then
local startTimeMS = os.clock() * 1000
local cursorScreenPos = ImGui.GetCursorScreenPosVec()
self:RenderTabs()
self:RenderImportButtonPopup()
local endTimeMS = os.clock() * 1000
local renderTimeMS = math.ceil(endTimeMS - startTimeMS)
if btnUtils.enableDebug then
if renderTimeMS > self.highestRenderTime then self.highestRenderTime = renderTimeMS end
ImGui.SetWindowFontScale(0.8)
self:RenderDebugText(cursorScreenPos, tostring(self.highestRenderTime))
ImGui.SetWindowFontScale(1)
end
end
ImGui.End()
ImGui.PopID()
self:EndTheme(colorPop, stylePop)
if self.openGUI ~= self:IsVisible() then
self:SetVisible(self.openGUI)
self.openGUI = true
if not self:IsVisible() then
btnUtils.Output("Hotbar %d hidden! Use `/btn %d` to bring it back.", self.id, self.id)
end
end
self.setupComplete = true
end
function BMHotbarClass:RenderTabs()
local lockedIcon = BMSettings:GetCharacterWindow(self.id).Locked and Icons.FA_LOCK .. '##lockTabButton' or
Icons.FA_UNLOCK .. '##lockTablButton'
if BMSettings:GetCharacterWindow(self.id).CompactMode then
local start_x, start_y = ImGui.GetCursorPos()
local iconPadding = 2
local settingsIconSize = math.ceil(((BMSettings:GetCharacterWindow(self.id).ButtonSize or 6) * 10) / 2) -
iconPadding
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, 0, iconPadding)
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, 0, 0)
if ImGui.Button(lockedIcon, settingsIconSize, settingsIconSize) then
--ImGuiWindowFlags.NoMove
BMSettings:GetCharacterWindow(self.id).Locked = not BMSettings:GetCharacterWindow(self.id).Locked
BMSettings:SaveSettings(true)
end
ImGui.SetCursorPosY(ImGui.GetCursorPosY() + (iconPadding))
ImGui.Button(Icons.MD_SETTINGS, settingsIconSize, settingsIconSize)
ImGui.PopStyleVar(2)
ImGui.SameLine()
self:RenderTabContextMenu()
self:RenderCreateTab()
self.currentSelectedSet = 1
local style = ImGui.GetStyle()
ImGui.SetCursorPos(ImVec2(start_x + settingsIconSize + (style.ItemSpacing.x), start_y))
ImGui.PushStyleVar(ImGuiStyleVar.WindowPadding, 0, 0)
ImGui.PushStyleVar(ImGuiStyleVar.FramePadding, 0, 0)
ImGui.BeginChild("##buttons_child", nil, nil, bit32.bor(ImGuiChildFlags.AlwaysAutoResize, ImGuiChildFlags.AutoResizeY))
if BMSettings:GetCharacterWindowSets(self.id)[1] ~= nil then
self:RenderButtons(BMSettings:GetCharacterWindowSets(self.id)[1], "")
end
ImGui.EndChild()
ImGui.PopStyleVar(2)
else
if ImGui.Button(lockedIcon, WINDOW_SETTINGS_ICON_SIZE, WINDOW_SETTINGS_ICON_SIZE) then
--ImGuiWindowFlags.NoMove
BMSettings:GetCharacterWindow(self.id).Locked = not BMSettings:GetCharacterWindow(self.id).Locked
BMSettings:SaveSettings(true)
end
ImGui.SameLine()
ImGui.Button(Icons.MD_SETTINGS, WINDOW_SETTINGS_ICON_SIZE, WINDOW_SETTINGS_ICON_SIZE)
ImGui.SameLine()
self:RenderTabContextMenu()
self:RenderCreateTab()
if ImGui.BeginTabBar("Tabs", ImGuiTabBarFlags.Reorderable) then
if (#BMSettings:GetCharacterWindowSets(self.id) or 0) > 0 then
for i, set in ipairs(BMSettings:GetCharacterWindowSets(self.id)) do
if ImGui.BeginTabItem(set) then
SetLabel = set
self.currentSelectedSet = i
-- tab edit popup
if ImGui.BeginPopupContextItem(set) then
ImGui.Text("Edit Name:")
local tmp, changed = ImGui.InputText("##edit", set, 0)
if changed or self.newSetName:len() == 0 then self.newSetName = tmp end
if ImGui.Button("Save") then
BMEditPopup:CloseEditPopup()
local newSetLabel = self.newSetName
if self.newSetName ~= nil then
BMSettings:GetCharacterWindowSets(self.id)[i] = self.newSetName
-- move the old button set to the new name
BMSettings:GetSettings().Sets[newSetLabel], BMSettings:GetSettings().Sets[SetLabel] =
BMSettings:GetSettings().Sets[SetLabel], nil
-- update the character button set name
for curCharKey, curCharData in pairs(BMSettings:GetSettings().Characters) do
for windowIdx, windowData in ipairs(curCharData.Windows or {}) do
for setIdx, oldSetName in ipairs(windowData.Sets or {}) do
if oldSetName == set then
btnUtils.Output(string.format(
"\awUpdating section '\ag%s\aw' renaming \am%s\aw => \at%s",
curCharKey,
oldSetName, self.newSetName))
BMSettings:GetSettings().Characters[curCharKey].Windows[windowIdx].Sets[setIdx] =
self.newSetName
end
end
end
end
-- update set to the new name so the button render doesn't fail
SetLabel = newSetLabel
BMSettings:SaveSettings(true)
end
ImGui.CloseCurrentPopup()
end
ImGui.EndPopup()
end
if BMSettings:GetCharacterWindow(self.id).ShowSearch then
ImGui.Text("Search")
ImGui.SameLine()
self.searchText = ImGui.InputText("##SearchText", self.searchText, ImGuiInputTextFlags.None)
else
self.searchText = ""
end
self:RenderButtons(SetLabel, self.searchText)
ImGui.EndTabItem()
end
end
end
else
ImGui.Text(string.format("No Sets Added! Add one by right-clicking on %s", Icons.MD_SETTINGS))
end
ImGui.EndTabBar()
end
end
---@param cursorScreenPos ImVec2 # cursor position on screen
---@param text string
function BMHotbarClass:RenderDebugText(cursorScreenPos, text)
local buttonLabelCol = IM_COL32(255, 0, 0, 255)
local draw_list = ImGui.GetWindowDrawList()
draw_list:AddText(ImVec2(cursorScreenPos.x, cursorScreenPos.y), buttonLabelCol, text)
end
function BMHotbarClass:RenderTabContextMenu()
local openPopup = false
local unassigned = {}
local charLoadedSets = {}
for _, v in ipairs(BMSettings:GetCharacterWindowSets(self.id) or {}) do
charLoadedSets[v] = true
end
for k, _ in pairs(BMSettings:GetSettings().Sets) do
if charLoadedSets[k] == nil then
unassigned[k] = true
end
end
if ImGui.BeginPopupContextItem() then
if btnUtils.getTableSize(unassigned) > 0 then
if ImGui.BeginMenu("Add Set") then
for k, _ in pairs(unassigned) do
if ImGui.MenuItem(k) then
table.insert(BMSettings:GetCharacterWindowSets(self.id), k)
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
end
if ImGui.BeginMenu("Remove Set") then
for i, v in ipairs(BMSettings:GetCharacterWindowSets(self.id)) do
if ImGui.MenuItem(v) then
table.remove(BMSettings:GetCharConfig().Windows[self.id].Sets, i)
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
if ImGui.BeginMenu("Delete Set") then
for k, _ in pairs(BMSettings:GetSettings().Sets) do
if ImGui.MenuItem(k) then
-- clean up any references to this set.
for charConfigKey, charConfigValue in pairs(BMSettings:GetSettings().Characters or {}) do
for windowKey, windowData in ipairs(charConfigValue.Windows or {}) do
for setKey, setName in pairs(windowData.Sets or {}) do
if setName == k then
BMSettings:GetSettings().Characters[charConfigKey].Windows[windowKey].Sets[setKey] = nil
end
end
end
end
BMSettings:GetSettings().Sets[k] = nil
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
if ImGui.BeginMenu("Delete Hotkey") then
local sortedKeys = {}
for k, v in pairs(BMSettings:GetSettings().Buttons) do
table.insert(sortedKeys,
{ Label = BMButtonHandlers.ResolveButtonLabel(v, true), id = k, })
end
table.sort(sortedKeys, function(a, b) return a.Label < b.Label end)
local sortedAlphaMenu = {}
for idx, buttonData in ipairs(sortedKeys) do
for _, menuGroup in ipairs(self.alphaMenu) do
sortedAlphaMenu[menuGroup.name] = sortedAlphaMenu[menuGroup.name] or {}
if menuGroup.filter(buttonData.Label:sub(1, 1):upper()) then
table.insert(sortedAlphaMenu[menuGroup.name], { idx = idx, buttonData = buttonData, })
break
end
end
end
for _, menuGroup in pairs(self.alphaMenu) do
local items = sortedAlphaMenu[menuGroup.name] or {}
if #items > 0 then
if ImGui.BeginMenu(menuGroup.name) then
for _, item in ipairs(items) do
if ImGui.MenuItem(item.buttonData.Label .. "##delete_menu_" .. tostring(item.idx)) then
-- clean up any references to this Button.
for setNameKey, setButtons in pairs(BMSettings:GetSettings().Sets) do
for buttonKey, buttonName in pairs(setButtons) do
if buttonName == item.buttonData.id then
BMSettings:GetSettings().Sets[setNameKey][buttonKey] = nil
end
end
end
BMSettings:GetSettings().Buttons[item.buttonData.id] = nil
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
end
end
ImGui.EndMenu()
end
if ImGui.MenuItem("Create New Set") then
openPopup = true
end
ImGui.Separator()
if ImGui.BeginMenu("Button Size") then
for i = 3, 10 do
local checked = BMSettings:GetCharacterWindow(self.id).ButtonSize == i
if ImGui.MenuItem(tostring(i), nil, checked) then
BMSettings:GetCharacterWindow(self.id).ButtonSize = i
self.buttonSizeDirty = true
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
local font_scale = {
{
label = "Tiny",
size = 8,
},
{
label = "Small",
size = 9,
},
{
label = "Normal",
size = 10,
},
{
label = "Large",
size = 11,
},
}
if ImGui.BeginMenu("Font Scale") then
for i, v in ipairs(font_scale) do
local checked = BMSettings:GetCharacterWindow(self.id).Font == v.size
if ImGui.MenuItem(v.label, nil, checked) then
BMSettings:GetCharacterWindow(self.id).Font = v.size
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
if ImGui.BeginMenu("Set Theme") then
local checked = BMSettings:GetCharacterWindow(self.id).Theme == nil
if ImGui.MenuItem("Default", nil, checked) then
BMSettings:GetCharacterWindow(self.id).Theme = nil
BMSettings:SaveSettings(true)
end
for n, _ in pairs(themes) do
checked = (BMSettings:GetCharacterWindow(self.id).Theme or "") == n
if ImGui.MenuItem(n, nil, checked) then
BMSettings:GetCharacterWindow(self.id).Theme = n
BMSettings:SaveSettings(true)
break
end
end
for n, _ in pairs(BMSettings.Globals.CustomThemes or {}) do
checked = (BMSettings:GetCharacterWindow(self.id).Theme or "") == n
if ImGui.MenuItem(n, nil, checked) then
BMSettings:GetCharacterWindow(self.id).Theme = n
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
ImGui.Separator()
if ImGui.BeginMenu("Share Set") then
for k, _ in pairs(BMSettings:GetSettings().Sets) do
if ImGui.MenuItem(k) then
BMButtonHandlers:ExportSetToClipBoard(k)
btnUtils.Output("Set: '%s' has been copied to your clipboard!", k)
end
end
ImGui.EndMenu()
end
if ImGui.MenuItem("Import Button or Set") then
self.importObjectPopupOpen = true
self.importText = ImGui.GetClipboardText() or ""
self.importTextChanged = true
end
if ImGui.BeginMenu("Copy Local Set") then
local charList = {}
for k, _ in pairs(BMSettings:GetSettings().Characters) do
local menuItem = k:sub(1, 1):upper() .. k:sub(2)
menuItem = menuItem:gsub("_", ": ")
table.insert(charList, { displayName = menuItem, key = k, })
end
table.sort(charList, function(a, b) return a.key < b.key end)
for _, value in ipairs(charList) do
if ImGui.MenuItem(value.displayName) then
CopyLocalSet(value.key)
end
end
ImGui.EndMenu()
end
ImGui.Separator()
if ImGui.BeginMenu("Display Settings") then
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).HideTitleBar and "Show" or "Hide") .. " Title Bar") then
BMSettings:GetCharacterWindow(self.id).HideTitleBar = not BMSettings:GetCharacterWindow(self.id)
.HideTitleBar
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).CompactMode and "Normal" or "Compact") .. " Mode") then
BMSettings:GetCharacterWindow(self.id).CompactMode = not BMSettings:GetCharacterWindow(self.id)
.CompactMode
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).PerCharacterPositioning and "Global Window Positioning" or "Per Char Window Positioning")) then
BMSettings:GetCharacterWindow(self.id).PerCharacterPositioning = not BMSettings:GetCharacterWindow(self.id)
.PerCharacterPositioning
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).AdvTooltips and "Disable" or "Enable") .. " Advanced Tooltips") then
BMSettings:GetCharacterWindow(self.id).AdvTooltips = not BMSettings:GetCharacterWindow(self.id)
.AdvTooltips
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).HideScrollbar and "Show" or "Hide") .. " Scrollbar") then
BMSettings:GetCharacterWindow(self.id).HideScrollbar = not BMSettings:GetCharacterWindow(self.id)
.HideScrollbar
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem((BMSettings:GetCharacterWindow(self.id).ShowSearch and "Disable" or "Enable") .. " Search") then
BMSettings:GetCharacterWindow(self.id).ShowSearch = not BMSettings:GetCharacterWindow(self.id)
.ShowSearch
BMSettings:SaveSettings(true)
end
local fps_scale = {
{
label = "Instant",
fps = 0,
},
{
label = "10 FPS",
fps = 1,
},
{
label = "4 FPS",
fps = 2.5,
},
{
label = "1 FPS",
fps = 10,
},
}
if ImGui.BeginMenu("Update FPS") then
for _, v in ipairs(fps_scale) do
local checked = BMSettings:GetCharacterWindow(self.id).FPS == v.fps
if ImGui.MenuItem(v.label, nil, checked) then
BMSettings:GetCharacterWindow(self.id).FPS = v.fps
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
-- TODO: Make this a reference to a character since it can dynamically change.
--if ImGui.MenuItem("Save Layout as Default") then
-- BMSettings:GetSettings().Defaults = {
-- width = self.lastButtonPageWidth,
-- height = self.lastButtonPageHeight,
-- x = self.lastWindowX,
-- y = self.lastWindowY,
-- CharSettings = BMSettings:GetCharConfig(),
-- }
-- BMSettings:SaveSettings(true)
--end
ImGui.EndMenu()
end
if ImGui.MenuItem("Create New Hotbar") then
table.insert(BMHotbars, BMHotbarClass.new(BMSettings:GetNextWindowId(), true))
end
if ImGui.BeginMenu("Show/Hide Hotbar") then
for hbIdx, hotbarClass in ipairs(BMHotbars) do
if ImGui.MenuItem(string.format("Button Master - %d", hbIdx), nil, hotbarClass:IsVisible()) then
hotbarClass:ToggleVisible()
end
end
ImGui.EndMenu()
end
--[[if ImGui.MenuItem("Replicate Size/Pos") then
local x, y = ImGui.GetWindowPos()
ButtonActors.send({
from = mq.TLO.Me.DisplayName(),
script = "ButtonMaster",
event = "CopyLoc",
width = self.lastButtonPageWidth,
height = self.lastButtonPageHeight,
x = self.lastWindowX,
y = self.lastWindowY,
windowId = self.id,
hideTitleBar = BMSettings:GetCharacterWindow(self.id).HideTitleBar,
compactMode = BMSettings:GetCharacterWindow(self.id).CompactMode,
})
end]]
ImGui.Separator()
if ImGui.BeginMenu("Dev") then
if ImGui.MenuItem((btnUtils.enableDebug and "Disable" or "Enable") .. " Debug") then
btnUtils.enableDebug = not btnUtils.enableDebug
end
if ImGui.MenuItem("Remove All Duped Buttons") then
local duplicatekeys = Set.new({})
for buttonKey, buttonData in pairs(BMSettings:GetSettings().Buttons or {}) do
btnUtils.Output("\awTesting Button: \am%s", buttonKey)
for curBtnKey, curBtn in pairs(BMSettings:GetSettings().Buttons or {}) do
if buttonKey ~= curBtnKey and curBtn.Cmd == buttonData.Cmd then
btnUtils.Output("\awButton: \am%s \awis a duplicate!", buttonKey)
duplicatekeys:add(curBtnKey)
duplicatekeys:add(buttonKey)
break
end
end
end
for _, key in ipairs(duplicatekeys:toList()) do
btnUtils.Output("\awDuplicate: \am%s \aw(\at%s\aw)", key, BMSettings:GetSettings().Buttons[key].Label)
local isUsed = false
for _, setButtons in pairs(BMSettings:GetSettings().Sets) do
for _, buttonName in pairs(setButtons) do
if buttonName == key then
isUsed = true
end
end
end
if isUsed then
btnUtils.Output(" \ag-> Used")
else
if BMSettings:GetSettings().Buttons[key] then
btnUtils.Output(" \ay-> Unused - Removing!")
BMSettings:GetSettings().Buttons[key] = nil
else
btnUtils.Output(" \ay-> Unused - Previosuly Removed!")
end
end
end
BMSettings:SaveSettings(true)
end
ImGui.EndMenu()
end
ImGui.EndPopup()
end
if openPopup and ImGui.IsPopupOpen(editTabPopup) == false then
ImGui.OpenPopup(editTabPopup)
openPopup = false
end
end
function BMHotbarClass:RenderContextMenu(Set, Index, buttonID)
local button = BMSettings:GetButtonBySetIndex(Set, Index)
if ImGui.BeginPopupContextItem(buttonID) then
local unassigned = {}
local keys = {}
for _, v in pairs(BMSettings:GetSettings().Sets[Set] or {}) do keys[v] = true end
for k, v in pairs(BMSettings:GetSettings().Buttons) do
if keys[k] == nil then
unassigned[k] = v
end
end
--editPopupName = "edit_button_popup|" .. Index
-- only list hotkeys that aren't already assigned to the button set
if btnUtils.getTableSize(unassigned) > 0 then
if ImGui.BeginMenu("Assign Hotkey") then
-- hytiek: BEGIN ADD
-- Create an array to store the sorted keys
local sortedKeys = {}
-- Populate the array with non-nil keys from the original table
for key, value in pairs(unassigned) do
if value ~= nil then
table.insert(sortedKeys, key)
end
end
-- Sort the keys based on the Label field
table.sort(sortedKeys, function(a, b)
local labelA = unassigned[a] and BMButtonHandlers.ResolveButtonLabel(unassigned[a], true)
local labelB = unassigned[b] and BMButtonHandlers.ResolveButtonLabel(unassigned[b], true)
return labelA < labelB
end)
local sortedAlphaMenu = {}
for idx, key in ipairs(sortedKeys) do
local value = unassigned[key]
if value ~= nil then
for _, menuGroup in ipairs(self.alphaMenu) do
sortedAlphaMenu[menuGroup.name] = sortedAlphaMenu[menuGroup.name] or {}
local label = BMButtonHandlers.ResolveButtonLabel(value, true)
if menuGroup.filter(label:sub(1, 1):upper()) then
table.insert(sortedAlphaMenu[menuGroup.name], { idx = idx, key = key, value = value, label = label, })
break
end
end
end
end
for _, menuGroup in pairs(self.alphaMenu) do
local items = sortedAlphaMenu[menuGroup.name] or {}
if #items > 0 then
if ImGui.BeginMenu(menuGroup.name) then
for _, item in ipairs(items) do
if ImGui.MenuItem(item.label .. "##assign_menu_" .. tostring(item.idx)) then
BMSettings:GetSettings().Sets[Set][Index] = item.key
BMSettings:SaveSettings(true)
break
end
end
ImGui.EndMenu()
end
end
end
ImGui.EndMenu()
end
end
-- only show create new for unassigned buttons
if button.Unassigned == true then
if ImGui.MenuItem("Create New") then
BMEditPopup:OpenEditPopup(Set, Index)
end
else
if ImGui.MenuItem("Edit") then
BMEditPopup:OpenEditPopup(Set, Index)
end
if ImGui.MenuItem("Unassign") then
BMSettings:GetSettings().Sets[Set][Index] = nil
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem("Delete") then
local buttonID = BMSettings:GetSettings().Sets[Set][Index]
for setNameKey, setButtons in pairs(BMSettings:GetSettings().Sets) do
for buttonKey, buttonName in pairs(setButtons) do
if buttonName == buttonID then
BMSettings:GetSettings().Sets[setNameKey][buttonKey] = nil
end
end
end
BMSettings:GetSettings().Buttons[buttonID] = nil
BMSettings:SaveSettings(true)
end
if ImGui.MenuItem(Icons.MD_SHARE) then
BMButtonHandlers.ExportButtonToClipBoard(button)
end
btnUtils.Tooltip("Copy contents of this button to share with friends.")
end
ImGui.EndPopup()
end
end
---@param Set string
---@param searchText string
function BMHotbarClass:RenderButtons(Set, searchText)
ImGui.PushStyleVar(ImGuiStyleVar.ItemSpacing, ImVec2(4, 4))
if ImGui.GetWindowWidth() ~= self.lastButtonPageWidth or ImGui.GetWindowHeight() ~= self.lastButtonPageHeight or self.buttonSizeDirty then
self:RecalculateVisibleButtons(Set)
end
local btnSize = (BMSettings:GetCharacterWindow(self.id).ButtonSize or 6) * 10
local renderButtonCount = self.visibleButtonCount
for ButtonIndex = 1, renderButtonCount do
local button = BMSettings:GetButtonBySetIndex(Set, ButtonIndex)
local searchMatch = true
if searchText:len() > 0 then
searchMatch =
(button.CachedLabel or ""):lower():find(searchText:lower()) ~= nil
or
(button.Cmd or ""):lower():find(searchText:lower()) ~= nil
end
if searchMatch then
local clicked = false
local buttonID = string.format("##Button_%s_%d", Set, ButtonIndex)
local showLabel = true
local btnKey = BMSettings:GetButtonSectionKeyBySetIndex(Set, ButtonIndex)
if BMSettings.settings.Buttons[btnKey] ~= nil and BMSettings.settings.Buttons[btnKey].ShowLabel ~= nil then
showLabel = BMSettings.settings.Buttons[btnKey].ShowLabel
end
ImGui.PushID(buttonID)
clicked = BMButtonHandlers.Render(button, btnSize, showLabel, (BMSettings:GetCharacterWindow(self.id).Font or 10) / 10,
BMSettings:GetCharacterWindow(self.id).AdvTooltips)
ImGui.PopID()
-- TODO Move this to button config class and out of the UI thread.
if clicked then
if button.Unassigned then
BMEditPopup:CreateButtonFromCursor(Set, ButtonIndex)
else
BMButtonHandlers.Exec(button)
end
else
-- setup drag and drop
if ImGui.BeginDragDropSource() then
self.currentDnDData = { Set = Set, Index = ButtonIndex, }
ImGui.SetDragDropPayload("BTN", self.id)
ImGui.Button(button.Label, btnSize, btnSize)
ImGui.EndDragDropSource()
end
if ImGui.BeginDragDropTarget() then
local payload = ImGui.AcceptDragDropPayload("BTN")
if payload ~= nil then
---@diagnostic disable-next-line: undefined-field
local dndData = BMHotbars[payload.Data].currentDnDData
local success = dndData ~= nil
if success then
local to_set = dndData.Set
local to_num = dndData.Index
btnUtils.Output("Dropping button from set '" ..
tostring(to_set) .. "' index " .. tostring(to_num) .. " to set '" .. tostring(Set) .. "' index " .. tostring(ButtonIndex))
-- swap the keys in the button set
BMSettings:GetSettings().Sets[to_set][to_num], BMSettings:GetSettings().Sets[Set][ButtonIndex] =
BMSettings:GetSettings().Sets[Set][ButtonIndex], BMSettings:GetSettings().Sets[to_set][to_num]
BMSettings:SaveSettings(true)
else
btnUtils.Output("\arError: Failed to decode dropped button payload :: %s!\ax", payload.Data or "nil")
end
end
ImGui.EndDragDropTarget()
end
self:RenderContextMenu(Set, ButtonIndex, buttonID)
end
-- button grid
if ButtonIndex % self.cachedCols ~= 0 then ImGui.SameLine() end
end
end
ImGui.PopStyleVar(1)
end
function BMHotbarClass:RecalculateVisibleButtons(Set)
self.buttonSizeDirty = false
btnUtils.Debug("\arHave old lW=%d lH=%d", self.lastButtonPageWidth, self.lastButtonPageHeight)
self.lastButtonPageWidth = ImGui.GetWindowWidth()
self.lastButtonPageHeight = ImGui.GetWindowHeight()
btnUtils.Debug("\arSetting new lW=%d lH=%d", self.lastButtonPageWidth, self.lastButtonPageHeight)
local cursorX, cursorY = ImGui.GetCursorPos() -- this will get us the x pos we start at which tells us of the offset from the main window border
local style = ImGui.GetStyle() -- this will get us ItemSpacing.x which is the amount of space between buttons
-- global button configs
local btnSize = (BMSettings:GetCharacterWindow(self.id).ButtonSize or 6) * 10
self.cachedCols = math.floor((self.lastButtonPageWidth - cursorX) / (btnSize + style.ItemSpacing.x))
self.cachedRows = math.floor((self.lastButtonPageHeight - cursorY) / (btnSize + style.ItemSpacing.y))
local count = 100
if self.cachedRows * self.cachedCols < 100 then count = self.cachedRows * self.cachedCols end
-- get the last assigned button and make sure it is visible.
local lastAssignedButton = 1
for i = 1, 100 do if not BMSettings:GetButtonBySetIndex(Set, i).Unassigned then lastAssignedButton = i end end
-- if the last forced visible buttons isn't the last in a row then render to the end of that row.
-- stay with me here. The last button needs to look at the number of buttons per row (cols) and
-- the position of this button in that row (button%cols) and add enough to get to the end of the row.
if lastAssignedButton % self.cachedCols ~= 0 then
lastAssignedButton = lastAssignedButton + (self.cachedCols - (lastAssignedButton % self.cachedCols))
end
self.visibleButtonCount = math.min(math.max(count, lastAssignedButton), 100)
end
function BMHotbarClass:RenderImportButtonPopup()
if not self.importObjectPopupOpen then return end