Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/asset_library/asset_library_editor_plugin.h
9896 views
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) 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
31
#pragma once
32
33
#include "editor/asset_library/editor_asset_installer.h"
34
#include "editor/plugins/editor_plugin.h"
35
#include "scene/gui/box_container.h"
36
#include "scene/gui/grid_container.h"
37
#include "scene/gui/line_edit.h"
38
#include "scene/gui/link_button.h"
39
#include "scene/gui/margin_container.h"
40
#include "scene/gui/option_button.h"
41
#include "scene/gui/panel_container.h"
42
#include "scene/gui/progress_bar.h"
43
#include "scene/gui/rich_text_label.h"
44
#include "scene/gui/scroll_container.h"
45
#include "scene/gui/texture_button.h"
46
#include "scene/gui/texture_rect.h"
47
#include "scene/main/http_request.h"
48
49
class EditorFileDialog;
50
class MenuButton;
51
52
class EditorAssetLibraryItem : public PanelContainer {
53
GDCLASS(EditorAssetLibraryItem, PanelContainer);
54
55
TextureButton *icon = nullptr;
56
LinkButton *title = nullptr;
57
LinkButton *category = nullptr;
58
LinkButton *author = nullptr;
59
Label *price = nullptr;
60
61
String title_text;
62
int asset_id = 0;
63
int category_id = 0;
64
int author_id = 0;
65
66
void _asset_clicked();
67
void _category_clicked();
68
void _author_clicked();
69
70
void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image);
71
72
protected:
73
void _notification(int p_what);
74
static void _bind_methods();
75
76
public:
77
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, const String &p_cost);
78
79
void clamp_width(int p_max_width);
80
81
EditorAssetLibraryItem(bool p_clickable = false);
82
};
83
84
class EditorAssetLibraryItemDescription : public ConfirmationDialog {
85
GDCLASS(EditorAssetLibraryItemDescription, ConfirmationDialog);
86
87
EditorAssetLibraryItem *item = nullptr;
88
RichTextLabel *description = nullptr;
89
VBoxContainer *previews_vbox = nullptr;
90
ScrollContainer *previews = nullptr;
91
HBoxContainer *preview_hb = nullptr;
92
PanelContainer *previews_bg = nullptr;
93
94
struct Preview {
95
int id = 0;
96
bool is_video = false;
97
String video_link;
98
Button *button = nullptr;
99
Ref<Texture2D> image;
100
};
101
102
Vector<Preview> preview_images;
103
TextureRect *preview = nullptr;
104
105
void set_image(int p_type, int p_index, const Ref<Texture2D> &p_image);
106
107
int asset_id = 0;
108
String download_url;
109
String title;
110
String sha256;
111
Ref<Texture2D> icon;
112
113
void _link_click(const String &p_url);
114
void _preview_click(int p_id);
115
116
protected:
117
void _notification(int p_what);
118
static void _bind_methods();
119
120
public:
121
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, 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);
122
void add_preview(int p_id, bool p_video, const String &p_url);
123
124
String get_title() { return title; }
125
Ref<Texture2D> get_preview_icon() { return icon; }
126
String get_download_url() { return download_url; }
127
int get_asset_id() { return asset_id; }
128
String get_sha256() { return sha256; }
129
EditorAssetLibraryItemDescription();
130
};
131
132
class EditorAssetLibraryItemDownload : public MarginContainer {
133
GDCLASS(EditorAssetLibraryItemDownload, MarginContainer);
134
135
PanelContainer *panel = nullptr;
136
TextureRect *icon = nullptr;
137
Label *title = nullptr;
138
ProgressBar *progress = nullptr;
139
Button *install_button = nullptr;
140
Button *retry_button = nullptr;
141
TextureButton *dismiss_button = nullptr;
142
143
AcceptDialog *download_error = nullptr;
144
HTTPRequest *download = nullptr;
145
String host;
146
String sha256;
147
Label *status = nullptr;
148
149
int prev_status;
150
151
int asset_id = 0;
152
153
bool external_install;
154
155
EditorAssetInstaller *asset_installer = nullptr;
156
157
void _close();
158
void _make_request();
159
void _http_download_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
160
161
protected:
162
void _notification(int p_what);
163
static void _bind_methods();
164
165
public:
166
void set_external_install(bool p_enable) { external_install = p_enable; }
167
int get_asset_id() { return asset_id; }
168
void configure(const String &p_title, int p_asset_id, const Ref<Texture2D> &p_preview, const String &p_download_url, const String &p_sha256_hash);
169
170
bool can_install() const;
171
void install();
172
173
EditorAssetLibraryItemDownload();
174
};
175
176
class EditorAssetLibrary : public PanelContainer {
177
GDCLASS(EditorAssetLibrary, PanelContainer);
178
179
String host;
180
181
EditorFileDialog *asset_open = nullptr;
182
EditorAssetInstaller *asset_installer = nullptr;
183
184
void _asset_open();
185
void _asset_file_selected(const String &p_file);
186
void _update_repository_options();
187
188
PanelContainer *library_scroll_bg = nullptr;
189
ScrollContainer *library_scroll = nullptr;
190
VBoxContainer *library_vb = nullptr;
191
VBoxContainer *library_message_box = nullptr;
192
Label *library_message = nullptr;
193
Button *library_message_button = nullptr;
194
Callable library_message_action;
195
196
void _set_library_message(const String &p_message);
197
void _set_library_message_with_action(const String &p_message, const String &p_action_text, const Callable &p_action);
198
199
LineEdit *filter = nullptr;
200
Timer *filter_debounce_timer = nullptr;
201
OptionButton *categories = nullptr;
202
OptionButton *repository = nullptr;
203
OptionButton *sort = nullptr;
204
HBoxContainer *error_hb = nullptr;
205
TextureRect *error_tr = nullptr;
206
Label *error_label = nullptr;
207
MenuButton *support = nullptr;
208
209
HBoxContainer *contents = nullptr;
210
211
HBoxContainer *asset_top_page = nullptr;
212
GridContainer *asset_items = nullptr;
213
HBoxContainer *asset_bottom_page = nullptr;
214
215
HTTPRequest *request = nullptr;
216
217
bool templates_only = false;
218
bool initial_loading = true;
219
bool loading_blocked = false;
220
221
void _force_online_mode();
222
223
enum Support {
224
SUPPORT_FEATURED,
225
SUPPORT_COMMUNITY,
226
SUPPORT_TESTING,
227
SUPPORT_MAX
228
};
229
230
enum SortOrder {
231
SORT_UPDATED,
232
SORT_UPDATED_REVERSE,
233
SORT_NAME,
234
SORT_NAME_REVERSE,
235
SORT_COST,
236
SORT_COST_REVERSE,
237
SORT_MAX
238
};
239
240
static const char *sort_key[SORT_MAX];
241
static const char *sort_text[SORT_MAX];
242
static const char *support_key[SUPPORT_MAX];
243
static const char *support_text[SUPPORT_MAX];
244
245
///MainListing
246
247
enum ImageType {
248
IMAGE_QUEUE_ICON,
249
IMAGE_QUEUE_THUMBNAIL,
250
IMAGE_QUEUE_SCREENSHOT,
251
252
};
253
254
struct ImageQueue {
255
bool active = false;
256
int queue_id = 0;
257
ImageType image_type = ImageType::IMAGE_QUEUE_ICON;
258
int image_index = 0;
259
String image_url;
260
HTTPRequest *request = nullptr;
261
ObjectID target;
262
int asset_id = -1;
263
};
264
265
int last_queue_id;
266
HashMap<int, ImageQueue> image_queue;
267
268
void _image_update(bool p_use_cache, bool p_final, const PackedByteArray &p_data, int p_queue_id);
269
void _image_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data, int p_queue_id);
270
void _request_image(ObjectID p_for, int p_asset_id, String p_image_url, ImageType p_type, int p_image_index);
271
void _update_image_queue();
272
273
HBoxContainer *_make_pages(int p_page, int p_page_count, int p_page_len, int p_total_items, int p_current_items);
274
275
//
276
EditorAssetLibraryItemDescription *description = nullptr;
277
//
278
279
enum RequestType {
280
REQUESTING_NONE,
281
REQUESTING_CONFIG,
282
REQUESTING_SEARCH,
283
REQUESTING_ASSET,
284
};
285
286
RequestType requesting;
287
Dictionary category_map;
288
289
ScrollContainer *downloads_scroll = nullptr;
290
HBoxContainer *downloads_hb = nullptr;
291
292
void _install_asset();
293
294
void _select_author(const String &p_author);
295
void _select_category(int p_id);
296
void _select_asset(int p_id);
297
298
void _manage_plugins();
299
300
void _search(int p_page = 0);
301
void _rerun_search(int p_ignore);
302
void _search_text_changed(const String &p_text = "");
303
void _search_text_submitted(const String &p_text = "");
304
void _api_request(const String &p_request, RequestType p_request_type, const String &p_arguments = "");
305
void _http_request_completed(int p_status, int p_code, const PackedStringArray &headers, const PackedByteArray &p_data);
306
void _filter_debounce_timer_timeout();
307
void _request_current_config();
308
EditorAssetLibraryItemDownload *_get_asset_in_progress(int p_asset_id) const;
309
310
void _repository_changed(int p_repository_id);
311
void _support_toggled(int p_support);
312
313
void _install_external_asset(String p_zip_path, String p_title);
314
315
int asset_items_column_width = 0;
316
317
void _update_asset_items_columns();
318
319
friend class EditorAssetLibraryItemDescription;
320
friend class EditorAssetLibraryItem;
321
322
protected:
323
static void _bind_methods();
324
void _notification(int p_what);
325
virtual void shortcut_input(const Ref<InputEvent> &p_event) override;
326
327
public:
328
void disable_community_support();
329
330
EditorAssetLibrary(bool p_templates_only = false);
331
};
332
333
class AssetLibraryEditorPlugin : public EditorPlugin {
334
GDCLASS(AssetLibraryEditorPlugin, EditorPlugin);
335
336
EditorAssetLibrary *addon_library = nullptr;
337
338
public:
339
static bool is_available();
340
341
virtual String get_plugin_name() const override { return TTRC("AssetLib"); }
342
bool has_main_screen() const override { return true; }
343
virtual void edit(Object *p_object) override {}
344
virtual bool handles(Object *p_object) const override { return false; }
345
virtual void make_visible(bool p_visible) override;
346
//virtual bool get_remove_list(List<Node*> *p_list) { return canvas_item_editor->get_remove_list(p_list); }
347
//virtual Dictionary get_state() const;
348
//virtual void set_state(const Dictionary& p_state);
349
350
AssetLibraryEditorPlugin();
351
};
352
353