diff options
Diffstat (limited to '')
-rw-r--r-- | src/citra_qt/configuration/config.cpp (renamed from src/citra_qt/config.cpp) | 84 | ||||
-rw-r--r-- | src/citra_qt/configuration/config.h (renamed from src/citra_qt/config.h) | 5 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure.ui (renamed from src/citra_qt/configure.ui) | 12 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_audio.cpp (renamed from src/citra_qt/configure_audio.cpp) | 2 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_audio.h (renamed from src/citra_qt/configure_audio.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_audio.ui (renamed from src/citra_qt/configure_audio.ui) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_debug.cpp (renamed from src/citra_qt/configure_debug.cpp) | 2 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_debug.h (renamed from src/citra_qt/configure_debug.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_debug.ui (renamed from src/citra_qt/configure_debug.ui) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_dialog.cpp (renamed from src/citra_qt/configure_dialog.cpp) | 4 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_dialog.h (renamed from src/citra_qt/configure_dialog.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_general.cpp (renamed from src/citra_qt/configure_general.cpp) | 2 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_general.h (renamed from src/citra_qt/configure_general.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_general.ui (renamed from src/citra_qt/configure_general.ui) | 2 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_graphics.cpp (renamed from src/citra_qt/configure_graphics.cpp) | 4 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_graphics.h (renamed from src/citra_qt/configure_graphics.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_graphics.ui (renamed from src/citra_qt/configure_graphics.ui) | 2 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_input.cpp | 205 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_input.h | 69 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_input.ui (renamed from src/citra_qt/configure_input.ui) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_system.cpp (renamed from src/citra_qt/configure_system.cpp) | 3 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_system.h (renamed from src/citra_qt/configure_system.h) | 0 | ||||
-rw-r--r-- | src/citra_qt/configuration/configure_system.ui (renamed from src/citra_qt/configure_system.ui) | 0 |
23 files changed, 360 insertions, 36 deletions
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/configuration/config.cpp index b65f57fdc..0b9b73f9e 100644 --- a/src/citra_qt/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -3,9 +3,10 @@ // Refer to the license.txt file included. #include <QSettings> -#include "citra_qt/config.h" +#include "citra_qt/configuration/config.h" #include "citra_qt/ui_settings.h" #include "common/file_util.h" +#include "input_common/main.h" Config::Config() { // TODO: Don't hardcode the path; let the frontend decide where to put the config files. @@ -16,25 +17,46 @@ Config::Config() { Reload(); } -const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> 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<int, Settings::NativeButton::NumButtons> Config::default_buttons = { + Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, + Qt::Key_Q, Qt::Key_W, Qt::Key_M, Qt::Key_N, Qt::Key_1, Qt::Key_2, Qt::Key_B, }; +const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{ + { + Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D, + }, + { + Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, Qt::Key_D, + }, +}}; + 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(); + for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { + std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]); + Settings::values.buttons[i] = + qt_config + ->value(Settings::NativeButton::mapping[i], QString::fromStdString(default_param)) + .toString() + .toStdString(); + if (Settings::values.buttons[i].empty()) + Settings::values.buttons[i] = default_param; + } + + for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { + std::string default_param = InputCommon::GenerateAnalogParamFromKeys( + default_analogs[i][0], default_analogs[i][1], default_analogs[i][2], + default_analogs[i][3], default_analogs[i][4], 0.5f); + Settings::values.analogs[i] = + qt_config + ->value(Settings::NativeAnalog::mapping[i], QString::fromStdString(default_param)) + .toString() + .toStdString(); + if (Settings::values.analogs[i].empty()) + Settings::values.analogs[i] = default_param; } - Settings::values.pad_circle_modifier_scale = - qt_config->value("pad_circle_modifier_scale", 0.5).toFloat(); + qt_config->endGroup(); qt_config->beginGroup("Core"); @@ -57,6 +79,15 @@ void Config::ReadValues() { Settings::values.layout_option = static_cast<Settings::LayoutOption>(qt_config->value("layout_option").toInt()); Settings::values.swap_screen = qt_config->value("swap_screen", false).toBool(); + Settings::values.custom_layout = qt_config->value("custom_layout", false).toBool(); + Settings::values.custom_top_left = qt_config->value("custom_top_left", 0).toInt(); + Settings::values.custom_top_top = qt_config->value("custom_top_top", 0).toInt(); + Settings::values.custom_top_right = qt_config->value("custom_top_right", 400).toInt(); + Settings::values.custom_top_bottom = qt_config->value("custom_top_bottom", 240).toInt(); + Settings::values.custom_bottom_left = qt_config->value("custom_bottom_left", 40).toInt(); + Settings::values.custom_bottom_top = qt_config->value("custom_bottom_top", 240).toInt(); + Settings::values.custom_bottom_right = qt_config->value("custom_bottom_right", 360).toInt(); + Settings::values.custom_bottom_bottom = qt_config->value("custom_bottom_bottom", 480).toInt(); qt_config->endGroup(); qt_config->beginGroup("Audio"); @@ -146,6 +177,7 @@ void Config::ReadValues() { UISettings::values.single_window_mode = qt_config->value("singleWindowMode", true).toBool(); UISettings::values.display_titlebar = qt_config->value("displayTitleBars", true).toBool(); + UISettings::values.show_status_bar = qt_config->value("showStatusBar", true).toBool(); UISettings::values.confirm_before_closing = qt_config->value("confirmClose", true).toBool(); UISettings::values.first_start = qt_config->value("firstStart", true).toBool(); @@ -154,12 +186,14 @@ void Config::ReadValues() { 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]]); + for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) { + qt_config->setValue(QString::fromStdString(Settings::NativeButton::mapping[i]), + QString::fromStdString(Settings::values.buttons[i])); + } + for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) { + qt_config->setValue(QString::fromStdString(Settings::NativeAnalog::mapping[i]), + QString::fromStdString(Settings::values.analogs[i])); } - qt_config->setValue("pad_circle_modifier_scale", - (double)Settings::values.pad_circle_modifier_scale); qt_config->endGroup(); qt_config->beginGroup("Core"); @@ -182,6 +216,15 @@ void Config::SaveValues() { qt_config->beginGroup("Layout"); qt_config->setValue("layout_option", static_cast<int>(Settings::values.layout_option)); qt_config->setValue("swap_screen", Settings::values.swap_screen); + qt_config->setValue("custom_layout", Settings::values.custom_layout); + qt_config->setValue("custom_top_left", Settings::values.custom_top_left); + qt_config->setValue("custom_top_top", Settings::values.custom_top_top); + qt_config->setValue("custom_top_right", Settings::values.custom_top_right); + qt_config->setValue("custom_top_bottom", Settings::values.custom_top_bottom); + qt_config->setValue("custom_bottom_left", Settings::values.custom_bottom_left); + qt_config->setValue("custom_bottom_top", Settings::values.custom_bottom_top); + qt_config->setValue("custom_bottom_right", Settings::values.custom_bottom_right); + qt_config->setValue("custom_bottom_bottom", Settings::values.custom_bottom_bottom); qt_config->endGroup(); qt_config->beginGroup("Audio"); @@ -252,6 +295,7 @@ void Config::SaveValues() { qt_config->setValue("singleWindowMode", UISettings::values.single_window_mode); qt_config->setValue("displayTitleBars", UISettings::values.display_titlebar); + qt_config->setValue("showStatusBar", UISettings::values.show_status_bar); qt_config->setValue("confirmClose", UISettings::values.confirm_before_closing); qt_config->setValue("firstStart", UISettings::values.first_start); diff --git a/src/citra_qt/config.h b/src/citra_qt/configuration/config.h index 79c901804..cbf745ea2 100644 --- a/src/citra_qt/config.h +++ b/src/citra_qt/configuration/config.h @@ -4,6 +4,7 @@ #pragma once +#include <array> #include <string> #include <QVariant> #include "core/settings.h" @@ -23,5 +24,7 @@ public: void Reload(); void Save(); - static const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults; + + static const std::array<int, Settings::NativeButton::NumButtons> default_buttons; + static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs; }; diff --git a/src/citra_qt/configure.ui b/src/citra_qt/configuration/configure.ui index 28b4a3b90..85e206e42 100644 --- a/src/citra_qt/configure.ui +++ b/src/citra_qt/configuration/configure.ui @@ -64,37 +64,37 @@ <customwidget> <class>ConfigureGeneral</class> <extends>QWidget</extends> - <header>configure_general.h</header> + <header>configuration/configure_general.h</header> <container>1</container> </customwidget> <customwidget> <class>ConfigureSystem</class> <extends>QWidget</extends> - <header>configure_system.h</header> + <header>configuration/configure_system.h</header> <container>1</container> </customwidget> <customwidget> <class>ConfigureAudio</class> <extends>QWidget</extends> - <header>configure_audio.h</header> + <header>configuration/configure_audio.h</header> <container>1</container> </customwidget> <customwidget> <class>ConfigureDebug</class> <extends>QWidget</extends> - <header>configure_debug.h</header> + <header>configuration/configure_debug.h</header> <container>1</container> </customwidget> <customwidget> <class>ConfigureInput</class> <extends>QWidget</extends> - <header>configure_input.h</header> + <header>configuration/configure_input.h</header> <container>1</container> </customwidget> <customwidget> <class>ConfigureGraphics</class> <extends>QWidget</extends> - <header>configure_graphics.h</header> + <header>configuration/configure_graphics.h</header> <container>1</container> </customwidget> </customwidgets> diff --git a/src/citra_qt/configure_audio.cpp b/src/citra_qt/configuration/configure_audio.cpp index 3ddcf9232..3fd1d127a 100644 --- a/src/citra_qt/configure_audio.cpp +++ b/src/citra_qt/configuration/configure_audio.cpp @@ -6,7 +6,7 @@ #include "audio_core/audio_core.h" #include "audio_core/sink.h" #include "audio_core/sink_details.h" -#include "citra_qt/configure_audio.h" +#include "citra_qt/configuration/configure_audio.h" #include "core/settings.h" #include "ui_configure_audio.h" diff --git a/src/citra_qt/configure_audio.h b/src/citra_qt/configuration/configure_audio.h index 8190e694f..8190e694f 100644 --- a/src/citra_qt/configure_audio.h +++ b/src/citra_qt/configuration/configure_audio.h diff --git a/src/citra_qt/configure_audio.ui b/src/citra_qt/configuration/configure_audio.ui index dd870eb61..dd870eb61 100644 --- a/src/citra_qt/configure_audio.ui +++ b/src/citra_qt/configuration/configure_audio.ui diff --git a/src/citra_qt/configure_debug.cpp b/src/citra_qt/configuration/configure_debug.cpp index dcc398eee..263f73f38 100644 --- a/src/citra_qt/configure_debug.cpp +++ b/src/citra_qt/configuration/configure_debug.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "citra_qt/configure_debug.h" +#include "citra_qt/configuration/configure_debug.h" #include "core/settings.h" #include "ui_configure_debug.h" diff --git a/src/citra_qt/configure_debug.h b/src/citra_qt/configuration/configure_debug.h index d167eb996..d167eb996 100644 --- a/src/citra_qt/configure_debug.h +++ b/src/citra_qt/configuration/configure_debug.h diff --git a/src/citra_qt/configure_debug.ui b/src/citra_qt/configuration/configure_debug.ui index bbbb0e3f4..bbbb0e3f4 100644 --- a/src/citra_qt/configure_debug.ui +++ b/src/citra_qt/configuration/configure_debug.ui diff --git a/src/citra_qt/configure_dialog.cpp b/src/citra_qt/configuration/configure_dialog.cpp index 525a7cc4e..dfc8c03a7 100644 --- a/src/citra_qt/configure_dialog.cpp +++ b/src/citra_qt/configuration/configure_dialog.cpp @@ -2,8 +2,8 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "citra_qt/config.h" -#include "citra_qt/configure_dialog.h" +#include "citra_qt/configuration/config.h" +#include "citra_qt/configuration/configure_dialog.h" #include "core/settings.h" #include "ui_configure.h" diff --git a/src/citra_qt/configure_dialog.h b/src/citra_qt/configuration/configure_dialog.h index 21fa1f501..21fa1f501 100644 --- a/src/citra_qt/configure_dialog.h +++ b/src/citra_qt/configuration/configure_dialog.h diff --git a/src/citra_qt/configure_general.cpp b/src/citra_qt/configuration/configure_general.cpp index ac90a6df4..a21176c34 100644 --- a/src/citra_qt/configure_general.cpp +++ b/src/citra_qt/configuration/configure_general.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "citra_qt/configure_general.h" +#include "citra_qt/configuration/configure_general.h" #include "citra_qt/ui_settings.h" #include "core/core.h" #include "core/settings.h" diff --git a/src/citra_qt/configure_general.h b/src/citra_qt/configuration/configure_general.h index 447552d8c..447552d8c 100644 --- a/src/citra_qt/configure_general.h +++ b/src/citra_qt/configuration/configure_general.h diff --git a/src/citra_qt/configure_general.ui b/src/citra_qt/configuration/configure_general.ui index 0f3352a1d..c739605a4 100644 --- a/src/citra_qt/configure_general.ui +++ b/src/citra_qt/configuration/configure_general.ui @@ -27,7 +27,7 @@ <item> <widget class="QCheckBox" name="toggle_deepscan"> <property name="text"> - <string>Recursive scan for game folder</string> + <string>Search sub-directories for games</string> </property> </widget> </item> diff --git a/src/citra_qt/configure_graphics.cpp b/src/citra_qt/configuration/configure_graphics.cpp index 54f799b47..b5a5ab1e1 100644 --- a/src/citra_qt/configure_graphics.cpp +++ b/src/citra_qt/configuration/configure_graphics.cpp @@ -2,7 +2,7 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "citra_qt/configure_graphics.h" +#include "citra_qt/configuration/configure_graphics.h" #include "core/core.h" #include "core/settings.h" #include "ui_configure_graphics.h" @@ -14,6 +14,8 @@ ConfigureGraphics::ConfigureGraphics(QWidget* parent) this->setConfiguration(); ui->toggle_vsync->setEnabled(!Core::System::GetInstance().IsPoweredOn()); + + ui->layoutBox->setEnabled(!Settings::values.custom_layout); } ConfigureGraphics::~ConfigureGraphics() {} diff --git a/src/citra_qt/configure_graphics.h b/src/citra_qt/configuration/configure_graphics.h index 5497a55f7..5497a55f7 100644 --- a/src/citra_qt/configure_graphics.h +++ b/src/citra_qt/configuration/configure_graphics.h diff --git a/src/citra_qt/configure_graphics.ui b/src/citra_qt/configuration/configure_graphics.ui index a091f4c60..228f2a869 100644 --- a/src/citra_qt/configure_graphics.ui +++ b/src/citra_qt/configuration/configure_graphics.ui @@ -126,7 +126,7 @@ </layout> </item> <item> - <widget class="QGroupBox" name="groupBox2"> + <widget class="QGroupBox" name="layoutBox"> <property name="title"> <string>Layout</string> </property> diff --git a/src/citra_qt/configuration/configure_input.cpp b/src/citra_qt/configuration/configure_input.cpp new file mode 100644 index 000000000..daac9b63a --- /dev/null +++ b/src/citra_qt/configuration/configure_input.cpp @@ -0,0 +1,205 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#include <algorithm> +#include <memory> +#include <utility> +#include <QTimer> +#include "citra_qt/configuration/config.h" +#include "citra_qt/configuration/configure_input.h" +#include "common/param_package.h" +#include "input_common/main.h" + +const std::array<std::string, ConfigureInput::ANALOG_SUB_BUTTONS_NUM> + ConfigureInput::analog_sub_buttons{{ + "up", "down", "left", "right", "modifier", + }}; + +static QString getKeyName(int key_code) { + switch (key_code) { + case Qt::Key_Shift: + return QObject::tr("Shift"); + case Qt::Key_Control: + return QObject::tr("Ctrl"); + case Qt::Key_Alt: + return QObject::tr("Alt"); + case Qt::Key_Meta: + return ""; + default: + return QKeySequence(key_code).toString(); + } +} + +static void SetButtonKey(int key, Common::ParamPackage& button_param) { + button_param = Common::ParamPackage{InputCommon::GenerateKeyboardParam(key)}; +} + +static void SetAnalogKey(int key, Common::ParamPackage& analog_param, + const std::string& button_name) { + if (analog_param.Get("engine", "") != "analog_from_button") { + analog_param = { + {"engine", "analog_from_button"}, {"modifier_scale", "0.5"}, + }; + } + analog_param.Set(button_name, InputCommon::GenerateKeyboardParam(key)); +} + +ConfigureInput::ConfigureInput(QWidget* parent) + : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), + timer(std::make_unique<QTimer>()) { + + ui->setupUi(this); + setFocusPolicy(Qt::ClickFocus); + + button_map = { + ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp, + ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR, + ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome, + }; + + analog_map = {{ + { + ui->buttonCircleUp, ui->buttonCircleDown, ui->buttonCircleLeft, ui->buttonCircleRight, + ui->buttonCircleMod, + }, + { + ui->buttonCStickUp, ui->buttonCStickDown, ui->buttonCStickLeft, ui->buttonCStickRight, + nullptr, + }, + }}; + + for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { + if (button_map[button_id]) + connect(button_map[button_id], &QPushButton::released, [=]() { + handleClick(button_map[button_id], + [=](int key) { SetButtonKey(key, buttons_param[button_id]); }); + }); + } + + 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[analog_id][sub_button_id] != nullptr) { + connect(analog_map[analog_id][sub_button_id], &QPushButton::released, [=]() { + handleClick(analog_map[analog_id][sub_button_id], [=](int key) { + SetAnalogKey(key, analogs_param[analog_id], + analog_sub_buttons[sub_button_id]); + }); + }); + } + } + } + + connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); + + timer->setSingleShot(true); + connect(timer.get(), &QTimer::timeout, [this]() { + releaseKeyboard(); + releaseMouse(); + key_setter = boost::none; + updateButtonLabels(); + }); + + this->loadConfiguration(); + + // TODO(wwylele): enable these when the input emulation for them is implemented + ui->buttonZL->setEnabled(false); + ui->buttonZR->setEnabled(false); + ui->buttonHome->setEnabled(false); + ui->buttonCStickUp->setEnabled(false); + ui->buttonCStickDown->setEnabled(false); + ui->buttonCStickLeft->setEnabled(false); + ui->buttonCStickRight->setEnabled(false); +} + +void ConfigureInput::applyConfiguration() { + std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(), + [](const Common::ParamPackage& param) { return param.Serialize(); }); + std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(), + [](const Common::ParamPackage& param) { return param.Serialize(); }); + + Settings::Apply(); +} + +void ConfigureInput::loadConfiguration() { + std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(), + buttons_param.begin(), + [](const std::string& str) { return Common::ParamPackage(str); }); + std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(), + analogs_param.begin(), + [](const std::string& str) { return Common::ParamPackage(str); }); + updateButtonLabels(); +} + +void ConfigureInput::restoreDefaults() { + for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) { + SetButtonKey(Config::default_buttons[button_id], buttons_param[button_id]); + } + + 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++) { + SetAnalogKey(Config::default_analogs[analog_id][sub_button_id], + analogs_param[analog_id], analog_sub_buttons[sub_button_id]); + } + } + updateButtonLabels(); + applyConfiguration(); +} + +void ConfigureInput::updateButtonLabels() { + QString non_keyboard(tr("[non-keyboard]")); + + auto KeyToText = [&non_keyboard](const Common::ParamPackage& param) { + if (param.Get("engine", "") != "keyboard") { + return non_keyboard; + } else { + return getKeyName(param.Get("code", 0)); + } + }; + + for (int button = 0; button < Settings::NativeButton::NumButtons; button++) { + button_map[button]->setText(KeyToText(buttons_param[button])); + } + + for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) { + if (analogs_param[analog_id].Get("engine", "") != "analog_from_button") { + for (QPushButton* button : analog_map[analog_id]) { + if (button) + button->setText(non_keyboard); + } + } else { + for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) { + Common::ParamPackage param( + analogs_param[analog_id].Get(analog_sub_buttons[sub_button_id], "")); + if (analog_map[analog_id][sub_button_id]) + analog_map[analog_id][sub_button_id]->setText(KeyToText(param)); + } + } + } +} + +void ConfigureInput::handleClick(QPushButton* button, std::function<void(int)> new_key_setter) { + button->setText(tr("[press key]")); + button->setFocus(); + + key_setter = new_key_setter; + + grabKeyboard(); + grabMouse(); + timer->start(5000); // Cancel after 5 seconds +} + +void ConfigureInput::keyPressEvent(QKeyEvent* event) { + releaseKeyboard(); + releaseMouse(); + + if (!key_setter || !event) + return; + + if (event->key() != Qt::Key_Escape) + (*key_setter)(event->key()); + + updateButtonLabels(); + key_setter = boost::none; + timer->stop(); +} diff --git a/src/citra_qt/configuration/configure_input.h b/src/citra_qt/configuration/configure_input.h new file mode 100644 index 000000000..c950fbcb4 --- /dev/null +++ b/src/citra_qt/configuration/configure_input.h @@ -0,0 +1,69 @@ +// Copyright 2016 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> +#include <functional> +#include <memory> +#include <string> +#include <QKeyEvent> +#include <QWidget> +#include <boost/optional.hpp> +#include "common/param_package.h" +#include "core/settings.h" +#include "ui_configure_input.h" + +class QPushButton; +class QString; +class QTimer; + +namespace Ui { +class ConfigureInput; +} + +class ConfigureInput : public QWidget { + Q_OBJECT + +public: + explicit ConfigureInput(QWidget* parent = nullptr); + + /// Save all button configurations to settings file + void applyConfiguration(); + +private: + std::unique_ptr<Ui::ConfigureInput> ui; + + std::unique_ptr<QTimer> timer; + + /// This will be the the setting function when an input is awaiting configuration. + boost::optional<std::function<void(int)>> key_setter; + + std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param; + std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param; + + static constexpr int ANALOG_SUB_BUTTONS_NUM = 5; + + /// Each button input is represented by a QPushButton. + std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map; + + /// Each analog input is represented by five QPushButtons which represents up, down, left, right + /// and modifier + std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs> + analog_map; + + static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons; + + /// Load configuration settings. + void loadConfiguration(); + /// Restore all buttons to their default values. + void restoreDefaults(); + /// Update UI to reflect current configuration. + void updateButtonLabels(); + + /// Called when the button was pressed. + void handleClick(QPushButton* button, std::function<void(int)> new_key_setter); + /// Handle key press events. + void keyPressEvent(QKeyEvent* event) override; +}; diff --git a/src/citra_qt/configure_input.ui b/src/citra_qt/configuration/configure_input.ui index 2760787e5..2760787e5 100644 --- a/src/citra_qt/configure_input.ui +++ b/src/citra_qt/configuration/configure_input.ui diff --git a/src/citra_qt/configure_system.cpp b/src/citra_qt/configuration/configure_system.cpp index eb1276ef3..a3a9015a4 100644 --- a/src/citra_qt/configure_system.cpp +++ b/src/citra_qt/configuration/configure_system.cpp @@ -2,8 +2,9 @@ // Licensed under GPLv2 or any later version // Refer to the license.txt file included. -#include "citra_qt/configure_system.h" +#include "citra_qt/configuration/configure_system.h" #include "citra_qt/ui_settings.h" +#include "core/core.h" #include "core/hle/service/cfg/cfg.h" #include "core/hle/service/fs/archive.h" #include "ui_configure_system.h" diff --git a/src/citra_qt/configure_system.h b/src/citra_qt/configuration/configure_system.h index db0ead13c..db0ead13c 100644 --- a/src/citra_qt/configure_system.h +++ b/src/citra_qt/configuration/configure_system.h diff --git a/src/citra_qt/configure_system.ui b/src/citra_qt/configuration/configure_system.ui index cc54fa37f..cc54fa37f 100644 --- a/src/citra_qt/configure_system.ui +++ b/src/citra_qt/configuration/configure_system.ui |