| 1 | /**************************************************************************/ |
| 2 | /* editor_run_native.cpp */ |
| 3 | /**************************************************************************/ |
| 4 | /* This file is part of: */ |
| 5 | /* GODOT ENGINE */ |
| 6 | /* https://godotengine.org */ |
| 7 | /**************************************************************************/ |
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ |
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ |
| 10 | /* */ |
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining */ |
| 12 | /* a copy of this software and associated documentation files (the */ |
| 13 | /* "Software"), to deal in the Software without restriction, including */ |
| 14 | /* without limitation the rights to use, copy, modify, merge, publish, */ |
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to */ |
| 16 | /* permit persons to whom the Software is furnished to do so, subject to */ |
| 17 | /* the following conditions: */ |
| 18 | /* */ |
| 19 | /* The above copyright notice and this permission notice shall be */ |
| 20 | /* included in all copies or substantial portions of the Software. */ |
| 21 | /* */ |
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ |
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ |
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ |
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ |
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ |
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ |
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ |
| 29 | /**************************************************************************/ |
| 30 | |
| 31 | #include "editor_run_native.h" |
| 32 | |
| 33 | #include "editor/editor_node.h" |
| 34 | #include "editor/editor_scale.h" |
| 35 | #include "editor/editor_settings.h" |
| 36 | #include "editor/export/editor_export.h" |
| 37 | #include "editor/export/editor_export_platform.h" |
| 38 | #include "scene/resources/image_texture.h" |
| 39 | |
| 40 | void EditorRunNative::_notification(int p_what) { |
| 41 | switch (p_what) { |
| 42 | case NOTIFICATION_THEME_CHANGED: { |
| 43 | remote_debug->set_icon(get_editor_theme_icon(SNAME("PlayRemote" ))); |
| 44 | } break; |
| 45 | |
| 46 | case NOTIFICATION_PROCESS: { |
| 47 | bool changed = EditorExport::get_singleton()->poll_export_platforms() || first; |
| 48 | |
| 49 | if (changed) { |
| 50 | PopupMenu * = remote_debug->get_popup(); |
| 51 | popup->clear(); |
| 52 | for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) { |
| 53 | Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i); |
| 54 | if (eep.is_null()) { |
| 55 | continue; |
| 56 | } |
| 57 | int dc = MIN(eep->get_options_count(), 9000); |
| 58 | if (dc > 0) { |
| 59 | popup->add_icon_item(eep->get_run_icon(), eep->get_name(), -1); |
| 60 | popup->set_item_disabled(-1, true); |
| 61 | for (int j = 0; j < dc; j++) { |
| 62 | popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * i + j); |
| 63 | popup->set_item_tooltip(-1, eep->get_option_tooltip(j)); |
| 64 | popup->set_item_indent(-1, 2); |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | if (popup->get_item_count() == 0) { |
| 69 | remote_debug->set_disabled(true); |
| 70 | remote_debug->set_tooltip_text(TTR("No Remote Debug export presets configured." )); |
| 71 | } else { |
| 72 | remote_debug->set_disabled(false); |
| 73 | remote_debug->set_tooltip_text(TTR("Remote Debug" )); |
| 74 | } |
| 75 | |
| 76 | first = false; |
| 77 | } |
| 78 | } break; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | Error EditorRunNative::start_run_native(int p_id) { |
| 83 | if (p_id < 0) { |
| 84 | return OK; |
| 85 | } |
| 86 | |
| 87 | int platform = p_id / 10000; |
| 88 | int idx = p_id % 10000; |
| 89 | |
| 90 | if (!EditorNode::get_singleton()->ensure_main_scene(true)) { |
| 91 | resume_id = p_id; |
| 92 | return OK; |
| 93 | } |
| 94 | |
| 95 | Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(platform); |
| 96 | ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE); |
| 97 | |
| 98 | Ref<EditorExportPreset> preset; |
| 99 | |
| 100 | for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) { |
| 101 | Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i); |
| 102 | if (ep->is_runnable() && ep->get_platform() == eep) { |
| 103 | preset = ep; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (preset.is_null()) { |
| 109 | EditorNode::get_singleton()->show_warning(TTR("No runnable export preset found for this platform.\nPlease add a runnable preset in the Export menu or define an existing preset as runnable." )); |
| 110 | return ERR_UNAVAILABLE; |
| 111 | } |
| 112 | |
| 113 | emit_signal(SNAME("native_run" ), preset); |
| 114 | |
| 115 | int flags = 0; |
| 116 | |
| 117 | bool deploy_debug_remote = is_deploy_debug_remote_enabled(); |
| 118 | bool deploy_dumb = EditorSettings::get_singleton()->get_project_metadata("debug_options" , "run_file_server" , false); |
| 119 | bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options" , "run_debug_collisions" , false); |
| 120 | bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options" , "run_debug_navigation" , false); |
| 121 | |
| 122 | if (deploy_debug_remote) { |
| 123 | flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG; |
| 124 | } |
| 125 | if (deploy_dumb) { |
| 126 | flags |= EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT; |
| 127 | } |
| 128 | if (debug_collisions) { |
| 129 | flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISIONS; |
| 130 | } |
| 131 | if (debug_navigation) { |
| 132 | flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION; |
| 133 | } |
| 134 | |
| 135 | eep->clear_messages(); |
| 136 | Error err = eep->run(preset, idx, flags); |
| 137 | result_dialog_log->clear(); |
| 138 | if (eep->fill_log_messages(result_dialog_log, err)) { |
| 139 | if (eep->get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_ERROR) { |
| 140 | result_dialog->popup_centered_ratio(0.5); |
| 141 | } |
| 142 | } |
| 143 | return err; |
| 144 | } |
| 145 | |
| 146 | void EditorRunNative::resume_run_native() { |
| 147 | start_run_native(resume_id); |
| 148 | } |
| 149 | |
| 150 | void EditorRunNative::_bind_methods() { |
| 151 | ADD_SIGNAL(MethodInfo("native_run" , PropertyInfo(Variant::OBJECT, "preset" , PROPERTY_HINT_RESOURCE_TYPE, "EditorExportPreset" ))); |
| 152 | } |
| 153 | |
| 154 | bool EditorRunNative::is_deploy_debug_remote_enabled() const { |
| 155 | return EditorSettings::get_singleton()->get_project_metadata("debug_options" , "run_deploy_remote_debug" , false); |
| 156 | } |
| 157 | |
| 158 | EditorRunNative::EditorRunNative() { |
| 159 | remote_debug = memnew(MenuButton); |
| 160 | remote_debug->get_popup()->connect("id_pressed" , callable_mp(this, &EditorRunNative::start_run_native)); |
| 161 | remote_debug->set_tooltip_text(TTR("Remote Debug" )); |
| 162 | remote_debug->set_disabled(true); |
| 163 | |
| 164 | add_child(remote_debug); |
| 165 | |
| 166 | result_dialog = memnew(AcceptDialog); |
| 167 | result_dialog->set_title(TTR("Project Run" )); |
| 168 | result_dialog_log = memnew(RichTextLabel); |
| 169 | result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE); |
| 170 | result_dialog->add_child(result_dialog_log); |
| 171 | |
| 172 | add_child(result_dialog); |
| 173 | result_dialog->hide(); |
| 174 | |
| 175 | set_process(true); |
| 176 | } |
| 177 | |