Implemented switch for sliding finger across dpad + fixed sensitivity

This commit is contained in:
Nathan Lepori 2020-07-12 11:11:42 +02:00 committed by bunnei
parent aa997054e4
commit 96d1fd4f10
6 changed files with 86 additions and 57 deletions

View File

@ -68,6 +68,7 @@ public final class EmulationActivity extends AppCompatActivity {
public static final int MENU_ACTION_LOAD_AMIIBO = 13; public static final int MENU_ACTION_LOAD_AMIIBO = 13;
public static final int MENU_ACTION_REMOVE_AMIIBO = 14; public static final int MENU_ACTION_REMOVE_AMIIBO = 14;
public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 15; public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 15;
public static final int MENU_ACTION_DPAD_SLIDE_ENABLE = 16;
public static final int REQUEST_SELECT_AMIIBO = 2; public static final int REQUEST_SELECT_AMIIBO = 2;
private static final int EMULATION_RUNNING_NOTIFICATION = 0x1000; private static final int EMULATION_RUNNING_NOTIFICATION = 0x1000;
@ -104,6 +105,8 @@ public final class EmulationActivity extends AppCompatActivity {
.append(R.id.menu_emulation_amiibo_remove, EmulationActivity.MENU_ACTION_REMOVE_AMIIBO); .append(R.id.menu_emulation_amiibo_remove, EmulationActivity.MENU_ACTION_REMOVE_AMIIBO);
buttonsActionsMap.append(R.id.menu_emulation_joystick_rel_center, buttonsActionsMap.append(R.id.menu_emulation_joystick_rel_center,
EmulationActivity.MENU_ACTION_JOYSTICK_REL_CENTER); EmulationActivity.MENU_ACTION_JOYSTICK_REL_CENTER);
buttonsActionsMap.append(R.id.menu_emulation_dpad_slide_enable,
EmulationActivity.MENU_ACTION_DPAD_SLIDE_ENABLE);
} }
private View mDecorView; private View mDecorView;
@ -292,6 +295,7 @@ public final class EmulationActivity extends AppCompatActivity {
menu.findItem(layoutOptionMenuItem).setChecked(true); menu.findItem(layoutOptionMenuItem).setChecked(true);
menu.findItem(R.id.menu_emulation_joystick_rel_center).setChecked(EmulationMenuSettings.getJoystickRelCenter()); menu.findItem(R.id.menu_emulation_joystick_rel_center).setChecked(EmulationMenuSettings.getJoystickRelCenter());
menu.findItem(R.id.menu_emulation_dpad_slide_enable).setChecked(EmulationMenuSettings.getDpadSlideEnable());
menu.findItem(R.id.menu_emulation_show_fps).setChecked(EmulationMenuSettings.getShowFps()); menu.findItem(R.id.menu_emulation_show_fps).setChecked(EmulationMenuSettings.getShowFps());
menu.findItem(R.id.menu_emulation_swap_screens).setChecked(EmulationMenuSettings.getSwapScreens()); menu.findItem(R.id.menu_emulation_swap_screens).setChecked(EmulationMenuSettings.getSwapScreens());
menu.findItem(R.id.menu_emulation_show_overlay).setChecked(EmulationMenuSettings.getShowOverlay()); menu.findItem(R.id.menu_emulation_show_overlay).setChecked(EmulationMenuSettings.getShowOverlay());
@ -395,9 +399,14 @@ public final class EmulationActivity extends AppCompatActivity {
break; break;
case MENU_ACTION_JOYSTICK_REL_CENTER: case MENU_ACTION_JOYSTICK_REL_CENTER:
final boolean isEnabled = !EmulationMenuSettings.getJoystickRelCenter(); final boolean isJoystickRelCenterEnabled = !EmulationMenuSettings.getJoystickRelCenter();
EmulationMenuSettings.setJoystickRelCenter(isEnabled); EmulationMenuSettings.setJoystickRelCenter(isJoystickRelCenterEnabled);
item.setChecked(isEnabled); item.setChecked(isJoystickRelCenterEnabled);
break;
case MENU_ACTION_DPAD_SLIDE_ENABLE:
final boolean isDpadSlideEnabled = !EmulationMenuSettings.getDpadSlideEnable();
EmulationMenuSettings.setDpadSlideEnable(isDpadSlideEnabled);
item.setChecked(isDpadSlideEnabled);
break; break;
} }

