Input settings WIP
This commit is contained in:
@@ -66,7 +66,9 @@ add_executable(kaizen-qt
|
||||
CPUSettings.cpp
|
||||
JSONUtils.hpp
|
||||
AudioSettings.hpp
|
||||
AudioSettings.cpp)
|
||||
AudioSettings.cpp
|
||||
InputSettings.hpp
|
||||
InputSettings.cpp)
|
||||
|
||||
target_link_libraries(kaizen-qt PUBLIC Qt6::Core Qt6::Gui Qt6::Widgets fmt mio nlohmann_json nfd parallel-rdp backend)
|
||||
|
||||
|
||||
158
src/frontend/InputSettings.cpp
Normal file
158
src/frontend/InputSettings.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#include <InputSettings.hpp>
|
||||
#include <QVBoxLayout>
|
||||
#include <QKeyEvent>
|
||||
#include <log.hpp>
|
||||
|
||||
InputSettings::InputSettings(nlohmann::json& settings) : settings(settings), QWidget(nullptr) {
|
||||
n64_button_labels[0] = new QLabel("A");
|
||||
n64_button_labels[1] = new QLabel("B");
|
||||
n64_button_labels[2] = new QLabel("Z");
|
||||
n64_button_labels[3] = new QLabel("Start");
|
||||
n64_button_labels[4] = new QLabel("L");
|
||||
n64_button_labels[5] = new QLabel("R");
|
||||
n64_button_labels[6] = new QLabel("Dpad Up");
|
||||
n64_button_labels[7] = new QLabel("Dpad Down");
|
||||
n64_button_labels[8] = new QLabel("Dpad Left");
|
||||
n64_button_labels[9] = new QLabel("Dpad Right");
|
||||
n64_button_labels[10] = new QLabel("C Up");
|
||||
n64_button_labels[11] = new QLabel("C Down");
|
||||
n64_button_labels[12] = new QLabel("C Left");
|
||||
n64_button_labels[13] = new QLabel("C Right");
|
||||
n64_button_labels[14] = new QLabel("Analog Up");
|
||||
n64_button_labels[15] = new QLabel("Analog Down");
|
||||
n64_button_labels[16] = new QLabel("Analog Left");
|
||||
n64_button_labels[17] = new QLabel("Analog Right");
|
||||
|
||||
auto str = JSONGetField<std::string>(settings, "input", "A");
|
||||
kb_buttons[0] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "B");
|
||||
kb_buttons[1] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Z");
|
||||
kb_buttons[2] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Start");
|
||||
kb_buttons[3] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "L");
|
||||
kb_buttons[4] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "R");
|
||||
kb_buttons[5] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Dpad Up");
|
||||
kb_buttons[6] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Dpad Down");
|
||||
kb_buttons[7] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Dpad Left");
|
||||
kb_buttons[8] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Dpad Right");
|
||||
kb_buttons[9] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "C Up");
|
||||
kb_buttons[10] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "C Down");
|
||||
kb_buttons[11] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "C Left");
|
||||
kb_buttons[12] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "C Right");
|
||||
kb_buttons[13] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Analog Up");
|
||||
kb_buttons[14] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Analog Down");
|
||||
kb_buttons[15] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Analog Left");
|
||||
kb_buttons[16] = new QPushButton(str.c_str());
|
||||
str = JSONGetField<std::string>(settings, "input", "Analog Right");
|
||||
kb_buttons[17] = new QPushButton(str.c_str());
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
connect(kb_buttons[i], &QPushButton::pressed, this, [&, i]() {
|
||||
for (int i = 0; i < 18; i++) {
|
||||
kb_buttons[i]->setEnabled(false);
|
||||
}
|
||||
grabKeyboard();
|
||||
grabbing = true;
|
||||
which_grabbing = i;
|
||||
});
|
||||
}
|
||||
|
||||
QHBoxLayout* AB = new QHBoxLayout;
|
||||
QHBoxLayout* ZStart = new QHBoxLayout;
|
||||
QHBoxLayout* LR = new QHBoxLayout;
|
||||
QHBoxLayout* DupDdown = new QHBoxLayout;
|
||||
QHBoxLayout* DleftDright = new QHBoxLayout;
|
||||
QHBoxLayout* CupCdown = new QHBoxLayout;
|
||||
QHBoxLayout* CleftCright = new QHBoxLayout;
|
||||
QHBoxLayout* AupAdown = new QHBoxLayout;
|
||||
QHBoxLayout* AleftAright = new QHBoxLayout;
|
||||
QVBoxLayout* mainLayout = new QVBoxLayout;
|
||||
|
||||
AB->addWidget(n64_button_labels[0]);
|
||||
AB->addWidget(kb_buttons[0]);
|
||||
AB->addWidget(n64_button_labels[1]);
|
||||
AB->addWidget(kb_buttons[1]);
|
||||
mainLayout->addLayout(AB);
|
||||
ZStart->addWidget(n64_button_labels[2]);
|
||||
ZStart->addWidget(kb_buttons[2]);
|
||||
ZStart->addWidget(n64_button_labels[3]);
|
||||
ZStart->addWidget(kb_buttons[3]);
|
||||
mainLayout->addLayout(ZStart);
|
||||
LR->addWidget(n64_button_labels[4]);
|
||||
LR->addWidget(kb_buttons[4]);
|
||||
LR->addWidget(n64_button_labels[5]);
|
||||
LR->addWidget(kb_buttons[5]);
|
||||
mainLayout->addLayout(LR);
|
||||
DupDdown->addWidget(n64_button_labels[6]);
|
||||
DupDdown->addWidget(kb_buttons[6]);
|
||||
DupDdown->addWidget(n64_button_labels[7]);
|
||||
DupDdown->addWidget(kb_buttons[7]);
|
||||
mainLayout->addLayout(DupDdown);
|
||||
DleftDright->addWidget(n64_button_labels[8]);
|
||||
DleftDright->addWidget(kb_buttons[8]);
|
||||
DleftDright->addWidget(n64_button_labels[9]);
|
||||
DleftDright->addWidget(kb_buttons[9]);
|
||||
mainLayout->addLayout(DleftDright);
|
||||
CupCdown->addWidget(n64_button_labels[10]);
|
||||
CupCdown->addWidget(kb_buttons[10]);
|
||||
CupCdown->addWidget(n64_button_labels[11]);
|
||||
CupCdown->addWidget(kb_buttons[11]);
|
||||
mainLayout->addLayout(CupCdown);
|
||||
CleftCright->addWidget(n64_button_labels[12]);
|
||||
CleftCright->addWidget(kb_buttons[12]);
|
||||
CleftCright->addWidget(n64_button_labels[13]);
|
||||
CleftCright->addWidget(kb_buttons[13]);
|
||||
mainLayout->addLayout(CleftCright);
|
||||
AupAdown->addWidget(n64_button_labels[14]);
|
||||
AupAdown->addWidget(kb_buttons[14]);
|
||||
AupAdown->addWidget(n64_button_labels[15]);
|
||||
AupAdown->addWidget(kb_buttons[15]);
|
||||
mainLayout->addLayout(AupAdown);
|
||||
AleftAright->addWidget(n64_button_labels[16]);
|
||||
AleftAright->addWidget(kb_buttons[16]);
|
||||
AleftAright->addWidget(n64_button_labels[17]);
|
||||
AleftAright->addWidget(kb_buttons[17]);
|
||||
mainLayout->addLayout(AleftAright);
|
||||
mainLayout->addStretch();
|
||||
setLayout(mainLayout);
|
||||
}
|
||||
|
||||
|
||||
void InputSettings::keyPressEvent(QKeyEvent* e) {
|
||||
if (grabbing) {
|
||||
auto k = QKeySequence(e->key()).toString();
|
||||
JSONSetField<std::string>(settings, "input", n64_button_labels[which_grabbing]->text().toStdString(), k.toStdString());
|
||||
kb_buttons[which_grabbing]->setText(k);
|
||||
grabbing = false;
|
||||
which_grabbing = -1;
|
||||
for (int i = 0; i < 18; i++) {
|
||||
kb_buttons[i]->setEnabled(true);
|
||||
}
|
||||
releaseKeyboard();
|
||||
emit modified();
|
||||
}
|
||||
}
|
||||
|
||||
std::array<Qt::Key, 18> InputSettings::GetMappedKeys() {
|
||||
std::array<Qt::Key, 18> ret{};
|
||||
|
||||
for (int i = 0; i < 18; i++) {
|
||||
ret[i] = QKeySequence(kb_buttons[i]->text().toUpper())[0].key();
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
20
src/frontend/InputSettings.hpp
Normal file
20
src/frontend/InputSettings.hpp
Normal file
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <QWidget>
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#include <JSONUtils.hpp>
|
||||
|
||||
class InputSettings : public QWidget {
|
||||
bool grabbing = false;
|
||||
int which_grabbing = -1;
|
||||
QPushButton* kb_buttons[18];
|
||||
QLabel* n64_button_labels[18];
|
||||
Q_OBJECT
|
||||
public:
|
||||
InputSettings(nlohmann::json&);
|
||||
nlohmann::json& settings;
|
||||
void keyPressEvent(QKeyEvent*) override;
|
||||
std::array<Qt::Key, 18> GetMappedKeys();
|
||||
Q_SIGNALS:
|
||||
void modified();
|
||||
};
|
||||
@@ -20,6 +20,26 @@ static inline nlohmann::json JSONOpenOrCreate(const std::string& path) {
|
||||
json["audio"]["volumeR"] = 0.5;
|
||||
json["audio"]["lock"] = true;
|
||||
json["cpu"]["type"] = "interpreter";
|
||||
json["input"] = {
|
||||
{"A", ""},
|
||||
{"B", ""},
|
||||
{"Z", ""},
|
||||
{"Start", ""},
|
||||
{"L", ""},
|
||||
{"R", ""},
|
||||
{"Dpad Up", ""},
|
||||
{"Dpad Down", ""},
|
||||
{"Dpad Left", ""},
|
||||
{"Dpad Right", ""},
|
||||
{"C Up", ""},
|
||||
{"C Down", ""},
|
||||
{"C Left", ""},
|
||||
{"C Right", ""},
|
||||
{"Analog Up", ""},
|
||||
{"Analog Down", ""},
|
||||
{"Analog Left", ""},
|
||||
{"Analog Right", ""},
|
||||
};
|
||||
|
||||
file << json;
|
||||
file.close();
|
||||
|
||||
@@ -21,6 +21,9 @@ KaizenQt::KaizenQt() noexcept : QWidget(nullptr) {
|
||||
mainWindow->show();
|
||||
settingsWindow = new SettingsWindow;
|
||||
settingsWindow->hide();
|
||||
connect(settingsWindow, &SettingsWindow::regrabKeyboard, this, [&]() {
|
||||
grabKeyboard();
|
||||
}),
|
||||
emuThread->core = new n64::Core();
|
||||
emuThread->settings = settingsWindow;
|
||||
}
|
||||
@@ -57,24 +60,24 @@ void KaizenQt::LoadROM(const QString& file_name) noexcept {
|
||||
void KaizenQt::keyPressEvent(QKeyEvent *e) {
|
||||
emuThread->core->pause = true;
|
||||
auto k = static_cast<Qt::Key>(e->key());
|
||||
if(k == Qt::Key_Z) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Z, true);
|
||||
if(k == Qt::Key_X) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::A, true);
|
||||
if(k == Qt::Key_C) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::B, true);
|
||||
if(k == Qt::Key_Return || k == Qt::Key_Enter) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Start, true);
|
||||
if(k == Qt::Key_I) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DUp, true);
|
||||
if(k == Qt::Key_K) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DDown, true);
|
||||
if(k == Qt::Key_J) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DLeft, true);
|
||||
if(k == Qt::Key_L) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DRight, true);
|
||||
if(k == Qt::Key_A) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::LT, true);
|
||||
if(k == Qt::Key_S) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::RT, true);
|
||||
if(k == Qt::Key_8) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CUp, true);
|
||||
if(k == Qt::Key_2) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CDown, true);
|
||||
if(k == Qt::Key_4) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CLeft, true);
|
||||
if(k == Qt::Key_6) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CRight, true);
|
||||
if(k == Qt::Key_Left) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, -86);
|
||||
if(k == Qt::Key_Right) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 86);
|
||||
if(k == Qt::Key_Up) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 86);
|
||||
if(k == Qt::Key_Down) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, -86);
|
||||
if(k == settingsWindow->keyMap[0]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::A, true);
|
||||
if(k == settingsWindow->keyMap[1]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::B, true);
|
||||
if(k == settingsWindow->keyMap[2]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Z, true);
|
||||
if(k == settingsWindow->keyMap[3]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Start, true);
|
||||
if(k == settingsWindow->keyMap[4]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::LT, true);
|
||||
if(k == settingsWindow->keyMap[5]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::RT, true);
|
||||
if(k == settingsWindow->keyMap[6]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DUp, true);
|
||||
if(k == settingsWindow->keyMap[7]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DDown, true);
|
||||
if(k == settingsWindow->keyMap[8]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DLeft, true);
|
||||
if(k == settingsWindow->keyMap[9]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DRight, true);
|
||||
if(k == settingsWindow->keyMap[10]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CUp, true);
|
||||
if(k == settingsWindow->keyMap[11]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CDown, true);
|
||||
if(k == settingsWindow->keyMap[12]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CLeft, true);
|
||||
if(k == settingsWindow->keyMap[13]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CRight, true);
|
||||
if(k == settingsWindow->keyMap[14]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 86);
|
||||
if(k == settingsWindow->keyMap[15]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, -86);
|
||||
if(k == settingsWindow->keyMap[16]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, -86);
|
||||
if(k == settingsWindow->keyMap[17]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 86);
|
||||
emuThread->core->pause = false;
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
@@ -82,24 +85,24 @@ void KaizenQt::keyPressEvent(QKeyEvent *e) {
|
||||
void KaizenQt::keyReleaseEvent(QKeyEvent *e) {
|
||||
emuThread->core->pause = true;
|
||||
auto k = static_cast<Qt::Key>(e->key());
|
||||
if(k == Qt::Key_Z) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Z, false);
|
||||
if(k == Qt::Key_X) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::A, false);
|
||||
if(k == Qt::Key_C) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::B, false);
|
||||
if(k == Qt::Key_Return || k == Qt::Key_Enter) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Start, false);
|
||||
if(k == Qt::Key_I) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DUp, false);
|
||||
if(k == Qt::Key_K) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DDown, false);
|
||||
if(k == Qt::Key_J) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DLeft, false);
|
||||
if(k == Qt::Key_L) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DRight, false);
|
||||
if(k == Qt::Key_A) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::LT, false);
|
||||
if(k == Qt::Key_S) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::RT, false);
|
||||
if(k == Qt::Key_8) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CUp, false);
|
||||
if(k == Qt::Key_2) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CDown, false);
|
||||
if(k == Qt::Key_4) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CLeft, false);
|
||||
if(k == Qt::Key_6) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CRight, false);
|
||||
if(k == Qt::Key_Left) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 0);
|
||||
if(k == Qt::Key_Right) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 0);
|
||||
if(k == Qt::Key_Up) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 0);
|
||||
if(k == Qt::Key_Down) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 0);
|
||||
if (k == settingsWindow->keyMap[0]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::A, false);
|
||||
if (k == settingsWindow->keyMap[1]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::B, false);
|
||||
if (k == settingsWindow->keyMap[2]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Z, false);
|
||||
if (k == settingsWindow->keyMap[3]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::Start, false);
|
||||
if (k == settingsWindow->keyMap[4]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::LT, false);
|
||||
if (k == settingsWindow->keyMap[5]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::RT, false);
|
||||
if (k == settingsWindow->keyMap[6]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DUp, false);
|
||||
if (k == settingsWindow->keyMap[7]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DDown, false);
|
||||
if (k == settingsWindow->keyMap[8]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DLeft, false);
|
||||
if (k == settingsWindow->keyMap[9]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::DRight, false);
|
||||
if (k == settingsWindow->keyMap[10]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CUp, false);
|
||||
if (k == settingsWindow->keyMap[11]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CDown, false);
|
||||
if (k == settingsWindow->keyMap[12]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CLeft, false);
|
||||
if (k == settingsWindow->keyMap[13]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateButton(n64::Controller::Key::CRight, false);
|
||||
if (k == settingsWindow->keyMap[14]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 0);
|
||||
if (k == settingsWindow->keyMap[15]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::Y, 0);
|
||||
if (k == settingsWindow->keyMap[16]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 0);
|
||||
if (k == settingsWindow->keyMap[17]) emuThread->core->cpu->mem.mmio.si.pif.joybusDevices[0].controller.UpdateAxis(n64::Controller::Axis::X, 0);
|
||||
emuThread->core->pause = false;
|
||||
QWidget::keyPressEvent(e);
|
||||
}
|
||||
@@ -14,10 +14,13 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
|
||||
|
||||
cpuSettings = new CPUSettings(settings);
|
||||
audioSettings = new AudioSettings(settings);
|
||||
inputSettings = new InputSettings(settings);
|
||||
keyMap = inputSettings->GetMappedKeys();
|
||||
|
||||
auto* tabs = new QTabWidget;
|
||||
tabs->addTab(cpuSettings, tr("CPU"));
|
||||
tabs->addTab(audioSettings, tr("Audio"));
|
||||
tabs->addTab(inputSettings, tr("Input"));
|
||||
|
||||
apply->setEnabled(false);
|
||||
|
||||
@@ -29,7 +32,16 @@ SettingsWindow::SettingsWindow() : QWidget(nullptr) {
|
||||
apply->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(inputSettings, &InputSettings::modified, this, [&]() {
|
||||
apply->setEnabled(true);
|
||||
});
|
||||
|
||||
connect(apply, &QPushButton::pressed, this, [&]() {
|
||||
auto newMap = inputSettings->GetMappedKeys();
|
||||
if (!std::equal(keyMap.begin(), keyMap.end(), newMap.begin(), newMap.end())) {
|
||||
keyMap = newMap;
|
||||
emit regrabKeyboard();
|
||||
}
|
||||
apply->setEnabled(false);
|
||||
std::ofstream file("resources/settings.json");
|
||||
file << settings;
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include <QPushButton>
|
||||
#include <CPUSettings.hpp>
|
||||
#include <AudioSettings.hpp>
|
||||
#include <InputSettings.hpp>
|
||||
|
||||
class SettingsWindow : public QWidget {
|
||||
QPushButton* cancel = new QPushButton("Cancel");
|
||||
@@ -12,8 +13,12 @@ class SettingsWindow : public QWidget {
|
||||
public:
|
||||
float getVolumeL() { return float(audioSettings->volumeL->value()) / 100.f; }
|
||||
float getVolumeR() { return float(audioSettings->volumeR->value()) / 100.f; }
|
||||
std::array<Qt::Key, 18> keyMap{};
|
||||
SettingsWindow();
|
||||
nlohmann::json settings;
|
||||
CPUSettings* cpuSettings;
|
||||
AudioSettings* audioSettings;
|
||||
InputSettings* inputSettings;
|
||||
Q_SIGNALS:
|
||||
void regrabKeyboard();
|
||||
};
|
||||
Reference in New Issue
Block a user