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
|
package org.godotengine.editor.embed
|
||||||
|
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.MotionEvent
|
import android.view.MotionEvent
|
||||||
@@ -63,6 +64,9 @@ class EmbeddedGodotGame : GodotGame() {
|
|||||||
private var layoutWidthInPx = 0
|
private var layoutWidthInPx = 0
|
||||||
private var layoutHeightInPx = 0
|
private var layoutHeightInPx = 0
|
||||||
|
|
||||||
|
private var gameRequestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||||
|
private var isFullscreen = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@@ -81,13 +85,26 @@ class EmbeddedGodotGame : GodotGame() {
|
|||||||
window.attributes = layoutParams
|
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 {
|
override fun dispatchTouchEvent(event: MotionEvent): Boolean {
|
||||||
when (event.actionMasked) {
|
when (event.actionMasked) {
|
||||||
MotionEvent.ACTION_OUTSIDE -> {
|
MotionEvent.ACTION_OUTSIDE -> {
|
||||||
if (gameMenuFragment?.isAlwaysOnTop() == true) {
|
if (!isFullscreen) {
|
||||||
enterPiPMode()
|
if (gameMenuFragment?.isAlwaysOnTop() == true) {
|
||||||
} else {
|
enterPiPMode()
|
||||||
minimizeGameWindow()
|
} else {
|
||||||
|
minimizeGameWindow()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,12 +144,18 @@ class EmbeddedGodotGame : GodotGame() {
|
|||||||
|
|
||||||
override fun onFullScreenUpdated(enabled: Boolean) {
|
override fun onFullScreenUpdated(enabled: Boolean) {
|
||||||
godot?.enableImmersiveMode(enabled)
|
godot?.enableImmersiveMode(enabled)
|
||||||
|
isFullscreen = enabled
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
layoutWidthInPx = FULL_SCREEN_WIDTH
|
layoutWidthInPx = FULL_SCREEN_WIDTH
|
||||||
layoutHeightInPx = FULL_SCREEN_HEIGHT
|
layoutHeightInPx = FULL_SCREEN_HEIGHT
|
||||||
|
requestedOrientation = gameRequestedOrientation
|
||||||
} else {
|
} else {
|
||||||
layoutWidthInPx = defaultWidthInPx
|
layoutWidthInPx = defaultWidthInPx
|
||||||
layoutHeightInPx = defaultHeightInPx
|
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)
|
updateWindowDimensions(layoutWidthInPx, layoutHeightInPx)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user