summaryrefslogtreecommitdiff
path: root/src/citra_qt
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra_qt')
-rw-r--r--src/citra_qt/CMakeLists.txt2
-rw-r--r--src/citra_qt/bootmanager.cpp26
-rw-r--r--src/citra_qt/bootmanager.h6
-rw-r--r--src/citra_qt/config.cpp62
-rw-r--r--src/citra_qt/config.h5
-rw-r--r--src/citra_qt/configure_input.cpp178
-rw-r--r--src/citra_qt/configure_input.h34
7 files changed, 204 insertions, 109 deletions
diff --git a/src/citra_qt/CMakeLists.txt b/src/citra_qt/CMakeLists.txt
index 15a6ccf9a..2b1c59a92 100644
--- a/src/citra_qt/CMakeLists.txt
+++ b/src/citra_qt/CMakeLists.txt
@@ -97,7 +97,7 @@ if (APPLE)
97else() 97else()
98 add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS}) 98 add_executable(citra-qt ${SRCS} ${HEADERS} ${UI_HDRS})
99endif() 99endif()
100target_link_libraries(citra-qt core video_core audio_core common) 100target_link_libraries(citra-qt core video_core audio_core common input_common)
101target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS}) 101target_link_libraries(citra-qt ${OPENGL_gl_LIBRARY} ${CITRA_QT_LIBS})
102target_link_libraries(citra-qt ${PLATFORM_LIBRARIES} Threads::Threads) 102target_link_libraries(citra-qt ${PLATFORM_LIBRARIES} Threads::Threads)
103 103
diff --git a/src/citra_qt/bootmanager.cpp b/src/citra_qt/bootmanager.cpp
index 69d18cf0c..28264df9a 100644
--- a/src/citra_qt/bootmanager.cpp
+++ b/src/citra_qt/bootmanager.cpp
@@ -13,7 +13,9 @@
13#include "common/scm_rev.h" 13#include "common/scm_rev.h"
14#include "common/string_util.h" 14#include "common/string_util.h"
15#include "core/core.h" 15#include "core/core.h"
16#include "core/frontend/key_map.h" 16#include "core/settings.h"
17#include "input_common/keyboard.h"
18#include "input_common/main.h"
17#include "video_core/debug_utils/debug_utils.h" 19#include "video_core/debug_utils/debug_utils.h"
18#include "video_core/video_core.h" 20#include "video_core/video_core.h"
19 21
@@ -99,14 +101,17 @@ private:
99}; 101};
100 102
101GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread) 103GRenderWindow::GRenderWindow(QWidget* parent, EmuThread* emu_thread)
102 : QWidget(parent), child(nullptr), keyboard_id(0), emu_thread(emu_thread) { 104 : QWidget(parent), child(nullptr), emu_thread(emu_thread) {
103 105
104 std::string window_title = Common::StringFromFormat("Citra %s| %s-%s", Common::g_build_name, 106 std::string window_title = Common::StringFromFormat("Citra %s| %s-%s", Common::g_build_name,
105 Common::g_scm_branch, Common::g_scm_desc); 107 Common::g_scm_branch, Common::g_scm_desc);
106 setWindowTitle(QString::fromStdString(window_title)); 108 setWindowTitle(QString::fromStdString(window_title));
107 109
108 keyboard_id = KeyMap::NewDeviceId(); 110 InputCommon::Init();
109 ReloadSetKeymaps(); 111}
112
113GRenderWindow::~GRenderWindow() {
114 InputCommon::Shutdown();
110} 115}
111 116
112void GRenderWindow::moveContext() { 117void GRenderWindow::moveContext() {
@@ -197,11 +202,11 @@ void GRenderWindow::closeEvent(QCloseEvent* event) {
197} 202}
198 203
199void GRenderWindow::keyPressEvent(QKeyEvent* event) { 204void GRenderWindow::keyPressEvent(QKeyEvent* event) {
200 KeyMap::PressKey(*this, {event->key(), keyboard_id}); 205 InputCommon::GetKeyboard()->PressKey(event->key());
201} 206}
202 207
203void GRenderWindow::keyReleaseEvent(QKeyEvent* event) { 208void GRenderWindow::keyReleaseEvent(QKeyEvent* event) {
204 KeyMap::ReleaseKey(*this, {event->key(), keyboard_id}); 209 InputCommon::GetKeyboard()->ReleaseKey(event->key());
205} 210}
206 211
207void GRenderWindow::mousePressEvent(QMouseEvent* event) { 212void GRenderWindow::mousePressEvent(QMouseEvent* event) {
@@ -230,14 +235,7 @@ void GRenderWindow::mouseReleaseEvent(QMouseEvent* event) {
230 motion_emu->EndTilt(); 235 motion_emu->EndTilt();
231} 236}
232 237
233void GRenderWindow::ReloadSetKeymaps() { 238void GRenderWindow::ReloadSetKeymaps() {}
234 KeyMap::ClearKeyMapping(keyboard_id);
235 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
236 KeyMap::SetKeyMapping(
237 {Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id},
238 KeyMap::mapping_targets[i]);
239 }
240}
241 239
242void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) { 240void GRenderWindow::OnClientAreaResized(unsigned width, unsigned height) {
243 NotifyClientAreaSizeChanged(std::make_pair(width, height)); 241 NotifyClientAreaSizeChanged(std::make_pair(width, height));
diff --git a/src/citra_qt/bootmanager.h b/src/citra_qt/bootmanager.h
index 7dac1c480..923a5b456 100644
--- a/src/citra_qt/bootmanager.h
+++ b/src/citra_qt/bootmanager.h
@@ -104,6 +104,7 @@ class GRenderWindow : public QWidget, public EmuWindow {
104 104
105public: 105public:
106 GRenderWindow(QWidget* parent, EmuThread* emu_thread); 106 GRenderWindow(QWidget* parent, EmuThread* emu_thread);
107 ~GRenderWindow();
107 108
108 // EmuWindow implementation 109 // EmuWindow implementation
109 void SwapBuffers() override; 110 void SwapBuffers() override;
@@ -127,7 +128,7 @@ public:
127 void mouseMoveEvent(QMouseEvent* event) override; 128 void mouseMoveEvent(QMouseEvent* event) override;
128 void mouseReleaseEvent(QMouseEvent* event) override; 129 void mouseReleaseEvent(QMouseEvent* event) override;
129 130
130 void ReloadSetKeymaps() override; 131 void ReloadSetKeymaps();
131 132
132 void OnClientAreaResized(unsigned width, unsigned height); 133 void OnClientAreaResized(unsigned width, unsigned height);
133 134
@@ -152,9 +153,6 @@ private:
152 153
153 QByteArray geometry; 154 QByteArray geometry;
154 155
155 /// Device id of keyboard for use with KeyMap
156 int keyboard_id;
157
158 EmuThread* emu_thread; 156 EmuThread* emu_thread;
159 157
160 /// Motion sensors emulation 158 /// Motion sensors emulation
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
index 5fe57dfa2..6ccfa1577 100644
--- a/src/citra_qt/config.cpp
+++ b/src/citra_qt/config.cpp
@@ -6,6 +6,7 @@
6#include "citra_qt/config.h" 6#include "citra_qt/config.h"
7#include "citra_qt/ui_settings.h" 7#include "citra_qt/ui_settings.h"
8#include "common/file_util.h" 8#include "common/file_util.h"
9#include "input_common/main.h"
9 10
10Config::Config() { 11Config::Config() {
11 // TODO: Don't hardcode the path; let the frontend decide where to put the config files. 12 // TODO: Don't hardcode the path; let the frontend decide where to put the config files.
@@ -16,25 +17,46 @@ Config::Config() {
16 Reload(); 17 Reload();
17} 18}
18 19
19const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> Config::defaults = { 20const std::array<int, Settings::NativeButton::NumButtons> Config::default_buttons = {
20 // directly mapped keys 21 Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H,
21 Qt::Key_A, Qt::Key_S, Qt::Key_Z, Qt::Key_X, Qt::Key_Q, Qt::Key_W, Qt::Key_1, Qt::Key_2, 22 Qt::Key_Q, Qt::Key_W, Qt::Key_M, Qt::Key_N, Qt::Key_1, Qt::Key_2, Qt::Key_B,
22 Qt::Key_M, Qt::Key_N, Qt::Key_B, Qt::Key_T, Qt::Key_G, Qt::Key_F, Qt::Key_H, Qt::Key_I,
23 Qt::Key_K, Qt::Key_J, Qt::Key_L,
24
25 // indirectly mapped keys
26 Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D,
27}; 23};
28 24
25const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> Config::default_analogs{{
26 {
27 Qt::Key_Up, Qt::Key_Down, Qt::Key_Left, Qt::Key_Right, Qt::Key_D,
28 },
29 {
30 Qt::Key_I, Qt::Key_K, Qt::Key_J, Qt::Key_L, Qt::Key_D,
31 },
32}};
33
29void Config::ReadValues() { 34void Config::ReadValues() {
30 qt_config->beginGroup("Controls"); 35 qt_config->beginGroup("Controls");
31 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { 36 for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
32 Settings::values.input_mappings[Settings::NativeInput::All[i]] = 37 std::string default_param = InputCommon::GenerateKeyboardParam(default_buttons[i]);
33 qt_config->value(QString::fromStdString(Settings::NativeInput::Mapping[i]), defaults[i]) 38 Settings::values.buttons[i] =
34 .toInt(); 39 qt_config
40 ->value(Settings::NativeButton::mapping[i], QString::fromStdString(default_param))
41 .toString()
42 .toStdString();
43 if (Settings::values.buttons[i].empty())
44 Settings::values.buttons[i] = default_param;
45 }
46
47 for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
48 std::string default_param = InputCommon::GenerateAnalogParamFromKeys(
49 default_analogs[i][0], default_analogs[i][1], default_analogs[i][2],
50 default_analogs[i][3], default_analogs[i][4], 0.5f);
51 Settings::values.analogs[i] =
52 qt_config
53 ->value(Settings::NativeAnalog::mapping[i], QString::fromStdString(default_param))
54 .toString()
55 .toStdString();
56 if (Settings::values.analogs[i].empty())
57 Settings::values.analogs[i] = default_param;
35 } 58 }
36 Settings::values.pad_circle_modifier_scale = 59
37 qt_config->value("pad_circle_modifier_scale", 0.5).toFloat();
38 qt_config->endGroup(); 60 qt_config->endGroup();
39 61
40 qt_config->beginGroup("Core"); 62 qt_config->beginGroup("Core");
@@ -155,12 +177,14 @@ void Config::ReadValues() {
155 177
156void Config::SaveValues() { 178void Config::SaveValues() {
157 qt_config->beginGroup("Controls"); 179 qt_config->beginGroup("Controls");
158 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) { 180 for (int i = 0; i < Settings::NativeButton::NumButtons; ++i) {
159 qt_config->setValue(QString::fromStdString(Settings::NativeInput::Mapping[i]), 181 qt_config->setValue(QString::fromStdString(Settings::NativeButton::mapping[i]),
160 Settings::values.input_mappings[Settings::NativeInput::All[i]]); 182 QString::fromStdString(Settings::values.buttons[i]));
183 }
184 for (int i = 0; i < Settings::NativeAnalog::NumAnalogs; ++i) {
185 qt_config->setValue(QString::fromStdString(Settings::NativeAnalog::mapping[i]),
186 QString::fromStdString(Settings::values.analogs[i]));
161 } 187 }
162 qt_config->setValue("pad_circle_modifier_scale",
163 (double)Settings::values.pad_circle_modifier_scale);
164 qt_config->endGroup(); 188 qt_config->endGroup();
165 189
166 qt_config->beginGroup("Core"); 190 qt_config->beginGroup("Core");
diff --git a/src/citra_qt/config.h b/src/citra_qt/config.h
index 79c901804..cbf745ea2 100644
--- a/src/citra_qt/config.h
+++ b/src/citra_qt/config.h
@@ -4,6 +4,7 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
7#include <string> 8#include <string>
8#include <QVariant> 9#include <QVariant>
9#include "core/settings.h" 10#include "core/settings.h"
@@ -23,5 +24,7 @@ public:
23 24
24 void Reload(); 25 void Reload();
25 void Save(); 26 void Save();
26 static const std::array<QVariant, Settings::NativeInput::NUM_INPUTS> defaults; 27
28 static const std::array<int, Settings::NativeButton::NumButtons> default_buttons;
29 static const std::array<std::array<int, 5>, Settings::NativeAnalog::NumAnalogs> default_analogs;
27}; 30};
diff --git a/src/citra_qt/configure_input.cpp b/src/citra_qt/configure_input.cpp
index c29652f32..b59713e2c 100644
--- a/src/citra_qt/configure_input.cpp
+++ b/src/citra_qt/configure_input.cpp
@@ -2,13 +2,21 @@
2// Licensed under GPLv2 or any later version 2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <algorithm>
5#include <memory> 6#include <memory>
6#include <utility> 7#include <utility>
7#include <QTimer> 8#include <QTimer>
8#include "citra_qt/config.h" 9#include "citra_qt/config.h"
9#include "citra_qt/configure_input.h" 10#include "citra_qt/configure_input.h"
11#include "common/param_package.h"
12#include "input_common/main.h"
10 13
11static QString getKeyName(Qt::Key key_code) { 14const std::array<std::string, ConfigureInput::ANALOG_SUB_BUTTONS_NUM>
15 ConfigureInput::analog_sub_buttons{{
16 "up", "down", "left", "right", "modifier",
17 }};
18
19static QString getKeyName(int key_code) {
12 switch (key_code) { 20 switch (key_code) {
13 case Qt::Key_Shift: 21 case Qt::Key_Shift:
14 return QObject::tr("Shift"); 22 return QObject::tr("Shift");
@@ -23,6 +31,20 @@ static QString getKeyName(Qt::Key key_code) {
23 } 31 }
24} 32}
25 33
34static void SetButtonKey(int key, Common::ParamPackage& button_param) {
35 button_param = Common::ParamPackage{InputCommon::GenerateKeyboardParam(key)};
36}
37
38static void SetAnalogKey(int key, Common::ParamPackage& analog_param,
39 const std::string& button_name) {
40 if (analog_param.Get("engine", "") != "analog_from_button") {
41 analog_param = {
42 {"engine", "analog_from_button"}, {"modifier_scale", "0.5"},
43 };
44 }
45 analog_param.Set(button_name, InputCommon::GenerateKeyboardParam(key));
46}
47
26ConfigureInput::ConfigureInput(QWidget* parent) 48ConfigureInput::ConfigureInput(QWidget* parent)
27 : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()), 49 : QWidget(parent), ui(std::make_unique<Ui::ConfigureInput>()),
28 timer(std::make_unique<QTimer>()) { 50 timer(std::make_unique<QTimer>()) {
@@ -31,36 +53,41 @@ ConfigureInput::ConfigureInput(QWidget* parent)
31 setFocusPolicy(Qt::ClickFocus); 53 setFocusPolicy(Qt::ClickFocus);
32 54
33 button_map = { 55 button_map = {
34 {Settings::NativeInput::Values::A, ui->buttonA}, 56 ui->buttonA, ui->buttonB, ui->buttonX, ui->buttonY, ui->buttonDpadUp,
35 {Settings::NativeInput::Values::B, ui->buttonB}, 57 ui->buttonDpadDown, ui->buttonDpadLeft, ui->buttonDpadRight, ui->buttonL, ui->buttonR,
36 {Settings::NativeInput::Values::X, ui->buttonX}, 58 ui->buttonStart, ui->buttonSelect, ui->buttonZL, ui->buttonZR, ui->buttonHome,
37 {Settings::NativeInput::Values::Y, ui->buttonY},
38 {Settings::NativeInput::Values::L, ui->buttonL},
39 {Settings::NativeInput::Values::R, ui->buttonR},
40 {Settings::NativeInput::Values::ZL, ui->buttonZL},
41 {Settings::NativeInput::Values::ZR, ui->buttonZR},
42 {Settings::NativeInput::Values::START, ui->buttonStart},
43 {Settings::NativeInput::Values::SELECT, ui->buttonSelect},
44 {Settings::NativeInput::Values::HOME, ui->buttonHome},
45 {Settings::NativeInput::Values::DUP, ui->buttonDpadUp},
46 {Settings::NativeInput::Values::DDOWN, ui->buttonDpadDown},
47 {Settings::NativeInput::Values::DLEFT, ui->buttonDpadLeft},
48 {Settings::NativeInput::Values::DRIGHT, ui->buttonDpadRight},
49 {Settings::NativeInput::Values::CUP, ui->buttonCStickUp},
50 {Settings::NativeInput::Values::CDOWN, ui->buttonCStickDown},
51 {Settings::NativeInput::Values::CLEFT, ui->buttonCStickLeft},
52 {Settings::NativeInput::Values::CRIGHT, ui->buttonCStickRight},
53 {Settings::NativeInput::Values::CIRCLE_UP, ui->buttonCircleUp},
54 {Settings::NativeInput::Values::CIRCLE_DOWN, ui->buttonCircleDown},
55 {Settings::NativeInput::Values::CIRCLE_LEFT, ui->buttonCircleLeft},
56 {Settings::NativeInput::Values::CIRCLE_RIGHT, ui->buttonCircleRight},
57 {Settings::NativeInput::Values::CIRCLE_MODIFIER, ui->buttonCircleMod},
58 }; 59 };
59 60
60 for (const auto& entry : button_map) { 61 analog_map = {{
61 const Settings::NativeInput::Values input_id = entry.first; 62 {
62 connect(entry.second, &QPushButton::released, 63 ui->buttonCircleUp, ui->buttonCircleDown, ui->buttonCircleLeft, ui->buttonCircleRight,
63 [this, input_id]() { handleClick(input_id); }); 64 ui->buttonCircleMod,
65 },
66 {
67 ui->buttonCStickUp, ui->buttonCStickDown, ui->buttonCStickLeft, ui->buttonCStickRight,
68 nullptr,
69 },
70 }};
71
72 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
73 if (button_map[button_id])
74 connect(button_map[button_id], &QPushButton::released, [=]() {
75 handleClick(button_map[button_id],
76 [=](int key) { SetButtonKey(key, buttons_param[button_id]); });
77 });
78 }
79
80 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
81 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
82 if (analog_map[analog_id][sub_button_id] != nullptr) {
83 connect(analog_map[analog_id][sub_button_id], &QPushButton::released, [=]() {
84 handleClick(analog_map[analog_id][sub_button_id], [=](int key) {
85 SetAnalogKey(key, analogs_param[analog_id],
86 analog_sub_buttons[sub_button_id]);
87 });
88 });
89 }
90 }
64 } 91 }
65 92
66 connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); }); 93 connect(ui->buttonRestoreDefaults, &QPushButton::released, [this]() { restoreDefaults(); });
@@ -69,50 +96,93 @@ ConfigureInput::ConfigureInput(QWidget* parent)
69 connect(timer.get(), &QTimer::timeout, [this]() { 96 connect(timer.get(), &QTimer::timeout, [this]() {
70 releaseKeyboard(); 97 releaseKeyboard();
71 releaseMouse(); 98 releaseMouse();
72 current_input_id = boost::none; 99 key_setter = boost::none;
73 updateButtonLabels(); 100 updateButtonLabels();
74 }); 101 });
75 102
76 this->loadConfiguration(); 103 this->loadConfiguration();
104
105 // TODO(wwylele): enable these when the input emulation for them is implemented
106 ui->buttonZL->setEnabled(false);
107 ui->buttonZR->setEnabled(false);
108 ui->buttonHome->setEnabled(false);
109 ui->buttonCStickUp->setEnabled(false);
110 ui->buttonCStickDown->setEnabled(false);
111 ui->buttonCStickLeft->setEnabled(false);
112 ui->buttonCStickRight->setEnabled(false);
77} 113}
78 114
79void ConfigureInput::applyConfiguration() { 115void ConfigureInput::applyConfiguration() {
80 for (const auto& input_id : Settings::NativeInput::All) { 116 std::transform(buttons_param.begin(), buttons_param.end(), Settings::values.buttons.begin(),
81 const size_t index = static_cast<size_t>(input_id); 117 [](const Common::ParamPackage& param) { return param.Serialize(); });
82 Settings::values.input_mappings[index] = static_cast<int>(key_map[input_id]); 118 std::transform(analogs_param.begin(), analogs_param.end(), Settings::values.analogs.begin(),
83 } 119 [](const Common::ParamPackage& param) { return param.Serialize(); });
120
84 Settings::Apply(); 121 Settings::Apply();
85} 122}
86 123
87void ConfigureInput::loadConfiguration() { 124void ConfigureInput::loadConfiguration() {
88 for (const auto& input_id : Settings::NativeInput::All) { 125 std::transform(Settings::values.buttons.begin(), Settings::values.buttons.end(),
89 const size_t index = static_cast<size_t>(input_id); 126 buttons_param.begin(),
90 key_map[input_id] = static_cast<Qt::Key>(Settings::values.input_mappings[index]); 127 [](const std::string& str) { return Common::ParamPackage(str); });
91 } 128 std::transform(Settings::values.analogs.begin(), Settings::values.analogs.end(),
129 analogs_param.begin(),
130 [](const std::string& str) { return Common::ParamPackage(str); });
92 updateButtonLabels(); 131 updateButtonLabels();
93} 132}
94 133
95void ConfigureInput::restoreDefaults() { 134void ConfigureInput::restoreDefaults() {
96 for (const auto& input_id : Settings::NativeInput::All) { 135 for (int button_id = 0; button_id < Settings::NativeButton::NumButtons; button_id++) {
97 const size_t index = static_cast<size_t>(input_id); 136 SetButtonKey(Config::default_buttons[button_id], buttons_param[button_id]);
98 key_map[input_id] = static_cast<Qt::Key>(Config::defaults[index].toInt()); 137 }
138
139 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
140 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
141 SetAnalogKey(Config::default_analogs[analog_id][sub_button_id],
142 analogs_param[analog_id], analog_sub_buttons[sub_button_id]);
143 }
99 } 144 }
100 updateButtonLabels(); 145 updateButtonLabels();
101 applyConfiguration(); 146 applyConfiguration();
102} 147}
103 148
104void ConfigureInput::updateButtonLabels() { 149void ConfigureInput::updateButtonLabels() {
105 for (const auto& input_id : Settings::NativeInput::All) { 150 QString non_keyboard(tr("[non-keyboard]"));
106 button_map[input_id]->setText(getKeyName(key_map[input_id])); 151
152 auto KeyToText = [&non_keyboard](const Common::ParamPackage& param) {
153 if (param.Get("engine", "") != "keyboard") {
154 return non_keyboard;
155 } else {
156 return getKeyName(param.Get("code", 0));
157 }
158 };
159
160 for (int button = 0; button < Settings::NativeButton::NumButtons; button++) {
161 button_map[button]->setText(KeyToText(buttons_param[button]));
162 }
163
164 for (int analog_id = 0; analog_id < Settings::NativeAnalog::NumAnalogs; analog_id++) {
165 if (analogs_param[analog_id].Get("engine", "") != "analog_from_button") {
166 for (QPushButton* button : analog_map[analog_id]) {
167 if (button)
168 button->setText(non_keyboard);
169 }
170 } else {
171 for (int sub_button_id = 0; sub_button_id < ANALOG_SUB_BUTTONS_NUM; sub_button_id++) {
172 Common::ParamPackage param(
173 analogs_param[analog_id].Get(analog_sub_buttons[sub_button_id], ""));
174 if (analog_map[analog_id][sub_button_id])
175 analog_map[analog_id][sub_button_id]->setText(KeyToText(param));
176 }
177 }
107 } 178 }
108} 179}
109 180
110void ConfigureInput::handleClick(Settings::NativeInput::Values input_id) { 181void ConfigureInput::handleClick(QPushButton* button, std::function<void(int)> new_key_setter) {
111 QPushButton* button = button_map[input_id];
112 button->setText(tr("[press key]")); 182 button->setText(tr("[press key]"));
113 button->setFocus(); 183 button->setFocus();
114 184
115 current_input_id = input_id; 185 key_setter = new_key_setter;
116 186
117 grabKeyboard(); 187 grabKeyboard();
118 grabMouse(); 188 grabMouse();
@@ -123,23 +193,13 @@ void ConfigureInput::keyPressEvent(QKeyEvent* event) {
123 releaseKeyboard(); 193 releaseKeyboard();
124 releaseMouse(); 194 releaseMouse();
125 195
126 if (!current_input_id || !event) 196 if (!key_setter || !event)
127 return; 197 return;
128 198
129 if (event->key() != Qt::Key_Escape) 199 if (event->key() != Qt::Key_Escape)
130 setInput(*current_input_id, static_cast<Qt::Key>(event->key())); 200 (*key_setter)(event->key());
131 201
132 updateButtonLabels(); 202 updateButtonLabels();
133 current_input_id = boost::none; 203 key_setter = boost::none;
134 timer->stop(); 204 timer->stop();
135} 205}
136
137void ConfigureInput::setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed) {
138 // Remove duplicates
139 for (auto& pair : key_map) {
140 if (pair.second == key_pressed)
141 pair.second = Qt::Key_unknown;
142 }
143
144 key_map[input_id] = key_pressed;
145}
diff --git a/src/citra_qt/configure_input.h b/src/citra_qt/configure_input.h
index bc343db83..c950fbcb4 100644
--- a/src/citra_qt/configure_input.h
+++ b/src/citra_qt/configure_input.h
@@ -4,10 +4,14 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <array>
8#include <functional>
7#include <memory> 9#include <memory>
10#include <string>
8#include <QKeyEvent> 11#include <QKeyEvent>
9#include <QWidget> 12#include <QWidget>
10#include <boost/optional.hpp> 13#include <boost/optional.hpp>
14#include "common/param_package.h"
11#include "core/settings.h" 15#include "core/settings.h"
12#include "ui_configure_input.h" 16#include "ui_configure_input.h"
13 17
@@ -31,15 +35,25 @@ public:
31private: 35private:
32 std::unique_ptr<Ui::ConfigureInput> ui; 36 std::unique_ptr<Ui::ConfigureInput> ui;
33 37
34 /// This input is currently awaiting configuration.
35 /// (i.e.: its corresponding QPushButton has been pressed.)
36 boost::optional<Settings::NativeInput::Values> current_input_id;
37 std::unique_ptr<QTimer> timer; 38 std::unique_ptr<QTimer> timer;
38 39
39 /// Each input is represented by a QPushButton. 40 /// This will be the the setting function when an input is awaiting configuration.
40 std::map<Settings::NativeInput::Values, QPushButton*> button_map; 41 boost::optional<std::function<void(int)>> key_setter;
41 /// Each input is configured to respond to the press of a Qt::Key. 42
42 std::map<Settings::NativeInput::Values, Qt::Key> key_map; 43 std::array<Common::ParamPackage, Settings::NativeButton::NumButtons> buttons_param;
44 std::array<Common::ParamPackage, Settings::NativeAnalog::NumAnalogs> analogs_param;
45
46 static constexpr int ANALOG_SUB_BUTTONS_NUM = 5;
47
48 /// Each button input is represented by a QPushButton.
49 std::array<QPushButton*, Settings::NativeButton::NumButtons> button_map;
50
51 /// Each analog input is represented by five QPushButtons which represents up, down, left, right
52 /// and modifier
53 std::array<std::array<QPushButton*, ANALOG_SUB_BUTTONS_NUM>, Settings::NativeAnalog::NumAnalogs>
54 analog_map;
55
56 static const std::array<std::string, ANALOG_SUB_BUTTONS_NUM> analog_sub_buttons;
43 57
44 /// Load configuration settings. 58 /// Load configuration settings.
45 void loadConfiguration(); 59 void loadConfiguration();
@@ -48,10 +62,8 @@ private:
48 /// Update UI to reflect current configuration. 62 /// Update UI to reflect current configuration.
49 void updateButtonLabels(); 63 void updateButtonLabels();
50 64
51 /// Called when the button corresponding to input_id was pressed. 65 /// Called when the button was pressed.
52 void handleClick(Settings::NativeInput::Values input_id); 66 void handleClick(QPushButton* button, std::function<void(int)> new_key_setter);
53 /// Handle key press events. 67 /// Handle key press events.
54 void keyPressEvent(QKeyEvent* event) override; 68 void keyPressEvent(QKeyEvent* event) override;
55 /// Configure input input_id to respond to key key_pressed.
56 void setInput(Settings::NativeInput::Values input_id, Qt::Key key_pressed);
57}; 69};