Android: Add 'Open Pause Menu' hotkey

This commit is contained in:
Connor McLaughlin 2021-01-13 18:54:37 +10:00
parent 60232c390a
commit 37f9f118c4
5 changed files with 35 additions and 4 deletions

View file

@ -45,6 +45,7 @@ static jmethodID s_EmulationActivity_method_onEmulationStopped;
static jmethodID s_EmulationActivity_method_onGameTitleChanged; static jmethodID s_EmulationActivity_method_onGameTitleChanged;
static jmethodID s_EmulationActivity_method_setVibration; static jmethodID s_EmulationActivity_method_setVibration;
static jmethodID s_EmulationActivity_method_getRefreshRate; static jmethodID s_EmulationActivity_method_getRefreshRate;
static jmethodID s_EmulationActivity_method_openPauseMenu;
static jclass s_PatchCode_class; static jclass s_PatchCode_class;
static jmethodID s_PatchCode_constructor; static jmethodID s_PatchCode_constructor;
static jclass s_GameListEntry_class; static jclass s_GameListEntry_class;
@ -224,6 +225,19 @@ std::unique_ptr<ByteStream> AndroidHostInterface::OpenPackageFile(const char* pa
return ret; return ret;
} }
void AndroidHostInterface::RegisterHotkeys()
{
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("OpenPauseMenu"),
StaticString(TRANSLATABLE("Hotkeys", "Open Pause Menu")), [this](bool pressed) {
if (pressed) {
AndroidHelpers::GetJNIEnv()->CallVoidMethod(m_emulation_activity_object,
s_EmulationActivity_method_openPauseMenu);
}
});
CommonHostInterface::RegisterHotkeys();
}
bool AndroidHostInterface::GetMainDisplayRefreshRate(float* refresh_rate) bool AndroidHostInterface::GetMainDisplayRefreshRate(float* refresh_rate)
{ {
if (!m_emulation_activity_object) if (!m_emulation_activity_object)
@ -898,6 +912,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
nullptr || nullptr ||
(s_EmulationActivity_method_getRefreshRate = (s_EmulationActivity_method_getRefreshRate =
env->GetMethodID(emulation_activity_class, "getRefreshRate", "()F")) == nullptr || env->GetMethodID(emulation_activity_class, "getRefreshRate", "()F")) == nullptr ||
(s_EmulationActivity_method_openPauseMenu =
env->GetMethodID(emulation_activity_class, "openPauseMenu", "()V")) == nullptr ||
(s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr || (s_PatchCode_constructor = env->GetMethodID(s_PatchCode_class, "<init>", "(ILjava/lang/String;Z)V")) == nullptr ||
(s_GameListEntry_constructor = env->GetMethodID( (s_GameListEntry_constructor = env->GetMethodID(
s_GameListEntry_class, "<init>", s_GameListEntry_class, "<init>",

View file

@ -72,6 +72,7 @@ protected:
void SetUserDirectory() override; void SetUserDirectory() override;
void LoadSettings() override; void LoadSettings() override;
void UpdateInputMap() override; void UpdateInputMap() override;
void RegisterHotkeys() override;
bool AcquireHostDisplay() override; bool AcquireHostDisplay() override;
void ReleaseHostDisplay() override; void ReleaseHostDisplay() override;

View file

@ -154,6 +154,12 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
return display.getRefreshRate(); return display.getRefreshRate();
} }
public void openPauseMenu() {
runOnUiThread(() -> {
showMenu();
});
}
private void doApplySettings() { private void doApplySettings() {
AndroidHostInterface.getInstance().applySettings(); AndroidHostInterface.getInstance().applySettings();
updateRequestedOrientation(); updateRequestedOrientation();

View file

@ -77,10 +77,7 @@ bool CommonHostInterface::Initialize()
m_save_state_selector_ui = std::make_unique<FrontendCommon::SaveStateSelectorUI>(this); m_save_state_selector_ui = std::make_unique<FrontendCommon::SaveStateSelectorUI>(this);
RegisterGeneralHotkeys(); RegisterHotkeys();
RegisterGraphicsHotkeys();
RegisterSaveStateHotkeys();
RegisterAudioHotkeys();
UpdateControllerInterface(); UpdateControllerInterface();
return true; return true;
@ -1462,6 +1459,14 @@ bool CommonHostInterface::AddRumbleToInputMap(const std::string& binding, u32 co
return false; return false;
} }
void CommonHostInterface::RegisterHotkeys()
{
RegisterGeneralHotkeys();
RegisterGraphicsHotkeys();
RegisterSaveStateHotkeys();
RegisterAudioHotkeys();
}
void CommonHostInterface::RegisterGeneralHotkeys() void CommonHostInterface::RegisterGeneralHotkeys()
{ {
RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"), RegisterHotkey(StaticString(TRANSLATABLE("Hotkeys", "General")), StaticString("FastForward"),

View file

@ -225,6 +225,9 @@ protected:
/// Request the frontend to exit. /// Request the frontend to exit.
virtual void RequestExit() = 0; virtual void RequestExit() = 0;
/// Registers frontend-specific hotkeys.
virtual void RegisterHotkeys();
/// Executes per-frame tasks such as controller polling. /// Executes per-frame tasks such as controller polling.
virtual void PollAndUpdate(); virtual void PollAndUpdate();