import_settings.cpp 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. /*************************************************************************/
  2. /* import_settings.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 "import_settings.h"
  30. #include "os/os.h"
  31. #include "editor_node.h"
  32. void ImportSettingsDialog::_item_pressed(int p_idx) {
  33. if (!edited)
  34. return;
  35. String p=edited->get_metadata(0);
  36. #if 0
  37. if (EditorImportDB::get_singleton()->is_image(p)) {
  38. uint32_t flags = EditorImportDB::get_singleton()->get_image_flags(p);
  39. bool pressed = !popup->is_item_checked(p_idx);
  40. if (pressed)
  41. flags|=(1<<p_idx);
  42. else
  43. flags&=~(1<<p_idx);
  44. EditorImportDB::get_singleton()->set_image_flags(p,flags);
  45. edited->set_text(2,_str_from_flags(flags));
  46. }
  47. #endif
  48. }
  49. void ImportSettingsDialog::_item_edited() {
  50. if (updating)
  51. return;
  52. TreeItem *it=tree->get_selected();
  53. int ec=tree->get_edited_column();
  54. String p=it->get_metadata(0);
  55. #if 0
  56. if (EditorImportDB::get_singleton()->is_image(p)) {
  57. if (ec==1) {
  58. EditorImportDB::get_singleton()->set_image_format(p,EditorImport::ImageFormat(int(it->get_range(1))));
  59. } else if (ec==2) {
  60. int flags = EditorImportDB::get_singleton()->get_image_flags(p);
  61. for(int i=0;i<popup->get_item_count();i++) {
  62. popup->set_item_checked(i,flags&(1<<i));
  63. }
  64. Rect2 r = tree->get_custom_popup_rect();
  65. popup->set_size(Size2(r.size.width,1));
  66. popup->set_pos(/*tree->get_global_pos()+*/r.pos+Point2(0,r.size.height));
  67. popup->popup();
  68. }
  69. edited=it;
  70. }
  71. #endif
  72. }
  73. void ImportSettingsDialog::_button_pressed(Object *p_button, int p_col, int p_id) {
  74. TreeItem *ti=p_button->cast_to<TreeItem>();
  75. if (!ti)
  76. return;
  77. String path = ti->get_metadata(0);
  78. print_line("PATH: "+path);
  79. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(path);
  80. ERR_FAIL_COND(rimd.is_null());
  81. Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
  82. ERR_FAIL_COND(!rimp.is_valid());
  83. rimp->import_dialog(path);
  84. hide();
  85. }
  86. bool ImportSettingsDialog::_generate_fs(TreeItem *p_parent,EditorFileSystemDirectory *p_dir) {
  87. bool valid=false;
  88. for(int i=0;i<p_dir->get_subdir_count();i++) {
  89. EditorFileSystemDirectory *sd=p_dir->get_subdir(i);
  90. TreeItem *ti = tree->create_item(p_parent);
  91. ti->set_text(0,sd->get_name()+"/");
  92. ti->set_icon(0,get_icon("Folder","EditorIcons"));
  93. if (!_generate_fs(ti,sd)) {
  94. memdelete(ti);
  95. } else {
  96. valid=true;
  97. }
  98. }
  99. for(int i=0;i<p_dir->get_file_count();i++) {
  100. String path=p_dir->get_file_path(i);
  101. if (!p_dir->get_file_meta(i))
  102. continue;
  103. valid=true;
  104. String f = p_dir->get_file(i);
  105. TreeItem *ti = tree->create_item(p_parent);
  106. String type = p_dir->get_file_type(i);
  107. Ref<Texture> t;
  108. if (has_icon(type,"EditorIcons"))
  109. t = get_icon(type,"EditorIcons");
  110. else
  111. t = get_icon("Object","EditorIcons");
  112. ti->set_icon(0,t);
  113. ti->set_text(0,f);
  114. // ti->add_button(0,get_icon("Reload","EditorIcons"));
  115. ti->set_metadata(0,p_dir->get_file_path(i));
  116. String tt = p_dir->get_file_path(i);
  117. if (p_dir->is_missing_sources(i)) {
  118. ti->set_icon(1,get_icon("ImportFail","EditorIcons"));
  119. Vector<String> missing = p_dir->get_missing_sources(i);
  120. for(int j=0;j<missing.size();j++) {
  121. tt+="\nmissing: "+missing[j];
  122. }
  123. } else
  124. ti->set_icon(1,get_icon("ImportCheck","EditorIcons"));
  125. ti->set_tooltip(0,tt);
  126. ti->set_tooltip(1,tt);
  127. }
  128. #if 0
  129. if (!EditorImportDB::get_singleton()->is_image(path) && !EditorImportDB::get_singleton()->is_scene(path))
  130. continue;
  131. String f = p_dir->get_file(i);
  132. TreeItem *ti = tree->create_item(p_parent);
  133. ti->set_text(0,f);
  134. String type = p_dir->get_file_type(i);
  135. Ref<Texture> icon = get_icon( (has_icon(type,"EditorIcons")?type:String("Object")),"EditorIcons");
  136. if (EditorImportDB::get_singleton()->is_image(path)) {
  137. ti->set_tooltip(0,"Type: Image\nSource: "+EditorImportDB::get_singleton()->get_file_source(path)+"\nSource MD5: "+EditorImportDB::get_singleton()->get_file_md5(path));
  138. ti->set_cell_mode(1,TreeItem::CELL_MODE_RANGE);
  139. ti->set_editable(1,true);
  140. ti->set_range_config(1,0,3,1);
  141. ti->set_range(1,EditorImportDB::get_singleton()->get_image_format(path));
  142. ti->set_text(1,texformat);
  143. ti->set_cell_mode(2,TreeItem::CELL_MODE_CUSTOM);
  144. ti->set_editable(2,true);
  145. ti->set_metadata(0,path);
  146. String txt;
  147. uint32_t flags=EditorImportDB::get_singleton()->get_image_flags(path);
  148. txt=_str_from_flags(flags);
  149. ti->set_text(2,txt);
  150. }
  151. ti->set_icon(0, icon);
  152. valid=true;
  153. #endif
  154. return valid;
  155. }
  156. void ImportSettingsDialog::update_tree() {
  157. updating=true;
  158. tree->clear();
  159. edited=NULL;
  160. TreeItem *root = tree->create_item();
  161. EditorFileSystemDirectory *fs = EditorFileSystem::get_singleton()->get_filesystem();
  162. _generate_fs(root,fs);
  163. updating=false;
  164. }
  165. void ImportSettingsDialog::_notification(int p_what) {
  166. if (p_what==NOTIFICATION_ENTER_SCENE) {
  167. EditorFileSystem::get_singleton()->connect("filesystem_changed",this,"update_tree");
  168. }
  169. }
  170. void ImportSettingsDialog::_bind_methods() {
  171. ObjectTypeDB::bind_method("update_tree",&ImportSettingsDialog::update_tree);
  172. ObjectTypeDB::bind_method("_item_edited",&ImportSettingsDialog::_item_edited);
  173. ObjectTypeDB::bind_method("_item_pressed",&ImportSettingsDialog::_item_pressed);
  174. ObjectTypeDB::bind_method("_button_pressed",&ImportSettingsDialog::_button_pressed);
  175. }
  176. void ImportSettingsDialog::popup_import_settings() {
  177. update_tree();
  178. popup_centered_ratio();
  179. }
  180. void ImportSettingsDialog::ok_pressed() {
  181. TreeItem *ti = tree->get_selected();
  182. if (!ti)
  183. return;
  184. String path = ti->get_metadata(0);
  185. print_line("PATH: "+path);
  186. Ref<ResourceImportMetadata> rimd = ResourceLoader::load_import_metadata(path);
  187. ERR_FAIL_COND(rimd.is_null());
  188. Ref<EditorImportPlugin> rimp = EditorImportExport::get_singleton()->get_import_plugin_by_name(rimd->get_editor());
  189. ERR_FAIL_COND(!rimp.is_valid());
  190. rimp->import_dialog(path);
  191. hide();
  192. }
  193. ImportSettingsDialog::ImportSettingsDialog(EditorNode *p_editor) {
  194. editor=p_editor;
  195. get_ok()->set_text("Close");
  196. tree = memnew( Tree );
  197. add_child(tree);
  198. set_child_rect(tree);
  199. set_title("Imported Resources");
  200. texformat="Keep,None,Disk,VRAM";
  201. tree->set_hide_root(true);
  202. tree->set_columns(2);
  203. tree->set_column_expand(1,false);
  204. tree->set_column_min_width(1,20);
  205. tree->connect("item_edited",this,"_item_edited");
  206. tree->connect("button_pressed",this,"_button_pressed");
  207. // add_button("Re-Import","reimport");
  208. get_ok()->set_text("Re-Import");
  209. get_cancel()->set_text("Close");
  210. updating=false;
  211. edited=NULL;
  212. set_hide_on_ok(false);
  213. }