From b01d49fa5264e81d7f3c8681d6d3d6e909bcbf12 Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 17 Jul 2021 20:09:41 +1000 Subject: [PATCH] CommonHostInterface: Enable rewind for Android --- src/frontend-common/common_host_interface.cpp | 58 ++++++++++++------- src/frontend-common/common_host_interface.h | 3 + 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index 202e9f0b8..25bfbd948 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -2010,6 +2010,12 @@ bool CommonHostInterface::AddRumbleToInputMap(const std::string& binding, u32 co return false; } +static void DisplayHotkeyBlockedByChallengeModeMessage() +{ + g_host_interface->AddOSDMessage(g_host_interface->TranslateStdString( + "OSDMessage", "Hotkey unavailable because achievements hardcore mode is active.")); +} + void CommonHostInterface::SetFastForwardEnabled(bool enabled) { if (!System::IsValid()) @@ -2034,6 +2040,33 @@ void CommonHostInterface::SetTurboEnabled(bool enabled) 2.0f); } +void CommonHostInterface::SetRewindState(bool enabled) +{ + if (!System::IsValid()) + return; + + if (!IsCheevosChallengeModeActive()) + { + if (!g_settings.rewind_enable) + { + if (enabled) + AddOSDMessage(TranslateStdString("OSDMessage", "Rewinding is not enabled."), 5.0f); + + return; + } + + AddOSDMessage(enabled ? TranslateStdString("OSDMessage", "Rewinding...") : + TranslateStdString("OSDMessage", "Stopped rewinding."), + 5.0f); + System::SetRewinding(enabled); + UpdateSpeedLimiterState(); + } + else + { + DisplayHotkeyBlockedByChallengeModeMessage(); + } +} + void CommonHostInterface::RegisterHotkeys() { RegisterGeneralHotkeys(); @@ -2043,12 +2076,6 @@ void CommonHostInterface::RegisterHotkeys() RegisterAudioHotkeys(); } -static void DisplayHotkeyBlockedByChallengeModeMessage() -{ - g_host_interface->AddOSDMessage(g_host_interface->TranslateStdString( - "OSDMessage", "Hotkey unavailable because achievements hardcore mode is active.")); -} - void CommonHostInterface::RegisterGeneralHotkeys() { #ifndef __ANDROID__ @@ -2189,25 +2216,12 @@ void CommonHostInterface::RegisterSystemHotkeys() DisplayHotkeyBlockedByChallengeModeMessage(); } }); +#endif RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("Rewind"), - StaticString(TRANSLATABLE("Hotkeys", "Rewind")), [this](bool pressed) { - if (System::IsValid()) - { - if (!IsCheevosChallengeModeActive()) - { - AddOSDMessage(pressed ? TranslateStdString("OSDMessage", "Rewinding...") : - TranslateStdString("OSDMessage", "Stopped rewinding."), - 5.0f); - System::SetRewinding(pressed); - } - else - { - DisplayHotkeyBlockedByChallengeModeMessage(); - } - } - }); + StaticString(TRANSLATABLE("Hotkeys", "Rewind")), [this](bool pressed) { SetRewindState(pressed); }); +#ifndef __ANDROID__ RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "System")), StaticString("ToggleCheats"), StaticString(TRANSLATABLE("Hotkeys", "Toggle Cheats")), [this](bool pressed) { if (pressed && System::IsValid()) diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index 970d22cef..31aa33e4d 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -334,6 +334,9 @@ public: bool IsTurboEnabled() const { return m_turbo_enabled; } void SetTurboEnabled(bool enabled); + /// Toggles rewind state. + void SetRewindState(bool enabled); + /// ImGui window drawing. void DrawFPSWindow(); void DrawOSDMessages();