diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp index 4c03bbb95..0c47ef899 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/config.cpp @@ -1,223 +1,223 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "citra_qt/config.h" -#include "citra_qt/ui_settings.h" - -#include "common/file_util.h" - -Config::Config() { - // TODO: Don't hardcode the path; let the frontend decide where to put the config files. - qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; - FileUtil::CreateFullPath(qt_config_loc); - qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); - - Reload(); -} - -const std::array Config::defaults = { - // directly mapped keys - Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, - Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, - Qt::Key_M, Qt::Key_N, Qt::Key_B, - Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, - Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, - - // indirectly mapped keys - Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, - Qt::Key_D, -}; - -const std::array& Config::getDefaultInput() -{ - return defaults; -} - -void Config::ReadValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - Settings::values.input_mappings[Settings::NativeInput::All[i]] = - qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); - } - Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); - Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); - Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); - - Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); - Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); - Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); - Settings::values.region_value = qt_config->value("region_value", 1).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); - Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - UISettings::values.geometry = qt_config->value("geometry").toByteArray(); - UISettings::values.state = qt_config->value("state").toByteArray(); - UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); - UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); - UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); - UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - UISettings::values.roms_path = qt_config->value("romsPath").toString(); - UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); - UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); - UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); - UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); - qt_config->endGroup(); - - qt_config->beginGroup("Shortcuts"); - QStringList groups = qt_config->childGroups(); - for (auto group : groups) { - qt_config->beginGroup(group); - - QStringList hotkeys = qt_config->childGroups(); - for (auto hotkey : hotkeys) { - qt_config->beginGroup(hotkey); - UISettings::values.shortcuts.emplace_back( - UISettings::Shortcut(group + "/" + hotkey, - UISettings::ContextualShortcut(qt_config->value("KeySeq").toString(), - qt_config->value("Context").toInt()))); - qt_config->endGroup(); - } - - qt_config->endGroup(); - } - qt_config->endGroup(); - - UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); - UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); - UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); - UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); - - qt_config->endGroup(); -} - -void Config::SaveValues() { - qt_config->beginGroup("Controls"); - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { - qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), - Settings::values.input_mappings[Settings::NativeInput::All[i]]); - } - qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); - qt_config->endGroup(); - - qt_config->beginGroup("Core"); - qt_config->setValue("frame_skip", Settings::values.frame_skip); - qt_config->endGroup(); - - qt_config->beginGroup("Renderer"); - qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); - qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); - qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); - - // Cast to double because Qt's written float values are not human-readable - qt_config->setValue("bg_red", (double)Settings::values.bg_red); - qt_config->setValue("bg_green", (double)Settings::values.bg_green); - qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); - qt_config->endGroup(); - - qt_config->beginGroup("Audio"); - qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); - qt_config->endGroup(); - - qt_config->beginGroup("Data Storage"); - qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); - qt_config->endGroup(); - - qt_config->beginGroup("System"); - qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); - qt_config->setValue("region_value", Settings::values.region_value); - qt_config->endGroup(); - - qt_config->beginGroup("Miscellaneous"); - qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); - qt_config->endGroup(); - - qt_config->beginGroup("Debugging"); - qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); - qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); - qt_config->endGroup(); - - qt_config->beginGroup("UI"); - - qt_config->beginGroup("UILayout"); - qt_config->setValue("geometry", UISettings::values.geometry); - qt_config->setValue("state", UISettings::values.state); - qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); - qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); - qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); - qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); - qt_config->endGroup(); - - qt_config->beginGroup("Paths"); - qt_config->setValue("romsPath", UISettings::values.roms_path); - qt_config->setValue("symbolsPath", UISettings::values.symbols_path); - qt_config->setValue("gameListRootDir", UISettings::values.gamedir); - qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); - qt_config->setValue("recentFiles", UISettings::values.recent_files); - qt_config->endGroup(); - - qt_config->beginGroup("Shortcuts"); - for (auto shortcut : UISettings::values.shortcuts) { - qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); - qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); - } - qt_config->endGroup(); - - qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); - qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); - qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); - qt_config->setValue("firstStart", UISettings::values.first_start); - - qt_config->endGroup(); -} - -void Config::Reload() { - ReadValues(); - Settings::Apply(); -} - -void Config::Save() { - SaveValues(); -} - -Config::~Config() { - Save(); - - delete qt_config; -} \ No newline at end of file +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "citra_qt/config.h" +#include "citra_qt/ui_settings.h" + +#include "common/file_util.h" + +Config::Config() { + // TODO: Don't hardcode the path; let the frontend decide where to put the config files. + qt_config_loc = FileUtil::GetUserPath(D_CONFIG_IDX) + "qt-config.ini"; + FileUtil::CreateFullPath(qt_config_loc); + qt_config = new QSettings(QString::fromStdString(qt_config_loc), QSettings::IniFormat); + + Reload(); +} + +const std::array Config::defaults = { + // directly mapped keys + Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, + Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, + Qt::Key_M, Qt::Key_N, Qt::Key_B, + Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, + Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, + + // indirectly mapped keys + Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, + Qt::Key_D, +}; + +const std::array& Config::getDefaultInput() +{ + return defaults; +} + +void Config::ReadValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + Settings::values.input_mappings[Settings::NativeInput::All[i]] = + qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]).toInt(); + } + Settings::values.pad_circle_modifier_scale = qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + Settings::values.frame_skip = qt_config->value("frame_skip", 0).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + Settings::values.use_hw_renderer = qt_config->value("use_hw_renderer", false).toBool(); + Settings::values.use_shader_jit = qt_config->value("use_shader_jit", true).toBool(); + Settings::values.use_scaled_resolution = qt_config->value("use_scaled_resolution", false).toBool(); + + Settings::values.bg_red = qt_config->value("bg_red", 1.0).toFloat(); + Settings::values.bg_green = qt_config->value("bg_green", 1.0).toFloat(); + Settings::values.bg_blue = qt_config->value("bg_blue", 1.0).toFloat(); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + Settings::values.sink_id = qt_config->value("output_engine", "auto").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + Settings::values.use_virtual_sd = qt_config->value("use_virtual_sd", true).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + Settings::values.is_new_3ds = qt_config->value("is_new_3ds", false).toBool(); + Settings::values.region_value = qt_config->value("region_value", 1).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString(); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + Settings::values.use_gdbstub = qt_config->value("use_gdbstub", false).toBool(); + Settings::values.gdbstub_port = qt_config->value("gdbstub_port", 24689).toInt(); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + UISettings::values.geometry = qt_config->value("geometry").toByteArray(); + UISettings::values.state = qt_config->value("state").toByteArray(); + UISettings::values.renderwindow_geometry = qt_config->value("geometryRenderWindow").toByteArray(); + UISettings::values.gamelist_header_state = qt_config->value("gameListHeaderState").toByteArray(); + UISettings::values.microprofile_geometry = qt_config->value("microProfileDialogGeometry").toByteArray(); + UISettings::values.microprofile_visible = qt_config->value("microProfileDialogVisible", false).toBool(); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + UISettings::values.roms_path = qt_config->value("romsPath").toString(); + UISettings::values.symbols_path = qt_config->value("symbolsPath").toString(); + UISettings::values.gamedir = qt_config->value("gameListRootDir", ".").toString(); + UISettings::values.gamedir_deepscan = qt_config->value("gameListDeepScan", false).toBool(); + UISettings::values.recent_files = qt_config->value("recentFiles").toStringList(); + qt_config->endGroup(); + + qt_config->beginGroup("Shortcuts"); + QStringList groups = qt_config->childGroups(); + for (auto group : groups) { + qt_config->beginGroup(group); + + QStringList hotkeys = qt_config->childGroups(); + for (auto hotkey : hotkeys) { + qt_config->beginGroup(hotkey); + UISettings::values.shortcuts.emplace_back( + UISettings::Shortcut(group + "/" + hotkey, + UISettings::ContextualShortcut(qt_config->value("KeySeq").toString(), + qt_config->value("Context").toInt()))); + qt_config->endGroup(); + } + + qt_config->endGroup(); + } + qt_config->endGroup(); + + UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); + UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); + UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); + UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); + + qt_config->endGroup(); +} + +void Config::SaveValues() { + qt_config->beginGroup("Controls"); + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { + qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), + Settings::values.input_mappings[Settings::NativeInput::All[i]]); + } + qt_config->setValue("pad_circle_modifier_scale", (double)Settings::values.pad_circle_modifier_scale); + qt_config->endGroup(); + + qt_config->beginGroup("Core"); + qt_config->setValue("frame_skip", Settings::values.frame_skip); + qt_config->endGroup(); + + qt_config->beginGroup("Renderer"); + qt_config->setValue("use_hw_renderer", Settings::values.use_hw_renderer); + qt_config->setValue("use_shader_jit", Settings::values.use_shader_jit); + qt_config->setValue("use_scaled_resolution", Settings::values.use_scaled_resolution); + + // Cast to double because Qt's written float values are not human-readable + qt_config->setValue("bg_red", (double)Settings::values.bg_red); + qt_config->setValue("bg_green", (double)Settings::values.bg_green); + qt_config->setValue("bg_blue", (double)Settings::values.bg_blue); + qt_config->endGroup(); + + qt_config->beginGroup("Audio"); + qt_config->setValue("output_engine", QString::fromStdString(Settings::values.sink_id)); + qt_config->endGroup(); + + qt_config->beginGroup("Data Storage"); + qt_config->setValue("use_virtual_sd", Settings::values.use_virtual_sd); + qt_config->endGroup(); + + qt_config->beginGroup("System"); + qt_config->setValue("is_new_3ds", Settings::values.is_new_3ds); + qt_config->setValue("region_value", Settings::values.region_value); + qt_config->endGroup(); + + qt_config->beginGroup("Miscellaneous"); + qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter)); + qt_config->endGroup(); + + qt_config->beginGroup("Debugging"); + qt_config->setValue("use_gdbstub", Settings::values.use_gdbstub); + qt_config->setValue("gdbstub_port", Settings::values.gdbstub_port); + qt_config->endGroup(); + + qt_config->beginGroup("UI"); + + qt_config->beginGroup("UILayout"); + qt_config->setValue("geometry", UISettings::values.geometry); + qt_config->setValue("state", UISettings::values.state); + qt_config->setValue("geometryRenderWindow", UISettings::values.renderwindow_geometry); + qt_config->setValue("gameListHeaderState", UISettings::values.gamelist_header_state); + qt_config->setValue("microProfileDialogGeometry", UISettings::values.microprofile_geometry); + qt_config->setValue("microProfileDialogVisible", UISettings::values.microprofile_visible); + qt_config->endGroup(); + + qt_config->beginGroup("Paths"); + qt_config->setValue("romsPath", UISettings::values.roms_path); + qt_config->setValue("symbolsPath", UISettings::values.symbols_path); + qt_config->setValue("gameListRootDir", UISettings::values.gamedir); + qt_config->setValue("gameListDeepScan", UISettings::values.gamedir_deepscan); + qt_config->setValue("recentFiles", UISettings::values.recent_files); + qt_config->endGroup(); + + qt_config->beginGroup("Shortcuts"); + for (auto shortcut : UISettings::values.shortcuts) { + qt_config->setValue(shortcut.first + "/KeySeq", shortcut.second.first); + qt_config->setValue(shortcut.first + "/Context", shortcut.second.second); + } + qt_config->endGroup(); + + qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); + qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); + qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); + qt_config->setValue("firstStart", UISettings::values.first_start); + + qt_config->endGroup(); +} + +void Config::Reload() { + ReadValues(); + Settings::Apply(); +} + +void Config::Save() { + SaveValues(); +} + +Config::~Config() { + Save(); + + delete qt_config; +} diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h index d98ed5468..d56d10658 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/config.h @@ -1,28 +1,28 @@ -// Copyright 2014 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once -#include -#include - -#include "core/settings.h" - -class QSettings; - -class Config { - QSettings* qt_config; - std::string qt_config_loc; - - static const std::array defaults; - - void ReadValues(); - void SaveValues(); -public: - Config(); - ~Config(); - - void Reload(); - void Save(); - static const std::array& getDefaultInput(); -}; +// Copyright 2014 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once +#include +#include + +#include "core/settings.h" + +class QSettings; + +class Config { + QSettings* qt_config; + std::string qt_config_loc; + + static const std::array defaults; + + void ReadValues(); + void SaveValues(); +public: + Config(); + ~Config(); + + void Reload(); + void Save(); + static const std::array& getDefaultInput(); +}; diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp index 5e925dfc1..6046f527c 100644 --- a/src/citra_qt/configure_input.cpp +++ b/src/citra_qt/configure_input.cpp @@ -1,167 +1,167 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#include - -#include "citra_qt/configure_input.h" - -ConfigureInput::ConfigureInput(QWidget* parent) : - QWidget(parent), - ui(new Ui::ConfigureInput) -{ - ui->setupUi(this); - - // Initialize mapping of input enum to UI button. - input_mapping = { - { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, - { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, - { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, - { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, - { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, - { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, - { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, - { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, - { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, - { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, - { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, - { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, - { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, - { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, - { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, - { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, - { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, - { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, - { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, - { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, - }; - - // Attach handle click method to each button click. - for (const auto& entry : input_mapping) { - connect(entry.second, SIGNAL(released()), this, SLOT(handleClick())); - } - connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); - setFocusPolicy(Qt::ClickFocus); - this->setConfiguration(); -} - -ConfigureInput::~ConfigureInput() -{ -} - -/// Event handler for all button released() event. -void ConfigureInput::handleClick() -{ - QPushButton* sender = qobject_cast(QObject::sender()); - previous_mapping = sender->text(); - sender->setText(tr("[waiting]")); - sender->setFocus(); - grabKeyboard(); - grabMouse(); - changing_button = sender; -} - -/// Save all button configurations to settings file -void ConfigureInput::applyConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); - Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; - } - Settings::Apply(); -} - -/// Load configuration settings into button text -void ConfigureInput::setConfiguration() -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(Settings::values.input_mappings[i]); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } -} - -/// Handle key press event for input tab when a button is 'waiting'. -void ConfigureInput::keyPressEvent(QKeyEvent* event) -{ - if (changing_button != nullptr && event->key() != Qt::Key_unknown) - { - key_pressed = event->key(); - setKey(); - } -} - -/// Set button text to name of key pressed. -void ConfigureInput::setKey() -{ - QString key_value = getKeyName(key_pressed); - if (key_pressed == Qt::Key_Escape) - changing_button->setText(previous_mapping); - else - changing_button->setText(key_value); - - key_pressed = Qt::Key_unknown; - releaseKeyboard(); - releaseMouse(); - changing_button = nullptr; - previous_mapping = nullptr; -} - -/// Convert key ASCII value to its' letter/name -QString ConfigureInput::getKeyName(int key_code) const -{ - if (key_code == Qt::Key_Shift) - return tr("Shift"); - - if (key_code == Qt::Key_Control) - return tr("Ctrl"); - - if (key_code == Qt::Key_Alt) - return tr("Alt"); - - if (key_code == Qt::Key_Meta) - return ""; - - if (key_code == -1) - return ""; - - return QKeySequence(key_code).toString(); -} - -/// Convert letter/name of key to its ASCII value. -Qt::Key ConfigureInput::getKeyValue(const QString& text) const -{ - if (text == "Shift") - return Qt::Key_Shift; - if (text == "Ctrl") - return Qt::Key_Control; - if (text == "Alt") - return Qt::Key_Alt; - if (text == "Meta") - return Qt::Key_unknown; - if (text == "") - return Qt::Key_unknown; - return Qt::Key(QKeySequence(text)[0]); -} - -/// Check all inputs for duplicate keys. Clears out any other button with same key as new button. -void ConfigureInput::removeDuplicates(const QString& newValue) -{ - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { - QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); - if (newValue == oldValue) - input_mapping[Settings::NativeInput::Values(i)]->setText(""); - } - } -} - -/// Restore all buttons to their default values. -void ConfigureInput::restoreDefaults() { - for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { - QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); - input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); - } -} \ No newline at end of file +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include + +#include "citra_qt/configure_input.h" + +ConfigureInput::ConfigureInput(QWidget* parent) : + QWidget(parent), + ui(new Ui::ConfigureInput) +{ + ui->setupUi(this); + + // Initialize mapping of input enum to UI button. + input_mapping = { + { std::make_pair(Settings::NativeInput::Values::A, ui->btnFaceA) }, + { std::make_pair(Settings::NativeInput::Values::B, ui->btnFaceB) }, + { std::make_pair(Settings::NativeInput::Values::X, ui->btnFaceX) }, + { std::make_pair(Settings::NativeInput::Values::Y, ui->btnFaceY) }, + { std::make_pair(Settings::NativeInput::Values::L, ui->btnShdrL) }, + { std::make_pair(Settings::NativeInput::Values::R, ui->btnShdrR) }, + { std::make_pair(Settings::NativeInput::Values::ZL, ui->btnShdrZL) }, + { std::make_pair(Settings::NativeInput::Values::ZR, ui->btnShdrZR) }, + { std::make_pair(Settings::NativeInput::Values::START, ui->btnStart) }, + { std::make_pair(Settings::NativeInput::Values::SELECT, ui->btnSelect) }, + { std::make_pair(Settings::NativeInput::Values::HOME, ui->btnHome) }, + { std::make_pair(Settings::NativeInput::Values::DUP, ui->btnDirUp) }, + { std::make_pair(Settings::NativeInput::Values::DDOWN, ui->btnDirDown) }, + { std::make_pair(Settings::NativeInput::Values::DLEFT, ui->btnDirLeft) }, + { std::make_pair(Settings::NativeInput::Values::DRIGHT, ui->btnDirRight) }, + { std::make_pair(Settings::NativeInput::Values::CUP, ui->btnStickUp) }, + { std::make_pair(Settings::NativeInput::Values::CDOWN, ui->btnStickDown) }, + { std::make_pair(Settings::NativeInput::Values::CLEFT, ui->btnStickLeft) }, + { std::make_pair(Settings::NativeInput::Values::CRIGHT, ui->btnStickRight) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_UP, ui->btnCircleUp) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_DOWN, ui->btnCircleDown) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_LEFT, ui->btnCircleLeft) }, + { std::make_pair(Settings::NativeInput::Values::CIRCLE_RIGHT, ui->btnCircleRight) }, + }; + + // Attach handle click method to each button click. + for (const auto& entry : input_mapping) { + connect(entry.second, SIGNAL(released()), this, SLOT(handleClick())); + } + connect(ui->btnRestoreDefaults, SIGNAL(released()), this, SLOT(restoreDefaults())); + setFocusPolicy(Qt::ClickFocus); + this->setConfiguration(); +} + +ConfigureInput::~ConfigureInput() +{ +} + +/// Event handler for all button released() event. +void ConfigureInput::handleClick() +{ + QPushButton* sender = qobject_cast(QObject::sender()); + previous_mapping = sender->text(); + sender->setText(tr("[waiting]")); + sender->setFocus(); + grabKeyboard(); + grabMouse(); + changing_button = sender; +} + +/// Save all button configurations to settings file +void ConfigureInput::applyConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + int value = getKeyValue(input_mapping[Settings::NativeInput::Values(i)]->text()); + Settings::values.input_mappings[Settings::NativeInput::All[i]] = value; + } + Settings::Apply(); +} + +/// Load configuration settings into button text +void ConfigureInput::setConfiguration() +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(Settings::values.input_mappings[i]); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} + +/// Handle key press event for input tab when a button is 'waiting'. +void ConfigureInput::keyPressEvent(QKeyEvent* event) +{ + if (changing_button != nullptr && event->key() != Qt::Key_unknown) + { + key_pressed = event->key(); + setKey(); + } +} + +/// Set button text to name of key pressed. +void ConfigureInput::setKey() +{ + QString key_value = getKeyName(key_pressed); + if (key_pressed == Qt::Key_Escape) + changing_button->setText(previous_mapping); + else + changing_button->setText(key_value); + + key_pressed = Qt::Key_unknown; + releaseKeyboard(); + releaseMouse(); + changing_button = nullptr; + previous_mapping = nullptr; +} + +/// Convert key ASCII value to its' letter/name +QString ConfigureInput::getKeyName(int key_code) const +{ + if (key_code == Qt::Key_Shift) + return tr("Shift"); + + if (key_code == Qt::Key_Control) + return tr("Ctrl"); + + if (key_code == Qt::Key_Alt) + return tr("Alt"); + + if (key_code == Qt::Key_Meta) + return ""; + + if (key_code == -1) + return ""; + + return QKeySequence(key_code).toString(); +} + +/// Convert letter/name of key to its ASCII value. +Qt::Key ConfigureInput::getKeyValue(const QString& text) const +{ + if (text == "Shift") + return Qt::Key_Shift; + if (text == "Ctrl") + return Qt::Key_Control; + if (text == "Alt") + return Qt::Key_Alt; + if (text == "Meta") + return Qt::Key_unknown; + if (text == "") + return Qt::Key_unknown; + return Qt::Key(QKeySequence(text)[0]); +} + +/// Check all inputs for duplicate keys. Clears out any other button with same key as new button. +void ConfigureInput::removeDuplicates(const QString& newValue) +{ + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + if (changing_button != input_mapping[Settings::NativeInput::Values(i)]) { + QString oldValue = input_mapping[Settings::NativeInput::Values(i)]->text(); + if (newValue == oldValue) + input_mapping[Settings::NativeInput::Values(i)]->setText(""); + } + } +} + +/// Restore all buttons to their default values. +void ConfigureInput::restoreDefaults() { + for (int i = 0; i < Settings::NativeInput::NUM_INPUTS - 1; ++i) { + QString keyValue = getKeyName(Config::getDefaultInput()[i].toInt()); + input_mapping[Settings::NativeInput::Values(i)]->setText(keyValue); + } +} diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h index 823b31580..cfa4a5163 100644 --- a/src/citra_qt/configure_input.h +++ b/src/citra_qt/configure_input.h @@ -1,47 +1,47 @@ -// Copyright 2016 Citra Emulator Project -// Licensed under GPLv2 or any later version -// Refer to the license.txt file included. - -#pragma once - -#include -#include -#include - -#include "citra_qt/config.h" -#include "core/settings.h" -#include "ui_configure_input.h" - -class QPushButton; -class QString; - -namespace Ui { - class ConfigureInput; -} - -class ConfigureInput : public QWidget -{ - Q_OBJECT - -public: - explicit ConfigureInput(QWidget* parent = nullptr); - ~ConfigureInput(); - void applyConfiguration(); - - public Q_SLOTS: - void handleClick(); - void restoreDefaults(); -private: - std::unique_ptr ui; - std::map input_mapping; - int key_pressed; - QPushButton* changing_button = nullptr; /// button currently waiting for key press. - QString previous_mapping; - - void setConfiguration(); - void setKey(); - void removeDuplicates(const QString& newValue); - void keyPressEvent(QKeyEvent* event) override; - QString getKeyName(int key_code) const; - Qt::Key ConfigureInput::getKeyValue(const QString& text) const; -}; +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include + +#include "citra_qt/config.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; + +namespace Ui { + class ConfigureInput; +} + +class ConfigureInput : public QWidget +{ + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + ~ConfigureInput(); + void applyConfiguration(); + + public Q_SLOTS: + void handleClick(); + void restoreDefaults(); +private: + std::unique_ptr ui; + std::map input_mapping; + int key_pressed; + QPushButton* changing_button = nullptr; /// button currently waiting for key press. + QString previous_mapping; + + void setConfiguration(); + void setKey(); + void removeDuplicates(const QString& newValue); + void keyPressEvent(QKeyEvent* event) override; + QString getKeyName(int key_code) const; + Qt::Key ConfigureInput::getKeyValue(const QString& text) const; +}; diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configure_input.ui index 5b7c568d1..fef62cb10 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configure_input.ui @@ -1,1004 +1,1004 @@ - - - ConfigureInput - - - - 0 - 0 - 390 - 445 - - - - ConfigureInput - - - - - - 2 - - - - - Face Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - A: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - B: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - X: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Y: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Directional Pad - - - false - - - false - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - Shoulder Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - L: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZR: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - R: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - ZL: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - Circle Pad - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - 2 - - - - - C-Stick - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Left: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Down: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Right: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Up: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - System Buttons - - - false - - - false - - - - - 10 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Start: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 100 - 20 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Select: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - 10 - 70 - 71 - 50 - - - - - - 0 - 0 - 51 - 16 - - - - Home: - - - - - - 0 - 20 - 71 - 26 - - - - - - - - - - - - - - - - 0 - 50 - - - - - 0 - 26 - - - - QFrame::StyledPanel - - - QFrame::Raised - - - - - 260 - 0 - 110 - 26 - - - - - 0 - 0 - - - - - 0 - 0 - - - - - 0 - 0 - - - - Qt::LeftToRight - - - Restore Defaults - - - - - - - - - + + + ConfigureInput + + + + 0 + 0 + 390 + 445 + + + + ConfigureInput + + + + + + 2 + + + + + Face Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + A: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + B: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + X: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Y: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Directional Pad + + + false + + + false + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + Shoulder Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + L: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZR: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + R: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + ZL: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + Circle Pad + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + 2 + + + + + C-Stick + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Left: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Down: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Right: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Up: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + System Buttons + + + false + + + false + + + + + 10 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Start: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 100 + 20 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Select: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + 10 + 70 + 71 + 50 + + + + + + 0 + 0 + 51 + 16 + + + + Home: + + + + + + 0 + 20 + 71 + 26 + + + + + + + + + + + + + + + + 0 + 50 + + + + + 0 + 26 + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + 260 + 0 + 110 + 26 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Restore Defaults + + + + + + + + +