Rename 'setting_name' to 'setting_id'

This commit is contained in:
Azumgi 2018-09-13 09:49:40 +03:00
parent 9b93f0c232
commit 0c3406ada5
5 changed files with 68 additions and 68 deletions

View file

@ -70,17 +70,17 @@ end
--[[ --[[
EVENT: on_setting_changed (setting_name) EVENT: on_setting_changed (setting_id)
Is called on `mod:set` call with the 3rd parameter set to 'true'. All the mod's settings changes done under Is called on `mod:set` call with the 3rd parameter set to 'true'. All the mod's settings changes done under
the VMF's hood call this event. the VMF's hood call this event.
* setting_name [string]: name of the setting that was changed * setting_id [string]: name of the setting that was changed
--]] --]]
function vmf.mod_setting_changed_event(mod, setting_name) function vmf.mod_setting_changed_event(mod, setting_id)
local event_name = "on_setting_changed" local event_name = "on_setting_changed"
run_event(mod, event_name, setting_name) run_event(mod, event_name, setting_id)
end end

View file

@ -9,7 +9,7 @@ VMFModsKeyMap = {
xb1 = {} xb1 = {}
} }
-- ["mod_name"]["setting_name"] = { -- ["mod_name"]["setting_id"] = {
-- "action_name", -- "action_name",
-- {"primary_key", "special_key", "special_key", "special_key"} -- {"primary_key", "special_key", "special_key", "special_key"}
-- } -- }
@ -71,25 +71,25 @@ end
-- #################################################################################################################### -- ####################################################################################################################
-- use it directly only for dedugging purposes, otherwise use keybind widget -- use it directly only for dedugging purposes, otherwise use keybind widget
-- setting_name [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 -- 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]} -- 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_name, action_name, keys) VMFMod.keybind = function (self, setting_id, action_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_name] = {action_name, keys} mod_keybinds[setting_id] = {action_name, keys}
_raw_keybinds[self:get_name()] = mod_keybinds _raw_keybinds[self:get_name()] = mod_keybinds
else else
local mod_keybinds = _raw_keybinds[self:get_name()] local mod_keybinds = _raw_keybinds[self:get_name()]
if mod_keybinds and mod_keybinds[setting_name] then if mod_keybinds and mod_keybinds[setting_id] then
mod_keybinds[setting_name] = nil mod_keybinds[setting_id] = nil
end end
end end

View file

@ -39,11 +39,11 @@ end
--[[ --[[
Sets mod's setting to a given value. If setting is used in some option widget, make sure given Sets mod's setting to a given value. If setting is used in some option widget, make sure given
value matches one of the predefined values in this widget. value matches one of the predefined values in this widget.
* setting_name [string] : setting name (can contain any characters lua-string can) * setting_id [string] : setting's identifier
* setting_value [anything]: setting value (can be any SJSON serializable format) * setting_value [anything]: setting value (can be any SJSON serializable format)
* notify_mod [bool] : if 'true', calls 'mod.on_setting_changed' event * notify_mod [bool] : if 'true', calls 'mod.on_setting_changed' event
--]] --]]
function VMFMod:set(setting_name, setting_value, notify_mod) function VMFMod:set(setting_id, setting_value, notify_mod)
local mod_name = self:get_name() local mod_name = self:get_name()
if not _mods_settings[mod_name] then if not _mods_settings[mod_name] then
@ -51,12 +51,12 @@ function VMFMod:set(setting_name, setting_value, notify_mod)
end end
local mod_settings = _mods_settings[mod_name] local mod_settings = _mods_settings[mod_name]
mod_settings[setting_name] = type(setting_value) == "table" and table.clone(setting_value) or setting_value mod_settings[setting_id] = type(setting_value) == "table" and table.clone(setting_value) or setting_value
_there_are_unsaved_changes = true _there_are_unsaved_changes = true
if notify_mod then if notify_mod then
vmf.mod_setting_changed_event(self, setting_name) vmf.mod_setting_changed_event(self, setting_id)
end end
end end
@ -64,12 +64,12 @@ end
--[[ --[[
Returns a mod's setting. Don't call this method for table settings very frequently, because tables are cloned on every Returns a mod's setting. Don't call this method for table settings very frequently, because tables are cloned on every
call. call.
* setting_name [string]: setting name (can contain any characters lua-string can) * setting_id [string]: setting's identifier
--]] --]]
function VMFMod:get(setting_name) function VMFMod:get(setting_id)
local mod_name = self:get_name() local mod_name = self:get_name()
local mod_settings = _mods_settings[mod_name] local mod_settings = _mods_settings[mod_name]
local setting_value = mod_settings and mod_settings[setting_name] local setting_value = mod_settings and mod_settings[setting_id]
return type(setting_value) == "table" and table.clone(setting_value) or setting_value return type(setting_value) == "table" and table.clone(setting_value) or setting_value
end end

