Skip to content

Commit

Permalink
front: Replaced InputMapPreference with InputMapActivity.
Browse files Browse the repository at this point in the history
Controller enabled/disabled is persisted as its own boolean now, rather
than being serialized with the input map. This is much more logical and
easier to maintain in the long run.

Fewer buttons/axes are mapped by default now, to minimize conflicts out
of the box.  They are
 - analog stick <-> AXIS_X and AXIS_Y
 - d-pad <-> KEY_DPAD_* (no AXIS_HAT_*, conflicts w/ Nyko PlayPad)
 - start, R, L buttons to their virtually universal keycodes

A TogglePreference was implemented.  Basically a fancier version of a
checkbox preference.  Besides the slider/toggle widget, the main
difference is that clicking on the list item in the preference menu
does not do anything (checkbox preference it toggles the check state).
This is so that you can handle the click in your own custom way, e.g.
to launch an activity like InputMapActivity.  To change widget state,
you need to click on the widget itself. This imitates the "master on/
off switch" pattern used in the Android settings:
 http://developer.android.com/design/patterns/settings.html
  • Loading branch information
littleguy77 committed Jan 21, 2013
1 parent 9c02855 commit 1b285a1
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 466 deletions.
56 changes: 40 additions & 16 deletions res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,18 @@
android:title="@string/touchpadLayout_title" />
</PreferenceScreen>

<paulscode.android.mupen64plusae.persistent.InputMapPreference
android:defaultValue="@string/inputMap_defaultOn"
<paulscode.android.mupen64plusae.persistent.TogglePreference
android:defaultValue="true"
android:icon="@drawable/ic_gamepad"
android:key="inputMap1"
android:key="inputEnabled1"
android:summary="@string/inputMap_summary"
android:title="@string/inputMap1_title" />
android:title="@string/inputMap1_title" >
<intent android:action=".input.InputMapActivity" >
<extra
android:name="paulscode.android.mupen64plusae.EXTRA_PLAYER"
android:value="1" />
</intent>
</paulscode.android.mupen64plusae.persistent.TogglePreference>

<CheckBoxPreference
android:defaultValue="true"
Expand All @@ -164,24 +170,42 @@
<PreferenceCategory
android:key="categoryMultiPlayer"
android:title="@string/categoryMultiPlayer_title" >
<paulscode.android.mupen64plusae.persistent.InputMapPreference
android:defaultValue="@string/inputMap_defaultOff"
<paulscode.android.mupen64plusae.persistent.TogglePreference
android:defaultValue="false"
android:icon="@drawable/ic_gamepad"
android:key="inputMap2"
android:key="inputEnabled2"
android:summary="@string/inputMap_summary"
android:title="@string/inputMap2_title" />
<paulscode.android.mupen64plusae.persistent.InputMapPreference
android:defaultValue="@string/inputMap_defaultOff"
android:title="@string/inputMap2_title" >
<intent android:action=".input.InputMapActivity" >
<extra
android:name="paulscode.android.mupen64plusae.EXTRA_PLAYER"
android:value="2" />
</intent>
</paulscode.android.mupen64plusae.persistent.TogglePreference>
<paulscode.android.mupen64plusae.persistent.TogglePreference
android:defaultValue="false"
android:icon="@drawable/ic_gamepad"
android:key="inputMap3"
android:key="inputEnabled3"
android:summary="@string/inputMap_summary"
android:title="@string/inputMap3_title" />
<paulscode.android.mupen64plusae.persistent.InputMapPreference
android:defaultValue="@string/inputMap_defaultOff"
android:title="@string/inputMap3_title" >
<intent android:action=".input.InputMapActivity" >
<extra
android:name="paulscode.android.mupen64plusae.EXTRA_PLAYER"
android:value="3" />
</intent>
</paulscode.android.mupen64plusae.persistent.TogglePreference>
<paulscode.android.mupen64plusae.persistent.TogglePreference
android:defaultValue="false"
android:icon="@drawable/ic_gamepad"
android:key="inputMap4"
android:key="inputEnabled4"
android:summary="@string/inputMap_summary"
android:title="@string/inputMap4_title" />
android:title="@string/inputMap4_title" >
<intent android:action=".input.InputMapActivity" >
<extra
android:name="paulscode.android.mupen64plusae.EXTRA_PLAYER"
android:value="4" />
</intent>
</paulscode.android.mupen64plusae.persistent.TogglePreference>

<CheckBoxPreference
android:defaultValue="false"
Expand Down
8 changes: 4 additions & 4 deletions src/paulscode/android/mupen64plusae/GameLifecycleHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -308,22 +308,22 @@ private void initControllers( View inputSource )
: null;

