Implemented switching between the running game and the editor in the android editor.

This commit is contained in:
Relintai 2023-06-15 10:21:23 +02:00
parent c68ec30899
commit c978f27634
9 changed files with 121 additions and 2 deletions

View File

@ -190,6 +190,47 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
return instanceId
}
override fun enableForStealingFocus(processId: Int) {
if (shouldGameLaunchAdjacent()) {
return;
}
var reorder_intent : Intent? = null;
when (processId) {
GAME_ID -> {
reorder_intent = Intent(this, PandemoniumGame::class.java);
}
EDITOR_ID -> {
reorder_intent = Intent(this, PandemoniumEditor::class.java);
}
PROJECT_MANAGER_ID -> {
reorder_intent = Intent(this, PandemoniumProjectManager::class.java);
}
else -> {
// An unknown PID means the original editor instance
reorder_intent = Intent(this, PandemoniumEditor::class.java);
}
}
if (reorder_intent != null) {
reorder_intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
reorder_intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(reorder_intent);
}
}
override fun moveWindowToForeground() {
if (shouldGameLaunchAdjacent()) {
return;
}
var reorder_intent : Intent = Intent(this, javaClass);
reorder_intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
reorder_intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(reorder_intent);
}
override fun onPandemoniumForceQuit(pandemoniumInstanceId: Int): Boolean {
val processNameSuffix = when (pandemoniumInstanceId) {
GAME_ID -> {
@ -261,7 +302,7 @@ open class PandemoniumEditor : FullScreenPandemoniumApp() {
private fun shouldGameLaunchAdjacent(): Boolean {
protected open fun shouldGameLaunchAdjacent(): Boolean {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
try {
when (Integer.parseInt(PandemoniumLib.getEditorSetting("run/window_placement/android_window"))) {

View File

@ -30,10 +30,15 @@
package net.relintai.pandemonium.editor
import android.content.Intent
import android.os.*
/**
* Drives the 'run project' window of the Pandemonium Editor.
*/
class PandemoniumGame : PandemoniumEditor() {
private var isAdjacentFlagSet = false
override fun overrideOrientationRequest() = false
override fun enableLongPressGestures() = false
@ -44,4 +49,14 @@ class PandemoniumGame : PandemoniumEditor() {
// Nothing to do.. by the time we get here, the project permissions will have already
// been requested by the Editor window.
}
override fun onCreate(savedInstanceState : Bundle?) {
isAdjacentFlagSet = (getIntent().getFlags() and Intent.FLAG_ACTIVITY_LAUNCH_ADJACENT) != 0;
super.onCreate(savedInstanceState);
}
override fun shouldGameLaunchAdjacent(): Boolean {
return isAdjacentFlagSet
}
}

View File

@ -42,5 +42,9 @@ class PandemoniumProjectManager : PandemoniumEditor() {
override fun checkForProjectPermissionsToEnable() {
// Nothing to do here.. we have yet to select a project to load.
}
override fun shouldGameLaunchAdjacent(): Boolean {
return false
}
}

View File

@ -558,6 +558,26 @@ public class Pandemonium extends Fragment implements SensorEventListener, IDownl
});
}
/**
* Used by the native code (java_pandemonium_wrapper.h).
*/
@Keep
public void enableForStealingFocus(int processId) {
if (pandemoniumHost != null) {
pandemoniumHost.enableForStealingFocus(processId);
}
}
/**
* Used by the native code (java_pandemonium_wrapper.h).
*/
@Keep
public void moveWindowToForeground() {
if (pandemoniumHost != null) {
pandemoniumHost.moveWindowToForeground();
}
}
public int getGLESVersionCode() {
ActivityManager am = (ActivityManager)getContext().getSystemService(Context.ACTIVITY_SERVICE);
ConfigurationInfo deviceInfo = am.getDeviceConfigurationInfo();
@ -1264,7 +1284,7 @@ public class Pandemonium extends Fragment implements SensorEventListener, IDownl
@Keep
private int createNewPandemoniumInstance(String[] args) {
if (pandemoniumHost != null) {
pandemoniumHost.onNewPandemoniumInstanceRequested(args);
return pandemoniumHost.onNewPandemoniumInstanceRequested(args);
}
return 0;

View File

@ -86,4 +86,10 @@ public interface PandemoniumHost {
default int onNewPandemoniumInstanceRequested(String[] args) {
return 0;
}
default public void enableForStealingFocus(int processId) {
}
default public void moveWindowToForeground() {
}
}

View File

@ -66,6 +66,8 @@ PandemoniumJavaWrapper::PandemoniumJavaWrapper(JNIEnv *p_env, jobject p_activity
_finish = p_env->GetMethodID(pandemonium_class, "forceQuit", "(I)Z");
_set_keep_screen_on = p_env->GetMethodID(pandemonium_class, "setKeepScreenOn", "(Z)V");
_alert = p_env->GetMethodID(pandemonium_class, "alert", "(Ljava/lang/String;Ljava/lang/String;)V");
_enable_for_stealing_focus = p_env->GetMethodID(pandemonium_class, "enableForStealingFocus", "(I)V");
_move_window_to_foreground = p_env->GetMethodID(pandemonium_class, "moveWindowToForeground", "()V");
_get_GLES_version_code = p_env->GetMethodID(pandemonium_class, "getGLESVersionCode", "()I");
_get_clipboard = p_env->GetMethodID(pandemonium_class, "getClipboard", "()Ljava/lang/String;");
_set_clipboard = p_env->GetMethodID(pandemonium_class, "setClipboard", "(Ljava/lang/String;)V");
@ -252,6 +254,23 @@ void PandemoniumJavaWrapper::alert(const String &p_message, const String &p_titl
}
}
void PandemoniumJavaWrapper::enable_for_stealing_focus(int pid) {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND(env == nullptr);
if (_enable_for_stealing_focus) {
env->CallVoidMethod(pandemonium_instance, _enable_for_stealing_focus, pid);
}
}
void PandemoniumJavaWrapper::move_window_to_foreground() {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND(env == nullptr);
if (_move_window_to_foreground) {
env->CallVoidMethod(pandemonium_instance, _move_window_to_foreground);
}
}
int PandemoniumJavaWrapper::get_gles_version_code() {
JNIEnv *env = get_jni_env();
ERR_FAIL_COND_V(env == nullptr, 0);

View File

@ -59,6 +59,8 @@ private:
jmethodID _finish = 0;
jmethodID _set_keep_screen_on = 0;
jmethodID _alert = 0;
jmethodID _enable_for_stealing_focus = 0;
jmethodID _move_window_to_foreground = 0;
jmethodID _get_GLES_version_code = 0;
jmethodID _get_clipboard = 0;
jmethodID _set_clipboard = 0;
@ -102,6 +104,8 @@ public:
bool force_quit(JNIEnv *p_env = NULL, int p_instance_id = 0);
void set_keep_screen_on(bool p_enabled);
void alert(const String &p_message, const String &p_title);
void enable_for_stealing_focus(int pid);
void move_window_to_foreground();
int get_gles_version_code();
bool has_get_clipboard();
String get_clipboard();

View File

@ -580,6 +580,13 @@ OS::ScreenOrientation OS_Android::get_screen_orientation() const {
return OS::ScreenOrientation(orientation);
}
void OS_Android::enable_for_stealing_focus(ProcessID pid) {
pandemonium_java->enable_for_stealing_focus(pid);
}
void OS_Android::move_window_to_foreground() {
pandemonium_java->move_window_to_foreground();
}
String OS_Android::get_unique_id() const {
String unique_id = pandemonium_io_java->get_unique_id();
if (unique_id != "")

View File

@ -176,6 +176,9 @@ public:
virtual void set_screen_orientation(ScreenOrientation p_orientation);
virtual ScreenOrientation get_screen_orientation() const;
virtual void enable_for_stealing_focus(ProcessID pid);
virtual void move_window_to_foreground();
virtual Error shell_open(String p_uri);
virtual String get_executable_path() const;
virtual String get_user_data_dir() const;