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)
{
cheatsOn = enable;
if (cheatFile)
if (cheatsOn && cheatFile)
nds->AREngine.Cheats = cheatFile->GetCodes();
else
nds->AREngine.Cheats.clear();

View File

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

View File

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

View File

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