project_list.h 8.6 KB

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