diff options
| author | 2024-01-22 04:34:08 -0500 | |
|---|---|---|
| committer | 2024-01-22 04:34:08 -0500 | |
| commit | 17b0aac80945d28c88097789fe732cd0b053bec1 (patch) | |
| tree | 168f7c2eceee0e492ee7cf519abee0a990040809 /src | |
| parent | Merge pull request #12736 from t895/verify-contents (diff) | |
| parent | android: Port "Lock drawer" feature from Citra (diff) | |
| download | yuzu-17b0aac80945d28c88097789fe732cd0b053bec1.tar.gz yuzu-17b0aac80945d28c88097789fe732cd0b053bec1.tar.xz yuzu-17b0aac80945d28c88097789fe732cd0b053bec1.zip | |
Merge pull request #12738 from t895/lock-drawer
android: Port "Lock drawer" feature from Citra
Diffstat (limited to 'src')
6 files changed, 70 insertions, 4 deletions
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt index 16fb87614..71be2d0b2 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/model/IntSetting.kt | |||
| @@ -23,7 +23,8 @@ enum class IntSetting(override val key: String) : AbstractIntSetting { | |||
| 23 | THEME("theme"), | 23 | THEME("theme"), |
| 24 | THEME_MODE("theme_mode"), | 24 | THEME_MODE("theme_mode"), |
| 25 | OVERLAY_SCALE("control_scale"), | 25 | OVERLAY_SCALE("control_scale"), |
| 26 | OVERLAY_OPACITY("control_opacity"); | 26 | OVERLAY_OPACITY("control_opacity"), |
| 27 | LOCK_DRAWER("lock_drawer"); | ||
| 27 | 28 | ||
| 28 | override fun getInt(needsGlobal: Boolean): Int = NativeConfig.getInt(key, needsGlobal) | 29 | override fun getInt(needsGlobal: Boolean): Int = NativeConfig.getInt(key, needsGlobal) |
| 29 | 30 | ||
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 47767454a..2a97ae14d 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 | |||
| @@ -182,11 +182,11 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 182 | } | 182 | } |
| 183 | 183 | ||
| 184 | override fun onDrawerOpened(drawerView: View) { | 184 | override fun onDrawerOpened(drawerView: View) { |
| 185 | // No op | 185 | binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) |
| 186 | } | 186 | } |
| 187 | 187 | ||
| 188 | override fun onDrawerClosed(drawerView: View) { | 188 | override fun onDrawerClosed(drawerView: View) { |
| 189 | // No op | 189 | binding.drawerLayout.setDrawerLockMode(IntSetting.LOCK_DRAWER.getInt()) |
| 190 | } | 190 | } |
| 191 | 191 | ||
| 192 | override fun onDrawerStateChanged(newState: Int) { | 192 | override fun onDrawerStateChanged(newState: Int) { |
| @@ -196,6 +196,28 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 196 | binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) | 196 | binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) |
| 197 | binding.inGameMenu.getHeaderView(0).findViewById<TextView>(R.id.text_game_title).text = | 197 | binding.inGameMenu.getHeaderView(0).findViewById<TextView>(R.id.text_game_title).text = |
| 198 | game.title | 198 | game.title |
| 199 | |||
| 200 | binding.inGameMenu.menu.findItem(R.id.menu_lock_drawer).apply { | ||
| 201 | val lockMode = IntSetting.LOCK_DRAWER.getInt() | ||
| 202 | val titleId = if (lockMode == DrawerLayout.LOCK_MODE_LOCKED_CLOSED) { | ||
| 203 | R.string.unlock_drawer | ||
| 204 | } else { | ||
| 205 | R.string.lock_drawer | ||
| 206 | } | ||
| 207 | val iconId = if (lockMode == DrawerLayout.LOCK_MODE_UNLOCKED) { | ||
| 208 | R.drawable.ic_unlock | ||
| 209 | } else { | ||
| 210 | R.drawable.ic_lock | ||
| 211 | } | ||
| 212 | |||
| 213 | title = getString(titleId) | ||
| 214 | icon = ResourcesCompat.getDrawable( | ||
| 215 | resources, | ||
| 216 | iconId, | ||
| 217 | requireContext().theme | ||
| 218 | ) | ||
| 219 | } | ||
| 220 | |||
| 199 | binding.inGameMenu.setNavigationItemSelectedListener { | 221 | binding.inGameMenu.setNavigationItemSelectedListener { |
| 200 | when (it.itemId) { | 222 | when (it.itemId) { |
| 201 | R.id.menu_pause_emulation -> { | 223 | R.id.menu_pause_emulation -> { |
| @@ -242,6 +264,32 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 242 | true | 264 | true |
| 243 | } | 265 | } |
| 244 | 266 | ||
| 267 | R.id.menu_lock_drawer -> { | ||
| 268 | when (IntSetting.LOCK_DRAWER.getInt()) { | ||
| 269 | DrawerLayout.LOCK_MODE_UNLOCKED -> { | ||
| 270 | IntSetting.LOCK_DRAWER.setInt(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) | ||
| 271 | it.title = resources.getString(R.string.unlock_drawer) | ||
| 272 | it.icon = ResourcesCompat.getDrawable( | ||
| 273 | resources, | ||
| 274 | R.drawable.ic_lock, | ||
| 275 | requireContext().theme | ||
| 276 | ) | ||
| 277 | } | ||
| 278 | |||
| 279 | DrawerLayout.LOCK_MODE_LOCKED_CLOSED -> { | ||
| 280 | IntSetting.LOCK_DRAWER.setInt(DrawerLayout.LOCK_MODE_UNLOCKED) | ||
| 281 | it.title = resources.getString(R.string.lock_drawer) | ||
| 282 | it.icon = ResourcesCompat.getDrawable( | ||
| 283 | resources, | ||
| 284 | R.drawable.ic_unlock, | ||
| 285 | requireContext().theme | ||
| 286 | ) | ||
| 287 | } | ||
| 288 | } | ||
| 289 | NativeConfig.saveGlobalConfig() | ||
| 290 | true | ||
| 291 | } | ||
| 292 | |||
| 245 | R.id.menu_exit -> { | 293 | R.id.menu_exit -> { |
| 246 | emulationState.stop() | 294 | emulationState.stop() |
| 247 | emulationViewModel.setIsEmulationStopping(true) | 295 | emulationViewModel.setIsEmulationStopping(true) |
| @@ -326,7 +374,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 326 | repeatOnLifecycle(Lifecycle.State.CREATED) { | 374 | repeatOnLifecycle(Lifecycle.State.CREATED) { |
| 327 | emulationViewModel.emulationStarted.collectLatest { | 375 | emulationViewModel.emulationStarted.collectLatest { |
| 328 | if (it) { | 376 | if (it) { |
| 329 | binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) | 377 | binding.drawerLayout.setDrawerLockMode(IntSetting.LOCK_DRAWER.getInt()) |
| 330 | ViewUtils.showView(binding.surfaceInputOverlay) | 378 | ViewUtils.showView(binding.surfaceInputOverlay) |
| 331 | ViewUtils.hideView(binding.loadingIndicator) | 379 | ViewUtils.hideView(binding.loadingIndicator) |
| 332 | 380 | ||
diff --git a/src/android/app/src/main/jni/android_settings.h b/src/android/app/src/main/jni/android_settings.h index 559ae83eb..cf93304da 100644 --- a/src/android/app/src/main/jni/android_settings.h +++ b/src/android/app/src/main/jni/android_settings.h | |||
| @@ -63,6 +63,7 @@ struct Values { | |||
| 63 | Settings::Setting<bool> show_input_overlay{linkage, true, "show_input_overlay", | 63 | Settings::Setting<bool> show_input_overlay{linkage, true, "show_input_overlay", |
| 64 | Settings::Category::Overlay}; | 64 | Settings::Category::Overlay}; |
| 65 | Settings::Setting<bool> touchscreen{linkage, true, "touchscreen", Settings::Category::Overlay}; | 65 | Settings::Setting<bool> touchscreen{linkage, true, "touchscreen", Settings::Category::Overlay}; |
| 66 | Settings::Setting<s32> lock_drawer{linkage, false, "lock_drawer", Settings::Category::Overlay}; | ||
| 66 | }; | 67 | }; |
| 67 | 68 | ||
| 68 | extern Values values; | 69 | extern Values values; |
diff --git a/src/android/app/src/main/res/drawable/ic_lock.xml b/src/android/app/src/main/res/drawable/ic_lock.xml new file mode 100644 index 000000000..ef97b1936 --- /dev/null +++ b/src/android/app/src/main/res/drawable/ic_lock.xml | |||
| @@ -0,0 +1,9 @@ | |||
| 1 | <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| 2 | android:height="24dp" | ||
| 3 | android:viewportHeight="24" | ||
| 4 | android:viewportWidth="24" | ||
| 5 | android:width="24dp"> | ||
| 6 | <path | ||
| 7 | android:fillColor="?attr/colorControlNormal" | ||
| 8 | android:pathData="M18,8h-1L17,6c0,-2.76 -2.24,-5 -5,-5S7,3.24 7,6v2L6,8c-1.1,0 -2,0.9 -2,2v10c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L20,10c0,-1.1 -0.9,-2 -2,-2zM12,17c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2zM15.1,8L8.9,8L8.9,6c0,-1.71 1.39,-3.1 3.1,-3.1 1.71,0 3.1,1.39 3.1,3.1v2z" /> | ||
| 9 | </vector> | ||
diff --git a/src/android/app/src/main/res/menu/menu_in_game.xml b/src/android/app/src/main/res/menu/menu_in_game.xml index ac6ab06ff..eecb0563b 100644 --- a/src/android/app/src/main/res/menu/menu_in_game.xml +++ b/src/android/app/src/main/res/menu/menu_in_game.xml | |||
| @@ -22,6 +22,11 @@ | |||
| 22 | android:title="@string/emulation_input_overlay" /> | 22 | android:title="@string/emulation_input_overlay" /> |
| 23 | 23 | ||
| 24 | <item | 24 | <item |
| 25 | android:id="@+id/menu_lock_drawer" | ||
| 26 | android:icon="@drawable/ic_unlock" | ||
| 27 | android:title="@string/emulation_input_overlay" /> | ||
| 28 | |||
| 29 | <item | ||
| 25 | android:id="@+id/menu_exit" | 30 | android:id="@+id/menu_exit" |
| 26 | android:icon="@drawable/ic_exit" | 31 | android:icon="@drawable/ic_exit" |
| 27 | android:title="@string/emulation_exit" /> | 32 | android:title="@string/emulation_exit" /> |
diff --git a/src/android/app/src/main/res/values/strings.xml b/src/android/app/src/main/res/values/strings.xml index eefcc3ff4..779eb36a8 100644 --- a/src/android/app/src/main/res/values/strings.xml +++ b/src/android/app/src/main/res/values/strings.xml | |||
| @@ -392,6 +392,8 @@ | |||
| 392 | <string name="emulation_unpause">Unpause emulation</string> | 392 | <string name="emulation_unpause">Unpause emulation</string> |
| 393 | <string name="emulation_input_overlay">Overlay options</string> | 393 | <string name="emulation_input_overlay">Overlay options</string> |
| 394 | <string name="touchscreen">Touchscreen</string> | 394 | <string name="touchscreen">Touchscreen</string> |
| 395 | <string name="lock_drawer">Lock drawer</string> | ||
| 396 | <string name="unlock_drawer">Unlock drawer</string> | ||
| 395 | 397 | ||
| 396 | <string name="load_settings">Loading settingsā¦</string> | 398 | <string name="load_settings">Loading settingsā¦</string> |
| 397 | 399 | ||