Block all other sdl events instead of pausing game, automatic parse inputs after saving

This commit is contained in:
rainmakerv3 2025-06-26 09:36:46 +08:00
parent 7d14392874
commit 134ae3e997
7 changed files with 33 additions and 36 deletions

View File

@ -8,13 +8,13 @@
#include "common/logging/log.h"
#include "common/path_util.h"
#include "control_settings.h"
#include "sdl_window.h"
#include "input/input_handler.h"
#include "ui_control_settings.h"
ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, bool isGameRunning,
QWidget* parent)
std::string GameRunningSerial, QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning),
ui(new Ui::ControlSettings) {
RunningGameSerial(GameRunningSerial), ui(new Ui::ControlSettings) {
ui->setupUi(this);
@ -24,9 +24,6 @@ ControlSettings::ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, b
CheckGamePad();
} else {
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1");
SDL_Event pauseGame{};
pauseGame.type = SDL_EVENT_TOGGLE_PAUSE;
SDL_PushEvent(&pauseGame);
}
AddBoxItems();
@ -327,6 +324,11 @@ void ControlSettings::SaveControllerConfig(bool CloseOnSave) {
ui->BSlider->value());
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
if (GameRunning) {
Config::GetUseUnifiedInputConfig() ? Input::ParseInputConfig("default")
: Input::ParseInputConfig(RunningGameSerial);
}
if (CloseOnSave)
QWidget::close();
}
@ -929,9 +931,6 @@ void ControlSettings::Cleanup() {
SDL_Quit();
} else {
SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "0");
SDL_Event resumeGame{};
resumeGame.type = SDL_EVENT_TOGGLE_PAUSE;
SDL_PushEvent(&resumeGame);
}
}

View File

@ -15,7 +15,7 @@ class ControlSettings : public QDialog {
Q_OBJECT
public:
explicit ControlSettings(std::shared_ptr<GameInfoClass> game_info_get, bool GameRunning,
QWidget* parent = nullptr);
std::string GameRunningSerial, QWidget* parent = nullptr);
~ControlSettings();
signals:
@ -50,6 +50,7 @@ private:
QList<QPushButton*> AxisList;
QSet<QString> pressedButtons;
std::string RunningGameSerial;
bool GameRunning;
bool L2Pressed = false;
bool R2Pressed = false;

View File

@ -10,29 +10,23 @@
#include <SDL3/SDL_events.h>
#include "common/path_util.h"
#include "input/input_handler.h"
#include "kbm_config_dialog.h"
#include "kbm_gui.h"
#include "kbm_help_dialog.h"
#include "sdl_window.h"
#include "ui_kbm_gui.h"
HelpDialog* HelpWindow;
KBMSettings::KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool isGameRunning,
QWidget* parent)
std::string GameRunningSerial, QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning),
ui(new Ui::KBMSettings) {
RunningGameSerial(GameRunningSerial), ui(new Ui::KBMSettings) {
ui->setupUi(this);
ui->PerGameCheckBox->setChecked(!Config::GetUseUnifiedInputConfig());
ui->TextEditorButton->setFocus();
this->setFocusPolicy(Qt::StrongFocus);
if (GameRunning) {
SDL_Event pauseGame{};
pauseGame.type = SDL_EVENT_TOGGLE_PAUSE;
SDL_PushEvent(&pauseGame);
}
ui->MouseJoystickBox->addItem("none");
ui->MouseJoystickBox->addItem("right");
ui->MouseJoystickBox->addItem("left");
@ -340,6 +334,11 @@ QString(tr("Cannot bind any unique input more than once. Duplicate inputs mapped
Config::SetUseUnifiedInputConfig(!ui->PerGameCheckBox->isChecked());
Config::save(Common::FS::GetUserPath(Common::FS::PathType::UserDir) / "config.toml");
if (GameRunning) {
Config::GetUseUnifiedInputConfig() ? Input::ParseInputConfig("default")
: Input::ParseInputConfig(RunningGameSerial);
}
if (close_on_save)
QWidget::close();
}
@ -1011,12 +1010,4 @@ bool KBMSettings::eventFilter(QObject* obj, QEvent* event) {
return QDialog::eventFilter(obj, event);
}
void KBMSettings::Cleanup() {
if (GameRunning) {
SDL_Event resumeGame{};
resumeGame.type = SDL_EVENT_TOGGLE_PAUSE;
SDL_PushEvent(&resumeGame);
}
}
KBMSettings::~KBMSettings() {}

View File

@ -24,7 +24,7 @@ class KBMSettings : public QDialog {
Q_OBJECT
public:
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool GameRunning,
QWidget* parent = nullptr);
std::string GameRunningSerial, QWidget* parent = nullptr);
~KBMSettings();
private Q_SLOTS:
@ -47,6 +47,7 @@ private:
void SetMapping(QString input);
void Cleanup();
std::string RunningGameSerial;
QSet<QString> pressedKeys;
bool GameRunning;
bool EnableMapping = false;
@ -69,9 +70,4 @@ private:
"pad_left", "pad_right", "axis_left_x", "axis_left_y", "axis_right_x",
"axis_right_y", "back"};
protected:
void closeEvent(QCloseEvent* event) override {
Cleanup();
}
};

