Android: Add support for GunCon

This commit is contained in:
Connor McLaughlin 2021-04-03 14:53:34 +10:00
parent 17707525dc
commit bb21a062d8
16 changed files with 169 additions and 27 deletions

View File

@ -749,26 +749,6 @@ void AndroidHostInterface::SetDisplayAlignment(HostDisplay::Alignment alignment)
m_display->SetDisplayAlignment(alignment);
}
void AndroidHostInterface::SetControllerType(u32 index, std::string_view type_name)
{
ControllerType type =
Settings::ParseControllerTypeName(std::string(type_name).c_str()).value_or(ControllerType::None);
if (!IsEmulationThreadRunning())
{
g_settings.controller_types[index] = type;
return;
}
RunOnEmulationThread(
[index, type]() {
Log_InfoPrintf("Changing controller slot %d to %s", index, Settings::GetControllerTypeName(type));
g_settings.controller_types[index] = type;
System::UpdateControllers();
},
false);
}
void AndroidHostInterface::SetControllerButtonState(u32 index, s32 button_code, bool pressed)
{
if (!IsEmulationThreadRunning())
@ -1163,10 +1143,14 @@ DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_surfaceChanged, jobject obj, j
block);
}
DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setControllerType, jobject obj, jint index, jstring controller_type)
DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setMousePosition, jobject obj, jint positionX, jint positionY)
{
AndroidHelpers::GetNativeClass(env, obj)->SetControllerType(index,
AndroidHelpers::JStringToString(env, controller_type));
HostDisplay* display = AndroidHelpers::GetNativeClass(env, obj)->GetDisplay();
if (!display)
return;
// Technically a race, but shouldn't cause any issues.
display->SetMousePosition(positionX, positionY);
}
DEFINE_JNI_ARGS_METHOD(void, AndroidHostInterface_setControllerButtonState, jobject obj, jint index, jint button_code,

View File

@ -53,7 +53,6 @@ public:
void SurfaceChanged(ANativeWindow* surface, int format, int width, int height);
void SetDisplayAlignment(HostDisplay::Alignment alignment);
void SetControllerType(u32 index, std::string_view type_name);
void SetControllerButtonState(u32 index, s32 button_code, bool pressed);
void SetControllerAxisState(u32 index, s32 button_code, float value);
void HandleControllerButtonEvent(u32 controller_index, u32 button_index, bool pressed);

View File

@ -67,13 +67,12 @@ public class AndroidHostInterface {
public native void surfaceChanged(Surface surface, int format, int width, int height);
// TODO: Find a better place for this.
public native void setControllerType(int index, String typeName);
public native void setControllerButtonState(int index, int buttonCode, boolean pressed);
public native void setControllerAxisState(int index, int axisCode, float value);
public native void setMousePosition(int positionX, int positionY);
public static native int getControllerButtonCode(String controllerType, String buttonName);
public static native int getControllerAxisCode(String controllerType, String axisName);

View File

@ -36,6 +36,7 @@ public class TouchscreenControllerView extends FrameLayout {
private ArrayList<TouchscreenControllerButtonView> mButtonViews = new ArrayList<>();
private ArrayList<TouchscreenControllerAxisView> mAxisViews = new ArrayList<>();
private TouchscreenControllerDPadView mDPadView = null;
private int mPointerButtonCode = -1;
private boolean mHapticFeedback;
private String mLayoutOrientation;
private boolean mEditingLayout = false;
@ -223,6 +224,7 @@ public class TouchscreenControllerView extends FrameLayout {
removeAllViews();
LayoutInflater inflater = LayoutInflater.from(getContext());
String pointerButtonName = null;
switch (viewType) {
case "digital":
mMainView = inflater.inflate(R.layout.layout_touchscreen_controller_digital, this, true);
@ -236,6 +238,11 @@ public class TouchscreenControllerView extends FrameLayout {
mMainView = inflater.inflate(R.layout.layout_touchscreen_controller_analog_sticks, this, true);
break;
case "lightgun":
mMainView = inflater.inflate(R.layout.layout_touchscreen_controller_lightgun, this, true);
pointerButtonName = "Trigger";
break;
case "none":
default:
mMainView = null;
@ -276,6 +283,11 @@ public class TouchscreenControllerView extends FrameLayout {
linkHotkeyButton(mMainView, R.id.controller_button_analog, "AnalogToggle",
TouchscreenControllerButtonView.Hotkey.ANALOG_TOGGLE, false);
linkButton(mMainView, R.id.controller_button_a, "AButton", "A", true, true);
linkButton(mMainView, R.id.controller_button_b, "BButton", "B", true, true);
if (pointerButtonName != null)
linkPointer(pointerButtonName);
reloadButtonSettings();
updateOpacity();
requestLayout();
@ -371,6 +383,12 @@ public class TouchscreenControllerView extends FrameLayout {
mButtonViews.add(buttonView);
}
private boolean linkPointer(String buttonName) {
mPointerButtonCode = AndroidHostInterface.getInstance().getControllerButtonCode(mControllerType, buttonName);
Log.i("TouchscreenController", String.format("Pointer -> %s,%d", buttonName, mPointerButtonCode));
return (mPointerButtonCode >= 0);
}
private int dpToPixels(float dp) {
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()));
}
@ -570,6 +588,18 @@ public class TouchscreenControllerView extends FrameLayout {
mDPadView.setUnpressed();
}
if (mPointerButtonCode >= 0 && pointerCount > 0) {
if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
AndroidHostInterface.getInstance().setControllerButtonState(mControllerIndex,
mPointerButtonCode, true);
}
final int pointerId = event.getPointerId(0);
AndroidHostInterface.getInstance().setMousePosition(
(int)event.getX(pointerId),
(int)event.getY(pointerId));
}
return true;
}
@ -592,6 +622,11 @@ public class TouchscreenControllerView extends FrameLayout {
if (mDPadView != null)
mDPadView.setUnpressed();
if (mPointerButtonCode >= 0) {
AndroidHostInterface.getInstance().setControllerButtonState(
mControllerIndex, mPointerButtonCode, false);
}
return true;
}

View File

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M99.279,49.946A49.271,49.236 0,0 1,50.009 99.182,49.271 49.236,0 0,1 0.738,49.946 49.271,49.236 0,0 1,50.009 0.711,49.271 49.236,0 0,1 99.279,49.946Z"
android:strokeWidth="1.5"
android:fillColor="#000000"
android:strokeColor="#c8c8c8"
android:fillType="evenOdd"
android:fillAlpha="0"/>
<path
android:pathData="m61.587,68.222 l-4.369,-11.227h-14.376l-4.318,11.227h-4.623l14.173,-36.424h4.115l14.122,36.424zM55.846,52.931 L51.782,41.958q-0.152,-0.406 -0.508,-1.473 -0.356,-1.067 -0.711,-2.184 -0.305,-1.168 -0.508,-1.778 -0.356,1.575 -0.813,3.099 -0.457,1.473 -0.762,2.337l-4.115,10.973z"
android:fillColor="#c8c8c8"
android:strokeColor="#00000000"/>
</vector>

View File

@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M99.279,49.946A49.271,49.236 0,0 1,50.009 99.182,49.271 49.236,0 0,1 0.738,49.946 49.271,49.236 0,0 1,50.009 0.711,49.271 49.236,0 0,1 99.279,49.946Z"
android:strokeWidth="1.5"
android:fillColor="#969696"
android:strokeColor="#c8c8c8"
android:fillType="evenOdd"/>
<path
android:pathData="m61.587,68.222 l-4.369,-11.227h-14.376l-4.318,11.227h-4.623l14.173,-36.424h4.115l14.122,36.424zM55.846,52.931 L51.782,41.958q-0.152,-0.406 -0.508,-1.473 -0.356,-1.067 -0.711,-2.184 -0.305,-1.168 -0.508,-1.778 -0.356,1.575 -0.813,3.099 -0.457,1.473 -0.762,2.337l-4.115,10.973z"
android:fillColor="#c8c8c8"
android:strokeColor="#00000000"/>
</vector>

View File

@ -0,0 +1,17 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M99.279,49.946A49.271,49.236 0,0 1,50.009 99.182,49.271 49.236,0 0,1 0.738,49.946 49.271,49.236 0,0 1,50.009 0.711,49.271 49.236,0 0,1 99.279,49.946Z"
android:strokeWidth="1.5"
android:fillColor="#000000"
android:strokeColor="#c8c8c8"
android:fillType="evenOdd"
android:fillAlpha="0"/>
<path
android:pathData="m37.431,31.811h10.363q6.807,0 10.262,2.032 3.505,1.981 3.505,6.96 0,3.2 -1.778,5.334 -1.778,2.083 -5.131,2.692v0.254q2.286,0.356 4.115,1.321 1.88,0.965 2.946,2.743 1.067,1.778 1.067,4.623 0,4.928 -3.404,7.62 -3.353,2.692 -9.195,2.692h-12.751zM42.003,47.254h6.706q4.674,0 6.401,-1.473 1.727,-1.524 1.727,-4.47 0,-2.997 -2.134,-4.267 -2.083,-1.321 -6.706,-1.321h-5.994zM42.003,51.064v13.157h7.315q4.826,0 6.706,-1.88 1.88,-1.88 1.88,-4.928 0,-2.845 -1.981,-4.572 -1.93,-1.778 -6.96,-1.778z"
android:fillColor="#c8c8c8"
android:strokeColor="#00000000"/>
</vector>

View File

@ -0,0 +1,16 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="100dp"
android:height="100dp"
android:viewportWidth="100"
android:viewportHeight="100">
<path
android:pathData="M99.279,49.946A49.271,49.236 0,0 1,50.009 99.182,49.271 49.236,0 0,1 0.738,49.946 49.271,49.236 0,0 1,50.009 0.711,49.271 49.236,0 0,1 99.279,49.946Z"
android:strokeWidth="1.5"
android:fillColor="#969696"
android:strokeColor="#c8c8c8"
android:fillType="evenOdd"/>
<path
android:pathData="m37.431,31.811h10.363q6.807,0 10.262,2.032 3.505,1.981 3.505,6.96 0,3.2 -1.778,5.334 -1.778,2.083 -5.131,2.692v0.254q2.286,0.356 4.115,1.321 1.88,0.965 2.946,2.743 1.067,1.778 1.067,4.623 0,4.928 -3.404,7.62 -3.353,2.692 -9.195,2.692h-12.751zM42.003,47.254h6.706q4.674,0 6.401,-1.473 1.727,-1.524 1.727,-4.47 0,-2.997 -2.134,-4.267 -2.083,-1.321 -6.706,-1.321h-5.994zM42.003,51.064v13.157h7.315q4.826,0 6.706,-1.88 1.88,-1.88 1.88,-4.928 0,-2.845 -1.981,-4.572 -1.93,-1.778 -6.96,-1.778z"
android:fillColor="#c8c8c8"
android:strokeColor="#00000000"/>
</vector>

View File

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_a"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="30dp"
android:layout_marginBottom="30dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:pressedDrawable="@drawable/ic_controller_a_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_a_button" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_b"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginEnd="80dp"
android:layout_marginBottom="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:pressedDrawable="@drawable/ic_controller_b_button_pressed"
app:unpressedDrawable="@drawable/ic_controller_b_button" />
<com.github.stenzek.duckstation.TouchscreenControllerButtonView
android:id="@+id/controller_button_fast_forward"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_marginBottom="50dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:pressedDrawable="@drawable/ic_controller_fast_forward_pressed"
app:unpressedDrawable="@drawable/ic_controller_fast_forward" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -74,6 +74,7 @@
<item>Control Analógico (DualShock)</item>
<item>Analog Joystick</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>Sin tarjeta de memoria</item>
@ -114,6 +115,7 @@
<item>Digital Pad</item>
<item>Pad Analógico Unico</item>
<item>Pad Analógico Dual</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Nulo (Sin Salida)</item>

View File

@ -74,6 +74,7 @@
<item>Controller Analogico (DualShock)</item>
<item>Analog Joystick</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>No Memory Card</item>
@ -114,6 +115,7 @@
<item>Pad Digitale</item>
<item>Pad Analogico Singolo</item>
<item>Pad Analogico Doppio</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Null (No Output)</item>

View File

@ -74,6 +74,7 @@
<item>Analoge Controller (DualShock)</item>
<item>Analog Joystick</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>Geen Geheugenkaart</item>
@ -114,6 +115,7 @@
<item>Digitale Pad</item>
<item>Enekele Analoge Pad</item>
<item>Dubbele Analoge Pad</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Null (Geen Output)</item>

View File

@ -74,6 +74,7 @@
<item>Controle Analógico (DualShock)</item>
<item>Analog Joystick</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>Sem Cartão de Memória</item>
@ -120,6 +121,7 @@
<item>Digital D-Pad</item>
<item>1 Analógico</item>
<item>2 Analógicos</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Mudo</item>

View File

@ -74,6 +74,7 @@
<item>Аналоговый (DualShock)</item>
<item>Аналоговый джойстик</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>Без карты памяти</item>
@ -120,6 +121,7 @@
<item>Цифровой</item>
<item>Аналоговый, один джойстик</item>
<item>Аналоговый, два джойстика</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Нет (без звука)</item>

View File

@ -143,6 +143,7 @@
<item>Analog Controller (DualShock)</item>
<item>Analog Joystick</item>
<item>NeGcon</item>
<item>GunCon</item>
</string-array>
<string-array name="settings_controller_type_values">
<item>None</item>
@ -150,6 +151,7 @@
<item>AnalogController</item>
<item>AnalogJoystick</item>
<item>NeGcon</item>
<item>NamcoGunCon</item>
</string-array>
<string-array name="settings_memory_card_mode_entries">
<item>No Memory Card</item>
@ -214,12 +216,14 @@
<item>Digital Pad</item>
<item>Single Analog Pad</item>
<item>Dual Analog Pad</item>
<item>Lightgun</item>
</string-array>
<string-array name="settings_touchscreen_controller_view_values">
<item>none</item>
<item>digital</item>
<item>analog_stick</item>
<item>analog_sticks</item>
<item>lightgun</item>
</string-array>
<string-array name="settings_audio_backend_entries">
<item>Null (No Output)</item>

View File

@ -278,11 +278,13 @@ void NamcoGunCon::LoadSettings(const char* section)
}
}
#ifndef __ANDROID__
if (!m_crosshair_image.IsValid())
{
m_crosshair_image.SetPixels(Resources::CROSSHAIR_IMAGE_WIDTH, Resources::CROSSHAIR_IMAGE_HEIGHT,
Resources::CROSSHAIR_IMAGE_DATA.data());
}
#endif
m_crosshair_image_scale = g_host_interface->GetFloatSettingValue(section, "CrosshairScale", 1.0f);