Add per game checkbox, fix filename, better whitespace deletion

This commit is contained in:
rainmakerv2 2025-02-02 08:21:58 +08:00
parent cdb6c05a36
commit 552b93e3a2
3 changed files with 69 additions and 22 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 79 KiB

After

Width:  |  Height:  |  Size: 92 KiB

View File

@ -17,6 +17,7 @@ ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, Q
: QDialog(parent), m_game_info(game_info_get), ui(new Ui::ControlSettings) {
ui->setupUi(this);
ui->PerGameCheckBox->setChecked(!Config::GetUseUnifiedInputConfig());
AddBoxItems();
SetUIValuestoMappings();
@ -61,7 +62,11 @@ ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, Q
}
void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
game_id = (ui->ProfileComboBox->currentText().toStdString());
if (ui->ProfileComboBox->currentText() == "Common Config") {
game_id = ("default");
} else {
game_id = (ui->ProfileComboBox->currentText().toStdString());
}
const auto config_file = Config::GetFoolproofKbmConfigFile(game_id);
int lineCount = 0;
@ -102,7 +107,8 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
std::size_t comment_pos = line.find('#');
if (comment_pos != std::string::npos) {
lines.push_back(line);
if (!line.contains("Range of deadzones"))
lines.push_back(line);
continue;
}
@ -115,6 +121,7 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
output_string = line.substr(0, equal_pos - 1);
input_string = line.substr(equal_pos + 2);
// Remove all controller lines
if (std::find(controlleroutputs.begin(), controlleroutputs.end(), input_string) !=
controlleroutputs.end() ||
output_string == "analog_deadzone") {
@ -124,8 +131,6 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
lines.push_back(line);
}
lines.resize(lines.size() - 6);
input_string = "cross";
output_string = ui->ABox->currentText().toStdString();
lines.push_back(output_string + " = " + input_string);
@ -223,8 +228,31 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
deadzonevalue = std::to_string(ui->RightDeadzoneSlider->value());
lines.push_back("analog_deadzone = rightjoystick, " + deadzonevalue);
std::ofstream output_file(config_file);
// remove consecutive empty lines
std::vector<std::string> save;
bool CurrentLineEmpty = false;
bool LastLineEmpty = false;
for (auto const& line : lines) {
if (CurrentLineEmpty) {
LastLineEmpty = true;
} else {
LastLineEmpty = false;
}
if (line.empty()) {
CurrentLineEmpty = true;
} else {
CurrentLineEmpty = false;
}
if (CurrentLineEmpty && LastLineEmpty)
continue;
save.push_back(line);
}
std::ofstream output_file(config_file);
for (auto const& line : save) {
output_file << line << '\n';
}
@ -232,6 +260,9 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
if (CloseOnSave) {
QWidget::close();
}
Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked());
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
}
void ControlSettings::SetDefault() {
@ -292,16 +323,20 @@ void ControlSettings::AddBoxItems() {
ui->RStickLeftBox->addItems(StickInputs);
ui->RStickRightBox->addItems(StickInputs);
ui->ProfileComboBox->addItem("Default");
ui->ProfileComboBox->addItem("Common Config");
for (int i = 0; i < m_game_info->m_games.size(); i++) {
ui->ProfileComboBox->addItem(QString::fromStdString(m_game_info->m_games[i].serial));
}
ui->ProfileComboBox->setCurrentText("Default");
ui->TitleLabel->setText("Default Config");
ui->ProfileComboBox->setCurrentText("Common Config");
ui->TitleLabel->setText("Common Config");
}
void ControlSettings::SetUIValuestoMappings() {
game_id = (ui->ProfileComboBox->currentText().toStdString());
if (ui->ProfileComboBox->currentText() == "Common Config") {
game_id = ("default");
} else {
game_id = (ui->ProfileComboBox->currentText().toStdString());
}
const auto config_file = Config::GetFoolproofKbmConfigFile(game_id);
int lineCount = 0;

View File

@ -81,9 +81,6 @@
<property name="title">
<string>D-Pad</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignLeading|Qt::AlignmentFlag::AlignLeft|Qt::AlignmentFlag::AlignVCenter</set>
</property>
<layout class="QVBoxLayout" name="gb_dpad_layout">
<property name="spacing">
<number>6</number>
@ -546,14 +543,14 @@
</font>
</property>
<property name="title">
<string>Profile Selection</string>
<string>Config Selection</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QComboBox" name="ProfileComboBox">
<property name="font">
@ -569,24 +566,20 @@
<number>-1</number>
</property>
<property name="placeholderText">
<string>CUSA03173</string>
<string>Common Config</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="TitleLabel">
<property name="font">
<font>
<pointsize>12</pointsize>
<pointsize>10</pointsize>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Game Title</string>
<string>Common Config</string>
</property>
<property name="alignment">
<set>Qt::AlignmentFlag::AlignCenter</set>
@ -598,6 +591,25 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="PerGameCheckBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="font">
<font>
<pointsize>9</pointsize>
<bold>false</bold>
</font>
</property>
<property name="text">
<string>Use per-game configs</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>