Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/asset_library/editor_asset_installer.cpp
9902 views
1
/**************************************************************************/
2
/* editor_asset_installer.cpp */
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
#include "editor_asset_installer.h"
32
33
#include "core/io/dir_access.h"
34
#include "core/io/file_access.h"
35
#include "core/io/zip_io.h"
36
#include "editor/editor_node.h"
37
#include "editor/editor_string_names.h"
38
#include "editor/file_system/editor_file_system.h"
39
#include "editor/gui/editor_file_dialog.h"
40
#include "editor/gui/editor_toaster.h"
41
#include "editor/gui/progress_dialog.h"
42
#include "editor/themes/editor_scale.h"
43
#include "scene/gui/check_box.h"
44
#include "scene/gui/label.h"
45
#include "scene/gui/link_button.h"
46
#include "scene/gui/separator.h"
47
#include "scene/gui/split_container.h"
48
49
void EditorAssetInstaller::_item_checked_cbk() {
50
if (updating_source || !source_tree->get_edited()) {
51
return;
52
}
53
54
updating_source = true;
55
TreeItem *item = source_tree->get_edited();
56
item->propagate_check(0);
57
_fix_conflicted_indeterminate_state(source_tree->get_root(), 0);
58
_update_confirm_button();
59
_rebuild_destination_tree();
60
updating_source = false;
61
}
62
63
// Determine parent state based on non-conflict children, to avoid indeterminate state, and allow toggle dir with conflicts.
64
bool EditorAssetInstaller::_fix_conflicted_indeterminate_state(TreeItem *p_item, int p_column) {
65
if (p_item->get_child_count() == 0) {
66
return false;
67
}
68
bool all_non_conflict_checked = true;
69
bool all_non_conflict_unchecked = true;
70
bool has_conflict_child = false;
71
bool has_indeterminate_child = false;
72
TreeItem *child_item = p_item->get_first_child();
73
while (child_item) {
74
has_conflict_child |= _fix_conflicted_indeterminate_state(child_item, p_column);
75
Dictionary child_meta = child_item->get_metadata(p_column);
76
bool child_conflict = child_meta.get("is_conflict", false);
77
if (child_conflict) {
78
child_item->set_checked(p_column, false);
79
has_conflict_child = true;
80
} else {
81
bool child_checked = child_item->is_checked(p_column);
82
bool child_indeterminate = child_item->is_indeterminate(p_column);
83
all_non_conflict_checked &= (child_checked || child_indeterminate);
84
all_non_conflict_unchecked &= !child_checked;
85
has_indeterminate_child |= child_indeterminate;
86
}
87
child_item = child_item->get_next();
88
}
89
if (has_indeterminate_child) {
90
p_item->set_indeterminate(p_column, true);
91
} else if (all_non_conflict_checked) {
92
p_item->set_checked(p_column, true);
93
} else if (all_non_conflict_unchecked) {
94
p_item->set_checked(p_column, false);
95
}
96
if (has_conflict_child) {
97
p_item->set_custom_color(p_column, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
98
} else {
99
p_item->clear_custom_color(p_column);
100
}
101
return has_conflict_child;
102
}
103
104
bool EditorAssetInstaller::_is_item_checked(const String &p_source_path) const {
105
return file_item_map.has(p_source_path) && (file_item_map[p_source_path]->is_checked(0) || file_item_map[p_source_path]->is_indeterminate(0));
106
}
107
108
void EditorAssetInstaller::open_asset(const String &p_path, bool p_autoskip_toplevel) {
109
package_path = p_path;
110
asset_files.clear();
111
112
Ref<FileAccess> io_fa;
113
zlib_filefunc_def io = zipio_create_io(&io_fa);
114
115
unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io);
116
if (!pkg) {
117
EditorToaster::get_singleton()->popup_str(vformat(TTR("Error opening asset file for \"%s\" (not in ZIP format)."), asset_name), EditorToaster::SEVERITY_ERROR);
118
return;
119
}
120
121
int ret = unzGoToFirstFile(pkg);
122
123
while (ret == UNZ_OK) {
124
//get filename
125
unz_file_info info;
126
char fname[16384];
127
unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
128
129
String source_name = String::utf8(fname);
130
131
// Create intermediate directories if they aren't reported by unzip.
132
// We are only interested in subfolders, so skip the root slash.
133
int separator = source_name.find_char('/', 1);
134
while (separator != -1) {
135
String dir_name = source_name.substr(0, separator + 1);
136
if (!dir_name.is_empty() && !asset_files.has(dir_name)) {
137
asset_files.insert(dir_name);
138
}
139
140
separator = source_name.find_char('/', separator + 1);
141
}
142
143
if (!source_name.is_empty() && !asset_files.has(source_name)) {
144
asset_files.insert(source_name);
145
}
146
147
ret = unzGoToNextFile(pkg);
148
}
149
150
unzClose(pkg);
151
152
asset_title_label->set_text(asset_name);
153
154
_check_has_toplevel();
155
// Default to false, unless forced.
156
skip_toplevel = p_autoskip_toplevel;
157
skip_toplevel_check->set_block_signals(true);
158
skip_toplevel_check->set_pressed(!skip_toplevel_check->is_disabled() && skip_toplevel);
159
skip_toplevel_check->set_block_signals(false);
160
161
_update_file_mappings();
162
_rebuild_source_tree();
163
_rebuild_destination_tree();
164
165
popup_centered_clamped(Size2(620, 640) * EDSCALE);
166
}
167
168
void EditorAssetInstaller::_update_file_mappings() {
169
mapped_files.clear();
170
171
bool first = true;
172
for (const String &E : asset_files) {
173
if (first) {
174
first = false;
175
176
if (!toplevel_prefix.is_empty() && skip_toplevel) {
177
continue;
178
}
179
}
180
181
String path = E; // We're going to mutate it.
182
if (!toplevel_prefix.is_empty() && skip_toplevel) {
183
path = path.trim_prefix(toplevel_prefix);
184
}
185
186
mapped_files[E] = path;
187
}
188
}
189
190
void EditorAssetInstaller::_rebuild_source_tree() {
191
updating_source = true;
192
source_tree->clear();
193
194
TreeItem *root = source_tree->create_item();
195
root->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
196
root->set_checked(0, true);
197
root->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));
198
root->set_text(0, "/");
199
root->set_editable(0, true);
200
201
file_item_map.clear();
202
HashMap<String, TreeItem *> directory_item_map;
203
int num_file_conflicts = 0;
204
first_file_conflict = nullptr;
205
206
for (const String &E : asset_files) {
207
String path = E; // We're going to mutate it.
208
209
bool is_directory = false;
210
if (path.ends_with("/")) {
211
path = path.trim_suffix("/");
212
is_directory = true;
213
}
214
215
TreeItem *parent_item;
216
217
int separator = path.rfind_char('/');
218
if (separator == -1) {
219
parent_item = root;
220
} else {
221
String parent_path = path.substr(0, separator);
222
HashMap<String, TreeItem *>::Iterator I = directory_item_map.find(parent_path);
223
ERR_CONTINUE(!I);
224
parent_item = I->value;
225
}
226
227
TreeItem *ti;
228
if (is_directory) {
229
ti = _create_dir_item(source_tree, parent_item, path, directory_item_map);
230
} else {
231
ti = _create_file_item(source_tree, parent_item, path, &num_file_conflicts);
232
}
233
file_item_map[E] = ti;
234
}
235
236
_update_conflict_status(num_file_conflicts);
237
_update_confirm_button();
238
239
updating_source = false;
240
}
241
242
void EditorAssetInstaller::_update_source_tree() {
243
int num_file_conflicts = 0;
244
first_file_conflict = nullptr;
245
246
for (const KeyValue<String, TreeItem *> &E : file_item_map) {
247
TreeItem *ti = E.value;
248
Dictionary item_meta = ti->get_metadata(0);
249
if ((bool)item_meta.get("is_dir", false)) {
250
continue;
251
}
252
253
String asset_path = item_meta.get("asset_path", "");
254
ERR_CONTINUE(asset_path.is_empty());
255
256
bool target_exists = _update_source_item_status(ti, asset_path);
257
if (target_exists) {
258
if (first_file_conflict == nullptr) {
259
first_file_conflict = ti;
260
}
261
num_file_conflicts += 1;
262
}
263
264
item_meta["is_conflict"] = target_exists;
265
ti->set_metadata(0, item_meta);
266
}
267
268
_update_conflict_status(num_file_conflicts);
269
_update_confirm_button();
270
}
271
272
bool EditorAssetInstaller::_update_source_item_status(TreeItem *p_item, const String &p_path) {
273
ERR_FAIL_COND_V(!mapped_files.has(p_path), false);
274
String target_path = target_dir_path.path_join(mapped_files[p_path]);
275
276
bool target_exists = FileAccess::exists(target_path);
277
if (target_exists) {
278
p_item->set_custom_color(0, get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
279
p_item->set_tooltip_text(0, vformat(TTR("%s (already exists)"), target_path));
280
p_item->set_checked(0, false);
281
} else {
282
p_item->clear_custom_color(0);
283
p_item->set_tooltip_text(0, target_path);
284
p_item->set_checked(0, true);
285
}
286
287
p_item->propagate_check(0);
288
_fix_conflicted_indeterminate_state(p_item->get_tree()->get_root(), 0);
289
return target_exists;
290
}
291
292
void EditorAssetInstaller::_rebuild_destination_tree() {
293
destination_tree->clear();
294
295
TreeItem *root = destination_tree->create_item();
296
root->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));
297
root->set_text(0, target_dir_path + (target_dir_path == "res://" ? "" : "/"));
298
299
HashMap<String, TreeItem *> directory_item_map;
300
301
for (const KeyValue<String, String> &E : mapped_files) {
302
if (!_is_item_checked(E.key)) {
303
continue;
304
}
305
306
String path = E.value; // We're going to mutate it.
307
308
bool is_directory = false;
309
if (path.ends_with("/")) {
310
path = path.trim_suffix("/");
311
is_directory = true;
312
}
313
314
TreeItem *parent_item;
315
316
int separator = path.rfind_char('/');
317
if (separator == -1) {
318
parent_item = root;
319
} else {
320
String parent_path = path.substr(0, separator);
321
HashMap<String, TreeItem *>::Iterator I = directory_item_map.find(parent_path);
322
ERR_CONTINUE(!I);
323
parent_item = I->value;
324
}
325
326
if (is_directory) {
327
_create_dir_item(destination_tree, parent_item, path, directory_item_map);
328
} else {
329
int num_file_conflicts = 0; // Don't need it, but need to pass something.
330
_create_file_item(destination_tree, parent_item, path, &num_file_conflicts);
331
}
332
}
333
}
334
335
TreeItem *EditorAssetInstaller::_create_dir_item(Tree *p_tree, TreeItem *p_parent, const String &p_path, HashMap<String, TreeItem *> &p_item_map) {
336
TreeItem *ti = p_tree->create_item(p_parent);
337
338
if (p_tree == source_tree) {
339
ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
340
ti->set_editable(0, true);
341
ti->set_checked(0, true);
342
ti->propagate_check(0);
343
_fix_conflicted_indeterminate_state(ti->get_tree()->get_root(), 0);
344
345
Dictionary meta;
346
meta["asset_path"] = p_path + "/";
347
meta["is_dir"] = true;
348
meta["is_conflict"] = false;
349
ti->set_metadata(0, meta);
350
}
351
352
ti->set_text(0, p_path.get_file() + "/");
353
ti->set_icon(0, get_theme_icon(SNAME("folder"), SNAME("FileDialog")));
354
355
p_item_map[p_path] = ti;
356
return ti;
357
}
358
359
TreeItem *EditorAssetInstaller::_create_file_item(Tree *p_tree, TreeItem *p_parent, const String &p_path, int *r_conflicts) {
360
TreeItem *ti = p_tree->create_item(p_parent);
361
362
if (p_tree == source_tree) {
363
ti->set_cell_mode(0, TreeItem::CELL_MODE_CHECK);
364
ti->set_editable(0, true);
365
366
bool target_exists = _update_source_item_status(ti, p_path);
367
if (target_exists) {
368
if (first_file_conflict == nullptr) {
369
first_file_conflict = ti;
370
}
371
*r_conflicts += 1;
372
}
373
374
Dictionary meta;
375
meta["asset_path"] = p_path;
376
meta["is_dir"] = false;
377
meta["is_conflict"] = target_exists;
378
ti->set_metadata(0, meta);
379
}
380
381
String file = p_path.get_file();
382
String extension = file.get_extension().to_lower();
383
if (extension_icon_map.has(extension)) {
384
ti->set_icon(0, extension_icon_map[extension]);
385
} else {
386
ti->set_icon(0, generic_extension_icon);
387
}
388
ti->set_text(0, file);
389
390
return ti;
391
}
392
393
void EditorAssetInstaller::_update_conflict_status(int p_conflicts) {
394
if (p_conflicts >= 1) {
395
asset_conflicts_link->set_text(vformat(TTRN("%d file conflicts with your project and won't be installed", "%d files conflict with your project and won't be installed", p_conflicts), p_conflicts));
396
asset_conflicts_link->show();
397
asset_conflicts_label->hide();
398
} else {
399
asset_conflicts_link->hide();
400
asset_conflicts_label->show();
401
}
402
}
403
404
void EditorAssetInstaller::_update_confirm_button() {
405
TreeItem *root = source_tree->get_root();
406
get_ok_button()->set_disabled(!root || (!root->is_checked(0) && !root->is_indeterminate(0)));
407
}
408
409
void EditorAssetInstaller::_toggle_source_tree(bool p_visible, bool p_scroll_to_error) {
410
source_tree_vb->set_visible(p_visible);
411
show_source_files_button->set_pressed_no_signal(p_visible); // To keep in sync if triggered by something else.
412
413
if (p_visible) {
414
show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));
415
} else {
416
show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));
417
}
418
419
if (p_visible && p_scroll_to_error && first_file_conflict) {
420
source_tree->scroll_to_item(first_file_conflict, true);
421
}
422
}
423
424
void EditorAssetInstaller::_check_has_toplevel() {
425
// Check if the file structure has a distinct top-level directory. This is typical
426
// for archives generated by GitHub, etc, but not for manually created ZIPs.
427
428
toplevel_prefix = "";
429
skip_toplevel_check->set_pressed(false);
430
skip_toplevel_check->set_disabled(true);
431
skip_toplevel_check->set_tooltip_text(TTRC("This asset doesn't have a root directory, so it can't be ignored."));
432
433
if (asset_files.is_empty()) {
434
return;
435
}
436
437
String first_asset;
438
for (const String &E : asset_files) {
439
if (first_asset.is_empty()) { // Checking the first file/directory.
440
if (!E.ends_with("/")) {
441
return; // No directories in this asset.
442
}
443
444
// We will match everything else against this directory.
445
first_asset = E;
446
continue;
447
}
448
449
if (!E.begins_with(first_asset)) {
450
return; // Found a file or a directory that doesn't share the same base path.
451
}
452
}
453
454
toplevel_prefix = first_asset;
455
skip_toplevel_check->set_disabled(false);
456
skip_toplevel_check->set_tooltip_text(TTRC("Ignore the root directory when extracting files."));
457
}
458
459
void EditorAssetInstaller::_set_skip_toplevel(bool p_checked) {
460
if (skip_toplevel == p_checked) {
461
return;
462
}
463
464
skip_toplevel = p_checked;
465
_update_file_mappings();
466
_update_source_tree();
467
_rebuild_destination_tree();
468
}
469
470
void EditorAssetInstaller::_open_target_dir_dialog() {
471
if (!target_dir_dialog) {
472
target_dir_dialog = memnew(EditorFileDialog);
473
target_dir_dialog->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_DIR);
474
target_dir_dialog->set_title(TTRC("Select Install Folder"));
475
target_dir_dialog->set_current_dir(target_dir_path);
476
target_dir_dialog->connect("dir_selected", callable_mp(this, &EditorAssetInstaller::_target_dir_selected));
477
add_child(target_dir_dialog);
478
}
479
480
target_dir_dialog->popup_file_dialog();
481
}
482
483
void EditorAssetInstaller::_target_dir_selected(const String &p_target_path) {
484
if (target_dir_path == p_target_path) {
485
return;
486
}
487
488
target_dir_path = p_target_path;
489
_update_file_mappings();
490
_update_source_tree();
491
_rebuild_destination_tree();
492
}
493
494
void EditorAssetInstaller::ok_pressed() {
495
_install_asset();
496
}
497
498
void EditorAssetInstaller::_install_asset() {
499
Ref<FileAccess> io_fa;
500
zlib_filefunc_def io = zipio_create_io(&io_fa);
501
502
unzFile pkg = unzOpen2(package_path.utf8().get_data(), &io);
503
if (!pkg) {
504
EditorToaster::get_singleton()->popup_str(vformat(TTR("Error opening asset file for \"%s\" (not in ZIP format)."), asset_name), EditorToaster::SEVERITY_ERROR);
505
return;
506
}
507
508
Vector<String> failed_files;
509
int ret = unzGoToFirstFile(pkg);
510
511
ProgressDialog::get_singleton()->add_task("uncompress", TTR("Uncompressing Assets"), file_item_map.size());
512
513
Ref<DirAccess> da = DirAccess::create(DirAccess::ACCESS_RESOURCES);
514
for (int idx = 0; ret == UNZ_OK; ret = unzGoToNextFile(pkg), idx++) {
515
unz_file_info info;
516
char fname[16384];
517
ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, nullptr, 0, nullptr, 0);
518
if (ret != UNZ_OK) {
519
break;
520
}
521
522
String source_name = String::utf8(fname);
523
if (!_is_item_checked(source_name)) {
524
continue;
525
}
526
527
HashMap<String, String>::Iterator E = mapped_files.find(source_name);
528
if (!E) {
529
continue; // No remapped path means we don't want it; most likely the root.
530
}
531
532
String target_path = target_dir_path.path_join(E->value);
533
534
Dictionary asset_meta = file_item_map[source_name]->get_metadata(0);
535
bool is_dir = asset_meta.get("is_dir", false);
536
if (is_dir) {
537
if (target_path.ends_with("/")) {
538
target_path = target_path.substr(0, target_path.length() - 1);
539
}
540
541
da->make_dir_recursive(target_path);
542
} else {
543
Vector<uint8_t> uncomp_data;
544
uncomp_data.resize(info.uncompressed_size);
545
546
unzOpenCurrentFile(pkg);
547
unzReadCurrentFile(pkg, uncomp_data.ptrw(), uncomp_data.size());
548
unzCloseCurrentFile(pkg);
549
550
// Ensure that the target folder exists.
551
da->make_dir_recursive(target_path.get_base_dir());
552
553
Ref<FileAccess> f = FileAccess::open(target_path, FileAccess::WRITE);
554
if (f.is_valid()) {
555
f->store_buffer(uncomp_data.ptr(), uncomp_data.size());
556
} else {
557
failed_files.push_back(target_path);
558
}
559
560
ProgressDialog::get_singleton()->task_step("uncompress", target_path, idx);
561
}
562
}
563
564
ProgressDialog::get_singleton()->end_task("uncompress");
565
unzClose(pkg);
566
567
if (failed_files.size()) {
568
String msg = vformat(TTR("The following files failed extraction from asset \"%s\":"), asset_name) + "\n\n";
569
for (int i = 0; i < failed_files.size(); i++) {
570
if (i > 10) {
571
msg += "\n" + vformat(TTR("(and %s more files)"), itos(failed_files.size() - i));
572
break;
573
}
574
msg += "\n" + failed_files[i];
575
}
576
if (EditorNode::get_singleton() != nullptr) {
577
EditorNode::get_singleton()->show_warning(msg);
578
}
579
} else {
580
if (EditorNode::get_singleton() != nullptr) {
581
EditorNode::get_singleton()->show_warning(vformat(TTR("Asset \"%s\" installed successfully!"), asset_name), TTRC("Success!"));
582
}
583
}
584
585
EditorFileSystem::get_singleton()->scan_changes();
586
}
587
588
void EditorAssetInstaller::set_asset_name(const String &p_asset_name) {
589
asset_name = p_asset_name;
590
}
591
592
String EditorAssetInstaller::get_asset_name() const {
593
return asset_name;
594
}
595
596
void EditorAssetInstaller::_notification(int p_what) {
597
switch (p_what) {
598
case NOTIFICATION_THEME_CHANGED: {
599
if (show_source_files_button->is_pressed()) {
600
show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Back")));
601
} else {
602
show_source_files_button->set_button_icon(get_editor_theme_icon(SNAME("Forward")));
603
}
604
asset_conflicts_link->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
605
606
generic_extension_icon = get_editor_theme_icon(SNAME("Object"));
607
608
extension_icon_map.clear();
609
{
610
extension_icon_map["bmp"] = get_editor_theme_icon(SNAME("ImageTexture"));
611
extension_icon_map["dds"] = get_editor_theme_icon(SNAME("ImageTexture"));
612
extension_icon_map["exr"] = get_editor_theme_icon(SNAME("ImageTexture"));
613
extension_icon_map["hdr"] = get_editor_theme_icon(SNAME("ImageTexture"));
614
extension_icon_map["jpg"] = get_editor_theme_icon(SNAME("ImageTexture"));
615
extension_icon_map["jpeg"] = get_editor_theme_icon(SNAME("ImageTexture"));
616
extension_icon_map["png"] = get_editor_theme_icon(SNAME("ImageTexture"));
617
extension_icon_map["svg"] = get_editor_theme_icon(SNAME("ImageTexture"));
618
extension_icon_map["tga"] = get_editor_theme_icon(SNAME("ImageTexture"));
619
extension_icon_map["webp"] = get_editor_theme_icon(SNAME("ImageTexture"));
620
621
extension_icon_map["wav"] = get_editor_theme_icon(SNAME("AudioStreamWAV"));
622
extension_icon_map["ogg"] = get_editor_theme_icon(SNAME("AudioStreamOggVorbis"));
623
extension_icon_map["mp3"] = get_editor_theme_icon(SNAME("AudioStreamMP3"));
624
625
extension_icon_map["scn"] = get_editor_theme_icon(SNAME("PackedScene"));
626
extension_icon_map["tscn"] = get_editor_theme_icon(SNAME("PackedScene"));
627
extension_icon_map["escn"] = get_editor_theme_icon(SNAME("PackedScene"));
628
extension_icon_map["dae"] = get_editor_theme_icon(SNAME("PackedScene"));
629
extension_icon_map["gltf"] = get_editor_theme_icon(SNAME("PackedScene"));
630
extension_icon_map["glb"] = get_editor_theme_icon(SNAME("PackedScene"));
631
632
extension_icon_map["gdshader"] = get_editor_theme_icon(SNAME("Shader"));
633
extension_icon_map["gdshaderinc"] = get_editor_theme_icon(SNAME("TextFile"));
634
extension_icon_map["gd"] = get_editor_theme_icon(SNAME("GDScript"));
635
if (ClassDB::class_exists("CSharpScript")) {
636
extension_icon_map["cs"] = get_editor_theme_icon(SNAME("CSharpScript"));
637
} else {
638
// Mark C# support as unavailable.
639
extension_icon_map["cs"] = get_editor_theme_icon(SNAME("ImportFail"));
640
}
641
642
extension_icon_map["res"] = get_editor_theme_icon(SNAME("Resource"));
643
extension_icon_map["tres"] = get_editor_theme_icon(SNAME("Resource"));
644
extension_icon_map["atlastex"] = get_editor_theme_icon(SNAME("AtlasTexture"));
645
// By default, OBJ files are imported as Mesh resources rather than PackedScenes.
646
extension_icon_map["obj"] = get_editor_theme_icon(SNAME("MeshItem"));
647
648
extension_icon_map["txt"] = get_editor_theme_icon(SNAME("TextFile"));
649
extension_icon_map["md"] = get_editor_theme_icon(SNAME("TextFile"));
650
extension_icon_map["rst"] = get_editor_theme_icon(SNAME("TextFile"));
651
extension_icon_map["json"] = get_editor_theme_icon(SNAME("TextFile"));
652
extension_icon_map["yml"] = get_editor_theme_icon(SNAME("TextFile"));
653
extension_icon_map["yaml"] = get_editor_theme_icon(SNAME("TextFile"));
654
extension_icon_map["toml"] = get_editor_theme_icon(SNAME("TextFile"));
655
extension_icon_map["cfg"] = get_editor_theme_icon(SNAME("TextFile"));
656
extension_icon_map["ini"] = get_editor_theme_icon(SNAME("TextFile"));
657
}
658
} break;
659
}
660
}
661
662
EditorAssetInstaller::EditorAssetInstaller() {
663
VBoxContainer *vb = memnew(VBoxContainer);
664
add_child(vb);
665
666
// Status bar.
667
668
HBoxContainer *asset_status = memnew(HBoxContainer);
669
vb->add_child(asset_status);
670
671
Label *asset_label = memnew(Label);
672
asset_label->set_text(TTRC("Asset:"));
673
asset_label->set_theme_type_variation("HeaderSmall");
674
asset_status->add_child(asset_label);
675
676
asset_title_label = memnew(Label);
677
asset_title_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
678
asset_status->add_child(asset_title_label);
679
680
// File remapping controls.
681
682
HBoxContainer *remapping_tools = memnew(HBoxContainer);
683
vb->add_child(remapping_tools);
684
685
show_source_files_button = memnew(Button);
686
show_source_files_button->set_toggle_mode(true);
687
show_source_files_button->set_tooltip_text(TTRC("Open the list of the asset contents and select which files to install."));
688
remapping_tools->add_child(show_source_files_button);
689
show_source_files_button->connect(SceneStringName(toggled), callable_mp(this, &EditorAssetInstaller::_toggle_source_tree).bind(false));
690
691
Button *target_dir_button = memnew(Button);
692
target_dir_button->set_text(TTRC("Change Install Folder"));
693
target_dir_button->set_tooltip_text(TTRC("Change the folder where the contents of the asset are going to be installed."));
694
remapping_tools->add_child(target_dir_button);
695
target_dir_button->connect(SceneStringName(pressed), callable_mp(this, &EditorAssetInstaller::_open_target_dir_dialog));
696
697
remapping_tools->add_child(memnew(VSeparator));
698
699
skip_toplevel_check = memnew(CheckBox);
700
skip_toplevel_check->set_text(TTRC("Ignore asset root"));
701
skip_toplevel_check->set_tooltip_text(TTRC("Ignore the root directory when extracting files."));
702
skip_toplevel_check->connect(SceneStringName(toggled), callable_mp(this, &EditorAssetInstaller::_set_skip_toplevel));
703
remapping_tools->add_child(skip_toplevel_check);
704
705
remapping_tools->add_spacer();
706
707
asset_conflicts_label = memnew(Label);
708
asset_conflicts_label->set_focus_mode(Control::FOCUS_ACCESSIBILITY);
709
asset_conflicts_label->set_theme_type_variation("HeaderSmall");
710
asset_conflicts_label->set_text(TTRC("No files conflict with your project"));
711
remapping_tools->add_child(asset_conflicts_label);
712
asset_conflicts_link = memnew(LinkButton);
713
asset_conflicts_link->set_theme_type_variation("HeaderSmallLink");
714
asset_conflicts_link->set_v_size_flags(Control::SIZE_SHRINK_CENTER);
715
asset_conflicts_link->set_tooltip_text(TTRC("Show contents of the asset and conflicting files."));
716
asset_conflicts_link->set_visible(false);
717
remapping_tools->add_child(asset_conflicts_link);
718
asset_conflicts_link->connect(SceneStringName(pressed), callable_mp(this, &EditorAssetInstaller::_toggle_source_tree).bind(true, true));
719
720
// File hierarchy trees.
721
722
HSplitContainer *tree_split = memnew(HSplitContainer);
723
tree_split->set_v_size_flags(Control::SIZE_EXPAND_FILL);
724
vb->add_child(tree_split);
725
726
source_tree_vb = memnew(VBoxContainer);
727
source_tree_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
728
source_tree_vb->set_visible(show_source_files_button->is_pressed());
729
tree_split->add_child(source_tree_vb);
730
731
Label *source_tree_label = memnew(Label);
732
source_tree_label->set_text(TTRC("Contents of the asset:"));
733
source_tree_label->set_theme_type_variation("HeaderSmall");
734
source_tree_vb->add_child(source_tree_label);
735
736
source_tree = memnew(Tree);
737
source_tree->set_accessibility_name(TTRC("Source Files"));
738
source_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
739
source_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
740
source_tree->connect("item_edited", callable_mp(this, &EditorAssetInstaller::_item_checked_cbk));
741
source_tree->set_theme_type_variation("TreeSecondary");
742
source_tree_vb->add_child(source_tree);
743
744
VBoxContainer *destination_tree_vb = memnew(VBoxContainer);
745
destination_tree_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL);
746
tree_split->add_child(destination_tree_vb);
747
748
Label *destination_tree_label = memnew(Label);
749
destination_tree_label->set_text(TTRC("Installation preview:"));
750
destination_tree_label->set_theme_type_variation("HeaderSmall");
751
destination_tree_vb->add_child(destination_tree_label);
752
753
destination_tree = memnew(Tree);
754
destination_tree->set_accessibility_name(TTRC("Destination Files"));
755
destination_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
756
destination_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL);
757
destination_tree->connect("item_edited", callable_mp(this, &EditorAssetInstaller::_item_checked_cbk));
758
destination_tree_vb->add_child(destination_tree);
759
760
// Dialog configuration.
761
762
set_title(TTRC("Configure Asset Before Installing"));
763
set_ok_button_text(TTRC("Install"));
764
set_hide_on_ok(true);
765
}
766
767