From 2b9a8e5605eae426d34336aa95ddbb475889c9be Mon Sep 17 00:00:00 2001 From: rainmakerv2 <30595646+rainmakerv3@users.noreply.github.com> Date: Sun, 16 Feb 2025 00:19:04 +0800 Subject: [PATCH] add lightbar color override to Controller GUI (#2443) * WIP Lightbar GUI, needs saving and loading * Implement saving and loading lightbar values * replace license header deleted by QT --- src/qt_gui/control_settings.cpp | 93 +- src/qt_gui/control_settings.h | 1 + src/qt_gui/control_settings.ui | 2450 ++++++++++++++++--------------- 3 files changed, 1375 insertions(+), 1169 deletions(-) diff --git a/src/qt_gui/control_settings.cpp b/src/qt_gui/control_settings.cpp index 644576feb..73622e6b0 100644 --- a/src/qt_gui/control_settings.cpp +++ b/src/qt_gui/control_settings.cpp @@ -3,9 +3,9 @@ #include #include +#include #include "common/path_util.h" #include "control_settings.h" -#include "kbm_config_dialog.h" #include "ui_control_settings.h" ControlSettings::ControlSettings(std::shared_ptr game_info_get, QWidget* parent) @@ -16,7 +16,7 @@ ControlSettings::ControlSettings(std::shared_ptr game_info_get, Q AddBoxItems(); SetUIValuestoMappings(); - ui->KBMButton->setFocus(); + UpdateLightbarColor(); connect(ui->buttonBox, &QDialogButtonBox::clicked, this, [this](QAbstractButton* button) { if (button == ui->buttonBox->button(QDialogButtonBox::Save)) { @@ -29,11 +29,7 @@ ControlSettings::ControlSettings(std::shared_ptr game_info_get, Q }); connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QWidget::close); - connect(ui->KBMButton, &QPushButton::clicked, this, [this] { - auto KBMWindow = new EditorDialog(this); - KBMWindow->exec(); - SetUIValuestoMappings(); - }); + connect(ui->ProfileComboBox, &QComboBox::currentTextChanged, this, [this] { GetGameTitle(); SetUIValuestoMappings(); @@ -61,6 +57,27 @@ ControlSettings::ControlSettings(std::shared_ptr game_info_get, Q [this](int value) { ui->RStickLeftBox->setCurrentIndex(value); }); connect(ui->RStickLeftBox, &QComboBox::currentIndexChanged, this, [this](int value) { ui->RStickRightBox->setCurrentIndex(value); }); + + connect(ui->RSlider, &QSlider::valueChanged, this, [this](int value) { + QString RedValue = QString("%1").arg(value, 3, 10, QChar('0')); + QString RValue = "R: " + RedValue; + ui->RLabel->setText(RValue); + UpdateLightbarColor(); + }); + + connect(ui->GSlider, &QSlider::valueChanged, this, [this](int value) { + QString GreenValue = QString("%1").arg(value, 3, 10, QChar('0')); + QString GValue = "G: " + GreenValue; + ui->GLabel->setText(GValue); + UpdateLightbarColor(); + }); + + connect(ui->BSlider, &QSlider::valueChanged, this, [this](int value) { + QString BlueValue = QString("%1").arg(value, 3, 10, QChar('0')); + QString BValue = "B: " + BlueValue; + ui->BLabel->setText(BValue); + UpdateLightbarColor(); + }); } void ControlSettings::SaveControllerConfig(bool CloseOnSave) { @@ -121,7 +138,7 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) { if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) != ControllerInputs.end() || - output_string == "analog_deadzone") { + output_string == "analog_deadzone" || output_string == "override_controller_color") { line.erase(); continue; } @@ -227,6 +244,14 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) { deadzonevalue = std::to_string(ui->RightDeadzoneSlider->value()); lines.push_back("analog_deadzone = rightjoystick, " + deadzonevalue + ", 127"); + lines.push_back(""); + std::string OverrideLB = ui->LightbarCheckBox->isChecked() ? "true" : "false"; + std::string LightBarR = std::to_string(ui->RSlider->value()); + std::string LightBarG = std::to_string(ui->GSlider->value()); + std::string LightBarB = std::to_string(ui->BSlider->value()); + lines.push_back("override_controller_color = " + OverrideLB + ", " + LightBarR + ", " + + LightBarG + ", " + LightBarB); + std::vector save; bool CurrentLineEmpty = false, LastLineEmpty = false; for (auto const& line : lines) { @@ -243,6 +268,9 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) { output_file.close(); Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked()); + Config::SetOverrideControllerColor(ui->LightbarCheckBox->isChecked()); + Config::SetControllerCustomColor(ui->RSlider->value(), ui->GSlider->value(), + ui->BSlider->value()); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml"); if (CloseOnSave) @@ -351,7 +379,7 @@ void ControlSettings::SetUIValuestoMappings() { if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) != ControllerInputs.end() || - output_string == "analog_deadzone") { + output_string == "analog_deadzone" || output_string == "override_controller_color") { if (input_string == "cross") { ui->ABox->setCurrentText(QString::fromStdString(output_string)); CrossExists = true; @@ -436,9 +464,45 @@ void ControlSettings::SetUIValuestoMappings() { ui->RightDeadzoneSlider->setValue(2); ui->RightDeadzoneValue->setText("2"); } + } else if (output_string == "override_controller_color") { + std::size_t comma_pos = line.find(','); + if (comma_pos != std::string::npos) { + std::string overridestring = line.substr(equal_pos + 1, comma_pos); + bool override = overridestring.contains("true") ? true : false; + ui->LightbarCheckBox->setChecked(override); + + std::string lightbarstring = line.substr(comma_pos + 1); + std::size_t comma_pos2 = lightbarstring.find(','); + if (comma_pos2 != std::string::npos) { + std::string Rstring = lightbarstring.substr(0, comma_pos2); + ui->RSlider->setValue(std::stoi(Rstring)); + QString RedValue = QString("%1").arg(std::stoi(Rstring), 3, 10, QChar('0')); + QString RValue = "R: " + RedValue; + ui->RLabel->setText(RValue); + } + + std::string GBstring = lightbarstring.substr(comma_pos2 + 1); + std::size_t comma_pos3 = GBstring.find(','); + if (comma_pos3 != std::string::npos) { + std::string Gstring = GBstring.substr(0, comma_pos3); + ui->GSlider->setValue(std::stoi(Gstring)); + QString GreenValue = + QString("%1").arg(std::stoi(Gstring), 3, 10, QChar('0')); + QString GValue = "G: " + GreenValue; + ui->GLabel->setText(GValue); + + std::string Bstring = GBstring.substr(comma_pos3 + 1); + ui->BSlider->setValue(std::stoi(Bstring)); + QString BlueValue = + QString("%1").arg(std::stoi(Bstring), 3, 10, QChar('0')); + QString BValue = "B: " + BlueValue; + ui->BLabel->setText(BValue); + } + } } } } + file.close(); // If an entry does not exist in the config file, we assume the user wants it unmapped if (!CrossExists) @@ -490,8 +554,6 @@ void ControlSettings::SetUIValuestoMappings() { ui->RStickUpBox->setCurrentText("unmapped"); ui->RStickDownBox->setCurrentText("unmapped"); } - - file.close(); } void ControlSettings::GetGameTitle() { @@ -507,4 +569,13 @@ void ControlSettings::GetGameTitle() { } } +void ControlSettings::UpdateLightbarColor() { + ui->LightbarColorFrame->setStyleSheet(""); + QString RValue = QString::number(ui->RSlider->value()); + QString GValue = QString::number(ui->GSlider->value()); + QString BValue = QString::number(ui->BSlider->value()); + QString colorstring = "background-color: rgb(" + RValue + "," + GValue + "," + BValue + ")"; + ui->LightbarColorFrame->setStyleSheet(colorstring); +} + ControlSettings::~ControlSettings() {} diff --git a/src/qt_gui/control_settings.h b/src/qt_gui/control_settings.h index 04227f3a8..e686f044d 100644 --- a/src/qt_gui/control_settings.h +++ b/src/qt_gui/control_settings.h @@ -18,6 +18,7 @@ public: private Q_SLOTS: void SaveControllerConfig(bool CloseOnSave); void SetDefault(); + void UpdateLightbarColor(); private: std::unique_ptr ui; diff --git a/src/qt_gui/control_settings.ui b/src/qt_gui/control_settings.ui index b6acb5ca9..e88e239e9 100644 --- a/src/qt_gui/control_settings.ui +++ b/src/qt_gui/control_settings.ui @@ -11,8 +11,8 @@ 0 0 - 1012 - 721 + 1043 + 792 @@ -25,760 +25,681 @@ - - QFrame::Shape::NoFrame - - - 0 - true - + 0 0 - 994 - 673 + 1019 + 732 - - - Control Settings - - - - 5 - - - 5 - - - 5 - - - 5 - + + + + 0 + 0 + 1021 + 731 + + + - + + + 5 + - - - 5 + + + true - - - - true - - - - 0 - 0 - - - - - 16777215 - 16777215 - - - - D-Pad - - - - 6 - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - 0 + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + D-Pad + + + + 6 + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 124 + 0 + + + + 0 + 16777215 + + + + Up + + + + + + false + + + QComboBox::SizeAdjustPolicy::AdjustToContents + + + + + + + + + + + + + + + Left + + - 0 + 5 - 0 + 5 - 0 + 5 - 0 + 5 - - - - 124 - 0 - - - - - 0 - 16777215 - - - - Up - - - - - - false - - - QComboBox::SizeAdjustPolicy::AdjustToContents - - - - - + - - - - - Left - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - Right - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - false - - - - - - - - - - - + + + Right + + - 0 + 5 - 0 + 5 - 0 + 5 - 0 + 5 - - - - 124 - 16777215 - + + + false - - Down - - - - - - true - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Maximum - - - - 20 - 40 - - - - - - - - - 0 - 0 - - - - Left Stick Deadzone (def:2 max:127) - - - - - - - 0 - 0 - - - - Left Deadzone - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 0 - 0 - - - - 1 - - - 127 - - - Qt::Orientation::Horizontal - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Left Stick - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - 16777215 - 2121 - - - - - 0 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 124 + 16777215 + - - 0 + + Down - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 124 - 16777215 - - - - Up - - - - - - true - - - - - - - - - - - - - - - Left - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - true - - - - - - - - - - - 179 - 16777215 - - - - Right - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - true - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 124 - 0 - - - - - 124 - 21212 - - - - Down - - - - - - true - - - false - - - false - - - - - - - - - - - - - + + + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + + + + + + + + + - - - 0 + + + Qt::Orientation::Vertical - - - - - 0 - 0 - - - - - 12 - true - - - - Config Selection - - - Qt::AlignmentFlag::AlignCenter - - + + QSizePolicy::Policy::Maximum + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Left Stick Deadzone (def:2 max:127) + + + + + + + 0 + 0 + + + + Left Deadzone + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + 0 + 0 + + + + 1 + + + 127 + + + Qt::Orientation::Horizontal + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Left Stick + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 16777215 + 2121 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 124 + 16777215 + + + + Up + + + + + + true + + + + + + + + + + + - - - - - - 9 - false - - - - - - - -1 - - - Common Config - - - - - - - - 10 - true - - - - Common Config - - - Qt::AlignmentFlag::AlignCenter - - - true - - - - + + + Left + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + true + + + + + - - - - 0 - 0 - + + + + 179 + 16777215 + + + Right + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + true + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 124 + 0 + + + + + 124 + 21212 + + + + Down + + + + + + true + + + false + + + false + + + + + + + + + + + + + + + + + + 0 + + + + + + 0 + 0 + + + + + 12 + true + + + + Config Selection + + + Qt::AlignmentFlag::AlignCenter + + + + + + 9 false + + + + + -1 + + + Common Config + + + + + + + + 10 + true + + - Use per-game configs + Common Config + + + Qt::AlignmentFlag::AlignCenter + + + true - + + + + + + 0 + 0 + + + + + 9 + false + + + + Use per-game configs + + + + + + + + + + 0 + + + + + + + L1 / LB + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + + + L2 / LT + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + - - - 0 - + - - - - - L1 / LB - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - L2 / LT - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Preferred + + + + 20 + 40 + + + - + + + 10 + - - - 10 - - - - - - true - - - - KBM Controls - - - - - - - true - - - - KBM Editor - - - - - - - - - - Back - - - - - - - - - - - - - - - - + - R1 / RB + Back - - - 5 - - - 5 - - - 5 - - - 5 - + - - - - - - - - - R2 / RT - - - - 5 - - - 5 - - - 5 - - - 5 - - - + @@ -788,62 +709,13 @@ - - - - 0 - 200 - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 415 - 256 - - - - :/images/ps4_controller.png - - - true - - - Qt::AlignmentFlag::AlignBottom|Qt::AlignmentFlag::AlignHCenter - - - - - - - - - - 10 - - - QLayout::SizeConstraint::SetDefaultConstraint - + - + - L3 + R1 / RB - + 5 @@ -857,17 +729,17 @@ 5 - + - + - Options / Start + R2 / RT - + 5 @@ -881,31 +753,7 @@ 5 - - - - - - - - - R3 - - - - 5 - - - 5 - - - 5 - - - 5 - - - + @@ -915,22 +763,62 @@ - + + + + 0 + 200 + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 415 + 256 + + + + :/images/ps4_controller.png + + + true + + + Qt::AlignmentFlag::AlignBottom|Qt::AlignmentFlag::AlignHCenter + + + + + + + + - 5 + 10 + + + QLayout::SizeConstraint::SetDefaultConstraint - - - - 0 - 0 - - + - Face Buttons + L3 - + 5 @@ -944,244 +832,17 @@ 5 - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 124 - 0 - - - - - 0 - 16777215 - - - - Triangle / Y - - - - - - true - - - - 0 - 0 - - - - - - - - - - - - - - - - Square / X - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - Circle / B - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 124 - 0 - - - - - 124 - 16777215 - - - - Cross / A - - - - - - - - - - + - - - Qt::Orientation::Vertical - - - QSizePolicy::Policy::Maximum - - - - 20 - 40 - - - - - - - - - 0 - 0 - - + - Right Stick Deadzone (def:2, max:127) + Options / Start - - - - - - 0 - 0 - - - - Right Deadzone - - - Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter - - - - - - - - 0 - 0 - - - - 1 - - - 127 - - - Qt::Orientation::Horizontal - - - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Right Stick - - + 5 @@ -1195,164 +856,637 @@ 5 - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 124 - 1231321 - - - - Up - - - - - - true - - - - - - - - + + + + + + + + R3 + + + + 5 + + + 5 + + + 5 + + + 5 + - - - - - Left - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - true - - - - - - - - - - Right - - - - 5 - - - 5 - - - 5 - - - 5 - - - - - - - - - - - - - - 0 - - - 0 - - - 0 - - - 0 - - - - - - 124 - 0 - - - - - 124 - 2121 - - - - Down - - - - - - true - - - - - - - - + + + + + + + + + + false + + + + Color Adjustment + + + + + + + + + false + + + + R: 000 + + + + + + + + 0 + 0 + + + + 255 + + + Qt::Orientation::Horizontal + + + + + + + + + + + + false + + + + G: 000 + + + + + + + + 0 + 0 + + + + 255 + + + Qt::Orientation::Horizontal + + + + + + + + + + + + false + + + + B: 255 + + + + + + + + 0 + 0 + + + + 255 + + + 255 + + + Qt::Orientation::Horizontal + + + + + + + + + + + + + + + + + false + + + + Override Lightbar Color + + + + + + + false + + + + Override Color + + + + + + + QFrame::Shape::StyledPanel + + + QFrame::Shadow::Raised + + + + + + + + + + + + + + + + 5 + + + + + + 0 + 0 + + + + Face Buttons + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 124 + 0 + + + + + 0 + 16777215 + + + + Triangle / Y + + + + + + true + + + + 0 + 0 + + + + + + + + + + + + + + + + Square / X + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + + + Circle / B + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 124 + 0 + + + + + 124 + 16777215 + + + + Cross / A + + + + + + + + + + + + + + + + + + Qt::Orientation::Vertical + + + QSizePolicy::Policy::Maximum + + + + 20 + 40 + + + + + + + + + 0 + 0 + + + + Right Stick Deadzone (def:2, max:127) + + + + + + + 0 + 0 + + + + Right Deadzone + + + Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignTrailing|Qt::AlignmentFlag::AlignVCenter + + + + + + + + 0 + 0 + + + + 1 + + + 127 + + + Qt::Orientation::Horizontal + + + + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + Right Stick + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 124 + 1231321 + + + + Up + + + + + + true + + + + + + + + + + + + + + + Left + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + true + + + + + + + + + + Right + + + + 5 + + + 5 + + + 5 + + + 5 + + + + + + + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + + + + 124 + 0 + + + + + 124 + 2121 + + + + Down + + + + + + true + + + + + + + + + + + +