diff options
-rw-r--r-- | doc/base/classes.xml | 56 | ||||
-rw-r--r-- | scene/2d/canvas_item.cpp | 11 | ||||
-rw-r--r-- | scene/2d/canvas_item.h | 1 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 22 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 3 | ||||
-rw-r--r-- | scene/resources/default_theme/default_theme.cpp | 6 | ||||
-rw-r--r-- | tools/editor/asset_library_editor_plugin.cpp | 26 | ||||
-rw-r--r-- | tools/editor/asset_library_editor_plugin.h | 5 | ||||
-rw-r--r-- | tools/editor/editor_node.cpp | 3 | ||||
-rw-r--r-- | tools/editor/editor_settings.cpp | 4 | ||||
-rw-r--r-- | tools/editor/plugins/script_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | tools/editor/plugins/shader_editor_plugin.cpp | 2 | ||||
-rw-r--r-- | tools/editor/project_manager.cpp | 217 | ||||
-rw-r--r-- | tools/editor/project_manager.h | 2 |
14 files changed, 323 insertions, 37 deletions
diff --git a/doc/base/classes.xml b/doc/base/classes.xml index b5384cfc2b..ae5438c430 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -7339,6 +7339,22 @@ </description> </method> <method name="update"> + <method name="make_screen_coord_local" qualifiers="const"> + <return type="Vector2"> + </return> + <argument index="0" name="screen_point" type="Vector2"> + </argument> + <description> + Take a 2d screen point and convert to 2D local coords relative to this Canvas + item. If this CanvasItem is the root of a Scene, its essentially the + world coords for that scene. + </description> + </method> + <method name="make_input_local" qualifiers="const"> + <return type="InputEvent"> + </return> + <argument index="0" name="event" type="InputEvent"> + </argument> <description> Queue the CanvasItem for update. [code]NOTIFICATION_DRAW[/code] will be called on idle time to request redraw. </description> @@ -39392,6 +39408,34 @@ Set the color for symbols. </description> </method> + <method name="set_show_line_numbers"> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + Set to enable showing line numbers. + </description> + </method> + <method name="is_show_line_numbers_enabled" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns true if line numbers are enabled. + </description> + </method> + <method name="set_highlight_all_occurrences"> + <argument index="0" name="enable" type="bool"> + </argument> + <description> + Set to enable highlighting all occurrences of the current selection. + </description> + </method> + <method name="is_highlight_all_occurrences_enabled" qualifiers="const"> + <return type="bool"> + </return> + <description> + Returns true if highlight all occurrences is enabled. + </description> + </method> <method name="set_syntax_coloring"> <argument index="0" name="enable" type="bool"> </argument> @@ -39473,6 +39517,8 @@ </theme_item> <theme_item name="completion_existing_color" type="Color"> </theme_item> + <theme_item name="completion_font_color" type="Color"> + </theme_item> <theme_item name="completion_lines" type="int"> </theme_item> <theme_item name="completion_max_width" type="int"> @@ -39493,18 +39539,28 @@ </theme_item> <theme_item name="font_color_selected" type="Color"> </theme_item> + <theme_item name="function_color" type="Color"> + </theme_item> + <theme_item name="line_number_color" type="Color"> + </theme_item> <theme_item name="line_spacing" type="int"> </theme_item> <theme_item name="mark_color" type="Color"> </theme_item> + <theme_item name="member_variable_color" type="Color"> + </theme_item> <theme_item name="normal" type="StyleBox"> </theme_item> + <theme_item name="number_color" type="Color"> + </theme_item> <theme_item name="selection_color" type="Color"> </theme_item> <theme_item name="symbol_color" type="Color"> </theme_item> <theme_item name="tab" type="Texture"> </theme_item> + <theme_item name="word_highlighted_color" type="Color"> + </theme_item> </theme_items> </class> <class name="Texture" inherits="Resource" category="Core"> diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index bc5bff3b8e..eb4f457975 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -948,6 +948,15 @@ Ref<CanvasItemMaterial> CanvasItem::get_material() const{ return material; } +Vector2 CanvasItem::make_canvas_pos_local(const Vector2& screen_point) const { + + ERR_FAIL_COND_V(!is_inside_tree(),screen_point); + + Matrix32 local_matrix = (get_canvas_transform() * + get_global_transform()).affine_inverse(); + + return local_matrix.xform(screen_point); +} InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const { @@ -1052,6 +1061,8 @@ void CanvasItem::_bind_methods() { ObjectTypeDB::bind_method(_MD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material); ObjectTypeDB::bind_method(_MD("get_use_parent_material"),&CanvasItem::get_use_parent_material); + ObjectTypeDB::bind_method(_MD("make_canvas_pos_local","screen_point"), + &CanvasItem::make_canvas_pos_local); ObjectTypeDB::bind_method(_MD("make_input_local","event"),&CanvasItem::make_input_local); BIND_VMETHOD(MethodInfo("_draw")); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 8a61b449fd..b894310ce2 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -263,6 +263,7 @@ public: bool get_use_parent_material() const; InputEvent make_input_local(const InputEvent& pevent) const; + Vector2 make_canvas_pos_local(const Vector2& screen_point) const; Vector2 get_global_mouse_pos() const; Vector2 get_local_mouse_pos() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 1315b67ea1..a680d5d873 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1111,7 +1111,7 @@ void TextEdit::_notification(int p_what) { int l = line_from + i; ERR_CONTINUE( l < 0 || l>= completion_options.size()); - Color text_color = cache.font_color; + Color text_color = cache.completion_font_color; for(int j=0;j<color_regions.size();j++) { if (completion_options[l].begins_with(color_regions[j].begin_key)) { text_color=color_regions[j].color; @@ -3312,6 +3312,7 @@ void TextEdit::_update_caches() { cache.completion_background_color=get_color("completion_background_color"); cache.completion_selected_color=get_color("completion_selected_color"); cache.completion_existing_color=get_color("completion_existing_color"); + cache.completion_font_color=get_color("completion_font_color"); cache.font=get_font("font"); cache.caret_color=get_color("caret_color"); cache.line_number_color=get_color("line_number_color"); @@ -3609,6 +3610,10 @@ void TextEdit::set_highlight_all_occurrences(const bool p_enabled) { update(); } +bool TextEdit::is_highlight_all_occurrences_enabled() const { + return highlight_all_occurrences; +} + int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column) { int col = -1; @@ -4318,6 +4323,10 @@ void TextEdit::set_show_line_numbers(bool p_show) { update(); } +bool TextEdit::is_show_line_numbers_enabled() const { + return line_numbers; +} + void TextEdit::set_draw_breakpoint_gutter(bool p_draw) { draw_breakpoint_gutter = p_draw; update(); @@ -4432,6 +4441,12 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("redo"),&TextEdit::redo); ObjectTypeDB::bind_method(_MD("clear_undo_history"),&TextEdit::clear_undo_history); + ObjectTypeDB::bind_method(_MD("set_show_line_numbers", "enable"), &TextEdit::set_show_line_numbers); + ObjectTypeDB::bind_method(_MD("is_show_line_numbers_enabled"), &TextEdit::is_show_line_numbers_enabled); + + ObjectTypeDB::bind_method(_MD("set_highlight_all_occurrences", "enable"), &TextEdit::set_highlight_all_occurrences); + ObjectTypeDB::bind_method(_MD("is_highlight_all_occurrences_enabled"), &TextEdit::is_highlight_all_occurrences_enabled); + ObjectTypeDB::bind_method(_MD("set_syntax_coloring","enable"),&TextEdit::set_syntax_coloring); ObjectTypeDB::bind_method(_MD("is_syntax_coloring_enabled"),&TextEdit::is_syntax_coloring_enabled); @@ -4444,7 +4459,10 @@ void TextEdit::_bind_methods() { ObjectTypeDB::bind_method(_MD("menu_option"),&TextEdit::menu_option); ObjectTypeDB::bind_method(_MD("get_menu:PopupMenu"),&TextEdit::get_menu); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret/caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled"));; + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_line_numbers"), _SCS("set_show_line_numbers"), _SCS("is_show_line_numbers_enabled")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "highlight_all_occurrences"), _SCS("set_highlight_all_occurrences"), _SCS("is_highlight_all_occurrences_enabled")); + + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret/caret_blink"), _SCS("cursor_set_blink_enabled"), _SCS("cursor_get_blink_enabled")); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "caret/caret_blink_speed",PROPERTY_HINT_RANGE,"0.1,10,0.1"), _SCS("cursor_set_blink_speed"),_SCS("cursor_get_blink_speed") ); ADD_SIGNAL(MethodInfo("cursor_changed")); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index acac687b59..270a1723b1 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -77,6 +77,7 @@ class TextEdit : public Control { Color completion_background_color; Color completion_selected_color; Color completion_existing_color; + Color completion_font_color; Color caret_color; Color line_number_color; Color font_color; @@ -427,6 +428,7 @@ public: void set_current_search_result(int line, int col); void set_highlight_all_occurrences(const bool p_enabled); + bool is_highlight_all_occurrences_enabled() const; bool is_selection_active() const; int get_selection_from_line() const; int get_selection_from_column() const; @@ -468,6 +470,7 @@ public: void menu_option(int p_option); void set_show_line_numbers(bool p_show); + bool is_show_line_numbers_enabled() const; void set_draw_breakpoint_gutter(bool p_draw); bool is_drawing_breakpoint_gutter() const; diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index 7ed83f50f8..182bc5dabc 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -473,6 +473,7 @@ void fill_default_theme(Ref<Theme>& t,const Ref<Font> & default_font,const Ref<F t->set_color("completion_selected_color", "TextEdit",Color::html("434244")); t->set_color("completion_existing_color", "TextEdit",Color::html("21dfdfdf")); t->set_color("completion_scroll_color","TextEdit", control_font_color_pressed ); + t->set_color("completion_font_color","TextEdit", Color::html("aaaaaa")); t->set_color("font_color","TextEdit", control_font_color ); t->set_color("font_color_selected","TextEdit", Color(0,0,0) ); t->set_color("selection_color","TextEdit", font_color_selection ); @@ -482,6 +483,11 @@ void fill_default_theme(Ref<Theme>& t,const Ref<Font> & default_font,const Ref<F t->set_color("caret_color","TextEdit", control_font_color ); t->set_color("symbol_color","TextEdit", control_font_color_hover ); t->set_color("brace_mismatch_color","TextEdit", Color(1,0.2,0.2) ); + t->set_color("line_number_color","TextEdit",Color::html("66aaaaaa")); + t->set_color("function_color","TextEdit",Color::html("66a2ce")); + t->set_color("member_variable_color","TextEdit",Color::html("e64e59")); + t->set_color("number_color","TextEdit",Color::html("EB9532")); + t->set_color("word_highlighted_color","TextEdit",Color(0.8,0.9,0.9,0.15)); t->set_constant("completion_lines","TextEdit", 7 ); t->set_constant("completion_max_width","TextEdit", 50 ); diff --git a/tools/editor/asset_library_editor_plugin.cpp b/tools/editor/asset_library_editor_plugin.cpp index f132e94690..4f685badfb 100644 --- a/tools/editor/asset_library_editor_plugin.cpp +++ b/tools/editor/asset_library_editor_plugin.cpp @@ -444,6 +444,13 @@ void EditorAssetLibraryItemDownload::_close() { void EditorAssetLibraryItemDownload::_install() { String file = download->get_download_file(); + + if (external_install) { + emit_signal("install_asset",file,title->get_text()); + return; + } + + asset_installer->open(file,1); } @@ -465,6 +472,8 @@ void EditorAssetLibraryItemDownload::_bind_methods() { ObjectTypeDB::bind_method("_close",&EditorAssetLibraryItemDownload::_close); ObjectTypeDB::bind_method("_make_request",&EditorAssetLibraryItemDownload::_make_request); + ADD_SIGNAL(MethodInfo("install_asset",PropertyInfo(Variant::STRING,"zip_path"),PropertyInfo(Variant::STRING,"name"))); + } EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { @@ -530,6 +539,8 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { prev_status=-1; + external_install=false; + } @@ -611,6 +622,11 @@ void EditorAssetLibrary::_install_asset() { downloads_hb->add_child(download); download->configure(description->get_title(),description->get_asset_id(),description->get_preview_icon(),description->get_download_url(),description->get_sha256()); + if (templates_only) { + download->set_external_install(true); + download->connect("install_asset",this,"_install_external_asset"); + } + } const char* EditorAssetLibrary::sort_key[SORT_MAX]={ @@ -1259,6 +1275,11 @@ void EditorAssetLibrary::_manage_plugins() { +void EditorAssetLibrary::_install_external_asset(String p_zip_path,String p_title) { + + emit_signal("install_asset",p_zip_path,p_title); +} + void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_http_request_completed",&EditorAssetLibrary::_http_request_completed); @@ -1274,6 +1295,11 @@ void EditorAssetLibrary::_bind_methods() { ObjectTypeDB::bind_method("_repository_changed",&EditorAssetLibrary::_repository_changed); ObjectTypeDB::bind_method("_support_toggled",&EditorAssetLibrary::_support_toggled); ObjectTypeDB::bind_method("_rerun_search",&EditorAssetLibrary::_rerun_search); + ObjectTypeDB::bind_method("_install_external_asset",&EditorAssetLibrary::_install_external_asset); + + + + ADD_SIGNAL(MethodInfo("install_asset",PropertyInfo(Variant::STRING,"zip_path"),PropertyInfo(Variant::STRING,"name"))); } diff --git a/tools/editor/asset_library_editor_plugin.h b/tools/editor/asset_library_editor_plugin.h index 89663aa00b..fe40255af9 100644 --- a/tools/editor/asset_library_editor_plugin.h +++ b/tools/editor/asset_library_editor_plugin.h @@ -155,6 +155,8 @@ class EditorAssetLibraryItemDownload : public PanelContainer { int asset_id; + bool external_install; + EditorAssetInstaller *asset_installer; void _close(); @@ -168,6 +170,7 @@ protected: static void _bind_methods(); public: + void set_external_install(bool p_enable) { external_install=p_enable; } 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, const String& p_sha256_hash); EditorAssetLibraryItemDownload(); @@ -301,6 +304,8 @@ class EditorAssetLibrary : public PanelContainer { void _repository_changed(int p_repository_id); void _support_toggled(int p_support); + void _install_external_asset(String p_zip_path,String p_title); + friend class EditorAssetLibraryItemDescription; friend class EditorAssetLibraryItem; protected: diff --git a/tools/editor/editor_node.cpp b/tools/editor/editor_node.cpp index 80fadd18bd..81f9927b92 100644 --- a/tools/editor/editor_node.cpp +++ b/tools/editor/editor_node.cpp @@ -5856,7 +5856,8 @@ EditorNode::EditorNode() { play_custom_scene_button->set_focus_mode(Control::FOCUS_NONE); play_custom_scene_button->set_icon(gui_base->get_icon("PlayCustom","EditorIcons")); play_custom_scene_button->connect("pressed", this,"_menu_option",make_binds(RUN_PLAY_CUSTOM_SCENE)); - play_custom_scene_button->set_tooltip(TTR("Play custom scene")+" ("+keycode_get_string(KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F5)+")."); + play_custom_scene_button->set_tooltip(TTR("Play custom scene")); + play_custom_scene_button->set_shortcut(ED_SHORTCUT("editor/play_custom_scene",TTR("Play Custom Scene"),KEY_MASK_CMD|KEY_MASK_SHIFT|KEY_F5)); debug_button = memnew( MenuButton ); debug_button->set_flat(true); diff --git a/tools/editor/editor_settings.cpp b/tools/editor/editor_settings.cpp index 2ce9502293..97bba92e00 100644 --- a/tools/editor/editor_settings.cpp +++ b/tools/editor/editor_settings.cpp @@ -683,6 +683,8 @@ void EditorSettings::_load_default_text_editor_theme() { set("text_editor/completion_background_color", Color::html("2C2A32")); set("text_editor/completion_selected_color", Color::html("434244")); set("text_editor/completion_existing_color", Color::html("21dfdfdf")); + set("text_editor/completion_scroll_color", Color::html("ffffff")); + set("text_editor/completion_font_color", Color::html("aaaaaa")); set("text_editor/caret_color",Color::html("aaaaaa")); set("text_editor/line_number_color",Color::html("66aaaaaa")); set("text_editor/text_color",Color::html("aaaaaa")); @@ -918,6 +920,8 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { cf->set_value(theme_section, "completion_background_color", ((Color)get("text_editor/completion_background_color")).to_html()); cf->set_value(theme_section, "completion_selected_color", ((Color)get("text_editor/completion_selected_color")).to_html()); cf->set_value(theme_section, "completion_existing_color", ((Color)get("text_editor/completion_existing_color")).to_html()); + cf->set_value(theme_section, "completion_scroll_color", ((Color)get("text_editor/completion_scroll_color")).to_html()); + cf->set_value(theme_section, "completion_font_color", ((Color)get("text_editor/completion_font_color")).to_html()); cf->set_value(theme_section, "caret_color", ((Color)get("text_editor/caret_color")).to_html()); cf->set_value(theme_section, "line_number_color", ((Color)get("text_editor/line_number_color")).to_html()); cf->set_value(theme_section, "text_color", ((Color)get("text_editor/text_color")).to_html()); diff --git a/tools/editor/plugins/script_editor_plugin.cpp b/tools/editor/plugins/script_editor_plugin.cpp index 3b095d15f9..fc5f552723 100644 --- a/tools/editor/plugins/script_editor_plugin.cpp +++ b/tools/editor/plugins/script_editor_plugin.cpp @@ -312,6 +312,8 @@ void ScriptTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/completion_background_color", Color(0,0,0,0))); get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/completion_selected_color", Color::html("434244"))); get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/completion_existing_color", Color::html("21dfdfdf"))); + get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/completion_scroll_color", Color::html("ffffff"))); + get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/completion_font_color", Color::html("aaaaaa"))); get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0))); get_text_edit()->add_color_override("line_number_color",EDITOR_DEF("text_editor/line_number_color",Color(0,0,0))); get_text_edit()->add_color_override("caret_color",EDITOR_DEF("text_editor/caret_color",Color(0,0,0))); diff --git a/tools/editor/plugins/shader_editor_plugin.cpp b/tools/editor/plugins/shader_editor_plugin.cpp index 864df42b6e..9ef84af260 100644 --- a/tools/editor/plugins/shader_editor_plugin.cpp +++ b/tools/editor/plugins/shader_editor_plugin.cpp @@ -81,6 +81,8 @@ void ShaderTextEditor::_load_theme_settings() { get_text_edit()->add_color_override("completion_background_color", EDITOR_DEF("text_editor/completion_background_color", Color(0,0,0,0))); get_text_edit()->add_color_override("completion_selected_color", EDITOR_DEF("text_editor/completion_selected_color", Color::html("434244"))); get_text_edit()->add_color_override("completion_existing_color", EDITOR_DEF("text_editor/completion_existing_color", Color::html("21dfdfdf"))); + get_text_edit()->add_color_override("completion_scroll_color", EDITOR_DEF("text_editor/completion_scroll_color", Color::html("ffffff"))); + get_text_edit()->add_color_override("completion_font_color", EDITOR_DEF("text_editor/completion_font_color", Color::html("aaaaaa"))); get_text_edit()->add_color_override("font_color",EDITOR_DEF("text_editor/text_color",Color(0,0,0))); get_text_edit()->add_color_override("line_number_color",EDITOR_DEF("text_editor/line_number_color",Color(0,0,0))); get_text_edit()->add_color_override("caret_color",EDITOR_DEF("text_editor/caret_color",Color(0,0,0))); diff --git a/tools/editor/project_manager.cpp b/tools/editor/project_manager.cpp index 52f6d1dd9c..25d42eb601 100644 --- a/tools/editor/project_manager.cpp +++ b/tools/editor/project_manager.cpp @@ -49,17 +49,30 @@ #include "editor_initialize_ssl.h" #include "editor_scale.h" +#include "io/zip_io.h" + class NewProjectDialog : public ConfirmationDialog { OBJ_TYPE(NewProjectDialog,ConfirmationDialog); +public: + + enum Mode { + MODE_NEW, + MODE_IMPORT, + MODE_INSTALL + }; +private: - bool import_mode; + Mode mode; Label *pp,*pn; Label *error; LineEdit *project_path; LineEdit *project_name; FileDialog *fdialog; + String zip_path; + String zip_title; + AcceptDialog *dialog_error; bool _test_path() { @@ -72,7 +85,7 @@ class NewProjectDialog : public ConfirmationDialog { return false; } - if (!import_mode) { + if (mode!=MODE_IMPORT) { if (d->file_exists("engine.cfg")) { @@ -109,7 +122,7 @@ class NewProjectDialog : public ConfirmationDialog { if (lidx!=-1) { sp=sp.substr(lidx+1,sp.length()); } - if (sp=="" && import_mode ) + if (sp=="" && mode==MODE_IMPORT ) sp=TTR("Imported Project"); project_name->set_text(sp); @@ -119,7 +132,7 @@ class NewProjectDialog : public ConfirmationDialog { void _file_selected(const String& p_path) { String p = p_path; - if (import_mode) { + if (mode==MODE_IMPORT) { if (p.ends_with("engine.cfg")) { p=p.get_base_dir(); @@ -141,7 +154,7 @@ class NewProjectDialog : public ConfirmationDialog { void _browse_path() { - if (import_mode) { + if (mode==MODE_IMPORT) { fdialog->set_mode(FileDialog::MODE_OPEN_FILE); fdialog->clear_filters(); @@ -163,7 +176,7 @@ class NewProjectDialog : public ConfirmationDialog { String dir; - if (import_mode) { + if (mode==MODE_IMPORT) { dir=project_path->get_text(); @@ -179,26 +192,130 @@ class NewProjectDialog : public ConfirmationDialog { dir=d->get_current_dir(); memdelete(d); - FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); - if (!f) { - error->set_text(TTR("Couldn't create engine.cfg in project path.")); - } else { + if (mode==MODE_NEW) { + + + + + FileAccess *f = FileAccess::open(dir.plus_file("/engine.cfg"),FileAccess::WRITE); + if (!f) { + error->set_text(TTR("Couldn't create engine.cfg in project path.")); + } else { + + f->store_line("; Engine configuration file."); + f->store_line("; It's best to edit using the editor UI, not directly,"); + f->store_line("; becausethe parameters that go here are not obvious."); + f->store_line("; "); + f->store_line("; Format: "); + f->store_line("; [section] ; section goes between []"); + f->store_line("; param=value ; assign values to parameters"); + f->store_line("\n"); + f->store_line("[application]"); + f->store_line("name=\""+project_name->get_text()+"\""); + f->store_line("icon=\"res://icon.png\""); + + memdelete(f); + + ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); + } + + } else if (mode==MODE_INSTALL) { + + + FileAccess *src_f=NULL; + zlib_filefunc_def io = zipio_create_io_from_file(&src_f); + + unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io); + if (!pkg) { + + dialog_error->set_text("Error opening package file, not in zip format."); + return; + } + + int ret = unzGoToFirstFile(pkg); + + Vector<String> failed_files; + + int idx=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 path=fname; + + int depth=1; //stuff from github comes with tag + bool skip=false; + while(depth>0) { + int pp = path.find("/"); + if (pp==-1) { + skip=true; + break; + } + path=path.substr(pp+1,path.length()); + depth--; + } + + + if (skip || path==String()) { + // + } else if (path.ends_with("/")) { // a dir + + path=path.substr(0,path.length()-1); + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + da->make_dir(dir.plus_file(path)); + memdelete(da); + + } else { + + Vector<uint8_t> data; + data.resize(info.uncompressed_size); + + //read + unzOpenCurrentFile(pkg); + unzReadCurrentFile(pkg,data.ptr(),data.size()); + unzCloseCurrentFile(pkg); + + FileAccess *f=FileAccess::open(dir.plus_file(path),FileAccess::WRITE); + + if (f) { + f->store_buffer(data.ptr(),data.size()); + memdelete(f); + } else { + failed_files.push_back(path); + } + + + } + + idx++; + ret = unzGoToNextFile(pkg); + } + + unzClose(pkg); + + if (failed_files.size()) { + String msg=TTR("The following files failed extraction from package:")+"\n\n"; + for(int i=0;i<failed_files.size();i++) { + + if (i>15) { + msg+="\nAnd "+itos(failed_files.size()-i)+" more files."; + break; + } + msg+=failed_files[i]+"\n"; + } + + dialog_error->set_text(msg); + dialog_error->popup_centered_minsize(); + + } else { + dialog_error->set_text(TTR("Package Installed Successfully!")); + dialog_error->popup_centered_minsize(); + } - f->store_line("; Engine configuration file."); - f->store_line("; It's best to edit using the editor UI, not directly,"); - f->store_line("; becausethe parameters that go here are not obvious."); - f->store_line("; "); - f->store_line("; Format: "); - f->store_line("; [section] ; section goes between []"); - f->store_line("; param=value ; assign values to parameters"); - f->store_line("\n"); - f->store_line("[application]"); - f->store_line("name=\""+project_name->get_text()+"\""); - f->store_line("icon=\"res://icon.png\""); - - memdelete(f); - - ResourceSaver::save(dir.plus_file("/icon.png"),get_icon("DefaultProjectIcon","EditorIcons")); } @@ -233,10 +350,16 @@ protected: public: + void set_zip_path(const String& p_path) { + zip_path=p_path; + } + void set_zip_title(const String& p_title) { + zip_title=p_title; + } - void set_import_mode(bool p_import ) { + void set_mode(Mode p_mode) { - import_mode=p_import; + mode=p_mode; } void show_dialog() { @@ -245,7 +368,7 @@ public: project_path->clear(); project_name->clear(); - if (import_mode) { + if (mode==MODE_IMPORT) { set_title(TTR("Import Existing Project")); get_ok()->set_text(TTR("Import")); pp->set_text(TTR("Project Path (Must Exist):")); @@ -253,9 +376,10 @@ public: pn->hide(); project_name->hide(); - popup_centered(Size2(500,125)); + popup_centered(Size2(500,125)*EDSCALE); + + } else if (mode==MODE_NEW){ - } else { set_title(TTR("Create New Project")); get_ok()->set_text(TTR("Create")); pp->set_text(TTR("Project Path:")); @@ -263,7 +387,16 @@ public: pn->show(); project_name->show(); - popup_centered(Size2(500,145)); + popup_centered(Size2(500,145)*EDSCALE); + } else if (mode==MODE_INSTALL){ + + set_title(TTR("Install Project: ")+zip_title); + get_ok()->set_text(TTR("Install")); + pp->set_text(TTR("Project Path:")); + pn->hide(); + project_name->hide(); + + popup_centered(Size2(500,125)*EDSCALE); } @@ -329,7 +462,10 @@ public: fdialog->connect("dir_selected", this,"_path_selected"); fdialog->connect("file_selected", this,"_file_selected"); set_hide_on_ok(false); - import_mode=false; + mode=MODE_NEW; + + dialog_error = memnew( AcceptDialog ); + add_child(dialog_error); } @@ -616,6 +752,8 @@ void ProjectManager::_load_recent_projects() { run_btn->set_disabled(selected_list.size()<1 || (selected_list.size()==1 && single_selected_main=="")); EditorSettings::get_singleton()->save(); + + tabs->set_current_tab(0); } void ProjectManager::_open_project_confirm() { @@ -755,14 +893,14 @@ void ProjectManager::_scan_projects() { void ProjectManager::_new_project() { - npdialog->set_import_mode(false); + npdialog->set_mode(NewProjectDialog::MODE_NEW); npdialog->show_dialog(); } void ProjectManager::_import_project() { - npdialog->set_import_mode(true); + npdialog->set_mode(NewProjectDialog::MODE_IMPORT); npdialog->show_dialog(); } @@ -800,6 +938,15 @@ void ProjectManager::_exit_dialog() { get_tree()->quit(); } + +void ProjectManager::_install_project(const String& p_zip_path,const String& p_title) { + + npdialog->set_mode(NewProjectDialog::MODE_INSTALL); + npdialog->set_zip_path(p_zip_path); + npdialog->set_zip_title(p_title); + npdialog->show_dialog(); +} + void ProjectManager::_bind_methods() { ObjectTypeDB::bind_method("_open_project",&ProjectManager::_open_project); @@ -817,6 +964,7 @@ void ProjectManager::_bind_methods() { ObjectTypeDB::bind_method("_panel_draw",&ProjectManager::_panel_draw); ObjectTypeDB::bind_method("_panel_input",&ProjectManager::_panel_input); ObjectTypeDB::bind_method("_favorite_pressed",&ProjectManager::_favorite_pressed); + ObjectTypeDB::bind_method("_install_project",&ProjectManager::_install_project); } @@ -1016,6 +1164,7 @@ ProjectManager::ProjectManager() { gui_base->add_child(multi_run_ask); + asset_library->connect("install_asset",this,"_install_project"); OS::get_singleton()->set_low_processor_usage_mode(true); diff --git a/tools/editor/project_manager.h b/tools/editor/project_manager.h index 2db1bb839e..69467f50e7 100644 --- a/tools/editor/project_manager.h +++ b/tools/editor/project_manager.h @@ -88,6 +88,8 @@ class ProjectManager : public Control { void _load_recent_projects(); void _scan_dir(DirAccess *da,float pos, float total,List<String> *r_projects); + void _install_project(const String& p_zip_path,const String& p_title); + void _panel_draw(Node *p_hb); void _panel_input(const InputEvent& p_ev,Node *p_hb); void _favorite_pressed(Node *p_hb); |