View file

@ -1262,13 +1262,13 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
end end
local mod_name = content.mod_name local mod_name = content.mod_name
local setting_name = content.setting_name local setting_id = content.setting_id
local old_value = content.is_checkbox_checked local old_value = content.is_checkbox_checked
local new_value = not old_value local new_value = not old_value
content.is_checkbox_checked = new_value content.is_checkbox_checked = new_value
content.callback_setting_changed(mod_name, setting_name, old_value, new_value) content.callback_setting_changed(mod_name, setting_id, old_value, new_value)
end end
end end
@ -1334,7 +1334,7 @@ local function create_checkbox_widget(widget_definition, scenegraph_id)
tooltip_text = widget_definition.tooltip, tooltip_text = widget_definition.tooltip,
mod_name = widget_definition.mod_name, mod_name = widget_definition.mod_name,
setting_name = widget_definition.setting_id, setting_id = widget_definition.setting_id,
widget_type = widget_definition.type, widget_type = widget_definition.type,
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,
@ -1549,7 +1549,7 @@ local function create_group_widget(widget_definition, scenegraph_id)
mod_name = widget_definition.mod_name, mod_name = widget_definition.mod_name,
setting_name = widget_definition.setting_id, setting_id = widget_definition.setting_id,
widget_type = widget_definition.type, widget_type = widget_definition.type,
parent_widget_number = widget_definition.parent_index, parent_widget_number = widget_definition.parent_index,
show_widget_condition = show_widget_condition show_widget_condition = show_widget_condition
@ -1841,10 +1841,10 @@ local function create_dropdown_widget(widget_definition, scenegraph_id, scenegra
end end
local mod_name = content.mod_name local mod_name = content.mod_name
local setting_name = content.setting_name local setting_id = content.setting_id
local new_value = content.options_values[content.current_option_number] local new_value = content.options_values[content.current_option_number]
content.callback_setting_changed(mod_name, setting_name, old_value, new_value) content.callback_setting_changed(mod_name, setting_id, old_value, new_value)
end end
end end
@ -1911,7 +1911,7 @@ local function create_dropdown_widget(widget_definition, scenegraph_id, scenegra
tooltip_text = widget_definition.tooltip, tooltip_text = widget_definition.tooltip,
mod_name = widget_definition.mod_name, mod_name = widget_definition.mod_name,
setting_name = widget_definition.setting_id, setting_id = widget_definition.setting_id,
widget_type = widget_definition.type, widget_type = widget_definition.type,
options_texts = options_texts, options_texts = options_texts,
@ -2298,10 +2298,10 @@ local function create_numeric_widget(widget_definition, scenegraph_id, scenegrap
if content.callback_draw_numeric_menu(content) then if content.callback_draw_numeric_menu(content) then
local mod_name = content.mod_name local mod_name = content.mod_name
local setting_name = content.setting_name local setting_id = content.setting_id
local new_value = content.current_value local new_value = content.current_value
content.callback_setting_changed(mod_name, setting_name, old_value, new_value) content.callback_setting_changed(mod_name, setting_id, old_value, new_value)
end end
end end
@ -2369,7 +2369,7 @@ local function create_numeric_widget(widget_definition, scenegraph_id, scenegrap
right_bracket = "]", right_bracket = "]",
mod_name = widget_definition.mod_name, mod_name = widget_definition.mod_name,
setting_name = widget_definition.setting_id, setting_id = widget_definition.setting_id,
widget_type = widget_definition.type, widget_type = widget_definition.type,
current_value_text = "whatever", current_value_text = "whatever",
@ -2588,7 +2588,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
if content.is_setting_keybind then if content.is_setting_keybind then
if content.callback_setting_keybind(content) then if content.callback_setting_keybind(content) then
content.callback_setting_changed(content.mod_name, content.setting_name, nil, content.keys) content.callback_setting_changed(content.mod_name, content.setting_id, nil, content.keys)
return return
end end
end end
@ -2651,7 +2651,7 @@ local function create_keybind_widget(widget_definition, scenegraph_id)
tooltip_text = widget_definition.tooltip, tooltip_text = widget_definition.tooltip,
mod_name = widget_definition.mod_name, mod_name = widget_definition.mod_name,
setting_name = 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.action_name,
@ -3044,10 +3044,10 @@ end
-- #################################################################################################################### -- ####################################################################################################################
VMFOptionsView.callback_setting_changed = function (self, mod_name, setting_name, old_value, new_value) VMFOptionsView.callback_setting_changed = function (self, mod_name, setting_id, old_value, new_value)
if self.is_setting_changes_applied_immidiately and old_value ~= new_value then if self.is_setting_changes_applied_immidiately and old_value ~= new_value then
get_mod(mod_name):set(setting_name, new_value, true) get_mod(mod_name):set(setting_id, new_value, true)
end end
WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select") WwiseWorld.trigger_event(self.wwise_world, "Play_hud_select")
@ -3189,10 +3189,10 @@ end
VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content) VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content)
local mod_name = widget_content.mod_name local mod_name = widget_content.mod_name
local setting_name = widget_content.setting_name local setting_id = widget_content.setting_id
local is_widget_collapsed = widget_content.is_widget_collapsed local is_widget_collapsed = widget_content.is_widget_collapsed
local widget_number = not setting_name and 1 -- if (setting_name == nil) -> it's header -> #1 local widget_number = not setting_id and 1 -- if (setting_id == nil) -> it's header -> #1
local are_there_visible_sub_widgets = false local are_there_visible_sub_widgets = false
@ -3209,7 +3209,7 @@ VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content)
are_there_visible_sub_widgets = are_there_visible_sub_widgets or widget.content.is_widget_visible are_there_visible_sub_widgets = are_there_visible_sub_widgets or widget.content.is_widget_visible
end end
else else
if widget.content.setting_name == setting_name then if widget.content.setting_id == setting_id then
widget_number = i widget_number = i
end end
end end
@ -3229,7 +3229,7 @@ VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content)
widget_content.is_widget_collapsed = is_widget_collapsed_new widget_content.is_widget_collapsed = is_widget_collapsed_new
if setting_name then if setting_id then
local all_collapsed_widgets = vmf:get("options_menu_collapsed_widgets") local all_collapsed_widgets = vmf:get("options_menu_collapsed_widgets")
@ -3238,12 +3238,12 @@ VMFOptionsView.callback_hide_sub_widgets = function (self, widget_content)
if widget_content.is_widget_collapsed then if widget_content.is_widget_collapsed then
mod_collapsed_widgets = mod_collapsed_widgets or {} mod_collapsed_widgets = mod_collapsed_widgets or {}
mod_collapsed_widgets[setting_name] = true mod_collapsed_widgets[setting_id] = true
all_collapsed_widgets[mod_name] = mod_collapsed_widgets all_collapsed_widgets[mod_name] = mod_collapsed_widgets
else else
if mod_collapsed_widgets then if mod_collapsed_widgets then
mod_collapsed_widgets[setting_name] = nil mod_collapsed_widgets[setting_id] = nil
local is_collapsed_widgets_list_empty = true local is_collapsed_widgets_list_empty = true
@ -3369,7 +3369,7 @@ VMFOptionsView.callback_setting_keybind = function (self, widget_content)
widget_content.first_pressed_button_type = nil widget_content.first_pressed_button_type = nil
if widget_content.action then if widget_content.action then
get_mod(widget_content.mod_name):keybind(widget_content.setting_name, widget_content.action, widget_content.keys) get_mod(widget_content.mod_name):keybind(widget_content.setting_id, widget_content.action, widget_content.keys)
end end
self:callback_change_setting_keybind_state(widget_content) self:callback_change_setting_keybind_state(widget_content)
@ -3384,7 +3384,7 @@ VMFOptionsView.callback_setting_keybind = function (self, widget_content)
widget_content.keybind_text = build_keybind_string(widget_content.keys) widget_content.keybind_text = build_keybind_string(widget_content.keys)
if widget_content.action then if widget_content.action then
get_mod(widget_content.mod_name):keybind(widget_content.setting_name, widget_content.action, widget_content.keys) get_mod(widget_content.mod_name):keybind(widget_content.setting_id, widget_content.action, widget_content.keys)
end end
self:callback_change_setting_keybind_state(widget_content) self:callback_change_setting_keybind_state(widget_content)
@ -3805,7 +3805,7 @@ VMFOptionsView.update_picked_option_for_settings_list_widgets = function (self)
if widget_type == "checkbox" then if widget_type == "checkbox" then
loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_name) loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_id)
if type(loaded_setting_value) == "boolean" then if type(loaded_setting_value) == "boolean" then
widget_content.is_checkbox_checked = loaded_setting_value widget_content.is_checkbox_checked = loaded_setting_value
@ -3815,12 +3815,12 @@ VMFOptionsView.update_picked_option_for_settings_list_widgets = function (self)
--end --end
widget_content.is_checkbox_checked = widget_content.default_value widget_content.is_checkbox_checked = widget_content.default_value
get_mod(widget_content.mod_name):set(widget_content.setting_name, widget_content.default_value) get_mod(widget_content.mod_name):set(widget_content.setting_id, widget_content.default_value)
end end
elseif widget_type == "dropdown" then elseif widget_type == "dropdown" then
loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_name) loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_id)
local setting_not_found = true local setting_not_found = true
for i, option_value in ipairs(widget_content.options_values) do for i, option_value in ipairs(widget_content.options_values) do
@ -3846,7 +3846,7 @@ VMFOptionsView.update_picked_option_for_settings_list_widgets = function (self)
widget_content.current_option_number = i widget_content.current_option_number = i
widget_content.current_option_text = widget_content.options_texts[i] widget_content.current_option_text = widget_content.options_texts[i]
widget_content.current_shown_widgets = widget_content.options_shown_widgets[i] widget_content.current_shown_widgets = widget_content.options_shown_widgets[i]
get_mod(widget_content.mod_name):set(widget_content.setting_name, widget_content.default_value) get_mod(widget_content.mod_name):set(widget_content.setting_id, widget_content.default_value)
end end
end end
end end
@ -3857,7 +3857,7 @@ VMFOptionsView.update_picked_option_for_settings_list_widgets = function (self)
elseif widget_type == "keybind" then elseif widget_type == "keybind" then
loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_name) loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_id)
if type(loaded_setting_value) == "table" then if type(loaded_setting_value) == "table" then
widget_content.keys = loaded_setting_value widget_content.keys = loaded_setting_value
@ -3870,7 +3870,7 @@ VMFOptionsView.update_picked_option_for_settings_list_widgets = function (self)
elseif widget_type == "numeric" then elseif widget_type == "numeric" then
loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_name) loaded_setting_value = get_mod(widget_content.mod_name):get(widget_content.setting_id)
if type(loaded_setting_value) == "number" then if type(loaded_setting_value) == "number" then
@ -3920,7 +3920,7 @@ VMFOptionsView.update_settings_list_widgets_visibility = function (self, mod_nam
-- Usually it had to throw an error by this point, but now it's another part of compatibility -- Usually it had to throw an error by this point, but now it's another part of compatibility
else else
widget.content.is_widget_visible = parent_widget.content.current_shown_widgets[i] and parent_widget.content.is_widget_visible and not parent_widget.content.is_widget_collapsed widget.content.is_widget_visible = parent_widget.content.current_shown_widgets[i] and parent_widget.content.is_widget_visible and not parent_widget.content.is_widget_collapsed
--get_mod(widget.content.mod_name):error("(vmf_options_view): the dropdown widget in the options menu has sub_widgets, but some of its sub_widgets doesn't have 'show_widget_condition' (%s)" , widget.content.setting_name) --get_mod(widget.content.mod_name):error("(vmf_options_view): the dropdown widget in the options menu has sub_widgets, but some of its sub_widgets doesn't have 'show_widget_condition' (%s)" , widget.content.setting_id)
end end
-- if 'group' -- if 'group'
else else

View file

@ -166,54 +166,54 @@ vmf_mod_data.options = {
-- ##### VMF internal functions and variables ######################################################################### -- ##### VMF internal functions and variables #########################################################################
-- #################################################################################################################### -- ####################################################################################################################
vmf.on_setting_changed = function (setting_name) vmf.on_setting_changed = function (setting_id)
if setting_name == "vmf_options_scrolling_speed" then if setting_id == "vmf_options_scrolling_speed" then
vmf.load_vmf_options_view_settings() vmf.load_vmf_options_view_settings()
elseif setting_name == "developer_mode" then elseif setting_id == "developer_mode" then
vmf.load_developer_mode_settings() vmf.load_developer_mode_settings()
vmf.load_network_settings() vmf.load_network_settings()
vmf.load_custom_textures_settings() vmf.load_custom_textures_settings()
vmf.load_dev_console_settings() vmf.load_dev_console_settings()
elseif setting_name == "show_developer_console" then elseif setting_id == "show_developer_console" then
vmf.load_dev_console_settings() vmf.load_dev_console_settings()
elseif setting_name == "show_network_debug_info" then elseif setting_id == "show_network_debug_info" then
vmf.load_network_settings() vmf.load_network_settings()
elseif setting_name == "log_ui_renderers_info" then elseif setting_id == "log_ui_renderers_info" then
vmf.load_custom_textures_settings() vmf.load_custom_textures_settings()
elseif setting_name == "ui_scaling" then elseif setting_id == "ui_scaling" then
vmf.load_ui_scaling_settings() vmf.load_ui_scaling_settings()
elseif setting_name == "logging_mode" elseif setting_id == "logging_mode"
or setting_name == "output_mode_echo" or setting_id == "output_mode_echo"
or setting_name == "output_mode_error" or setting_id == "output_mode_error"
or setting_name == "output_mode_warning" or setting_id == "output_mode_warning"
or setting_name == "output_mode_info" or setting_id == "output_mode_info"
or setting_name == "output_mode_debug" then or setting_id == "output_mode_debug" then
vmf.load_logging_settings() vmf.load_logging_settings()
elseif setting_name == "chat_history_enable" elseif setting_id == "chat_history_enable"
or setting_name == "chat_history_save" or setting_id == "chat_history_save"
or setting_name == "chat_history_buffer_size" or setting_id == "chat_history_buffer_size"
or setting_name == "chat_history_remove_dups" or setting_id == "chat_history_remove_dups"
or setting_name == "chat_history_remove_dups_mode" or setting_id == "chat_history_remove_dups_mode"
or setting_name == "chat_history_commands_only" then or setting_id == "chat_history_commands_only" then
vmf.load_chat_history_settings(setting_name == "chat_history_enable" or vmf.load_chat_history_settings(setting_id == "chat_history_enable" or
setting_name == "chat_history_buffer_size" or setting_id == "chat_history_buffer_size" or
setting_name == "chat_history_commands_only") setting_id == "chat_history_commands_only")
end end
end end