CommonHostInterface: Extract ff/turbo hotkeys to functions

This commit is contained in:
Connor McLaughlin 2021-01-30 15:49:09 +10:00
parent bed1abf0b8
commit e1bf362d13
2 changed files with 37 additions and 29 deletions

View File

@ -1535,6 +1535,30 @@ bool CommonHostInterface::AddRumbleToInputMap(const std::string& binding, u32 co
return false; return false;
} }
void CommonHostInterface::SetFastForwardEnabled(bool enabled)
{
if (!System::IsValid())
return;
m_fast_forward_enabled = enabled;
UpdateSpeedLimiterState();
AddOSDMessage(enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") :
TranslateStdString("OSDMessage", "Stopped fast forwarding."),
2.0f);
}
void CommonHostInterface::SetTurboEnabled(bool enabled)
{
if (!System::IsValid())
return;
m_turbo_enabled = enabled;
UpdateSpeedLimiterState();
AddOSDMessage(enabled ? TranslateStdString("OSDMessage", "Turboing...") :
TranslateStdString("OSDMessage", "Stopped turboing."),
2.0f);
}
void CommonHostInterface::RegisterHotkeys() void CommonHostInterface::RegisterHotkeys()
{ {
RegisterGeneralHotkeys(); RegisterGeneralHotkeys();
@ -1545,47 +1569,23 @@ void CommonHostInterface::RegisterHotkeys()
void CommonHostInterface::RegisterGeneralHotkeys() void CommonHostInterface::RegisterGeneralHotkeys()
{ {
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"),
TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { SetFastForwardEnabled(pressed); });
m_fast_forward_enabled = pressed;
UpdateSpeedLimiterState();
AddOSDMessage(m_fast_forward_enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") :
TranslateStdString("OSDMessage", "Stopped fast forwarding."),
2.0f);
});
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFastForward"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFastForward"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Fast Forward")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Toggle Fast Forward")), [this](bool pressed) {
if (pressed) if (pressed)
{ SetFastForwardEnabled(!m_fast_forward_enabled);
m_fast_forward_enabled = !m_fast_forward_enabled;
UpdateSpeedLimiterState();
AddOSDMessage(m_fast_forward_enabled ?
TranslateStdString("OSDMessage", "Fast forwarding...") :
TranslateStdString("OSDMessage", "Stopped fast forwarding."),
2.0f);
}
}); });
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Turbo"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Turbo"),
TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { SetTurboEnabled(pressed); });
m_turbo_enabled = pressed;
UpdateSpeedLimiterState();
AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") :
TranslateStdString("OSDMessage", "Stopped turboing."),
2.0f);
});
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleTurbo"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleTurbo"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Turbo")), [this](bool pressed) { StaticString(TRANSLATABLE("Hotkeys", "Toggle Turbo")), [this](bool pressed) {
if (pressed) if (pressed)
{ SetTurboEnabled(!m_turbo_enabled);
m_turbo_enabled = !m_turbo_enabled;
UpdateSpeedLimiterState();
AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") :
TranslateStdString("OSDMessage", "Stopped turboing."),
2.0f);
}
}); });
#ifndef ANDROID #ifndef ANDROID
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFullscreen"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFullscreen"),

View File

@ -222,6 +222,14 @@ public:
/// This is the APK for Android builds, or the program directory for standalone builds. /// This is the APK for Android builds, or the program directory for standalone builds.
virtual std::unique_ptr<ByteStream> OpenPackageFile(const char* path, u32 flags) override; virtual std::unique_ptr<ByteStream> OpenPackageFile(const char* path, u32 flags) override;
/// Toggles fast forward state.
bool IsFastForwardEnabled() const { return m_fast_forward_enabled; }
void SetFastForwardEnabled(bool enabled);
/// Toggles turbo state.
bool IsTurboEnabled() const { return m_turbo_enabled; }
void SetTurboEnabled(bool enabled);
protected: protected:
enum : u32 enum : u32
{ {