|
|
@ -24,8 +24,9 @@ import androidx.core.content.res.ResourcesCompat
|
|
|
|
import androidx.core.graphics.Insets
|
|
|
|
import androidx.core.graphics.Insets
|
|
|
|
import androidx.core.view.ViewCompat
|
|
|
|
import androidx.core.view.ViewCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
import androidx.core.view.WindowInsetsCompat
|
|
|
|
import androidx.core.view.isVisible
|
|
|
|
import androidx.drawerlayout.widget.DrawerLayout
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
|
|
|
|
import androidx.fragment.app.activityViewModels
|
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle
|
|
|
@ -50,6 +51,7 @@ import org.yuzu.yuzu_emu.features.settings.model.IntSetting
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
|
|
import org.yuzu.yuzu_emu.features.settings.utils.SettingsFile
|
|
|
|
import org.yuzu.yuzu_emu.model.Game
|
|
|
|
import org.yuzu.yuzu_emu.model.Game
|
|
|
|
|
|
|
|
import org.yuzu.yuzu_emu.model.EmulationViewModel
|
|
|
|
import org.yuzu.yuzu_emu.overlay.InputOverlay
|
|
|
|
import org.yuzu.yuzu_emu.overlay.InputOverlay
|
|
|
|
import org.yuzu.yuzu_emu.utils.*
|
|
|
|
import org.yuzu.yuzu_emu.utils.*
|
|
|
|
|
|
|
|
|
|
|
@ -66,6 +68,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
|
|
|
|
|
|
|
private lateinit var game: Game
|
|
|
|
private lateinit var game: Game
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private val emulationViewModel: EmulationViewModel by activityViewModels()
|
|
|
|
|
|
|
|
|
|
|
|
private var isInFoldableLayout = false
|
|
|
|
private var isInFoldableLayout = false
|
|
|
|
|
|
|
|
|
|
|
|
override fun onAttach(context: Context) {
|
|
|
|
override fun onAttach(context: Context) {
|
|
|
@ -130,9 +134,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
binding.showFpsText.setTextColor(Color.YELLOW)
|
|
|
|
binding.showFpsText.setTextColor(Color.YELLOW)
|
|
|
|
binding.doneControlConfig.setOnClickListener { stopConfiguringControls() }
|
|
|
|
binding.doneControlConfig.setOnClickListener { stopConfiguringControls() }
|
|
|
|
|
|
|
|
|
|
|
|
// Setup overlay.
|
|
|
|
binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
|
|
|
updateShowFpsOverlay()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding.inGameMenu.getHeaderView(0).findViewById<TextView>(R.id.text_game_title).text =
|
|
|
|
binding.inGameMenu.getHeaderView(0).findViewById<TextView>(R.id.text_game_title).text =
|
|
|
|
game.title
|
|
|
|
game.title
|
|
|
|
binding.inGameMenu.setNavigationItemSelectedListener {
|
|
|
|
binding.inGameMenu.setNavigationItemSelectedListener {
|
|
|
@ -174,7 +176,9 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
|
|
|
|
|
|
|
R.id.menu_exit -> {
|
|
|
|
R.id.menu_exit -> {
|
|
|
|
emulationState.stop()
|
|
|
|
emulationState.stop()
|
|
|
|
requireActivity().finish()
|
|
|
|
emulationViewModel.setIsEmulationStopping(true)
|
|
|
|
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
|
|
|
|
binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED)
|
|
|
|
true
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -188,6 +192,10 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
requireActivity(),
|
|
|
|
requireActivity(),
|
|
|
|
object : OnBackPressedCallback(true) {
|
|
|
|
object : OnBackPressedCallback(true) {
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
override fun handleOnBackPressed() {
|
|
|
|
|
|
|
|
if (!NativeLibrary.isRunning()) {
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (binding.drawerLayout.isOpen) {
|
|
|
|
if (binding.drawerLayout.isOpen) {
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -204,6 +212,54 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
.collect { updateFoldableLayout(requireActivity() as EmulationActivity, it) }
|
|
|
|
.collect { updateFoldableLayout(requireActivity() as EmulationActivity, it) }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
GameIconUtils.loadGameIcon(game, binding.loadingImage)
|
|
|
|
|
|
|
|
binding.loadingTitle.text = game.title
|
|
|
|
|
|
|
|
binding.loadingTitle.isSelected = true
|
|
|
|
|
|
|
|
binding.loadingText.isSelected = true
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emulationViewModel.shaderProgress.observe(viewLifecycleOwner) {
|
|
|
|
|
|
|
|
if (it > 0 && it != emulationViewModel.totalShaders.value!!) {
|
|
|
|
|
|
|
|
binding.loadingProgressIndicator.isIndeterminate = false
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (it < binding.loadingProgressIndicator.max) {
|
|
|
|
|
|
|
|
binding.loadingProgressIndicator.progress = it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (it == emulationViewModel.totalShaders.value!!) {
|
|
|
|
|
|
|
|
binding.loadingText.setText(R.string.loading)
|
|
|
|
|
|
|
|
binding.loadingProgressIndicator.isIndeterminate = true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
emulationViewModel.totalShaders.observe(viewLifecycleOwner) {
|
|
|
|
|
|
|
|
binding.loadingProgressIndicator.max = it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
emulationViewModel.shaderMessage.observe(viewLifecycleOwner) {
|
|
|
|
|
|
|
|
if (it.isNotEmpty()) {
|
|
|
|
|
|
|
|
binding.loadingText.text = it
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emulationViewModel.emulationStarted.observe(viewLifecycleOwner) { started ->
|
|
|
|
|
|
|
|
if (started) {
|
|
|
|
|
|
|
|
binding.drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED)
|
|
|
|
|
|
|
|
ViewUtils.showView(binding.surfaceInputOverlay)
|
|
|
|
|
|
|
|
ViewUtils.hideView(binding.loadingIndicator)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Setup overlay
|
|
|
|
|
|
|
|
updateShowFpsOverlay()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emulationViewModel.isEmulationStopping.observe(viewLifecycleOwner) {
|
|
|
|
|
|
|
|
if (it) {
|
|
|
|
|
|
|
|
binding.loadingText.setText(R.string.shutting_down)
|
|
|
|
|
|
|
|
ViewUtils.showView(binding.loadingIndicator)
|
|
|
|
|
|
|
|
ViewUtils.hideView(binding.inputContainer)
|
|
|
|
|
|
|
|
ViewUtils.hideView(binding.showFpsText)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
|
|
@ -213,11 +269,21 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
binding.drawerLayout.close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (EmulationMenuSettings.showOverlay) {
|
|
|
|
if (EmulationMenuSettings.showOverlay) {
|
|
|
|
binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = false }
|
|
|
|
binding.surfaceInputOverlay.post {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (EmulationMenuSettings.showOverlay) {
|
|
|
|
if (EmulationMenuSettings.showOverlay &&
|
|
|
|
binding.surfaceInputOverlay.post { binding.surfaceInputOverlay.isVisible = true }
|
|
|
|
emulationViewModel.emulationStarted.value == true
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.post {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.visibility = View.VISIBLE
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.post {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.visibility = View.INVISIBLE
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!isInFoldableLayout) {
|
|
|
|
if (!isInFoldableLayout) {
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
|
if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
|
|
@ -226,9 +292,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
binding.surfaceInputOverlay.layout = InputOverlay.LANDSCAPE
|
|
|
|
binding.surfaceInputOverlay.layout = InputOverlay.LANDSCAPE
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!binding.surfaceInputOverlay.isInEditMode) {
|
|
|
|
|
|
|
|
refreshInputOverlay()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -260,10 +323,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
super.onDetach()
|
|
|
|
super.onDetach()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun refreshInputOverlay() {
|
|
|
|
|
|
|
|
binding.surfaceInputOverlay.refreshControls()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private fun resetInputOverlay() {
|
|
|
|
private fun resetInputOverlay() {
|
|
|
|
preferences.edit()
|
|
|
|
preferences.edit()
|
|
|
|
.remove(Settings.PREF_CONTROL_SCALE)
|
|
|
|
.remove(Settings.PREF_CONTROL_SCALE)
|
|
|
@ -281,17 +340,15 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
val FRAMETIME = 2
|
|
|
|
val FRAMETIME = 2
|
|
|
|
val SPEED = 3
|
|
|
|
val SPEED = 3
|
|
|
|
perfStatsUpdater = {
|
|
|
|
perfStatsUpdater = {
|
|
|
|
val perfStats = NativeLibrary.getPerfStats()
|
|
|
|
if (emulationViewModel.emulationStarted.value == true) {
|
|
|
|
if (perfStats[FPS] > 0 && _binding != null) {
|
|
|
|
val perfStats = NativeLibrary.getPerfStats()
|
|
|
|
binding.showFpsText.text = String.format("FPS: %.1f", perfStats[FPS])
|
|
|
|
if (perfStats[FPS] > 0 && _binding != null) {
|
|
|
|
}
|
|
|
|
binding.showFpsText.text = String.format("FPS: %.1f", perfStats[FPS])
|
|
|
|
|
|
|
|
}
|
|
|
|
if (!emulationState.isStopped) {
|
|
|
|
|
|
|
|
perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 100)
|
|
|
|
perfStatsUpdateHandler.postDelayed(perfStatsUpdater!!, 100)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
perfStatsUpdateHandler.post(perfStatsUpdater!!)
|
|
|
|
perfStatsUpdateHandler.post(perfStatsUpdater!!)
|
|
|
|
binding.showFpsText.text = resources.getString(R.string.emulation_game_loading)
|
|
|
|
|
|
|
|
binding.showFpsText.visibility = View.VISIBLE
|
|
|
|
binding.showFpsText.visibility = View.VISIBLE
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (perfStatsUpdater != null) {
|
|
|
|
if (perfStatsUpdater != null) {
|
|
|
@ -349,7 +406,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
|
|
|
|
|
|
|
|
isInFoldableLayout = true
|
|
|
|
isInFoldableLayout = true
|
|
|
|
binding.surfaceInputOverlay.layout = InputOverlay.FOLDABLE
|
|
|
|
binding.surfaceInputOverlay.layout = InputOverlay.FOLDABLE
|
|
|
|
refreshInputOverlay()
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
it.isSeparating
|
|
|
|
it.isSeparating
|
|
|
@ -437,7 +493,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
.apply()
|
|
|
|
.apply()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
|
|
|
.setPositiveButton(android.R.string.ok) { _, _ ->
|
|
|
|
refreshInputOverlay()
|
|
|
|
binding.surfaceInputOverlay.refreshControls()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setNegativeButton(android.R.string.cancel, null)
|
|
|
|
.setNeutralButton(R.string.emulation_toggle_all) { _, _ -> }
|
|
|
|
.setNeutralButton(R.string.emulation_toggle_all) { _, _ -> }
|
|
|
@ -461,7 +517,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
R.id.menu_show_overlay -> {
|
|
|
|
R.id.menu_show_overlay -> {
|
|
|
|
it.isChecked = !it.isChecked
|
|
|
|
it.isChecked = !it.isChecked
|
|
|
|
EmulationMenuSettings.showOverlay = it.isChecked
|
|
|
|
EmulationMenuSettings.showOverlay = it.isChecked
|
|
|
|
refreshInputOverlay()
|
|
|
|
binding.surfaceInputOverlay.refreshControls()
|
|
|
|
true
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -567,14 +623,14 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|
|
|
preferences.edit()
|
|
|
|
preferences.edit()
|
|
|
|
.putInt(Settings.PREF_CONTROL_SCALE, scale)
|
|
|
|
.putInt(Settings.PREF_CONTROL_SCALE, scale)
|
|
|
|
.apply()
|
|
|
|
.apply()
|
|
|
|
refreshInputOverlay()
|
|
|
|
binding.surfaceInputOverlay.refreshControls()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun setControlOpacity(opacity: Int) {
|
|
|
|
private fun setControlOpacity(opacity: Int) {
|
|
|
|
preferences.edit()
|
|
|
|
preferences.edit()
|
|
|
|
.putInt(Settings.PREF_CONTROL_OPACITY, opacity)
|
|
|
|
.putInt(Settings.PREF_CONTROL_OPACITY, opacity)
|
|
|
|
.apply()
|
|
|
|
.apply()
|
|
|
|
refreshInputOverlay()
|
|
|
|
binding.surfaceInputOverlay.refreshControls()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private fun setInsets() {
|
|
|
|
private fun setInsets() {
|
|
|
|