project_list.h 7.8 KB

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