From 7075152aaec4c14c9badefedaaf9ed58950473c7 Mon Sep 17 00:00:00 2001 From: Aussiemon Date: Wed, 29 Mar 2023 14:55:35 -0600 Subject: [PATCH] Support for optional require_restart, callbacks, and gamepad fixes --- dmf/scripts/mods/dmf/modules/core/options.lua | 11 ++++++----- .../dmf/modules/ui/options/dmf_options_view.lua | 17 ++++++++++------- .../dmf_options_view_content_blueprints.lua | 11 ++++++++--- .../mods/dmf/modules/ui/options/mod_options.lua | 3 +++ 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/dmf/scripts/mods/dmf/modules/core/options.lua b/dmf/scripts/mods/dmf/modules/core/options.lua index 58cc515..66bf77f 100644 --- a/dmf/scripts/mods/dmf/modules/core/options.lua +++ b/dmf/scripts/mods/dmf/modules/core/options.lua @@ -117,11 +117,12 @@ local function initialize_generic_widget_data(mod, data, localize) new_data.mod_name = mod:get_name() -- Defined in widget - new_data.type = data.type - new_data.setting_id = data.setting_id - new_data.title = data.title -- optional, if (localize == true) - new_data.tooltip = data.tooltip -- optional - new_data.default_value = data.default_value + new_data.type = data.type + new_data.setting_id = data.setting_id + new_data.title = data.title -- optional, if (localize == true) + new_data.tooltip = data.tooltip -- optional + new_data.default_value = data.default_value + new_data.require_restart = data.require_restart -- optional -- Overwrite global optons localization setting if widget defined it if data.localize == nil then diff --git a/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view.lua b/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view.lua index e0d7dbe..8991315 100644 --- a/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view.lua +++ b/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view.lua @@ -924,7 +924,7 @@ DMFOptionsView._update_settings_content_widgets = function (self, dt, t, input_s end end -DMFOptionsView._create_settings_widget_from_config = function (self, config, category, suffix, callback_name) +DMFOptionsView._create_settings_widget_from_config = function (self, config, category, suffix, callback_name, changed_callback_name) local scenegraph_id = "settings_grid_content_pivot" local default_value = config.default_value local default_value_type = type(default_value) @@ -1112,20 +1112,23 @@ DMFOptionsView.cb_on_settings_pressed = function (self, widget, entry) end end -DMFOptionsView.cb_on_settings_changed = function (self, widget, entry, option_id) +DMFOptionsView.cb_on_settings_changed = function (self, widget, entry, option_value) if not self._require_restart then - if option_id then + + -- Entry supersedes option + if entry.require_restart then + self._require_restart = true + + -- Search by option value + elseif option_value then for i = 1, #entry.options do local option = entry.options[i] - if option.id == option_id then + if option.value == option_value then self._require_restart = option.require_restart - break end end - else - self._require_restart = entry.require_restart end end end diff --git a/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints.lua b/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints.lua index 33afc0a..8279c96 100644 --- a/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints.lua +++ b/dmf/scripts/mods/dmf/modules/ui/options/dmf_options_view_content_blueprints.lua @@ -171,6 +171,7 @@ local blueprints = { if new_value ~= nil and new_value ~= value then on_activated(new_value, entry) + entry.changed_callback(new_value) end end } @@ -291,6 +292,7 @@ blueprints.percent_slider = { if new_value then on_activated(new_value * 100, entry) + entry.changed_callback(new_value) content.slider_value = new_value content.previous_slider_value = new_value @@ -389,6 +391,7 @@ blueprints.value_slider = { local new_value = explode_function(new_normalized_value, entry) on_activated(new_value, entry) + entry.changed_callback(new_value) content.slider_value = new_normalized_value content.previous_slider_value = new_normalized_value @@ -499,6 +502,7 @@ blueprints.slider = { local new_value = math.lerp(entry.min_value, entry.max_value, new_value_fraction) on_activated(new_value, entry) + entry.changed_callback(new_value) content.slider_value = new_value_fraction content.previous_slider_value = new_value_fraction @@ -601,7 +605,7 @@ blueprints.dropdown = { if selected_index and focused then if using_gamepad and hotspot.on_pressed then - new_value = options[selected_index].id + new_value = options[selected_index].value end hotspot_style.on_pressed_sound = hotspot_style.on_pressed_fold_in_sound @@ -612,7 +616,7 @@ blueprints.dropdown = { value = entry.get_function and entry:get_function() or content.internal_value or "" local preview_option = options_by_value[value] - local preview_option_id = preview_option and preview_option.id + local preview_option_value = preview_option and preview_option.value local preview_value = preview_option and preview_option.display_name or Managers.localization:localize("loc_settings_option_unavailable") content.value_text = preview_value @@ -636,7 +640,7 @@ blueprints.dropdown = { for i = 1, #options do local option = options[i] - if option.id == preview_option_id then + if option.value == preview_option_value then selected_index = i break @@ -729,6 +733,7 @@ blueprints.dropdown = { if new_value ~= value then local on_activated = entry.on_activated on_activated(new_value, entry) + entry.changed_callback(new_value) end end diff --git a/dmf/scripts/mods/dmf/modules/ui/options/mod_options.lua b/dmf/scripts/mods/dmf/modules/ui/options/mod_options.lua index acc1088..39c039a 100644 --- a/dmf/scripts/mods/dmf/modules/ui/options/mod_options.lua +++ b/dmf/scripts/mods/dmf/modules/ui/options/mod_options.lua @@ -159,6 +159,7 @@ local create_checkbox_template = function (self, params) display_name = params.title, indentation_level = params.depth, tooltip_text = params.tooltip, + require_restart = params.require_restart, value_type = "boolean", } template.on_activated = function(new_value) @@ -189,6 +190,7 @@ local create_mod_toggle_template = function (self, params) disabled = params.disabled, indentation_level = 0, tooltip_text = params.description, + require_restart = params.require_restart, value_type = "boolean", } @@ -226,6 +228,7 @@ local create_dropdown_template = function (self, params) indentation_level = params.depth, options = params.options, tooltip_text = params.tooltip, + require_restart = params.require_restart, widget_type = "dropdown", } template.on_activated = function(new_value)