View File

@ -52,6 +52,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
// Stores the ID of the pointer that interacted with the 3DS touchscreen. // Stores the ID of the pointer that interacted with the 3DS touchscreen.
private int mTouchscreenPointerId = -1; private int mTouchscreenPointerId = -1;
/** /**
* Constructor * Constructor
* *
@ -439,6 +440,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
boolean down = false; boolean down = false;
boolean left = false; boolean left = false;
boolean right = false; boolean right = false;
if (EmulationMenuSettings.getDpadSlideEnable() ||
(event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN ||
(event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
if (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { if (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
NativeLibrary.ButtonState.PRESSED); NativeLibrary.ButtonState.PRESSED);
@ -498,6 +502,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
} }
} }
} }
}
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) { for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
joystick.TrackEvent(event); joystick.TrackEvent(event);

View File

@ -27,7 +27,7 @@ public final class InputOverlayDrawableDpad {
public static final int STATE_PRESSED_UP_RIGHT = 6; public static final int STATE_PRESSED_UP_RIGHT = 6;
public static final int STATE_PRESSED_DOWN_LEFT = 7; public static final int STATE_PRESSED_DOWN_LEFT = 7;
public static final int STATE_PRESSED_DOWN_RIGHT = 8; public static final int STATE_PRESSED_DOWN_RIGHT = 8;
public static final float VIRT_AXIS_DEADZONE = 0.2f; public static final float VIRT_AXIS_DEADZONE = 0.5f;
// The ID identifying what type of button this Drawable represents. // The ID identifying what type of button this Drawable represents.
private int[] mButtonType = new int[4]; private int[] mButtonType = new int[4];
private int mTrackId; private int mTrackId;

View File

@ -26,6 +26,16 @@ public class EmulationMenuSettings {
editor.apply(); editor.apply();
} }
public static boolean getDpadSlideEnable() {
return mPreferences.getBoolean("EmulationMenuSettings_DpadSlideEnable", true);
}
public static void setDpadSlideEnable(boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean("EmulationMenuSettings_DpadSlideEnable", value);
editor.apply();
}
public static int getLandscapeScreenLayout() { public static int getLandscapeScreenLayout() {
return mPreferences.getInt("EmulationMenuSettings_LandscapeScreenLayout", LayoutOption_MobileLandscape); return mPreferences.getInt("EmulationMenuSettings_LandscapeScreenLayout", LayoutOption_MobileLandscape);
} }

View File

@ -24,6 +24,10 @@
android:id="@+id/menu_emulation_joystick_rel_center" android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true" android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/> android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_dpad_slide_enable"
android:checkable="true"
android:title="@string/emulation_control_dpad_slide_enable" />
</group> </group>
<item <item

View File

@ -150,6 +150,7 @@
<string name="emulation_toggle_controls">Toggle Controls</string> <string name="emulation_toggle_controls">Toggle Controls</string>
<string name="emulation_control_scale">Adjust Scale</string> <string name="emulation_control_scale">Adjust Scale</string>
<string name="emulation_control_joystick_rel_center">Relative Stick Center</string> <string name="emulation_control_joystick_rel_center">Relative Stick Center</string>
<string name="emulation_control_dpad_slide_enable">Enable DPad Sliding</string>
<string name="emulation_open_settings">Open Settings</string> <string name="emulation_open_settings">Open Settings</string>
<string name="emulation_switch_screen_layout">Landscape Screen Layout</string> <string name="emulation_switch_screen_layout">Landscape Screen Layout</string>
<string name="emulation_screen_layout_landscape">Default</string> <string name="emulation_screen_layout_landscape">Default</string>