Permalink
Browse files

front: Added global settings for controller profile and player map.

  • Loading branch information...
nicklauslittle authored and fzurita committed Dec 31, 2015
1 parent 7bc14f1 commit e86f3f56820cac06bab20e52823f98d8b10d4fb6
@@ -212,6 +212,41 @@
android:key="inputShareController"
android:summary="@string/inputShareController_summary"
android:title="@string/inputShareController_title" />
+
+ <paulscode.android.mupen64plusae.preference.ProfilePreference
+ android:icon="@drawable/ic_gamepad"
+ android:key="controllerProfile1"
+ android:summary="@string/selectedValue"
+ android:title="@string/controllerProfile1_title"
+ mupen64:allowDisable="true"
+ mupen64:managerAction=".profile.ManageControllerProfilesActivity" />
+ <paulscode.android.mupen64plusae.preference.ProfilePreference
+ android:icon="@drawable/ic_gamepad"
+ android:key="controllerProfile2"
+ android:summary="@string/selectedValue"
+ android:title="@string/controllerProfile2_title"
+ mupen64:allowDisable="true"
+ mupen64:managerAction=".profile.ManageControllerProfilesActivity" />
+ <paulscode.android.mupen64plusae.preference.ProfilePreference
+ android:icon="@drawable/ic_gamepad"
+ android:key="controllerProfile3"
+ android:summary="@string/selectedValue"
+ android:title="@string/controllerProfile3_title"
+ mupen64:allowDisable="true"
+ mupen64:managerAction=".profile.ManageControllerProfilesActivity" />
+ <paulscode.android.mupen64plusae.preference.ProfilePreference
+ android:icon="@drawable/ic_gamepad"
+ android:key="controllerProfile4"
+ android:summary="@string/selectedValue"
+ android:title="@string/controllerProfile4_title"
+ mupen64:allowDisable="true"
+ mupen64:managerAction=".profile.ManageControllerProfilesActivity" />
+
+ <paulscode.android.mupen64plusae.preference.PlayerMapPreference
+ android:icon="@drawable/ic_users"
+ android:key="playerMapV2"
+ android:summary="@string/playerMap_summary"
+ android:title="@string/playerMap_title" />
</android.support.v7.preference.PreferenceCategory>
<android.support.v7.preference.PreferenceCategory
android:key="categoryData"
@@ -292,21 +292,26 @@ public GamePrefs( Context context, String romMd5, String crc, String headerName,
}
// Controller profiles
- controllerProfile1 = loadControllerProfile( mPreferences, CONTROLLER_PROFILE1,
- globalPrefs.getControllerProfileDefault(),
+ controllerProfile1 = loadControllerProfile( mPreferences, globalPrefs, CONTROLLER_PROFILE1,
+ globalPrefs.getControllerProfileDefault(1),
globalPrefs.GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
- controllerProfile2 = loadControllerProfile( mPreferences, CONTROLLER_PROFILE2,
- "",
+ controllerProfile2 = loadControllerProfile( mPreferences, globalPrefs, CONTROLLER_PROFILE2,
+ globalPrefs.getControllerProfileDefault(2),
globalPrefs.GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
- controllerProfile3 = loadControllerProfile( mPreferences, CONTROLLER_PROFILE3,
- "",
+ controllerProfile3 = loadControllerProfile( mPreferences, globalPrefs, CONTROLLER_PROFILE3,
+ globalPrefs.getControllerProfileDefault(3),
globalPrefs.GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
- controllerProfile4 = loadControllerProfile( mPreferences, CONTROLLER_PROFILE4,
- "",
+ controllerProfile4 = loadControllerProfile( mPreferences, globalPrefs, CONTROLLER_PROFILE4,
+ globalPrefs.getControllerProfileDefault(4),
globalPrefs.GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
// Player map
- playerMap = new PlayerMap( mPreferences.getString( PLAYER_MAP, "" ) );
+ String playerMapString = mPreferences.getString( PLAYER_MAP, "" );
+
+ if( playerMapString.isEmpty() )
+ playerMapString = globalPrefs.getString( PLAYER_MAP, "" );
+
+ playerMap = new PlayerMap( playerMapString );
// Cheats menu
isCheatOptionsShown = mPreferences.getBoolean( PLAY_SHOW_CHEATS, false );
@@ -601,10 +606,11 @@ else if( builtin.keySet().contains( defaultName ) )
return null;
}
- private static ControllerProfile loadControllerProfile( SharedPreferences prefs, String key,
- String defaultName, ConfigFile custom, ConfigFile builtin )
+ private static ControllerProfile loadControllerProfile( SharedPreferences prefs, GlobalPrefs globalPrefs,
+ String key, String defaultName, ConfigFile custom, ConfigFile builtin )
{
- final String name = prefs.getString( key, defaultName );
+ String globalName = globalPrefs.getString( key, defaultName );
+ final String name = prefs.getString( key, globalName );
if( custom.keySet().contains( name ) )
return new ControllerProfile( false, custom.get( name ) );
@@ -283,28 +283,28 @@ private void refreshViews()
if(mControllerProfile1 != null)
{
mControllerProfile1.populateProfiles( mAppData.GetControllerProfilesConfig(),
- mGlobalPrefs.GetControllerProfilesConfig(), mGlobalPrefs.getControllerProfileDefault() );
+ mGlobalPrefs.GetControllerProfilesConfig(), mGlobalPrefs.getControllerProfileDefault(1) );
mControllerProfile1.setSummary(mControllerProfile1.getCurrentValue());
}
if(mControllerProfile2 != null)
{
mControllerProfile2.populateProfiles( mAppData.GetControllerProfilesConfig(),
- mGlobalPrefs.GetControllerProfilesConfig(), "" );
+ mGlobalPrefs.GetControllerProfilesConfig(), mGlobalPrefs.getControllerProfileDefault(2) );
mControllerProfile2.setSummary(mControllerProfile2.getCurrentValue());
}
if(mControllerProfile3 != null)
{
mControllerProfile3.populateProfiles( mAppData.GetControllerProfilesConfig(),
- mGlobalPrefs.GetControllerProfilesConfig(), "" );
+ mGlobalPrefs.GetControllerProfilesConfig(), mGlobalPrefs.getControllerProfileDefault(3) );
mControllerProfile3.setSummary(mControllerProfile3.getCurrentValue());
}
if(mControllerProfile4 != null)
{
mControllerProfile4.populateProfiles( mAppData.GetControllerProfilesConfig(),
- mGlobalPrefs.GetControllerProfilesConfig(), "" );
+ mGlobalPrefs.GetControllerProfilesConfig(), mGlobalPrefs.getControllerProfileDefault(4) );
mControllerProfile4.setSummary(mControllerProfile4.getCurrentValue());
}
@@ -332,6 +332,9 @@ private void refreshViews()
boolean enable3 = mGamePrefs.isControllerEnabled3 && mRomDetail.players > 2;
boolean enable4 = mGamePrefs.isControllerEnabled4 && mRomDetail.players > 3;
playerPref.setControllersEnabled( enable1, enable2, enable3, enable4 );
+
+ // Set the initial value
+ playerPref.setValue( mGamePrefs.playerMap.serialize() );
}
mPrefs.registerOnSharedPreferenceChangeListener( this );
@@ -501,6 +504,9 @@ public void onDialogClosed(int inputCode, int hardwareId, int which)
{
PlayerMapPreference playerPref = (PlayerMapPreference) findPreference( GamePrefs.PLAYER_MAP );
playerPref.onDialogClosed(inputCode, hardwareId, which);
+
+ if( playerPref.getValue().equals( mGlobalPrefs.getString( GamePrefs.PLAYER_MAP, "" ) ) )
+ playerPref.setValue( "" );
}
@Override
@@ -30,8 +30,10 @@
import org.mupen64plusae.v3.alpha.R;
import paulscode.android.mupen64plusae.ActivityHelper;
+import paulscode.android.mupen64plusae.input.map.PlayerMap;
import paulscode.android.mupen64plusae.jni.NativeConstants;
import paulscode.android.mupen64plusae.persistent.AppData.HardwareInfo;
+import paulscode.android.mupen64plusae.profile.ControllerProfile;
import paulscode.android.mupen64plusae.util.Plugin;
import paulscode.android.mupen64plusae.util.SafeMethods;
import android.app.Activity;
@@ -204,6 +206,21 @@
/** Maximum number of auto saves */
public final int maxAutoSaves;
+ /** The input profile for Player 1. */
+ public final ControllerProfile controllerProfile1;
+
+ /** The input profile for Player 2. */
+ public final ControllerProfile controllerProfile2;
+
+ /** The input profile for Player 3. */
+ public final ControllerProfile controllerProfile3;
+
+ /** The input profile for Player 4. */
+ public final ControllerProfile controllerProfile4;
+
+ /** The player map for multi-player gaming. */
+ public final PlayerMap playerMap;
+
// Shared preferences keys and key templates
private static final String KEY_EMULATION_PROFILE_DEFAULT = "emulationProfileDefault";
private static final String KEY_TOUCHSCREEN_PROFILE_DEFAULT = "touchscreenProfileDefault";
@@ -415,6 +432,32 @@ else if( navMode.equals( "standard" ) )
unmappables.add( KeyEvent.KEYCODE_VOLUME_MUTE );
}
unmappableKeyCodes = Collections.unmodifiableList( unmappables );
+
+ // Controller profiles
+ controllerProfile1 = loadControllerProfile( mPreferences, GamePrefs.CONTROLLER_PROFILE1,
+ getControllerProfileDefault(1),
+ GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
+ controllerProfile2 = loadControllerProfile( mPreferences, GamePrefs.CONTROLLER_PROFILE2,
+ getControllerProfileDefault(2),
+ GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
+ controllerProfile3 = loadControllerProfile( mPreferences, GamePrefs.CONTROLLER_PROFILE3,
+ getControllerProfileDefault(3),
+ GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
+ controllerProfile4 = loadControllerProfile( mPreferences, GamePrefs.CONTROLLER_PROFILE4,
+ getControllerProfileDefault(4),
+ GetControllerProfilesConfig(), appData.GetControllerProfilesConfig() );
+
+ // Player map
+ playerMap = new PlayerMap( mPreferences.getString( GamePrefs.PLAYER_MAP, "" ) );
+
+ // Determine whether controller deconfliction is needed
+ int numControllers = 0;
+ numControllers += controllerProfile1 != null ? 1 : 0;
+ numControllers += controllerProfile2 != null ? 1 : 0;
+ numControllers += controllerProfile3 != null ? 1 : 0;
+ numControllers += controllerProfile4 != null ? 1 : 0;
+
+ playerMap.setEnabled( numControllers > 1 && !isControllerShared );
}
public void enforceLocale( Activity activity )
@@ -461,9 +504,17 @@ public String getTouchscreenProfileDefault()
return getString( KEY_TOUCHSCREEN_PROFILE_DEFAULT, DEFAULT_TOUCHSCREEN_PROFILE_DEFAULT );
}
- public String getControllerProfileDefault()
+ public String getControllerProfileDefault( int player )
{
- return getString( KEY_CONTROLLER_PROFILE_DEFAULT, DEFAULT_CONTROLLER_PROFILE_DEFAULT );
+ switch( player )
+ {
+ case 2: return getString( GamePrefs.CONTROLLER_PROFILE2, DEFAULT_CONTROLLER_PROFILE_DEFAULT );
+ case 3: return getString( GamePrefs.CONTROLLER_PROFILE3, DEFAULT_CONTROLLER_PROFILE_DEFAULT );
+ case 4: return getString( GamePrefs.CONTROLLER_PROFILE4, DEFAULT_CONTROLLER_PROFILE_DEFAULT );
+ default: break;
+ }
+
+ return getString( GamePrefs.CONTROLLER_PROFILE1, getString( KEY_CONTROLLER_PROFILE_DEFAULT, DEFAULT_CONTROLLER_PROFILE_DEFAULT ) );
}
public PakType getPakType( int player )
@@ -488,7 +539,7 @@ public void putTouchscreenProfileDefault( String value )
public void putControllerProfileDefault( String value )
{
- putString( KEY_CONTROLLER_PROFILE_DEFAULT, value );
+ putString( GamePrefs.CONTROLLER_PROFILE1, value );
}
public void putPakType( int player, PakType pakType )
@@ -501,18 +552,18 @@ public void putPlayerMapReminder( boolean value )
putBoolean( KEY_PLAYER_MAP_REMINDER, value );
}
- private boolean getBoolean( String key, boolean defaultValue )
+ public boolean getBoolean( String key, boolean defaultValue )
{
return mPreferences.getBoolean( key, defaultValue );
}
- private int getInt( String keyTemplate, int index, int defaultValue )
+ public int getInt( String keyTemplate, int index, int defaultValue )
{
String key = String.format( Locale.US, keyTemplate, index );
return mPreferences.getInt( key, defaultValue );
}
- private String getString( String key, String defaultValue )
+ public String getString( String key, String defaultValue )
{
return mPreferences.getString( key, defaultValue );
}
@@ -600,4 +651,20 @@ public ConfigFile GetControllerProfilesConfig()
return mControllerProfilesConfig;
}
+ private static ControllerProfile loadControllerProfile( SharedPreferences prefs, String key,
+ String defaultName, ConfigFile custom, ConfigFile builtin )
+ {
+ final String name = prefs.getString( key, defaultName );
+
+ if( custom.keySet().contains( name ) )
+ return new ControllerProfile( false, custom.get( name ) );
+ else if( builtin.keySet().contains( name ) )
+ return new ControllerProfile( true, builtin.get( name ) );
+ else if( custom.keySet().contains( defaultName ) )
+ return new ControllerProfile( false, custom.get( defaultName ) );
+ else if( builtin.keySet().contains( defaultName ) )
+ return new ControllerProfile( true, builtin.get( defaultName ) );
+ else
+ return null;
+ }
}
Oops, something went wrong.

0 comments on commit e86f3f5

Please sign in to comment.