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 xperia64
parent d99271c3c6
commit 037178fae1
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,60 +440,64 @@ 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 (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { if (EmulationMenuSettings.getDpadSlideEnable() ||
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN ||
NativeLibrary.ButtonState.PRESSED); (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_POINTER_DOWN) {
up = true; if (AxisY < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
} else { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0), NativeLibrary.ButtonState.PRESSED);
NativeLibrary.ButtonState.RELEASED); up = true;
} } else {
if (AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1), NativeLibrary.ButtonState.RELEASED);
NativeLibrary.ButtonState.PRESSED); }
down = true; if (AxisY > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
} else { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1), NativeLibrary.ButtonState.PRESSED);
NativeLibrary.ButtonState.RELEASED); down = true;
} } else {
if (AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(1),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2), NativeLibrary.ButtonState.RELEASED);
NativeLibrary.ButtonState.PRESSED); }
left = true; if (AxisX < -InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
} else { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2), NativeLibrary.ButtonState.PRESSED);
NativeLibrary.ButtonState.RELEASED); left = true;
} } else {
if (AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(2),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3), NativeLibrary.ButtonState.RELEASED);
NativeLibrary.ButtonState.PRESSED); }
right = true; if (AxisX > InputOverlayDrawableDpad.VIRT_AXIS_DEADZONE) {
} else { NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3),
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3), NativeLibrary.ButtonState.PRESSED);
NativeLibrary.ButtonState.RELEASED); right = true;
} } else {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(3),
NativeLibrary.ButtonState.RELEASED);
}
// Set state // Set state
if (up) { if (up) {
if (left) if (left)
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_LEFT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_LEFT);
else if (right) else if (right)
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_RIGHT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP_RIGHT);
else else
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_UP);
} else if (down) { } else if (down) {
if (left) if (left)
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_LEFT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_LEFT);
else if (right) else if (right)
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_RIGHT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN_RIGHT);
else else
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_DOWN);
} else if (left) { } else if (left) {
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_LEFT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_LEFT);
} else if (right) { } else if (right) {
dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_RIGHT); dpad.setState(InputOverlayDrawableDpad.STATE_PRESSED_RIGHT);
} else { } else {
dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT); dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
}
} }
} }
} }

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>