Commit 0c45cc7d authored by TwistedUmbrella's avatar TwistedUmbrella
Browse files

Add compatibility code to support unidentifiable controllers

parent 9fa119a9
......@@ -65,6 +65,18 @@
android:layout_height="wrap_content" />
</LinearLayout>
</TableRow>
<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/buttonKeycodeEditor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:ems="8"
android:text="@string/menu_edit_keycodes" />
</TableRow>
</TableLayout>
<TableLayout
......@@ -252,17 +264,6 @@
android:text="@string/remove" />
</LinearLayout>
</TableRow>
<TableRow android:gravity="center_vertical" >
<Button
android:id="@+id/buttonKeycodeEditor"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:layout_weight="1"
android:ems="8"
android:text="@string/menu_edit_keycodes" />
</TableRow>
</TableLayout>
</LinearLayout>
......
......@@ -44,7 +44,7 @@
<string name="controller_already_in_use">This controller is already in use!</string>
<string name="modified_layout">Enable Custom Key Layout</string>
<string name="menu_edit_keycodes">Edit Key Bindings</string>
<string name="menu_edit_keycodes">Custom Button Layout</string>
<string name="map_keycode_title">Modify Controller</string>
<string name="map_keycode_message">Press the new controller button for %1$s</string>
......
package com.reicast.emulator;
import java.util.Arrays;
import java.util.HashMap;
// Keeping a reference just in case it's needed
......@@ -40,6 +41,7 @@ public class GL2JNIActivity extends Activity {
private SharedPreferences prefs;
static boolean[] custom = { false, false, false, false }, xbox = { false,
false, false, false }, nVidia = { false, false, false, false };
int[] name = { -1, -1, -1, -1 };
float[] globalLS_X = new float[4], globalLS_Y = new float[4],
previousLS_X = new float[4], previousLS_Y = new float[4];
......@@ -301,6 +303,22 @@ public class GL2JNIActivity extends Activity {
}
} else {
if (prefs.getBoolean("modified_key_layout", false)) {
for (int i = 0; i < 4; i++) {
String[] players = getResources().getStringArray(R.array.controllers);
String id = players[i].substring(
players[i].lastIndexOf(" "), players[i].length());
name[i] = prefs.getInt("controller" + id, -1);
if (name[i] != -1) {
map[i] = setModifiedKeys(i);
custom[i] = true;
}
globalLS_X[i] = previousLS_X[i] = 0.0f;
globalLS_Y[i] = previousLS_Y[i] = 0.0f;
}
}
}
// When viewing a resource, pass its URI to the native code for opening
......@@ -437,46 +455,52 @@ public class GL2JNIActivity extends Activity {
*/
boolean handle_key(Integer playerNum, int kc, boolean down) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
if (playerNum == null)
return false;
if (playerNum == null || playerNum == -1)
return false;
if (!moga.isActive[playerNum]) {
if (!moga.isActive[playerNum]) {
boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
boolean rav = false;
for (int i = 0; i < map[playerNum].length; i += 2) {
if (map[playerNum][i + 0] == kc) {
if (down)
GL2JNIView.kcode_raw[playerNum] &= ~map[playerNum][i + 1];
else
GL2JNIView.kcode_raw[playerNum] |= map[playerNum][i + 1];
rav = true;
break;
}
rav = true;
break;
}
}
return rav;
return rav;
} else {
return true;
}
} else {
return false;
return true;
}
}
public boolean onKeyUp(int keyCode, KeyEvent event) {
Integer playerNum = deviceDescriptor_PlayerNum
Integer playerNum = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
} else {
playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
}
return handle_key(playerNum, keyCode, false)
|| super.onKeyUp(keyCode, event);
}
public boolean onKeyDown(int keyCode, KeyEvent event) {
Integer playerNum = deviceDescriptor_PlayerNum
Integer playerNum = 0;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
playerNum = deviceDescriptor_PlayerNum
.get(deviceId_deviceDescriptor.get(event.getDeviceId()));
} else {
playerNum = Arrays.asList(name).indexOf(event.getDeviceId());
}
if (handle_key(playerNum, keyCode, true)) {
if (playerNum == 0)
......
......@@ -80,6 +80,18 @@ public class InputFragment extends Fragment {
}
switchTouchVibrationEnabled.setOnCheckedChangeListener(touch_vibration);
Button buttonKeycodeEditor = (Button) getView().findViewById(
R.id.buttonKeycodeEditor);
buttonKeycodeEditor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InputModFragment inputModFrag = new InputModFragment();
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, inputModFrag,
"INPUT_MOD_FRAG").addToBackStack(null).commit();
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
Button buttonSelectControllerPlayer1 = (Button) getView()
......@@ -153,22 +165,6 @@ public class InputFragment extends Fragment {
}
updateVibration();
Button buttonKeycodeEditor = (Button) getView().findViewById(
R.id.buttonKeycodeEditor);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD) {
buttonKeycodeEditor.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
InputModFragment inputModFrag = new InputModFragment();
getActivity().getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, inputModFrag,
"INPUT_MOD_FRAG").addToBackStack(null).commit();
}
});
} else {
buttonKeycodeEditor.setVisibility(View.GONE);
}
}
private void updateVibration() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment