diff options
Diffstat (limited to 'editor')
-rw-r--r-- | editor/editor_export.cpp | 3 | ||||
-rw-r--r-- | editor/editor_node.cpp | 87 | ||||
-rw-r--r-- | editor/editor_node.h | 6 | ||||
-rw-r--r-- | editor/export_template_manager.cpp | 395 | ||||
-rw-r--r-- | editor/export_template_manager.h | 40 | ||||
-rw-r--r-- | editor/project_export.cpp | 60 | ||||
-rw-r--r-- | editor/project_export.h | 6 |
7 files changed, 520 insertions, 77 deletions
diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 7ac299974c..bbc5d7dbd1 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -51,7 +51,7 @@ static int _get_pad(int p_alignment, int p_n) { }; return pad; -}; +} #define PCK_PADDING 16 @@ -870,6 +870,7 @@ bool EditorExportPlatformPC::can_export(const Ref<EditorExportPreset> &p_preset, } else if (find_export_template(debug_file_64) == String()) { r_missing_templates = true; } + return !r_missing_templates; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3319f1cbee..078bb95ec9 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -1201,78 +1201,9 @@ void EditorNode::_dialog_action(String p_file) { } } break; - case SETTINGS_LOAD_EXPORT_TEMPLATES: { + // case SETTINGS_LOAD_EXPORT_TEMPLATES: { - FileAccess *fa = NULL; - zlib_filefunc_def io = zipio_create_io_from_file(&fa); - - unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); - if (!pkg) { - - current_option = -1; - //confirmation->get_cancel()->hide(); - accept->get_ok()->set_text(TTR("I see..")); - accept->set_text(TTR("Can't open export templates zip.")); - accept->popup_centered_minsize(); - return; - } - int ret = unzGoToFirstFile(pkg); - - int fc = 0; //count them - - while (ret == UNZ_OK) { - fc++; - ret = unzGoToNextFile(pkg); - } - - ret = unzGoToFirstFile(pkg); - - EditorProgress p("ltask", TTR("Loading Export Templates"), fc); - - fc = 0; - - while (ret == UNZ_OK) { - - //get filename - unz_file_info info; - char fname[16384]; - ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); - - String file = fname; - - Vector<uint8_t> data; - data.resize(info.uncompressed_size); - - //read - ret = unzOpenCurrentFile(pkg); - ret = unzReadCurrentFile(pkg, data.ptr(), data.size()); - unzCloseCurrentFile(pkg); - - print_line(fname); - /* - for(int i=0;i<512;i++) { - print_line(itos(data[i])); - } - */ - - file = file.get_file(); - - p.step(TTR("Importing:") + " " + file, fc); - - FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_settings_path() + "/templates/" + file, FileAccess::WRITE); - - ERR_CONTINUE(!f); - f->store_buffer(data.ptr(), data.size()); - - memdelete(f); - - ret = unzGoToNextFile(pkg); - fc++; - } - - unzClose(pkg); - - } break; + // } break; case RESOURCE_SAVE: case RESOURCE_SAVE_AS: { @@ -2604,9 +2535,9 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { //optimized_presets->popup_centered_ratio(); } break; - case SETTINGS_LOAD_EXPORT_TEMPLATES: { + case SETTINGS_MANAGE_EXPORT_TEMPLATES: { - file_templates->popup_centered_ratio(); + export_template_manager->popup_manager(); } break; case SETTINGS_TOGGLE_FULLSCREN: { @@ -4759,6 +4690,11 @@ void EditorNode::_dim_timeout() { } } +void EditorNode::open_export_template_manager() { + + export_template_manager->popup_manager(); +} + void EditorNode::_bind_methods() { ClassDB::bind_method("_menu_option", &EditorNode::_menu_option); @@ -5529,7 +5465,7 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT("editor/fullscreen_mode", TTR("Toggle Fullscreen"), KEY_MASK_SHIFT | KEY_F11), SETTINGS_TOGGLE_FULLSCREN); p->add_separator(); - p->add_item(TTR("Install Export Templates"), SETTINGS_LOAD_EXPORT_TEMPLATES); + p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES); p->add_separator(); p->add_item(TTR("About"), SETTINGS_ABOUT); @@ -5855,6 +5791,9 @@ EditorNode::EditorNode() { run_settings_dialog = memnew(RunSettingsDialog); gui_base->add_child(run_settings_dialog); + export_template_manager = memnew(ExportTemplateManager); + gui_base->add_child(export_template_manager); + about = memnew(AcceptDialog); about->set_title(TTR("Thanks from the Godot community!")); about->get_ok()->set_text(TTR("Thanks!")); diff --git a/editor/editor_node.h b/editor/editor_node.h index ef8ae34475..5182650abc 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -35,6 +35,7 @@ #include "editor/editor_data.h" #include "editor/editor_path.h" #include "editor/editor_run.h" +#include "editor/export_template_manager.h" #include "editor/filesystem_dock.h" #include "editor/groups_editor.h" #include "editor/import_dock.h" @@ -180,7 +181,7 @@ private: SETTINGS_LAYOUT_SAVE, SETTINGS_LAYOUT_DELETE, SETTINGS_LAYOUT_DEFAULT, - SETTINGS_LOAD_EXPORT_TEMPLATES, + SETTINGS_MANAGE_EXPORT_TEMPLATES, SETTINGS_PICK_MAIN_SCENE, SETTINGS_TOGGLE_FULLSCREN, SETTINGS_HELP, @@ -300,6 +301,7 @@ private: RunSettingsDialog *run_settings_dialog; ProjectSettings *project_settings; EditorFileDialog *file; + ExportTemplateManager *export_template_manager; FileDialog *file_templates; FileDialog *file_export; FileDialog *file_export_lib; @@ -739,6 +741,8 @@ public: void update_keying(); + void open_export_template_manager(); + void reload_scene(const String &p_path); bool is_exiting() const { return exiting; } diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp new file mode 100644 index 0000000000..83ada90144 --- /dev/null +++ b/editor/export_template_manager.cpp @@ -0,0 +1,395 @@ +#include "export_template_manager.h" +#include "editor_node.h" +#include "editor_scale.h" +#include "os/dir_access.h" +#include "version.h" + +#include "io/zip_io.h" + +void ExportTemplateManager::_update_template_list() { + + while (current_hb->get_child_count()) { + memdelete(current_hb->get_child(0)); + } + + while (installed_vb->get_child_count()) { + memdelete(installed_vb->get_child(0)); + } + + DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + Error err = d->change_dir(EditorSettings::get_singleton()->get_settings_path().plus_file("templates")); + + d->list_dir_begin(); + Set<String> templates; + + if (err == OK) { + + bool isdir; + String c = d->get_next(&isdir); + while (c != String()) { + if (isdir && !c.begins_with(".")) { + templates.insert(c); + } + c = d->get_next(&isdir); + } + } + d->list_dir_end(); + + memdelete(d); + + String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS); + + Label *current = memnew(Label); + current->set_h_size_flags(SIZE_EXPAND_FILL); + current_hb->add_child(current); + + if (templates.has(current_version)) { + current->add_color_override("font_color", Color(0.5, 1, 0.5)); + Button *redownload = memnew(Button); + redownload->set_text(TTR("Re-Download")); + current_hb->add_child(redownload); + redownload->connect("pressed", this, "_download_template", varray(current_version)); + + Button *uninstall = memnew(Button); + uninstall->set_text(TTR("Uninstall")); + current_hb->add_child(uninstall); + current->set_text(current_version + " " + TTR("(Installed)")); + uninstall->connect("pressed", this, "_uninstall_template", varray(current_version)); + + } else { + current->add_color_override("font_color", Color(1.0, 0.5, 0.5)); + Button *redownload = memnew(Button); + redownload->set_text(TTR("Download")); + redownload->connect("pressed", this, "_download_template", varray(current_version)); + current_hb->add_child(redownload); + current->set_text(current_version + " " + TTR("(Missing)")); + } + + for (Set<String>::Element *E = templates.back(); E; E = E->prev()) { + + HBoxContainer *hbc = memnew(HBoxContainer); + Label *version = memnew(Label); + version->set_modulate(Color(1, 1, 1, 0.7)); + String text = E->get(); + if (text == current_version) { + text += " " + TTR("(Current)"); + } + version->set_text(text); + version->set_h_size_flags(SIZE_EXPAND_FILL); + hbc->add_child(version); + + Button *uninstall = memnew(Button); + + uninstall->set_text(TTR("Uninstall")); + hbc->add_child(uninstall); + uninstall->connect("pressed", this, "_uninstall_template", varray(E->get())); + + installed_vb->add_child(hbc); + } +} + +void ExportTemplateManager::_download_template(const String &p_version) { + + print_line("download " + p_version); +} + +void ExportTemplateManager::_uninstall_template(const String &p_version) { + + remove_confirm->set_text(vformat(TTR("Remove template version '%s'?"), p_version)); + remove_confirm->popup_centered_minsize(); + to_remove = p_version; +} + +void ExportTemplateManager::_uninstall_template_confirm() { + + DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + Error err = d->change_dir(EditorSettings::get_singleton()->get_settings_path().plus_file("templates")); + + ERR_FAIL_COND(err != OK); + + err = d->change_dir(to_remove); + + ERR_FAIL_COND(err != OK); + + Vector<String> files; + + d->list_dir_begin(); + + bool isdir; + String c = d->get_next(&isdir); + while (c != String()) { + if (!isdir) { + files.push_back(c); + } + c = d->get_next(&isdir); + } + + d->list_dir_end(); + + for (int i = 0; i < files.size(); i++) { + d->remove(files[i]); + } + + d->change_dir(".."); + d->remove(to_remove); + + _update_template_list(); +} + +void ExportTemplateManager::_install_from_file(const String &p_file) { + + FileAccess *fa = NULL; + zlib_filefunc_def io = zipio_create_io_from_file(&fa); + + unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); + if (!pkg) { + + EditorNode::get_singleton()->show_warning(TTR("Can't open export templates zip.")); + return; + } + int ret = unzGoToFirstFile(pkg); + + int fc = 0; //count them and find version + String version; + + while (ret == UNZ_OK) { + + unz_file_info info; + char fname[16384]; + ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); + + String file = fname; + + if (file.ends_with("version.txt")) { + + Vector<uint8_t> data; + data.resize(info.uncompressed_size); + + //read + ret = unzOpenCurrentFile(pkg); + ret = unzReadCurrentFile(pkg, data.ptr(), data.size()); + unzCloseCurrentFile(pkg); + + String data_str; + data_str.parse_utf8((const char *)data.ptr(), data.size()); + data_str = data_str.strip_edges(); + + if (data_str.get_slice_count("-") != 2 || data_str.get_slice_count(".") != 2) { + EditorNode::get_singleton()->show_warning(TTR("Invalid version.txt format inside templates.")); + unzClose(pkg); + return; + } + + String ver = data_str.get_slice("-", 0); + + int major = ver.get_slice(".", 0).to_int(); + int minor = ver.get_slice(".", 1).to_int(); + String rev = data_str.get_slice("-", 1); + + if (!rev.is_valid_identifier()) { + EditorNode::get_singleton()->show_warning(TTR("Invalid version.txt format inside templates. Revision is not a valid identifier.")); + unzClose(pkg); + return; + } + + version = itos(major) + "." + itos(minor) + "-" + rev; + } + + fc++; + ret = unzGoToNextFile(pkg); + } + + if (version == String()) { + EditorNode::get_singleton()->show_warning(TTR("No version.txt found inside templates.")); + unzClose(pkg); + return; + } + + String template_path = EditorSettings::get_singleton()->get_settings_path().plus_file("templates").plus_file(version); + + DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + Error err = d->make_dir_recursive(template_path); + if (err != OK) { + EditorNode::get_singleton()->show_warning(TTR("Error creating path for templates:\n") + template_path); + unzClose(pkg); + return; + } + + memdelete(d); + + ret = unzGoToFirstFile(pkg); + + EditorProgress p("ltask", TTR("Extracting Export Templates"), fc); + + fc = 0; + + while (ret == UNZ_OK) { + + //get filename + unz_file_info info; + char fname[16384]; + ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); + + String file = fname; + + Vector<uint8_t> data; + data.resize(info.uncompressed_size); + + //read + ret = unzOpenCurrentFile(pkg); + ret = unzReadCurrentFile(pkg, data.ptr(), data.size()); + unzCloseCurrentFile(pkg); + + print_line(fname); + /* + for(int i=0;i<512;i++) { + print_line(itos(data[i])); + } + */ + + file = file.get_file(); + + p.step(TTR("Importing:") + " " + file, fc); + + FileAccess *f = FileAccess::open(template_path.plus_file(file), FileAccess::WRITE); + + ERR_CONTINUE(!f); + f->store_buffer(data.ptr(), data.size()); + + memdelete(f); + + ret = unzGoToNextFile(pkg); + fc++; + } + + unzClose(pkg); + + _update_template_list(); +} + +void ExportTemplateManager::popup_manager() { + + _update_template_list(); + popup_centered_minsize(Size2(400, 600) * EDSCALE); +} + +void ExportTemplateManager::ok_pressed() { + + template_open->popup_centered_ratio(); +} + +void ExportTemplateManager::_bind_methods() { + + ClassDB::bind_method("_download_template", &ExportTemplateManager::_download_template); + ClassDB::bind_method("_uninstall_template", &ExportTemplateManager::_uninstall_template); + ClassDB::bind_method("_uninstall_template_confirm", &ExportTemplateManager::_uninstall_template_confirm); + ClassDB::bind_method("_install_from_file", &ExportTemplateManager::_install_from_file); + +#if 0 + FileAccess *fa = NULL; + zlib_filefunc_def io = zipio_create_io_from_file(&fa); + + unzFile pkg = unzOpen2(p_file.utf8().get_data(), &io); + if (!pkg) { + + current_option = -1; + //confirmation->get_cancel()->hide(); + accept->get_ok()->set_text(TTR("I see..")); + accept->set_text(TTR("Can't open export templates zip.")); + accept->popup_centered_minsize(); + return; + } + int ret = unzGoToFirstFile(pkg); + + int fc = 0; //count them + + while (ret == UNZ_OK) { + fc++; + ret = unzGoToNextFile(pkg); + } + + ret = unzGoToFirstFile(pkg); + + EditorProgress p("ltask", TTR("Loading Export Templates"), fc); + + fc = 0; + + while (ret == UNZ_OK) { + + //get filename + unz_file_info info; + char fname[16384]; + ret = unzGetCurrentFileInfo(pkg, &info, fname, 16384, NULL, 0, NULL, 0); + + String file = fname; + + Vector<uint8_t> data; + data.resize(info.uncompressed_size); + + //read + ret = unzOpenCurrentFile(pkg); + ret = unzReadCurrentFile(pkg, data.ptr(), data.size()); + unzCloseCurrentFile(pkg); + + print_line(fname); + /* + for(int i=0;i<512;i++) { + print_line(itos(data[i])); + } + */ + + file = file.get_file(); + + p.step(TTR("Importing:") + " " + file, fc); + + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_settings_path() + "/templates/" + file, FileAccess::WRITE); + + ERR_CONTINUE(!f); + f->store_buffer(data.ptr(), data.size()); + + memdelete(f); + + ret = unzGoToNextFile(pkg); + fc++; + } + + unzClose(pkg); +#endif +} + +ExportTemplateManager::ExportTemplateManager() { + + VBoxContainer *main_vb = memnew(VBoxContainer); + add_child(main_vb); + + current_hb = memnew(HBoxContainer); + main_vb->add_margin_child(TTR("Current Version:"), current_hb, false); + + installed_scroll = memnew(ScrollContainer); + main_vb->add_margin_child(TTR("Installed Versions:"), installed_scroll, true); + + installed_vb = memnew(VBoxContainer); + installed_scroll->add_child(installed_vb); + installed_scroll->set_enable_v_scroll(true); + installed_scroll->set_enable_h_scroll(false); + installed_vb->set_h_size_flags(SIZE_EXPAND_FILL); + + get_cancel()->set_text(TTR("Close")); + get_ok()->set_text(TTR("Install From File")); + + remove_confirm = memnew(ConfirmationDialog); + remove_confirm->set_title(TTR("Remove Template")); + add_child(remove_confirm); + remove_confirm->connect("confirmed", this, "_uninstall_template_confirm"); + + template_open = memnew(FileDialog); + template_open->set_title(TTR("Select template file")); + template_open->add_filter("*.tpz ; Godot Export Templates"); + template_open->set_access(FileDialog::ACCESS_FILESYSTEM); + template_open->set_mode(FileDialog::MODE_OPEN_FILE); + template_open->connect("file_selected", this, "_install_from_file"); + add_child(template_open); + + set_title(TTR("Export Template Manager")); + set_hide_on_ok(false); +} diff --git a/editor/export_template_manager.h b/editor/export_template_manager.h new file mode 100644 index 0000000000..c3834ec643 --- /dev/null +++ b/editor/export_template_manager.h @@ -0,0 +1,40 @@ +#ifndef EXPORT_TEMPLATE_MANAGER_H +#define EXPORT_TEMPLATE_MANAGER_H + +#include "editor/editor_settings.h" +#include "scene/gui/dialogs.h" +#include "scene/gui/file_dialog.h" +#include "scene/gui/scroll_container.h" + +class ExportTemplateVersion; + +class ExportTemplateManager : public ConfirmationDialog { + GDCLASS(ExportTemplateManager, ConfirmationDialog) + + ScrollContainer *installed_scroll; + VBoxContainer *installed_vb; + HBoxContainer *current_hb; + FileDialog *template_open; + + ConfirmationDialog *remove_confirm; + String to_remove; + + void _update_template_list(); + + void _download_template(const String &p_version); + void _uninstall_template(const String &p_version); + void _uninstall_template_confirm(); + + virtual void ok_pressed(); + void _install_from_file(const String &p_file); + +protected: + static void _bind_methods(); + +public: + void popup_manager(); + + ExportTemplateManager(); +}; + +#endif // EXPORT_TEMPLATE_MANAGER_H diff --git a/editor/project_export.cpp b/editor/project_export.cpp index 78327a5d66..f01536e521 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -155,6 +155,8 @@ void ProjectExportDialog::_edit_preset(int p_index) { delete_preset->set_disabled(true); sections->hide(); patches->clear(); + export_error->hide(); + export_templates_error->hide(); return; } @@ -205,6 +207,33 @@ void ProjectExportDialog::_edit_preset(int p_index) { _fill_resource_tree(); + bool needs_templates; + String error; + if (!current->get_platform()->can_export(current, error, needs_templates)) { + + if (error != String()) { + + Vector<String> items = error.split("\n"); + error = ""; + for (int i = 0; i < items.size(); i++) { + if (i > 0) + error += "\n"; + error += " - " + items[i]; + } + + export_error->set_text(error); + export_error->show(); + } else { + export_error->hide(); + } + if (needs_templates) + export_templates_error->show(); + + } else { + export_error->show(); + export_templates_error->hide(); + } + updating = false; } @@ -607,6 +636,12 @@ void ProjectExportDialog::_export_pck_zip_selected(const String &p_path) { } } +void ProjectExportDialog::_open_export_template_manager() { + + EditorNode::get_singleton()->open_export_template_manager(); + hide(); +} + void ProjectExportDialog::_bind_methods() { ClassDB::bind_method("_add_preset", &ProjectExportDialog::_add_preset); @@ -627,14 +662,18 @@ void ProjectExportDialog::_bind_methods() { ClassDB::bind_method("_patch_edited", &ProjectExportDialog::_patch_edited); ClassDB::bind_method("_export_pck_zip", &ProjectExportDialog::_export_pck_zip); ClassDB::bind_method("_export_pck_zip_selected", &ProjectExportDialog::_export_pck_zip_selected); + ClassDB::bind_method("_open_export_template_manager", &ProjectExportDialog::_open_export_template_manager); } ProjectExportDialog::ProjectExportDialog() { set_title(TTR("Export")); set_resizable(true); + VBoxContainer *main_vb = memnew(VBoxContainer); + add_child(main_vb); HBoxContainer *hbox = memnew(HBoxContainer); - add_child(hbox); + main_vb->add_child(hbox); + hbox->set_v_size_flags(SIZE_EXPAND_FILL); VBoxContainer *preset_vb = memnew(VBoxContainer); preset_vb->set_h_size_flags(Control::SIZE_EXPAND_FILL); @@ -770,6 +809,25 @@ ProjectExportDialog::ProjectExportDialog() { add_child(export_pck_zip); export_pck_zip->connect("file_selected", this, "_export_pck_zip_selected"); + export_error = memnew(Label); + main_vb->add_child(export_error); + export_error->hide(); + export_error->add_color_override("font_color", Color(1, 0.5, 0.5)); + + export_templates_error = memnew(HBoxContainer); + main_vb->add_child(export_templates_error); + export_templates_error->hide(); + + Label *export_error2 = memnew(Label); + export_templates_error->add_child(export_error2); + export_error2->add_color_override("font_color", Color(1, 0.5, 0.5)); + export_error2->set_text(" - " + TTR("Export templates for this platform are missing:") + " "); + + LinkButton *download_templates = memnew(LinkButton); + download_templates->set_text(TTR("Manage Export Templates")); + export_templates_error->add_child(download_templates); + download_templates->connect("pressed", this, "_open_export_template_manager"); + set_hide_on_ok(false); editor_icons = "EditorIcons"; diff --git a/editor/project_export.h b/editor/project_export.h index dff3ab356f..2d9ae9b122 100644 --- a/editor/project_export.h +++ b/editor/project_export.h @@ -37,6 +37,7 @@ #include "scene/gui/dialogs.h" #include "scene/gui/file_dialog.h" #include "scene/gui/label.h" +#include "scene/gui/link_button.h" #include "scene/gui/option_button.h" #include "scene/gui/tab_container.h" #include "scene/gui/tree.h" @@ -89,6 +90,9 @@ private: Button *export_button; + Label *export_error; + HBoxContainer *export_templates_error; + void _patch_selected(const String &p_path); void _patch_deleted(); @@ -116,6 +120,8 @@ private: FileDialog *export_pck_zip; + void _open_export_template_manager(); + void _export_pck_zip(); void _export_pck_zip_selected(const String &p_path); |