-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathkeybind.examples.lua
More file actions
78 lines (68 loc) · 3.71 KB
/
Copy pathkeybind.examples.lua
File metadata and controls
78 lines (68 loc) · 3.71 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
--Example file of how to create a keybind panel using the details framework
local detailsFramework = DetailsFramework
--a table with a list of all keybinds already set, usually this is stored in the addon saved variables, but for the example, it's just an empty table
local keybindings = {}
--[[
a keybindTable store the information of a keybind set, its fields are:
name: string -> a name to identify the keybind
keybind: string -> the key or combination of keys that trigger the keybind, for example "CTRL-SHIFT-A"
macro: string -> the macro text if the keybind runs a macro, if it's not a macro, this field can be nil or empty
action: string -> which action the keybind trigger, example: a 'spellId' to cast a spell, 'macro', 'target', 'focus', 'togglemenu'
icon: string -> an icon for the keybind
--]]
---callback function that will be called when a keybind is modified, removed, or when the conditions, name, icon or macro of a keybind is changed, the parameters are:
---@param keybindFrame df_keybindframe
---@param type string "modified", "removed", "conditions", "name", "icon", "macro"
---@param keybindTable df_keybind?
---@param keybindPressed string?
---@param removedIndex number?
---@param macroText string?
local callback = function(keybindFrame, type, keybindTable, keybindPressed, removedIndex, macroText)
if (not keybindFrame.options.can_modify_keybind_data) then
--the key to active the keybind has changed
if (type == "modified") then
---@cast keybindTable df_keybind
if (type(keybindPressed) == "string") then
--if can_modify_keybind_data is true, this part won't be necessary
--since the keybindTable will be already updated with the new keybindPressed value
keybindTable.keybind = keybindPressed
end
--the macro text has changed
elseif (type == "macro") then
---@cast keybindTable df_keybind
if (type(macroText) == "string") then
--if can_modify_keybind_data is true, this part won't be necessary
--it is here for an example
keybindTable.macro = macroText
end
--the keybind has been removed
elseif (type == "removed") then
table.remove(keybindings, removedIndex)
end
end
end
local parent = UIParent
local frameName = "KeybindFrameName"
local keybindOptions = {
--when 'can_modify_keybind_data' the internal code won't change the keybindTable
--it'll be the responsibility of the callback function to update the keybindTable
--when a keybind is modified, removed, or when the conditions, name, icon or macro of a keybind is changed
--this is useful when the addon want to have more control over how the keybind data is stored and updated
--for example, if the addon want to store the keybinds in a different format or
--if it want to have some validation before updating the keybindTable
can_modify_keybind_data = true,
--optional settings, values are the default ones
width = 580,
height = 500,
edit_width = 400,
edit_height = 0,
scroll_width = 580,
scroll_height = 480,
amount_lines = 18,
line_height = 26,
show_spells = true,
show_unitcontrols = true,
show_macros = true,
}
local keybindFrame = detailsFramework:CreateKeybindFrame(parent, frameName, keybindOptions, callback, keybindings)
keybindFrame:SetPoint("topleft", parent, "topleft", 10, -10)