Skip to content

Commit

Permalink
front: Added option to disable cheat menu altogether (speedup loading).
Browse files Browse the repository at this point in the history
The transition when you change the checkbox state is a little funny,
but it works.
  • Loading branch information
littleguy77 committed Jan 14, 2013
1 parent ce18401 commit 6e27cf1
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 18 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@
<string name="categoryCrashReports_title">Crash reports</string>

<!-- Checkbox Preferences -->
<string name="playShowCheats_title">Enable cheats</string>
<string name="playShowCheats_summary">Menu loading is slower when enabled</string>
<string name="touchscreenEnabled_title">Enable touchscreen</string>
<string name="touchpadEnabled_title">Enable touchpad</string>
<string name="inputOctagonConstraints_title">Octagonal joystick limits</string>
Expand Down
6 changes: 6 additions & 0 deletions res/xml/preferences_play.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
android:summary="@string/playerMap_summary"
android:title="@string/playerMap_title" />

<CheckBoxPreference
android:defaultValue="false"
android:key="playShowCheats"
android:summary="@string/playShowCheats_summary"
android:title="@string/playShowCheats_title" />

<PreferenceCategory
android:key="categoryCheats"
android:title="@string/categoryCheats_title" />
Expand Down
83 changes: 65 additions & 18 deletions src/paulscode/android/mupen64plusae/PlayMenuActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,28 @@
import paulscode.android.mupen64plusae.util.TaskHandler.Task;
import paulscode.android.mupen64plusae.util.Utility;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;

public class PlayMenuActivity extends PreferenceActivity implements OnPreferenceClickListener
public class PlayMenuActivity extends PreferenceActivity implements OnPreferenceClickListener,
OnSharedPreferenceChangeListener
{
// These constants must match the keys used in res/xml/preferences_play.xml
private static final String SCREEN_PLAY = "screenPlay";
private static final String ACTION_RESUME = "actionResume";
private static final String ACTION_RESTART = "actionRestart";
private static final String PLAYER_MAP = "playerMap";
private static final String PLAY_SHOW_CHEATS = "playShowCheats";
private static final String CATEGORY_CHEATS = "categoryCheats";

// App data
Expand Down Expand Up @@ -90,16 +95,54 @@ protected void onCreate( Bundle savedInstanceState )
if( !userPrefs.playerMap.isEnabled() )
PrefUtil.removePreference( this, SCREEN_PLAY, PLAYER_MAP );

// Populate cheats category with menu items
if( userPrefs.selectedGame.equals( mAppData.getLastRom() ) )
// Hide or populate the cheats category depending on user preference
if( userPrefs.isCheatOptionsShown )
{
// Use the cached CRC and add the cheats menu items
build( mAppData.getLastCrc() );
// Populate cheats category with menu items
if( userPrefs.selectedGame.equals( mAppData.getLastRom() ) )
{
// Use the cached CRC and add the cheats menu items
build( mAppData.getLastCrc() );
}
else
{
// Recompute the CRC in a separate thread, then add the cheats menu items
rebuild( userPrefs.selectedGame );
}
}
else
{
// Recompute the CRC in a separate thread, then add the cheats menu items
rebuild( userPrefs.selectedGame );
// Hide the cheats category
PrefUtil.removePreference( this, SCREEN_PLAY, CATEGORY_CHEATS );
}
}

@Override
protected void onResume()
{
super.onResume();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences( this );
sharedPreferences.registerOnSharedPreferenceChangeListener( this );
}

@Override
protected void onPause()
{
super.onPause();
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences( this );
sharedPreferences.unregisterOnSharedPreferenceChangeListener( this );
}

@Override
public void onSharedPreferenceChanged( SharedPreferences sharedPreferences, String key )
{
if( key.equals( PLAY_SHOW_CHEATS ) )
{
// Rebuild the menu; the easiest way is to simply restart the activity
Intent intent = getIntent();
intent.setFlags( Intent.FLAG_ACTIVITY_NO_ANIMATION );
startActivity( intent );
finish();
}
}

Expand Down Expand Up @@ -281,22 +324,26 @@ private void launchGame( boolean isRestarting )
@SuppressWarnings( "deprecation" )
private String getCheatArgs()
{
PreferenceCategory cheatsCategory = (PreferenceCategory) findPreference( CATEGORY_CHEATS );

String cheatArgs = null;
for( int i = 0; i < cheatsCategory.getPreferenceCount(); i++ )

PreferenceCategory cheatsCategory = (PreferenceCategory) findPreference( CATEGORY_CHEATS );
if( cheatsCategory != null )
{
CheatPreference pref = (CheatPreference) cheatsCategory.getPreference( i );
if( pref.isCheatEnabled() )
for( int i = 0; i < cheatsCategory.getPreferenceCount(); i++ )
{
if( cheatArgs == null )
cheatArgs = ""; // First time through
else
cheatArgs += ",";

cheatArgs += pref.getCheatCodeString( i );
CheatPreference pref = (CheatPreference) cheatsCategory.getPreference( i );
if( pref.isCheatEnabled() )
{
if( cheatArgs == null )
cheatArgs = ""; // First time through
else
cheatArgs += ",";

cheatArgs += pref.getCheatCodeString( i );
}
}
}

return cheatArgs;
}
}
6 changes: 6 additions & 0 deletions src/paulscode/android/mupen64plusae/persistent/UserPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ public class UserPrefs
/** The selected emulator core. */
public final Plugin corePlugin;

/** True if the cheats category should be shown in the menu. */
public final boolean isCheatOptionsShown;

/** True if the touchscreen is enabled. */
public final boolean isTouchscreenEnabled;

Expand Down Expand Up @@ -250,6 +253,9 @@ public UserPrefs( Context context )
rspPlugin = new Plugin( prefsData, appData.libsDir, "pluginRsp" );
corePlugin = new Plugin( prefsData, appData.libsDir, "pluginCore" );

// Play menu
isCheatOptionsShown = prefsData.getBoolean( "playShowCheats", false );

// Touchscreen prefs
isTouchscreenEnabled = prefsData.getBoolean( "touchscreenEnabled", true );
touchscreenRefresh = getSafeInt( prefsData, "touchscreenRefresh", 0 );
Expand Down

0 comments on commit 6e27cf1

Please sign in to comment.