editor_run_native.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*************************************************************************/
  2. /* editor_run_native.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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_import_export.h"
  32. void EditorRunNative::_notification(int p_what) {
  33. if (p_what == NOTIFICATION_ENTER_TREE) {
  34. List<StringName> ep;
  35. EditorImportExport::get_singleton()->get_export_platforms(&ep);
  36. ep.sort_custom<StringName::AlphCompare>();
  37. for (List<StringName>::Element *E = ep.front(); E; E = E->next()) {
  38. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(E->get());
  39. if (eep.is_null())
  40. continue;
  41. Ref<ImageTexture> icon = eep->get_logo();
  42. if (!icon.is_null()) {
  43. Image im = icon->get_data();
  44. im.clear_mipmaps();
  45. if (!im.empty()) {
  46. im.resize(16, 16);
  47. Ref<ImageTexture> small_icon = memnew(ImageTexture);
  48. small_icon->create_from_image(im);
  49. MenuButton *mb = memnew(MenuButton);
  50. mb->get_popup()->connect("item_pressed", this, "_run_native", varray(E->get()));
  51. mb->connect("pressed", this, "_run_native", varray(-1, E->get()));
  52. mb->set_icon(small_icon);
  53. add_child(mb);
  54. menus[E->get()] = mb;
  55. }
  56. }
  57. }
  58. }
  59. if (p_what == NOTIFICATION_PROCESS) {
  60. bool changed = EditorImportExport::get_singleton()->poll_export_platforms() || first;
  61. if (changed) {
  62. for (Map<StringName, MenuButton *>::Element *E = menus.front(); E; E = E->next()) {
  63. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(E->key());
  64. MenuButton *mb = E->get();
  65. int dc = eep->get_device_count();
  66. if (dc == 0) {
  67. mb->hide();
  68. } else {
  69. mb->get_popup()->clear();
  70. mb->show();
  71. if (dc == 1) {
  72. mb->set_tooltip(eep->get_device_name(0) + "\n\n" + eep->get_device_info(0).strip_edges());
  73. } else {
  74. mb->set_tooltip("Select device from the list");
  75. for (int i = 0; i < dc; i++) {
  76. mb->get_popup()->add_icon_item(get_icon("Play", "EditorIcons"), eep->get_device_name(i));
  77. mb->get_popup()->set_item_tooltip(mb->get_popup()->get_item_count() - 1, eep->get_device_info(i).strip_edges());
  78. }
  79. }
  80. }
  81. }
  82. first = false;
  83. }
  84. }
  85. }
  86. void EditorRunNative::_run_native(int p_idx, const String &p_platform) {
  87. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(p_platform);
  88. ERR_FAIL_COND(eep.is_null());
  89. if (p_idx == -1) {
  90. if (eep->get_device_count() == 1) {
  91. menus[p_platform]->get_popup()->hide();
  92. p_idx = 0;
  93. } else {
  94. return;
  95. }
  96. }
  97. emit_signal("native_run");
  98. int flags = 0;
  99. if (deploy_debug_remote)
  100. flags |= EditorExportPlatform::EXPORT_REMOTE_DEBUG;
  101. if (deploy_dumb)
  102. flags |= EditorExportPlatform::EXPORT_DUMB_CLIENT;
  103. if (debug_collisions)
  104. flags |= EditorExportPlatform::EXPORT_VIEW_COLLISONS;
  105. if (debug_navigation)
  106. flags |= EditorExportPlatform::EXPORT_VIEW_NAVIGATION;
  107. eep->run(p_idx, flags);
  108. }
  109. void EditorRunNative::_bind_methods() {
  110. ObjectTypeDB::bind_method("_run_native", &EditorRunNative::_run_native);
  111. ADD_SIGNAL(MethodInfo("native_run"));
  112. }
  113. void EditorRunNative::set_deploy_dumb(bool p_enabled) {
  114. deploy_dumb = p_enabled;
  115. }
  116. bool EditorRunNative::is_deploy_dumb_enabled() const {
  117. return deploy_dumb;
  118. }
  119. void EditorRunNative::set_deploy_debug_remote(bool p_enabled) {
  120. deploy_debug_remote = p_enabled;
  121. }
  122. bool EditorRunNative::is_deploy_debug_remote_enabled() const {
  123. return deploy_debug_remote;
  124. }
  125. void EditorRunNative::set_debug_collisions(bool p_debug) {
  126. debug_collisions = p_debug;
  127. }
  128. bool EditorRunNative::get_debug_collisions() const {
  129. return debug_collisions;
  130. }
  131. void EditorRunNative::set_debug_navigation(bool p_debug) {
  132. debug_navigation = p_debug;
  133. }
  134. bool EditorRunNative::get_debug_navigation() const {
  135. return debug_navigation;
  136. }
  137. EditorRunNative::EditorRunNative() {
  138. set_process(true);
  139. first = true;
  140. deploy_dumb = false;
  141. deploy_debug_remote = false;
  142. debug_collisions = false;
  143. debug_navigation = false;
  144. }