asset_library_editor_plugin.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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-2017 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2017 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. GDCLASS(EditorAssetLibraryItem, PanelContainer);
  51. TextureButton *icon;
  52. LinkButton *title;
  53. LinkButton *category;
  54. LinkButton *author;
  55. TextureRect *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. GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog);
  73. EditorAssetLibraryItem *item;
  74. RichTextLabel *description;
  75. ScrollContainer *previews;
  76. HBoxContainer *preview_hb;
  77. PanelContainer *previews_bg;
  78. PanelContainer *desc_bg;
  79. struct Preview {
  80. int id;
  81. bool is_video;
  82. String video_link;
  83. Button *button;
  84. Ref<Texture> image;
  85. };
  86. Vector<Preview> preview_images;
  87. TextureRect *preview;
  88. void set_image(int p_type, int p_index, const Ref<Texture> &p_image);
  89. int asset_id;
  90. String download_url;
  91. String title;
  92. String sha256;
  93. Ref<Texture> icon;
  94. void _link_click(const String &p_url);
  95. void _preview_click(int p_id);
  96. protected:
  97. void _notification(int p_what);
  98. static void _bind_methods();
  99. public:
  100. 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);
  101. void add_preview(int p_id, bool p_video, const String &p_url);
  102. String get_title() { return title; }
  103. Ref<Texture> get_preview_icon() { return icon; }
  104. String get_download_url() { return download_url; }
  105. int get_asset_id() { return asset_id; }
  106. String get_sha256() { return sha256; }
  107. EditorAssetLibraryItemDescription();
  108. };
  109. class EditorAssetLibraryItemDownload : public PanelContainer {
  110. GDCLASS(EditorAssetLibraryItemDownload, PanelContainer);
  111. TextureRect *icon;
  112. Label *title;
  113. ProgressBar *progress;
  114. Button *install;
  115. Button *retry;
  116. TextureButton *dismiss;
  117. AcceptDialog *download_error;
  118. HTTPRequest *download;
  119. String host;
  120. String sha256;
  121. Label *status;
  122. int prev_status;
  123. int asset_id;
  124. bool external_install;
  125. EditorAssetInstaller *asset_installer;
  126. void _close();
  127. void _install();
  128. void _make_request();
  129. void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
  130. protected:
  131. void _notification(int p_what);
  132. static void _bind_methods();
  133. public:
  134. void set_external_install(bool p_enable) { external_install = p_enable; }
  135. int get_asset_id() { return asset_id; }
  136. 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);
  137. EditorAssetLibraryItemDownload();
  138. };
  139. class EditorAssetLibrary : public PanelContainer {
  140. GDCLASS(EditorAssetLibrary, PanelContainer);
  141. String host;
  142. EditorFileDialog *asset_open;
  143. EditorAssetInstaller *asset_installer;
  144. void _asset_open();
  145. void _asset_file_selected(const String &p_file);
  146. PanelContainer *library_scroll_bg;
  147. ScrollContainer *library_scroll;
  148. VBoxContainer *library_vb;
  149. LineEdit *filter;
  150. OptionButton *categories;
  151. OptionButton *repository;
  152. OptionButton *sort;
  153. ToolButton *reverse;
  154. Button *search;
  155. ProgressBar *load_status;
  156. HBoxContainer *error_hb;
  157. Label *error_label;
  158. MenuButton *support;
  159. HBoxContainer *contents;
  160. HBoxContainer *asset_top_page;
  161. GridContainer *asset_items;
  162. HBoxContainer *asset_bottom_page;
  163. HTTPRequest *request;
  164. bool templates_only;
  165. enum Support {
  166. SUPPORT_OFFICIAL,
  167. SUPPORT_COMMUNITY,
  168. SUPPORT_TESTING,
  169. SUPPORT_MAX
  170. };
  171. enum SortOrder {
  172. SORT_RATING,
  173. SORT_DOWNLOADS,
  174. SORT_NAME,
  175. SORT_COST,
  176. SORT_UPDATED,
  177. SORT_MAX
  178. };
  179. static const char *sort_key[SORT_MAX];
  180. static const char *sort_text[SORT_MAX];
  181. static const char *support_key[SUPPORT_MAX];
  182. ///MainListing
  183. enum ImageType {
  184. IMAGE_QUEUE_ICON,
  185. IMAGE_QUEUE_THUMBNAIL,
  186. IMAGE_QUEUE_SCREENSHOT,
  187. };
  188. struct ImageQueue {
  189. bool active;
  190. int queue_id;
  191. int asset_id;
  192. ImageType image_type;
  193. int image_index;
  194. String image_url;
  195. HTTPRequest *request;
  196. ObjectID target;
  197. };
  198. int last_queue_id;
  199. Map<int, ImageQueue> image_queue;
  200. void _image_update(bool use_cache, bool final, const PoolByteArray &p_data, int p_queue_id);
  201. void _image_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data, int p_queue_id);
  202. void _request_image(ObjectID p_for, String p_image_url, ImageType p_type, int p_image_index);
  203. void _update_image_queue();
  204. HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);
  205. //
  206. EditorAssetLibraryItemDescription *description;
  207. //
  208. enum RequestType {
  209. REQUESTING_NONE,
  210. REQUESTING_CONFIG,
  211. REQUESTING_SEARCH,
  212. REQUESTING_ASSET,
  213. };
  214. RequestType requesting;
  215. Dictionary category_map;
  216. ScrollContainer *downloads_scroll;
  217. HBoxContainer *downloads_hb;
  218. void _install_asset();
  219. void _select_author(int p_id);
  220. void _select_category(int p_id);
  221. void _select_asset(int p_id);
  222. void _manage_plugins();
  223. void _search(int p_page = 0);
  224. void _rerun_search(int p_ignore);
  225. void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");
  226. void _http_request_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
  227. void _http_download_completed(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
  228. void _repository_changed(int p_repository_id);
  229. void _support_toggled(int p_support);
  230. void _install_external_asset(String p_zip_path, String p_title);
  231. friend class EditorAssetLibraryItemDescription;
  232. friend class EditorAssetLibraryItem;
  233. protected:
  234. static void _bind_methods();
  235. void _notification(int p_what);
  236. public:
  237. EditorAssetLibrary(bool p_templates_only = false);
  238. };
  239. class AssetLibraryEditorPlugin : public EditorPlugin {
  240. GDCLASS(AssetLibraryEditorPlugin, EditorPlugin);
  241. EditorAssetLibrary *addon_library;
  242. EditorNode *editor;
  243. public:
  244. virtual String get_name() const { return "AssetLib"; }
  245. bool has_main_screen() const { return true; }
  246. virtual void edit(Object *p_object) {}
  247. virtual bool handles(Object *p_object) const { return false; }
  248. virtual void make_visible(bool p_visible);
  249. //virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
  250. //virtual Dictionary get_state() const;
  251. //virtual void set_state(const Dictionary& p_state);
  252. AssetLibraryEditorPlugin(EditorNode *p_node);
  253. ~AssetLibraryEditorPlugin();
  254. };
  255. #endif // EDITORASSETLIBRARY_H