diff --git a/vmf/scripts/mods/vmf/modules/core/keybindings.lua b/vmf/scripts/mods/vmf/modules/core/keybindings.lua index b3c6ccc..dcacf72 100644 --- a/vmf/scripts/mods/vmf/modules/core/keybindings.lua +++ b/vmf/scripts/mods/vmf/modules/core/keybindings.lua @@ -10,14 +10,14 @@ VMFModsKeyMap = { } -- ["mod_name"]["setting_id"] = { --- "action_name", +-- "function_name", -- {"primary_key", "special_key", "special_key", "special_key"} -- } -- Special Keys: "ctrl" / "shift" / "alt" local _raw_keybinds = {} -- ["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 _, keybind in pairs(mod_keybinds) do - local action_name = keybind[1] + local function_name = keybind[1] local primary_key = keybind[2][1] local special_key1 = keybind[2][2] @@ -57,7 +57,7 @@ local function apply_keybinds() _optimized_keybinds[primary_key] = _optimized_keybinds[primary_key] or {} table.insert(_optimized_keybinds[primary_key], { - mod_name, action_name, + mod_name, function_name, special_keys["ctrl"], special_keys["alt"], special_keys["shift"] @@ -71,17 +71,17 @@ end -- #################################################################################################################### -- use it directly only for dedugging purposes, otherwise use keybind widget --- setting_id [string] - keybind identifyer for certain mod --- action_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]} --- 2, 3, 4 keys can contain words "ctrl", "alt", "shift" (lowercase) -VMFMod.keybind = function (self, setting_id, action_name, keys) +-- setting_id [string] - keybind identifyer for certain mod +-- 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]} +-- 2, 3, 4 keys can contain words "ctrl", "alt", "shift" (lowercase) +VMFMod.keybind = function (self, setting_id, function_name, keys) if keys[1] then 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 else diff --git a/vmf/scripts/mods/vmf/modules/core/options.lua b/vmf/scripts/mods/vmf/modules/core/options.lua index c569953..9913318 100644 --- a/vmf/scripts/mods/vmf/modules/core/options.lua +++ b/vmf/scripts/mods/vmf/modules/core/options.lua @@ -145,6 +145,10 @@ end local function initialize_group_data(mod, data, localize, collapsed_widgets) 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] return new_data @@ -193,6 +197,10 @@ local function validate_dropdown_data(data) data.setting_id) 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_match = false local used_values = {} @@ -289,9 +297,9 @@ local allowed_keybind_triggers = { held = true } local allowed_keybind_types = { - action_call = true, - view_toggle = true, - mod_toggle = true + function_call = true, + view_toggle = true, + mod_toggle = true } local allowed_special_keys = { ctrl = true, @@ -305,16 +313,16 @@ local function validate_keybind_data(data) if not allowed_keybind_triggers[data.keybind_trigger] then 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 local keybind_type = data.keybind_type if not allowed_keybind_types[keybind_type] then 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 - if keybind_type == "action_call" and type(data.action_name) ~= "string" then - vmf.throw_error("[widget \"%s\" (keybind)]: 'keybind_type' is set to \"action_call\" so 'action_name' " .. + if keybind_type == "function_call" and type(data.function_name) ~= "string" then + 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) end 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_trigger = data.keybind_trigger 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") 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) end 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 diff --git a/vmf/scripts/mods/vmf/modules/legacy/options.lua b/vmf/scripts/mods/vmf/modules/legacy/options.lua index 9ebe98c..c38e13a 100644 --- a/vmf/scripts/mods/vmf/modules/legacy/options.lua +++ b/vmf/scripts/mods/vmf/modules/legacy/options.lua @@ -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.options = current_widget.options -- dropdown 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.parent_index = parent_number -- all [gen] diff --git a/vmf/scripts/mods/vmf/modules/ui/options/vmf_options_view.lua b/vmf/scripts/mods/vmf/modules/ui/options/vmf_options_view.lua index 3967434..1865cd6 100644 --- a/vmf/scripts/mods/vmf/modules/ui/options/vmf_options_view.lua +++ b/vmf/scripts/mods/vmf/modules/ui/options/vmf_options_view.lua @@ -2654,7 +2654,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id) setting_id = widget_definition.setting_id, widget_type = widget_definition.type, - action = widget_definition.action_name, + action = widget_definition.function_name, keybind_text = widget_definition.keybind_text, default_value = widget_definition.default_value, parent_widget_number = widget_definition.parent_index, diff --git a/vmf/scripts/mods/vmf/modules/vmf_options.lua b/vmf/scripts/mods/vmf/modules/vmf_options.lua index 5498391..c166f69 100644 --- a/vmf/scripts/mods/vmf/modules/vmf_options.lua +++ b/vmf/scripts/mods/vmf/modules/vmf_options.lua @@ -9,8 +9,8 @@ vmf_mod_data.options = { type = "keybind", default_value = {"f4"}, keybind_trigger = "pressed", - keybind_type = "action_call", - action_name = "open_vmf_options" + keybind_type = "function_call", + function_name = "open_vmf_options" }, { setting_id = "vmf_options_scrolling_speed", @@ -39,8 +39,8 @@ vmf_mod_data.options = { type = "keybind", default_value = {}, keybind_trigger = "pressed", - keybind_type = "action_call", - action_name = "toggle_developer_console" + keybind_type = "function_call", + function_name = "toggle_developer_console" }, { setting_id = "show_network_debug_info",