[Options] More widget checks and names changes
This commit is contained in:
parent
0c3406ada5
commit
fd1e3a1379
5 changed files with 33 additions and 25 deletions
|
@ -10,14 +10,14 @@ VMFModsKeyMap = {
|
||||||
}
|
}
|
||||||
|
|
||||||
-- ["mod_name"]["setting_id"] = {
|
-- ["mod_name"]["setting_id"] = {
|
||||||
-- "action_name",
|
-- "function_name",
|
||||||
-- {"primary_key", "special_key", "special_key", "special_key"}
|
-- {"primary_key", "special_key", "special_key", "special_key"}
|
||||||
-- }
|
-- }
|
||||||
-- Special Keys: "ctrl" / "shift" / "alt"
|
-- Special Keys: "ctrl" / "shift" / "alt"
|
||||||
local _raw_keybinds = {}
|
local _raw_keybinds = {}
|
||||||
|
|
||||||
-- ["primary_key"] = {
|
-- ["primary_key"] = {
|
||||||
-- {"mod_name", "action_name", ctrl_used(bool), alt_used(bool), shift_used(bool)},
|
-- {"mod_name", "function_name", ctrl_used(bool), alt_used(bool), shift_used(bool)},
|
||||||
-- {},
|
-- {},
|
||||||
-- {},
|
-- {},
|
||||||
-- ...
|
-- ...
|
||||||
|
@ -36,7 +36,7 @@ local function apply_keybinds()
|
||||||
|
|
||||||
for mod_name, mod_keybinds in pairs(_raw_keybinds) do
|
for mod_name, mod_keybinds in pairs(_raw_keybinds) do
|
||||||
for _, keybind in pairs(mod_keybinds) do
|
for _, keybind in pairs(mod_keybinds) do
|
||||||
local action_name = keybind[1]
|
local function_name = keybind[1]
|
||||||
local primary_key = keybind[2][1]
|
local primary_key = keybind[2][1]
|
||||||
|
|
||||||
local special_key1 = keybind[2][2]
|
local special_key1 = keybind[2][2]
|
||||||
|
@ -57,7 +57,7 @@ local function apply_keybinds()
|
||||||
|
|
||||||
_optimized_keybinds[primary_key] = _optimized_keybinds[primary_key] or {}
|
_optimized_keybinds[primary_key] = _optimized_keybinds[primary_key] or {}
|
||||||
table.insert(_optimized_keybinds[primary_key], {
|
table.insert(_optimized_keybinds[primary_key], {
|
||||||
mod_name, action_name,
|
mod_name, function_name,
|
||||||
special_keys["ctrl"],
|
special_keys["ctrl"],
|
||||||
special_keys["alt"],
|
special_keys["alt"],
|
||||||
special_keys["shift"]
|
special_keys["shift"]
|
||||||
|
@ -71,17 +71,17 @@ end
|
||||||
-- ####################################################################################################################
|
-- ####################################################################################################################
|
||||||
|
|
||||||
-- use it directly only for dedugging purposes, otherwise use keybind widget
|
-- use it directly only for dedugging purposes, otherwise use keybind widget
|
||||||
-- setting_id [string] - keybind identifyer for certain mod
|
-- setting_id [string] - keybind identifyer for certain mod
|
||||||
-- action_name [string] - name of some mod.function which will be called when keybind is pressed
|
-- function_name [string] - name of some mod.function which will be called when keybind is pressed
|
||||||
-- keys [table] = {"primary_key", "2nd_key" [optional], "3rd_key" [optional], "4th_key" [optional]}
|
-- keys [table] = {"primary_key", "2nd_key" [optional], "3rd_key" [optional], "4th_key" [optional]}
|
||||||
-- 2, 3, 4 keys can contain words "ctrl", "alt", "shift" (lowercase)
|
-- 2, 3, 4 keys can contain words "ctrl", "alt", "shift" (lowercase)
|
||||||
VMFMod.keybind = function (self, setting_id, action_name, keys)
|
VMFMod.keybind = function (self, setting_id, function_name, keys)
|
||||||
|
|
||||||
if keys[1] then
|
if keys[1] then
|
||||||
|
|
||||||
local mod_keybinds = _raw_keybinds[self:get_name()] or {}
|
local mod_keybinds = _raw_keybinds[self:get_name()] or {}
|
||||||
|
|
||||||
mod_keybinds[setting_id] = {action_name, keys}
|
mod_keybinds[setting_id] = {function_name, keys}
|
||||||
|
|
||||||
_raw_keybinds[self:get_name()] = mod_keybinds
|
_raw_keybinds[self:get_name()] = mod_keybinds
|
||||||
else
|
else
|
||||||
|
|
|
@ -145,6 +145,10 @@ end
|
||||||
local function initialize_group_data(mod, data, localize, collapsed_widgets)
|
local function initialize_group_data(mod, data, localize, collapsed_widgets)
|
||||||
local new_data = initialize_generic_widget_data(mod, data, localize)
|
local new_data = initialize_generic_widget_data(mod, data, localize)
|
||||||
|
|
||||||
|
if not data.sub_widgets or not (#data.sub_widgets > 0) then
|
||||||
|
vmf.throw_error("[widget \"%s\" (group)]: must have at least 1 sub_widget", data.setting_id)
|
||||||
|
end
|
||||||
|
|
||||||
new_data.is_collapsed = collapsed_widgets[data.setting_id]
|
new_data.is_collapsed = collapsed_widgets[data.setting_id]
|
||||||
|
|
||||||
return new_data
|
return new_data
|
||||||
|
@ -193,6 +197,10 @@ local function validate_dropdown_data(data)
|
||||||
data.setting_id)
|
data.setting_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if #data.options < 2 then
|
||||||
|
vmf.throw_error("[widget \"%s\" (dropdown)]: 'options' table must have at least 2 elements", data.setting_id)
|
||||||
|
end
|
||||||
|
|
||||||
local default_value = data.default_value
|
local default_value = data.default_value
|
||||||
local default_value_match = false
|
local default_value_match = false
|
||||||
local used_values = {}
|
local used_values = {}
|
||||||
|
@ -289,9 +297,9 @@ local allowed_keybind_triggers = {
|
||||||
held = true
|
held = true
|
||||||
}
|
}
|
||||||
local allowed_keybind_types = {
|
local allowed_keybind_types = {
|
||||||
action_call = true,
|
function_call = true,
|
||||||
view_toggle = true,
|
view_toggle = true,
|
||||||
mod_toggle = true
|
mod_toggle = true
|
||||||
}
|
}
|
||||||
local allowed_special_keys = {
|
local allowed_special_keys = {
|
||||||
ctrl = true,
|
ctrl = true,
|
||||||
|
@ -305,16 +313,16 @@ local function validate_keybind_data(data)
|
||||||
|
|
||||||
if not allowed_keybind_triggers[data.keybind_trigger] then
|
if not allowed_keybind_triggers[data.keybind_trigger] then
|
||||||
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_trigger' field is required and must contain string " ..
|
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_trigger' field is required and must contain string " ..
|
||||||
"\"action_call\", \"view_toggle\" or \"mod_toggle\"", data.setting_id)
|
"\"pressed\", \"released\" or \"held\"", data.setting_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
local keybind_type = data.keybind_type
|
local keybind_type = data.keybind_type
|
||||||
if not allowed_keybind_types[keybind_type] then
|
if not allowed_keybind_types[keybind_type] then
|
||||||
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_type' field is required and must contain string " ..
|
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_type' field is required and must contain string " ..
|
||||||
"\"pressed\", \"released\" or \"held\"", data.setting_id)
|
"\"function_call\", \"view_toggle\" or \"mod_toggle\"", data.setting_id)
|
||||||
end
|
end
|
||||||
if keybind_type == "action_call" and type(data.action_name) ~= "string" then
|
if keybind_type == "function_call" and type(data.function_name) ~= "string" then
|
||||||
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_type' is set to \"action_call\" so 'action_name' " ..
|
vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_type' is set to \"function_call\" so 'function_name' " ..
|
||||||
"field is required and must have 'string' type", data.setting_id)
|
"field is required and must have 'string' type", data.setting_id)
|
||||||
end
|
end
|
||||||
if keybind_type == "view_toggle" and type(data.view_name) ~= "string" then
|
if keybind_type == "view_toggle" and type(data.view_name) ~= "string" then
|
||||||
|
@ -359,7 +367,7 @@ local function initialize_keybind_data(mod, data, localize)
|
||||||
new_data.keybind_global = data.keybind_global -- optional
|
new_data.keybind_global = data.keybind_global -- optional
|
||||||
new_data.keybind_trigger = data.keybind_trigger
|
new_data.keybind_trigger = data.keybind_trigger
|
||||||
new_data.keybind_type = data.keybind_type
|
new_data.keybind_type = data.keybind_type
|
||||||
new_data.action_name = data.action_name -- required, if (keybind_type == "action_call")
|
new_data.function_name = data.function_name -- required, if (keybind_type == "function_call")
|
||||||
new_data.view_name = data.view_name -- required, if (keybind_type == "view_toggle")
|
new_data.view_name = data.view_name -- required, if (keybind_type == "view_toggle")
|
||||||
|
|
||||||
validate_keybind_data(new_data)
|
validate_keybind_data(new_data)
|
||||||
|
@ -534,7 +542,7 @@ local function initialize_default_settings_and_keybinds(mod, initialized_widgets
|
||||||
mod:set(data.setting_id, data.default_value)
|
mod:set(data.setting_id, data.default_value)
|
||||||
end
|
end
|
||||||
if data.type == "keybind" then
|
if data.type == "keybind" then
|
||||||
mod:keybind(data.setting_id, data.action_name, mod:get(data.setting_id))
|
mod:keybind(data.setting_id, data.function_name, mod:get(data.setting_id))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -81,7 +81,7 @@ vmf.initialize_mod_options_legacy = function (mod, widgets_definition)
|
||||||
new_widget_definition.decimals_number = current_widget.decimals_number -- numeric [optional]
|
new_widget_definition.decimals_number = current_widget.decimals_number -- numeric [optional]
|
||||||
new_widget_definition.options = current_widget.options -- dropdown
|
new_widget_definition.options = current_widget.options -- dropdown
|
||||||
new_widget_definition.default_value = current_widget.default_value -- all
|
new_widget_definition.default_value = current_widget.default_value -- all
|
||||||
new_widget_definition.action_name = current_widget.action -- keybind [optional?]
|
new_widget_definition.function_name = current_widget.action -- keybind [optional?]
|
||||||
new_widget_definition.show_widget_condition = current_widget.show_widget_condition -- all
|
new_widget_definition.show_widget_condition = current_widget.show_widget_condition -- all
|
||||||
new_widget_definition.parent_index = parent_number -- all [gen]
|
new_widget_definition.parent_index = parent_number -- all [gen]
|
||||||
|
|
||||||
|
|
|
@ -2654,7 +2654,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
|
||||||
setting_id = widget_definition.setting_id,
|
setting_id = widget_definition.setting_id,
|
||||||
widget_type = widget_definition.type,
|
widget_type = widget_definition.type,
|
||||||
|
|
||||||
action = widget_definition.action_name,
|
action = widget_definition.function_name,
|
||||||
keybind_text = widget_definition.keybind_text,
|
keybind_text = widget_definition.keybind_text,
|
||||||
default_value = widget_definition.default_value,
|
default_value = widget_definition.default_value,
|
||||||
parent_widget_number = widget_definition.parent_index,
|
parent_widget_number = widget_definition.parent_index,
|
||||||
|
|
|
@ -9,8 +9,8 @@ vmf_mod_data.options = {
|
||||||
type = "keybind",
|
type = "keybind",
|
||||||
default_value = {"f4"},
|
default_value = {"f4"},
|
||||||
keybind_trigger = "pressed",
|
keybind_trigger = "pressed",
|
||||||
keybind_type = "action_call",
|
keybind_type = "function_call",
|
||||||
action_name = "open_vmf_options"
|
function_name = "open_vmf_options"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
setting_id = "vmf_options_scrolling_speed",
|
setting_id = "vmf_options_scrolling_speed",
|
||||||
|
@ -39,8 +39,8 @@ vmf_mod_data.options = {
|
||||||
type = "keybind",
|
type = "keybind",
|
||||||
default_value = {},
|
default_value = {},
|
||||||
keybind_trigger = "pressed",
|
keybind_trigger = "pressed",
|
||||||
keybind_type = "action_call",
|
keybind_type = "function_call",
|
||||||
action_name = "toggle_developer_console"
|
function_name = "toggle_developer_console"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
setting_id = "show_network_debug_info",
|
setting_id = "show_network_debug_info",
|
||||||
|
|
Loading…
Add table
Reference in a new issue