Permalink
Browse files

front: Move game launch logic from GamePrefsActivity to GalleryActivity.

Note: Cheats and multi-player mapping are temporarily disabled until
refactoring is complete.
  • Loading branch information...
littleguy77 committed May 2, 2015
1 parent 5d1165f commit fb68143a21d7484832d3cf60832552c37251c5cb
@@ -67,6 +67,7 @@
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
@@ -463,8 +464,7 @@ public void updateSidebar()
@Override
public void onAction()
{
GamePrefsActivity.action = GamePrefsActivity.ACTION_RESUME;
ActivityHelper.startGamePrefsActivity( GalleryActivity.this, finalItem.romFile.getAbsolutePath(), finalItem.md5 );
launchGameActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5, false );
}
} );
@@ -482,8 +482,7 @@ public void onAction()
@Override
public void onConfirm()
{
GamePrefsActivity.action = GamePrefsActivity.ACTION_RESTART;
ActivityHelper.startGamePrefsActivity( GalleryActivity.this, finalItem.romFile.getAbsolutePath(), finalItem.md5 );
launchGameActivity( finalItem.romFile.getAbsolutePath(), finalItem.md5, true );
}
} );
}
@@ -801,4 +800,80 @@ private void refreshViews()
// Refresh the gallery
refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) );
}
public void launchGameActivity( String romPath, String romMd5, boolean isRestarting )
{
// TODO FIXME
// // Popup the multi-player dialog if necessary and abort if any players are unassigned
// RomHeader romHeader = new RomHeader( romPath );
// RomDatabase romDatabase = new RomDatabase( mAppData.mupen64plus_ini );
// RomDetail romDetail = romDatabase.lookupByMd5WithFallback( romMd5, new File( romPath ) );
// GamePrefs gamePrefs = new GamePrefs( this, romMd5, romHeader );
// if( romDetail.players > 1 && gamePrefs.playerMap.isEnabled()
// && mGlobalPrefs.getPlayerMapReminder() )
// {
// gamePrefs.playerMap.removeUnavailableMappings();
// boolean needs1 = gamePrefs.isControllerEnabled1 && !gamePrefs.playerMap.isMapped( 1 );
// boolean needs2 = gamePrefs.isControllerEnabled2 && !gamePrefs.playerMap.isMapped( 2 );
// boolean needs3 = gamePrefs.isControllerEnabled3 && !gamePrefs.playerMap.isMapped( 3 )
// && romDetail.players > 2;
// boolean needs4 = gamePrefs.isControllerEnabled4 && !gamePrefs.playerMap.isMapped( 4 )
// && romDetail.players > 3;
//
// if( needs1 || needs2 || needs3 || needs4 )
// {
// @SuppressWarnings( "deprecation" )
// PlayerMapPreference pref = (PlayerMapPreference) findPreference( "playerMap" );
// pref.show();
// return;
// }
// }
// Make sure that the storage is accessible
if( !mAppData.isSdCardAccessible() )
{
Log.e( "CheatMenuHandler", "SD Card not accessible in method onPreferenceClick" );
Notifier.showToast( this, R.string.toast_sdInaccessible );
return;
}
// Notify user that the game activity is starting
Notifier.showToast( this, R.string.toast_launchingEmulator );
// Update the ConfigSection with the new value for lastPlayed
String lastPlayed = Integer.toString( (int) ( new Date().getTime() / 1000 ) );
ConfigFile config = new ConfigFile( mGlobalPrefs.romInfoCache_cfg );
if( config != null )
{
config.put( romMd5, "lastPlayed", lastPlayed );
config.save();
}
// Launch the game activity
ActivityHelper.startGameActivity( this, romPath, romMd5, getCheatArgs(), isRestarting, mGlobalPrefs.isTouchpadEnabled );
}
private String getCheatArgs()
{
String cheatArgs = null;
// TODO FIXME
// PreferenceCategory cheatsCategory = (PreferenceCategory) findPreference( CATEGORY_CHEATS );
// if( cheatsCategory != null )
// {
// for( int i = 0; i < cheatsCategory.getPreferenceCount(); 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;
}
}
@@ -22,7 +22,6 @@
import java.io.File;
import java.util.ArrayList;
import java.util.Date;
import org.mupen64plusae.v3.alpha.R;
@@ -39,7 +38,6 @@
import paulscode.android.mupen64plusae.preference.PlayerMapPreference;
import paulscode.android.mupen64plusae.preference.PrefUtil;
import paulscode.android.mupen64plusae.preference.ProfilePreference;
import paulscode.android.mupen64plusae.util.Notifier;
import paulscode.android.mupen64plusae.util.RomDatabase;
import paulscode.android.mupen64plusae.util.RomDatabase.RomDetail;
import paulscode.android.mupen64plusae.util.RomHeader;
@@ -50,7 +48,6 @@
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;
import android.preference.PreferenceCategory;
import android.preference.PreferenceGroup;
import android.preference.PreferenceManager;
import android.text.TextUtils;
@@ -66,12 +63,9 @@
private static final String SCREEN_CHEATS = "screenCheats";
private static final String CATEGORY_CHEATS = "categoryCheats";
public static final String ACTION_RESUME = "actionResume";
public static final String ACTION_RESTART = "actionRestart";
private static final String ACTION_CHEAT_EDITOR = "actionCheatEditor";
private static final String ACTION_WIKI = "actionWiki";
private static final String ACTION_RESET_GAME_PREFS = "actionResetGamePrefs";
private static final String ACTION_EXIT = "actionExit";
private static final String EMULATION_PROFILE = "emulationProfile";
private static final String TOUCHSCREEN_PROFILE = "touchscreenProfile";
@@ -205,22 +199,6 @@ protected void onResume()
mPrefs.registerOnSharedPreferenceChangeListener( this );
mMogaController.onResume();
refreshViews();
if( ACTION_RESUME.equals( action ) )
{
action = ACTION_EXIT;
launchGame( false );
}
else if( ACTION_RESTART.equals( action ) )
{
action = ACTION_EXIT;
launchGame( true );
}
else if( ACTION_EXIT.equals( action ) )
{
action = null;
finish();
}
}
@Override
@@ -395,79 +373,6 @@ private void buildCheatsCategory( final String crc )
}
}
private void launchGame( boolean isRestarting )
{
// Popup the multi-player dialog if necessary and abort if any players are unassigned
if( mRomDetail.players > 1 && mGamePrefs.playerMap.isEnabled()
&& mGlobalPrefs.getPlayerMapReminder() )
{
mGamePrefs.playerMap.removeUnavailableMappings();
boolean needs1 = mGamePrefs.isControllerEnabled1 && !mGamePrefs.playerMap.isMapped( 1 );
boolean needs2 = mGamePrefs.isControllerEnabled2 && !mGamePrefs.playerMap.isMapped( 2 );
boolean needs3 = mGamePrefs.isControllerEnabled3 && !mGamePrefs.playerMap.isMapped( 3 )
&& mRomDetail.players > 2;
boolean needs4 = mGamePrefs.isControllerEnabled4 && !mGamePrefs.playerMap.isMapped( 4 )
&& mRomDetail.players > 3;
if( needs1 || needs2 || needs3 || needs4 )
{
@SuppressWarnings( "deprecation" )
PlayerMapPreference pref = (PlayerMapPreference) findPreference( "playerMap" );
pref.show();
return;
}
}
// Make sure that the storage is accessible
if( !mAppData.isSdCardAccessible() )
{
Log.e( "CheatMenuHandler", "SD Card not accessible in method onPreferenceClick" );
Notifier.showToast( this, R.string.toast_sdInaccessible );
return;
}
// Notify user that the game activity is starting
Notifier.showToast( this, R.string.toast_launchingEmulator );
// Update the ConfigSection with the new value for lastPlayed
String lastPlayed = Integer.toString( (int) ( new Date().getTime() / 1000 ) );
ConfigFile config = new ConfigFile( mGlobalPrefs.romInfoCache_cfg );
if( config != null )
{
config.put( mRomMd5, "lastPlayed", lastPlayed );
config.save();
}
// Launch the game activity
ActivityHelper.startGameActivity( this, mRomPath, mRomMd5, getCheatArgs(), isRestarting, mGlobalPrefs.isTouchpadEnabled );
}
@SuppressWarnings( "deprecation" )
private String getCheatArgs()
{
String cheatArgs = null;
PreferenceCategory cheatsCategory = (PreferenceCategory) findPreference( CATEGORY_CHEATS );
if( cheatsCategory != null )
{
for( int i = 0; i < cheatsCategory.getPreferenceCount(); 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;
}
private void actionResetGamePrefs()
{
String title = getString( R.string.confirm_title );

0 comments on commit fb68143

Please sign in to comment.