citra-emu
/
citra
Archived
1
0
Fork 0
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

@ -103,161 +103,160 @@ ConfigureInput::ConfigureInput(QWidget* parent)
for (const auto& profile : Settings::values::profiles) { for (const auto& profile : Settings::values::profiles) {
ui->profile->addItem(QString::fromStdString(profile.name)); ui->profile->addItem(QString::fromStdString(profile.name));
} }
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,
ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR,
ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome,
}; };
analog_map_buttons = {{ analog_map_buttons = {{
{ {
ui->buttonCircleUp, ui->buttonCircleUp,
ui->buttonCircleDown, ui->buttonCircleDown,
ui->buttonCircleLeft, ui->buttonCircleLeft,
ui->buttonCircleRight, ui->buttonCircleRight,
ui->buttonCircleMod, ui->buttonCircleMod,
}, },
{ {
ui->buttonCStickUp, ui->buttonCStickUp,
ui->buttonCStickDown, ui->buttonCStickDown,
ui->buttonCStickLeft, ui->buttonCStickLeft,
ui->buttonCStickRight, ui->buttonCStickRight,
nullptr, nullptr,
}, },
}}; }};
analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog}; analog_map_stick = {ui->buttonCircleAnalog, ui->buttonCStickAnalog};
for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
if (!button_map[button_id]) if (!button_map[button_id])
continue;
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button_map[button_id], &QPushButton::released, [=]() {
handleClick(
button_map[button_id],
[=](const Common::ParamPackage& params) {
buttons_param[button_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Button);
});
connect(button_map[button_id], &QPushButton::customContextMenuRequested,
[=](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
buttons_param[button_id].Clear();
button_map[button_id]->setText(tr("[not set]"));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.addAction(tr("Restore Default"), [&] {
buttons_param[button_id] = Common::ParamPackage{
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])};
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
});
}
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_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])
continue; continue;
button_map[button_id]->setContextMenuPolicy(Qt::CustomContextMenu); analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(Qt::CustomContextMenu);
connect(button_map[button_id], &QPushButton::released, [=]() { connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() {
handleClick( handleClick(
button_map[button_id], analog_map_buttons[analog_id][sub_button_id],
[=](const Common::ParamPackage& params) { [=](const Common::ParamPackage& params) {
buttons_param[button_id] = params; SetAnalogButton(params, analogs_param[analog_id],
analog_sub_buttons[sub_button_id]);
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
}, },
InputCommon::Polling::DeviceType::Button); InputCommon::Polling::DeviceType::Button);
}); });
connect(button_map[button_id], &QPushButton::customContextMenuRequested, connect(analog_map_buttons[analog_id][sub_button_id],
[=](const QPoint& menu_location) { &QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
QMenu context_menu; QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] { context_menu.addAction(tr("Clear"), [&] {
buttons_param[button_id].Clear(); analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
button_map[button_id]->setText(tr("[not set]")); analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
}); });
context_menu.addAction(tr("Restore Default"), [&] { context_menu.addAction(tr("Restore Default"), [&] {
buttons_param[button_id] = Common::ParamPackage{ Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
InputCommon::GenerateKeyboardParam(Config::default_buttons[button_id])}; Config::default_analogs[analog_id][sub_button_id])};
button_map[button_id]->setText(ButtonToText(buttons_param[button_id]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(button_map[button_id]->mapToGlobal(menu_location));
});
}
for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_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])
continue;
analog_map_buttons[analog_id][sub_button_id]->setContextMenuPolicy(
Qt::CustomContextMenu);
connect(analog_map_buttons[analog_id][sub_button_id], &QPushButton::released, [=]() {
handleClick(
analog_map_buttons[analog_id][sub_button_id],
[=](const Common::ParamPackage& params) {
SetAnalogButton(params, analogs_param[analog_id], SetAnalogButton(params, analogs_param[analog_id],
analog_sub_buttons[sub_button_id]); analog_sub_buttons[sub_button_id]);
analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText(
analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex()); Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Button);
});
connect(analog_map_buttons[analog_id][sub_button_id],
&QPushButton::customContextMenuRequested, [=](const QPoint& menu_location) {
QMenu context_menu;
context_menu.addAction(tr("Clear"), [&] {
analogs_param[analog_id].Erase(analog_sub_buttons[sub_button_id]);
analog_map_buttons[analog_id][sub_button_id]->setText(tr("[not set]"));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.addAction(tr("Restore Default"), [&] {
Common::ParamPackage params{InputCommon::GenerateKeyboardParam(
Config::default_analogs[analog_id][sub_button_id])};
SetAnalogButton(params, analogs_param[analog_id],
analog_sub_buttons[sub_button_id]);
analog_map_buttons[analog_id][sub_button_id]->setText(AnalogToText(
analogs_param[analog_id], analog_sub_buttons[sub_button_id]));
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
});
context_menu.exec(analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(
menu_location));
}); });
} context_menu.exec(
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() { analog_map_buttons[analog_id][sub_button_id]->mapToGlobal(menu_location));
QMessageBox::information(this, tr("Information"), });
tr("After pressing OK, first move your joystick horizontally, "
"and then vertically."));
handleClick(
analog_map_stick[analog_id],
[=](const Common::ParamPackage& params) {
analogs_param[analog_id] = params;
applyConfiguration();
Settings::SaveProfile(ui->profile->currentIndex());
},
InputCommon::Polling::DeviceType::Analog);
});
} }
connect(analog_map_stick[analog_id], &QPushButton::released, [=]() {
connect(ui->buttonMotionTouch, &QPushButton::released, [this] { QMessageBox::information(this, tr("Information"),
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this); tr("After pressing OK, first move your joystick horizontally, "
return motion_touch_dialog->exec(); "and then vertically."));
}); handleClick(
connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); }); analog_map_stick[analog_id],
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); [=](const Common::ParamPackage& params) {
connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); }); analogs_param[analog_id] = params;
connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); });
connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); });
connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
[this](int i) {
applyConfiguration(); applyConfiguration();
Settings::SaveProfile(Settings::values.profile); Settings::SaveProfile(ui->profile->currentIndex());
Settings::LoadProfile(i); },
loadConfiguration(); InputCommon::Polling::DeviceType::Analog);
});
timeout_timer->setSingleShot(true);
connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this]() {
Common::ParamPackage params;
for (auto& poller : device_pollers) {
params = poller->GetNextInput();
if (params.Has("engine")) {
setPollingResult(params, false);
return;
}
}
}); });
}
this->loadConfiguration(); connect(ui->buttonMotionTouch, &QPushButton::released, [this] {
QDialog* motion_touch_dialog = new ConfigureMotionTouch(this);
return motion_touch_dialog->exec();
});
connect(ui->buttonClearAll, &QPushButton::released, [this] { ClearAll(); });
connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
connect(ui->buttonNew, &QPushButton::released, [this] { newProfile(); });
connect(ui->buttonDelete, &QPushButton::released, [this] { deleteProfile(); });
connect(ui->buttonRename, &QPushButton::released, [this] { renameProfile(); });
// TODO(wwylele): enable this when we actually emulate it connect(ui->profile, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged),
ui->buttonHome->setEnabled(false); [this](int i) {
applyConfiguration();
Settings::SaveProfile(Settings::values.current_input_profile);
Settings::LoadProfile(i);
loadConfiguration();
});
timeout_timer->setSingleShot(true);
connect(timeout_timer.get(), &QTimer::timeout, [this]() { setPollingResult({}, true); });
connect(poll_timer.get(), &QTimer::timeout, [this]() {
Common::ParamPackage params;
for (auto& poller : device_pollers) {
params = poller->GetNextInput();
if (params.Has("engine")) {
setPollingResult(params, false);
return;
}
}
});
this->loadConfiguration();
// TODO(wwylele): enable this when we actually emulate it
ui->buttonHome->setEnabled(false);
} }
ConfigureInput::~ConfigureInput() = default; ConfigureInput::~ConfigureInput() = default;
@ -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

View File

@ -117,7 +117,7 @@ struct Values {
u16 udp_input_port; u16 udp_input_port;
u8 udp_pad_index; u8 udp_pad_index;
int current_input_profile; ///< The current input profile index int current_input_profile; ///< The current input profile index
std::vector<InputProfile> input_profiles; ///< The list of input profiles std::vector<InputProfile> input_profiles; ///< The list of input profiles
// Core // Core