diff options
Diffstat (limited to 'editor')
117 files changed, 2298 insertions, 1773 deletions
diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 9b376ae090..c93dc2b340 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -31,6 +31,7 @@ #include "animation_track_editor.h" #include "animation_track_editor_plugins.h" +#include "core/os/input.h" #include "core/os/keyboard.h" #include "editor/animation_bezier_editor.h" #include "editor/plugins/animation_player_editor_plugin.h" @@ -1747,7 +1748,11 @@ void AnimationTimelineEdit::_play_position_draw() { if (px >= get_name_limit() && px < (play_position->get_size().width - get_buttons_width())) { Color color = get_color("accent_color", "Editor"); - play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(EDSCALE)); + play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE)); + play_position->draw_texture( + get_icon("TimelineIndicator", "EditorIcons"), + Point2(px - get_icon("TimelineIndicator", "EditorIcons")->get_width() * 0.5, 0), + color); } } @@ -2437,7 +2442,7 @@ void AnimationTrackEdit::_play_position_draw() { if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) { Color color = get_color("accent_color", "Editor"); - play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(EDSCALE)); + play_position->draw_line(Point2(px, 0), Point2(px, h), color, Math::round(2 * EDSCALE)); } } @@ -3183,7 +3188,7 @@ void AnimationTrackEditGroup::_notification(int p_what) { if (px >= timeline->get_name_limit() && px < (get_size().width - timeline->get_buttons_width())) { Color accent = get_color("accent_color", "Editor"); - draw_line(Point2(px, 0), Point2(px, get_size().height), accent, Math::round(EDSCALE)); + draw_line(Point2(px, 0), Point2(px, get_size().height), accent, Math::round(2 * EDSCALE)); } } } @@ -4082,6 +4087,10 @@ bool AnimationTrackEditor::is_selection_active() const { return selection.size(); } +bool AnimationTrackEditor::is_snap_enabled() const { + return snap->is_pressed() ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); +} + void AnimationTrackEditor::_update_tracks() { int selected = _get_track_selected(); @@ -5045,10 +5054,9 @@ float AnimationTrackEditor::get_moving_selection_offset() const { void AnimationTrackEditor::_box_selection_draw() { - Color color = get_color("accent_color", "Editor"); - color.a = 0.2; - Rect2 rect = Rect2(Point2(), box_selection->get_size()); - box_selection->draw_rect(rect, color); + const Rect2 selection_rect = Rect2(Point2(), box_selection->get_size()); + box_selection->draw_rect(selection_rect, get_color("box_selection_fill_color", "Editor")); + box_selection->draw_rect(selection_rect, get_color("box_selection_stroke_color", "Editor"), false, Math::round(EDSCALE)); } void AnimationTrackEditor::_scroll_input(const Ref<InputEvent> &p_event) { @@ -5679,7 +5687,7 @@ void AnimationTrackEditor::_selection_changed() { float AnimationTrackEditor::snap_time(float p_value) { - if (snap->is_pressed()) { + if (is_snap_enabled()) { double snap_increment; if (timeline->is_using_fps() && step->get_value() > 0) @@ -5857,7 +5865,7 @@ AnimationTrackEditor::AnimationTrackEditor() { step = memnew(EditorSpinSlider); step->set_min(0); step->set_max(1000000); - step->set_step(0.01); + step->set_step(0.001); step->set_hide_slider(true); step->set_custom_minimum_size(Size2(100, 0) * EDSCALE); step->set_tooltip(TTR("Animation step value.")); diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 9e16f2faf7..96fd10effd 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -520,8 +520,8 @@ public: bool is_key_selected(int p_track, int p_key) const; bool is_selection_active() const; bool is_moving_selection() const; + bool is_snap_enabled() const; float get_moving_selection_offset() const; - bool is_snap_enabled(); float snap_time(float p_value); bool is_grouping_tracks(); diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 89a88dc6e7..61adff7c9c 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -163,16 +163,17 @@ bool FindReplaceBar::_search(uint32_t p_flags, int p_from_line, int p_from_col) result_col = col; _update_results_count(); - set_error(vformat(TTR("Found %d match(es)."), results_count)); } else { + results_count = 0; result_line = -1; result_col = -1; text_edit->set_search_text(""); text_edit->set_search_flags(p_flags); text_edit->set_current_search_result(line, col); - set_error(text.empty() ? "" : TTR("No Matches")); } + _update_matches_label(); + return found; } @@ -196,7 +197,7 @@ void FindReplaceBar::_replace() { void FindReplaceBar::_replace_all() { text_edit->disconnect("text_changed", this, "_editor_text_changed"); - // line as x so it gets priority in comparison, column as y + // Line as x so it gets priority in comparison, column as y. Point2i orig_cursor(text_edit->cursor_get_line(), text_edit->cursor_get_column()); Point2i prev_match = Point2(-1, -1); @@ -228,7 +229,7 @@ void FindReplaceBar::_replace_all() { Point2i match_to(result_line, result_col + search_text_len); if (match_from < prev_match) { - break; // done + break; // Done. } prev_match = Point2i(result_line, result_col + replace_text.length()); @@ -241,14 +242,14 @@ void FindReplaceBar::_replace_all() { continue; } - // replace but adjust selection bounds + // Replace but adjust selection bounds. text_edit->insert_text_at_cursor(replace_text); if (match_to.x == selection_end.x) { selection_end.y += replace_text.length() - search_text_len; } } else { - // just replace + // Just replace. text_edit->insert_text_at_cursor(replace_text); } @@ -260,12 +261,12 @@ void FindReplaceBar::_replace_all() { replace_all_mode = false; - // restore editor state (selection, cursor, scroll) + // Restore editor state (selection, cursor, scroll). text_edit->cursor_set_line(orig_cursor.x); text_edit->cursor_set_column(orig_cursor.y); if (selection_enabled && is_selection_only()) { - // reselect + // Reselect. text_edit->select(selection_begin.x, selection_begin.y, selection_end.x, selection_end.y); } else { text_edit->deselect(); @@ -283,20 +284,6 @@ void FindReplaceBar::_get_search_from(int &r_line, int &r_col) { r_line = text_edit->cursor_get_line(); r_col = text_edit->cursor_get_column(); - if (text_edit->is_selection_active() && !replace_all_mode) { - - int selection_line = text_edit->get_selection_from_line(); - - if (text_edit->get_selection_text() == get_search_text() && r_line == selection_line) { - - int selection_from_col = text_edit->get_selection_from_column(); - - if (r_col >= selection_from_col && r_col <= text_edit->get_selection_to_column()) { - r_col = selection_from_col; - } - } - } - if (r_line == result_line && r_col >= result_col && r_col <= result_col + get_search_text().length()) { r_col = result_col; } @@ -332,6 +319,18 @@ void FindReplaceBar::_update_results_count() { } } +void FindReplaceBar::_update_matches_label() { + + if (search_text->get_text().empty() || results_count == -1) { + matches_label->hide(); + } else { + matches_label->show(); + + matches_label->add_color_override("font_color", results_count > 0 ? Color(1, 1, 1) : EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); + } +} + bool FindReplaceBar::search_current() { uint32_t flags = 0; @@ -349,6 +348,9 @@ bool FindReplaceBar::search_current() { bool FindReplaceBar::search_prev() { + if (!is_visible()) + popup_search(true); + uint32_t flags = 0; String text = get_search_text(); @@ -361,13 +363,17 @@ bool FindReplaceBar::search_prev() { int line, col; _get_search_from(line, col); + if (text_edit->is_selection_active()) + col--; // Skip currently selected word. - col -= text.length(); - if (col < 0) { - line -= 1; - if (line < 0) - line = text_edit->get_line_count() - 1; - col = text_edit->get_line(line).length(); + if (line == result_line && col == result_col) { + col -= text.length(); + if (col < 0) { + line -= 1; + if (line < 0) + line = text_edit->get_line_count() - 1; + col = text_edit->get_line(line).length(); + } } return _search(flags, line, col); @@ -375,6 +381,9 @@ bool FindReplaceBar::search_prev() { bool FindReplaceBar::search_next() { + if (!is_visible()) + popup_search(true); + uint32_t flags = 0; String text; if (replace_all_mode) @@ -411,38 +420,54 @@ void FindReplaceBar::_hide_bar() { text_edit->set_search_text(""); result_line = -1; result_col = -1; - set_error(""); hide(); } -void FindReplaceBar::_show_search() { +void FindReplaceBar::_show_search(bool p_focus_replace, bool p_show_only) { show(); - search_text->call_deferred("grab_focus"); + if (p_show_only) + return; + + if (p_focus_replace) { + search_text->deselect(); + replace_text->call_deferred("grab_focus"); + } else { + replace_text->deselect(); + search_text->call_deferred("grab_focus"); + } if (text_edit->is_selection_active() && !selection_only->is_pressed()) { search_text->set_text(text_edit->get_selection_text()); } if (!get_search_text().empty()) { - search_text->select_all(); - search_text->set_cursor_position(search_text->get_text().length()); - search_current(); + if (p_focus_replace) { + replace_text->select_all(); + replace_text->set_cursor_position(replace_text->get_text().length()); + } else { + search_text->select_all(); + search_text->set_cursor_position(search_text->get_text().length()); + } + + results_count = -1; + _update_results_count(); + _update_matches_label(); } } -void FindReplaceBar::popup_search() { +void FindReplaceBar::popup_search(bool p_show_only) { - replace_text->hide(); + if (!is_visible()) + replace_text->hide(); hbc_button_replace->hide(); hbc_option_replace->hide(); - _show_search(); + _show_search(false, p_show_only); } void FindReplaceBar::popup_replace() { if (!replace_text->is_visible_in_tree()) { - replace_text->clear(); replace_text->show(); hbc_button_replace->show(); hbc_option_replace->show(); @@ -450,7 +475,7 @@ void FindReplaceBar::popup_replace() { selection_only->set_pressed((text_edit->is_selection_active() && text_edit->get_selection_from_line() < text_edit->get_selection_to_line())); - _show_search(); + _show_search(is_visible() || text_edit->is_selection_active()); } void FindReplaceBar::_search_options_changed(bool p_pressed) { @@ -557,6 +582,7 @@ FindReplaceBar::FindReplaceBar() { vbc_lineedit = memnew(VBoxContainer); add_child(vbc_lineedit); + vbc_lineedit->set_alignment(ALIGN_CENTER); vbc_lineedit->set_h_size_flags(SIZE_EXPAND_FILL); VBoxContainer *vbc_button = memnew(VBoxContainer); add_child(vbc_button); @@ -565,8 +591,10 @@ FindReplaceBar::FindReplaceBar() { HBoxContainer *hbc_button_search = memnew(HBoxContainer); vbc_button->add_child(hbc_button_search); + hbc_button_search->set_alignment(ALIGN_END); hbc_button_replace = memnew(HBoxContainer); vbc_button->add_child(hbc_button_replace); + hbc_button_replace->set_alignment(ALIGN_END); HBoxContainer *hbc_option_search = memnew(HBoxContainer); vbc_option->add_child(hbc_option_search); @@ -580,6 +608,10 @@ FindReplaceBar::FindReplaceBar() { search_text->connect("text_changed", this, "_search_text_changed"); search_text->connect("text_entered", this, "_search_text_entered"); + matches_label = memnew(Label); + hbc_button_search->add_child(matches_label); + matches_label->hide(); + find_prev = memnew(ToolButton); hbc_button_search->add_child(find_prev); find_prev->set_focus_mode(FOCUS_NONE); @@ -720,7 +752,7 @@ void CodeTextEditor::_zoom_changed() { } void CodeTextEditor::_reset_zoom() { - Ref<DynamicFont> font = text_editor->get_font("font"); // reset source font size to default + Ref<DynamicFont> font = text_editor->get_font("font"); // Reset source font size to default. if (font.is_valid()) { EditorSettings::get_singleton()->set("interface/editor/code_font_size", 14); @@ -876,6 +908,8 @@ void CodeTextEditor::update_editor_settings() { 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->set_wrap_enabled(EditorSettings::get_singleton()->get("text_editor/line_numbers/word_wrap")); + text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/line_numbers/draw_minimap")); + text_editor->set_minimap_width(EditorSettings::get_singleton()->get("text_editor/line_numbers/minimap_width")); text_editor->set_draw_info_gutter(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_info_gutter")); 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")); @@ -1230,7 +1264,7 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { int col_to = text_editor->get_selection_to_column(); int cursor_pos = text_editor->cursor_get_column(); - // Check if all lines in the selected block are commented + // Check if all lines in the selected block are commented. bool is_commented = true; for (int i = begin; i <= end; i++) { if (!text_editor->get_line(i).begins_with(delimiter)) { @@ -1425,14 +1459,14 @@ void CodeTextEditor::_on_settings_change() { font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); - // AUTO BRACE COMPLETION + // Auto brace completion. text_editor->set_auto_brace_completion( EDITOR_GET("text_editor/completion/auto_brace_complete")); code_complete_timer->set_wait_time( EDITOR_GET("text_editor/completion/code_complete_delay")); - // call hint settings + // Call hint settings. text_editor->set_callhint_settings( EDITOR_GET("text_editor/completion/put_callhint_tooltip_below_current_line"), EDITOR_GET("text_editor/completion/callhint_tooltip_offset")); diff --git a/editor/code_editor.h b/editor/code_editor.h index 700e72627c..f2a55cfb70 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -64,6 +64,7 @@ class FindReplaceBar : public HBoxContainer { GDCLASS(FindReplaceBar, HBoxContainer); LineEdit *search_text; + Label *matches_label; ToolButton *find_prev; ToolButton *find_next; CheckBox *case_sensitive; @@ -90,8 +91,9 @@ class FindReplaceBar : public HBoxContainer { void _get_search_from(int &r_line, int &r_col); void _update_results_count(); + void _update_matches_label(); - void _show_search(); + void _show_search(bool p_focus_replace = false, bool p_show_only = false); void _hide_bar(); void _editor_text_changed(); @@ -123,7 +125,7 @@ public: void set_text_edit(TextEdit *p_text_edit); - void popup_search(); + void popup_search(bool p_show_only = false); void popup_replace(); bool search_current(); diff --git a/editor/collada/collada.cpp b/editor/collada/collada.cpp index 57c00e1bef..aea7f461f1 100644 --- a/editor/collada/collada.cpp +++ b/editor/collada/collada.cpp @@ -1696,7 +1696,7 @@ Collada::Node *Collada::_parse_visual_scene_node(XMLParser &parser) { } } - } else if (section == "node") { + } else { /* Found a child node!! what to do..*/ @@ -1903,8 +1903,7 @@ void Collada::_parse_animation(XMLParser &parser) { Vector<float> &output = float_sources[output_id]; - ERR_EXPLAIN("Wrong number of keys in output"); - ERR_CONTINUE((output.size() / stride) != key_count); + ERR_CONTINUE_MSG((output.size() / stride) != key_count, "Wrong number of keys in output."); for (int j = 0; j < key_count; j++) { track.keys.write[j].data.resize(output_len); @@ -2447,8 +2446,7 @@ void Collada::_find_morph_nodes(VisualScene *p_vscene, Node *p_node) { state.morph_ownership_map[base] = nj->id; break; } else { - ERR_EXPLAIN("Invalid scene"); - ERR_FAIL(); + ERR_FAIL_MSG("Invalid scene."); } } } diff --git a/editor/connections_dialog.cpp b/editor/connections_dialog.cpp index 48bc409b73..c5b81c4685 100644 --- a/editor/connections_dialog.cpp +++ b/editor/connections_dialog.cpp @@ -881,7 +881,6 @@ void ConnectionsDock::update_tree() { icon = get_icon(scr->get_class(), "EditorIcons"); } } - } else { ClassDB::get_signal_list(base, &node_signals2, true); @@ -891,6 +890,10 @@ void ConnectionsDock::update_tree() { name = base; } + if (!icon.is_valid()) { + icon = get_icon("Object", "EditorIcons"); + } + TreeItem *pitem = NULL; if (node_signals2.size()) { @@ -939,7 +942,7 @@ void ConnectionsDock::update_tree() { item->set_metadata(0, sinfo); item->set_icon(0, get_icon("Signal", "EditorIcons")); - // Set tooltip with the signal's documentation + // Set tooltip with the signal's documentation. { String descr; bool found = false; diff --git a/editor/create_dialog.h b/editor/create_dialog.h index f6c3b57589..f3ed1d7af6 100644 --- a/editor/create_dialog.h +++ b/editor/create_dialog.h @@ -38,9 +38,6 @@ #include "scene/gui/label.h" #include "scene/gui/line_edit.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CreateDialog : public ConfirmationDialog { diff --git a/editor/doc/doc_data.cpp b/editor/doc/doc_data.cpp index 5b8c8fffb8..0f99e2ba1e 100644 --- a/editor/doc/doc_data.cpp +++ b/editor/doc/doc_data.cpp @@ -720,8 +720,7 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & methods.push_back(method); } else { - ERR_EXPLAIN("Invalid tag in doc file: " + parser->get_node_name()); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + parser->get_node_name() + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == section) @@ -841,8 +840,7 @@ Error DocData::_load(Ref<XMLParser> parser) { if (parser->get_node_type() == XMLParser::NODE_TEXT) c.tutorials.push_back(parser->get_node_data().strip_edges()); } else { - ERR_EXPLAIN("Invalid tag in doc file: " + name3); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "tutorials") break; //end of <tutorials> @@ -883,8 +881,7 @@ Error DocData::_load(Ref<XMLParser> parser) { prop2.description = parser->get_node_data(); c.properties.push_back(prop2); } else { - ERR_EXPLAIN("Invalid tag in doc file: " + name3); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "members") @@ -912,8 +909,7 @@ Error DocData::_load(Ref<XMLParser> parser) { prop2.description = parser->get_node_data(); c.theme_properties.push_back(prop2); } else { - ERR_EXPLAIN("Invalid tag in doc file: " + name3); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "theme_items") @@ -943,8 +939,7 @@ Error DocData::_load(Ref<XMLParser> parser) { constant2.description = parser->get_node_data(); c.constants.push_back(constant2); } else { - ERR_EXPLAIN("Invalid tag in doc file: " + name3); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name3 + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "constants") @@ -953,8 +948,7 @@ Error DocData::_load(Ref<XMLParser> parser) { } else { - ERR_EXPLAIN("Invalid tag in doc file: " + name2); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Invalid tag in doc file: " + name2 + "."); } } else if (parser->get_node_type() == XMLParser::NODE_ELEMENT_END && parser->get_node_name() == "class") @@ -991,10 +985,8 @@ Error DocData::save_classes(const String &p_default_path, const Map<String, Stri Error err; String save_file = save_path.plus_file(c.name + ".xml"); FileAccessRef f = FileAccess::open(save_file, FileAccess::WRITE, &err); - if (err) { - ERR_EXPLAIN("Can't write doc file: " + save_file); - ERR_CONTINUE(err); - } + + ERR_CONTINUE_MSG(err != OK, "Can't write doc file: " + save_file + "."); _write_string(f, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); diff --git a/editor/editor_about.cpp b/editor/editor_about.cpp index bea1980b09..b2567249d8 100644 --- a/editor/editor_about.cpp +++ b/editor/editor_about.cpp @@ -181,14 +181,14 @@ EditorAbout::EditorAbout() { // Thirdparty License VBoxContainer *license_thirdparty = memnew(VBoxContainer); - license_thirdparty->set_name(TTR("Thirdparty License")); + license_thirdparty->set_name(TTR("Third-party Licenses")); license_thirdparty->set_h_size_flags(Control::SIZE_EXPAND_FILL); tc->add_child(license_thirdparty); Label *tpl_label = memnew(Label); tpl_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); tpl_label->set_autowrap(true); - tpl_label->set_text(TTR("Godot Engine relies on a number of thirdparty free and open source libraries, all compatible with the terms of its MIT license. The following is an exhaustive list of all such thirdparty components with their respective copyright statements and license terms.")); + tpl_label->set_text(TTR("Godot Engine relies on a number of third-party free and open source libraries, all compatible with the terms of its MIT license. The following is an exhaustive list of all such third-party components with their respective copyright statements and license terms.")); tpl_label->set_size(Size2(630, 1) * EDSCALE); license_thirdparty->add_child(tpl_label); diff --git a/editor/editor_about.h b/editor/editor_about.h index 87e824083e..e2ba366c65 100644 --- a/editor/editor_about.h +++ b/editor/editor_about.h @@ -43,9 +43,6 @@ #include "scene/gui/tree.h" #include "editor_scale.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class EditorAbout : public AcceptDialog { diff --git a/editor/editor_asset_installer.cpp b/editor/editor_asset_installer.cpp index b706f2cae6..98e670f952 100644 --- a/editor/editor_asset_installer.cpp +++ b/editor/editor_asset_installer.cpp @@ -90,7 +90,7 @@ void EditorAssetInstaller::open(const String &p_path, int p_depth) { unzFile pkg = unzOpen2(p_path.utf8().get_data(), &io); if (!pkg) { - error->set_text(TTR("Error opening package file, not in zip format.")); + error->set_text(TTR("Error opening package file, not in ZIP format.")); return; } @@ -217,7 +217,7 @@ void EditorAssetInstaller::ok_pressed() { unzFile pkg = unzOpen2(package_path.utf8().get_data(), &io); if (!pkg) { - error->set_text(TTR("Error opening package file, not in zip format.")); + error->set_text(TTR("Error opening package file, not in ZIP format.")); return; } diff --git a/editor/editor_autoload_settings.cpp b/editor/editor_autoload_settings.cpp index 7210211d90..f44e1b7b14 100644 --- a/editor/editor_autoload_settings.cpp +++ b/editor/editor_autoload_settings.cpp @@ -315,8 +315,7 @@ void EditorAutoloadSettings::_autoload_file_callback(const String &p_path) { Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { RES res = ResourceLoader::load(p_path); - ERR_EXPLAIN("Can't autoload: " + p_path); - ERR_FAIL_COND_V(res.is_null(), NULL); + ERR_FAIL_COND_V_MSG(res.is_null(), NULL, "Can't autoload: " + p_path + "."); Node *n = NULL; if (res->is_class("PackedScene")) { Ref<PackedScene> ps = res; @@ -325,20 +324,17 @@ Node *EditorAutoloadSettings::_create_autoload(const String &p_path) { Ref<Script> s = res; StringName ibt = s->get_instance_base_type(); bool valid_type = ClassDB::is_parent_class(ibt, "Node"); - ERR_EXPLAIN("Script does not inherit a Node: " + p_path); - ERR_FAIL_COND_V(!valid_type, NULL); + ERR_FAIL_COND_V_MSG(!valid_type, NULL, "Script does not inherit a Node: " + p_path + "."); Object *obj = ClassDB::instance(ibt); - ERR_EXPLAIN("Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt)); - ERR_FAIL_COND_V(obj == NULL, NULL); + ERR_FAIL_COND_V_MSG(obj == NULL, NULL, "Cannot instance script for autoload, expected 'Node' inheritance, got: " + String(ibt) + "."); n = Object::cast_to<Node>(obj); n->set_script(s.get_ref_ptr()); } - ERR_EXPLAIN("Path in autoload not a node or script: " + p_path); - ERR_FAIL_COND_V(!n, NULL); + ERR_FAIL_COND_V_MSG(!n, NULL, "Path in autoload not a node or script: " + p_path + "."); return n; } @@ -443,11 +439,11 @@ void EditorAutoloadSettings::update_autoload() { } if (info.in_editor) { ERR_CONTINUE(!info.node); - get_tree()->get_root()->remove_child(info.node); + get_tree()->get_root()->call_deferred("remove_child", info.node); } if (info.node) { - memdelete(info.node); + info.node->queue_delete(); info.node = NULL; } } diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index f5846c10f6..c98635d16b 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -537,6 +537,7 @@ int EditorData::add_edited_scene(int p_at_pos) { p_at_pos = edited_scene.size(); EditedScene es; es.root = NULL; + es.path = String(); es.history_current = -1; es.version = 0; es.live_edit_root = NodePath(String("/root")); @@ -653,6 +654,8 @@ bool EditorData::check_and_update_scene(int p_idx) { memdelete(edited_scene[p_idx].root); edited_scene.write[p_idx].root = new_scene; + if (new_scene->get_filename() != "") + edited_scene.write[p_idx].path = new_scene->get_filename(); edited_scene.write[p_idx].selection = new_selection; return true; @@ -684,6 +687,12 @@ void EditorData::set_edited_scene_root(Node *p_root) { ERR_FAIL_INDEX(current_edited_scene, edited_scene.size()); edited_scene.write[current_edited_scene].root = p_root; + if (p_root) { + if (p_root->get_filename() != "") + edited_scene.write[current_edited_scene].path = p_root->get_filename(); + else + p_root->set_filename(edited_scene[current_edited_scene].path); + } } int EditorData::get_edited_scene_count() const { @@ -773,6 +782,7 @@ String EditorData::get_scene_title(int p_idx) const { void EditorData::set_scene_path(int p_idx, const String &p_path) { ERR_FAIL_INDEX(p_idx, edited_scene.size()); + edited_scene.write[p_idx].path = p_path; if (!edited_scene[p_idx].root) return; @@ -783,9 +793,14 @@ String EditorData::get_scene_path(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, edited_scene.size(), String()); - if (!edited_scene[p_idx].root) - return ""; - return edited_scene[p_idx].root->get_filename(); + if (edited_scene[p_idx].root) { + if (edited_scene[p_idx].root->get_filename() == "") + edited_scene[p_idx].root->set_filename(edited_scene[p_idx].path); + else + return edited_scene[p_idx].root->get_filename(); + } + + return edited_scene[p_idx].path; } void EditorData::set_edited_scene_live_edit_root(const NodePath &p_root) { diff --git a/editor/editor_data.h b/editor/editor_data.h index 845878e070..df83135942 100644 --- a/editor/editor_data.h +++ b/editor/editor_data.h @@ -117,6 +117,7 @@ public: struct EditedScene { Node *root; + String path; Dictionary editor_states; List<Node *> selection; Vector<EditorHistory::History> history_stored; diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index ed262d9c4f..e58c7c992a 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -30,11 +30,12 @@ #include "editor_export.h" +#include "core/crypto/crypto_core.h" #include "core/io/config_file.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/io/zip_io.h" -#include "core/math/crypto_core.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/project_settings.h" #include "core/script_language.h" @@ -147,6 +148,12 @@ String EditorExportPreset::get_include_filter() const { void EditorExportPreset::set_export_path(const String &p_path) { export_path = p_path; + /* NOTE(SonerSound): if there is a need to implement a PropertyHint that specifically indicates a relative path, + * this should be removed. */ + if (export_path.is_abs_path()) { + String res_path = OS::get_singleton()->get_resource_dir(); + export_path = res_path.path_to_file(export_path); + } EditorExport::singleton->save_presets(); } @@ -884,6 +891,7 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & 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); + DirAccess::remove_file_or_error(engine_cfb); p_func(p_udata, "res://" + config_file, data, idx, total); @@ -916,8 +924,10 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c memdelete(ftmp); //close tmp file - if (err) + if (err != OK) { + DirAccess::remove_file_or_error(tmppath); return err; + } pd.file_ofs.sort(); //do sort, so we can do binary search later @@ -926,11 +936,17 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c if (!p_embed) { // Regular output to separate PCK file f = FileAccess::open(p_path, FileAccess::WRITE); - ERR_FAIL_COND_V(!f, ERR_CANT_CREATE); + if (!f) { + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V(ERR_CANT_CREATE); + } } else { // Append to executable f = FileAccess::open(p_path, FileAccess::READ_WRITE); - ERR_FAIL_COND_V(!f, ERR_FILE_CANT_OPEN); + if (!f) { + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V(ERR_FILE_CANT_OPEN); + } f->seek_end(); embed_pos = f->get_position(); @@ -995,13 +1011,13 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c f->store_8(0); } - //save the rest of the data + // Save the rest of the data. ftmp = FileAccess::open(tmppath, FileAccess::READ); if (!ftmp) { memdelete(f); - ERR_EXPLAIN("Can't open file to read from path: " + String(tmppath)); - ERR_FAIL_V(ERR_CANT_CREATE); + DirAccess::remove_file_or_error(tmppath); + ERR_FAIL_V_MSG(ERR_CANT_CREATE, "Can't open file to read from path: " + String(tmppath) + "."); } const int bufsize = 16384; @@ -1035,6 +1051,7 @@ Error EditorExportPlatform::save_pack(const Ref<EditorExportPreset> &p_preset, c } memdelete(f); + DirAccess::remove_file_or_error(tmppath); return OK; } @@ -1043,8 +1060,6 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co EditorProgress ep("savezip", TTR("Packing"), 102, true); - //FileAccess *tmp = FileAccess::open(tmppath,FileAccess::WRITE); - FileAccess *src_f; zlib_filefunc_def io = zipio_create_io_from_file(&src_f); zipFile zip = zipOpen2(p_path.utf8().get_data(), APPEND_STATUS_CREATE, NULL, &io); @@ -1694,11 +1709,18 @@ void EditorExportTextSceneToBinaryPlugin::_export_file(const String &p_path, con bool convert = GLOBAL_GET("editor/convert_text_resources_to_binary_on_export"); if (!convert) return; - String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("file.res"); + String tmp_path = EditorSettings::get_singleton()->get_cache_dir().plus_file("tmpfile.res"); Error err = ResourceFormatLoaderText::convert_file_to_binary(p_path, tmp_path); - ERR_FAIL_COND(err != OK); + if (err != OK) { + DirAccess::remove_file_or_error(tmp_path); + ERR_FAIL(); + } Vector<uint8_t> data = FileAccess::get_file_as_array(tmp_path); - ERR_FAIL_COND(data.size() == 0); + if (data.size() == 0) { + DirAccess::remove_file_or_error(tmp_path); + ERR_FAIL(); + } + DirAccess::remove_file_or_error(tmp_path); add_file(p_path + ".converted.res", data, true); } diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 1f43740858..80aeeef868 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -257,6 +257,7 @@ void EditorFileDialog::_post_popup() { if (is_visible_in_tree()) { Ref<Texture> folder = get_icon("folder", "FileDialog"); + const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); recent->clear(); bool res = access == ACCESS_RESOURCES; @@ -274,6 +275,7 @@ void EditorFileDialog::_post_popup() { recent->add_item(name, folder); recent->set_item_metadata(recent->get_item_count() - 1, recentd[i]); + recent->set_item_icon_modulate(recent->get_item_count() - 1, folder_color); } local_history.clear(); @@ -734,6 +736,7 @@ void EditorFileDialog::update_file_list() { dir_access->list_dir_begin(); Ref<Texture> folder = get_icon("folder", "FileDialog"); + const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); List<String> files; List<String> dirs; @@ -774,6 +777,7 @@ void EditorFileDialog::update_file_list() { d["dir"] = true; item_list->set_item_metadata(item_list->get_item_count() - 1, d); + item_list->set_item_icon_modulate(item_list->get_item_count() - 1, folder_color); dirs.pop_front(); } @@ -1200,6 +1204,7 @@ void EditorFileDialog::_update_favorites() { String current = get_current_dir(); Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons"); + const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); favorites->clear(); favorite->set_pressed(false); @@ -1230,6 +1235,7 @@ void EditorFileDialog::_update_favorites() { } favorites->set_item_metadata(favorites->get_item_count() - 1, favorited[i]); + favorites->set_item_icon_modulate(favorites->get_item_count() - 1, folder_color); if (setthis) { favorite->set_pressed(true); diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h index 86bf0f0eb3..2ecfa7db15 100644 --- a/editor/editor_file_dialog.h +++ b/editor/editor_file_dialog.h @@ -44,9 +44,6 @@ class DependencyRemoveDialog; -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class EditorFileDialog : public ConfirmationDialog { GDCLASS(EditorFileDialog, ConfirmationDialog); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index be3df2815e..6d3377a85b 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -1930,8 +1930,7 @@ void EditorFileSystem::reimport_files(const Vector<String> &p_files) { Error err = da->make_dir(".import"); if (err) { memdelete(da); - ERR_EXPLAIN("Failed to create 'res://.import' folder."); - ERR_FAIL(); + ERR_FAIL_MSG("Failed to create 'res://.import' folder."); } } memdelete(da); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 73438ffc0c..55cae35a4a 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -94,7 +94,31 @@ void editor_register_fonts(Ref<Theme> p_theme) { /* Custom font */ bool font_antialiased = (bool)EditorSettings::get_singleton()->get("interface/editor/font_antialiased"); - DynamicFontData::Hinting font_hinting = (DynamicFontData::Hinting)(int)EditorSettings::get_singleton()->get("interface/editor/font_hinting"); + int font_hinting_setting = (int)EditorSettings::get_singleton()->get("interface/editor/font_hinting"); + + DynamicFontData::Hinting font_hinting; + switch (font_hinting_setting) { + case 0: + // The "Auto" setting uses the setting that best matches the OS' font rendering: + // - macOS doesn't use font hinting. + // - Windows uses ClearType, which is in between "Light" and "Normal" hinting. + // - Linux has configurable font hinting, but most distributions including Ubuntu default to "Light". +#ifdef OSX_ENABLED + font_hinting = DynamicFontData::HINTING_NONE; +#else + font_hinting = DynamicFontData::HINTING_LIGHT; +#endif + break; + case 1: + font_hinting = DynamicFontData::HINTING_NONE; + break; + case 2: + font_hinting = DynamicFontData::HINTING_LIGHT; + break; + default: + font_hinting = DynamicFontData::HINTING_NORMAL; + break; + } String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); Ref<DynamicFontData> CustomFont; diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index d81a1dbd77..2e8f8ec646 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -164,6 +164,17 @@ void EditorHelp::_class_desc_select(const String &p_select) { void EditorHelp::_class_desc_input(const Ref<InputEvent> &p_input) { } +void EditorHelp::_class_desc_resized() { + // Add extra horizontal margins for better readability. + // The margins increase as the width of the editor help container increases. + const int display_margin = MAX(30 * EDSCALE, get_parent_anchorable_rect().size.width - 900 * EDSCALE) * 0.5; + + Ref<StyleBox> class_desc_stylebox = EditorNode::get_singleton()->get_theme_base()->get_stylebox("normal", "RichTextLabel")->duplicate(); + class_desc_stylebox->set_default_margin(MARGIN_LEFT, display_margin); + class_desc_stylebox->set_default_margin(MARGIN_RIGHT, display_margin); + class_desc->add_style_override("normal", class_desc_stylebox); +} + void EditorHelp::_add_type(const String &p_type, const String &p_enum) { String t = p_type; @@ -1427,11 +1438,10 @@ void EditorHelp::generate_doc() { void EditorHelp::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - _update_doc(); + _update_doc(); } break; default: break; } @@ -1489,6 +1499,7 @@ void EditorHelp::_bind_methods() { ClassDB::bind_method("_class_list_select", &EditorHelp::_class_list_select); ClassDB::bind_method("_class_desc_select", &EditorHelp::_class_desc_select); ClassDB::bind_method("_class_desc_input", &EditorHelp::_class_desc_input); + ClassDB::bind_method("_class_desc_resized", &EditorHelp::_class_desc_resized); ClassDB::bind_method("_request_help", &EditorHelp::_request_help); ClassDB::bind_method("_unhandled_key_input", &EditorHelp::_unhandled_key_input); ClassDB::bind_method("_search", &EditorHelp::_search); @@ -1507,8 +1518,11 @@ EditorHelp::EditorHelp() { add_child(class_desc); class_desc->set_v_size_flags(SIZE_EXPAND_FILL); class_desc->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); + class_desc->connect("meta_clicked", this, "_class_desc_select"); class_desc->connect("gui_input", this, "_class_desc_input"); + class_desc->connect("resized", this, "_class_desc_resized"); + _class_desc_resized(); // Added second so it opens at the bottom so it won't offset the entire widget. find_bar = memnew(FindBar); @@ -1573,7 +1587,6 @@ void EditorHelpBit::_notification(int p_what) { rich_text->add_color_override("selection_color", get_color("accent_color", "Editor") * Color(1, 1, 1, 0.4)); } break; - default: break; } } @@ -1603,6 +1616,10 @@ FindBar::FindBar() { search_text->connect("text_changed", this, "_search_text_changed"); search_text->connect("text_entered", this, "_search_text_entered"); + matches_label = memnew(Label); + add_child(matches_label); + matches_label->hide(); + find_prev = memnew(ToolButton); add_child(find_prev); find_prev->set_focus_mode(FOCUS_NONE); @@ -1613,9 +1630,9 @@ FindBar::FindBar() { find_next->set_focus_mode(FOCUS_NONE); find_next->connect("pressed", this, "_search_next"); - error_label = memnew(Label); - add_child(error_label); - error_label->add_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + Control *space = memnew(Control); + add_child(space); + space->set_custom_minimum_size(Size2(4, 0) * EDSCALE); hide_button = memnew(TextureButton); add_child(hide_button); @@ -1645,25 +1662,21 @@ void FindBar::popup_search() { void FindBar::_notification(int p_what) { - if (p_what == NOTIFICATION_READY) { - - find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); - } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - - set_process_unhandled_input(is_visible_in_tree()); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { - - find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); - find_next->set_icon(get_icon("MoveDown", "EditorIcons")); - hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); - hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); - hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); - hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: { + + find_prev->set_icon(get_icon("MoveUp", "EditorIcons")); + find_next->set_icon(get_icon("MoveDown", "EditorIcons")); + hide_button->set_normal_texture(get_icon("Close", "EditorIcons")); + hide_button->set_hover_texture(get_icon("Close", "EditorIcons")); + hide_button->set_pressed_texture(get_icon("Close", "EditorIcons")); + hide_button->set_custom_minimum_size(hide_button->get_normal_texture()->get_size()); + } break; + case NOTIFICATION_VISIBILITY_CHANGED: { + + set_process_unhandled_input(is_visible_in_tree()); + } break; } } @@ -1708,17 +1721,46 @@ bool FindBar::_search(bool p_search_previous) { prev_search = stext; if (ret) { - set_error(""); + _update_results_count(); } else { - set_error(stext.empty() ? "" : TTR("No Matches")); + results_count = 0; } + _update_matches_label(); return ret; } -void FindBar::set_error(const String &p_label) { +void FindBar::_update_results_count() { + + results_count = 0; - error_label->set_text(p_label); + String searched = search_text->get_text(); + if (searched.empty()) return; + + String full_text = rich_text_label->get_text(); + + int from_pos = 0; + + while (true) { + int pos = full_text.find(searched, from_pos); + if (pos == -1) + break; + + results_count++; + from_pos = pos + searched.length(); + } +} + +void FindBar::_update_matches_label() { + + if (search_text->get_text().empty() || results_count == -1) { + matches_label->hide(); + } else { + matches_label->show(); + + matches_label->add_color_override("font_color", results_count > 0 ? Color(1, 1, 1) : EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + matches_label->set_text(vformat(results_count == 1 ? TTR("%d match.") : TTR("%d matches."), results_count)); + } } void FindBar::_hide_bar() { diff --git a/editor/editor_help.h b/editor/editor_help.h index a50ab8a9f9..1019cafffc 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -49,18 +49,23 @@ class FindBar : public HBoxContainer { LineEdit *search_text; ToolButton *find_prev; ToolButton *find_next; - Label *error_label; + Label *matches_label; TextureButton *hide_button; String prev_search; RichTextLabel *rich_text_label; + int results_count; + void _show_search(); void _hide_bar(); void _search_text_changed(const String &p_text); void _search_text_entered(const String &p_text); + void _update_results_count(); + void _update_matches_label(); + void _update_size(); protected: @@ -72,8 +77,6 @@ protected: static void _bind_methods(); public: - void set_error(const String &p_label); - void set_rich_text_label(RichTextLabel *p_rich_text_label); void popup_search(); @@ -148,6 +151,7 @@ class EditorHelp : public VBoxContainer { void _class_list_select(const String &p_select); void _class_desc_select(const String &p_select); void _class_desc_input(const Ref<InputEvent> &p_input); + void _class_desc_resized(); Error _goto_desc(const String &p_class, int p_vscr = -1); //void _update_history_buttons(); diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index fbfc999dbf..af79c21f85 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -354,7 +354,7 @@ bool EditorHelpSearch::Runner::_phase_match_classes() { match.constants.push_back(const_cast<DocData::ConstantDoc *>(&class_doc.constants[i])); if (search_flags & SEARCH_PROPERTIES) for (int i = 0; i < class_doc.properties.size(); i++) - if (_match_string(term, class_doc.properties[i].name)) + if (_match_string(term, class_doc.properties[i].name) || _match_string(term, class_doc.properties[i].getter) || _match_string(term, class_doc.properties[i].setter)) match.properties.push_back(const_cast<DocData::PropertyDoc *>(&class_doc.properties[i])); if (search_flags & SEARCH_THEME_ITEMS) for (int i = 0; i < class_doc.theme_properties.size(); i++) diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 70bbd0fd6c..8b3e108690 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -378,7 +378,7 @@ bool EditorPropertyRevert::get_instanced_node_original_property(Node *p_node, co node = node->get_owner(); } - if (!found) { + if (!found && node) { //if not found, try default class value Variant attempt = ClassDB::class_get_default_property_value(node->get_class_name(), p_prop); if (attempt.get_type() != Variant::NIL) { @@ -1302,6 +1302,7 @@ void EditorInspector::remove_inspector_plugin(const Ref<EditorInspectorPlugin> & } } + ERR_FAIL_COND(idx == -1); for (int i = idx; i < inspector_plugin_count - 1; i++) { inspector_plugins[i] = inspector_plugins[i + 1]; } diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index faa936bd64..3e97dbd96c 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -334,6 +334,11 @@ void EditorNode::_notification(int p_what) { OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(int(EDITOR_GET("interface/editor/unfocused_low_processor_mode_sleep_usec"))); } break; + case MainLoop::NOTIFICATION_WM_ABOUT: { + + show_about(); + } break; + case MainLoop::NOTIFICATION_WM_QUIT_REQUEST: { _menu_option_confirm(FILE_QUIT, false); @@ -1576,6 +1581,7 @@ void EditorNode::push_item(Object *p_object, const String &p_property, bool p_in get_inspector()->edit(NULL); node_dock->set_node(NULL); scene_tree_dock->set_selected(NULL); + inspector_dock->update(NULL); return; } @@ -1664,9 +1670,10 @@ void EditorNode::_edit_current() { Resource *current_res = Object::cast_to<Resource>(current_obj); ERR_FAIL_COND(!current_res); - scene_tree_dock->set_selected(NULL); get_inspector()->edit(current_res); + scene_tree_dock->set_selected(NULL); node_dock->set_node(NULL); + inspector_dock->update(NULL); EditorNode::get_singleton()->get_import_dock()->set_edit_path(current_res->get_path()); int subr_idx = current_res->get_path().find("::"); @@ -1693,9 +1700,11 @@ void EditorNode::_edit_current() { if (current_node->is_inside_tree()) { node_dock->set_node(current_node); scene_tree_dock->set_selected(current_node); + inspector_dock->update(current_node); } else { node_dock->set_node(NULL); scene_tree_dock->set_selected(NULL); + inspector_dock->update(NULL); } if (get_edited_scene() && get_edited_scene()->get_filename() != String()) { @@ -1715,6 +1724,8 @@ void EditorNode::_edit_current() { get_inspector()->edit(current_obj); node_dock->set_node(NULL); + scene_tree_dock->set_selected(NULL); + inspector_dock->update(NULL); } inspector_dock->set_warning(editable_warning); @@ -1915,10 +1926,7 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { switch (p_option) { case FILE_NEW_SCENE: { - int idx = editor_data.add_edited_scene(-1); - _scene_tab_changed(idx); - editor_data.clear_editor_states(); - _update_scene_tabs(); + new_scene(); } break; case FILE_NEW_INHERITED_SCENE: @@ -2777,6 +2785,19 @@ void EditorNode::_editor_select(int p_which) { } } +void EditorNode::select_editor_by_name(const String &p_name) { + ERR_FAIL_COND(p_name == ""); + + for (int i = 0; i < main_editor_buttons.size(); i++) { + if (main_editor_buttons[i]->get_text() == p_name) { + _editor_select(i); + return; + } + } + + ERR_FAIL_MSG("The editor name '" + p_name + "' was not found."); +} + void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed) { if (p_editor->has_main_screen()) { @@ -2900,36 +2921,39 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled, return; } - String path = cf->get_value("plugin", "script"); - path = String("res://addons").plus_file(p_addon).plus_file(path); + String script_path = cf->get_value("plugin", "script"); + Ref<Script> script; // We need to save it for creating "ep" below. - Ref<Script> script = ResourceLoader::load(path); + // Only try to load the script if it has a name. Else, the plugin has no init script. + if (script_path.length() > 0) { + script_path = String("res://addons").plus_file(p_addon).plus_file(script_path); + script = ResourceLoader::load(script_path); - if (script.is_null()) { - show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), path)); - return; - } + if (script.is_null()) { + show_warning(vformat(TTR("Unable to load addon script from path: '%s'."), script_path)); + return; + } - //errors in the script cause the base_type to be "" - if (String(script->get_instance_base_type()) == "") { - show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), path)); - return; - } + // Errors in the script cause the base_type to be an empty string. + if (String(script->get_instance_base_type()) == "") { + show_warning(vformat(TTR("Unable to load addon script from path: '%s' There seems to be an error in the code, please check the syntax."), script_path)); + return; + } - //could check inheritance.. - if (String(script->get_instance_base_type()) != "EditorPlugin") { - show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), path)); - return; - } + // Plugin init scripts must inherit from EditorPlugin and be tools. + if (String(script->get_instance_base_type()) != "EditorPlugin") { + show_warning(vformat(TTR("Unable to load addon script from path: '%s' Base type is not EditorPlugin."), script_path)); + return; + } - if (!script->is_tool()) { - show_warning(vformat(TTR("Unable to load addon script from path: '%s' Script is not in tool mode."), path)); - return; + if (!script->is_tool()) { + show_warning(vformat(TTR("Unable to load addon script from path: '%s' Script is not in tool mode."), script_path)); + return; + } } EditorPlugin *ep = memnew(EditorPlugin); ep->set_script(script.get_ref_ptr()); - ep->set_dir_cache(p_addon); plugin_addons[p_addon] = ep; add_editor_plugin(ep, p_config_changed); @@ -3137,6 +3161,14 @@ void EditorNode::fix_dependencies(const String &p_for_file) { dependency_fixer->edit(p_for_file); } +int EditorNode::new_scene() { + int idx = editor_data.add_edited_scene(-1); + _scene_tab_changed(idx); + editor_data.clear_editor_states(); + _update_scene_tabs(); + return idx; +} + Error EditorNode::load_scene(const String &p_scene, bool p_ignore_broken_deps, bool p_set_inherited, bool p_clear_errors, bool p_force_open_imported) { if (!is_inside_tree()) { @@ -3795,9 +3827,13 @@ void EditorNode::show_accept(const String &p_text, const String &p_title) { void EditorNode::show_warning(const String &p_text, const String &p_title) { - warning->set_text(p_text); - warning->set_title(p_title); - warning->popup_centered_minsize(); + if (warning->is_inside_tree()) { + warning->set_text(p_text); + warning->set_title(p_title); + warning->popup_centered_minsize(); + } else { + WARN_PRINTS(p_title + " " + p_text); + } } void EditorNode::_copy_warning(const String &p_str) { @@ -4341,6 +4377,15 @@ bool EditorNode::ensure_main_scene(bool p_from_native) { return true; } +void EditorNode::run_play() { + _menu_option_confirm(RUN_STOP, true); + _run(false); +} + +void EditorNode::run_stop() { + _menu_option_confirm(RUN_STOP, false); +} + int EditorNode::get_current_tab() { return scene_tabs->get_current_tab(); } @@ -4758,8 +4803,7 @@ void EditorNode::remove_control_from_dock(Control *p_control) { } } - ERR_EXPLAIN("Control was not in dock"); - ERR_FAIL_COND(!dock); + ERR_FAIL_COND_MSG(!dock, "Control was not in dock."); dock->remove_child(p_control); _update_dock_slots_visibility(); @@ -5471,6 +5515,9 @@ EditorNode::EditorNode() { } } + // Define a minimum window size to prevent UI elements from overlapping or being cut off + OS::get_singleton()->set_min_window_size(Size2(1024, 600) * EDSCALE); + ResourceLoader::set_abort_on_missing_resources(false); FileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); EditorFileDialog::set_default_show_hidden_files(EditorSettings::get_singleton()->get("filesystem/file_dialog/show_hidden_files")); @@ -5909,19 +5956,19 @@ EditorNode::EditorNode() { p->add_shortcut(ED_SHORTCUT("editor/new_scene", TTR("New Scene")), FILE_NEW_SCENE); p->add_shortcut(ED_SHORTCUT("editor/new_inherited_scene", TTR("New Inherited Scene...")), FILE_NEW_INHERITED_SCENE); p->add_shortcut(ED_SHORTCUT("editor/open_scene", TTR("Open Scene..."), KEY_MASK_CMD + KEY_O), FILE_OPEN_SCENE); + p->add_shortcut(ED_SHORTCUT("editor/reopen_closed_scene", TTR("Reopen Closed Scene"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_T), FILE_OPEN_PREV); + p->add_submenu_item(TTR("Open Recent"), "RecentScenes", FILE_OPEN_RECENT); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/save_scene", TTR("Save Scene"), KEY_MASK_CMD + KEY_S), FILE_SAVE_SCENE); p->add_shortcut(ED_SHORTCUT("editor/save_scene_as", TTR("Save Scene As..."), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S), FILE_SAVE_AS_SCENE); p->add_shortcut(ED_SHORTCUT("editor/save_all_scenes", TTR("Save All Scenes"), KEY_MASK_ALT + KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_S), FILE_SAVE_ALL_SCENES); - p->add_separator(); - p->add_shortcut(ED_SHORTCUT("editor/close_scene", TTR("Close Scene"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_W), FILE_CLOSE); - p->add_separator(); - p->add_submenu_item(TTR("Open Recent"), "RecentScenes", FILE_OPEN_RECENT); - p->add_shortcut(ED_SHORTCUT("editor/reopen_closed_scene", TTR("Reopen Closed Scene"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_T), FILE_OPEN_PREV); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/quick_open", TTR("Quick Open..."), KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_O), FILE_QUICK_OPEN); p->add_shortcut(ED_SHORTCUT("editor/quick_open_scene", TTR("Quick Open Scene..."), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_O), FILE_QUICK_OPEN_SCENE); p->add_shortcut(ED_SHORTCUT("editor/quick_open_script", TTR("Quick Open Script..."), KEY_MASK_ALT + KEY_MASK_CMD + KEY_O), FILE_QUICK_OPEN_SCRIPT); + p->add_separator(); PopupMenu *pm_export = memnew(PopupMenu); pm_export->set_name("Export"); @@ -5934,8 +5981,10 @@ EditorNode::EditorNode() { p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/undo", TTR("Undo"), KEY_MASK_CMD + KEY_Z), EDIT_UNDO, true); p->add_shortcut(ED_SHORTCUT("editor/redo", TTR("Redo"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Z), EDIT_REDO, true); + p->add_separator(); p->add_shortcut(ED_SHORTCUT("editor/revert_scene", TTR("Revert Scene")), EDIT_REVERT); + p->add_shortcut(ED_SHORTCUT("editor/close_scene", TTR("Close Scene"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_W), FILE_CLOSE); recent_scenes = memnew(PopupMenu); recent_scenes->set_name("RecentScenes"); @@ -5943,7 +5992,7 @@ EditorNode::EditorNode() { recent_scenes->connect("id_pressed", this, "_open_recent_scene"); p->add_separator(); - p->add_item(TTR("Quit"), FILE_QUIT, KEY_MASK_CMD + KEY_Q); + p->add_shortcut(ED_SHORTCUT("editor/file_quit", TTR("Quit"), KEY_MASK_CMD + KEY_Q), FILE_QUIT, true); project_menu = memnew(MenuButton); project_menu->set_flat(false); @@ -5955,31 +6004,31 @@ EditorNode::EditorNode() { p = project_menu->get_popup(); p->set_hide_on_window_lose_focus(true); - p->add_shortcut(ED_SHORTCUT("editor/project_settings", TTR("Project Settings")), RUN_SETTINGS); - p->add_separator(); + p->add_shortcut(ED_SHORTCUT("editor/project_settings", TTR("Project Settings...")), RUN_SETTINGS); p->connect("id_pressed", this, "_menu_option"); - p->add_shortcut(ED_SHORTCUT("editor/export", TTR("Export")), FILE_EXPORT_PROJECT); + + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("editor/export", TTR("Export...")), FILE_EXPORT_PROJECT); + p->add_item(TTR("Install Android Build Template..."), FILE_INSTALL_ANDROID_SOURCE); + p->add_item(TTR("Open Project Data Folder"), RUN_PROJECT_DATA_FOLDER); plugin_config_dialog = memnew(PluginConfigDialog); plugin_config_dialog->connect("plugin_ready", this, "_on_plugin_ready"); gui_base->add_child(plugin_config_dialog); + p->add_separator(); tool_menu = memnew(PopupMenu); tool_menu->set_name("Tools"); tool_menu->connect("index_pressed", this, "_tool_menu_option"); - p->add_separator(); p->add_child(tool_menu); p->add_submenu_item(TTR("Tools"), "Tools"); - tool_menu->add_item(TTR("Orphan Resource Explorer"), TOOLS_ORPHAN_RESOURCES); - tool_menu->add_item(TTR("Open Project Data Folder"), RUN_PROJECT_DATA_FOLDER); - p->add_separator(); - p->add_item(TTR("Install Android Build Template"), FILE_INSTALL_ANDROID_SOURCE); - p->add_separator(); + tool_menu->add_item(TTR("Orphan Resource Explorer..."), TOOLS_ORPHAN_RESOURCES); + p->add_separator(); #ifdef OSX_ENABLED - p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q); + p->add_shortcut(ED_SHORTCUT("editor/quit_to_project_list", TTR("Quit to Project List"), KEY_MASK_SHIFT + KEY_MASK_ALT + KEY_Q), RUN_PROJECT_MANAGER, true); #else - p->add_item(TTR("Quit to Project List"), RUN_PROJECT_MANAGER, KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Q); + p->add_shortcut(ED_SHORTCUT("editor/quit_to_project_list", TTR("Quit to Project List"), KEY_MASK_SHIFT + KEY_MASK_CMD + KEY_Q), RUN_PROJECT_MANAGER, true); #endif menu_hb->add_spacer(); @@ -6027,7 +6076,7 @@ EditorNode::EditorNode() { p = settings_menu->get_popup(); p->set_hide_on_window_lose_focus(true); - p->add_shortcut(ED_SHORTCUT("editor/editor_settings", TTR("Editor Settings")), SETTINGS_PREFERENCES); + p->add_shortcut(ED_SHORTCUT("editor/editor_settings", TTR("Editor Settings...")), SETTINGS_PREFERENCES); p->add_separator(); editor_layouts = memnew(PopupMenu); @@ -6062,11 +6111,8 @@ EditorNode::EditorNode() { } p->add_separator(); - p->add_item(TTR("Manage Editor Features"), SETTINGS_MANAGE_FEATURE_PROFILES); - - p->add_separator(); - - p->add_item(TTR("Manage Export Templates"), SETTINGS_MANAGE_EXPORT_TEMPLATES); + p->add_item(TTR("Manage Editor Features..."), SETTINGS_MANAGE_FEATURE_PROFILES); + p->add_item(TTR("Manage Export Templates..."), SETTINGS_MANAGE_EXPORT_TEMPLATES); // Help Menu help_menu = memnew(MenuButton); diff --git a/editor/editor_node.h b/editor/editor_node.h index 75827cc65f..a8443549ed 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -86,10 +86,6 @@ #include "scene/gui/tree.h" #include "scene/gui/viewport_container.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - typedef void (*EditorNodeInitCallback)(); typedef void (*EditorPluginInitializeCallback)(); typedef bool (*EditorBuildCallback)(); @@ -732,6 +728,8 @@ public: bool item_has_editor(Object *p_object); void hide_top_editors(); + void select_editor_by_name(const String &p_name); + void open_request(const String &p_path); bool is_changing_scene() const; @@ -747,6 +745,7 @@ public: void fix_dependencies(const String &p_for_file); void clear_scene() { _cleanup_scene(); } + int new_scene(); Error load_scene(const String &p_scene, bool p_ignore_broken_deps = false, bool p_set_inherited = false, bool p_clear_errors = true, bool p_force_open_imported = false); Error load_resource(const String &p_resource, bool p_ignore_broken_deps = false); @@ -867,6 +866,9 @@ public: static void add_build_callback(EditorBuildCallback p_callback); bool ensure_main_scene(bool p_from_native); + + void run_play(); + void run_stop(); }; struct EditorProgress { diff --git a/editor/editor_path.cpp b/editor/editor_path.cpp index 12510e27de..23d28261d1 100644 --- a/editor/editor_path.cpp +++ b/editor/editor_path.cpp @@ -78,6 +78,9 @@ void EditorPath::_about_to_show() { } void EditorPath::update_path() { + set_text(""); + set_tooltip(""); + set_icon(NULL); for (int i = 0; i < history->get_path_size(); i++) { diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index c2a845653e..e27f1ab9eb 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -149,6 +149,10 @@ Vector<Ref<Texture> > EditorInterface::make_mesh_previews(const Vector<Ref<Mesh> return textures; } +void EditorInterface::set_main_screen_editor(const String &p_name) { + EditorNode::get_singleton()->select_editor_by_name(p_name); +} + Control *EditorInterface::get_editor_viewport() { return EditorNode::get_singleton()->get_viewport(); @@ -260,6 +264,10 @@ void EditorInterface::save_scene_as(const String &p_scene, bool p_with_preview) EditorNode::get_singleton()->save_scene_to_path(p_scene, p_with_preview); } +void EditorInterface::set_distraction_free_mode(bool p_enter) { + EditorNode::get_singleton()->set_distraction_free_mode(p_enter); +} + EditorInterface *EditorInterface::singleton = NULL; void EditorInterface::_bind_methods() { @@ -288,6 +296,9 @@ void EditorInterface::_bind_methods() { ClassDB::bind_method(D_METHOD("save_scene"), &EditorInterface::save_scene); ClassDB::bind_method(D_METHOD("save_scene_as", "path", "with_preview"), &EditorInterface::save_scene_as, DEFVAL(true)); + + ClassDB::bind_method(D_METHOD("set_main_screen_editor", "name"), &EditorInterface::set_main_screen_editor); + ClassDB::bind_method(D_METHOD("set_distraction_free_mode", "enter"), &EditorInterface::set_distraction_free_mode); } EditorInterface::EditorInterface() { @@ -313,12 +324,6 @@ void EditorPlugin::remove_autoload_singleton(const String &p_name) { EditorNode::get_singleton()->get_project_settings()->get_autoload_settings()->autoload_remove(p_name); } -Ref<ConfigFile> EditorPlugin::get_config() { - Ref<ConfigFile> cf = memnew(ConfigFile); - cf->load(_dir_cache.plus_file("plugin.cfg")); - return cf; -} - ToolButton *EditorPlugin::add_control_to_bottom_panel(Control *p_control, const String &p_title) { ERR_FAIL_NULL_V(p_control, NULL); return EditorNode::get_singleton()->add_bottom_panel_item(p_title, p_control); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index 75c230adb7..8941dfa28c 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -41,10 +41,6 @@ #include "scene/main/node.h" #include "scene/resources/texture.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class EditorNode; class Spatial; class Camera; @@ -103,6 +99,9 @@ public: Vector<Ref<Texture> > make_mesh_previews(const Vector<Ref<Mesh> > &p_meshes, Vector<Transform> *p_transforms, int p_preview_size); + void set_main_screen_editor(const String &p_name); + void set_distraction_free_mode(bool p_enter); + EditorInterface(); }; @@ -118,7 +117,6 @@ class EditorPlugin : public Node { bool force_draw_over_forwarding_enabled; String last_main_screen_name; - String _dir_cache; protected: static void _bind_methods(); @@ -237,10 +235,6 @@ public: void add_autoload_singleton(const String &p_name, const String &p_path); void remove_autoload_singleton(const String &p_name); - void set_dir_cache(const String &p_dir) { _dir_cache = p_dir; } - String get_dir_cache() { return _dir_cache; } - Ref<ConfigFile> get_config(); - void enable_plugin(); void disable_plugin(); diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 3300228921..378dd34e39 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -116,7 +116,7 @@ void EditorPropertyMultilineText::_open_big_text() { add_child(big_text_dialog); } - big_text_dialog->popup_centered_ratio(); + big_text_dialog->popup_centered_clamped(Size2(1000, 900) * EDSCALE, 0.8); big_text->set_text(text->get_text()); big_text->grab_focus(); } @@ -209,13 +209,7 @@ EditorPropertyTextEnum::EditorPropertyTextEnum() { void EditorPropertyPath::_path_selected(const String &p_path) { - String final_path = p_path; - if (final_path.is_abs_path()) { - String res_path = OS::get_singleton()->get_resource_dir() + "/"; - final_path = res_path.path_to_file(final_path); - } - - emit_changed(get_edited_property(), final_path); + emit_changed(get_edited_property(), p_path); update_property(); } void EditorPropertyPath::_path_pressed() { @@ -228,13 +222,6 @@ void EditorPropertyPath::_path_pressed() { } String full_path = get_edited_object()->get(get_edited_property()); - if (full_path.is_rel_path()) { - - if (!DirAccess::exists(full_path.get_base_dir())) { - DirAccessRef da(DirAccess::create(DirAccess::ACCESS_FILESYSTEM)); - da->make_dir_recursive(full_path.get_base_dir()); - } - } dialog->clear_filters(); diff --git a/editor/editor_properties_array_dict.cpp b/editor/editor_properties_array_dict.cpp index 203136a3f8..d1371a04b1 100644 --- a/editor/editor_properties_array_dict.cpp +++ b/editor/editor_properties_array_dict.cpp @@ -312,7 +312,8 @@ void EditorPropertyArray::update_property() { } else { //bye bye children of the box while (vbox->get_child_count() > 2) { - memdelete(vbox->get_child(2)); + vbox->get_child(2)->queue_delete(); // button still needed after pressed is called + vbox->remove_child(vbox->get_child(2)); } } diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 327e61cea3..4a7a9fb863 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -46,8 +46,7 @@ bool EditorResourcePreviewGenerator::handles(const String &p_type) const { if (get_script_instance() && get_script_instance()->has_method("handles")) { return get_script_instance()->call("handles", p_type); } - ERR_EXPLAIN("EditorResourcePreviewGenerator::handles needs to be overridden"); - ERR_FAIL_V(false); + ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::handles needs to be overridden."); } Ref<Texture> EditorResourcePreviewGenerator::generate(const RES &p_from, const Size2 &p_size) const { @@ -55,8 +54,7 @@ Ref<Texture> EditorResourcePreviewGenerator::generate(const RES &p_from, const S if (get_script_instance() && get_script_instance()->has_method("generate")) { return get_script_instance()->call("generate", p_from, p_size); } - ERR_EXPLAIN("EditorResourcePreviewGenerator::generate needs to be overridden"); - ERR_FAIL_V(Ref<Texture>()); + ERR_FAIL_V_MSG(Ref<Texture>(), "EditorResourcePreviewGenerator::generate needs to be overridden."); } Ref<Texture> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 &p_size) const { diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 45000517cb..ea6361665c 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -324,8 +324,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("interface/editor/code_font_size", 14); hints["interface/editor/code_font_size"] = PropertyInfo(Variant::INT, "interface/editor/code_font_size", PROPERTY_HINT_RANGE, "8,48,1", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/font_antialiased", true); - _initial_set("interface/editor/font_hinting", 2); - hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT); + _initial_set("interface/editor/font_hinting", 0); + hints["interface/editor/font_hinting"] = PropertyInfo(Variant::INT, "interface/editor/font_hinting", PROPERTY_HINT_ENUM, "Auto,None,Light,Normal", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/main_font", ""); hints["interface/editor/main_font"] = PropertyInfo(Variant::STRING, "interface/editor/main_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/main_font_bold", ""); @@ -334,9 +334,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { hints["interface/editor/code_font"] = PropertyInfo(Variant::STRING, "interface/editor/code_font", PROPERTY_HINT_GLOBAL_FILE, "*.ttf,*.otf", PROPERTY_USAGE_DEFAULT); _initial_set("interface/editor/dim_editor_on_dialog_popup", true); _initial_set("interface/editor/low_processor_mode_sleep_usec", 6900); // ~144 FPS - hints["interface/editor/low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT); + hints["interface/editor/low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("interface/editor/unfocused_low_processor_mode_sleep_usec", 50000); // 20 FPS - hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT); + hints["interface/editor/unfocused_low_processor_mode_sleep_usec"] = PropertyInfo(Variant::REAL, "interface/editor/unfocused_low_processor_mode_sleep_usec", PROPERTY_HINT_RANGE, "1,100000,1", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED); _initial_set("interface/editor/separate_distraction_mode", false); _initial_set("interface/editor/automatically_open_screenshots", true); _initial_set("interface/editor/hide_console_window", false); @@ -448,6 +448,9 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("text_editor/line_numbers/show_info_gutter", true); _initial_set("text_editor/line_numbers/code_folding", true); _initial_set("text_editor/line_numbers/word_wrap", false); + _initial_set("text_editor/line_numbers/draw_minimap", true); + _initial_set("text_editor/line_numbers/minimap_width", 80); + hints["text_editor/line_numbers/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/line_numbers/minimap_width", PROPERTY_HINT_RANGE, "50,250,1"); _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, 1"); @@ -561,6 +564,7 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { // 2D _initial_set("editors/2d/grid_color", Color(1.0, 1.0, 1.0, 0.07)); _initial_set("editors/2d/guides_color", Color(0.6, 0.0, 0.8)); + _initial_set("editors/2d/smart_snapping_line_color", Color(0.9, 0.1, 0.1)); _initial_set("editors/2d/bone_width", 5); _initial_set("editors/2d/bone_color1", Color(1.0, 1.0, 1.0, 0.9)); _initial_set("editors/2d/bone_color2", Color(0.6, 0.6, 0.6, 0.9)); @@ -608,6 +612,18 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("run/output/always_open_output_on_play", true); _initial_set("run/output/always_close_output_on_stop", false); + /* Network */ + + // Debug + _initial_set("network/debug/remote_host", "127.0.0.1"); // Hints provided in setup_network + + _initial_set("network/debug/remote_port", 6007); + hints["network/debug/remote_port"] = PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1"); + + // SSL + _initial_set("network/ssl/editor_ssl_certificates", _SYSTEM_CERTS_PATH); + hints["network/ssl/editor_ssl_certificates"] = PropertyInfo(Variant::STRING, "network/ssl/editor_ssl_certificates", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem"); + /* Extra config */ _initial_set("project_manager/sorting_order", 0); @@ -773,10 +789,16 @@ void EditorSettings::create() { if (d->file_exists(exe_path + "/._sc_")) { self_contained = true; - extra_config->load(exe_path + "/._sc_"); + Error err = extra_config->load(exe_path + "/._sc_"); + if (err != OK) { + ERR_PRINTS("Can't load config from path: " + exe_path + "/._sc_"); + } } else if (d->file_exists(exe_path + "/_sc_")) { self_contained = true; - extra_config->load(exe_path + "/_sc_"); + Error err = extra_config->load(exe_path + "/_sc_"); + if (err != OK) { + ERR_PRINTS("Can't load config from path: " + exe_path + "/_sc_"); + } } memdelete(d); @@ -987,11 +1009,11 @@ void EditorSettings::setup_network() { List<IP_Address> local_ip; IP::get_singleton()->get_local_addresses(&local_ip); - String lip = "127.0.0.1"; String hint; String current = has_setting("network/debug/remote_host") ? get("network/debug/remote_host") : ""; - int port = has_setting("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007; + String selected = "127.0.0.1"; + // Check that current remote_host is a valid interface address and populate hints. for (List<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) { String ip = E->get(); @@ -1002,22 +1024,18 @@ void EditorSettings::setup_network() { // Same goes for IPv4 link-local (APIPA) addresses. if (ip.begins_with("169.254.")) // 169.254.0.0/16 continue; + // Select current IP (found) if (ip == current) - lip = current; //so it saves + selected = ip; if (hint != "") hint += ","; hint += ip; } - _initial_set("network/debug/remote_host", lip); + // Add hints with valid IP addresses to remote_host property. add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint)); - - _initial_set("network/debug/remote_port", port); - add_property_hint(PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1")); - - // Editor SSL certificates override - _initial_set("network/ssl/editor_ssl_certificates", _SYSTEM_CERTS_PATH); - add_property_hint(PropertyInfo(Variant::STRING, "network/ssl/editor_ssl_certificates", PROPERTY_HINT_GLOBAL_FILE, "*.crt,*.pem")); + // Fix potentially invalid remote_host due to network change. + set("network/debug/remote_host", selected); } void EditorSettings::save() { @@ -1191,6 +1209,11 @@ String EditorSettings::get_script_templates_dir() const { return get_settings_dir().plus_file("script_templates"); } +String EditorSettings::get_project_script_templates_dir() const { + + return ProjectSettings::get_singleton()->get("editor/script_templates_search_path"); +} + // Cache directory String EditorSettings::get_cache_dir() const { @@ -1208,9 +1231,12 @@ String EditorSettings::get_feature_profiles_dir() const { 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_dir().plus_file("project_metadata.cfg"); - cf->load(path); + Error err; + err = cf->load(path); + ERR_FAIL_COND(err != OK && err != ERR_FILE_NOT_FOUND); cf->set_value(p_section, p_key, p_data); - cf->save(path); + err = cf->save(path); + ERR_FAIL_COND(err != OK); } Variant EditorSettings::get_project_metadata(const String &p_section, const String &p_key, Variant p_default) const { @@ -1408,10 +1434,14 @@ bool EditorSettings::is_default_text_editor_theme() { return _is_default_text_editor_theme(p_file.get_file().to_lower()); } -Vector<String> EditorSettings::get_script_templates(const String &p_extension) { +Vector<String> EditorSettings::get_script_templates(const String &p_extension, const String &p_custom_path) { Vector<String> templates; - DirAccess *d = DirAccess::open(get_script_templates_dir()); + String template_dir = get_script_templates_dir(); + if (!p_custom_path.empty()) { + template_dir = p_custom_path; + } + DirAccess *d = DirAccess::open(template_dir); if (d) { d->list_dir_begin(); String file = d->get_next(); @@ -1442,10 +1472,7 @@ void EditorSettings::add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcu bool EditorSettings::is_shortcut(const String &p_name, const Ref<InputEvent> &p_event) const { const Map<String, Ref<ShortCut> >::Element *E = shortcuts.find(p_name); - if (!E) { - ERR_EXPLAIN("Unknown Shortcut: " + p_name); - ERR_FAIL_V(false); - } + ERR_FAIL_COND_V_MSG(!E, false, "Unknown Shortcut: " + p_name + "."); return E->get()->is_shortcut(p_event); } @@ -1474,10 +1501,8 @@ Ref<ShortCut> ED_GET_SHORTCUT(const String &p_path) { } Ref<ShortCut> sc = EditorSettings::get_singleton()->get_shortcut(p_path); - if (!sc.is_valid()) { - ERR_EXPLAIN("Used ED_GET_SHORTCUT with invalid shortcut: " + p_path); - ERR_FAIL_COND_V(!sc.is_valid(), sc); - } + + ERR_FAIL_COND_V_MSG(!sc.is_valid(), sc, "Used ED_GET_SHORTCUT with invalid shortcut: " + p_path + "."); return sc; } diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 890850629e..0738185e95 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -166,6 +166,7 @@ public: String get_project_settings_dir() const; String get_text_editor_themes_dir() const; String get_script_templates_dir() const; + String get_project_script_templates_dir() const; String get_cache_dir() const; String get_feature_profiles_dir() const; @@ -187,7 +188,7 @@ public: bool save_text_editor_theme_as(String p_file); bool is_default_text_editor_theme(); - Vector<String> get_script_templates(const String &p_extension); + Vector<String> get_script_templates(const String &p_extension, const String &p_custom_path = String()); String get_editor_layouts_config() const; void add_shortcut(const String &p_name, Ref<ShortCut> &p_shortcut); diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index 9966394025..46a30b7554 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -47,42 +47,48 @@ void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { return; Ref<InputEventMouseButton> mb = p_event; - if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT) { + if (mb.is_valid()) { - if (mb->is_pressed()) { + if (mb->get_button_index() == BUTTON_LEFT) { + if (mb->is_pressed()) { - if (updown_offset != -1 && mb->get_position().x > updown_offset) { - //there is an updown, so use it. - if (mb->get_position().y < get_size().height / 2) { - set_value(get_value() + get_step()); + if (updown_offset != -1 && mb->get_position().x > updown_offset) { + //there is an updown, so use it. + if (mb->get_position().y < get_size().height / 2) { + set_value(get_value() + get_step()); + } else { + set_value(get_value() - get_step()); + } + return; } else { - set_value(get_value() - get_step()); + + grabbing_spinner_attempt = true; + grabbing_spinner_dist_cache = 0; + pre_grab_value = get_value(); + grabbing_spinner = false; + grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position(); } - return; } else { - grabbing_spinner_attempt = true; - grabbing_spinner_dist_cache = 0; - pre_grab_value = get_value(); - grabbing_spinner = false; - grabbing_spinner_mouse_pos = Input::get_singleton()->get_mouse_position(); - } - } else { + if (grabbing_spinner_attempt) { - if (grabbing_spinner_attempt) { + if (grabbing_spinner) { - if (grabbing_spinner) { + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); + update(); + } else { + _focus_entered(); + } - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - Input::get_singleton()->warp_mouse_position(grabbing_spinner_mouse_pos); - update(); - } else { - _focus_entered(); + grabbing_spinner = false; + grabbing_spinner_attempt = false; } - - grabbing_spinner = false; - grabbing_spinner_attempt = false; } + } else if (mb->get_button_index() == BUTTON_WHEEL_UP || mb->get_button_index() == BUTTON_WHEEL_DOWN) { + + if (grabber->is_visible()) + call_deferred("update"); } } @@ -347,6 +353,11 @@ void EditorSpinSlider::_value_input_closed() { //focus_exited signal void EditorSpinSlider::_value_focus_exited() { + + // discontinue because the focus_exit was caused by right-click context menu + if (value_input->get_menu()->is_visible()) + return; + _evaluate_input_text(); // focus is not on the same element after the vlalue_input was exited // -> focus is on next element diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 4eceb09792..56eed96e31 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -113,11 +113,11 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ffffff", "#000000"); // white ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b4b4b4", "#000000"); // script darker color - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#cea4f1", "#bb6dff"); // animation - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fc9c9c", "#ff5f5f"); // spatial - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5b7f3", "#6d90ff"); // 2d - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#708cea", "#0843ff"); // 2d dark - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5efac", "#29d739"); // control + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#cea4f1", "#a85de9"); // animation + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#fc9c9c", "#cd3838"); // spatial + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5b7f3", "#3d64dd"); // 2d + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#708cea", "#1a3eac"); // 2d dark + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#a5efac", "#2aa235"); // control // rainbow ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ff7070", "#ff2929"); // red @@ -140,7 +140,13 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84ffb1", "#00db50"); // add (green) ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#84c2ff", "#5caeff"); // selection (blue) - ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ea686c", "#e3383d"); // key xform (red) + // Animation editor tracks + // The property track icon color is set by the common icon color + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#ea9568", "#bd5e2c"); // 3D Transform track + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#66f376", "#16a827"); // Call Method track + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#5792f6", "#236be6"); // Bezier Curve track + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#eae668", "#aea923"); // Audio Playback track + ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#b76ef0", "#9853ce"); // Animation Playback track ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#69ecbd", "#25e3a0"); // VS variant ADD_CONVERT_COLOR(dark_icon_color_dictionary, "#8da6f0", "#6d8eeb"); // VS bool @@ -345,6 +351,8 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_color("dark_color_3", "Editor", dark_color_3); theme->set_color("contrast_color_1", "Editor", contrast_color_1); theme->set_color("contrast_color_2", "Editor", contrast_color_2); + theme->set_color("box_selection_fill_color", "Editor", accent_color * Color(1, 1, 1, 0.3)); + theme->set_color("box_selection_stroke_color", "Editor", accent_color * Color(1, 1, 1, 0.8)); theme->set_color("font_color", "Editor", font_color); theme->set_color("highlighted_font_color", "Editor", font_color_hl); @@ -1058,6 +1066,9 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // FileDialog theme->set_icon("folder", "FileDialog", theme->get_icon("Folder", "EditorIcons")); + // Use a different color for folder icons to make them easier to distinguish from files. + // On a light theme, the icon will be dark, so we need to lighten it before blending it with the accent color. + theme->set_color("folder_icon_modulate", "FileDialog", (dark_theme ? Color(1, 1, 1) : Color(5, 5, 5)).linear_interpolate(accent_color, 0.7)); theme->set_color("files_disabled", "FileDialog", font_color_disabled); // color picker diff --git a/editor/export_template_manager.cpp b/editor/export_template_manager.cpp index ecfad4d146..1447a143d4 100644 --- a/editor/export_template_manager.cpp +++ b/editor/export_template_manager.cpp @@ -69,6 +69,9 @@ void ExportTemplateManager::_update_template_list() { memdelete(d); String current_version = VERSION_FULL_CONFIG; + // Downloadable export templates are only available for stable, alpha, beta and RC versions. + // Therefore, don't display download-related features when using a development version + const bool downloads_available = String(VERSION_STATUS) != String("dev"); Label *current = memnew(Label); current->set_h_size_flags(SIZE_EXPAND_FILL); @@ -76,10 +79,14 @@ void ExportTemplateManager::_update_template_list() { if (templates.has(current_version)) { current->add_color_override("font_color", get_color("success_color", "Editor")); - Button *redownload = memnew(Button); - redownload->set_text(TTR("Re-Download")); - current_hb->add_child(redownload); - redownload->connect("pressed", this, "_download_template", varray(current_version)); + + // Only display a redownload button if it can be downloaded in the first place + if (downloads_available) { + Button *redownload = memnew(Button); + redownload->set_text(TTR("Redownload")); + current_hb->add_child(redownload); + redownload->connect("pressed", this, "_download_template", varray(current_version)); + } Button *uninstall = memnew(Button); uninstall->set_text(TTR("Uninstall")); @@ -91,6 +98,12 @@ void ExportTemplateManager::_update_template_list() { current->add_color_override("font_color", get_color("error_color", "Editor")); Button *redownload = memnew(Button); redownload->set_text(TTR("Download")); + + if (!downloads_available) { + redownload->set_disabled(true); + redownload->set_tooltip(TTR("Official export templates aren't available for development builds.")); + } + redownload->connect("pressed", this, "_download_template", varray(current_version)); current_hb->add_child(redownload); current->set_text(current_version + " " + TTR("(Missing)")); @@ -308,8 +321,7 @@ bool ExportTemplateManager::_install_from_file(const String &p_file, bool p_use_ if (!f) { ret = unzGoToNextFile(pkg); fc++; - ERR_EXPLAIN("Can't open file from path: " + String(to_write)); - ERR_CONTINUE(true); + ERR_CONTINUE_MSG(true, "Can't open file from path: " + String(to_write) + "."); } f->store_buffer(data.ptr(), data.size()); @@ -422,14 +434,16 @@ void ExportTemplateManager::_http_download_templates_completed(int p_status, int String path = download_templates->get_download_file(); template_list_state->set_text(TTR("Download Complete.")); template_downloader->hide(); - int ret = _install_from_file(path, false); + bool ret = _install_from_file(path, false); if (ret) { - Error err = OS::get_singleton()->move_to_trash(path); + // Clean up downloaded file. + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + Error err = da->remove(path); if (err != OK) { - EditorNode::get_singleton()->add_io_error(TTR("Cannot remove:") + "\n" + path + "\n"); + EditorNode::get_singleton()->add_io_error(TTR("Cannot remove temporary file:") + "\n" + path + "\n"); } } else { - WARN_PRINTS(vformat(TTR("Templates installation failed. The problematic templates archives can be found at '%s'."), path)); + EditorNode::get_singleton()->add_io_error(vformat(TTR("Templates installation failed.\nThe problematic templates archives can be found at '%s'."), path)); } } } break; @@ -458,7 +472,7 @@ void ExportTemplateManager::_begin_template_download(const String &p_url) { Error err = download_templates->request(p_url); if (err != OK) { - EditorNode::get_singleton()->show_warning(TTR("Error requesting url: ") + p_url); + EditorNode::get_singleton()->show_warning(TTR("Error requesting URL:") + " " + p_url); return; } @@ -576,8 +590,7 @@ Error ExportTemplateManager::install_android_template() { zlib_filefunc_def io = zipio_create_io_from_file(&src_f); unzFile pkg = unzOpen2(source_zip.utf8().get_data(), &io); - ERR_EXPLAIN("Android sources not in zip format"); - ERR_FAIL_COND_V(!pkg, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!pkg, ERR_CANT_OPEN, "Android sources not in ZIP format."); int ret = unzGoToFirstFile(pkg); diff --git a/editor/file_type_cache.cpp b/editor/file_type_cache.cpp index 1bcbc45d3b..746d38f2b5 100644 --- a/editor/file_type_cache.cpp +++ b/editor/file_type_cache.cpp @@ -83,11 +83,8 @@ void FileTypeCache::save() { GLOBAL_LOCK_FUNCTION String project = ProjectSettings::get_singleton()->get_resource_path(); FileAccess *f = FileAccess::open(project + "/file_type_cache.cch", FileAccess::WRITE); - if (!f) { - ERR_EXPLAIN(TTR("Can't open file_type_cache.cch for writing, not saving file type cache!")); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(!f, "Can't open file_type_cache.cch for writing, not saving file type cache!"); const String *K = NULL; diff --git a/editor/filesystem_dock.cpp b/editor/filesystem_dock.cpp index 8e332ad20e..a729befe8e 100644 --- a/editor/filesystem_dock.cpp +++ b/editor/filesystem_dock.cpp @@ -39,6 +39,7 @@ #include "editor_node.h" #include "editor_settings.h" #include "scene/main/viewport.h" +#include "scene/resources/packed_scene.h" Ref<Texture> FileSystemDock::_get_tree_item_icon(EditorFileSystemDirectory *p_dir, int p_idx) { Ref<Texture> file_icon; @@ -52,10 +53,9 @@ Ref<Texture> FileSystemDock::_get_tree_item_icon(EditorFileSystemDirectory *p_di } bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory *p_dir, Vector<String> &uncollapsed_paths, bool p_select_in_favorites) { - bool parent_should_expand = false; - // Create a tree item for the subdirectory + // Create a tree item for the subdirectory. TreeItem *subdirectory_item = tree->create_item(p_parent); String dname = p_dir->get_name(); if (dname == "") @@ -63,6 +63,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory subdirectory_item->set_text(0, dname); subdirectory_item->set_icon(0, get_icon("Folder", "EditorIcons")); + subdirectory_item->set_icon_modulate(0, get_color("folder_icon_modulate", "FileDialog")); subdirectory_item->set_selectable(0, true); String lpath = p_dir->get_path(); subdirectory_item->set_metadata(0, lpath); @@ -79,28 +80,28 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory parent_should_expand = true; } - // Create items for all subdirectories + // Create items for all subdirectories. for (int i = 0; i < p_dir->get_subdir_count(); i++) parent_should_expand = (_create_tree(subdirectory_item, p_dir->get_subdir(i), uncollapsed_paths, p_select_in_favorites) || parent_should_expand); - // Create all items for the files in the subdirectory + // Create all items for the files in the subdirectory. if (display_mode == DISPLAY_MODE_TREE_ONLY) { for (int i = 0; i < p_dir->get_file_count(); i++) { String file_type = p_dir->get_file_type(i); if (_is_file_type_disabled_by_feature_profile(file_type)) { - //if type is disabled, file won't be displayed. + // If type is disabled, file won't be displayed. continue; } String file_name = p_dir->get_file(i); if (searched_string.length() > 0) { if (file_name.to_lower().find(searched_string) < 0) { - // The searched string is not in the file name, we skip it + // The searched string is not in the file name, we skip it. continue; } else { - // We expand all parents + // We expand all parents. parent_should_expand = true; } } @@ -133,7 +134,7 @@ bool FileSystemDock::_create_tree(TreeItem *p_parent, EditorFileSystemDirectory } Vector<String> FileSystemDock::_compute_uncollapsed_paths() { - // Register currently collapsed paths + // Register currently collapsed paths. Vector<String> uncollapsed_paths; TreeItem *root = tree->get_root(); if (root) { @@ -164,14 +165,13 @@ Vector<String> FileSystemDock::_compute_uncollapsed_paths() { } void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, bool p_uncollapse_root, bool p_select_in_favorites) { - - // Recreate the tree + // Recreate the tree. tree->clear(); tree_update_id++; updating_tree = true; TreeItem *root = tree->create_item(); - // Handles the favorites + // Handles the favorites. TreeItem *favorites = tree->create_item(root); favorites->set_icon(0, get_icon("Favorites", "EditorIcons")); favorites->set_text(0, TTR("Favorites:")); @@ -185,15 +185,19 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo continue; Ref<Texture> folder_icon = get_icon("Folder", "EditorIcons"); + const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); String text; Ref<Texture> icon; + Color color; if (fave == "res://") { text = "/"; icon = folder_icon; + color = folder_color; } else if (fave.ends_with("/")) { text = fave.substr(0, fave.length() - 1).get_file(); icon = folder_icon; + color = folder_color; } else { text = fave.get_file(); int index; @@ -203,12 +207,14 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo } else { icon = get_icon("File", "EditorIcons"); } + color = Color(1, 1, 1); } if (searched_string.length() == 0 || text.to_lower().find(searched_string) >= 0) { TreeItem *ti = tree->create_item(favorites); ti->set_text(0, text); ti->set_icon(0, icon); + ti->set_icon_modulate(0, color); ti->set_tooltip(0, fave); ti->set_selectable(0, true); ti->set_metadata(0, fave); @@ -230,7 +236,7 @@ void FileSystemDock::_update_tree(const Vector<String> &p_uncollapsed_paths, boo uncollapsed_paths.push_back("res://"); } - // Create the remaining of the tree + // Create the remaining of the tree. _create_tree(root, EditorFileSystem::get_singleton()->get_filesystem(), uncollapsed_paths, p_select_in_favorites); tree->ensure_cursor_is_visible(); updating_tree = false; @@ -242,7 +248,7 @@ void FileSystemDock::set_display_mode(DisplayMode p_display_mode) { } void FileSystemDock::_update_display_mode(bool p_force) { - // Compute the new display mode + // Compute the new display mode. if (p_force || old_display_mode != display_mode) { button_toggle_display_mode->set_pressed(display_mode == DISPLAY_MODE_SPLIT); switch (display_mode) { @@ -275,11 +281,8 @@ void FileSystemDock::_update_display_mode(bool p_force) { } void FileSystemDock::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - if (initialized) return; initialized = true; @@ -319,18 +322,15 @@ void FileSystemDock::_notification(int p_what) { } else { _update_tree(Vector<String>(), true); } - } break; + case NOTIFICATION_PROCESS: { if (EditorFileSystem::get_singleton()->is_scanning()) { scanning_progress->set_value(EditorFileSystem::get_singleton()->get_scanning_progress() * 100); } } break; - case NOTIFICATION_EXIT_TREE: { - } break; case NOTIFICATION_DRAG_BEGIN: { - Dictionary dd = get_viewport()->gui_get_drag_data(); if (tree->is_visible_in_tree() && dd.has("type")) { if ((String(dd["type"]) == "files") || (String(dd["type"]) == "files_and_dirs") || (String(dd["type"]) == "resource")) { @@ -339,20 +339,20 @@ void FileSystemDock::_notification(int p_what) { tree->set_drop_mode_flags(Tree::DROP_MODE_INBETWEEN); } } - } break; - case NOTIFICATION_DRAG_END: { + case NOTIFICATION_DRAG_END: { tree->set_drop_mode_flags(0); - } break; + case NOTIFICATION_THEME_CHANGED: { if (is_visible_in_tree()) { _update_display_mode(true); } } break; + case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - // Update icons + // Update icons. String ei = "EditorIcons"; button_reload->set_icon(get_icon("Reload", ei)); button_toggle_display_mode->set_icon(get_icon("Panels2", ei)); @@ -369,48 +369,47 @@ void FileSystemDock::_notification(int p_what) { file_list_search_box->set_right_icon(get_icon("Search", ei)); file_list_search_box->set_clear_button_enabled(true); - // Update always showfolders + // Update always show folders. bool new_always_show_folders = bool(EditorSettings::get_singleton()->get("docks/filesystem/always_show_folders")); if (new_always_show_folders != always_show_folders) { always_show_folders = new_always_show_folders; _update_file_list(true); } - // Change full tree mode + // Change full tree mode. _update_display_mode(); - } break; } } void FileSystemDock::_tree_multi_selected(Object *p_item, int p_column, bool p_selected) { - // Update the import dock + // Update the import dock. import_dock_needs_update = true; call_deferred("_update_import_dock"); - // Return if we don't select something new + // Return if we don't select something new. if (!p_selected) return; - // Tree item selected + // Tree item selected. TreeItem *selected = tree->get_selected(); if (!selected) return; TreeItem *favorites_item = tree->get_root()->get_children(); if (selected->get_parent() == favorites_item && !String(selected->get_metadata(0)).ends_with("/")) { - // Go to the favorites if we click in the favorites and the path has changed + // Go to the favorites if we click in the favorites and the path has changed. path = "Favorites"; } else { path = selected->get_metadata(0); - // Note: the "Favorites" item also leads to this path + // Note: the "Favorites" item also leads to this path. } - // Set the current path + // Set the current path. _set_current_path_text(path); _push_to_history(); - // Update the file list + // Update the file list. if (!updating_tree && display_mode == DISPLAY_MODE_SPLIT) { _update_file_list(false); } @@ -424,7 +423,6 @@ String FileSystemDock::get_selected_path() const { } String FileSystemDock::get_current_path() const { - return path; } @@ -452,8 +450,7 @@ void FileSystemDock::_navigate_to_path(const String &p_path, bool p_select_in_fa path = target_path + "/"; } else { memdelete(dirAccess); - ERR_EXPLAIN(vformat(TTR("Cannot navigate to '%s' as it has not been found in the file system!"), p_path)); - ERR_FAIL(); + ERR_FAIL_MSG(vformat("Cannot navigate to '%s' as it has not been found in the file system!", p_path)); } memdelete(dirAccess); } @@ -484,7 +481,6 @@ void FileSystemDock::navigate_to_path(const String &p_path) { } void FileSystemDock::_file_list_thumbnail_done(const String &p_path, const Ref<Texture> &p_preview, const Ref<Texture> &p_small_preview, const Variant &p_udata) { - if ((file_list_vb->is_visible_in_tree() || path == p_path.get_base_dir()) && p_preview.is_valid()) { Array uarr = p_udata; int idx = uarr[0]; @@ -532,7 +528,6 @@ void FileSystemDock::_set_file_display(bool p_active) { } bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName &p_class) { - Ref<EditorFeatureProfile> profile = EditorFeatureProfileManager::get_singleton()->get_current_profile(); if (profile.is_null()) { return false; @@ -552,7 +547,6 @@ bool FileSystemDock::_is_file_type_disabled_by_feature_profile(const StringName } void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> *matches, int p_max_items) { - if (matches->size() > p_max_items) return; @@ -570,10 +564,9 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * fi.type = p_path->get_file_type(i); fi.path = p_path->get_file_path(i); fi.import_broken = !p_path->get_file_import_is_valid(i); - fi.import_status = 0; if (_is_file_type_disabled_by_feature_profile(fi.type)) { - //this type is disabled, will not appear here + // This type is disabled, will not appear here. continue; } @@ -585,8 +578,7 @@ void FileSystemDock::_search(EditorFileSystemDirectory *p_path, List<FileInfo> * } void FileSystemDock::_update_file_list(bool p_keep_selection) { - - // Register the previously selected items + // Register the previously selected items. Set<String> cselection; if (p_keep_selection) { for (int i = 0; i < files->get_item_count(); i++) { @@ -612,7 +604,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { bool use_thumbnails = (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS); if (use_thumbnails) { - // Thumbnails mode + // Thumbnails mode. files->set_max_columns(0); files->set_icon_mode(ItemList::ICON_MODE_TOP); files->set_fixed_column_width(thumbnail_size * 3 / 2); @@ -629,8 +621,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { file_thumbnail_broken = get_icon("FileDeadBigThumb", ei); } } else { - - // No thumbnails + // No thumbnails. files->set_icon_mode(ItemList::ICON_MODE_LEFT); files->set_max_columns(1); files->set_max_text_lines(1); @@ -639,11 +630,12 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } Ref<Texture> folder_icon = (use_thumbnails) ? folder_thumbnail : get_icon("folder", "FileDialog"); + const Color folder_color = get_color("folder_icon_modulate", "FileDialog"); - // Build the FileInfo list + // Build the FileInfo list. List<FileInfo> filelist; if (path == "Favorites") { - // Display the favorites + // Display the favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < favorites.size(); i++) { String favorite = favorites[i]; @@ -677,7 +669,6 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { fi.type = ""; fi.import_broken = true; } - fi.import_status = 0; if (searched_string.length() == 0 || fi.name.to_lower().find(searched_string) >= 0) { filelist.push_back(fi); @@ -685,8 +676,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } } } else { - - // Get infos on the directory + file + // Get infos on the directory + file. if (directory.ends_with("/") && directory != "res://") { directory = directory.substr(0, directory.length() - 1); } @@ -700,13 +690,11 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { return; if (searched_string.length() > 0) { - // Display the search results + // Display the search results. _search(EditorFileSystem::get_singleton()->get_filesystem(), &filelist, 128); } else { - if (display_mode == DISPLAY_MODE_TREE_ONLY || always_show_folders) { - // Display folders in the list - + // Display folders in the list. if (directory != "res://") { files->add_item("..", folder_icon, true); @@ -716,14 +704,15 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->set_item_metadata(files->get_item_count() - 1, bd); files->set_item_selectable(files->get_item_count() - 1, false); + files->set_item_icon_modulate(files->get_item_count() - 1, folder_color); } for (int i = 0; i < efd->get_subdir_count(); i++) { - String dname = efd->get_subdir(i)->get_name(); files->add_item(dname, folder_icon, true); files->set_item_metadata(files->get_item_count() - 1, directory.plus_file(dname) + "/"); + files->set_item_icon_modulate(files->get_item_count() - 1, folder_color); if (cselection.has(dname)) { files->select(files->get_item_count() - 1, false); @@ -731,15 +720,13 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { } } - // Display the folder content + // Display the folder content. for (int i = 0; i < efd->get_file_count(); i++) { - FileInfo fi; fi.name = efd->get_file(i); fi.path = directory.plus_file(fi.name); fi.type = efd->get_file_type(i); fi.import_broken = !efd->get_file_import_is_valid(i); - fi.import_status = 0; filelist.push_back(fi); } @@ -747,7 +734,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { filelist.sort(); } - // Fills the ItemList control node from the FileInfos + // Fills the ItemList control node from the FileInfos. String oi = "Object"; for (List<FileInfo>::Element *E = filelist.front(); E; E = E->next()) { FileInfo *finfo = &(E->get()); @@ -760,7 +747,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { String tooltip = fpath; - // Select the icons + // Select the icons. if (!finfo->import_broken) { type_icon = (has_icon(ftype, ei)) ? get_icon(ftype, ei) : get_icon(oi, ei); big_icon = file_thumbnail; @@ -770,7 +757,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { tooltip += "\n" + TTR("Status: Import of file failed. Please fix file and reimport manually."); } - // Add the item to the ItemList + // Add the item to the ItemList. int item_index; if (use_thumbnails) { files->add_item(fname, big_icon, true); @@ -784,7 +771,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->set_item_metadata(item_index, fpath); } - // Generate the preview + // Generate the preview. if (!finfo->import_broken) { Array udata; udata.resize(2); @@ -793,7 +780,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { EditorResourcePreview::get_singleton()->queue_resource_preview(fpath, this, "_file_list_thumbnail_done", udata); } - // Select the items + // Select the items. if (cselection.has(fname)) files->select(item_index, false); @@ -802,7 +789,7 @@ void FileSystemDock::_update_file_list(bool p_keep_selection) { files->ensure_current_is_visible(); } - // Tooltip + // Tooltip. if (finfo->sources.size()) { for (int j = 0; j < finfo->sources.size(); j++) { tooltip += "\nSource: " + finfo->sources[j]; @@ -849,13 +836,12 @@ void FileSystemDock::_file_list_activate_file(int p_idx) { } void FileSystemDock::_preview_invalidated(const String &p_path) { - if (file_list_display_mode == FILE_LIST_DISPLAY_THUMBNAILS && p_path.get_base_dir() == path && searched_string.length() == 0 && file_list_vb->is_visible_in_tree()) { for (int i = 0; i < files->get_item_count(); i++) { if (files->get_item_metadata(i) == p_path) { - //re-request preview + // Re-request preview. Array udata; udata.resize(2); udata[0] = i; @@ -868,7 +854,6 @@ void FileSystemDock::_preview_invalidated(const String &p_path) { } void FileSystemDock::_fs_changed() { - button_hist_prev->set_disabled(history_pos == 0); button_hist_next->set_disabled(history_pos == history.size() - 1); scanning_vb->hide(); @@ -886,7 +871,6 @@ void FileSystemDock::_fs_changed() { } void FileSystemDock::_set_scanning_mode() { - button_hist_prev->set_disabled(true); button_hist_next->set_disabled(true); split_box->hide(); @@ -900,7 +884,6 @@ void FileSystemDock::_set_scanning_mode() { } void FileSystemDock::_fw_history() { - if (history_pos < history.size() - 1) history_pos++; @@ -978,7 +961,7 @@ void FileSystemDock::_find_remaps(EditorFileSystemDirectory *efsd, const Map<Str void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_new_path, Map<String, String> &p_file_renames, Map<String, String> &p_folder_renames) { - //Ensure folder paths end with "/" + // Ensure folder paths end with "/". String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/"); String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/"); @@ -988,12 +971,12 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root.")); return; } else if (!p_item.is_file && new_path.begins_with(old_path)) { - //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/" + // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/". EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n"); return; } - //Build a list of files which will have new paths as a result of this operation + // Build a list of files which will have new paths as a result of this operation. Vector<String> file_changed_paths; Vector<String> folder_changed_paths; if (p_item.is_file) { @@ -1007,8 +990,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ print_verbose("Moving " + old_path + " -> " + new_path); Error err = da->rename(old_path, new_path); if (err == OK) { - - //Move/Rename any corresponding import settings too + // Move/Rename any corresponding import settings too. if (p_item.is_file && FileAccess::exists(old_path + ".import")) { err = da->rename(old_path + ".import", new_path + ".import"); if (err != OK) { @@ -1016,7 +998,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } } - // update scene if it is open + // Update scene if it is open. for (int i = 0; i < file_changed_paths.size(); ++i) { String new_item_path = p_item.is_file ? new_path : file_changed_paths[i].replace_first(old_path, new_path); if (ResourceLoader::get_resource_type(new_item_path) == "PackedScene" && editor->is_scene_open(file_changed_paths[i])) { @@ -1031,7 +1013,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } } - //Only treat as a changed dependency if it was successfully moved + // Only treat as a changed dependency if it was successfully moved. for (int i = 0; i < file_changed_paths.size(); ++i) { p_file_renames[file_changed_paths[i]] = file_changed_paths[i].replace_first(old_path, new_path); print_verbose(" Remap: " + file_changed_paths[i] + " -> " + p_file_renames[file_changed_paths[i]]); @@ -1048,7 +1030,7 @@ void FileSystemDock::_try_move_item(const FileOrFolder &p_item, const String &p_ } void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const String &p_new_path) const { - //Ensure folder paths end with "/" + // Ensure folder paths end with "/". String old_path = (p_item.is_file || p_item.path.ends_with("/")) ? p_item.path : (p_item.path + "/"); String new_path = (p_item.is_file || p_new_path.ends_with("/")) ? p_new_path : (p_new_path + "/"); @@ -1058,7 +1040,7 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin EditorNode::get_singleton()->add_io_error(TTR("Cannot move/rename resources root.")); return; } else if (!p_item.is_file && new_path.begins_with(old_path)) { - //This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/" + // This check doesn't erroneously catch renaming to a longer name as folder paths always end with "/". EditorNode::get_singleton()->add_io_error(TTR("Cannot move a folder into itself.") + "\n" + old_path + "\n"); return; } @@ -1067,7 +1049,7 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin print_verbose("Duplicating " + old_path + " -> " + new_path); Error err = p_item.is_file ? da->copy(old_path, new_path) : da->copy_dir(old_path, new_path); if (err == OK) { - //Move/Rename any corresponding import settings too + // Move/Rename any corresponding import settings too. if (p_item.is_file && FileAccess::exists(old_path + ".import")) { err = da->copy(old_path + ".import", new_path + ".import"); if (err != OK) { @@ -1081,13 +1063,11 @@ void FileSystemDock::_try_duplicate_item(const FileOrFolder &p_item, const Strin } void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> &p_renames) const { - - //Rename all resources loaded, be it subresources or actual resources + // Rename all resources loaded, be it subresources or actual resources. List<Ref<Resource> > cached; ResourceCache::get_cached_resources(&cached); for (List<Ref<Resource> >::Element *E = cached.front(); E; E = E->next()) { - Ref<Resource> r = E->get(); String base_path = r->get_path(); @@ -1106,7 +1086,6 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> } for (int i = 0; i < EditorNode::get_editor_data().get_edited_scene_count(); i++) { - String path; if (i == EditorNode::get_editor_data().get_edited_scene()) { if (!get_tree()->get_edited_scene_root()) @@ -1114,7 +1093,6 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> path = get_tree()->get_edited_scene_root()->get_filename(); } else { - path = EditorNode::get_editor_data().get_scene_path(i); } @@ -1123,23 +1101,21 @@ void FileSystemDock::_update_resource_paths_after_move(const Map<String, String> } if (i == EditorNode::get_editor_data().get_edited_scene()) { - get_tree()->get_edited_scene_root()->set_filename(path); } else { - EditorNode::get_editor_data().set_scene_path(i, path); } } } void FileSystemDock::_update_dependencies_after_move(const Map<String, String> &p_renames) const { - //The following code assumes that the following holds: + // The following code assumes that the following holds: // 1) EditorFileSystem contains the old paths/folder structure from before the rename/move. // 2) ResourceLoader can use the new paths without needing to call rescan. Vector<String> remaps; _find_remaps(EditorFileSystem::get_singleton()->get_filesystem(), p_renames, remaps); for (int i = 0; i < remaps.size(); ++i) { - //Because we haven't called a rescan yet the found remap might still be an old path itself. + // Because we haven't called a rescan yet the found remap might still be an old path itself. String file = p_renames.has(remaps[i]) ? p_renames[remaps[i]] : remaps[i]; print_verbose("Remapping dependencies for: " + file); Error err = ResourceLoader::rename_dependencies(file, p_renames); @@ -1153,8 +1129,7 @@ void FileSystemDock::_update_dependencies_after_move(const Map<String, String> & } void FileSystemDock::_update_project_settings_after_move(const Map<String, String> &p_renames) const { - - // Find all project settings of type FILE and replace them if needed + // Find all project settings of type FILE and replace them if needed. const Map<StringName, PropertyInfo> prop_info = ProjectSettings::get_singleton()->get_custom_property_info(); for (const Map<StringName, PropertyInfo>::Element *E = prop_info.front(); E; E = E->next()) { if (E->get().hint == PROPERTY_HINT_FILE) { @@ -1185,7 +1160,6 @@ void FileSystemDock::_update_project_settings_after_move(const Map<String, Strin } void FileSystemDock::_update_favorites_list_after_move(const Map<String, String> &p_files_renames, const Map<String, String> &p_folders_renames) const { - Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); Vector<String> new_favorites; @@ -1250,6 +1224,48 @@ void FileSystemDock::_make_dir_confirm() { } } +void FileSystemDock::_make_scene_confirm() { + String scene_name = make_scene_dialog_text->get_text().strip_edges(); + + if (scene_name.length() == 0) { + EditorNode::get_singleton()->show_warning(TTR("No name provided.")); + return; + } + + String directory = path; + if (!directory.ends_with("/")) { + directory = directory.get_base_dir(); + } + + String extension = scene_name.get_extension(); + List<String> extensions; + Ref<PackedScene> sd = memnew(PackedScene); + ResourceSaver::get_recognized_extensions(sd, &extensions); + + bool extension_correct = false; + for (List<String>::Element *E = extensions.front(); E; E = E->next()) { + if (E->get() == extension) { + extension_correct = true; + break; + } + } + if (!extension_correct) + scene_name = scene_name.get_basename() + ".tscn"; + + scene_name = directory.plus_file(scene_name); + + DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + if (da->file_exists(scene_name)) { + EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists.")); + memdelete(da); + return; + } + memdelete(da); + + int idx = editor->new_scene(); + editor->get_editor_data().set_scene_path(idx, scene_name); +} + void FileSystemDock::_file_deleted(String p_file) { emit_signal("file_deleted", p_file); } @@ -1259,7 +1275,6 @@ void FileSystemDock::_folder_deleted(String p_folder) { } void FileSystemDock::_rename_operation_confirm() { - String new_name = rename_dialog_text->get_text().strip_edges(); if (new_name.length() == 0) { EditorNode::get_singleton()->show_warning(TTR("No name provided.")); @@ -1279,10 +1294,10 @@ void FileSystemDock::_rename_operation_confirm() { EditorFileSystem::get_singleton()->move_group_file(old_path, new_path); } - //Present a more user friendly warning for name conflict + // Present a more user friendly warning for name conflict. DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); #if defined(WINDOWS_ENABLED) || defined(UWP_ENABLED) - // Workaround case insensitivity on Windows + // Workaround case insensitivity on Windows. if ((da->file_exists(new_path) || da->dir_exists(new_path)) && new_path.to_lower() != old_path.to_lower()) { #else if (da->file_exists(new_path) || da->dir_exists(new_path)) { @@ -1314,7 +1329,6 @@ void FileSystemDock::_rename_operation_confirm() { } void FileSystemDock::_duplicate_operation_confirm() { - String new_name = duplicate_dialog_text->get_text().strip_edges(); if (new_name.length() == 0) { EditorNode::get_singleton()->show_warning(TTR("No name provided.")); @@ -1332,7 +1346,7 @@ void FileSystemDock::_duplicate_operation_confirm() { String new_path = base_dir.plus_file(new_name); - //Present a more user friendly warning for name conflict + // Present a more user friendly warning for name conflict DirAccess *da = DirAccess::create(DirAccess::ACCESS_RESOURCES); if (da->file_exists(new_path) || da->dir_exists(new_path)) { EditorNode::get_singleton()->show_warning(TTR("A file or folder with this name already exists.")); @@ -1343,7 +1357,7 @@ void FileSystemDock::_duplicate_operation_confirm() { _try_duplicate_item(to_duplicate, new_path); - //Rescan everything + // Rescan everything. print_verbose("FileSystem: calling rescan."); _rescan(); } @@ -1376,14 +1390,14 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw to_move_path = p_to_path; bool can_move = _check_existing(); if (!can_move) { - //ask to do something + // Ask to do something. overwrite_dialog->popup_centered_minsize(); overwrite_dialog->grab_focus(); return; } } - //check groups + // Check groups. for (int i = 0; i < to_move.size(); i++) { print_line("is group: " + to_move[i].path + ": " + itos(EditorFileSystem::get_singleton()->is_group_file(to_move[i].path))); @@ -1424,7 +1438,7 @@ void FileSystemDock::_move_operation_confirm(const String &p_to_path, bool overw } Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { - // Build a list of selected items with the active one at the first position + // Build a list of selected items with the active one at the first position. Vector<String> selected_strings; TreeItem *favorites_item = tree->get_root()->get_children(); @@ -1442,8 +1456,15 @@ Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { selected = tree->get_next_selected(selected); } - // Remove paths or files that are included into another - if (remove_self_inclusion && selected_strings.size() > 1) { + if (remove_self_inclusion) { + selected_strings = _remove_self_included_paths(selected_strings); + } + return selected_strings; +} + +Vector<String> FileSystemDock::_remove_self_included_paths(Vector<String> selected_strings) { + // Remove paths or files that are included into another. + if (selected_strings.size() > 1) { selected_strings.sort_custom<NaturalNoCaseComparator>(); String last_path = ""; for (int i = 0; i < selected_strings.size(); i++) { @@ -1460,10 +1481,9 @@ Vector<String> FileSystemDock::_tree_get_selected(bool remove_self_inclusion) { } void FileSystemDock::_tree_rmb_option(int p_option) { + Vector<String> selected_strings = _tree_get_selected(false); - Vector<String> selected_strings = _tree_get_selected(); - - // Execute the current option + // Execute the current option. switch (p_option) { case FOLDER_EXPAND_ALL: case FOLDER_COLLAPSE_ALL: { @@ -1503,11 +1523,11 @@ void FileSystemDock::_file_list_rmb_option(int p_option) { } void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected) { - // The first one should be the active item + // The first one should be the active item. switch (p_option) { case FILE_SHOW_IN_EXPLORER: { - // Show the file / folder in the OS explorer + // Show the file/folder in the OS explorer. String fpath = path; if (path == "Favorites") { fpath = p_selected[0]; @@ -1521,7 +1541,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_OPEN: { - // Open folders + // Open folders. TreeItem *selected = tree->get_root(); selected = tree->get_next_selected(selected); while (selected) { @@ -1530,21 +1550,21 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } selected = tree->get_next_selected(selected); } - // Open the file + // Open the file. for (int i = 0; i < p_selected.size(); i++) { _select_file(p_selected[i]); } } break; case FILE_INHERIT: { - // Create a new scene inherited from the selected one + // Create a new scene inherited from the selected one. if (p_selected.size() == 1) { emit_signal("inherit", p_selected[0]); } } break; case FILE_INSTANCE: { - // Instance all selected scenes + // Instance all selected scenes. Vector<String> paths; for (int i = 0; i < p_selected.size(); i++) { String fpath = p_selected[i]; @@ -1558,7 +1578,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_ADD_FAVORITE: { - // Add the files from favorites + // Add the files from favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < p_selected.size(); i++) { if (favorites.find(p_selected[i]) == -1) { @@ -1570,7 +1590,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REMOVE_FAVORITE: { - // Remove the files from favorites + // Remove the files from favorites. Vector<String> favorites = EditorSettings::get_singleton()->get_favorites(); for (int i = 0; i < p_selected.size(); i++) { favorites.erase(p_selected[i]); @@ -1582,7 +1602,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_DEPENDENCIES: { - // Checkout the file dependencies + // Checkout the file dependencies. if (!p_selected.empty()) { String fpath = p_selected[0]; deps_editor->edit(fpath); @@ -1590,7 +1610,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_OWNERS: { - // Checkout the file owners + // Checkout the file owners. if (!p_selected.empty()) { String fpath = p_selected[0]; owners_editor->show(fpath); @@ -1598,10 +1618,11 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_MOVE: { - // Move the files to a given location + // Move the files to a given location. to_move.clear(); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + Vector<String> collapsed_paths = _remove_self_included_paths(p_selected); + for (int i = collapsed_paths.size() - 1; i >= 0; i--) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { to_move.push_back(FileOrFolder(fpath, !fpath.ends_with("/"))); } @@ -1612,7 +1633,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_RENAME: { - // Rename the active file + // Rename the active file. if (!p_selected.empty()) { to_rename.path = p_selected[0]; if (to_rename.path != "res://") { @@ -1635,12 +1656,13 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REMOVE: { - // Remove the selected files + // Remove the selected files. Vector<String> remove_files; Vector<String> remove_folders; + Vector<String> collapsed_paths = _remove_self_included_paths(p_selected); - for (int i = 0; i < p_selected.size(); i++) { - String fpath = p_selected[i]; + for (int i = 0; i < collapsed_paths.size(); i++) { + String fpath = collapsed_paths[i]; if (fpath != "res://") { if (fpath.ends_with("/")) { remove_folders.push_back(fpath); @@ -1656,7 +1678,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_DUPLICATE: { - // Duplicate the selected files + // Duplicate the selected files. for (int i = 0; i < p_selected.size(); i++) { to_duplicate.path = p_selected[i]; to_duplicate.is_file = !to_duplicate.path.ends_with("/"); @@ -1681,7 +1703,7 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_REIMPORT: { - // Reimport all selected files + // Reimport all selected files. Vector<String> reimport; for (int i = 0; i < p_selected.size(); i++) { reimport.push_back(p_selected[i]); @@ -1691,15 +1713,20 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_FOLDER: { - // Create a new folder make_dir_dialog_text->set_text("new folder"); make_dir_dialog_text->select_all(); make_dir_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE); make_dir_dialog_text->grab_focus(); } break; + case FILE_NEW_SCENE: { + make_scene_dialog_text->set_text("new scene"); + make_scene_dialog_text->select_all(); + make_scene_dialog->popup_centered_minsize(Size2(250, 80) * EDSCALE); + make_scene_dialog_text->grab_focus(); + } break; + case FILE_NEW_SCRIPT: { - // Create a new script String fpath = path; if (!fpath.ends_with("/")) { fpath = fpath.get_base_dir(); @@ -1709,7 +1736,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_COPY_PATH: { - // Copy the file path if (!p_selected.empty()) { String fpath = p_selected[0]; OS::get_singleton()->set_clipboard(fpath); @@ -1717,7 +1743,6 @@ void FileSystemDock::_file_option(int p_option, const Vector<String> &p_selected } break; case FILE_NEW_RESOURCE: { - // Create a new resource new_resource_dialog->popup_create(true); } break; } @@ -1745,7 +1770,7 @@ void FileSystemDock::_resource_created() const { void FileSystemDock::_search_changed(const String &p_text, const Control *p_from) { if (searched_string.length() == 0 && p_text.length() > 0) { - // Register the uncollapsed paths before they change + // Register the uncollapsed paths before they change. uncollapsed_paths_before_search = _compute_uncollapsed_paths(); } @@ -1753,7 +1778,7 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from if (p_from == tree_search_box) file_list_search_box->set_text(searched_string); - else // file_list_search_box + else // File_list_search_box. tree_search_box->set_text(searched_string); switch (display_mode) { @@ -1768,7 +1793,6 @@ void FileSystemDock::_search_changed(const String &p_text, const Control *p_from } void FileSystemDock::_rescan() { - _set_scanning_mode(); EditorFileSystem::get_singleton()->scan(); } @@ -1783,12 +1807,10 @@ void FileSystemDock::fix_dependencies(const String &p_for_file) { } void FileSystemDock::focus_on_filter() { - file_list_search_box->grab_focus(); } void FileSystemDock::set_file_list_display_mode(FileListDisplayMode p_mode) { - if (p_mode == file_list_display_mode) return; @@ -1802,12 +1824,12 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) Vector<String> paths; if (p_from == tree) { - // Check if the first selected is in favorite + // Check if the first selected is in favorite. TreeItem *selected = tree->get_next_selected(tree->get_root()); while (selected) { TreeItem *favorites_item = tree->get_root()->get_children(); if (selected == favorites_item) { - // The "Favorites" item is not draggable + // The "Favorites" item is not draggable. return Variant(); } @@ -1845,12 +1867,11 @@ Variant FileSystemDock::get_drag_data_fw(const Point2 &p_point, Control *p_from) } bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { - Dictionary drag_data = p_data; if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { - // Moving favorite around + // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); if (!ti) return false; @@ -1861,20 +1882,20 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da TreeItem *resources_item = favorites_item->get_next(); if (ti == favorites_item) { - return (drop_section == 1); // The parent, first fav + return (drop_section == 1); // The parent, first fav. } if (ti->get_parent() && favorites_item == ti->get_parent()) { return true; // A favorite } if (ti == resources_item) { - return (drop_section == -1); // The tree, last fav + return (drop_section == -1); // The tree, last fav. } return false; } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - // Move resources + // Move resources. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -1882,7 +1903,7 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { - // Move files or dir + // Move files or dir. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -1893,8 +1914,8 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da 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 + // 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"]; for (int i = 0; i < fnames.size(); ++i) { @@ -1909,7 +1930,6 @@ bool FileSystemDock::can_drop_data_fw(const Point2 &p_point, const Variant &p_da } void FileSystemDock::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 drag_data = p_data; @@ -1917,7 +1937,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, Vector<String> dirs = EditorSettings::get_singleton()->get_favorites(); if (drag_data.has("type") && String(drag_data["type"]) == "favorite") { - // Moving favorite around + // Moving favorite around. TreeItem *ti = tree->get_item_at_position(p_point); if (!ti) return; @@ -1929,20 +1949,20 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, TreeItem *resources_item = favorites_item->get_next(); if (ti == favorites_item) { - // Drop on the favorite folder + // Drop on the favorite folder. drop_position = 0; } else if (ti == resources_item) { - // Drop on the resource item + // Drop on the resource item. drop_position = dirs.size(); } else { - // Drop in the list + // Drop in the list. drop_position = dirs.find(ti->get_metadata(0)); if (drop_section == 1) { drop_position++; } } - // Remove dragged favorites + // Remove dragged favorites. Vector<int> to_remove; int offset = 0; for (int i = 0; i < files.size(); i++) { @@ -1958,7 +1978,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, dirs.remove(to_remove[i] - i); } - // Re-add them at the right position + // Re-add them at the right position. for (int i = 0; i < files.size(); i++) { dirs.insert(drop_position, files[i]); drop_position++; @@ -1973,7 +1993,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } if (drag_data.has("type") && String(drag_data["type"]) == "resource") { - // Moving resource + // Moving resource. Ref<Resource> res = drag_data["resource"]; String to_dir; bool favorite; @@ -1985,7 +2005,7 @@ void FileSystemDock::drop_data_fw(const Point2 &p_point, const Variant &p_data, } if (drag_data.has("type") && (String(drag_data["type"]) == "files" || String(drag_data["type"]) == "files_and_dirs")) { - // Move files or add to favorites + // Move files or add to favorites. String to_dir; bool favorite; _get_drag_target_folder(to_dir, favorite, p_point, p_from); @@ -2015,7 +2035,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori target = String(); target_favorites = false; - // In the file list + // In the file list. if (p_from == files) { int pos = files->get_item_at_position(p_point, true); if (pos == -1) { @@ -2027,12 +2047,12 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori return; } - // In the tree + // In the tree. if (p_from == tree) { TreeItem *ti = tree->get_item_at_position(p_point); int section = tree->get_drop_section_at_position(p_point); if (ti) { - // Check the favorites first + // Check the favorites first. if (ti == tree->get_root()->get_children() && section >= 0) { target_favorites = true; return; @@ -2043,13 +2063,13 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori String fpath = ti->get_metadata(0); if (section == 0) { if (fpath.ends_with("/")) { - // We drop on a folder + // We drop on a folder. target = fpath; return; } } else { if (ti->get_parent() != tree->get_root()->get_children()) { - // Not in the favorite section + // Not in the favorite section. if (fpath != "res://") { // We drop between two files if (fpath.ends_with("/")) { @@ -2066,7 +2086,7 @@ void FileSystemDock::_get_drag_target_folder(String &target, bool &target_favori } void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<String> p_paths, bool p_display_path_dependent_options) { - // Add options for files and folders + // Add options for files and folders. ERR_FAIL_COND(p_paths.empty()); Vector<String> filenames; @@ -2090,7 +2110,7 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str all_files_scenes &= (EditorFileSystem::get_singleton()->get_file_type(fpath) == "PackedScene"); } - // Check if in favorites + // Check if in favorites. bool found = false; for (int j = 0; j < favorites.size(); j++) { if (favorites[j] == fpath) { @@ -2106,7 +2126,6 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } if (all_files) { - if (all_files_scenes) { if (filenames.size() == 1) { p_popup->add_item(TTR("Open Scene"), FILE_OPEN); @@ -2146,19 +2165,25 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str if (p_paths.size() == 1) { p_popup->add_item(TTR("Copy Path"), FILE_COPY_PATH); - p_popup->add_item(TTR("Rename..."), FILE_RENAME); - p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + if (p_paths[0] != "res://") { + p_popup->add_item(TTR("Rename..."), FILE_RENAME); + p_popup->add_item(TTR("Duplicate..."), FILE_DUPLICATE); + } } - p_popup->add_item(TTR("Move To..."), FILE_MOVE); - p_popup->add_item(TTR("Delete"), FILE_REMOVE); + if (p_paths.size() > 1 || p_paths[0] != "res://") { + p_popup->add_item(TTR("Move To..."), FILE_MOVE); + p_popup->add_item(TTR("Delete"), FILE_REMOVE); + } if (p_paths.size() == 1) { p_popup->add_separator(); if (p_display_path_dependent_options) { p_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); + p_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); p_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); p_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); + p_popup->add_separator(); } String fpath = p_paths[0]; @@ -2168,8 +2193,8 @@ void FileSystemDock::_file_and_folders_fill_popup(PopupMenu *p_popup, Vector<Str } void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { - // Right click is pressed in the tree - Vector<String> paths = _tree_get_selected(); + // Right click is pressed in the tree. + Vector<String> paths = _tree_get_selected(false); if (paths.size() == 1) { if (paths[0].ends_with("/")) { @@ -2179,7 +2204,7 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { } } - // Popup + // Popup. if (!paths.empty()) { tree_popup->clear(); tree_popup->set_size(Size2(1, 1)); @@ -2190,11 +2215,12 @@ void FileSystemDock::_tree_rmb_select(const Vector2 &p_pos) { } void FileSystemDock::_tree_rmb_empty(const Vector2 &p_pos) { - // Right click is pressed in the empty space of the tree + // Right click is pressed in the empty space of the tree. path = "res://"; tree_popup->clear(); tree_popup->set_size(Size2(1, 1)); tree_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); + tree_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); tree_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); tree_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); tree_popup->set_position(tree->get_global_position() + p_pos); @@ -2206,7 +2232,7 @@ void FileSystemDock::_tree_empty_selected() { } void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { - // Right click is pressed in the file list + // Right click is pressed in the file list. Vector<String> paths; for (int i = 0; i < files->get_item_count(); i++) { if (!files->is_selected(i)) @@ -2218,7 +2244,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { paths.push_back(files->get_item_metadata(i)); } - // Popup + // Popup. if (!paths.empty()) { file_list_popup->clear(); file_list_popup->set_size(Size2(1, 1)); @@ -2229,7 +2255,7 @@ void FileSystemDock::_file_list_rmb_select(int p_item, const Vector2 &p_pos) { } void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { - // Right click on empty space for file list + // Right click on empty space for file list. if (searched_string.length() > 0) return; @@ -2237,21 +2263,21 @@ void FileSystemDock::_file_list_rmb_pressed(const Vector2 &p_pos) { file_list_popup->set_size(Size2(1, 1)); file_list_popup->add_item(TTR("New Folder..."), FILE_NEW_FOLDER); + file_list_popup->add_item(TTR("New Scene..."), FILE_NEW_SCENE); file_list_popup->add_item(TTR("New Script..."), FILE_NEW_SCRIPT); file_list_popup->add_item(TTR("New Resource..."), FILE_NEW_RESOURCE); - file_list_popup->add_item(TTR("Show in File Manager"), FILE_SHOW_IN_EXPLORER); + file_list_popup->add_separator(); + file_list_popup->add_item(TTR("Open in File Manager"), FILE_SHOW_IN_EXPLORER); file_list_popup->set_position(files->get_global_position() + p_pos); file_list_popup->popup(); } void FileSystemDock::select_file(const String &p_file) { - _navigate_to_path(p_file); } void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { - - // Set the path to the current focused item + // Set the path to the current focused item. int current = files->get_current(); if (current == p_index) { String fpath = files->get_item_metadata(current); @@ -2263,15 +2289,14 @@ void FileSystemDock::_file_multi_selected(int p_index, bool p_selected) { } } - // Update the import dock + // Update the import dock. import_dock_needs_update = true; call_deferred("_update_import_dock"); } void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { - if (get_viewport()->get_modal_stack_top()) - return; //ignore because of modal window + return; // Ignore because of modal window. Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { @@ -2288,9 +2313,8 @@ void FileSystemDock::_tree_gui_input(Ref<InputEvent> p_event) { } void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { - if (get_viewport()->get_modal_stack_top()) - return; //ignore because of modal window + return; // Ignore because of modal window. Ref<InputEventKey> key = p_event; if (key.is_valid() && key->is_pressed() && !key->is_echo()) { @@ -2307,18 +2331,17 @@ void FileSystemDock::_file_list_gui_input(Ref<InputEvent> p_event) { } void FileSystemDock::_update_import_dock() { - if (!import_dock_needs_update) return; - // List selected + // List selected. Vector<String> selected; if (display_mode == DISPLAY_MODE_TREE_ONLY) { // Use the tree selected = _tree_get_selected(); } else { - // Use the file list + // Use the file list. for (int i = 0; i < files->get_item_count(); i++) { if (!files->is_selected(i)) continue; @@ -2327,7 +2350,7 @@ void FileSystemDock::_update_import_dock() { } } - // Check import + // Check import. Vector<String> imports; String import_type; for (int i = 0; i < selected.size(); i++) { @@ -2354,7 +2377,7 @@ void FileSystemDock::_update_import_dock() { if (import_type == "") { import_type = type; } else if (import_type != type) { - //all should be the same type + // All should be the same type. imports.clear(); break; } @@ -2373,12 +2396,10 @@ void FileSystemDock::_update_import_dock() { } void FileSystemDock::_feature_profile_changed() { - _update_display_mode(true); } void FileSystemDock::_bind_methods() { - ClassDB::bind_method(D_METHOD("_file_list_gui_input"), &FileSystemDock::_file_list_gui_input); ClassDB::bind_method(D_METHOD("_tree_gui_input"), &FileSystemDock::_tree_gui_input); @@ -2411,6 +2432,7 @@ void FileSystemDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_fs_changed"), &FileSystemDock::_fs_changed); ClassDB::bind_method(D_METHOD("_tree_multi_selected"), &FileSystemDock::_tree_multi_selected); ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileSystemDock::_make_dir_confirm); + ClassDB::bind_method(D_METHOD("_make_scene_confirm"), &FileSystemDock::_make_scene_confirm); ClassDB::bind_method(D_METHOD("_resource_created"), &FileSystemDock::_resource_created); ClassDB::bind_method(D_METHOD("_move_operation_confirm", "to_path", "overwrite"), &FileSystemDock::_move_operation_confirm, DEFVAL(false)); ClassDB::bind_method(D_METHOD("_move_with_overwrite"), &FileSystemDock::_move_with_overwrite); @@ -2442,7 +2464,6 @@ void FileSystemDock::_bind_methods() { } FileSystemDock::FileSystemDock(EditorNode *p_editor) { - set_name("FileSystem"); editor = p_editor; path = "res://"; @@ -2523,7 +2544,6 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { tree->set_custom_minimum_size(Size2(0, 15 * EDSCALE)); split_box->add_child(tree); - tree->connect("item_edited", this, "_favorite_toggled"); tree->connect("item_activated", this, "_tree_activate_file"); tree->connect("multi_selected", this, "_tree_multi_selected"); tree->connect("item_rmb_selected", this, "_tree_rmb_select"); @@ -2626,6 +2646,17 @@ FileSystemDock::FileSystemDock(EditorNode *p_editor) { make_dir_dialog->register_text_enter(make_dir_dialog_text); make_dir_dialog->connect("confirmed", this, "_make_dir_confirm"); + make_scene_dialog = memnew(ConfirmationDialog); + make_scene_dialog->set_title(TTR("Create Scene")); + VBoxContainer *make_scene_dialog_vb = memnew(VBoxContainer); + make_scene_dialog->add_child(make_scene_dialog_vb); + + make_scene_dialog_text = memnew(LineEdit); + make_scene_dialog_vb->add_margin_child(TTR("Name:"), make_scene_dialog_text); + add_child(make_scene_dialog); + make_scene_dialog->register_text_enter(make_scene_dialog_text); + make_scene_dialog->connect("confirmed", this, "_make_scene_confirm"); + make_script_dialog_text = memnew(ScriptCreateDialog); make_script_dialog_text->set_title(TTR("Create Script")); add_child(make_script_dialog_text); diff --git a/editor/filesystem_dock.h b/editor/filesystem_dock.h index 6de370ad29..49eb31e330 100644 --- a/editor/filesystem_dock.h +++ b/editor/filesystem_dock.h @@ -87,6 +87,7 @@ private: FILE_INFO, FILE_NEW_FOLDER, FILE_NEW_SCRIPT, + FILE_NEW_SCENE, FILE_SHOW_IN_EXPLORER, FILE_COPY_PATH, FILE_NEW_RESOURCE, @@ -135,6 +136,8 @@ private: LineEdit *duplicate_dialog_text; ConfirmationDialog *make_dir_dialog; LineEdit *make_dir_dialog_text; + ConfirmationDialog *make_scene_dialog; + LineEdit *make_scene_dialog_text; ConfirmationDialog *overwrite_dialog; ScriptCreateDialog *make_script_dialog_text; CreateDialog *new_resource_dialog; @@ -168,7 +171,7 @@ private: bool updating_tree; int tree_update_id; - Tree *tree; //directories + Tree *tree; ItemList *files; bool import_dock_needs_update; @@ -213,6 +216,7 @@ private: void _resource_created() const; void _make_dir_confirm(); + void _make_scene_confirm(); void _rename_operation_confirm(); void _duplicate_operation_confirm(); void _move_with_overwrite(); @@ -246,7 +250,6 @@ private: String name; String path; StringName type; - int import_status; //0 not imported, 1 - ok, 2- must reimport, 3- broken Vector<String> sources; bool import_broken; @@ -275,6 +278,7 @@ private: bool _is_file_type_disabled_by_feature_profile(const StringName &p_class); void _feature_profile_changed(); + Vector<String> _remove_self_included_paths(Vector<String> selected_strings); protected: void _notification(int p_what); diff --git a/editor/find_in_files.cpp b/editor/find_in_files.cpp index e1ab5c62a7..cc2efb92ae 100644 --- a/editor/find_in_files.cpp +++ b/editor/find_in_files.cpp @@ -524,6 +524,7 @@ FindInFilesPanel::FindInFilesPanel() { _progress_bar = memnew(ProgressBar); _progress_bar->set_h_size_flags(SIZE_EXPAND_FILL); + _progress_bar->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(_progress_bar); set_progress_visible(false); @@ -546,6 +547,7 @@ FindInFilesPanel::FindInFilesPanel() { _results_display->connect("item_edited", this, "_on_item_edited"); _results_display->set_hide_root(true); _results_display->set_select_mode(Tree::SELECT_ROW); + _results_display->set_allow_rmb_select(true); _results_display->create_item(); // Root vbc->add_child(_results_display); diff --git a/editor/icons/icon_editor_curve_handle.svg b/editor/icons/icon_editor_curve_handle.svg new file mode 100644 index 0000000000..c405ceab9d --- /dev/null +++ b/editor/icons/icon_editor_curve_handle.svg @@ -0,0 +1 @@ +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><circle cx="5" cy="5" fill="#fefefe" r="2.75" stroke="#000" stroke-linecap="square"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_editor_path_sharp_handle.svg b/editor/icons/icon_editor_path_sharp_handle.svg new file mode 100644 index 0000000000..db160dfeae --- /dev/null +++ b/editor/icons/icon_editor_path_sharp_handle.svg @@ -0,0 +1 @@ +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><path d="m-3.035534-10.106602h6.071068v6.071068h-6.071068z" fill="#fefefe" stroke="#000" stroke-linecap="square" transform="matrix(-.70710678 .70710678 -.70710678 -.70710678 0 0)"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_editor_path_smooth_handle.svg b/editor/icons/icon_editor_path_smooth_handle.svg new file mode 100644 index 0000000000..34f3d290bd --- /dev/null +++ b/editor/icons/icon_editor_path_smooth_handle.svg @@ -0,0 +1 @@ +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><path d="m1.5-8.5h7v7h-7z" fill="#fefefe" stroke="#000" stroke-linecap="square" transform="rotate(90)"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_gizmo_c_p_u_particles.svg b/editor/icons/icon_gizmo_c_p_u_particles.svg new file mode 100644 index 0000000000..a6f0eaef5b --- /dev/null +++ b/editor/icons/icon_gizmo_c_p_u_particles.svg @@ -0,0 +1,85 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + width="128" + height="128" + version="1.1" + viewBox="0 0 128 128" + id="svg6" + sodipodi:docname="icon_gizmo_c_p_u_particles.svg" + inkscape:version="0.92.4 5da689c313, 2019-01-14"> + <metadata + id="metadata12"> + <rdf:RDF> + <cc:Work + rdf:about=""> + <dc:format>image/svg+xml</dc:format> + <dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> + <dc:title></dc:title> + </cc:Work> + </rdf:RDF> + </metadata> + <defs + id="defs10" /> + <sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1606" + inkscape:window-height="821" + id="namedview8" + showgrid="false" + inkscape:zoom="2.6074563" + inkscape:cx="101.29539" + inkscape:cy="83.191634" + inkscape:window-x="295" + inkscape:window-y="81" + inkscape:window-maximized="0" + inkscape:current-layer="svg6" + fit-margin-top="0" + fit-margin-left="0" + fit-margin-right="0" + fit-margin-bottom="0" /> + <path + style="display:inline;opacity:1;fill:#f7f5cf;fill-opacity:1;stroke:#b4b4b4;stroke-width:2.56380486;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" + d="m 35.503779,1.2819066 c -3.570424,0 -6.435164,2.9483368 -6.435164,6.6019028 v 4.3900146 c 0,0.889114 0.169457,1.726301 0.478513,2.49893 H 19.465369 c -3.570424,0 -6.435167,2.931453 -6.435167,6.585021 v 7.969562 c -0.341543,-0.0568 -0.648813,-0.202614 -1.006525,-0.202614 H 7.7335674 c -3.5704232,0 -6.451665,2.948338 -6.451665,6.601904 v 3.224972 c 0,3.653568 2.8812418,6.585016 6.451665,6.585016 h 4.2901096 c 0.358169,0 0.664563,-0.14568 1.006525,-0.202618 V 83.83104 C 12.688659,83.77398 12.381388,83.628424 12.023677,83.628424 H 7.7335674 c -3.5704232,0 -6.451665,2.948332 -6.451665,6.601908 v 3.224971 c 0,3.653575 2.8812418,6.585017 6.451665,6.585017 h 4.2901096 c 0.358169,0 0.664563,-0.145692 1.006525,-0.202612 v 9.725542 c 0,3.6536 2.864743,6.60193 6.435167,6.60193 h 9.603246 v 3.951 c 0,3.65357 2.86474,6.60192 6.435164,6.60192 h 3.15158 c 3.57042,0 6.451663,-2.94836 6.451663,-6.60192 v -3.95104 h 37.224955 v 3.951 c 0,3.65358 2.86474,6.60193 6.435166,6.60193 h 3.151583 c 3.570418,0 6.451653,-2.94836 6.451653,-6.60193 v -3.951 h 10.725281 c 3.57043,0 6.45166,-2.94833 6.45166,-6.60191 v -9.607372 c 0.14985,0.0105 0.27643,0.0846 0.42899,0.0846 h 4.29014 c 3.5704,0 6.45165,-2.931432 6.45165,-6.585011 v -3.224992 c 0,-3.653565 -2.88125,-6.601906 -6.45165,-6.601906 h -4.29014 c -0.15231,0 -0.27938,0.07348 -0.42899,0.08472 V 45.452198 c 0.14985,0.01042 0.27643,0.08445 0.42899,0.08445 h 4.29014 c 3.5704,0 6.45165,-2.931451 6.45165,-6.585023 v -3.224986 c 0,-3.653566 -2.88125,-6.601906 -6.45165,-6.601906 h -4.29014 c -0.15231,0 -0.27938,0.07392 -0.42899,0.08446 v -7.851429 c 0,-3.653567 -2.88123,-6.585019 -6.45166,-6.585021 H 97.875379 c 0.309043,-0.772641 0.494982,-1.609791 0.494982,-2.498929 V 7.8838054 c 0,-3.6535651 -2.881246,-6.601903 -6.451662,-6.601903 h -3.15158 c -3.570428,0 -6.435167,2.9483379 -6.435167,6.601903 V 12.27382 c 0,0.889115 0.16948,1.726301 0.478507,2.49893 H 44.612011 c 0.309083,-0.772642 0.495011,-1.609792 0.495011,-2.49893 V 7.8838054 c 0,-3.6535651 -2.881243,-6.601903 -6.451663,-6.601903 z" + id="path4542" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="M 62.861474,21.661698 A 27.707285,31.502779 0 0 1 90.004671,47.07312 18.471523,18.901669 0 0 1 105.96058,65.764449 18.471523,18.901669 0 0 1 87.480108,84.658396 H 38.226348 A 18.471523,18.901669 0 0 1 19.762375,65.764449 18.471523,18.901669 0 0 1 35.685283,47.056234 27.707285,31.502779 0 0 1 62.861474,21.661698 Z" + id="path4540" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 38.226348,90.956369 a 6.1571744,6.3005562 0 0 1 6.154657,6.297979 6.1571744,6.3005562 0 0 1 -6.154657,6.314882 6.1571744,6.3005562 0 0 1 -6.154657,-6.314882 6.1571744,6.3005562 0 0 1 6.154657,-6.297979 z" + id="path4538" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 87.480108,90.956369 a 6.1571744,6.3005562 0 0 1 6.171159,6.297979 6.1571744,6.3005562 0 0 1 -6.171159,6.314882 6.1571744,6.3005562 0 0 1 -6.154656,-6.314882 6.1571744,6.3005562 0 0 1 6.154656,-6.297979 z" + id="path4536" + inkscape:connector-curvature="0" /> + <path + style="opacity:1;fill:#b4b4b4;fill-opacity:1;stroke-width:8.54601765" + d="m 62.861474,97.254348 a 6.1571744,6.3005562 0 0 1 6.154662,6.314882 6.1571744,6.3005562 0 0 1 -6.154662,6.29797 6.1571744,6.3005562 0 0 1 -6.154651,-6.29797 6.1571744,6.3005562 0 0 1 6.154651,-6.314882 z" + id="rect822" + inkscape:connector-curvature="0" /> + <g + inkscape:groupmode="layer" + id="layer1" + inkscape:label="Layer 1" + transform="translate(-0.35794507,-5.5049216)" /> +</svg> diff --git a/editor/icons/icon_key_animation.svg b/editor/icons/icon_key_animation.svg index a09567498f..6db513ca26 100644 --- a/editor/icons/icon_key_animation.svg +++ b/editor/icons/icon_key_animation.svg @@ -1,65 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_animation.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="1852" - inkscape:window-height="781" - id="namedview8" - showgrid="false" - inkscape:zoom="29.5" - inkscape:cx="-10.271186" - inkscape:cy="3.4149032" - inkscape:window-x="68" - inkscape:window-y="117" - inkscape:window-maximized="0" - inkscape:current-layer="g4" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#ea686c" - id="rect2" - style="fill:#b76ef0;fill-opacity:1" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#b76ef0" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 0 -1042.4)" width="6.1027" x="-740.13947" y="741.10779"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_audio.svg b/editor/icons/icon_key_audio.svg index 7c728bfd01..75576885ec 100644 --- a/editor/icons/icon_key_audio.svg +++ b/editor/icons/icon_key_audio.svg @@ -1,65 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_audio.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title></dc:title> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="1053" - inkscape:window-height="591" - id="namedview8" - showgrid="false" - inkscape:zoom="29.5" - inkscape:cx="4" - inkscape:cy="4" - inkscape:window-x="67" - inkscape:window-y="27" - inkscape:window-maximized="0" - inkscape:current-layer="g4" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#ea686c" - id="rect2" - style="fill:#eae668;fill-opacity:1" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#eae668" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 0 -1042.4)" width="6.1027" x="-740.13947" y="741.10779"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_bezier.svg b/editor/icons/icon_key_bezier.svg index 62af6fdb34..dc5800fd5a 100644 --- a/editor/icons/icon_key_bezier.svg +++ b/editor/icons/icon_key_bezier.svg @@ -1,65 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_bezier.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - <dc:title /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="1852" - inkscape:window-height="781" - id="namedview8" - showgrid="false" - inkscape:zoom="29.5" - inkscape:cx="-17.152542" - inkscape:cy="3.4149032" - inkscape:window-x="67" - inkscape:window-y="27" - inkscape:window-maximized="0" - inkscape:current-layer="g4" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#ea686c" - id="rect2" - style="fill:#5792f6;fill-opacity:1" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#5792f6" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 0 -1042.4)" width="6.1027" x="-740.13947" y="741.10779"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_call.svg b/editor/icons/icon_key_call.svg index e702898288..6cc442c391 100644 --- a/editor/icons/icon_key_call.svg +++ b/editor/icons/icon_key_call.svg @@ -1,64 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_call.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="836" - inkscape:window-height="480" - id="namedview8" - showgrid="false" - inkscape:zoom="29.5" - inkscape:cx="4" - inkscape:cy="4" - inkscape:window-x="67" - inkscape:window-y="27" - inkscape:window-maximized="0" - inkscape:current-layer="g4" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#adf18f" - id="rect2" - style="fill:#66f376;fill-opacity:1" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#66f376" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 0 -1042.4)" width="6.1027" x="-740.13947" y="741.10779"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_selected.svg b/editor/icons/icon_key_selected.svg index 2842fd93eb..6594aec6ee 100644 --- a/editor/icons/icon_key_selected.svg +++ b/editor/icons/icon_key_selected.svg @@ -1,76 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_selected.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="1568" - inkscape:window-height="767" - id="namedview8" - showgrid="false" - inkscape:zoom="41.7193" - inkscape:cx="-0.48848775" - inkscape:cy="3.5639274" - inkscape:window-x="67" - inkscape:window-y="27" - inkscape:window-maximized="0" - inkscape:current-layer="g4-3" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#84c2ff" - id="rect2" /> - </g> - <g - transform="translate(0,-1044.4)" - id="g4-3"> - <rect - style="fill:#003e7a;fill-opacity:1;stroke-width:0.56281364" - transform="matrix(0.71728847,-0.69677633,0.71728847,0.69677633,0,0)" - x="-751.20953" - y="753.42743" - width="3.4346831" - height="3.4346831" - ry="0.42934799" - id="rect2-6" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#84c2ff" height="6.1027" ry=".76286" transform="matrix(.87871827 -.87871827 .87871827 .87871827 .03288 -1297.7965)" width="6.1027" x="-741.53003" y="741.08002"/><rect fill="#003e7a" height="3.434683" ry=".429348" stroke-width=".562814" transform="matrix(.89137101 -.86588067 .89137101 .86588067 -.038545 -1297.8361)" width="3.434683" x="-751.20953" y="753.42743"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_value.svg b/editor/icons/icon_key_value.svg index 61032a1e16..8a4787d6ed 100644 --- a/editor/icons/icon_key_value.svg +++ b/editor/icons/icon_key_value.svg @@ -1,5 +1 @@ -<svg width="8" height="8" version="1.1" viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg"> -<g transform="translate(0 -1044.4)"> -<rect transform="rotate(-45)" x="-741.53" y="741.08" width="6.1027" height="6.1027" ry=".76286" fill="#e0e0e0"/> -</g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#e0e0e0" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 1.002946 -1043.3636)" width="6.1027" x="-741.53003" y="741.08002"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_key_xform.svg b/editor/icons/icon_key_xform.svg index fd22b67f52..4a567075a7 100644 --- a/editor/icons/icon_key_xform.svg +++ b/editor/icons/icon_key_xform.svg @@ -1,64 +1 @@ -<?xml version="1.0" encoding="UTF-8" standalone="no"?> -<svg - xmlns:dc="http://purl.org/dc/elements/1.1/" - xmlns:cc="http://creativecommons.org/ns#" - xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" - xmlns:svg="http://www.w3.org/2000/svg" - xmlns="http://www.w3.org/2000/svg" - xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" - xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" - width="8" - height="8" - version="1.1" - viewBox="0 0 8 8" - id="svg6" - sodipodi:docname="icon_key_xform.svg" - inkscape:version="0.92.3 (2405546, 2018-03-11)"> - <metadata - id="metadata12"> - <rdf:RDF> - <cc:Work - rdf:about=""> - <dc:format>image/svg+xml</dc:format> - <dc:type - rdf:resource="http://purl.org/dc/dcmitype/StillImage" /> - </cc:Work> - </rdf:RDF> - </metadata> - <defs - id="defs10" /> - <sodipodi:namedview - pagecolor="#ffffff" - bordercolor="#666666" - borderopacity="1" - objecttolerance="10" - gridtolerance="10" - guidetolerance="10" - inkscape:pageopacity="0" - inkscape:pageshadow="2" - inkscape:window-width="836" - inkscape:window-height="480" - id="namedview8" - showgrid="false" - inkscape:zoom="29.5" - inkscape:cx="4" - inkscape:cy="4" - inkscape:window-x="67" - inkscape:window-y="27" - inkscape:window-maximized="0" - inkscape:current-layer="g4" /> - <g - transform="translate(0 -1044.4)" - id="g4"> - <rect - transform="rotate(-45)" - x="-741.53" - y="741.08" - width="6.1027" - height="6.1027" - ry=".76286" - fill="#ea686c" - id="rect2" - style="fill:#ea9568;fill-opacity:1" /> - </g> -</svg> +<svg height="10" viewBox="0 0 10 10" width="10" xmlns="http://www.w3.org/2000/svg"><rect fill="#ea9568" height="6.1027" ry=".76286" transform="matrix(.70710678 -.70710678 .70710678 .70710678 0 -1042.4)" width="6.1027" x="-740.13947" y="741.10779"/></svg>
\ No newline at end of file diff --git a/editor/icons/icon_timeline_indicator.svg b/editor/icons/icon_timeline_indicator.svg new file mode 100644 index 0000000000..fd18192705 --- /dev/null +++ b/editor/icons/icon_timeline_indicator.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m3 0h10l-4 4h-2z" fill="#fefefe"/></svg>
\ No newline at end of file diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 1c4a8c43a9..449124acec 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -692,16 +692,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me pre_weights[w_i] = weights; - /* - for(Set<int>::Element *E=vertex_map[w_i].front();E;E=E->next()) { - - int dst = E->get(); - ERR_EXPLAIN("invalid vertex index in array"); - ERR_FAIL_INDEX_V(dst,vertex_array.size(),ERR_INVALID_DATA); - vertex_array[dst].weights=weights; - - }*/ - index_ofs += wstride * amount; } @@ -711,7 +701,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me Set<Collada::Vertex> vertex_set; //vertex set will be the vertices List<int> indices_list; //indices will be the indices - //Map<int,Set<int> > vertex_map; //map vertices (for setting skinning/morph) /**************************/ /* CREATE PRIMITIVE ARRAY */ @@ -834,9 +823,6 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<ArrayMesh> &p_me vertex_set.insert(vertex); } - /* if (!vertex_map.has(vertex_index)) - vertex_map[vertex_index]=Set<int>(); - vertex_map[vertex_index].insert(index); //should be outside..*/ //build triangles if needed if (j == 0) prev2[0] = index; @@ -1204,10 +1190,7 @@ Error ColladaImport::_create_resources(Collada::Node *p_node, bool p_use_compres } } - if (ngsource != "") { - ERR_EXPLAIN("Controller Instance Source '" + ngsource + "' is neither skin or morph!"); - ERR_FAIL_V(ERR_INVALID_DATA); - } + ERR_FAIL_COND_V_MSG(ngsource != "", ERR_INVALID_DATA, "Controller instance source '" + ngsource + "' is neither skin or morph!"); } else { meshid = ng2->source; @@ -1608,7 +1591,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } if (xform_idx == -1) { - WARN_PRINTS("Collada: Couldn't find matching node " + at.target + " xform for track " + at.param); + WARN_PRINTS("Collada: Couldn't find matching node " + at.target + " xform for track " + at.param + "."); continue; } @@ -1630,8 +1613,7 @@ void ColladaImport::create_animation(int p_clip, bool p_make_tracks_in_all_bones } else if (data.size() == xf.data.size()) { xf.data = data; } else { - ERR_EXPLAIN("Component " + at.component + " has datasize " + itos(data.size()) + ", xfdatasize " + itos(xf.data.size())); - ERR_CONTINUE(data.size() != xf.data.size()); + ERR_CONTINUE_MSG(data.size() != xf.data.size(), "Component " + at.component + " has datasize " + itos(data.size()) + ", xfdatasize " + itos(xf.data.size()) + "."); } } diff --git a/editor/import/editor_scene_importer_gltf.cpp b/editor/import/editor_scene_importer_gltf.cpp index c9c5b3818f..9ea7c86e0c 100644 --- a/editor/import/editor_scene_importer_gltf.cpp +++ b/editor/import/editor_scene_importer_gltf.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "editor_scene_importer_gltf.h" +#include "core/crypto/crypto_core.h" #include "core/io/json.h" -#include "core/math/crypto_core.h" #include "core/math/math_defs.h" #include "core/os/file_access.h" #include "core/os/os.h" @@ -1544,8 +1544,7 @@ Error EditorSceneImporterGLTF::_parse_cameras(GLTFState &state) { camera.fov_size = 10; } } else { - ERR_EXPLAIN("Camera should be in 'orthographic' or 'perspective'"); - ERR_FAIL_V(ERR_PARSE_ERROR); + ERR_FAIL_V_MSG(ERR_PARSE_ERROR, "Camera should be in 'orthographic' or 'perspective'"); } state.cameras.push_back(camera); diff --git a/editor/import/resource_importer_csv_translation.cpp b/editor/import/resource_importer_csv_translation.cpp index cfcdbc8de4..301422a25a 100644 --- a/editor/import/resource_importer_csv_translation.cpp +++ b/editor/import/resource_importer_csv_translation.cpp @@ -101,8 +101,7 @@ Error ResourceImporterCSVTranslation::import(const String &p_source_file, const for (int i = 1; i < line.size(); i++) { String locale = line[i]; - ERR_EXPLAIN("Error importing CSV translation: '" + locale + "' is not a valid locale"); - ERR_FAIL_COND_V(!TranslationServer::is_locale_valid(locale), ERR_PARSE_ERROR); + ERR_FAIL_COND_V_MSG(!TranslationServer::is_locale_valid(locale), ERR_PARSE_ERROR, "Error importing CSV translation: '" + locale + "' is not a valid locale."); locales.push_back(locale); Ref<Translation> translation; diff --git a/editor/import/resource_importer_obj.cpp b/editor/import/resource_importer_obj.cpp index 868f67fd77..9061c92f6e 100644 --- a/editor/import/resource_importer_obj.cpp +++ b/editor/import/resource_importer_obj.cpp @@ -45,8 +45,7 @@ uint32_t EditorOBJImporter::get_import_flags() const { static Error _parse_material_library(const String &p_path, Map<String, Ref<SpatialMaterial> > &material_map, List<String> *r_missing_deps) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); - ERR_EXPLAIN(vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path)); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open MTL file '%s', it may not exist or not be readable.", p_path)); Ref<SpatialMaterial> current; String current_name; @@ -207,8 +206,7 @@ static Error _parse_material_library(const String &p_path, Map<String, Ref<Spati static Error _parse_obj(const String &p_path, List<Ref<Mesh> > &r_meshes, bool p_single_mesh, bool p_generate_tangents, bool p_optimize, Vector3 p_scale_mesh, List<String> *r_missing_deps) { FileAccessRef f = FileAccess::open(p_path, FileAccess::READ); - ERR_EXPLAIN(vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path)); - ERR_FAIL_COND_V(!f, ERR_CANT_OPEN); + ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, vformat("Couldn't open OBJ file '%s', it may not exist or not be readable.", p_path)); Ref<ArrayMesh> mesh; mesh.instance(); diff --git a/editor/import/resource_importer_wav.cpp b/editor/import/resource_importer_wav.cpp index d267b29224..4fd4ab2f2e 100644 --- a/editor/import/resource_importer_wav.cpp +++ b/editor/import/resource_importer_wav.cpp @@ -123,8 +123,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s file->close(); memdelete(file); - ERR_EXPLAIN("Not a WAV file (no WAVE RIFF Header)"); - ERR_FAIL_V(ERR_FILE_UNRECOGNIZED); + ERR_FAIL_V_MSG(ERR_FILE_UNRECOGNIZED, "Not a WAV file (no WAVE RIFF header)."); } int format_bits = 0; @@ -166,16 +165,14 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s if (compression_code != 1 && compression_code != 3) { file->close(); memdelete(file); - ERR_EXPLAIN("Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not PCM). Save WAVE files as uncompressed PCM instead."); } format_channels = file->get_16(); if (format_channels != 1 && format_channels != 2) { file->close(); memdelete(file); - ERR_EXPLAIN("Format not supported for WAVE file (not stereo or mono)."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Format not supported for WAVE file (not stereo or mono)."); } format_freq = file->get_32(); //sampling rate @@ -187,8 +184,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s if (format_bits % 8 || format_bits == 0) { file->close(); memdelete(file); - ERR_EXPLAIN("Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32)."); - ERR_FAIL_V(ERR_INVALID_DATA); + ERR_FAIL_V_MSG(ERR_INVALID_DATA, "Invalid amount of bits in the sample (should be one of 8, 16, 24 or 32)."); } /* Don't need anything else, continue */ @@ -258,8 +254,7 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s if (file->eof_reached()) { file->close(); memdelete(file); - ERR_EXPLAIN("Premature end of file."); - ERR_FAIL_V(ERR_FILE_CORRUPT); + ERR_FAIL_V_MSG(ERR_FILE_CORRUPT, "Premature end of file."); } } diff --git a/editor/node_dock.cpp b/editor/node_dock.cpp index 1c0151ed0a..d6df3bd369 100644 --- a/editor/node_dock.cpp +++ b/editor/node_dock.cpp @@ -56,10 +56,7 @@ void NodeDock::_bind_methods() { void NodeDock::_notification(int p_what) { - if (p_what == NOTIFICATION_ENTER_TREE) { - connections_button->set_icon(get_icon("Signals", "EditorIcons")); - groups_button->set_icon(get_icon("Groups", "EditorIcons")); - } else if (p_what == EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED) { + if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { connections_button->set_icon(get_icon("Signals", "EditorIcons")); groups_button->set_icon(get_icon("Groups", "EditorIcons")); } @@ -131,7 +128,7 @@ NodeDock::NodeDock() { groups->hide(); select_a_node = memnew(Label); - select_a_node->set_text(TTR("Select a Node to edit Signals and Groups.")); + select_a_node->set_text(TTR("Select a single node to edit its signals and groups.")); select_a_node->set_v_size_flags(SIZE_EXPAND_FILL); select_a_node->set_valign(Label::VALIGN_CENTER); select_a_node->set_align(Label::ALIGN_CENTER); diff --git a/editor/plugin_config_dialog.cpp b/editor/plugin_config_dialog.cpp index 12bf544357..23056d25c0 100644 --- a/editor/plugin_config_dialog.cpp +++ b/editor/plugin_config_dialog.cpp @@ -130,7 +130,8 @@ void PluginConfigDialog::_notification(int p_what) { void PluginConfigDialog::config(const String &p_config_path) { if (p_config_path.length()) { Ref<ConfigFile> cf = memnew(ConfigFile); - cf->load(p_config_path); + Error err = cf->load(p_config_path); + ERR_FAIL_COND(err != OK); name_edit->set_text(cf->get_value("plugin", "name", "")); subfolder_edit->set_text(p_config_path.get_base_dir().get_basename().get_file()); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 574b47d770..7f023af848 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -571,7 +571,8 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl return; Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); - const Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); + // All polygon points are sharp, so use the sharp handle icon + const Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); const Vertex active_point = get_active_point(); const int n_polygons = _get_polygon_count(); diff --git a/editor/plugins/abstract_polygon_2d_editor.h b/editor/plugins/abstract_polygon_2d_editor.h index 97244fa4e9..a00cdd0cf6 100644 --- a/editor/plugins/abstract_polygon_2d_editor.h +++ b/editor/plugins/abstract_polygon_2d_editor.h @@ -36,9 +36,6 @@ #include "scene/2d/polygon_2d.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditor; class AbstractPolygon2DEditor : public HBoxContainer { diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 74186791e1..850a6201bb 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -40,9 +40,6 @@ #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index cb40159a40..77b57a50d0 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -40,9 +40,6 @@ #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 5163b372b2..f42716c827 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -32,6 +32,7 @@ #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" +#include "core/os/input.h" #include "core/os/keyboard.h" #include "core/project_settings.h" #include "editor/animation_track_editor.h" @@ -293,10 +294,6 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { } } frame->set_max(anim->get_length()); - if (anim->get_step()) - frame->set_step(anim->get_step()); - else - frame->set_step(0.00001); } else { track_editor->set_animation(Ref<Animation>()); @@ -1008,7 +1005,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { }; updating = true; - String current = player->get_assigned_animation(); //animation->get_item_text( animation->get_selected() ); + String current = player->get_assigned_animation(); if (current == "" || !player->has_animation(current)) { updating = false; current = ""; @@ -1018,14 +1015,9 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { Ref<Animation> anim; anim = player->get_animation(current); - float pos = anim->get_length() * (p_value / frame->get_max()); - float step = anim->get_step(); - if (step) { - pos = Math::stepify(pos, step); - if (pos < 0) - pos = 0; - if (pos >= anim->get_length()) - pos = anim->get_length(); + float pos = CLAMP(anim->get_length() * (p_value / frame->get_max()), 0, anim->get_length()); + if (track_editor->is_snap_enabled()) { + pos = Math::stepify(pos, anim->get_step()); } if (player->is_valid() && !p_set) { @@ -1063,14 +1055,6 @@ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) frame->set_max(p_len); } -void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) { - - if (p_len) - frame->set_step(p_len); - else - frame->set_step(0.00001); -} - void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) { if (!is_visible_in_tree()) @@ -1081,8 +1065,10 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) if (player->is_playing()) return; + Ref<Animation> anim = player->get_animation(player->get_assigned_animation()); + updating = true; - frame->set_value(p_pos); + frame->set_value(Math::stepify(p_pos, track_editor->is_snap_enabled() ? anim->get_step() : 0)); updating = false; _seek_value_changed(p_pos, !p_drag); @@ -1558,7 +1544,6 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"), &AnimationPlayerEditor::_animation_key_editor_seek); ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_len_changed); - ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_step_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_step_changed); ClassDB::bind_method(D_METHOD("_hide_anim_editors"), &AnimationPlayerEditor::_hide_anim_editors); ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate); ClassDB::bind_method(D_METHOD("_blend_editor_next_changed"), &AnimationPlayerEditor::_blend_editor_next_changed); @@ -1621,6 +1606,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay hb->add_child(frame); frame->set_custom_minimum_size(Size2(60, 0)); frame->set_stretch_ratio(2); + frame->set_step(0.0001); frame->set_tooltip(TTR("Animation position (in seconds).")); hb->add_child(memnew(VSeparator)); @@ -1774,7 +1760,6 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay track_editor->set_v_size_flags(SIZE_EXPAND_FILL); track_editor->connect("timeline_changed", this, "_animation_key_editor_seek"); track_editor->connect("animation_len_changed", this, "_animation_key_editor_anim_len_changed"); - track_editor->connect("animation_step_changed", this, "_animation_key_editor_anim_step_changed"); _update_player(); diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 398ef6ff14..2ab2df68e6 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -39,9 +39,6 @@ #include "scene/gui/spin_box.h" #include "scene/gui/texture_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationTrackEditor; class AnimationPlayerEditorPlugin; @@ -203,7 +200,6 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_key_editor_seek(float p_pos, bool p_drag); void _animation_key_editor_anim_len_changed(float p_len); - void _animation_key_editor_anim_step_changed(float p_len); void _unhandled_key_input(const Ref<InputEvent> &p_ev); void _animation_tool_menu(int p_option); diff --git a/editor/plugins/animation_tree_player_editor_plugin.h b/editor/plugins/animation_tree_player_editor_plugin.h index f4bfe58909..03bc559b86 100644 --- a/editor/plugins/animation_tree_player_editor_plugin.h +++ b/editor/plugins/animation_tree_player_editor_plugin.h @@ -38,9 +38,6 @@ #include "scene/gui/button.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationTreePlayerEditor : public Control { diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 31b11d8bea..3eea888950 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -270,10 +270,10 @@ void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, cons if (!p_video) { preview.image = get_icon("ThumbnailWait", "EditorIcons"); } - if (preview_images.size() == 0 && !p_video) { + preview_images.push_back(preview); + if (preview_images.size() == 1 && !p_video) { _preview_click(p_id); } - preview_images.push_back(preview); } EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { @@ -333,18 +333,14 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int switch (p_status) { - case HTTPRequest::RESULT_CANT_RESOLVE: { - error_text = TTR("Can't resolve hostname:") + " " + host; - status->set_text(TTR("Can't resolve.")); - } break; - case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: + case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: case HTTPRequest::RESULT_CONNECTION_ERROR: - case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { + case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: { error_text = TTR("Connection error, please try again."); status->set_text(TTR("Can't connect.")); } break; - case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: - case HTTPRequest::RESULT_CANT_CONNECT: { + case HTTPRequest::RESULT_CANT_CONNECT: + case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: { error_text = TTR("Can't connect to host:") + " " + host; status->set_text(TTR("Can't connect.")); } break; @@ -352,13 +348,26 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int error_text = TTR("No response from host:") + " " + host; status->set_text(TTR("No response.")); } break; + case HTTPRequest::RESULT_CANT_RESOLVE: { + error_text = TTR("Can't resolve hostname:") + " " + host; + status->set_text(TTR("Can't resolve.")); + } break; case HTTPRequest::RESULT_REQUEST_FAILED: { error_text = TTR("Request failed, return code:") + " " + itos(p_code); - status->set_text(TTR("Request Failed.")); + status->set_text(TTR("Request failed.")); + } break; + case HTTPRequest::RESULT_DOWNLOAD_FILE_CANT_OPEN: + case HTTPRequest::RESULT_DOWNLOAD_FILE_WRITE_ERROR: { + error_text = TTR("Cannot save response to:") + " " + download->get_download_file(); + status->set_text(TTR("Write error.")); } break; case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { error_text = TTR("Request failed, too many redirects"); - status->set_text(TTR("Redirect Loop.")); + status->set_text(TTR("Redirect loop.")); + } break; + case HTTPRequest::RESULT_TIMEOUT: { + error_text = TTR("Request failed, timeout"); + status->set_text(TTR("Timeout.")); } break; default: { if (p_code != 200) { @@ -398,8 +407,6 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse icon->set_texture(get_icon("DefaultProjectIcon", "EditorIcons")); host = p_download_url; sha256 = p_sha256_hash; - asset_installer->connect("confirmed", this, "_close"); - dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); _make_request(); } @@ -407,9 +414,11 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: { + // FIXME: The editor crashes if 'NOTICATION_THEME_CHANGED' is used. + case NOTIFICATION_ENTER_TREE: { add_style_override("panel", get_stylebox("panel", "TabContainer")); + dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); } break; case NOTIFICATION_PROCESS: { @@ -463,9 +472,8 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { } void EditorAssetLibraryItemDownload::_close() { - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - da->remove(download->get_download_file()); //clean up removed file - memdelete(da); + // Clean up downloaded file. + DirAccess::remove_file_or_error(download->get_download_file()); queue_delete(); } @@ -562,6 +570,7 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { asset_installer = memnew(EditorAssetInstaller); add_child(asset_installer); + asset_installer->connect("confirmed", this, "_close"); prev_status = -1; @@ -591,33 +600,15 @@ void EditorAssetLibrary::_notification(int p_what) { case NOTIFICATION_PROCESS: { HTTPClient::Status s = request->get_http_client_status(); - bool visible = s != HTTPClient::STATUS_DISCONNECTED; - - if (visible != load_status->is_visible()) { - load_status->set_visible(visible); - } + const bool loading = s != HTTPClient::STATUS_DISCONNECTED; - if (visible) { - switch (s) { - - case HTTPClient::STATUS_RESOLVING: { - load_status->set_value(0.1); - } break; - case HTTPClient::STATUS_CONNECTING: { - load_status->set_value(0.2); - } break; - case HTTPClient::STATUS_REQUESTING: { - load_status->set_value(0.3); - } break; - case HTTPClient::STATUS_BODY: { - load_status->set_value(0.4); - } break; - default: { - } - } + if (loading) { + library_scroll->set_modulate(Color(1, 1, 1, 0.5)); + } else { + library_scroll->set_modulate(Color(1, 1, 1, 1)); } - bool no_downloads = downloads_hb->get_child_count() == 0; + const bool no_downloads = downloads_hb->get_child_count() == 0; if (no_downloads == downloads_scroll->is_visible()) { downloads_scroll->set_visible(!no_downloads); } @@ -749,7 +740,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt switch (image_queue[p_queue_id].image_type) { case IMAGE_QUEUE_ICON: - image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_CUBIC); + image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_LANCZOS); break; case IMAGE_QUEUE_THUMBNAIL: { @@ -1148,6 +1139,10 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const _search(); } break; case REQUESTING_SEARCH: { + + // The loading text only needs to be displayed before the first page is loaded + library_loading->hide(); + if (asset_items) { memdelete(asset_items); } @@ -1463,6 +1458,10 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_vb_border->add_child(library_vb); + library_loading = memnew(Label(TTR("Loading..."))); + library_loading->set_align(Label::ALIGN_CENTER); + library_vb->add_child(library_loading); + asset_top_page = memnew(HBoxContainer); library_vb->add_child(asset_top_page); @@ -1485,12 +1484,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_vb->add_constant_override("separation", 20 * EDSCALE); - load_status = memnew(ProgressBar); - load_status->set_min(0); - load_status->set_max(1); - load_status->set_step(0.001); - library_main->add_child(load_status); - error_hb = memnew(HBoxContainer); library_main->add_child(error_hb); error_label = memnew(Label); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index 81288ae831..d81606c284 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -186,13 +186,13 @@ class EditorAssetLibrary : public PanelContainer { PanelContainer *library_scroll_bg; ScrollContainer *library_scroll; VBoxContainer *library_vb; + Label *library_loading; LineEdit *filter; OptionButton *categories; OptionButton *repository; OptionButton *sort; ToolButton *reverse; Button *search; - ProgressBar *load_status; HBoxContainer *error_hb; TextureRect *error_tr; Label *error_label; diff --git a/editor/plugins/camera_editor_plugin.h b/editor/plugins/camera_editor_plugin.h index eac9acab93..400aee132d 100644 --- a/editor/plugins/camera_editor_plugin.h +++ b/editor/plugins/camera_editor_plugin.h @@ -35,10 +35,6 @@ #include "editor/editor_plugin.h" #include "scene/3d/camera.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class CameraEditor : public Control { GDCLASS(CameraEditor, Control); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 3af8da5e18..2daee70474 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -174,15 +174,6 @@ public: } }; -void CanvasItemEditor::_snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius) { - float radius = p_radius / zoom; - float dist = Math::abs(p_value - p_target_snap); - if ((p_radius < 0 || dist < radius) && (!r_snapped || dist < Math::abs(r_current_snap - p_value))) { - r_current_snap = p_target_snap; - r_snapped = true; - } -} - bool CanvasItemEditor::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } @@ -200,108 +191,174 @@ bool CanvasItemEditor::_is_node_movable(const Node *p_node, bool p_popup_warning return true; } -void CanvasItemEditor::_snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation, float p_radius) { +void CanvasItemEditor::_snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius) { + + float radius = p_radius / zoom; + float dist = Math::abs(p_value - p_target_value); + if ((p_radius < 0 || dist < radius) && (r_current_snap_target == SNAP_TARGET_NONE || dist < Math::abs(r_current_snap - p_value))) { + r_current_snap = p_target_value; + r_current_snap_target = p_snap_target; + } +} + +void CanvasItemEditor::_snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation, + float p_radius) { + Transform2D rot_trans = Transform2D(rotation, Point2()); p_value = rot_trans.inverse().xform(p_value); - p_target_snap = rot_trans.inverse().xform(p_target_snap); + p_target_value = rot_trans.inverse().xform(p_target_value); r_current_snap = rot_trans.inverse().xform(r_current_snap); - _snap_if_closer_float(p_value.x, p_target_snap.x, r_current_snap.x, r_snapped[0], p_radius); - _snap_if_closer_float(p_value.y, p_target_snap.y, r_current_snap.y, r_snapped[1], p_radius); + _snap_if_closer_float( + p_value.x, + r_current_snap.x, + r_current_snap_target[0], + p_target_value.x, + p_snap_target, + p_radius); + + _snap_if_closer_float( + p_value.y, + r_current_snap.y, + r_current_snap_target[1], + p_target_value.y, + p_snap_target, + p_radius); r_current_snap = rot_trans.xform(r_current_snap); } -void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap) { +void CanvasItemEditor::_snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current) { const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_current); - if (canvas_item && (!p_to_snap || p_current != p_to_snap)) { + + // Check if the element is in the exception + bool exception = false; + for (List<const CanvasItem *>::Element *E = p_exceptions.front(); E; E = E->next()) { + if (E->get() == p_current) { + exception = true; + break; + } + }; + + if (canvas_item && !exception) { 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) { + if (fmod(ci_transform.get_rotation() - p_transform_to_snap.get_rotation(), (real_t)360.0) == 0.0) { if (canvas_item->_edit_use_rect()) { 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()); + + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, begin, p_snap_target, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, end, p_snap_target, ci_transform.get_rotation()); } else { Point2 position = ci_transform.xform(Point2()); - _snap_if_closer_point(p_value, position, r_current_snap, r_snapped, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, position, p_snap_target, ci_transform.get_rotation()); } } } for (int i = 0; i < p_current->get_child_count(); i++) { - _snap_other_nodes(p_value, r_current_snap, r_snapped, p_current->get_child(i), p_to_snap); + _snap_other_nodes(p_value, p_transform_to_snap, r_current_snap, r_current_snap_target, p_snap_target, p_exceptions, p_current->get_child(i)); } } -Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const CanvasItem *p_canvas_item, unsigned int p_forced_modes) { - bool snapped[2] = { false, false }; +Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsigned int p_forced_modes, const CanvasItem *p_self_canvas_item, List<CanvasItem *> p_other_nodes_exceptions) { + + snap_target[0] = SNAP_TARGET_NONE; + snap_target[1] = SNAP_TARGET_NONE; + bool is_snap_active = snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); // Smart snap using the canvas position Vector2 output = p_target; real_t rotation = 0.0; - if (p_canvas_item) { - rotation = p_canvas_item->get_global_transform_with_canvas().get_rotation(); + if (p_self_canvas_item) { + rotation = p_self_canvas_item->get_global_transform_with_canvas().get_rotation(); // Parent sides and center if ((is_snap_active && snap_node_parent && (p_modes & SNAP_NODE_PARENT)) || (p_forced_modes & SNAP_NODE_PARENT)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); - } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_canvas_item->get_parent())) { + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); + } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_self_canvas_item->get_parent())) { if (parent_ci->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); - Point2 end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + Point2 begin = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); } else { - Point2 position = p_canvas_item->get_transform().affine_inverse().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_transform().affine_inverse().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_PARENT, rotation); } } } // Self anchors if ((is_snap_active && snap_node_anchors && (p_modes & SNAP_NODE_ANCHORS)) || (p_forced_modes & SNAP_NODE_ANCHORS)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF_ANCHORS, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF_ANCHORS, rotation); } } // Self sides if ((is_snap_active && snap_node_sides && (p_modes & SNAP_NODE_SIDES)) || (p_forced_modes & SNAP_NODE_SIDES)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position()); - Point2 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); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF, rotation); } } // Self center if ((is_snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 center = 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() / 2.0); - _snap_if_closer_point(p_target, center, output, snapped, rotation); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 center = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size() / 2.0); + _snap_if_closer_point(p_target, output, snap_target, center, SNAP_TARGET_SELF, rotation); } else { - Point2 position = p_canvas_item->get_global_transform_with_canvas().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_global_transform_with_canvas().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_SELF, rotation); } } } // Other nodes sides if ((is_snap_active && snap_other_nodes && (p_modes & SNAP_OTHER_NODES)) || (p_forced_modes & SNAP_OTHER_NODES)) { - _snap_other_nodes(p_target, output, snapped, get_tree()->get_edited_scene_root(), p_canvas_item); + Transform2D to_snap_transform = Transform2D(); + List<const CanvasItem *> exceptions = List<const CanvasItem *>(); + for (List<CanvasItem *>::Element *E = p_other_nodes_exceptions.front(); E; E = E->next()) { + exceptions.push_back(E->get()); + } + if (p_self_canvas_item) { + exceptions.push_back(p_self_canvas_item); + to_snap_transform = p_self_canvas_item->get_global_transform_with_canvas(); + } + + _snap_other_nodes( + p_target, to_snap_transform, + output, snap_target, + SNAP_TARGET_OTHER_NODE, + exceptions, + get_tree()->get_edited_scene_root()); } if (((is_snap_active && snap_guides && (p_modes & SNAP_GUIDES)) || (p_forced_modes & SNAP_GUIDES)) && fmod(rotation, (real_t)360.0) == 0.0) { @@ -309,14 +366,14 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_"); for (int i = 0; i < vguides.size(); i++) { - _snap_if_closer_float(p_target.x, vguides[i], output.x, snapped[0]); + _snap_if_closer_float(p_target.x, output.x, snap_target[0], vguides[i], SNAP_TARGET_GUIDE); } } if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) { Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_"); for (int i = 0; i < hguides.size(); i++) { - _snap_if_closer_float(p_target.y, hguides[i], output.y, snapped[1]); + _snap_if_closer_float(p_target.y, output.y, snap_target[1], hguides[i], SNAP_TARGET_GUIDE); } } } @@ -335,7 +392,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const Point2 grid_output; grid_output.x = Math::stepify(p_target.x - offset.x, grid_step.x * Math::pow(2.0, grid_step_multiplier)) + offset.x; grid_output.y = Math::stepify(p_target.y - offset.y, grid_step.y * Math::pow(2.0, grid_step_multiplier)) + offset.y; - _snap_if_closer_point(p_target, grid_output, output, snapped, 0.0, -1.0); + _snap_if_closer_point(p_target, output, snap_target, grid_output, SNAP_TARGET_GRID, 0.0, -1.0); } if (((snap_pixel && (p_modes & SNAP_PIXEL)) || (p_forced_modes & SNAP_PIXEL)) && rotation == 0.0) { @@ -343,6 +400,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const output = output.snapped(Size2(1, 1)); } + snap_transform = Transform2D(rotation, output); + return output; } @@ -1205,10 +1264,11 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { if (drag_selection.size() > 0) { drag_from = transform.affine_inverse().xform((b.is_valid()) ? b->get_position() : viewport->get_local_mouse_position()); Vector2 new_pos; - if (drag_selection.size() == 1) - new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); - else - new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); + if (drag_selection.size() == 1) { + new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); + } else { + new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, NULL, drag_selection); + } for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get(); canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); @@ -1228,7 +1288,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { _restore_canvas_item_state(drag_selection); Vector2 new_pos; if (drag_selection.size() == 1) - new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); + new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); else new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { @@ -1478,7 +1538,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { previous_anchor.y = (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_TOP_RIGHT) ? control->get_anchor(MARGIN_TOP) : control->get_anchor(MARGIN_BOTTOM); previous_anchor = xform.affine_inverse().xform(_anchor_to_position(control, previous_anchor)); - Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, control, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER)); + Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER, control)); new_anchor = _position_to_anchor(control, new_anchor).snapped(Vector2(0.001, 0.001)); bool use_single_axis = m->get_shift(); @@ -1624,8 +1684,8 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse(); - Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); - Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); + Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); + Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); Point2 drag_begin = xform.xform(drag_to_snapped_begin); Point2 drag_end = xform.xform(drag_to_snapped_end); @@ -1866,7 +1926,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } - Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES); + Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES, 0, NULL, drag_selection); bool single_axis = m->get_shift(); if (single_axis) { if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) { @@ -2421,6 +2481,20 @@ void CanvasItemEditor::_draw_guides() { } } +void CanvasItemEditor::_draw_smart_snapping() { + Color line_color = EditorSettings::get_singleton()->get("editors/2d/smart_snapping_line_color"); + if (snap_target[0] != SNAP_TARGET_NONE && snap_target[0] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(0, -1.0e+10F), Point2(0, 1.0e+10F), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } + if (snap_target[1] != SNAP_TARGET_NONE && snap_target[1] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(-1.0e+10F, 0), Point2(1.0e+10F, 0), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } +} + void CanvasItemEditor::_draw_rulers() { Color bg_color = get_color("dark_color_2", "Editor"); Color graduation_color = get_color("font_color", "Editor").linear_interpolate(bg_color, 0.5); @@ -2505,6 +2579,8 @@ void CanvasItemEditor::_draw_rulers() { } } } + + // Draw the top left corner viewport->draw_rect(Rect2(Point2(), Size2(RULER_WIDTH, RULER_WIDTH)), graduation_color); } @@ -2623,7 +2699,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { if (dragged_anchor >= 0) { // Draw the 4 lines when dragged - bool snapped; + bool anchor_snapped; Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); Vector2 corners_pos[4]; @@ -2637,14 +2713,8 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); - snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; - int line_width; - if (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) { - line_width = 2; - } else { - line_width = 1; - } - viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, Math::round(line_width * EDSCALE)); + anchor_snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; + viewport->draw_line(line_starts[i], line_ends[i], anchor_snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); } // Display the percentages next to the lines @@ -2918,10 +2988,15 @@ void CanvasItemEditor::_draw_selection() { Point2 bsfrom = transform.xform(drag_from); Point2 bsto = transform.xform(box_selecting_to); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, + viewport->draw_rect( Rect2(bsfrom, bsto - bsfrom), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + get_color("box_selection_fill_color", "Editor")); + + viewport->draw_rect( + Rect2(bsfrom, bsto - bsfrom), + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } if (drag_type == DRAG_ROTATE) { @@ -3307,6 +3382,7 @@ void CanvasItemEditor::_draw_viewport() { _draw_rulers(); if (show_guides) _draw_guides(); + _draw_smart_snapping(); _draw_focus(); _draw_hover(); } @@ -3316,6 +3392,10 @@ void CanvasItemEditor::update_viewport() { viewport->update(); } +void CanvasItemEditor::set_current_tool(Tool p_tool) { + _button_tool_select(p_tool); +} + void CanvasItemEditor::_notification(int p_what) { if (p_what == NOTIFICATION_PHYSICS_PROCESS) { @@ -5019,11 +5099,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->set_hide_on_checkable_item_selection(false); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_grid", TTR("Snap to Grid")), SNAP_USE_GRID); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION); - p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap...")), SNAP_CONFIGURE); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_relative", TTR("Snap Relative")), SNAP_RELATIVE); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_pixel_snap", TTR("Use Pixel Snap")), SNAP_USE_PIXEL); p->add_submenu_item(TTR("Smart Snapping"), "SmartSnapping"); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap...")), SNAP_CONFIGURE); + smartsnap_config_popup = memnew(PopupMenu); p->add_child(smartsnap_config_popup); smartsnap_config_popup->set_name("SmartSnapping"); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 87130a2c56..ac7d612292 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -39,9 +39,6 @@ #include "scene/gui/label.h" #include "scene/gui/panel_container.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditorViewport; @@ -89,6 +86,17 @@ public: private: EditorNode *editor; + enum SnapTarget { + SNAP_TARGET_NONE = 0, + SNAP_TARGET_PARENT, + SNAP_TARGET_SELF_ANCHORS, + SNAP_TARGET_SELF, + SNAP_TARGET_OTHER_NODE, + SNAP_TARGET_GUIDE, + SNAP_TARGET_GRID, + SNAP_TARGET_PIXEL + }; + enum MenuOption { SNAP_USE, SNAP_USE_NODE_PARENT, @@ -444,6 +452,7 @@ private: void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side); void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color); + void _draw_smart_snapping(); void _draw_rulers(); void _draw_guides(); void _draw_focus(); @@ -479,9 +488,25 @@ private: void _solve_IK(Node2D *leaf_node, Point2 target_position); - void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0); - void _snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0); - void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap = NULL); + SnapTarget snap_target[2]; + Transform2D snap_transform; + void _snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius = 10.0); + void _snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation = 0.0, + float p_radius = 10.0); + void _snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current); void _set_anchors_preset(Control::LayoutPreset p_preset); void _set_margins_preset(Control::LayoutPreset p_preset); @@ -562,7 +587,7 @@ public: SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL, }; - Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0); + Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, unsigned int p_forced_modes = 0, const CanvasItem *p_self_canvas_item = NULL, List<CanvasItem *> p_other_nodes_exceptions = List<CanvasItem *>()); float snap_angle(float p_target, float p_start = 0) const; Transform2D get_canvas_transform() const { return transform; } @@ -585,6 +610,7 @@ public: void update_viewport(); Tool get_current_tool() { return tool; } + void set_current_tool(Tool p_tool); void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } void edit(CanvasItem *p_canvas_item); diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h index e15360d4e5..3f0734fb19 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/collision_polygon_2d.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CollisionPolygon2DEditor : public AbstractPolygon2DEditor { GDCLASS(CollisionPolygon2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h index a699641aba..2a904a53ba 100644 --- a/editor/plugins/collision_polygon_editor_plugin.h +++ b/editor/plugins/collision_polygon_editor_plugin.h @@ -38,10 +38,6 @@ #include "scene/3d/mesh_instance.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class CanvasItemEditor; class Polygon3DEditor : public HBoxContainer { diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 7c2116f06b..9d625af959 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -87,8 +87,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_EXPLAIN(TTR("Error loading image:") + " " + source_emission_file); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); if (img->is_compressed()) { img->decompress(); @@ -196,8 +195,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image...")); - ERR_FAIL_COND(valid_positions.size() == 0); + ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); if (capture_colors) { PoolColorArray pca; diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h index 701632e576..78b176620e 100644 --- a/editor/plugins/item_list_editor_plugin.h +++ b/editor/plugins/item_list_editor_plugin.h @@ -39,10 +39,6 @@ #include "scene/gui/option_button.h" #include "scene/gui/popup_menu.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class ItemListPlugin : public Object { GDCLASS(ItemListPlugin, Object); diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h index 633fda7091..95fa0df2c1 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/editor/plugins/light_occluder_2d_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/light_occluder_2d.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class LightOccluder2DEditor : public AbstractPolygon2DEditor { GDCLASS(LightOccluder2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index d59efe49e7..3ea014a38d 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -147,9 +147,8 @@ void MultiMeshEditor::_populate() { w.release(); PoolVector<Face3> faces = geometry; - ERR_EXPLAIN(TTR("Parent has no solid faces to populate.")); int facecount = faces.size(); - ERR_FAIL_COND(!facecount); + ERR_FAIL_COND_MSG(!facecount, "Parent has no solid faces to populate."); PoolVector<Face3>::Read r = faces.read(); @@ -164,10 +163,8 @@ void MultiMeshEditor::_populate() { area_accum += area; } - ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(triangle_area_map.size() == 0); - ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(area_accum == 0); + ERR_FAIL_COND_MSG(triangle_area_map.size() == 0, "Couldn't map area."); + ERR_FAIL_COND_MSG(area_accum == 0, "Couldn't map area."); Ref<MultiMesh> multimesh = memnew(MultiMesh); multimesh->set_mesh(mesh); diff --git a/editor/plugins/multimesh_editor_plugin.h b/editor/plugins/multimesh_editor_plugin.h index fe87a2b9cb..5323441bd8 100644 --- a/editor/plugins/multimesh_editor_plugin.h +++ b/editor/plugins/multimesh_editor_plugin.h @@ -36,10 +36,6 @@ #include "scene/3d/multimesh_instance.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class MultiMeshEditor : public Control { GDCLASS(MultiMeshEditor, Control); diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 336c28d642..2a387a8b1e 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/navigation_polygon.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class NavigationPolygonEditor : public AbstractPolygon2DEditor { GDCLASS(NavigationPolygonEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index e68bca55cb..8025e12885 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -160,8 +160,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_EXPLAIN(TTR("Error loading image:") + " " + source_emission_file); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); if (img->is_compressed()) { img->decompress(); @@ -269,8 +268,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image...")); - ERR_FAIL_COND(valid_positions.size() == 0); + ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); PoolVector<uint8_t> texdata; diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 75d31459e8..31b0539bfe 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -55,8 +55,7 @@ bool ParticlesEditorBase::_generate(PoolVector<Vector3> &points, PoolVector<Vect if (!triangle_area_map.size() || area_accum == 0) { - err_dialog->set_text(TTR("Faces contain no area!")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(TTR("The geometry's faces don't contain any area.")); return false; } @@ -90,8 +89,7 @@ bool ParticlesEditorBase::_generate(PoolVector<Vector3> &points, PoolVector<Vect if (gcount == 0) { - err_dialog->set_text(TTR("No faces!")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(TTR("The geometry doesn't contain any faces.")); return false; } @@ -169,11 +167,16 @@ void ParticlesEditorBase::_node_selected(const NodePath &p_path) { if (!sel) return; + if (!sel->is_class("Spatial")) { + + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't inherit from Spatial."), sel->get_name())); + return; + } + VisualInstance *vi = Object::cast_to<VisualInstance>(sel); if (!vi) { - err_dialog->set_text(TTR("Node does not contain geometry.")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain geometry."), sel->get_name())); return; } @@ -181,8 +184,7 @@ void ParticlesEditorBase::_node_selected(const NodePath &p_path) { if (geometry.size() == 0) { - err_dialog->set_text(TTR("Node does not contain geometry (faces).")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain face geometry."), sel->get_name())); return; } @@ -231,9 +233,6 @@ ParticlesEditorBase::ParticlesEditorBase() { emission_dialog->get_ok()->set_text(TTR("Create")); emission_dialog->connect("confirmed", this, "_generate_emission_points"); - err_dialog = memnew(ConfirmationDialog); - add_child(err_dialog); - emission_file_dialog = memnew(EditorFileDialog); add_child(emission_file_dialog); emission_file_dialog->connect("file_selected", this, "_resource_seleted"); diff --git a/editor/plugins/particles_editor_plugin.h b/editor/plugins/particles_editor_plugin.h index 5d05fbd4ac..1b3a1877a4 100644 --- a/editor/plugins/particles_editor_plugin.h +++ b/editor/plugins/particles_editor_plugin.h @@ -36,10 +36,6 @@ #include "scene/3d/particles.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class ParticlesEditorBase : public Control { GDCLASS(ParticlesEditorBase, Control); @@ -53,8 +49,6 @@ protected: EditorFileDialog *emission_file_dialog; SceneTreeDialog *emission_tree_dialog; - ConfirmationDialog *err_dialog; - ConfirmationDialog *emission_dialog; SpinBox *emission_amount; OptionButton *emission_fill; diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index b87bd29cbd..f02dc0bd6d 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -367,18 +367,18 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node) + if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid()) return; - if (!node->is_visible_in_tree()) - return; + Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - if (!node->get_curve().is_valid()) - return; + const Ref<Texture> path_sharp_handle = get_icon("EditorPathSharpHandle", "EditorIcons"); + const Ref<Texture> path_smooth_handle = get_icon("EditorPathSmoothHandle", "EditorIcons"); + // Both handle icons must be of the same size + const Size2 handle_size = path_sharp_handle->get_size(); - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - Size2 handle_size = handle->get_size(); + const Ref<Texture> curve_handle = get_icon("EditorCurveHandle", "EditorIcons"); + const Size2 curve_handle_size = curve_handle->get_size(); Ref<Curve2D> curve = node->get_curve(); @@ -387,19 +387,35 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { for (int i = 0; i < len; i++) { Vector2 point = xform.xform(curve->get_point_position(i)); - vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1)); + // Determines the point icon to be used + bool smooth = false; if (i < len - 1) { Vector2 pointout = xform.xform(curve->get_point_position(i) + curve->get_point_out(i)); - vpc->draw_line(point, pointout, Color(0.5, 0.5, 1.0, 0.8), 1.0); - vpc->draw_texture_rect(handle, Rect2(pointout - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); + if (point != pointout) { + smooth = true; + // Draw the line with a dark and light color to be visible on all backgrounds + vpc->draw_line(point, pointout, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointout, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_texture_rect(curve_handle, Rect2(pointout - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); + } } if (i > 0) { Vector2 pointin = xform.xform(curve->get_point_position(i) + curve->get_point_in(i)); - vpc->draw_line(point, pointin, Color(0.5, 0.5, 1.0, 0.8), 1.0); - vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); + if (point != pointin) { + smooth = true; + // Draw the line with a dark and light color to be visible on all backgrounds + vpc->draw_line(point, pointin, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointin, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_texture_rect(curve_handle, Rect2(pointin - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); + } } + + vpc->draw_texture_rect( + smooth ? path_smooth_handle : path_sharp_handle, + Rect2(point - handle_size * 0.5, handle_size), + false); } if (on_edge) { diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index 44472f7a81..ecec5f5253 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -36,9 +36,6 @@ #include "scene/2d/path_2d.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditor; class Path2DEditor : public HBoxContainer { diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 1ae5acc5ff..2493380585 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -652,7 +652,6 @@ PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() { Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8)); create_material("path_material", path_color); - path_color.a = 0.4; - create_material("path_thin_material", path_color); + create_material("path_thin_material", Color(0.5, 0.5, 0.5)); create_handle_material("handles"); } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 59004a08c0..bd532a6418 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -1045,8 +1045,8 @@ void Polygon2DEditor::_uv_draw() { } } - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - Ref<Texture> internal_handle = get_icon("EditorInternalHandle", "EditorIcons"); + // All UV points are sharp, so use the sharp handle icon + Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); Color poly_line_color = Color(0.9, 0.5, 0.5); if (polygons.size() || polygon_create.size()) { @@ -1120,7 +1120,8 @@ void Polygon2DEditor::_uv_draw() { if (i < uv_draw_max) { uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5); } else { - uv_edit_draw->draw_texture(internal_handle, mtx.xform(uvs[i]) - internal_handle->get_size() * 0.5); + // Internal vertex + uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1)); } } } diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index 24ca2ea3f4..009501a70c 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -33,9 +33,7 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/gui/scroll_container.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ + class Polygon2DEditor : public AbstractPolygon2DEditor { GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 9418349d71..76c7545874 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -44,6 +44,7 @@ #include "editor/script_editor_debugger.h" #include "scene/main/viewport.h" #include "script_text_editor.h" +#include "text_editor.h" /*** SCRIPT EDITOR ****/ @@ -55,7 +56,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); - // TODO This signal is no use for VisualScript... + // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); } @@ -204,11 +205,13 @@ void ScriptEditorQuickOpen::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { disconnect("confirmed", this, "_confirmed"); @@ -241,6 +244,8 @@ ScriptEditorQuickOpen::ScriptEditorQuickOpen() { set_hide_on_ok(false); search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); + search_options->set_hide_folding(true); + search_options->add_constant_override("draw_guides", 1); } ///////////////////////////////// @@ -485,9 +490,6 @@ void ScriptEditor::_update_recent_scripts() { Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); recent_scripts->clear(); - recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"))); - recent_scripts->add_separator(); - String path; for (int i = 0; i < rc.size(); i++) { @@ -510,11 +512,6 @@ void ScriptEditor::_open_recent_script(int p_idx) { return; } - // take two for the open recent button - if (p_idx > 0) { - p_idx -= 2; - } - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); ERR_FAIL_INDEX(p_idx, rc.size()); @@ -995,7 +992,7 @@ void ScriptEditor::_menu_option(int p_option) { file_dialog->clear_filters(); file_dialog->popup_centered_ratio(); - file_dialog->set_title(TTR("New TextFile...")); + file_dialog->set_title(TTR("New Text File...")); } break; case FILE_OPEN: { file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); @@ -1067,6 +1064,7 @@ void ScriptEditor::_menu_option(int p_option) { save_all_scripts(); } break; case SEARCH_IN_FILES: { + _on_find_in_files_requested(""); } break; case SEARCH_HELP: { @@ -1419,15 +1417,25 @@ void ScriptEditor::_notification(int p_what) { } EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_icon("Instance", "EditorIcons")); request_docs->set_icon(get_icon("Issue", "EditorIcons")); script_forward->set_icon(get_icon("Forward", "EditorIcons")); script_back->set_icon(get_icon("Back", "EditorIcons")); + members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons")); + filter_scripts->set_right_icon(get_icon("Search", "EditorIcons")); filter_methods->set_right_icon(get_icon("Search", "EditorIcons")); + + filename->add_style_override("normal", editor->get_gui_base()->get_stylebox("normal", "LineEdit")); + + recent_scripts->set_as_minsize(); } break; case NOTIFICATION_READY: { @@ -1450,20 +1458,6 @@ void ScriptEditor::_notification(int p_what) { _update_modified_scripts_for_external_editor(); } break; - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - - help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); - site_search->set_icon(get_icon("Instance", "EditorIcons")); - - script_forward->set_icon(get_icon("Forward", "EditorIcons")); - script_back->set_icon(get_icon("Back", "EditorIcons")); - - members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons")); - filename->add_style_override("normal", editor->get_gui_base()->get_stylebox("normal", "LineEdit")); - - recent_scripts->set_as_minsize(); - } break; - case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { @@ -2988,18 +2982,38 @@ void ScriptEditor::_on_find_in_files_requested(String text) { void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) { - RES res = ResourceLoader::load(fpath); - if (fpath.get_extension() == "shader") { - ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); - shader_editor->edit(res.ptr()); - shader_editor->make_visible(true); - shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); - } else { - edit(res); + if (ResourceLoader::exists(fpath)) { + RES res = ResourceLoader::load(fpath); - ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); - if (ste) { - ste->goto_line_selection(line_number - 1, begin, end); + if (fpath.get_extension() == "shader") { + ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); + shader_editor->edit(res.ptr()); + shader_editor->make_visible(true); + shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); + return; + } else { + Ref<Script> script = res; + if (script.is_valid()) { + edit(script); + + ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); + if (ste) { + ste->goto_line_selection(line_number - 1, begin, end); + } + return; + } + } + } + + // If the file is not a valid resource/script, load it as a text file. + Error err; + Ref<TextFile> text_file = _load_text_file(fpath, &err); + if (text_file.is_valid()) { + edit(text_file); + + TextEditor *te = Object::cast_to<TextEditor>(_get_current_editor()); + if (te) { + te->goto_line_selection(line_number - 1, begin, end); } } } @@ -3219,7 +3233,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->set_switch_on_hover(true); file_menu->get_popup()->set_hide_on_window_lose_focus(true); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script...")), FILE_NEW); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New TextFile...")), FILE_NEW_TEXTFILE); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New Text File...")), FILE_NEW_TEXTFILE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open...")), FILE_OPEN); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reopen_closed_script", TTR("Reopen Closed Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T), FILE_REOPEN_CLOSED); file_menu->get_popup()->add_submenu_item(TTR("Open Recent"), "RecentScripts", FILE_OPEN_RECENT); @@ -3252,17 +3266,20 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { theme_submenu->connect("id_pressed", this, "_theme_option"); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme...")), THEME_IMPORT); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), THEME_RELOAD); + theme_submenu->add_separator(); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), THEME_SAVE); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As...")), THEME_SAVE_AS); file_menu->get_popup()->add_separator(); - 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_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); + 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(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL); file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); @@ -3551,8 +3568,7 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_flags", PROPERTY_HINT_PLACEHOLDER_TEXT, "Call flags with placeholders: {project}, {file}, {col}, {line}.")); ED_SHORTCUT("script_editor/reopen_closed_script", TTR("Reopen Closed Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T); - ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent")); - ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files")); + ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Scripts")); } ScriptEditorPlugin::~ScriptEditorPlugin() { diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 07303da2ff..bded590351 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -30,6 +30,7 @@ #include "script_text_editor.h" +#include "core/math/expression.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -1147,6 +1148,32 @@ void ScriptTextEditor::_edit_option(int p_op) { _convert_case(CodeTextEditor::CAPITALIZE); } break; + case EDIT_EVALUATE: { + + Expression expression; + Vector<String> lines = code_editor->get_text_edit()->get_selection_text().split("\n"); + PoolStringArray results; + + for (int i = 0; i < lines.size(); i++) { + String line = lines[i]; + String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning + + if (expression.parse(line) == OK) { + Variant result = expression.execute(Array(), Variant(), false); + if (expression.get_error_text() == "") { + results.append(whitespace + (String)result); + } else { + results.append(line); + } + } else { + results.append(line); + } + } + + code_editor->get_text_edit()->begin_complex_operation(); //prevents creating a two-step undo + code_editor->get_text_edit()->insert_text_at_cursor(results.join("\n")); + code_editor->get_text_edit()->end_complex_operation(); + } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); @@ -1170,7 +1197,6 @@ void ScriptTextEditor::_edit_option(int p_op) { // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal("search_in_files_requested", selected_text); - } break; case SEARCH_LOCATE_FUNCTION: { @@ -1572,7 +1598,9 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { if (has_color) { String line = tx->get_line(row); - color_line = row; + color_position.x = row; + color_position.y = col; + int begin = 0; int end = 0; bool valid = false; @@ -1612,25 +1640,33 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")"); } - String line = code_editor->get_text_edit()->get_line(color_line); - String new_line = line.replace(color_args, new_args); + String line = code_editor->get_text_edit()->get_line(color_position.x); + int color_args_pos = line.find(color_args, color_position.y); + String line_with_replaced_args = line; + line_with_replaced_args.erase(color_args_pos, color_args.length()); + line_with_replaced_args = line_with_replaced_args.insert(color_args_pos, new_args); + color_args = new_args; - code_editor->get_text_edit()->set_line(color_line, new_line); + code_editor->get_text_edit()->begin_complex_operation(); + code_editor->get_text_edit()->set_line(color_position.x, line_with_replaced_args); + code_editor->get_text_edit()->end_complex_operation(); + code_editor->get_text_edit()->update(); } void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition) { 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/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/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); @@ -1641,6 +1677,7 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p context_menu->add_separator(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); } if (p_foldable) context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); @@ -1710,6 +1747,7 @@ ScriptTextEditor::ScriptTextEditor() { color_panel = memnew(PopupPanel); add_child(color_panel); color_picker = memnew(ColorPicker); + color_picker->set_deferred_mode(true); color_panel->add_child(color_picker); color_picker->connect("color_changed", this, "_color_changed"); @@ -1740,6 +1778,7 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu->get_popup()->add_separator(); 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/complete_symbol"), EDIT_COMPLETE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS); @@ -1776,11 +1815,7 @@ ScriptTextEditor::ScriptTextEditor() { search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL); - search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_hb->add_child(edit_menu); @@ -1789,6 +1824,11 @@ ScriptTextEditor::ScriptTextEditor() { edit_hb->add_child(goto_menu); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); bookmarks_menu = memnew(PopupMenu); bookmarks_menu->set_name("Bookmarks"); @@ -1848,16 +1888,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN); ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K); - //leave these at zero, same can be accomplished with tab/shift-tab, including selection - //the next/previous in history shortcut in this case makes a lot more sene. + // Leave these at zero, same can be accomplished with tab/shift-tab, including selection. + // The next/previous in history shortcut in this case makes a lot more sense. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0); 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/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); - ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); - ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); - ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F); 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); @@ -1868,20 +1904,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D); ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif + ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E); ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T); ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y); ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I); ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); -#ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); -#else - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); -#endif - ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); - ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); - ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); - ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_MASK_CMD | KEY_G); @@ -1896,6 +1924,17 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F); #ifdef OSX_ENABLED + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); +#else + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); +#endif + + ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); + ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); + ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); + ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); + +#ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J); #else ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F); @@ -1903,10 +1942,13 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L); #ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); #else - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); #endif + ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); + ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); + ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); ScriptEditor::register_create_script_editor_function(create_editor); } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 4dbade472c..38c6da5c33 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -81,7 +81,7 @@ class ScriptTextEditor : public ScriptEditorBase { PopupPanel *color_panel; ColorPicker *color_picker; - int color_line; + Vector2 color_position; String color_args; void _update_member_keywords(); @@ -120,6 +120,7 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, EDIT_CAPITALIZE, + EDIT_EVALUATE, EDIT_TOGGLE_FOLD_LINE, EDIT_FOLD_ALL_LINES, EDIT_UNFOLD_ALL_LINES, diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 37460c58ff..04820b8a8f 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -529,19 +529,19 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { void ShaderEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = shader_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = shader_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -550,17 +550,17 @@ void ShaderEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void ShaderEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _menu_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _menu_option(bookmarks_menu->get_item_id(p_idx)); } else { - shader_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + shader_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } @@ -649,16 +649,23 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { 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_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - bookmarks_menu = memnew(MenuButton); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name("Bookmarks"); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); help_menu = memnew(MenuButton); help_menu->set_text(TTR("Help")); @@ -670,7 +677,7 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { main_container->add_child(hbc); hbc->add_child(search_menu); hbc->add_child(edit_menu); - hbc->add_child(bookmarks_menu); + hbc->add_child(goto_menu); hbc->add_child(help_menu); hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles")); main_container->add_child(shader_editor); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 5d03c37dc4..8d3f4d4fe8 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -99,7 +99,7 @@ class ShaderEditor : public PanelContainer { MenuButton *edit_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; + PopupMenu *bookmarks_menu; MenuButton *help_menu; PopupMenu *context_menu; uint64_t idle; diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index d2b1cfc5af..2eb3ce1ec3 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2373,16 +2373,22 @@ void SpatialEditorViewport::_draw() { get_stylebox("Focus", "EditorStyles")->draw(surface->get_canvas_item(), r); } - RID ci = surface->get_canvas_item(); - if (cursor.region_select) { + const Rect2 selection_rect = Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, - Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + surface->draw_rect( + selection_rect, + get_color("box_selection_fill_color", "Editor")); + + surface->draw_rect( + selection_rect, + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } + RID ci = surface->get_canvas_item(); + if (message_time > 0) { Ref<Font> font = get_font("font", "Label"); Point2 msgpos = Point2(5, get_size().y - 20); @@ -3551,7 +3557,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Doppler Enable")), VIEW_AUDIO_DOPPLER); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Enable Doppler")), VIEW_AUDIO_DOPPLER); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); @@ -5170,7 +5176,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() { // We add a bit of margin to the from position to avoid it from snapping // when the spatial is already on a floor and there's another floor under // it - from = from + Vector3(0.0, 0.1, 0.0); + from = from + Vector3(0.0, 0.2, 0.0); Dictionary d; @@ -5185,31 +5191,56 @@ void SpatialEditor::snap_selected_nodes_to_floor() { Array keys = snap_data.keys(); - if (keys.size()) { - undo_redo->create_action(TTR("Snap Nodes To Floor")); + // The maximum height an object can travel to be snapped + const float max_snap_height = 20.0; + + // Will be set to `true` if at least one node from the selection was sucessfully snapped + bool snapped_to_floor = false; + if (keys.size()) { + // For snapping to be performed, there must be solid geometry under at least one of the selected nodes. + // We need to check this before snapping to register the undo/redo action only if needed. for (int i = 0; i < keys.size(); i++) { Node *node = keys[i]; Spatial *sp = Object::cast_to<Spatial>(node); - Dictionary d = snap_data[node]; Vector3 from = d["from"]; - Vector3 position_offset = d["position_offset"]; - - Vector3 to = from - Vector3(0.0, 10.0, 0.0); + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); Set<RID> excluded = _get_physics_bodies_rid(sp); if (ss->intersect_ray(from, to, result, excluded)) { - Transform new_transform = sp->get_global_transform(); - new_transform.origin.y = result.position.y; - new_transform.origin = new_transform.origin - position_offset; - - undo_redo->add_do_method(sp, "set_global_transform", new_transform); - undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + snapped_to_floor = true; } } - undo_redo->commit_action(); + if (snapped_to_floor) { + undo_redo->create_action(TTR("Snap Nodes To Floor")); + + // Perform snapping if at least one node can be snapped + for (int i = 0; i < keys.size(); i++) { + Node *node = keys[i]; + Spatial *sp = Object::cast_to<Spatial>(node); + Dictionary d = snap_data[node]; + Vector3 from = d["from"]; + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); + Set<RID> excluded = _get_physics_bodies_rid(sp); + + if (ss->intersect_ray(from, to, result, excluded)) { + Vector3 position_offset = d["position_offset"]; + Transform new_transform = sp->get_global_transform(); + + new_transform.origin.y = result.position.y; + new_transform.origin = new_transform.origin - position_offset; + + undo_redo->add_do_method(sp, "set_global_transform", new_transform); + undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + } + } + + undo_redo->commit_action(); + } else { + EditorNode::get_singleton()->show_warning(TTR("Couldn't find a solid floor to snap the selection to.")); + } } } @@ -5219,42 +5250,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) { return; snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); - - Ref<InputEventKey> k = p_event; - - if (k.is_valid()) { - - // Note: need to check is_echo because first person movement keys might still be held - if (!is_any_freelook_active() && !p_event->is_echo()) { - - if (!k->is_pressed()) - return; - - if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event)) { - _menu_item_pressed(MENU_TOOL_SELECT); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event)) { - _menu_item_pressed(MENU_TOOL_MOVE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event)) { - _menu_item_pressed(MENU_TOOL_ROTATE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) { - _menu_item_pressed(MENU_TOOL_SCALE); - } else if (ED_IS_SHORTCUT("spatial_editor/snap_to_floor", p_event)) { - snap_selected_nodes_to_floor(); - } else if (ED_IS_SHORTCUT("spatial_editor/local_coords", p_event)) { - if (are_local_coords_enabled()) { - _menu_item_toggled(false, MENU_TOOL_LOCAL_COORDS); - } else { - _menu_item_toggled(true, MENU_TOOL_LOCAL_COORDS); - } - } else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { - if (is_snap_enabled()) { - _menu_item_toggled(false, MENU_TOOL_USE_SNAP); - } else { - _menu_item_toggled(true, MENU_TOOL_USE_SNAP); - } - } - } - } } void SpatialEditor::_notification(int p_what) { @@ -5438,6 +5433,7 @@ void SpatialEditor::_register_all_gizmos() { add_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); add_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); add_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); + add_gizmo_plugin(Ref<CPUParticlesGizmoPlugin>(memnew(CPUParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); @@ -5527,7 +5523,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SELECT]->set_pressed(true); button_binds.write[0] = MENU_TOOL_SELECT; tool_button[TOOL_MODE_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SELECT]->set_tooltip(TTR("Select Mode (Q)") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); + tool_button[TOOL_MODE_SELECT]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), KEY_Q)); + tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); hbc_menu->add_child(memnew(VSeparator)); @@ -5537,7 +5534,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_MOVE]->set_flat(true); button_binds.write[0] = MENU_TOOL_MOVE; tool_button[TOOL_MODE_MOVE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_MOVE]->set_tooltip(TTR("Move Mode (W)")); + tool_button[TOOL_MODE_MOVE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_move", TTR("Move Mode"), KEY_W)); tool_button[TOOL_MODE_ROTATE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_ROTATE]); @@ -5545,7 +5542,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_ROTATE]->set_flat(true); button_binds.write[0] = MENU_TOOL_ROTATE; tool_button[TOOL_MODE_ROTATE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_ROTATE]->set_tooltip(TTR("Rotate Mode (E)")); + tool_button[TOOL_MODE_ROTATE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Rotate Mode"), KEY_E)); tool_button[TOOL_MODE_SCALE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_SCALE]); @@ -5553,7 +5550,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SCALE]->set_flat(true); button_binds.write[0] = MENU_TOOL_SCALE; tool_button[TOOL_MODE_SCALE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SCALE]->set_tooltip(TTR("Scale Mode (R)")); + tool_button[TOOL_MODE_SCALE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_scale", TTR("Scale Mode"), KEY_R)); hbc_menu->add_child(memnew(VSeparator)); @@ -5597,9 +5594,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_flat(true); button_binds.write[0] = MENU_TOOL_LOCAL_COORDS; tool_option_button[TOOL_OPT_LOCAL_COORDS]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/local_coords", TTR("Local Coords"), KEY_T); - sct = ED_GET_SHORTCUT("spatial_editor/local_coords").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_tooltip(vformat(TTR("Local Space Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_shortcut(ED_SHORTCUT("spatial_editor/local_coords", TTR("Use Local Space"), KEY_T)); tool_option_button[TOOL_OPT_USE_SNAP] = memnew(ToolButton); hbc_menu->add_child(tool_option_button[TOOL_OPT_USE_SNAP]); @@ -5607,9 +5602,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_USE_SNAP]->set_flat(true); button_binds.write[0] = MENU_TOOL_USE_SNAP; tool_option_button[TOOL_OPT_USE_SNAP]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_Y); - sct = ED_GET_SHORTCUT("spatial_editor/snap").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_USE_SNAP]->set_tooltip(vformat(TTR("Snap Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_USE_SNAP]->set_shortcut(ED_SHORTCUT("spatial_editor/snap", TTR("Use Snap"), KEY_Y)); hbc_menu->add_child(memnew(VSeparator)); @@ -5629,12 +5622,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { ED_SHORTCUT("spatial_editor/focus_selection", TTR("Focus Selection"), KEY_F); ED_SHORTCUT("spatial_editor/align_transform_with_view", TTR("Align Transform with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_M); ED_SHORTCUT("spatial_editor/align_rotation_with_view", TTR("Align Rotation with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_F); - - ED_SHORTCUT("spatial_editor/tool_select", TTR("Tool Select"), KEY_Q); - ED_SHORTCUT("spatial_editor/tool_move", TTR("Tool Move"), KEY_W); - ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Tool Rotate"), KEY_E); - ED_SHORTCUT("spatial_editor/tool_scale", TTR("Tool Scale"), KEY_R); - ED_SHORTCUT("spatial_editor/freelook_toggle", TTR("Toggle Freelook"), KEY_MASK_SHIFT + KEY_F); PopupMenu *p; @@ -5646,10 +5633,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p = transform_menu->get_popup(); p->add_shortcut(ED_SHORTCUT("spatial_editor/snap_to_floor", TTR("Snap Object to Floor"), KEY_PAGEDOWN), MENU_SNAP_TO_FLOOR); - p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); - p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/transform_dialog", TTR("Transform Dialog...")), MENU_TRANSFORM_DIALOG); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); + p->connect("id_pressed", this, "_menu_item_pressed"); view_menu = memnew(MenuButton); @@ -5673,11 +5661,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_submenu_item(TTR("Gizmos"), "GizmosMenu"); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); + p->add_separator(); - p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); + p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings...")), MENU_VIEW_CAMERA_SETTINGS); p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index 523573333b..728b67f6fa 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -37,9 +37,6 @@ #include "scene/3d/light.h" #include "scene/3d/visual_instance.h" #include "scene/gui/panel_container.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class Camera; class SpatialEditor; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 34d8e6aff5..89e419ede8 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -221,19 +221,19 @@ void TextEditor::_validate_script() { void TextEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -242,17 +242,17 @@ void TextEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void TextEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _edit_option(bookmarks_menu->get_item_id(p_idx)); } else { - code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } @@ -313,6 +313,11 @@ void TextEditor::goto_line(int p_line, bool p_with_error) { code_editor->goto_line(p_line); } +void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { + + code_editor->goto_line_selection(p_line, p_begin, p_end); +} + void TextEditor::set_executing_line(int p_line) { code_editor->set_executing_line(p_line); @@ -477,6 +482,14 @@ void TextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; + case SEARCH_IN_FILES: { + + String selected_text = code_editor->get_text_edit()->get_selection_text(); + + // Yep, because it doesn't make sense to instance this dialog for every single script open... + // So this will be delegated to the ScriptEditor. + emit_signal("search_in_files_requested", selected_text); + } break; case SEARCH_GOTO_LINE: { goto_line_dialog->popup_find_line(tx); @@ -553,7 +566,7 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int to_column = tx->get_selection_to_column(); if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { - // Right click is outside the selected text + // Right click is outside the selected text. tx->deselect(); } } @@ -632,17 +645,14 @@ TextEditor::TextEditor() { 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_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - - goto_line_dialog = memnew(GotoLineDialog); - add_child(goto_line_dialog); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); edit_menu = memnew(MenuButton); + edit_hb->add_child(edit_menu); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); - edit_hb->add_child(edit_menu); 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(); @@ -684,13 +694,25 @@ TextEditor::TextEditor() { highlighter_menu->add_radio_check_item(TTR("Standard")); highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter"); - bookmarks_menu = memnew(MenuButton); - edit_hb->add_child(bookmarks_menu); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + edit_hb->add_child(goto_menu); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name(TTR("Bookmarks")); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); + + goto_line_dialog = memnew(GotoLineDialog); + add_child(goto_line_dialog); code_editor->get_text_edit()->set_drag_forwarding(this); } diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 3a330576ae..c8b49a61e0 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -46,7 +46,7 @@ private: MenuButton *edit_menu; PopupMenu *highlighter_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; + PopupMenu *bookmarks_menu; PopupMenu *context_menu; GotoLineDialog *goto_line_dialog; @@ -87,6 +87,7 @@ private: SEARCH_FIND_NEXT, SEARCH_FIND_PREV, SEARCH_REPLACE, + SEARCH_IN_FILES, SEARCH_GOTO_LINE, BOOKMARK_TOGGLE, BOOKMARK_GOTO_NEXT, @@ -131,6 +132,7 @@ public: virtual Vector<String> get_functions(); virtual void get_breakpoints(List<int> *p_breakpoints); virtual void goto_line(int p_line, bool p_with_error = false); + void goto_line_selection(int p_line, int p_begin, int p_end); virtual void set_executing_line(int p_line); virtual void clear_executing_line(); virtual void trim_trailing_whitespace(); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 5b67d259ba..3055a9382c 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -36,6 +36,7 @@ void ThemeEditor::edit(const Ref<Theme> &p_theme) { theme = p_theme; + main_panel->set_theme(p_theme); main_container->set_theme(p_theme); } @@ -53,6 +54,7 @@ void ThemeEditor::_propagate_redraw(Control *p_at) { void ThemeEditor::_refresh_interval() { + _propagate_redraw(main_panel); _propagate_redraw(main_container); } @@ -130,14 +132,14 @@ void ThemeEditor::_save_template_cbk(String fname) { Map<String, _TECategory> categories; - //fill types + // Fill types. List<StringName> type_list; Theme::get_default()->get_type_list(&type_list); for (List<StringName>::Element *E = type_list.front(); E; E = E->next()) { categories.insert(E->get(), _TECategory()); } - //fill default theme + // Fill default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); @@ -189,11 +191,9 @@ void ThemeEditor::_save_template_cbk(String fname) { } FileAccess *file = FileAccess::open(filename, FileAccess::WRITE); - if (!file) { - ERR_EXPLAIN(TTR("Can't save theme to file:") + " " + filename); - return; - } + ERR_FAIL_COND_MSG(!file, "Can't save theme to file: " + filename + "."); + file->store_line("; ******************* "); file->store_line("; Template Theme File "); file->store_line("; ******************* "); @@ -256,7 +256,7 @@ void ThemeEditor::_save_template_cbk(String fname) { file->store_line(""); file->store_line(""); - //write default theme + // Write default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); @@ -501,7 +501,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { type_select_label->show(); type_select->show(); - if (p_option == POPUP_ADD) { //add + if (p_option == POPUP_ADD) { // Add. add_del_dialog->set_title(TTR("Add Item")); add_del_dialog->get_ok()->set_text(TTR("Add")); @@ -509,7 +509,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme = Theme::get_default(); - } else if (p_option == POPUP_CLASS_ADD) { //add + } else if (p_option == POPUP_CLASS_ADD) { // Add. add_del_dialog->set_title(TTR("Add All Items")); add_del_dialog->get_ok()->set_text(TTR("Add All")); @@ -552,12 +552,10 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { type_menu->get_popup()->clear(); - if (p_option == 0 || p_option == 1) { //add + if (p_option == 0 || p_option == 1) { // Add. List<StringName> new_types; theme->get_type_list(&new_types); - - //uh kind of sucks for (List<StringName>::Element *F = new_types.front(); F; F = F->next()) { bool found = false; @@ -583,15 +581,17 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { void ThemeEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PROCESS) { - - time_left -= get_process_delta_time(); - if (time_left < 0) { - time_left = 1.5; - _refresh_interval(); - } - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - theme_menu->set_icon(get_icon("Theme", "EditorIcons")); + switch (p_what) { + case NOTIFICATION_PROCESS: { + time_left -= get_process_delta_time(); + if (time_left < 0) { + time_left = 1.5; + _refresh_interval(); + } + } break; + case NOTIFICATION_THEME_CHANGED: { + theme_menu->set_icon(get_icon("Theme", "EditorIcons")); + } break; } } @@ -629,35 +629,34 @@ ThemeEditor::ThemeEditor() { top_menu->add_child(theme_menu); theme_menu->get_popup()->connect("id_pressed", this, "_theme_menu_cbk"); - scroll = memnew(ScrollContainer); + ScrollContainer *scroll = memnew(ScrollContainer); add_child(scroll); - scroll->set_theme(Theme::get_default()); scroll->set_enable_v_scroll(true); scroll->set_enable_h_scroll(false); scroll->set_v_size_flags(SIZE_EXPAND_FILL); - main_container = memnew(MarginContainer); - scroll->add_child(main_container); - main_container->set_theme(Theme::get_default()); - main_container->set_clip_contents(true); - main_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE); - main_container->set_v_size_flags(SIZE_EXPAND_FILL); - main_container->set_h_size_flags(SIZE_EXPAND_FILL); + MarginContainer *root_container = memnew(MarginContainer); + scroll->add_child(root_container); + root_container->set_theme(Theme::get_default()); + root_container->set_clip_contents(true); + root_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE); + root_container->set_v_size_flags(SIZE_EXPAND_FILL); + root_container->set_h_size_flags(SIZE_EXPAND_FILL); //// Preview Controls //// - Panel *panel = memnew(Panel); - main_container->add_child(panel); + main_panel = memnew(Panel); + root_container->add_child(main_panel); - MarginContainer *mc = memnew(MarginContainer); - main_container->add_child(mc); - mc->add_constant_override("margin_right", 4 * EDSCALE); - mc->add_constant_override("margin_top", 4 * EDSCALE); - mc->add_constant_override("margin_left", 4 * EDSCALE); - mc->add_constant_override("margin_bottom", 4 * EDSCALE); + main_container = memnew(MarginContainer); + root_container->add_child(main_container); + main_container->add_constant_override("margin_right", 4 * EDSCALE); + main_container->add_constant_override("margin_top", 4 * EDSCALE); + main_container->add_constant_override("margin_left", 4 * EDSCALE); + main_container->add_constant_override("margin_bottom", 4 * EDSCALE); HBoxContainer *main_hb = memnew(HBoxContainer); - mc->add_child(main_hb); + main_container->add_child(main_hb); VBoxContainer *first_vb = memnew(VBoxContainer); main_hb->add_child(first_vb); @@ -695,19 +694,19 @@ ThemeEditor::ThemeEditor() { test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_check_item(TTR("Check Item")); test_menu_button->get_popup()->add_check_item(TTR("Checked Item")); - test_menu_button->get_popup()->set_item_checked(3, true); + test_menu_button->get_popup()->set_item_checked(4, true); test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_radio_check_item(TTR("Radio Item")); test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item")); - test_menu_button->get_popup()->set_item_checked(6, true); + test_menu_button->get_popup()->set_item_checked(7, true); test_menu_button->get_popup()->add_separator(TTR("Named Sep.")); PopupMenu *test_submenu = memnew(PopupMenu); test_menu_button->get_popup()->add_child(test_submenu); test_submenu->set_name("submenu"); test_menu_button->get_popup()->add_submenu_item(TTR("Submenu"), "submenu"); - test_submenu->add_item(TTR("Item 1")); - test_submenu->add_item(TTR("Item 2")); + test_submenu->add_item(TTR("Subitem 1")); + test_submenu->add_item(TTR("Subitem 2")); first_vb->add_child(test_menu_button); OptionButton *test_option_button = memnew(OptionButton); diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index cc236907a9..6ffee46569 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -45,7 +45,7 @@ class ThemeEditor : public VBoxContainer { GDCLASS(ThemeEditor, VBoxContainer); - ScrollContainer *scroll; + Panel *main_panel; MarginContainer *main_container; Ref<Theme> theme; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index b2f06ca41f..26fae96025 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -972,7 +972,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree()) + if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return false; Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); @@ -1533,7 +1533,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node) + if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return; Transform2D cell_xf = node->get_cell_transform(); @@ -2006,7 +2006,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { // Tools paint_button = memnew(ToolButton); paint_button->set_shortcut(ED_SHORTCUT("tile_map_editor/paint_tile", TTR("Paint Tile"), KEY_P)); - paint_button->set_tooltip(TTR("Shift+RMB: Line Draw\nShift+Ctrl+RMB: Rectangle Paint")); + paint_button->set_tooltip(TTR("Shift+LMB: Line Draw\nShift+Ctrl+LMB: Rectangle Paint")); paint_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_NONE)); paint_button->set_toggle_mode(true); toolbar->add_child(paint_button); @@ -2136,6 +2136,7 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { tile_map_editor->show(); tile_map_editor->get_toolbar()->show(); tile_map_editor->get_toolbar_right()->show(); + CanvasItemEditor::get_singleton()->set_current_tool(CanvasItemEditor::TOOL_SELECT); //Change to TOOL_SELECT when TileMap node is selected, to prevent accidental movement. } else { tile_map_editor->hide(); diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 3331fb971f..c841eb1f98 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -41,10 +41,6 @@ #include "scene/gui/menu_button.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class TileMapEditor : public VBoxContainer { GDCLASS(TileMapEditor, VBoxContainer); diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index 1a27e749e2..c1e85788f8 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -646,8 +646,7 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { for (int i = 0; i < p_paths.size(); i++) { Ref<Texture> t = Ref<Texture>(ResourceLoader::load(p_paths[i])); - ERR_EXPLAIN("'" + p_paths[i] + "' is not a valid texture."); - ERR_CONTINUE(!t.is_valid()); + ERR_CONTINUE_MSG(!t.is_valid(), "'" + p_paths[i] + "' is not a valid texture."); if (texture_map.has(t->get_rid())) { invalid_count++; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 4f7b9f9815..c036a31ab5 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -41,18 +41,19 @@ #include "scene/gui/panel.h" #include "scene/main/viewport.h" #include "scene/resources/visual_shader_nodes.h" +#include "servers/visual/shader_types.h" -Control *VisualShaderNodePlugin::create_editor(const Ref<VisualShaderNode> &p_node) { +Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { if (get_script_instance()) { - return get_script_instance()->call("create_editor", p_node); + return get_script_instance()->call("create_editor", p_parent_resource, p_node); } return NULL; } void VisualShaderNodePlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); } /////////////////// @@ -69,8 +70,16 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { } } visual_shader = Ref<VisualShader>(p_visual_shader); + if (!visual_shader->is_connected("changed", this, "_update_preview")) { + visual_shader->connect("changed", this, "_update_preview"); + } visual_shader->set_graph_offset(graph->get_scroll_ofs() / EDSCALE); } else { + if (visual_shader.is_valid()) { + if (visual_shader->is_connected("changed", this, "")) { + visual_shader->disconnect("changed", this, "_update_preview"); + } + } visual_shader.unref(); } @@ -78,7 +87,10 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { hide(); } else { if (changed) { // to avoid tree collapse + _clear_buffer(); + _update_custom_nodes(); _update_options_menu(); + _update_preview(); } _update_graph(); } @@ -94,31 +106,36 @@ void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plug plugins.erase(p_plugin); } -void VisualShaderEditor::add_custom_type(const String &p_name, const String &p_category, const Ref<Script> &p_script) { - +void VisualShaderEditor::clear_custom_types() { for (int i = 0; i < add_options.size(); i++) { - ERR_FAIL_COND(add_options[i].script == p_script); + if (add_options[i].is_custom) { + add_options.remove(i); + } } - - AddOption ao; - ao.name = p_name; - ao.script = p_script; - ao.category = p_category; - add_options.push_back(ao); - - _update_options_menu(); } -void VisualShaderEditor::remove_custom_type(const Ref<Script> &p_script) { +void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_sub_category) { + + ERR_FAIL_COND(!p_name.is_valid_identifier()); + ERR_FAIL_COND(!p_script.is_valid()); for (int i = 0; i < add_options.size(); i++) { - if (add_options[i].script == p_script) { - add_options.remove(i); - return; + if (add_options[i].is_custom) { + if (add_options[i].script == p_script) + return; } } - _update_options_menu(); + AddOption ao; + ao.name = p_name; + ao.script = p_script; + ao.return_type = p_return_icon_type; + ao.description = p_description; + ao.category = p_category; + ao.sub_category = p_sub_category; + ao.is_custom = true; + + add_options.push_back(ao); } bool VisualShaderEditor::_is_available(int p_mode) { @@ -161,6 +178,66 @@ bool VisualShaderEditor::_is_available(int p_mode) { return (p_mode == -1 || (p_mode & current_mode) != 0); } +void VisualShaderEditor::_update_custom_nodes() { + clear_custom_types(); + List<StringName> class_list; + ScriptServer::get_global_class_list(&class_list); + for (int i = 0; i < class_list.size(); i++) { + if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") { + + String script_path = ScriptServer::get_global_class_path(class_list[i]); + Ref<Resource> res = ResourceLoader::load(script_path); + ERR_FAIL_COND(res.is_null()); + ERR_FAIL_COND(!res->is_class("Script")); + Ref<Script> script = Ref<Script>(res); + + Ref<VisualShaderNodeCustom> ref; + ref.instance(); + ref->set_script(script.get_ref_ptr()); + + String name; + if (ref->has_method("_get_name")) { + name = (String)ref->call("_get_name"); + } else { + name = "Unnamed"; + } + + String description = ""; + if (ref->has_method("_get_description")) { + description = (String)ref->call("_get_description"); + } + + int return_icon_type = -1; + if (ref->has_method("_get_return_icon_type")) { + return_icon_type = (int)ref->call("_get_return_icon_type"); + } + + String category = ""; + if (ref->has_method("_get_category")) { + category = (String)ref->call("_get_category"); + } + if (category == "") { + category = "Custom"; + } + + String sub_category = ""; + if (ref->has_method("_get_subcategory")) { + sub_category = (String)ref->call("_get_subcategory"); + } + + add_custom_type(name, script, description, return_icon_type, category, sub_category); + } + } +} + +String VisualShaderEditor::_get_description(int p_idx) { + if (add_options[p_idx].highend) { + return TTR("(GLES3 only)") + " " + add_options[p_idx].description; // TODO: change it to (Vulkan Only) when its ready + } else { + return add_options[p_idx].description; + } +} + void VisualShaderEditor::_update_options_menu() { node_desc->set_text(""); @@ -210,6 +287,9 @@ void VisualShaderEditor::_update_options_menu() { if (!use_filter || add_options[i].name.findn(filter) != -1) { + if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) + continue; + if (prev_category != add_options[i].category) { if (category != NULL && item_count == 0) { memdelete(category); @@ -240,73 +320,52 @@ void VisualShaderEditor::_update_options_menu() { sub_category->set_collapsed(true); } } - if (sub_category != NULL) { - if ((add_options[i].func == current_func || add_options[i].func == -1) && _is_available(add_options[i].mode)) { - ++item_count2; - TreeItem *item = members->create_item(sub_category); - if (add_options[i].highend && low_driver) - item->set_custom_color(0, unsupported_color); - else if (add_options[i].highend) - item->set_custom_color(0, supported_color); - item->set_text(0, add_options[i].name); - if (is_first_item) { - item->select(0); - is_first_item = false; - } - switch (add_options[i].return_type) { - case VisualShaderNode::PORT_TYPE_SCALAR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_VECTOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_BOOLEAN: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_TRANSFORM: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_COLOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); - break; - default: - break; - } - item->set_meta("id", i); - } - } } else { - if (category != NULL) { - if ((add_options[i].func == current_func || add_options[i].func == -1) && _is_available(add_options[i].mode)) { - ++item_count; - TreeItem *item = members->create_item(category); - if (add_options[i].highend && low_driver) - item->set_custom_color(0, unsupported_color); - else if (add_options[i].highend) - item->set_custom_color(0, supported_color); - item->set_text(0, add_options[i].name); - switch (add_options[i].return_type) { - case VisualShaderNode::PORT_TYPE_SCALAR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_VECTOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_BOOLEAN: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_TRANSFORM: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_COLOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); - break; - default: - break; - } - item->set_meta("id", i); - } + sub_category = NULL; + } + + TreeItem *p_category = NULL; + + if (sub_category != NULL) { + p_category = sub_category; + ++item_count2; + } else if (category != NULL) { + p_category = category; + ++item_count; + } + + if (p_category != NULL) { + TreeItem *item = members->create_item(p_category); + if (add_options[i].highend && low_driver) + item->set_custom_color(0, unsupported_color); + else if (add_options[i].highend) + item->set_custom_color(0, supported_color); + item->set_text(0, add_options[i].name); + if (is_first_item && use_filter) { + item->select(0); + node_desc->set_text(_get_description(i)); + is_first_item = false; } + switch (add_options[i].return_type) { + case VisualShaderNode::PORT_TYPE_SCALAR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_VECTOR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_BOOLEAN: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_TRANSFORM: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_ICON_COLOR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); + break; + default: + break; + } + item->set_meta("id", i); } prev_sub_category = add_options[i].sub_category; @@ -462,7 +521,7 @@ void VisualShaderEditor::_update_graph() { } for (int i = 0; i < plugins.size(); i++) { - custom_editor = plugins.write[i]->create_editor(vsnode); + custom_editor = plugins.write[i]->create_editor(visual_shader, vsnode); if (custom_editor) { break; } @@ -482,21 +541,23 @@ void VisualShaderEditor::_update_graph() { offset->set_custom_minimum_size(Size2(0, 6 * EDSCALE)); node->add_child(offset); - HBoxContainer *hb2 = memnew(HBoxContainer); + if (group_node->is_editable()) { + HBoxContainer *hb2 = memnew(HBoxContainer); - Button *add_input_btn = memnew(Button); - add_input_btn->set_text(TTR("Add input +")); - add_input_btn->connect("pressed", this, "_add_input_port", varray(nodes[n_i], group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "input" + itos(group_node->get_free_input_port_id())), CONNECT_DEFERRED); - hb2->add_child(add_input_btn); + Button *add_input_btn = memnew(Button); + add_input_btn->set_text(TTR("Add input +")); + add_input_btn->connect("pressed", this, "_add_input_port", varray(nodes[n_i], group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "input" + itos(group_node->get_free_input_port_id())), CONNECT_DEFERRED); + hb2->add_child(add_input_btn); - hb2->add_spacer(); + hb2->add_spacer(); - Button *add_output_btn = memnew(Button); - add_output_btn->set_text(TTR("Add output +")); - add_output_btn->connect("pressed", this, "_add_output_port", varray(nodes[n_i], group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "output" + itos(group_node->get_free_output_port_id())), CONNECT_DEFERRED); - hb2->add_child(add_output_btn); + Button *add_output_btn = memnew(Button); + add_output_btn->set_text(TTR("Add output +")); + add_output_btn->connect("pressed", this, "_add_output_port", varray(nodes[n_i], group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "output" + itos(group_node->get_free_output_port_id())), CONNECT_DEFERRED); + hb2->add_child(add_output_btn); - node->add_child(hb2); + node->add_child(hb2); + } } for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) { @@ -958,8 +1019,10 @@ void VisualShaderEditor::_expression_focus_out(Object *text_edit, int p_node) { } void VisualShaderEditor::_rebuild() { - EditorNode::get_singleton()->get_log()->clear(); - visual_shader->rebuild(); + if (visual_shader != NULL) { + EditorNode::get_singleton()->get_log()->clear(); + visual_shader->rebuild(); + } } void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) { @@ -1155,7 +1218,9 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { Ref<VisualShaderNode> vsnode; - if (add_options[p_idx].type != String()) { + bool is_custom = add_options[p_idx].is_custom; + + if (!is_custom && add_options[p_idx].type != String()) { VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type)); ERR_FAIL_COND(!vsn); @@ -1520,6 +1585,32 @@ void VisualShaderEditor::_notification(int p_what) { node_filter->set_right_icon(Control::get_icon("Search", "EditorIcons")); + preview_shader->set_icon(Control::get_icon("Shader", "EditorIcons")); + + { + Color background_color = EDITOR_GET("text_editor/highlighting/background_color"); + Color text_color = EDITOR_GET("text_editor/highlighting/text_color"); + Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); + Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); + + preview_text->add_color_override("background_color", background_color); + + for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { + + preview_text->add_keyword_color(E->get(), keyword_color); + } + + preview_text->add_font_override("font", get_font("expression", "EditorFonts")); + preview_text->add_color_override("font_color", text_color); + preview_text->add_color_override("symbol_color", symbol_color); + preview_text->add_color_region("/*", "*/", comment_color, false); + preview_text->add_color_region("//", "", comment_color, false); + + error_text->add_font_override("font", get_font("status_source", "EditorFonts")); + error_text->add_color_override("font_color", get_color("error_color", "Editor")); + } + tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Tools", "EditorIcons")); if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) @@ -1594,22 +1685,38 @@ void VisualShaderEditor::_dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int selection_center /= (float)r_nodes.size(); } -void VisualShaderEditor::_dup_paste_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select) { +void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select) { VisualShader::Type type = (VisualShader::Type)p_type; + VisualShader::Type pasted_type = (VisualShader::Type)p_pasted_type; int base_id = visual_shader->get_valid_node_id(type); int id_from = base_id; Map<int, int> connection_remap; + Set<int> unsupported_set; for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) { connection_remap[E->get()] = id_from; - Ref<VisualShaderNode> node = visual_shader->get_node(type, E->get()); + Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E->get()); + + bool unsupported = false; + for (int i = 0; i < add_options.size(); i++) { + if (add_options[i].type == node->get_class_name()) { + if (!_is_available(add_options[i].mode)) { + unsupported = true; + } + break; + } + } + if (unsupported) { + unsupported_set.insert(E->get()); + continue; + } Ref<VisualShaderNode> dupli = node->duplicate(); - undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(type, E->get()) + p_offset, id_from); + undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(pasted_type, E->get()) + p_offset, id_from); undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from); // duplicate size, inputs and outputs if node is group @@ -1629,9 +1736,12 @@ void VisualShaderEditor::_dup_paste_nodes(int p_type, List<int> &r_nodes, Set<in } List<VisualShader::Connection> conns; - visual_shader->get_node_connections(type, &conns); + visual_shader->get_node_connections(pasted_type, &conns); for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { + if (unsupported_set.has(E->get().from_node) || unsupported_set.has(E->get().to_node)) { + continue; + } if (connection_remap.has(E->get().from_node) && connection_remap.has(E->get().to_node)) { undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port); } @@ -1678,7 +1788,7 @@ void VisualShaderEditor::_duplicate_nodes() { undo_redo->create_action(TTR("Duplicate Nodes")); - _dup_paste_nodes(type, nodes, excluded, Vector2(10, 10) * EDSCALE, true); + _dup_paste_nodes(type, type, nodes, excluded, Vector2(10, 10) * EDSCALE, true); } void VisualShaderEditor::_copy_nodes() { @@ -1701,7 +1811,7 @@ void VisualShaderEditor::_paste_nodes() { float scale = graph->get_zoom(); - _dup_paste_nodes(type, copy_nodes_buffer, copy_nodes_excluded_buffer, (graph->get_scroll_ofs() / scale + graph->get_local_mouse_position() / scale - selection_center), false); + _dup_paste_nodes(type, copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer, (graph->get_scroll_ofs() / scale + graph->get_local_mouse_position() / scale - selection_center), false); _dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste } @@ -1780,9 +1890,6 @@ void VisualShaderEditor::_on_nodes_delete() { void VisualShaderEditor::_mode_selected(int p_id) { - copy_nodes_buffer.clear(); - copy_nodes_excluded_buffer.clear(); - _update_options_menu(); _update_graph(); } @@ -1830,11 +1937,7 @@ void VisualShaderEditor::_member_selected() { if (item != NULL && item->has_meta("id")) { members_dialog->get_ok()->set_disabled(false); - if (add_options[item->get_meta("id")].highend) { - node_desc->set_text(TTR("(GLES3 only)") + " " + add_options[item->get_meta("id")].description); // TODO: change it to (Vulkan Only) when its ready - } else { - node_desc->set_text(add_options[item->get_meta("id")].description); - } + node_desc->set_text(_get_description(item->get_meta("id"))); } else { members_dialog->get_ok()->set_disabled(true); node_desc->set_text(""); @@ -1954,6 +2057,48 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } } +void VisualShaderEditor::_show_preview_text() { + preview_showed = !preview_showed; + preview_vbox->set_visible(preview_showed); + if (preview_showed) { + if (pending_update_preview) { + _update_preview(); + pending_update_preview = false; + } + } +} + +void VisualShaderEditor::_update_preview() { + + if (!preview_showed) { + pending_update_preview = true; + return; + } + + String code = visual_shader->get_code(); + + preview_text->set_text(code); + + ShaderLanguage sl; + + Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_types()); + + for (int i = 0; i < preview_text->get_line_count(); i++) { + preview_text->set_line_as_marked(i, false); + } + if (err != OK) { + preview_text->set_line_as_marked(sl.get_error_line() - 1, true); + error_text->set_visible(true); + + String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); + error_text->set_text(text); + shader_error = true; + } else { + error_text->set_visible(false); + shader_error = false; + } +} + void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_rebuild", &VisualShaderEditor::_rebuild); ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph); @@ -1993,6 +2138,8 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_node_resized", &VisualShaderEditor::_node_resized); ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size); ClassDB::bind_method("_clear_buffer", &VisualShaderEditor::_clear_buffer); + ClassDB::bind_method("_show_preview_text", &VisualShaderEditor::_show_preview_text); + ClassDB::bind_method("_update_preview", &VisualShaderEditor::_update_preview); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw); @@ -2019,13 +2166,25 @@ VisualShaderEditor::VisualShaderEditor() { saved_node_pos = Point2(0, 0); ShaderLanguage::get_keyword_list(&keyword_list); + preview_showed = false; + pending_update_preview = false; + shader_error = false; + to_node = -1; to_slot = -1; from_node = -1; from_slot = -1; + main_box = memnew(HSplitContainer); + main_box->set_v_size_flags(SIZE_EXPAND_FILL); + main_box->set_h_size_flags(SIZE_EXPAND_FILL); + add_child(main_box); + graph = memnew(GraphEdit); - add_child(graph); + graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL); + graph->set_v_size_flags(SIZE_EXPAND_FILL); + graph->set_h_size_flags(SIZE_EXPAND_FILL); + main_box->add_child(graph); graph->set_drag_forwarding(this); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN); @@ -2074,6 +2233,32 @@ VisualShaderEditor::VisualShaderEditor() { graph->get_zoom_hbox()->move_child(add_node, 0); add_node->connect("pressed", this, "_show_members_dialog", varray(false)); + preview_shader = memnew(ToolButton); + preview_shader->set_toggle_mode(true); + preview_shader->set_tooltip(TTR("Show resulted shader code.")); + graph->get_zoom_hbox()->add_child(preview_shader); + preview_shader->connect("pressed", this, "_show_preview_text"); + + /////////////////////////////////////// + // PREVIEW PANEL + /////////////////////////////////////// + + preview_vbox = memnew(VBoxContainer); + preview_vbox->set_visible(preview_showed); + main_box->add_child(preview_vbox); + preview_text = memnew(TextEdit); + preview_vbox->add_child(preview_text); + preview_text->set_h_size_flags(SIZE_EXPAND_FILL); + preview_text->set_v_size_flags(SIZE_EXPAND_FILL); + preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0)); + preview_text->set_syntax_coloring(true); + preview_text->set_show_line_numbers(true); + preview_text->set_readonly(true); + + error_text = memnew(Label); + preview_vbox->add_child(error_text); + error_text->set_visible(false); + /////////////////////////////////////// // SHADER NODES TREE /////////////////////////////////////// @@ -2164,8 +2349,8 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Screen", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), VisualShaderNodeColorOp::OP_SCREEN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("SoftLight", "Color", "Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), VisualShaderNodeColorOp::OP_SOFT_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("ColorConstant", "Color", "Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, VisualShaderNode::PORT_TYPE_COLOR)); + add_options.push_back(AddOption("ColorConstant", "Color", "Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); // CONDITIONAL @@ -2351,8 +2536,8 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Sin", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("SinH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Sqrt", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeScalarFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), VisualShaderNodeScalarOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeScalarOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Tan", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("TanH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Trunc", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeScalarFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -2368,12 +2553,12 @@ VisualShaderEditor::VisualShaderEditor() { // TEXTURES - add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); + add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); - add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, VisualShaderNode::PORT_TYPE_COLOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); // TRANSFORM @@ -2429,6 +2614,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Max", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), VisualShaderNodeVectorOp::OP_MAX, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Min", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), VisualShaderNodeVectorOp::OP_MIN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeVectorInterp", TTR("Linear interpolation between two vectors."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeVectorScalarMix", TTR("Linear interpolation between two vectors using scalar."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Negate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Normalize", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("OneMinus", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNode::PORT_TYPE_VECTOR)); @@ -2444,10 +2630,10 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Sin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("SinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Sqrt", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Tan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("TanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Trunc", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_VECTOR)); @@ -2465,6 +2651,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Expression", "Special", "", "VisualShaderNodeExpression", TTR("Custom Godot Shader Language expression, with custom amount of input and output ports. This is a direct injection of code into the vertex/fragment/light function, do not use it to write the function declarations inside."))); add_options.push_back(AddOption("Fresnel", "Special", "", "VisualShaderNodeFresnel", TTR("Returns falloff based on the dot product of surface normal and view direction of camera (pass associated inputs to it)."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("GlobalExpression", "Special", "", "VisualShaderNodeGlobalExpression", TTR("Custom Godot Shader Language expression, which placed on top of the resulted shader. You can place various function definitions inside and call it later in the Expressions. You can also declare varyings, uniforms and constants."))); add_options.push_back(AddOption("ScalarDerivativeFunc", "Special", "Common", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) Scalar derivative function."), -1, VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, -1, -1, true)); add_options.push_back(AddOption("VectorDerivativeFunc", "Special", "Common", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) Vector derivative function."), -1, VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, -1, -1, true)); @@ -2590,6 +2777,7 @@ public: class VisualShaderNodePluginDefaultEditor : public VBoxContainer { GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer); + Ref<Resource> parent_resource; public: void _property_changed(const String &prop, const Variant &p_value, const String &p_field, bool p_changing = false) { @@ -2603,7 +2791,27 @@ public: undo_redo->create_action(TTR("Edit Visual Property") + ": " + prop, UndoRedo::MERGE_ENDS); undo_redo->add_do_property(node.ptr(), prop, p_value); undo_redo->add_undo_property(node.ptr(), prop, node->get(prop)); + + if (p_value.get_type() == Variant::OBJECT) { + + RES prev_res = node->get(prop); + RES curr_res = p_value; + + if (curr_res.is_null()) { + undo_redo->add_do_method(this, "_open_inspector", (RES)parent_resource.ptr()); + } else { + undo_redo->add_do_method(this, "_open_inspector", (RES)curr_res.ptr()); + } + if (!prev_res.is_null()) { + undo_redo->add_undo_method(this, "_open_inspector", (RES)prev_res.ptr()); + } else { + undo_redo->add_undo_method(this, "_open_inspector", (RES)parent_resource.ptr()); + } + undo_redo->add_do_method(this, "_refresh_request"); + undo_redo->add_undo_method(this, "_refresh_request"); + } undo_redo->commit_action(); + updating = false; } @@ -2619,11 +2827,20 @@ public: VisualShaderEditor::get_singleton()->call_deferred("_update_graph"); } + void _resource_selected(const String &p_path, RES p_resource) { + _open_inspector(p_resource); + } + + void _open_inspector(RES p_resource) { + EditorNode::get_singleton()->get_inspector()->edit(p_resource.ptr()); + } + bool updating; Ref<VisualShaderNode> node; Vector<EditorProperty *> properties; - void setup(Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) { + void setup(Ref<Resource> p_parent_resource, Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) { + parent_resource = p_parent_resource; updating = false; node = p_node; properties = p_properties; @@ -2632,6 +2849,11 @@ public: add_child(p_properties[i]); + bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]); + if (res_prop) { + p_properties[i]->connect("resource_selected", this, "_resource_selected"); + } + properties[i]->connect("property_changed", this, "_property_changed"); properties[i]->set_object_and_property(node.ptr(), p_names[i]); properties[i]->update_property(); @@ -2645,10 +2867,12 @@ public: ClassDB::bind_method("_property_changed", &VisualShaderNodePluginDefaultEditor::_property_changed, DEFVAL(String()), DEFVAL(false)); ClassDB::bind_method("_node_changed", &VisualShaderNodePluginDefaultEditor::_node_changed); ClassDB::bind_method("_refresh_request", &VisualShaderNodePluginDefaultEditor::_refresh_request); + ClassDB::bind_method("_resource_selected", &VisualShaderNodePluginDefaultEditor::_resource_selected); + ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); } }; -Control *VisualShaderNodePluginDefault::create_editor(const Ref<VisualShaderNode> &p_node) { +Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { if (p_node->is_class("VisualShaderNodeInput")) { //create input @@ -2706,7 +2930,7 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<VisualShaderNode properties.push_back(pinfo[i].name); } VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor); - editor->setup(editors, properties, p_node); + editor->setup(p_parent_resource, editors, properties, p_node); return editor; } diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index d396243bf3..cd5efc366b 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -48,7 +48,7 @@ protected: static void _bind_methods(); public: - virtual Control *create_editor(const Ref<VisualShaderNode> &p_node); + virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; class VisualShaderEditor : public VBoxContainer { @@ -60,14 +60,22 @@ class VisualShaderEditor : public VBoxContainer { int editing_port; Ref<VisualShader> visual_shader; + HSplitContainer *main_box; GraphEdit *graph; ToolButton *add_node; + ToolButton *preview_shader; OptionButton *edit_type; PanelContainer *error_panel; Label *error_label; + bool pending_update_preview; + bool shader_error; + VBoxContainer *preview_vbox; + TextEdit *preview_text; + Label *error_text; + UndoRedo *undo_redo; Point2 saved_node_pos; bool saved_node_pos_dirty; @@ -75,6 +83,8 @@ class VisualShaderEditor : public VBoxContainer { ConfirmationDialog *members_dialog; MenuButton *tools; + bool preview_showed; + enum ToolsMenuOptions { EXPAND_ALL, COLLAPSE_ALL @@ -104,6 +114,7 @@ class VisualShaderEditor : public VBoxContainer { int func; float value; bool highend; + bool is_custom; AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_sub_category = String(), const String &p_type = String(), const String &p_description = String(), int p_sub_func = -1, int p_return_type = -1, int p_mode = -1, int p_func = -1, float p_value = -1, bool p_highend = false) { name = p_name; @@ -117,6 +128,7 @@ class VisualShaderEditor : public VBoxContainer { func = p_func; value = p_value; highend = p_highend; + is_custom = false; } AddOption(const String &p_name, const String &p_category, const String &p_sub_category, const String &p_type, const String &p_description, const String &p_sub_func, int p_return_type = -1, int p_mode = -1, int p_func = -1, float p_value = -1, bool p_highend = false) { @@ -131,6 +143,7 @@ class VisualShaderEditor : public VBoxContainer { func = p_func; value = p_value; highend = p_highend; + is_custom = false; } }; @@ -140,8 +153,13 @@ class VisualShaderEditor : public VBoxContainer { void _draw_color_over_button(Object *obj, Color p_color); void _add_node(int p_idx, int p_op_idx = -1); + void _update_custom_nodes(); void _update_options_menu(); + void _show_preview_text(); + void _update_preview(); + String _get_description(int p_idx); + static VisualShaderEditor *singleton; void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node); @@ -178,7 +196,7 @@ class VisualShaderEditor : public VBoxContainer { void _dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded); void _dup_update_excluded(int p_type, Set<int> &r_excluded); - void _dup_paste_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select); + void _dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select); void _duplicate_nodes(); @@ -240,8 +258,8 @@ public: static VisualShaderEditor *get_singleton() { return singleton; } - void add_custom_type(const String &p_name, const String &p_category, const Ref<Script> &p_script); - void remove_custom_type(const Ref<Script> &p_script); + void clear_custom_types(); + void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_sub_category); virtual Size2 get_minimum_size() const; void edit(VisualShader *p_visual_shader); @@ -272,7 +290,7 @@ class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); public: - virtual Control *create_editor(const Ref<VisualShaderNode> &p_node); + virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; class EditorPropertyShaderMode : public EditorProperty { diff --git a/editor/project_export.cpp b/editor/project_export.cpp index c78a81dbe0..956da92c35 100644 --- a/editor/project_export.cpp +++ b/editor/project_export.cpp @@ -931,17 +931,8 @@ void ProjectExportDialog::_export_project() { export_project->add_filter("*." + extension_list[i] + " ; " + platform->get_name() + " Export"); } - String current_preset_export_path = current->get_export_path(); - - if (current_preset_export_path != "") { - - if (!DirAccess::exists(current_preset_export_path.get_base_dir())) { - - DirAccessRef da(DirAccess::create(DirAccess::ACCESS_FILESYSTEM)); - da->make_dir_recursive(current_preset_export_path.get_base_dir()); - } - - export_project->set_current_path(current_preset_export_path); + if (current->get_export_path() != "") { + export_project->set_current_path(current->get_export_path()); } else { if (extension_list.size() >= 1) { export_project->set_current_file(default_filename + "." + extension_list[0]); diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index feb2cdd071..5709bdc3fa 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -195,7 +195,7 @@ private: unzFile pkg = unzOpen2(valid_path.utf8().get_data(), &io); if (!pkg) { - set_message(TTR("Error opening package file, not in zip format."), MESSAGE_ERROR); + set_message(TTR("Error opening package file, not in ZIP format."), MESSAGE_ERROR); memdelete(d); get_ok()->set_disabled(true); unzClose(pkg); @@ -519,7 +519,7 @@ private: unzFile pkg = unzOpen2(zip_path.utf8().get_data(), &io); if (!pkg) { - dialog_error->set_text(TTR("Error opening package file, not in zip format.")); + dialog_error->set_text(TTR("Error opening package file, not in ZIP format.")); dialog_error->popup_centered_minsize(); return; } @@ -997,7 +997,6 @@ public: void load_projects(); void set_search_term(String p_search_term); - void set_filter_option(ProjectListFilter::FilterOption p_option); void set_order_option(ProjectListFilter::FilterOption p_option); void sort_projects(); int get_project_count() const; @@ -1030,7 +1029,6 @@ private: static void load_project_data(const String &p_property_key, Item &p_item, bool p_favorite); String _search_term; - ProjectListFilter::FilterOption _filter_option; ProjectListFilter::FilterOption _order_option; Set<String> _selected_project_keys; String _last_clicked; // Project key @@ -1063,7 +1061,6 @@ struct ProjectListComparator { }; ProjectList::ProjectList() { - _filter_option = ProjectListFilter::FILTER_NAME; _order_option = ProjectListFilter::FILTER_MODIFIED; _scroll_children = memnew(VBoxContainer); @@ -1109,7 +1106,7 @@ void ProjectList::load_project_icon(int p_index) { Error err = img->load(item.icon.replace_first("res://", item.path + "/")); if (err == OK) { - img->resize(default_icon->get_width(), default_icon->get_height()); + img->resize(default_icon->get_width(), default_icon->get_height(), Image::INTERPOLATE_LANCZOS); Ref<ImageTexture> it = memnew(ImageTexture); it->create_from_image(img); icon = it; @@ -1258,19 +1255,22 @@ void ProjectList::create_project_item_control(int p_index) { TextureRect *tf = memnew(TextureRect); tf->set_texture(get_icon("DefaultProjectIcon", "EditorIcons")); + if (item.missing) { + tf->set_modulate(Color(1, 1, 1, 0.5)); + } hb->add_child(tf); hb->icon = tf; VBoxContainer *vb = memnew(VBoxContainer); if (item.grayed) - vb->set_modulate(Color(0.5, 0.5, 0.5)); + vb->set_modulate(Color(1, 1, 1, 0.5)); vb->set_h_size_flags(SIZE_EXPAND_FILL); hb->add_child(vb); Control *ec = memnew(Control); ec->set_custom_minimum_size(Size2(0, 1)); ec->set_mouse_filter(MOUSE_FILTER_PASS); vb->add_child(ec); - Label *title = memnew(Label(item.project_name)); + Label *title = memnew(Label(!item.missing ? item.project_name : TTR("Missing Project"))); title->add_font_override("font", get_font("title", "EditorFonts")); title->add_color_override("font_color", font_color); title->set_clip_text(true); @@ -1281,12 +1281,21 @@ void ProjectList::create_project_item_control(int p_index) { vb->add_child(path_hb); Button *show = memnew(Button); - show->set_icon(get_icon("Load", "EditorIcons")); // Folder icon + // Display a folder icon if the project directory can be opened, or a "broken file" icon if it can't + show->set_icon(get_icon(!item.missing ? "Load" : "FileBroken", "EditorIcons")); show->set_flat(true); - show->set_modulate(Color(1, 1, 1, 0.5)); + if (!item.grayed) { + // Don't make the icon less prominent if the parent is already grayed out + show->set_modulate(Color(1, 1, 1, 0.5)); + } path_hb->add_child(show); - show->connect("pressed", this, "_show_project", varray(item.path)); - show->set_tooltip(TTR("Show in File Manager")); + + if (!item.missing) { + show->connect("pressed", this, "_show_project", varray(item.path)); + show->set_tooltip(TTR("Show in File Manager")); + } else { + show->set_tooltip(TTR("Error: Project is missing on the filesystem.")); + } Label *fpath = memnew(Label(item.path)); path_hb->add_child(fpath); @@ -1303,16 +1312,10 @@ void ProjectList::set_search_term(String p_search_term) { _search_term = p_search_term; } -void ProjectList::set_filter_option(ProjectListFilter::FilterOption p_option) { - if (_filter_option != p_option) { - _filter_option = p_option; - } -} - void ProjectList::set_order_option(ProjectListFilter::FilterOption p_option) { if (_order_option != p_option) { _order_option = p_option; - EditorSettings::get_singleton()->set("project_manager/sorting_order", (int)_filter_option); + EditorSettings::get_singleton()->set("project_manager/sorting_order", (int)_order_option); EditorSettings::get_singleton()->save(); } } @@ -1328,11 +1331,18 @@ void ProjectList::sort_projects() { bool visible = true; if (_search_term != "") { - if (_filter_option == ProjectListFilter::FILTER_PATH) { - visible = item.path.findn(_search_term) != -1; - } else if (_filter_option == ProjectListFilter::FILTER_NAME) { - visible = item.project_name.findn(_search_term) != -1; + + String search_path; + if (_search_term.find("/") != -1) { + // Search path will match the whole path + search_path = item.path; + } else { + // Search path will only match the last path component to make searching more strict + search_path = item.path.get_file(); } + + // When searching, display projects whose name or path contain the search term + visible = item.project_name.findn(_search_term) != -1 || search_path.findn(_search_term) != -1; } item.control->set_visible(visible); @@ -1694,7 +1704,6 @@ void ProjectList::_bind_methods() { ClassDB::bind_method("_panel_input", &ProjectList::_panel_input); ClassDB::bind_method("_favorite_pressed", &ProjectList::_favorite_pressed); ClassDB::bind_method("_show_project", &ProjectList::_show_project); - //ClassDB::bind_method("_unhandled_input", &ProjectList::_unhandled_input); ADD_SIGNAL(MethodInfo(SIGNAL_SELECTION_CHANGED)); ADD_SIGNAL(MethodInfo(SIGNAL_PROJECT_ASK_OPEN)); @@ -1740,10 +1749,18 @@ void ProjectManager::_update_project_buttons() { Vector<ProjectList::Item> selected_projects = _project_list->get_selected_projects(); bool empty_selection = selected_projects.empty(); + bool is_missing_project_selected = false; + for (int i = 0; i < selected_projects.size(); ++i) { + if (selected_projects[i].missing) { + is_missing_project_selected = true; + break; + } + } + erase_btn->set_disabled(empty_selection); - open_btn->set_disabled(empty_selection); - rename_btn->set_disabled(empty_selection); - run_btn->set_disabled(empty_selection); + open_btn->set_disabled(empty_selection || is_missing_project_selected); + rename_btn->set_disabled(empty_selection || is_missing_project_selected); + run_btn->set_disabled(empty_selection || is_missing_project_selected); erase_missing_btn->set_visible(_project_list->is_any_project_missing()); } @@ -1754,8 +1771,19 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { if (k.is_valid()) { - if (!k->is_pressed()) + if (!k->is_pressed()) { return; + } + + // Pressing Command + Q quits the Project Manager + // This is handled by the platform implementation on macOS, + // so only define the shortcut on other platforms +#ifndef OSX_ENABLED + if (k->get_scancode_with_modifiers() == (KEY_MASK_CMD | KEY_Q)) { + _dim_window(); + get_tree()->quit(); + } +#endif if (tabs->get_current_tab() != 0) return; @@ -1834,7 +1862,6 @@ void ProjectManager::_unhandled_input(const Ref<InputEvent> &p_ev) { void ProjectManager::_load_recent_projects() { - _project_list->set_filter_option(project_filter->get_filter_option()); _project_list->set_order_option(project_order_filter->get_filter_option()); _project_list->set_search_term(project_filter->get_search_term()); _project_list->load_projects(); @@ -1921,6 +1948,9 @@ void ProjectManager::_open_selected_projects_ask() { } ProjectList::Item project = _project_list->get_selected_projects()[0]; + if (project.missing) { + return; + } // Update the project settings or don't open String conf = project.path.plus_file("project.godot"); @@ -2075,10 +2105,12 @@ void ProjectManager::_rename_project() { void ProjectManager::_erase_project_confirm() { _project_list->erase_selected_projects(); + _update_project_buttons(); } void ProjectManager::_erase_missing_projects_confirm() { _project_list->erase_missing_projects(); + _update_project_buttons(); } void ProjectManager::_erase_project() { @@ -2101,7 +2133,7 @@ void ProjectManager::_erase_project() { void ProjectManager::_erase_missing_projects() { - erase_missing_ask->set_text(TTR("Remove all missing projects from the list? (Folders contents will not be modified)")); + erase_missing_ask->set_text(TTR("Remove all missing projects from the list?\nThe project folders' contents won't be modified.")); erase_missing_ask->popup_centered_minsize(); } @@ -2196,7 +2228,6 @@ void ProjectManager::_on_order_option_changed() { } void ProjectManager::_on_filter_option_changed() { - _project_list->set_filter_option(project_filter->get_filter_option()); _project_list->set_search_term(project_filter->get_search_term()); _project_list->sort_projects(); } @@ -2268,6 +2299,9 @@ ProjectManager::ProjectManager() { } break; } + // Define a minimum window size to prevent UI elements from overlapping or being cut off + OS::get_singleton()->set_min_window_size(Size2(750, 420) * EDSCALE); + #ifndef OSX_ENABLED // The macOS platform implementation uses its own hiDPI window resizing code // TODO: Resize windows on hiDPI displays on Windows and Linux and remove the line below @@ -2293,26 +2327,11 @@ ProjectManager::ProjectManager() { VBoxContainer *vb = memnew(VBoxContainer); panel->add_child(vb); vb->set_anchors_and_margins_preset(Control::PRESET_WIDE, Control::PRESET_MODE_MINSIZE, 8 * EDSCALE); - vb->add_constant_override("separation", 8 * EDSCALE); String cp; cp += 0xA9; OS::get_singleton()->set_window_title(VERSION_NAME + String(" - ") + TTR("Project Manager") + " - " + cp + " 2007-2019 Juan Linietsky, Ariel Manzur & Godot Contributors"); - HBoxContainer *top_hb = memnew(HBoxContainer); - vb->add_child(top_hb); - Label *l = memnew(Label); - l->set_text(VERSION_NAME + String(" - ") + TTR("Project Manager")); - top_hb->add_child(l); - top_hb->add_spacer(); - l = memnew(Label); - String hash = String(VERSION_HASH); - if (hash.length() != 0) - hash = "." + hash.left(9); - l->set_text("v" VERSION_FULL_BUILD "" + hash); - l->set_align(Label::ALIGN_CENTER); - top_hb->add_child(l); - Control *center_box = memnew(Control); center_box->set_v_size_flags(SIZE_EXPAND_FILL); vb->add_child(center_box); @@ -2320,11 +2339,12 @@ ProjectManager::ProjectManager() { tabs = memnew(TabContainer); center_box->add_child(tabs); tabs->set_anchors_and_margins_preset(Control::PRESET_WIDE); + tabs->set_tab_align(TabContainer::ALIGN_LEFT); HBoxContainer *tree_hb = memnew(HBoxContainer); projects_hb = tree_hb; - projects_hb->set_name(TTR("Project List")); + projects_hb->set_name(TTR("Projects")); tabs->add_child(tree_hb); @@ -2341,6 +2361,7 @@ ProjectManager::ProjectManager() { sort_filter_titles.push_back("Path"); sort_filter_titles.push_back("Last Modified"); project_order_filter = memnew(ProjectListFilter); + project_order_filter->add_filter_option(); project_order_filter->_setup_filters(sort_filter_titles); project_order_filter->set_filter_size(150); sort_filters->add_child(project_order_filter); @@ -2351,21 +2372,12 @@ ProjectManager::ProjectManager() { project_order_filter->set_filter_option((ProjectListFilter::FilterOption)projects_sorting_order); sort_filters->add_spacer(true); - Label *search_label = memnew(Label); - search_label->set_text(TTR("Search:")); - sort_filters->add_child(search_label); - - HBoxContainer *search_filters = memnew(HBoxContainer); - Vector<String> vec2; - vec2.push_back("Name"); - vec2.push_back("Path"); + project_filter = memnew(ProjectListFilter); - project_filter->_setup_filters(vec2); project_filter->add_search_box(); - search_filters->add_child(project_filter); project_filter->connect("filter_changed", this, "_on_filter_option_changed"); project_filter->set_custom_minimum_size(Size2(280, 10) * EDSCALE); - sort_filters->add_child(search_filters); + sort_filters->add_child(project_filter); search_tree_vb->add_child(sort_filters); @@ -2455,6 +2467,17 @@ ProjectManager::ProjectManager() { settings_hb->set_alignment(BoxContainer::ALIGN_END); settings_hb->set_h_grow_direction(Control::GROW_DIRECTION_BEGIN); + Label *version_label = memnew(Label); + String hash = String(VERSION_HASH); + if (hash.length() != 0) { + hash = "." + hash.left(9); + } + version_label->set_text("v" VERSION_FULL_BUILD "" + hash); + // Fade out the version label to be less prominent, but still readable + version_label->set_self_modulate(Color(1, 1, 1, 0.6)); + version_label->set_align(Label::ALIGN_CENTER); + settings_hb->add_child(version_label); + language_btn = memnew(OptionButton); language_btn->set_flat(true); language_btn->set_focus_mode(Control::FOCUS_NONE); @@ -2487,27 +2510,6 @@ ProjectManager::ProjectManager() { center_box->add_child(settings_hb); settings_hb->set_anchors_and_margins_preset(Control::PRESET_TOP_RIGHT); - CenterContainer *cc = memnew(CenterContainer); - Button *cancel = memnew(Button); - cancel->set_text(TTR("Exit")); - cancel->set_custom_minimum_size(Size2(100, 1) * EDSCALE); - -#ifndef OSX_ENABLED - // Pressing Command + Q quits the Project Manager - // This is handled by the platform implementation on macOS, - // so only define the shortcut on other platforms - InputEventKey *quit_key = memnew(InputEventKey); - quit_key->set_command(true); - quit_key->set_scancode(KEY_Q); - ShortCut *quit_shortcut = memnew(ShortCut); - quit_shortcut->set_shortcut(quit_key); - cancel->set_shortcut(quit_shortcut); -#endif - - cc->add_child(cancel); - cancel->connect("pressed", this, "_exit_dialog"); - vb->add_child(cc); - ////////////////////////////////////////////////////////////// language_restart_ask = memnew(ConfirmationDialog); @@ -2628,11 +2630,20 @@ void ProjectListFilter::_bind_methods() { ADD_SIGNAL(MethodInfo("filter_changed")); } +void ProjectListFilter::add_filter_option() { + filter_option = memnew(OptionButton); + filter_option->set_clip_text(true); + filter_option->connect("item_selected", this, "_filter_option_selected"); + add_child(filter_option); +} + void ProjectListFilter::add_search_box() { search_box = memnew(LineEdit); + search_box->set_placeholder(TTR("Search")); search_box->connect("text_changed", this, "_search_text_changed"); search_box->set_h_size_flags(SIZE_EXPAND_FILL); add_child(search_box); + has_search_box = true; } @@ -2643,13 +2654,6 @@ void ProjectListFilter::set_filter_size(int h_size) { ProjectListFilter::ProjectListFilter() { _current_filter = FILTER_NAME; - - filter_option = memnew(OptionButton); - set_filter_size(80); - filter_option->set_clip_text(true); - filter_option->connect("item_selected", this, "_filter_option_selected"); - add_child(filter_option); - has_search_box = false; } diff --git a/editor/project_manager.h b/editor/project_manager.h index 4ccb99d6bd..2a5fd02892 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -152,6 +152,7 @@ protected: public: void _setup_filters(Vector<String> options); + void add_filter_option(); void add_search_box(); void set_filter_size(int h_size); String get_search_term(); diff --git a/editor/property_editor.h b/editor/property_editor.h index a8ef1d6fc1..029c2211d5 100644 --- a/editor/property_editor.h +++ b/editor/property_editor.h @@ -46,10 +46,6 @@ #include "scene/gui/texture_rect.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class PropertyValueEvaluator; class CreateDialog; class PropertySelector; diff --git a/editor/pvrtc_compress.cpp b/editor/pvrtc_compress.cpp index 84cd6da3d9..7cdd900d25 100644 --- a/editor/pvrtc_compress.cpp +++ b/editor/pvrtc_compress.cpp @@ -32,6 +32,7 @@ #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" +#include "core/os/dir_access.h" #include "core/os/file_access.h" #include "core/os/os.h" #include "editor_settings.h" @@ -52,57 +53,75 @@ static void _compress_image(Image::CompressMode p_mode, Image *p_image) { _base_image_compress_pvrtc2_func(p_image); else if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); - break; case Image::COMPRESS_PVRTC4: if (_base_image_compress_pvrtc4_func) _base_image_compress_pvrtc4_func(p_image); - break; - default: ERR_FAIL(); + default: + ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module."); } return; } - String tmppath = EditorSettings::get_singleton()->get_cache_dir(); - - List<String> args; + String tmppath = EditorSettings::get_singleton()->get_cache_dir(); String src_img = tmppath.plus_file("_tmp_src_img.png"); String dst_img = tmppath.plus_file("_tmp_dst_img.pvr"); + List<String> args; args.push_back("-i"); args.push_back(src_img); args.push_back("-o"); args.push_back(dst_img); args.push_back("-f"); - switch (p_mode) { - case Image::COMPRESS_PVRTC2: args.push_back("PVRTC2"); break; - case Image::COMPRESS_PVRTC4: args.push_back("PVRTC4"); break; - case Image::COMPRESS_ETC: args.push_back("ETC"); break; - default: ERR_FAIL(); + switch (p_mode) { + case Image::COMPRESS_PVRTC2: + args.push_back("PVRTC2"); + break; + case Image::COMPRESS_PVRTC4: + args.push_back("PVRTC4"); + break; + case Image::COMPRESS_ETC: + args.push_back("ETC"); + break; + default: + ERR_FAIL_MSG("Unsupported Image compress mode used in PVRTC module."); } if (EditorSettings::get_singleton()->get("filesystem/import/pvrtc_fast_conversion").operator bool()) { args.push_back("-pvrtcfast"); } - if (p_image->has_mipmaps()) + if (p_image->has_mipmaps()) { args.push_back("-m"); + } + // Save source PNG. Ref<ImageTexture> t = memnew(ImageTexture); t->create_from_image(Ref<Image>(p_image), 0); ResourceSaver::save(src_img, t); Error err = OS::get_singleton()->execute(ttpath, args, true); - ERR_EXPLAIN(TTR("Could not execute PVRTC tool:") + " " + ttpath); - ERR_FAIL_COND(err != OK); + if (err != OK) { + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); + ERR_FAIL_MSG("Could not execute PVRTC tool: " + ttpath); + } t = ResourceLoader::load(dst_img, "Texture"); - - ERR_EXPLAIN(TTR("Can't load back converted image using PVRTC tool:") + " " + dst_img); - ERR_FAIL_COND(t.is_null()); + if (t.is_null()) { + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); + ERR_FAIL_MSG("Can't load back converted image using PVRTC tool."); + } p_image->copy_internals_from(t->get_data()); + + // Clean up generated files. + DirAccess::remove_file_or_error(src_img); + DirAccess::remove_file_or_error(dst_img); } static void _compress_pvrtc2(Image *p_image) { diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index dc2f098333..4e1c900ee4 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -256,16 +256,16 @@ void EditorQuickOpen::_confirmed() { void EditorQuickOpen::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { - disconnect("confirmed", this, "_confirmed"); } break; } @@ -289,7 +289,6 @@ EditorQuickOpen::EditorQuickOpen() { VBoxContainer *vbc = memnew(VBoxContainer); add_child(vbc); - //set_child_rect(vbc); search_box = memnew(LineEdit); vbc->add_margin_child(TTR("Search:"), search_box); search_box->connect("text_changed", this, "_text_changed"); @@ -302,6 +301,7 @@ EditorQuickOpen::EditorQuickOpen() { set_hide_on_ok(false); search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); + search_options->set_hide_folding(true); search_options->add_constant_override("draw_guides", 1); ei = "EditorIcons"; ot = "Object"; diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index aeee829de2..f0114b393d 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -399,6 +399,9 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } Node *selected = scene_tree->get_selected(); + if (!selected && !editor_selection->get_selected_node_list().empty()) + selected = editor_selection->get_selected_node_list().front()->get(); + if (selected) create_dialog->popup_create(false, true, selected->get_class()); @@ -983,9 +986,10 @@ void SceneTreeDock::_tool_selected(int p_tool, bool p_confirm_override) { } else { new_node = Object::cast_to<Node>(ClassDB::instance(selected_favorite_root)); } + if (!new_node) { - ERR_EXPLAIN("Creating root from favorite '" + selected_favorite_root + "' failed. Creating 'Node' instead."); new_node = memnew(Node); + ERR_PRINTS("Creating root from favorite '" + selected_favorite_root + "' failed. Creating 'Node' instead."); } } else { switch (p_tool) { @@ -1534,10 +1538,7 @@ void SceneTreeDock::_do_reparent(Node *p_new_parent, int p_position_in_parent, V Node *validate = new_parent; while (validate) { - if (p_nodes.find(validate) != -1) { - ERR_EXPLAIN("Selection changed at some point.. can't reparent"); - ERR_FAIL(); - } + ERR_FAIL_COND_MSG(p_nodes.find(validate) != -1, "Selection changed at some point.. can't reparent."); validate = validate->get_parent(); } //ok all valid @@ -1983,6 +1984,10 @@ void SceneTreeDock::_create() { } else if (current_option == TOOL_REPLACE) { List<Node *> selection = editor_selection->get_selected_node_list(); ERR_FAIL_COND(selection.size() <= 0); + + UndoRedo *ur = EditorNode::get_singleton()->get_undo_redo(); + ur->create_action(TTR("Change type of node(s)")); + for (List<Node *>::Element *E = selection.front(); E; E = E->next()) { Node *n = E->get(); ERR_FAIL_COND(!n); @@ -1993,8 +1998,13 @@ void SceneTreeDock::_create() { Node *newnode = Object::cast_to<Node>(c); ERR_FAIL_COND(!newnode); - replace_node(n, newnode); + ur->add_do_method(this, "replace_node", n, newnode, true, false); + ur->add_do_reference(newnode); + ur->add_undo_method(this, "replace_node", newnode, n, false, false); + ur->add_undo_reference(n); } + + ur->commit_action(); } else if (current_option == TOOL_REPARENT_TO_NEW_NODE) { List<Node *> selection = editor_selection->get_selected_node_list(); ERR_FAIL_COND(selection.size() <= 0); @@ -2241,8 +2251,7 @@ void SceneTreeDock::_normalize_drop(Node *&to_node, int &to_pos, int p_type) { //drop at above selected node if (to_node == EditorNode::get_singleton()->get_edited_scene()) { to_node = NULL; - ERR_EXPLAIN("Cannot perform drop above the root node!"); - ERR_FAIL(); + ERR_FAIL_MSG("Cannot perform drop above the root node!"); } to_pos = to_node->get_index(); @@ -2700,6 +2709,7 @@ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_feature_profile_changed"), &SceneTreeDock::_feature_profile_changed); ClassDB::bind_method(D_METHOD("instance"), &SceneTreeDock::instance); + ClassDB::bind_method(D_METHOD("get_tree_editor"), &SceneTreeDock::get_tree_editor); ClassDB::bind_method(D_METHOD("replace_node"), &SceneTreeDock::replace_node); ADD_SIGNAL(MethodInfo("remote_tree_selected")); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 2d9accc3d8..43f540e688 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -270,15 +270,30 @@ bool SceneTreeEditor::_add_nodes(Node *p_node, TreeItem *p_parent) { item->add_button(0, get_icon("NodeWarning", "EditorIcons"), BUTTON_WARNING, false, TTR("Node configuration warning:") + "\n" + p_node->get_configuration_warning()); } - bool has_connections = p_node->has_persistent_signal_connections(); - bool has_groups = p_node->has_persistent_groups(); - - if (has_connections && has_groups) { - item->add_button(0, get_icon("SignalsAndGroups", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connection(s) and group(s).\nClick to show signals dock.")); - } else if (has_connections) { - item->add_button(0, get_icon("Signals", "EditorIcons"), BUTTON_SIGNALS, false, TTR("Node has connections.\nClick to show signals dock.")); - } else if (has_groups) { - item->add_button(0, get_icon("Groups", "EditorIcons"), BUTTON_GROUPS, false, TTR("Node is in group(s).\nClick to show groups dock.")); + int num_connections = p_node->get_persistent_signal_connection_count(); + int num_groups = p_node->get_persistent_group_count(); + + if (num_connections >= 1 && num_groups >= 1) { + item->add_button( + 0, + get_icon("SignalsAndGroups", "EditorIcons"), + BUTTON_SIGNALS, + false, + vformat(TTR("Node has %s connection(s) and %s group(s).\nClick to show signals dock."), num_connections, num_groups)); + } else if (num_connections >= 1) { + item->add_button( + 0, + get_icon("Signals", "EditorIcons"), + BUTTON_SIGNALS, + false, + vformat(TTR("Node has %s connection(s).\nClick to show signals dock."), num_connections)); + } else if (num_groups >= 1) { + item->add_button( + 0, + get_icon("Groups", "EditorIcons"), + BUTTON_GROUPS, + false, + vformat(TTR("Node is in %s group(s).\nClick to show groups dock."), num_groups)); } } @@ -995,6 +1010,17 @@ bool SceneTreeEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_d return true; } + if (String(d["type"]) == "script_list_element") { + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(d["script_list_element"]); + if (se) { + String sp = se->get_edited_resource()->get_path(); + if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) { + tree->set_drop_mode_flags(Tree::DROP_MODE_ON_ITEM); + return true; + } + } + } + return String(d["type"]) == "nodes"; } void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { @@ -1032,6 +1058,16 @@ void SceneTreeEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, emit_signal("files_dropped", files, np, section); } } + + if (String(d["type"]) == "script_list_element") { + ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(d["script_list_element"]); + if (se) { + String sp = se->get_edited_resource()->get_path(); + if (_is_script_type(EditorFileSystem::get_singleton()->get_file_type(sp))) { + emit_signal("script_dropped", sp, np); + } + } + } } void SceneTreeEditor::_rmb_select(const Vector2 &p_pos) { diff --git a/editor/scene_tree_editor.h b/editor/scene_tree_editor.h index 61cb59ce6f..b216be3b59 100644 --- a/editor/scene_tree_editor.h +++ b/editor/scene_tree_editor.h @@ -37,9 +37,7 @@ #include "scene/gui/button.h" #include "scene/gui/dialogs.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ + class SceneTreeEditor : public Control { GDCLASS(SceneTreeEditor, Control); diff --git a/editor/script_create_dialog.cpp b/editor/script_create_dialog.cpp index ed9a24311d..ffb3f5feab 100644 --- a/editor/script_create_dialog.cpp +++ b/editor/script_create_dialog.cpp @@ -34,6 +34,7 @@ #include "core/os/file_access.h" #include "core/project_settings.h" #include "core/script_language.h" +#include "core/string_builder.h" #include "editor/create_dialog.h" #include "editor/editor_node.h" #include "editor/editor_scale.h" @@ -44,6 +45,23 @@ void ScriptCreateDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: case NOTIFICATION_ENTER_TREE: { + for (int i = 0; i < ScriptServer::get_language_count(); i++) { + String lang = ScriptServer::get_language(i)->get_name(); + Ref<Texture> lang_icon = get_icon(lang, "EditorIcons"); + if (lang_icon.is_valid()) { + language_menu->set_item_icon(i, lang_icon); + } + } + String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", ""); + Ref<Texture> last_lang_icon; + if (!last_lang.empty()) { + last_lang_icon = get_icon(last_lang, "EditorIcons"); + } else { + last_lang_icon = language_menu->get_item_icon(default_language); + } + if (last_lang_icon.is_valid()) { + language_menu->set_icon(last_lang_icon); + } path_button->set_icon(get_icon("Folder", "EditorIcons")); parent_browse_button->set_icon(get_icon("Folder", "EditorIcons")); parent_search_button->set_icon(get_icon("ClassList", "EditorIcons")); @@ -221,16 +239,22 @@ void ScriptCreateDialog::_parent_name_changed(const String &p_parent) { void ScriptCreateDialog::_template_changed(int p_template) { - String selected_template = p_template == 0 ? "" : template_menu->get_item_text(template_menu->get_selected()); + String selected_template = p_template == 0 ? "" : template_menu->get_item_text(p_template); EditorSettings::get_singleton()->set_project_metadata("script_setup", "last_selected_template", selected_template); if (p_template == 0) { //default script_template = ""; return; } - 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_script_templates_dir().plus_file(name); + int selected_id = template_menu->get_selected_id(); + + for (int i = 0; i < template_list.size(); i++) { + const ScriptTemplateInfo &sinfo = template_list[i]; + if (sinfo.id == selected_id) { + script_template = sinfo.dir.plus_file(sinfo.name + "." + sinfo.extension); + break; + } + } } void ScriptCreateDialog::ok_pressed() { @@ -351,23 +375,77 @@ void ScriptCreateDialog::_lang_changed(int l) { bool use_templates = language->is_using_templates(); template_menu->set_disabled(!use_templates); template_menu->clear(); - if (use_templates) { - template_list = EditorSettings::get_singleton()->get_script_templates(language->get_extension()); + if (use_templates) { + _update_script_templates(language->get_extension()); String last_lang = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_language", ""); String last_template = EditorSettings::get_singleton()->get_project_metadata("script_setup", "last_selected_template", ""); template_menu->add_item(TTR("Default")); + + ScriptTemplateInfo *templates = template_list.ptrw(); + + Vector<String> origin_names; + origin_names.push_back(TTR("Project")); + origin_names.push_back(TTR("Editor")); + int cur_origin = -1; + + // Populate script template items previously sorted and now grouped by origin for (int i = 0; i < template_list.size(); i++) { - String s = template_list[i].capitalize(); - template_menu->add_item(s); - if (language_menu->get_item_text(language_menu->get_selected()) == last_lang && last_template == s) { - template_menu->select(i + 1); + + if (int(templates[i].origin) != cur_origin) { + template_menu->add_separator(); + + String origin_name = origin_names[templates[i].origin]; + + int last_index = template_menu->get_item_count() - 1; + template_menu->set_item_text(last_index, origin_name); + + cur_origin = templates[i].origin; } + String item_name = templates[i].name.capitalize(); + template_menu->add_item(item_name); + + int new_id = template_menu->get_item_count() - 1; + templates[i].id = new_id; } - } else { + // Disable overridden + for (Map<String, Vector<int> >::Element *E = template_overrides.front(); E; E = E->next()) { + const Vector<int> &overrides = E->get(); + + if (overrides.size() == 1) { + continue; // doesn't override anything + } + const ScriptTemplateInfo &extended = template_list[overrides[0]]; + + StringBuilder override_info; + override_info += TTR("Overrides"); + override_info += ": "; + for (int i = 1; i < overrides.size(); i++) { + const ScriptTemplateInfo &overridden = template_list[overrides[i]]; + + int disable_index = template_menu->get_item_index(overridden.id); + template_menu->set_item_disabled(disable_index, true); + + override_info += origin_names[overridden.origin]; + if (i < overrides.size() - 1) { + override_info += ", "; + } + } + template_menu->set_item_icon(extended.id, get_icon("Override", "EditorIcons")); + template_menu->get_popup()->set_item_tooltip(extended.id, override_info.as_string()); + } + // Reselect last selected template + for (int i = 0; i < template_menu->get_item_count(); i++) { + const String &ti = template_menu->get_item_text(i); + if (language_menu->get_item_text(language_menu->get_selected()) == last_lang && last_template == ti) { + template_menu->select(i); + break; + } + } + } else { template_menu->add_item(TTR("N/A")); script_template = ""; } @@ -379,6 +457,41 @@ void ScriptCreateDialog::_lang_changed(int l) { _update_dialog(); } +void ScriptCreateDialog::_update_script_templates(const String &p_extension) { + + template_list.clear(); + template_overrides.clear(); + + Vector<String> dirs; + + // Ordered from local to global for correct override mechanism + dirs.push_back(EditorSettings::get_singleton()->get_project_script_templates_dir()); + dirs.push_back(EditorSettings::get_singleton()->get_script_templates_dir()); + + for (int i = 0; i < dirs.size(); i++) { + + Vector<String> list = EditorSettings::get_singleton()->get_script_templates(p_extension, dirs[i]); + + for (int j = 0; j < list.size(); j++) { + ScriptTemplateInfo sinfo; + sinfo.origin = ScriptOrigin(i); + sinfo.dir = dirs[i]; + sinfo.name = list[j]; + sinfo.extension = p_extension; + template_list.push_back(sinfo); + + if (!template_overrides.has(sinfo.name)) { + Vector<int> overrides; + overrides.push_back(template_list.size() - 1); // first one + template_overrides.insert(sinfo.name, overrides); + } else { + Vector<int> &overrides = template_overrides[sinfo.name]; + overrides.push_back(template_list.size() - 1); + } + } + } +} + void ScriptCreateDialog::_built_in_pressed() { if (internal->is_pressed()) { @@ -671,13 +784,13 @@ ScriptCreateDialog::ScriptCreateDialog() { gc->add_child(l); gc->add_child(language_menu); - int default_lang = 0; + default_language = 0; for (int i = 0; i < ScriptServer::get_language_count(); i++) { String lang = ScriptServer::get_language(i)->get_name(); language_menu->add_item(lang); if (lang == "GDScript") { - default_lang = i; + default_language = i; } } @@ -691,8 +804,8 @@ ScriptCreateDialog::ScriptCreateDialog() { } } } else { - language_menu->select(default_lang); - current_language = default_lang; + language_menu->select(default_language); + current_language = default_language; } language_menu->connect("item_selected", this, "_lang_changed"); diff --git a/editor/script_create_dialog.h b/editor/script_create_dialog.h index 288b8f604b..31cf2478cf 100644 --- a/editor/script_create_dialog.h +++ b/editor/script_create_dialog.h @@ -76,9 +76,27 @@ class ScriptCreateDialog : public ConfirmationDialog { bool is_built_in; bool built_in_enabled; int current_language; + int default_language; bool re_check_path; + + enum ScriptOrigin { + SCRIPT_ORIGIN_PROJECT, + SCRIPT_ORIGIN_EDITOR, + }; + struct ScriptTemplateInfo { + int id; + ScriptOrigin origin; + String dir; + String name; + String extension; + }; + String script_template; - Vector<String> template_list; + Vector<ScriptTemplateInfo> template_list; + Map<String, Vector<int> > template_overrides; // name : indices + + void _update_script_templates(const String &p_extension); + String base_type; void _path_hbox_sorted(); diff --git a/editor/script_editor_debugger.cpp b/editor/script_editor_debugger.cpp index f7ff754a0b..fc5aecdbe9 100644 --- a/editor/script_editor_debugger.cpp +++ b/editor/script_editor_debugger.cpp @@ -1376,7 +1376,7 @@ void ScriptEditorDebugger::stop() { profiler->set_enabled(true); inspect_scene_tree->clear(); - inspector->edit(NULL); + EditorNode::get_singleton()->edit_current(); EditorNode::get_singleton()->get_pause_button()->set_pressed(false); EditorNode::get_singleton()->get_pause_button()->set_disabled(true); EditorNode::get_singleton()->get_scene_tree_dock()->hide_remote_tree(); diff --git a/editor/spatial_editor_gizmos.cpp b/editor/spatial_editor_gizmos.cpp index cbfd0f3742..4c5371769f 100644 --- a/editor/spatial_editor_gizmos.cpp +++ b/editor/spatial_editor_gizmos.cpp @@ -36,6 +36,7 @@ #include "scene/3d/baked_lightmap.h" #include "scene/3d/collision_polygon.h" #include "scene/3d/collision_shape.h" +#include "scene/3d/cpu_particles.h" #include "scene/3d/gi_probe.h" #include "scene/3d/light.h" #include "scene/3d/listener.h" @@ -2036,8 +2037,11 @@ PortalSpatialGizmo::PortalSpatialGizmo(Portal *p_portal) { RayCastSpatialGizmoPlugin::RayCastSpatialGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); + const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); create_material("shape_material", gizmo_color); + const float gizmo_value = gizmo_color.get_v(); + const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65); + create_material("shape_material_disabled", gizmo_color_disabled); } bool RayCastSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) { @@ -2063,7 +2067,8 @@ void RayCastSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { lines.push_back(Vector3()); lines.push_back(raycast->get_cast_to()); - Ref<SpatialMaterial> material = get_material("shape_material", p_gizmo); + const Ref<SpatialMaterial> material = + get_material(raycast->is_enabled() ? "shape_material" : "shape_material_disabled", p_gizmo); p_gizmo->add_lines(lines, material); p_gizmo->add_collision_segments(lines); @@ -2415,6 +2420,33 @@ void VisibilityNotifierGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { //// +CPUParticlesGizmoPlugin::CPUParticlesGizmoPlugin() { + create_icon_material("particles_icon", SpatialEditor::get_singleton()->get_icon("GizmoCPUParticles", "EditorIcons")); +} + +bool CPUParticlesGizmoPlugin::has_gizmo(Spatial *p_spatial) { + return Object::cast_to<CPUParticles>(p_spatial) != NULL; +} + +String CPUParticlesGizmoPlugin::get_name() const { + return "CPUParticles"; +} + +int CPUParticlesGizmoPlugin::get_priority() const { + return -1; +} + +bool CPUParticlesGizmoPlugin::is_selectable_when_hidden() const { + return true; +} + +void CPUParticlesGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { + Ref<Material> icon = get_material("particles_icon", p_gizmo); + p_gizmo->add_unscaled_billboard(icon, 0.05); +} + +//// + ParticlesGizmoPlugin::ParticlesGizmoPlugin() { Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/particles", Color(0.8, 0.7, 0.4)); create_material("particles_material", gizmo_color); @@ -3080,8 +3112,11 @@ void BakedIndirectLightGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { //// CollisionShapeSpatialGizmoPlugin::CollisionShapeSpatialGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); + const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); create_material("shape_material", gizmo_color); + const float gizmo_value = gizmo_color.get_v(); + const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65); + create_material("shape_material_disabled", gizmo_color_disabled); create_handle_material("handles"); } @@ -3404,7 +3439,8 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { if (s.is_null()) return; - Ref<Material> material = get_material("shape_material", p_gizmo); + const Ref<Material> material = + get_material(!cs->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo); Ref<Material> handles_material = get_material("handles"); if (Object::cast_to<SphereShape>(*s)) { @@ -3705,8 +3741,11 @@ void CollisionShapeSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { ///// CollisionPolygonSpatialGizmoPlugin::CollisionPolygonSpatialGizmoPlugin() { - Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); + const Color gizmo_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/shape", Color(0.5, 0.7, 1)); create_material("shape_material", gizmo_color); + const float gizmo_value = gizmo_color.get_v(); + const Color gizmo_color_disabled = Color(gizmo_value, gizmo_value, gizmo_value, 0.65); + create_material("shape_material_disabled", gizmo_color_disabled); } bool CollisionPolygonSpatialGizmoPlugin::has_gizmo(Spatial *p_spatial) { @@ -3742,7 +3781,8 @@ void CollisionPolygonSpatialGizmoPlugin::redraw(EditorSpatialGizmo *p_gizmo) { lines.push_back(Vector3(points[i].x, points[i].y, -depth)); } - Ref<Material> material = get_material("shape_material", p_gizmo); + const Ref<Material> material = + get_material(!polygon->is_disabled() ? "shape_material" : "shape_material_disabled", p_gizmo); p_gizmo->add_lines(lines, material); p_gizmo->add_collision_segments(lines); diff --git a/editor/spatial_editor_gizmos.h b/editor/spatial_editor_gizmos.h index 3661df4bad..317ea0c570 100644 --- a/editor/spatial_editor_gizmos.h +++ b/editor/spatial_editor_gizmos.h @@ -249,6 +249,18 @@ public: VisibilityNotifierGizmoPlugin(); }; +class CPUParticlesGizmoPlugin : public EditorSpatialGizmoPlugin { + GDCLASS(CPUParticlesGizmoPlugin, EditorSpatialGizmoPlugin); + +public: + bool has_gizmo(Spatial *p_spatial); + String get_name() const; + int get_priority() const; + bool is_selectable_when_hidden() const; + void redraw(EditorSpatialGizmo *p_gizmo); + CPUParticlesGizmoPlugin(); +}; + class ParticlesGizmoPlugin : public EditorSpatialGizmoPlugin { GDCLASS(ParticlesGizmoPlugin, EditorSpatialGizmoPlugin); |