mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-05-14 08:12:16 +00:00
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
This commit is contained in:
parent
bdf4a5249d
commit
2b9a8e5605
3 changed files with 1375 additions and 1169 deletions
|
@ -3,9 +3,9 @@
|
|||
|
||||
#include <fstream>
|
||||
#include <QMessageBox>
|
||||
#include <QPushButton>
|
||||
#include "common/path_util.h"
|
||||
#include "control_settings.h"
|
||||
#include "kbm_config_dialog.h"
|
||||
#include "ui_control_settings.h"
|
||||
|
||||
ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent)
|
||||
|
@ -16,7 +16,7 @@ ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> 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<GameInfoClass> 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<GameInfoClass> 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<std::string> 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() {}
|
||||
|
|
|
@ -18,6 +18,7 @@ public:
|
|||
private Q_SLOTS:
|
||||
void SaveControllerConfig(bool CloseOnSave);
|
||||
void SetDefault();
|
||||
void UpdateLightbarColor();
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui::ControlSettings> ui;
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1012</width>
|
||||
<height>721</height>
|
||||
<width>1043</width>
|
||||
<height>792</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
|
@ -25,43 +25,28 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QScrollArea" name="scrollArea">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::NoFrame</enum>
|
||||
</property>
|
||||
<property name="lineWidth">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="widgetResizable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<widget class="QWidget" name="scrollAreaWidgetContents">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>994</width>
|
||||
<height>673</height>
|
||||
<width>1019</width>
|
||||
<height>732</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
<string>Control Settings</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="mainLayout">
|
||||
<property name="leftMargin">
|
||||
<number>5</number>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>1021</width>
|
||||
<height>731</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>5</number>
|
||||
</property>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="bottomLayout">
|
||||
<layout class="QHBoxLayout" name="RemapLayout">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_left">
|
||||
<property name="spacing">
|
||||
|
@ -538,7 +523,7 @@
|
|||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_middle" stretch="0,0,0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_middle" stretch="0,0,0,0,0">
|
||||
<property name="spacing">
|
||||
<number>0</number>
|
||||
</property>
|
||||
|
@ -686,37 +671,27 @@
|
|||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="layout_system_buttons">
|
||||
<item>
|
||||
<spacer name="verticalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::Policy::Preferred</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||
<property name="spacing">
|
||||
<number>10</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>KBM Controls</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_11">
|
||||
<item>
|
||||
<widget class="QPushButton" name="KBMButton">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>KBM Editor</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_2">
|
||||
<property name="title">
|
||||
|
@ -912,6 +887,167 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_14">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Color Adjustment</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_18">
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_9">
|
||||
<item>
|
||||
<widget class="QLabel" name="RLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>R: 000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="RSlider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||
<item>
|
||||
<widget class="QLabel" name="GLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>G: 000</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="GSlider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<item>
|
||||
<widget class="QLabel" name="BLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>B: 255</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSlider" name="BSlider">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="maximum">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="value">
|
||||
<number>255</number>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_17">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox_3">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Override Lightbar Color</string>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_19">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="LightbarCheckBox">
|
||||
<property name="font">
|
||||
<font>
|
||||
<bold>false</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Override Color</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="LightbarColorFrame">
|
||||
<property name="frameShape">
|
||||
<enum>QFrame::Shape::StyledPanel</enum>
|
||||
</property>
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Shadow::Raised</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
|
@ -1354,8 +1490,6 @@
|
|||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
</widget>
|
||||
|
|
Loading…
Add table
Reference in a new issue