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 0507234077
commit ab285bb6bb
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_REMOVE_AMIIBO = 14;
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;
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);
buttonsActionsMap.append(R.id.menu_emulation_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;
@ -292,6 +295,7 @@ public final class EmulationActivity extends AppCompatActivity {
menu.findItem(layoutOptionMenuItem).setChecked(true);
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_swap_screens).setChecked(EmulationMenuSettings.getSwapScreens());
menu.findItem(R.id.menu_emulation_show_overlay).setChecked(EmulationMenuSettings.getShowOverlay());
@ -395,9 +399,14 @@ public final class EmulationActivity extends AppCompatActivity {
break;
case MENU_ACTION_JOYSTICK_REL_CENTER:
final boolean isEnabled = !EmulationMenuSettings.getJoystickRelCenter();
EmulationMenuSettings.setJoystickRelCenter(isEnabled);
item.setChecked(isEnabled);
final boolean isJoystickRelCenterEnabled = !EmulationMenuSettings.getJoystickRelCenter();
EmulationMenuSettings.setJoystickRelCenter(isJoystickRelCenterEnabled);
item.setChecked(isJoystickRelCenterEnabled);
break;
case MENU_ACTION_DPAD_SLIDE_ENABLE:
final boolean isDpadSlideEnabled = !EmulationMenuSettings.getDpadSlideEnable();
EmulationMenuSettings.setDpadSlideEnable(isDpadSlideEnabled);
item.setChecked(isDpadSlideEnabled);
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.
private int mTouchscreenPointerId = -1;
/**
* Constructor
*
@ -439,6 +440,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
boolean down = false;
boolean left = 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) {
NativeLibrary.onGamePadEvent(NativeLibrary.TouchScreenDevice, dpad.getId(0),
NativeLibrary.ButtonState.PRESSED);
@ -498,6 +502,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener {
}
}
}
}
for (InputOverlayDrawableJoystick joystick : overlayJoysticks) {
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_DOWN_LEFT = 7;
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.
private int[] mButtonType = new int[4];
private int mTrackId;

View File

@ -26,6 +26,16 @@ public class EmulationMenuSettings {
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() {
return mPreferences.getInt("EmulationMenuSettings_LandscapeScreenLayout", LayoutOption_MobileLandscape);
}

View File

@ -24,6 +24,10 @@
android:id="@+id/menu_emulation_joystick_rel_center"
android:checkable="true"
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>
<item

View File

@ -150,6 +150,7 @@
<string name="emulation_toggle_controls">Toggle Controls</string>
<string name="emulation_control_scale">Adjust Scale</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_switch_screen_layout">Landscape Screen Layout</string>
<string name="emulation_screen_layout_landscape">Default</string>