asset_library_editor_plugin.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. /*************************************************************************/
  2. /* asset_library_editor_plugin.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
  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 ASSET_LIBRARY_EDITOR_PLUGIN_H
  31. #define ASSET_LIBRARY_EDITOR_PLUGIN_H
  32. #include "editor_plugin.h"
  33. #include "scene/gui/box_container.h"
  34. #include "scene/gui/check_box.h"
  35. #include "scene/gui/line_edit.h"
  36. #include "scene/gui/link_button.h"
  37. #include "scene/gui/option_button.h"
  38. #include "scene/gui/panel_container.h"
  39. #include "scene/gui/progress_bar.h"
  40. #include "scene/gui/separator.h"
  41. #include "scene/gui/tab_container.h"
  42. #include "editor_plugin_settings.h"
  43. #include "scene/gui/grid_container.h"
  44. #include "scene/gui/rich_text_label.h"
  45. #include "scene/gui/scroll_container.h"
  46. #include "scene/gui/texture_button.h"
  47. #include "editor_asset_installer.h"
  48. #include "scene/main/http_request.h"
  49. class EditorAssetLibraryItem : public PanelContainer {
  50. OBJ_TYPE(EditorAssetLibraryItem, PanelContainer);
  51. TextureButton *icon;
  52. LinkButton *title;
  53. LinkButton *category;
  54. LinkButton *author;
  55. TextureFrame *stars[5];
  56. Label *price;
  57. int asset_id;
  58. int category_id;
  59. int author_id;
  60. void _asset_clicked();
  61. void _category_clicked();
  62. void _author_clicked();
  63. void set_image(int p_type, int p_index, const Ref<Texture> &p_image);
  64. protected:
  65. void _notification(int p_what);
  66. static void _bind_methods();
  67. public:
  68. void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost);
  69. EditorAssetLibraryItem();
  70. };
  71. class EditorAssetLibraryItemDescription : public ConfirmationDialog {
  72. OBJ_TYPE(EditorAssetLibraryItemDescription, ConfirmationDialog);
  73. EditorAssetLibraryItem *item;
  74. RichTextLabel *description;
  75. ScrollContainer *previews;
  76. HBoxContainer *preview_hb;
  77. struct Preview {
  78. int id;
  79. bool is_video;
  80. String video_link;
  81. Button *button;
  82. Ref<Texture> image;
  83. };
  84. Vector<Preview> preview_images;
  85. TextureFrame *preview;
  86. void set_image(int p_type, int p_index, const Ref<Texture> &p_image);
  87. int asset_id;
  88. String download_url;
  89. String title;
  90. String sha256;
  91. Ref<Texture> icon;
  92. void _link_click(const String &p_url);
  93. void _preview_click(int p_index);
  94. protected:
  95. static void _bind_methods();
  96. public:
  97. void configure(const String &p_title, int p_asset_id, const String &p_category, int p_category_id, const String &p_author, int p_author_id, int p_rating, const String &p_cost, int p_version, const String &p_version_string, const String &p_description, const String &p_download_url, const String &p_browse_url, const String &p_sha256_hash);
  98. void add_preview(int p_id, bool p_video, const String &p_url);
  99. String get_title() { return title; }
  100. Ref<Texture> get_preview_icon() { return icon; }
  101. String get_download_url() { return download_url; }
  102. int get_asset_id() { return asset_id; }
  103. String get_sha256() { return sha256; }
  104. EditorAssetLibraryItemDescription();
  105. };
  106. class EditorAssetLibraryItemDownload : public PanelContainer {
  107. OBJ_TYPE(EditorAssetLibraryItemDownload, PanelContainer);
  108. TextureFrame *icon;
  109. Label *title;
  110. ProgressBar *progress;
  111. Button *install;
  112. Button *retry;
  113. TextureButton *dismiss;
  114. AcceptDialog *download_error;
  115. HTTPRequest *download;
  116. String host;
  117. String sha256;
  118. Label *status;
  119. int prev_status;
  120. int asset_id;
  121. bool external_install;
  122. EditorAssetInstaller *asset_installer;
  123. void _close();
  124. void _install();
  125. void _make_request();
  126. void _http_download_completed(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data);
  127. protected:
  128. void _notification(int p_what);
  129. static void _bind_methods();
  130. public:
  131. void set_external_install(bool p_enable) { external_install = p_enable; }
  132. int get_asset_id() { return asset_id; }
  133. void configure(const String &p_title, int p_asset_id, const Ref<Texture> &p_preview, const String &p_download_url, const String &p_sha256_hash);
  134. EditorAssetLibraryItemDownload();
  135. };
  136. class EditorAssetLibrary : public PanelContainer {
  137. OBJ_TYPE(EditorAssetLibrary, PanelContainer);
  138. String host;
  139. EditorFileDialog *asset_open;
  140. EditorAssetInstaller *asset_installer;
  141. void _asset_open();
  142. void _asset_file_selected(const String &p_file);
  143. ScrollContainer *library_scroll;
  144. VBoxContainer *library_vb;
  145. LineEdit *filter;
  146. OptionButton *categories;
  147. OptionButton *repository;
  148. OptionButton *sort;
  149. ToolButton *reverse;
  150. Button *search;
  151. ProgressBar *load_status;
  152. HBoxContainer *error_hb;
  153. Label *error_label;
  154. MenuButton *support;
  155. HBoxContainer *contents;
  156. HBoxContainer *asset_top_page;
  157. GridContainer *asset_items;
  158. HBoxContainer *asset_bottom_page;
  159. HTTPRequest *request;
  160. bool templates_only;
  161. enum Support {
  162. SUPPORT_OFFICIAL,
  163. SUPPORT_COMMUNITY,
  164. SUPPORT_TESTING,
  165. SUPPORT_MAX
  166. };
  167. enum SortOrder {
  168. SORT_RATING,
  169. SORT_DOWNLOADS,
  170. SORT_NAME,
  171. SORT_COST,
  172. SORT_UPDATED,
  173. SORT_MAX
  174. };
  175. static const char *sort_key[SORT_MAX];
  176. static const char *sort_text[SORT_MAX];
  177. static const char *support_key[SUPPORT_MAX];
  178. ///MainListing
  179. enum ImageType {
  180. IMAGE_QUEUE_ICON,
  181. IMAGE_QUEUE_THUMBNAIL,
  182. IMAGE_QUEUE_SCREENSHOT,
  183. };
  184. struct ImageQueue {
  185. bool active;
  186. int queue_id;
  187. int asset_id;
  188. ImageType image_type;
  189. int image_index;
  190. String image_url;
  191. HTTPRequest *request;
  192. ObjectID target;
  193. };
  194. int last_queue_id;
  195. Map<int, ImageQueue> image_queue;
  196. void _image_update(bool use_cache, bool final, const ByteArray &p_data, int p_queue_id);
  197. void _image_request_completed(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data, int p_queue_id);
  198. void _request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index);
  199. void _update_image_queue();
  200. HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);
  201. //
  202. EditorAssetLibraryItemDescription *description;
  203. //
  204. enum RequestType {
  205. REQUESTING_NONE,
  206. REQUESTING_CONFIG,
  207. REQUESTING_SEARCH,
  208. REQUESTING_ASSET,
  209. };
  210. RequestType requesting;
  211. Dictionary category_map;
  212. ScrollContainer *downloads_scroll;
  213. HBoxContainer *downloads_hb;
  214. void _install_asset();
  215. void _select_author(int p_id);
  216. void _select_category(int p_id);
  217. void _select_asset(int p_id);
  218. void _manage_plugins();
  219. void _search(int p_page = 0);
  220. void _rerun_search(int p_ignore);
  221. void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");
  222. void _http_request_completed(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data);
  223. void _http_download_completed(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data);
  224. void _repository_changed(int p_repository_id);
  225. void _support_toggled(int p_support);
  226. void _install_external_asset(String p_zip_path, String p_title);
  227. friend class EditorAssetLibraryItemDescription;
  228. friend class EditorAssetLibraryItem;
  229. protected:
  230. static void _bind_methods();
  231. void _notification(int p_what);
  232. public:
  233. EditorAssetLibrary(bool p_templates_only = false);
  234. };
  235. class AssetLibraryEditorPlugin : public EditorPlugin {
  236. OBJ_TYPE(AssetLibraryEditorPlugin, EditorPlugin);
  237. EditorAssetLibrary *addon_library;
  238. EditorNode *editor;
  239. public:
  240. virtual String get_name() const { return "AssetLib"; }
  241. bool has_main_screen() const { return true; }
  242. virtual void edit(Object *p_object) {}
  243. virtual bool handles(Object *p_object) const { return false; }
  244. virtual void make_visible(bool p_visible);
  245. //virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
  246. //virtual Dictionary get_state() const;
  247. //virtual void set_state(const Dictionary& p_state);
  248. AssetLibraryEditorPlugin(EditorNode *p_node);
  249. ~AssetLibraryEditorPlugin();
  250. };
  251. #endif // EDITORASSETLIBRARY_H