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