Permalink
Browse files

front: Move game launch logic from GamePrefsActivity to GalleryActivity.

Note: Automatic multi-player map checking is disabled until refactoring
is complete.  Multi-player mapping can still be done in the game prefs
activity.
  • Loading branch information...
littleguy77 committed May 4, 2015
1 parent 1ad6800 commit fa68a9097859cfd5ab2d3c7072315cbadd7bd27b
@@ -37,6 +37,7 @@
import paulscode.android.mupen64plusae.persistent.AppData;
import paulscode.android.mupen64plusae.persistent.ConfigFile;
import paulscode.android.mupen64plusae.persistent.ConfigFile.ConfigSection;
+import paulscode.android.mupen64plusae.persistent.GamePrefs;
import paulscode.android.mupen64plusae.persistent.GamePrefsActivity;
import paulscode.android.mupen64plusae.persistent.GlobalPrefs;
import paulscode.android.mupen64plusae.task.CacheRomInfoTask;
@@ -45,6 +46,7 @@
import paulscode.android.mupen64plusae.task.ComputeMd5Task.ComputeMd5Listener;
import paulscode.android.mupen64plusae.util.DeviceUtil;
import paulscode.android.mupen64plusae.util.Notifier;
+import paulscode.android.mupen64plusae.util.RomHeader;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.AlertDialog.Builder;
@@ -67,6 +69,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 +466,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 +484,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 +802,56 @@ private void refreshViews()
// Refresh the gallery
refreshGrid( new ConfigFile( mGlobalPrefs.romInfoCache_cfg ) );
}
+
+ public void launchGameActivity( String romPath, String romMd5, boolean isRestarting )
+ {
+ RomHeader romHeader = new RomHeader( romPath );
+ GamePrefs gamePrefs = new GamePrefs( this, romMd5, romHeader );
+// TODO FIXME
+// // Popup the multi-player dialog if necessary and abort if any players are unassigned
+// RomDatabase romDatabase = new RomDatabase( mAppData.mupen64plus_ini );
+// RomDetail romDetail = romDatabase.lookupByMd5WithFallback( romMd5, new File( romPath ) );
+// 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( "GalleryActivity", "SD Card not accessible" );
+ 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, gamePrefs.getCheatArgs(), isRestarting, mGlobalPrefs.isTouchpadEnabled );
+ }
}
@@ -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;
@@ -65,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";
@@ -204,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
@@ -394,53 +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, mGamePrefs.getCheatArgs(), isRestarting, mGlobalPrefs.isTouchpadEnabled );
- }
-
private void actionResetGamePrefs()
{
String title = getString( R.string.confirm_title );

0 comments on commit fa68a90

Please sign in to comment.