Android: Add pause/menu button to touchscreen controller
This commit is contained in:
parent
308320c4e2
commit
3769f30260
|
@ -39,6 +39,7 @@ static jclass s_String_class;
|
||||||
static jclass s_AndroidHostInterface_class;
|
static jclass s_AndroidHostInterface_class;
|
||||||
static jmethodID s_AndroidHostInterface_constructor;
|
static jmethodID s_AndroidHostInterface_constructor;
|
||||||
static jfieldID s_AndroidHostInterface_field_mNativePointer;
|
static jfieldID s_AndroidHostInterface_field_mNativePointer;
|
||||||
|
static jfieldID s_AndroidHostInterface_field_mEmulationActivity;
|
||||||
static jmethodID s_AndroidHostInterface_method_reportError;
|
static jmethodID s_AndroidHostInterface_method_reportError;
|
||||||
static jmethodID s_AndroidHostInterface_method_reportMessage;
|
static jmethodID s_AndroidHostInterface_method_reportMessage;
|
||||||
static jmethodID s_AndroidHostInterface_method_openAssetStream;
|
static jmethodID s_AndroidHostInterface_method_openAssetStream;
|
||||||
|
@ -464,11 +465,13 @@ void AndroidHostInterface::EmulationThreadEntryPoint(JNIEnv* env, jobject emulat
|
||||||
emulation_activity = env->NewGlobalRef(emulation_activity);
|
emulation_activity = env->NewGlobalRef(emulation_activity);
|
||||||
Assert(emulation_activity != nullptr);
|
Assert(emulation_activity != nullptr);
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lock(m_mutex);
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
m_emulation_thread_running.store(true);
|
m_emulation_thread_running.store(true);
|
||||||
m_emulation_activity_object = emulation_activity;
|
m_emulation_activity_object = emulation_activity;
|
||||||
m_emulation_thread_id = std::this_thread::get_id();
|
m_emulation_thread_id = std::this_thread::get_id();
|
||||||
|
env->SetObjectField(m_java_object, s_AndroidHostInterface_field_mEmulationActivity, emulation_activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplySettings(true);
|
ApplySettings(true);
|
||||||
|
@ -500,6 +503,7 @@ void AndroidHostInterface::EmulationThreadEntryPoint(JNIEnv* env, jobject emulat
|
||||||
callback();
|
callback();
|
||||||
lock.lock();
|
lock.lock();
|
||||||
}
|
}
|
||||||
|
env->SetObjectField(m_java_object, s_AndroidHostInterface_field_mEmulationActivity, nullptr);
|
||||||
m_emulation_thread_running.store(false);
|
m_emulation_thread_running.store(false);
|
||||||
m_emulation_thread_id = {};
|
m_emulation_thread_id = {};
|
||||||
m_emulation_activity_object = {};
|
m_emulation_activity_object = {};
|
||||||
|
@ -974,6 +978,8 @@ extern "C" jint JNI_OnLoad(JavaVM* vm, void* reserved)
|
||||||
"(Landroid/content/Context;Lcom/github/stenzek/duckstation/FileHelper;)V")) == nullptr ||
|
"(Landroid/content/Context;Lcom/github/stenzek/duckstation/FileHelper;)V")) == nullptr ||
|
||||||
(s_AndroidHostInterface_field_mNativePointer =
|
(s_AndroidHostInterface_field_mNativePointer =
|
||||||
env->GetFieldID(s_AndroidHostInterface_class, "mNativePointer", "J")) == nullptr ||
|
env->GetFieldID(s_AndroidHostInterface_class, "mNativePointer", "J")) == nullptr ||
|
||||||
|
(s_AndroidHostInterface_field_mEmulationActivity =
|
||||||
|
env->GetFieldID(s_AndroidHostInterface_class, "mEmulationActivity", "Lcom/github/stenzek/duckstation/EmulationActivity;")) == nullptr ||
|
||||||
(s_AndroidHostInterface_method_reportError =
|
(s_AndroidHostInterface_method_reportError =
|
||||||
env->GetMethodID(s_AndroidHostInterface_class, "reportError", "(Ljava/lang/String;)V")) == nullptr ||
|
env->GetMethodID(s_AndroidHostInterface_class, "reportError", "(Ljava/lang/String;)V")) == nullptr ||
|
||||||
(s_AndroidHostInterface_method_reportMessage =
|
(s_AndroidHostInterface_method_reportMessage =
|
||||||
|
|
|
@ -24,6 +24,7 @@ public class AndroidHostInterface {
|
||||||
private long mNativePointer;
|
private long mNativePointer;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
private FileHelper mFileHelper;
|
private FileHelper mFileHelper;
|
||||||
|
private EmulationActivity mEmulationActivity;
|
||||||
|
|
||||||
public AndroidHostInterface(Context context, FileHelper fileHelper) {
|
public AndroidHostInterface(Context context, FileHelper fileHelper) {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
|
@ -50,6 +51,8 @@ public class AndroidHostInterface {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EmulationActivity getEmulationActivity() { return mEmulationActivity; }
|
||||||
|
|
||||||
static public native String getScmVersion();
|
static public native String getScmVersion();
|
||||||
|
|
||||||
static public native String getFullScmVersion();
|
static public native String getFullScmVersion();
|
||||||
|
|
|
@ -17,7 +17,8 @@ public final class TouchscreenControllerButtonView extends View {
|
||||||
{
|
{
|
||||||
NONE,
|
NONE,
|
||||||
FAST_FORWARD,
|
FAST_FORWARD,
|
||||||
ANALOG_TOGGLE
|
ANALOG_TOGGLE,
|
||||||
|
OPEN_PAUSE_MENU,
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable mUnpressedDrawable;
|
private Drawable mUnpressedDrawable;
|
||||||
|
@ -144,11 +145,17 @@ public final class TouchscreenControllerButtonView extends View {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ANALOG_TOGGLE: {
|
case ANALOG_TOGGLE: {
|
||||||
if (mPressed)
|
if (!mPressed)
|
||||||
AndroidHostInterface.getInstance().toggleControllerAnalogMode();
|
AndroidHostInterface.getInstance().toggleControllerAnalogMode();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case OPEN_PAUSE_MENU: {
|
||||||
|
if (!mPressed)
|
||||||
|
AndroidHostInterface.getInstance().getEmulationActivity().openPauseMenu();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case NONE:
|
case NONE:
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -312,6 +312,8 @@ public class TouchscreenControllerView extends FrameLayout {
|
||||||
TouchscreenControllerButtonView.Hotkey.FAST_FORWARD, false);
|
TouchscreenControllerButtonView.Hotkey.FAST_FORWARD, false);
|
||||||
linkHotkeyButton(mMainView, R.id.controller_button_analog, "AnalogToggle",
|
linkHotkeyButton(mMainView, R.id.controller_button_analog, "AnalogToggle",
|
||||||
TouchscreenControllerButtonView.Hotkey.ANALOG_TOGGLE, false);
|
TouchscreenControllerButtonView.Hotkey.ANALOG_TOGGLE, false);
|
||||||
|
linkHotkeyButton(mMainView, R.id.controller_button_pause, "OpenPauseMenu",
|
||||||
|
TouchscreenControllerButtonView.Hotkey.OPEN_PAUSE_MENU, true);
|
||||||
|
|
||||||
linkButton(mMainView, R.id.controller_button_a, "AButton", "A", true, true);
|
linkButton(mMainView, R.id.controller_button_a, "AButton", "A", true, true);
|
||||||
linkButton(mMainView, R.id.controller_button_b, "BButton", "B", true, true);
|
linkButton(mMainView, R.id.controller_button_b, "BButton", "B", true, true);
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24"
|
||||||
|
android:tint="?attr/colorControlNormal">
|
||||||
|
<path
|
||||||
|
android:fillColor="@android:color/white"
|
||||||
|
android:pathData="M9,16h2L11,8L9,8v8zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8zM13,16h2L15,8h-2v8z"/>
|
||||||
|
</vector>
|
|
@ -158,4 +158,15 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
|
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
|
||||||
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
|
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
|
||||||
|
|
||||||
|
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||||
|
android:id="@+id/controller_button_pause"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:pressedDrawable="@drawable/ic_controller_pause_button"
|
||||||
|
app:unpressedDrawable="@drawable/ic_controller_pause_button" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -180,4 +180,15 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
|
app:pressedDrawable="@drawable/ic_controller_analog_button_pressed"
|
||||||
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
|
app:unpressedDrawable="@drawable/ic_controller_analog_button" />
|
||||||
|
|
||||||
|
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||||
|
android:id="@+id/controller_button_pause"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:pressedDrawable="@drawable/ic_controller_pause_button"
|
||||||
|
app:unpressedDrawable="@drawable/ic_controller_pause_button" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -142,4 +142,15 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
|
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
|
||||||
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
|
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
|
||||||
|
|
||||||
|
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||||
|
android:id="@+id/controller_button_pause"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:pressedDrawable="@drawable/ic_controller_pause_button"
|
||||||
|
app:unpressedDrawable="@drawable/ic_controller_pause_button" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
@ -41,4 +41,15 @@
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
|
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
|
||||||
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
|
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
|
||||||
|
|
||||||
|
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
|
||||||
|
android:id="@+id/controller_button_pause"
|
||||||
|
android:layout_width="35dp"
|
||||||
|
android:layout_height="35dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
app:pressedDrawable="@drawable/ic_controller_pause_button"
|
||||||
|
app:unpressedDrawable="@drawable/ic_controller_pause_button" />
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue