merge doublemelon (#2067)

non-exhaustive (but exhausting) list of changes:

* base laid for multiple window support, but will likely require more work to work correctly
* encapsulation of frontend state for proper multi-instance support
* (JIT still needs a fix for the NDS::Current workaround but we can get there later)
* new, more flexible configuration system
This commit is contained in:
Arisotura
2024-06-15 13:52:47 +02:00
committed by GitHub
parent 8e9b88d01d
commit 25a7b1ca1d
111 changed files with 16802 additions and 5042 deletions

View File

@ -26,10 +26,9 @@
#include "types.h"
#include "Platform.h"
#include "MapButton.h"
#include "Input.h"
#include "InputConfigDialog.h"
#include "ui_InputConfigDialog.h"
#include "MapButton.h"
using namespace melonDS;
@ -43,31 +42,42 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
emuInstance = ((MainWindow*)parent)->getEmuInstance();
Config::Table& instcfg = emuInstance->getLocalConfig();
Config::Table keycfg = instcfg.GetTable("Keyboard");
Config::Table joycfg = instcfg.GetTable("Joystick");
for (int i = 0; i < keypad_num; i++)
{
keypadKeyMap[i] = Config::KeyMapping[dskeyorder[i]];
keypadJoyMap[i] = Config::JoyMapping[dskeyorder[i]];
const char* btn = EmuInstance::buttonNames[dskeyorder[i]];
keypadKeyMap[i] = keycfg.GetInt(btn);
keypadJoyMap[i] = joycfg.GetInt(btn);
}
int i = 0;
for (int hotkey : hk_addons)
{
addonsKeyMap[i] = Config::HKKeyMapping[hotkey];
addonsJoyMap[i] = Config::HKJoyMapping[hotkey];
const char* btn = EmuInstance::hotkeyNames[hotkey];
addonsKeyMap[i] = keycfg.GetInt(btn);
addonsJoyMap[i] = joycfg.GetInt(btn);
i++;
}
i = 0;
for (int hotkey : hk_general)
{
hkGeneralKeyMap[i] = Config::HKKeyMapping[hotkey];
hkGeneralJoyMap[i] = Config::HKJoyMapping[hotkey];
const char* btn = EmuInstance::hotkeyNames[hotkey];
hkGeneralKeyMap[i] = keycfg.GetInt(btn);
hkGeneralJoyMap[i] = joycfg.GetInt(btn);
i++;
}
populatePage(ui->tabAddons, hk_addons_labels, addonsKeyMap, addonsJoyMap);
populatePage(ui->tabHotkeysGeneral, hk_general_labels, hkGeneralKeyMap, hkGeneralJoyMap);
joystickID = instcfg.GetInt("JoystickID");
int njoy = SDL_NumJoysticks();
if (njoy > 0)
{
@ -76,7 +86,7 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
const char* name = SDL_JoystickNameForIndex(i);
ui->cbxJoystick->addItem(QString(name));
}
ui->cbxJoystick->setCurrentIndex(Input::JoystickID);
ui->cbxJoystick->setCurrentIndex(joystickID);
}
else
{
@ -86,7 +96,7 @@ InputConfigDialog::InputConfigDialog(QWidget* parent) : QDialog(parent), ui(new
setupKeypadPage();
int inst = Platform::InstanceID();
int inst = emuInstance->getInstanceID();
if (inst > 0)
ui->lblInstanceNum->setText(QString("Configuring mappings for instance %1").arg(inst+1));
else
@ -174,38 +184,47 @@ void InputConfigDialog::populatePage(QWidget* page,
void InputConfigDialog::on_InputConfigDialog_accepted()
{
Config::Table& instcfg = emuInstance->getLocalConfig();
Config::Table keycfg = instcfg.GetTable("Keyboard");
Config::Table joycfg = instcfg.GetTable("Joystick");
for (int i = 0; i < keypad_num; i++)
{
Config::KeyMapping[dskeyorder[i]] = keypadKeyMap[i];
Config::JoyMapping[dskeyorder[i]] = keypadJoyMap[i];
const char* btn = EmuInstance::buttonNames[dskeyorder[i]];
keycfg.SetInt(btn, keypadKeyMap[i]);
joycfg.SetInt(btn, keypadJoyMap[i]);
}
int i = 0;
for (int hotkey : hk_addons)
{
Config::HKKeyMapping[hotkey] = addonsKeyMap[i];
Config::HKJoyMapping[hotkey] = addonsJoyMap[i];
const char* btn = EmuInstance::hotkeyNames[hotkey];
keycfg.SetInt(btn, addonsKeyMap[i]);
joycfg.SetInt(btn, addonsJoyMap[i]);
i++;
}
i = 0;
for (int hotkey : hk_general)
{
Config::HKKeyMapping[hotkey] = hkGeneralKeyMap[i];
Config::HKJoyMapping[hotkey] = hkGeneralJoyMap[i];
const char* btn = EmuInstance::hotkeyNames[hotkey];
keycfg.SetInt(btn, hkGeneralKeyMap[i]);
joycfg.SetInt(btn, hkGeneralJoyMap[i]);
i++;
}
Config::JoystickID = Input::JoystickID;
instcfg.SetInt("JoystickID", joystickID);
Config::Save();
emuInstance->inputLoadConfig();
closeDlg();
}
void InputConfigDialog::on_InputConfigDialog_rejected()
{
Input::JoystickID = Config::JoystickID;
Input::OpenJoystick();
Config::Table& instcfg = emuInstance->getLocalConfig();
emuInstance->setJoystick(instcfg.GetInt("JoystickID"));
closeDlg();
}
@ -225,6 +244,11 @@ void InputConfigDialog::on_cbxJoystick_currentIndexChanged(int id)
// prevent a spurious change
if (ui->cbxJoystick->count() < 2) return;
Input::JoystickID = id;
Input::OpenJoystick();
joystickID = id;
emuInstance->setJoystick(id);
}
SDL_Joystick* InputConfigDialog::getJoystick()
{
return emuInstance->getJoystick();
}

View File

@ -24,6 +24,7 @@
#include <initializer_list>
#include "Config.h"
#include "EmuInstance.h"
static constexpr int keypad_num = 12;
@ -89,6 +90,8 @@ public:
explicit InputConfigDialog(QWidget* parent);
~InputConfigDialog();
SDL_Joystick* getJoystick();
static InputConfigDialog* currentDlg;
static InputConfigDialog* openDlg(QWidget* parent)
{
@ -123,9 +126,12 @@ private:
Ui::InputConfigDialog* ui;
EmuInstance* emuInstance;
int keypadKeyMap[12], keypadJoyMap[12];
int addonsKeyMap[hk_addons.size()], addonsJoyMap[hk_addons.size()];
int hkGeneralKeyMap[hk_general.size()], hkGeneralJoyMap[hk_general.size()];
int joystickID;
};

View File

@ -23,8 +23,10 @@
#include <SDL2/SDL.h>
#include "Input.h"
#include "Platform.h"
#include "EmuInstance.h"
class InputConfigDialog;
class KeyMapButton : public QPushButton
{
@ -76,7 +78,7 @@ protected:
if (!ismod)
key |= mod;
else if (Input::IsRightModKey(event))
else if (isRightModKey(event))
key |= (1<<31);
*mapping = key;
@ -162,6 +164,9 @@ public:
this->mapping = mapping;
this->isHotkey = hotkey;
// the parent will be set later when this button is added to a layout
parentDialog = nullptr;
setCheckable(true);
setText(mappingText());
setFocusPolicy(Qt::StrongFocus); //Fixes binding keys in macOS
@ -176,6 +181,20 @@ public:
}
protected:
void showEvent(QShowEvent* event) override
{
if (event->spontaneous()) return;
QWidget* w = parentWidget();
for (;;)
{
parentDialog = qobject_cast<InputConfigDialog*>(w);
if (parentDialog) break;
w = w->parentWidget();
if (!w) break;
}
}
void keyPressEvent(QKeyEvent* event) override
{
if (!isChecked()) return QPushButton::keyPressEvent(event);
@ -203,7 +222,7 @@ protected:
void timerEvent(QTimerEvent* event) override
{
SDL_Joystick* joy = Input::Joystick;
SDL_Joystick* joy = parentDialog->getJoystick();
if (!joy) { click(); return; }
if (!SDL_JoystickGetAttached(joy)) { click(); return; }
@ -279,13 +298,15 @@ private slots:
timerID = startTimer(50);
memset(axesRest, 0, sizeof(axesRest));
if (Input::Joystick && SDL_JoystickGetAttached(Input::Joystick))
SDL_Joystick* joy = parentDialog->getJoystick();
if (joy && SDL_JoystickGetAttached(joy))
{
int naxes = SDL_JoystickNumAxes(Input::Joystick);
int naxes = SDL_JoystickNumAxes(joy);
if (naxes > 16) naxes = 16;
for (int a = 0; a < naxes; a++)
{
axesRest[a] = SDL_JoystickGetAxis(Input::Joystick, a);
axesRest[a] = SDL_JoystickGetAxis(joy, a);
}
}
}
@ -349,6 +370,8 @@ private:
return str;
}
InputConfigDialog* parentDialog;
int* mapping;
bool isHotkey;