This commit is contained in:
Valentin Vanelslande 2018-12-28 21:13:57 -05:00
parent 90965525ac
commit bf93b94658
6 changed files with 148 additions and 148 deletions

View file

@ -51,7 +51,7 @@ const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config:
void Config::ReadValues() { void Config::ReadValues() {
qt_config->beginGroup("Controls"); qt_config->beginGroup("Controls");
Settings::values.profile = ReadSetting("profile", 0).toInt(); Settings::values.current_input_profile = ReadSetting("profile", 0).toInt();
const auto append_profile = [this] { const auto append_profile = [this] {
Settings::InputProfile profile; Settings::InputProfile profile;
@ -95,22 +95,23 @@ void Config::ReadValues() {
const int num_input_profiles = qt_config->beginReadArray("profiles"); const int num_input_profiles = qt_config->beginReadArray("profiles");
for (int i = 0; i < size; ++i) { for (int i = 0; i < num_input_profiles; ++i) {
qt_config->setArrayIndex(i); qt_config->setArrayIndex(i);
append_profile(); append_profile();
} }
qt_config->endArray(); qt_config->endArray();
if (Settings::values.profile <= size) { if (Settings::values.current_input_profile <= num_input_profiles) {
Settings::values.profile = 0; Settings::values.current_input_profile = 0;
} }
if (size == 0) { // create a input profile if no input profiles exist, with the default or old settings
if (num_input_profiles == 0) {
append_profile(); append_profile();
} }
Settings::LoadProfile(Settings::values.profile); Settings::LoadProfile(Settings::values.current_input_profile);
qt_config->endArray(); qt_config->endArray();
@ -281,7 +282,7 @@ void Config::ReadValues() {
UISettings::values.game_dir_deprecated = ReadSetting("gameListRootDir", ".").toString(); UISettings::values.game_dir_deprecated = ReadSetting("gameListRootDir", ".").toString();
UISettings::values.game_dir_deprecated_deepscan = UISettings::values.game_dir_deprecated_deepscan =
ReadSetting("gameListDeepScan", false).toBool(); ReadSetting("gameListDeepScan", false).toBool();
size = qt_config->beginReadArray("gamedirs"); int size = qt_config->beginReadArray("gamedirs");
for (int i = 0; i < size; ++i) { for (int i = 0; i < size; ++i) {
qt_config->setArrayIndex(i); qt_config->setArrayIndex(i);
UISettings::GameDir game_dir; UISettings::GameDir game_dir;
@ -376,10 +377,10 @@ void Config::ReadValues() {
void Config::SaveValues() { void Config::SaveValues() {
qt_config->beginGroup("Controls"); qt_config->beginGroup("Controls");
WriteSetting("profile", Settings::values.profile, 0); WriteSetting("profile", Settings::values.current_input_profile, 0);
qt_config->beginWriteArray("profiles"); qt_config->beginWriteArray("profiles");
for (int p = 0; p < Settings::values.profiles.size(); ++p) { for (std::size_t p = 0; p < Settings::values.inprofiles.size(); ++p) {
qt_config->setArrayIndex(p); qt_config->setArrayIndex(static_cast<int>(p));
const auto& profile = Settings::values.profiles[p]; const auto& profile = Settings::values.profiles[p];
for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);

View file

@ -106,7 +106,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name)); ui->profile->addItem(QString::fromStdString(Settings::values.profiles[i].name));
} }
ui->profile->setCurrentIndex(Settings::values.profile); ui->profile->setCurrentIndex(Settings::values.current_input_profile);
button_map = { button_map = {
ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp,
@ -171,8 +171,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
if (!analog_map_buttons[analog_id][sub_button_id]) if (!analog_map_buttons[analog_id][sub_button_id])
continue; continue;
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy( analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
Qt::CustomContextMenu);
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() { connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() {
handleClick( handleClick(
analog_map_buttons[analog_id][sub_button_id], analog_map_buttons[analog_id][sub_button_id],
@ -203,8 +202,8 @@ ConfigureInput::ConfigureInput(QWidget* parent)
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
}); });
context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal( context_menu.exec(
menu_location)); analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location));
}); });
} }
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { connect(analog_map_stick[analog_id], &QPushButton::released, [=]() {
@ -235,7 +234,7 @@ ConfigureInput::ConfigureInput(QWidget* parent)
connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int i) { [this](int i) {
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(Settings::values.profile); Settings::SaveProfile(Settings::values.current_input_profile);
Settings::LoadProfile(i); Settings::LoadProfile(i);
loadConfiguration(); loadConfiguration();
}); });
@ -270,7 +269,7 @@ void ConfigureInput::applyConfiguration() {
} }
void ConfigureInput::applyProfile() { void ConfigureInput::applyProfile() {
Settings::values.profile = ui->profile->currentIndex(); Settings::values.current_input_profile = ui->profile->currentIndex();
} }
void ConfigureInput::loadConfiguration() { void ConfigureInput::loadConfiguration() {
@ -400,7 +399,7 @@ void ConfigureInput::newProfile() {
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
Settings::CreateProfile(name.toStdString()); Settings::CreateProfile(name.toStdString());
ui->profile->addItem(name); ui->profile->addItem(name);
ui->profile->setCurrentIndex(Settings::values.profile); ui->profile->setCurrentIndex(Settings::values.current_input_profile);
loadConfiguration(); loadConfiguration();
} }

View file

@ -270,7 +270,7 @@ void ConfigureMotionTouch::applyConfiguration() {
Settings::values.udp_input_address = ui->udp_server->text().toStdString(); Settings::values.udp_input_address = ui->udp_server->text().toStdString();
Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt()); Settings::values.udp_input_port = static_cast<u16>(ui->udp_port->text().toInt());
Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex()); Settings::values.udp_pad_index = static_cast<u8>(ui->udp_pad_index->currentIndex());
Settings::SaveProfile(Settings::values.profile); Settings::SaveProfile(Settings::values.current_input_profile);
InputCommon::ReloadInputDevices(); InputCommon::ReloadInputDevices();
accept(); accept();

View file

@ -1326,8 +1326,8 @@ void GMainWindow::OnConfigure() {
connect(&configureDialog, &ConfigureDialog::languageChanged, this, connect(&configureDialog, &ConfigureDialog::languageChanged, this,
&GMainWindow::OnLanguageChanged); &GMainWindow::OnLanguageChanged);
auto old_theme = UISettings::values.theme; auto old_theme = UISettings::values.theme;
const int old_profile = Settings::values.profile; const int old_input_profile = Settings::values.current_input_profile;
const auto old_profiles = Settings::values.profiles; const auto old_input_profiles = Settings::values.input_profiles;
const bool old_discord_presence = UISettings::values.enable_discord_presence; const bool old_discord_presence = UISettings::values.enable_discord_presence;
auto result = configureDialog.exec(); auto result = configureDialog.exec();
if (result == QDialog::Accepted) { if (result == QDialog::Accepted) {
@ -1341,8 +1341,8 @@ void GMainWindow::OnConfigure() {
game_list->RefreshGameDirectory(); game_list->RefreshGameDirectory();
config->Save(); config->Save();
} else { } else {
Settings::values.profiles = old_profiles; Settings::values.input_profiles = old_input_profiles;
Settings::LoadProfile(old_profile); Settings::LoadProfile(old_input_profile);
} }
} }

View file

@ -102,7 +102,7 @@ void LogSettings() {
void LoadProfile(int index) { void LoadProfile(int index) {
const auto& profile = values.profiles[index]; const auto& profile = values.profiles[index];
values.profile = index; values.current_input_profile = index;
values.analogs = profile.analogs; values.analogs = profile.analogs;
values.buttons = profile.buttons; values.buttons = profile.buttons;
values.motion_device = profile.motion_device; values.motion_device = profile.motion_device;
@ -134,8 +134,8 @@ void CreateProfile(std::string name) {
profile.udp_input_port = values.udp_input_port; profile.udp_input_port = values.udp_input_port;
profile.udp_pad_index = values.udp_pad_index; profile.udp_pad_index = values.udp_pad_index;
values.profiles.push_back(std::move(profile)); values.profiles.push_back(std::move(profile));
values.profile = static_cast<int>(values.profiles.size()) - 1; values.current_input_profile = static_cast<int>(values.profiles.size()) - 1;
LoadProfile(values.profile); LoadProfile(values.current_input_profile);
} }
void DeleteProfile(int index) { void DeleteProfile(int index) {
@ -144,7 +144,7 @@ void DeleteProfile(int index) {
} }
void RenameCurrentProfile(std::string new_name) { void RenameCurrentProfile(std::string new_name) {
values.profiles[values.profile].name = std::move(new_name); values.profiles[values.current_input_profile].name = std::move(new_name);
} }
} // namespace Settings } // namespace Settings