Migrate the Godot Editor java source file to Kotlin.
(cherry picked from commit 6b9a81900e
)
This commit is contained in:
parent
0ba78201ae
commit
5946b4bdc6
3 changed files with 79 additions and 87 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* GodotEditor.java */
|
/* GodotEditor.kt */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
|
@ -28,23 +28,17 @@
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
package org.godotengine.editor;
|
package org.godotengine.editor
|
||||||
|
|
||||||
import org.godotengine.godot.FullScreenGodotApp;
|
import android.content.Intent
|
||||||
import org.godotengine.godot.utils.PermissionsUtil;
|
import android.os.Build
|
||||||
|
import android.os.Bundle
|
||||||
import android.content.Intent;
|
import android.os.Debug
|
||||||
import android.os.Build;
|
import androidx.window.layout.WindowMetricsCalculator
|
||||||
import android.os.Bundle;
|
import org.godotengine.godot.FullScreenGodotApp
|
||||||
import android.os.Debug;
|
import org.godotengine.godot.utils.PermissionsUtil
|
||||||
|
import java.util.*
|
||||||
import androidx.annotation.Nullable;
|
import kotlin.math.min
|
||||||
import androidx.window.layout.WindowMetrics;
|
|
||||||
import androidx.window.layout.WindowMetricsCalculator;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for the Godot Android Editor activities.
|
* Base class for the Godot Android Editor activities.
|
||||||
|
@ -55,97 +49,98 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* It also plays the role of the primary editor window.
|
* It also plays the role of the primary editor window.
|
||||||
*/
|
*/
|
||||||
public class GodotEditor extends FullScreenGodotApp {
|
open class GodotEditor : FullScreenGodotApp() {
|
||||||
private static final boolean WAIT_FOR_DEBUGGER = false;
|
|
||||||
private static final String COMMAND_LINE_PARAMS = "command_line_params";
|
|
||||||
|
|
||||||
private static final String EDITOR_ARG = "--editor";
|
companion object {
|
||||||
private static final String PROJECT_MANAGER_ARG = "--project-manager";
|
private const val WAIT_FOR_DEBUGGER = false
|
||||||
|
|
||||||
private final List<String> commandLineParams = new ArrayList<>();
|
private const val COMMAND_LINE_PARAMS = "command_line_params"
|
||||||
|
|
||||||
@Override
|
private const val EDITOR_ARG = "--editor"
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
private const val PROJECT_MANAGER_ARG = "--project-manager"
|
||||||
PermissionsUtil.requestManifestPermissions(this);
|
|
||||||
|
|
||||||
String[] params = getIntent().getStringArrayExtra(COMMAND_LINE_PARAMS);
|
|
||||||
updateCommandLineParams(params);
|
|
||||||
|
|
||||||
if (BuildConfig.BUILD_TYPE.equals("debug") && WAIT_FOR_DEBUGGER) {
|
|
||||||
Debug.waitForDebugger();
|
|
||||||
}
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCommandLineParams(@Nullable String[] args) {
|
private val commandLineParams = ArrayList<String>()
|
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
|
PermissionsUtil.requestManifestPermissions(this)
|
||||||
|
|
||||||
|
val params = intent.getStringArrayExtra(COMMAND_LINE_PARAMS)
|
||||||
|
updateCommandLineParams(params)
|
||||||
|
|
||||||
|
if (BuildConfig.BUILD_TYPE == "debug" && WAIT_FOR_DEBUGGER) {
|
||||||
|
Debug.waitForDebugger()
|
||||||
|
}
|
||||||
|
|
||||||
|
super.onCreate(savedInstanceState)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateCommandLineParams(args: Array<String>?) {
|
||||||
// Update the list of command line params with the new args
|
// Update the list of command line params with the new args
|
||||||
commandLineParams.clear();
|
commandLineParams.clear()
|
||||||
if (args != null && args.length > 0) {
|
if (args != null && args.isNotEmpty()) {
|
||||||
commandLineParams.addAll(Arrays.asList(args));
|
commandLineParams.addAll(listOf(*args))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun getCommandLine() = commandLineParams
|
||||||
public List<String> getCommandLine() {
|
|
||||||
return commandLineParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
override fun onNewGodotInstanceRequested(args: Array<String>) {
|
||||||
public void onNewGodotInstanceRequested(String[] args) {
|
|
||||||
// Parse the arguments to figure out which activity to start.
|
// Parse the arguments to figure out which activity to start.
|
||||||
Class<?> targetClass = GodotGame.class;
|
var targetClass: Class<*> = GodotGame::class.java
|
||||||
|
|
||||||
// Whether we should launch the new godot instance in an adjacent window
|
// Whether we should launch the new godot instance in an adjacent window
|
||||||
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
||||||
boolean launchAdjacent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode() || isLargeScreen());
|
var launchAdjacent =
|
||||||
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode || isLargeScreen)
|
||||||
|
|
||||||
for (String arg : args) {
|
for (arg in args) {
|
||||||
if (EDITOR_ARG.equals(arg)) {
|
if (EDITOR_ARG == arg) {
|
||||||
targetClass = GodotEditor.class;
|
targetClass = GodotEditor::class.java
|
||||||
launchAdjacent = false;
|
launchAdjacent = false
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PROJECT_MANAGER_ARG.equals(arg)) {
|
if (PROJECT_MANAGER_ARG == arg) {
|
||||||
targetClass = GodotProjectManager.class;
|
targetClass = GodotProjectManager::class.java
|
||||||
launchAdjacent = false;
|
launchAdjacent = false
|
||||||
break;
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch a new activity
|
// Launch a new activity
|
||||||
Intent newInstance = new Intent(this, targetClass)
|
val newInstance = Intent(this, targetClass)
|
||||||
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||||
.putExtra(COMMAND_LINE_PARAMS, args);
|
.putExtra(COMMAND_LINE_PARAMS, args)
|
||||||
if (launchAdjacent) {
|
if (launchAdjacent) {
|
||||||
newInstance.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT);
|
newInstance.addFlags(Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT)
|
||||||
}
|
}
|
||||||
startActivity(newInstance);
|
startActivity(newInstance)
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean isLargeScreen() {
|
// Get the screen's density scale
|
||||||
WindowMetrics metrics =
|
protected val isLargeScreen: Boolean
|
||||||
WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(this);
|
// Get the minimum window size // Correspond to the EXPANDED window size class.
|
||||||
|
get() {
|
||||||
|
val metrics = WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(this)
|
||||||
|
|
||||||
// Get the screen's density scale
|
// Get the screen's density scale
|
||||||
float scale = getResources().getDisplayMetrics().density;
|
val scale = resources.displayMetrics.density
|
||||||
|
|
||||||
// Get the minimum window size
|
// Get the minimum window size
|
||||||
float minSize = Math.min(metrics.getBounds().width(), metrics.getBounds().height());
|
val minSize = min(metrics.bounds.width(), metrics.bounds.height()).toFloat()
|
||||||
float minSizeDp = minSize / scale;
|
val minSizeDp = minSize / scale
|
||||||
return minSizeDp >= 840f; // Correspond to the EXPANDED window size class.
|
return minSizeDp >= 840f // Correspond to the EXPANDED window size class.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
override fun setRequestedOrientation(requestedOrientation: Int) {
|
||||||
public void setRequestedOrientation(int requestedOrientation) {
|
|
||||||
if (!overrideOrientationRequest()) {
|
if (!overrideOrientationRequest()) {
|
||||||
super.setRequestedOrientation(requestedOrientation);
|
super.setRequestedOrientation(requestedOrientation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Godot Android Editor sets its own orientation via its AndroidManifest
|
* The Godot Android Editor sets its own orientation via its AndroidManifest
|
||||||
*/
|
*/
|
||||||
protected boolean overrideOrientationRequest() {
|
protected open fun overrideOrientationRequest() = true
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* GodotGame.java */
|
/* GodotGame.kt */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
|
@ -28,13 +28,11 @@
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
package org.godotengine.editor;
|
package org.godotengine.editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drives the 'run project' window of the Godot Editor.
|
* Drives the 'run project' window of the Godot Editor.
|
||||||
*/
|
*/
|
||||||
public class GodotGame extends GodotEditor {
|
class GodotGame : GodotEditor() {
|
||||||
protected boolean overrideOrientationRequest() {
|
override fun overrideOrientationRequest() = false
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* GodotProjectManager.java */
|
/* GodotProjectManager.kt */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
|
@ -28,14 +28,13 @@
|
||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
package org.godotengine.editor;
|
package org.godotengine.editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launcher activity for the Godot Android Editor.
|
* Launcher activity for the Godot Android Editor.
|
||||||
*
|
*
|
||||||
* It presents the user with the project manager interface.
|
* It presents the user with the project manager interface.
|
||||||
* Upon selection of a project, this activity (via its parent logic) starts the
|
* Upon selection of a project, this activity (via its parent logic) starts the
|
||||||
* {@link GodotEditor} activity.
|
* [GodotEditor] activity.
|
||||||
*/
|
*/
|
||||||
public class GodotProjectManager extends GodotEditor {
|
class GodotProjectManager : GodotEditor()
|
||||||
}
|
|
Loading…
Reference in a new issue