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;
}
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()
{
RegisterGeneralHotkeys();
@ -1545,47 +1569,23 @@ void CommonHostInterface::RegisterHotkeys()
void CommonHostInterface::RegisterGeneralHotkeys()
{
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"),
TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) {
m_fast_forward_enabled = pressed;
UpdateSpeedLimiterState();
AddOSDMessage(m_fast_forward_enabled ? TranslateStdString("OSDMessage", "Fast forwarding...") :
TranslateStdString("OSDMessage", "Stopped fast forwarding."),
2.0f);
});
TRANSLATABLE("Hotkeys", "Fast Forward"), [this](bool pressed) { SetFastForwardEnabled(pressed); });
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleFastForward"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Fast Forward")), [this](bool pressed) {
if (pressed)
{
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);
}
SetFastForwardEnabled(!m_fast_forward_enabled);
});
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("Turbo"),
TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) {
m_turbo_enabled = pressed;
UpdateSpeedLimiterState();
AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") :
TranslateStdString("OSDMessage", "Stopped turboing."),
2.0f);
});
TRANSLATABLE("Hotkeys", "Turbo"), [this](bool pressed) { SetTurboEnabled(pressed); });
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("ToggleTurbo"),
StaticString(TRANSLATABLE("Hotkeys", "Toggle Turbo")), [this](bool pressed) {
if (pressed)
{
m_turbo_enabled = !m_turbo_enabled;
UpdateSpeedLimiterState();
AddOSDMessage(m_turbo_enabled ? TranslateStdString("OSDMessage", "Turboing...") :
TranslateStdString("OSDMessage", "Stopped turboing."),
2.0f);
}
SetTurboEnabled(!m_turbo_enabled);
});
#ifndef ANDROID
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.
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:
enum : u32
{