Android: Support no right stick function, Fix L / R

This commit is contained in:
Ender's Games 2018-08-24 09:40:43 -04:00
parent e4f934c581
commit dae71628a5
8 changed files with 339 additions and 319 deletions

View File

@ -350,28 +350,27 @@ public class GL2JNIActivity extends Activity {
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
if (prefs.getInt(Gamepad.pref_js_rstick + pad.portId[playerNum], 0) == 1) {
float R2Sum = RS_Y > 0.25 ? RS_Y : R2;
GL2JNIView.rt[playerNum] = (int) (R2Sum * 255);
float L2Sum = RS_Y < -0.25 ? -(RS_Y) : L2;
GL2JNIView.lt[playerNum] = (int) (L2Sum * 255);
} else {
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
if (prefs.getBoolean(Gamepad.pref_js_rbuttons + pad.portId[playerNum], true)) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]){
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
} else if (L2 == 0 && R2 ==0) {
if (RS_Y > 0.25) {
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
} else if (RS_Y < 0.25) {
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
if (prefs.getInt(Gamepad.pref_js_rstick + pad.portId[playerNum], 0) == 2) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]) {
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
}
}

View File

@ -350,28 +350,27 @@ public class GL2JNINative extends NativeActivity {
GL2JNIView.jx[playerNum] = (int) (LS_X * 126);
GL2JNIView.jy[playerNum] = (int) (LS_Y * 126);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
if (prefs.getInt(Gamepad.pref_js_rstick + pad.portId[playerNum], 0) == 1) {
float R2Sum = R2 > 0.25 ? R2 : RS_Y;
GL2JNIView.rt[playerNum] = (int) (R2Sum * 255);
float L2Sum = L2 > 0.25 ? L2 : -(RS_Y);
GL2JNIView.lt[playerNum] = (int) (L2Sum * 255);
} else {
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
if (prefs.getBoolean(Gamepad.pref_js_rbuttons + pad.portId[playerNum], true)) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]){
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
} else if (L2 == 0 && R2 ==0) {
if (RS_Y > 0.25) {
GL2JNIView.rt[playerNum] = (int) (RS_Y * 255);
GL2JNIView.lt[playerNum] = (int) (L2 * 255);
} else if (RS_Y < 0.25) {
GL2JNIView.rt[playerNum] = (int) (R2 * 255);
GL2JNIView.lt[playerNum] = (int) (-(RS_Y) * 255);
if (prefs.getInt(Gamepad.pref_js_rstick + pad.portId[playerNum], 0) == 2) {
if (RS_Y > 0.25) {
handle_key(playerNum, pad.map[playerNum][0]/* A */, true);
pad.wasKeyStick[playerNum] = true;
} else if (RS_Y < 0.25) {
handle_key(playerNum, pad.map[playerNum][1]/* B */, true);
pad.wasKeyStick[playerNum] = true;
} else if (pad.wasKeyStick[playerNum]) {
handle_key(playerNum, pad.map[playerNum][0], false);
handle_key(playerNum, pad.map[playerNum][1], false);
pad.wasKeyStick[playerNum] = false;
}
}
}

View File

@ -44,10 +44,10 @@ public class InputModFragment extends Fragment {
private SharedPreferences mPrefs;
private CompoundButton switchJoystickDpadEnabled;
private CompoundButton switchRightStickLREnabled;
private CompoundButton switchModifiedLayoutEnabled;
private CompoundButton switchCompatibilityEnabled;
private Spinner right_stick_spinner;
private CompoundButton switchJoystickDpadEnabled;
private TextView a_button_text;
private TextView b_button_text;
@ -95,8 +95,6 @@ public class InputModFragment extends Fragment {
switchJoystickDpadEnabled = (CompoundButton) getView().findViewById(
R.id.switchJoystickDpadEnabled);
switchRightStickLREnabled = (CompoundButton) getView().findViewById(
R.id.switchRightStickLREnabled);
switchModifiedLayoutEnabled = (CompoundButton) getView().findViewById(
R.id.switchModifiedLayoutEnabled);
switchCompatibilityEnabled = (CompoundButton) getView().findViewById(
@ -111,14 +109,23 @@ public class InputModFragment extends Fragment {
switchJoystickDpadEnabled.setOnCheckedChangeListener(joystick_mode);
OnCheckedChangeListener rstick_mode = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
mPrefs.edit().putBoolean(Gamepad.pref_js_rbuttons + player, isChecked).apply();
}
};
String[] rstick = getResources().getStringArray(R.array.right_stick);
right_stick_spinner = (Spinner) getView().findViewById(R.id.rstick_spinner);
ArrayAdapter<String> rstickAdapter = new ArrayAdapter<String>(
getActivity(), android.R.layout.simple_spinner_item, rstick);
rstickAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
right_stick_spinner.setAdapter(rstickAdapter);
right_stick_spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
switchRightStickLREnabled.setOnCheckedChangeListener(rstick_mode);
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
mPrefs.edit().putInt(Gamepad.pref_js_rstick + player, pos).apply();
}
public void onNothingSelected(AdapterView<?> arg0) {
}
});
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,
@ -307,7 +314,7 @@ public class InputModFragment extends Fragment {
});
joystick_x_text = (TextView) getView().findViewById(
R.id.joystick_x_key);
R.id.joystick_x_axis);
Button joystick_x = (Button) getView().findViewById(
R.id.joystick_x_edit);
joystick_x.setOnClickListener(new View.OnClickListener() {
@ -324,7 +331,7 @@ public class InputModFragment extends Fragment {
});
joystick_y_text = (TextView) getView().findViewById(
R.id.joystick_y_key);
R.id.joystick_y_axis);
Button joystick_y = (Button) getView().findViewById(
R.id.joystick_y_edit);
joystick_y.setOnClickListener(new View.OnClickListener() {
@ -608,8 +615,7 @@ public class InputModFragment extends Fragment {
private void updateController(String player) {
switchJoystickDpadEnabled.setChecked(mPrefs.getBoolean(
Gamepad.pref_js_merged + player, false));
switchRightStickLREnabled.setChecked(mPrefs.getBoolean(
Gamepad.pref_js_rbuttons + player, true));
right_stick_spinner.setSelection(mPrefs.getInt(Gamepad.pref_js_rstick + player, 0));
switchModifiedLayoutEnabled.setChecked(mPrefs.getBoolean(
Gamepad.pref_js_modified + player, false));
switchCompatibilityEnabled.setChecked(mPrefs.getBoolean(

View File

@ -32,7 +32,7 @@ public class Gamepad {
public static final String pref_js_modified = "modified_key_layout";
public static final String pref_js_compat = "controller_compat";
public static final String pref_js_merged = "merged_joystick";
public static final String pref_js_rbuttons = "right_buttons";
public static final String pref_js_rstick = "right_joystick";
public static final String pref_button_a = "a_button";
public static final String pref_button_b = "b_button";

View File

@ -84,60 +84,6 @@
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/rstick_mode" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Switch
android:id="@+id/switchRightStickLREnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/joystick_layout" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Switch
android:id="@+id/switchJoystickDpadEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
@ -444,6 +390,141 @@
</LinearLayout>
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:text="@string/rstick_mode" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Spinner
android:id="@+id/rstick_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:entries="@array/right_stick" >
<requestFocus />
</Spinner>
</LinearLayout>
</LinearLayout>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/joystick_layout" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Switch
android:id="@+id/switchJoystickDpadEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_x_axis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_x_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_y_axis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_y" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_y_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
@ -596,82 +677,6 @@
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_x_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_x_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_y_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_y" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_y_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >

View File

@ -84,60 +84,6 @@
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/rstick_mode" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Checkbox
android:id="@+id/switchRightStickLREnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/joystick_layout" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Checkbox
android:id="@+id/switchJoystickDpadEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
@ -444,6 +390,141 @@
</LinearLayout>
</TableRow>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:layout_marginTop="20dp"
android:orientation="vertical" >
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:text="@string/rstick_mode" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Spinner
android:id="@+id/rstick_spinner"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:entries="@array/right_stick" >
<requestFocus />
</Spinner>
</LinearLayout>
</LinearLayout>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:ems="10"
android:gravity="center_vertical|left"
android:text="@string/joystick_layout" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Checkbox
android:id="@+id/switchJoystickDpadEnabled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_x_axis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_x_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_y_axis"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_y" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_y_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
@ -596,82 +677,6 @@
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_x_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_x" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_x_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_x"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >
<TextView
android:id="@+id/joystick_y_key"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:ems="10"
android:text="@string/joystick_y" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="right"
android:orientation="vertical" >
<Button
android:id="@+id/joystick_y_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/select" />
<Button
android:id="@+id/remove_joystick_y"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="6"
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow
android:layout_marginTop="25dp"
android:gravity="center_vertical" >

View File

@ -70,4 +70,10 @@
<item>Purupuru</item>
</string-array>
<string-array name="right_stick">
<item>None</item>
<item>L / R</item>
<item>A / B</item>
</string-array>
</resources>

View File

@ -91,7 +91,7 @@
<string name="select_controller_title">Select Controller</string>
<string name="select_controller_message">Press any button on the controller %1$s to assign to port</string>
<string name="controller_already_in_use">This controller is already in use!</string>
<string name="rstick_mode">Right Stick: On - L/R, Off - A/B</string>
<string name="rstick_mode">Right Stick Mode</string>
<string name="joystick_layout">Use Joystick For D-Pad Input</string>
<string name="modified_layout">Enable Custom Key Layout</string>
<string name="controller_compat">Enable Compatibility Mode</string>