Config: Add dynamic options to SettingInfo

This commit is contained in:
Connor McLaughlin 2022-12-05 00:55:48 +10:00 committed by refractionpcsx2
parent b1ff979171
commit 8dba6a186f
3 changed files with 36 additions and 10 deletions

View File

@ -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<std::pair<std::string, std::string>> 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);

View File

@ -17,6 +17,7 @@
#include "common/emitter/tools.h"
#include "common/General.h"
#include <array>
#include <string>
#include <vector>
@ -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<std::pair<std::string, std::string>>(*)();
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;

View File

@ -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[] = {