CommonHostInterface: Add a hotkey to toggle all cheats

This commit is contained in:
Connor McLaughlin
2020-12-06 23:32:32 +10:00
parent 922e17f677
commit 737a87b483
3 changed files with 30 additions and 2 deletions

View File

@ -964,6 +964,25 @@ void CommonHostInterface::DoFrameStep()
PauseSystem(false);
}
void CommonHostInterface::DoToggleCheats()
{
if (System::IsShutdown())
return;
CheatList* cl = System::GetCheatList();
if (!cl)
{
AddOSDMessage(TranslateStdString("OSDMessage", "No cheats are loaded."), 10.0f);
return;
}
cl->SetMasterEnable(!cl->GetMasterEnable());
AddFormattedOSDMessage(10.0f,
cl->GetMasterEnable() ? TranslateString("OSDMessage", "%u cheats are now active.") :
TranslateString("OSDMessage", "%u cheats are now inactive."),
cl->GetEnabledCodeCount());
}
std::optional<CommonHostInterface::HostKeyCode>
CommonHostInterface::GetHostKeyCode(const std::string_view key_code) const
{
@ -1449,6 +1468,12 @@ void CommonHostInterface::RegisterGeneralHotkeys()
PauseSystem(!System::IsPaused());
});
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleCheats"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) {
if (pressed)
DoToggleCheats();
});
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("PowerOff"),
StaticString(TRANSLATABLE("Hotkeys", "Power Off System")), [this](bool pressed) {
if (pressed && System::IsValid())
@ -1490,9 +1515,7 @@ void CommonHostInterface::RegisterGeneralHotkeys()
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FrameStep"),
StaticString(TRANSLATABLE("Hotkeys", "Frame Step")), [this](bool pressed) {
if (pressed)
{
DoFrameStep();
}
});
}

View File

@ -331,6 +331,7 @@ protected:
void DrawOSDMessages();
void DrawDebugWindows();
void DoFrameStep();
void DoToggleCheats();
std::unique_ptr<GameList> m_game_list;