editor_run_native.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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_export.h"
  32. #include "editor_node.h"
  33. #include "editor_scale.h"
  34. void EditorRunNative::_notification(int p_what) {
  35. if (p_what == NOTIFICATION_ENTER_TREE) {
  36. for (int i = 0; i < EditorExport::get_singleton()->get_export_platform_count(); i++) {
  37. Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(i);
  38. if (eep.is_null())
  39. continue;
  40. Ref<ImageTexture> icon = eep->get_run_icon();
  41. if (!icon.is_null()) {
  42. Ref<Image> im = icon->get_data();
  43. im = im->duplicate();
  44. im->clear_mipmaps();
  45. if (!im->empty()) {
  46. im->resize(16 * EDSCALE, 16 * EDSCALE);
  47. Ref<ImageTexture> small_icon;
  48. small_icon.instance();
  49. small_icon->create_from_image(im, 0);
  50. MenuButton *mb = memnew(MenuButton);
  51. mb->get_popup()->connect("id_pressed", this, "_run_native", varray(i));
  52. //mb->connect("pressed", this, "_run_native", varray(-1, i));
  53. mb->set_icon(small_icon);
  54. add_child(mb);
  55. menus[i] = mb;
  56. }
  57. }
  58. }
  59. }
  60. if (p_what == NOTIFICATION_PROCESS) {
  61. bool changed = EditorExport::get_singleton()->poll_export_platforms() || first;
  62. if (changed) {
  63. for (Map<int, MenuButton *>::Element *E = menus.front(); E; E = E->next()) {
  64. Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(E->key());
  65. MenuButton *mb = E->get();
  66. int dc = eep->get_device_count();
  67. if (dc == 0) {
  68. mb->hide();
  69. } else {
  70. mb->get_popup()->clear();
  71. mb->show();
  72. mb->set_tooltip(TTR("Select device from the list"));
  73. for (int i = 0; i < dc; i++) {
  74. mb->get_popup()->add_icon_item(get_icon("Play", "EditorIcons"), eep->get_device_name(i));
  75. mb->get_popup()->set_item_tooltip(mb->get_popup()->get_item_count() - 1, eep->get_device_info(i).strip_edges());
  76. }
  77. }
  78. }
  79. first = false;
  80. }
  81. }
  82. }
  83. void EditorRunNative::_run_native(int p_idx, int p_platform) {
  84. Ref<EditorExportPlatform> eep = EditorExport::get_singleton()->get_export_platform(p_platform);
  85. ERR_FAIL_COND(eep.is_null());
  86. /*if (p_idx == -1) {
  87. if (eep->get_device_count() == 1) {
  88. menus[p_platform]->get_popup()->hide();
  89. p_idx = 0;
  90. } else {
  91. return;
  92. }
  93. }*/
  94. Ref<EditorExportPreset> preset;
  95. for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
  96. Ref<EditorExportPreset> ep = EditorExport::get_singleton()->get_export_preset(i);
  97. if (ep->is_runnable() && ep->get_platform() == eep) {
  98. preset = ep;
  99. break;
  100. }
  101. }
  102. if (preset.is_null()) {
  103. EditorNode::get_singleton()->show_warning(TTR("No runnable export preset found for this platform.\nPlease add a runnable preset in the export menu."));
  104. return;
  105. }
  106. emit_signal("native_run");
  107. int flags = 0;
  108. if (deploy_debug_remote)
  109. flags |= EditorExportPlatform::DEBUG_FLAG_REMOTE_DEBUG;
  110. if (deploy_dumb)
  111. flags |= EditorExportPlatform::DEBUG_FLAG_DUMB_CLIENT;
  112. if (debug_collisions)
  113. flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_COLLISONS;
  114. if (debug_navigation)
  115. flags |= EditorExportPlatform::DEBUG_FLAG_VIEW_NAVIGATION;
  116. eep->run(preset, p_idx, flags);
  117. }
  118. void EditorRunNative::_bind_methods() {
  119. ClassDB::bind_method("_run_native", &EditorRunNative::_run_native);
  120. ADD_SIGNAL(MethodInfo("native_run"));
  121. }
  122. void EditorRunNative::set_deploy_dumb(bool p_enabled) {
  123. deploy_dumb = p_enabled;
  124. }
  125. bool EditorRunNative::is_deploy_dumb_enabled() const {
  126. return deploy_dumb;
  127. }
  128. void EditorRunNative::set_deploy_debug_remote(bool p_enabled) {
  129. deploy_debug_remote = p_enabled;
  130. }
  131. bool EditorRunNative::is_deploy_debug_remote_enabled() const {
  132. return deploy_debug_remote;
  133. }
  134. void EditorRunNative::set_debug_collisions(bool p_debug) {
  135. debug_collisions = p_debug;
  136. }
  137. bool EditorRunNative::get_debug_collisions() const {
  138. return debug_collisions;
  139. }
  140. void EditorRunNative::set_debug_navigation(bool p_debug) {
  141. debug_navigation = p_debug;
  142. }
  143. bool EditorRunNative::get_debug_navigation() const {
  144. return debug_navigation;
  145. }
  146. EditorRunNative::EditorRunNative() {
  147. set_process(true);
  148. first = true;
  149. deploy_dumb = false;
  150. deploy_debug_remote = false;
  151. debug_collisions = false;
  152. debug_navigation = false;
  153. }