-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFastBinding.lua
More file actions
151 lines (124 loc) · 4.14 KB
/
FastBinding.lua
File metadata and controls
151 lines (124 loc) · 4.14 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
FastBinding.Frame = CreateFrame("Frame");
FastBinding.Enabled = false;
FastBinding.UIAddon = "WoW Vanilla";
local FBDarkOverlay
-- Plugin enabler
function FastBinding.Enable(enable)
FastBinding.Enabled = enable;
if not FBDarkOverlay then
FBDarkOverlay = CreateFrame("Frame", "FBDarkOverlay", UIParent)
FBDarkOverlay:SetAllPoints(UIParent)
FBDarkOverlay.texture = FBDarkOverlay:CreateTexture()
FBDarkOverlay.texture:SetAllPoints(FBDarkOverlay)
FBDarkOverlay.texture:SetTexture(0, 0, 0, 0.7)
end
if enable then
FastBinding.Frame:EnableKeyboard(true);
FastBinding.Frame:SetScript("OnKeyDown", function()
local key = arg1;
this:OnKeyDown(key);
end);
FBPrint.Chat("Enabled binding. Press ENTER or ESCAPE (with mouse out of action bars) to disable", "green");
FBDarkOverlay:Show()
else
FastBinding.Frame:EnableKeyboard(nil);
FastBinding.Frame:SetScript("OnKeyDown", nil);
FBPrint.Chat("Disabled binding", "green");
FBDarkOverlay:Hide()
end
end
-- Handler: /fb slash command
SLASH_FASTBINDING1 = "/fb";
SlashCmdList["FASTBINDING"] = function(cmd)
if(cmd == "") then
FastBinding.Enable(not FastBinding.Enabled)
elseif(cmd == "debug") then
if(FastBinding.Debug) then
FastBinding.Debug = false
FBPrint.Chat("Debug mode disabled")
else
FastBinding.Debug = true
FBPrint.Chat("Debug mode enabled")
end
else
if(FastBinding.Debug) then
FBPrint.Debug(GetBindingAction(cmd))
end
end
end
-- Handler: on load to detect UIAddon
FastBinding.Frame:RegisterEvent("PLAYER_LOGIN")
FastBinding.Frame:SetScript("OnEvent", function()
for i = 1, GetNumAddOns() do
local name, title, _, enabled, loadable, reason = GetAddOnInfo(i)
if IsAddOnLoaded(i) then
if IsAcceptedUIAddon(name) then
FastBinding.UIAddon = name
break
end
end
end
if(FastBinding.Debug) then
FBPrint.Chat("Loaded FastBinding as Debug", "yellow")
else
FBPrint.Chat("Loaded FastBinding", "yellow")
end
FBPrint.Chat("Detected '"..FastBinding.UIAddon.."' as UI Manager", "yellow")
end)
-- Handler: on key down to detect pressed key
function FastBinding.Frame:OnKeyDown(key)
local frame = GetMouseFocus():GetName();
-- ENTER always disables FastBinding
if key == "ENTER" then
FastBinding.Enable(false)
return
end
-- Ignore modifier keys
if key == "ALT" or key == "SHIFT" or key == "CTRL" then
return
end
if IsActionButton(frame, FastBinding.UIAddon) then
-- ESCAPE on ActionButton resets binding
if key == "ESCAPE" then
FastBinding.ResetActionButton(frame)
else
FastBinding.SetKeyToActionButton(key, frame)
end
else
-- ESCAPE out ActionButton disables FB
if key == "ESCAPE" then
FastBinding.Enable(false)
end
end
end
-- Actioner: Set binding
function FastBinding.SetKeyToActionButton(key, actionButton)
local bindingName = GetBindingName(actionButton, FastBinding.UIAddon);
if (IsShiftKeyDown()) then
key = "SHIFT-"..key;
end
if (IsControlKeyDown()) then
key = "CTRL-"..key;
end
if (IsAltKeyDown()) then
key = "ALT-"..key;
end
local usedKey = GetBindingKey(bindingName);
if usedKey then
SetBinding(usedKey);
end
if SetBinding(key, bindingName, 1) then
FBPrint.Chat("Set "..key.. " to "..bindingName);
end
SaveBindings(2);
end
-- Actioner: Reset binding
function FastBinding.ResetActionButton(actionButton)
local bindingName = GetBindingName(actionButton, FastBinding.UIAddon);
local usedKey = GetBindingKey(bindingName);
if usedKey then
SetBinding(usedKey);
FBPrint.Chat("Removed "..usedKey.." from "..bindingName);
SaveBindings(2);
end
end