diff options
author | Tomasz Chabora <kobewi4e@gmail.com> | 2019-03-22 02:08:28 +0100 |
---|---|---|
committer | Tomasz Chabora <kobewi4e@gmail.com> | 2019-05-31 16:02:57 +0200 |
commit | 9e18e94dc1cf70d3e4982828cf87317382abc326 (patch) | |
tree | bb299056eedd5c4d97b14a71f74b12754289bf44 /editor | |
parent | 9c3ddf05cb9c59817d885e9daca6e8f61c89dc97 (diff) |
Ensure main scene is set when running on device
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_node.cpp | 61 | ||||
-rw-r--r-- | editor/editor_node.h | 2 | ||||
-rw-r--r-- | editor/editor_run_native.cpp | 12 | ||||
-rw-r--r-- | editor/editor_run_native.h | 5 |
4 files changed, 57 insertions, 23 deletions
diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 6140412a32..fbd3d9b4bd 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1265,7 +1265,12 @@ void EditorNode::_dialog_action(String p_file) { ProjectSettings::get_singleton()->set("application/run/main_scene", p_file); ProjectSettings::get_singleton()->save(); //would be nice to show the project manager opened with the highlighted field.. - _run(false, ""); // automatically run the project + + if (pick_main_scene->has_meta("from_native") && (bool)pick_main_scene->get_meta("from_native")) { + run_native->resume_run_native(); + } else { + _run(false, ""); // automatically run the project + } } break; case FILE_CLOSE: case FILE_CLOSE_ALL_AND_QUIT: @@ -1737,28 +1742,7 @@ void EditorNode::_run(bool p_current, const String &p_custom) { if (run_filename == "") { //evidently, run the scene - main_scene = GLOBAL_DEF("application/run/main_scene", ""); - if (main_scene == "") { - - current_option = -1; - pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in \"Project Settings\" under the 'application' category.")); - pick_main_scene->popup_centered_minsize(); - return; - } - - if (!FileAccess::exists(main_scene)) { - - current_option = -1; - pick_main_scene->set_text(vformat(TTR("Selected scene '%s' does not exist, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); - pick_main_scene->popup_centered_minsize(); - return; - } - - if (ResourceLoader::get_resource_type(main_scene) != "PackedScene") { - - current_option = -1; - pick_main_scene->set_text(vformat(TTR("Selected scene '%s' is not a scene file, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); - pick_main_scene->popup_centered_minsize(); + if (!ensure_main_scene(false)) { return; } } @@ -4001,6 +3985,37 @@ bool EditorNode::has_scenes_in_session() { return !scenes.empty(); } +bool EditorNode::ensure_main_scene(bool p_from_native) { + pick_main_scene->set_meta("from_native", p_from_native); //whether from play button or native run + String main_scene = GLOBAL_DEF("application/run/main_scene", ""); + + if (main_scene == "") { + + current_option = -1; + pick_main_scene->set_text(TTR("No main scene has ever been defined, select one?\nYou can change it later in \"Project Settings\" under the 'application' category.")); + pick_main_scene->popup_centered_minsize(); + return false; + } + + if (!FileAccess::exists(main_scene)) { + + current_option = -1; + pick_main_scene->set_text(vformat(TTR("Selected scene '%s' does not exist, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); + pick_main_scene->popup_centered_minsize(); + return false; + } + + if (ResourceLoader::get_resource_type(main_scene) != "PackedScene") { + + current_option = -1; + pick_main_scene->set_text(vformat(TTR("Selected scene '%s' is not a scene file, select a valid one?\nYou can change it later in \"Project Settings\" under the 'application' category."), main_scene)); + pick_main_scene->popup_centered_minsize(); + return false; + } + + return true; +} + void EditorNode::_update_layouts_menu() { editor_layouts->clear(); diff --git a/editor/editor_node.h b/editor/editor_node.h index 267c70c773..22da2c43fb 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -804,6 +804,8 @@ public: static void add_init_callback(EditorNodeInitCallback p_callback) { _init_callbacks.push_back(p_callback); } static void add_build_callback(EditorBuildCallback p_callback); + + bool ensure_main_scene(bool p_from_native); }; struct EditorProgress { diff --git a/editor/editor_run_native.cpp b/editor/editor_run_native.cpp index 06cadca1c0..c7c86df2ac 100644 --- a/editor/editor_run_native.cpp +++ b/editor/editor_run_native.cpp @@ -97,6 +97,12 @@ void EditorRunNative::_notification(int p_what) { void EditorRunNative::_run_native(int p_idx, int p_platform) { + if (!EditorNode::get_singleton()->ensure_main_scene(true)) { + resume_idx = p_idx; + resume_platform = p_platform; + return; + } + Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(p_platform); ERR_FAIL_COND(eep.is_null()); /*if (p_idx == -1) { @@ -139,6 +145,10 @@ void EditorRunNative::_run_native(int p_idx, int p_platform) { eep->run(preset, p_idx, flags); } +void EditorRunNative::resume_run_native() { + _run_native(resume_idx, resume_platform); +} + void EditorRunNative::_bind_methods() { ClassDB::bind_method("_run_native", &EditorRunNative::_run_native); @@ -193,4 +203,6 @@ EditorRunNative::EditorRunNative() { deploy_debug_remote = false; debug_collisions = false; debug_navigation = false; + resume_idx = 0; + resume_platform = 0; } diff --git a/editor/editor_run_native.h b/editor/editor_run_native.h index 10cca014cf..d62c982725 100644 --- a/editor/editor_run_native.h +++ b/editor/editor_run_native.h @@ -45,6 +45,9 @@ class EditorRunNative : public HBoxContainer { bool debug_collisions; bool debug_navigation; + int resume_idx; + int resume_platform; + void _run_native(int p_idx, int p_platform); protected: @@ -64,6 +67,8 @@ public: void set_debug_navigation(bool p_debug); bool get_debug_navigation() const; + void resume_run_native(); + EditorRunNative(); }; |