mirror of
https://github.com/yuzu-emu/yuzu.git
synced 2024-11-26 03:55:41 +01:00
android: Set portrait default control params
This commit is contained in:
parent
eb4026e3db
commit
fb28f9fd96
@ -334,6 +334,8 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
// Prevent touch regions from being displayed in the hinge
|
// Prevent touch regions from being displayed in the hinge
|
||||||
binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
|
binding.overlayContainer.layoutParams.height = it.bounds.bottom - 48.toPx
|
||||||
binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
|
binding.overlayContainer.updatePadding(0, 0, 0, 24.toPx)
|
||||||
|
binding.inGameMenu.layoutParams.height = it.bounds.bottom
|
||||||
|
refreshInputOverlay()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
it.isSeparating
|
it.isSeparating
|
||||||
@ -342,10 +344,12 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
|
|||||||
binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
binding.emulationContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
binding.overlayContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
binding.overlayContainer.updatePadding(0, 0, 0, 0)
|
binding.overlayContainer.updatePadding(0, 0, 0, 0)
|
||||||
|
binding.inGameMenu.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||||
updateScreenLayout()
|
updateScreenLayout()
|
||||||
}
|
}
|
||||||
binding.emulationContainer.requestLayout()
|
binding.emulationContainer.requestLayout()
|
||||||
binding.overlayContainer.requestLayout()
|
binding.overlayContainer.requestLayout()
|
||||||
|
binding.inGameMenu.requestLayout()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun surfaceCreated(holder: SurfaceHolder) {
|
override fun surfaceCreated(holder: SurfaceHolder) {
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
package org.yuzu.yuzu_emu.overlay
|
package org.yuzu.yuzu_emu.overlay
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
@ -16,14 +15,12 @@ import android.graphics.drawable.Drawable
|
|||||||
import android.graphics.drawable.VectorDrawable
|
import android.graphics.drawable.VectorDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Rational
|
|
||||||
import android.view.HapticFeedbackConstants
|
import android.view.HapticFeedbackConstants
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
import android.view.SurfaceView
|
import android.view.SurfaceView
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.View.OnTouchListener
|
import android.view.View.OnTouchListener
|
||||||
import android.view.WindowInsets
|
import android.view.WindowInsets
|
||||||
import android.view.WindowManager
|
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import androidx.preference.PreferenceManager
|
import androidx.preference.PreferenceManager
|
||||||
import androidx.window.layout.WindowMetricsCalculator
|
import androidx.window.layout.WindowMetricsCalculator
|
||||||
@ -36,7 +33,6 @@ import org.yuzu.yuzu_emu.features.settings.model.Settings
|
|||||||
import org.yuzu.yuzu_emu.utils.EmulationMenuSettings
|
import org.yuzu.yuzu_emu.utils.EmulationMenuSettings
|
||||||
import kotlin.math.max
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
import kotlin.math.roundToInt
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the interactive input overlay on top of the
|
* Draws the interactive input overlay on top of the
|
||||||
@ -237,11 +233,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
|||||||
val fingerPositionX = event.getX(pointerIndex).toInt()
|
val fingerPositionX = event.getX(pointerIndex).toInt()
|
||||||
val fingerPositionY = event.getY(pointerIndex).toInt()
|
val fingerPositionY = event.getY(pointerIndex).toInt()
|
||||||
|
|
||||||
val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
|
|
||||||
"-Portrait"
|
|
||||||
else
|
|
||||||
""
|
|
||||||
|
|
||||||
for (button in overlayButtons) {
|
for (button in overlayButtons) {
|
||||||
// Determine the button state to apply based on the MotionEvent action flag.
|
// Determine the button state to apply based on the MotionEvent action flag.
|
||||||
when (event.action and MotionEvent.ACTION_MASK) {
|
when (event.action and MotionEvent.ACTION_MASK) {
|
||||||
@ -538,10 +529,6 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
|||||||
overlayButtons.clear()
|
overlayButtons.clear()
|
||||||
overlayDpads.clear()
|
overlayDpads.clear()
|
||||||
overlayJoysticks.clear()
|
overlayJoysticks.clear()
|
||||||
val orientation = if (resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT)
|
|
||||||
"-Portrait"
|
|
||||||
else
|
|
||||||
""
|
|
||||||
|
|
||||||
// Add all the enabled overlay items back to the HashSet.
|
// Add all the enabled overlay items back to the HashSet.
|
||||||
if (EmulationMenuSettings.showOverlay) {
|
if (EmulationMenuSettings.showOverlay) {
|
||||||
@ -566,6 +553,9 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
|||||||
|
|
||||||
private fun defaultOverlay() {
|
private fun defaultOverlay() {
|
||||||
if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {
|
if (!preferences.getBoolean(Settings.PREF_OVERLAY_INIT, false)) {
|
||||||
|
if (orientation == portrait)
|
||||||
|
defaultOverlayPortrait()
|
||||||
|
else
|
||||||
defaultOverlayLandscape()
|
defaultOverlayLandscape()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -576,10 +566,141 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun resetButtonPlacement() {
|
fun resetButtonPlacement() {
|
||||||
|
if (orientation == portrait)
|
||||||
|
defaultOverlayPortrait()
|
||||||
|
else
|
||||||
defaultOverlayLandscape()
|
defaultOverlayLandscape()
|
||||||
refreshControls()
|
refreshControls()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun defaultOverlayPortrait() {
|
||||||
|
// Each value represents the position of the button in relation to the screen size without insets.
|
||||||
|
preferences.edit()
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_A.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_A.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_A_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_B.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_B.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_B_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_X.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_X.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_X_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_Y.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_Y.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_Y_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_ZL.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_ZL.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_ZL_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_ZR.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_ZR.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_ZR_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.DPAD_UP.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.DPAD_UP.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_DPAD_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_L.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_L.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_L_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_R.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.TRIGGER_R.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_TRIGGER_R_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_PLUS.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_PLUS.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_PLUS_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_MINUS.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_MINUS.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_MINUS_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_HOME.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_HOME.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_HOME_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_CAPTURE.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_X)
|
||||||
|
.toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.BUTTON_CAPTURE.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_BUTTON_CAPTURE_PORTRAIT_Y)
|
||||||
|
.toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.STICK_R.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.STICK_R.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_STICK_R_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.STICK_L.toString() + "$portrait-X",
|
||||||
|
resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_X).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.putFloat(
|
||||||
|
ButtonType.STICK_L.toString() + "$portrait-Y",
|
||||||
|
resources.getInteger(R.integer.SWITCH_STICK_L_PORTRAIT_Y).toFloat() / 1000
|
||||||
|
)
|
||||||
|
.apply()
|
||||||
|
}
|
||||||
|
|
||||||
private fun defaultOverlayLandscape() {
|
private fun defaultOverlayLandscape() {
|
||||||
// Each value represents the position of the button in relation to the screen size without insets.
|
// Each value represents the position of the button in relation to the screen size without insets.
|
||||||
preferences.edit()
|
preferences.edit()
|
||||||
@ -712,10 +833,22 @@ class InputOverlay(context: Context, attrs: AttributeSet?) : SurfaceView(context
|
|||||||
return inEditMode
|
return inEditMode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration?) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
orientation =
|
||||||
|
if (newConfig?.orientation == Configuration.ORIENTATION_PORTRAIT)
|
||||||
|
portrait
|
||||||
|
else
|
||||||
|
""
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val preferences: SharedPreferences =
|
private val preferences: SharedPreferences =
|
||||||
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
PreferenceManager.getDefaultSharedPreferences(YuzuApplication.appContext)
|
||||||
|
|
||||||
|
private const val portrait = "-Portrait"
|
||||||
|
private var orientation = ""
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resizes a [Bitmap] by a given scale factor
|
* Resizes a [Bitmap] by a given scale factor
|
||||||
*
|
*
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
android:id="@+id/surface_input_overlay"
|
android:id="@+id/surface_input_overlay"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="center"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
android:focusableInTouchMode="true" />
|
android:focusableInTouchMode="true" />
|
||||||
|
|
||||||
@ -72,7 +72,7 @@
|
|||||||
android:id="@+id/in_game_menu"
|
android:id="@+id/in_game_menu"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="start"
|
android:layout_gravity="start|bottom"
|
||||||
app:headerLayout="@layout/header_in_game"
|
app:headerLayout="@layout/header_in_game"
|
||||||
app:menu="@menu/menu_in_game" />
|
app:menu="@menu/menu_in_game" />
|
||||||
|
|
||||||
|
@ -2,6 +2,38 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<integer name="game_title_lines">2</integer>
|
<integer name="game_title_lines">2</integer>
|
||||||
|
|
||||||
|
<!-- Default SWITCH portrait layout -->
|
||||||
|
<integer name="SWITCH_BUTTON_A_PORTRAIT_X">830</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_A_PORTRAIT_Y">820</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_B_PORTRAIT_X">730</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_B_PORTRAIT_Y">870</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_X_PORTRAIT_X">730</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_X_PORTRAIT_Y">770</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_Y_PORTRAIT_X">630</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_Y_PORTRAIT_Y">820</integer>
|
||||||
|
<integer name="SWITCH_STICK_L_PORTRAIT_X">170</integer>
|
||||||
|
<integer name="SWITCH_STICK_L_PORTRAIT_Y">640</integer>
|
||||||
|
<integer name="SWITCH_STICK_R_PORTRAIT_X">820</integer>
|
||||||
|
<integer name="SWITCH_STICK_R_PORTRAIT_Y">640</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_L_PORTRAIT_X">140</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_L_PORTRAIT_Y">240</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_R_PORTRAIT_X">860</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_R_PORTRAIT_Y">240</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_X">140</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_ZL_PORTRAIT_Y">180</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_X">860</integer>
|
||||||
|
<integer name="SWITCH_TRIGGER_ZR_PORTRAIT_Y">180</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_X">440</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_MINUS_PORTRAIT_Y">950</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_X">560</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_PLUS_PORTRAIT_Y">950</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_X">600</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_HOME_PORTRAIT_Y">950</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_X">400</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_CAPTURE_PORTRAIT_Y">950</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_X">240</integer>
|
||||||
|
<integer name="SWITCH_BUTTON_DPAD_PORTRAIT_Y">820</integer>
|
||||||
|
|
||||||
<!-- Default SWITCH landscape layout -->
|
<!-- Default SWITCH landscape layout -->
|
||||||
<integer name="SWITCH_BUTTON_A_X">760</integer>
|
<integer name="SWITCH_BUTTON_A_X">760</integer>
|
||||||
<integer name="SWITCH_BUTTON_A_Y">790</integer>
|
<integer name="SWITCH_BUTTON_A_Y">790</integer>
|
||||||
|
Loading…
Reference in New Issue
Block a user