project_manager.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  1. /**************************************************************************/
  2. /* project_manager.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_MANAGER_H
  31. #define PROJECT_MANAGER_H
  32. #include "core/io/config_file.h"
  33. #include "editor/editor_about.h"
  34. #include "scene/gui/dialogs.h"
  35. #include "scene/gui/file_dialog.h"
  36. #include "scene/gui/scroll_container.h"
  37. class CheckBox;
  38. class EditorAssetLibrary;
  39. class EditorFileDialog;
  40. class PanelContainer;
  41. class ProjectDialog : public ConfirmationDialog {
  42. GDCLASS(ProjectDialog, ConfirmationDialog);
  43. public:
  44. enum Mode {
  45. MODE_NEW,
  46. MODE_IMPORT,
  47. MODE_INSTALL,
  48. MODE_RENAME,
  49. };
  50. private:
  51. enum MessageType {
  52. MESSAGE_ERROR,
  53. MESSAGE_WARNING,
  54. MESSAGE_SUCCESS,
  55. };
  56. enum InputType {
  57. PROJECT_PATH,
  58. INSTALL_PATH,
  59. };
  60. Mode mode = MODE_NEW;
  61. bool is_folder_empty = true;
  62. Button *browse = nullptr;
  63. Button *install_browse = nullptr;
  64. Button *create_dir = nullptr;
  65. Container *name_container = nullptr;
  66. Container *path_container = nullptr;
  67. Container *install_path_container = nullptr;
  68. Container *renderer_container = nullptr;
  69. Label *renderer_info = nullptr;
  70. HBoxContainer *default_files_container = nullptr;
  71. Ref<ButtonGroup> renderer_button_group;
  72. Label *msg = nullptr;
  73. LineEdit *project_path = nullptr;
  74. LineEdit *project_name = nullptr;
  75. LineEdit *install_path = nullptr;
  76. TextureRect *status_rect = nullptr;
  77. TextureRect *install_status_rect = nullptr;
  78. OptionButton *vcs_metadata_selection = nullptr;
  79. EditorFileDialog *fdialog = nullptr;
  80. EditorFileDialog *fdialog_install = nullptr;
  81. AcceptDialog *dialog_error = nullptr;
  82. String zip_path;
  83. String zip_title;
  84. String fav_dir;
  85. String created_folder_path;
  86. void _set_message(const String &p_msg, MessageType p_type = MESSAGE_SUCCESS, InputType input_type = PROJECT_PATH);
  87. String _test_path();
  88. void _path_text_changed(const String &p_path);
  89. void _path_selected(const String &p_path);
  90. void _file_selected(const String &p_path);
  91. void _install_path_selected(const String &p_path);
  92. void _browse_path();
  93. void _browse_install_path();
  94. void _create_folder();
  95. void _text_changed(const String &p_text);
  96. void _nonempty_confirmation_ok_pressed();
  97. void _renderer_selected();
  98. void _remove_created_folder();
  99. void ok_pressed() override;
  100. void cancel_pressed() override;
  101. protected:
  102. void _notification(int p_what);
  103. static void _bind_methods();
  104. public:
  105. void set_zip_path(const String &p_path);
  106. void set_zip_title(const String &p_title);
  107. void set_mode(Mode p_mode);
  108. void set_project_path(const String &p_path);
  109. void show_dialog();
  110. ProjectDialog();
  111. };
  112. class ProjectListItemControl : public HBoxContainer {
  113. GDCLASS(ProjectListItemControl, HBoxContainer)
  114. VBoxContainer *main_vbox = nullptr;
  115. TextureButton *favorite_button = nullptr;
  116. Button *explore_button = nullptr;
  117. TextureRect *project_icon = nullptr;
  118. Label *project_title = nullptr;
  119. Label *project_path = nullptr;
  120. Label *project_unsupported_features = nullptr;
  121. bool project_is_missing = false;
  122. bool icon_needs_reload = true;
  123. bool is_selected = false;
  124. bool is_hovering = false;
  125. void _favorite_button_pressed();
  126. void _explore_button_pressed();
  127. protected:
  128. void _notification(int p_what);
  129. static void _bind_methods();
  130. public:
  131. void set_project_title(const String &p_title);
  132. void set_project_path(const String &p_path);
  133. void set_project_icon(const Ref<Texture2D> &p_icon);
  134. void set_unsupported_features(const PackedStringArray &p_features);
  135. bool should_load_project_icon() const;
  136. void set_selected(bool p_selected);
  137. void set_is_favorite(bool p_favorite);
  138. void set_is_missing(bool p_missing);
  139. void set_is_grayed(bool p_grayed);
  140. ProjectListItemControl();
  141. };
  142. class ProjectList : public ScrollContainer {
  143. GDCLASS(ProjectList, ScrollContainer)
  144. friend class ProjectManager;
  145. public:
  146. enum FilterOption {
  147. EDIT_DATE,
  148. NAME,
  149. PATH,
  150. };
  151. // Can often be passed by copy
  152. struct Item {
  153. String project_name;
  154. String description;
  155. String path;
  156. String icon;
  157. String main_scene;
  158. PackedStringArray unsupported_features;
  159. uint64_t last_edited = 0;
  160. bool favorite = false;
  161. bool grayed = false;
  162. bool missing = false;
  163. int version = 0;
  164. ProjectListItemControl *control = nullptr;
  165. Item() {}
  166. Item(const String &p_name,
  167. const String &p_description,
  168. const String &p_path,
  169. const String &p_icon,
  170. const String &p_main_scene,
  171. const PackedStringArray &p_unsupported_features,
  172. uint64_t p_last_edited,
  173. bool p_favorite,
  174. bool p_grayed,
  175. bool p_missing,
  176. int p_version) {
  177. project_name = p_name;
  178. description = p_description;
  179. path = p_path;
  180. icon = p_icon;
  181. main_scene = p_main_scene;
  182. unsupported_features = p_unsupported_features;
  183. last_edited = p_last_edited;
  184. favorite = p_favorite;
  185. grayed = p_grayed;
  186. missing = p_missing;
  187. version = p_version;
  188. control = nullptr;
  189. }
  190. _FORCE_INLINE_ bool operator==(const Item &l) const {
  191. return path == l.path;
  192. }
  193. };
  194. private:
  195. bool project_opening_initiated = false;
  196. String _search_term;
  197. FilterOption _order_option = FilterOption::EDIT_DATE;
  198. HashSet<String> _selected_project_paths;
  199. String _last_clicked; // Project key
  200. VBoxContainer *_scroll_children = nullptr;
  201. int _icon_load_index = 0;
  202. Vector<Item> _projects;
  203. ConfigFile _config;
  204. String _config_path;
  205. void _panel_input(const Ref<InputEvent> &p_ev, Node *p_hb);
  206. void _favorite_pressed(Node *p_hb);
  207. void _show_project(const String &p_path);
  208. void _clear_project_selection();
  209. void _toggle_project(int p_index);
  210. void _select_project_nocheck(int p_index);
  211. void _deselect_project_nocheck(int p_index);
  212. void _select_project_range(int p_begin, int p_end);
  213. void _create_project_item_control(int p_index);
  214. void _remove_project(int p_index, bool p_update_settings);
  215. static Item load_project_data(const String &p_property_key, bool p_favorite);
  216. void _update_icons_async();
  217. void _load_project_icon(int p_index);
  218. void _global_menu_new_window(const Variant &p_tag);
  219. void _global_menu_open_project(const Variant &p_tag);
  220. protected:
  221. void _notification(int p_what);
  222. static void _bind_methods();
  223. public:
  224. static const char *SIGNAL_SELECTION_CHANGED;
  225. static const char *SIGNAL_PROJECT_ASK_OPEN;
  226. void load_projects();
  227. int get_project_count() const;
  228. void sort_projects();
  229. void add_project(const String &dir_path, bool favorite);
  230. void set_project_version(const String &p_project_path, int version);
  231. int refresh_project(const String &dir_path);
  232. void ensure_project_visible(int p_index);
  233. void select_project(int p_index);
  234. void select_first_visible_project();
  235. void erase_selected_projects(bool p_delete_project_contents);
  236. Vector<Item> get_selected_projects() const;
  237. const HashSet<String> &get_selected_project_keys() const;
  238. int get_single_selected_index() const;
  239. bool is_any_project_missing() const;
  240. void erase_missing_projects();
  241. void set_search_term(String p_search_term);
  242. void set_order_option(int p_option);
  243. void update_dock_menu();
  244. void migrate_config();
  245. void save_config();
  246. ProjectList();
  247. };
  248. class ProjectManager : public Control {
  249. GDCLASS(ProjectManager, Control);
  250. HashMap<String, Ref<Texture2D>> icon_type_cache;
  251. void _build_icon_type_cache(Ref<Theme> p_theme);
  252. static ProjectManager *singleton;
  253. Panel *background_panel = nullptr;
  254. TabContainer *tabs = nullptr;
  255. ProjectList *_project_list = nullptr;
  256. LineEdit *search_box = nullptr;
  257. Label *loading_label = nullptr;
  258. OptionButton *filter_option = nullptr;
  259. PanelContainer *search_panel = nullptr;
  260. Button *create_btn = nullptr;
  261. Button *import_btn = nullptr;
  262. Button *scan_btn = nullptr;
  263. Button *open_btn = nullptr;
  264. Button *run_btn = nullptr;
  265. Button *rename_btn = nullptr;
  266. Button *erase_btn = nullptr;
  267. Button *erase_missing_btn = nullptr;
  268. Button *about_btn = nullptr;
  269. HBoxContainer *local_projects_hb = nullptr;
  270. EditorAssetLibrary *asset_library = nullptr;
  271. EditorFileDialog *scan_dir = nullptr;
  272. ConfirmationDialog *language_restart_ask = nullptr;
  273. ConfirmationDialog *erase_ask = nullptr;
  274. Label *erase_ask_label = nullptr;
  275. // Comment out for now until we have a better warning system to
  276. // ensure users delete their project only.
  277. //CheckBox *delete_project_contents = nullptr;
  278. ConfirmationDialog *erase_missing_ask = nullptr;
  279. ConfirmationDialog *multi_open_ask = nullptr;
  280. ConfirmationDialog *multi_run_ask = nullptr;
  281. ConfirmationDialog *multi_scan_ask = nullptr;
  282. ConfirmationDialog *ask_full_convert_dialog = nullptr;
  283. ConfirmationDialog *ask_update_settings = nullptr;
  284. ConfirmationDialog *open_templates = nullptr;
  285. EditorAbout *about = nullptr;
  286. HBoxContainer *settings_hb = nullptr;
  287. AcceptDialog *run_error_diag = nullptr;
  288. AcceptDialog *dialog_error = nullptr;
  289. ProjectDialog *npdialog = nullptr;
  290. Button *full_convert_button = nullptr;
  291. OptionButton *language_btn = nullptr;
  292. LinkButton *version_btn = nullptr;
  293. void _open_asset_library();
  294. void _scan_projects();
  295. void _run_project();
  296. void _run_project_confirm();
  297. void _open_selected_projects();
  298. void _open_selected_projects_ask();
  299. void _full_convert_button_pressed();
  300. void _perform_full_project_conversion();
  301. void _import_project();
  302. void _new_project();
  303. void _rename_project();
  304. void _erase_project();
  305. void _erase_missing_projects();
  306. void _erase_project_confirm();
  307. void _erase_missing_projects_confirm();
  308. void _show_about();
  309. void _update_project_buttons();
  310. void _language_selected(int p_id);
  311. void _restart_confirm();
  312. void _confirm_update_settings();
  313. void _load_recent_projects();
  314. void _on_project_created(const String &dir);
  315. void _on_projects_updated();
  316. void _scan_multiple_folders(PackedStringArray p_files);
  317. void _scan_begin(const String &p_base);
  318. void _scan_dir(const String &path);
  319. void _install_project(const String &p_zip_path, const String &p_title);
  320. void _dim_window();
  321. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  322. void _files_dropped(PackedStringArray p_files);
  323. void _version_button_pressed();
  324. void _on_order_option_changed(int p_idx);
  325. void _on_tab_changed(int p_tab);
  326. void _on_search_term_changed(const String &p_term);
  327. static Ref<Texture2D> _file_dialog_get_icon(const String &p_path);
  328. static Ref<Texture2D> _file_dialog_get_thumbnail(const String &p_path);
  329. protected:
  330. void _notification(int p_what);
  331. static void _bind_methods();
  332. public:
  333. static ProjectManager *get_singleton() { return singleton; }
  334. ProjectManager();
  335. ~ProjectManager();
  336. };
  337. #endif // PROJECT_MANAGER_H