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_setVibration;
static jmethodID s_EmulationActivity_method_getRefreshRate;
static jmethodID s_EmulationActivity_method_openPauseMenu;
static jclass s_PatchCode_class;
static jmethodID s_PatchCode_constructor;
static jclass s_GameListEntry_class;
@ -224,6 +225,19 @@ std::unique_ptr<ByteStream> AndroidHostInterface::OpenPackageFile(const char* pa
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)
{
if (!m_emulation_activity_object)
@ -898,6 +912,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
nullptr ||
(s_EmulationActivity_method_getRefreshRate =
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_GameListEntry_constructor = env->GetMethodID(
s_GameListEntry_class, "<init>",

View File

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

View File

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

View File

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

View File

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