mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-24 20:57:18 +01:00
Ported: Migrate the Godot Editor java source file to Kotlin. - m4gr3d
5946b4bdc6
This commit is contained in:
parent
b829fff345
commit
d6e3a9e014
@ -1,5 +1,5 @@
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* PandemoniumEditor.java */
|
/* PandemoniumEditor.kt */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
@ -28,23 +28,20 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
package net.relintai.pandemonium.editor;
|
package net.relintai.pandemonium.editor
|
||||||
|
|
||||||
import net.relintai.pandemonium.pandemonium.FullScreenPandemoniumApp;
|
import net.relintai.pandemonium.pandemonium.FullScreenPandemoniumApp
|
||||||
import net.relintai.pandemonium.pandemonium.utils.PermissionsUtil;
|
import net.relintai.pandemonium.pandemonium.utils.PermissionsUtil
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent
|
||||||
import android.os.Build;
|
import android.os.Build
|
||||||
import android.os.Bundle;
|
import android.os.Bundle
|
||||||
import android.os.Debug;
|
import android.os.Debug
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.window.layout.WindowMetrics;
|
|
||||||
import androidx.window.layout.WindowMetricsCalculator;
|
import androidx.window.layout.WindowMetricsCalculator;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*
|
||||||
import java.util.Arrays;
|
import kotlin.math.min
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for the Pandemonium Android Editor activities.
|
* Base class for the Pandemonium Android Editor activities.
|
||||||
@ -55,100 +52,95 @@ 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 PandemoniumEditor extends FullScreenPandemoniumApp {
|
open class PandemoniumEditor : FullScreenPandemoniumApp() {
|
||||||
private static final boolean WAIT_FOR_DEBUGGER = false;
|
companion object {
|
||||||
private static final String COMMAND_LINE_PARAMS = "command_line_params";
|
private const val WAIT_FOR_DEBUGGER = false
|
||||||
|
private const val COMMAND_LINE_PARAMS = "command_line_params"
|
||||||
|
|
||||||
private static final String EDITOR_ARG = "--editor";
|
private const val EDITOR_ARG = "--editor"
|
||||||
private static final String PROJECT_MANAGER_ARG = "--project-manager";
|
private const val PROJECT_MANAGER_ARG = "--project-manager"
|
||||||
|
}
|
||||||
|
|
||||||
private final List<String> commandLineParams = new ArrayList<>();
|
private val commandLineParams = ArrayList<String>()
|
||||||
|
|
||||||
@Override
|
override fun onCreate(savedInstanceState : Bundle?) {
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
PermissionsUtil.requestManifestPermissions(this);
|
PermissionsUtil.requestManifestPermissions(this);
|
||||||
|
|
||||||
String[] params = getIntent().getStringArrayExtra(COMMAND_LINE_PARAMS);
|
//String[]
|
||||||
|
val params = getIntent().getStringArrayExtra(COMMAND_LINE_PARAMS);
|
||||||
updateCommandLineParams(params);
|
updateCommandLineParams(params);
|
||||||
|
|
||||||
if (BuildConfig.BUILD_TYPE.equals("debug") && WAIT_FOR_DEBUGGER) {
|
if (BuildConfig.BUILD_TYPE == "debug" && WAIT_FOR_DEBUGGER) {
|
||||||
Debug.waitForDebugger();
|
Debug.waitForDebugger();
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateCommandLineParams(@Nullable String[] args) {
|
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 onNewGodotInstanceRequested(args: Array<String>) {
|
||||||
public List<String> getCommandLine() {
|
|
||||||
return commandLineParams;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onNewPandemoniumInstanceRequested(String[] args) {
|
|
||||||
// Parse the arguments to figure out which activity to start.
|
// Parse the arguments to figure out which activity to start.
|
||||||
Class<?> targetClass = PandemoniumGame.class;
|
var targetClass: Class<*> = PandemoniumGame::class.java
|
||||||
// Whether we should launch the new godot instance in an adjacent window
|
|
||||||
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
|
||||||
boolean launchAdjacent = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode() || isLargeScreen());
|
|
||||||
|
|
||||||
for (String arg : args) {
|
// Whether we should launch the new godot instance in an adjacent window
|
||||||
if (EDITOR_ARG.equals(arg)) {
|
// https://developer.android.com/reference/android/content/Intent#FLAG_ACTIVITY_LAUNCH_ADJACENT
|
||||||
targetClass = PandemoniumEditor.class;
|
var launchAdjacent =
|
||||||
launchAdjacent = false;
|
Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && (isInMultiWindowMode || isLargeScreen)
|
||||||
break;
|
|
||||||
|
for (arg in args) {
|
||||||
|
if (EDITOR_ARG == arg) {
|
||||||
|
targetClass = PandemoniumEditor::class.java
|
||||||
|
launchAdjacent = false
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
if (PROJECT_MANAGER_ARG.equals(arg)) {
|
if (PROJECT_MANAGER_ARG == arg) {
|
||||||
targetClass = PandemoniumProjectManager.class;
|
targetClass = PandemoniumProjectManager::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)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the screen's density scale
|
||||||
|
protected val isLargeScreen: Boolean
|
||||||
|
// 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
|
||||||
|
val scale = resources.displayMetrics.density
|
||||||
|
|
||||||
|
// Get the minimum window size
|
||||||
|
val minSize = min(metrics.bounds.width(), metrics.bounds.height()).toFloat()
|
||||||
|
val minSizeDp = minSize / scale
|
||||||
|
return minSizeDp >= 840f // Correspond to the EXPANDED window size class.
|
||||||
}
|
}
|
||||||
|
|
||||||
startActivity(newInstance);
|
override fun setRequestedOrientation(requestedOrientation: Int) {
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isLargeScreen() {
|
|
||||||
WindowMetrics metrics =
|
|
||||||
WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(this);
|
|
||||||
|
|
||||||
// Get the screen's density scale
|
|
||||||
float scale = getResources().getDisplayMetrics().density;
|
|
||||||
|
|
||||||
// Get the minimum window size
|
|
||||||
float minSize = Math.min(metrics.getBounds().width(), metrics.getBounds().height());
|
|
||||||
float minSizeDp = minSize / scale;
|
|
||||||
return minSizeDp >= 840f; // Correspond to the EXPANDED window size class.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setRequestedOrientation(int requestedOrientation) {
|
|
||||||
if (!overrideOrientationRequest()) {
|
if (!overrideOrientationRequest()) {
|
||||||
super.setRequestedOrientation(requestedOrientation);
|
super.setRequestedOrientation(requestedOrientation)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Android Editor sets its own orientation via its AndroidManifest
|
* The Android Editor sets its own orientation via its AndroidManifest
|
||||||
*/
|
*/
|
||||||
protected boolean overrideOrientationRequest() {
|
protected open fun overrideOrientationRequest() = true
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* PandemoniumGame.java */
|
/* PandemoniumGame.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 net.relintai.pandemonium.editor;
|
package net.relintai.pandemonium.editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drives the 'run project' window of the Pandemonium Editor.
|
* Drives the 'run project' window of the Pandemonium Editor.
|
||||||
*/
|
*/
|
||||||
public class PandemoniumGame extends PandemoniumEditor {
|
class PandemoniumGame : PandemoniumEditor {
|
||||||
protected boolean overrideOrientationRequest() {
|
override fun overrideOrientationRequest() = false
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* PandemoniumProjectManager.java */
|
/* PandemoniumProjectManager.kt */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
/* This file is part of: */
|
/* This file is part of: */
|
||||||
/* GODOT ENGINE */
|
/* GODOT ENGINE */
|
||||||
@ -28,14 +28,15 @@
|
|||||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||||
/*************************************************************************/
|
/*************************************************************************/
|
||||||
|
|
||||||
package net.relintai.pandemonium.editor;
|
package net.relintai.pandemonium.editor
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Launcher activity for the Pandemonium Android Editor.
|
* Launcher activity for the Pandemonium 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 PandemoniumEditor} activity.
|
* [PandemoniumEditor] activity.
|
||||||
*/
|
*/
|
||||||
public class PandemoniumProjectManager extends PandemoniumEditor {
|
|
||||||
}
|
class PandemoniumProjectManager : PandemoniumEditor()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user