mirror of https://github.com/mgba-emu/mgba.git
Qt: Key autofire
This commit is contained in:
parent
50d4b31b58
commit
b2193d9191
1
CHANGES
1
CHANGES
|
@ -9,6 +9,7 @@ Features:
|
|||
- ROM information view
|
||||
- Support for VBA-style cheat codes
|
||||
- Savestates now store creation timestamps
|
||||
- Key autofire
|
||||
Bugfixes:
|
||||
- Util: Fix PowerPC PNG read/write pixel order
|
||||
- VFS: Fix VFileReadline and remove _vfdReadline
|
||||
|
|
|
@ -50,6 +50,8 @@ GameController::GameController(QObject* parent)
|
|||
, m_wasPaused(false)
|
||||
, m_audioChannels{ true, true, true, true, true, true }
|
||||
, m_videoLayers{ true, true, true, true, true }
|
||||
, m_autofire{}
|
||||
, m_autofireStatus{}
|
||||
, m_inputController(nullptr)
|
||||
, m_multiplayer(nullptr)
|
||||
, m_stateSlot(1)
|
||||
|
@ -204,6 +206,7 @@ GameController::GameController(QObject* parent)
|
|||
connect(this, SIGNAL(gamePaused(GBAThread*)), m_audioProcessor, SLOT(pause()));
|
||||
connect(this, SIGNAL(gameUnpaused(GBAThread*)), m_audioProcessor, SLOT(start()));
|
||||
connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(pollEvents()));
|
||||
connect(this, SIGNAL(frameAvailable(const uint32_t*)), this, SLOT(updateAutofire()));
|
||||
}
|
||||
|
||||
GameController::~GameController() {
|
||||
|
@ -596,6 +599,14 @@ void GameController::clearKeys() {
|
|||
updateKeys();
|
||||
}
|
||||
|
||||
void GameController::setAutofire(int key, bool enable) {
|
||||
if (key >= GBA_KEY_MAX || key < 0) {
|
||||
return;
|
||||
}
|
||||
m_autofire[key] = enable;
|
||||
m_autofireStatus[key] = 0;
|
||||
}
|
||||
|
||||
void GameController::setAudioBufferSamples(int samples) {
|
||||
if (m_audioProcessor) {
|
||||
threadInterrupt();
|
||||
|
@ -979,3 +990,18 @@ void GameController::pollEvents() {
|
|||
m_activeButtons = m_inputController->pollEvents();
|
||||
updateKeys();
|
||||
}
|
||||
|
||||
void GameController::updateAutofire() {
|
||||
// TODO: Move all key events onto the CPU thread...somehow
|
||||
for (int k = 0; k < GBA_KEY_MAX; ++k) {
|
||||
if (!m_autofire[k]) {
|
||||
continue;
|
||||
}
|
||||
m_autofireStatus[k] ^= 1;
|
||||
if (m_autofireStatus[k]) {
|
||||
keyPressed(k);
|
||||
} else {
|
||||
keyReleased(k);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -118,6 +118,7 @@ public slots:
|
|||
void keyPressed(int key);
|
||||
void keyReleased(int key);
|
||||
void clearKeys();
|
||||
void setAutofire(int key, bool enable);
|
||||
void setAudioBufferSamples(int samples);
|
||||
void setAudioSampleRate(unsigned rate);
|
||||
void setAudioChannelEnabled(int channel, bool enable = true);
|
||||
|
@ -161,6 +162,7 @@ private slots:
|
|||
void crashGame(const QString& crashMessage);
|
||||
|
||||
void pollEvents();
|
||||
void updateAutofire();
|
||||
|
||||
private:
|
||||
void updateKeys();
|
||||
|
@ -202,6 +204,9 @@ private:
|
|||
bool m_audioChannels[6];
|
||||
bool m_videoLayers[5];
|
||||
|
||||
bool m_autofire[GBA_KEY_MAX];
|
||||
int m_autofireStatus[GBA_KEY_MAX];
|
||||
|
||||
int m_stateSlot;
|
||||
GBASerializedState* m_backupLoadState;
|
||||
QByteArray m_backupSaveState;
|
||||
|
|
|
@ -1270,6 +1270,69 @@ void Window::setupMenu(QMenuBar* menubar) {
|
|||
exitFullScreen->setShortcut(QKeySequence("Esc"));
|
||||
addHiddenAction(frameMenu, exitFullScreen, "exitFullScreen");
|
||||
|
||||
QMenu* autofireMenu = new QMenu(tr("Autofire"), this);
|
||||
m_shortcutController->addMenu(autofireMenu);
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_A, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_A, false);
|
||||
}, QKeySequence("W"), tr("Autofire A"), "autofireA");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_B, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_B, false);
|
||||
}, QKeySequence("Q"), tr("Autofire B"), "autofireB");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_L, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_L, false);
|
||||
}, QKeySequence(), tr("Autofire L"), "autofireL");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_R, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_R, false);
|
||||
}, QKeySequence(), tr("Autofire R"), "autofireR");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_START, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_START, false);
|
||||
}, QKeySequence(), tr("Autofire Start"), "autofireStart");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_SELECT, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_SELECT, false);
|
||||
}, QKeySequence(), tr("Autofire Select"), "autofireSelect");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_UP, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_UP, false);
|
||||
}, QKeySequence(), tr("Autofire Up"), "autofireUp");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_RIGHT, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_RIGHT, false);
|
||||
}, QKeySequence(), tr("Autofire Right"), "autofireRight");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_DOWN, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_DOWN, false);
|
||||
}, QKeySequence(), tr("Autofire Down"), "autofireDown");
|
||||
|
||||
m_shortcutController->addFunctions(autofireMenu, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_LEFT, true);
|
||||
}, [this]() {
|
||||
m_controller->setAutofire(GBA_KEY_LEFT, false);
|
||||
}, QKeySequence(), tr("Autofire Left"), "autofireLeft");
|
||||
|
||||
foreach (QAction* action, m_gameActions) {
|
||||
action->setDisabled(true);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue