diff options
Diffstat (limited to 'editor')
66 files changed, 2126 insertions, 1008 deletions
diff --git a/editor/SCsub b/editor/SCsub index 2b6494608b..75ec422bd5 100644 --- a/editor/SCsub +++ b/editor/SCsub @@ -21,11 +21,11 @@ def make_certs_header(target, source, env): g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") g.write("#ifndef _CERTS_RAW_H\n") g.write("#define _CERTS_RAW_H\n") - g.write("static const int _certs_compressed_size=" + str(len(buf)) + ";\n") - g.write("static const int _certs_uncompressed_size=" + str(decomp_size) + ";\n") - g.write("static const unsigned char _certs_compressed[]={\n") + g.write("static const int _certs_compressed_size = " + str(len(buf)) + ";\n") + g.write("static const int _certs_uncompressed_size = " + str(decomp_size) + ";\n") + g.write("static const unsigned char _certs_compressed[] = {\n") for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") + g.write("\t" + byte_to_str(buf[i]) + ",\n") g.write("};\n") g.write("#endif") @@ -39,9 +39,11 @@ def make_doc_header(target, source, env): docend = "" for s in source: src = s.srcnode().abspath + if not src.endswith(".xml"): + continue f = open_utf8(src, "r") content = f.read() - buf+=content + buf += content buf = encode_utf8(docbegin + buf + docend) decomp_size = len(buf) @@ -51,11 +53,11 @@ def make_doc_header(target, source, env): g.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n") g.write("#ifndef _DOC_DATA_RAW_H\n") g.write("#define _DOC_DATA_RAW_H\n") - g.write("static const int _doc_data_compressed_size=" + str(len(buf)) + ";\n") - g.write("static const int _doc_data_uncompressed_size=" + str(decomp_size) + ";\n") - g.write("static const unsigned char _doc_data_compressed[]={\n") + g.write("static const int _doc_data_compressed_size = " + str(len(buf)) + ";\n") + g.write("static const int _doc_data_uncompressed_size = " + str(decomp_size) + ";\n") + g.write("static const unsigned char _doc_data_compressed[] = {\n") for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") + g.write("\t" + byte_to_str(buf[i]) + ",\n") g.write("};\n") g.write("#endif") @@ -80,10 +82,10 @@ def make_fonts_header(target, source, env): name = os.path.splitext(os.path.basename(source[i].srcnode().abspath))[0] - g.write("static const int _font_" + name + "_size=" + str(len(buf)) + ";\n") - g.write("static const unsigned char _font_" + name + "[]={\n") + g.write("static const int _font_" + name + "_size = " + str(len(buf)) + ";\n") + g.write("static const unsigned char _font_" + name + "[] = {\n") for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") + g.write("\t" + byte_to_str(buf[i]) + ",\n") g.write("};\n") @@ -114,11 +116,9 @@ def make_translations_header(target, source, env): buf = zlib.compress(buf) name = os.path.splitext(os.path.basename(sorted_paths[i]))[0] - #g.write("static const int _translation_"+name+"_compressed_size="+str(len(buf))+";\n") - #g.write("static const int _translation_"+name+"_uncompressed_size="+str(decomp_size)+";\n") - g.write("static const unsigned char _translation_" + name + "_compressed[]={\n") + g.write("static const unsigned char _translation_" + name + "_compressed[] = {\n") for i in range(len(buf)): - g.write(byte_to_str(buf[i]) + ",\n") + g.write("\t" + byte_to_str(buf[i]) + ",\n") g.write("};\n") @@ -130,10 +130,10 @@ def make_translations_header(target, source, env): g.write("\tint uncomp_size;\n") g.write("\tconst unsigned char* data;\n") g.write("};\n\n") - g.write("static EditorTranslationList _editor_translations[]={\n") + g.write("static EditorTranslationList _editor_translations[] = {\n") for x in xl_names: - g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ",_translation_" + x[0] + "_compressed},\n") - g.write("\t{NULL,0,0,NULL}\n") + g.write("\t{ \"" + x[0] + "\", " + str(x[1]) + ", " + str(x[2]) + ", _translation_" + x[0] + "_compressed},\n") + g.write("\t{NULL, 0, 0, NULL}\n") g.write("};\n") g.write("#endif") @@ -390,13 +390,13 @@ def make_license_header(target, source, env): def _make_doc_data_class_path(to_path): g = open_utf8(os.path.join(to_path,"doc_data_class_path.gen.h"), "w") - g.write("static const int _doc_data_class_path_count="+str(len(env.doc_class_path))+";\n") + g.write("static const int _doc_data_class_path_count = " + str(len(env.doc_class_path)) + ";\n") g.write("struct _DocDataClassPath { const char* name; const char* path; };\n") - g.write("static const _DocDataClassPath _doc_data_class_paths["+str(len(env.doc_class_path)+1)+"]={\n"); - for c in env.doc_class_path: - g.write("{\""+c+"\",\""+env.doc_class_path[c]+"\"},\n") - g.write("{NULL,NULL}\n") + g.write("static const _DocDataClassPath _doc_data_class_paths[" + str(len(env.doc_class_path) + 1) + "] = {\n"); + for c in sorted(env.doc_class_path): + g.write("\t{\"" + c + "\", \"" + env.doc_class_path[c] + "\"},\n") + g.write("\t{NULL, NULL}\n") g.write("};\n") @@ -416,11 +416,22 @@ if env['tools']: # API documentation docs = [] - for f in os.listdir(os.path.join(env.Dir('#').abspath, "doc/classes")): - docs.append("#doc/classes/" + f) + doc_dirs = ["doc/classes"] + + for p in env.doc_class_path.values(): + if p not in doc_dirs: + doc_dirs.append(p) + + for d in doc_dirs: + try: + for f in os.listdir(os.path.join(env.Dir('#').abspath, d)): + docs.append("#" + os.path.join(d, f)) + except OSError: + pass _make_doc_data_class_path(os.path.join(env.Dir('#').abspath, "editor/doc")) + docs = sorted(docs) env.Depends("#editor/doc_data_compressed.gen.h", docs) env.Command("#editor/doc_data_compressed.gen.h", docs, make_doc_header) # Certificates diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index 54eb695178..7d877bdb8c 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -1368,7 +1368,7 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x-=hsep; */ - track_ofs[0] = size.width - icon_ofs.x; + track_ofs[0] = size.width - icon_ofs.x + ofs.x; icon_ofs.x -= down_icon->get_width(); te->draw_texture(down_icon, icon_ofs - Size2(0, 4 * EDSCALE)); @@ -1380,7 +1380,7 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x -= hsep; te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor); - track_ofs[1] = size.width - icon_ofs.x; + track_ofs[1] = size.width - icon_ofs.x + ofs.x; icon_ofs.x -= down_icon->get_width(); te->draw_texture(down_icon, icon_ofs - Size2(0, 4 * EDSCALE)); @@ -1394,7 +1394,7 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x -= hsep; te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor); - track_ofs[2] = size.width - icon_ofs.x; + track_ofs[2] = size.width - icon_ofs.x + ofs.x; if (animation->track_get_type(idx) == Animation::TYPE_VALUE) { @@ -1415,13 +1415,12 @@ void AnimationKeyEditor::_track_editor_draw() { icon_ofs.x -= hsep; te->draw_line(Point2(icon_ofs.x, ofs.y + y), Point2(icon_ofs.x, ofs.y + y + h), sepcolor); - track_ofs[3] = size.width - icon_ofs.x; + track_ofs[3] = size.width - icon_ofs.x + ofs.x; icon_ofs.x -= hsep; icon_ofs.x -= add_key_icon->get_width(); te->draw_texture((mouse_over.over == MouseOver::OVER_ADD_KEY && mouse_over.track == idx) ? add_key_icon_hl : add_key_icon, icon_ofs); - - track_ofs[4] = size.width - icon_ofs.x; + track_ofs[4] = size.width - icon_ofs.x + ofs.x; //draw the keys; int tt = animation->track_get_type(idx); @@ -2080,7 +2079,7 @@ void AnimationKeyEditor::_track_editor_gui_input(const Ref<InputEvent> &p_input) return; } - if (mpos.x < name_limit) { + if (mpos.x < name_limit - (type_icon[0]->get_width() / 2.0)) { //name column // area @@ -3330,7 +3329,7 @@ int AnimationKeyEditor::_confirm_insert(InsertData p_id, int p_last_track) { h.type == Variant::VECTOR2 || h.type == Variant::RECT2 || h.type == Variant::VECTOR3 || - h.type == Variant::RECT3 || + h.type == Variant::AABB || h.type == Variant::QUAT || h.type == Variant::COLOR || h.type == Variant::TRANSFORM) { diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 0100c221c4..c7012a0c14 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -56,6 +56,7 @@ void GotoLineDialog::ok_pressed() { if (get_line() < 1 || get_line() > text_editor->get_line_count()) return; + text_editor->unfold_line(get_line() - 1); text_editor->cursor_set_line(get_line() - 1); hide(); } @@ -139,6 +140,7 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) if (found) { if (!preserve_cursor) { + text_edit->unfold_line(line); text_edit->cursor_set_line(line, false); text_edit->cursor_set_column(col + text.length(), false); text_edit->center_viewport_to_cursor(); @@ -167,6 +169,7 @@ void FindReplaceBar::_replace() { if (result_line != -1 && result_col != -1) { text_edit->begin_complex_operation(); + text_edit->unfold_line(result_line); text_edit->select(result_line, result_col, result_line, result_col + get_search_text().length()); text_edit->insert_text_at_cursor(get_replace_text()); @@ -214,6 +217,7 @@ void FindReplaceBar::_replace_all() { prev_match = Point2i(result_line, result_col + replace_text.length()); + text_edit->unfold_line(result_line); text_edit->select(result_line, result_col, result_line, match_to.y); if (selection_enabled && is_selection_only()) { @@ -751,6 +755,7 @@ bool FindReplaceDialog::_search() { if (found) { // print_line("found"); + text_edit->unfold_line(line); text_edit->cursor_set_line(line); if (is_backwards()) text_edit->cursor_set_column(col); @@ -1093,6 +1098,8 @@ void CodeTextEditor::update_editor_settings() { text_editor->cursor_set_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); text_editor->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); text_editor->set_draw_breakpoint_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_breakpoint_gutter")); + text_editor->set_hiding_enabled(EditorSettings::get_singleton()->get("text_editor/line_numbers/code_folding")); + text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/code_folding")); text_editor->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/open_scripts/smooth_scrolling")); text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/open_scripts/v_scroll_speed")); diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index b4c2ac95cc..cd60455f4f 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -209,7 +209,7 @@ void ConnectDialog::_add_bind() { case Variant::VECTOR3: value = Vector3(); break; case Variant::PLANE: value = Plane(); break; case Variant::QUAT: value = Quat(); break; - case Variant::RECT3: value = Rect3(); break; + case Variant::AABB: value = AABB(); break; case Variant::BASIS: value = Basis(); break; case Variant::TRANSFORM: value = Transform(); break; case Variant::COLOR: value = Color(); break; @@ -295,7 +295,7 @@ ConnectDialog::ConnectDialog() { type_list->add_item("Vector3", Variant::VECTOR3); type_list->add_item("Plane", Variant::PLANE); type_list->add_item("Quat", Variant::QUAT); - type_list->add_item("Rect3", Variant::RECT3); + type_list->add_item("AABB", Variant::AABB); type_list->add_item("Basis", Variant::BASIS); type_list->add_item("Transform", Variant::TRANSFORM); //type_list->add_separator(); diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index 95b4f7e982..c058d290bf 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -41,7 +41,7 @@ void CreateDialog::popup_create(bool p_dontclear) { recent->clear(); - FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::READ); + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::READ); if (f) { @@ -63,7 +63,7 @@ void CreateDialog::popup_create(bool p_dontclear) { favorites->clear(); - f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites." + base_type), FileAccess::READ); + f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::READ); favorite_list.clear(); @@ -97,6 +97,15 @@ void CreateDialog::popup_create(bool p_dontclear) { search_box->grab_focus(); _update_search(); + + bool enable_rl = EditorSettings::get_singleton()->get("docks/scene_tree/draw_relationship_lines"); + Color rl_color = EditorSettings::get_singleton()->get("docks/scene_tree/relationship_line_color"); + + if (enable_rl) { + search_options->add_constant_override("draw_relationship_lines", 1); + search_options->add_color_override("relationship_line_color", rl_color); + } else + search_options->add_constant_override("draw_relationship_lines", 0); } void CreateDialog::_text_changed(const String &p_newtext) { @@ -307,7 +316,7 @@ void CreateDialog::_confirmed() { if (!ti) return; - FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("create_recent." + base_type), FileAccess::WRITE); + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("create_recent." + base_type), FileAccess::WRITE); if (f) { f->store_line(get_selected_type()); @@ -467,7 +476,7 @@ void CreateDialog::_favorite_toggled() { void CreateDialog::_save_favorite_list() { - FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_path().plus_file("favorites." + base_type), FileAccess::WRITE); + FileAccess *f = FileAccess::open(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("favorites." + base_type), FileAccess::WRITE); if (f) { diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 057b2d827d..1f9884aa70 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "doc_data.h" +#include "engine.h" #include "global_constants.h" #include "io/compression.h" #include "io/marshalls.h" @@ -529,7 +530,7 @@ void DocData::generate(bool p_basic_types) { { - String cname = "@Global Scope"; + String cname = "@GlobalScope"; class_list[cname] = ClassDoc(); ClassDoc &c = class_list[cname]; c.name = cname; @@ -543,14 +544,14 @@ void DocData::generate(bool p_basic_types) { c.constants.push_back(cd); } - List<ProjectSettings::Singleton> singletons; - ProjectSettings::get_singleton()->get_singletons(&singletons); + List<Engine::Singleton> singletons; + Engine::get_singleton()->get_singletons(&singletons); //servers (this is kind of hackish) - for (List<ProjectSettings::Singleton>::Element *E = singletons.front(); E; E = E->next()) { + for (List<Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) { PropertyDoc pd; - ProjectSettings::Singleton &s = E->get(); + Engine::Singleton &s = E->get(); pd.name = s.name; pd.type = s.ptr->get_class(); while (String(ClassDB::get_parent_class(pd.type)) != "Object") @@ -615,11 +616,6 @@ void DocData::generate(bool p_basic_types) { } } -static String _format_description(const String &string) { - - return string.dedent().strip_edges().replace("\n", "\n\n"); -} - static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> &methods) { String section = parser->get_node_name(); @@ -666,7 +662,7 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - method.description = _format_description(parser->get_node_data()); + method.description = parser->get_node_data(); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == element) @@ -781,20 +777,20 @@ Error DocData::_load(Ref<XMLParser> parser) { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.brief_description = _format_description(parser->get_node_data()); + c.brief_description = parser->get_node_data(); } else if (name == "description") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.description = _format_description(parser->get_node_data()); + c.description = parser->get_node_data(); } else if (name == "tutorials") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.tutorials = parser->get_node_data().strip_edges(); + c.tutorials = parser->get_node_data(); } else if (name == "demos") { parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - c.demos = parser->get_node_data().strip_edges(); + c.demos = parser->get_node_data(); } else if (name == "methods") { Error err = _parse_methods(parser, c.methods); @@ -828,7 +824,7 @@ Error DocData::_load(Ref<XMLParser> parser) { prop.enumeration = parser->get_attribute_value("enum"); parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - prop.description = _format_description(parser->get_node_data()); + prop.description = parser->get_node_data(); c.properties.push_back(prop); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -857,7 +853,7 @@ Error DocData::_load(Ref<XMLParser> parser) { prop.type = parser->get_attribute_value("type"); parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - prop.description = parser->get_node_data().strip_edges(); + prop.description = parser->get_node_data(); c.theme_properties.push_back(prop); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -888,7 +884,7 @@ Error DocData::_load(Ref<XMLParser> parser) { } parser->read(); if (parser->get_node_type() == XMLParser::NODE_TEXT) - constant.description = parser->get_node_data().strip_edges(); + constant.description = parser->get_node_data(); c.constants.push_back(constant); } else { ERR_EXPLAIN("Invalid tag in doc file: " + name); @@ -915,6 +911,8 @@ Error DocData::_load(Ref<XMLParser> parser) { static void _write_string(FileAccess *f, int p_tablevel, const String &p_string) { + if (p_string == "") + return; String tab; for (int i = 0; i < p_tablevel; i++) tab += "\t"; @@ -953,24 +951,20 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri if (c.category == "") category = "Core"; header += " category=\"" + category + "\""; - header += " version=\"" + String(VERSION_MKSTRING) + "\""; + header += String(" version=\"") + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + VERSION_STATUS + "\""; header += ">"; _write_string(f, 0, header); _write_string(f, 1, "<brief_description>"); - if (c.brief_description != "") - _write_string(f, 2, c.brief_description.xml_escape()); + _write_string(f, 2, c.brief_description.strip_edges().xml_escape()); _write_string(f, 1, "</brief_description>"); _write_string(f, 1, "<description>"); - if (c.description != "") - _write_string(f, 2, c.description.xml_escape()); + _write_string(f, 2, c.description.strip_edges().xml_escape()); _write_string(f, 1, "</description>"); _write_string(f, 1, "<tutorials>"); - if (c.tutorials != "") - _write_string(f, 2, c.tutorials.xml_escape()); + _write_string(f, 2, c.tutorials.strip_edges().xml_escape()); _write_string(f, 1, "</tutorials>"); _write_string(f, 1, "<demos>"); - if (c.demos != "") - _write_string(f, 2, c.demos.xml_escape()); + _write_string(f, 2, c.demos.strip_edges().xml_escape()); _write_string(f, 1, "</demos>"); _write_string(f, 1, "<methods>"); @@ -1014,8 +1008,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri } _write_string(f, 3, "<description>"); - if (m.description != "") - _write_string(f, 4, m.description.xml_escape()); + _write_string(f, 4, m.description.strip_edges().xml_escape()); _write_string(f, 3, "</description>"); _write_string(f, 2, "</method>"); @@ -1036,8 +1029,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri } PropertyDoc &p = c.properties[i]; _write_string(f, 2, "<member name=\"" + p.name + "\" type=\"" + p.type + "\" setter=\"" + p.setter + "\" getter=\"" + p.getter + "\"" + enum_text + ">"); - if (p.description != "") - _write_string(f, 3, p.description.xml_escape()); + _write_string(f, 3, p.description.strip_edges().xml_escape()); _write_string(f, 2, "</member>"); } _write_string(f, 1, "</members>"); @@ -1060,8 +1052,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri } _write_string(f, 3, "<description>"); - if (m.description != "") - _write_string(f, 4, m.description.xml_escape()); + _write_string(f, 4, m.description.strip_edges().xml_escape()); _write_string(f, 3, "</description>"); _write_string(f, 2, "</signal>"); @@ -1080,8 +1071,7 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri } else { _write_string(f, 2, "<constant name=\"" + k.name + "\" value=\"" + k.value + "\" enum=\"" + k.enumeration + "\">"); } - if (k.description != "") - _write_string(f, 3, k.description.xml_escape()); + _write_string(f, 3, k.description.strip_edges().xml_escape()); _write_string(f, 2, "</constant>"); } diff --git a/editor/doc/doc_dump.cpp b/editor/doc/doc_dump.cpp index 2ba7e3c779..9dd05d9d0f 100644 --- a/editor/doc/doc_dump.cpp +++ b/editor/doc/doc_dump.cpp @@ -82,8 +82,8 @@ void DocDump::dump(const String &p_file) { FileAccess *f = FileAccess::open(p_file, FileAccess::WRITE); _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); + _write_string(f, 0, String("<doc version=\"") + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + VERSION_STATUS + "\" name=\"Engine Types\">"); - _write_string(f, 0, "<doc version=\"" + String(VERSION_MKSTRING) + "\" name=\"Engine Types\">"); while (class_list.size()) { String name = class_list.front()->get(); @@ -182,7 +182,7 @@ void DocDump::dump(const String &p_file) { case Variant::VECTOR3: case Variant::PLANE: case Variant::QUAT: - case Variant::RECT3: + case Variant::AABB: case Variant::BASIS: case Variant::COLOR: case Variant::POOL_BYTE_ARRAY: diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index a48e6c9057..290cb1be42 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -117,7 +117,7 @@ EditorAbout::EditorAbout() { Label *about_text = memnew(Label); about_text->set_v_size_flags(Control::SIZE_SHRINK_CENTER); - about_text->set_text(VERSION_FULL_NAME + hash + String::utf8("\n\u00A9 2007-2017 Juan Linietsky, Ariel Manzur.\n\u00A9 2014-2017 ") + + about_text->set_text(VERSION_FULL_NAME + hash + String::utf8("\n\xc2\xa9 2007-2017 Juan Linietsky, Ariel Manzur.\n\xc2\xa9 2014-2017 ") + TTR("Godot Engine contributors") + "\n"); hbc->add_child(about_text); @@ -201,7 +201,7 @@ EditorAbout::EditorAbout() { for (int j = 0; j < about_tp_copyright_count[i]; j++) { text += "\n Files:\n " + String(about_tp_file[read_idx]).replace("\n", "\n ") + "\n"; - String copyright = String::utf8(" \u00A9 ") + String::utf8(about_tp_copyright[read_idx]).replace("\n", String::utf8("\n \u00A9 ")); + String copyright = String::utf8(" \xc2\xa9 ") + String::utf8(about_tp_copyright[read_idx]).replace("\n", String::utf8("\n \xc2\xa9 ")); text += copyright; long_text += copyright; String license = "\n License: " + String(about_tp_license[read_idx]) + "\n"; diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index efe32b99ab..519bc33d42 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -336,33 +336,18 @@ Error EditorExportPlatform::_save_zip_file(void *p_userdata, const String &p_pat String EditorExportPlatform::find_export_template(String template_file_name, String *err) const { - String base_name = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS) + "/" + template_file_name; - String user_file = EditorSettings::get_singleton()->get_settings_path() + "/templates/" + base_name; - String system_file = OS::get_singleton()->get_installed_templates_path(); - bool has_system_path = (system_file != ""); - system_file = system_file.plus_file(base_name); - - // Prefer user file - if (FileAccess::exists(user_file)) { - return user_file; - } + String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + VERSION_STATUS + VERSION_MODULE_CONFIG; + String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(current_version).plus_file(template_file_name); - // Now check system file - if (has_system_path) { - if (FileAccess::exists(system_file)) { - return system_file; - } + if (FileAccess::exists(template_path)) { + return template_path; } // Not found if (err) { - *err += "No export template found at \"" + user_file + "\""; - if (has_system_path) - *err += "\n or \"" + system_file + "\"."; - else - *err += "."; + *err += "No export template found at \"" + template_path + "\"."; } - return String(); // not found + return String(); } bool EditorExportPlatform::exists_export_template(String template_file_name, String *err) const { @@ -692,7 +677,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & } String config_file = "project.binary"; - String engine_cfb = EditorSettings::get_singleton()->get_settings_path() + "/tmp/tmp" + config_file; + String engine_cfb = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp" + config_file); ProjectSettings::get_singleton()->save_custom(engine_cfb, custom_map, custom_list); Vector<uint8_t> data = FileAccess::get_file_as_array(engine_cfb); @@ -705,7 +690,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c EditorProgress ep("savepack", TTR("Packing"), 102); - String tmppath = EditorSettings::get_singleton()->get_settings_path() + "/tmp/packtmp"; + String tmppath = EditorSettings::get_singleton()->get_cache_dir().plus_file("packtmp"); FileAccess *ftmp = FileAccess::open(tmppath, FileAccess::WRITE); ERR_FAIL_COND_V(!ftmp, ERR_CANT_CREATE) @@ -982,7 +967,7 @@ void EditorExport::remove_export_preset(int p_idx) { void EditorExport::add_export_plugin(const Ref<EditorExportPlugin> &p_plugin) { - if (export_plugins.find(p_plugin) == 1) { + if (export_plugins.find(p_plugin) == -1) { export_plugins.push_back(p_plugin); } } diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index a6fc8dcddf..8d5bad3346 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -188,7 +188,7 @@ void EditorFileSystem::_scan_filesystem() { String project = ProjectSettings::get_singleton()->get_resource_path(); - String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache3"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache3"); FileAccess *f = FileAccess::open(fscache, FileAccess::READ); if (f) { @@ -238,7 +238,7 @@ void EditorFileSystem::_scan_filesystem() { memdelete(f); } - String update_cache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update3"); + String update_cache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update3"); if (FileAccess::exists(update_cache)) { { @@ -282,7 +282,7 @@ void EditorFileSystem::_scan_filesystem() { } void EditorFileSystem::_save_filesystem_cache() { - String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_cache3"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_cache3"); FileAccess *f = FileAccess::open(fscache, FileAccess::WRITE); _save_filesystem_cache(filesystem, f); @@ -821,8 +821,6 @@ void EditorFileSystem::_scan_fs_changes(EditorFileSystemDirectory *p_dir, const scan_actions.push_back(ia); } } - - EditorResourcePreview::get_singleton()->check_for_invalidation(p_dir->get_file_path(i)); } for (int i = 0; i < p_dir->subdirs.size(); i++) { @@ -915,7 +913,8 @@ void EditorFileSystem::_notification(int p_what) { case NOTIFICATION_ENTER_TREE: { - scan(); + call_deferred("scan"); //this should happen after every editor node entered the tree + } break; case NOTIFICATION_EXIT_TREE: { if (use_threads && thread) { @@ -1181,7 +1180,7 @@ EditorFileSystemDirectory *EditorFileSystem::get_filesystem_path(const String &p void EditorFileSystem::_save_late_updated_files() { //files that already existed, and were modified, need re-scanning for dependencies upon project restart. This is done via saving this special file - String fscache = EditorSettings::get_singleton()->get_project_settings_path().plus_file("filesystem_update3"); + String fscache = EditorSettings::get_singleton()->get_project_settings_dir().plus_file("filesystem_update3"); FileAccessRef f = FileAccess::open(fscache, FileAccess::WRITE); for (Set<String>::Element *E = late_update_files.front(); E; E = E->next()) { f->store_line(E->get()); @@ -1266,7 +1265,6 @@ void EditorFileSystem::update_file(const String &p_file) { fs->files[cpos]->deps = _get_dependencies(p_file); fs->files[cpos]->import_valid = ResourceLoader::is_import_valid(p_file); - EditorResourcePreview::get_singleton()->call_deferred("check_for_invalidation", p_file); call_deferred("emit_signal", "filesystem_changed"); //update later } @@ -1436,6 +1434,8 @@ void EditorFileSystem::_reimport_file(const String &p_file) { r->set_import_last_modified_time(0); } } + + EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } void EditorFileSystem::reimport_files(const Vector<String> &p_files) { diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 05f9da03e1..7e20077fd6 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -122,20 +122,24 @@ void editor_register_fonts(Ref<Theme> p_theme) { dfmono->set_font_ptr(_font_Hack_Regular, _font_Hack_Regular_size); //dfd->set_force_autohinter(true); //just looks better..i think? - MAKE_DEFAULT_FONT(df, int(EditorSettings::get_singleton()->get("interface/editor/font_size")) * EDSCALE); + int default_font_size = int(EditorSettings::get_singleton()->get("interface/editor/font_size")) * EDSCALE; + MAKE_DEFAULT_FONT(df, default_font_size); p_theme->set_default_theme_font(df); + MAKE_DEFAULT_FONT(df_title, default_font_size + 2 * EDSCALE); + p_theme->set_font("title", "EditorFonts", df_title); + //Ref<BitmapFont> doc_font = make_font(_bi_font_doc_font_height,_bi_font_doc_font_ascent,0,_bi_font_doc_font_charcount,_bi_font_doc_font_characters,p_theme->get_icon("DocFont","EditorIcons")); //Ref<BitmapFont> doc_title_font = make_font(_bi_font_doc_title_font_height,_bi_font_doc_title_font_ascent,0,_bi_font_doc_title_font_charcount,_bi_font_doc_title_font_characters,p_theme->get_icon("DocTitleFont","EditorIcons")); //Ref<BitmapFont> doc_code_font = make_font(_bi_font_doc_code_font_height,_bi_font_doc_code_font_ascent,0,_bi_font_doc_code_font_charcount,_bi_font_doc_code_font_characters,p_theme->get_icon("DocCodeFont","EditorIcons")); - MAKE_DEFAULT_FONT(df_title, int(EDITOR_DEF("text_editor/help/help_title_font_size", 16)) * EDSCALE); + MAKE_DEFAULT_FONT(df_doc_title, int(EDITOR_DEF("text_editor/help/help_title_font_size", 16)) * EDSCALE); MAKE_DEFAULT_FONT(df_doc, int(EDITOR_DEF("text_editor/help/help_font_size", 14)) * EDSCALE); p_theme->set_font("doc", "EditorFonts", df_doc); - p_theme->set_font("doc_title", "EditorFonts", df_title); + p_theme->set_font("doc_title", "EditorFonts", df_doc_title); MAKE_DEFAULT_FONT(df_rulers, int(EDITOR_DEF("canvas_item_editor/rulers", 8)) * EDSCALE); p_theme->set_font("rulers", "EditorFonts", df_rulers); @@ -176,9 +180,4 @@ void editor_register_fonts(Ref<Theme> p_theme) { df_output_code->set_font_data(dfmono); MAKE_FALLBACKS(df_output_code); p_theme->set_font("status_source", "EditorFonts", df_output_code); - - //replace default theme - Ref<Texture> di; - Ref<StyleBox> ds; - fill_default_theme(p_theme, df, df_doc, di, ds, EDSCALE); } diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index 03cd2c9b6b..cc7f1cac43 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -555,7 +555,7 @@ void EditorHelp::_class_desc_select(const String &p_select) { if (select.find(".") != -1) { class_name = select.get_slice(".", 0); } else { - class_name = "@Global Scope"; + class_name = "@GlobalScope"; } emit_signal("go_to_help", "class_enum:" + class_name + ":" + select); return; @@ -1478,9 +1478,10 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { Color font_color_hl = p_rt->get_color("headline_color", "EditorHelp"); Color link_color = p_rt->get_color("accent_color", "Editor").linear_interpolate(font_color_hl, 0.8); - String bbcode = p_bbcode.replace("\t", " ").replace("\r", " ").strip_edges(); + String bbcode = p_bbcode.dedent().replace("\t", "").replace("\r", "").strip_edges(); List<String> tag_stack; + bool code_tag = false; int pos = 0; while (pos < bbcode.length()) { @@ -1491,7 +1492,10 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { brk_pos = bbcode.length(); if (brk_pos > pos) { - p_rt->add_text(bbcode.substr(pos, brk_pos - pos)); + String text = bbcode.substr(pos, brk_pos - pos); + if (!code_tag) + text = text.replace("\n", "\n\n"); + p_rt->add_text(text); } if (brk_pos == bbcode.length()) @@ -1500,7 +1504,11 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { int brk_end = bbcode.find("]", brk_pos + 1); if (brk_end == -1) { - p_rt->add_text(bbcode.substr(brk_pos, bbcode.length() - brk_pos)); + + String text = bbcode.substr(brk_pos, bbcode.length() - brk_pos); + if (!code_tag) + text = text.replace("\n", "\n\n"); + p_rt->add_text(text); break; } @@ -1509,20 +1517,23 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { if (tag.begins_with("/")) { bool tag_ok = tag_stack.size() && tag_stack.front()->get() == tag.substr(1, tag.length()); - if (tag_stack.size()) { - } if (!tag_ok) { p_rt->add_text("["); - pos++; + pos = brk_pos + 1; continue; } tag_stack.pop_front(); pos = brk_end + 1; + code_tag = false; if (tag != "/img") p_rt->pop(); + } else if (code_tag) { + + p_rt->add_text("["); + pos = brk_pos + 1; } else if (tag.begins_with("method ")) { @@ -1559,6 +1570,7 @@ static void _add_text_to_rt(const String &p_bbcode, RichTextLabel *p_rt) { //use monospace font p_rt->push_font(doc_code_font); + code_tag = true; pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "center") { diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 3513126a9b..7627fecc43 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -147,7 +147,7 @@ void EditorNode::_update_scene_tabs() { void EditorNode::_update_title() { String appname = ProjectSettings::get_singleton()->get("application/config/name"); - String title = appname.empty() ? String(VERSION_FULL_NAME) : String(_MKSTR(VERSION_NAME) + String(" - ") + appname); + String title = appname.empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname); String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); if (!edited.empty()) title += " - " + String(edited.get_file()); @@ -284,9 +284,10 @@ void EditorNode::_notification(int p_what) { if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { scene_tabs->set_tab_close_display_policy((bool(EDITOR_DEF("interface/editor/always_show_close_button_in_scene_tabs", false)) ? Tabs::CLOSE_BUTTON_SHOW_ALWAYS : Tabs::CLOSE_BUTTON_SHOW_ACTIVE_ONLY)); property_editor->set_enable_capitalize_paths(bool(EDITOR_DEF("interface/editor/capitalize_properties", true))); - Ref<Theme> theme = create_editor_theme(theme_base->get_theme()); + Ref<Theme> theme = create_custom_theme(theme_base->get_theme()); theme_base->set_theme(theme); + gui_base->set_theme(theme); gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles")); play_button_panel->add_style_override("panel", gui_base->get_stylebox("PlayButtonPanel", "EditorStyles")); @@ -704,7 +705,7 @@ void EditorNode::_get_scene_metadata(const String &p_file) { if (!scene) return; - String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); + String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; cf.instance(); @@ -738,7 +739,7 @@ void EditorNode::_set_scene_metadata(const String &p_file, int p_idx) { scene->set_meta("__editor_run_settings__", Variant()); //clear it (no point in keeping it) scene->set_meta("__editor_plugin_states__", Variant()); - String path = EditorSettings::get_singleton()->get_project_settings_path().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); + String path = EditorSettings::get_singleton()->get_project_settings_dir().plus_file(p_file.get_file() + "-editstate-" + p_file.md5_text() + ".cfg"); Ref<ConfigFile> cf; cf.instance(); @@ -871,7 +872,7 @@ void EditorNode::_find_node_types(Node *p_node, int &count_2d, int &count_3d) { _find_node_types(p_node->get_child(i), count_2d, count_3d); } -void EditorNode::_save_scene_with_preview(String p_file) { +void EditorNode::_save_scene_with_preview(String p_file, int p_idx) { EditorProgress save("save", TTR("Saving Scene"), 4); save.step(TTR("Analyzing"), 0); @@ -905,27 +906,33 @@ void EditorNode::_save_scene_with_preview(String p_file) { int preview_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); preview_size *= EDSCALE; - int width, height; - if (img->get_width() > preview_size && img->get_width() >= img->get_height()) { - width = preview_size; - height = img->get_height() * preview_size / img->get_width(); - } else if (img->get_height() > preview_size && img->get_height() >= img->get_width()) { + // consider a square region + int vp_size = MIN(img->get_width(), img->get_height()); + int x = (img->get_width() - vp_size) / 2; + int y = (img->get_height() - vp_size) / 2; - height = preview_size; - width = img->get_width() * preview_size / img->get_height(); + img->convert(Image::FORMAT_RGB8); + + if (vp_size < preview_size) { + // just square it. + img->crop_from_point(x, y, vp_size, vp_size); } else { + int ratio = vp_size / preview_size; + int size = preview_size * (ratio / 2); - width = img->get_width(); - height = img->get_height(); + x = (img->get_width() - size) / 2; + y = (img->get_height() - size) / 2; + + img->crop_from_point(x, y, size, size); + // We could get better pictures with better filters + img->resize(preview_size, preview_size, Image::INTERPOLATE_CUBIC); } - img->convert(Image::FORMAT_RGB8); - img->resize(width, height); img->flip_y(); //save thumbnail directly, as thumbnailer may not update due to actual scene not changing md5 - String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_file).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); @@ -937,7 +944,7 @@ void EditorNode::_save_scene_with_preview(String p_file) { } save.step(TTR("Saving Scene"), 4); - _save_scene(p_file); + _save_scene(p_file, p_idx); EditorResourcePreview::get_singleton()->check_for_invalidation(p_file); } @@ -1095,10 +1102,7 @@ void EditorNode::_dialog_action(String p_file) { if (file->get_mode() == EditorFileDialog::MODE_SAVE_FILE) { _save_default_environment(); - if (scene_idx != editor_data.get_edited_scene()) - _save_scene(p_file, scene_idx); - else - _save_scene_with_preview(p_file); + _save_scene_with_preview(p_file, scene_idx); if (scene_idx != -1) _discard_changes(); @@ -1111,7 +1115,7 @@ void EditorNode::_dialog_action(String p_file) { _save_default_environment(); _save_scene_with_preview(p_file); - _run(true); + _run(false, p_file); } } break; @@ -1200,7 +1204,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err == ERR_CANT_OPEN) { config.instance(); // new config @@ -1211,7 +1215,7 @@ void EditorNode::_dialog_action(String p_file) { _save_docks_to_config(config, p_file); - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); layout_dialog->hide(); _update_layouts_menu(); @@ -1228,7 +1232,7 @@ void EditorNode::_dialog_action(String p_file) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK || !config->has_section(p_file)) { show_warning(TTR("Layout name not found!")); @@ -1242,7 +1246,7 @@ void EditorNode::_dialog_action(String p_file) { config->set_value(p_file, E->get(), Variant()); } - config->save(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + config->save(EditorSettings::get_singleton()->get_editor_layouts_config()); layout_dialog->hide(); _update_layouts_menu(); @@ -1825,7 +1829,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { if (scene && scene->get_filename() != "") { if (scene_idx != editor_data.get_edited_scene()) - _save_scene(scene->get_filename(), scene_idx); + _save_scene_with_preview(scene->get_filename(), scene_idx); else _save_scene_with_preview(scene->get_filename()); @@ -1933,6 +1937,15 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { } break; case FILE_EXPORT_TILESET: { + //Make sure that the scene has a root before trying to convert to tileset + if (!editor_data.get_edited_scene_root()) { + current_option = -1; + accept->get_ok()->set_text(TTR("I see..")); + accept->set_text(TTR("This operation can't be done without a root node.")); + accept->popup_centered_minsize(); + break; + } + List<String> extensions; Ref<TileSet> ml(memnew(TileSet)); ResourceSaver::get_recognized_extensions(ml, &extensions); @@ -3254,11 +3267,11 @@ void EditorNode::register_editor_types() { ClassDB::register_class<EditorScript>(); ClassDB::register_class<EditorSelection>(); ClassDB::register_class<EditorFileDialog>(); - ClassDB::register_class<EditorSettings>(); + ClassDB::register_virtual_class<EditorSettings>(); ClassDB::register_class<EditorSpatialGizmo>(); - ClassDB::register_class<EditorResourcePreview>(); + ClassDB::register_virtual_class<EditorResourcePreview>(); ClassDB::register_class<EditorResourcePreviewGenerator>(); - ClassDB::register_class<EditorFileSystem>(); + ClassDB::register_virtual_class<EditorFileSystem>(); ClassDB::register_class<EditorFileSystemDirectory>(); ClassDB::register_virtual_class<ScriptEditor>(); ClassDB::register_virtual_class<EditorInterface>(); @@ -3266,7 +3279,7 @@ void EditorNode::register_editor_types() { ClassDB::register_class<EditorResourceConversionPlugin>(); // FIXME: Is this stuff obsolete, or should it be ported to new APIs? - //ClassDB::register_class<EditorScenePostImport>(); + ClassDB::register_class<EditorScenePostImport>(); //ClassDB::register_type<EditorImportExport>(); } @@ -3574,7 +3587,7 @@ void EditorNode::_save_docks() { _save_docks_to_config(config, "docks"); editor_data.get_plugin_window_layout(config); - config->save(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); + config->save(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); } void EditorNode::_save_docks_to_config(Ref<ConfigFile> p_layout, const String &p_section) { @@ -3636,7 +3649,7 @@ void EditorNode::_load_docks() { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_project_settings_path().plus_file("editor_layout.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_project_settings_dir().plus_file("editor_layout.cfg")); if (err != OK) { //no config if (overridden_default_layout >= 0) { @@ -3805,7 +3818,7 @@ void EditorNode::_update_layouts_menu() { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config } @@ -3853,7 +3866,7 @@ void EditorNode::_layout_menu_option(int p_id) { Ref<ConfigFile> config; config.instance(); - Error err = config->load(EditorSettings::get_singleton()->get_settings_path().plus_file("editor_layouts-3.cfg")); + Error err = config->load(EditorSettings::get_singleton()->get_editor_layouts_config()); if (err != OK) { return; //no config } @@ -4217,72 +4230,71 @@ Variant EditorNode::drag_resource(const Ref<Resource> &p_res, Control *p_from) { return drag_data; } -Variant EditorNode::drag_files(const Vector<String> &p_files, Control *p_from) { - - VBoxContainer *files = memnew(VBoxContainer); - - int max_files = 6; - - for (int i = 0; i < MIN(max_files, p_files.size()); i++) { - - Label *label = memnew(Label); - label->set_text(p_files[i].get_file()); - files->add_child(label); +Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from) { + bool has_folder = false; + bool has_file = false; + for (int i = 0; i < p_paths.size(); i++) { + bool is_folder = p_paths[i].ends_with("/"); + has_folder |= is_folder; + has_file |= !is_folder; } - if (p_files.size() > max_files) { - + int max_rows = 6; + int num_rows = p_paths.size() > max_rows ? max_rows - 1 : p_paths.size(); //Don't waste a row to say "1 more file" - list it instead. + VBoxContainer *vbox = memnew(VBoxContainer); + for (int i = 0; i < num_rows; i++) { + HBoxContainer *hbox = memnew(HBoxContainer); + TextureRect *icon = memnew(TextureRect); Label *label = memnew(Label); - label->set_text(vformat(TTR("%d more file(s)"), p_files.size() - max_files)); - files->add_child(label); - } - Dictionary drag_data; - drag_data["type"] = "files"; - drag_data["files"] = p_files; - drag_data["from"] = p_from; - p_from->set_drag_preview(files); //wait until it enters scene - - return drag_data; -} - -Variant EditorNode::drag_files_and_dirs(const Vector<String> &p_files, Control *p_from) { - - VBoxContainer *files = memnew(VBoxContainer); - - int max_files = 6; - - for (int i = 0; i < MIN(max_files, p_files.size()); i++) { - - Label *label = memnew(Label); - label->set_text(p_files[i].get_file()); - files->add_child(label); + if (p_paths[i].ends_with("/")) { + label->set_text(p_paths[i].substr(0, p_paths[i].length() - 1).get_file()); + icon->set_texture(gui_base->get_icon("Folder", "EditorIcons")); + } else { + label->set_text(p_paths[i].get_file()); + icon->set_texture(gui_base->get_icon("File", "EditorIcons")); + } + icon->set_size(Size2(16, 16)); + hbox->add_child(icon); + hbox->add_child(label); + vbox->add_child(hbox); } - if (p_files.size() > max_files) { - + if (p_paths.size() > num_rows) { Label *label = memnew(Label); - label->set_text(vformat(TTR("%d more file(s) or folder(s)"), p_files.size() - max_files)); - files->add_child(label); + if (has_file && has_folder) { + label->set_text(vformat(TTR("%d more files or folders"), p_paths.size() - num_rows)); + } else if (has_folder) { + label->set_text(vformat(TTR("%d more folders"), p_paths.size() - num_rows)); + } else { + label->set_text(vformat(TTR("%d more files"), p_paths.size() - num_rows)); + } + vbox->add_child(label); } + p_from->set_drag_preview(vbox); //wait until it enters scene + Dictionary drag_data; - drag_data["type"] = "files_and_dirs"; - drag_data["files"] = p_files; + drag_data["type"] = has_folder ? "files_and_dirs" : "files"; + drag_data["files"] = p_paths; drag_data["from"] = p_from; - - p_from->set_drag_preview(files); //wait until it enters scene - return drag_data; } void EditorNode::_dropped_files(const Vector<String> &p_files, int p_screen) { - /* - String cur_path = filesystem_dock->get_current_path(); - for(int i=0;i<EditorImportExport::get_singleton()->get_import_plugin_count();i++) { - EditorImportExport::get_singleton()->get_import_plugin(i)->import_from_drop(p_files,cur_path); + String to_path = ProjectSettings::get_singleton()->globalize_path(get_filesystem_dock()->get_current_path()); + DirAccessRef dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + + for (int i = 0; i < p_files.size(); i++) { + + String from = p_files[i]; + if (!ResourceFormatImporter::get_singleton()->can_be_imported(from)) { + continue; + } + String to = to_path.plus_file(from.get_file()); + dir->copy(from, to); } - */ + EditorFileSystem::get_singleton()->scan_changes(); } void EditorNode::_file_access_close_error_notify(const String &p_str) { @@ -4553,6 +4565,11 @@ static Node *_resource_get_edited_scene() { return EditorNode::get_singleton()->get_edited_scene(); } +void EditorNode::_print_handler(void *p_this, const String &p_string, bool p_error) { + EditorNode *en = (EditorNode *)p_this; + en->log->add_message(p_string, p_error); +} + EditorNode::EditorNode() { Resource::_get_local_scene_func = _resource_get_edited_scene; @@ -4690,9 +4707,9 @@ EditorNode::EditorNode() { theme_base->add_child(gui_base); gui_base->set_anchors_and_margins_preset(Control::PRESET_WIDE); - Ref<Theme> theme = create_editor_theme(); + Ref<Theme> theme = create_custom_theme(); theme_base->set_theme(theme); - gui_base->set_theme(create_custom_theme()); + gui_base->set_theme(theme); gui_base->add_style_override("panel", gui_base->get_stylebox("Background", "EditorStyles")); resource_preview = memnew(EditorResourcePreview); @@ -4789,7 +4806,12 @@ EditorNode::EditorNode() { dock_tab_move_left->set_focus_mode(Control::FOCUS_NONE); dock_tab_move_left->connect("pressed", this, "_dock_move_left"); dock_hb->add_child(dock_tab_move_left); - dock_hb->add_spacer(); + + Label *dock_label = memnew(Label); + dock_label->set_text(TTR("Dock Position")); + dock_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + dock_hb->add_child(dock_label); + dock_tab_move_right = memnew(ToolButton); dock_tab_move_right->set_icon(theme->get_icon("Forward", "EditorIcons")); dock_tab_move_right->set_focus_mode(Control::FOCUS_NONE); @@ -5387,12 +5409,12 @@ EditorNode::EditorNode() { save_confirmation->connect("confirmed", this, "_menu_confirm_current"); save_confirmation->connect("custom_action", this, "_discard_changes"); - file_templates = memnew(FileDialog); + file_templates = memnew(EditorFileDialog); file_templates->set_title(TTR("Import Templates From ZIP File")); gui_base->add_child(file_templates); - file_templates->set_mode(FileDialog::MODE_OPEN_FILE); - file_templates->set_access(FileDialog::ACCESS_FILESYSTEM); + file_templates->set_mode(EditorFileDialog::MODE_OPEN_FILE); + file_templates->set_access(EditorFileDialog::ACCESS_FILESYSTEM); file_templates->clear_filters(); file_templates->add_filter("*.tpz ; Template Package"); @@ -5400,15 +5422,15 @@ EditorNode::EditorNode() { gui_base->add_child(file); file->set_current_dir("res://"); - file_export = memnew(FileDialog); - file_export->set_access(FileDialog::ACCESS_FILESYSTEM); + file_export = memnew(EditorFileDialog); + file_export->set_access(EditorFileDialog::ACCESS_FILESYSTEM); gui_base->add_child(file_export); file_export->set_title(TTR("Export Project")); file_export->connect("file_selected", this, "_dialog_action"); - file_export_lib = memnew(FileDialog); + file_export_lib = memnew(EditorFileDialog); file_export_lib->set_title(TTR("Export Library")); - file_export_lib->set_mode(FileDialog::MODE_SAVE_FILE); + file_export_lib->set_mode(EditorFileDialog::MODE_SAVE_FILE); file_export_lib->connect("file_selected", this, "_dialog_action"); file_export_lib_merge = memnew(CheckButton); file_export_lib_merge->set_text(TTR("Merge With Existing")); @@ -5421,10 +5443,10 @@ EditorNode::EditorNode() { file_export_password->set_editable(false); file_export->get_vbox()->add_margin_child(TTR("Password:"), file_export_password); - file_script = memnew(FileDialog); + file_script = memnew(EditorFileDialog); file_script->set_title(TTR("Open & Run a Script")); - file_script->set_access(FileDialog::ACCESS_FILESYSTEM); - file_script->set_mode(FileDialog::MODE_OPEN_FILE); + file_script->set_access(EditorFileDialog::ACCESS_FILESYSTEM); + file_script->set_mode(EditorFileDialog::MODE_OPEN_FILE); List<String> sexts; ResourceLoader::get_recognized_extensions_for_type("Script", &sexts); for (List<String>::Element *E = sexts.front(); E; E = E->next()) { @@ -5534,6 +5556,10 @@ EditorNode::EditorNode() { spatial_mat_convert.instance(); resource_conversion_plugins.push_back(spatial_mat_convert); + Ref<CanvasItemMaterialConversionPlugin> canvas_item_mat_convert; + canvas_item_mat_convert.instance(); + resource_conversion_plugins.push_back(canvas_item_mat_convert); + Ref<ParticlesMaterialConversionPlugin> particles_mat_convert; particles_mat_convert.instance(); resource_conversion_plugins.push_back(particles_mat_convert); @@ -5649,6 +5675,10 @@ EditorNode::EditorNode() { _dim_timer->connect("timeout", this, "_dim_timeout"); add_child(_dim_timer); + print_handler.printfunc = _print_handler; + print_handler.userdata = this; + add_print_handler(&print_handler); + ED_SHORTCUT("editor/editor_2d", TTR("Open 2D Editor"), KEY_F1); ED_SHORTCUT("editor/editor_3d", TTR("Open 3D Editor"), KEY_F2); ED_SHORTCUT("editor/editor_script", TTR("Open Script Editor"), KEY_F3); //hack neded for script editor F3 search to work :) Assign like this or don't use F3 @@ -5660,6 +5690,7 @@ EditorNode::EditorNode() { EditorNode::~EditorNode() { + remove_print_handler(&print_handler); memdelete(EditorHelp::get_doc_data()); memdelete(editor_selection); memdelete(editor_plugins_over); diff --git a/editor/editor_node.h b/editor/editor_node.h index 32d46e686b..54cb414835 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -30,6 +30,7 @@ #ifndef EDITOR_NODE_H #define EDITOR_NODE_H +#include "core/print_string.h" #include "editor/connections_dialog.h" #include "editor/create_dialog.h" #include "editor/editor_about.h" @@ -294,10 +295,10 @@ private: ProjectSettingsEditor *project_settings; EditorFileDialog *file; ExportTemplateManager *export_template_manager; - FileDialog *file_templates; - FileDialog *file_export; - FileDialog *file_export_lib; - FileDialog *file_script; + EditorFileDialog *file_templates; + EditorFileDialog *file_export; + EditorFileDialog *file_export_lib; + EditorFileDialog *file_script; CheckButton *file_export_lib_merge; LineEdit *file_export_password; String current_path; @@ -503,7 +504,7 @@ private: void _mark_unsaved_scenes(); void _find_node_types(Node *p_node, int &count_2d, int &count_3d); - void _save_scene_with_preview(String p_file); + void _save_scene_with_preview(String p_file, int p_idx = -1); Map<String, Set<String> > dependency_errors; @@ -610,6 +611,9 @@ private: Vector<Ref<EditorResourceConversionPlugin> > resource_conversion_plugins; + PrintHandlerList print_handler; + static void _print_handler(void *p_this, const String &p_string, bool p_error); + protected: void _notification(int p_what); static void _bind_methods(); @@ -765,8 +769,7 @@ public: void remove_bottom_panel_item(Control *p_item); Variant drag_resource(const Ref<Resource> &p_res, Control *p_from); - Variant drag_files(const Vector<String> &p_files, Control *p_from); - Variant drag_files_and_dirs(const Vector<String> &p_files, Control *p_from); + Variant drag_files_and_dirs(const Vector<String> &p_paths, Control *p_from); void add_tool_menu_item(const String &p_name, Object *p_handler, const String &p_callback, const Variant &p_ud = Variant()); void add_tool_submenu_item(const String &p_name, PopupMenu *p_submenu); diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index c8abc1f9db..38e8b301b7 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -76,11 +76,11 @@ Vector<Ref<Texture> > EditorInterface::make_mesh_previews(const Vector<Ref<Mesh> //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); - RID light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + RID light = VS::get_singleton()->directional_light_create(); RID light_instance = VS::get_singleton()->instance_create2(light, scenario); VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); - RID light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + RID light2 = VS::get_singleton()->directional_light_create(); VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); RID light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); @@ -102,14 +102,14 @@ Vector<Ref<Texture> > EditorInterface::make_mesh_previews(const Vector<Ref<Mesh> textures.push_back(Ref<Texture>()); continue; } - Rect3 aabb = mesh->get_aabb(); + AABB aabb = mesh->get_aabb(); print_line("aabb: " + aabb); Vector3 ofs = aabb.position + aabb.size * 0.5; aabb.position -= ofs; Transform xform; xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.25); xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.25) * xform.basis; - Rect3 rot_aabb = xform.xform(aabb); + AABB rot_aabb = xform.xform(aabb); print_line("rot_aabb: " + rot_aabb); float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; if (m == 0) { @@ -455,7 +455,11 @@ void EditorPlugin::make_visible(bool p_visible) { void EditorPlugin::edit(Object *p_object) { if (get_script_instance() && get_script_instance()->has_method("edit")) { - get_script_instance()->call("edit", p_object); + if (p_object->is_class("Resource")) { + get_script_instance()->call("edit", Ref<Resource>(Object::cast_to<Resource>(p_object))); + } else { + get_script_instance()->call("edit", p_object); + } } } diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index f92962a4cb..467451cd2b 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -86,7 +86,6 @@ void EditorResourcePreview::_thread_func(void *ud) { void EditorResourcePreview::_preview_ready(const String &p_str, const Ref<Texture> &p_texture, ObjectID id, const StringName &p_func, const Variant &p_ud) { - //print_line("preview is ready"); preview_mutex->lock(); String path = p_str; @@ -121,7 +120,6 @@ Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem &p_item, c type = p_item.resource->get_class(); else type = ResourceLoader::get_resource_type(p_item.path); - //print_line("resource type is: "+type); if (type == "") return Ref<Texture>(); //could not guess type @@ -144,7 +142,6 @@ Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem &p_item, c if (!p_item.resource.is_valid()) { // cache the preview in case it's a resource on disk if (generated.is_valid()) { - //print_line("was generated"); int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; //wow it generated a preview... save cache @@ -164,15 +161,11 @@ Ref<Texture> EditorResourcePreview::_generate_preview(const QueueItem &p_item, c void EditorResourcePreview::_thread() { - //print_line("begin thread"); while (!exit) { - //print_line("wait for semaphore"); preview_sem->wait(); preview_mutex->lock(); - //print_line("blue team go"); - if (queue.size()) { QueueItem item = queue.front()->get(); @@ -189,12 +182,11 @@ void EditorResourcePreview::_thread() { preview_mutex->unlock(); } else { + preview_mutex->unlock(); Ref<ImageTexture> texture; - //print_line("pop from queue "+item.path); - int thumbnail_size = EditorSettings::get_singleton()->get("filesystem/file_dialog/thumbnail_size"); thumbnail_size *= EDSCALE; @@ -206,7 +198,7 @@ void EditorResourcePreview::_thread() { } else { - String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(item.path).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); @@ -304,7 +296,6 @@ void EditorResourcePreview::queue_edited_resource_preview(const Ref<Resource> &p cache.erase(path_id); //erase if exists, since it will be regen - //print_line("send to thread "+p_path); QueueItem item; item.function = p_receiver_func; item.id = p_receiver->get_instance_id(); @@ -328,7 +319,6 @@ void EditorResourcePreview::queue_resource_preview(const String &p_path, Object return; } - //print_line("send to thread "+p_path); QueueItem item; item.function = p_receiver_func; item.id = p_receiver->get_instance_id(); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index bc91fcdf04..d228dd2581 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -135,6 +135,7 @@ bool EditorSettings::_get(const StringName &p_name, Variant &r_ret) const { void EditorSettings::_initial_set(const StringName &p_name, const Variant &p_value) { set(p_name, p_value); props[p_name].initial = p_value; + props[p_name].initial_set = true; } struct _EVCSort { @@ -214,6 +215,14 @@ void EditorSettings::_add_property_info_bind(const Dictionary &p_info) { } // Default configs +bool EditorSettings::has_default_value(const String &p_setting) const { + + _THREAD_SAFE_METHOD_ + + if (!props.has(p_setting)) + return false; + return props[p_setting].initial_set; +} void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { @@ -325,6 +334,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("text_editor/line_numbers/show_line_numbers", true); _initial_set("text_editor/line_numbers/line_numbers_zero_padded", false); _initial_set("text_editor/line_numbers/show_breakpoint_gutter", true); + _initial_set("text_editor/line_numbers/code_folding", true); _initial_set("text_editor/line_numbers/show_line_length_guideline", false); _initial_set("text_editor/line_numbers/line_length_guideline_column", 80); hints["text_editor/line_numbers/line_length_guideline_column"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/line_length_guideline_column", PROPERTY_HINT_RANGE, "20, 160, 10"); @@ -630,10 +640,14 @@ void EditorSettings::create() { return; //pointless DirAccess *dir = NULL; - Variant meta; + String data_path; + String data_dir; String config_path; String config_dir; + String cache_path; + String cache_dir; + Ref<ConfigFile> extra_config = memnew(ConfigFile); String exe_path = OS::get_singleton()->get_executable_path().get_base_dir(); @@ -650,38 +664,50 @@ void EditorSettings::create() { memdelete(d); if (self_contained) { - // editor is self contained + + // editor is self contained, all in same folder + data_path = exe_path; + data_dir = data_path.plus_file("editor_data"); config_path = exe_path; - config_dir = "editor_data"; + config_dir = data_dir; + cache_path = exe_path; + cache_dir = data_dir.plus_file("cache"); } else { - if (OS::get_singleton()->has_environment("APPDATA")) { - // Most likely under windows, save here - config_path = OS::get_singleton()->get_environment("APPDATA"); - config_dir = String(_MKSTR(VERSION_SHORT_NAME)).capitalize(); - } else if (OS::get_singleton()->has_environment("HOME")) { - - config_path = OS::get_singleton()->get_environment("HOME"); - config_dir = "." + String(_MKSTR(VERSION_SHORT_NAME)).to_lower(); + // Typically XDG_DATA_HOME or %APPDATA% + data_path = OS::get_singleton()->get_data_path(); + data_dir = data_path.plus_file(OS::get_singleton()->get_godot_dir_name()); + // Can be different from data_path e.g. on Linux or macOS + config_path = OS::get_singleton()->get_config_path(); + config_dir = config_path.plus_file(OS::get_singleton()->get_godot_dir_name()); + // Can be different from above paths, otherwise a subfolder of data_dir + cache_path = OS::get_singleton()->get_cache_path(); + if (cache_path == data_path) { + cache_dir = data_dir.plus_file("cache"); + } else { + cache_dir = cache_path.plus_file(OS::get_singleton()->get_godot_dir_name()); } - }; + } ClassDB::register_class<EditorSettings>(); //otherwise it can't be unserialized + String config_file_path; - if (config_path != "") { + if (data_path != "" && config_path != "" && cache_path != "") { + + // Validate/create data dir and subdirectories dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - if (dir->change_dir(config_path) != OK) { - ERR_PRINT("Cannot find path for config directory!"); + if (dir->change_dir(data_path) != OK) { + ERR_PRINT("Cannot find path for data directory!"); memdelete(dir); goto fail; } - if (dir->change_dir(config_dir) != OK) { - dir->make_dir(config_dir); - if (dir->change_dir(config_dir) != OK) { - ERR_PRINT("Cannot create config directory!"); + if (dir->change_dir(data_dir) != OK) { + dir->make_dir(data_dir); + if (dir->change_dir(data_dir) != OK) { + ERR_PRINT("Cannot create data directory!"); memdelete(dir); goto fail; } @@ -690,10 +716,43 @@ void EditorSettings::create() { if (dir->change_dir("templates") != OK) { dir->make_dir("templates"); } else { - dir->change_dir(".."); } + // Validate/create cache dir + + if (dir->change_dir(cache_path) != OK) { + ERR_PRINT("Cannot find path for cache directory!"); + memdelete(dir); + goto fail; + } + + if (dir->change_dir(cache_dir) != OK) { + dir->make_dir(cache_dir); + if (dir->change_dir(cache_dir) != OK) { + ERR_PRINT("Cannot create cache directory!"); + memdelete(dir); + goto fail; + } + } + + // Validate/create config dir and subdirectories + + if (dir->change_dir(config_path) != OK) { + ERR_PRINT("Cannot find path for config directory!"); + memdelete(dir); + goto fail; + } + + if (dir->change_dir(config_dir) != OK) { + dir->make_dir(config_dir); + if (dir->change_dir(config_dir) != OK) { + ERR_PRINT("Cannot create config directory!"); + memdelete(dir); + goto fail; + } + } + if (dir->change_dir("text_editor_themes") != OK) { dir->make_dir("text_editor_themes"); } else { @@ -705,52 +764,40 @@ void EditorSettings::create() { } else { dir->change_dir(".."); } - _create_script_templates(dir->get_current_dir() + "/script_templates"); + _create_script_templates(dir->get_current_dir().plus_file("script_templates")); - if (dir->change_dir("tmp") != OK) { - dir->make_dir("tmp"); + if (dir->change_dir("projects") != OK) { + dir->make_dir("projects"); } else { - dir->change_dir(".."); } - if (dir->change_dir("config") != OK) { - dir->make_dir("config"); - } else { - - dir->change_dir(".."); - } + // Validate/create project-specific config dir - dir->change_dir("config"); + dir->change_dir("projects"); + String project_config_dir = ProjectSettings::get_singleton()->get_resource_path(); + if (project_config_dir.ends_with("/")) + project_config_dir = config_path.substr(0, project_config_dir.size() - 1); + project_config_dir = project_config_dir.get_file() + "-" + project_config_dir.md5_text(); - String pcp = ProjectSettings::get_singleton()->get_resource_path(); - if (pcp.ends_with("/")) - pcp = config_path.substr(0, pcp.size() - 1); - pcp = pcp.get_file() + "-" + pcp.md5_text(); - - if (dir->change_dir(pcp)) { - dir->make_dir(pcp); + if (dir->change_dir(project_config_dir) != OK) { + dir->make_dir(project_config_dir); } else { dir->change_dir(".."); } - dir->change_dir(".."); - // path at least is validated, so validate config file - - String config_file_name = "editor_settings-" + String(_MKSTR(VERSION_MAJOR)) + ".tres"; - config_file_path = config_path + "/" + config_dir + "/" + config_file_name; - - String open_path = config_file_path; + // Validate editor config file + String config_file_name = "editor_settings-" + itos(VERSION_MAJOR) + ".tres"; + config_file_path = config_dir.plus_file(config_file_name); if (!dir->file_exists(config_file_name)) { - goto fail; } memdelete(dir); - singleton = ResourceLoader::load(open_path, "EditorSettings"); + singleton = ResourceLoader::load(config_file_path, "EditorSettings"); if (singleton.is_null()) { WARN_PRINT("Could not open config file."); @@ -759,8 +806,10 @@ void EditorSettings::create() { singleton->save_changed_setting = true; singleton->config_file_path = config_file_path; - singleton->project_config_path = pcp; - singleton->settings_path = config_path + "/" + config_dir; + singleton->project_config_dir = project_config_dir; + singleton->settings_dir = config_dir; + singleton->data_dir = data_dir; + singleton->cache_dir = cache_dir; if (OS::get_singleton()->is_stdout_verbose()) { @@ -790,7 +839,9 @@ fail: singleton = Ref<EditorSettings>(memnew(EditorSettings)); singleton->save_changed_setting = true; singleton->config_file_path = config_file_path; - singleton->settings_path = config_path + "/" + config_dir; + singleton->settings_dir = config_dir; + singleton->data_dir = data_dir; + singleton->cache_dir = cache_dir; singleton->_load_defaults(extra_config); singleton->setup_language(); singleton->setup_network(); @@ -834,10 +885,10 @@ void EditorSettings::setup_network() { hint += ip; } - set("network/debug/remote_host", lip); + _initial_set("network/debug/remote_host", lip); add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint)); - set("network/debug/remote_port", port); + _initial_set("network/debug/remote_port", port); add_property_hint(PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1")); } @@ -913,18 +964,23 @@ void EditorSettings::raise_order(const String &p_setting) { void EditorSettings::set_initial_value(const StringName &p_setting, const Variant &p_value) { - ERR_FAIL_COND(!props.has(p_setting)); + if (!props.has(p_setting)) + return; props[p_setting].initial = p_value; + props[p_setting].initial_set = true; } Variant _EDITOR_DEF(const String &p_setting, const Variant &p_default) { + Variant ret = p_default; if (EditorSettings::get_singleton()->has_setting(p_setting)) - return EditorSettings::get_singleton()->get(p_setting); - EditorSettings::get_singleton()->set(p_setting, p_default); - EditorSettings::get_singleton()->set_initial_value(p_setting, p_default); + ret = EditorSettings::get_singleton()->get(p_setting); + if (!EditorSettings::get_singleton()->has_default_value(p_setting)) { + EditorSettings::get_singleton()->set_initial_value(p_setting, p_default); + EditorSettings::get_singleton()->set(p_setting, p_default); + } - return p_default; + return ret; } Variant _EDITOR_GET(const String &p_setting) { @@ -956,21 +1012,52 @@ void EditorSettings::add_property_hint(const PropertyInfo &p_hint) { hints[p_hint.name] = p_hint; } -// Settings paths and saved metadata +// Data directories -String EditorSettings::get_settings_path() const { +String EditorSettings::get_data_dir() const { - return settings_path; + return data_dir; } -String EditorSettings::get_project_settings_path() const { +String EditorSettings::get_templates_dir() const { - return get_settings_path().plus_file("config").plus_file(project_config_path); + return get_data_dir().plus_file("templates"); } +// Config directories + +String EditorSettings::get_settings_dir() const { + + return settings_dir; +} + +String EditorSettings::get_project_settings_dir() const { + + return get_settings_dir().plus_file("projects").plus_file(project_config_dir); +} + +String EditorSettings::get_text_editor_themes_dir() const { + + return get_settings_dir().plus_file("text_editor_themes"); +} + +String EditorSettings::get_script_templates_dir() const { + + return get_settings_dir().plus_file("script_templates"); +} + +// Cache directory + +String EditorSettings::get_cache_dir() const { + + return cache_dir; +} + +// Metadata + void EditorSettings::set_project_metadata(const String &p_section, const String &p_key, Variant p_data) { Ref<ConfigFile> cf = memnew(ConfigFile); - String path = get_project_settings_path().plus_file("project_metadata.cfg"); + String path = get_project_settings_dir().plus_file("project_metadata.cfg"); cf->load(path); cf->set_value(p_section, p_key, p_data); cf->save(path); @@ -978,7 +1065,7 @@ void EditorSettings::set_project_metadata(const String &p_section, const String Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) { Ref<ConfigFile> cf = memnew(ConfigFile); - String path = get_project_settings_path().plus_file("project_metadata.cfg"); + String path = get_project_settings_dir().plus_file("project_metadata.cfg"); Error err = cf->load(path); if (err != OK) { return p_default; @@ -989,7 +1076,7 @@ Variant EditorSettings::get_project_metadata(const String &p_section, const Stri void EditorSettings::set_favorite_dirs(const Vector<String> &p_favorites_dirs) { favorite_dirs = p_favorites_dirs; - FileAccess *f = FileAccess::open(get_project_settings_path().plus_file("favorite_dirs"), FileAccess::WRITE); + FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorite_dirs"), FileAccess::WRITE); if (f) { for (int i = 0; i < favorite_dirs.size(); i++) f->store_line(favorite_dirs[i]); @@ -1005,7 +1092,7 @@ Vector<String> EditorSettings::get_favorite_dirs() const { void EditorSettings::set_recent_dirs(const Vector<String> &p_recent_dirs) { recent_dirs = p_recent_dirs; - FileAccess *f = FileAccess::open(get_project_settings_path().plus_file("recent_dirs"), FileAccess::WRITE); + FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::WRITE); if (f) { for (int i = 0; i < recent_dirs.size(); i++) f->store_line(recent_dirs[i]); @@ -1020,7 +1107,7 @@ Vector<String> EditorSettings::get_recent_dirs() const { void EditorSettings::load_favorites() { - FileAccess *f = FileAccess::open(get_project_settings_path().plus_file("favorite_dirs"), FileAccess::READ); + FileAccess *f = FileAccess::open(get_project_settings_dir().plus_file("favorite_dirs"), FileAccess::READ); if (f) { String line = f->get_line().strip_edges(); while (line != "") { @@ -1030,7 +1117,7 @@ void EditorSettings::load_favorites() { memdelete(f); } - f = FileAccess::open(get_project_settings_path().plus_file("recent_dirs"), FileAccess::READ); + f = FileAccess::open(get_project_settings_dir().plus_file("recent_dirs"), FileAccess::READ); if (f) { String line = f->get_line().strip_edges(); while (line != "") { @@ -1043,7 +1130,7 @@ void EditorSettings::load_favorites() { void EditorSettings::list_text_editor_themes() { String themes = "Adaptive,Default"; - DirAccess *d = DirAccess::open(get_settings_path().plus_file("text_editor_themes")); + DirAccess *d = DirAccess::open(get_text_editor_themes_dir()); if (d) { d->list_dir_begin(); String file = d->get_next(); @@ -1065,7 +1152,7 @@ void EditorSettings::load_text_editor_theme() { return; } - String theme_path = get_settings_path().plus_file("text_editor_themes").plus_file((String)get("text_editor/theme/color_theme") + ".tet"); + String theme_path = get_text_editor_themes_dir().plus_file((String)get("text_editor/theme/color_theme") + ".tet"); Ref<ConfigFile> cf = memnew(ConfigFile); Error err = cf->load(theme_path); @@ -1103,9 +1190,9 @@ bool EditorSettings::import_text_editor_theme(String p_file) { return false; } - DirAccess *d = DirAccess::open(get_settings_path().plus_file("text_editor_themes")); + DirAccess *d = DirAccess::open(get_text_editor_themes_dir()); if (d) { - d->copy(p_file, get_settings_path().plus_file("text_editor_themes").plus_file(p_file.get_file())); + d->copy(p_file, get_text_editor_themes_dir().plus_file(p_file.get_file())); memdelete(d); return true; } @@ -1120,7 +1207,7 @@ bool EditorSettings::save_text_editor_theme() { if (p_file.get_file().to_lower() == "default" || p_file.get_file().to_lower() == "adaptive") { return false; } - String theme_path = get_settings_path().plus_file("text_editor_themes").plus_file(p_file + ".tet"); + String theme_path = get_text_editor_themes_dir().plus_file(p_file + ".tet"); return _save_text_editor_theme(theme_path); } @@ -1138,7 +1225,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { list_text_editor_themes(); String theme_name = p_file.substr(0, p_file.length() - 4).get_file(); - if (p_file.get_base_dir() == get_settings_path().plus_file("text_editor_themes")) { + if (p_file.get_base_dir() == get_text_editor_themes_dir()) { _initial_set("text_editor/theme/color_theme", theme_name); load_text_editor_theme(); } @@ -1150,7 +1237,7 @@ bool EditorSettings::save_text_editor_theme_as(String p_file) { Vector<String> EditorSettings::get_script_templates(const String &p_extension) { Vector<String> templates; - DirAccess *d = DirAccess::open(get_settings_path().plus_file("script_templates")); + DirAccess *d = DirAccess::open(get_script_templates_dir()); if (d) { d->list_dir_begin(); String file = d->get_next(); @@ -1166,6 +1253,11 @@ Vector<String> EditorSettings::get_script_templates(const String &p_extension) { return templates; } +String EditorSettings::get_editor_layouts_config() const { + + return get_settings_dir().plus_file("editor_layouts.cfg"); +} + // Shortcuts void EditorSettings::add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut) { @@ -1272,8 +1364,8 @@ void EditorSettings::_bind_methods() { ClassDB::bind_method(D_METHOD("property_get_revert", "name"), &EditorSettings::property_get_revert); ClassDB::bind_method(D_METHOD("add_property_info", "info"), &EditorSettings::_add_property_info_bind); - ClassDB::bind_method(D_METHOD("get_settings_path"), &EditorSettings::get_settings_path); - ClassDB::bind_method(D_METHOD("get_project_settings_path"), &EditorSettings::get_project_settings_path); + ClassDB::bind_method(D_METHOD("get_settings_dir"), &EditorSettings::get_settings_dir); + ClassDB::bind_method(D_METHOD("get_project_settings_dir"), &EditorSettings::get_project_settings_dir); ClassDB::bind_method(D_METHOD("set_favorite_dirs", "dirs"), &EditorSettings::set_favorite_dirs); ClassDB::bind_method(D_METHOD("get_favorite_dirs"), &EditorSettings::get_favorite_dirs); diff --git a/editor/editor_settings.h b/editor/editor_settings.h index a74be6494a..f11f4dfd43 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -66,11 +66,13 @@ private: int order; Variant variant; Variant initial; + bool initial_set; bool hide_from_editor; bool save; VariantContainer() { order = 0; hide_from_editor = false; + initial_set = false; save = false; } VariantContainer(const Variant &p_variant, int p_order) { @@ -91,9 +93,11 @@ private: Map<String, Ref<ShortCut> > shortcuts; String resource_path; + String settings_dir; + String data_dir; + String cache_dir; String config_file_path; - String settings_path; - String project_config_path; + String project_config_dir; Vector<String> favorite_dirs; Vector<String> recent_dirs; @@ -128,6 +132,7 @@ public: static void destroy(); void set_optimize_save(bool p_optimize); + bool has_default_value(const String &p_setting) const; void set_setting(const String &p_setting, const Variant &p_value); Variant get_setting(const String &p_setting) const; bool has_setting(const String &p_setting) const; @@ -144,8 +149,13 @@ public: void set_resource_clipboard(const Ref<Resource> &p_resource) { clipboard = p_resource; } Ref<Resource> get_resource_clipboard() const { return clipboard; } - String get_settings_path() const; - String get_project_settings_path() const; + String get_data_dir() const; + String get_templates_dir() const; + String get_settings_dir() const; + String get_project_settings_dir() const; + String get_text_editor_themes_dir() const; + String get_script_templates_dir() const; + String get_cache_dir() const; void set_project_metadata(const String &p_section, const String &p_key, Variant p_data); Variant get_project_metadata(const String &p_section, const String &p_key, Variant p_default); @@ -163,6 +173,7 @@ public: bool save_text_editor_theme_as(String p_file); Vector<String> get_script_templates(const String &p_extension); + String get_editor_layouts_config() const; void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut); bool is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const; diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 29859a1a56..0f9f50095d 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -568,6 +568,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_constant("modulate_arrow", "OptionButton", true); // CheckButton + theme->set_stylebox("normal", "CheckButton", style_menu); + theme->set_stylebox("pressed", "CheckButton", style_menu); + theme->set_stylebox("disabled", "CheckButton", style_menu); + theme->set_stylebox("hover", "CheckButton", style_menu); + theme->set_icon("on", "CheckButton", theme->get_icon("GuiToggleOn", "EditorIcons")); theme->set_icon("off", "CheckButton", theme->get_icon("GuiToggleOff", "EditorIcons")); @@ -577,7 +582,22 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_color("font_color_disabled", "CheckButton", font_color_disabled); theme->set_color("icon_color_hover", "CheckButton", font_color_hl); + theme->set_constant("hseparation", "CheckButton", 4 * EDSCALE); + theme->set_constant("check_vadjust", "CheckButton", 0 * EDSCALE); + // Checkbox + Ref<StyleBoxFlat> sb_checkbox = style_menu->duplicate(); + // HACK, in reality, the checkbox draws the text over the icon by default, so the margin compensates that. + const int cb_w = theme->get_icon("GuiChecked", "EditorIcons")->get_width() + default_margin_size; + sb_checkbox->set_default_margin(MARGIN_LEFT, cb_w * EDSCALE); + sb_checkbox->set_default_margin(MARGIN_RIGHT, default_margin_size * EDSCALE); + sb_checkbox->set_default_margin(MARGIN_TOP, default_margin_size * EDSCALE); + sb_checkbox->set_default_margin(MARGIN_BOTTOM, default_margin_size * EDSCALE); + + theme->set_stylebox("normal", "CheckBox", sb_checkbox); + theme->set_stylebox("pressed", "CheckBox", sb_checkbox); + theme->set_stylebox("disabled", "CheckBox", sb_checkbox); + theme->set_stylebox("hover", "CheckBox", sb_checkbox); theme->set_icon("checked", "CheckBox", theme->get_icon("GuiChecked", "EditorIcons")); theme->set_icon("unchecked", "CheckBox", theme->get_icon("GuiUnchecked", "EditorIcons")); theme->set_icon("radio_checked", "CheckBox", theme->get_icon("GuiRadioChecked", "EditorIcons")); @@ -589,6 +609,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_color("font_color_disabled", "CheckBox", font_color_disabled); theme->set_color("icon_color_hover", "CheckBox", font_color_hl); + theme->set_constant("hseparation", "CheckBox", 4 * EDSCALE); + theme->set_constant("check_vadjust", "CheckBox", 0 * EDSCALE); + // PopupMenu Ref<StyleBoxFlat> style_popup_menu = style_popup; theme->set_stylebox("panel", "PopupMenu", style_popup_menu); @@ -801,6 +824,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_constant("close_h_ofs", "WindowDialog", 22 * EDSCALE); theme->set_constant("close_v_ofs", "WindowDialog", 20 * EDSCALE); theme->set_constant("title_height", "WindowDialog", 24 * EDSCALE); + theme->set_font("title_font", "WindowDialog", theme->get_font("title", "EditorFonts")); // complex window, for now only Editor settings and Project settings Ref<StyleBoxFlat> style_complex_window = style_window->duplicate(); @@ -1043,12 +1067,14 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { return theme; } -Ref<Theme> create_custom_theme() { +Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) { Ref<Theme> theme; String custom_theme = EditorSettings::get_singleton()->get("interface/theme/custom_theme"); if (custom_theme != "") { theme = ResourceLoader::load(custom_theme); + } else { + theme = create_editor_theme(p_theme); } String global_font = EditorSettings::get_singleton()->get("interface/editor/custom_font"); diff --git a/editor/editor_themes.h b/editor/editor_themes.h index a644c5936f..6f3b83e0b0 100644 --- a/editor/editor_themes.h +++ b/editor/editor_themes.h @@ -34,6 +34,6 @@ Ref<Theme> create_editor_theme(Ref<Theme> p_theme = NULL); -Ref<Theme> create_custom_theme(); +Ref<Theme> create_custom_theme(Ref<Theme> p_theme = NULL); #endif diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index 8641fc7667..d208bbe662 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -35,6 +35,7 @@ #include "io/zip_io.h" #include "os/dir_access.h" #include "version.h" + void ExportTemplateManager::_update_template_list() { while (current_hb->get_child_count()) { @@ -46,7 +47,7 @@ void ExportTemplateManager::_update_template_list() { } DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - Error err = d->change_dir(EditorSettings::get_singleton()->get_settings_path().plus_file("templates")); + Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir()); d->list_dir_begin(); Set<String> templates; @@ -66,7 +67,7 @@ void ExportTemplateManager::_update_template_list() { memdelete(d); - String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + _MKSTR(VERSION_STATUS) + VERSION_MODULE_CONFIG; + String current_version = itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR) + "-" + VERSION_STATUS + VERSION_MODULE_CONFIG; Label *current = memnew(Label); current->set_h_size_flags(SIZE_EXPAND_FILL); @@ -142,7 +143,7 @@ void ExportTemplateManager::_uninstall_template(const String &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")); + Error err = d->change_dir(EditorSettings::get_singleton()->get_templates_dir()); ERR_FAIL_COND(err != OK); @@ -244,7 +245,7 @@ void ExportTemplateManager::_install_from_file(const String &p_file) { return; } - String template_path = EditorSettings::get_singleton()->get_settings_path().plus_file("templates").plus_file(version); + String template_path = EditorSettings::get_singleton()->get_templates_dir().plus_file(version); DirAccess *d = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); Error err = d->make_dir_recursive(template_path); @@ -393,7 +394,7 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int if (p_code != 200) { template_list_state->set_text(TTR("Failed:") + " " + itos(p_code)); } else { - String path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_templates.tpz"); + String path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_templates.tpz"); FileAccess *f = FileAccess::open(path, FileAccess::WRITE); if (!f) { template_list_state->set_text(TTR("Can't write file.")); diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 00cbd9bb72..533401b317 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -333,7 +333,7 @@ void FileSystemDock::navigate_to_path(const String &p_path) { } else if (dirAccess->dir_exists(p_path)) { path = p_path; } else { - ERR_EXPLAIN(TTR("Cannot navigate to '" + p_path + "' as it has not been found in the file system!")); + ERR_EXPLAIN(vformat(TTR("Cannot navigate to '%s' as it has not been found in the file system!"), p_path)); ERR_FAIL(); } @@ -1186,78 +1186,36 @@ void FileSystemDock::set_display_mode(int p_mode) { } Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + bool is_favorite = false; + Vector<String> paths; if (p_from == tree) { - TreeItem *selected = tree->get_selected(); if (!selected) return Variant(); - String fpath = selected->get_metadata(0); - if (fpath == String()) + String folder = selected->get_metadata(0); + if (folder == String()) return Variant(); - if (!fpath.ends_with("/")) - fpath = fpath + "/"; - Vector<String> paths; - paths.push_back(fpath); - Dictionary d = EditorNode::get_singleton()->drag_files(paths, p_from); - - if (selected->get_parent() && tree->get_root()->get_children() == selected->get_parent()) { - //a favorite.. treat as such - d["type"] = "favorite"; - } - - return d; - } - - if (p_from == files) { - - List<int> seldirs; - List<int> selfiles; + paths.push_back(folder.ends_with("/") ? folder : (folder + "/")); + is_favorite = selected->get_parent() != NULL && tree->get_root()->get_children() == selected->get_parent(); + } else if (p_from == files) { for (int i = 0; i < files->get_item_count(); i++) { if (files->is_selected(i)) { - String fpath = files->get_item_metadata(i); - if (fpath.ends_with("/")) - seldirs.push_back(i); - else - selfiles.push_back(i); + paths.push_back(files->get_item_metadata(i)); } } + } - if (seldirs.empty() && selfiles.empty()) - return Variant(); - /* - if (seldirs.size() && selfiles.size()) - return Variant(); //can't really mix files and dirs (i think?) - yes you can, commenting - */ - - /*if (selfiles.size()==1) { - Ref<Resource> resource = ResourceLoader::load(files->get_item_metadata(selfiles.front()->get())); - if (resource.is_valid()) { - return EditorNode::get_singleton()->drag_resource(resource,p_from); - } - }*/ - - Vector<String> fnames; - if (selfiles.size() > 0 || seldirs.size() > 0) { - if (selfiles.size() > 0) { - for (List<int>::Element *E = selfiles.front(); E; E = E->next()) { - fnames.push_back(files->get_item_metadata(E->get())); - } - if (seldirs.size() == 0) - return EditorNode::get_singleton()->drag_files(fnames, p_from); - } + if (paths.empty()) + return Variant(); - for (List<int>::Element *E = seldirs.front(); E; E = E->next()) { - fnames.push_back(files->get_item_metadata(E->get())); - } - - return EditorNode::get_singleton()->drag_files_and_dirs(fnames, p_from); - } + Dictionary drag_data = EditorNode::get_singleton()->drag_files_and_dirs(paths, p_from); + if (is_favorite) { + drag_data["type"] = "favorite"; } - - return Variant(); + return drag_data; } bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { @@ -1288,36 +1246,25 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - return true; + String to_dir = _get_drag_target_folder(p_point, p_from); + return !to_dir.empty(); } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { + String to_dir = _get_drag_target_folder(p_point, p_from); + if (to_dir.empty()) + return false; + //Attempting to move a folder into itself will fail later + //Rather than bring up a message don't try to do it in the first place + to_dir = to_dir.ends_with("/") ? to_dir : (to_dir + "/"); Vector<String> fnames = drag_data["files"]; - - if (p_from == files) { - - int at_pos = files->get_item_at_position(p_point); - if (at_pos != -1) { - - String dir = files->get_item_metadata(at_pos); - if (dir.ends_with("/")) - return true; - } - } - - if (p_from == tree) { - - TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) - return false; - - String fpath = ti->get_metadata(0); - if (fpath == String()) + for (int i = 0; i < fnames.size(); ++i) { + if (fnames[i].ends_with("/") && to_dir.begins_with(fnames[i])) return false; - - return true; } + + return true; } return false; @@ -1393,66 +1340,16 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, if (drag_data.has("type") && String(drag_data["type"]) == "resource") { Ref<Resource> res = drag_data["resource"]; - - if (!res.is_valid()) { - return; - } - - if (p_from == tree) { - - TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) - return; - - String fpath = ti->get_metadata(0); - if (fpath == String()) - return; - - EditorNode::get_singleton()->save_resource_as(res, fpath); - return; - } - - if (p_from == files) { - String save_path = path; - - int at_pos = files->get_item_at_position(p_point); - if (at_pos != -1) { - String to_dir = files->get_item_metadata(at_pos); - if (to_dir.ends_with("/")) { - save_path = to_dir; - if (save_path != "res://") - save_path = save_path.substr(0, save_path.length() - 1); - } - } - - EditorNode::get_singleton()->save_resource_as(res, save_path); - return; + String to_dir = _get_drag_target_folder(p_point, p_from); + if (res.is_valid() && !to_dir.empty()) { + EditorNode::get_singleton()->push_item(res.ptr()); + EditorNode::get_singleton()->save_resource_as(res, to_dir); } } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { - - if (p_from == files || p_from == tree) { - - String to_dir; - - if (p_from == files) { - - int at_pos = files->get_item_at_position(p_point); - ERR_FAIL_COND(at_pos == -1); - to_dir = files->get_item_metadata(at_pos); - } else { - TreeItem *ti = tree->get_item_at_position(p_point); - if (!ti) - return; - to_dir = ti->get_metadata(0); - ERR_FAIL_COND(to_dir == String()); - } - - if (to_dir != "res://" && to_dir.ends_with("/")) { - to_dir = to_dir.substr(0, to_dir.length() - 1); - } - + String to_dir = _get_drag_target_folder(p_point, p_from); + if (!to_dir.empty()) { Vector<String> fnames = drag_data["files"]; to_move.clear(); for (int i = 0; i < fnames.size(); i++) { @@ -1463,6 +1360,25 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } } +String FileSystemDock::_get_drag_target_folder(const Point2 &p_point, Control *p_from) const { + if (p_from == files) { + int pos = files->get_item_at_position(p_point, true); + if (pos == -1) + return path; + + String target = files->get_item_metadata(pos); + return target.ends_with("/") ? target : path; + } + + if (p_from == tree) { + TreeItem *ti = tree->get_item_at_position(p_point); + if (ti && ti != tree->get_root()->get_children()) + return ti->get_metadata(0); + } + + return String(); +} + void FileSystemDock::_files_list_rmb_select(int p_item, const Vector2 &p_pos) { //Right clicking ".." should clear current selection @@ -1538,11 +1454,21 @@ void FileSystemDock::select_file(const String &p_file) { void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { - _file_selected(); + import_dock_needs_update = true; + call_deferred("_update_import_dock"); } void FileSystemDock::_file_selected() { + import_dock_needs_update = true; + _update_import_dock(); +} + +void FileSystemDock::_update_import_dock() { + + if (!import_dock_needs_update) + return; + //check import Vector<String> imports; String import_type; @@ -1582,6 +1508,8 @@ void FileSystemDock::_file_selected() { } else { EditorNode::get_singleton()->get_import_dock()->set_edit_multiple_paths(imports); } + + import_dock_needs_update = false; } void FileSystemDock::_bind_methods() { @@ -1618,6 +1546,7 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_preview_invalidated"), &FileSystemDock::_preview_invalidated); ClassDB::bind_method(D_METHOD("_file_selected"), &FileSystemDock::_file_selected); ClassDB::bind_method(D_METHOD("_file_multi_selected"), &FileSystemDock::_file_multi_selected); + ClassDB::bind_method(D_METHOD("_update_import_dock"), &FileSystemDock::_update_import_dock); ADD_SIGNAL(MethodInfo("instance", PropertyInfo(Variant::POOL_STRING_ARRAY, "files"))); ADD_SIGNAL(MethodInfo("open")); @@ -1789,6 +1718,7 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { updating_tree = false; initialized = false; + import_dock_needs_update = false; history_pos = 0; history_max_size = 20; diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 2cb0573a3d..d100de8b72 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -147,6 +147,7 @@ private: bool updating_tree; Tree *tree; //directories ItemList *files; + bool import_dock_needs_update; bool _create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths); void _update_tree(bool keep_collapse_state); @@ -161,6 +162,7 @@ private: void _select_file(int p_idx); void _file_multi_selected(int p_index, bool p_selected); + void _update_import_dock(); void _file_selected(); void _dir_selected(); @@ -209,6 +211,7 @@ private: Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + String _get_drag_target_folder(const Point2 &p_point, Control *p_from) const; void _preview_invalidated(const String &p_path); void _thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Variant &p_udata); diff --git a/editor/icons/icon_GUI_toggle_off.svg b/editor/icons/icon_GUI_toggle_off.svg index 0d43b158b5..aea0f85f96 100644 --- a/editor/icons/icon_GUI_toggle_off.svg +++ b/editor/icons/icon_GUI_toggle_off.svg @@ -1,5 +1,5 @@ -<svg width="64" height="32" version="1.1" viewBox="0 0 64 31.999998" xmlns="http://www.w3.org/2000/svg"> -<g transform="translate(0 -1020.4)"> -<path transform="translate(0 1020.4)" d="m24 4.002c-6.6307 0-12 5.3654-12 11.996v0.003906c0 6.6307 5.3693 12 12 12h16c6.6307 0 12-5.3693 12-12v-0.003906c0-6.6307-5.3693-11.996-12-11.996h-16zm0 2h16c5.5573 0 10 4.4388 10 9.9961v0.003906c0 5.5573-4.4427 10-10 10h-16c-5.5573 0-10-4.4427-10-10v-0.003906c0-5.5573 4.4427-9.9961 10-9.9961zm7 4.9961a1.0001 1.0001 0 0 0 -1 1v8a1 1 0 0 0 1 1 1 1 0 0 0 1 -1v-3h2a1 1 0 0 0 1 -1 1 1 0 0 0 -1 -1h-2v-2h4a1 1 0 0 0 1 -1 1 1 0 0 0 -1 -1h-5zm9 0a1.0001 1.0001 0 0 0 -1 1v4 4a1 1 0 0 0 1 1 1 1 0 0 0 1 -1v-3h2a1 1 0 0 0 1 -1 1 1 0 0 0 -1 -1h-2v-2h4a1 1 0 0 0 1 -1 1 1 0 0 0 -1 -1h-5zm-17 0.003906c-2.7496 0-5 2.2504-5 5s2.2504 5 5 5 5-2.2504 5-5-2.2504-5-5-5zm0 2c1.6687 0 3 1.3313 3 3s-1.3313 3-3 3-3-1.3313-3-3 1.3313-3 3-3z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#e0e0e0" fill-opacity=".78431" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="filter-blend-mode:normal;filter-gaussianBlur-deviation:0;font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/> +<svg width="42" height="26" version="1.1" viewBox="0 0 42 25.999998" xmlns="http://www.w3.org/2000/svg"> +<g transform="translate(0 -1026.4)"> +<path d="m13 1027.4c-6.6307 0-12 5.3663-12 11.998 0 6.6318 5.3693 12.002 12 12.002h16c6.6307 0 12-5.3702 12-12.002 0-6.6317-5.3693-11.998-12-11.998zm0 2.0003h16c5.5573 0 10 4.4395 10 9.9977 0 5.5583-4.4427 10.002-10 10.002h-16c-5.5573 0-10-4.4434-10-10.002 0-5.5582 4.4427-9.9977 10-9.9977zm7 4.9969a1.0001 1.0003 0 0 0 -1 1.0002v8.0013a1 1.0002 0 0 0 1 1.0002 1 1.0002 0 0 0 1 -1.0002v-3.0005h2a1 1.0002 0 0 0 1 -1.0002 1 1.0002 0 0 0 -1 -1.0001h-2v-2.0003h4a1 1.0002 0 0 0 1 -1.0002 1 1.0002 0 0 0 -1 -1.0002zm9 0a1.0001 1.0003 0 0 0 -1 1.0002v8.0013a1 1.0002 0 0 0 1 1.0002 1 1.0002 0 0 0 1 -1.0002v-3.0005h2a1 1.0002 0 0 0 1 -1.0002 1 1.0002 0 0 0 -1 -1.0001h-2v-2.0003h4a1 1.0002 0 0 0 1 -1.0002 1 1.0002 0 0 0 -1 -1.0002zm-17 0c-2.7496 0-5 2.2508-5 5.0008 0 2.7501 2.2504 5.0009 5 5.0009s5-2.2508 5-5.0009c0-2.75-2.2504-5.0008-5-5.0008zm0 2.0004c1.6687 0 3 1.3315 3 3.0004 0 1.669-1.3313 3.0005-3 3.0005s-3-1.3315-3-3.0005c0-1.6689 1.3313-3.0004 3-3.0004z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#e0e0e0" fill-opacity=".78431" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/> </g> </svg> diff --git a/editor/icons/icon_GUI_toggle_on.svg b/editor/icons/icon_GUI_toggle_on.svg index fd2b915fc3..c0a11810d4 100644 --- a/editor/icons/icon_GUI_toggle_on.svg +++ b/editor/icons/icon_GUI_toggle_on.svg @@ -1,5 +1,5 @@ -<svg width="64" height="32" version="1.1" viewBox="0 0 64 31.999998" xmlns="http://www.w3.org/2000/svg"> -<g transform="translate(0 -1020.4)"> -<path transform="translate(0 1020.4)" d="m24 4.002c-6.6307 0-12 5.3654-12 11.996 0 6.6307 5.3693 12 12 12h16c6.6307 0 12-5.3693 12-12 0-6.6307-5.3693-11.996-12-11.996h-16zm17 6.9961a1 1 0 0 1 1 1v8a1.0001 1.0001 0 0 1 -1.752 0.66211l-5.248-6v5.3379a1 1 0 0 1 -1 1 1 1 0 0 1 -1 -1v-8a1.0001 1.0001 0 0 1 1.752 -0.6582l5.248 6v-5.3418a1 1 0 0 1 1 -1zm-15 0.003906c2.7496 0 5 2.2504 5 5s-2.2504 5-5 5-5-2.2504-5-5 2.2504-5 5-5zm0 2c-1.6687 0-3 1.3313-3 3s1.3313 3 3 3 3-1.3313 3-3-1.3313-3-3-3z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#e0e0e0" fill-opacity=".78431" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-east-asian:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/> +<svg width="42" height="26" version="1.1" viewBox="0 0 42 25.999998" xmlns="http://www.w3.org/2000/svg"> +<g transform="translate(0 -1026.4)"> +<path d="m13 1027.4c-6.6307 0-12 5.3662-12 11.998s5.3693 12.002 12 12.002h16c6.6307 0 12-5.3702 12-12.002s-5.3693-11.998-12-11.998zm17 6.9972a1 1.0002 0 0 1 1 1.0001v8.0014a1.0001 1.0003 0 0 1 -1.752 0.6623l-5.248-6.001v5.3387a1 1.0002 0 0 1 -1 1.0001 1 1.0002 0 0 1 -1 -1.0001v-8.0014a1.0001 1.0003 0 0 1 1.752 -0.6583l5.248 6.001v-5.3427a1 1.0002 0 0 1 1 -1.0001zm-15 0c2.7496 0 5 2.2507 5 5.0008s-2.2504 5.0008-5 5.0008-5-2.2507-5-5.0008 2.2504-5.0008 5-5.0008zm0 2.0003c-1.6687 0-3 1.3315-3 3.0005s1.3313 3.0005 3 3.0005 3-1.3315 3-3.0005-1.3313-3.0005-3-3.0005z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#e0e0e0" fill-opacity=".78431" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/> </g> </svg> diff --git a/editor/icons/icon_texture_button.svg b/editor/icons/icon_texture_button.svg index 17f87ab861..19f5e8d5c9 100644 --- a/editor/icons/icon_texture_button.svg +++ b/editor/icons/icon_texture_button.svg @@ -1,7 +1,5 @@ <svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"> <g transform="translate(0 -1036.4)"> -<path transform="translate(0 1036.4)" d="m1 3v8h14v-8h-1-12-1zm8 2h1v1h1v2h1v2h-2-2-2-2v-1h1v-1h1v-1h2v-1h1v-1z" fill="#a5efac"/> -<rect transform="scale(1,-1)" x="1" y="-1049.4" width="14" height="2.0001" fill="#a5efac"/> -<rect transform="scale(1,-1)" x="1" y="-1049.4" width="14" height="2.0001" fill-opacity=".078431"/> +<path transform="translate(0 1036.4)" d="m8 1v2h6v10h-4v2h6v-14h-8zm-5 1v3.1328l-1.4453-0.96484-1.1094 1.6641 3 2c0.3359 0.2239 0.77347 0.2239 1.1094 0l3-2-1.1094-1.6641-1.4453 0.96484v-3.1328h-2zm7 4v1h-1v1h-1v1h1v2h2 2v-2h-1v-2h-1v-1h-1zm-7.5 4c-0.831 0-1.5 0.669-1.5 1.5v0.5 1h-1v2h8v-2h-1v-1-0.5c0-0.831-0.669-1.5-1.5-1.5h-3z" fill="#a5efac"/> </g> </svg> diff --git a/editor/icons/icon_texture_rect.svg b/editor/icons/icon_texture_rect.svg index 86d24ac223..2dbbe7f247 100644 --- a/editor/icons/icon_texture_rect.svg +++ b/editor/icons/icon_texture_rect.svg @@ -1,6 +1,5 @@ <svg width="16" height="16" version="1.1" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"> <g transform="translate(0 -1036.4)"> -<rect x="2" y="1038.4" width="12" height="12" fill="none" stroke="#a5efac" stroke-linecap="round" stroke-width="2"/> -<path d="m9 1042.4v1h-1v1h-2v1h-1v1h-1v1h2 2 2 2v-2h-1v-2h-1v-1h-1z" fill="#a5efac"/> +<path transform="translate(0 1036.4)" d="m1 1v14h14v-14h-14zm2 2h10v10h-10v-10zm6 3v1h-1v1h-2v1h-1v1h-1v1h2 2 2 2v-2h-1v-2h-1v-1h-1z" color="#000000" color-rendering="auto" dominant-baseline="auto" fill="#a5efac" image-rendering="auto" shape-rendering="auto" solid-color="#000000" style="font-feature-settings:normal;font-variant-alternates:normal;font-variant-caps:normal;font-variant-ligatures:normal;font-variant-numeric:normal;font-variant-position:normal;isolation:auto;mix-blend-mode:normal;shape-padding:0;text-decoration-color:#000000;text-decoration-line:none;text-decoration-style:solid;text-indent:0;text-orientation:mixed;text-transform:none;white-space:normal"/> </g> </svg> diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index 831eb74b66..397bb6ad68 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -1,5 +1,6 @@ #include "editor_scene_importer_gltf.h" #include "io/json.h" +#include "math_defs.h" #include "os/file_access.h" #include "os/os.h" #include "scene/3d/camera.h" @@ -1378,8 +1379,8 @@ Error EditorSceneImporterGLTF::_parse_skins(GLTFState &state) { state.nodes[skin_node]->skeleton_children.push_back(i); } - state.skins.push_back(skin); } + state.skins.push_back(skin); } print_line("total skins: " + itos(state.skins.size())); @@ -1419,7 +1420,8 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { camera.perspective = true; if (d.has("perspective")) { Dictionary ppt = d["perspective"]; - camera.fov_size = ppt["yfov"]; + // GLTF spec is in radians, Godot's camera is in degrees. + camera.fov_size = (double)ppt["yfov"] * 180.0 / Math_PI; camera.zfar = ppt["zfar"]; camera.znear = ppt["znear"]; } else { diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 4541c77085..bd24aac99b 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -413,6 +413,7 @@ Node *EditorOBJImporter::import_scene(const String &p_path, uint32_t p_flags, in for (List<Ref<Mesh> >::Element *E = meshes.front(); E; E = E->next()) { MeshInstance *mi = memnew(MeshInstance); + mi->set_mesh(E->get()); mi->set_name(E->get()->get_name()); scene->add_child(mi); mi->set_owner(scene); diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 660db9ac27..cbc21c9536 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -232,16 +232,26 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array } } - if (_teststr(name, "colonly")) { + if (_teststr(name, "colonly") || _teststr(name, "convcolonly")) { if (isroot) return p_node; MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); if (mi) { - Node *col = mi->create_trimesh_collision_node(); - ERR_FAIL_COND_V(!col, NULL); + Node *col; + + if (_teststr(name, "colonly")) { + col = mi->create_trimesh_collision_node(); + ERR_FAIL_COND_V(!col, NULL); + + col->set_name(_fixstr(name, "colonly")); + } else { + col = mi->create_convex_collision_node(); + ERR_FAIL_COND_V(!col, NULL); + + col->set_name(_fixstr(name, "convcolonly")); + } - col->set_name(_fixstr(name, "colonly")); Object::cast_to<Spatial>(col)->set_transform(mi->get_transform()); p_node->replace_by(col); memdelete(p_node); @@ -292,7 +302,7 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array // get mesh instance and bounding box MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); - Rect3 aabb = mi->get_aabb(); + AABB aabb = mi->get_aabb(); // create a new rigid body collision node RigidBody *rigid_body = memnew(RigidBody); @@ -328,15 +338,25 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array rb->add_child(colshape); colshape->set_owner(p_node->get_owner()); - } else if (_teststr(name, "col") && Object::cast_to<MeshInstance>(p_node)) { + } else if ((_teststr(name, "col") || (_teststr(name, "convcol"))) && Object::cast_to<MeshInstance>(p_node)) { MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); + Node *col; - mi->set_name(_fixstr(name, "col")); - Node *col = mi->create_trimesh_collision_node(); - ERR_FAIL_COND_V(!col, NULL); + if (_teststr(name, "col")) { + mi->set_name(_fixstr(name, "col")); + col = mi->create_trimesh_collision_node(); + ERR_FAIL_COND_V(!col, NULL); + + col->set_name("col"); + } else { + mi->set_name(_fixstr(name, "convcol")); + col = mi->create_convex_collision_node(); + ERR_FAIL_COND_V(!col, NULL); + + col->set_name("convcol"); + } - col->set_name("col"); p_node->add_child(col); StaticBody *sb = Object::cast_to<StaticBody>(col); @@ -527,26 +547,55 @@ Node *ResourceImporterScene::_fix_node(Node *p_node, Node *p_root, Map<Ref<Array #endif } else if (Object::cast_to<MeshInstance>(p_node)) { - //last attempt, maybe collision insde the mesh data + //last attempt, maybe collision inside the mesh data MeshInstance *mi = Object::cast_to<MeshInstance>(p_node); Ref<ArrayMesh> mesh = mi->get_mesh(); if (!mesh.is_null()) { - if (_teststr(mesh->get_name(), "col")) { - - mesh->set_name(_fixstr(mesh->get_name(), "col")); + if (_teststr(mesh->get_name(), "col") || _teststr(mesh->get_name(), "convcol")) { Ref<Shape> shape; + if (_teststr(mesh->get_name(), "col")) { + mesh->set_name(_fixstr(mesh->get_name(), "col")); + + if (collision_map.has(mesh)) { + shape = collision_map[mesh]; + + } else { + + shape = mesh->create_trimesh_shape(); + if (!shape.is_null()) + collision_map[mesh] = shape; + } + } else if (_teststr(mesh->get_name(), "convcol")) { + mesh->set_name(_fixstr(mesh->get_name(), "convcol")); + + if (collision_map.has(mesh)) { + shape = collision_map[mesh]; + + } else { + + shape = mesh->create_convex_shape(); + if (!shape.is_null()) + collision_map[mesh] = shape; + } + } - if (collision_map.has(mesh)) { - shape = collision_map[mesh]; + if (!shape.is_null()) { + StaticBody *col = memnew(StaticBody); + CollisionShape *cshape = memnew(CollisionShape); + cshape->set_shape(shape); + col->add_child(cshape); - } else { + col->set_transform(mi->get_transform()); + col->set_name(mi->get_name()); + p_node->replace_by(col); + memdelete(p_node); + p_node = col; - shape = mesh->create_trimesh_shape(); - if (!shape.is_null()) - collision_map[mesh] = shape; + cshape->set_name("shape"); + cshape->set_owner(p_node->get_owner()); } } } diff --git a/editor/import_dock.cpp b/editor/import_dock.cpp index 77fd6d883a..84d55b4d14 100644 --- a/editor/import_dock.cpp +++ b/editor/import_dock.cpp @@ -87,23 +87,7 @@ void ImportDock::set_edit_path(const String &p_path) { return; } - List<ResourceImporter::ImportOption> options; - params->importer->get_import_options(&options); - - params->properties.clear(); - params->values.clear(); - - for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { - - params->properties.push_back(E->get().option); - if (config->has_section_key("params", E->get().option.name)) { - params->values[E->get().option.name] = config->get_value("params", E->get().option.name); - } else { - params->values[E->get().option.name] = E->get().default_value; - } - } - - params->update(); + _update_options(config); List<Ref<ResourceImporter> > importers; ResourceFormatImporter::get_singleton()->get_importers_for_extension(p_path.get_extension(), &importers); @@ -125,6 +109,34 @@ void ImportDock::set_edit_path(const String &p_path) { } } + params->paths.clear(); + params->paths.push_back(p_path); + import->set_disabled(false); + import_as->set_disabled(false); + + imported->set_text(p_path.get_file()); +} + +void ImportDock::_update_options(const Ref<ConfigFile> &p_config) { + + List<ResourceImporter::ImportOption> options; + params->importer->get_import_options(&options); + + params->properties.clear(); + params->values.clear(); + + for (List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { + + params->properties.push_back(E->get().option); + if (p_config.is_valid() && p_config->has_section_key("params", E->get().option.name)) { + params->values[E->get().option.name] = p_config->get_value("params", E->get().option.name); + } else { + params->values[E->get().option.name] = E->get().default_value; + } + } + + params->update(); + preset->get_popup()->clear(); if (params->importer->get_preset_count() == 0) { @@ -142,13 +154,6 @@ void ImportDock::set_edit_path(const String &p_path) { preset->get_popup()->add_separator(); preset->get_popup()->add_item(vformat(TTR("Clear Default for '%s'"), params->importer->get_visible_name()), ITEM_CLEAR_DEFAULT); } - - params->paths.clear(); - params->paths.push_back(p_path); - import->set_disabled(false); - import_as->set_disabled(false); - - imported->set_text(p_path.get_file()); } void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { @@ -263,6 +268,24 @@ void ImportDock::set_edit_multiple_paths(const Vector<String> &p_paths) { imported->set_text(itos(p_paths.size()) + TTR(" Files")); } +void ImportDock::_importer_selected(int i_idx) { + String name = import_as->get_selected_metadata(); + Ref<ResourceImporter> importer = ResourceFormatImporter::get_singleton()->get_importer_by_name(name); + ERR_FAIL_COND(importer.is_null()); + + params->importer = importer; + + Ref<ConfigFile> config; + if (params->paths.size()) { + config.instance(); + Error err = config->load(params->paths[0] + ".import"); + if (err != OK) { + config.unref(); + } + } + _update_options(config); +} + void ImportDock::_preset_selected(int p_idx) { int item_id = preset->get_popup()->get_item_id(p_idx); @@ -336,6 +359,7 @@ void ImportDock::_reimport() { Error err = config->load(params->paths[i] + ".import"); ERR_CONTINUE(err != OK); + config->set_value("remap", "importer", params->importer->get_importer_name()); config->erase_section("params"); for (List<PropertyInfo>::Element *E = params->properties.front(); E; E = E->next()) { @@ -356,12 +380,18 @@ void ImportDock::_notification(int p_what) { imported->add_style_override("normal", get_stylebox("normal", "LineEdit")); } break; + + case NOTIFICATION_ENTER_TREE: { + + import_opts->edit(params); + } break; } } void ImportDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_reimport"), &ImportDock::_reimport); ClassDB::bind_method(D_METHOD("_preset_selected"), &ImportDock::_preset_selected); + ClassDB::bind_method(D_METHOD("_importer_selected"), &ImportDock::_importer_selected); } void ImportDock::initialize_import_options() const { @@ -379,6 +409,7 @@ ImportDock::ImportDock() { HBoxContainer *hb = memnew(HBoxContainer); add_margin_child(TTR("Import As:"), hb); import_as = memnew(OptionButton); + import_as->connect("item_selected", this, "_importer_selected"); hb->add_child(import_as); import_as->set_h_size_flags(SIZE_EXPAND_FILL); preset = memnew(MenuButton); diff --git a/editor/import_dock.h b/editor/import_dock.h index 029c458320..28c29e4b20 100644 --- a/editor/import_dock.h +++ b/editor/import_dock.h @@ -54,6 +54,8 @@ class ImportDock : public VBoxContainer { ImportDockParameters *params; void _preset_selected(int p_idx); + void _importer_selected(int i_idx); + void _update_options(const Ref<ConfigFile> &p_config = Ref<ConfigFile>()); void _reimport(); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index f2f913d2b3..736e176ab8 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -563,6 +563,14 @@ void AbstractPolygon2DEditor::forward_draw_over_canvas(Control *p_canvas) { const Vector2 next_point = xform.xform(p2); vpc->draw_line(point, next_point, col, 2); } + } + + for (int i = 0; i < n_points; i++) { + + const Vertex vertex(j, i); + + const Vector2 p = (vertex == edited_point) ? edited_point.pos : (points[i] + offset); + const Vector2 point = xform.xform(p); Ref<Texture> handle = vertex == active_point ? selected_handle : default_handle; vpc->draw_texture(handle, point - handle->get_size() * 0.5); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index cd53264437..b63352389e 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -33,6 +33,8 @@ #include "editor_settings.h" #include "io/json.h" +#include "version_generated.gen.h" + void EditorAssetLibraryItem::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, int p_rating, const String &p_cost) { title->set_text(p_title); @@ -45,9 +47,9 @@ void EditorAssetLibraryItem::configure(const String &p_title, int p_asset_id, co for (int i = 0; i < 5; i++) { if (i < p_rating) - stars[i]->set_texture(get_icon("RatingStar", "EditorIcons")); + stars[i]->set_texture(get_icon("Favorites", "EditorIcons")); else - stars[i]->set_texture(get_icon("RatingNoStar", "EditorIcons")); + stars[i]->set_texture(get_icon("NonFavorite", "EditorIcons")); } } @@ -271,15 +273,15 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { HBoxContainer *hbox = memnew(HBoxContainer); vbox->add_child(hbox); - vbox->add_constant_override("separation", 15); + vbox->add_constant_override("separation", 15 * EDSCALE); VBoxContainer *desc_vbox = memnew(VBoxContainer); hbox->add_child(desc_vbox); - hbox->add_constant_override("separation", 15); + hbox->add_constant_override("separation", 15 * EDSCALE); item = memnew(EditorAssetLibraryItem); desc_vbox->add_child(item); - desc_vbox->set_custom_minimum_size(Size2(300, 0)); + desc_vbox->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); desc_bg = memnew(PanelContainer); desc_vbox->add_child(desc_bg); @@ -290,12 +292,12 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { desc_bg->add_child(description); preview = memnew(TextureRect); - preview->set_custom_minimum_size(Size2(640, 345)); + preview->set_custom_minimum_size(Size2(640 * EDSCALE, 345 * EDSCALE)); hbox->add_child(preview); previews_bg = memnew(PanelContainer); vbox->add_child(previews_bg); - previews_bg->set_custom_minimum_size(Size2(0, 85)); + previews_bg->set_custom_minimum_size(Size2(0, 101 * EDSCALE)); previews = memnew(ScrollContainer); previews_bg->add_child(previews); @@ -443,7 +445,7 @@ void EditorAssetLibraryItemDownload::_install() { void EditorAssetLibraryItemDownload::_make_request() { download->cancel_request(); - download->set_download_file(EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("tmp_asset_" + itos(asset_id)) + ".zip"); + download->set_download_file(EditorSettings::get_singleton()->get_cache_dir().plus_file("tmp_asset_" + itos(asset_id)) + ".zip"); Error err = download->request(host); if (err != OK) { @@ -678,7 +680,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt PoolByteArray image_data = p_data; if (use_cache) { - String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); + String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); FileAccess *file = FileAccess::open(cache_filename_base + ".data", FileAccess::READ); @@ -700,15 +702,28 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt Ref<Image> image = Ref<Image>(memnew(Image(r.ptr(), len))); if (!image->empty()) { - float max_height = 10000; switch (image_queue[p_queue_id].image_type) { - case IMAGE_QUEUE_ICON: max_height = 80; break; - case IMAGE_QUEUE_THUMBNAIL: max_height = 80; break; - case IMAGE_QUEUE_SCREENSHOT: max_height = 345; break; - } - float scale_ratio = max_height / image->get_height(); - if (scale_ratio < 1) { - image->resize(image->get_width() * scale_ratio, image->get_height() * scale_ratio, Image::INTERPOLATE_CUBIC); + case IMAGE_QUEUE_ICON: + + image->resize(80 * EDSCALE, 80 * EDSCALE, Image::INTERPOLATE_CUBIC); + + break; + case IMAGE_QUEUE_THUMBNAIL: { + float max_height = 85 * EDSCALE; + + float scale_ratio = max_height / (image->get_height() * EDSCALE); + if (scale_ratio < 1) { + image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_CUBIC); + } + } break; + case IMAGE_QUEUE_SCREENSHOT: { + float max_height = 397 * EDSCALE; + + float scale_ratio = max_height / (image->get_height() * EDSCALE); + if (scale_ratio < 1) { + image->resize(image->get_width() * EDSCALE * scale_ratio, image->get_height() * EDSCALE * scale_ratio, Image::INTERPOLATE_CUBIC); + } + } break; } Ref<ImageTexture> tex; @@ -736,7 +751,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons if (p_code != HTTPClient::RESPONSE_NOT_MODIFIED) { for (int i = 0; i < headers.size(); i++) { if (headers[i].findn("ETag:") == 0) { // Save etag - String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); + String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + image_queue[p_queue_id].image_url.md5_text()); String new_etag = headers[i].substr(headers[i].find(":") + 1, headers[i].length()).strip_edges(); FileAccess *file; @@ -784,7 +799,7 @@ void EditorAssetLibrary::_update_image_queue() { for (Map<int, ImageQueue>::Element *E = image_queue.front(); E; E = E->next()) { if (!E->get().active && current_images < max_images) { - String cache_filename_base = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp").plus_file("assetimage_" + E->get().image_url.md5_text()); + String cache_filename_base = EditorSettings::get_singleton()->get_cache_dir().plus_file("assetimage_" + E->get().image_url.md5_text()); Vector<String> headers; if (FileAccess::exists(cache_filename_base + ".etag") && FileAccess::exists(cache_filename_base + ".data")) { @@ -867,6 +882,8 @@ void EditorAssetLibrary::_search(int p_page) { } args += String() + "sort=" + sort_key[sort->get_selected()]; + args += "&godot_version=" + itos(VERSION_MAJOR) + "." + itos(VERSION_MINOR); + String support_list; for (int i = 0; i < SUPPORT_MAX; i++) { if (support->get_popup()->is_item_checked(i)) { @@ -1348,13 +1365,11 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { search_hb2->add_child(memnew(Label(TTR("Site:") + " "))); repository = memnew(OptionButton); - // FIXME: Reenable me once GH-7147 is fixed. - /* repository->add_item("godotengine.org"); repository->set_item_metadata(0, "https://godotengine.org/asset-library/api"); - */ repository->add_item("localhost"); - repository->set_item_metadata(/*1*/ 0, "http://127.0.0.1/asset-library/api"); + repository->set_item_metadata(1, "http://127.0.0.1/asset-library/api"); + repository->connect("item_selected", this, "_repository_changed"); search_hb2->add_child(repository); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 3807c8961a..b6ba09fb58 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -176,9 +176,9 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) { for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Node2D *n2d = Object::cast_to<Node2D>(E->get()); - if (n2d && n2d->edit_has_pivot()) { + if (n2d && n2d->_edit_use_pivot()) { - Vector2 offset = n2d->edit_get_pivot(); + Vector2 offset = n2d->_edit_get_pivot(); Vector2 gpos = n2d->get_global_position(); Vector2 local_mouse_pos = n2d->get_canvas_transform().affine_inverse().xform(mouse_pos); @@ -186,9 +186,9 @@ void CanvasItemEditor::_edit_set_pivot(const Vector2 &mouse_pos) { Vector2 motion_ofs = gpos - local_mouse_pos; undo_redo->add_do_method(n2d, "set_global_position", local_mouse_pos); - undo_redo->add_do_method(n2d, "edit_set_pivot", offset + n2d->get_global_transform().affine_inverse().basis_xform(motion_ofs)); + undo_redo->add_do_method(n2d, "_edit_set_pivot", offset + n2d->get_global_transform().affine_inverse().basis_xform(motion_ofs)); undo_redo->add_undo_method(n2d, "set_global_position", gpos); - undo_redo->add_undo_method(n2d, "edit_set_pivot", offset); + undo_redo->add_undo_method(n2d, "_edit_set_pivot", offset); for (int i = 0; i < n2d->get_child_count(); i++) { Node2D *n2dc = Object::cast_to<Node2D>(n2d->get_child(i)); if (!n2dc) @@ -249,8 +249,8 @@ void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap, Transform2D ci_transform = canvas_item->get_global_transform_with_canvas(); Transform2D to_snap_transform = p_to_snap ? p_to_snap->get_global_transform_with_canvas() : Transform2D(); if (fmod(ci_transform.get_rotation() - to_snap_transform.get_rotation(), (real_t)360.0) == 0.0) { - Point2 begin = ci_transform.xform(canvas_item->get_item_rect().get_position()); - Point2 end = ci_transform.xform(canvas_item->get_item_rect().get_position() + canvas_item->get_item_rect().get_size()); + Point2 begin = ci_transform.xform(canvas_item->_edit_get_rect().get_position()); + Point2 end = ci_transform.xform(canvas_item->_edit_get_rect().get_position() + canvas_item->_edit_get_rect().get_size()); _snap_if_closer_point(p_value, begin, r_current_snap, r_snapped, ci_transform.get_rotation()); _snap_if_closer_point(p_value, end, r_current_snap, r_snapped, ci_transform.get_rotation()); @@ -282,8 +282,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); can_snap = true; } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_canvas_item->get_parent())) { - begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->get_item_rect().get_position()); - end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->get_item_rect().get_position() + parent_ci->get_item_rect().get_size()); + begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); + end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); can_snap = true; } @@ -306,8 +306,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const // Self sides (for anchors) if ((snap_active && snap_node_sides && (p_modes & SNAP_NODE_SIDES)) || (p_forced_modes & SNAP_NODE_SIDES)) { - begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->get_item_rect().get_position()); - end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->get_item_rect().get_position() + p_canvas_item->get_item_rect().get_size()); + begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position()); + end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size()); _snap_if_closer_point(p_target, begin, output, snapped, rotation); _snap_if_closer_point(p_target, end, output, snapped, rotation); } @@ -629,7 +629,7 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) { - Rect2 rect = c->get_item_rect(); + Rect2 rect = c->_edit_get_rect(); Point2 local_pos = (p_parent_xform * p_canvas_xform * c->get_transform()).affine_inverse().xform(p_pos); if (rect.has_point(local_pos)) { @@ -675,7 +675,7 @@ void CanvasItemEditor::_find_canvas_items_at_rect(const Rect2 &p_rect, Node *p_n if (c && c->is_visible_in_tree() && !c->has_meta("_edit_lock_") && !Object::cast_to<CanvasLayer>(c)) { - Rect2 rect = c->get_item_rect(); + Rect2 rect = c->_edit_get_rect(); Transform2D xform = p_parent_xform * p_canvas_xform * c->get_transform(); if (p_rect.has_point(xform.xform(rect.position)) && @@ -767,15 +767,15 @@ void CanvasItemEditor::_key_move(const Vector2 &p_dir, bool p_snap, KeyMoveMODE if (p_snap) drag *= grid_step * Math::pow(2.0, grid_step_multiplier); - undo_redo->add_undo_method(canvas_item, "edit_set_state", canvas_item->edit_get_state()); + undo_redo->add_undo_method(canvas_item, "_edit_set_state", canvas_item->_edit_get_state()); if (p_move_mode == MOVE_VIEW_BASE) { // drag = transform.affine_inverse().basis_xform(p_dir); // zoom sensitive drag = canvas_item->get_global_transform_with_canvas().affine_inverse().basis_xform(drag); - Rect2 local_rect = canvas_item->get_item_rect(); + Rect2 local_rect = canvas_item->_edit_get_rect(); local_rect.position += drag; - undo_redo->add_do_method(canvas_item, "edit_set_rect", local_rect); + undo_redo->add_do_method(canvas_item, "_edit_set_rect", local_rect); } else { // p_move_mode==MOVE_LOCAL_BASE || p_move_mode==MOVE_LOCAL_WITH_ROT @@ -816,7 +816,7 @@ Point2 CanvasItemEditor::_find_topleftmost_point() { if (canvas_item->get_viewport() != EditorNode::get_singleton()->get_scene_root()) continue; - Rect2 rect = canvas_item->get_item_rect(); + Rect2 rect = canvas_item->_edit_get_rect(); Transform2D xform = canvas_item->get_global_transform_with_canvas(); r2.expand_to(xform.xform(rect.position)); @@ -877,7 +877,7 @@ CanvasItemEditor::DragType CanvasItemEditor::_get_resize_handle_drag_type(const ERR_FAIL_COND_V(!canvas_item, DRAG_NONE); - Rect2 rect = canvas_item->get_item_rect(); + Rect2 rect = canvas_item->_edit_get_rect(); Transform2D xforml = canvas_item->get_global_transform_with_canvas(); Transform2D xform = transform * xforml; @@ -1011,14 +1011,14 @@ void CanvasItemEditor::_prepare_drag(const Point2 &p_click_pos) { if (!se) continue; - se->undo_state = canvas_item->edit_get_state(); + se->undo_state = canvas_item->_edit_get_state(); if (Object::cast_to<Node2D>(canvas_item)) - se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot(); + se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset(); se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); - se->pre_drag_rect = canvas_item->get_item_rect(); + se->pre_drag_rect = canvas_item->_edit_get_rect(); } if (selection.size() == 1 && Object::cast_to<Node2D>(selection[0]) && bone_ik_list.size() == 0) { @@ -1500,7 +1500,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { // Cancel a drag if (bone_ik_list.size()) { for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) { - E->get().node->edit_set_state(E->get().orig_state); + E->get().node->_edit_set_state(E->get().orig_state); } bone_ik_list.clear(); @@ -1519,9 +1519,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { if (!se) continue; - canvas_item->edit_set_state(se->undo_state); + canvas_item->_edit_set_state(se->undo_state); if (Object::cast_to<Node2D>(canvas_item)) - Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot); + Object::cast_to<Node2D>(canvas_item)->_edit_set_pivot(se->undo_pivot); if (Object::cast_to<Control>(canvas_item)) Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot); } @@ -1574,8 +1574,8 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { for (List<BoneIK>::Element *E = bone_ik_list.back(); E; E = E->prev()) { - undo_redo->add_do_method(E->get().node, "edit_set_state", E->get().node->edit_get_state()); - undo_redo->add_undo_method(E->get().node, "edit_set_state", E->get().orig_state); + undo_redo->add_do_method(E->get().node, "_edit_set_state", E->get().node->_edit_get_state()); + undo_redo->add_undo_method(E->get().node, "_edit_set_state", E->get().orig_state); } undo_redo->add_do_method(viewport, "update"); @@ -1601,14 +1601,14 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { if (!se) continue; - Variant state = canvas_item->edit_get_state(); - undo_redo->add_do_method(canvas_item, "edit_set_state", state); - undo_redo->add_undo_method(canvas_item, "edit_set_state", se->undo_state); + Variant state = canvas_item->_edit_get_state(); + undo_redo->add_do_method(canvas_item, "_edit_set_state", state); + undo_redo->add_undo_method(canvas_item, "_edit_set_state", se->undo_state); { Node2D *pvt = Object::cast_to<Node2D>(canvas_item); - if (pvt && pvt->edit_has_pivot()) { - undo_redo->add_do_method(canvas_item, "edit_set_pivot", pvt->edit_get_pivot()); - undo_redo->add_undo_method(canvas_item, "edit_set_pivot", se->undo_pivot); + if (pvt && pvt->_edit_use_pivot()) { + undo_redo->add_do_method(canvas_item, "_edit_set_pivot", pvt->_edit_get_pivot()); + undo_redo->add_undo_method(canvas_item, "_edit_set_pivot", se->undo_pivot); } Control *cnt = Object::cast_to<Control>(canvas_item); @@ -1709,7 +1709,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { BoneIK bik; bik.node = b; bik.len = len; - bik.orig_state = b->edit_get_state(); + bik.orig_state = b->_edit_get_state(); bone_ik_list.push_back(bik); @@ -1741,13 +1741,13 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { if ((b->get_control() && tool == TOOL_SELECT) || tool == TOOL_ROTATE) { drag = DRAG_ROTATE; drag_from = transform.affine_inverse().xform(click); - se->undo_state = canvas_item->edit_get_state(); + se->undo_state = canvas_item->_edit_get_state(); if (Object::cast_to<Node2D>(canvas_item)) - se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot(); + se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset(); se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); - se->pre_drag_rect = canvas_item->get_item_rect(); + se->pre_drag_rect = canvas_item->_edit_get_rect(); return; } @@ -1764,13 +1764,13 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { drag = _get_resize_handle_drag_type(click, drag_point_from); if (drag != DRAG_NONE) { drag_from = transform.affine_inverse().xform(click); - se->undo_state = canvas_item->edit_get_state(); + se->undo_state = canvas_item->_edit_get_state(); if (Object::cast_to<Node2D>(canvas_item)) - se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->edit_get_pivot(); + se->undo_pivot = Object::cast_to<Node2D>(canvas_item)->_edit_get_pivot(); if (Object::cast_to<Control>(canvas_item)) se->undo_pivot = Object::cast_to<Control>(canvas_item)->get_pivot_offset(); se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); - se->pre_drag_rect = canvas_item->get_item_rect(); + se->pre_drag_rect = canvas_item->_edit_get_rect(); return; } @@ -1780,9 +1780,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { drag = _get_anchor_handle_drag_type(click, drag_point_from); if (drag != DRAG_NONE) { drag_from = transform.affine_inverse().xform(click); - se->undo_state = canvas_item->edit_get_state(); + se->undo_state = canvas_item->_edit_get_state(); se->pre_drag_xform = canvas_item->get_global_transform_with_canvas(); - se->pre_drag_rect = canvas_item->get_item_rect(); + se->pre_drag_rect = canvas_item->_edit_get_rect(); return; } } @@ -1890,9 +1890,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { bool dragging_bone = drag == DRAG_ALL && selection.size() == 1 && bone_ik_list.size(); if (!dragging_bone) { - canvas_item->edit_set_state(se->undo_state); //reset state and reapply + canvas_item->_edit_set_state(se->undo_state); //reset state and reapply if (Object::cast_to<Node2D>(canvas_item)) - Object::cast_to<Node2D>(canvas_item)->edit_set_pivot(se->undo_pivot); + Object::cast_to<Node2D>(canvas_item)->_edit_set_pivot(se->undo_pivot); if (Object::cast_to<Control>(canvas_item)) Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot); } @@ -2003,10 +2003,10 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dto) - canvas_item->get_global_transform_with_canvas().affine_inverse().xform(dfrom); - Rect2 local_rect = canvas_item->get_item_rect(); + Rect2 local_rect = canvas_item->_edit_get_rect(); Vector2 begin = local_rect.position; Vector2 end = local_rect.position + local_rect.size; - Vector2 minsize = canvas_item->edit_get_minimum_size(); + Vector2 minsize = canvas_item->_edit_get_minimum_size(); if (uniform) { // Keep the height/width ratio of the item @@ -2084,7 +2084,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { if (Object::cast_to<Node2D>(canvas_item)) { Node2D *n2d = Object::cast_to<Node2D>(canvas_item); - n2d->edit_set_pivot(se->undo_pivot + drag_vector); + n2d->_edit_set_pivot(se->undo_pivot + drag_vector); } if (Object::cast_to<Control>(canvas_item)) { Object::cast_to<Control>(canvas_item)->set_pivot_offset(se->undo_pivot + drag_vector); @@ -2103,7 +2103,7 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { local_rect.position = begin; local_rect.size = end - begin; - canvas_item->edit_set_rect(local_rect); + canvas_item->_edit_set_rect(local_rect); } else { //ok, all that had to be done was done, now solve IK @@ -2454,7 +2454,7 @@ void CanvasItemEditor::_draw_selection() { if (!se) continue; - Rect2 rect = canvas_item->get_item_rect(); + Rect2 rect = canvas_item->_edit_get_rect(); if (show_helpers && drag != DRAG_NONE && drag != DRAG_PIVOT) { const Transform2D pre_drag_xform = transform * se->pre_drag_xform; @@ -2496,7 +2496,7 @@ void CanvasItemEditor::_draw_selection() { Node2D *node2d = Object::cast_to<Node2D>(canvas_item); if (node2d) { - if (node2d->edit_has_pivot()) { + if (node2d->_edit_use_pivot()) { viewport->draw_texture(pivot_icon, xform.get_origin() + (-pivot_icon->get_size() / 2).floor()); can_move_pivot = true; pivot_found = true; @@ -2868,7 +2868,7 @@ void CanvasItemEditor::_get_encompassing_rect(Node *p_node, Rect2 &r_rect, const CanvasItem *c = Object::cast_to<CanvasItem>(p_node); if (c && c->is_visible_in_tree()) { - Rect2 rect = c->get_item_rect(); + Rect2 rect = c->_edit_get_rect(); Transform2D xform = p_xform * c->get_transform(); r_rect.expand_to(xform.xform(rect.position)); r_rect.expand_to(xform.xform(rect.position + Point2(rect.size.x, 0))); @@ -2963,7 +2963,7 @@ void CanvasItemEditor::_notification(int p_what) { if (!se) continue; - Rect2 r = canvas_item->get_item_rect(); + Rect2 r = canvas_item->_edit_get_rect(); Transform2D xform = canvas_item->get_transform(); if (r != se->prev_rect || xform != se->prev_xform) { @@ -3623,7 +3623,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (key_pos) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "position", n2d->get_position(), existing); if (key_rot) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "rotation_deg", Math::rad2deg(n2d->get_rotation()), existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "rotation_degrees", Math::rad2deg(n2d->get_rotation()), existing); if (key_scale) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(n2d, "scale", n2d->get_scale(), existing); @@ -3654,7 +3654,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (key_pos) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "position", F->get()->get_position(), existing); if (key_rot) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "rotation_deg", Math::rad2deg(F->get()->get_rotation()), existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "rotation_degrees", Math::rad2deg(F->get()->get_rotation()), existing); if (key_scale) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(F->get(), "scale", F->get()->get_scale(), existing); } @@ -3668,7 +3668,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { if (key_pos) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_position", ctrl->get_position(), existing); if (key_rot) - AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_deg(), existing); + AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_rotation", ctrl->get_rotation_degrees(), existing); if (key_scale) AnimationPlayerEditor::singleton->get_key_editor()->insert_node_value_key(ctrl, "rect_size", ctrl->get_size(), existing); } @@ -3899,7 +3899,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { //if (!canvas_item->is_visible_in_tree()) continue; ++count; - Rect2 item_rect = canvas_item->get_item_rect(); + Rect2 item_rect = canvas_item->_edit_get_rect(); Vector2 pos = canvas_item->get_global_transform().get_origin(); Vector2 scale = canvas_item->get_global_transform().get_scale(); @@ -4373,11 +4373,11 @@ void CanvasItemEditorViewport::_on_mouse_exit() { void CanvasItemEditorViewport::_on_select_type(Object *selected) { CheckBox *check = Object::cast_to<CheckBox>(selected); String type = check->get_text(); - selector_label->set_text(vformat(TTR("Add %s"), type)); + selector->set_title(vformat(TTR("Add %s"), type)); label->set_text(vformat(TTR("Adding %s..."), type)); } -void CanvasItemEditorViewport::_on_change_type() { +void CanvasItemEditorViewport::_on_change_type_confirmed() { if (!button_group->get_pressed_button()) return; @@ -4387,6 +4387,11 @@ void CanvasItemEditorViewport::_on_change_type() { selector->hide(); } +void CanvasItemEditorViewport::_on_change_type_closed() { + + _remove_preview(); +} + void CanvasItemEditorViewport::_create_preview(const Vector<String> &files) const { label->set_position(get_global_position() + Point2(14, 14) * EDSCALE); label_desc->set_position(label->get_position() + Point2(0, label->get_size().height)); @@ -4698,7 +4703,7 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]); check->set_pressed(check->get_text() == default_type); } - selector_label->set_text(vformat(TTR("Add %s"), default_type)); + selector->set_title(vformat(TTR("Add %s"), default_type)); selector->popup_centered_minsize(); } else { _perform_drop_data(); @@ -4721,7 +4726,8 @@ void CanvasItemEditorViewport::_notification(int p_what) { void CanvasItemEditorViewport::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_select_type"), &CanvasItemEditorViewport::_on_select_type); - ClassDB::bind_method(D_METHOD("_on_change_type"), &CanvasItemEditorViewport::_on_change_type); + ClassDB::bind_method(D_METHOD("_on_change_type_confirmed"), &CanvasItemEditorViewport::_on_change_type_confirmed); + ClassDB::bind_method(D_METHOD("_on_change_type_closed"), &CanvasItemEditorViewport::_on_change_type_closed); ClassDB::bind_method(D_METHOD("_on_mouse_exit"), &CanvasItemEditorViewport::_on_mouse_exit); } @@ -4749,7 +4755,8 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte selector = memnew(AcceptDialog); editor->get_gui_base()->add_child(selector); selector->set_title(TTR("Change default type")); - selector->connect("confirmed", this, "_on_change_type"); + selector->connect("confirmed", this, "_on_change_type_confirmed"); + selector->connect("popup_hide", this, "_on_change_type_closed"); VBoxContainer *vbc = memnew(VBoxContainer); selector->add_child(vbc); @@ -4757,12 +4764,6 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte vbc->set_v_size_flags(SIZE_EXPAND_FILL); vbc->set_custom_minimum_size(Size2(200, 260) * EDSCALE); - selector_label = memnew(Label); - vbc->add_child(selector_label); - selector_label->set_align(Label::ALIGN_CENTER); - selector_label->set_valign(Label::VALIGN_BOTTOM); - selector_label->set_custom_minimum_size(Size2(0, 30) * EDSCALE); - btn_group = memnew(VBoxContainer); vbc->add_child(btn_group); btn_group->set_h_size_flags(0); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 97e3b03569..457833e1a7 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -568,7 +568,8 @@ class CanvasItemEditorViewport : public Control { void _on_mouse_exit(); void _on_select_type(Object *selected); - void _on_change_type(); + void _on_change_type_confirmed(); + void _on_change_type_closed(); void _create_preview(const Vector<String> &files) const; void _remove_preview(); diff --git a/editor/plugins/collision_polygon_editor_plugin.cpp b/editor/plugins/collision_polygon_editor_plugin.cpp index 24c4813771..0818c8975e 100644 --- a/editor/plugins/collision_polygon_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_editor_plugin.cpp @@ -389,7 +389,7 @@ void CollisionPolygonEditor::_polygon_draw() { rect = rect.grow(1); - Rect3 r; + AABB r; r.position.x = rect.position.x; r.position.y = rect.position.y; r.position.z = depth; diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index c48a241e4d..ed04c90cc5 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -184,7 +184,7 @@ Ref<Texture> EditorPackedScenePreviewPlugin::generate(const RES &p_from) { Ref<Texture> EditorPackedScenePreviewPlugin::generate_from_path(const String &p_path) { - String temp_path = EditorSettings::get_singleton()->get_settings_path().plus_file("tmp"); + String temp_path = EditorSettings::get_singleton()->get_cache_dir(); String cache_base = ProjectSettings::get_singleton()->globalize_path(p_path).md5_text(); cache_base = temp_path.plus_file("resthumb-" + cache_base); @@ -278,11 +278,11 @@ EditorMaterialPreviewPlugin::EditorMaterialPreviewPlugin() { VS::get_singleton()->camera_set_transform(camera, Transform(Basis(), Vector3(0, 0, 3))); VS::get_singleton()->camera_set_perspective(camera, 45, 0.1, 10); - light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + light = VS::get_singleton()->directional_light_create(); light_instance = VS::get_singleton()->instance_create2(light, scenario); VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); - light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + light2 = VS::get_singleton()->directional_light_create(); VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); //VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); @@ -790,13 +790,13 @@ Ref<Texture> EditorMeshPreviewPlugin::generate(const RES &p_from) { VS::get_singleton()->instance_set_base(mesh_instance, mesh->get_rid()); - Rect3 aabb = mesh->get_aabb(); + AABB aabb = mesh->get_aabb(); Vector3 ofs = aabb.position + aabb.size * 0.5; aabb.position -= ofs; Transform xform; xform.basis = Basis().rotated(Vector3(0, 1, 0), -Math_PI * 0.125); xform.basis = Basis().rotated(Vector3(1, 0, 0), Math_PI * 0.125) * xform.basis; - Rect3 rot_aabb = xform.xform(aabb); + AABB rot_aabb = xform.xform(aabb); float m = MAX(rot_aabb.size.x, rot_aabb.size.y) * 0.5; if (m == 0) return Ref<Texture>(); @@ -850,11 +850,11 @@ EditorMeshPreviewPlugin::EditorMeshPreviewPlugin() { //VS::get_singleton()->camera_set_perspective(camera,45,0.1,10); VS::get_singleton()->camera_set_orthogonal(camera, 1.0, 0.01, 1000.0); - light = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + light = VS::get_singleton()->directional_light_create(); light_instance = VS::get_singleton()->instance_create2(light, scenario); VS::get_singleton()->instance_set_transform(light_instance, Transform().looking_at(Vector3(-1, -1, -1), Vector3(0, 1, 0))); - light2 = VS::get_singleton()->light_create(VS::LIGHT_DIRECTIONAL); + light2 = VS::get_singleton()->directional_light_create(); VS::get_singleton()->light_set_color(light2, Color(0.7, 0.7, 0.7)); //VS::get_singleton()->light_set_color(light2, VS::LIGHT_COLOR_SPECULAR, Color(0.0, 0.0, 0.0)); light_instance2 = VS::get_singleton()->instance_create2(light2, scenario); diff --git a/editor/plugins/material_editor_plugin.cpp b/editor/plugins/material_editor_plugin.cpp index bd4891ccb7..1fc112896d 100644 --- a/editor/plugins/material_editor_plugin.cpp +++ b/editor/plugins/material_editor_plugin.cpp @@ -503,3 +503,41 @@ Ref<Resource> ParticlesMaterialConversionPlugin::convert(const Ref<Resource> &p_ smat->set_render_priority(mat->get_render_priority()); return smat; } + +String CanvasItemMaterialConversionPlugin::converts_to() const { + + return "ShaderMaterial"; +} +bool CanvasItemMaterialConversionPlugin::handles(const Ref<Resource> &p_resource) const { + + Ref<CanvasItemMaterial> mat = p_resource; + return mat.is_valid(); +} +Ref<Resource> CanvasItemMaterialConversionPlugin::convert(const Ref<Resource> &p_resource) { + + Ref<CanvasItemMaterial> mat = p_resource; + ERR_FAIL_COND_V(!mat.is_valid(), Ref<Resource>()); + + Ref<ShaderMaterial> smat; + smat.instance(); + + Ref<Shader> shader; + shader.instance(); + + String code = VS::get_singleton()->shader_get_code(mat->get_shader_rid()); + + shader->set_code(code); + + smat->set_shader(shader); + + List<PropertyInfo> params; + VS::get_singleton()->shader_get_param_list(mat->get_shader_rid(), ¶ms); + + for (List<PropertyInfo>::Element *E = params.front(); E; E = E->next()) { + Variant value = VS::get_singleton()->material_get_param(mat->get_rid(), E->get().name); + smat->set_shader_param(E->get().name, value); + } + + smat->set_render_priority(mat->get_render_priority()); + return smat; +} diff --git a/editor/plugins/material_editor_plugin.h b/editor/plugins/material_editor_plugin.h index 52c73cb7d8..2cc24be33a 100644 --- a/editor/plugins/material_editor_plugin.h +++ b/editor/plugins/material_editor_plugin.h @@ -119,4 +119,12 @@ public: virtual Ref<Resource> convert(const Ref<Resource> &p_resource); }; +class CanvasItemMaterialConversionPlugin : public EditorResourceConversionPlugin { + GDCLASS(CanvasItemMaterialConversionPlugin, EditorResourceConversionPlugin) +public: + virtual String converts_to() const; + virtual bool handles(const Ref<Resource> &p_resource) const; + virtual Ref<Resource> convert(const Ref<Resource> &p_resource); +}; + #endif // MATERIAL_EDITOR_PLUGIN_H diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 74618aecc2..60e8858b2d 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -95,7 +95,7 @@ void MeshEditor::edit(Ref<Mesh> p_mesh) { rot_y = 0; _update_rotation(); - Rect3 aabb = mesh->get_aabb(); + AABB aabb = mesh->get_aabb(); print_line("aabb: " + aabb); Vector3 ofs = aabb.position + aabb.size * 0.5; float m = aabb.get_longest_axis_size(); diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 10834b74ff..f4a9960087 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -153,15 +153,15 @@ void ParticlesEditor::_generate_aabb() { EditorProgress ep("gen_aabb", TTR("Generating AABB"), int(time)); - Rect3 rect; + AABB rect; while (running < time) { uint64_t ticks = OS::get_singleton()->get_ticks_usec(); ep.step("Generating..", int(running), true); OS::get_singleton()->delay_usec(1000); - Rect3 capture = node->capture_aabb(); - if (rect == Rect3()) + AABB capture = node->capture_aabb(); + if (rect == AABB()) rect = capture; else rect.merge_with(capture); @@ -247,7 +247,7 @@ void ParticlesEditor::_generate_emission_points() { PoolVector<Face3>::Read r = geometry.read(); - Rect3 aabb; + AABB aabb; for (int i = 0; i < gcount; i++) { diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index d421b3798b..3210af1433 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -43,7 +43,7 @@ void ResourcePreloaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_icon("Folder", "EditorIcons")); - _delete->set_icon(get_icon("Del", "EditorIcons")); + _delete->set_icon(get_icon("Remove", "EditorIcons")); } if (p_what == NOTIFICATION_READY) { diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index a1183307fb..32ec9b2ba9 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -586,6 +586,32 @@ void ScriptEditor::_close_docs_tab() { } } +void ScriptEditor::_close_other_tabs() { + + int child_count = tab_container->get_child_count(); + int current_idx = tab_container->get_current_tab(); + for (int i = child_count - 1; i >= 0; i--) { + + if (i == current_idx) { + continue; + } + + tab_container->set_current_tab(i); + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); + + if (se) { + + // Maybe there are unsaved changes + if (se->is_unsaved()) { + _ask_close_current_unsaved_tab(se); + continue; + } + } + + _close_current_tab(); + } +} + void ScriptEditor::_close_all_tabs() { int child_count = tab_container->get_child_count(); @@ -855,7 +881,7 @@ void ScriptEditor::_menu_option(int p_option) { file_dialog_option = FILE_SAVE_THEME_AS; file_dialog->clear_filters(); file_dialog->add_filter("*.tet"); - file_dialog->set_current_path(EditorSettings::get_singleton()->get_settings_path() + "/text_editor_themes/" + EditorSettings::get_singleton()->get("text_editor/theme/color_theme")); + file_dialog->set_current_path(EditorSettings::get_singleton()->get_text_editor_themes_dir().plus_file(EditorSettings::get_singleton()->get("text_editor/theme/color_theme"))); file_dialog->popup_centered_ratio(); file_dialog->set_title(TTR("Save Theme As..")); } break; @@ -865,20 +891,7 @@ void ScriptEditor::_menu_option(int p_option) { } break; case SEARCH_CLASSES: { - String current; - - if (tab_container->get_tab_count() > 0) { - EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(tab_container->get_current_tab())); - if (eh) { - current = eh->get_class(); - } - } - help_index->popup(); - - if (current != "") { - help_index->call_deferred("select_class", current); - } } break; case SEARCH_WEBSITE: { @@ -890,8 +903,13 @@ void ScriptEditor::_menu_option(int p_option) { _history_forward(); } break; case WINDOW_PREV: { + _history_back(); } break; + case WINDOW_SORT: { + _sort_list_on_update = true; + _update_script_names(); + } break; case DEBUG_SHOW: { if (debugger) { bool visible = debug_menu->get_popup()->is_item_checked(debug_menu->get_popup()->get_item_index(DEBUG_SHOW)); @@ -926,10 +944,6 @@ void ScriptEditor::_menu_option(int p_option) { if (current) { switch (p_option) { - case FILE_NEW: { - script_create_dialog->config("Node", ".gd"); - script_create_dialog->popup_centered(Size2(300, 300) * EDSCALE); - } break; case FILE_SAVE: { if (_test_script_times_on_disk()) @@ -1015,6 +1029,9 @@ void ScriptEditor::_menu_option(int p_option) { case CLOSE_DOCS: { _close_docs_tab(); } break; + case CLOSE_OTHER_TABS: { + _close_other_tabs(); + } break; case CLOSE_ALL: { _close_all_tabs(); } break; @@ -1041,26 +1058,22 @@ void ScriptEditor::_menu_option(int p_option) { debugger->debug_continue(); } break; - case WINDOW_MOVE_LEFT: { + case WINDOW_MOVE_UP: { if (tab_container->get_current_tab() > 0) { - tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() - 1); - script_list->call_deferred("select", tab_container->get_current_tab() - 1); tab_container->move_child(current, tab_container->get_current_tab() - 1); + tab_container->set_current_tab(tab_container->get_current_tab() - 1); _update_script_names(); } } break; - case WINDOW_MOVE_RIGHT: { + case WINDOW_MOVE_DOWN: { if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) { - tab_container->call_deferred("set_current_tab", tab_container->get_current_tab() + 1); - script_list->call_deferred("select", tab_container->get_current_tab() + 1); tab_container->move_child(current, tab_container->get_current_tab() + 1); + tab_container->set_current_tab(tab_container->get_current_tab() + 1); _update_script_names(); } - } break; - default: { if (p_option >= WINDOW_SELECT_BASE) { @@ -1077,6 +1090,11 @@ void ScriptEditor::_menu_option(int p_option) { switch (p_option) { + case SEARCH_CLASSES: { + + help_index->popup(); + help_index->call_deferred("select_class", help->get_class()); + } break; case HELP_SEARCH_FIND: { help->popup_search(); } break; @@ -1089,9 +1107,28 @@ void ScriptEditor::_menu_option(int p_option) { case CLOSE_DOCS: { _close_docs_tab(); } break; + case CLOSE_OTHER_TABS: { + _close_other_tabs(); + } break; case CLOSE_ALL: { _close_all_tabs(); } break; + case WINDOW_MOVE_UP: { + + if (tab_container->get_current_tab() > 0) { + tab_container->move_child(help, tab_container->get_current_tab() - 1); + tab_container->set_current_tab(tab_container->get_current_tab() - 1); + _update_script_names(); + } + } break; + case WINDOW_MOVE_DOWN: { + + if (tab_container->get_current_tab() < tab_container->get_child_count() - 1) { + tab_container->move_child(help, tab_container->get_current_tab() + 1); + tab_container->set_current_tab(tab_container->get_current_tab() + 1); + _update_script_names(); + } + } break; } } } @@ -1114,6 +1151,7 @@ void ScriptEditor::_notification(int p_what) { editor->connect("script_add_function_request", this, "_add_callback"); editor->connect("resource_saved", this, "_res_saved_callback"); script_list->connect("item_selected", this, "_script_selected"); + members_overview->connect("item_selected", this, "_members_overview_selected"); help_overview->connect("item_selected", this, "_help_overview_selected"); script_split->connect("dragged", this, "_script_split_dragged"); @@ -1361,6 +1399,7 @@ struct _ScriptEditorItemData { String tooltip; bool used; int category; + Node *ref; bool operator<(const _ScriptEditorItemData &id) const { @@ -1526,6 +1565,7 @@ void ScriptEditor::_update_script_names() { sd.index = i; sd.used = used.has(se->get_edited_script()); sd.category = 0; + sd.ref = se; switch (sort_by) { case SORT_BY_NAME: { @@ -1565,16 +1605,38 @@ void ScriptEditor::_update_script_names() { _ScriptEditorItemData sd; sd.icon = icon; sd.name = name; - sd.sort_key = name; + sd.sort_key = name.to_lower(); sd.tooltip = tooltip; sd.index = i; sd.used = false; sd.category = split_script_help ? 1 : 0; + sd.ref = eh; + sedata.push_back(sd); } } - sedata.sort(); + if (_sort_list_on_update && !sedata.empty()) { + sedata.sort(); + + // change actual order of tab_container so that the order can be rearranged by user + int cur_tab = tab_container->get_current_tab(); + int prev_tab = tab_container->get_previous_tab(); + int new_cur_tab = -1; + int new_prev_tab = -1; + for (int i = 0; i < sedata.size(); i++) { + tab_container->move_child(sedata[i].ref, i); + if (new_prev_tab == -1 && sedata[i].index == prev_tab) { + new_prev_tab = i; + } + if (new_cur_tab == -1 && sedata[i].index == cur_tab) { + new_cur_tab = i; + } + } + tab_container->call_deferred("set_current_tab", new_prev_tab); + tab_container->call_deferred("set_current_tab", new_cur_tab); + _sort_list_on_update = false; + } for (int i = 0; i < sedata.size(); i++) { @@ -1903,8 +1965,171 @@ void ScriptEditor::_script_split_dragged(float) { _save_layout(); } +Variant ScriptEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + + // return Variant(); // return this if drag disabled + + Node *cur_node = tab_container->get_child(tab_container->get_current_tab()); + + HBoxContainer *drag_preview = memnew(HBoxContainer); + String preview_name = ""; + Ref<Texture> preview_icon; + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(cur_node); + if (se) { + preview_name = se->get_name(); + preview_icon = se->get_icon(); + } + EditorHelp *eh = Object::cast_to<EditorHelp>(cur_node); + if (eh) { + preview_name = eh->get_class(); + preview_icon = get_icon("Help", "EditorIcons"); + } + + if (!preview_icon.is_null()) { + TextureRect *tf = memnew(TextureRect); + tf->set_texture(preview_icon); + drag_preview->add_child(tf); + } + Label *label = memnew(Label(preview_name)); + drag_preview->add_child(label); + set_drag_preview(drag_preview); + + Dictionary drag_data; + drag_data["type"] = "script_list_element"; // using a custom type because node caused problems when dragging to scene tree + drag_data["script_list_element"] = cur_node; + + return drag_data; +} + +bool ScriptEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { + + Dictionary d = p_data; + if (!d.has("type")) + return false; + + if (String(d["type"]) == "script_list_element") { + + Node *node = d["script_list_element"]; + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); + if (se) { + return true; + } + EditorHelp *eh = Object::cast_to<EditorHelp>(node); + if (eh) { + return true; + } + } + + if (String(d["type"]) == "nodes") { + + Array nodes = d["nodes"]; + if (nodes.size() == 0) + return false; + Node *node = get_node((nodes[0])); + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); + if (se) { + return true; + } + EditorHelp *eh = Object::cast_to<EditorHelp>(node); + if (eh) { + return true; + } + } + + if (String(d["type"]) == "files") { + + Vector<String> files = d["files"]; + + if (files.size() == 0) + return false; //weird + + for (int i = 0; i < files.size(); i++) { + String file = files[i]; + if (file == "" || !FileAccess::exists(file)) + continue; + Ref<Script> scr = ResourceLoader::load(file); + if (scr.is_valid()) { + return true; + } + } + return true; + } + + return false; +} + +void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { + + if (!can_drop_data_fw(p_point, p_data, p_from)) + return; + + Dictionary d = p_data; + if (!d.has("type")) + return; + + if (String(d["type"]) == "script_list_element") { + + Node *node = d["script_list_element"]; + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); + EditorHelp *eh = Object::cast_to<EditorHelp>(node); + if (se || eh) { + int new_index = script_list->get_item_at_position(p_point); + tab_container->move_child(node, new_index); + tab_container->set_current_tab(new_index); + _update_script_names(); + } + } + + if (String(d["type"]) == "nodes") { + + Array nodes = d["nodes"]; + if (nodes.size() == 0) + return; + Node *node = get_node(nodes[0]); + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(node); + EditorHelp *eh = Object::cast_to<EditorHelp>(node); + if (se || eh) { + int new_index = script_list->get_item_at_position(p_point); + tab_container->move_child(node, new_index); + tab_container->set_current_tab(new_index); + _update_script_names(); + } + } + + if (String(d["type"]) == "files") { + + Vector<String> files = d["files"]; + + int new_index = script_list->get_item_at_position(p_point); + int num_tabs_before = tab_container->get_child_count(); + for (int i = 0; i < files.size(); i++) { + String file = files[i]; + if (file == "" || !FileAccess::exists(file)) + continue; + Ref<Script> scr = ResourceLoader::load(file); + if (scr.is_valid()) { + edit(scr); + if (tab_container->get_child_count() > num_tabs_before) { + tab_container->move_child(tab_container->get_child(tab_container->get_child_count() - 1), new_index); + num_tabs_before = tab_container->get_child_count(); + } else { + tab_container->move_child(tab_container->get_child(tab_container->get_current_tab()), new_index); + } + } + } + tab_container->set_current_tab(new_index); + _update_script_names(); + } +} + void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) { - if (p_event->is_pressed() || !is_visible_in_tree()) return; + if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) + return; if (ED_IS_SHORTCUT("script_editor/next_script", p_event)) { int next_tab = script_list->get_current() + 1; next_tab %= script_list->get_item_count(); @@ -1917,6 +2142,64 @@ void ScriptEditor::_unhandled_input(const Ref<InputEvent> &p_event) { _go_to_tab(script_list->get_item_metadata(next_tab)); _update_script_names(); } + if (ED_IS_SHORTCUT("script_editor/window_move_up", p_event)) { + _menu_option(WINDOW_MOVE_UP); + } + if (ED_IS_SHORTCUT("script_editor/window_move_down", p_event)) { + _menu_option(WINDOW_MOVE_DOWN); + } +} + +void ScriptEditor::_script_list_gui_input(const Ref<InputEvent> &ev) { + + Ref<InputEventMouseButton> mb = ev; + if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { + + _make_script_list_context_menu(); + } +} + +void ScriptEditor::_make_script_list_context_menu() { + + context_menu->clear(); + + int selected = tab_container->get_current_tab(); + if (selected < 0 || selected >= tab_container->get_child_count()) + return; + + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(selected)); + if (se) { + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save"), FILE_SAVE); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/save_as"), FILE_SAVE_AS); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_all"), CLOSE_ALL); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_other_tabs"), CLOSE_OTHER_TABS); + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/reload_script_soft"), FILE_TOOL_RELOAD_SOFT); + + Ref<Script> scr = se->get_edited_script(); + if (!scr.is_null() && scr->is_tool()) { + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/run_file"), FILE_RUN); + } + } else { + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/close_file"), FILE_CLOSE); + } + + EditorHelp *eh = Object::cast_to<EditorHelp>(tab_container->get_child(selected)); + if (eh) { + // nothing + } + + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_up"), WINDOW_MOVE_UP); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_move_down"), WINDOW_MOVE_DOWN); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/window_sort"), WINDOW_SORT); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_editor/toggle_scripts_panel"), TOGGLE_SCRIPTS_PANEL); + + context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); + context_menu->set_size(Vector2(1, 1)); + context_menu->popup(); } void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { @@ -2210,6 +2493,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_close_discard_current_tab", &ScriptEditor::_close_discard_current_tab); ClassDB::bind_method("_close_docs_tab", &ScriptEditor::_close_docs_tab); ClassDB::bind_method("_close_all_tabs", &ScriptEditor::_close_all_tabs); + ClassDB::bind_method("_close_other_tabs", &ScriptEditor::_close_other_tabs); ClassDB::bind_method("_open_recent_script", &ScriptEditor::_open_recent_script); ClassDB::bind_method("_editor_play", &ScriptEditor::_editor_play); ClassDB::bind_method("_editor_pause", &ScriptEditor::_editor_pause); @@ -2243,9 +2527,14 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_history_back", &ScriptEditor::_history_back); ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts); ClassDB::bind_method("_unhandled_input", &ScriptEditor::_unhandled_input); + ClassDB::bind_method("_script_list_gui_input", &ScriptEditor::_script_list_gui_input); ClassDB::bind_method("_script_changed", &ScriptEditor::_script_changed); ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts); + ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &ScriptEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &ScriptEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("drop_data_fw"), &ScriptEditor::drop_data_fw); + ClassDB::bind_method(D_METHOD("get_current_script"), &ScriptEditor::_get_current_script); ClassDB::bind_method(D_METHOD("get_open_scripts"), &ScriptEditor::_get_open_scripts); @@ -2286,6 +2575,14 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { script_list->set_v_size_flags(SIZE_EXPAND_FILL); script_split->set_split_offset(140); //list_split->set_split_offset(500); + _sort_list_on_update = true; + script_list->connect("gui_input", this, "_script_list_gui_input"); + script_list->set_allow_rmb_select(true); + script_list->set_drag_forwarding(this); + + context_menu = memnew(PopupMenu); + add_child(context_menu); + context_menu->connect("id_pressed", this, "_menu_option"); members_overview = memnew(ItemList); list_split->add_child(members_overview); @@ -2303,8 +2600,11 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { tab_container->set_h_size_flags(SIZE_EXPAND_FILL); - ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_GREATER); - ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_LESS); + ED_SHORTCUT("script_editor/window_sort", TTR("Sort")); + ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP); + ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); + ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work + ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COLON); set_process_unhandled_input(true); file_menu = memnew(MenuButton); @@ -2339,6 +2639,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_other_tabs", TTR("Close Other Tabs")), CLOSE_OTHER_TABS); file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN); file_menu->get_popup()->add_separator(); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 03fc4da7ce..77ca4bc9d9 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -135,6 +135,7 @@ class ScriptEditor : public PanelContainer { FILE_CLOSE, CLOSE_DOCS, CLOSE_ALL, + CLOSE_OTHER_TABS, TOGGLE_SCRIPTS_PANEL, FILE_TOOL_RELOAD, FILE_TOOL_RELOAD_SOFT, @@ -150,10 +151,11 @@ class ScriptEditor : public PanelContainer { SEARCH_WEBSITE, HELP_SEARCH_FIND, HELP_SEARCH_FIND_NEXT, - WINDOW_MOVE_LEFT, - WINDOW_MOVE_RIGHT, + WINDOW_MOVE_UP, + WINDOW_MOVE_DOWN, WINDOW_NEXT, WINDOW_PREV, + WINDOW_SORT, WINDOW_SELECT_BASE = 100 }; @@ -173,6 +175,7 @@ class ScriptEditor : public PanelContainer { MenuButton *edit_menu; MenuButton *script_search_menu; MenuButton *debug_menu; + PopupMenu *context_menu; Timer *autosave_timer; uint64_t idle; @@ -249,6 +252,7 @@ class ScriptEditor : public PanelContainer { void _close_current_tab(); void _close_discard_current_tab(const String &p_str); void _close_docs_tab(); + void _close_other_tabs(); void _close_all_tabs(); void _ask_close_current_unsaved_tab(ScriptEditorBase *current); @@ -292,6 +296,7 @@ class ScriptEditor : public PanelContainer { void _update_members_overview_visibility(); void _update_members_overview(); void _update_script_names(); + bool _sort_list_on_update; void _members_overview_selected(int p_idx); void _script_selected(int p_idx); @@ -306,8 +311,15 @@ class ScriptEditor : public PanelContainer { void _script_split_dragged(float); + Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); + bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; + void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _unhandled_input(const Ref<InputEvent> &p_event); + void _script_list_gui_input(const Ref<InputEvent> &ev); + void _make_script_list_context_menu(); + void _help_search(String p_text); void _help_index(String p_text); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index adf65c11e1..214f24b386 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -201,7 +201,7 @@ void ScriptTextEditor::_set_theme_for_script() { text_edit->add_keyword_color("Rect2", basetype_color); text_edit->add_keyword_color("Transform2D", basetype_color); text_edit->add_keyword_color("Vector3", basetype_color); - text_edit->add_keyword_color("Rect3", basetype_color); + text_edit->add_keyword_color("AABB", basetype_color); text_edit->add_keyword_color("Basis", basetype_color); text_edit->add_keyword_color("Plane", basetype_color); text_edit->add_keyword_color("Transform", basetype_color); @@ -518,7 +518,9 @@ void ScriptTextEditor::tag_saved_version() { } void ScriptTextEditor::goto_line(int p_line, bool p_with_error) { - code_editor->get_text_edit()->call_deferred("cursor_set_line", p_line); + TextEdit *tx = code_editor->get_text_edit(); + tx->unfold_line(p_line); + tx->call_deferred("cursor_set_line", p_line); } void ScriptTextEditor::ensure_focus() { @@ -712,15 +714,6 @@ void ScriptTextEditor::_breakpoint_toggled(int p_row) { ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(script->get_path(), p_row + 1, code_editor->get_text_edit()->is_line_set_as_breakpoint(p_row)); } -static void swap_lines(TextEdit *tx, int line1, int line2) { - String tmp = tx->get_line(line1); - String tmp2 = tx->get_line(line2); - tx->set_line(line2, tmp); - tx->set_line(line1, tmp2); - - tx->cursor_set_line(line2); -} - void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_column) { Node *base = get_tree()->get_edited_scene_root(); @@ -799,39 +792,41 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c void ScriptTextEditor::_edit_option(int p_op) { + TextEdit *tx = code_editor->get_text_edit(); + switch (p_op) { case EDIT_UNDO: { - code_editor->get_text_edit()->undo(); - code_editor->get_text_edit()->call_deferred("grab_focus"); + + tx->undo(); + tx->call_deferred("grab_focus"); } break; case EDIT_REDO: { - code_editor->get_text_edit()->redo(); - code_editor->get_text_edit()->call_deferred("grab_focus"); + + tx->redo(); + tx->call_deferred("grab_focus"); } break; case EDIT_CUT: { - code_editor->get_text_edit()->cut(); - code_editor->get_text_edit()->call_deferred("grab_focus"); + tx->cut(); + tx->call_deferred("grab_focus"); } break; case EDIT_COPY: { - code_editor->get_text_edit()->copy(); - code_editor->get_text_edit()->call_deferred("grab_focus"); + tx->copy(); + tx->call_deferred("grab_focus"); } break; case EDIT_PASTE: { - code_editor->get_text_edit()->paste(); - code_editor->get_text_edit()->call_deferred("grab_focus"); + tx->paste(); + tx->call_deferred("grab_focus"); } break; case EDIT_SELECT_ALL: { - code_editor->get_text_edit()->select_all(); - code_editor->get_text_edit()->call_deferred("grab_focus"); - + tx->select_all(); + tx->call_deferred("grab_focus"); } break; case EDIT_MOVE_LINE_UP: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = script; if (scr.is_null()) return; @@ -850,7 +845,11 @@ void ScriptTextEditor::_edit_option(int p_op) { if (line_id == 0 || next_id < 0) return; - swap_lines(tx, line_id, next_id); + tx->unfold_line(line_id); + tx->unfold_line(next_id); + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); } int from_line_up = from_line > 0 ? from_line - 1 : from_line; int to_line_up = to_line > 0 ? to_line - 1 : to_line; @@ -862,15 +861,17 @@ void ScriptTextEditor::_edit_option(int p_op) { if (line_id == 0 || next_id < 0) return; - swap_lines(tx, line_id, next_id); + tx->unfold_line(line_id); + tx->unfold_line(next_id); + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); } tx->end_complex_operation(); tx->update(); - } break; case EDIT_MOVE_LINE_DOWN: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -889,7 +890,11 @@ void ScriptTextEditor::_edit_option(int p_op) { if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) return; - swap_lines(tx, line_id, next_id); + tx->unfold_line(line_id); + tx->unfold_line(next_id); + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); } int from_line_down = from_line < tx->get_line_count() ? from_line + 1 : from_line; int to_line_down = to_line < tx->get_line_count() ? to_line + 1 : to_line; @@ -901,7 +906,11 @@ void ScriptTextEditor::_edit_option(int p_op) { if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) return; - swap_lines(tx, line_id, next_id); + tx->unfold_line(line_id); + tx->unfold_line(next_id); + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); } tx->end_complex_operation(); tx->update(); @@ -909,7 +918,6 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case EDIT_INDENT_LEFT: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -934,11 +942,9 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->end_complex_operation(); tx->update(); //tx->deselect(); - } break; case EDIT_INDENT_RIGHT: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -955,11 +961,9 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->end_complex_operation(); tx->update(); //tx->deselect(); - } break; case EDIT_DELETE_LINE: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -968,13 +972,12 @@ void ScriptTextEditor::_edit_option(int p_op) { int line = tx->cursor_get_line(); tx->set_line(tx->cursor_get_line(), ""); tx->backspace_at_cursor(); + tx->unfold_line(line); tx->cursor_set_line(line); tx->end_complex_operation(); - } break; case EDIT_CLONE_DOWN: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -993,6 +996,7 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->begin_complex_operation(); for (int i = from_line; i <= to_line; i++) { + tx->unfold_line(i); if (i >= tx->get_line_count() - 1) { tx->set_line(i, tx->get_line(i) + "\n"); } @@ -1008,11 +1012,29 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->end_complex_operation(); tx->update(); + } break; + case EDIT_FOLD_LINE: { + + tx->fold_line(tx->cursor_get_line()); + tx->update(); + } break; + case EDIT_UNFOLD_LINE: { + + tx->unfold_line(tx->cursor_get_line()); + tx->update(); + } break; + case EDIT_FOLD_ALL_LINES: { + + tx->fold_all_lines(); + tx->update(); + } break; + case EDIT_UNFOLD_ALL_LINES: { + tx->unhide_all_lines(); + tx->update(); } break; case EDIT_TOGGLE_COMMENT: { - TextEdit *tx = code_editor->get_text_edit(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; @@ -1061,62 +1083,65 @@ void ScriptTextEditor::_edit_option(int p_op) { tx->end_complex_operation(); tx->update(); //tx->deselect(); - } break; case EDIT_COMPLETE: { - code_editor->get_text_edit()->query_code_comple(); - + tx->query_code_comple(); } break; case EDIT_AUTO_INDENT: { - TextEdit *te = code_editor->get_text_edit(); - String text = te->get_text(); + String text = tx->get_text(); Ref<Script> scr = get_edited_script(); if (scr.is_null()) return; - te->begin_complex_operation(); + tx->begin_complex_operation(); int begin, end; - if (te->is_selection_active()) { - begin = te->get_selection_from_line(); - end = te->get_selection_to_line(); + if (tx->is_selection_active()) { + begin = tx->get_selection_from_line(); + end = tx->get_selection_to_line(); // ignore if the cursor is not past the first column - if (te->get_selection_to_column() == 0) { + if (tx->get_selection_to_column() == 0) { end--; } } else { begin = 0; - end = te->get_line_count() - 1; + end = tx->get_line_count() - 1; } scr->get_language()->auto_indent_code(text, begin, end); Vector<String> lines = text.split("\n"); for (int i = begin; i <= end; ++i) { - te->set_line(i, lines[i]); + tx->set_line(i, lines[i]); } - te->end_complex_operation(); - + tx->end_complex_operation(); } break; case EDIT_TRIM_TRAILING_WHITESAPCE: { + trim_trailing_whitespace(); } break; case EDIT_CONVERT_INDENT_TO_SPACES: { + convert_indent_to_spaces(); } break; case EDIT_CONVERT_INDENT_TO_TABS: { + convert_indent_to_tabs(); } break; case EDIT_PICK_COLOR: { + color_panel->popup(); } break; case EDIT_TO_UPPERCASE: { + _convert_case(UPPER); } break; case EDIT_TO_LOWERCASE: { + _convert_case(LOWER); } break; case EDIT_CAPITALIZE: { + _convert_case(CAPITALIZE); } break; case SEARCH_FIND: { @@ -1141,41 +1166,47 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case SEARCH_GOTO_LINE: { - goto_line_dialog->popup_find_line(code_editor->get_text_edit()); + goto_line_dialog->popup_find_line(tx); } break; case DEBUG_TOGGLE_BREAKPOINT: { - int line = code_editor->get_text_edit()->cursor_get_line(); - bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); - code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak); + + int line = tx->cursor_get_line(); + bool dobreak = !tx->is_line_set_as_breakpoint(line); + tx->set_line_as_breakpoint(line, dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak); } break; case DEBUG_REMOVE_ALL_BREAKPOINTS: { + List<int> bpoints; - code_editor->get_text_edit()->get_breakpoints(&bpoints); + tx->get_breakpoints(&bpoints); for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { int line = E->get(); - bool dobreak = !code_editor->get_text_edit()->is_line_set_as_breakpoint(line); - code_editor->get_text_edit()->set_line_as_breakpoint(line, dobreak); + bool dobreak = !tx->is_line_set_as_breakpoint(line); + tx->set_line_as_breakpoint(line, dobreak); ScriptEditor::get_singleton()->get_debugger()->set_breakpoint(get_edited_script()->get_path(), line + 1, dobreak); } } case DEBUG_GOTO_NEXT_BREAKPOINT: { + List<int> bpoints; - code_editor->get_text_edit()->get_breakpoints(&bpoints); + tx->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } - int line = code_editor->get_text_edit()->cursor_get_line(); + int line = tx->cursor_get_line(); + // wrap around if (line >= bpoints[bpoints.size() - 1]) { - code_editor->get_text_edit()->cursor_set_line(bpoints[0]); + tx->unfold_line(bpoints[0]); + tx->cursor_set_line(bpoints[0]); } else { for (List<int>::Element *E = bpoints.front(); E; E = E->next()) { int bline = E->get(); if (bline > line) { - code_editor->get_text_edit()->cursor_set_line(bline); + tx->unfold_line(bline); + tx->cursor_set_line(bline); return; } } @@ -1183,21 +1214,24 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case DEBUG_GOTO_PREV_BREAKPOINT: { + List<int> bpoints; - code_editor->get_text_edit()->get_breakpoints(&bpoints); + tx->get_breakpoints(&bpoints); if (bpoints.size() <= 0) { return; } - int line = code_editor->get_text_edit()->cursor_get_line(); + int line = tx->cursor_get_line(); // wrap around if (line <= bpoints[0]) { - code_editor->get_text_edit()->cursor_set_line(bpoints[bpoints.size() - 1]); + tx->unfold_line(bpoints[bpoints.size() - 1]); + tx->cursor_set_line(bpoints[bpoints.size() - 1]); } else { for (List<int>::Element *E = bpoints.back(); E; E = E->prev()) { int bline = E->get(); if (bline < line) { - code_editor->get_text_edit()->cursor_set_line(bline); + tx->unfold_line(bline); + tx->cursor_set_line(bline); return; } } @@ -1206,9 +1240,10 @@ void ScriptTextEditor::_edit_option(int p_op) { } break; case HELP_CONTEXTUAL: { - String text = code_editor->get_text_edit()->get_selection_text(); + + String text = tx->get_selection_text(); if (text == "") - text = code_editor->get_text_edit()->get_word_under_cursor(); + text = tx->get_word_under_cursor(); if (text != "") { emit_signal("request_help_search", text); } @@ -1394,6 +1429,9 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { Vector2 mpos = mb->get_global_position() - tx->get_global_position(); bool have_selection = (tx->get_selection_text().length() > 0); bool have_color = (tx->get_word_at_pos(mpos) == "Color"); + int fold_state = 0; + bool can_fold = tx->can_fold(row); + bool is_folded = tx->is_folded(row); if (have_color) { String line = tx->get_line(row); @@ -1424,7 +1462,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { have_color = false; } } - _make_context_menu(have_selection, have_color); + _make_context_menu(have_selection, have_color, can_fold, is_folded); } } } @@ -1443,7 +1481,7 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { code_editor->get_text_edit()->set_line(color_line, new_line); } -void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) { +void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_can_fold, bool p_is_folded) { context_menu->clear(); if (p_selection) { @@ -1463,6 +1501,13 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); } + if (p_can_fold) { + // can fold + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE); + } else if (p_is_folded) { + // can unfold + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE); + } if (p_color) { context_menu->add_separator(); context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR); @@ -1526,6 +1571,10 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_line"), EDIT_FOLD_LINE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/fold_all_lines"), EDIT_FOLD_ALL_LINES); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_line"), EDIT_UNFOLD_LINE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/unfold_all_lines"), EDIT_UNFOLD_ALL_LINES); edit_menu->get_popup()->add_separator(); #ifdef OSX_ENABLED edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); @@ -1603,6 +1652,10 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0); ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K); ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_B); + ED_SHORTCUT("script_text_editor/fold_line", TTR("Fold Line"), KEY_MASK_ALT | KEY_LEFT); + ED_SHORTCUT("script_text_editor/unfold_line", TTR("Unfold Line"), KEY_MASK_ALT | KEY_RIGHT); + ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0); + ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CTRL | KEY_SPACE); #else diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 83f3ea57c0..722015ef3e 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -91,6 +91,10 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, EDIT_CAPITALIZE, + EDIT_FOLD_LINE, + EDIT_UNFOLD_LINE, + EDIT_FOLD_ALL_LINES, + EDIT_UNFOLD_ALL_LINES, SEARCH_FIND, SEARCH_FIND_NEXT, SEARCH_FIND_PREV, @@ -118,7 +122,7 @@ protected: static void _bind_methods(); void _edit_option(int p_op); - void _make_context_menu(bool p_selection, bool p_color); + void _make_context_menu(bool p_selection, bool p_color, bool p_can_fold, bool p_is_folded); void _text_edit_gui_input(const Ref<InputEvent> &ev); void _color_changed(const Color &p_color); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index f7dcc4b52d..49e4642049 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -248,6 +248,8 @@ void ShaderTextEditor::_validate_script() { if (err != OK) { String error_text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); set_error(error_text); + for (int i = 0; i < get_text_edit()->get_line_count(); i++) + get_text_edit()->set_line_as_marked(i, false); get_text_edit()->set_line_as_marked(sl.get_error_line() - 1, true); } else { @@ -269,55 +271,284 @@ ShaderTextEditor::ShaderTextEditor() { void ShaderEditor::_menu_option(int p_option) { - ShaderTextEditor *current = shader_editor; - switch (p_option) { case EDIT_UNDO: { - - current->get_text_edit()->undo(); + shader_editor->get_text_edit()->undo(); } break; case EDIT_REDO: { - current->get_text_edit()->redo(); - + shader_editor->get_text_edit()->redo(); } break; case EDIT_CUT: { - - current->get_text_edit()->cut(); + shader_editor->get_text_edit()->cut(); } break; case EDIT_COPY: { - current->get_text_edit()->copy(); - + shader_editor->get_text_edit()->copy(); } break; case EDIT_PASTE: { - current->get_text_edit()->paste(); - + shader_editor->get_text_edit()->paste(); } break; case EDIT_SELECT_ALL: { + shader_editor->get_text_edit()->select_all(); + } break; + case EDIT_MOVE_LINE_UP: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + if (tx->is_selection_active()) { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); + + for (int i = from_line; i <= to_line; i++) { + int line_id = i; + int next_id = i - 1; + + if (line_id == 0 || next_id < 0) + return; + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); + } + int from_line_up = from_line > 0 ? from_line - 1 : from_line; + int to_line_up = to_line > 0 ? to_line - 1 : to_line; + tx->select(from_line_up, from_col, to_line_up, to_column); + } else { + int line_id = tx->cursor_get_line(); + int next_id = line_id - 1; + + if (line_id == 0 || next_id < 0) + return; + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); + } + tx->end_complex_operation(); + tx->update(); + + } break; + case EDIT_MOVE_LINE_DOWN: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + if (tx->is_selection_active()) { + int from_line = tx->get_selection_from_line(); + int from_col = tx->get_selection_from_column(); + int to_line = tx->get_selection_to_line(); + int to_column = tx->get_selection_to_column(); + + for (int i = to_line; i >= from_line; i--) { + int line_id = i; + int next_id = i + 1; + + if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) + return; + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); + } + int from_line_down = from_line < tx->get_line_count() ? from_line + 1 : from_line; + int to_line_down = to_line < tx->get_line_count() ? to_line + 1 : to_line; + tx->select(from_line_down, from_col, to_line_down, to_column); + } else { + int line_id = tx->cursor_get_line(); + int next_id = line_id + 1; + + if (line_id == tx->get_line_count() - 1 || next_id > tx->get_line_count()) + return; + + tx->swap_lines(line_id, next_id); + tx->cursor_set_line(next_id); + } + tx->end_complex_operation(); + tx->update(); + + } break; + case EDIT_INDENT_LEFT: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + if (tx->is_selection_active()) { + tx->indent_selection_left(); + } else { + int begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + // begins with tab + if (line_text.begins_with("\t")) { + line_text = line_text.substr(1, line_text.length()); + tx->set_line(begin, line_text); + } + // begins with 4 spaces + else if (line_text.begins_with(" ")) { + line_text = line_text.substr(4, line_text.length()); + tx->set_line(begin, line_text); + } + } + tx->end_complex_operation(); + tx->update(); + //tx->deselect(); + + } break; + case EDIT_INDENT_RIGHT: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + if (tx->is_selection_active()) { + tx->indent_selection_right(); + } else { + int begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + line_text = '\t' + line_text; + tx->set_line(begin, line_text); + } + tx->end_complex_operation(); + tx->update(); + //tx->deselect(); + + } break; + case EDIT_DELETE_LINE: { - current->get_text_edit()->select_all(); + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + int line = tx->cursor_get_line(); + tx->set_line(tx->cursor_get_line(), ""); + tx->backspace_at_cursor(); + tx->cursor_set_line(line); + tx->end_complex_operation(); } break; + case EDIT_CLONE_DOWN: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + int from_line = tx->cursor_get_line(); + int to_line = tx->cursor_get_line(); + int column = tx->cursor_get_column(); + + if (tx->is_selection_active()) { + from_line = tx->get_selection_from_line(); + to_line = tx->get_selection_to_line(); + column = tx->cursor_get_column(); + } + int next_line = to_line + 1; + + tx->begin_complex_operation(); + for (int i = from_line; i <= to_line; i++) { + + if (i >= tx->get_line_count() - 1) { + tx->set_line(i, tx->get_line(i) + "\n"); + } + String line_clone = tx->get_line(i); + tx->insert_at(line_clone, next_line); + next_line++; + } + + tx->cursor_set_column(column); + if (tx->is_selection_active()) { + tx->select(to_line + 1, tx->get_selection_from_column(), next_line - 1, tx->get_selection_to_column()); + } + + tx->end_complex_operation(); + tx->update(); + + } break; + case EDIT_TOGGLE_COMMENT: { + + TextEdit *tx = shader_editor->get_text_edit(); + if (shader.is_null()) + return; + + tx->begin_complex_operation(); + if (tx->is_selection_active()) { + int begin = tx->get_selection_from_line(); + int end = tx->get_selection_to_line(); + + // End of selection ends on the first column of the last line, ignore it. + if (tx->get_selection_to_column() == 0) + end -= 1; + + // Check if all lines in the selected block are commented + bool is_commented = true; + for (int i = begin; i <= end; i++) { + if (!tx->get_line(i).begins_with("//")) { + is_commented = false; + break; + } + } + for (int i = begin; i <= end; i++) { + String line_text = tx->get_line(i); + + if (line_text.strip_edges().empty()) { + line_text = "//"; + } else { + if (is_commented) { + line_text = line_text.substr(2, line_text.length()); + } else { + line_text = "//" + line_text; + } + } + tx->set_line(i, line_text); + } + } else { + int begin = tx->cursor_get_line(); + String line_text = tx->get_line(begin); + + if (line_text.begins_with("//")) + line_text = line_text.substr(2, line_text.length()); + else + line_text = "//" + line_text; + tx->set_line(begin, line_text); + } + tx->end_complex_operation(); + tx->update(); + //tx->deselect(); + + } break; + case EDIT_COMPLETE: { + + shader_editor->get_text_edit()->query_code_comple(); + } break; case SEARCH_FIND: { - current->get_find_replace_bar()->popup_search(); + shader_editor->get_find_replace_bar()->popup_search(); } break; case SEARCH_FIND_NEXT: { - current->get_find_replace_bar()->search_next(); + shader_editor->get_find_replace_bar()->search_next(); } break; case SEARCH_FIND_PREV: { - current->get_find_replace_bar()->search_prev(); + shader_editor->get_find_replace_bar()->search_prev(); } break; case SEARCH_REPLACE: { - current->get_find_replace_bar()->popup_replace(); + shader_editor->get_find_replace_bar()->popup_replace(); } break; case SEARCH_GOTO_LINE: { - goto_line_dialog->popup_find_line(current->get_text_edit()); + goto_line_dialog->popup_find_line(shader_editor->get_text_edit()); } break; } + if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) { + shader_editor->get_text_edit()->call_deferred("grab_focus"); + } } void ShaderEditor::_notification(int p_what) { @@ -325,10 +556,6 @@ void ShaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { } if (p_what == NOTIFICATION_DRAW) { - - RID ci = get_canvas_item(); - Ref<StyleBox> style = get_stylebox("panel", "Panel"); - style->draw(ci, Rect2(Point2(), get_size())); } } @@ -360,6 +587,7 @@ void ShaderEditor::_editor_settings_changed() { void ShaderEditor::_bind_methods() { ClassDB::bind_method("_editor_settings_changed", &ShaderEditor::_editor_settings_changed); + ClassDB::bind_method("_text_edit_gui_input", &ShaderEditor::_text_edit_gui_input); ClassDB::bind_method("_menu_option", &ShaderEditor::_menu_option); ClassDB::bind_method("_params_changed", &ShaderEditor::_params_changed); @@ -413,49 +641,122 @@ void ShaderEditor::apply_shaders() { } } -ShaderEditor::ShaderEditor() { +void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { - HBoxContainer *hbc = memnew(HBoxContainer); + Ref<InputEventMouseButton> mb = ev; - add_child(hbc); + if (mb.is_valid()) { + + if (mb->get_button_index() == BUTTON_RIGHT && !mb->is_pressed()) { + + int col, row; + TextEdit *tx = shader_editor->get_text_edit(); + tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); + Vector2 mpos = mb->get_global_position() - tx->get_global_position(); + bool have_selection = (tx->get_selection_text().length() > 0); + _make_context_menu(have_selection); + } + } +} + +void ShaderEditor::_make_context_menu(bool p_selection) { + + context_menu->clear(); + if (p_selection) { + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY); + } + + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE); + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); + + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); + + context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); + context_menu->set_size(Vector2(1, 1)); + context_menu->popup(); +} + +ShaderEditor::ShaderEditor(EditorNode *p_node) { + + shader_editor = memnew(ShaderTextEditor); + shader_editor->set_v_size_flags(SIZE_EXPAND_FILL); + shader_editor->add_constant_override("separation", 0); + shader_editor->set_anchors_and_margins_preset(Control::PRESET_WIDE); + + shader_editor->connect("script_changed", this, "apply_shaders"); + EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); + + shader_editor->get_text_edit()->set_callhint_settings( + EditorSettings::get_singleton()->get("text_editor/completion/put_callhint_tooltip_below_current_line"), + EditorSettings::get_singleton()->get("text_editor/completion/callhint_tooltip_offset")); + + shader_editor->get_text_edit()->set_select_identifiers_on_hover(true); + shader_editor->get_text_edit()->set_context_menu_enabled(false); + shader_editor->get_text_edit()->connect("gui_input", this, "_text_edit_gui_input"); + + shader_editor->update_editor_settings(); + + context_menu = memnew(PopupMenu); + add_child(context_menu); + context_menu->connect("id_pressed", this, "_menu_option"); + + VBoxContainer *main_container = memnew(VBoxContainer); + HBoxContainer *hbc = memnew(HBoxContainer); edit_menu = memnew(MenuButton); - hbc->add_child(edit_menu); - edit_menu->set_position(Point2(5, -1)); + //edit_menu->set_position(Point2(5, -1)); edit_menu->set_text(TTR("Edit")); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/undo", TTR("Undo"), KEY_MASK_CMD | KEY_Z), EDIT_UNDO); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/redo", TTR("Redo"), KEY_MASK_CMD | KEY_Y), EDIT_REDO); + + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); + edit_menu->get_popup()->add_separator(); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE); + edit_menu->get_popup()->add_separator(); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/cut", TTR("Cut"), KEY_MASK_CMD | KEY_X), EDIT_CUT); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/copy", TTR("Copy"), KEY_MASK_CMD | KEY_C), EDIT_COPY); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/paste", TTR("Paste"), KEY_MASK_CMD | KEY_V), EDIT_PASTE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_up"), EDIT_MOVE_LINE_UP); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/move_down"), EDIT_MOVE_LINE_DOWN); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/delete_line"), EDIT_DELETE_LINE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); edit_menu->get_popup()->add_separator(); - edit_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/select_all", TTR("Select All"), KEY_MASK_CMD | KEY_A), EDIT_SELECT_ALL); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); + edit_menu->get_popup()->connect("id_pressed", this, "_menu_option"); search_menu = memnew(MenuButton); - hbc->add_child(search_menu); - search_menu->set_position(Point2(38, -1)); + //search_menu->set_position(Point2(38, -1)); search_menu->set_text(TTR("Search")); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find", TTR("Find.."), KEY_MASK_CMD | KEY_F), SEARCH_FIND); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_next", TTR("Find Next"), KEY_F3), SEARCH_FIND_NEXT); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/find_previous", TTR("Find Previous"), KEY_MASK_SHIFT | KEY_F3), SEARCH_FIND_PREV); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/replace", TTR("Replace.."), KEY_MASK_CMD | KEY_R), SEARCH_REPLACE); + + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find"), SEARCH_FIND); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); - //search_menu->get_popup()->add_item("Locate Symbol..",SEARCH_LOCATE_SYMBOL,KEY_MASK_CMD|KEY_K); - search_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/goto_line", TTR("Goto Line.."), KEY_MASK_CMD | KEY_L), SEARCH_GOTO_LINE); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + add_child(main_container); + main_container->add_child(hbc); + hbc->add_child(search_menu); + hbc->add_child(edit_menu); + hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles")); + main_container->add_child(shader_editor); + goto_line_dialog = memnew(GotoLineDialog); add_child(goto_line_dialog); - shader_editor = memnew(ShaderTextEditor); - add_child(shader_editor); - shader_editor->set_v_size_flags(SIZE_EXPAND_FILL); - - shader_editor->connect("script_changed", this, "apply_shaders"); - EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); - _editor_settings_changed(); } @@ -504,7 +805,7 @@ void ShaderEditorPlugin::apply_changes() { ShaderEditorPlugin::ShaderEditorPlugin(EditorNode *p_node) { editor = p_node; - shader_editor = memnew(ShaderEditor); + shader_editor = memnew(ShaderEditor(p_node)); shader_editor->set_custom_minimum_size(Size2(0, 300)); button = editor->add_bottom_panel_item(TTR("Shader"), shader_editor); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index ab18784d9f..b191f5700f 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -33,6 +33,7 @@ #include "editor/code_editor.h" #include "editor/editor_plugin.h" #include "scene/gui/menu_button.h" +#include "scene/gui/panel_container.h" #include "scene/gui/tab_container.h" #include "scene/gui/text_edit.h" #include "scene/main/timer.h" @@ -61,9 +62,9 @@ public: ShaderTextEditor(); }; -class ShaderEditor : public VBoxContainer { +class ShaderEditor : public PanelContainer { - GDCLASS(ShaderEditor, VBoxContainer); + GDCLASS(ShaderEditor, PanelContainer); enum { @@ -73,6 +74,14 @@ class ShaderEditor : public VBoxContainer { EDIT_COPY, EDIT_PASTE, EDIT_SELECT_ALL, + EDIT_MOVE_LINE_UP, + EDIT_MOVE_LINE_DOWN, + EDIT_INDENT_LEFT, + EDIT_INDENT_RIGHT, + EDIT_DELETE_LINE, + EDIT_CLONE_DOWN, + EDIT_TOGGLE_COMMENT, + EDIT_COMPLETE, SEARCH_FIND, SEARCH_FIND_NEXT, SEARCH_FIND_PREV, @@ -84,6 +93,7 @@ class ShaderEditor : public VBoxContainer { MenuButton *edit_menu; MenuButton *search_menu; MenuButton *settings_menu; + PopupMenu *context_menu; uint64_t idle; GotoLineDialog *goto_line_dialog; @@ -100,6 +110,8 @@ class ShaderEditor : public VBoxContainer { protected: void _notification(int p_what); static void _bind_methods(); + void _make_context_menu(bool p_selection); + void _text_edit_gui_input(const Ref<InputEvent> &ev); public: void apply_shaders(); @@ -110,7 +122,7 @@ public: virtual Size2 get_minimum_size() const { return Size2(0, 200); } void save_external_data(); - ShaderEditor(); + ShaderEditor(EditorNode *p_node); }; class ShaderEditorPlugin : public EditorPlugin { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 25ca2d731e..b3d3d5e13a 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -758,17 +758,49 @@ bool SpatialEditorViewport::_gizmo_select(const Vector2 &p_screenpos, bool p_hig } } + bool is_plane_scale = false; + // plane select + if (col_axis == -1) { + col_d = 1e20; + + for (int i = 0; i < 3; i++) { + + Vector3 ivec2 = gt.basis.get_axis((i + 1) % 3).normalized(); + Vector3 ivec3 = gt.basis.get_axis((i + 2) % 3).normalized(); + + Vector3 grabber_pos = gt.origin + (ivec2 + ivec3) * gs * (GIZMO_PLANE_SIZE + GIZMO_PLANE_DST); + + Vector3 r; + Plane plane(gt.origin, gt.basis.get_axis(i).normalized()); + + if (plane.intersects_ray(ray_pos, ray, &r)) { + + float dist = r.distance_to(grabber_pos); + if (dist < (gs * GIZMO_PLANE_SIZE)) { + + float d = ray_pos.distance_to(r); + if (d < col_d) { + col_d = d; + col_axis = i; + + is_plane_scale = true; + } + } + } + } + } + if (col_axis != -1) { if (p_highlight_only) { - spatial_editor->select_gizmo_highlight_axis(col_axis + 9); + spatial_editor->select_gizmo_highlight_axis(col_axis + (is_plane_scale ? 12 : 9)); } else { //handle scale _edit.mode = TRANSFORM_SCALE; _compute_edit(Point2(p_screenpos.x, p_screenpos.y)); - _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis); + _edit.plane = TransformPlane(TRANSFORM_X_AXIS + col_axis + (is_plane_scale ? 3 : 0)); } return true; } @@ -1255,7 +1287,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 motion_mask; Plane plane; - bool plane_mv; + bool plane_mv = false; switch (_edit.plane) { case TRANSFORM_VIEW: @@ -1274,6 +1306,21 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2); plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); break; + case TRANSFORM_YZ: + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(1); + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0)); + plane_mv = true; + break; + case TRANSFORM_XZ: + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(0); + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1)); + plane_mv = true; + break; + case TRANSFORM_XY: + motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0) + spatial_editor->get_gizmo_transform().basis.get_axis(1); + plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2)); + plane_mv = true; + break; } Vector3 intersection; @@ -1285,12 +1332,21 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { break; Vector3 motion = intersection - click; - print_line(String(intersection) + " --- " + String(click)); - if (motion_mask != Vector3()) { + if (_edit.plane != TRANSFORM_VIEW) { - motion = motion_mask.dot(motion) * motion_mask; - } else { + if (!plane_mv) { + + motion = motion_mask.dot(motion) * motion_mask; + + } else { + // Alternative planar scaling mode + if (_get_key_modifier(m) != KEY_SHIFT) { + motion = motion_mask.dot(motion) * motion_mask; + } + } + + } else { float center_click_dist = click.distance_to(_edit.center); float center_inters_dist = intersection.distance_to(_edit.center); if (center_click_dist == 0) @@ -1302,12 +1358,19 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - bool local_coords = (spatial_editor->are_local_coords_enabled() && motion_mask != Vector3()); // Disable local transformation for TRANSFORM_VIEW + bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { snap = spatial_editor->get_scale_snap() / 100; + + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + set_message(TTR("Scaling: ") + motion_snapped); + + } else { + set_message(TTR("Scaling: ") + motion); } for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1339,6 +1402,15 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { local_scale = original_local.basis.get_scale() * (local_motion + Vector3(1, 1, 1)); + // Prevent scaling to 0 it would break the gizmo + Basis check = original_local.basis; + check.scale(local_scale); + if (check.determinant() != 0) { + + // Apply scale + sp->set_scale(local_scale); + } + } else { if (_edit.snap || spatial_editor->is_snap_enabled()) { @@ -1348,12 +1420,8 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Transform r; r.basis.scale(motion + Vector3(1, 1, 1)); t = base * (r * (base.inverse() * original)); - } - // Apply scale - if (local_coords) { - sp->set_scale(local_scale); - } else { + // Apply scale sp->set_global_transform(t); } } @@ -1366,11 +1434,10 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Vector3 motion_mask; Plane plane; - bool plane_mv; + bool plane_mv = false; switch (_edit.plane) { case TRANSFORM_VIEW: - motion_mask = Vector3(0, 0, 0); plane = Plane(_edit.center, _get_camera_normal()); break; case TRANSFORM_X_AXIS: @@ -1386,17 +1453,14 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { plane = Plane(_edit.center, motion_mask.cross(motion_mask.cross(_get_camera_normal())).normalized()); break; case TRANSFORM_YZ: - motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(1); plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(0)); plane_mv = true; break; case TRANSFORM_XZ: - motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(2) + spatial_editor->get_gizmo_transform().basis.get_axis(0); plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(1)); plane_mv = true; break; case TRANSFORM_XY: - motion_mask = spatial_editor->get_gizmo_transform().basis.get_axis(0) + spatial_editor->get_gizmo_transform().basis.get_axis(1); plane = Plane(_edit.center, spatial_editor->get_gizmo_transform().basis.get_axis(2)); plane_mv = true; break; @@ -1410,55 +1474,27 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (!plane.intersects_ray(_edit.click_ray_pos, _edit.click_ray, &click)) break; - //_validate_selection(); Vector3 motion = intersection - click; - if (motion_mask != Vector3()) { - if (plane_mv) - motion *= motion_mask; - else + if (_edit.plane != TRANSFORM_VIEW) { + if (!plane_mv) { motion = motion_mask.dot(motion) * motion_mask; + } } - //set_message("Translating: "+motion); - List<Node *> &selection = editor_selection->get_selected_node_list(); - float snap = 0; + bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW + float snap = 0; if (_edit.snap || spatial_editor->is_snap_enabled()) { snap = spatial_editor->get_translate_snap(); - bool local_coords = spatial_editor->are_local_coords_enabled(); - - if (local_coords) { - bool multiple = false; - Spatial *node = NULL; - for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { - - Spatial *sp = Object::cast_to<Spatial>(E->get()); - if (!sp) { - continue; - } - if (node) { - multiple = true; - break; - } else { - node = sp; - } - } - if (multiple) { - motion.snap(Vector3(snap, snap, snap)); - } else { - Basis b = node->get_global_transform().basis.orthonormalized(); - Vector3 local_motion = b.inverse().xform(motion); - local_motion.snap(Vector3(snap, snap, snap)); - motion = b.xform(local_motion); - } - - } else { - motion.snap(Vector3(snap, snap, snap)); - } + Vector3 motion_snapped = motion; + motion_snapped.snap(Vector3(snap, snap, snap)); + set_message(TTR("Translating: ") + motion_snapped); + } else { + set_message(TTR("Translating: ") + motion); } for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1473,10 +1509,34 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { continue; } - Transform t = se->original; + Transform original = se->original; + Transform t; + + if (local_coords) { + + if (_edit.snap || spatial_editor->is_snap_enabled()) { + Basis g = original.basis.orthonormalized(); + Vector3 local_motion = g.inverse().xform(motion); + local_motion.snap(Vector3(snap, snap, snap)); + + motion = g.xform(local_motion); + } + + } else { + + if (_edit.snap || spatial_editor->is_snap_enabled()) { + motion.snap(Vector3(snap, snap, snap)); + } + } + + // Apply translation + t = original; t.origin += motion; sp->set_global_transform(t); } + + surface->update(); + } break; case TRANSFORM_ROTATE: { @@ -1533,7 +1593,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { List<Node *> &selection = editor_selection->get_selected_node_list(); - bool local_coords = spatial_editor->are_local_coords_enabled(); + bool local_coords = (spatial_editor->are_local_coords_enabled() && _edit.plane != TRANSFORM_VIEW); // Disable local transformation for TRANSFORM_VIEW for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { @@ -1552,10 +1612,12 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { Transform original_local = se->original_local; Basis rot = Basis(axis, angle); - t.basis = original_local.get_basis() * rot; + t.basis = original_local.get_basis().orthonormalized() * rot; t.origin = original_local.origin; + // Apply rotation sp->set_transform(t); + sp->set_scale(original_local.basis.get_scale()); // re-apply original scale } else { @@ -1566,6 +1628,7 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { r.basis.rotate(plane.normal, angle); t = base * r * base.inverse() * original; + // Apply rotation sp->set_global_transform(t); } } @@ -1803,6 +1866,11 @@ void SpatialEditorViewport::_sinput(const Ref<InputEvent> &p_event) { if (!k->is_pressed()) emit_signal("toggle_maximize_view", this); } } + + // freelook uses most of the useful shortcuts, like save, so its ok + // to consider freelook active as end of the line for future events. + if (freelook_active) + accept_event(); } void SpatialEditorViewport::set_freelook_active(bool active_now) { @@ -2001,7 +2069,7 @@ void SpatialEditorViewport::_notification(int p_what) { if (se->aabb.has_no_surface()) { - se->aabb = vi ? vi->get_aabb() : Rect3(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4)); + se->aabb = vi ? vi->get_aabb() : AABB(Vector3(-0.2, -0.2, -0.2), Vector3(0.4, 0.4, 0.4)); } Transform t = sp->get_global_transform(); @@ -2089,6 +2157,29 @@ void SpatialEditorViewport::_notification(int p_what) { } } + // FPS Counter. + bool show_fps = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_FPS)); + if (show_fps != fps->is_visible()) { + if (show_fps) + fps->show(); + else + fps->hide(); + } + + if (show_fps) { + String text; + const float temp_fps = Engine::get_singleton()->get_frames_per_second(); + text += TTR("FPS") + ": " + itos(temp_fps) + " (" + String::num(1000.0f / temp_fps, 2) + " ms)"; + + if (fps_label->get_text() != text || surface->get_size() != prev_size) { + fps_label->set_text(text); + Size2 ms = fps->get_size(); + Size2 size = surface->get_size(); + size.y = ms.y + 20; + fps->set_position(size - ms - Vector2(20, 0) * EDSCALE); + } + } + prev_size = surface->get_size(); } @@ -2099,6 +2190,7 @@ void SpatialEditorViewport::_notification(int p_what) { surface->connect("mouse_entered", this, "_smouseenter"); surface->connect("mouse_exited", this, "_smouseexit"); info->add_style_override("panel", get_stylebox("panel", "Panel")); + fps->add_style_override("panel", get_stylebox("panel", "Panel")); preview_camera->set_icon(get_icon("Camera", "EditorIcons")); _init_gizmo_instance(index); } @@ -2421,6 +2513,13 @@ void SpatialEditorViewport::_menu_option(int p_option) { view_menu->get_popup()->set_item_checked(idx, !current); } break; + case VIEW_FPS: { + + int idx = view_menu->get_popup()->get_item_index(VIEW_FPS); + bool current = view_menu->get_popup()->is_item_checked(idx); + view_menu->get_popup()->set_item_checked(idx, !current); + + } break; case VIEW_DISPLAY_NORMAL: { viewport->set_debug_draw(Viewport::DEBUG_DRAW_DISABLED); @@ -2506,6 +2605,14 @@ void SpatialEditorViewport::_init_gizmo_instance(int p_idx) { //VS::get_singleton()->instance_geometry_set_flag(scale_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); VS::get_singleton()->instance_geometry_set_cast_shadows_setting(scale_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF); VS::get_singleton()->instance_set_layer_mask(scale_gizmo_instance[i], layer); + + scale_plane_gizmo_instance[i] = VS::get_singleton()->instance_create(); + VS::get_singleton()->instance_set_base(scale_plane_gizmo_instance[i], spatial_editor->get_scale_plane_gizmo(i)->get_rid()); + VS::get_singleton()->instance_set_scenario(scale_plane_gizmo_instance[i], get_tree()->get_root()->get_world()->get_scenario()); + VS::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], false); + //VS::get_singleton()->instance_geometry_set_flag(scale_plane_gizmo_instance[i],VS::INSTANCE_FLAG_DEPH_SCALE,true); + VS::get_singleton()->instance_geometry_set_cast_shadows_setting(scale_plane_gizmo_instance[i], VS::SHADOW_CASTING_SETTING_OFF); + VS::get_singleton()->instance_set_layer_mask(scale_plane_gizmo_instance[i], layer); } } @@ -2516,6 +2623,7 @@ void SpatialEditorViewport::_finish_gizmo_instances() { VS::get_singleton()->free(move_plane_gizmo_instance[i]); VS::get_singleton()->free(rotate_gizmo_instance[i]); VS::get_singleton()->free(scale_gizmo_instance[i]); + VS::get_singleton()->free(scale_plane_gizmo_instance[i]); } } void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { @@ -2612,6 +2720,8 @@ void SpatialEditorViewport::update_transform_gizmo_view() { VisualServer::get_singleton()->instance_set_visible(rotate_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SELECT || spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_ROTATE)); VisualServer::get_singleton()->instance_set_transform(scale_gizmo_instance[i], xform); VisualServer::get_singleton()->instance_set_visible(scale_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE)); + VisualServer::get_singleton()->instance_set_transform(scale_plane_gizmo_instance[i], xform); + VisualServer::get_singleton()->instance_set_visible(scale_plane_gizmo_instance[i], spatial_editor->is_gizmo_visible() && (spatial_editor->get_tool_mode() == SpatialEditor::TOOL_MODE_SCALE)); } } @@ -2746,7 +2856,7 @@ void SpatialEditorViewport::focus_selection() { cursor.pos = center; } -void SpatialEditorViewport::assign_pending_data_pointers(Spatial *p_preview_node, Rect3 *p_preview_bounds, AcceptDialog *p_accept) { +void SpatialEditorViewport::assign_pending_data_pointers(Spatial *p_preview_node, AABB *p_preview_bounds, AcceptDialog *p_accept) { preview_node = p_preview_node; preview_bounds = p_preview_bounds; accept = p_accept; @@ -2809,14 +2919,14 @@ Vector3 SpatialEditorViewport::_get_instance_position(const Point2 &p_pos) const return point + offset; } -Rect3 SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, const Rect3 p_bounds) { - Rect3 bounds = p_bounds; +AABB SpatialEditorViewport::_calculate_spatial_bounds(const Spatial *p_parent, const AABB p_bounds) { + AABB bounds = p_bounds; for (int i = 0; i < p_parent->get_child_count(); i++) { Spatial *child = Object::cast_to<Spatial>(p_parent->get_child(i)); if (child) { MeshInstance *mesh_instance = Object::cast_to<MeshInstance>(child); if (mesh_instance) { - Rect3 mesh_instance_bounds = mesh_instance->get_aabb(); + AABB mesh_instance_bounds = mesh_instance->get_aabb(); mesh_instance_bounds.position += mesh_instance->get_global_transform().origin - p_parent->get_global_transform().origin; bounds.merge_with(mesh_instance_bounds); } @@ -2848,7 +2958,7 @@ void SpatialEditorViewport::_create_preview(const Vector<String> &files) const { editor->get_scene_root()->add_child(preview_node); } } - *preview_bounds = _calculate_spatial_bounds(preview_node, Rect3()); + *preview_bounds = _calculate_spatial_bounds(preview_node, AABB()); } void SpatialEditorViewport::_remove_preview() { @@ -2911,7 +3021,9 @@ bool SpatialEditorViewport::_create_instance(Node *parent, String &path, const P } } - instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); + if (scene != NULL) { + instanced_scene->set_filename(ProjectSettings::get_singleton()->localize_path(path)); + } editor_data->get_undo_redo().add_do_method(parent, "add_child", instanced_scene); editor_data->get_undo_redo().add_do_method(instanced_scene, "set_owner", editor->get_edited_scene()); @@ -3137,6 +3249,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_environment", TTR("View Environment")), VIEW_ENVIRONMENT); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_gizmos", TTR("View Gizmos")), VIEW_GIZMOS); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_information", TTR("View Information")), VIEW_INFORMATION); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_fps", TTR("View FPS")), VIEW_FPS); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_ENVIRONMENT), true); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION); @@ -3179,6 +3292,14 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed info->add_child(info_label); info->hide(); + // FPS Counter. + fps = memnew(PanelContainer); + fps->set_self_modulate(Color(1, 1, 1, 0.4)); + surface->add_child(fps); + fps_label = memnew(Label); + fps->add_child(fps_label); + fps->hide(); + accept = NULL; freelook_active = false; @@ -3516,13 +3637,14 @@ void SpatialEditor::select_gizmo_highlight_axis(int p_axis) { move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? gizmo_hl : plane_gizmo_color[i]); rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]); scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_hl : gizmo_color[i]); + scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? gizmo_hl : plane_gizmo_color[i]); } } void SpatialEditor::update_transform_gizmo() { List<Node *> &selection = editor_selection->get_selected_node_list(); - Rect3 center; + AABB center; bool first = true; Basis gizmo_basis; @@ -3583,7 +3705,7 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) { void SpatialEditor::_generate_selection_box() { - Rect3 aabb(Vector3(), Vector3(1, 1, 1)); + AABB aabb(Vector3(), Vector3(1, 1, 1)); aabb.grow_by(aabb.get_longest_axis_size() / 20.0); Ref<SurfaceTool> st = memnew(SurfaceTool); @@ -4089,6 +4211,7 @@ void SpatialEditor::_init_indicators() { move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); scale_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); + scale_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); Ref<SpatialMaterial> mat = memnew(SpatialMaterial); mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); @@ -4284,6 +4407,49 @@ void SpatialEditor::_init_indicators() { surftool->set_material(mat); surftool->commit(scale_gizmo[i]); } + + // Plane Scale + { + Ref<SurfaceTool> surftool = memnew(SurfaceTool); + surftool->begin(Mesh::PRIMITIVE_TRIANGLES); + + Vector3 vec = ivec2 - ivec3; + Vector3 plane[4] = { + vec * GIZMO_PLANE_DST, + vec * GIZMO_PLANE_DST + ivec2 * GIZMO_PLANE_SIZE, + vec * (GIZMO_PLANE_DST + GIZMO_PLANE_SIZE), + vec * GIZMO_PLANE_DST - ivec3 * GIZMO_PLANE_SIZE + }; + + Basis ma(ivec, Math_PI / 2); + + Vector3 points[4] = { + ma.xform(plane[0]), + ma.xform(plane[1]), + ma.xform(plane[2]), + ma.xform(plane[3]), + }; + surftool->add_vertex(points[0]); + surftool->add_vertex(points[1]); + surftool->add_vertex(points[2]); + + surftool->add_vertex(points[0]); + surftool->add_vertex(points[2]); + surftool->add_vertex(points[3]); + + Ref<SpatialMaterial> plane_mat = memnew(SpatialMaterial); + plane_mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); + plane_mat->set_on_top_of_alpha(); + plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); + plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); + Color col; + col[i] = 1.0; + col.a = gizmo_alph; + plane_mat->set_albedo(col); + plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides + surftool->set_material(plane_mat); + surftool->commit(scale_plane_gizmo[i]); + } } } @@ -4610,7 +4776,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { // Drag and drop support; preview_node = memnew(Spatial); - preview_bounds = Rect3(); + preview_bounds = AABB(); ED_SHORTCUT("spatial_editor/bottom_view", TTR("Bottom View"), KEY_MASK_ALT + KEY_KP_7); ED_SHORTCUT("spatial_editor/top_view", TTR("Top View"), KEY_KP_7); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index c2b698068f..c986e45f43 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -88,6 +88,7 @@ class SpatialEditorViewport : public Control { VIEW_AUDIO_DOPPLER, VIEW_GIZMOS, VIEW_INFORMATION, + VIEW_FPS, VIEW_DISPLAY_NORMAL, VIEW_DISPLAY_WIREFRAME, VIEW_DISPLAY_OVERDRAW, @@ -108,7 +109,7 @@ private: Size2 prev_size; Spatial *preview_node; - Rect3 *preview_bounds; + AABB *preview_bounds; Vector<String> selected_files; AcceptDialog *accept; @@ -138,6 +139,9 @@ private: PanelContainer *info; Label *info_label; + PanelContainer *fps; + Label *fps_label; + struct _RayResult { Spatial *item; @@ -255,7 +259,7 @@ private: real_t zoom_indicator_delay; - RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3], scale_gizmo_instance[3]; + RID move_gizmo_instance[3], move_plane_gizmo_instance[3], rotate_gizmo_instance[3], scale_gizmo_instance[3], scale_plane_gizmo_instance[3]; String last_message; String message; @@ -287,7 +291,7 @@ private: Point2i _get_warped_mouse_motion(const Ref<InputEventMouseMotion> &p_ev_mouse_motion) const; Vector3 _get_instance_position(const Point2 &p_pos) const; - static Rect3 _calculate_spatial_bounds(const Spatial *p_parent, const Rect3 p_bounds); + static AABB _calculate_spatial_bounds(const Spatial *p_parent, const AABB p_bounds); void _create_preview(const Vector<String> &files) const; void _remove_preview(); bool _cyclical_dependency_exists(const String &p_target_scene_path, Node *p_desired_node); @@ -314,7 +318,7 @@ public: void assign_pending_data_pointers( Spatial *p_preview_node, - Rect3 *p_preview_bounds, + AABB *p_preview_bounds, AcceptDialog *p_accept); Viewport *get_viewport_node() { return viewport; } @@ -327,7 +331,7 @@ class SpatialEditorSelectedItem : public Object { GDCLASS(SpatialEditorSelectedItem, Object); public: - Rect3 aabb; + AABB aabb; Transform original; // original location when moving Transform original_local; Transform last_xform; // last transform @@ -418,7 +422,7 @@ private: bool grid_enable[3]; //should be always visible if true bool grid_enabled; - Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3]; + Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3], scale_plane_gizmo[3]; Ref<SpatialMaterial> gizmo_color[3]; Ref<SpatialMaterial> plane_gizmo_color[3]; Ref<SpatialMaterial> gizmo_hl; @@ -435,7 +439,7 @@ private: // Scene drag and drop support Spatial *preview_node; - Rect3 preview_bounds; + AABB preview_bounds; /* struct Selected { @@ -571,6 +575,7 @@ public: Ref<ArrayMesh> get_move_plane_gizmo(int idx) const { return move_plane_gizmo[idx]; } Ref<ArrayMesh> get_rotate_gizmo(int idx) const { return rotate_gizmo[idx]; } Ref<ArrayMesh> get_scale_gizmo(int idx) const { return scale_gizmo[idx]; } + Ref<ArrayMesh> get_scale_plane_gizmo(int idx) const { return scale_plane_gizmo[idx]; } void update_transform_gizmo(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 8870166dba..48aed0cf6c 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -860,6 +860,7 @@ TextureRegionEditor::TextureRegionEditor(EditorNode *p_editor) { hb_tools->add_child(separator); icon_zoom = memnew(TextureRect); + icon_zoom->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); hb_tools->add_child(icon_zoom); zoom_out = memnew(ToolButton); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 02ead3aee8..7f956b01ff 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -427,7 +427,9 @@ void ThemeEditor::_dialog_cbk() { void ThemeEditor::_theme_menu_cbk(int p_option) { - if (p_option == POPUP_CREATE_EMPTY || p_option == POPUP_CREATE_EDITOR_EMPTY) { + if (p_option == POPUP_CREATE_EMPTY || p_option == POPUP_CREATE_EDITOR_EMPTY || p_option == POPUP_IMPORT_EDITOR_THEME) { + + bool import = (p_option == POPUP_IMPORT_EDITOR_THEME); Ref<Theme> base_theme; @@ -449,21 +451,21 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme->get_icon_list(type, &icons); for (List<StringName>::Element *E = icons.front(); E; E = E->next()) { - theme->set_icon(E->get(), type, Ref<Texture>()); + theme->set_icon(E->get(), type, import ? base_theme->get_icon(E->get(), type) : Ref<Texture>()); } List<StringName> shaders; base_theme->get_shader_list(type, &shaders); for (List<StringName>::Element *E = shaders.front(); E; E = E->next()) { - theme->set_shader(E->get(), type, Ref<Shader>()); + theme->set_shader(E->get(), type, import ? base_theme->get_shader(E->get(), type) : Ref<Shader>()); } List<StringName> styleboxs; base_theme->get_stylebox_list(type, &styleboxs); for (List<StringName>::Element *E = styleboxs.front(); E; E = E->next()) { - theme->set_stylebox(E->get(), type, Ref<StyleBox>()); + theme->set_stylebox(E->get(), type, import ? base_theme->get_stylebox(E->get(), type) : Ref<StyleBox>()); } List<StringName> fonts; @@ -477,14 +479,14 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme->get_color_list(type, &colors); for (List<StringName>::Element *E = colors.front(); E; E = E->next()) { - theme->set_color(E->get(), type, Color()); + theme->set_color(E->get(), type, import ? base_theme->get_color(E->get(), type) : Color()); } List<StringName> constants; base_theme->get_constant_list(type, &constants); for (List<StringName>::Element *E = constants.front(); E; E = E->next()) { - theme->set_constant(E->get(), type, base_theme->get_constant(type, E->get())); + theme->set_constant(E->get(), type, base_theme->get_constant(E->get(), type)); } } } @@ -639,7 +641,7 @@ ThemeEditor::ThemeEditor() { theme_menu->get_popup()->add_separator(); theme_menu->get_popup()->add_item(TTR("Create Empty Template"), POPUP_CREATE_EMPTY); theme_menu->get_popup()->add_item(TTR("Create Empty Editor Template"), POPUP_CREATE_EDITOR_EMPTY); - + theme_menu->get_popup()->add_item(TTR("Create From Current Editor Theme"), POPUP_IMPORT_EDITOR_THEME); add_child(theme_menu); theme_menu->set_position(Vector2(3, 3) * EDSCALE); theme_menu->get_popup()->connect("id_pressed", this, "_theme_menu_cbk"); diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index 16b2da94d1..4d46282ba1 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -69,7 +69,8 @@ class ThemeEditor : public Control { POPUP_REMOVE, POPUP_CLASS_REMOVE, POPUP_CREATE_EMPTY, - POPUP_CREATE_EDITOR_EMPTY + POPUP_CREATE_EDITOR_EMPTY, + POPUP_IMPORT_EDITOR_THEME }; int popup_mode; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 9235dafaa6..ffddd8a3a9 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -363,7 +363,7 @@ PoolVector<Vector2> TileMapEditor::_bucket_fill(const Point2i &p_start, bool era return PoolVector<Vector2>(); } - Rect2i r = node->get_item_rect(); + Rect2i r = node->_edit_get_rect(); r.position = r.position / node->get_cell_size(); r.size = r.size / node->get_cell_size(); @@ -973,7 +973,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Point2i pos = points[i]; - if (!paint_undo.has(over_tile)) { + if (!paint_undo.has(pos)) { paint_undo[pos] = _get_op_from_cell(pos); } @@ -993,7 +993,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { Point2i pos = points[i]; - if (!paint_undo.has(over_tile)) { + if (!paint_undo.has(pos)) { paint_undo[pos] = _get_op_from_cell(pos); } diff --git a/editor/project_export.cpp b/editor/project_export.cpp index eac5720b43..dda2851166 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -308,7 +308,7 @@ void ProjectExportDialog::_patch_button_pressed(Object *p_item, int p_column, in if (p_id == 0) { Vector<String> patches = current->get_patches(); ERR_FAIL_INDEX(patch_index, patches.size()); - patch_erase->set_text(vformat(TTR("Delete patch '" + patches[patch_index].get_file() + "' from list?"))); + patch_erase->set_text(vformat(TTR("Delete patch '%s' from list?"), patches[patch_index].get_file())); patch_erase->popup_centered_minsize(); } else { patch_dialog->popup_centered_ratio(); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 18416868ec..16b85121ef 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -233,7 +233,7 @@ private: fdialog->set_mode(FileDialog::MODE_OPEN_FILE); fdialog->clear_filters(); - fdialog->add_filter("project.godot ; " _MKSTR(VERSION_NAME) " Project"); + fdialog->add_filter("project.godot ; " VERSION_NAME " Project"); } else { fdialog->set_mode(FileDialog::MODE_OPEN_DIR); } @@ -284,7 +284,6 @@ private: } ProjectSettings *current = memnew(ProjectSettings); - current->add_singleton(ProjectSettings::Singleton("Current")); if (current->setup(dir, "")) { set_message(TTR("Couldn't get project.godot in project path."), MESSAGE_ERROR); @@ -503,7 +502,6 @@ public: name_container->show(); ProjectSettings *current = memnew(ProjectSettings); - current->add_singleton(ProjectSettings::Singleton("Current")); if (current->setup(project_path->get_text(), "")) { set_message(TTR("Couldn't get project.godot in the project path."), MESSAGE_ERROR); @@ -1053,7 +1051,7 @@ void ProjectManager::_load_recent_projects() { ec->set_custom_minimum_size(Size2(0, 1)); vb->add_child(ec); Label *title = memnew(Label(project_name)); - title->add_font_override("font", gui_base->get_font("large", "Fonts")); + title->add_font_override("font", gui_base->get_font("title", "EditorFonts")); title->add_color_override("font_color", font_color); title->set_clip_text(true); vb->add_child(title); @@ -1485,14 +1483,13 @@ ProjectManager::ProjectManager() { String cp; cp.push_back(0xA9); cp.push_back(0); - OS::get_singleton()->set_window_title(_MKSTR(VERSION_NAME) + String(" - ") + TTR("Project Manager") + " - " + cp + " 2008-2017 Juan Linietsky, Ariel Manzur & Godot Contributors"); + OS::get_singleton()->set_window_title(VERSION_NAME + String(" - ") + TTR("Project Manager") + " - " + cp + " 2008-2017 Juan Linietsky, Ariel Manzur & Godot Contributors"); HBoxContainer *top_hb = memnew(HBoxContainer); vb->add_child(top_hb); CenterContainer *ccl = memnew(CenterContainer); Label *l = memnew(Label); - l->set_text(_MKSTR(VERSION_NAME) + String(" - ") + TTR("Project Manager")); - l->add_font_override("font", gui_base->get_font("doc", "EditorFonts")); + l->set_text(VERSION_NAME + String(" - ") + TTR("Project Manager")); ccl->add_child(l); top_hb->add_child(ccl); top_hb->add_spacer(); @@ -1501,11 +1498,8 @@ ProjectManager::ProjectManager() { if (hash.length() != 0) hash = "." + hash.left(7); l->set_text("v" VERSION_MKSTRING "" + hash); - //l->add_font_override("font",get_font("bold","Fonts")); l->set_align(Label::ALIGN_CENTER); top_hb->add_child(l); - //vb->add_child(memnew(HSeparator)); - //vb->add_margin_child("\n",memnew(Control)); Control *center_box = memnew(Control); center_box->set_v_size_flags(SIZE_EXPAND_FILL); diff --git a/editor/project_settings_editor.cpp b/editor/project_settings_editor.cpp index b21c176543..b07280a4cd 100644 --- a/editor/project_settings_editor.cpp +++ b/editor/project_settings_editor.cpp @@ -785,12 +785,12 @@ void ProjectSettingsEditor::_item_del() { String property = globals_editor->get_current_section().plus_file(path); if (!ProjectSettings::get_singleton()->has_setting(property)) { - EditorNode::get_singleton()->show_warning(TTR("No property '" + property + "' exists.")); + EditorNode::get_singleton()->show_warning(vformat(TTR("No property '%s' exists."), property)); return; } if (ProjectSettings::get_singleton()->get_order(property) < ProjectSettings::NO_BUILTIN_ORDER_BASE) { - EditorNode::get_singleton()->show_warning(TTR("Setting '" + property + "' is internal, and it can't be deleted.")); + EditorNode::get_singleton()->show_warning(vformat(TTR("Setting '%s' is internal, and it can't be deleted."), property)); return; } @@ -1318,7 +1318,7 @@ void ProjectSettingsEditor::_update_translations() { t->set_text(0, translations[i].replace_first("res://", "")); t->set_tooltip(0, translations[i]); t->set_metadata(0, i); - t->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove")); + t->add_button(0, get_icon("Remove", "EditorIcons"), 0, false, TTR("Remove")); } } @@ -1436,7 +1436,7 @@ void ProjectSettingsEditor::_update_translations() { t->set_text(0, keys[i].replace_first("res://", "")); t->set_tooltip(0, keys[i]); t->set_metadata(0, keys[i]); - t->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove")); + t->add_button(0, get_icon("Remove", "EditorIcons"), 0, false, TTR("Remove")); if (keys[i] == remap_selected) { t->select(0); translation_res_option_add_button->set_disabled(false); @@ -1454,7 +1454,7 @@ void ProjectSettingsEditor::_update_translations() { t2->set_text(0, path.replace_first("res://", "")); t2->set_tooltip(0, path); t2->set_metadata(0, j); - t2->add_button(0, get_icon("Del", "EditorIcons"), 0, false, TTR("Remove")); + t2->add_button(0, get_icon("Remove", "EditorIcons"), 0, false, TTR("Remove")); t2->set_cell_mode(1, TreeItem::CELL_MODE_RANGE); t2->set_text(1, langnames); t2->set_editable(1, true); @@ -1782,6 +1782,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) { tab_container->add_child(translations); //remap for properly select language in popup translation_locales_idxs_remap = Vector<int>(); + translation_locales_list_created = false; { diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index f4d5530faa..5136c96cbf 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -755,7 +755,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: value_editor[3]->set_text(String::num(q.w)); } break; - case Variant::RECT3: { + case Variant::AABB: { field_names.push_back("px"); field_names.push_back("py"); @@ -765,7 +765,7 @@ bool CustomPropertyEditor::edit(Object *p_owner, const String &p_name, Variant:: field_names.push_back("sz"); config_value_editors(6, 3, 16, field_names); - Rect3 aabb = v; + AABB aabb = v; value_editor[0]->set_text(String::num(aabb.position.x)); value_editor[1]->set_text(String::num(aabb.position.y)); value_editor[2]->set_text(String::num(aabb.position.z)); @@ -1585,7 +1585,7 @@ void CustomPropertyEditor::_modified(String p_string) { _emit_changed_whole_or_field(); } break; - case Variant::RECT3: { + case Variant::AABB: { Vector3 pos; Vector3 size; @@ -1605,7 +1605,7 @@ void CustomPropertyEditor::_modified(String p_string) { size.y = value_editor[4]->get_text().to_double(); size.z = value_editor[5]->get_text().to_double(); } - v = Rect3(pos, size); + v = AABB(pos, size); _emit_changed_whole_or_field(); } break; @@ -1727,7 +1727,7 @@ void CustomPropertyEditor::_focus_enter() { case Variant::VECTOR3: case Variant::PLANE: case Variant::QUAT: - case Variant::RECT3: + case Variant::AABB: case Variant::TRANSFORM2D: case Variant::BASIS: case Variant::TRANSFORM: { @@ -1752,7 +1752,7 @@ void CustomPropertyEditor::_focus_exit() { case Variant::VECTOR3: case Variant::PLANE: case Variant::QUAT: - case Variant::RECT3: + case Variant::AABB: case Variant::TRANSFORM2D: case Variant::BASIS: case Variant::TRANSFORM: { @@ -2238,7 +2238,7 @@ void PropertyEditor::set_item_text(TreeItem *p_item, int p_type, const String &p case Variant::VECTOR3: case Variant::QUAT: case Variant::VECTOR2: - case Variant::RECT3: + case Variant::AABB: case Variant::RECT2: case Variant::TRANSFORM2D: case Variant::BASIS: @@ -3367,13 +3367,13 @@ void PropertyEditor::update_tree() { item->set_icon(0, get_icon("Plane", "EditorIcons")); } break; - case Variant::RECT3: { + case Variant::AABB: { item->set_cell_mode(1, TreeItem::CELL_MODE_CUSTOM); item->set_editable(1, true); - item->set_text(1, "Rect3"); + item->set_text(1, "AABB"); if (show_type_icons) - item->set_icon(0, get_icon("Rect3", "EditorIcons")); + item->set_icon(0, get_icon("AABB", "EditorIcons")); } break; case Variant::QUAT: { @@ -3714,7 +3714,7 @@ void PropertyEditor::_item_edited() { _edit_set(name, item->get_text(1), refresh_all); } } break; - // math types + // math types case Variant::VECTOR3: { @@ -3725,7 +3725,7 @@ void PropertyEditor::_item_edited() { case Variant::QUAT: { } break; - case Variant::RECT3: { + case Variant::AABB: { } break; case Variant::BASIS: { @@ -4258,7 +4258,7 @@ PropertyEditor::PropertyEditor() { use_filter = false; subsection_selectable = false; property_selectable = false; - show_type_icons = EDITOR_DEF("interface/editor/show_type_icons", false); + show_type_icons = false; // maybe one day will return. } PropertyEditor::~PropertyEditor() { diff --git a/editor/pvrtc_compress.cpp b/editor/pvrtc_compress.cpp index 13d74a6593..575ff40287 100644 --- a/editor/pvrtc_compress.cpp +++ b/editor/pvrtc_compress.cpp @@ -62,12 +62,12 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) { } return; } - String spath = EditorSettings::get_singleton()->get_settings_path(); + String tmppath = EditorSettings::get_singleton()->get_cache_dir(); List<String> args; - String src_img = spath + "/" + "_tmp_src_img.png"; - String dst_img = spath + "/" + "_tmp_dst_img.pvr"; + String src_img = tmppath.plus_file("_tmp_src_img.png"); + String dst_img = tmppath.plus_file("_tmp_dst_img.pvr"); args.push_back("-i"); args.push_back(src_img); diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 7438c7671e..f866a158f3 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -443,8 +443,8 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { List<Node *> owned; node->get_owned_by(node->get_owner(), &owned); - Map<Node *, Node *> duplimap; - Node *dup = _duplicate(node, duplimap); + Map<const Node *, Node *> duplimap; + Node *dup = node->duplicate_from_editor(duplimap); ERR_CONTINUE(!dup); @@ -533,10 +533,6 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { if (p_confirm_override) { _delete_confirm(); - // hack, force 2d editor viewport to refresh after deletion - if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) - editor->get_viewport_control()->update(); - } else { delete_dialog->set_text(TTR("Delete Node(s)?")); delete_dialog->popup_centered_minsize(); @@ -825,74 +821,6 @@ void SceneTreeDock::_node_renamed() { _node_selected(); } -Node *SceneTreeDock::_duplicate(Node *p_node, Map<Node *, Node *> &duplimap) { - - Node *node = NULL; - - if (p_node->get_filename() != "") { //an instance - - Ref<PackedScene> sd = ResourceLoader::load(p_node->get_filename()); - ERR_FAIL_COND_V(!sd.is_valid(), NULL); - node = sd->instance(PackedScene::GEN_EDIT_STATE_INSTANCE); - ERR_FAIL_COND_V(!node, NULL); - node->set_scene_instance_load_placeholder(p_node->get_scene_instance_load_placeholder()); - } else { - Object *obj = ClassDB::instance(p_node->get_class()); - ERR_FAIL_COND_V(!obj, NULL); - node = Object::cast_to<Node>(obj); - if (!node) - memdelete(obj); - ERR_FAIL_COND_V(!node, NULL); - } - - List<PropertyInfo> plist; - - p_node->get_property_list(&plist); - - for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - - if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) - continue; - String name = E->get().name; - Variant value = p_node->get(name); - // Duplicate dictionaries and arrays, mainly needed for __meta__ - if (value.get_type() == Variant::DICTIONARY) { - value = Dictionary(value).copy(); - } else if (value.get_type() == Variant::ARRAY) { - value = Array(value).duplicate(); - } - node->set(name, value); - } - - List<Node::GroupInfo> group_info; - p_node->get_groups(&group_info); - for (List<Node::GroupInfo>::Element *E = group_info.front(); E; E = E->next()) { - - if (E->get().persistent) - node->add_to_group(E->get().name, true); - } - - node->set_name(p_node->get_name()); - duplimap[p_node] = node; - - for (int i = 0; i < p_node->get_child_count(); i++) { - - Node *child = p_node->get_child(i); - if (p_node->get_owner() != child->get_owner()) - continue; //don't bother with not in-scene nodes. - - Node *dup = _duplicate(child, duplimap); - if (!dup) { - memdelete(node); - return NULL; - } - - node->add_child(dup); - } - - return node; -} - void SceneTreeDock::_set_owners(Node *p_owner, const Array &p_nodes) { for (int i = 0; i < p_nodes.size(); i++) { @@ -1300,6 +1228,7 @@ void SceneTreeDock::_delete_confirm() { editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", (Object *)NULL); editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", edited_scene); editor_data->get_undo_redo().add_undo_method(edited_scene, "set_owner", edited_scene->get_owner()); + editor_data->get_undo_redo().add_undo_method(scene_tree, "update_tree"); editor_data->get_undo_redo().add_undo_reference(edited_scene); } else { @@ -1345,6 +1274,12 @@ void SceneTreeDock::_delete_confirm() { } } editor_data->get_undo_redo().commit_action(); + + // hack, force 2d editor viewport to refresh after deletion + if (CanvasItemEditor *editor = CanvasItemEditor::get_singleton()) + editor->get_viewport_control()->update(); + + editor->push_item(NULL); } void SceneTreeDock::_selection_changed() { @@ -1412,6 +1347,7 @@ void SceneTreeDock::_create() { } else { editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child); + editor_data->get_undo_redo().add_do_method(scene_tree, "update_tree"); editor_data->get_undo_redo().add_do_reference(child); editor_data->get_undo_redo().add_undo_method(editor, "set_edited_scene", (Object *)NULL); } @@ -1447,6 +1383,8 @@ void SceneTreeDock::_create() { for (List<PropertyInfo>::Element *E = pinfo.front(); E; E = E->next()) { if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; + if (E->get().name == "__meta__") + continue; newnode->set(E->get().name, n->get(E->get().name)); } @@ -1876,6 +1814,43 @@ void SceneTreeDock::open_script_dialog(Node *p_for_node) { _tool_selected(TOOL_ATTACH_SCRIPT); } +void SceneTreeDock::add_remote_tree_editor(Control *p_remote) { + ERR_FAIL_COND(remote_tree != NULL); + add_child(p_remote); + remote_tree = p_remote; + remote_tree->hide(); +} + +void SceneTreeDock::show_remote_tree() { + + button_hb->show(); + _remote_tree_selected(); +} + +void SceneTreeDock::hide_remote_tree() { + + button_hb->hide(); + _local_tree_selected(); +} + +void SceneTreeDock::_remote_tree_selected() { + + scene_tree->hide(); + if (remote_tree) + remote_tree->show(); + edit_remote->set_pressed(true); + edit_local->set_pressed(false); +} + +void SceneTreeDock::_local_tree_selected() { + + scene_tree->show(); + if (remote_tree) + remote_tree->hide(); + edit_remote->set_pressed(false); + edit_local->set_pressed(true); +} + void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_tool_selected"), &SceneTreeDock::_tool_selected, DEFVAL(false)); @@ -1901,6 +1876,8 @@ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_tree_rmb"), &SceneTreeDock::_tree_rmb); ClassDB::bind_method(D_METHOD("_filter_changed"), &SceneTreeDock::_filter_changed); ClassDB::bind_method(D_METHOD("_focus_node"), &SceneTreeDock::_focus_node); + ClassDB::bind_method(D_METHOD("_remote_tree_selected"), &SceneTreeDock::_remote_tree_selected); + ClassDB::bind_method(D_METHOD("_local_tree_selected"), &SceneTreeDock::_local_tree_selected); ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance); } @@ -1971,7 +1948,28 @@ SceneTreeDock::SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSel button_clear_script = tb; tb->hide(); + button_hb = memnew(HBoxContainer); + vbc->add_child(button_hb); + + edit_remote = memnew(ToolButton); + button_hb->add_child(edit_remote); + edit_remote->set_h_size_flags(SIZE_EXPAND_FILL); + edit_remote->set_text(TTR("Remote")); + edit_remote->set_toggle_mode(true); + edit_remote->connect("pressed", this, "_remote_tree_selected"); + + edit_local = memnew(ToolButton); + button_hb->add_child(edit_local); + edit_local->set_h_size_flags(SIZE_EXPAND_FILL); + edit_local->set_text(TTR("Local")); + edit_local->set_toggle_mode(true); + edit_local->connect("pressed", this, "_local_tree_selected"); + + remote_tree = NULL; + button_hb->hide(); + scene_tree = memnew(SceneTreeEditor(false, true, true)); + vbc->add_child(scene_tree); scene_tree->set_v_size_flags(SIZE_EXPAND | SIZE_FILL); scene_tree->connect("rmb_pressed", this, "_tree_rmb"); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index f61c67bb13..7848052241 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -95,7 +95,10 @@ class SceneTreeDock : public VBoxContainer { ToolButton *button_create_script; ToolButton *button_clear_script; + HBoxContainer *button_hb; + ToolButton *edit_local, *edit_remote; SceneTreeEditor *scene_tree; + Control *remote_tree; HBoxContainer *tool_hbc; void _tool_selected(int p_tool, bool p_confirm_override = false); @@ -127,7 +130,6 @@ class SceneTreeDock : public VBoxContainer { void _add_children_to_popup(Object *p_obj, int p_depth); - Node *_duplicate(Node *p_node, Map<Node *, Node *> &duplimap); void _node_reparent(NodePath p_path, bool p_keep_global_xform); void _do_reparent(Node *p_new_parent, int p_position_in_parent, Vector<Node *> p_nodes, bool p_keep_global_xform); @@ -174,6 +176,9 @@ class SceneTreeDock : public VBoxContainer { void _file_selected(String p_file); + void _remote_tree_selected(); + void _local_tree_selected(); + protected: void _notification(int p_what); static void _bind_methods(); @@ -194,6 +199,10 @@ public: SceneTreeEditor *get_tree_editor() { return scene_tree; } EditorData *get_editor_data() { return editor_data; } + void add_remote_tree_editor(Control *p_remote); + void show_remote_tree(); + void hide_remote_tree(); + void open_script_dialog(Node *p_for_node); SceneTreeDock(EditorNode *p_editor, Node *p_scene_root, EditorSelection *p_editor_selection, EditorData &p_editor_data); }; diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index a6e0af05b2..c4b86c6b2b 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -354,7 +354,11 @@ void SceneTreeEditor::_update_visibility_color(Node *p_node, TreeItem *p_item) { void SceneTreeEditor::_node_script_changed(Node *p_node) { - _update_tree(); + if (tree_dirty) + return; + + MessageQueue::get_singleton()->push_call(this, "_update_tree"); + tree_dirty = true; /* changes the order :| TreeItem* item=p_node?_find(tree->get_root(),p_node->get_path()):NULL; diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index c19b80e649..3cab14b0c4 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -128,7 +128,7 @@ void ScriptCreateDialog::_template_changed(int p_template) { } String ext = ScriptServer::get_language(language_menu->get_selected())->get_extension(); String name = template_list[p_template - 1] + "." + ext; - script_template = EditorSettings::get_singleton()->get_settings_path() + "/script_templates/" + name; + script_template = EditorSettings::get_singleton()->get_script_templates_dir().plus_file(name); } void ScriptCreateDialog::ok_pressed() { @@ -703,9 +703,7 @@ ScriptCreateDialog::ScriptCreateDialog() { internal = memnew(CheckButton); internal->connect("pressed", this, "_built_in_pressed"); hb = memnew(HBoxContainer); - Control *empty = memnew(Control); hb->add_child(internal); - hb->add_child(empty); l = memnew(Label); l->set_text(TTR("Built-in Script")); l->set_align(Label::ALIGN_RIGHT); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index 3f8d93d976..3ffc61cb45 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -149,7 +149,7 @@ void EditorSpatialGizmo::add_lines(const Vector<Vector3> &p_lines, const Ref<Mat md = MAX(0, p_lines[i].length()); } if (md) { - mesh->set_custom_aabb(Rect3(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); + mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); } } @@ -196,7 +196,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, md = MAX(0, vs[i].length()); } if (md) { - mesh->set_custom_aabb(Rect3(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); + mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); } } @@ -211,7 +211,7 @@ void EditorSpatialGizmo::add_unscaled_billboard(const Ref<Material> &p_material, instances.push_back(ins); } -void EditorSpatialGizmo::add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const Rect3 &p_bounds) { +void EditorSpatialGizmo::add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const AABB &p_bounds) { collision_mesh = p_tmesh; collision_mesh_bounds = p_bounds; @@ -270,7 +270,7 @@ void EditorSpatialGizmo::add_handles(const Vector<Vector3> &p_handles, bool p_bi md = MAX(0, p_handles[i].length()); } if (md) { - mesh->set_custom_aabb(Rect3(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); + mesh->set_custom_aabb(AABB(Vector3(-md, -md, -md), Vector3(md, md, md) * 2.0)); } } @@ -1274,7 +1274,7 @@ void MeshInstanceSpatialGizmo::redraw() { Ref<TriangleMesh> tm = m->generate_triangle_mesh(); if (tm.is_valid()) { - Rect3 aabb; + AABB aabb; add_collision_triangles(tm, aabb); } } @@ -1336,7 +1336,7 @@ void SkeletonSpatialGizmo::redraw() { weights[0] = 1; - Rect3 aabb; + AABB aabb; Color bonecolor = Color(1.0, 0.4, 0.4, 0.3); Color rootcolor = Color(0.4, 1.0, 0.4, 0.1); @@ -1961,7 +1961,7 @@ void CollisionShapeSpatialGizmo::redraw() { Ref<BoxShape> bs = s; Vector<Vector3> lines; - Rect3 aabb; + AABB aabb; aabb.position = -bs->get_extents(); aabb.size = aabb.position * -2; @@ -2191,7 +2191,7 @@ void VisibilityNotifierGizmo::set_handle(int p_idx, Camera *p_camera, const Poin //gt.orthonormalize(); Transform gi = gt.affine_inverse(); - Rect3 aabb = notifier->get_aabb(); + AABB aabb = notifier->get_aabb(); Vector3 ray_from = p_camera->project_ray_origin(p_point); Vector3 ray_dir = p_camera->project_ray_normal(p_point); @@ -2234,7 +2234,7 @@ void VisibilityNotifierGizmo::redraw() { clear(); Vector<Vector3> lines; - Rect3 aabb = notifier->get_aabb(); + AABB aabb = notifier->get_aabb(); for (int i = 0; i < 12; i++) { Vector3 a, b; @@ -2293,7 +2293,7 @@ void ParticlesGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_poi bool move = p_idx >= 3; p_idx = p_idx % 3; - Rect3 aabb = particles->get_visibility_aabb(); + AABB aabb = particles->get_visibility_aabb(); Vector3 ray_from = p_camera->project_ray_origin(p_point); Vector3 ray_dir = p_camera->project_ray_normal(p_point); @@ -2347,7 +2347,7 @@ void ParticlesGizmo::redraw() { clear(); Vector<Vector3> lines; - Rect3 aabb = particles->get_visibility_aabb(); + AABB aabb = particles->get_visibility_aabb(); for (int i = 0; i < 12; i++) { Vector3 a, b; @@ -2420,7 +2420,7 @@ String ReflectionProbeGizmo::get_handle_name(int p_idx) const { } Variant ReflectionProbeGizmo::get_handle_value(int p_idx) const { - return Rect3(probe->get_extents(), probe->get_origin_offset()); + return AABB(probe->get_extents(), probe->get_origin_offset()); } void ReflectionProbeGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 &p_point) { @@ -2474,7 +2474,7 @@ void ReflectionProbeGizmo::set_handle(int p_idx, Camera *p_camera, const Point2 void ReflectionProbeGizmo::commit_handle(int p_idx, const Variant &p_restore, bool p_cancel) { - Rect3 restore = p_restore; + AABB restore = p_restore; if (p_cancel) { probe->set_extents(restore.position); @@ -2499,7 +2499,7 @@ void ReflectionProbeGizmo::redraw() { Vector<Vector3> internal_lines; Vector3 extents = probe->get_extents(); - Rect3 aabb; + AABB aabb; aabb.position = -extents; aabb.size = extents * 2; @@ -2641,7 +2641,7 @@ void GIProbeGizmo::redraw() { static const int subdivs[GIProbe::SUBDIV_MAX] = { 64, 128, 256, 512 }; - Rect3 aabb = Rect3(-extents, extents * 2); + AABB aabb = AABB(-extents, extents * 2); int subdiv = subdivs[probe->get_subdiv()]; float cell_size = aabb.get_longest_axis_size() / subdiv; diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index afe64c723c..751bad2b13 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -78,7 +78,7 @@ class EditorSpatialGizmo : public SpatialEditorGizmo { Vector<Vector3> collision_segments; Ref<TriangleMesh> collision_mesh; - Rect3 collision_mesh_bounds; + AABB collision_mesh_bounds; struct Handle { Vector3 pos; @@ -100,7 +100,7 @@ protected: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false); void add_mesh(const Ref<ArrayMesh> &p_mesh, bool p_billboard = false, const RID &p_skeleton = RID()); void add_collision_segments(const Vector<Vector3> &p_lines); - void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const Rect3 &p_bounds = Rect3()); + void add_collision_triangles(const Ref<TriangleMesh> &p_tmesh, const AABB &p_bounds = AABB()); void add_unscaled_billboard(const Ref<Material> &p_material, float p_scale = 1); void add_handles(const Vector<Vector3> &p_handles, bool p_billboard = false, bool p_secondary = false); void add_solid_box(Ref<Material> &p_material, Vector3 size); |