editor_run_native.cpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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. #include "editor_run_native.h"
  31. #include "editor/editor_node.h"
  32. #include "editor/editor_scale.h"
  33. #include "editor/editor_settings.h"
  34. #include "editor/export/editor_export.h"
  35. #include "editor/export/editor_export_platform.h"
  36. #include "scene/resources/image_texture.h"
  37. void EditorRunNative::_notification(int p_what) {
  38. switch (p_what) {
  39. case NOTIFICATION_THEME_CHANGED: {
  40. remote_debug->set_icon(get_editor_theme_icon(SNAME("PlayRemote")));
  41. } break;
  42. case NOTIFICATION_PROCESS: {
  43. bool changed = EditorExport::get_singleton()->poll_export_platforms() || first;
  44. if (changed) {
  45. PopupMenu *popup = remote_debug->get_popup();
  46. popup->clear();
  47. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  48. Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i);
  49. if (eep.is_null()) {
  50. continue;
  51. }
  52. int dc = MIN(eep->get_options_count(), 9000);
  53. if (dc > 0) {
  54. popup->add_icon_item(eep->get_run_icon(), eep->get_name(), -1);
  55. popup->set_item_disabled(-1, true);
  56. for (int j = 0; j < dc; j++) {
  57. popup->add_icon_item(eep->get_option_icon(j), eep->get_option_label(j), 10000 * i + j);
  58. popup->set_item_tooltip(-1, eep->get_option_tooltip(j));
  59. popup->set_item_indent(-1, 2);
  60. }
  61. }
  62. }
  63. if (popup->get_item_count() == 0) {
  64. remote_debug->set_disabled(true);
  65. remote_debug->set_tooltip_text(TTR("No Remote Debug export presets configured."));
  66. } else {
  67. remote_debug->set_disabled(false);
  68. remote_debug->set_tooltip_text(TTR("Remote Debug"));
  69. }
  70. first = false;
  71. }
  72. } break;
  73. }
  74. }
  75. Error EditorRunNative::start_run_native(int p_id) {
  76. if (p_id < 0) {
  77. return OK;
  78. }
  79. int platform = p_id / 10000;
  80. int idx = p_id % 10000;
  81. if (!EditorNode::get_singleton()->ensure_main_scene(true)) {
  82. resume_id = p_id;
  83. return OK;
  84. }
  85. Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(platform);
  86. ERR_FAIL_COND_V(eep.is_null(), ERR_UNAVAILABLE);
  87. Ref<EditorExportPreset> preset;
  88. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  89. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  90. if (ep->is_runnable() && ep->get_platform() == eep) {
  91. preset = ep;
  92. break;
  93. }
  94. }
  95. if (preset.is_null()) {
  96. 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."));
  97. return ERR_UNAVAILABLE;
  98. }
  99. emit_signal(SNAME("native_run"), preset);
  100. int flags = 0;
  101. bool deploy_debug_remote = is_deploy_debug_remote_enabled();
  102. bool deploy_dumb = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_file_server", false);
  103. bool debug_collisions = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_collisions", false);
  104. bool debug_navigation = EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_debug_navigation", false);
  105. if (deploy_debug_remote) {
  106. flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG;
  107. }
  108. if (deploy_dumb) {
  109. flags |= EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT;
  110. }
  111. if (debug_collisions) {
  112. flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISIONS;
  113. }
  114. if (debug_navigation) {
  115. flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION;
  116. }
  117. eep->clear_messages();
  118. Error err = eep->run(preset, idx, flags);
  119. result_dialog_log->clear();
  120. if (eep->fill_log_messages(result_dialog_log, err)) {
  121. if (eep->get_worst_message_type() >= EditorExportPlatform::EXPORT_MESSAGE_ERROR) {
  122. result_dialog->popup_centered_ratio(0.5);
  123. }
  124. }
  125. return err;
  126. }
  127. void EditorRunNative::resume_run_native() {
  128. start_run_native(resume_id);
  129. }
  130. void EditorRunNative::_bind_methods() {
  131. ADD_SIGNAL(MethodInfo("native_run", PropertyInfo(Variant::OBJECT, "preset", PROPERTY_HINT_RESOURCE_TYPE, "EditorExportPreset")));
  132. }
  133. bool EditorRunNative::is_deploy_debug_remote_enabled() const {
  134. return EditorSettings::get_singleton()->get_project_metadata("debug_options", "run_deploy_remote_debug", false);
  135. }
  136. EditorRunNative::EditorRunNative() {
  137. remote_debug = memnew(MenuButton);
  138. remote_debug->get_popup()->connect("id_pressed", callable_mp(this, &EditorRunNative::start_run_native));
  139. remote_debug->set_tooltip_text(TTR("Remote Debug"));
  140. remote_debug->set_disabled(true);
  141. add_child(remote_debug);
  142. result_dialog = memnew(AcceptDialog);
  143. result_dialog->set_title(TTR("Project Run"));
  144. result_dialog_log = memnew(RichTextLabel);
  145. result_dialog_log->set_custom_minimum_size(Size2(300, 80) * EDSCALE);
  146. result_dialog->add_child(result_dialog_log);
  147. add_child(result_dialog);
  148. result_dialog->hide();
  149. set_process(true);
  150. }