// Create the peripheral controls to handle key/stick presses
if( mUserPrefs.inputMap1.isEnabled() )
if( mUserPrefs.isInputEnabled1 )
{
mControllers.add( new PeripheralController( 1, mUserPrefs.playerMap,
mUserPrefs.inputMap1, mKeyProvider, axisProvider ) );
}
if( mUserPrefs.inputMap2.isEnabled() )
if( mUserPrefs.isInputEnabled2 )
{
mControllers.add( new PeripheralController( 2, mUserPrefs.playerMap,
mUserPrefs.inputMap2, mKeyProvider, axisProvider ) );
}
if( mUserPrefs.inputMap3.isEnabled() )
if( mUserPrefs.isInputEnabled3 )
{
mControllers.add( new PeripheralController( 3, mUserPrefs.playerMap,
mUserPrefs.inputMap3, mKeyProvider, axisProvider ) );
}
if( mUserPrefs.inputMap4.isEnabled() )
if( mUserPrefs.isInputEnabled4 )
{
mControllers.add( new PeripheralController( 4, mUserPrefs.playerMap,
mUserPrefs.inputMap4, mKeyProvider, axisProvider ) );
Expand Down
54 changes: 11 additions & 43 deletions src/paulscode/android/mupen64plusae/input/map/InputMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
package paulscode.android.mupen64plusae.input.map;

import paulscode.android.mupen64plusae.input.AbstractController;
import paulscode.android.mupen64plusae.input.InputMapActivity;
import paulscode.android.mupen64plusae.input.PeripheralController;
import paulscode.android.mupen64plusae.input.provider.AbstractProvider;
import paulscode.android.mupen64plusae.persistent.InputMapPreference;
import paulscode.android.mupen64plusae.util.SafeMethods;
import paulscode.android.mupen64plusae.util.SubscriptionManager;
import android.util.SparseIntArray;
Expand All @@ -33,7 +33,7 @@
*
* @see AbstractProvider
* @see PeripheralController
* @see InputMapPreference
* @see InputMapActivity
*/
public class InputMap
{
Expand Down Expand Up @@ -115,9 +115,6 @@ public interface Listener
/** Map from standardized input code to N64/Mupen command. */
private final SparseIntArray mMap;

/** Flag indicating whether the map is enabled. */
private boolean mEnabled;

/** Listener management. */
private final SubscriptionManager<Listener> mPublisher;

Expand Down Expand Up @@ -154,27 +151,6 @@ public int get( int inputCode )
return mMap.get( inputCode, UNMAPPED );
}

/**
* Checks if the map is enabled.
*
* @return True, if the map is enabled.
*/
public boolean isEnabled()
{
return mEnabled;
}

/**
* Enables or disables the map. Note that this does <b>not</b> change the map data itself, but
* rather indicates whether client code should or should not use the map.
*
* @param value True to enable the map; false to disable.
*/
public void setEnabled( boolean value )
{
mEnabled = value;
}

/**
* Maps an input code to an N64/Mupen command.
*
Expand Down Expand Up @@ -271,7 +247,7 @@ public void unregisterListener( Listener listener )
public String serialize()
{
// Serialize the map data to a multi-delimited string
String result = mEnabled + "/";
String result = "";
for( int i = 0; i < mMap.size(); i++ )
{
// Putting the n64 command first makes the string a bit more human readable IMO
Expand All @@ -289,28 +265,20 @@ public void deserialize( String s )
{
// Reset the map
mMap.clear();
mEnabled = false;

// Parse the new map data from the multi-delimited string
if( s != null )
{
String[] groups = s.split( "/" );
if( groups.length == 2 )
// Read the input mappings
String[] pairs = s.split( "," );
for( String pair : pairs )
{
// Read the enabled state
mEnabled = SafeMethods.toBoolean( groups[0], false );

// Read the input mappings
String[] pairs = groups[1].split( "," );
for( String pair : pairs )
String[] elements = pair.split( ":" );
if( elements.length == 2 )
{
String[] elements = pair.split( ":" );
if( elements.length == 2 )
{
int value = SafeMethods.toInt( elements[0], UNMAPPED );
int key = SafeMethods.toInt( elements[1], 0 );
mapInput( key, value, false );
}
int value = SafeMethods.toInt( elements[0], UNMAPPED );
int key = SafeMethods.toInt( elements[1], 0 );
mapInput( key, value, false );
}
}
}
Expand Down
Loading

0 comments on commit 1b285a1

Please sign in to comment.