Merge pull request #8858 from Ebola16/PUP

Android: Add Pause / Unpause Emulation Toggle
This commit is contained in:
JosJuice 2020-08-02 21:56:25 +02:00 committed by GitHub
commit bf3d1fa2d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 143 additions and 5 deletions

View File

@ -70,6 +70,9 @@ public final class EmulationActivity extends AppCompatActivity
private Settings mSettings; private Settings mSettings;
private MenuItem mPauseEmulationButton;
private MenuItem mUnpauseEmulationButton;
private boolean mDeviceHasTouchScreen; private boolean mDeviceHasTouchScreen;
private boolean mMenuVisible; private boolean mMenuVisible;
@ -81,12 +84,14 @@ public final class EmulationActivity extends AppCompatActivity
private String mSelectedGameId; private String mSelectedGameId;
private int mPlatform; private int mPlatform;
private String[] mPaths; private String[] mPaths;
private static boolean sUserPausedEmulation;
private boolean backPressedOnce = false; private boolean backPressedOnce = false;
public static final String EXTRA_SELECTED_GAMES = "SelectedGames"; public static final String EXTRA_SELECTED_GAMES = "SelectedGames";
public static final String EXTRA_SELECTED_TITLE = "SelectedTitle"; public static final String EXTRA_SELECTED_TITLE = "SelectedTitle";
public static final String EXTRA_SELECTED_GAMEID = "SelectedGameId"; public static final String EXTRA_SELECTED_GAMEID = "SelectedGameId";
public static final String EXTRA_PLATFORM = "Platform"; public static final String EXTRA_PLATFORM = "Platform";
public static final String EXTRA_USER_PAUSED_EMULATION = "sUserPausedEmulation";
@Retention(SOURCE) @Retention(SOURCE)
@IntDef({MENU_ACTION_EDIT_CONTROLS_PLACEMENT, MENU_ACTION_TOGGLE_CONTROLS, MENU_ACTION_ADJUST_SCALE, @IntDef({MENU_ACTION_EDIT_CONTROLS_PLACEMENT, MENU_ACTION_TOGGLE_CONTROLS, MENU_ACTION_ADJUST_SCALE,
@ -98,7 +103,8 @@ public final class EmulationActivity extends AppCompatActivity
MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5, MENU_ACTION_LOAD_SLOT3, MENU_ACTION_LOAD_SLOT4, MENU_ACTION_LOAD_SLOT5,
MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC, MENU_ACTION_LOAD_SLOT6, MENU_ACTION_EXIT, MENU_ACTION_CHANGE_DISC,
MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP, MENU_ACTION_RESET_OVERLAY, MENU_SET_IR_SENSITIVITY, MENU_ACTION_CHOOSE_DOUBLETAP,
MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS}) MENU_ACTION_SCREEN_ORIENTATION, MENU_ACTION_MOTION_CONTROLS, MENU_ACTION_PAUSE_EMULATION,
MENU_ACTION_UNPAUSE_EMULATION})
public @interface MenuAction public @interface MenuAction
{ {
} }
@ -134,6 +140,8 @@ public final class EmulationActivity extends AppCompatActivity
public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28; public static final int MENU_ACTION_CHOOSE_DOUBLETAP = 28;
public static final int MENU_ACTION_SCREEN_ORIENTATION = 29; public static final int MENU_ACTION_SCREEN_ORIENTATION = 29;
public static final int MENU_ACTION_MOTION_CONTROLS = 30; public static final int MENU_ACTION_MOTION_CONTROLS = 30;
public static final int MENU_ACTION_PAUSE_EMULATION = 31;
public static final int MENU_ACTION_UNPAUSE_EMULATION = 32;
private static SparseIntArray buttonsActionsMap = new SparseIntArray(); private static SparseIntArray buttonsActionsMap = new SparseIntArray();
@ -150,6 +158,10 @@ public final class EmulationActivity extends AppCompatActivity
EmulationActivity.MENU_ACTION_CHOOSE_CONTROLLER); EmulationActivity.MENU_ACTION_CHOOSE_CONTROLLER);
buttonsActionsMap buttonsActionsMap
.append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES); .append(R.id.menu_refresh_wiimotes, EmulationActivity.MENU_ACTION_REFRESH_WIIMOTES);
buttonsActionsMap
.append(R.id.menu_emulation_pause, EmulationActivity.MENU_ACTION_PAUSE_EMULATION);
buttonsActionsMap
.append(R.id.menu_emulation_unpause, EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION);
buttonsActionsMap buttonsActionsMap
.append(R.id.menu_emulation_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT); .append(R.id.menu_emulation_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT);
@ -274,6 +286,7 @@ public final class EmulationActivity extends AppCompatActivity
mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE); mSelectedTitle = gameToEmulate.getStringExtra(EXTRA_SELECTED_TITLE);
mSelectedGameId = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAMEID); mSelectedGameId = gameToEmulate.getStringExtra(EXTRA_SELECTED_GAMEID);
mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0); mPlatform = gameToEmulate.getIntExtra(EXTRA_PLATFORM, 0);
sUserPausedEmulation = gameToEmulate.getBooleanExtra(EXTRA_USER_PAUSED_EMULATION, false);
activityRecreated = false; activityRecreated = false;
} }
else else
@ -356,6 +369,7 @@ public final class EmulationActivity extends AppCompatActivity
outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle); outState.putString(EXTRA_SELECTED_TITLE, mSelectedTitle);
outState.putString(EXTRA_SELECTED_GAMEID, mSelectedGameId); outState.putString(EXTRA_SELECTED_GAMEID, mSelectedGameId);
outState.putInt(EXTRA_PLATFORM, mPlatform); outState.putInt(EXTRA_PLATFORM, mPlatform);
outState.putBoolean(EXTRA_USER_PAUSED_EMULATION, sUserPausedEmulation);
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
} }
@ -365,6 +379,7 @@ public final class EmulationActivity extends AppCompatActivity
mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE); mSelectedTitle = savedInstanceState.getString(EXTRA_SELECTED_TITLE);
mSelectedGameId = savedInstanceState.getString(EXTRA_SELECTED_GAMEID); mSelectedGameId = savedInstanceState.getString(EXTRA_SELECTED_GAMEID);
mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM); mPlatform = savedInstanceState.getInt(EXTRA_PLATFORM);
sUserPausedEmulation = savedInstanceState.getBoolean(EXTRA_USER_PAUSED_EMULATION);
} }
@Override @Override
@ -490,6 +505,14 @@ public final class EmulationActivity extends AppCompatActivity
getMenuInflater().inflate(R.menu.menu_emulation_wii, menu); getMenuInflater().inflate(R.menu.menu_emulation_wii, menu);
} }
mPauseEmulationButton = menu.findItem(R.id.menu_emulation_pause);
mUnpauseEmulationButton = menu.findItem(R.id.menu_emulation_unpause);
if (sUserPausedEmulation)
{
showUnpauseEmulationButton();
}
BooleanSetting enableSaveStates = BooleanSetting enableSaveStates =
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE) (BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES); .getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES);
@ -578,6 +601,18 @@ public final class EmulationActivity extends AppCompatActivity
NativeLibrary.RefreshWiimotes(); NativeLibrary.RefreshWiimotes();
return; return;
case MENU_ACTION_PAUSE_EMULATION:
sUserPausedEmulation = true;
NativeLibrary.PauseEmulation();
showUnpauseEmulationButton();
return;
case MENU_ACTION_UNPAUSE_EMULATION:
sUserPausedEmulation = false;
NativeLibrary.UnPauseEmulation();
showPauseEmulationButton();
return;
// Screenshot capturing // Screenshot capturing
case MENU_ACTION_TAKE_SCREENSHOT: case MENU_ACTION_TAKE_SCREENSHOT:
NativeLibrary.SaveScreenShot(); NativeLibrary.SaveScreenShot();
@ -688,6 +723,28 @@ public final class EmulationActivity extends AppCompatActivity
} }
} }
private void showPauseEmulationButton()
{
mUnpauseEmulationButton.setVisible(false);
mPauseEmulationButton.setVisible(true);
}
private void showUnpauseEmulationButton()
{
mPauseEmulationButton.setVisible(false);
mUnpauseEmulationButton.setVisible(true);
}
public static boolean getHasUserPausedEmulation()
{
return sUserPausedEmulation;
}
public static void setHasUserPausedEmulation(boolean value)
{
sUserPausedEmulation = value;
}
private void toggleJoystickRelCenter(boolean state) private void toggleJoystickRelCenter(boolean state)
{ {
final SharedPreferences.Editor editor = mPreferences.edit(); final SharedPreferences.Editor editor = mPreferences.edit();

View File

@ -417,9 +417,12 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
} }
else if (state == State.PAUSED) else if (state == State.PAUSED)
{ {
Log.debug("[EmulationFragment] Resuming emulation.");
NativeLibrary.SurfaceChanged(mSurface); NativeLibrary.SurfaceChanged(mSurface);
NativeLibrary.UnPauseEmulation(); if (!EmulationActivity.getHasUserPausedEmulation())
{
Log.debug("[EmulationFragment] Resuming emulation.");
NativeLibrary.UnPauseEmulation();
}
} }
else else
{ {

View File

@ -13,6 +13,7 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.activities.EmulationActivity; import org.dolphinemu.dolphinemu.activities.EmulationActivity;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting; import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
@ -21,11 +22,17 @@ import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
public final class MenuFragment extends Fragment implements View.OnClickListener public final class MenuFragment extends Fragment implements View.OnClickListener
{ {
private View mPauseEmulation;
private View mUnpauseEmulation;
private static final String KEY_TITLE = "title"; private static final String KEY_TITLE = "title";
private static SparseIntArray buttonsActionsMap = new SparseIntArray(); private static SparseIntArray buttonsActionsMap = new SparseIntArray();
static static
{ {
buttonsActionsMap
.append(R.id.menu_pause_emulation, EmulationActivity.MENU_ACTION_PAUSE_EMULATION);
buttonsActionsMap
.append(R.id.menu_unpause_emulation, EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION);
buttonsActionsMap buttonsActionsMap
.append(R.id.menu_take_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT); .append(R.id.menu_take_screenshot, EmulationActivity.MENU_ACTION_TAKE_SCREENSHOT);
buttonsActionsMap.append(R.id.menu_quicksave, EmulationActivity.MENU_ACTION_QUICK_SAVE); buttonsActionsMap.append(R.id.menu_quicksave, EmulationActivity.MENU_ACTION_QUICK_SAVE);
@ -59,6 +66,14 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
LinearLayout options = (LinearLayout) rootView.findViewById(R.id.layout_options); LinearLayout options = (LinearLayout) rootView.findViewById(R.id.layout_options);
mPauseEmulation = options.findViewById(R.id.menu_pause_emulation);
mUnpauseEmulation = options.findViewById(R.id.menu_unpause_emulation);
if (EmulationActivity.getHasUserPausedEmulation())
{
showUnpauseEmulationButton();
}
BooleanSetting enableSaveStates = BooleanSetting enableSaveStates =
(BooleanSetting) ((EmulationActivity) getActivity()).getSettings() (BooleanSetting) ((EmulationActivity) getActivity()).getSettings()
.getSection(Settings.SECTION_INI_CORE) .getSection(Settings.SECTION_INI_CORE)
@ -89,12 +104,36 @@ public final class MenuFragment extends Fragment implements View.OnClickListener
return rootView; return rootView;
} }
private void showPauseEmulationButton()
{
mUnpauseEmulation.setVisibility(View.GONE);
mPauseEmulation.setVisibility(View.VISIBLE);
}
private void showUnpauseEmulationButton()
{
mPauseEmulation.setVisibility(View.GONE);
mUnpauseEmulation.setVisibility(View.VISIBLE);
}
@SuppressWarnings("WrongConstant") @SuppressWarnings("WrongConstant")
@Override @Override
public void onClick(View button) public void onClick(View button)
{ {
int action = buttonsActionsMap.get(button.getId()); int action = buttonsActionsMap.get(button.getId());
if (action >= 0) if (action == EmulationActivity.MENU_ACTION_PAUSE_EMULATION)
{
EmulationActivity.setHasUserPausedEmulation(true);
NativeLibrary.PauseEmulation();
showUnpauseEmulationButton();
}
else if (action == EmulationActivity.MENU_ACTION_UNPAUSE_EMULATION)
{
EmulationActivity.setHasUserPausedEmulation(false);
NativeLibrary.UnPauseEmulation();
showPauseEmulationButton();
}
else if (action >= 0)
{ {
((EmulationActivity) getActivity()).handleMenuAction(action); ((EmulationActivity) getActivity()).handleMenuAction(action);
} }

View File

@ -27,6 +27,17 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> android:orientation="vertical">
<Button
android:id="@+id/menu_pause_emulation"
android:text="@string/pause_emulation"
style="@style/InGameMenuOption"/>
<Button
android:id="@+id/menu_unpause_emulation"
android:text="@string/unpause_emulation"
style="@style/InGameMenuOption"
android:visibility="gone"/>
<Button <Button
android:id="@+id/menu_take_screenshot" android:id="@+id/menu_take_screenshot"
android:text="@string/emulation_screenshot" android:text="@string/emulation_screenshot"
@ -75,4 +86,4 @@
</ScrollView> </ScrollView>
</LinearLayout> </LinearLayout>

View File

@ -3,6 +3,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity"> tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_pause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_pause"
android:title="@string/pause_emulation"/>
<item
android:id="@+id/menu_emulation_unpause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_play"
android:title="@string/unpause_emulation"
android:visible="false"/>
<item <item
android:id="@+id/menu_emulation_screenshot" android:id="@+id/menu_emulation_screenshot"
app:showAsAction="ifRoom" app:showAsAction="ifRoom"

View File

@ -3,6 +3,19 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity"> tools:context="org.dolphinemu.dolphinemu.activities.EmulationActivity">
<item
android:id="@+id/menu_emulation_pause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_pause"
android:title="@string/pause_emulation"/>
<item
android:id="@+id/menu_emulation_unpause"
app:showAsAction="ifRoom"
android:icon="@drawable/lb_ic_play"
android:title="@string/unpause_emulation"
android:visible="false"/>
<item <item
android:id="@+id/menu_emulation_screenshot" android:id="@+id/menu_emulation_screenshot"
app:showAsAction="ifRoom" app:showAsAction="ifRoom"

View File

@ -324,6 +324,8 @@
<string name="game_details_no_compression">No Compression</string> <string name="game_details_no_compression">No Compression</string>
<!-- Emulation Menu --> <!-- Emulation Menu -->
<string name="pause_emulation">Pause Emulation</string>
<string name="unpause_emulation">Unpause Emulation</string>
<string name="emulation_screenshot">Take Screenshot</string> <string name="emulation_screenshot">Take Screenshot</string>
<string name="emulation_savestate">Save State</string> <string name="emulation_savestate">Save State</string>
<string name="emulation_loadstate">Load State</string> <string name="emulation_loadstate">Load State</string>