Implement saving and loading lightbar values

This commit is contained in:
rainmakerv2 2025-02-15 16:47:25 +08:00
parent 055c456b10
commit b433cc3eff
2 changed files with 67 additions and 17 deletions

View File

@ -138,7 +138,7 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) != if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) !=
ControllerInputs.end() || ControllerInputs.end() ||
output_string == "analog_deadzone") { output_string == "analog_deadzone" || output_string == "override_controller_color") {
line.erase(); line.erase();
continue; continue;
} }
@ -244,6 +244,14 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
deadzonevalue = std::to_string(ui->RightDeadzoneSlider->value()); deadzonevalue = std::to_string(ui->RightDeadzoneSlider->value());
lines.push_back("analog_deadzone = rightjoystick, " + deadzonevalue + ", 127"); 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; std::vector<std::string> save;
bool CurrentLineEmpty = false, LastLineEmpty = false; bool CurrentLineEmpty = false, LastLineEmpty = false;
for (auto const& line : lines) { for (auto const& line : lines) {
@ -260,6 +268,9 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
output_file.close(); output_file.close();
Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked()); 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"); Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
if (CloseOnSave) if (CloseOnSave)
@ -368,7 +379,7 @@ void ControlSettings::SetUIValuestoMappings() {
if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) != if (std::find(ControllerInputs.begin(), ControllerInputs.end(), input_string) !=
ControllerInputs.end() || ControllerInputs.end() ||
output_string == "analog_deadzone") { output_string == "analog_deadzone" || output_string == "override_controller_color") {
if (input_string == "cross") { if (input_string == "cross") {
ui->ABox->setCurrentText(QString::fromStdString(output_string)); ui->ABox->setCurrentText(QString::fromStdString(output_string));
CrossExists = true; CrossExists = true;
@ -453,9 +464,45 @@ void ControlSettings::SetUIValuestoMappings() {
ui->RightDeadzoneSlider->setValue(2); ui->RightDeadzoneSlider->setValue(2);
ui->RightDeadzoneValue->setText("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 an entry does not exist in the config file, we assume the user wants it unmapped
if (!CrossExists) if (!CrossExists)
@ -507,8 +554,6 @@ void ControlSettings::SetUIValuestoMappings() {
ui->RStickUpBox->setCurrentText("unmapped"); ui->RStickUpBox->setCurrentText("unmapped");
ui->RStickDownBox->setCurrentText("unmapped"); ui->RStickDownBox->setCurrentText("unmapped");
} }
file.close();
} }
void ControlSettings::GetGameTitle() { void ControlSettings::GetGameTitle() {

View File

@ -10,7 +10,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1043</width> <width>1043</width>
<height>822</height> <height>792</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -22,21 +22,26 @@
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QVBoxLayout" name="verticalLayout">
<item> <item>
<widget class="QTabWidget" name="TabWidget"> <widget class="QScrollArea" name="scrollArea">
<property name="currentIndex"> <property name="widgetResizable">
<number>0</number> <bool>true</bool>
</property> </property>
<widget class="QWidget" name="RemapTab"> <widget class="QWidget" name="scrollAreaWidgetContents">
<attribute name="title"> <property name="geometry">
<string>Controller Remapping</string> <rect>
</attribute> <x>0</x>
<widget class="QWidget" name=""> <y>0</y>
<width>1019</width>
<height>732</height>
</rect>
</property>
<widget class="QWidget" name="layoutWidget">
<property name="geometry"> <property name="geometry">
<rect> <rect>
<x>10</x> <x>0</x>
<y>10</y> <y>0</y>
<width>1004</width> <width>1021</width>
<height>711</height> <height>731</height>
</rect> </rect>
</property> </property>
<layout class="QHBoxLayout" name="RemapLayout"> <layout class="QHBoxLayout" name="RemapLayout">