Skip to content

Commit

Permalink
Added option to show input overlay & quit during emulation
Browse files Browse the repository at this point in the history
  • Loading branch information
SSimco committed Sep 26, 2024
1 parent e4bacd8 commit a08958f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.KeyEvent;
import android.view.MotionEvent;

import androidx.activity.OnBackPressedCallback;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.WindowCompat;
import androidx.core.view.WindowInsetsCompat;
Expand Down Expand Up @@ -44,6 +45,13 @@ public boolean dispatchKeyEvent(KeyEvent event) {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getOnBackPressedDispatcher().addCallback(this, new OnBackPressedCallback(true) {
@Override
public void handleOnBackPressed() {
showExitConfirmationDialog();
}
});

viewModel = new ViewModelProvider(this).get(EmulationViewModel.class);
viewModel.getEmulationData().observe(this, this);
Intent intent = getIntent();
Expand All @@ -70,11 +78,7 @@ protected void onCreate(Bundle savedInstanceState) {
.add(R.id.emulation_frame, emulationFragment)
.commit();
}
}

@Override
public void onBackPressed() {
showExitConfirmationDialog();
}

private void showExitConfirmationDialog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,20 @@ public boolean onMenuItemClick(MenuItem item) {
else
sensorManager.pauseListening();
item.setChecked(isMotionEnabled);
return true;
}
if (itemId == R.id.exit_emulation) {
requireActivity().getOnBackPressedDispatcher().onBackPressed();
return true;
}
if (itemId == R.id.show_input_overlay) {
boolean showInputOverlay = !item.isChecked();
var menu = settingsMenu.getMenu();
menu.findItem(R.id.edit_inputs).setEnabled(showInputOverlay);
menu.findItem(R.id.reset_inputs).setEnabled(showInputOverlay);
item.setChecked(showInputOverlay);
inputOverlaySurfaceView.setVisibility(showInputOverlay ? View.VISIBLE : View.GONE);
return true;
}
return false;
}
Expand Down Expand Up @@ -265,8 +279,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
settingsMenu.getMenuInflater().inflate(R.menu.menu_emulation_in_game, settingsMenu.getMenu());
settingsMenu.setOnMenuItemClickListener(EmulationFragment.this);
binding.emulationSettingsButton.setOnClickListener(v -> settingsMenu.show());

var menu = settingsMenu.getMenu();
menu.findItem(R.id.show_input_overlay).setChecked(overlaySettings.isOverlayEnabled());
if (!overlaySettings.isOverlayEnabled()) {
menu.findItem(R.id.reset_inputs).setEnabled(false);
menu.findItem(R.id.edit_inputs).setEnabled(false);
inputOverlaySurfaceView.setVisibility(View.GONE);
}
SurfaceView mainCanvas = binding.mainCanvas;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public enum InputMode {
private InputMode inputMode = InputMode.DEFAULT;

public void resetInputs() {
if (inputs == null) return;
int width = getWidth();
int height = getHeight();
for (var input : InputOverlaySettingsProvider.Input.values()) {
Expand Down
9 changes: 8 additions & 1 deletion src/android/app/src/main/res/menu/menu_emulation_in_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
android:title="@string/edit_inputs" />
<item
android:id="@+id/reset_inputs"
android:title="@string/reset_overlay_inputs" />
android:title="@string/reset_input_overlay" />
<item
android:id="@+id/show_input_overlay"
android:checkable="true"
android:title="@string/show_input_overlay" />
<item
android:id="@+id/exit_emulation"
android:title="@string/exit" />
</menu>
4 changes: 3 additions & 1 deletion src/android/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
<string name="input_finish_edit_label">Done</string>
<string name="move_inputs_description">Move inputs</string>
<string name="resize_inputs_description">Resize inputs</string>
<string name="reset_overlay_inputs">Reset overlay inputs</string>
<string name="reset_input_overlay">Reset input overlay</string>
<string name="edit_inputs">Edit inputs</string>
<string name="show_pad">Show pad</string>
<string name="replace_tv_with_pad">Replace TV with PAD</string>
Expand Down Expand Up @@ -189,4 +189,6 @@
<string name="downscale_filter">Downscale filter</string>
<string name="overlay_text_scale">Overlay text scale</string>
<string name="notifications_text_scale">Notifications text scale</string>
<string name="exit">Exit</string>
<string name="show_input_overlay">Show input overlay</string>
</resources>

0 comments on commit a08958f

Please sign in to comment.