Path: blob/master/editor/asset_library/asset_library_editor_plugin.h
9896 views
/**************************************************************************/1/* asset_library_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/asset_library/editor_asset_installer.h"33#include "editor/plugins/editor_plugin.h"34#include "scene/gui/box_container.h"35#include "scene/gui/grid_container.h"36#include "scene/gui/line_edit.h"37#include "scene/gui/link_button.h"38#include "scene/gui/margin_container.h"39#include "scene/gui/option_button.h"40#include "scene/gui/panel_container.h"41#include "scene/gui/progress_bar.h"42#include "scene/gui/rich_text_label.h"43#include "scene/gui/scroll_container.h"44#include "scene/gui/texture_button.h"45#include "scene/gui/texture_rect.h"46#include "scene/main/http_request.h"4748class EditorFileDialog;49class MenuButton;5051class EditorAssetLibraryItem : public PanelContainer {52GDCLASS(EditorAssetLibraryItem, PanelContainer);5354TextureButton *icon = nullptr;55LinkButton *title = nullptr;56LinkButton *category = nullptr;57LinkButton *author = nullptr;58Label *price = nullptr;5960String title_text;61int asset_id = 0;62int category_id = 0;63int author_id = 0;6465void _asset_clicked();66void _category_clicked();67void _author_clicked();6869void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image);7071protected:72void _notification(int p_what);73static void _bind_methods();7475public:76void 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, const String &p_cost);7778void clamp_width(int p_max_width);7980EditorAssetLibraryItem(bool p_clickable = false);81};8283class EditorAssetLibraryItemDescription : public ConfirmationDialog {84GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog);8586EditorAssetLibraryItem *item = nullptr;87RichTextLabel *description = nullptr;88VBoxContainer *previews_vbox = nullptr;89ScrollContainer *previews = nullptr;90HBoxContainer *preview_hb = nullptr;91PanelContainer *previews_bg = nullptr;9293struct Preview {94int id = 0;95bool is_video = false;96String video_link;97Button *button = nullptr;98Ref<Texture2D> image;99};100101Vector<Preview> preview_images;102TextureRect *preview = nullptr;103104void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image);105106int asset_id = 0;107String download_url;108String title;109String sha256;110Ref<Texture2D> icon;111112void _link_click(const String &p_url);113void _preview_click(int p_id);114115protected:116void _notification(int p_what);117static void _bind_methods();118119public:120void 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, 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);121void add_preview(int p_id, bool p_video, const String &p_url);122123String get_title() { return title; }124Ref<Texture2D> get_preview_icon() { return icon; }125String get_download_url() { return download_url; }126int get_asset_id() { return asset_id; }127String get_sha256() { return sha256; }128EditorAssetLibraryItemDescription();129};130131class EditorAssetLibraryItemDownload : public MarginContainer {132GDCLASS(EditorAssetLibraryItemDownload, MarginContainer);133134PanelContainer *panel = nullptr;135TextureRect *icon = nullptr;136Label *title = nullptr;137ProgressBar *progress = nullptr;138Button *install_button = nullptr;139Button *retry_button = nullptr;140TextureButton *dismiss_button = nullptr;141142AcceptDialog *download_error = nullptr;143HTTPRequest *download = nullptr;144String host;145String sha256;146Label *status = nullptr;147148int prev_status;149150int asset_id = 0;151152bool external_install;153154EditorAssetInstaller *asset_installer = nullptr;155156void _close();157void _make_request();158void _http_download_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);159160protected:161void _notification(int p_what);162static void _bind_methods();163164public:165void set_external_install(bool p_enable) { external_install = p_enable; }166int get_asset_id() { return asset_id; }167void configure(const String &p_title, int p_asset_id, const Ref<Texture2D> &p_preview, const String &p_download_url, const String &p_sha256_hash);168169bool can_install() const;170void install();171172EditorAssetLibraryItemDownload();173};174175class EditorAssetLibrary : public PanelContainer {176GDCLASS(EditorAssetLibrary, PanelContainer);177178String host;179180EditorFileDialog *asset_open = nullptr;181EditorAssetInstaller *asset_installer = nullptr;182183void _asset_open();184void _asset_file_selected(const String &p_file);185void _update_repository_options();186187PanelContainer *library_scroll_bg = nullptr;188ScrollContainer *library_scroll = nullptr;189VBoxContainer *library_vb = nullptr;190VBoxContainer *library_message_box = nullptr;191Label *library_message = nullptr;192Button *library_message_button = nullptr;193Callable library_message_action;194195void _set_library_message(const String &p_message);196void _set_library_message_with_action(const String &p_message, const String &p_action_text, const Callable &p_action);197198LineEdit *filter = nullptr;199Timer *filter_debounce_timer = nullptr;200OptionButton *categories = nullptr;201OptionButton *repository = nullptr;202OptionButton *sort = nullptr;203HBoxContainer *error_hb = nullptr;204TextureRect *error_tr = nullptr;205Label *error_label = nullptr;206MenuButton *support = nullptr;207208HBoxContainer *contents = nullptr;209210HBoxContainer *asset_top_page = nullptr;211GridContainer *asset_items = nullptr;212HBoxContainer *asset_bottom_page = nullptr;213214HTTPRequest *request = nullptr;215216bool templates_only = false;217bool initial_loading = true;218bool loading_blocked = false;219220void _force_online_mode();221222enum Support {223SUPPORT_FEATURED,224SUPPORT_COMMUNITY,225SUPPORT_TESTING,226SUPPORT_MAX227};228229enum SortOrder {230SORT_UPDATED,231SORT_UPDATED_REVERSE,232SORT_NAME,233SORT_NAME_REVERSE,234SORT_COST,235SORT_COST_REVERSE,236SORT_MAX237};238239static const char *sort_key[SORT_MAX];240static const char *sort_text[SORT_MAX];241static const char *support_key[SUPPORT_MAX];242static const char *support_text[SUPPORT_MAX];243244///MainListing245246enum ImageType {247IMAGE_QUEUE_ICON,248IMAGE_QUEUE_THUMBNAIL,249IMAGE_QUEUE_SCREENSHOT,250251};252253struct ImageQueue {254bool active = false;255int queue_id = 0;256ImageType image_type = ImageType::IMAGE_QUEUE_ICON;257int image_index = 0;258String image_url;259HTTPRequest *request = nullptr;260ObjectID target;261int asset_id = -1;262};263264int last_queue_id;265HashMap<int, ImageQueue> image_queue;266267void _image_update(bool p_use_cache, bool p_final, const PackedByteArray &p_data, int p_queue_id);268void _image_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data, int p_queue_id);269void _request_image(ObjectID p_for, int p_asset_id, String p_image_url, ImageType p_type, int p_image_index);270void _update_image_queue();271272HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);273274//275EditorAssetLibraryItemDescription *description = nullptr;276//277278enum RequestType {279REQUESTING_NONE,280REQUESTING_CONFIG,281REQUESTING_SEARCH,282REQUESTING_ASSET,283};284285RequestType requesting;286Dictionary category_map;287288ScrollContainer *downloads_scroll = nullptr;289HBoxContainer *downloads_hb = nullptr;290291void _install_asset();292293void _select_author(const String &p_author);294void _select_category(int p_id);295void _select_asset(int p_id);296297void _manage_plugins();298299void _search(int p_page = 0);300void _rerun_search(int p_ignore);301void _search_text_changed(const String &p_text = "");302void _search_text_submitted(const String &p_text = "");303void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");304void _http_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);305void _filter_debounce_timer_timeout();306void _request_current_config();307EditorAssetLibraryItemDownload *_get_asset_in_progress(int p_asset_id) const;308309void _repository_changed(int p_repository_id);310void _support_toggled(int p_support);311312void _install_external_asset(String p_zip_path, String p_title);313314int asset_items_column_width = 0;315316void _update_asset_items_columns();317318friend class EditorAssetLibraryItemDescription;319friend class EditorAssetLibraryItem;320321protected:322static void _bind_methods();323void _notification(int p_what);324virtual void shortcut_input(const Ref<InputEvent> &p_event) override;325326public:327void disable_community_support();328329EditorAssetLibrary(bool p_templates_only = false);330};331332class AssetLibraryEditorPlugin : public EditorPlugin {333GDCLASS(AssetLibraryEditorPlugin, EditorPlugin);334335EditorAssetLibrary *addon_library = nullptr;336337public:338static bool is_available();339340virtual String get_plugin_name() const override { return TTRC("AssetLib"); }341bool has_main_screen() const override { return true; }342virtual void edit(Object *p_object) override {}343virtual bool handles(Object *p_object) const override { return false; }344virtual void make_visible(bool p_visible) override;345//virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }346//virtual Dictionary get_state() const;347//virtual void set_state(const Dictionary& p_state);348349AssetLibraryEditorPlugin();350};351352353