-
Notifications
You must be signed in to change notification settings - Fork 6
/
BindingsDialog.lua
116 lines (86 loc) · 2.56 KB
/
BindingsDialog.lua
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
--=============================================================================
--
-- lua/BindingsDialog.lua
--
-- Populate and manage key bindings in options screen.
--
-- Created by Henry Kropf and Charlie Cleveland
-- Copyright 2010, Unknown Worlds Entertainment
--
--=============================================================================
Script.Load("lua/BindingsShared.lua")
local specialKeys = {
[" "] = "SPACE"
}
local LazyLoadMode = true
local ChangedKeybinds = {}
if(Main.GetOptionString("ChangedKeybinds", "") ~= "") then
Main.SetOptionString("ChangedKeybinds", "")
end
--
-- Get the value of the input control
--/
function BindingsUI_GetInputValue(controlId)
if(LazyLoadMode) then
KeyBindInfo:Init()
LazyLoadMode = false
end
return KeyBindInfo:GetBoundKey(controlId) or ""
end
--
-- Set the value of the input control
--/
function BindingsUI_SetInputValue(controlId, controlValue)
if(LazyLoadMode) then
KeyBindInfo:Init()
LazyLoadMode = false
end
if(controlId ~= nil) then
KeyBindInfo:SetKeybind(controlValue, controlId)
if(Client) then
ChangedKeybinds[#ChangedKeybinds+1] = controlId
end
end
end
--
-- Return data in linear array of config elements
-- controlId, "input", name, value
-- controlId, "title", name, instructions
-- controlId, "separator", unused, unused
--/
function BindingsUI_GetBindingsData()
return KeyBindInfo:GetBindingDialogTable()
end
--
-- Returns list of control ids and text to display for each.
--/
function BindingsUI_GetBindingsTranslationData()
local bindingsTranslationData = {}
for i = 0, 255 do
local text = string.upper(string.char(i))
-- Add special values (must match any values in 'defaults' above)
for j = 1, table.count(specialKeys) do
if(specialKeys[j][1] == text) then
text = specialKeys[j][2]
end
end
table.insert(bindingsTranslationData, {i, text})
end
local tableData = table.tostring(bindingsTranslationData)
return bindingsTranslationData
end
--
-- Called when bindings is exited and something was changed.
--/
function BindingsUI_ExitDialog()
Main.ReloadKeyOptions()
if(#ChangedKeybinds ~= 0) then
if(Client) then
Main.SetOptionString("ChangedKeybinds", table.concat(ChangedKeybinds, "@"))
table.clear(ChangedKeybinds)
else
table.clear(ChangedKeybinds)
Main.SetOptionString("ChangedKeybinds", "")
end
end
end