forked from phuein/UserScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeystrip.lua
More file actions
47 lines (41 loc) · 1.35 KB
/
Copy pathkeystrip.lua
File metadata and controls
47 lines (41 loc) · 1.35 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
JunkeeKeyStrip = ZO_Object:Subclass()
function JunkeeKeyStrip:New(name, keybind, callback, alignment)
local obj = ZO_Object.New(self)
obj:Init(name, keybind, callback, alignment)
return obj
end
local function createStripDescriptor(name, keybind, callback, alignment)
return {{
alignment = alignment or KEYBIND_STRIP_ALIGN_LEFT,
name = name,
keybind = keybind,
callback = callback
}}
end
function JunkeeKeyStrip:Init(name, keybind, callback, alignment)
self.stripDescriptor = createStripDescriptor(name, keybind, callback, alignment)
self.wasAdded = false
end
function JunkeeKeyStrip:Add(onlyIfBound)
if (not onlyIfBound or self:IsBound()) then
KEYBIND_STRIP:AddKeybindButtonGroup(self.stripDescriptor)
self.wasAdded = true
end
end
function JunkeeKeyStrip:Remove()
if (self.wasAdded) then
KEYBIND_STRIP:RemoveKeybindButtonGroup(self.stripDescriptor)
self.wasAdded = false
end
end
function JunkeeKeyStrip:IsBound()
-- TODO: if this is too expensive, only call once in the construction and register for keybind events
local layer, category, action = GetActionIndicesFromName(self.stripDescriptor[1]["keybind"])
for binding = 1, GetMaxBindingsPerAction() do
local keyCode,_,_,_,_ = GetActionBindingInfo(layer, category, action, binding)
if (keyCode > 0) then
return true
end
end
return false
end