forked from 1onar/KeyUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCore.lua
More file actions
1807 lines (1573 loc) · 69.6 KB
/
Core.lua
File metadata and controls
1807 lines (1573 loc) · 69.6 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 name, addon = ...
-- Initialize libraries
local AceConfig = LibStub("AceConfig-3.0")
local AceConfigDialog = LibStub("AceConfigDialog-3.0")
local LibDBIcon = LibStub("LibDBIcon-1.0", true)
local LDB = LibStub("LibDataBroker-1.1")
-- Create the options frame and add it to the Interface Options
local optionsFrame = AceConfigDialog:AddToBlizOptions("KeyUI", "KeyUI")
-- Minimap button setup using LibDataBroker
local miniButton = LDB:NewDataObject("KeyUI", {
type = "data source",
text = "KeyUI",
icon = "Interface\\AddOns\\KeyUI\\Media\\keyui_icon.blp",
OnClick = function(self, btn)
if btn == "LeftButton" then
if addon.open == true then
-- Close the addon regardless of the combat state
addon:hide_all_frames()
else
-- Open the addon if stay_open_in_combat is true OR if not in combat
if not addon.in_combat or keyui_settings.stay_open_in_combat then
addon:load()
else
print("KeyUI: Cannot open while in combat.")
end
end
elseif btn == "RightButton" then
-- Open the Blizzard settings page
Settings.OpenToCategory("KeyUI")
end
end,
OnTooltipShow = function(tooltip)
if not tooltip or not tooltip.AddLine then return end
-- Add the title
tooltip:AddLine("KeyUI")
-- Add blank line for spacing
tooltip:AddLine(" ")
-- Add description lines with custom colors
tooltip:AddLine("|cffffffffLeft-Click|r |cFF00FF00to toggle addon|r")
tooltip:AddLine("|cffffffffRight-Click|r |cFF00FF00to open options|r")
end,
})
local function set_esc_close_enabled(frame, enabled)
if not frame or not frame:GetName() then return end
if enabled then
-- Remove the frame from UISpecialFrames if ESC closing is disabled
for i, frameName in ipairs(UISpecialFrames) do
if frameName == frame:GetName() then
tremove(UISpecialFrames, i)
--print(frame:GetName() .. " removed from UISpecialFrames")
break
end
end
else
-- Add the frame back to UISpecialFrames to allow ESC closing
if not tContains(UISpecialFrames, frame:GetName()) then
tinsert(UISpecialFrames, frame:GetName())
--print(frame:GetName() .. " added to UISpecialFrames")
end
end
end
-- Define the options table for AceConfig
local options = {
type = "group",
name = "KeyUI",
args = {
minimap = {
type = "toggle",
name = "Minimap Button",
desc = "Show or hide the minimap button",
order = 7,
get = function() return not keyui_settings.minimap.hide end,
set = function(_, value)
keyui_settings.minimap.hide = not value
if value then
LibDBIcon:Show("KeyUI")
print("KeyUI: Minimap button enabled")
else
LibDBIcon:Hide("KeyUI")
print("KeyUI: Minimap button disabled")
end
end,
},
stay_open_in_combat = {
type = "toggle",
name = "Stay Open In Combat",
desc = "Allow KeyUI to stay open during combat",
order = 8,
get = function() return keyui_settings.stay_open_in_combat end,
set = function(_, value)
keyui_settings.stay_open_in_combat = value
local status = value and "enabled" or "disabled"
print("KeyUI: Stay open in combat " .. status)
end,
},
show_keyboard = {
type = "toggle",
name = "Show Keyboard",
desc = "Show or hide the keyboard frame",
order = 1,
get = function() return keyui_settings.show_keyboard end,
set = function(_, value)
keyui_settings.show_keyboard = value
local status = value and "enabled" or "disabled"
print("KeyUI: Keyboard visibility", status)
end,
},
show_mouse = {
type = "toggle",
name = "Show Mouse",
desc = "Show or hide the mouse frame",
order = 2,
get = function() return keyui_settings.show_mouse end,
set = function(_, value)
keyui_settings.show_mouse = value
local status = value and "enabled" or "disabled"
print("KeyUI: Mouse visibility", status)
end,
},
show_controller = {
type = "toggle",
name = "Show Controller",
desc = "Show or hide the controller frame",
order = 3,
get = function() return keyui_settings.show_controller end,
set = function(_, value)
keyui_settings.show_controller = value
local status = value and "enabled" or "disabled"
print("KeyUI: Controller visibility", status)
end,
},
-- Add a button to reset all settings to defaults
reset_settings = {
type = "execute",
name = "Reset Addon Settings",
desc = "Reset all KeyUI settings to their default values",
order = 10,
confirm = true, -- Ask for confirmation
confirmText = "Are you sure you want to reset all KeyUI settings to default?",
func = function()
-- Reset all SavedVariables to their default values
keyui_settings = {
show_keyboard = false,
show_mouse = false,
show_controller = false,
stay_open_in_combat = true,
show_pushed_texture = true,
prevent_esc_close = true,
keyboard_position = {},
mouse_position = {},
minimap = { hide = false },
show_empty_binds = false,
show_interface_binds = false,
tutorial_completed = false,
listen_to_modifier = true,
dynamic_modifier = false,
key_bind_settings = {
keyboard = {},
mouse = {},
},
layout_current = {
keyboard = {},
mouse = {},
},
layout_edited = {
keyboard = {},
mouse = {},
},
show_keyboard_background = true,
show_mouse_graphic = true,
show_controller_background = true,
}
-- Reload the UI to apply the changes
ReloadUI()
end,
},
prevent_esc_close = {
type = "toggle",
name = "Enable ESC",
desc = "Enable or disable the addon window closing when pressing ESC",
order = 9,
get = function() return keyui_settings.prevent_esc_close end,
set = function(_, value)
keyui_settings.prevent_esc_close = value
-- Immediately update the ESC closing behavior for all relevant frames
set_esc_close_enabled(addon.keyboard_frame, not keyui_settings.prevent_esc_close)
set_esc_close_enabled(addon.controls_frame, not keyui_settings.prevent_esc_close)
set_esc_close_enabled(addon.mouse_image, not keyui_settings.prevent_esc_close)
set_esc_close_enabled(addon.mouse_frame, not keyui_settings.prevent_esc_close)
set_esc_close_enabled(addon.mouse_control_frame, not keyui_settings.prevent_esc_close)
local status = value and "enabled" or "disabled"
print("KeyUI: Closing with ESC " .. status)
end,
},
show_keyboard_background = {
type = "toggle",
name = "Keyboard Background",
desc = "Show or hide the background and border of the keyboard frame",
order = 4,
get = function() return keyui_settings.show_keyboard_background end,
set = function(_, value)
keyui_settings.show_keyboard_background = value
local status = value and "enabled" or "disabled"
print("KeyUI: Keyboard background", status)
end,
},
show_mouse_graphic = {
type = "toggle",
name = " Mouse Graphic",
desc = "Show or hide the graphical representation of the mouse",
order = 5,
get = function() return keyui_settings.show_mouse_graphic end,
set = function(_, value)
keyui_settings.show_mouse_graphic = value
local status = value and "enabled" or "disabled"
print("KeyUI: Mouse graphic", status)
end,
},
show_controller_background = {
type = "toggle",
name = "Controller Background",
desc = "Show or hide the background and border of the controller frame",
order = 6,
get = function() return keyui_settings.show_controller_background end,
set = function(_, value)
keyui_settings.show_controller_background = value
local status = value and "enabled" or "disabled"
print("KeyUI: Controller background", status)
end,
},
},
}
-- Handle addon load event and initialize
EventUtil.ContinueOnAddOnLoaded(..., function()
-- Load additional saved settings and update the UI
addon:InitializeSettings()
-- Register the minimap button using LibDBIcon
LibDBIcon:Register("KeyUI", miniButton, keyui_settings.minimap)
-- Register the options table
AceConfig:RegisterOptionsTable("KeyUI", options)
end)
-- Main function to load the addon.
function addon:load()
if keyui_settings.show_keyboard == false and keyui_settings.show_mouse == false and keyui_settings.show_controller == false then
-- Create the selection frame if not already created.
if not addon.selection_frame then
addon.selection_frame = addon:create_selection_frame()
else
addon.selection_frame:Show()
end
else
-- Prevent loading if in combat and 'stay_open_in_combat' is false.
if addon.in_combat and not keyui_settings.stay_open_in_combat then
return
end
addon.open = true -- Mark the addon as open
addon:show_frames()
if keyui_settings.show_keyboard == true then
-- Generate keyboard layout directly if the dropdown has not been created yet
local active_keyboard_board = next(keyui_settings.layout_current_keyboard)
if not addon.keyboard_selector then
addon:generate_keyboard_layout(active_keyboard_board)
end
end
if keyui_settings.show_mouse == true then
-- Generate mouse layout directly if the dropdown has not been created yet
local active_mouse_board = next(keyui_settings.layout_current_mouse)
if not addon.mouse_selector then
addon:generate_mouse_layout(active_mouse_board)
end
end
if keyui_settings.show_controller == true then
-- Generate controller layout directly if the dropdown has not been created yet
local active_controller_board = next(keyui_settings.layout_current_controller)
if not addon.controller_selector then
addon:generate_controller_layout(active_controller_board)
end
end
-- Ensure the dropdown menu is created.
addon:create_context_menu()
-- Initialize the tooltip if not already created.
addon.keyui_tooltip_frame = addon.keyui_tooltip_frame or addon:create_tooltip()
-- Load spells and refresh the key bindings.
addon:load_spellbook()
addon:refresh_layouts()
-- Show tutorial if not completed
if keyui_settings.tutorial_completed ~= true and addon.tutorial_frame1_created ~= true then
addon:create_tutorial_frame1()
end
end
end
function addon:load_spellbook()
addon.spells = {}
for i = 1, C_SpellBook.GetNumSpellBookSkillLines() do
local skillLineInfo = C_SpellBook.GetSpellBookSkillLineInfo(i)
local name = skillLineInfo.name
local offset, numSlots = skillLineInfo.itemIndexOffset, skillLineInfo.numSpellBookItems
-- Ensure the skill line has a name before proceeding.
if name then
addon.spells[name] = {}
for j = offset + 1, offset + numSlots do
local spellBookItemInfo = C_SpellBook.GetSpellBookItemInfo(j, Enum.SpellBookSpellBank.Player)
local spellName = spellBookItemInfo.name
local spellID = spellBookItemInfo.spellID
local isPassive = spellBookItemInfo.isPassive
if spellName and not isPassive then
table.insert(addon.spells[name], { name = spellName, id = spellID })
end
end
end
end
end
-- Triggers the functions to update the keyboard and mouse layouts on the current configuration.
function addon:refresh_layouts()
--print("refresh_layouts function called") -- print statement for debbuging
-- stop if the addon is not open
if addon.open == false then
return
end
-- stop if keyboard and mouse are not visible
if addon.is_keyboard_visible == false and addon.is_mouse_visible == false and addon.is_controller_visible == false then
return
end
-- if the keyboard is locked and not edited we refresh the keyboard board holding the keys
if addon.keyboard_locked ~= false and addon.keys_keyboard_edited ~= true then
addon:generate_keyboard_key_frames(keyui_settings.key_bind_settings_keyboard.currentboard)
end
-- if the mouse is locked and not edited we refresh the mouse board holding the keys
if addon.mouse_locked ~= false and addon.keys_mouse_edited ~= true then
addon:generate_mouse_key_frames(keyui_settings.key_bind_settings_mouse.currentboard)
end
-- if the controller is locked and not edited we refresh the controller board holding the keys
if addon.controller_locked ~= false and addon.keys_controller_edited ~= true then
addon:generate_controller_key_frames(keyui_settings.key_bind_settings_controller.currentboard)
end
-- update the textures/texts of the keys bindings.
addon:refresh_keys()
end
-- Update the visibility of keyboard and mouse based on settings, only if addon is open
function addon:show_frames()
if addon.open == false then
return
end
local keyboard_frame = addon:get_keyboard_frame()
local mouse_image = addon:get_mouse_image()
local mouse_frame = addon:get_mouse_frame()
local controller_frame = addon:get_controller_frame()
local controller_image = addon:get_controller_image()
if keyui_settings.show_keyboard == true then
addon.is_keyboard_visible = true
keyboard_frame:Show()
if keyui_settings.show_keyboard_background ~= true then
-- Remove the background and border if graphics are disabled
keyboard_frame:SetBackdrop(nil)
else
-- Restore the background and border if graphics are enabled
keyboard_frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface\\AddOns\\KeyUI\\Media\\Edge\\frame_edge",
tile = true,
tileSize = 8,
edgeSize = 14,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
keyboard_frame:SetBackdropColor(0.08, 0.08, 0.08, 1)
end
end
if keyui_settings.show_mouse == true then
addon.is_mouse_visible = true
mouse_image:Show()
mouse_frame:Show()
if keyui_settings.show_mouse_graphic ~= true then
mouse_image.Texture:Hide()
else
mouse_image.Texture:Show()
end
end
if keyui_settings.show_controller == true then
addon.is_controller_visible = true
controller_frame:Show()
if controller_image then
controller_image:Show()
end
if keyui_settings.show_controller_background ~= true then
-- Remove the background and border if graphics are disabled
controller_frame:SetBackdrop(nil)
else
-- Restore the background and border if graphics are enabled
controller_frame:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface\\AddOns\\KeyUI\\Media\\Edge\\frame_edge",
tile = true,
tileSize = 8,
edgeSize = 14,
insets = { left = 2, right = 2, top = 2, bottom = 2 }
})
controller_frame:SetBackdropColor(0.08, 0.08, 0.08, 1)
end
end
end
-- Hides all UI elements when the addon is closed
function addon:hide_all_frames()
local keyboard_frame = addon:get_keyboard_frame()
local mouse_image = addon:get_mouse_image()
local mouse_frame = addon:get_mouse_frame()
local controller_frame = addon:get_controller_frame()
keyboard_frame:Hide()
mouse_frame:Hide()
mouse_image:Hide()
controller_frame:Hide()
if addon.controls_frame then
addon.controls_frame:Hide()
end
if addon.selection_frame then
addon.selection_frame:Hide()
end
if addon.name_input_dialog then
addon.name_input_dialog:Hide()
end
if addon.edit_layout_dialog then
addon.edit_layout_dialog:Hide()
end
addon.open = false
addon.is_keyboard_visible = false
addon.is_mouse_visible = false
addon.is_controller_visible = false
end
local function on_frame_hide(self)
if (addon.is_keyboard_visible == false or keyui_settings.show_keyboard == false) and (addon.is_mouse_visible == false or keyui_settings.show_mouse == false) and (addon.is_controller_visible == false or keyui_settings.show_controller == false) then
addon.open = false
-- Discard Keyboard Editor Changes when closing
if addon.keyboard_locked == false or addon.keys_keyboard_edited == true then
addon:discard_keyboard_changes()
end
-- Discard Mouse Editor Changes when closing
if addon.mouse_locked == false or addon.keys_mouse_edited == true then
-- Discard any Editor Changes
addon:discard_mouse_changes()
end
-- Discard Controller Editor Changes when closing
if addon.controller_locked == false or addon.keys_controller_edited == true then
addon:discard_controller_changes()
end
end
end
-- Function to get or create the keyboard frame
function addon:get_keyboard_frame()
-- Check if the keyboard_frame already exists
if not addon.keyboard_frame then
-- Create the keyboard frame and assign it to the addon table
addon.keyboard_frame = addon:create_keyboard_frame()
addon.keyboard_frame:SetScript("OnHide", function()
addon:save_keyboard_position()
addon.is_keyboard_visible = false
on_frame_hide()
end)
addon.keyboard_frame:SetScript("OnShow", function()
addon.is_keyboard_visible = true
end)
end
return addon.keyboard_frame
end
-- Function to get or create the mouse image frame
function addon:get_mouse_image()
-- Check if the mouse_image already exists
if not addon.mouse_image then
-- Create the mouse image and assign it to the addon table
addon.mouse_image = addon:create_mouse_image()
addon.mouse_image:SetScript("OnHide", function()
addon:save_mouse_position()
addon.is_mouse_visible = false
on_frame_hide()
end)
addon.mouse_image:SetScript("OnShow", function()
addon.is_mouse_visible = true
end)
end
return addon.mouse_image
end
-- Function to get or create the mouse frame
function addon:get_mouse_frame()
if not addon.mouse_frame then
addon.mouse_frame = addon:create_mouse_frame()
end
return addon.mouse_frame
end
-- Function to get or create the controller frame
function addon:get_controller_frame()
-- Check if the controller_frame already exists
if not addon.controller_frame then
-- Create the controller frame and assign it to the addon table
addon.controller_frame = addon:create_controller_frame()
addon.controller_frame:SetScript("OnHide", function()
addon:save_controller_position()
addon.is_controller_visible = false
on_frame_hide()
end)
addon.controller_frame:SetScript("OnShow", function()
addon.is_controller_visible = true
end)
end
return addon.controller_frame
end
-- Function to get or create the controller image
function addon:get_controller_image()
if not addon.controller_image then
addon.controller_image = addon:create_controller_image()
end
return addon.controller_image
end
-- Function to get or create the keyboard control
function addon:get_controls_frame()
-- Check if the controls frame already exists
if not addon.controls_frame then
-- If it doesn't exist, create the controls frame and assign it to the addon
addon.controls_frame = addon:create_controls()
-- Immediately show the newly created controls frame
addon.controls_frame:Show()
end
-- Return the controls frame (either existing or newly created)
return addon.controls_frame
end
function addon:create_tooltip()
-- Create the tooltip frame with the GlowBoxTemplate.
local keyui_tooltip_frame = CreateFrame("Frame", nil, UIParent, "GlowBoxTemplate")
addon.keyui_tooltip_frame = keyui_tooltip_frame -- Save the tooltip to the addon table for reuse.
keyui_tooltip_frame:SetFrameStrata("TOOLTIP")
keyui_tooltip_frame:SetHeight(50)
-- Add a text to the tooltip.
keyui_tooltip_frame.key = keyui_tooltip_frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
keyui_tooltip_frame.key:SetPoint("CENTER", keyui_tooltip_frame, "CENTER", 0, 10)
keyui_tooltip_frame.key:SetTextColor(1, 1, 1)
keyui_tooltip_frame.key:SetFont("Interface\\AddOns\\KeyUI\\Media\\Fonts\\Expressway Regular.TTF", 16)
keyui_tooltip_frame.binding = keyui_tooltip_frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
keyui_tooltip_frame.binding:SetPoint("CENTER", keyui_tooltip_frame, "CENTER", 0, -10)
keyui_tooltip_frame.binding:SetTextColor(1, 1, 1)
keyui_tooltip_frame.binding:SetFont("Interface\\AddOns\\KeyUI\\Media\\Fonts\\Expressway Regular.TTF", 16)
-- Hide the GameTooltip when this custom tooltip hides.
keyui_tooltip_frame:SetScript("OnHide", function() GameTooltip:Hide() end)
return keyui_tooltip_frame
end
-- This function is called when the Mouse cursor hovers over a key binding button. It displays a tooltip description of the spell or ability.
function addon:button_mouse_over(button)
local raw_key = button.raw_key or ""
local short_key = button.short_key:GetText()
local readable_binding = button.readable_binding:GetText() or ""
local short_modifier_string = (addon.current_modifier_string or "")
-- Position the tooltip next to the hovered button
addon.keyui_tooltip_frame:SetPoint("BOTTOMLEFT", button, "BOTTOMRIGHT", 6, 5)
-- Adjust the tooltip size and text positions for gamepad buttons
if addon.gamepad_buttons[raw_key] then
addon.keyui_tooltip_frame:SetHeight(74) -- Increase height for gamepad buttons
addon.keyui_tooltip_frame.key:SetScale(0.8)
addon.keyui_tooltip_frame.key:SetPoint("CENTER", addon.keyui_tooltip_frame, "CENTER", 0, 14) -- Adjust key text position
addon.keyui_tooltip_frame.binding:SetPoint("CENTER", addon.keyui_tooltip_frame, "CENTER", 0, -22) -- Adjust binding text position
else
addon.keyui_tooltip_frame:SetHeight(50) -- Default height for non-gamepad buttons
addon.keyui_tooltip_frame.key:SetScale(1)
addon.keyui_tooltip_frame.key:SetPoint("CENTER", addon.keyui_tooltip_frame, "CENTER", 0, 10) -- Default key text position
addon.keyui_tooltip_frame.binding:SetPoint("CENTER", addon.keyui_tooltip_frame, "CENTER", 0, -10) -- Default binding text position
end
-- Display the key text with or without modifiers
if short_key then
if addon.no_modifier_keys[raw_key] then
-- For keys without modifiers, display only the key
addon.keyui_tooltip_frame.key:SetText(short_key)
else
-- For keys with modifiers, display the modifier string followed by the key
addon.keyui_tooltip_frame.key:SetText(short_modifier_string .. short_key)
end
else
addon.keyui_tooltip_frame.key:SetText("")
end
-- Display the readable binding text
addon.keyui_tooltip_frame.binding:SetText(readable_binding or "")
-- Adjust tooltip width based on the longer text dimension + 20
local binding_width = addon.keyui_tooltip_frame.binding:GetText() and addon.keyui_tooltip_frame.binding:GetWidth() or 0
local key_width = addon.keyui_tooltip_frame.key:GetText() and addon.keyui_tooltip_frame.key:GetWidth() or 0
addon.keyui_tooltip_frame:SetWidth(math.max(binding_width, key_width) + 20)
-- Show the tooltip
addon.keyui_tooltip_frame:Show()
-- Display the GameTooltip if the hovered button has an active slot
if addon.current_hovered_button.active_slot then
GameTooltip:SetOwner(addon.current_hovered_button, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", button, "BOTTOMLEFT")
GameTooltip:SetAction(addon.current_hovered_button.active_slot) -- Use SetAction for ActionButtons
GameTooltip:Show()
elseif addon.current_hovered_button.spellid then
GameTooltip:SetOwner(addon.current_hovered_button, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", button, "BOTTOMLEFT")
GameTooltip:SetSpellByID(addon.current_hovered_button.spellid)
GameTooltip:Show()
elseif addon.current_hovered_button.pet_action_index then
GameTooltip:SetOwner(addon.current_hovered_button, "ANCHOR_NONE")
GameTooltip:SetPoint("TOPLEFT", button, "BOTTOMLEFT")
GameTooltip:SetPetAction(addon.current_hovered_button.pet_action_index)
GameTooltip:Show()
else
-- Hide the GameTooltip if no active slot is found
GameTooltip:Hide()
end
end
-- Determines the texture displayed on the button based on the key binding.
function addon:set_key(button)
-- Reset button state
addon:reset_button_state(button)
-- Get the binding string
local binding = addon:get_binding(button.raw_key)
-- Store the interface command (Blizzard Interface Commands)
button.binding = binding
-- Centralized keybind mapping table
local keybind_patterns = {
-- ACTIONBUTTON
["^ACTIONBUTTON(%d+)$"] = function(binding, button)
local slot = tonumber(binding:match("ACTIONBUTTON(%d+)"))
return addon:process_actionbutton_slot(slot, button)
end,
-- MULTIACTIONBARBUTTON
["MULTIACTIONBAR(%d+)BUTTON(%d+)"] = function(binding, button)
local bar, bar_button = binding:match("MULTIACTIONBAR(%d+)BUTTON(%d+)")
if not bar or not bar_button then return end
return addon:process_multiactionbar_slot(tonumber(bar), tonumber(bar_button), button)
end,
-- BONUSACTIONBUTTON
["^BONUSACTIONBUTTON(%d+)$"] = function(binding, button)
return addon:process_pet_action_slot(binding, button)
end,
-- SHAPESHIFTBUTTON
["^SHAPESHIFTBUTTON(%d+)$"] = function(binding, button)
local slot = tonumber(binding:match("SHAPESHIFTBUTTON(%d+)"))
return addon:process_shapeshift_slot(slot, button)
end,
-- Spell
["^Spell (.+)$"] = function(binding, button)
local spell_name = binding:match("^Spell (.+)$")
return addon:process_spell(spell_name, button)
end,
-- Macro
["^Macro (.+)$"] = function(binding, button)
local macro_name = binding:match("^Macro (.+)$")
return addon:process_macro(macro_name, button)
end,
}
--ElvUI
if C_AddOns.IsAddOnLoaded("ElvUI") then
keybind_patterns["^CLICK ElvUI_Bar(%d+)Button(%d+):LeftButton$"] = function(binding, button)
return addon:process_elvui(binding, button)
end
end
-- Bartender
if C_AddOns.IsAddOnLoaded("Bartender4") then
keybind_patterns["^CLICK BT4Button(%d+):Keybind$"] = function(binding, button)
return addon:process_bartender(binding, button)
end
end
-- Dominos
if C_AddOns.IsAddOnLoaded("Dominos") then
keybind_patterns["^DominosActionButton(%d+)$"] = function(binding, button)
return addon:process_dominos(binding, button)
end
end
-- OPie
if C_AddOns.IsAddOnLoaded("OPie") then
keybind_patterns["CLICK ORL_RProxy"] = function(binding, button)
return addon:process_opie(button)
end
end
-- BindPad
if C_AddOns.IsAddOnLoaded("BindPad") then
-- Macro names can include anything; capture everything after "BindPadMacro:"
keybind_patterns["^CLICK BindPadMacro:(.+)$"] = function(binding, button)
return addon:process_bindpad(binding, button)
end
-- Spell names can also be arbitrary; capture everything after "BindPadKey:SPELL "
keybind_patterns["^CLICK BindPadKey:SPELL (.+)$"] = function(binding, button)
return addon:process_bindpad(binding, button)
end
-- Item names can be arbitrary; capture everything after "BindPadKey:ITEM "
keybind_patterns["^CLICK BindPadKey:ITEM (.+)$"] = function(binding, button)
return addon:process_bindpad(binding, button)
end
end
-- Loop through the keybind patterns and process the binding if the binding is not empty
if binding ~= "" then
for pattern, handler in pairs(keybind_patterns) do
if binding:find(pattern) then
handler(binding, button)
break -- Exit loop once a match is found
end
end
-- Check for specific bindings and set the icon
local specific_bindings = {
EXTRAACTIONBUTTON1 = 4200126,
MOVEFORWARD = "Interface\\AddOns\\KeyUI\\Media\\Icons\\arrow_up",
MOVEBACKWARD = "Interface\\AddOns\\KeyUI\\Media\\Icons\\arrow_down",
STRAFELEFT = "Interface\\AddOns\\KeyUI\\Media\\Icons\\arrow_left",
STRAFERIGHT = "Interface\\AddOns\\KeyUI\\Media\\Icons\\arrow_right",
TURNLEFT = "Interface\\AddOns\\KeyUI\\Media\\Icons\\circle_left",
TURNRIGHT = "Interface\\AddOns\\KeyUI\\Media\\Icons\\circle_right",
}
if specific_bindings[binding] then
button.icon:SetTexture(specific_bindings[binding])
button.icon:SetSize(30, 30)
button.icon:Show()
end
-- Handle interface action labels
addon:create_action_labels(binding, button)
else
-- Handle empty bindings if the option is enabled
if keyui_settings.show_empty_binds then
addon:update_empty_binds(button)
end
-- Highlight the modifier button if it is pressed
if keyui_settings.listen_to_modifier == true then
local function highlight_modifier_button(button)
button.highlight:SetTexture("Interface\\AddOns\\KeyUI\\Media\\Background\\yellow_bg")
button.highlight:SetSize(button:GetWidth() - 10, button:GetHeight() - 10)
button.highlight:Show()
end
if IsLeftAltKeyDown() and button.raw_key == "LALT" then
highlight_modifier_button(button)
end
if IsRightAltKeyDown() and button.raw_key == "RALT" then
highlight_modifier_button(button)
end
if IsLeftControlKeyDown() and button.raw_key == "LCTRL" then
highlight_modifier_button(button)
end
if IsRightControlKeyDown() and button.raw_key == "RCTRL" then
highlight_modifier_button(button)
end
if IsLeftShiftKeyDown() and button.raw_key == "LSHIFT" then
highlight_modifier_button(button)
end
if IsRightShiftKeyDown() and button.raw_key == "RSHIFT" then
highlight_modifier_button(button)
end
end
end
-- Update key text at the end
addon:update_button_key_text(button)
end
-- Resets the button's state
function addon:reset_button_state(button)
button.slot = nil
button.active_slot = nil
button.icon:SetTexture(nil)
button.icon:Hide()
button.readable_binding:Hide()
button.readable_binding:SetText("")
button.highlight:Hide()
end
-- Retrieves the binding action
function addon:get_binding(raw_key)
return GetBindingAction(self.current_modifier_string .. (raw_key or ""), true) or ""
end
-- Handles processing for ACTIONBUTTON
function addon:process_actionbutton_slot(slot, button)
if not slot then return end
-- Adjust the slot based on bonus bar offset and action bar page
local adjusted_slot = addon:get_action_button_slot(slot)
button.slot = adjusted_slot
-- Check if the slot has an action assigned
if HasAction(adjusted_slot) then
button.active_slot = adjusted_slot
button.icon:SetTexture(GetActionTexture(adjusted_slot))
button.icon:Show()
end
end
-- Adjusts the slot for ACTIONBUTTON bindings based on the class, stance, or action bar page
function addon:get_action_button_slot(action_slot)
if (addon.class_name == "ROGUE" or addon.class_name == "DRUID") and addon.bonusbar_offset ~= 0 and addon.current_actionbar_page == 1 then
if addon.bonusbar_offset == 1 then
return action_slot + 72
elseif addon.bonusbar_offset == 2 then
return action_slot + 84
elseif addon.bonusbar_offset == 3 then
return action_slot + 96
elseif addon.bonusbar_offset == 4 then
return action_slot + 108
end
end
if addon.bonusbar_offset == 5 and addon.current_actionbar_page == 1 then
return action_slot + 120
end
if addon.current_actionbar_page == 2 then
return action_slot + 12
elseif addon.current_actionbar_page == 3 then
return action_slot + 24
elseif addon.current_actionbar_page == 4 then
return action_slot + 36
elseif addon.current_actionbar_page == 5 then
return action_slot + 48
elseif addon.current_actionbar_page == 6 then
return action_slot + 60
end
return action_slot -- Default 1-12
end
-- Handles processing for MULTIACTIONBAR
function addon:process_multiactionbar_slot(bar, bar_button, button)
if not bar or not bar_button then return end
-- Calculate the slot based on the bar and button
local slot
if bar == 0 then
slot = bar_button
elseif bar == 1 then
slot = 60 + bar_button
elseif bar == 2 then
slot = 48 + bar_button
elseif bar == 3 then
slot = 24 + bar_button
elseif bar == 4 then
slot = 36 + bar_button
elseif bar == 5 then
slot = 144 + bar_button
elseif bar == 6 then
slot = 156 + bar_button
elseif bar == 7 then
slot = 168 + bar_button
else
return
end
button.slot = slot
-- Check if the slot has an action assigned
if slot and HasAction(slot) then
button.active_slot = slot
button.icon:SetTexture(GetActionTexture(slot))
button.icon:Show()
end
end
-- Handles processing for BONUSACTIONBUTTON
function addon:process_pet_action_slot(binding, button)
if not PetHasActionBar() then
button.icon:Hide()
button.slot = nil
button.spellid = nil
button.pet_action_index = nil -- Clear pet action index when no pet action bar
return
end
-- Match the button index from the binding
local pet_action_index = tonumber(binding:match("^BONUSACTIONBUTTON(%d+)$"))
if not pet_action_index then return end
-- Get pet action information
local pet_name, pet_texture, is_token, is_active, auto_cast_allowed, auto_cast_enabled, spell_id =
GetPetActionInfo(pet_action_index)
-- Handle the texture if it's a token
if is_token then
pet_texture = _G[pet_texture] or "Interface\\Icons\\" .. pet_texture -- Fallback to WoW's icon folder
end
if pet_texture then
button.icon:SetTexture(pet_texture)
button.icon:Show()
if spell_id then
-- Pet spell
button.slot = nil -- No slot for pet spells
button.spellid = spell_id
button.pet_action_index = nil -- Not a pet mode
else
-- Pet mode (e.g., Stay, Follow, Move To)
button.slot = nil
button.spellid = nil
button.pet_action_index = pet_action_index -- Set pet action index
end
end
end
-- Handles processing for SHAPESHIFTBUTTON bindings
function addon:process_shapeshift_slot(slot, button)
if not slot then return end