2016-06-07 20:29:15 +02:00
|
|
|
/*************************************************************************/
|
|
|
|
/* asset_library_editor_plugin.h */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* http://www.godotengine.org */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
|
|
|
#ifndef ASSET_LIBRARY_EDITOR_PLUGIN_H
|
|
|
|
#define ASSET_LIBRARY_EDITOR_PLUGIN_H
|
2016-02-29 13:56:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "editor_plugin.h"
|
|
|
|
#include "scene/gui/box_container.h"
|
|
|
|
#include "scene/gui/line_edit.h"
|
|
|
|
#include "scene/gui/option_button.h"
|
|
|
|
#include "scene/gui/tab_container.h"
|
2016-03-04 15:09:45 +01:00
|
|
|
#include "scene/gui/panel_container.h"
|
|
|
|
#include "scene/gui/link_button.h"
|
|
|
|
#include "scene/gui/check_box.h"
|
2016-03-05 16:24:12 +01:00
|
|
|
#include "scene/gui/progress_bar.h"
|
2016-03-04 15:09:45 +01:00
|
|
|
#include "scene/gui/separator.h"
|
|
|
|
|
|
|
|
#include "scene/gui/grid_container.h"
|
|
|
|
#include "scene/gui/scroll_container.h"
|
|
|
|
#include "scene/gui/texture_button.h"
|
|
|
|
#include "scene/gui/rich_text_label.h"
|
2016-02-29 13:56:36 +01:00
|
|
|
#include "editor_plugin_settings.h"
|
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
#include "scene/main/http_request.h"
|
2016-03-12 14:44:12 +01:00
|
|
|
#include "editor_asset_installer.h"
|
2016-03-04 15:09:45 +01:00
|
|
|
|
|
|
|
class EditorAssetLibraryItem : public PanelContainer {
|
|
|
|
|
|
|
|
OBJ_TYPE( EditorAssetLibraryItem, PanelContainer );
|
|
|
|
|
|
|
|
TextureButton *icon;
|
|
|
|
LinkButton* title;
|
|
|
|
LinkButton* category;
|
|
|
|
LinkButton* author;
|
|
|
|
TextureFrame *stars[5];
|
|
|
|
Label* price;
|
|
|
|
|
|
|
|
int asset_id;
|
|
|
|
int category_id;
|
|
|
|
int author_id;
|
|
|
|
|
|
|
|
|
|
|
|
void _asset_clicked();
|
|
|
|
void _category_clicked();
|
|
|
|
void _author_clicked();
|
|
|
|
|
|
|
|
|
|
|
|
void set_image(int p_type,int p_index,const Ref<Texture>& p_image);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
EditorAssetLibraryItem();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
class EditorAssetLibraryItemDescription : public ConfirmationDialog {
|
2016-03-04 15:09:45 +01:00
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
OBJ_TYPE(EditorAssetLibraryItemDescription, ConfirmationDialog);
|
2016-03-04 15:09:45 +01:00
|
|
|
|
|
|
|
EditorAssetLibraryItem *item;
|
|
|
|
RichTextLabel *description;
|
|
|
|
ScrollContainer *previews;
|
|
|
|
HBoxContainer *preview_hb;
|
|
|
|
|
|
|
|
struct Preview {
|
|
|
|
int id;
|
2016-06-07 20:29:15 +02:00
|
|
|
bool is_video;
|
2016-03-04 15:09:45 +01:00
|
|
|
String video_link;
|
|
|
|
Button *button;
|
2016-06-07 20:29:15 +02:00
|
|
|
Ref<Texture> image;
|
2016-03-04 15:09:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
Vector<Preview> preview_images;
|
|
|
|
TextureFrame *preview;
|
|
|
|
|
|
|
|
void set_image(int p_type,int p_index,const Ref<Texture>& p_image);
|
|
|
|
|
2016-03-12 14:44:12 +01:00
|
|
|
int asset_id;
|
|
|
|
String download_url;
|
|
|
|
String title;
|
|
|
|
Ref<Texture> icon;
|
|
|
|
|
|
|
|
void _link_click(const String& p_url);
|
2016-06-07 20:29:15 +02:00
|
|
|
void _preview_click(int p_index);
|
2016-03-04 15:09:45 +01:00
|
|
|
protected:
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
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);
|
2016-03-04 15:09:45 +01:00
|
|
|
void add_preview(int p_id, bool p_video,const String& p_url);
|
|
|
|
|
2016-03-12 14:44:12 +01:00
|
|
|
String get_title() { return title; }
|
|
|
|
Ref<Texture> get_preview_icon() { return icon; }
|
|
|
|
String get_download_url() { return download_url; }
|
|
|
|
int get_asset_id() { return asset_id; }
|
2016-06-08 14:25:47 +02:00
|
|
|
EditorAssetLibraryItemDescription();
|
2016-03-04 15:09:45 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
class EditorAssetLibraryItemDownload : public PanelContainer {
|
2016-03-12 14:44:12 +01:00
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
OBJ_TYPE(EditorAssetLibraryItemDownload, PanelContainer);
|
2016-03-12 14:44:12 +01:00
|
|
|
|
|
|
|
|
|
|
|
TextureFrame *icon;
|
|
|
|
Label* title;
|
|
|
|
ProgressBar *progress;
|
|
|
|
Button *install;
|
2016-06-07 20:29:15 +02:00
|
|
|
Button *retry;
|
2016-03-12 14:44:12 +01:00
|
|
|
TextureButton *dismiss;
|
|
|
|
|
|
|
|
AcceptDialog *download_error;
|
|
|
|
HTTPRequest *download;
|
|
|
|
String host;
|
|
|
|
Label *status;
|
|
|
|
|
|
|
|
int prev_status;
|
|
|
|
|
|
|
|
int asset_id;
|
|
|
|
|
|
|
|
EditorAssetInstaller *asset_installer;
|
|
|
|
|
|
|
|
void _close();
|
|
|
|
void _install();
|
2016-06-07 20:29:15 +02:00
|
|
|
void _make_request();
|
2016-03-12 14:44:12 +01:00
|
|
|
void _http_download_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void _notification(int p_what);
|
|
|
|
static void _bind_methods();
|
|
|
|
public:
|
|
|
|
|
|
|
|
int get_asset_id() { return asset_id; }
|
|
|
|
void configure(const String& p_title,int p_asset_id,const Ref<Texture>& p_preview, const String& p_download_url);
|
2016-06-08 14:25:47 +02:00
|
|
|
EditorAssetLibraryItemDownload();
|
2016-03-12 14:44:12 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
class EditorAssetLibrary : public PanelContainer {
|
|
|
|
OBJ_TYPE(EditorAssetLibrary,PanelContainer);
|
2016-02-29 13:56:36 +01:00
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
String host;
|
|
|
|
|
2016-03-12 14:44:12 +01:00
|
|
|
EditorFileDialog *asset_open;
|
|
|
|
EditorAssetInstaller *asset_installer;
|
|
|
|
|
|
|
|
|
|
|
|
void _asset_open();
|
|
|
|
void _asset_file_selected(const String& p_file);
|
|
|
|
|
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
ScrollContainer *library_scroll;
|
|
|
|
VBoxContainer *library_vb;
|
2016-02-29 13:56:36 +01:00
|
|
|
LineEdit *filter;
|
|
|
|
OptionButton *categories;
|
2016-03-04 15:09:45 +01:00
|
|
|
OptionButton *repository;
|
|
|
|
OptionButton *sort;
|
2016-06-08 15:17:16 +02:00
|
|
|
ToolButton *reverse;
|
2016-02-29 13:56:36 +01:00
|
|
|
Button *search;
|
2016-03-05 16:24:12 +01:00
|
|
|
ProgressBar *load_status;
|
|
|
|
HBoxContainer *error_hb;
|
|
|
|
Label *error_label;
|
2016-06-08 15:17:16 +02:00
|
|
|
MenuButton *support;
|
2016-02-29 13:56:36 +01:00
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
HBoxContainer *contents;
|
|
|
|
|
|
|
|
HBoxContainer *asset_top_page;
|
|
|
|
GridContainer *asset_items;
|
|
|
|
HBoxContainer *asset_bottom_page;
|
|
|
|
|
|
|
|
HTTPRequest *request;
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
bool templates_only;
|
|
|
|
|
2016-06-08 15:17:16 +02:00
|
|
|
enum Support {
|
|
|
|
SUPPORT_OFFICIAL,
|
|
|
|
SUPPORT_COMMUNITY,
|
|
|
|
SUPPORT_TESTING
|
|
|
|
};
|
2016-03-12 14:44:12 +01:00
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
enum SortOrder {
|
|
|
|
SORT_RATING,
|
|
|
|
SORT_DOWNLOADS,
|
|
|
|
SORT_NAME,
|
|
|
|
SORT_COST,
|
|
|
|
SORT_UPDATED,
|
|
|
|
SORT_MAX
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static const char* sort_key[SORT_MAX];
|
|
|
|
static const char* sort_text[SORT_MAX];
|
|
|
|
|
|
|
|
|
|
|
|
///MainListing
|
|
|
|
|
|
|
|
enum ImageType {
|
|
|
|
IMAGE_QUEUE_ICON,
|
|
|
|
IMAGE_QUEUE_THUMBNAIL,
|
|
|
|
IMAGE_QUEUE_SCREENSHOT,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImageQueue {
|
|
|
|
|
|
|
|
bool active;
|
|
|
|
int queue_id;
|
|
|
|
int asset_id;
|
|
|
|
ImageType image_type;
|
|
|
|
int image_index;
|
2016-06-07 20:29:15 +02:00
|
|
|
String image_url;
|
2016-03-04 15:09:45 +01:00
|
|
|
HTTPRequest *request;
|
|
|
|
ObjectID target;
|
|
|
|
};
|
|
|
|
|
|
|
|
int last_queue_id;
|
|
|
|
Map<int,ImageQueue> image_queue;
|
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
void _image_update(bool use_cache, bool final, const ByteArray& p_data, int p_queue_id);
|
2016-03-04 15:09:45 +01:00
|
|
|
void _image_request_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data, int p_queue_id);
|
2016-06-07 20:29:15 +02:00
|
|
|
void _request_image(ObjectID p_for,String p_image_url,ImageType p_type,int p_image_index);
|
2016-03-04 15:09:45 +01:00
|
|
|
void _update_image_queue();
|
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
HBoxContainer* _make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);
|
2016-03-04 15:09:45 +01:00
|
|
|
|
|
|
|
//
|
2016-06-08 14:25:47 +02:00
|
|
|
EditorAssetLibraryItemDescription *description;
|
2016-03-04 15:09:45 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
enum RequestType {
|
|
|
|
REQUESTING_NONE,
|
|
|
|
REQUESTING_CONFIG,
|
2016-06-07 20:29:15 +02:00
|
|
|
REQUESTING_SEARCH,
|
|
|
|
REQUESTING_ASSET,
|
2016-03-04 15:09:45 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RequestType requesting;
|
2016-06-07 20:29:15 +02:00
|
|
|
Dictionary category_map;
|
2016-03-04 15:09:45 +01:00
|
|
|
|
2016-03-12 14:44:12 +01:00
|
|
|
|
|
|
|
ScrollContainer *downloads_scroll;
|
|
|
|
HBoxContainer *downloads_hb;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void _install_asset();
|
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
void _select_author(int p_id);
|
|
|
|
void _select_category(int p_id);
|
|
|
|
void _select_asset(int p_id);
|
|
|
|
|
2016-03-12 14:44:12 +01:00
|
|
|
void _manage_plugins();
|
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
void _search(int p_page=0);
|
2016-06-07 20:29:15 +02:00
|
|
|
void _api_request(const String& p_request, RequestType p_request_type, const String &p_arguments="");
|
2016-03-04 15:09:45 +01:00
|
|
|
void _http_request_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data);
|
2016-03-12 14:44:12 +01:00
|
|
|
void _http_download_completed(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data);
|
2016-03-04 15:09:45 +01:00
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
void _repository_changed(int p_repository_id);
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
friend class EditorAssetLibraryItemDescription;
|
2016-03-04 15:09:45 +01:00
|
|
|
friend class EditorAssetLibraryItem;
|
|
|
|
protected:
|
2016-02-29 13:56:36 +01:00
|
|
|
|
2016-03-04 15:09:45 +01:00
|
|
|
static void _bind_methods();
|
|
|
|
void _notification(int p_what);
|
2016-02-29 13:56:36 +01:00
|
|
|
public:
|
2016-06-08 14:25:47 +02:00
|
|
|
EditorAssetLibrary(bool p_templates_only=false);
|
2016-02-29 13:56:36 +01:00
|
|
|
};
|
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
class AssetLibraryEditorPlugin : public EditorPlugin {
|
2016-02-29 13:56:36 +01:00
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
OBJ_TYPE( AssetLibraryEditorPlugin, EditorPlugin );
|
2016-02-29 13:56:36 +01:00
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
EditorAssetLibrary *addon_library;
|
2016-02-29 13:56:36 +01:00
|
|
|
EditorNode *editor;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2016-06-08 14:25:47 +02:00
|
|
|
virtual String get_name() const { return "AssetLib"; }
|
2016-02-29 13:56:36 +01:00
|
|
|
bool has_main_screen() const { return true; }
|
|
|
|
virtual void edit(Object *p_object) {}
|
|
|
|
virtual bool handles(Object *p_object) const { return false; }
|
|
|
|
virtual void make_visible(bool p_visible);
|
|
|
|
//virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
|
|
|
|
//virtual Dictionary get_state() const;
|
|
|
|
//virtual void set_state(const Dictionary& p_state);
|
|
|
|
|
2016-06-07 20:29:15 +02:00
|
|
|
AssetLibraryEditorPlugin(EditorNode *p_node);
|
|
|
|
~AssetLibraryEditorPlugin();
|
2016-02-29 13:56:36 +01:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // EDITORASSETLIBRARY_H
|