From 8dba6a186f3d693913dafc4eb06918230cb71a15 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Mon, 5 Dec 2022 00:55:48 +1000 Subject: [PATCH] Config: Add dynamic options to SettingInfo --- .../Settings/ControllerBindingWidgets.cpp | 22 +++++++++++++++++++ pcsx2/Config.h | 6 ++++- pcsx2/PAD/Host/PAD.cpp | 18 +++++++-------- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp index 0734473689..92262f36b4 100644 --- a/pcsx2-qt/Settings/ControllerBindingWidgets.cpp +++ b/pcsx2-qt/Settings/ControllerBindingWidgets.cpp @@ -558,6 +558,28 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge } break; + case SettingInfo::Type::StringList: + { + QComboBox* cb = new QComboBox(widget_parent); + cb->setObjectName(QString::fromUtf8(si.name)); + if (si.get_options) + { + std::vector> options(si.get_options()); + for (const auto& [name, display_name] : options) + cb->addItem(QString::fromStdString(display_name), QString::fromStdString(name)); + } + else if (si.options) + { + for (u32 i = 0; si.options[i] != nullptr; i++) + cb->addItem(qApp->translate(cinfo->name, si.options[i])); + } + SettingWidgetBinder::BindWidgetToStringSetting(sif, cb, section, std::move(key_name), si.StringDefaultValue()); + layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), widget_parent), current_row, 0); + layout->addWidget(cb, current_row, 1, 1, 3); + current_row++; + } + break; + case SettingInfo::Type::Path: { QLineEdit* le = new QLineEdit(widget_parent); diff --git a/pcsx2/Config.h b/pcsx2/Config.h index 7bfe3880d9..82c0ef1bea 100644 --- a/pcsx2/Config.h +++ b/pcsx2/Config.h @@ -17,6 +17,7 @@ #include "common/emitter/tools.h" #include "common/General.h" +#include #include #include @@ -28,6 +29,8 @@ enum class CDVD_SourceType : uint8_t; /// Generic setting information which can be reused in multiple components. struct SettingInfo { + using GetOptionsCallback = std::vector>(*)(); + enum class Type { Boolean, @@ -48,7 +51,8 @@ struct SettingInfo const char* max_value; const char* step_value; const char* format; - const char* const* options; + const char* const* options; // For integer lists. + GetOptionsCallback get_options; // For string lists. float multiplier; const char* StringDefaultValue() const; diff --git a/pcsx2/PAD/Host/PAD.cpp b/pcsx2/PAD/Host/PAD.cpp index 6f34e49a06..ffe930fe27 100644 --- a/pcsx2/PAD/Host/PAD.cpp +++ b/pcsx2/PAD/Host/PAD.cpp @@ -404,32 +404,32 @@ static const char* s_dualshock2_invert_entries[] = { static const SettingInfo s_dualshock2_settings[] = { {SettingInfo::Type::IntegerList, "InvertL", "Invert Left Stick", "Inverts the direction of the left analog stick.", - "0", "0", "3", nullptr, nullptr, s_dualshock2_invert_entries, 0.0f}, + "0", "0", "3", nullptr, nullptr, s_dualshock2_invert_entries, nullptr, 0.0f}, {SettingInfo::Type::IntegerList, "InvertR", "Invert Right Stick", "Inverts the direction of the right analog stick.", - "0", "0", "3", nullptr, nullptr, s_dualshock2_invert_entries, 0.0f}, + "0", "0", "3", nullptr, nullptr, s_dualshock2_invert_entries, nullptr, 0.0f}, {SettingInfo::Type::Float, "Deadzone", "Analog Deadzone", "Sets the analog stick deadzone, i.e. the fraction of the stick movement which will be ignored.", - "0.00", "0.00", "1.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "0.00", "0.00", "1.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, {SettingInfo::Type::Float, "AxisScale", "Analog Sensitivity", "Sets the analog stick axis scaling factor. A value between 1.30 and 1.40 is recommended when using recent " "controllers, e.g. DualShock 4, Xbox One Controller.", - "1.33", "0.01", "2.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "1.33", "0.01", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, {SettingInfo::Type::Float, "LargeMotorScale", "Large Motor Vibration Scale", "Increases or decreases the intensity of low frequency vibration sent by the game.", - "1.00", "0.00", "2.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "1.00", "0.00", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, {SettingInfo::Type::Float, "SmallMotorScale", "Small Motor Vibration Scale", "Increases or decreases the intensity of high frequency vibration sent by the game.", - "1.00", "0.00", "2.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "1.00", "0.00", "2.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, {SettingInfo::Type::Float, "ButtonDeadzone", "Button/Trigger Deadzone", "Sets the deadzone for activating buttons/triggers, i.e. the fraction of the trigger which will be ignored.", - "0.00", "0.00", "1.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "0.00", "0.00", "1.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, /*{SettingInfo::Type::Float, "InitialPressure", "Initial Pressure", "Sets the pressure when the modifier button isn't held.", - "1.00", "0.01", "1.00", "0.01", "%.0f%%", nullptr, 100.0f},*/ + "1.00", "0.01", "1.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f},*/ {SettingInfo::Type::Float, "PressureModifier", "Modifier Pressure", "Sets the pressure when the modifier button is held.", - "0.50", "0.01", "1.00", "0.01", "%.0f%%", nullptr, 100.0f}, + "0.50", "0.01", "1.00", "0.01", "%.0f%%", nullptr, nullptr, 100.0f}, }; static const PAD::ControllerInfo s_controller_info[] = {