fix up cheat toggle

This commit is contained in:
Arisotura 2024-10-31 20:33:57 +01:00
parent 6c6cefad6c
commit 1b8daa0465
4 changed files with 21 additions and 2 deletions

View File

@ -1161,7 +1161,7 @@ std::optional<FATStorage> EmuInstance::loadSDCard(const string& key) noexcept
void EmuInstance::enableCheats(bool enable) void EmuInstance::enableCheats(bool enable)
{ {
cheatsOn = enable; cheatsOn = enable;
if (cheatFile) if (cheatsOn && cheatFile)
nds->AREngine.Cheats = cheatFile->GetCodes(); nds->AREngine.Cheats = cheatFile->GetCodes();
else else
nds->AREngine.Cheats.clear(); nds->AREngine.Cheats.clear();

View File

@ -648,6 +648,10 @@ void EmuThread::handleMessages()
msgResult = 1; msgResult = 1;
} }
break; break;
case msg_EnableCheats:
emuInstance->enableCheats(msg.param.value<bool>());
break;
} }
msgSemaphore.release(); msgSemaphore.release();
@ -815,6 +819,12 @@ int EmuThread::importSavefile(const QString& filename)
return msgResult; return msgResult;
} }
void EmuThread::enableCheats(bool enable)
{
sendMessage({.type = msg_EnableCheats, .param = enable});
waitMessage();
}
void EmuThread::updateRenderer() void EmuThread::updateRenderer()
{ {
if (videoRenderer != lastVideoRenderer) if (videoRenderer != lastVideoRenderer)

View File

@ -83,6 +83,8 @@ public:
msg_UndoStateLoad, msg_UndoStateLoad,
msg_ImportSavefile, msg_ImportSavefile,
msg_EnableCheats,
}; };
struct Message struct Message
@ -124,6 +126,8 @@ public:
int importSavefile(const QString& filename); int importSavefile(const QString& filename);
void enableCheats(bool enable);
bool emuIsRunning(); bool emuIsRunning();
bool emuIsActive(); bool emuIsActive();

View File

@ -1655,7 +1655,12 @@ void MainWindow::onOpenPowerManagement()
void MainWindow::onEnableCheats(bool checked) void MainWindow::onEnableCheats(bool checked)
{ {
localCfg.SetBool("EnableCheats", checked); localCfg.SetBool("EnableCheats", checked);
emuInstance->enableCheats(checked); emuThread->enableCheats(checked);
emuInstance->doOnAllWindows([=](MainWindow* win)
{
win->actEnableCheats->setChecked(checked);
}, windowID);
} }
void MainWindow::onSetupCheats() void MainWindow::onSetupCheats()