pause game while KBM window is open for consistency

This commit is contained in:
rainmakerv3 2025-06-25 14:36:29 +08:00
parent 86be802223
commit 8b08e2b382
5 changed files with 33 additions and 8 deletions

View File

@ -918,7 +918,7 @@ void ControlSettings::pollSDLEvents() {
}
}
void ControlSettings::cleanup() {
void ControlSettings::Cleanup() {
SdlEventWrapper::Wrapper::wrapperActive = false;
if (gamepad)
SDL_CloseGamepad(gamepad);

View File

@ -44,7 +44,7 @@ private:
void SetMapping(QString input);
void DisableMappingButtons();
void EnableMappingButtons();
void cleanup();
void Cleanup();
QList<QPushButton*> ButtonsList;
QList<QPushButton*> AxisList;
@ -76,6 +76,6 @@ private:
protected:
void closeEvent(QCloseEvent* event) override {
cleanup();
Cleanup();
}
};

View File

@ -7,22 +7,32 @@
#include <QMouseEvent>
#include <QPushButton>
#include <QWheelEvent>
#include <SDL3/SDL_events.h>
#include "common/path_util.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, QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), ui(new Ui::KBMSettings) {
KBMSettings::KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool isGameRunning,
QWidget* parent)
: QDialog(parent), m_game_info(game_info_get), GameRunning(isGameRunning),
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");
@ -998,8 +1008,15 @@ 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

@ -23,7 +23,8 @@ class KBMSettings;
class KBMSettings : public QDialog {
Q_OBJECT
public:
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, QWidget* parent = nullptr);
explicit KBMSettings(std::shared_ptr<GameInfoClass> game_info_get, bool GameRunning,
QWidget* parent = nullptr);
~KBMSettings();
private Q_SLOTS:
@ -44,8 +45,10 @@ private:
void DisableMappingButtons();
void EnableMappingButtons();
void SetMapping(QString input);
void Cleanup();
QSet<QString> pressedKeys;
bool GameRunning;
bool EnableMapping = false;
bool MappingCompleted = false;
bool HelpWindowOpen = false;
@ -66,4 +69,9 @@ 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

@ -478,7 +478,7 @@ void MainWindow::CreateConnects() {
});
connect(ui->keyboardButton, &QPushButton::clicked, this, [this]() {
auto kbmWindow = new KBMSettings(m_game_info, this);
auto kbmWindow = new KBMSettings(m_game_info, isGameRunning, this);
kbmWindow->exec();
});