Add support for configuring controllers on a per-player basis
This commit is contained in:
parent
dd1d1ddcaf
commit
6ae54f5280
|
@ -14,6 +14,21 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:stretchColumns="*" >
|
android:stretchColumns="*" >
|
||||||
|
|
||||||
|
<TableRow
|
||||||
|
android:layout_marginTop="25dp"
|
||||||
|
android:gravity="center_vertical" >
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/player_spinner"
|
||||||
|
android:layout_width="0dip"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:ems="10" >
|
||||||
|
|
||||||
|
<requestFocus />
|
||||||
|
</Spinner>
|
||||||
|
</TableRow>
|
||||||
|
|
||||||
<TableRow
|
<TableRow
|
||||||
android:layout_marginTop="25dp"
|
android:layout_marginTop="25dp"
|
||||||
android:gravity="center_vertical" >
|
android:gravity="center_vertical" >
|
||||||
|
|
|
@ -54,6 +54,13 @@
|
||||||
<string name="about_title">About reicast</string>
|
<string name="about_title">About reicast</string>
|
||||||
<string name="about_text">reicast is a dreamcast emulator\n\nVersion: %1$s\n\n</string>
|
<string name="about_text">reicast is a dreamcast emulator\n\nVersion: %1$s\n\n</string>
|
||||||
|
|
||||||
|
<string-array name="controllers">
|
||||||
|
<item>Controller A</item>
|
||||||
|
<item>Controller B</item>
|
||||||
|
<item>Controller C</item>
|
||||||
|
<item>Controller D</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
<string-array name="images">
|
<string-array name="images">
|
||||||
<item>cdi</item>
|
<item>cdi</item>
|
||||||
<item>chd</item>
|
<item>chd</item>
|
||||||
|
|
|
@ -216,7 +216,7 @@ public class GL2JNIActivity extends Activity {
|
||||||
if (playerNum != null) {
|
if (playerNum != null) {
|
||||||
|
|
||||||
if (prefs.getBoolean("modified_key_layout", false)) {
|
if (prefs.getBoolean("modified_key_layout", false)) {
|
||||||
map[playerNum] = setModifiedKeys();
|
map[playerNum] = setModifiedKeys(playerNum);
|
||||||
} else if (InputDevice.getDevice(joys[i]).getName()
|
} else if (InputDevice.getDevice(joys[i]).getName()
|
||||||
.equals("Sony PLAYSTATION(R)3 Controller")) {
|
.equals("Sony PLAYSTATION(R)3 Controller")) {
|
||||||
map[playerNum] = new int[] {
|
map[playerNum] = new int[] {
|
||||||
|
@ -311,19 +311,20 @@ public class GL2JNIActivity extends Activity {
|
||||||
"Press the back button for a menu", Toast.LENGTH_SHORT).show();
|
"Press the back button for a menu", Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] setModifiedKeys() {
|
private int[] setModifiedKeys(int player) {
|
||||||
|
String id = String.valueOf(player);
|
||||||
return new int[] {
|
return new int[] {
|
||||||
prefs.getInt("a_button", OuyaController.BUTTON_O), key_CONT_A,
|
prefs.getInt("a_button" + id, OuyaController.BUTTON_O), key_CONT_A,
|
||||||
prefs.getInt("b_button", OuyaController.BUTTON_A), key_CONT_B,
|
prefs.getInt("b_button" + id, OuyaController.BUTTON_A), key_CONT_B,
|
||||||
prefs.getInt("x_button", OuyaController.BUTTON_U), key_CONT_X,
|
prefs.getInt("x_button" + id, OuyaController.BUTTON_U), key_CONT_X,
|
||||||
prefs.getInt("y_button", OuyaController.BUTTON_Y), key_CONT_Y,
|
prefs.getInt("y_button" + id, OuyaController.BUTTON_Y), key_CONT_Y,
|
||||||
|
|
||||||
prefs.getInt("dpad_up", OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
|
prefs.getInt("dpad_up" + id, OuyaController.BUTTON_DPAD_UP), key_CONT_DPAD_UP,
|
||||||
prefs.getInt("dpad_down", OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
|
prefs.getInt("dpad_down" + id, OuyaController.BUTTON_DPAD_DOWN), key_CONT_DPAD_DOWN,
|
||||||
prefs.getInt("dpad_left", OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
|
prefs.getInt("dpad_left" + id, OuyaController.BUTTON_DPAD_LEFT), key_CONT_DPAD_LEFT,
|
||||||
prefs.getInt("dpad_right", OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
|
prefs.getInt("dpad_right" + id, OuyaController.BUTTON_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
|
||||||
|
|
||||||
prefs.getInt("start_button", OuyaController.BUTTON_MENU), key_CONT_START,
|
prefs.getInt("start_button" + id, OuyaController.BUTTON_MENU), key_CONT_START,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,9 +14,13 @@ import android.view.KeyEvent;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.AdapterView;
|
||||||
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.Spinner;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.AdapterView.OnItemSelectedListener;
|
||||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||||
|
|
||||||
public class InputModFragment extends Fragment {
|
public class InputModFragment extends Fragment {
|
||||||
|
@ -24,6 +28,7 @@ public class InputModFragment extends Fragment {
|
||||||
private Activity parentActivity;
|
private Activity parentActivity;
|
||||||
private SharedPreferences mPrefs;
|
private SharedPreferences mPrefs;
|
||||||
private Switch switchModifiedLayoutEnabled;
|
private Switch switchModifiedLayoutEnabled;
|
||||||
|
private String player;
|
||||||
|
|
||||||
// Container Activity must implement this interface
|
// Container Activity must implement this interface
|
||||||
public interface OnClickListener {
|
public interface OnClickListener {
|
||||||
|
@ -44,6 +49,30 @@ public class InputModFragment extends Fragment {
|
||||||
mPrefs = PreferenceManager
|
mPrefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(parentActivity);
|
.getDefaultSharedPreferences(parentActivity);
|
||||||
|
|
||||||
|
String[] controllers = parentActivity.getResources().getStringArray(R.array.controllers);
|
||||||
|
|
||||||
|
Spinner player_spnr = (Spinner) getView().findViewById(
|
||||||
|
R.id.player_spinner);
|
||||||
|
ArrayAdapter<String> localeAdapter = new ArrayAdapter<String>(
|
||||||
|
parentActivity, android.R.layout.simple_spinner_item, controllers);
|
||||||
|
localeAdapter
|
||||||
|
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
|
player_spnr.setAdapter(localeAdapter);
|
||||||
|
|
||||||
|
player_spnr.setOnItemSelectedListener(new OnItemSelectedListener() {
|
||||||
|
|
||||||
|
public void onItemSelected(AdapterView<?> parent, View view,
|
||||||
|
int pos, long id) {
|
||||||
|
String selection = parent.getItemAtPosition(pos).toString();
|
||||||
|
player = selection.substring(selection.lastIndexOf(" "), selection.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onNothingSelected(AdapterView<?> arg0) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
|
OnCheckedChangeListener modified_layout = new OnCheckedChangeListener() {
|
||||||
public void onCheckedChanged(CompoundButton buttonView,
|
public void onCheckedChanged(CompoundButton buttonView,
|
||||||
boolean isChecked) {
|
boolean isChecked) {
|
||||||
|
|
|
@ -98,7 +98,6 @@ public class MOGAInput
|
||||||
protected void onCreate(Activity act)
|
protected void onCreate(Activity act)
|
||||||
{
|
{
|
||||||
this.act = act;
|
this.act = act;
|
||||||
setModifiedKeys();
|
|
||||||
|
|
||||||
mController = Controller.getInstance(act);
|
mController = Controller.getInstance(act);
|
||||||
mController.init();
|
mController.init();
|
||||||
|
@ -143,22 +142,23 @@ public class MOGAInput
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setModifiedKeys() {
|
private void setModifiedKeys(int player) {
|
||||||
prefs = PreferenceManager
|
prefs = PreferenceManager
|
||||||
.getDefaultSharedPreferences(act.getApplicationContext());
|
.getDefaultSharedPreferences(act.getApplicationContext());
|
||||||
if (prefs.getBoolean("modified_key_layout", false)) {
|
if (prefs.getBoolean("modified_key_layout", false)) {
|
||||||
|
String id = String.valueOf(player);
|
||||||
map = new int[] {
|
map = new int[] {
|
||||||
prefs.getInt("a_button", KeyEvent.KEYCODE_BUTTON_A), key_CONT_A,
|
prefs.getInt("a_button" + id, KeyEvent.KEYCODE_BUTTON_A), key_CONT_A,
|
||||||
prefs.getInt("b_button", KeyEvent.KEYCODE_BUTTON_B), key_CONT_B,
|
prefs.getInt("b_button" + id, KeyEvent.KEYCODE_BUTTON_B), key_CONT_B,
|
||||||
prefs.getInt("x_button", KeyEvent.KEYCODE_BUTTON_X), key_CONT_X,
|
prefs.getInt("x_button" + id, KeyEvent.KEYCODE_BUTTON_X), key_CONT_X,
|
||||||
prefs.getInt("y_button", KeyEvent.KEYCODE_BUTTON_Y), key_CONT_Y,
|
prefs.getInt("y_button" + id, KeyEvent.KEYCODE_BUTTON_Y), key_CONT_Y,
|
||||||
|
|
||||||
prefs.getInt("dpad_up", KeyEvent.KEYCODE_DPAD_UP), key_CONT_DPAD_UP,
|
prefs.getInt("dpad_up" + id, KeyEvent.KEYCODE_DPAD_UP), key_CONT_DPAD_UP,
|
||||||
prefs.getInt("dpad_down", KeyEvent.KEYCODE_DPAD_DOWN), key_CONT_DPAD_DOWN,
|
prefs.getInt("dpad_down" + id, KeyEvent.KEYCODE_DPAD_DOWN), key_CONT_DPAD_DOWN,
|
||||||
prefs.getInt("dpad_left", KeyEvent.KEYCODE_DPAD_LEFT), key_CONT_DPAD_LEFT,
|
prefs.getInt("dpad_left" + id, KeyEvent.KEYCODE_DPAD_LEFT), key_CONT_DPAD_LEFT,
|
||||||
prefs.getInt("dpad_right", KeyEvent.KEYCODE_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
|
prefs.getInt("dpad_right" + id, KeyEvent.KEYCODE_DPAD_RIGHT), key_CONT_DPAD_RIGHT,
|
||||||
|
|
||||||
prefs.getInt("start_button", KeyEvent.KEYCODE_BUTTON_START), key_CONT_START,
|
prefs.getInt("start_button" + id, KeyEvent.KEYCODE_BUTTON_START), key_CONT_START,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -233,10 +233,12 @@ public class MOGAInput
|
||||||
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
|
if (mControllerVersion == Controller.ACTION_VERSION_MOGAPRO) {
|
||||||
isActive[playerNum] = true;
|
isActive[playerNum] = true;
|
||||||
isMogaPro[playerNum] = true;
|
isMogaPro[playerNum] = true;
|
||||||
|
setModifiedKeys(playerNum);
|
||||||
notify = act.getApplicationContext().getString(R.string.moga_pro_connect);
|
notify = act.getApplicationContext().getString(R.string.moga_pro_connect);
|
||||||
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
|
} else if (mControllerVersion == Controller.ACTION_VERSION_MOGA) {
|
||||||
isActive[playerNum] = true;
|
isActive[playerNum] = true;
|
||||||
isMogaPro[playerNum] = false;
|
isMogaPro[playerNum] = false;
|
||||||
|
setModifiedKeys(playerNum);
|
||||||
notify = act.getApplicationContext().getString(R.string.moga_connect);
|
notify = act.getApplicationContext().getString(R.string.moga_connect);
|
||||||
}
|
}
|
||||||
if (notify != null && !notify.equals(null)) {
|
if (notify != null && !notify.equals(null)) {
|
||||||
|
|
Loading…
Reference in New Issue