You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Merge pull request #102802 from syntaxerror247/fix_orientation_handling
Android Editor: Fix embed mode orientation handling
This commit is contained in:
@@ -30,6 +30,7 @@
|
||||
|
||||
package org.godotengine.editor.embed
|
||||
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.os.Bundle
|
||||
import android.view.Gravity
|
||||
import android.view.MotionEvent
|
||||
@@ -63,6 +64,9 @@ class EmbeddedGodotGame : GodotGame() {
|
||||
private var layoutWidthInPx = 0
|
||||
private var layoutHeightInPx = 0
|
||||
|
||||
private var gameRequestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
private var isFullscreen = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -81,15 +85,28 @@ class EmbeddedGodotGame : GodotGame() {
|
||||
window.attributes = layoutParams
|
||||
}
|
||||
|
||||
override fun setRequestedOrientation(requestedOrientation: Int) {
|
||||
// Allow orientation change only if fullscreen mode is active
|
||||
// or if the requestedOrientation is landscape (i.e switching to default).
|
||||
if (isFullscreen || requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE) {
|
||||
super.setRequestedOrientation(requestedOrientation)
|
||||
} else {
|
||||
// Cache the requestedOrientation to apply when switching to fullscreen.
|
||||
gameRequestedOrientation = requestedOrientation
|
||||
}
|
||||
}
|
||||
|
||||
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||
when (event.actionMasked) {
|
||||
MotionEvent.ACTION_OUTSIDE -> {
|
||||
if (!isFullscreen) {
|
||||
if (gameMenuFragment?.isAlwaysOnTop() == true) {
|
||||
enterPiPMode()
|
||||
} else {
|
||||
minimizeGameWindow()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MotionEvent.ACTION_MOVE -> {
|
||||
// val layoutParams = window.attributes
|
||||
@@ -127,12 +144,18 @@ class EmbeddedGodotGame : GodotGame() {
|
||||
|
||||
override fun onFullScreenUpdated(enabled: Boolean) {
|
||||
godot?.enableImmersiveMode(enabled)
|
||||
isFullscreen = enabled
|
||||
if (enabled) {
|
||||
layoutWidthInPx = FULL_SCREEN_WIDTH
|
||||
layoutHeightInPx = FULL_SCREEN_HEIGHT
|
||||
requestedOrientation = gameRequestedOrientation
|
||||
} else {
|
||||
layoutWidthInPx = defaultWidthInPx
|
||||
layoutHeightInPx = defaultHeightInPx
|
||||
|
||||
// Cache the last used orientation in fullscreen to reapply when re-entering fullscreen.
|
||||
gameRequestedOrientation = requestedOrientation
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
||||
}
|
||||
updateWindowDimensions(layoutWidthInPx, layoutHeightInPx)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user