project_list.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. /**************************************************************************/
  2. /* project_list.h */
  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. #ifndef PROJECT_LIST_H
  31. #define PROJECT_LIST_H
  32. #include "core/io/config_file.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/scroll_container.h"
  35. class Button;
  36. class Label;
  37. class ProjectList;
  38. class TextureButton;
  39. class TextureRect;
  40. class ProjectListItemControl : public HBoxContainer {
  41. GDCLASS(ProjectListItemControl, HBoxContainer)
  42. VBoxContainer *main_vbox = nullptr;
  43. TextureButton *favorite_button = nullptr;
  44. Button *explore_button = nullptr;
  45. TextureRect *project_icon = nullptr;
  46. Label *project_title = nullptr;
  47. Label *project_path = nullptr;
  48. Label *last_edited_info = nullptr;
  49. Label *project_version = nullptr;
  50. TextureRect *project_unsupported_features = nullptr;
  51. HBoxContainer *tag_container = nullptr;
  52. bool project_is_missing = false;
  53. bool icon_needs_reload = true;
  54. bool is_selected = false;
  55. bool is_hovering = false;
  56. void _favorite_button_pressed();
  57. void _explore_button_pressed();
  58. protected:
  59. void _notification(int p_what);
  60. static void _bind_methods();
  61. public:
  62. void set_project_title(const String &p_title);
  63. void set_project_path(const String &p_path);
  64. void set_tags(const PackedStringArray &p_tags, ProjectList *p_parent_list);
  65. void set_project_icon(const Ref<Texture2D> &p_icon);
  66. void set_last_edited_info(const String &p_info);
  67. void set_project_version(const String &p_version);
  68. void set_unsupported_features(PackedStringArray p_features);
  69. bool should_load_project_icon() const;
  70. void set_selected(bool p_selected);
  71. void set_is_favorite(bool p_favorite);
  72. void set_is_missing(bool p_missing);
  73. void set_is_grayed(bool p_grayed);
  74. ProjectListItemControl();
  75. };
  76. class ProjectList : public ScrollContainer {
  77. GDCLASS(ProjectList, ScrollContainer)
  78. friend class ProjectManager;
  79. public:
  80. enum FilterOption {
  81. EDIT_DATE,
  82. NAME,
  83. PATH,
  84. TAGS,
  85. };
  86. // Can often be passed by copy.
  87. struct Item {
  88. String project_name;
  89. String description;
  90. String project_version;
  91. PackedStringArray tags;
  92. String tag_sort_string;
  93. String path;
  94. String icon;
  95. String main_scene;
  96. PackedStringArray unsupported_features;
  97. uint64_t last_edited = 0;
  98. bool favorite = false;
  99. bool grayed = false;
  100. bool missing = false;
  101. int version = 0;
  102. ProjectListItemControl *control = nullptr;
  103. Item() {}
  104. Item(const String &p_name,
  105. const String &p_description,
  106. const String &p_project_version,
  107. const PackedStringArray &p_tags,
  108. const String &p_path,
  109. const String &p_icon,
  110. const String &p_main_scene,
  111. const PackedStringArray &p_unsupported_features,
  112. uint64_t p_last_edited,
  113. bool p_favorite,
  114. bool p_grayed,
  115. bool p_missing,
  116. int p_version) {
  117. project_name = p_name;
  118. description = p_description;
  119. project_version = p_project_version;
  120. tags = p_tags;
  121. path = p_path;
  122. icon = p_icon;
  123. main_scene = p_main_scene;
  124. unsupported_features = p_unsupported_features;
  125. last_edited = p_last_edited;
  126. favorite = p_favorite;
  127. grayed = p_grayed;
  128. missing = p_missing;
  129. version = p_version;
  130. control = nullptr;
  131. PackedStringArray sorted_tags = tags;
  132. sorted_tags.sort();
  133. tag_sort_string = String().join(sorted_tags);
  134. }
  135. _FORCE_INLINE_ bool operator==(const Item &l) const {
  136. return path == l.path;
  137. }
  138. };
  139. private:
  140. String _config_path;
  141. ConfigFile _config;
  142. Vector<Item> _projects;
  143. int _icon_load_index = 0;
  144. bool project_opening_initiated = false;
  145. String _search_term;
  146. FilterOption _order_option = FilterOption::EDIT_DATE;
  147. HashSet<String> _selected_project_paths;
  148. String _last_clicked; // Project key
  149. VBoxContainer *project_list_vbox = nullptr;
  150. // Initialization & loading.
  151. void _migrate_config();
  152. static Item load_project_data(const String &p_property_key, bool p_favorite);
  153. void _update_icons_async();
  154. void _load_project_icon(int p_index);
  155. // Project list updates.
  156. void _scan_folder_recursive(const String &p_path, List<String> *r_projects);
  157. // Project list items.
  158. void _create_project_item_control(int p_index);
  159. void _toggle_project(int p_index);
  160. void _remove_project(int p_index, bool p_update_settings);
  161. void _list_item_input(const Ref<InputEvent> &p_ev, Node *p_hb);
  162. void _on_favorite_pressed(Node *p_hb);
  163. void _on_explore_pressed(const String &p_path);
  164. // Project list selection.
  165. void _clear_project_selection();
  166. void _select_project_nocheck(int p_index);
  167. void _deselect_project_nocheck(int p_index);
  168. void _select_project_range(int p_begin, int p_end);
  169. // Global menu integration.
  170. void _global_menu_new_window(const Variant &p_tag);
  171. void _global_menu_open_project(const Variant &p_tag);
  172. protected:
  173. void _notification(int p_what);
  174. static void _bind_methods();
  175. public:
  176. static const char *SIGNAL_LIST_CHANGED;
  177. static const char *SIGNAL_SELECTION_CHANGED;
  178. static const char *SIGNAL_PROJECT_ASK_OPEN;
  179. static bool project_feature_looks_like_version(const String &p_feature);
  180. // Initialization & loading.
  181. void save_config();
  182. // Project list updates.
  183. void load_project_list();
  184. void update_project_list();
  185. void sort_projects();
  186. int get_project_count() const;
  187. void find_projects(const String &p_path);
  188. void find_projects_multiple(const PackedStringArray &p_paths);
  189. // Project list items.
  190. void add_project(const String &dir_path, bool favorite);
  191. void set_project_version(const String &p_project_path, int version);
  192. int refresh_project(const String &dir_path);
  193. void ensure_project_visible(int p_index);
  194. // Project list selection.
  195. void select_project(int p_index);
  196. void select_first_visible_project();
  197. Vector<Item> get_selected_projects() const;
  198. const HashSet<String> &get_selected_project_keys() const;
  199. int get_single_selected_index() const;
  200. void erase_selected_projects(bool p_delete_project_contents);
  201. // Missing projects.
  202. bool is_any_project_missing() const;
  203. void erase_missing_projects();
  204. // Project list sorting and filtering.
  205. void set_search_term(String p_search_term);
  206. void add_search_tag(const String &p_tag);
  207. void set_order_option(int p_option);
  208. // Global menu integration.
  209. void update_dock_menu();
  210. ProjectList();
  211. };
  212. #endif // PROJECT_LIST_H