Repository navigation
Expand file tree
/
Copy pathKeybindFrame.lua
More file actions
374 lines (327 loc) · 13.4 KB
/
Copy pathKeybindFrame.lua
File metadata and controls
374 lines (327 loc) · 13.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
local detectedKey = nil
local detectedModifiers = {}
local selectedType = ""
local characterSpecificKeybindsCheckbox
local keybindTable = {
{
label = "Summon mount",
name = "normal",
iconPath = "Interface\\Icons\\Ability_Mount_RidingHorse",
icon = "Ability_Mount_RidingHorse",
macro = "/rms summon",
macroName = "RMS normal",
tooltip = "Summon a random flying or ground mount, \nbased on your current zone."
},
{
label = "Ground mount",
name = "ground",
iconPath = "Interface\\Icons\\ability_mount_raptor",
icon = "ability_mount_raptor",
macro = "/rms summonground",
macroName = "RMS ground",
},
{
label = "Small mount",
name = "small",
iconPath = "Interface\\Icons\\Inv_alpacamount_brown",
icon = "Inv_alpacamount_brown",
macro = "/rms summonsmall",
macroName = "RMS small",
tooltip =
"Summon a random flying or ground mount, \nbased on your current zone.\nIt will always pick a small mount."
},
{
label = "Aquatic mount",
name = "aquatic",
iconPath = "Interface\\Icons\\inv_stingray2mount_teal",
icon = "inv_stingray2mount_teal",
macro = "/rms summonswim",
macroName = "RMS aquatic",
tooltip =
"Summon a random aquatic mount. \nNote that aquatic mounts that can fly will only \ncount as aquatic if you are using steady flying."
},
{
label = "Repair",
name = "repair",
iconPath = "Interface\\Icons\\inv_hammer_20",
icon = "inv_hammer_20",
macro = "/rms repair",
macroName = "RMS repair"
},
{
label = "Transmog",
name = "transmog",
iconPath = "Interface\\Icons\\ability_ardenweald_mage",
icon = "ability_ardenweald_mage",
macro = "/rms transmog",
macroName = "RMS transmog"
},
{
label = "Auction house",
name = "auctionHouse",
iconPath = "Interface\\Icons\\Inv_misc_coinbag_special",
icon = "Inv_misc_coinbag_special",
macro = "/rms auctionHouse",
macroName = "RMS auctionHouse"
},
{
label = "Mailbox",
name = "mailbox",
iconPath = "Interface\\Icons\\inv_letter_15",
icon = "inv_letter_15",
macro = "/rms mailbox",
macroName = "RMS mailbox",
},
{
label = "Multiple riders",
name = "multiple",
iconPath = "Interface\\Icons\\ability_mount_camel_brown",
icon = "ability_mount_camel_brown",
macro = "/rms multiple",
macroName = "RMS multiple"
}
}
local function applySummonKeyBinding()
ClearOverrideBindings(RuthesMS.frames.mountSelectorFrame.frame)
local function bindKey(keyName, buttonName)
if keyName then
local formattedKey = string.gsub(keyName, "+", "-")
SetOverrideBindingClick(RuthesMS.frames.mountSelectorFrame.frame, true, formattedKey, buttonName)
end
end
bindKey(RuthesMS.keybinds.normal, "RuthesMSRandomMountButton")
bindKey(RuthesMS.keybinds.small, "RuthesMSRandomSmallMountButton")
bindKey(RuthesMS.keybinds.ground, "RuthesMSRandomGroundMountButton")
bindKey(RuthesMS.keybinds.aquatic, "RuthesMSRandomAquaticMountButton")
bindKey(RuthesMS.keybinds.repair, "RuthesMSRandomRepairMountButton")
bindKey(RuthesMS.keybinds.transmog, "RuthesMSRandomTransmogMountButton")
bindKey(RuthesMS.keybinds.auctionHouse, "RuthesMSRandomAuctionHouseMountButton")
bindKey(RuthesMS.keybinds.mailbox, "RuthesMSRandomMailboxMountButton")
bindKey(RuthesMS.keybinds.multiple, "RuthesMSRandomMultipleMountButton")
end
-- Ensure Keybinding is Applied After Login
local function loadSummoningKey()
RuthesMS.frames.keybindFrame.delete()
RuthesMS.frames.keybindFrame.create()
-- Reload the checkbox
if characterSpecificKeybindsCheckbox then
characterSpecificKeybindsCheckbox:SetChecked(not RuthesMS.settings.globalKeybinds)
end
applySummonKeyBinding()
end
StaticPopupDialogs["SET_KEYBIND"] = {
text = "Press a key to set as your summon key",
button1 = "Cancel",
button2 = "Delete",
OnAccept = function() end,
OnCancel = function(self)
-- Save & Apply Keybinding
RuthesMS.keybinds[selectedType] = ""
RuthesMS.db.saveSummonKey("", selectedType)
loadSummoningKey()
StaticPopup_Hide("SET_KEYBIND")
end,
OnShow = function(self)
self:EnableKeyboard(true)
self:SetScript("OnKeyDown", function(_, key)
if key == "ESCAPE" then
StaticPopup_Hide("SET_KEYBIND")
return
end
-- Detect Modifier Keys
if key == "LALT" or key == "RALT" or key == "LCTRL" or key == "RCTRL" or key == "LSHIFT" or key == "RSHIFT" then
detectedModifiers[key] = true
return
end
-- Store the actual key pressed
detectedKey = key
end)
self:SetScript("OnKeyUp", function()
if detectedKey then
-- Format the final keybinding string
local keyCombo = ""
if detectedModifiers["LALT"] or detectedModifiers["RALT"] then keyCombo = keyCombo .. "ALT+" end
if detectedModifiers["LCTRL"] or detectedModifiers["RCTRL"] then keyCombo = keyCombo .. "CTRL+" end
if detectedModifiers["LSHIFT"] or detectedModifiers["RSHIFT"] then keyCombo = keyCombo .. "SHIFT+" end
keyCombo = keyCombo .. detectedKey
-- Save & Apply Keybinding
RuthesMS.keybinds[selectedType] = keyCombo
RuthesMS.db.saveSummonKey(keyCombo, selectedType)
loadSummoningKey()
StaticPopup_Hide("SET_KEYBIND")
end
end)
end,
OnHide = function(self)
self:SetScript("OnKeyDown", nil)
self:SetScript("OnKeyUp", nil)
end,
timeout = 0,
whileDead = true,
hideOnEscape = true,
preferredIndex = 3,
}
local function deleteKeybindFrame()
if RuthesMS.frames.keybindFrame.frame then
for _, child in ipairs({ RuthesMS.frames.keybindFrame.frame:GetChildren() }) do
child:Hide()
child:SetParent(nil)
end
RuthesMS.frames.keybindFrame.frame:Hide()
RuthesMS.frames.keybindFrame.frame:SetParent(nil)
RuthesMS.frames.keybindFrame.frame = nil
end
end
local function createAndDragMacro(macroName, macroBody, macroIcon)
local macroIndex = GetMacroIndexByName(macroName)
if macroIndex == 0 then
macroIndex = CreateMacro(macroName, macroIcon, macroBody, true)
else
EditMacro(macroIndex, macroName, macroIcon, macroBody)
end
if macroIndex then
PickupMacro(macroIndex)
end
end
local function createMacroButton(parentFrame, size, position, iconPath, tooltipText, macroName, macroBody, macroIcon)
local button = CreateFrame("Button", nil, parentFrame, "UIPanelButtonTemplate")
button:SetSize(size, size)
button:SetPoint(unpack(position))
button:SetNormalTexture(iconPath)
-- Set up the click handler to create and drag the macro
button:SetScript("OnClick", function()
createAndDragMacro(macroName, macroBody, macroIcon)
end)
-- Add a tooltip
button:EnableMouse(true)
button:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(tooltipText, 1, 1, 1)
GameTooltip:Show()
end)
button:SetScript("OnLeave", function(self)
GameTooltip:Hide()
end)
return button
end
local function createKeybindFrame()
local mountSelectorFrame = RuthesMS.frames.mountSelectorFrame.frame
local keybindFrame = CreateFrame("Frame", "MountSelectorKeybindFrame", mountSelectorFrame,
"BackdropTemplate")
keybindFrame:SetSize(400, 360)
keybindFrame:SetPoint("TOPLEFT", mountSelectorFrame, "TOPLEFT", 20, -65)
local yOffset = 0
local lineHeight = 30
-- Mount type
local mountTypeLabel = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
mountTypeLabel:SetPoint("TOPLEFT", keybindFrame, "TOPLEFT", 0, yOffset)
mountTypeLabel:SetText("Mount Type")
-- Set keybind
local setKeybindLabel = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
setKeybindLabel:SetPoint("TOP", keybindFrame, "TOP", 0, yOffset)
setKeybindLabel:SetText("Keybind")
-- Action button
local setActionButtonLabel = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
setActionButtonLabel:SetPoint("TOPRIGHT", keybindFrame, "TOPRIGHT", -40, yOffset)
setActionButtonLabel:SetText("Button")
for index, value in ipairs(keybindTable) do
if (index == 1 or index == 2) then
yOffset = yOffset - lineHeight / 3 -- Add space for the first line
end
-- Mount type
local keybindLabel = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
keybindLabel:SetPoint("TOPLEFT", keybindFrame, "TOPLEFT", 0, yOffset - (index * lineHeight))
keybindLabel:SetText(value.label)
-- Keybind button
if value.noKey then
local label = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("TOP", keybindFrame, "TOP", 0, yOffset - (index * lineHeight))
label:SetText("Not available")
else
local setKeyButton = CreateFrame("Button", nil, keybindFrame, "UIPanelButtonTemplate")
local keybindText = RuthesMS.keybinds[value.name]
if keybindText == "" or keybindText == nil then
keybindText = "Not set"
else
keybindText = RuthesMS.keybinds[value.name]
end
setKeyButton:SetSize(110, 22)
setKeyButton:SetPoint("TOP", keybindFrame, "TOP", -0, yOffset - (index * lineHeight))
setKeyButton:SetText(keybindText)
-- Keybinding Popup (Detects Key Press)
setKeyButton:SetScript("OnClick", function()
detectedKey = nil
detectedModifiers = {}
selectedType = value.name
StaticPopup_Show("SET_KEYBIND")
end)
end
-- Action button icon
createMacroButton(
keybindFrame, -- Parent frame
30, -- Button size
{ "TOPRIGHT", keybindFrame, "TOPRIGHT", -47, yOffset - (index * lineHeight) }, -- Position
value.iconPath, -- Icon path
"Create Summon Macro", -- Tooltip text
value.macroName, -- Macro name
value.macro, -- Macro body
value.icon -- Macro icon
)
-- Tooltip
if (value.tooltip) then
local icon = CreateFrame("Button", nil, keybindFrame)
icon:SetSize(15, 15)
icon:SetPoint("LEFT", keybindLabel, "RIGHT", 5, 0)
local texture = icon:CreateTexture(nil, "BACKGROUND")
texture:SetAllPoints()
texture:SetTexture("Interface\\FriendsFrame\\InformationIcon")
icon:EnableMouse(true)
icon:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(value.tooltip)
GameTooltip:SetAlpha(0)
GameTooltip:Show()
end)
icon:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
end
end
-- Character specific checkbox
characterSpecificKeybindsCheckbox = CreateFrame("CheckButton", "CharacterSpecificKeybindsCheckbox", keybindFrame,
"ChatConfigCheckButtonTemplate")
characterSpecificKeybindsCheckbox:SetPoint("TOPLEFT", keybindFrame, "TOPLEFT", -5,
yOffset - (#keybindTable * lineHeight) - 50)
characterSpecificKeybindsCheckbox:SetScript("OnClick", function(self)
RuthesMS.db.saveGlobalKeybinds(not self:GetChecked())
RuthesMS.frames.keybindFrame.loadSummoningKey()
RuthesMS.buttons.mountButtons.reload()
end)
local characterSpecificKeybindLabel = keybindFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
characterSpecificKeybindLabel:SetPoint("LEFT", characterSpecificKeybindsCheckbox, "RIGHT", 5, 0)
characterSpecificKeybindLabel:SetText("Character specific keybinds")
keybindFrame:Show()
RuthesMS.frames.keybindFrame.frame = keybindFrame
end
local function show()
-- Create if missing
if not RuthesMS.frames.keybindFrame.frame then
RuthesMS.frames.keybindFrame.create()
end
local keybindFrame = RuthesMS.frames.keybindFrame.frame
keybindFrame:Show()
end
local function hide()
local keybindFrame = RuthesMS.frames.keybindFrame.frame
if keybindFrame then
keybindFrame:Hide()
end
end
RuthesMS.frames.keybindFrame = {
frame = nil,
create = createKeybindFrame,
delete = deleteKeybindFrame,
show = show,
hide = hide,
loadSummoningKey = loadSummoningKey,
}