View File

@ -473,12 +473,13 @@ void MainWindow::CreateConnects() {
});
connect(ui->controllerButton, &QPushButton::clicked, this, [this]() {
ControlSettings* remapWindow = new ControlSettings(m_game_info, isGameRunning, this);
ControlSettings* remapWindow =
new ControlSettings(m_game_info, isGameRunning, runningGameSerial, this);
remapWindow->exec();
});
connect(ui->keyboardButton, &QPushButton::clicked, this, [this]() {
auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, this);
auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, runningGameSerial, this);
kbmWindow->exec();
});
@ -846,12 +847,14 @@ void MainWindow::StartGame() {
if (m_game_list_frame->currentItem()) {
int itemID = m_game_list_frame->currentItem()->row();
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
runningGameSerial = m_game_info->m_games[itemID].serial;
}
} else if (table_mode == 1) {
if (m_game_grid_frame->cellClicked) {
int itemID = (m_game_grid_frame->crtRow * m_game_grid_frame->columnCnt) +
m_game_grid_frame->crtColumn;
Common::FS::PathToQString(gamePath, m_game_info->m_games[itemID].path / "eboot.bin");
runningGameSerial = m_game_info->m_games[itemID].serial;
}
} else {
if (m_elf_viewer->currentItem()) {

View File

@ -75,11 +75,13 @@ private:
void PlayBackgroundMusic();
QIcon RecolorIcon(const QIcon& icon, bool isWhite);
void StartEmulator(std::filesystem::path);
bool isIconBlack = false;
bool isTableList = true;
bool isGameRunning = false;
bool isWhite = false;
bool is_paused = false;
std::string runningGameSerial = "";
QActionGroup* m_icon_size_act_group = nullptr;
QActionGroup* m_list_mode_act_group = nullptr;

View File

@ -19,6 +19,10 @@ Wrapper* Wrapper::GetInstance() {
bool Wrapper::ProcessEvent(SDL_Event* event) {
switch (event->type) {
case SDL_EVENT_GAMEPAD_ADDED:
return false;
case SDL_EVENT_GAMEPAD_REMOVED:
return false;
case SDL_EVENT_QUIT:
emit SDLEvent(SDL_EVENT_QUIT, 0, 0);
return true;
@ -31,8 +35,9 @@ bool Wrapper::ProcessEvent(SDL_Event* event) {
case SDL_EVENT_GAMEPAD_AXIS_MOTION:
emit SDLEvent(SDL_EVENT_GAMEPAD_AXIS_MOTION, event->gaxis.axis, event->gaxis.value);
return true;
// block all other SDL events while wrapper is active
default:
return false;
return true;
}
}
Wrapper::~Wrapper() {}