diff options
| author | Léo Lam <leo@leolam.fr> | 2020-10-21 22:29:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-21 22:29:21 +0200 |
| commit | 18b2553538acf647b9e965136b035adaeef87b88 (patch) | |
| tree | 40de11fa4728ffe37963e7b80aecf9303e0095a8 /Source/Android/app/src/main/java | |
| parent | 548bfbe2a201f26580ad3d23b4f7cc51c6772c2f (diff) | |
| parent | e86d713600b5e97af9904518b47152c97949c85e (diff) | |
Merge pull request #9078 from JosJuice/android-metadata-from-core
Android: Get game metadata from core
Diffstat (limited to 'Source/Android/app/src/main/java')
10 files changed, 116 insertions, 111 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 705be47560..c9d00cc225 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -447,6 +447,40 @@ public final class NativeLibrary public static native void SetObscuredPixelsTop(int height); + public static native boolean IsGameMetadataValid(); + + public static boolean IsEmulatingWii() + { + CheckGameMetadataValid(); + return IsEmulatingWiiUnchecked(); + } + + public static String GetCurrentGameID() + { + CheckGameMetadataValid(); + return GetCurrentGameIDUnchecked(); + } + + public static String GetCurrentTitleDescription() + { + CheckGameMetadataValid(); + return GetCurrentTitleDescriptionUnchecked(); + } + + private static void CheckGameMetadataValid() + { + if (!IsGameMetadataValid()) + { + throw new IllegalStateException("No game is running"); + } + } + + private static native boolean IsEmulatingWiiUnchecked(); + + private static native String GetCurrentGameIDUnchecked(); + + private static native String GetCurrentTitleDescriptionUnchecked(); + public static boolean displayAlertMsg(final String caption, final String text, final boolean yesNo, final boolean isWarning) { @@ -537,6 +571,19 @@ public final class NativeLibrary } } + private static void onTitleChanged() + { + final EmulationActivity emulationActivity = sEmulationActivity.get(); + if (emulationActivity == null) + { + Log.warning("[NativeLibrary] EmulationActivity is null."); + } + else + { + emulationActivity.runOnUiThread(emulationActivity::onTitleChanged); + } + } + public static float getRenderSurfaceScale() { DisplayMetrics metrics = new DisplayMetrics(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AppLinkActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AppLinkActivity.java index 44db12e273..156995e26d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AppLinkActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/AppLinkActivity.java @@ -139,6 +139,6 @@ public class AppLinkActivity extends FragmentActivity mAfterDirectoryInitializationRunner.cancel(); mAfterDirectoryInitializationRunner = null; } - EmulationActivity.launch(this, game); + EmulationActivity.launch(this, GameFileCacheService.findSecondDiscAndGetPaths(game)); } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 2d7d633277..cbbe1393fb 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -80,20 +80,13 @@ public final class EmulationActivity extends AppCompatActivity private boolean mMenuVisible; private static boolean sIgnoreLaunchRequests = false; - private static boolean sIsGameCubeGame; private boolean activityRecreated; - private String mSelectedTitle; - private String mSelectedGameId; - private int mPlatform; private String[] mPaths; private boolean mIgnoreWarnings; private static boolean sUserPausedEmulation; public static final String EXTRA_SELECTED_GAMES = "SelectedGames"; - public static final String EXTRA_SELECTED_TITLE = "SelectedTitle"; - public static final String EXTRA_SELECTED_GAMEID = "SelectedGameId"; - public static final String EXTRA_PLATFORM = "Platform"; public static final String EXTRA_IGNORE_WARNINGS = "IgnoreWarnings"; public static final String EXTRA_USER_PAUSED_EMULATION = "sUserPausedEmulation"; @@ -176,34 +169,7 @@ public final class EmulationActivity extends AppCompatActivity EmulationActivity.MENU_ACTION_MOTION_CONTROLS); } - private static String[] scanForSecondDisc(GameFile gameFile) - { - GameFile secondFile = GameFileCacheService.findSecondDisc(gameFile); - if (secondFile == null) - return new String[]{gameFile.getPath()}; - else - return new String[]{gameFile.getPath(), secondFile.getPath()}; - } - - public static void launch(FragmentActivity activity, GameFile gameFile) - { - if (sIgnoreLaunchRequests) - return; - - sIgnoreLaunchRequests = true; - - Intent launcher = new Intent(activity, EmulationActivity.class); - - launcher.putExtra(EXTRA_SELECTED_GAMES, scanForSecondDisc(gameFile)); - launcher.putExtra(EXTRA_SELECTED_TITLE, gameFile.getTitle()); - launcher.putExtra(EXTRA_SELECTED_GAMEID, gameFile.getGameId()); - launcher.putExtra(EXTRA_PLATFORM, gameFile.getPlatform()); - - new AfterDirectoryInitializationRunner().run(activity, true, - () -> activity.startActivity(launcher)); - } - - public static void launchFile(FragmentActivity activity, String[] filePaths) + public static void launch(FragmentActivity activity, String[] filePaths) { if (sIgnoreLaunchRequests) return; @@ -213,30 +179,6 @@ public final class EmulationActivity extends AppCompatActivity Intent launcher = new Intent(activity, EmulationActivity.class); launcher.putExtra(EXTRA_SELECTED_GAMES, filePaths); - // Try parsing a GameFile first. This should succeed for disc images. - GameFile gameFile = GameFile.parse(filePaths[0]); - if (gameFile != null) - { - // We don't want to pollute the game file cache with this new file, - // so we can't just call launch() and let it handle the setup. - launcher.putExtra(EXTRA_SELECTED_TITLE, gameFile.getTitle()); - launcher.putExtra(EXTRA_SELECTED_GAMEID, gameFile.getGameId()); - launcher.putExtra(EXTRA_PLATFORM, gameFile.getPlatform()); - } - else - { - // Display the path to the file as the game title in the menu. - launcher.putExtra(EXTRA_SELECTED_TITLE, filePaths[0]); - - // Use 00000000 as the game ID. This should match the Desktop version behavior. - // TODO: This should really be pulled from the Core. - launcher.putExtra(EXTRA_SELECTED_GAMEID, "00000000"); - - // GameFile might be a FIFO log. Assume GameCube for the platform. It doesn't really matter - // anyway, since this only controls the input, and the FIFO player doesn't take any input. - launcher.putExtra(EXTRA_PLATFORM, Platform.GAMECUBE); - } - new AfterDirectoryInitializationRunner().run(activity, true, () -> activity.startActivity(launcher)); } @@ -272,9 +214,6 @@ public final class EmulationActivity extends AppCompatActivity // Get params we were passed Intent gameToEmulate = getIntent(); mPaths = gameToEmulate.getStringArrayExtra(EXTRA_SELECTED_GAMES); - mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE); - mSelectedGameId = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAMEID); - mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0); mIgnoreWarnings = gameToEmulate.getBooleanExtra(EXTRA_IGNORE_WARNINGS, false); sUserPausedEmulation = gameToEmulate.getBooleanExtra(EXTRA_USER_PAUSED_EMULATION, false); activityRecreated = false; @@ -293,9 +232,6 @@ public final class EmulationActivity extends AppCompatActivity updateOrientation(); - // TODO: The accurate way to find out which console we're emulating is to first - // launch emulation and then ask the core which console we're emulating - sIsGameCubeGame = Platform.fromNativeInt(mPlatform) == Platform.GAMECUBE; mDeviceHasTouchScreen = getPackageManager().hasSystemFeature("android.hardware.touchscreen"); mMotionListener = new MotionListener(this); @@ -317,7 +253,8 @@ public final class EmulationActivity extends AppCompatActivity .commit(); } - setTitle(mSelectedTitle); + if (NativeLibrary.IsGameMetadataValid()) + setTitle(NativeLibrary.GetCurrentTitleDescription()); } @Override @@ -329,9 +266,6 @@ public final class EmulationActivity extends AppCompatActivity mEmulationFragment.saveTemporaryState(); } outState.putStringArray(EXTRA_SELECTED_GAMES, mPaths); - outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle); - outState.putString(EXTRA_SELECTED_GAMEID, mSelectedGameId); - outState.putInt(EXTRA_PLATFORM, mPlatform); outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, mIgnoreWarnings); outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, sUserPausedEmulation); super.onSaveInstanceState(outState); @@ -340,9 +274,6 @@ public final class EmulationActivity extends AppCompatActivity protected void restoreState(Bundle savedInstanceState) { mPaths = savedInstanceState.getStringArray(EXTRA_SELECTED_GAMES); - mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE); - mSelectedGameId = savedInstanceState.getString(EXTRA_SELECTED_GAMEID); - mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM); mIgnoreWarnings = savedInstanceState.getBoolean(EXTRA_IGNORE_WARNINGS); sUserPausedEmulation = savedInstanceState.getBoolean(EXTRA_USER_PAUSED_EMULATION); } @@ -361,8 +292,8 @@ public final class EmulationActivity extends AppCompatActivity { super.onResume(); - if (!sIsGameCubeGame && IntSetting.MAIN_MOTION_CONTROLS.getInt(mSettings) != 2) - mMotionListener.enable(); + if (NativeLibrary.IsGameMetadataValid()) + updateMotionListener(); } @Override @@ -378,6 +309,23 @@ public final class EmulationActivity extends AppCompatActivity super.onStop(); } + public void onTitleChanged() + { + setTitle(NativeLibrary.GetCurrentTitleDescription()); + updateMotionListener(); + + if (mDeviceHasTouchScreen) + mEmulationFragment.refreshInputOverlay(); + } + + private void updateMotionListener() + { + if (NativeLibrary.IsEmulatingWii() && IntSetting.MAIN_MOTION_CONTROLS.getInt(mSettings) != 2) + mMotionListener.enable(); + else + mMotionListener.disable(); + } + @Override protected void onDestroy() { @@ -459,7 +407,7 @@ public final class EmulationActivity extends AppCompatActivity if (!closeMenu()) { // Removing the menu failed, so that means it wasn't visible. Add it. - Fragment fragment = MenuFragment.newInstance(mSelectedTitle); + Fragment fragment = MenuFragment.newInstance(); getSupportFragmentManager().beginTransaction() .setCustomAnimations( R.animator.menu_slide_in_from_start, @@ -478,7 +426,8 @@ public final class EmulationActivity extends AppCompatActivity PopupMenu popup = new PopupMenu(this, anchor); Menu menu = popup.getMenu(); - int id = sIsGameCubeGame ? R.menu.menu_overlay_controls_gc : R.menu.menu_overlay_controls_wii; + boolean wii = NativeLibrary.IsEmulatingWii(); + int id = wii ? R.menu.menu_overlay_controls_wii : R.menu.menu_overlay_controls_gc; popup.getMenuInflater().inflate(id, menu); // Populate the checkbox value for joystick center on touch @@ -748,7 +697,7 @@ public final class EmulationActivity extends AppCompatActivity { AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase); builder.setTitle(R.string.emulation_toggle_controls); - if (sIsGameCubeGame || mPreferences.getInt("wiiController", 3) == 0) + if (!NativeLibrary.IsEmulatingWii() || mPreferences.getInt("wiiController", 3) == 0) { boolean[] gcEnabledButtons = new boolean[11]; String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_"; @@ -972,7 +921,7 @@ public final class EmulationActivity extends AppCompatActivity private void setIRSensitivity() { // IR settings always get saved per-game since WiimoteNew.ini is wiped upon reinstall. - File file = SettingsFile.getCustomGameSettingsFile(mSelectedGameId); + File file = SettingsFile.getCustomGameSettingsFile(NativeLibrary.GetCurrentGameID()); IniFile ini = new IniFile(file); int ir_pitch = ini.getInt(Settings.SECTION_CONTROLS, SettingsFile.KEY_WIIBIND_IR_PITCH, 15); @@ -1214,16 +1163,6 @@ public final class EmulationActivity extends AppCompatActivity .commit(); } - public String getSelectedTitle() - { - return mSelectedTitle; - } - - public static boolean isGameCubeGame() - { - return sIsGameCubeGame; - } - public boolean isActivityRecreated() { return activityRecreated; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java index 5e813fd099..f83aaeb575 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/adapters/GameAdapter.java @@ -138,7 +138,8 @@ public final class GameAdapter extends RecyclerView.Adapter<GameViewHolder> impl { GameViewHolder holder = (GameViewHolder) view.getTag(); - EmulationActivity.launch((FragmentActivity) view.getContext(), holder.gameFile); + String[] paths = GameFileCacheService.findSecondDiscAndGetPaths(holder.gameFile); + EmulationActivity.launch((FragmentActivity) view.getContext(), paths); } /** diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java index 1da21470e8..d11d5f93e7 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/MenuFragment.java @@ -26,6 +26,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener private View mUnpauseEmulation; private static final String KEY_TITLE = "title"; + private static final String KEY_WII = "wii"; private static SparseIntArray buttonsActionsMap = new SparseIntArray(); static @@ -55,12 +56,16 @@ public final class MenuFragment extends Fragment implements View.OnClickListener EmulationActivity.MENU_ACTION_SETTINGS_GRAPHICS); } - public static MenuFragment newInstance(String title) + public static MenuFragment newInstance() { MenuFragment fragment = new MenuFragment(); Bundle arguments = new Bundle(); - arguments.putSerializable(KEY_TITLE, title); + if (NativeLibrary.IsGameMetadataValid()) + { + arguments.putString(KEY_TITLE, NativeLibrary.GetCurrentTitleDescription()); + arguments.putBoolean(KEY_WII, NativeLibrary.IsEmulatingWii()); + } fragment.setArguments(arguments); return fragment; @@ -93,7 +98,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener options.findViewById(R.id.menu_overlay_controls).setVisibility(View.GONE); } - if (EmulationActivity.isGameCubeGame()) + if (!getArguments().getBoolean(KEY_WII, true)) { options.findViewById(R.id.menu_refresh_wiimotes).setVisibility(View.GONE); } @@ -131,7 +136,7 @@ public final class MenuFragment extends Fragment implements View.OnClickListener rootView.findViewById(R.id.menu_exit).setOnClickListener(this); mTitleText = rootView.findViewById(R.id.text_game_title); - String title = getArguments().getString(KEY_TITLE); + String title = getArguments().getString(KEY_TITLE, null); if (title != null) { mTitleText.setText(title); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java index 37ce3aeb72..8347582830 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java @@ -124,17 +124,20 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener if (!mPreferences.getBoolean("OverlayInitV3", false)) defaultOverlay(); - // Load the controls. - if (NativeLibrary.IsRunning()) + // Load the controls if we can. If not, EmulationActivity has to do it later. + if (NativeLibrary.IsGameMetadataValid()) { - // We would've needed a refreshControls call here in addition to the initTouchPointer call - // if it wasn't for initTouchPointer calling refreshControls. - initTouchPointer(); - } - else - { - // We can't call initTouchPointer yet because it needs the aspect ratio of the running game. - refreshControls(); + if (NativeLibrary.IsRunning()) + { + // We would've needed a refreshControls call here in addition to the initTouchPointer call + // if it wasn't for initTouchPointer calling refreshControls. + initTouchPointer(); + } + else + { + // We can't call initTouchPointer yet because it needs the aspect ratio of the running game. + refreshControls(); + } } // Set the on touch listener. @@ -152,7 +155,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // Refresh before starting the pointer refreshControls(); - if (!EmulationActivity.isGameCubeGame()) + if (!NativeLibrary.IsEmulatingWii()) { int doubleTapButton = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getIntGlobal(); @@ -715,7 +718,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener if (BooleanSetting.MAIN_SHOW_INPUT_OVERLAY.getBooleanGlobal()) { // Add all the enabled overlay items back to the HashSet. - if (EmulationActivity.isGameCubeGame()) + if (!NativeLibrary.IsEmulatingWii()) { IniFile dolphinIni = new IniFile(SettingsFile.getSettingsFile(Settings.FILE_DOLPHIN)); @@ -775,7 +778,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; // Values for these come from R.array.controllersEntries - if (EmulationActivity.isGameCubeGame() || mPreferences.getInt("wiiController", 3) == 0) + if (!NativeLibrary.IsEmulatingWii() || mPreferences.getInt("wiiController", 3) == 0) { if (isLandscape) gcDefaultOverlay(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java index 61f3efa755..ff37ccac4b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/services/GameFileCacheService.java @@ -86,6 +86,15 @@ public final class GameFileCacheService extends IntentService return matchWithoutRevision; } + public static String[] findSecondDiscAndGetPaths(GameFile gameFile) + { + GameFile secondFile = findSecondDisc(gameFile); + if (secondFile == null) + return new String[]{gameFile.getPath()}; + else + return new String[]{gameFile.getPath(), secondFile.getPath()}; + } + public static boolean hasLoadedCache() { return hasLoadedCache.get(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java index a57ee0d1ce..53306d8e4d 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/MainActivity.java @@ -201,7 +201,7 @@ public final class MainActivity extends AppCompatActivity implements MainView break; case MainPresenter.REQUEST_GAME_FILE: - EmulationActivity.launchFile(this, FileBrowserHelper.getSelectedFiles(result)); + EmulationActivity.launch(this, FileBrowserHelper.getSelectedFiles(result)); break; case MainPresenter.REQUEST_WAD_FILE: diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java index 6bdbaac846..f1c8c37a41 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/ui/main/TvMainActivity.java @@ -142,7 +142,8 @@ public final class TvMainActivity extends FragmentActivity implements MainView TvGameViewHolder holder = (TvGameViewHolder) itemViewHolder; // Start the emulation activity and send the path of the clicked ISO to it. - EmulationActivity.launch(TvMainActivity.this, holder.gameFile); + String[] paths = GameFileCacheService.findSecondDiscAndGetPaths(holder.gameFile); + EmulationActivity.launch(TvMainActivity.this, paths); } }); } @@ -224,7 +225,7 @@ public final class TvMainActivity extends FragmentActivity implements MainView break; case MainPresenter.REQUEST_GAME_FILE: - EmulationActivity.launchFile(this, FileBrowserHelper.getSelectedFiles(result)); + EmulationActivity.launch(this, FileBrowserHelper.getSelectedFiles(result)); break; case MainPresenter.REQUEST_WAD_FILE: diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java index ed6415821e..20d71a4e85 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/StartupHandler.java @@ -48,7 +48,7 @@ public final class StartupHandler if (start_files != null && start_files.length > 0) { // Start the emulation activity, send the ISO passed in and finish the main activity - EmulationActivity.launchFile(parent, start_files); + EmulationActivity.launch(parent, start_files); parent.finish(); } } |
