From 5ac9c3f0226f8afaf3aa79832267cf93d4c95107 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Wed, 10 Aug 2022 13:03:15 +1000 Subject: [PATCH] Controller: Add multiplier/format to settings --- src/core/analog_controller.cpp | 67 ++++++++++++------- src/core/analog_controller.h | 4 +- src/core/analog_joystick.cpp | 6 +- src/core/guncon.cpp | 4 +- src/core/negcon.cpp | 2 +- src/core/settings.h | 6 +- .../controllerbindingwidgets.cpp | 34 +++++----- 7 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/core/analog_controller.cpp b/src/core/analog_controller.cpp index b9ab90794..46ace1e86 100644 --- a/src/core/analog_controller.cpp +++ b/src/core/analog_controller.cpp @@ -1,4 +1,5 @@ #include "analog_controller.h" +#include "IconsFontAwesome5.h" #include "common/log.h" #include "common/string_util.h" #include "host.h" @@ -10,8 +11,9 @@ Log_SetChannel(AnalogController); AnalogController::AnalogController(u32 index) : Controller(index) { + m_status_byte = 0x5A; m_axis_state.fill(0x80); - Reset(); + m_rumble_config.fill(0xFF); } AnalogController::~AnalogController() = default; @@ -45,14 +47,16 @@ void AnalogController::Reset() { if (g_settings.controller_disable_analog_mode_forcing) { - Host::AddKeyedOSDMessage( - "analog_controller_mode_ignored", + Host::AddIconOSDMessage( + fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, Host::TranslateStdString( "OSDMessage", "Analog mode forcing is disabled by game settings. Controller will start in digital mode."), 10.0f); } else - SetAnalogMode(true); + { + SetAnalogMode(true, false); + } } } @@ -94,11 +98,14 @@ bool AnalogController::DoState(StateWrapper& sw, bool apply_input_state) if (old_analog_mode != m_analog_mode) { - Host::AddFormattedOSDMessage( - 5.0f, - m_analog_mode ? Host::TranslateString("AnalogController", "Controller %u switched to analog mode.") : - Host::TranslateString("AnalogController", "Controller %u switched to digital mode."), - m_index + 1u); + Host::AddIconOSDMessage( + fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, + fmt::format((m_analog_mode ? + Host::TranslateString("AnalogController", "Controller {} switched to analog mode.") : + Host::TranslateString("AnalogController", "Controller {} switched to digital mode.")) + .GetCharArray(), + m_index + 1u), + 5.0f); } } return true; @@ -230,17 +237,22 @@ void AnalogController::ResetTransferState() m_command_step = 0; } -void AnalogController::SetAnalogMode(bool enabled) +void AnalogController::SetAnalogMode(bool enabled, bool show_message) { if (m_analog_mode == enabled) return; Log_InfoPrintf("Controller %u switched to %s mode.", m_index + 1u, enabled ? "analog" : "digital"); - Host::AddFormattedOSDMessage(5.0f, - enabled ? - Host::TranslateString("AnalogController", "Controller %u switched to analog mode.") : - Host::TranslateString("AnalogController", "Controller %u switched to digital mode."), - m_index + 1u); + if (show_message) + { + Host::AddIconOSDMessage( + fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, + fmt::format((enabled ? Host::TranslateString("AnalogController", "Controller {} switched to analog mode.") : + Host::TranslateString("AnalogController", "Controller {} switched to digital mode.")) + .GetCharArray(), + m_index + 1u), + 5.0f); + } m_analog_mode = enabled; } @@ -248,15 +260,18 @@ void AnalogController::ProcessAnalogModeToggle() { if (m_analog_locked) { - Host::AddFormattedOSDMessage( - 5.0f, - m_analog_mode ? Host::TranslateString("AnalogController", "Controller %u is locked to analog mode by the game.") : - Host::TranslateString("AnalogController", "Controller %u is locked to digital mode by the game."), - m_index + 1u); + Host::AddIconOSDMessage( + fmt::format("Controller{}AnalogMode", m_index), ICON_FA_GAMEPAD, + fmt::format((m_analog_mode ? + Host::TranslateString("AnalogController", "Controller %u is locked to analog mode by the game.") : + Host::TranslateString("AnalogController", "Controller %u is locked to digital mode by the game.")) + .GetCharArray(), + m_index + 1u), + 5.0f); } else { - SetAnalogMode(!m_analog_mode); + SetAnalogMode(!m_analog_mode, true); ResetRumbleConfig(); if (m_dualshock_enabled) @@ -604,7 +619,7 @@ bool AnalogController::Transfer(const u8 data_in, u8* data_out) Log_DevPrintf("analog mode val 0x%02x", data_in); if (data_in == 0x00 || data_in == 0x01) - SetAnalogMode((data_in == 0x01)); + SetAnalogMode((data_in == 0x01), true); } else if (m_command_step == 3) { @@ -777,17 +792,17 @@ static const SettingInfo s_settings[] = { {SettingInfo::Type::Float, "AnalogDeadzone", TRANSLATABLE("AnalogController", "Analog Deadzone"), TRANSLATABLE("AnalogController", "Sets the analog stick deadzone, i.e. the fraction of the stick movement which will be ignored."), - "0.00f", "0.00f", "1.00f", "0.01f"}, + "0.00f", "0.00f", "1.00f", "0.01f", "%.0f%%", 100.0f}, {SettingInfo::Type::Float, "AnalogSensitivity", TRANSLATABLE("AnalogController", "Analog Sensitivity"), TRANSLATABLE( "AnalogController", - "Sets the analog stick axis scaling factor. A value between 1.30 and 1.40 is recommended when using recent " + "Sets the analog stick axis scaling factor. A value between 130% and 140% is recommended when using recent " "controllers, e.g. DualShock 4, Xbox One Controller."), - "1.33f", "0.01f", "2.00f", "0.01f"}, + "1.33f", "0.01f", "2.00f", "0.01f", "%.0f%%", 100.0f}, {SettingInfo::Type::Integer, "VibrationBias", TRANSLATABLE("AnalogController", "Vibration Bias"), TRANSLATABLE("AnalogController", "Sets the rumble bias value. If rumble in some games is too weak or not " "functioning, try increasing this value."), - "8", "0", "255", "1"}}; + "8", "0", "255", "1", "%d", 1.0f}}; const Controller::ControllerInfo AnalogController::INFO = {ControllerType::AnalogController, "AnalogController", diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 411338f1a..dd7426da8 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -108,7 +108,7 @@ private: u8 GetModeID() const; u8 GetIDByte() const; - void SetAnalogMode(bool enabled); + void SetAnalogMode(bool enabled, bool show_message); void ProcessAnalogModeToggle(); void SetMotorState(u32 motor, u8 value); void UpdateHostVibration(); @@ -140,7 +140,7 @@ private: int m_rumble_config_small_motor_index = -1; bool m_analog_toggle_queued = false; - u8 m_status_byte = 0x5A; + u8 m_status_byte = 0; // TODO: Set this with command 0x4D and increase response length in digital mode accordingly u8 m_digital_mode_extra_halfwords = 0; diff --git a/src/core/analog_joystick.cpp b/src/core/analog_joystick.cpp index c4f7d14e4..873182a49 100644 --- a/src/core/analog_joystick.cpp +++ b/src/core/analog_joystick.cpp @@ -328,13 +328,13 @@ static const SettingInfo s_settings[] = { {SettingInfo::Type::Float, "AnalogDeadzone", TRANSLATABLE("AnalogJoystick", "Analog Deadzone"), TRANSLATABLE("AnalogJoystick", "Sets the analog stick deadzone, i.e. the fraction of the stick movement which will be ignored."), - "1.00f", "0.00f", "1.00f", "0.01f"}, + "1.00f", "0.00f", "1.00f", "0.01f", "%.0f%%", 100.0f}, {SettingInfo::Type::Float, "AnalogSensitivity", TRANSLATABLE("AnalogJoystick", "Analog Sensitivity"), TRANSLATABLE( "AnalogJoystick", - "Sets the analog stick axis scaling factor. A value between 1.30 and 1.40 is recommended when using recent " + "Sets the analog stick axis scaling factor. A value between 130% and 140% is recommended when using recent " "controllers, e.g. DualShock 4, Xbox One Controller."), - "1.33f", "0.01f", "2.00f", "0.01f"}}; + "1.33f", "0.01f", "2.00f", "0.01f", "%.0f%%", 100.0f}}; const Controller::ControllerInfo AnalogJoystick::INFO = {ControllerType::AnalogJoystick, "AnalogJoystick", diff --git a/src/core/guncon.cpp b/src/core/guncon.cpp index 7369676e6..17dce7bd1 100644 --- a/src/core/guncon.cpp +++ b/src/core/guncon.cpp @@ -220,10 +220,10 @@ static const SettingInfo s_settings[] = { {SettingInfo::Type::Path, "CrosshairImagePath", TRANSLATABLE("GunCon", "Crosshair Image Path"), TRANSLATABLE("GunCon", "Path to an image to use as a crosshair/cursor.")}, {SettingInfo::Type::Float, "CrosshairScale", TRANSLATABLE("GunCon", "Crosshair Image Scale"), - TRANSLATABLE("GunCon", "Scale of crosshair image on screen."), "1.0", "0.0001", "100.0", "0.10"}, + TRANSLATABLE("GunCon", "Scale of crosshair image on screen."), "1.0", "0.0001", "100.0", "0.10", "%.0f%%", 100.0f}, {SettingInfo::Type::Float, "XScale", TRANSLATABLE("GunCon", "X Scale"), TRANSLATABLE("GunCon", "Scales X coordinates relative to the center of the screen."), "1.0", "0.01", "2.0", - "0.01"}}; + "0.01", "%.0f%%", 100.0f}}; const Controller::ControllerInfo GunCon::INFO = {ControllerType::GunCon, "GunCon", diff --git a/src/core/negcon.cpp b/src/core/negcon.cpp index b520406ed..4e78319c6 100644 --- a/src/core/negcon.cpp +++ b/src/core/negcon.cpp @@ -251,7 +251,7 @@ static const Controller::ControllerBindingInfo s_binding_info[] = { static const SettingInfo s_settings[] = { {SettingInfo::Type::Float, "SteeringDeadzone", TRANSLATABLE("NeGcon", "Steering Axis Deadzone"), - TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f"}}; + TRANSLATABLE("NeGcon", "Sets deadzone size for steering axis."), "0.00f", "0.00f", "0.99f", "0.01f", "%.0f%%", 100.0f}}; const Controller::ControllerInfo NeGcon::INFO = {ControllerType::NeGcon, "NeGcon", diff --git a/src/core/settings.h b/src/core/settings.h index eb36c7fa1..f71e95315 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -21,13 +21,15 @@ struct SettingInfo }; Type type; - const char* key; - const char* visible_name; + const char* name; + const char* display_name; const char* description; const char* default_value; const char* min_value; const char* max_value; const char* step_value; + const char* format; + float multiplier; const char* StringDefaultValue() const; bool BooleanDefaultValue() const; diff --git a/src/duckstation-qt/controllerbindingwidgets.cpp b/src/duckstation-qt/controllerbindingwidgets.cpp index 1838ce61c..4547ad9c9 100644 --- a/src/duckstation-qt/controllerbindingwidgets.cpp +++ b/src/duckstation-qt/controllerbindingwidgets.cpp @@ -521,14 +521,14 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge for (u32 i = 0; i < cinfo->num_settings; i++) { const SettingInfo& si = cinfo->settings[i]; - std::string key_name = si.key; + std::string key_name = si.name; switch (si.type) { case SettingInfo::Type::Boolean: { - QCheckBox* cb = new QCheckBox(qApp->translate(cinfo->name, si.visible_name), this); - cb->setObjectName(QString::fromUtf8(si.key)); + QCheckBox* cb = new QCheckBox(qApp->translate(cinfo->name, si.display_name), this); + cb->setObjectName(QString::fromUtf8(si.name)); ControllerSettingWidgetBinder::BindWidgetToInputProfileBool(sif, cb, section, std::move(key_name), si.BooleanDefaultValue()); layout->addWidget(cb, current_row, 0, 1, 4); @@ -539,12 +539,12 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge case SettingInfo::Type::Integer: { QSpinBox* sb = new QSpinBox(this); - sb->setObjectName(QString::fromUtf8(si.key)); + sb->setObjectName(QString::fromUtf8(si.name)); sb->setMinimum(si.IntegerMinValue()); sb->setMaximum(si.IntegerMaxValue()); sb->setSingleStep(si.IntegerStepValue()); SettingWidgetBinder::BindWidgetToIntSetting(sif, sb, section, std::move(key_name), si.IntegerDefaultValue()); - layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.visible_name), this), current_row, 0); + layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0); layout->addWidget(sb, current_row, 1, 1, 3); current_row++; } @@ -553,12 +553,12 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge case SettingInfo::Type::Float: { QDoubleSpinBox* sb = new QDoubleSpinBox(this); - sb->setObjectName(QString::fromUtf8(si.key)); + sb->setObjectName(QString::fromUtf8(si.name)); sb->setMinimum(si.FloatMinValue()); sb->setMaximum(si.FloatMaxValue()); sb->setSingleStep(si.FloatStepValue()); SettingWidgetBinder::BindWidgetToFloatSetting(sif, sb, section, std::move(key_name), si.FloatDefaultValue()); - layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.visible_name), this), current_row, 0); + layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0); layout->addWidget(sb, current_row, 1, 1, 3); current_row++; } @@ -567,9 +567,9 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge case SettingInfo::Type::String: { QLineEdit* le = new QLineEdit(this); - le->setObjectName(QString::fromUtf8(si.key)); + le->setObjectName(QString::fromUtf8(si.name)); SettingWidgetBinder::BindWidgetToStringSetting(sif, le, section, std::move(key_name), si.StringDefaultValue()); - layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.visible_name), this), current_row, 0); + layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0); layout->addWidget(le, current_row, 1, 1, 3); current_row++; } @@ -578,7 +578,7 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge case SettingInfo::Type::Path: { QLineEdit* le = new QLineEdit(this); - le->setObjectName(QString::fromUtf8(si.key)); + le->setObjectName(QString::fromUtf8(si.name)); QPushButton* browse_button = new QPushButton(tr("Browse..."), this); SettingWidgetBinder::BindWidgetToStringSetting(sif, le, section, std::move(key_name), si.StringDefaultValue()); connect(browse_button, &QPushButton::clicked, [this, le]() { @@ -591,7 +591,7 @@ void ControllerCustomSettingsWidget::createSettingWidgets(ControllerBindingWidge hbox->addWidget(le, 1); hbox->addWidget(browse_button); - layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.visible_name), this), current_row, 0); + layout->addWidget(new QLabel(qApp->translate(cinfo->name, si.display_name), this), current_row, 0); layout->addLayout(hbox, current_row, 1, 1, 3); current_row++; } @@ -615,13 +615,13 @@ void ControllerCustomSettingsWidget::restoreDefaults() for (u32 i = 0; i < cinfo->num_settings; i++) { const SettingInfo& si = cinfo->settings[i]; - const QString key(QString::fromStdString(si.key)); + const QString key(QString::fromStdString(si.name)); switch (si.type) { case SettingInfo::Type::Boolean: { - QCheckBox* widget = findChild(QString::fromStdString(si.key)); + QCheckBox* widget = findChild(QString::fromStdString(si.name)); if (widget) widget->setChecked(si.BooleanDefaultValue()); } @@ -629,7 +629,7 @@ void ControllerCustomSettingsWidget::restoreDefaults() case SettingInfo::Type::Integer: { - QSpinBox* widget = findChild(QString::fromStdString(si.key)); + QSpinBox* widget = findChild(QString::fromStdString(si.name)); if (widget) widget->setValue(si.IntegerDefaultValue()); } @@ -637,7 +637,7 @@ void ControllerCustomSettingsWidget::restoreDefaults() case SettingInfo::Type::Float: { - QDoubleSpinBox* widget = findChild(QString::fromStdString(si.key)); + QDoubleSpinBox* widget = findChild(QString::fromStdString(si.name)); if (widget) widget->setValue(si.FloatDefaultValue()); } @@ -645,7 +645,7 @@ void ControllerCustomSettingsWidget::restoreDefaults() case SettingInfo::Type::String: { - QLineEdit* widget = findChild(QString::fromStdString(si.key)); + QLineEdit* widget = findChild(QString::fromStdString(si.name)); if (widget) widget->setText(QString::fromUtf8(si.StringDefaultValue())); } @@ -653,7 +653,7 @@ void ControllerCustomSettingsWidget::restoreDefaults() case SettingInfo::Type::Path: { - QLineEdit* widget = findChild(QString::fromStdString(si.key)); + QLineEdit* widget = findChild(QString::fromStdString(si.name)); if (widget) widget->setText(QString::fromUtf8(si.StringDefaultValue())); }