From 1ea84854bd72a4a76eb3193d0f22fd8bd7010c19 Mon Sep 17 00:00:00 2001 From: Charles Lombardo Date: Sat, 1 Apr 2023 00:16:01 -0400 Subject: [PATCH] android: Add toggle controls option to input overlay --- .../yuzu_emu/fragments/EmulationFragment.kt | 36 ++++++++++++++++--- .../yuzu_emu/utils/EmulationMenuSettings.kt | 2 +- .../main/res/menu/menu_overlay_options.xml | 4 +++ .../app/src/main/res/values/arrays.xml | 18 ++++++++++ .../app/src/main/res/values/strings.xml | 8 +++++ 5 files changed, 62 insertions(+), 6 deletions(-) diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index edc1a19ff..703d4623b 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt @@ -21,6 +21,7 @@ import androidx.core.view.WindowInsetsCompat import androidx.fragment.app.Fragment import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.preference.PreferenceManager +import com.google.android.material.dialog.MaterialAlertDialogBuilder import org.yuzu.yuzu_emu.NativeLibrary import org.yuzu.yuzu_emu.R import org.yuzu.yuzu_emu.YuzuApplication @@ -30,12 +31,8 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings import org.yuzu.yuzu_emu.features.settings.ui.SettingsActivity import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile import org.yuzu.yuzu_emu.model.Game -import org.yuzu.yuzu_emu.utils.DirectoryInitialization +import org.yuzu.yuzu_emu.utils.* import org.yuzu.yuzu_emu.utils.DirectoryInitialization.DirectoryInitializationState -import org.yuzu.yuzu_emu.utils.DirectoryStateReceiver -import org.yuzu.yuzu_emu.utils.EmulationMenuSettings -import org.yuzu.yuzu_emu.utils.InsetsHelper -import org.yuzu.yuzu_emu.utils.Log import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.FrameCallback { @@ -281,6 +278,35 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram startConfiguringControls() true } + R.id.menu_toggle_controls -> { + val preferences = + PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext) + val optionsArray = BooleanArray(15) + for (i in 0..14) { + optionsArray[i] = preferences.getBoolean("buttonToggle$i", i < 13) + } + + MaterialAlertDialogBuilder(requireContext()) + .setTitle(R.string.emulation_toggle_controls) + .setMultiChoiceItems( + R.array.gamepadButtons, + optionsArray + ) { _, indexSelected, isChecked -> + preferences.edit() + .putBoolean("buttonToggle$indexSelected", isChecked) + .commit() + } + .setPositiveButton(android.R.string.ok) { _, _ -> + refreshInputOverlay() + } + .setNeutralButton(R.string.emulation_toggle_all) { _, _ -> + EmulationMenuSettings.showOverlay = !EmulationMenuSettings.showOverlay + refreshInputOverlay() + } + .show() + + true + } R.id.menu_reset_overlay -> { binding.drawerLayout.close() resetInputOverlay() diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/EmulationMenuSettings.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/EmulationMenuSettings.kt index 937f13fea..e51ac1cc1 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/EmulationMenuSettings.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/utils/EmulationMenuSettings.kt @@ -57,6 +57,6 @@ object EmulationMenuSettings { set(value) { preferences.edit() .putBoolean(Settings.PREF_MENU_SETTINGS_SHOW_OVERLAY, value) - .apply() + .commit() } } diff --git a/src/android/app/src/main/res/menu/menu_overlay_options.xml b/src/android/app/src/main/res/menu/menu_overlay_options.xml index 75c84cdf3..b9341c508 100644 --- a/src/android/app/src/main/res/menu/menu_overlay_options.xml +++ b/src/android/app/src/main/res/menu/menu_overlay_options.xml @@ -5,6 +5,10 @@ android:id="@+id/menu_edit_overlay" android:title="@string/emulation_touch_overlay_edit" /> + + diff --git a/src/android/app/src/main/res/values/arrays.xml b/src/android/app/src/main/res/values/arrays.xml index 7e25f12b8..6d909ddae 100644 --- a/src/android/app/src/main/res/values/arrays.xml +++ b/src/android/app/src/main/res/values/arrays.xml @@ -135,4 +135,22 @@ 3 + + A + B + X + Y + L + R + ZL + ZR + + + - + @string/gamepad_d_pad + @string/gamepad_left_stick + @string/gamepad_right_stick + @string/gamepad_home + @string/gamepad_screenshot + + diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index 5c31fb322..ea9290df5 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml @@ -85,6 +85,7 @@ Exit Emulation Done Toggle Controls + Toggle All Adjust Scale Reset Overlay Edit Overlay @@ -173,4 +174,11 @@ Unsafe Paranoid (Slow) + + D-Pad + Left Stick + Right Stick + Home + Screenshot +