editor_run_native.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*************************************************************************/
  2. /* editor_run_native.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "editor_run_native.h"
  30. #include "editor_import_export.h"
  31. void EditorRunNative::_notification(int p_what) {
  32. if (p_what==NOTIFICATION_ENTER_SCENE) {
  33. List<StringName> ep;
  34. EditorImportExport::get_singleton()->get_export_platforms(&ep);
  35. ep.sort_custom<StringName::AlphCompare>();
  36. for(List<StringName>::Element *E=ep.front();E;E=E->next()) {
  37. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(E->get());
  38. if (eep.is_null())
  39. continue;
  40. Ref<ImageTexture> icon = eep->get_logo();
  41. if (!icon.is_null()) {
  42. Image im = icon->get_data();
  43. im.clear_mipmaps();
  44. if (!im.empty()) {
  45. im.resize(16,16);
  46. Ref<ImageTexture> small_icon = memnew( ImageTexture);
  47. small_icon->create_from_image(im);
  48. MenuButton *mb = memnew( MenuButton );
  49. mb->get_popup()->connect("item_pressed",this,"_run_native",varray(E->get()));
  50. mb->set_icon(small_icon);
  51. add_child(mb);
  52. menus[E->get()]=mb;
  53. }
  54. }
  55. }
  56. }
  57. if (p_what==NOTIFICATION_PROCESS) {
  58. bool changed = EditorImportExport::get_singleton()->poll_export_platforms() || first;
  59. if (changed) {
  60. for(Map<StringName,MenuButton*>::Element *E=menus.front();E;E=E->next()) {
  61. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(E->key());
  62. MenuButton *mb = E->get();
  63. int dc = eep->get_device_count();
  64. if (dc==0) {
  65. mb->hide();
  66. } else {
  67. mb->get_popup()->clear();
  68. mb->show();
  69. for(int i=0;i<dc;i++) {
  70. mb->get_popup()->add_icon_item(get_icon("Play","EditorIcons"),eep->get_device_name(i));
  71. mb->get_popup()->set_item_tooltip(mb->get_popup()->get_item_count() -1,eep->get_device_info(i));
  72. }
  73. }
  74. }
  75. first=false;
  76. }
  77. }
  78. }
  79. void EditorRunNative::_run_native(int p_idx,const String& p_platform) {
  80. Ref<EditorExportPlatform> eep = EditorImportExport::get_singleton()->get_export_platform(p_platform);
  81. ERR_FAIL_COND(eep.is_null());
  82. eep->run(p_idx,deploy_dumb);
  83. }
  84. void EditorRunNative::_bind_methods() {
  85. ObjectTypeDB::bind_method("_run_native",&EditorRunNative::_run_native);
  86. }
  87. void EditorRunNative::set_deploy_dumb(bool p_enabled) {
  88. deploy_dumb=p_enabled;
  89. }
  90. bool EditorRunNative::is_deploy_dumb_enabled() const{
  91. return deploy_dumb;
  92. }
  93. EditorRunNative::EditorRunNative()
  94. {
  95. set_process(true);
  96. first=true;
  97. deploy_dumb=false;
  98. }