From ac197682474a1f6b4f52a8af1882cf0531e8d65a Mon Sep 17 00:00:00 2001 From: Stenzek Date: Sun, 3 Nov 2024 20:26:52 +1000 Subject: [PATCH] Qt: Make multitap mode non-inheritable as well --- .../controllerglobalsettingswidget.cpp | 24 +++++--- .../controllerglobalsettingswidget.ui | 23 +------- .../controllersettingwidgetbinder.h | 56 +++++++++++++++++++ 3 files changed, 72 insertions(+), 31 deletions(-) diff --git a/src/duckstation-qt/controllerglobalsettingswidget.cpp b/src/duckstation-qt/controllerglobalsettingswidget.cpp index 5943dbd19..5741f0fce 100644 --- a/src/duckstation-qt/controllerglobalsettingswidget.cpp +++ b/src/duckstation-qt/controllerglobalsettingswidget.cpp @@ -20,14 +20,16 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLSource, "InputSources", "SDL", true); ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLEnhancedMode, "InputSources", - "SDLControllerEnhancedMode", false); + "SDLControllerEnhancedMode", false); connect(m_ui.enableSDLSource, &QCheckBox::checkStateChanged, this, &ControllerGlobalSettingsWidget::updateSDLOptionsEnabled); connect(m_ui.ledSettings, &QToolButton::clicked, this, &ControllerGlobalSettingsWidget::ledSettingsClicked); #ifdef __APPLE__ - ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLIOKitDriver, "InputSources", "SDLIOKitDriver", true); - ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLMFIDriver, "InputSources", "SDLMFIDriver", true); + ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLIOKitDriver, "InputSources", + "SDLIOKitDriver", true); + ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableSDLMFIDriver, "InputSources", + "SDLMFIDriver", true); #else m_ui.sdlGridLayout->removeWidget(m_ui.enableSDLIOKitDriver); delete m_ui.enableSDLIOKitDriver; @@ -38,9 +40,12 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, #endif #ifdef _WIN32 - ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableDInputSource, "InputSources", "DInput", false); - ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableXInputSource, "InputSources", "XInput", false); - ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableRawInput, "InputSources", "RawInput", false); + ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableDInputSource, "InputSources", "DInput", + false); + ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableXInputSource, "InputSources", "XInput", + false); + ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableRawInput, "InputSources", "RawInput", + false); #else m_ui.mainLayout->removeWidget(m_ui.xinputGroup); delete m_ui.xinputGroup; @@ -52,9 +57,10 @@ ControllerGlobalSettingsWidget::ControllerGlobalSettingsWidget(QWidget* parent, ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, m_ui.enableMouseMapping, "UI", "EnableMouseMapping", false); - SettingWidgetBinder::BindWidgetToEnumSetting(sif, m_ui.multitapMode, "ControllerPorts", "MultitapMode", - &Settings::ParseMultitapModeName, &Settings::GetMultitapModeName, - Settings::DEFAULT_MULTITAP_MODE); + ControllerSettingWidgetBinder::BindWidgetToInputProfileEnumSetting( + sif, m_ui.multitapMode, "ControllerPorts", "MultitapMode", &Settings::ParseMultitapModeName, + &Settings::GetMultitapModeName, &Settings::GetMultitapModeDisplayName, Settings::DEFAULT_MULTITAP_MODE, + MultitapMode::Count); ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerXScale, "ControllerPorts", "PointerXScale", 8.0f); ControllerSettingWidgetBinder::BindWidgetToInputProfileFloat(sif, m_ui.pointerYScale, "ControllerPorts", diff --git a/src/duckstation-qt/controllerglobalsettingswidget.ui b/src/duckstation-qt/controllerglobalsettingswidget.ui index abf4160b2..28a7483e7 100644 --- a/src/duckstation-qt/controllerglobalsettingswidget.ui +++ b/src/duckstation-qt/controllerglobalsettingswidget.ui @@ -98,28 +98,7 @@ - - - - Disabled - - - - - Enable on Port 1 Only - - - - - Enable on Port 2 Only - - - - - Enable on Ports 1 and 2 - - - + diff --git a/src/duckstation-qt/controllersettingwidgetbinder.h b/src/duckstation-qt/controllersettingwidgetbinder.h index e1a217d85..6ee2761af 100644 --- a/src/duckstation-qt/controllersettingwidgetbinder.h +++ b/src/duckstation-qt/controllersettingwidgetbinder.h @@ -164,4 +164,60 @@ static void BindWidgetToInputProfileString(SettingsInterface* sif, WidgetType* w }); } } + +/// Interface specific method of BindWidgetToEnumSetting(). +template +static void BindWidgetToInputProfileEnumSetting(SettingsInterface* sif, WidgetType* widget, std::string section, + std::string key, + std::optional (*from_string_function)(const char* str), + const char* (*to_string_function)(DataType value), + const char* (*to_display_name_function)(DataType value), + DataType default_value, ValueCountType value_count) +{ + using Accessor = SettingWidgetBinder::SettingAccessor; + using UnderlyingType = std::underlying_type_t; + + for (UnderlyingType i = 0; i < static_cast(value_count); i++) + Accessor::addOption(widget, to_display_name_function(static_cast(i))); + + const std::string value = + sif ? sif->GetStringValue(section.c_str(), key.c_str(), to_string_function(default_value)) : + Host::GetBaseStringSettingValue(section.c_str(), key.c_str(), to_string_function(default_value)); + const std::optional typed_value = from_string_function(value.c_str()); + if (typed_value.has_value()) + Accessor::setIntValue(widget, static_cast(static_cast(typed_value.value()))); + else + Accessor::setIntValue(widget, static_cast(static_cast(default_value))); + + if (sif) + { + Accessor::connectValueChanged( + widget, [sif, widget, section = std::move(section), key = std::move(key), to_string_function]() { + if (std::optional new_value = Accessor::getIntValue(widget); new_value.has_value()) + { + const char* string_value = + to_string_function(static_cast(static_cast(new_value.value()))); + sif->SetStringValue(section.c_str(), key.c_str(), string_value); + } + else + { + sif->DeleteValue(section.c_str(), key.c_str()); + } + + QtHost::SaveGameSettings(sif, true); + g_emu_thread->reloadGameSettings(); + }); + } + else + { + Accessor::connectValueChanged( + widget, [widget, section = std::move(section), key = std::move(key), to_string_function]() { + const DataType value = static_cast(static_cast(Accessor::getIntValue(widget))); + const char* string_value = to_string_function(value); + Host::SetBaseStringSettingValue(section.c_str(), key.c_str(), string_value); + Host::CommitBaseSettingChanges(); + g_emu_thread->applySettings(); + }); + } +} } // namespace ControllerSettingWidgetBinder