diff options
Diffstat (limited to 'editor')
163 files changed, 6099 insertions, 2244 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index 6ef36f16f5..fca69f34f3 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -178,7 +178,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { } if (lines.size() >= 2) { - draw_multiline(lines, p_color); + draw_multiline(lines, p_color, Math::round(EDSCALE)); } } } @@ -212,11 +212,13 @@ void AnimationBezierTrackEdit::_draw_line_clipped(const Vector2 &p_from, const V from = from.lerp(to, c); } - draw_line(from, to, p_color); + draw_line(from, to, p_color, Math::round(EDSCALE)); } void AnimationBezierTrackEdit::_notification(int p_what) { if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_ENTER_TREE) { + close_button->set_icon(get_theme_icon(SNAME("Close"), SNAME("EditorIcons"))); + bezier_icon = get_theme_icon(SNAME("KeyBezierPoint"), SNAME("EditorIcons")); bezier_handle_icon = get_theme_icon(SNAME("KeyBezierHandle"), SNAME("EditorIcons")); selected_icon = get_theme_icon(SNAME("KeyBezierSelected"), SNAME("EditorIcons")); @@ -231,8 +233,8 @@ void AnimationBezierTrackEdit::_notification(int p_what) { int hsep = get_theme_constant(SNAME("hseparation"), SNAME("ItemList")); int vsep = get_theme_constant(SNAME("vseparation"), SNAME("ItemList")); - handle_mode_option->set_position(Vector2(right_limit + hsep, get_size().height - handle_mode_option->get_combined_minimum_size().height - vsep)); - handle_mode_option->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, handle_mode_option->get_combined_minimum_size().height)); + right_column->set_position(Vector2(right_limit + hsep, vsep)); + right_column->set_size(Vector2(timeline->get_buttons_width() - hsep * 2, get_size().y - vsep * 2)); } if (p_what == NOTIFICATION_DRAW) { if (animation.is_null()) { @@ -244,7 +246,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { if (has_focus()) { Color accent = get_theme_color(SNAME("accent_color"), SNAME("Editor")); accent.a *= 0.7; - draw_rect(Rect2(Point2(), get_size()), accent, false); + draw_rect(Rect2(Point2(), get_size()), accent, false, Math::round(EDSCALE)); } Ref<Font> font = get_theme_font(SNAME("font"), SNAME("Label")); @@ -255,17 +257,11 @@ void AnimationBezierTrackEdit::_notification(int p_what) { Color linecolor = color; linecolor.a = 0.2; - draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor); + draw_line(Point2(limit, 0), Point2(limit, get_size().height), linecolor, Math::round(EDSCALE)); int right_limit = get_size().width - timeline->get_buttons_width(); - draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor); - - Ref<Texture2D> close_icon = get_theme_icon(SNAME("Close"), SNAME("EditorIcons")); - - close_icon_rect.position = Vector2(get_size().width - close_icon->get_width() - hsep, hsep); - close_icon_rect.size = close_icon->get_size(); - draw_texture(close_icon, close_icon_rect.position); + draw_line(Point2(right_limit, 0), Point2(right_limit, get_size().height), linecolor, Math::round(EDSCALE)); String base_path = animation->track_get_path(track); int end = base_path.find(":"); @@ -387,7 +383,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { if (!first && iv != prev_iv) { Color lc = linecolor; lc.a *= 0.5; - draw_line(Point2(limit, i), Point2(right_limit, i), lc); + draw_line(Point2(limit, i), Point2(right_limit, i), lc, Math::round(EDSCALE)); Color c = color; c.a *= 0.5; draw_string(font, Point2(limit + 8, i - 2), TS->format_number(rtos(Math::snapped((iv + 1) * scale, step))), HALIGN_LEFT, -1, font_size, c); @@ -461,7 +457,7 @@ void AnimationBezierTrackEdit::_notification(int p_what) { ep.point_rect.size = bezier_icon->get_size(); if (selection.has(i)) { draw_texture(selected_icon, ep.point_rect.position); - draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 4), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent); + draw_string(font, ep.point_rect.position + Vector2(8, -font->get_height(font_size) - 8), TTR("Time:") + " " + TS->format_number(rtos(Math::snapped(offset, 0.001))), HALIGN_LEFT, -1, font_size, accent); draw_string(font, ep.point_rect.position + Vector2(8, -8), TTR("Value:") + " " + TS->format_number(rtos(Math::snapped(value, 0.001))), HALIGN_LEFT, -1, font_size, accent); } else { draw_texture(bezier_icon, ep.point_rect.position); @@ -485,8 +481,6 @@ void AnimationBezierTrackEdit::_notification(int p_what) { } if (box_selecting) { - Color bs = accent; - bs.a *= 0.5; Vector2 bs_from = box_selection_from; Vector2 bs_to = box_selection_to; if (bs_from.x > bs_to.x) { @@ -495,7 +489,14 @@ void AnimationBezierTrackEdit::_notification(int p_what) { if (bs_from.y > bs_to.y) { SWAP(bs_from.y, bs_to.y); } - draw_rect(Rect2(bs_from, bs_to - bs_from), bs); + draw_rect( + Rect2(bs_from, bs_to - bs_from), + get_theme_color("box_selection_fill_color", "Editor")); + draw_rect( + Rect2(bs_from, bs_to - bs_from), + get_theme_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } } } @@ -601,7 +602,7 @@ void AnimationBezierTrackEdit::_select_at_anim(const Ref<Animation> &p_anim, int update(); } -void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { +void AnimationBezierTrackEdit::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (p_event->is_pressed()) { @@ -618,9 +619,9 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_DOWN) { - float v_zoom_orig = v_zoom; + const float v_zoom_orig = v_zoom; if (mb->is_command_pressed()) { - timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05); + timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05); } else { if (v_zoom < 100000) { v_zoom *= 1.2; @@ -631,9 +632,9 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { } if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP) { - float v_zoom_orig = v_zoom; + const float v_zoom_orig = v_zoom; if (mb->is_command_pressed()) { - timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() / 1.05); + timeline->get_zoom()->set_value(timeline->get_zoom()->get_value() * 1.05); } else { if (v_zoom > 0.000001) { v_zoom /= 1.2; @@ -974,7 +975,7 @@ void AnimationBezierTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { if (moving_handle != 0 && mm.is_valid()) { float y = (get_size().height / 2 - mm->get_position().y) * v_zoom + v_scroll; - float x = ((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value(); + float x = editor->snap_time((mm->get_position().x - timeline->get_name_limit()) / timeline->get_zoom_scale()) + timeline->get_value(); Vector2 key_pos = Vector2(animation->track_get_key_time(track, moving_handle_key), animation->bezier_track_get_key_value(track, moving_handle_key)); @@ -1121,13 +1122,7 @@ void AnimationBezierTrackEdit::delete_selection() { } } -void AnimationBezierTrackEdit::set_block_animation_update_ptr(bool *p_block_ptr) { - block_animation_update_ptr = p_block_ptr; -} - void AnimationBezierTrackEdit::_bind_methods() { - ClassDB::bind_method("_gui_input", &AnimationBezierTrackEdit::_gui_input); - ClassDB::bind_method("_clear_selection", &AnimationBezierTrackEdit::_clear_selection); ClassDB::bind_method("_clear_selection_for_anim", &AnimationBezierTrackEdit::_clear_selection_for_anim); ClassDB::bind_method("_select_at_anim", &AnimationBezierTrackEdit::_select_at_anim); @@ -1147,21 +1142,6 @@ void AnimationBezierTrackEdit::_bind_methods() { } AnimationBezierTrackEdit::AnimationBezierTrackEdit() { - undo_redo = nullptr; - timeline = nullptr; - root = nullptr; - menu = nullptr; - block_animation_update_ptr = nullptr; - - moving_selection_attempt = false; - moving_selection = false; - select_single_attempt = -1; - box_selecting = false; - box_selecting_attempt = false; - - moving_handle = 0; - - play_position_pos = 0; play_position = memnew(Control); play_position->set_mouse_filter(MOUSE_FILTER_PASS); add_child(play_position); @@ -1169,18 +1149,21 @@ AnimationBezierTrackEdit::AnimationBezierTrackEdit() { play_position->connect("draw", callable_mp(this, &AnimationBezierTrackEdit::_play_position_draw)); set_focus_mode(FOCUS_CLICK); - v_scroll = 0; - v_zoom = 1; - - panning_timeline = false; set_clip_contents(true); handle_mode = HANDLE_MODE_FREE; handle_mode_option = memnew(OptionButton); - add_child(handle_mode_option); + + close_button = memnew(Button); + close_button->connect("pressed", Callable(this, SNAME("emit_signal")), varray(SNAME("close_request"))); + close_button->set_text(TTR("Close")); + + right_column = memnew(VBoxContainer); + right_column->add_child(close_button); + right_column->add_spacer(); + right_column->add_child(handle_mode_option); + add_child(right_column); menu = memnew(PopupMenu); add_child(menu); menu->connect("id_pressed", callable_mp(this, &AnimationBezierTrackEdit::_menu_selected)); - - //set_mouse_filter(MOUSE_FILTER_PASS); //scroll has to work too for selection } diff --git a/editor/animation_bezier_editor.h b/editor/animation_bezier_editor.h index b082cae3ea..578c6f9337 100644 --- a/editor/animation_bezier_editor.h +++ b/editor/animation_bezier_editor.h @@ -51,11 +51,14 @@ class AnimationBezierTrackEdit : public Control { HandleMode handle_mode; OptionButton *handle_mode_option; - AnimationTimelineEdit *timeline; - UndoRedo *undo_redo; - Node *root; + VBoxContainer *right_column; + Button *close_button; + + AnimationTimelineEdit *timeline = nullptr; + UndoRedo *undo_redo = nullptr; + Node *root = nullptr; Control *play_position; //separate control used to draw so updates for only position changed are much faster - float play_position_pos; + float play_position_pos = 0; Ref<Animation> animation; int track; @@ -70,37 +73,35 @@ class AnimationBezierTrackEdit : public Control { Map<int, Rect2> subtracks; - float v_scroll; - float v_zoom; + float v_scroll = 0; + float v_zoom = 1; - PopupMenu *menu; + PopupMenu *menu = nullptr; void _zoom_changed(); - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void _menu_selected(int p_index); - bool *block_animation_update_ptr; //used to block all tracks re-gen (speed up) - void _play_position_draw(); Vector2 insert_at_pos; - bool moving_selection_attempt; - int select_single_attempt; - bool moving_selection; + bool moving_selection_attempt = false; + int select_single_attempt = -1; + bool moving_selection = false; int moving_selection_from_key; Vector2 moving_selection_offset; - bool box_selecting_attempt; - bool box_selecting; - bool box_selecting_add; + bool box_selecting_attempt = false; + bool box_selecting = false; + bool box_selecting_add = false; Vector2 box_selection_from; Vector2 box_selection_to; - int moving_handle; //0 no move -1 or +1 out - int moving_handle_key; + int moving_handle = 0; //0 no move -1 or +1 out + int moving_handle_key = 0; Vector2 moving_handle_left; Vector2 moving_handle_right; @@ -129,7 +130,7 @@ class AnimationBezierTrackEdit : public Control { Set<int> selection; - bool panning_timeline; + bool panning_timeline = false; float panning_timeline_from; float panning_timeline_at; @@ -155,8 +156,6 @@ public: void set_editor(AnimationTrackEditor *p_editor); void set_root(Node *p_root); - void set_block_animation_update_ptr(bool *p_block_ptr); - void set_play_position(float p_pos); void update_play_position(); diff --git a/editor/animation_track_editor.cpp b/editor/animation_track_editor.cpp index 964c37906f..324237ff82 100644 --- a/editor/animation_track_editor.cpp +++ b/editor/animation_track_editor.cpp @@ -1642,7 +1642,7 @@ void AnimationTimelineEdit::_play_position_draw() { } } -void AnimationTimelineEdit::_gui_input(const Ref<InputEvent> &p_event) { +void AnimationTimelineEdit::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); const Ref<InputEventMouseButton> mb = p_event; @@ -1754,8 +1754,6 @@ void AnimationTimelineEdit::_track_added(int p_track) { } void AnimationTimelineEdit::_bind_methods() { - ClassDB::bind_method("_gui_input", &AnimationTimelineEdit::_gui_input); - ADD_SIGNAL(MethodInfo("zoom_changed")); ADD_SIGNAL(MethodInfo("name_limit_changed")); ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag"))); @@ -2551,7 +2549,7 @@ String AnimationTrackEdit::get_tooltip(const Point2 &p_pos) const { return Control::get_tooltip(p_pos); } -void AnimationTrackEdit::_gui_input(const Ref<InputEvent> &p_event) { +void AnimationTrackEdit::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (p_event->is_pressed()) { @@ -2965,8 +2963,6 @@ void AnimationTrackEdit::append_to_selection(const Rect2 &p_box, bool p_deselect } void AnimationTrackEdit::_bind_methods() { - ClassDB::bind_method("_gui_input", &AnimationTrackEdit::_gui_input); - ADD_SIGNAL(MethodInfo("timeline_changed", PropertyInfo(Variant::FLOAT, "position"), PropertyInfo(Variant::BOOL, "drag"))); ADD_SIGNAL(MethodInfo("remove_request", PropertyInfo(Variant::INT, "track"))); ADD_SIGNAL(MethodInfo("dropped", PropertyInfo(Variant::INT, "from_track"), PropertyInfo(Variant::INT, "to_track"))); @@ -5642,6 +5638,11 @@ float AnimationTrackEditor::snap_time(float p_value, bool p_relative) { snap_increment = step->get_value(); } + if (Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { + // Use more precise snapping when holding Shift. + snap_increment *= 0.25; + } + if (p_relative) { double rel = Math::fmod(timeline->get_value(), snap_increment); p_value = Math::snapped(p_value + rel, snap_increment) - rel; @@ -5756,7 +5757,7 @@ void AnimationTrackEditor::_pick_track_filter_input(const Ref<InputEvent> &p_ie) case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - pick_track->get_scene_tree()->get_scene_tree()->call("_gui_input", k); + pick_track->get_scene_tree()->get_scene_tree()->gui_input(k); pick_track->get_filter_line_edit()->accept_event(); } break; default: diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index 6d977e5a3f..4da708dd1c 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -89,7 +89,7 @@ class AnimationTimelineEdit : public Range { float dragging_hsize_from; float dragging_hsize_at; - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void _track_added(int p_track); protected: @@ -195,7 +195,7 @@ protected: static void _bind_methods(); void _notification(int p_what); - virtual void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; public: virtual Variant get_drag_data(const Point2 &p_point) override; diff --git a/editor/animation_track_editor_plugins.cpp b/editor/animation_track_editor_plugins.cpp index 0caed1e8e3..4ee8b991e4 100644 --- a/editor/animation_track_editor_plugins.cpp +++ b/editor/animation_track_editor_plugins.cpp @@ -1035,7 +1035,7 @@ void AnimationTrackEditTypeAudio::drop_data(const Point2 &p_point, const Variant AnimationTrackEdit::drop_data(p_point, p_data); } -void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) { +void AnimationTrackEditTypeAudio::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseMotion> mm = p_event; @@ -1132,7 +1132,7 @@ void AnimationTrackEditTypeAudio::_gui_input(const Ref<InputEvent> &p_event) { return; } - AnimationTrackEdit::_gui_input(p_event); + AnimationTrackEdit::gui_input(p_event); } //////////////////// diff --git a/editor/animation_track_editor_plugins.h b/editor/animation_track_editor_plugins.h index 66229c3012..a362422c2b 100644 --- a/editor/animation_track_editor_plugins.h +++ b/editor/animation_track_editor_plugins.h @@ -124,7 +124,7 @@ protected: static void _bind_methods(); public: - virtual void _gui_input(const Ref<InputEvent> &p_event) override; + virtual void gui_input(const Ref<InputEvent> &p_event) override; virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override; virtual void drop_data(const Point2 &p_point, const Variant &p_data) override; diff --git a/editor/code_editor.cpp b/editor/code_editor.cpp index 4a3be1d29c..89c2e49814 100644 --- a/editor/code_editor.cpp +++ b/editor/code_editor.cpp @@ -114,7 +114,7 @@ void FindReplaceBar::_notification(int p_what) { } } -void FindReplaceBar::_unhandled_input(const Ref<InputEvent> &p_event) { +void FindReplaceBar::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; @@ -611,7 +611,6 @@ void FindReplaceBar::set_text_edit(CodeTextEditor *p_text_editor) { } void FindReplaceBar::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &FindReplaceBar::_unhandled_input); ClassDB::bind_method("_search_current", &FindReplaceBar::search_current); ADD_SIGNAL(MethodInfo("search")); @@ -712,7 +711,7 @@ FindReplaceBar::FindReplaceBar() { // This function should be used to handle shortcuts that could otherwise // be handled too late if they weren't handled here. -void CodeTextEditor::_input(const Ref<InputEvent> &event) { +void CodeTextEditor::input(const Ref<InputEvent> &event) { ERR_FAIL_COND(event.is_null()); const Ref<InputEventKey> key_event = event; @@ -926,38 +925,55 @@ bool CodeTextEditor::_add_font_size(int p_delta) { } void CodeTextEditor::update_editor_settings() { - completion_font_color = EDITOR_GET("text_editor/highlighting/completion_font_color"); - completion_string_color = EDITOR_GET("text_editor/highlighting/string_color"); - completion_comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); - - text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); - text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); - text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); - text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/indent/size")); - text_editor->set_auto_indent_enabled(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); - text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); - text_editor->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/indent/draw_spaces")); - text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); - text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); - text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/navigation/show_minimap")); - text_editor->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/navigation/minimap_width") * EDSCALE); - text_editor->set_draw_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); - text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/line_numbers_zero_padded")); - text_editor->set_draw_bookmarks_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/show_bookmark_gutter")); - text_editor->set_line_folding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); - text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/code_folding")); - text_editor->set_line_wrapping_mode((TextEdit::LineWrappingMode)EditorSettings::get_singleton()->get("text_editor/appearance/word_wrap").operator int()); - text_editor->set_scroll_past_end_of_file_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/scroll_past_end_of_file")); - text_editor->set_caret_type((TextEdit::CaretType)EditorSettings::get_singleton()->get("text_editor/cursor/type").operator int()); - text_editor->set_caret_blink_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink")); - text_editor->set_caret_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); + // Theme: Highlighting + completion_font_color = EDITOR_GET("text_editor/theme/highlighting/completion_font_color"); + completion_string_color = EDITOR_GET("text_editor/theme/highlighting/string_color"); + completion_comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); + + // Appearance: Caret + text_editor->set_caret_type((TextEdit::CaretType)EditorSettings::get_singleton()->get("text_editor/appearance/caret/type").operator int()); + text_editor->set_caret_blink_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/caret/caret_blink")); + text_editor->set_caret_blink_speed(EditorSettings::get_singleton()->get("text_editor/appearance/caret/caret_blink_speed")); + text_editor->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/appearance/caret/highlight_current_line")); + text_editor->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/appearance/caret/highlight_all_occurrences")); + + // Appearance: Gutters + text_editor->set_draw_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/gutters/show_line_numbers")); + text_editor->set_line_numbers_zero_padded(EditorSettings::get_singleton()->get("text_editor/appearance/gutters/line_numbers_zero_padded")); + text_editor->set_draw_bookmarks_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/gutters/show_bookmark_gutter")); + + // Appearance: Minimap + text_editor->set_draw_minimap(EditorSettings::get_singleton()->get("text_editor/appearance/minimap/show_minimap")); + text_editor->set_minimap_width((int)EditorSettings::get_singleton()->get("text_editor/appearance/minimap/minimap_width") * EDSCALE); + + // Appearance: Lines + text_editor->set_line_folding_enabled(EditorSettings::get_singleton()->get("text_editor/appearance/lines/code_folding")); + text_editor->set_draw_fold_gutter(EditorSettings::get_singleton()->get("text_editor/appearance/lines/code_folding")); + text_editor->set_line_wrapping_mode((TextEdit::LineWrappingMode)EditorSettings::get_singleton()->get("text_editor/appearance/lines/word_wrap").operator int()); + + // Appearance: Whitespace + text_editor->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/appearance/whitespace/draw_tabs")); + text_editor->set_draw_spaces(EditorSettings::get_singleton()->get("text_editor/appearance/whitespace/draw_spaces")); + + // Behavior: Navigation + text_editor->set_scroll_past_end_of_file_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/scroll_past_end_of_file")); + text_editor->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/smooth_scrolling")); + text_editor->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/v_scroll_speed")); + + // Behavior: indent + text_editor->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/behavior/indent/type")); + text_editor->set_indent_size(EditorSettings::get_singleton()->get("text_editor/behavior/indent/size")); + text_editor->set_auto_indent_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/indent/auto_indent")); + + // Completion text_editor->set_auto_brace_completion_enabled(EditorSettings::get_singleton()->get("text_editor/completion/auto_brace_complete")); - if (EditorSettings::get_singleton()->get("text_editor/appearance/show_line_length_guidelines")) { + // Appearance: Guidelines + if (EditorSettings::get_singleton()->get("text_editor/appearance/guidelines/show_line_length_guidelines")) { TypedArray<int> guideline_cols; - guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_hard_column")); - if (EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column") != guideline_cols[0]) { - guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/line_length_guideline_soft_column")); + guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/guidelines/line_length_guideline_hard_column")); + if (EditorSettings::get_singleton()->get("text_editor/appearance/guidelines/line_length_guideline_soft_column") != guideline_cols[0]) { + guideline_cols.append(EditorSettings::get_singleton()->get("text_editor/appearance/guidelines/line_length_guideline_soft_column")); } text_editor->set_line_length_guidelines(guideline_cols); } @@ -1028,7 +1044,7 @@ void CodeTextEditor::insert_final_newline() { } void CodeTextEditor::convert_indent_to_spaces() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + int indent_size = EditorSettings::get_singleton()->get("text_editor/behavior/indent/size"); String indent = ""; for (int i = 0; i < indent_size; i++) { @@ -1072,7 +1088,7 @@ void CodeTextEditor::convert_indent_to_spaces() { } void CodeTextEditor::convert_indent_to_tabs() { - int indent_size = EditorSettings::get_singleton()->get("text_editor/indent/size"); + int indent_size = EditorSettings::get_singleton()->get("text_editor/behavior/indent/size"); indent_size -= 1; int cursor_line = text_editor->get_caret_line(); @@ -1412,13 +1428,13 @@ void CodeTextEditor::toggle_inline_comment(const String &delimiter) { void CodeTextEditor::goto_line(int p_line) { text_editor->deselect(); text_editor->unfold_line(p_line); - text_editor->call_deferred(SNAME("cursor_set_line"), p_line); + text_editor->call_deferred(SNAME("set_caret_line"), p_line); } void CodeTextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { text_editor->unfold_line(p_line); - text_editor->call_deferred(SNAME("cursor_set_line"), p_line); - text_editor->call_deferred(SNAME("cursor_set_column"), p_begin); + text_editor->call_deferred(SNAME("set_caret_line"), p_line); + text_editor->call_deferred(SNAME("set_caret_column"), p_begin); text_editor->select(p_line, p_begin, p_line, p_end); } @@ -1520,40 +1536,12 @@ void CodeTextEditor::goto_error() { } void CodeTextEditor::_update_text_editor_theme() { - text_editor->add_theme_color_override("background_color", EDITOR_GET("text_editor/highlighting/background_color")); - text_editor->add_theme_color_override("completion_background_color", EDITOR_GET("text_editor/highlighting/completion_background_color")); - text_editor->add_theme_color_override("completion_selected_color", EDITOR_GET("text_editor/highlighting/completion_selected_color")); - text_editor->add_theme_color_override("completion_existing_color", EDITOR_GET("text_editor/highlighting/completion_existing_color")); - text_editor->add_theme_color_override("completion_scroll_color", EDITOR_GET("text_editor/highlighting/completion_scroll_color")); - text_editor->add_theme_color_override("completion_font_color", EDITOR_GET("text_editor/highlighting/completion_font_color")); - text_editor->add_theme_color_override("font_color", EDITOR_GET("text_editor/highlighting/text_color")); - text_editor->add_theme_color_override("line_number_color", EDITOR_GET("text_editor/highlighting/line_number_color")); - text_editor->add_theme_color_override("caret_color", EDITOR_GET("text_editor/highlighting/caret_color")); - text_editor->add_theme_color_override("caret_background_color", EDITOR_GET("text_editor/highlighting/caret_background_color")); - text_editor->add_theme_color_override("font_selected_color", EDITOR_GET("text_editor/highlighting/text_selected_color")); - text_editor->add_theme_color_override("selection_color", EDITOR_GET("text_editor/highlighting/selection_color")); - text_editor->add_theme_color_override("brace_mismatch_color", EDITOR_GET("text_editor/highlighting/brace_mismatch_color")); - text_editor->add_theme_color_override("current_line_color", EDITOR_GET("text_editor/highlighting/current_line_color")); - text_editor->add_theme_color_override("line_length_guideline_color", EDITOR_GET("text_editor/highlighting/line_length_guideline_color")); - text_editor->add_theme_color_override("word_highlighted_color", EDITOR_GET("text_editor/highlighting/word_highlighted_color")); - text_editor->add_theme_color_override("bookmark_color", EDITOR_GET("text_editor/highlighting/bookmark_color")); - text_editor->add_theme_color_override("breakpoint_color", EDITOR_GET("text_editor/highlighting/breakpoint_color")); - text_editor->add_theme_color_override("executing_line_color", EDITOR_GET("text_editor/highlighting/executing_line_color")); - text_editor->add_theme_color_override("code_folding_color", EDITOR_GET("text_editor/highlighting/code_folding_color")); - text_editor->add_theme_color_override("search_result_color", EDITOR_GET("text_editor/highlighting/search_result_color")); - text_editor->add_theme_color_override("search_result_border_color", EDITOR_GET("text_editor/highlighting/search_result_border_color")); - text_editor->add_theme_constant_override("line_spacing", EDITOR_DEF("text_editor/theme/line_spacing", 6)); emit_signal(SNAME("load_theme_settings")); - _load_theme_settings(); -} - -void CodeTextEditor::_update_font() { - text_editor->add_theme_font_override("font", get_theme_font(SNAME("source"), SNAME("EditorFonts"))); - text_editor->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("source_size"), SNAME("EditorFonts"))); - error->add_theme_font_override("font", get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); - error->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); - error->add_theme_color_override("font_color", get_theme_color(SNAME("error_color"), SNAME("Editor"))); + error->begin_bulk_theme_override(); + error->add_theme_font_override(SNAME("font"), get_theme_font(SNAME("status_source"), SNAME("EditorFonts"))); + error->add_theme_font_size_override(SNAME("font_size"), get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts"))); + error->add_theme_color_override(SNAME("font_color"), get_theme_color(SNAME("error_color"), SNAME("Editor"))); Ref<Font> status_bar_font = get_theme_font(SNAME("status_source"), SNAME("EditorFonts")); int status_bar_font_size = get_theme_font_size(SNAME("status_source_size"), SNAME("EditorFonts")); @@ -1567,6 +1555,7 @@ void CodeTextEditor::_update_font() { n->add_theme_font_size_override("font_size", status_bar_font_size); } } + error->end_bulk_theme_override(); } void CodeTextEditor::_on_settings_change() { @@ -1582,7 +1571,6 @@ void CodeTextEditor::_apply_settings_change() { settings_changed = false; _update_text_editor_theme(); - _update_font(); font_size = EditorSettings::get_singleton()->get("interface/editor/code_font_size"); @@ -1668,7 +1656,6 @@ void CodeTextEditor::_notification(int p_what) { update_toggle_scripts_button(); } _update_text_editor_theme(); - _update_font(); } break; case NOTIFICATION_ENTER_TREE: { error_button->set_icon(get_theme_icon(SNAME("StatusError"), SNAME("EditorIcons"))); @@ -1765,8 +1752,6 @@ void CodeTextEditor::remove_all_bookmarks() { } void CodeTextEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_input"), &CodeTextEditor::_input); - ADD_SIGNAL(MethodInfo("validate_script")); ADD_SIGNAL(MethodInfo("load_theme_settings")); ADD_SIGNAL(MethodInfo("show_errors_panel")); diff --git a/editor/code_editor.h b/editor/code_editor.h index 4cd4880df0..dfe6561f13 100644 --- a/editor/code_editor.h +++ b/editor/code_editor.h @@ -105,7 +105,7 @@ class FindReplaceBar : public HBoxContainer { protected: void _notification(int p_what); - void _unhandled_input(const Ref<InputEvent> &p_event); + virtual void unhandled_input(const Ref<InputEvent> &p_event) override; bool _search(uint32_t p_flags, int p_from_line, int p_from_col); @@ -168,13 +168,12 @@ class CodeTextEditor : public VBoxContainer { void _apply_settings_change(); void _update_text_editor_theme(); - void _update_font(); void _complete_request(); Ref<Texture2D> _get_completion_icon(const ScriptCodeCompletionOption &p_option); void _font_resize_timeout(); bool _add_font_size(int p_delta); - void _input(const Ref<InputEvent> &event); + virtual void input(const Ref<InputEvent> &event) override; void _text_editor_gui_input(const Ref<InputEvent> &p_event); void _zoom_in(); void _zoom_out(); diff --git a/editor/create_dialog.cpp b/editor/create_dialog.cpp index eeab0fc2f5..f0b27702e7 100644 --- a/editor/create_dialog.cpp +++ b/editor/create_dialog.cpp @@ -356,7 +356,7 @@ void CreateDialog::_sbox_input(const Ref<InputEvent> &p_ie) { case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); + search_options->gui_input(k); search_box->accept_event(); } break; default: diff --git a/editor/debugger/editor_debugger_node.cpp b/editor/debugger/editor_debugger_node.cpp index 64a8a298c7..07c02eb022 100644 --- a/editor/debugger/editor_debugger_node.cpp +++ b/editor/debugger/editor_debugger_node.cpp @@ -658,6 +658,17 @@ void EditorDebuggerNode::live_debug_reparent_node(const NodePath &p_at, const No }); } +void EditorDebuggerNode::set_camera_override(CameraOverride p_override) { + _for_all(tabs, [&](ScriptEditorDebugger *dbg) { + dbg->set_camera_override(p_override); + }); + camera_override = p_override; +} + +EditorDebuggerNode::CameraOverride EditorDebuggerNode::get_camera_override() { + return camera_override; +} + void EditorDebuggerNode::add_debugger_plugin(const Ref<Script> &p_script) { ERR_FAIL_COND_MSG(debugger_plugins.has(p_script), "Debugger plugin already exists."); ERR_FAIL_COND_MSG(p_script.is_null(), "Debugger plugin script is null"); diff --git a/editor/debugger/editor_debugger_node.h b/editor/debugger/editor_debugger_node.h index 0849ecf1c9..39a95326be 100644 --- a/editor/debugger/editor_debugger_node.h +++ b/editor/debugger/editor_debugger_node.h @@ -185,9 +185,8 @@ public: void live_debug_duplicate_node(const NodePath &p_at, const String &p_new_name); void live_debug_reparent_node(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); - // Camera - void set_camera_override(CameraOverride p_override) { camera_override = p_override; } - CameraOverride get_camera_override() { return camera_override; } + void set_camera_override(CameraOverride p_override); + CameraOverride get_camera_override(); Error start(const String &p_protocol = "tcp://"); diff --git a/editor/doc_tools.cpp b/editor/doc_tools.cpp index 56a9d2c258..fee2deddda 100644 --- a/editor/doc_tools.cpp +++ b/editor/doc_tools.cpp @@ -64,35 +64,42 @@ void DocTools::merge_from(const DocTools &p_data) { if (cf.methods[j].name != m.name) { continue; } - if (cf.methods[j].arguments.size() != m.arguments.size()) { - continue; - } - // since polymorphic functions are allowed we need to check the type of - // the arguments so we make sure they are different. - int arg_count = cf.methods[j].arguments.size(); - Vector<bool> arg_used; - arg_used.resize(arg_count); - for (int l = 0; l < arg_count; ++l) { - arg_used.write[l] = false; - } - // also there is no guarantee that argument ordering will match, so we - // have to check one by one so we make sure we have an exact match - for (int k = 0; k < arg_count; ++k) { + + const char *operator_prefix = "operator "; // Operators use a space at the end, making this prefix an invalid identifier (and differentiating from methods). + + if (cf.methods[j].name == c.name || cf.methods[j].name.begins_with(operator_prefix)) { + // Since constructors and operators can repeat, we need to check the type of + // the arguments so we make sure they are different. + + if (cf.methods[j].arguments.size() != m.arguments.size()) { + continue; + } + + int arg_count = cf.methods[j].arguments.size(); + Vector<bool> arg_used; + arg_used.resize(arg_count); for (int l = 0; l < arg_count; ++l) { - if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) { - arg_used.write[l] = true; - break; + arg_used.write[l] = false; + } + // also there is no guarantee that argument ordering will match, so we + // have to check one by one so we make sure we have an exact match + for (int k = 0; k < arg_count; ++k) { + for (int l = 0; l < arg_count; ++l) { + if (cf.methods[j].arguments[k].type == m.arguments[l].type && !arg_used[l]) { + arg_used.write[l] = true; + break; + } } } - } - bool not_the_same = false; - for (int l = 0; l < arg_count; ++l) { - if (!arg_used[l]) { // at least one of the arguments was different - not_the_same = true; + bool not_the_same = false; + for (int l = 0; l < arg_count; ++l) { + if (!arg_used[l]) { // at least one of the arguments was different + not_the_same = true; + } + } + if (not_the_same) { + continue; } - } - if (not_the_same) { - continue; } const DocData::MethodDoc &mf = cf.methods[j]; @@ -245,9 +252,6 @@ void DocTools::generate(bool p_basic_types) { } String cname = name; - if (cname.begins_with("_")) { //proxy class - cname = cname.substr(1, name.length()); - } class_list[cname] = DocData::ClassDoc(); DocData::ClassDoc &c = class_list[cname]; @@ -430,6 +434,18 @@ void DocTools::generate(bool p_basic_types) { } } + Vector<Error> errs = ClassDB::get_method_error_return_values(name, E.name); + if (errs.size()) { + if (errs.find(OK) == -1) { + errs.insert(0, OK); + } + for (int i = 0; i < errs.size(); i++) { + if (method.errors_returned.find(errs[i]) == -1) { + method.errors_returned.push_back(errs[i]); + } + } + } + c.methods.push_back(method); } @@ -740,9 +756,6 @@ void DocTools::generate(bool p_basic_types) { while (String(ClassDB::get_parent_class(pd.type)) != "Object") { pd.type = ClassDB::get_parent_class(pd.type); } - if (pd.type.begins_with("_")) { - pd.type = pd.type.substr(1, pd.type.length()); - } c.properties.push_back(pd); } @@ -873,6 +886,9 @@ static Error _parse_methods(Ref<XMLParser> &parser, Vector<DocData::MethodDoc> & if (parser->has_attribute("enum")) { method.return_enum = parser->get_attribute_value("enum"); } + } else if (name == "returns_error") { + ERR_FAIL_COND_V(!parser->has_attribute("number"), ERR_FILE_CORRUPT); + method.errors_returned.push_back(parser->get_attribute_value("number").to_int()); } else if (name == "argument") { DocData::ArgumentDoc argument; ERR_FAIL_COND_V(!parser->has_attribute("name"), ERR_FILE_CORRUPT); @@ -1221,6 +1237,11 @@ Error DocTools::save_classes(const String &p_default_path, const Map<String, Str } _write_string(f, 3, "<return type=\"" + m.return_type + "\"" + enum_text + " />"); } + if (m.errors_returned.size() > 0) { + for (int j = 0; j < m.errors_returned.size(); j++) { + _write_string(f, 3, "<returns_error number=\"" + itos(m.errors_returned[j]) + "\"/>"); + } + } for (int j = 0; j < m.arguments.size(); j++) { const DocData::ArgumentDoc &a = m.arguments[j]; diff --git a/editor/editor_audio_buses.cpp b/editor/editor_audio_buses.cpp index 5209ee06c6..88087664d7 100644 --- a/editor/editor_audio_buses.cpp +++ b/editor/editor_audio_buses.cpp @@ -530,7 +530,7 @@ void EditorAudioBus::_effect_add(int p_which) { ur->commit_action(); } -void EditorAudioBus::_gui_input(const Ref<InputEvent> &p_event) { +void EditorAudioBus::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseButton> mb = p_event; @@ -744,7 +744,7 @@ void EditorAudioBus::_effect_rmb(const Vector2 &p_pos) { void EditorAudioBus::_bind_methods() { ClassDB::bind_method("update_bus", &EditorAudioBus::update_bus); ClassDB::bind_method("update_send", &EditorAudioBus::update_send); - ClassDB::bind_method("_gui_input", &EditorAudioBus::_gui_input); + ClassDB::bind_method("_get_drag_data_fw", &EditorAudioBus::get_drag_data_fw); ClassDB::bind_method("_can_drop_data_fw", &EditorAudioBus::can_drop_data_fw); ClassDB::bind_method("_drop_data_fw", &EditorAudioBus::drop_data_fw); diff --git a/editor/editor_audio_buses.h b/editor/editor_audio_buses.h index 0fbda8ece9..e1aaa060c6 100644 --- a/editor/editor_audio_buses.h +++ b/editor/editor_audio_buses.h @@ -90,7 +90,7 @@ class EditorAudioBus : public PanelContainer { bool is_master; mutable bool hovering_drop; - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void _effects_gui_input(Ref<InputEvent> p_event); void _bus_popup_pressed(int p_option); diff --git a/editor/editor_command_palette.cpp b/editor/editor_command_palette.cpp index bffd0655a7..25250e231e 100644 --- a/editor/editor_command_palette.cpp +++ b/editor/editor_command_palette.cpp @@ -60,7 +60,6 @@ void EditorCommandPalette::_update_command_search(const String &search_text) { commands.get_key_list(&command_keys); ERR_FAIL_COND(command_keys.is_empty()); - const bool empty_search = search_text.is_empty(); Map<String, TreeItem *> sections; TreeItem *first_section = nullptr; @@ -71,8 +70,12 @@ void EditorCommandPalette::_update_command_search(const String &search_text) { r.key_name = command_keys[i]; r.display_name = commands[r.key_name].name; r.shortcut_text = commands[r.key_name].shortcut; - if (!empty_search && search_text.is_subsequence_ofi(r.display_name)) { - r.score = _score_path(search_text, r.display_name.to_lower()); + + if (search_text.is_subsequence_ofi(r.display_name)) { + if (!search_text.is_empty()) { + r.score = _score_path(search_text, r.display_name.to_lower()); + } + entries.push_back(r); } } @@ -82,60 +85,55 @@ void EditorCommandPalette::_update_command_search(const String &search_text) { TreeItem *root = search_options->get_root(); root->clear_children(); - if (entries.size() > 0) { - if (!empty_search) { - SortArray<CommandEntry, CommandEntryComparator> sorter; - sorter.sort(entries.ptrw(), entries.size()); - } + if (entries.is_empty()) { + get_ok_button()->set_disabled(true); - const int entry_limit = MIN(entries.size(), 300); - for (int i = 0; i < entry_limit; i++) { - String section_name = entries[i].key_name.get_slice("/", 0); - TreeItem *section; + return; + } - if (sections.has(section_name)) { - section = sections[section_name]; - } else { - section = search_options->create_item(root); + if (!search_text.is_empty()) { + SortArray<CommandEntry, CommandEntryComparator> sorter; + sorter.sort(entries.ptrw(), entries.size()); + } - if (!first_section) { - first_section = section; - } + const int entry_limit = MIN(entries.size(), 300); + for (int i = 0; i < entry_limit; i++) { + String section_name = entries[i].key_name.get_slice("/", 0); + TreeItem *section; - String item_name = section_name.capitalize(); - section->set_text(0, item_name); + if (sections.has(section_name)) { + section = sections[section_name]; + } else { + section = search_options->create_item(root); - sections[section_name] = section; - section->set_custom_bg_color(0, search_options->get_theme_color("prop_subsection", "Editor")); - section->set_custom_bg_color(1, search_options->get_theme_color("prop_subsection", "Editor")); + if (!first_section) { + first_section = section; } - TreeItem *ti = search_options->create_item(section); - String shortcut_text = entries[i].shortcut_text == "None" ? "" : entries[i].shortcut_text; - ti->set_text(0, entries[i].display_name); - ti->set_metadata(0, entries[i].key_name); - ti->set_text_align(1, TreeItem::TextAlign::ALIGN_RIGHT); - ti->set_text(1, shortcut_text); - Color c = Color(1, 1, 1, 0.5); - ti->set_custom_color(1, c); - } - - TreeItem *to_select = first_section->get_first_child(); - to_select->select(0); - to_select->set_as_cursor(0); - search_options->scroll_to_item(to_select); + String item_name = section_name.capitalize(); + section->set_text(0, item_name); + section->set_selectable(0, false); + section->set_selectable(1, false); + section->set_custom_bg_color(0, search_options->get_theme_color("prop_subsection", "Editor")); + section->set_custom_bg_color(1, search_options->get_theme_color("prop_subsection", "Editor")); - get_ok_button()->set_disabled(false); - } else { - TreeItem *ti = search_options->create_item(root); - ti->set_text(0, TTR("No Matching Command")); - ti->set_metadata(0, ""); - Color c = Color(0.5, 0.5, 0.5, 0.5); - ti->set_custom_color(0, c); - search_options->deselect_all(); + sections[section_name] = section; + } - get_ok_button()->set_disabled(true); + TreeItem *ti = search_options->create_item(section); + String shortcut_text = entries[i].shortcut_text == "None" ? "" : entries[i].shortcut_text; + ti->set_text(0, entries[i].display_name); + ti->set_metadata(0, entries[i].key_name); + ti->set_text_align(1, TreeItem::TextAlign::ALIGN_RIGHT); + ti->set_text(1, shortcut_text); + Color c = Color(1, 1, 1, 0.5); + ti->set_custom_color(1, c); } + + TreeItem *to_select = first_section->get_first_child(); + to_select->select(0); + to_select->set_as_cursor(0); + search_options->ensure_cursor_is_visible(); } void EditorCommandPalette::_bind_methods() { @@ -151,7 +149,7 @@ void EditorCommandPalette::_sbox_input(const Ref<InputEvent> &p_ie) { case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); + search_options->gui_input(k); } break; default: break; @@ -170,8 +168,11 @@ void EditorCommandPalette::_confirmed() { void EditorCommandPalette::open_popup() { popup_centered_clamped(Size2i(600, 440), 0.8f); + command_search_box->clear(); command_search_box->grab_focus(); + + search_options->scroll_to_item(search_options->get_root()); } void EditorCommandPalette::get_actions_list(List<String> *p_list) const { @@ -179,35 +180,35 @@ void EditorCommandPalette::get_actions_list(List<String> *p_list) const { } void EditorCommandPalette::remove_command(String p_key_name) { - ERR_FAIL_COND_MSG(!commands.has(p_key_name), "The EditorAction '" + String(p_key_name) + "' Doesn't exists. Unable to remove it."); + ERR_FAIL_COND_MSG(!commands.has(p_key_name), "The Command '" + String(p_key_name) + "' doesn't exists. Unable to remove it."); commands.erase(p_key_name); } void EditorCommandPalette::add_command(String p_command_name, String p_key_name, Callable p_action, Vector<Variant> arguments, String p_shortcut_text) { - ERR_FAIL_COND_MSG(commands.has(p_key_name), "The EditorAction '" + String(p_command_name) + "' already exists. Unable to add it."); + ERR_FAIL_COND_MSG(commands.has(p_key_name), "The Command '" + String(p_command_name) + "' already exists. Unable to add it."); const Variant **argptrs = (const Variant **)alloca(sizeof(Variant *) * arguments.size()); for (int i = 0; i < arguments.size(); i++) { argptrs[i] = &arguments[i]; } - Command p_command; - p_command.name = p_command_name; - p_command.callable = p_action.bind(argptrs, arguments.size()); - p_command.shortcut = p_shortcut_text; + Command command; + command.name = p_command_name; + command.callable = p_action.bind(argptrs, arguments.size()); + command.shortcut = p_shortcut_text; - commands[p_key_name] = p_command; + commands[p_key_name] = command; } void EditorCommandPalette::_add_command(String p_command_name, String p_key_name, Callable p_binded_action, String p_shortcut_text) { - ERR_FAIL_COND_MSG(commands.has(p_key_name), "The EditorAction '" + String(p_command_name) + "' already exists. Unable to add it."); + ERR_FAIL_COND_MSG(commands.has(p_key_name), "The Command '" + String(p_command_name) + "' already exists. Unable to add it."); - Command p_command; - p_command.name = p_command_name; - p_command.callable = p_binded_action; - p_command.shortcut = p_shortcut_text; + Command command; + command.name = p_command_name; + command.callable = p_binded_action; + command.shortcut = p_shortcut_text; - commands[p_key_name] = p_command; + commands[p_key_name] = command; } void EditorCommandPalette::execute_command(String &p_command_key) { @@ -216,17 +217,17 @@ void EditorCommandPalette::execute_command(String &p_command_key) { } void EditorCommandPalette::register_shortcuts_as_command() { - const String *p_key = nullptr; - p_key = unregistered_shortcuts.next(p_key); - while (p_key != nullptr) { - String command_name = unregistered_shortcuts[*p_key].first; - Ref<Shortcut> p_shortcut = unregistered_shortcuts[*p_key].second; + const String *key = nullptr; + key = unregistered_shortcuts.next(key); + while (key != nullptr) { + String command_name = unregistered_shortcuts[*key].first; + Ref<Shortcut> shortcut = unregistered_shortcuts[*key].second; Ref<InputEventShortcut> ev; ev.instantiate(); - ev->set_shortcut(p_shortcut); - String shortcut_text = String(p_shortcut->get_as_text()); - add_command(command_name, *p_key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::unhandled_input), varray(ev, false), shortcut_text); - p_key = unregistered_shortcuts.next(p_key); + ev->set_shortcut(shortcut); + String shortcut_text = String(shortcut->get_as_text()); + add_command(command_name, *key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_unhandled_input), varray(ev, false), shortcut_text); + key = unregistered_shortcuts.next(key); } unregistered_shortcuts.clear(); } @@ -237,12 +238,12 @@ Ref<Shortcut> EditorCommandPalette::add_shortcut_command(const String &p_command ev.instantiate(); ev->set_shortcut(p_shortcut); String shortcut_text = String(p_shortcut->get_as_text()); - add_command(p_command, p_key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::unhandled_input), varray(ev, false), shortcut_text); + add_command(p_command, p_key, callable_mp(EditorNode::get_singleton()->get_viewport(), &Viewport::push_unhandled_input), varray(ev, false), shortcut_text); } else { const String key_name = String(p_key); const String command_name = String(p_command); - Pair p_pair = Pair(command_name, p_shortcut); - unregistered_shortcuts[key_name] = p_pair; + Pair pair = Pair(command_name, p_shortcut); + unregistered_shortcuts[key_name] = pair; } return p_shortcut; } @@ -259,17 +260,19 @@ EditorCommandPalette *EditorCommandPalette::get_singleton() { } EditorCommandPalette::EditorCommandPalette() { + set_hide_on_ok(false); + connect("confirmed", callable_mp(this, &EditorCommandPalette::_confirmed)); + VBoxContainer *vbc = memnew(VBoxContainer); vbc->connect("theme_changed", callable_mp(this, &EditorCommandPalette::_theme_changed)); add_child(vbc); command_search_box = memnew(LineEdit); - command_search_box->set_placeholder("search for a command"); - command_search_box->set_placeholder_alpha(0.5); + command_search_box->set_placeholder(TTR("Filter commands")); command_search_box->connect("gui_input", callable_mp(this, &EditorCommandPalette::_sbox_input)); command_search_box->connect("text_changed", callable_mp(this, &EditorCommandPalette::_update_command_search)); - command_search_box->connect("text_submitted", callable_mp(this, &EditorCommandPalette::_confirmed).unbind(1)); command_search_box->set_v_size_flags(Control::SIZE_EXPAND_FILL); + command_search_box->set_clear_button_enabled(true); MarginContainer *margin_container_csb = memnew(MarginContainer); margin_container_csb->add_child(command_search_box); vbc->add_child(margin_container_csb); @@ -277,18 +280,15 @@ EditorCommandPalette::EditorCommandPalette() { search_options = memnew(Tree); search_options->connect("item_activated", callable_mp(this, &EditorCommandPalette::_confirmed)); + search_options->connect("item_selected", callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled), varray(false)); + search_options->connect("nothing_selected", callable_mp((BaseButton *)get_ok_button(), &BaseButton::set_disabled), varray(true)); search_options->create_item(); search_options->set_hide_root(true); - search_options->set_hide_folding(true); - search_options->add_theme_constant_override("draw_guides", 1); search_options->set_columns(2); search_options->set_v_size_flags(Control::SIZE_EXPAND_FILL); search_options->set_h_size_flags(Control::SIZE_EXPAND_FILL); search_options->set_column_custom_minimum_width(0, int(8 * EDSCALE)); - vbc->add_child(search_options, true); - - set_hide_on_ok(false); } Ref<Shortcut> ED_SHORTCUT_AND_COMMAND(const String &p_path, const String &p_name, Key p_keycode, String p_command_name) { @@ -296,7 +296,7 @@ Ref<Shortcut> ED_SHORTCUT_AND_COMMAND(const String &p_path, const String &p_name p_command_name = p_name; } - Ref<Shortcut> p_shortcut = ED_SHORTCUT(p_path, p_name, p_keycode); - EditorCommandPalette::get_singleton()->add_shortcut_command(p_command_name, p_path, p_shortcut); - return p_shortcut; + Ref<Shortcut> shortcut = ED_SHORTCUT(p_path, p_name, p_keycode); + EditorCommandPalette::get_singleton()->add_shortcut_command(p_command_name, p_path, shortcut); + return shortcut; } diff --git a/editor/editor_command_palette.h b/editor/editor_command_palette.h index cfd8b964c8..093f4b797d 100644 --- a/editor/editor_command_palette.h +++ b/editor/editor_command_palette.h @@ -31,9 +31,9 @@ #ifndef EDITOR_COMMAND_PALETTE_H #define EDITOR_COMMAND_PALETTE_H +#include "core/input/shortcut.h" #include "core/os/thread_safe.h" #include "scene/gui/dialogs.h" -#include "scene/gui/shortcut.h" #include "scene/gui/tree.h" class EditorCommandPalette : public ConfirmationDialog { diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index b374f56f6d..1240496028 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -32,6 +32,7 @@ #include "core/config/project_settings.h" #include "core/crypto/crypto_core.h" +#include "core/extension/native_extension.h" #include "core/io/config_file.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" @@ -624,21 +625,15 @@ Vector<String> EditorExportPlugin::get_ios_project_static_libs() const { } void EditorExportPlugin::_export_file_script(const String &p_path, const String &p_type, const Vector<String> &p_features) { - if (get_script_instance()) { - get_script_instance()->call("_export_file", p_path, p_type, p_features); - } + GDVIRTUAL_CALL(_export_file, p_path, p_type, p_features); } void EditorExportPlugin::_export_begin_script(const Vector<String> &p_features, bool p_debug, const String &p_path, int p_flags) { - if (get_script_instance()) { - get_script_instance()->call("_export_begin", p_features, p_debug, p_path, p_flags); - } + GDVIRTUAL_CALL(_export_begin, p_features, p_debug, p_path, p_flags); } void EditorExportPlugin::_export_end_script() { - if (get_script_instance()) { - get_script_instance()->call("_export_end"); - } + GDVIRTUAL_CALL(_export_end); } void EditorExportPlugin::_export_file(const String &p_path, const String &p_type, const Set<String> &p_features) { @@ -663,9 +658,9 @@ void EditorExportPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_ios_cpp_code", "code"), &EditorExportPlugin::add_ios_cpp_code); ClassDB::bind_method(D_METHOD("skip"), &EditorExportPlugin::skip); - BIND_VMETHOD(MethodInfo("_export_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::STRING, "type"), PropertyInfo(Variant::PACKED_STRING_ARRAY, "features"))); - BIND_VMETHOD(MethodInfo("_export_begin", PropertyInfo(Variant::PACKED_STRING_ARRAY, "features"), PropertyInfo(Variant::BOOL, "is_debug"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"))); - BIND_VMETHOD(MethodInfo("_export_end")); + GDVIRTUAL_BIND(_export_file, "path", "type", "features"); + GDVIRTUAL_BIND(_export_begin, "features", "is_debug", "path", "flags"); + GDVIRTUAL_BIND(_export_end); } EditorExportPlugin::EditorExportPlugin() { @@ -1056,6 +1051,14 @@ Error EditorExportPlatform::export_project_files(const Ref<EditorExportPreset> & } } + if (FileAccess::exists(NativeExtension::EXTENSION_LIST_CONFIG_FILE)) { + Vector<uint8_t> array = FileAccess::get_file_as_array(NativeExtension::EXTENSION_LIST_CONFIG_FILE); + err = p_func(p_udata, NativeExtension::EXTENSION_LIST_CONFIG_FILE, array, idx, total, enc_in_filters, enc_ex_filters, key); + if (err != OK) { + return err; + } + } + // Store text server data if it is supported. if (TS->has_feature(TextServer::FEATURE_USE_SUPPORT_DATA)) { bool use_data = ProjectSettings::get_singleton()->get("internationalization/locale/include_text_server_data"); diff --git a/editor/editor_export.h b/editor/editor_export.h index c9401df9c2..b681f52330 100644 --- a/editor/editor_export.h +++ b/editor/editor_export.h @@ -349,6 +349,10 @@ protected: static void _bind_methods(); + GDVIRTUAL3(_export_file, String, String, Vector<String>) + GDVIRTUAL4(_export_begin, Vector<String>, bool, String, uint32_t) + GDVIRTUAL0(_export_end) + public: Vector<String> get_ios_frameworks() const; Vector<String> get_ios_embedded_frameworks() const; diff --git a/editor/editor_file_dialog.cpp b/editor/editor_file_dialog.cpp index 5ccbed1b49..bf95e6cf62 100644 --- a/editor/editor_file_dialog.cpp +++ b/editor/editor_file_dialog.cpp @@ -124,7 +124,7 @@ void EditorFileDialog::_notification(int p_what) { } } -void EditorFileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { +void EditorFileDialog::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; @@ -728,6 +728,7 @@ void EditorFileDialog::update_file_list() { item_list->set_icon_mode(ItemList::ICON_MODE_TOP); item_list->set_fixed_column_width(thumbnail_size * 3 / 2); item_list->set_max_text_lines(2); + item_list->set_text_overrun_behavior(TextParagraph::OVERRUN_TRIM_ELLIPSIS); item_list->set_fixed_icon_size(Size2(thumbnail_size, thumbnail_size)); if (thumbnail_size < 64) { @@ -957,7 +958,7 @@ String EditorFileDialog::get_current_path() const { } void EditorFileDialog::set_current_dir(const String &p_dir) { - if (p_dir.is_rel_path()) { + if (p_dir.is_relative_path()) { dir_access->change_dir(OS::get_singleton()->get_resource_dir()); } dir_access->change_dir(p_dir); @@ -1354,8 +1355,6 @@ EditorFileDialog::DisplayMode EditorFileDialog::get_display_mode() const { } void EditorFileDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorFileDialog::_unhandled_input); - ClassDB::bind_method(D_METHOD("_cancel_pressed"), &EditorFileDialog::_cancel_pressed); ClassDB::bind_method(D_METHOD("clear_filters"), &EditorFileDialog::clear_filters); @@ -1645,6 +1644,7 @@ EditorFileDialog::EditorFileDialog() { item_list->connect("item_rmb_selected", callable_mp(this, &EditorFileDialog::_item_list_item_rmb_selected)); item_list->connect("rmb_clicked", callable_mp(this, &EditorFileDialog::_item_list_rmb_clicked)); item_list->set_allow_rmb_select(true); + list_vb->add_child(item_list); item_menu = memnew(PopupMenu); diff --git a/editor/editor_file_dialog.h b/editor/editor_file_dialog.h index d789956a3e..ed427dc76e 100644 --- a/editor/editor_file_dialog.h +++ b/editor/editor_file_dialog.h @@ -193,7 +193,7 @@ private: void _thumbnail_done(const String &p_path, const Ref<Texture2D> &p_preview, const Ref<Texture2D> &p_small_preview, const Variant &p_udata); void _request_single_thumbnail(const String &p_path); - void _unhandled_input(const Ref<InputEvent> &p_event); + virtual void unhandled_input(const Ref<InputEvent> &p_event) override; bool _is_open_should_be_disabled(); diff --git a/editor/editor_file_system.cpp b/editor/editor_file_system.cpp index 78861eff9d..aa89a14725 100644 --- a/editor/editor_file_system.cpp +++ b/editor/editor_file_system.cpp @@ -31,6 +31,7 @@ #include "editor_file_system.h" #include "core/config/project_settings.h" +#include "core/extension/native_extension_manager.h" #include "core/io/file_access.h" #include "core/io/resource_importer.h" #include "core/io/resource_loader.h" @@ -605,6 +606,18 @@ bool EditorFileSystem::_update_scan_actions() { } } + if (_scan_extensions()) { + //needs editor restart + //extensions also may provide filetypes to be imported, so they must run before importing + if (EditorNode::immediate_confirmation_dialog(TTR("Some extensions need the editor to restart to take effect."), first_scan ? TTR("Restart") : TTR("Save&Restart"), TTR("Continue"))) { + if (!first_scan) { + EditorNode::get_singleton()->save_all_scenes(); + } + EditorNode::get_singleton()->restart_editor(); + //do not import + return true; + } + } if (reimports.size()) { reimport_files(reimports); } else { @@ -2222,6 +2235,76 @@ ResourceUID::ID EditorFileSystem::_resource_saver_get_resource_id_for_path(const } } +static void _scan_extensions_dir(EditorFileSystemDirectory *d, Set<String> &extensions) { + int fc = d->get_file_count(); + for (int i = 0; i < fc; i++) { + if (d->get_file_type(i) == SNAME("NativeExtension")) { + extensions.insert(d->get_file_path(i)); + } + } + int dc = d->get_subdir_count(); + for (int i = 0; i < dc; i++) { + _scan_extensions_dir(d->get_subdir(i), extensions); + } +} +bool EditorFileSystem::_scan_extensions() { + EditorFileSystemDirectory *d = get_filesystem(); + Set<String> extensions; + _scan_extensions_dir(d, extensions); + + //verify against loaded extensions + + Vector<String> extensions_added; + Vector<String> extensions_removed; + + for (const String &E : extensions) { + if (!NativeExtensionManager::get_singleton()->is_extension_loaded(E)) { + extensions_added.push_back(E); + } + } + + Vector<String> loaded_extensions = NativeExtensionManager::get_singleton()->get_loaded_extensions(); + for (int i = 0; i < loaded_extensions.size(); i++) { + if (!extensions.has(loaded_extensions[i])) { + extensions_removed.push_back(loaded_extensions[i]); + } + } + + if (extensions.size()) { + if (extensions_added.size() || extensions_removed.size()) { //extensions were added or removed + FileAccessRef f = FileAccess::open(NativeExtension::EXTENSION_LIST_CONFIG_FILE, FileAccess::WRITE); + for (const String &E : extensions) { + f->store_line(E); + } + } + } else { + if (loaded_extensions.size() || FileAccess::exists(NativeExtension::EXTENSION_LIST_CONFIG_FILE)) { //extensions were removed + DirAccessRef da = DirAccess::create(DirAccess::ACCESS_RESOURCES); + da->remove(NativeExtension::EXTENSION_LIST_CONFIG_FILE); + } + } + + bool needs_restart = false; + for (int i = 0; i < extensions_added.size(); i++) { + NativeExtensionManager::LoadStatus st = NativeExtensionManager::get_singleton()->load_extension(extensions_added[i]); + if (st == NativeExtensionManager::LOAD_STATUS_FAILED) { + EditorNode::get_singleton()->add_io_error("Error loading extension: " + extensions_added[i]); + } else if (st == NativeExtensionManager::LOAD_STATUS_NEEDS_RESTART) { + needs_restart = true; + } + } + for (int i = 0; i < extensions_removed.size(); i++) { + NativeExtensionManager::LoadStatus st = NativeExtensionManager::get_singleton()->unload_extension(extensions_removed[i]); + if (st == NativeExtensionManager::LOAD_STATUS_FAILED) { + EditorNode::get_singleton()->add_io_error("Error removing extension: " + extensions_added[i]); + } else if (st == NativeExtensionManager::LOAD_STATUS_NEEDS_RESTART) { + needs_restart = true; + } + } + + return needs_restart; +} + void EditorFileSystem::_bind_methods() { ClassDB::bind_method(D_METHOD("get_filesystem"), &EditorFileSystem::get_filesystem); ClassDB::bind_method(D_METHOD("is_scanning"), &EditorFileSystem::is_scanning); diff --git a/editor/editor_file_system.h b/editor/editor_file_system.h index 9dce29d09c..b47cf5523a 100644 --- a/editor/editor_file_system.h +++ b/editor/editor_file_system.h @@ -255,6 +255,8 @@ class EditorFileSystem : public Node { static ResourceUID::ID _resource_saver_get_resource_id_for_path(const String &p_path, bool p_generate); + bool _scan_extensions(); + protected: void _notification(int p_what); static void _bind_methods(); diff --git a/editor/editor_fonts.cpp b/editor/editor_fonts.cpp index 1e3db1a7b0..e5d6315ef7 100644 --- a/editor/editor_fonts.cpp +++ b/editor/editor_fonts.cpp @@ -67,46 +67,113 @@ m_name->add_data(FontJapanese); \ m_name->add_data(FontFallback); -// the custom spacings might only work with Noto Sans -#define MAKE_DEFAULT_FONT(m_name) \ - Ref<Font> m_name; \ - m_name.instantiate(); \ - if (CustomFont.is_valid()) { \ - m_name->add_data(CustomFont); \ - m_name->add_data(DefaultFont); \ - } else { \ - m_name->add_data(DefaultFont); \ - } \ - m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_DEFAULT_FONT(m_name, m_variations, m_base_size) \ + Ref<Font> m_name; \ + m_name.instantiate(); \ + if (CustomFont.is_valid()) { \ + m_name->add_data(CustomFont); \ + m_name->add_data(DefaultFont); \ + } else { \ + m_name->add_data(DefaultFont); \ + } \ + { \ + Dictionary variations; \ + if (m_variations != String()) { \ + Vector<String> variation_tags = m_variations.split(","); \ + for (int i = 0; i < variation_tags.size(); i++) { \ + Vector<String> tokens = variation_tags[i].split("="); \ + if (tokens.size() == 2) { \ + variations[tokens[0]] = tokens[1].to_float(); \ + } \ + } \ + } \ + m_name->set_variation_coordinates(variations); \ + } \ + m_name->set_base_size(m_base_size); \ + m_name->set_spacing(TextServer::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS(m_name); -#define MAKE_BOLD_FONT(m_name) \ - Ref<Font> m_name; \ - m_name.instantiate(); \ - if (CustomFontBold.is_valid()) { \ - m_name->add_data(CustomFontBold); \ - m_name->add_data(DefaultFontBold); \ - } else { \ - m_name->add_data(DefaultFontBold); \ - } \ - m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_BOLD_FONT(m_name, m_variations, m_base_size) \ + Ref<Font> m_name; \ + m_name.instantiate(); \ + if (CustomFontBold.is_valid()) { \ + m_name->add_data(CustomFontBold); \ + m_name->add_data(DefaultFontBold); \ + } else { \ + m_name->add_data(DefaultFontBold); \ + } \ + { \ + Dictionary variations; \ + if (m_variations != String()) { \ + Vector<String> variation_tags = m_variations.split(","); \ + for (int i = 0; i < variation_tags.size(); i++) { \ + Vector<String> tokens = variation_tags[i].split("="); \ + if (tokens.size() == 2) { \ + variations[tokens[0]] = tokens[1].to_float(); \ + } \ + } \ + } \ + m_name->set_variation_coordinates(variations); \ + } \ + m_name->set_base_size(m_base_size); \ + m_name->set_spacing(TextServer::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS_BOLD(m_name); -#define MAKE_SOURCE_FONT(m_name) \ - Ref<Font> m_name; \ - m_name.instantiate(); \ - if (CustomFontSource.is_valid()) { \ - m_name->add_data(CustomFontSource); \ - m_name->add_data(dfmono); \ - } else { \ - m_name->add_data(dfmono); \ - } \ - m_name->set_spacing(Font::SPACING_TOP, -EDSCALE); \ - m_name->set_spacing(Font::SPACING_BOTTOM, -EDSCALE); \ +#define MAKE_SOURCE_FONT(m_name, m_variations, m_base_size) \ + Ref<Font> m_name; \ + m_name.instantiate(); \ + if (CustomFontSource.is_valid()) { \ + m_name->add_data(CustomFontSource); \ + m_name->add_data(dfmono); \ + } else { \ + m_name->add_data(dfmono); \ + } \ + { \ + Dictionary variations; \ + if (m_variations != String()) { \ + Vector<String> variation_tags = m_variations.split(","); \ + for (int i = 0; i < variation_tags.size(); i++) { \ + Vector<String> tokens = variation_tags[i].split("="); \ + if (tokens.size() == 2) { \ + variations[tokens[0]] = tokens[1].to_float(); \ + } \ + } \ + } \ + m_name->set_variation_coordinates(variations); \ + } \ + m_name->set_base_size(m_base_size); \ + m_name->set_spacing(TextServer::SPACING_TOP, -EDSCALE); \ + m_name->set_spacing(TextServer::SPACING_BOTTOM, -EDSCALE); \ MAKE_FALLBACKS(m_name); +Ref<FontData> load_cached_external_font(const String &p_path, TextServer::Hinting p_hinting, bool p_aa, bool p_autohint) { + Ref<FontData> font; + font.instantiate(); + + Vector<uint8_t> data = FileAccess::get_file_as_array(p_path); + + font->set_data(data); + font->set_antialiased(p_aa); + font->set_hinting(p_hinting); + font->set_force_autohinter(p_autohint); + + return font; +} + +Ref<FontData> load_cached_internal_font(const uint8_t *p_data, size_t p_size, TextServer::Hinting p_hinting, bool p_aa, bool p_autohint) { + Ref<FontData> font; + font.instantiate(); + + font->set_data_ptr(p_data, p_size); + font->set_antialiased(p_aa); + font->set_hinting(p_hinting); + font->set_force_autohinter(p_autohint); + + return font; +} + void editor_register_fonts(Ref<Theme> p_theme) { DirAccess *dir = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); @@ -144,11 +211,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path = EditorSettings::get_singleton()->get("interface/editor/main_font"); Ref<FontData> CustomFont; if (custom_font_path.length() > 0 && dir->file_exists(custom_font_path)) { - CustomFont.instantiate(); - CustomFont->load_resource(custom_font_path, default_font_size); - CustomFont->set_antialiased(font_antialiased); - CustomFont->set_hinting(font_hinting); - CustomFont->set_force_autohinter(true); //just looks better..i think? + CustomFont = load_cached_external_font(custom_font_path, font_hinting, font_antialiased, true); } else { EditorSettings::get_singleton()->set_manually("interface/editor/main_font", ""); } @@ -158,11 +221,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path_bold = EditorSettings::get_singleton()->get("interface/editor/main_font_bold"); Ref<FontData> CustomFontBold; if (custom_font_path_bold.length() > 0 && dir->file_exists(custom_font_path_bold)) { - CustomFontBold.instantiate(); - CustomFontBold->load_resource(custom_font_path_bold, default_font_size); - CustomFontBold->set_antialiased(font_antialiased); - CustomFontBold->set_hinting(font_hinting); - CustomFontBold->set_force_autohinter(true); //just looks better..i think? + CustomFontBold = load_cached_external_font(custom_font_path_bold, font_hinting, font_antialiased, true); } else { EditorSettings::get_singleton()->set_manually("interface/editor/main_font_bold", ""); } @@ -172,231 +231,51 @@ void editor_register_fonts(Ref<Theme> p_theme) { String custom_font_path_source = EditorSettings::get_singleton()->get("interface/editor/code_font"); Ref<FontData> CustomFontSource; if (custom_font_path_source.length() > 0 && dir->file_exists(custom_font_path_source)) { - CustomFontSource.instantiate(); - CustomFontSource->load_resource(custom_font_path_source, default_font_size); - CustomFontSource->set_antialiased(font_antialiased); - CustomFontSource->set_hinting(font_hinting); - - Vector<String> subtag = String(EditorSettings::get_singleton()->get("interface/editor/code_font_custom_variations")).split(","); - for (int i = 0; i < subtag.size(); i++) { - Vector<String> subtag_a = subtag[i].split("="); - if (subtag_a.size() == 2) { - CustomFontSource->set_variation(subtag_a[0], subtag_a[1].to_float()); - } - } + CustomFontSource = load_cached_external_font(custom_font_path_source, font_hinting, font_antialiased, true); } else { EditorSettings::get_singleton()->set_manually("interface/editor/code_font", ""); } memdelete(dir); - /* Noto Sans UI */ - - Ref<FontData> DefaultFont; - DefaultFont.instantiate(); - DefaultFont->load_memory(_font_NotoSans_Regular, _font_NotoSans_Regular_size, "ttf", default_font_size); - DefaultFont->set_antialiased(font_antialiased); - DefaultFont->set_hinting(font_hinting); - DefaultFont->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> DefaultFontBold; - DefaultFontBold.instantiate(); - DefaultFontBold->load_memory(_font_NotoSans_Bold, _font_NotoSans_Bold_size, "ttf", default_font_size); - DefaultFontBold->set_antialiased(font_antialiased); - DefaultFontBold->set_hinting(font_hinting); - DefaultFontBold->set_force_autohinter(true); // just looks better..i think? - - Ref<FontData> FontArabic; - FontArabic.instantiate(); - FontArabic->load_memory(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, "ttf", default_font_size); - FontArabic->set_antialiased(font_antialiased); - FontArabic->set_hinting(font_hinting); - FontArabic->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontArabicBold; - FontArabicBold.instantiate(); - FontArabicBold->load_memory(_font_NotoNaskhArabicUI_Bold, _font_NotoNaskhArabicUI_Bold_size, "ttf", default_font_size); - FontArabicBold->set_antialiased(font_antialiased); - FontArabicBold->set_hinting(font_hinting); - FontArabicBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontBengali; - FontBengali.instantiate(); - FontBengali->load_memory(_font_NotoSansBengaliUI_Regular, _font_NotoSansBengaliUI_Regular_size, "ttf", default_font_size); - FontBengali->set_antialiased(font_antialiased); - FontBengali->set_hinting(font_hinting); - FontBengali->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontBengaliBold; - FontBengaliBold.instantiate(); - FontBengaliBold->load_memory(_font_NotoSansBengaliUI_Bold, _font_NotoSansBengaliUI_Bold_size, "ttf", default_font_size); - FontBengaliBold->set_antialiased(font_antialiased); - FontBengaliBold->set_hinting(font_hinting); - FontBengaliBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontDevanagari; - FontDevanagari.instantiate(); - FontDevanagari->load_memory(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, "ttf", default_font_size); - FontDevanagari->set_antialiased(font_antialiased); - FontDevanagari->set_hinting(font_hinting); - FontDevanagari->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontDevanagariBold; - FontDevanagariBold.instantiate(); - FontDevanagariBold->load_memory(_font_NotoSansDevanagariUI_Bold, _font_NotoSansDevanagariUI_Bold_size, "ttf", default_font_size); - FontDevanagariBold->set_antialiased(font_antialiased); - FontDevanagariBold->set_hinting(font_hinting); - FontDevanagariBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontGeorgian; - FontGeorgian.instantiate(); - FontGeorgian->load_memory(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, "ttf", default_font_size); - FontGeorgian->set_antialiased(font_antialiased); - FontGeorgian->set_hinting(font_hinting); - FontGeorgian->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontGeorgianBold; - FontGeorgianBold.instantiate(); - FontGeorgianBold->load_memory(_font_NotoSansGeorgian_Bold, _font_NotoSansGeorgian_Bold_size, "ttf", default_font_size); - FontGeorgianBold->set_antialiased(font_antialiased); - FontGeorgianBold->set_hinting(font_hinting); - FontGeorgianBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontHebrew; - FontHebrew.instantiate(); - FontHebrew->load_memory(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, "ttf", default_font_size); - FontHebrew->set_antialiased(font_antialiased); - FontHebrew->set_hinting(font_hinting); - FontHebrew->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontHebrewBold; - FontHebrewBold.instantiate(); - FontHebrewBold->load_memory(_font_NotoSansHebrew_Bold, _font_NotoSansHebrew_Bold_size, "ttf", default_font_size); - FontHebrewBold->set_antialiased(font_antialiased); - FontHebrewBold->set_hinting(font_hinting); - FontHebrewBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontMalayalam; - FontMalayalam.instantiate(); - FontMalayalam->load_memory(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, "ttf", default_font_size); - FontMalayalam->set_antialiased(font_antialiased); - FontMalayalam->set_hinting(font_hinting); - FontMalayalam->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontMalayalamBold; - FontMalayalamBold.instantiate(); - FontMalayalamBold->load_memory(_font_NotoSansMalayalamUI_Bold, _font_NotoSansMalayalamUI_Bold_size, "ttf", default_font_size); - FontMalayalamBold->set_antialiased(font_antialiased); - FontMalayalamBold->set_hinting(font_hinting); - FontMalayalamBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontOriya; - FontOriya.instantiate(); - FontOriya->load_memory(_font_NotoSansOriyaUI_Regular, _font_NotoSansOriyaUI_Regular_size, "ttf", default_font_size); - FontOriya->set_antialiased(font_antialiased); - FontOriya->set_hinting(font_hinting); - FontOriya->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontOriyaBold; - FontOriyaBold.instantiate(); - FontOriyaBold->load_memory(_font_NotoSansOriyaUI_Bold, _font_NotoSansOriyaUI_Bold_size, "ttf", default_font_size); - FontOriyaBold->set_antialiased(font_antialiased); - FontOriyaBold->set_hinting(font_hinting); - FontOriyaBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontSinhala; - FontSinhala.instantiate(); - FontSinhala->load_memory(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, "ttf", default_font_size); - FontSinhala->set_antialiased(font_antialiased); - FontSinhala->set_hinting(font_hinting); - FontSinhala->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontSinhalaBold; - FontSinhalaBold.instantiate(); - FontSinhalaBold->load_memory(_font_NotoSansSinhalaUI_Bold, _font_NotoSansSinhalaUI_Bold_size, "ttf", default_font_size); - FontSinhalaBold->set_antialiased(font_antialiased); - FontSinhalaBold->set_hinting(font_hinting); - FontSinhalaBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontTamil; - FontTamil.instantiate(); - FontTamil->load_memory(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, "ttf", default_font_size); - FontTamil->set_antialiased(font_antialiased); - FontTamil->set_hinting(font_hinting); - FontTamil->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontTamilBold; - FontTamilBold.instantiate(); - FontTamilBold->load_memory(_font_NotoSansTamilUI_Bold, _font_NotoSansTamilUI_Bold_size, "ttf", default_font_size); - FontTamilBold->set_antialiased(font_antialiased); - FontTamilBold->set_hinting(font_hinting); - FontTamilBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontTelugu; - FontTelugu.instantiate(); - FontTelugu->load_memory(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, "ttf", default_font_size); - FontTelugu->set_antialiased(font_antialiased); - FontTelugu->set_hinting(font_hinting); - FontTelugu->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontTeluguBold; - FontTeluguBold.instantiate(); - FontTeluguBold->load_memory(_font_NotoSansTeluguUI_Bold, _font_NotoSansTeluguUI_Bold_size, "ttf", default_font_size); - FontTeluguBold->set_antialiased(font_antialiased); - FontTeluguBold->set_hinting(font_hinting); - FontTeluguBold->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontThai; - FontThai.instantiate(); - FontThai->load_memory(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, "ttf", default_font_size); - FontThai->set_antialiased(font_antialiased); - FontThai->set_hinting(font_hinting); - FontThai->set_force_autohinter(true); //just looks better..i think? - - Ref<FontData> FontThaiBold; - FontThaiBold.instantiate(); - FontThaiBold->load_memory(_font_NotoSansThaiUI_Bold, _font_NotoSansThaiUI_Bold_size, "ttf", default_font_size); - FontThaiBold->set_antialiased(font_antialiased); - FontThaiBold->set_hinting(font_hinting); - FontThaiBold->set_force_autohinter(true); //just looks better..i think? - - /* Droid Sans Fallback */ - - Ref<FontData> FontFallback; - FontFallback.instantiate(); - FontFallback->load_memory(_font_DroidSansFallback, _font_DroidSansFallback_size, "ttf", default_font_size); - FontFallback->set_antialiased(font_antialiased); - FontFallback->set_hinting(font_hinting); - FontFallback->set_force_autohinter(true); //just looks better..i think? - - /* Droid Sans Japanese */ - - Ref<FontData> FontJapanese; - FontJapanese.instantiate(); - FontJapanese->load_memory(_font_DroidSansJapanese, _font_DroidSansJapanese_size, "ttf", default_font_size); - FontJapanese->set_antialiased(font_antialiased); - FontJapanese->set_hinting(font_hinting); - FontJapanese->set_force_autohinter(true); //just looks better..i think? + /* Noto Sans */ + + Ref<FontData> DefaultFont = load_cached_internal_font(_font_NotoSans_Regular, _font_NotoSans_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> DefaultFontBold = load_cached_internal_font(_font_NotoSans_Bold, _font_NotoSans_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontArabic = load_cached_internal_font(_font_NotoNaskhArabicUI_Regular, _font_NotoNaskhArabicUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontArabicBold = load_cached_internal_font(_font_NotoNaskhArabicUI_Bold, _font_NotoNaskhArabicUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontBengali = load_cached_internal_font(_font_NotoSansBengaliUI_Regular, _font_NotoSansBengaliUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontBengaliBold = load_cached_internal_font(_font_NotoSansBengaliUI_Bold, _font_NotoSansBengaliUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontDevanagari = load_cached_internal_font(_font_NotoSansDevanagariUI_Regular, _font_NotoSansDevanagariUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontDevanagariBold = load_cached_internal_font(_font_NotoSansDevanagariUI_Bold, _font_NotoSansDevanagariUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontGeorgian = load_cached_internal_font(_font_NotoSansGeorgian_Regular, _font_NotoSansGeorgian_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontGeorgianBold = load_cached_internal_font(_font_NotoSansGeorgian_Bold, _font_NotoSansGeorgian_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontHebrew = load_cached_internal_font(_font_NotoSansHebrew_Regular, _font_NotoSansHebrew_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontHebrewBold = load_cached_internal_font(_font_NotoSansHebrew_Bold, _font_NotoSansHebrew_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontMalayalam = load_cached_internal_font(_font_NotoSansMalayalamUI_Regular, _font_NotoSansMalayalamUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontMalayalamBold = load_cached_internal_font(_font_NotoSansMalayalamUI_Bold, _font_NotoSansMalayalamUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontOriya = load_cached_internal_font(_font_NotoSansOriyaUI_Regular, _font_NotoSansOriyaUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontOriyaBold = load_cached_internal_font(_font_NotoSansOriyaUI_Bold, _font_NotoSansOriyaUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontSinhala = load_cached_internal_font(_font_NotoSansSinhalaUI_Regular, _font_NotoSansSinhalaUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontSinhalaBold = load_cached_internal_font(_font_NotoSansSinhalaUI_Bold, _font_NotoSansSinhalaUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontTamil = load_cached_internal_font(_font_NotoSansTamilUI_Regular, _font_NotoSansTamilUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontTamilBold = load_cached_internal_font(_font_NotoSansTamilUI_Bold, _font_NotoSansTamilUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontTelugu = load_cached_internal_font(_font_NotoSansTeluguUI_Regular, _font_NotoSansTeluguUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontTeluguBold = load_cached_internal_font(_font_NotoSansTeluguUI_Bold, _font_NotoSansTeluguUI_Bold_size, font_hinting, font_antialiased, true); + Ref<FontData> FontThai = load_cached_internal_font(_font_NotoSansThaiUI_Regular, _font_NotoSansThaiUI_Regular_size, font_hinting, font_antialiased, true); + Ref<FontData> FontThaiBold = load_cached_internal_font(_font_NotoSansThaiUI_Bold, _font_NotoSansThaiUI_Bold_size, font_hinting, font_antialiased, true); + + /* Droid Sans */ + + Ref<FontData> FontFallback = load_cached_internal_font(_font_DroidSansFallback, _font_DroidSansFallback_size, font_hinting, font_antialiased, true); + Ref<FontData> FontJapanese = load_cached_internal_font(_font_DroidSansJapanese, _font_DroidSansJapanese_size, font_hinting, font_antialiased, true); /* Hack */ - Ref<FontData> dfmono; - dfmono.instantiate(); - dfmono->load_memory(_font_Hack_Regular, _font_Hack_Regular_size, "ttf", default_font_size); - dfmono->set_antialiased(font_antialiased); - dfmono->set_hinting(font_hinting); - - Vector<String> subtag = String(EditorSettings::get_singleton()->get("interface/editor/code_font_custom_variations")).split(","); - Dictionary ftrs; - for (int i = 0; i < subtag.size(); i++) { - Vector<String> subtag_a = subtag[i].split("="); - if (subtag_a.size() == 2) { - dfmono->set_variation(subtag_a[0], subtag_a[1].to_float()); - } - } + Ref<FontData> dfmono = load_cached_internal_font(_font_Hack_Regular, _font_Hack_Regular_size, font_hinting, font_antialiased, true); // Default font - MAKE_DEFAULT_FONT(df); + MAKE_DEFAULT_FONT(df, String(), default_font_size); p_theme->set_default_theme_font(df); // Default theme font p_theme->set_default_theme_font_size(default_font_size); @@ -404,7 +283,7 @@ void editor_register_fonts(Ref<Theme> p_theme) { p_theme->set_font("main", "EditorFonts", df); // Bold font - MAKE_BOLD_FONT(df_bold); + MAKE_BOLD_FONT(df_bold, String(), default_font_size); p_theme->set_font_size("bold_size", "EditorFonts", default_font_size); p_theme->set_font("bold", "EditorFonts", df_bold); @@ -430,7 +309,8 @@ void editor_register_fonts(Ref<Theme> p_theme) { p_theme->set_font_size("font_size", "HeaderLarge", default_font_size + 3 * EDSCALE); // Documentation fonts - MAKE_SOURCE_FONT(df_code); + String code_font_custom_variations = EditorSettings::get_singleton()->get("interface/editor/code_font_custom_variations"); + MAKE_SOURCE_FONT(df_code, code_font_custom_variations, default_font_size); p_theme->set_font_size("doc_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); p_theme->set_font("doc", "EditorFonts", df); p_theme->set_font_size("doc_bold_size", "EditorFonts", int(EDITOR_GET("text_editor/help/help_font_size")) * EDSCALE); diff --git a/editor/editor_help.cpp b/editor/editor_help.cpp index f92b9ac8ba..24b6ba1a14 100644 --- a/editor/editor_help.cpp +++ b/editor/editor_help.cpp @@ -30,6 +30,7 @@ #include "editor_help.h" +#include "core/core_constants.h" #include "core/input/input.h" #include "core/os/keyboard.h" #include "doc_data_compressed.gen.h" @@ -170,7 +171,7 @@ void EditorHelp::_add_type(const String &p_type, const String &p_enum) { if (t.is_empty()) { t = "void"; } - bool can_ref = (t != "void") || !p_enum.is_empty(); + bool can_ref = (t != "void" && t.find("*") == -1) || !p_enum.is_empty(); if (!p_enum.is_empty()) { if (p_enum.get_slice_count(".") > 1) { @@ -632,8 +633,8 @@ void EditorHelp::_update_doc() { continue; } } - // Ignore undocumented private. - if (cd.methods[i].name.begins_with("_") && cd.methods[i].description.is_empty()) { + // Ignore undocumented non virtual private. + if (cd.methods[i].name.begins_with("_") && cd.methods[i].description.is_empty() && cd.methods[i].qualifiers.find("virtual") == -1) { continue; } methods.push_back(cd.methods[i]); @@ -695,7 +696,7 @@ void EditorHelp::_update_doc() { class_desc->pop(); //cell } - if (m[i].description != "") { + if (m[i].description != "" || m[i].errors_returned.size() > 0) { method_descr = true; } @@ -1227,6 +1228,31 @@ void EditorHelp::_update_doc() { class_desc->push_color(text_color); class_desc->push_font(doc_font); class_desc->push_indent(1); + if (methods_filtered[i].errors_returned.size()) { + class_desc->append_bbcode(TTR("Error codes returned:")); + class_desc->add_newline(); + class_desc->push_list(0, RichTextLabel::LIST_DOTS, false); + for (int j = 0; j < methods_filtered[i].errors_returned.size(); j++) { + if (j > 0) { + class_desc->add_newline(); + } + int val = methods_filtered[i].errors_returned[j]; + String text = itos(val); + for (int k = 0; k < CoreConstants::get_global_constant_count(); k++) { + if (CoreConstants::get_global_constant_value(k) == val && CoreConstants::get_global_constant_enum(k) == SNAME("Error")) { + text = CoreConstants::get_global_constant_name(k); + break; + } + } + + class_desc->push_bold(); + class_desc->append_bbcode(text); + class_desc->pop(); + } + class_desc->pop(); + class_desc->add_newline(); + class_desc->add_newline(); + } if (!methods_filtered[i].description.strip_edges().is_empty()) { _add_text(DTR(methods_filtered[i].description)); } else { @@ -1825,8 +1851,6 @@ void FindBar::_notification(int p_what) { } void FindBar::_bind_methods() { - ClassDB::bind_method("_unhandled_input", &FindBar::_unhandled_input); - ADD_SIGNAL(MethodInfo("search")); } @@ -1902,7 +1926,7 @@ void FindBar::_hide_bar() { hide(); } -void FindBar::_unhandled_input(const Ref<InputEvent> &p_event) { +void FindBar::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; diff --git a/editor/editor_help.h b/editor/editor_help.h index 69bb72c52d..0b0821a7f4 100644 --- a/editor/editor_help.h +++ b/editor/editor_help.h @@ -70,7 +70,7 @@ class FindBar : public HBoxContainer { protected: void _notification(int p_what); - void _unhandled_input(const Ref<InputEvent> &p_event); + virtual void unhandled_input(const Ref<InputEvent> &p_event) override; bool _search(bool p_search_previous = false); diff --git a/editor/editor_help_search.cpp b/editor/editor_help_search.cpp index 2b5eee4c1f..e56b10720d 100644 --- a/editor/editor_help_search.cpp +++ b/editor/editor_help_search.cpp @@ -71,7 +71,7 @@ void EditorHelpSearch::_search_box_gui_input(const Ref<InputEvent> &p_event) { case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - results_tree->call("_gui_input", key); + results_tree->gui_input(key); search_box->accept_event(); } break; default: diff --git a/editor/editor_inspector.cpp b/editor/editor_inspector.cpp index 679f2e8ce4..fee27dae58 100644 --- a/editor/editor_inspector.cpp +++ b/editor/editor_inspector.cpp @@ -31,11 +31,13 @@ #include "editor_inspector.h" #include "array_property_edit.h" +#include "core/os/keyboard.h" #include "dictionary_property_edit.h" #include "editor/doc_tools.h" #include "editor_feature_profile.h" #include "editor_node.h" #include "editor_scale.h" +#include "editor_settings.h" #include "multi_node_edit.h" #include "scene/resources/packed_scene.h" @@ -379,9 +381,7 @@ StringName EditorProperty::get_edited_property() { } void EditorProperty::update_property() { - if (get_script_instance()) { - get_script_instance()->call("_update_property"); - } + GDVIRTUAL_CALL(_update_property); } void EditorProperty::set_read_only(bool p_read_only) { @@ -694,7 +694,7 @@ bool EditorProperty::is_selected() const { return selected; } -void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { +void EditorProperty::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (property == StringName()) { @@ -766,7 +766,7 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { call_deferred(SNAME("emit_changed"), property, object->get(property).operator int64_t() + 1, "", false); } - call_deferred(SNAME("_update_property")); + call_deferred(SNAME("update_property")); } } if (delete_rect.has_point(mpos)) { @@ -784,6 +784,30 @@ void EditorProperty::_gui_input(const Ref<InputEvent> &p_event) { update(); emit_signal(SNAME("property_checked"), property, checked); } + } else if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_RIGHT) { + _ensure_popup(); + menu->set_position(get_screen_position() + get_local_mouse_position()); + menu->set_size(Vector2(1, 1)); + menu->popup(); + select(); + return; + } +} + +void EditorProperty::unhandled_key_input(const Ref<InputEvent> &p_event) { + if (!selected) { + return; + } + + if (ED_IS_SHORTCUT("property_editor/copy_property", p_event)) { + menu_option(MENU_COPY_PROPERTY); + accept_event(); + } else if (ED_IS_SHORTCUT("property_editor/paste_property", p_event) && !is_read_only()) { + menu_option(MENU_PASTE_PROPERTY); + accept_event(); + } else if (ED_IS_SHORTCUT("property_editor/copy_property_path", p_event)) { + menu_option(MENU_COPY_PROPERTY_PATH); + accept_event(); } } @@ -887,7 +911,7 @@ Control *EditorProperty::make_custom_tooltip(const String &p_text) const { text += "\n" + property_doc; } } - help_bit->set_text(text); + help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene } return help_bit; @@ -897,6 +921,20 @@ String EditorProperty::get_tooltip_text() const { return tooltip_text; } +void EditorProperty::menu_option(int p_option) { + switch (p_option) { + case MENU_COPY_PROPERTY: { + EditorNode::get_singleton()->get_inspector()->set_property_clipboard(object->get(property)); + } break; + case MENU_PASTE_PROPERTY: { + emit_changed(property, EditorNode::get_singleton()->get_inspector()->get_property_clipboard()); + } break; + case MENU_COPY_PROPERTY_PATH: { + DisplayServer::get_singleton()->clipboard_set(property); + } break; + } +} + void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("set_label", "text"), &EditorProperty::set_label); ClassDB::bind_method(D_METHOD("get_label"), &EditorProperty::get_label); @@ -922,9 +960,8 @@ void EditorProperty::_bind_methods() { ClassDB::bind_method(D_METHOD("get_edited_property"), &EditorProperty::get_edited_property); ClassDB::bind_method(D_METHOD("get_edited_object"), &EditorProperty::get_edited_object); - ClassDB::bind_method(D_METHOD("_gui_input"), &EditorProperty::_gui_input); - ClassDB::bind_method(D_METHOD("get_tooltip_text"), &EditorProperty::get_tooltip_text); + ClassDB::bind_method(D_METHOD("update_property"), &EditorProperty::update_property); ClassDB::bind_method(D_METHOD("add_focusable", "control"), &EditorProperty::add_focusable); ClassDB::bind_method(D_METHOD("set_bottom_editor", "editor"), &EditorProperty::set_bottom_editor); @@ -948,7 +985,7 @@ void EditorProperty::_bind_methods() { ADD_SIGNAL(MethodInfo("object_id_selected", PropertyInfo(Variant::STRING_NAME, "property"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("selected", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "focusable_idx"))); - BIND_VMETHOD(MethodInfo("_update_property")); + GDVIRTUAL_BIND(_update_property) } EditorProperty::EditorProperty() { @@ -974,6 +1011,21 @@ EditorProperty::EditorProperty() { label_reference = nullptr; bottom_editor = nullptr; delete_hover = false; + menu = nullptr; + set_process_unhandled_key_input(true); +} + +void EditorProperty::_ensure_popup() { + if (menu) { + return; + } + menu = memnew(PopupMenu); + menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property"), MENU_COPY_PROPERTY); + menu->add_shortcut(ED_GET_SHORTCUT("property_editor/paste_property"), MENU_PASTE_PROPERTY); + menu->add_shortcut(ED_GET_SHORTCUT("property_editor/copy_property_path"), MENU_COPY_PROPERTY_PATH); + menu->connect("id_pressed", callable_mp(this, &EditorProperty::menu_option)); + menu->set_item_disabled(MENU_PASTE_PROPERTY, is_read_only()); + add_child(menu); } //////////////////////////////////////////////// @@ -1003,43 +1055,31 @@ void EditorInspectorPlugin::add_property_editor_for_multiple_properties(const St } bool EditorInspectorPlugin::can_handle(Object *p_object) { - if (get_script_instance()) { - return get_script_instance()->call("_can_handle", p_object); + bool success; + if (GDVIRTUAL_CALL(_can_handle, p_object, success)) { + return success; } return false; } void EditorInspectorPlugin::parse_begin(Object *p_object) { - if (get_script_instance()) { - get_script_instance()->call("_parse_begin", p_object); - } + GDVIRTUAL_CALL(_parse_begin); } void EditorInspectorPlugin::parse_category(Object *p_object, const String &p_parse_category) { - if (get_script_instance()) { - get_script_instance()->call("_parse_category", p_object, p_parse_category); - } + GDVIRTUAL_CALL(_parse_category, p_object, p_parse_category); } bool EditorInspectorPlugin::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { - if (get_script_instance()) { - Variant arg[6] = { - p_object, p_type, p_path, p_hint, p_hint_text, p_usage - }; - const Variant *argptr[6] = { - &arg[0], &arg[1], &arg[2], &arg[3], &arg[4], &arg[5] - }; - - Callable::CallError err; - return get_script_instance()->call("_parse_property", (const Variant **)&argptr, 6, err); + bool ret; + if (GDVIRTUAL_CALL(_parse_property, p_object, p_type, p_path, p_hint, p_hint_text, p_usage, p_wide, ret)) { + return ret; } return false; } void EditorInspectorPlugin::parse_end() { - if (get_script_instance()) { - get_script_instance()->call("_parse_end"); - } + GDVIRTUAL_CALL(_parse_end); } void EditorInspectorPlugin::_bind_methods() { @@ -1047,11 +1087,11 @@ void EditorInspectorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_property_editor", "property", "editor"), &EditorInspectorPlugin::add_property_editor); ClassDB::bind_method(D_METHOD("add_property_editor_for_multiple_properties", "label", "properties", "editor"), &EditorInspectorPlugin::add_property_editor_for_multiple_properties); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_handle", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_begin")); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_category", PropertyInfo(Variant::STRING, "category"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_parse_property", PropertyInfo(Variant::INT, "type"), PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "hint"), PropertyInfo(Variant::STRING, "hint_text"), PropertyInfo(Variant::INT, "usage"))); - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_end")); + GDVIRTUAL_BIND(_can_handle, "object") + GDVIRTUAL_BIND(_parse_begin) + GDVIRTUAL_BIND(_parse_category, "object", "category") + GDVIRTUAL_BIND(_parse_property, "object", "type", "name", "hint_type", "hint_string", "usage_flags", "wide"); + GDVIRTUAL_BIND(_parse_end) } //////////////////////////////////////////////// @@ -1102,7 +1142,7 @@ Control *EditorInspectorCategory::make_custom_tooltip(const String &p_text) cons text += "\n" + property_doc; } } - help_bit->set_text(text); //hack so it uses proper theme once inside scene + help_bit->call_deferred(SNAME("set_text"), text); //hack so it uses proper theme once inside scene } return help_bit; @@ -1332,7 +1372,7 @@ void EditorInspectorSection::setup(const String &p_section, const String &p_labe } } -void EditorInspectorSection::_gui_input(const Ref<InputEvent> &p_event) { +void EditorInspectorSection::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (!foldable) { @@ -1391,7 +1431,6 @@ void EditorInspectorSection::_bind_methods() { ClassDB::bind_method(D_METHOD("get_vbox"), &EditorInspectorSection::get_vbox); ClassDB::bind_method(D_METHOD("unfold"), &EditorInspectorSection::unfold); ClassDB::bind_method(D_METHOD("fold"), &EditorInspectorSection::fold); - ClassDB::bind_method(D_METHOD("_gui_input"), &EditorInspectorSection::_gui_input); } EditorInspectorSection::EditorInspectorSection() { @@ -2243,6 +2282,13 @@ void EditorInspector::_edit_set(const String &p_name, const Variant &p_value, bo undo_redo->add_do_property(object, p_name, p_value); undo_redo->add_undo_property(object, p_name, object->get(p_name)); + PropertyInfo prop_info; + if (ClassDB::get_property_info(object->get_class_name(), p_name, &prop_info)) { + for (const String &linked_prop : prop_info.linked_properties) { + undo_redo->add_undo_property(object, linked_prop, object->get(linked_prop)); + } + } + Variant v_undo_redo = (Object *)undo_redo; Variant v_object = object; Variant v_name = p_name; @@ -2610,13 +2656,15 @@ void EditorInspector::_update_script_class_properties(const Object &p_object, Li } // NodeC -> C props... -> NodeB..C.. - r_list.erase(script_variables); - List<PropertyInfo>::Element *to_delete = bottom->next(); - while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) { - r_list.erase(to_delete); - to_delete = bottom->next(); + if (script_variables) { + r_list.erase(script_variables); + List<PropertyInfo>::Element *to_delete = bottom->next(); + while (to_delete && !(to_delete->get().usage & PROPERTY_USAGE_CATEGORY)) { + r_list.erase(to_delete); + to_delete = bottom->next(); + } + r_list.erase(bottom); } - r_list.erase(bottom); } void EditorInspector::set_restrict_to_basic_settings(bool p_restrict) { @@ -2624,6 +2672,14 @@ void EditorInspector::set_restrict_to_basic_settings(bool p_restrict) { update_tree(); } +void EditorInspector::set_property_clipboard(const Variant &p_value) { + property_clipboard = p_value; +} + +Variant EditorInspector::get_property_clipboard() const { + return property_clipboard; +} + void EditorInspector::_bind_methods() { ClassDB::bind_method("_edit_request_change", &EditorInspector::_edit_request_change); @@ -2666,6 +2722,7 @@ EditorInspector::EditorInspector() { property_focusable = -1; sub_inspector = false; deletable_properties = false; + property_clipboard = Variant(); get_v_scrollbar()->connect("value_changed", callable_mp(this, &EditorInspector::_vscroll_changed)); update_scroll_request = -1; @@ -2675,4 +2732,8 @@ EditorInspector::EditorInspector() { //used when class is created by the docgen to dump default values of everything bindable, editorsettings may not be created refresh_countdown = 0.33; } + + ED_SHORTCUT("property_editor/copy_property", TTR("Copy Property"), KEY_MASK_CMD | KEY_C); + ED_SHORTCUT("property_editor/paste_property", TTR("Paste Property"), KEY_MASK_CMD | KEY_V); + ED_SHORTCUT("property_editor/copy_property_path", TTR("Copy Property Path"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_C); } diff --git a/editor/editor_inspector.h b/editor/editor_inspector.h index 3c9ba9f39d..8c522f00ef 100644 --- a/editor/editor_inspector.h +++ b/editor/editor_inspector.h @@ -51,6 +51,13 @@ public: class EditorProperty : public Container { GDCLASS(EditorProperty, Container); +public: + enum MenuItems { + MENU_COPY_PROPERTY, + MENU_PASTE_PROPERTY, + MENU_COPY_PROPERTY_PATH, + }; + private: String label; int text_size; @@ -84,6 +91,7 @@ private: bool use_folding; bool draw_top_bg; + void _ensure_popup(); bool _is_property_different(const Variant &p_current, const Variant &p_orig); bool _get_instantiated_node_original_property(const StringName &p_prop, Variant &value); void _focusable_focused(int p_index); @@ -97,16 +105,19 @@ private: Vector<Control *> focusables; Control *label_reference; Control *bottom_editor; + PopupMenu *menu; mutable String tooltip_text; Map<StringName, Variant> cache; + GDVIRTUAL0(_update_property) protected: void _notification(int p_what); static void _bind_methods(); - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; + virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; public: void emit_changed(const StringName &p_property, const Variant &p_value, const StringName &p_field = StringName(), bool p_changing = false); @@ -174,6 +185,8 @@ public: bool can_revert_to_default() const { return can_revert; } + void menu_option(int p_option); + EditorProperty(); }; @@ -192,6 +205,12 @@ class EditorInspectorPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1RC(bool, _can_handle, Variant) + GDVIRTUAL0(_parse_begin) + GDVIRTUAL2(_parse_category, Object *, String) + GDVIRTUAL7R(bool, _parse_property, Object *, int, String, int, String, int, bool) + GDVIRTUAL0(_parse_end) + public: void add_custom_control(Control *control); void add_property_editor(const String &p_for_property, Control *p_prop); @@ -245,7 +264,7 @@ class EditorInspectorSection : public Container { protected: void _notification(int p_what); static void _bind_methods(); - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; public: virtual Size2 get_minimum_size() const override; @@ -314,6 +333,7 @@ class EditorInspector : public ScrollContainer { String property_prefix; //used for sectioned inspector String object_class; + Variant property_clipboard; bool restrict_to_basic = false; @@ -405,6 +425,8 @@ public: void set_use_deletable_properties(bool p_enabled); void set_restrict_to_basic_settings(bool p_restrict); + void set_property_clipboard(const Variant &p_value); + Variant get_property_clipboard() const; EditorInspector(); }; diff --git a/editor/editor_log.cpp b/editor/editor_log.cpp index 2cb73664f5..296a33d917 100644 --- a/editor/editor_log.cpp +++ b/editor/editor_log.cpp @@ -397,7 +397,7 @@ EditorLog::EditorLog() { show_search_button->set_focus_mode(FOCUS_NONE); show_search_button->set_toggle_mode(true); show_search_button->set_pressed(true); - show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Open the search box."), KEY_MASK_CMD | KEY_F)); + show_search_button->set_shortcut(ED_SHORTCUT("editor/open_search", TTR("Focus Search/Filter Bar"), KEY_MASK_CMD | KEY_F)); show_search_button->set_shortcut_context(this); show_search_button->connect("toggled", callable_mp(this, &EditorLog::_set_search_visible)); hb_tools2->add_child(show_search_button); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index e376325a85..9c7bddf037 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -97,10 +97,14 @@ #include "editor/editor_translation_parser.h" #include "editor/export_template_manager.h" #include "editor/filesystem_dock.h" +#include "editor/import/dynamicfont_import_settings.h" #include "editor/import/editor_import_collada.h" #include "editor/import/resource_importer_bitmask.h" +#include "editor/import/resource_importer_bmfont.h" #include "editor/import/resource_importer_csv_translation.h" +#include "editor/import/resource_importer_dynamicfont.h" #include "editor/import/resource_importer_image.h" +#include "editor/import/resource_importer_imagefont.h" #include "editor/import/resource_importer_layered_texture.h" #include "editor/import/resource_importer_obj.h" #include "editor/import/resource_importer_scene.h" @@ -388,20 +392,22 @@ void EditorNode::_version_control_menu_option(int p_idx) { } void EditorNode::_update_title() { - String appname = ProjectSettings::get_singleton()->get("application/config/name"); - String title = appname.is_empty() ? String(VERSION_FULL_NAME) : String(VERSION_NAME + String(" - ") + appname); - String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); + const String appname = ProjectSettings::get_singleton()->get("application/config/name"); + String title = (appname.is_empty() ? "Unnamed Project" : appname) + String(" - ") + VERSION_NAME; + const String edited = editor_data.get_edited_scene_root() ? editor_data.get_edited_scene_root()->get_filename() : String(); if (!edited.is_empty()) { - title += " - " + String(edited.get_file()); + // Display the edited scene name before the program name so that it can be seen in the OS task bar. + title = vformat("%s - %s", edited.get_file(), title); } if (unsaved_cache) { - title += " (*)"; + // Display the "modified" mark before anything else so that it can always be seen in the OS task bar. + title = vformat("(*) %s", title); } DisplayServer::get_singleton()->window_set_title(title); } -void EditorNode::_unhandled_input(const Ref<InputEvent> &p_event) { +void EditorNode::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventKey> k = p_event; @@ -2592,26 +2598,26 @@ void EditorNode::_menu_option_confirm(int p_option, bool p_confirmed) { case EDIT_UNDO: { if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { - log->add_message("Can't undo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); + log->add_message(TTR("Can't undo while mouse buttons are pressed."), EditorLog::MSG_TYPE_EDITOR); } else { String action = editor_data.get_undo_redo().get_current_action_name(); if (!editor_data.get_undo_redo().undo()) { - log->add_message("Nothing to undo.", EditorLog::MSG_TYPE_EDITOR); + log->add_message(TTR("Nothing to undo."), EditorLog::MSG_TYPE_EDITOR); } else if (action != "") { - log->add_message("Undo: " + action, EditorLog::MSG_TYPE_EDITOR); + log->add_message(vformat(TTR("Undo: %s"), action), EditorLog::MSG_TYPE_EDITOR); } } } break; case EDIT_REDO: { if (Input::get_singleton()->get_mouse_button_mask() & 0x7) { - log->add_message("Can't redo while mouse buttons are pressed.", EditorLog::MSG_TYPE_EDITOR); + log->add_message(TTR("Can't redo while mouse buttons are pressed."), EditorLog::MSG_TYPE_EDITOR); } else { if (!editor_data.get_undo_redo().redo()) { - log->add_message("Nothing to redo.", EditorLog::MSG_TYPE_EDITOR); + log->add_message(TTR("Nothing to redo."), EditorLog::MSG_TYPE_EDITOR); } else { String action = editor_data.get_undo_redo().get_current_action_name(); - log->add_message("Redo: " + action, EditorLog::MSG_TYPE_EDITOR); + log->add_message(vformat(TTR("Redo: %s"), action), EditorLog::MSG_TYPE_EDITOR); } } } break; @@ -3014,8 +3020,13 @@ void EditorNode::_update_file_menu_opened() { close_scene_sc->set_name(TTR("Close Scene")); Ref<Shortcut> reopen_closed_scene_sc = ED_GET_SHORTCUT("editor/reopen_closed_scene"); reopen_closed_scene_sc->set_name(TTR("Reopen Closed Scene")); + PopupMenu *pop = file_menu->get_popup(); pop->set_item_disabled(pop->get_item_index(FILE_OPEN_PREV), previous_scenes.is_empty()); + + const UndoRedo &undo_redo = editor_data.get_undo_redo(); + pop->set_item_disabled(pop->get_item_index(EDIT_UNDO), !undo_redo.has_undo()); + pop->set_item_disabled(pop->get_item_index(EDIT_REDO), !undo_redo.has_redo()); } void EditorNode::_update_file_menu_closed() { @@ -4797,6 +4808,32 @@ String EditorNode::get_run_playing_scene() const { return run_filename; } +void EditorNode::_immediate_dialog_confirmed() { + immediate_dialog_confirmed = true; +} +bool EditorNode::immediate_confirmation_dialog(const String &p_text, const String &p_ok_text, const String &p_cancel_text) { + ConfirmationDialog *cd = memnew(ConfirmationDialog); + cd->set_text(p_text); + cd->get_ok_button()->set_text(p_ok_text); + cd->get_cancel_button()->set_text(p_cancel_text); + cd->connect("confirmed", callable_mp(singleton, &EditorNode::_immediate_dialog_confirmed)); + singleton->gui_base->add_child(cd); + + cd->popup_centered(); + + while (true) { + OS::get_singleton()->delay_usec(1); + DisplayServer::get_singleton()->process_events(); + Main::iteration(); + if (singleton->immediate_dialog_confirmed || !cd->is_visible()) { + break; + } + } + + memdelete(cd); + return singleton->immediate_dialog_confirmed; +} + int EditorNode::get_current_tab() { return scene_tabs->get_current_tab(); } @@ -5585,7 +5622,6 @@ void EditorNode::_bind_methods() { ClassDB::bind_method("_editor_select", &EditorNode::_editor_select); ClassDB::bind_method("_node_renamed", &EditorNode::_node_renamed); ClassDB::bind_method("edit_node", &EditorNode::edit_node); - ClassDB::bind_method("_unhandled_input", &EditorNode::_unhandled_input); ClassDB::bind_method(D_METHOD("push_item", "object", "property", "inspector_only"), &EditorNode::push_item, DEFVAL(""), DEFVAL(false)); @@ -5825,6 +5861,18 @@ EditorNode::EditorNode() { import_texture_atlas.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_texture_atlas); + Ref<ResourceImporterDynamicFont> import_font_data_dynamic; + import_font_data_dynamic.instantiate(); + ResourceFormatImporter::get_singleton()->add_importer(import_font_data_dynamic); + + Ref<ResourceImporterBMFont> import_font_data_bmfont; + import_font_data_bmfont.instantiate(); + ResourceFormatImporter::get_singleton()->add_importer(import_font_data_bmfont); + + Ref<ResourceImporterImageFont> import_font_data_image; + import_font_data_image.instantiate(); + ResourceFormatImporter::get_singleton()->add_importer(import_font_data_image); + Ref<ResourceImporterCSVTranslation> import_csv_translation; import_csv_translation.instantiate(); ResourceFormatImporter::get_singleton()->add_importer(import_csv_translation); @@ -6230,6 +6278,9 @@ EditorNode::EditorNode() { scene_import_settings = memnew(SceneImportSettings); gui_base->add_child(scene_import_settings); + fontdata_import_settings = memnew(DynamicFontImportSettings); + gui_base->add_child(fontdata_import_settings); + export_template_manager = memnew(ExportTemplateManager); gui_base->add_child(export_template_manager); @@ -6244,9 +6295,9 @@ EditorNode::EditorNode() { gui_base->add_child(warning); warning->connect("custom_action", callable_mp(this, &EditorNode::_copy_warning)); - ED_SHORTCUT("editor/next_tab", TTR("Next tab"), KEY_MASK_CMD + KEY_TAB); - ED_SHORTCUT("editor/prev_tab", TTR("Previous tab"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB); - ED_SHORTCUT("editor/filter_files", TTR("Filter Files..."), KEY_MASK_CMD + KEY_MASK_ALT + KEY_P); + ED_SHORTCUT("editor/next_tab", TTR("Next Scene Tab"), KEY_MASK_CMD + KEY_TAB); + ED_SHORTCUT("editor/prev_tab", TTR("Previous Scene Tab"), KEY_MASK_CMD + KEY_MASK_SHIFT + KEY_TAB); + ED_SHORTCUT("editor/filter_files", TTR("Focus FileSystem Filter"), KEY_MASK_CMD + KEY_MASK_ALT + KEY_P); command_palette = EditorCommandPalette::get_singleton(); command_palette->set_title(TTR("Command Palette")); @@ -6373,6 +6424,7 @@ EditorNode::EditorNode() { #else p->add_shortcut(ED_SHORTCUT_AND_COMMAND("editor/editor_settings", TTR("Editor Settings...")), SETTINGS_PREFERENCES); #endif + p->add_shortcut(ED_SHORTCUT("editor/command_palette", TTR("Command Palette..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_P), HELP_COMMAND_PALETTE); p->add_separator(); editor_layouts = memnew(PopupMenu); @@ -6686,7 +6738,7 @@ EditorNode::EditorNode() { bottom_panel_raise->set_flat(true); bottom_panel_raise->set_icon(gui_base->get_theme_icon(SNAME("ExpandBottomDock"), SNAME("EditorIcons"))); - bottom_panel_raise->set_shortcut(ED_SHORTCUT("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KEY_MASK_SHIFT | KEY_F12)); + bottom_panel_raise->set_shortcut(ED_SHORTCUT_AND_COMMAND("editor/bottom_panel_expand", TTR("Expand Bottom Panel"), KEY_MASK_SHIFT | KEY_F12)); bottom_panel_hb->add_child(bottom_panel_raise); bottom_panel_raise->hide(); @@ -6790,7 +6842,6 @@ EditorNode::EditorNode() { preview_gen = memnew(AudioStreamPreviewGenerator); add_child(preview_gen); - //plugin stuff add_editor_plugin(memnew(DebuggerEditorPlugin(this, debug_menu))); add_editor_plugin(memnew(DebugAdapterServer())); @@ -7051,17 +7102,15 @@ EditorNode::EditorNode() { ED_SHORTCUT_AND_COMMAND("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_ALT | KEY_2); ED_SHORTCUT_AND_COMMAND("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_ALT | KEY_3); ED_SHORTCUT_AND_COMMAND("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_ALT | KEY_4); - ED_SHORTCUT("editor/command_palette", TTR("Open Command Palette"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_P); #else // Use the Ctrl modifier so F2 can be used to rename nodes in the scene tree dock. ED_SHORTCUT_AND_COMMAND("editor/editor_2d", TTR("Open 2D Editor"), KEY_MASK_CTRL | KEY_F1); ED_SHORTCUT_AND_COMMAND("editor/editor_3d", TTR("Open 3D Editor"), KEY_MASK_CTRL | KEY_F2); ED_SHORTCUT_AND_COMMAND("editor/editor_script", TTR("Open Script Editor"), KEY_MASK_CTRL | KEY_F3); ED_SHORTCUT_AND_COMMAND("editor/editor_assetlib", TTR("Open Asset Library"), KEY_MASK_CTRL | KEY_F4); - ED_SHORTCUT("editor/command_palette", TTR("Open Command Palette"), KEY_MASK_CTRL | KEY_MASK_SHIFT | KEY_P); #endif - ED_SHORTCUT_AND_COMMAND("editor/editor_next", TTR("Open the next Editor")); - ED_SHORTCUT_AND_COMMAND("editor/editor_prev", TTR("Open the previous Editor")); + ED_SHORTCUT_AND_COMMAND("editor/editor_next", TTR("Next Editor Tab")); + ED_SHORTCUT_AND_COMMAND("editor/editor_prev", TTR("Previous Editor Tab")); screenshot_timer = memnew(Timer); screenshot_timer->set_one_shot(true); diff --git a/editor/editor_node.h b/editor/editor_node.h index 1035072308..03c18a8972 100644 --- a/editor/editor_node.h +++ b/editor/editor_node.h @@ -92,6 +92,8 @@ class VSplitContainer; class Window; class SubViewport; class SceneImportSettings; +class EditorExtensionManager; +class DynamicFontImportSettings; class EditorNode : public Node { GDCLASS(EditorNode, Node); @@ -421,6 +423,7 @@ private: EditorResourcePreview *resource_preview; EditorFolding editor_folding; + DynamicFontImportSettings *fontdata_import_settings; SceneImportSettings *scene_import_settings; struct BottomPanelItem { String name; @@ -530,7 +533,7 @@ private: bool convert_old; - void _unhandled_input(const Ref<InputEvent> &p_event); + virtual void unhandled_input(const Ref<InputEvent> &p_event) override; static void _load_error_notify(void *p_ud, const String &p_text); @@ -675,6 +678,9 @@ private: void _pick_main_scene_custom_action(const String &p_custom_action_name); + bool immediate_dialog_confirmed = false; + void _immediate_dialog_confirmed(); + protected: void _notification(int p_what); @@ -708,7 +714,6 @@ public: EditorInspector *get_inspector() { return inspector_dock->get_inspector(); } Container *get_inspector_dock_addon_area() { return inspector_dock->get_addon_area(); } ScriptCreateDialog *get_script_create_dialog() { return scene_tree_dock->get_script_create_dialog(); } - EditorCommandPalette *get_editor_command_palette() { return command_palette; } ProjectSettingsEditor *get_project_settings() { return project_settings; } @@ -900,6 +905,8 @@ public: void run_stop(); bool is_run_playing() const; String get_run_playing_scene() const; + + static bool immediate_confirmation_dialog(const String &p_text, const String &p_ok_text = TTR("Ok"), const String &p_cancel_text = TTR("Cancel")); }; struct EditorProgress { diff --git a/editor/editor_plugin.cpp b/editor/editor_plugin.cpp index b71a3944fc..73ea4fb5ef 100644 --- a/editor/editor_plugin.cpp +++ b/editor/editor_plugin.cpp @@ -311,7 +311,7 @@ bool EditorInterface::is_distraction_free_mode_enabled() const { } EditorCommandPalette *EditorInterface::get_command_palette() const { - return EditorNode::get_singleton()->get_editor_command_palette(); + return EditorCommandPalette::get_singleton(); } EditorInterface *EditorInterface::singleton = nullptr; @@ -558,22 +558,19 @@ void EditorPlugin::notify_resource_saved(const Ref<Resource> &p_resource) { } bool EditorPlugin::forward_canvas_gui_input(const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_gui_input")) { - return get_script_instance()->call("_forward_canvas_gui_input", p_event); + bool success; + if (GDVIRTUAL_CALL(_forward_canvas_gui_input, p_event, success)) { + return success; } return false; } void EditorPlugin::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_draw_over_viewport")) { - get_script_instance()->call("_forward_canvas_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_canvas_draw_over_viewport, p_overlay); } void EditorPlugin::forward_canvas_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_canvas_force_draw_over_viewport")) { - get_script_instance()->call("_forward_canvas_force_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_canvas_force_draw_over_viewport, p_overlay); } // Updates the overlays of the 2D viewport or, if in 3D mode, of every 3D viewport. @@ -596,110 +593,101 @@ int EditorPlugin::update_overlays() const { } bool EditorPlugin::forward_spatial_gui_input(Camera3D *p_camera, const Ref<InputEvent> &p_event) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_gui_input")) { - return get_script_instance()->call("_forward_spatial_gui_input", p_camera, p_event); + bool success; + + if (GDVIRTUAL_CALL(_forward_3d_gui_input, p_camera, p_event, success)) { + return success; } return false; } void EditorPlugin::forward_spatial_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_draw_over_viewport")) { - get_script_instance()->call("_forward_spatial_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_3d_draw_over_viewport, p_overlay); } void EditorPlugin::forward_spatial_force_draw_over_viewport(Control *p_overlay) { - if (get_script_instance() && get_script_instance()->has_method("_forward_spatial_force_draw_over_viewport")) { - get_script_instance()->call("_forward_spatial_force_draw_over_viewport", p_overlay); - } + GDVIRTUAL_CALL(_forward_3d_force_draw_over_viewport, p_overlay); } String EditorPlugin::get_name() const { - if (get_script_instance() && get_script_instance()->has_method("_get_plugin_name")) { - return get_script_instance()->call("_get_plugin_name"); + String name; + if (GDVIRTUAL_CALL(_get_plugin_name, name)) { + return name; } return String(); } const Ref<Texture2D> EditorPlugin::get_icon() const { - if (get_script_instance() && get_script_instance()->has_method("_get_plugin_icon")) { - return get_script_instance()->call("_get_plugin_icon"); + Ref<Texture2D> icon; + if (GDVIRTUAL_CALL(_get_plugin_icon, icon)) { + return icon; } return Ref<Texture2D>(); } bool EditorPlugin::has_main_screen() const { - if (get_script_instance() && get_script_instance()->has_method("_has_main_screen")) { - return get_script_instance()->call("_has_main_screen"); + bool success; + if (GDVIRTUAL_CALL(_has_main_screen, success)) { + return success; } return false; } void EditorPlugin::make_visible(bool p_visible) { - if (get_script_instance() && get_script_instance()->has_method("_make_visible")) { - get_script_instance()->call("_make_visible", p_visible); - } + GDVIRTUAL_CALL(_make_visible, p_visible); } void EditorPlugin::edit(Object *p_object) { - if (get_script_instance() && get_script_instance()->has_method("_edit")) { - if (p_object->is_class("Resource")) { - get_script_instance()->call("_edit", Ref<Resource>(Object::cast_to<Resource>(p_object))); - } else { - get_script_instance()->call("_edit", p_object); - } + if (p_object->is_class("Resource")) { + GDVIRTUAL_CALL(_edit, Ref<Resource>(Object::cast_to<Resource>(p_object))); + } else { + GDVIRTUAL_CALL(_edit, p_object); } } bool EditorPlugin::handles(Object *p_object) const { - if (get_script_instance() && get_script_instance()->has_method("_handles")) { - return get_script_instance()->call("_handles", p_object); + bool success; + if (GDVIRTUAL_CALL(_handles, p_object, success)) { + return success; } return false; } Dictionary EditorPlugin::get_state() const { - if (get_script_instance() && get_script_instance()->has_method("_get_state")) { - return get_script_instance()->call("_get_state"); + Dictionary state; + if (GDVIRTUAL_CALL(_get_state, state)) { + return state; } return Dictionary(); } void EditorPlugin::set_state(const Dictionary &p_state) { - if (get_script_instance() && get_script_instance()->has_method("_set_state")) { - get_script_instance()->call("_set_state", p_state); - } + GDVIRTUAL_CALL(_set_state, p_state); } void EditorPlugin::clear() { - if (get_script_instance() && get_script_instance()->has_method("_clear")) { - get_script_instance()->call("_clear"); - } + GDVIRTUAL_CALL(_clear); } // if editor references external resources/scenes, save them void EditorPlugin::save_external_data() { - if (get_script_instance() && get_script_instance()->has_method("_save_external_data")) { - get_script_instance()->call("_save_external_data"); - } + GDVIRTUAL_CALL(_save_external_data); } // if changes are pending in editor, apply them void EditorPlugin::apply_changes() { - if (get_script_instance() && get_script_instance()->has_method("_apply_changes")) { - get_script_instance()->call("_apply_changes"); - } + GDVIRTUAL_CALL(_apply_changes); } void EditorPlugin::get_breakpoints(List<String> *p_breakpoints) { - if (get_script_instance() && get_script_instance()->has_method("_get_breakpoints")) { - PackedStringArray arr = get_script_instance()->call("_get_breakpoints"); + PackedStringArray arr; + if (GDVIRTUAL_CALL(_get_breakpoints, arr)) { for (int i = 0; i < arr.size(); i++) { p_breakpoints->push_back(arr[i]); } @@ -796,37 +784,28 @@ int find(const PackedStringArray &a, const String &v) { void EditorPlugin::enable_plugin() { // Called when the plugin gets enabled in project settings, after it's added to the tree. // You can implement it to register autoloads. - if (get_script_instance() && get_script_instance()->has_method("_enable_plugin")) { - get_script_instance()->call("_enable_plugin"); - } + GDVIRTUAL_CALL(_enable_plugin); } void EditorPlugin::disable_plugin() { // Last function called when the plugin gets disabled in project settings. // Implement it to cleanup things from the project, such as unregister autoloads. - - if (get_script_instance() && get_script_instance()->has_method("_disable_plugin")) { - get_script_instance()->call("_disable_plugin"); - } + GDVIRTUAL_CALL(_disable_plugin); } void EditorPlugin::set_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("_set_window_layout")) { - get_script_instance()->call("_set_window_layout", p_layout); - } + GDVIRTUAL_CALL(_set_window_layout, p_layout); } void EditorPlugin::get_window_layout(Ref<ConfigFile> p_layout) { - if (get_script_instance() && get_script_instance()->has_method("_get_window_layout")) { - get_script_instance()->call("_get_window_layout", p_layout); - } + GDVIRTUAL_CALL(_get_window_layout, p_layout); } bool EditorPlugin::build() { - if (get_script_instance() && get_script_instance()->has_method("_build")) { - return get_script_instance()->call("_build"); + bool success; + if (GDVIRTUAL_CALL(_build, success)) { + return success; } - return true; } @@ -915,29 +894,29 @@ void EditorPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("add_debugger_plugin", "script"), &EditorPlugin::add_debugger_plugin); ClassDB::bind_method(D_METHOD("remove_debugger_plugin", "script"), &EditorPlugin::remove_debugger_plugin); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_canvas_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo("_forward_canvas_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo("_forward_canvas_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_forward_spatial_gui_input", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - BIND_VMETHOD(MethodInfo("_forward_spatial_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo("_forward_spatial_force_draw_over_viewport", PropertyInfo(Variant::OBJECT, "overlay", PROPERTY_HINT_RESOURCE_TYPE, "Control"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_plugin_name")); - BIND_VMETHOD(MethodInfo(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "_get_plugin_icon")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_main_screen")); - BIND_VMETHOD(MethodInfo("_make_visible", PropertyInfo(Variant::BOOL, "visible"))); - BIND_VMETHOD(MethodInfo("_edit", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::OBJECT, "object"))); - BIND_VMETHOD(MethodInfo(Variant::DICTIONARY, "_get_state")); - BIND_VMETHOD(MethodInfo("_set_state", PropertyInfo(Variant::DICTIONARY, "state"))); - BIND_VMETHOD(MethodInfo("_clear")); - BIND_VMETHOD(MethodInfo("_save_external_data")); - BIND_VMETHOD(MethodInfo("_apply_changes")); - BIND_VMETHOD(MethodInfo(Variant::PACKED_STRING_ARRAY, "_get_breakpoints")); - BIND_VMETHOD(MethodInfo("_set_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - BIND_VMETHOD(MethodInfo("_get_window_layout", PropertyInfo(Variant::OBJECT, "layout", PROPERTY_HINT_RESOURCE_TYPE, "ConfigFile"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_build")); - BIND_VMETHOD(MethodInfo("_enable_plugin")); - BIND_VMETHOD(MethodInfo("_disable_plugin")); + GDVIRTUAL_BIND(_forward_canvas_gui_input, "event"); + GDVIRTUAL_BIND(_forward_canvas_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_canvas_force_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_3d_gui_input, "viewport_camera", "event"); + GDVIRTUAL_BIND(_forward_3d_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_forward_3d_force_draw_over_viewport, "viewport_control"); + GDVIRTUAL_BIND(_get_plugin_name); + GDVIRTUAL_BIND(_get_plugin_icon); + GDVIRTUAL_BIND(_has_main_screen); + GDVIRTUAL_BIND(_make_visible, "visible"); + GDVIRTUAL_BIND(_edit, "object"); + GDVIRTUAL_BIND(_handles, "object"); + GDVIRTUAL_BIND(_get_state); + GDVIRTUAL_BIND(_set_state, "state"); + GDVIRTUAL_BIND(_clear); + GDVIRTUAL_BIND(_save_external_data); + GDVIRTUAL_BIND(_apply_changes); + GDVIRTUAL_BIND(_get_breakpoints); + GDVIRTUAL_BIND(_set_window_layout, "configuration"); + GDVIRTUAL_BIND(_get_window_layout, "configuration"); + GDVIRTUAL_BIND(_build); + GDVIRTUAL_BIND(_enable_plugin); + GDVIRTUAL_BIND(_disable_plugin); ADD_SIGNAL(MethodInfo("scene_changed", PropertyInfo(Variant::OBJECT, "scene_root", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); ADD_SIGNAL(MethodInfo("scene_closed", PropertyInfo(Variant::STRING, "filepath"))); diff --git a/editor/editor_plugin.h b/editor/editor_plugin.h index d665278144..169106d901 100644 --- a/editor/editor_plugin.h +++ b/editor/editor_plugin.h @@ -39,9 +39,9 @@ #include "editor/import/editor_import_plugin.h" #include "editor/import/resource_importer_scene.h" #include "editor/script_create_dialog.h" +#include "scene/3d/camera_3d.h" #include "scene/main/node.h" #include "scene/resources/texture.h" - class EditorNode; class Node3D; class Camera3D; @@ -148,6 +148,30 @@ protected: void add_custom_type(const String &p_type, const String &p_base, const Ref<Script> &p_script, const Ref<Texture2D> &p_icon); void remove_custom_type(const String &p_type); + GDVIRTUAL1R(bool, _forward_canvas_gui_input, Ref<InputEvent>) + GDVIRTUAL1(_forward_canvas_draw_over_viewport, Control *) + GDVIRTUAL1(_forward_canvas_force_draw_over_viewport, Control *) + GDVIRTUAL2R(bool, _forward_3d_gui_input, Camera3D *, Ref<InputEvent>) + GDVIRTUAL1(_forward_3d_draw_over_viewport, Control *) + GDVIRTUAL1(_forward_3d_force_draw_over_viewport, Control *) + GDVIRTUAL0RC(String, _get_plugin_name) + GDVIRTUAL0RC(Ref<Texture2D>, _get_plugin_icon) + GDVIRTUAL0RC(bool, _has_main_screen) + GDVIRTUAL1(_make_visible, bool) + GDVIRTUAL1(_edit, Variant) + GDVIRTUAL1RC(bool, _handles, Variant) + GDVIRTUAL0RC(Dictionary, _get_state) + GDVIRTUAL1(_set_state, Dictionary) + GDVIRTUAL0(_clear) + GDVIRTUAL0(_save_external_data) + GDVIRTUAL0(_apply_changes) + GDVIRTUAL0RC(Vector<String>, _get_breakpoints) + GDVIRTUAL1(_set_window_layout, Ref<ConfigFile>) + GDVIRTUAL1(_get_window_layout, Ref<ConfigFile>) + GDVIRTUAL0R(bool, _build) + GDVIRTUAL0(_enable_plugin) + GDVIRTUAL0(_disable_plugin) + public: enum CustomControlContainer { CONTAINER_TOOLBAR, diff --git a/editor/editor_properties.cpp b/editor/editor_properties.cpp index 99619cfc40..9507833746 100644 --- a/editor/editor_properties.cpp +++ b/editor/editor_properties.cpp @@ -68,9 +68,9 @@ void EditorPropertyText::_text_changed(const String &p_string) { } if (string_name) { - emit_changed(get_edited_property(), StringName(p_string), "", true); + emit_changed(get_edited_property(), StringName(p_string)); } else { - emit_changed(get_edited_property(), p_string, "", true); + emit_changed(get_edited_property(), p_string); } } @@ -735,7 +735,7 @@ public: return String(); } - void _gui_input(const Ref<InputEvent> &p_ev) { + void gui_input(const Ref<InputEvent> &p_ev) override { const Ref<InputEventMouseMotion> mm = p_ev; if (mm.is_valid()) { bool expand_was_hovered = expand_hovered; @@ -931,7 +931,6 @@ public: } static void _bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &EditorPropertyLayersGrid::_gui_input); ADD_SIGNAL(MethodInfo("flag_changed", PropertyInfo(Variant::INT, "flag"))); } }; diff --git a/editor/editor_resource_preview.cpp b/editor/editor_resource_preview.cpp index 7f4ee7848f..8fc1345f3e 100644 --- a/editor/editor_resource_preview.cpp +++ b/editor/editor_resource_preview.cpp @@ -40,22 +40,25 @@ #include "editor_settings.h" 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); + bool success; + if (GDVIRTUAL_CALL(_handles, p_type, success)) { + return success; } ERR_FAIL_V_MSG(false, "EditorResourcePreviewGenerator::_handles needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate(const RES &p_from, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("_generate")) { - return get_script_instance()->call("_generate", p_from, p_size); + Ref<Texture2D> preview; + if (GDVIRTUAL_CALL(_generate, p_from, p_size, preview)) { + return preview; } ERR_FAIL_V_MSG(Ref<Texture2D>(), "EditorResourcePreviewGenerator::_generate needs to be overridden."); } Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String &p_path, const Size2 &p_size) const { - if (get_script_instance() && get_script_instance()->has_method("_generate_from_path")) { - return get_script_instance()->call("_generate_from_path", p_path, p_size); + Ref<Texture2D> preview; + if (GDVIRTUAL_CALL(_generate_from_path, p_path, p_size, preview)) { + return preview; } RES res = ResourceLoader::load(p_path); @@ -66,27 +69,29 @@ Ref<Texture2D> EditorResourcePreviewGenerator::generate_from_path(const String & } bool EditorResourcePreviewGenerator::generate_small_preview_automatically() const { - if (get_script_instance() && get_script_instance()->has_method("_generate_small_preview_automatically")) { - return get_script_instance()->call("_generate_small_preview_automatically"); + bool success; + if (GDVIRTUAL_CALL(_generate_small_preview_automatically, success)) { + return success; } return false; } bool EditorResourcePreviewGenerator::can_generate_small_preview() const { - if (get_script_instance() && get_script_instance()->has_method("_can_generate_small_preview")) { - return get_script_instance()->call("_can_generate_small_preview"); + bool success; + if (GDVIRTUAL_CALL(_can_generate_small_preview, success)) { + return success; } return false; } void EditorResourcePreviewGenerator::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_handles", PropertyInfo(Variant::STRING, "type"))); - BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate", PropertyInfo(Variant::OBJECT, "from", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::VECTOR2, "size"))); - BIND_VMETHOD(MethodInfo(CLASS_INFO(Texture2D), "_generate_from_path", PropertyInfo(Variant::STRING, "path", PROPERTY_HINT_FILE), PropertyInfo(Variant::VECTOR2, "size"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_generate_small_preview_automatically")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_generate_small_preview")); + GDVIRTUAL_BIND(_handles, "type"); + GDVIRTUAL_BIND(_generate, "resource", "size"); + GDVIRTUAL_BIND(_generate_from_path, "path", "size"); + GDVIRTUAL_BIND(_generate_small_preview_automatically); + GDVIRTUAL_BIND(_can_generate_small_preview); } EditorResourcePreviewGenerator::EditorResourcePreviewGenerator() { diff --git a/editor/editor_resource_preview.h b/editor/editor_resource_preview.h index 67f83220d0..ea16c8fde0 100644 --- a/editor/editor_resource_preview.h +++ b/editor/editor_resource_preview.h @@ -43,6 +43,12 @@ class EditorResourcePreviewGenerator : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1RC(bool, _handles, String) + GDVIRTUAL2RC(Ref<Texture2D>, _generate, RES, Vector2i) + GDVIRTUAL2RC(Ref<Texture2D>, _generate_from_path, String, Vector2i) + GDVIRTUAL0RC(bool, _generate_small_preview_automatically) + GDVIRTUAL0RC(bool, _can_generate_small_preview) + public: virtual bool handles(const String &p_type) const; virtual Ref<Texture2D> generate(const RES &p_from, const Size2 &p_size) const; diff --git a/editor/editor_run_script.cpp b/editor/editor_run_script.cpp index 83ce50a9f9..27923ef413 100644 --- a/editor/editor_run_script.cpp +++ b/editor/editor_run_script.cpp @@ -60,18 +60,8 @@ Node *EditorScript::get_scene() { } void EditorScript::_run() { - Ref<Script> s = get_script(); - ERR_FAIL_COND(!s.is_valid()); - if (!get_script_instance()) { - EditorNode::add_io_error(TTR("Couldn't instance script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the 'tool' keyword?")); - return; - } - - Callable::CallError ce; - ce.error = Callable::CallError::CALL_OK; - get_script_instance()->call("_run", nullptr, 0, ce); - if (ce.error != Callable::CallError::CALL_OK) { - EditorNode::add_io_error(TTR("Couldn't run script:") + "\n " + s->get_path() + "\n" + TTR("Did you forget the '_run' method?")); + if (!GDVIRTUAL_CALL(_run)) { + EditorNode::add_io_error(TTR("Couldn't run editor script, did you forget to override the '_run' method?")); } } @@ -83,7 +73,7 @@ void EditorScript::_bind_methods() { ClassDB::bind_method(D_METHOD("add_root_node", "node"), &EditorScript::add_root_node); ClassDB::bind_method(D_METHOD("get_scene"), &EditorScript::get_scene); ClassDB::bind_method(D_METHOD("get_editor_interface"), &EditorScript::get_editor_interface); - BIND_VMETHOD(MethodInfo("_run")); + GDVIRTUAL_BIND(_run); } EditorScript::EditorScript() { diff --git a/editor/editor_run_script.h b/editor/editor_run_script.h index c8412c3c92..6c7e37774d 100644 --- a/editor/editor_run_script.h +++ b/editor/editor_run_script.h @@ -41,6 +41,7 @@ class EditorScript : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL0(_run) public: void add_root_node(Node *p_node); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 009a83994c..8d579753c2 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -492,68 +492,73 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { // Theme _initial_set("text_editor/theme/color_theme", "Default"); hints["text_editor/theme/color_theme"] = PropertyInfo(Variant::STRING, "text_editor/theme/color_theme", PROPERTY_HINT_ENUM, "Default,Godot 2,Custom"); - _initial_set("text_editor/theme/line_spacing", 6); - hints["text_editor/theme/line_spacing"] = PropertyInfo(Variant::INT, "text_editor/theme/line_spacing", PROPERTY_HINT_RANGE, "0,50,1"); + // Theme: Highlighting _load_godot2_text_editor_theme(); - // Highlighting - _initial_set("text_editor/highlighting/highlight_all_occurrences", true); - _initial_set("text_editor/highlighting/highlight_current_line", true); - _initial_set("text_editor/highlighting/highlight_type_safe_lines", true); - - // Indent - _initial_set("text_editor/indent/type", 0); - hints["text_editor/indent/type"] = PropertyInfo(Variant::INT, "text_editor/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); - _initial_set("text_editor/indent/size", 4); - hints["text_editor/indent/size"] = PropertyInfo(Variant::INT, "text_editor/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. - _initial_set("text_editor/indent/auto_indent", true); - _initial_set("text_editor/indent/convert_indent_on_save", true); - _initial_set("text_editor/indent/draw_tabs", true); - _initial_set("text_editor/indent/draw_spaces", false); - - // Navigation - _initial_set("text_editor/navigation/smooth_scrolling", true); - _initial_set("text_editor/navigation/v_scroll_speed", 80); - _initial_set("text_editor/navigation/show_minimap", true); - _initial_set("text_editor/navigation/minimap_width", 80); - hints["text_editor/navigation/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/navigation/minimap_width", PROPERTY_HINT_RANGE, "50,250,1"); - // Appearance - _initial_set("text_editor/appearance/show_line_numbers", true); - _initial_set("text_editor/appearance/line_numbers_zero_padded", false); - _initial_set("text_editor/appearance/show_bookmark_gutter", true); - _initial_set("text_editor/appearance/show_info_gutter", true); - _initial_set("text_editor/appearance/code_folding", true); - _initial_set("text_editor/appearance/word_wrap", 0); - hints["text_editor/appearance/word_wrap"] = PropertyInfo(Variant::INT, "text_editor/appearance/word_wrap", PROPERTY_HINT_ENUM, "None,Boundary"); - - _initial_set("text_editor/appearance/show_line_length_guidelines", true); - _initial_set("text_editor/appearance/line_length_guideline_soft_column", 80); - hints["text_editor/appearance/line_length_guideline_soft_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_soft_column", PROPERTY_HINT_RANGE, "20, 160, 1"); - _initial_set("text_editor/appearance/line_length_guideline_hard_column", 100); - hints["text_editor/appearance/line_length_guideline_hard_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/line_length_guideline_hard_column", PROPERTY_HINT_RANGE, "20, 160, 1"); + // Appearance: Caret + _initial_set("text_editor/appearance/caret/type", 0); + hints["text_editor/appearance/caret/type"] = PropertyInfo(Variant::INT, "text_editor/appearance/caret/type", PROPERTY_HINT_ENUM, "Line,Block"); + _initial_set("text_editor/appearance/caret/caret_blink", true); + _initial_set("text_editor/appearance/caret/caret_blink_speed", 0.5); + hints["text_editor/appearance/caret/caret_blink_speed"] = PropertyInfo(Variant::FLOAT, "text_editor/appearance/caret/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.01"); + _initial_set("text_editor/appearance/caret/highlight_current_line", true); + _initial_set("text_editor/appearance/caret/highlight_all_occurrences", true); + + // Appearance: Guidelines + _initial_set("text_editor/appearance/guidelines/show_line_length_guidelines", true); + _initial_set("text_editor/appearance/guidelines/line_length_guideline_soft_column", 80); + hints["text_editor/appearance/guidelines/line_length_guideline_soft_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/guidelines/line_length_guideline_soft_column", PROPERTY_HINT_RANGE, "20, 160, 1"); + _initial_set("text_editor/appearance/guidelines/line_length_guideline_hard_column", 100); + hints["text_editor/appearance/guidelines/line_length_guideline_hard_column"] = PropertyInfo(Variant::INT, "text_editor/appearance/guidelines/line_length_guideline_hard_column", PROPERTY_HINT_RANGE, "20, 160, 1"); + + // Appearance: Gutters + _initial_set("text_editor/appearance/gutters/show_line_numbers", true); + _initial_set("text_editor/appearance/gutters/line_numbers_zero_padded", false); + _initial_set("text_editor/appearance/gutters/highlight_type_safe_lines", true); + _initial_set("text_editor/appearance/gutters/show_bookmark_gutter", true); + _initial_set("text_editor/appearance/gutters/show_info_gutter", true); + + // Appearance: Minimap + _initial_set("text_editor/appearance/minimap/show_minimap", true); + _initial_set("text_editor/appearance/minimap/minimap_width", 80); + hints["text_editor/appearance/minimap/minimap_width"] = PropertyInfo(Variant::INT, "text_editor/appearance/minimap/minimap_width", PROPERTY_HINT_RANGE, "50,250,1"); + + // Appearance: Lines + _initial_set("text_editor/appearance/lines/code_folding", true); + _initial_set("text_editor/appearance/lines/word_wrap", 0); + hints["text_editor/appearance/lines/word_wrap"] = PropertyInfo(Variant::INT, "text_editor/appearance/lines/word_wrap", PROPERTY_HINT_ENUM, "None,Boundary"); + + // Appearance: Whitespace + _initial_set("text_editor/appearance/whitespace/draw_tabs", true); + _initial_set("text_editor/appearance/whitespace/draw_spaces", false); + _initial_set("text_editor/appearance/whitespace/line_spacing", 6); + hints["text_editor/appearance/whitespace/line_spacing"] = PropertyInfo(Variant::INT, "text_editor/appearance/whitespace/line_spacing", PROPERTY_HINT_RANGE, "0,50,1"); + + // Behavior + // Behavior: Navigation + _initial_set("text_editor/behavior/navigation/move_caret_on_right_click", true); + _initial_set("text_editor/behavior/navigation/scroll_past_end_of_file", false); + _initial_set("text_editor/behavior/navigation/smooth_scrolling", true); + _initial_set("text_editor/behavior/navigation/v_scroll_speed", 80); + + // Behavior: Indent + _initial_set("text_editor/behavior/indent/type", 0); + hints["text_editor/behavior/indent/type"] = PropertyInfo(Variant::INT, "text_editor/behavior/indent/type", PROPERTY_HINT_ENUM, "Tabs,Spaces"); + _initial_set("text_editor/behavior/indent/size", 4); + hints["text_editor/behavior/indent/size"] = PropertyInfo(Variant::INT, "text_editor/behavior/indent/size", PROPERTY_HINT_RANGE, "1, 64, 1"); // size of 0 crashes. + _initial_set("text_editor/behavior/indent/auto_indent", true); + + // Behavior: Files + _initial_set("text_editor/behavior/files/trim_trailing_whitespace_on_save", false); + _initial_set("text_editor/behavior/files/autosave_interval_secs", 0); + _initial_set("text_editor/behavior/files/restore_scripts_on_load", true); + _initial_set("text_editor/behavior/files/convert_indent_on_save", true); // Script list _initial_set("text_editor/script_list/show_members_overview", true); - - // Files - _initial_set("text_editor/files/trim_trailing_whitespace_on_save", false); - _initial_set("text_editor/files/autosave_interval_secs", 0); - _initial_set("text_editor/files/restore_scripts_on_load", true); - - // Tools - _initial_set("text_editor/tools/create_signal_callbacks", true); - _initial_set("text_editor/tools/sort_members_outline_alphabetically", false); - - // Cursor - _initial_set("text_editor/cursor/scroll_past_end_of_file", false); - _initial_set("text_editor/cursor/type", 0); - hints["text_editor/cursor/type"] = PropertyInfo(Variant::INT, "text_editor/cursor/type", PROPERTY_HINT_ENUM, "Line,Block"); - _initial_set("text_editor/cursor/caret_blink", true); - _initial_set("text_editor/cursor/caret_blink_speed", 0.5); - hints["text_editor/cursor/caret_blink_speed"] = PropertyInfo(Variant::FLOAT, "text_editor/cursor/caret_blink_speed", PROPERTY_HINT_RANGE, "0.1, 10, 0.01"); - _initial_set("text_editor/cursor/right_click_moves_caret", true); + _initial_set("text_editor/script_list/sort_members_outline_alphabetically", false); // Completion _initial_set("text_editor/completion/idle_parse_delay", 2.0); @@ -699,8 +704,8 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { _initial_set("editors/tiles_editor/grid_color", Color(1.0, 0.5, 0.2, 0.5)); // Polygon editor - _initial_set("editors/poly_editor/point_grab_radius", 8); - _initial_set("editors/poly_editor/show_previous_outline", true); + _initial_set("editors/polygon_editor/point_grab_radius", 8); + _initial_set("editors/polygon_editor/show_previous_outline", true); // Animation _initial_set("editors/animation/autorename_animation_tracks", true); @@ -777,41 +782,41 @@ void EditorSettings::_load_defaults(Ref<ConfigFile> p_extra_config) { void EditorSettings::_load_godot2_text_editor_theme() { // Godot 2 is only a dark theme; it doesn't have a light theme counterpart. - _initial_set("text_editor/highlighting/symbol_color", Color(0.73, 0.87, 1.0)); - _initial_set("text_editor/highlighting/keyword_color", Color(1.0, 1.0, 0.7)); - _initial_set("text_editor/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7)); - _initial_set("text_editor/highlighting/base_type_color", Color(0.64, 1.0, 0.83)); - _initial_set("text_editor/highlighting/engine_type_color", Color(0.51, 0.83, 1.0)); - _initial_set("text_editor/highlighting/user_type_color", Color(0.42, 0.67, 0.93)); - _initial_set("text_editor/highlighting/comment_color", Color(0.4, 0.4, 0.4)); - _initial_set("text_editor/highlighting/string_color", Color(0.94, 0.43, 0.75)); - _initial_set("text_editor/highlighting/background_color", Color(0.13, 0.12, 0.15)); - _initial_set("text_editor/highlighting/completion_background_color", Color(0.17, 0.16, 0.2)); - _initial_set("text_editor/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27)); - _initial_set("text_editor/highlighting/completion_existing_color", Color(0.13, 0.87, 0.87, 0.87)); - _initial_set("text_editor/highlighting/completion_scroll_color", Color(1, 1, 1)); - _initial_set("text_editor/highlighting/completion_font_color", Color(0.67, 0.67, 0.67)); - _initial_set("text_editor/highlighting/text_color", Color(0.67, 0.67, 0.67)); - _initial_set("text_editor/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4)); - _initial_set("text_editor/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6)); - _initial_set("text_editor/highlighting/caret_color", Color(0.67, 0.67, 0.67)); - _initial_set("text_editor/highlighting/caret_background_color", Color(0, 0, 0)); - _initial_set("text_editor/highlighting/text_selected_color", Color(0, 0, 0)); - _initial_set("text_editor/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35)); - _initial_set("text_editor/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)); - _initial_set("text_editor/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15)); - _initial_set("text_editor/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1)); - _initial_set("text_editor/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15)); - _initial_set("text_editor/highlighting/number_color", Color(0.92, 0.58, 0.2)); - _initial_set("text_editor/highlighting/function_color", Color(0.4, 0.64, 0.81)); - _initial_set("text_editor/highlighting/member_variable_color", Color(0.9, 0.31, 0.35)); - _initial_set("text_editor/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)); - _initial_set("text_editor/highlighting/bookmark_color", Color(0.08, 0.49, 0.98)); - _initial_set("text_editor/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3)); - _initial_set("text_editor/highlighting/executing_line_color", Color(0.98, 0.89, 0.27)); - _initial_set("text_editor/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8)); - _initial_set("text_editor/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)); - _initial_set("text_editor/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38)); + _initial_set("text_editor/theme/highlighting/symbol_color", Color(0.73, 0.87, 1.0)); + _initial_set("text_editor/theme/highlighting/keyword_color", Color(1.0, 1.0, 0.7)); + _initial_set("text_editor/theme/highlighting/control_flow_keyword_color", Color(1.0, 0.85, 0.7)); + _initial_set("text_editor/theme/highlighting/base_type_color", Color(0.64, 1.0, 0.83)); + _initial_set("text_editor/theme/highlighting/engine_type_color", Color(0.51, 0.83, 1.0)); + _initial_set("text_editor/theme/highlighting/user_type_color", Color(0.42, 0.67, 0.93)); + _initial_set("text_editor/theme/highlighting/comment_color", Color(0.4, 0.4, 0.4)); + _initial_set("text_editor/theme/highlighting/string_color", Color(0.94, 0.43, 0.75)); + _initial_set("text_editor/theme/highlighting/background_color", Color(0.13, 0.12, 0.15)); + _initial_set("text_editor/theme/highlighting/completion_background_color", Color(0.17, 0.16, 0.2)); + _initial_set("text_editor/theme/highlighting/completion_selected_color", Color(0.26, 0.26, 0.27)); + _initial_set("text_editor/theme/highlighting/completion_existing_color", Color(0.13, 0.87, 0.87, 0.87)); + _initial_set("text_editor/theme/highlighting/completion_scroll_color", Color(1, 1, 1)); + _initial_set("text_editor/theme/highlighting/completion_font_color", Color(0.67, 0.67, 0.67)); + _initial_set("text_editor/theme/highlighting/text_color", Color(0.67, 0.67, 0.67)); + _initial_set("text_editor/theme/highlighting/line_number_color", Color(0.67, 0.67, 0.67, 0.4)); + _initial_set("text_editor/theme/highlighting/safe_line_number_color", Color(0.67, 0.78, 0.67, 0.6)); + _initial_set("text_editor/theme/highlighting/caret_color", Color(0.67, 0.67, 0.67)); + _initial_set("text_editor/theme/highlighting/caret_background_color", Color(0, 0, 0)); + _initial_set("text_editor/theme/highlighting/text_selected_color", Color(0, 0, 0)); + _initial_set("text_editor/theme/highlighting/selection_color", Color(0.41, 0.61, 0.91, 0.35)); + _initial_set("text_editor/theme/highlighting/brace_mismatch_color", Color(1, 0.2, 0.2)); + _initial_set("text_editor/theme/highlighting/current_line_color", Color(0.3, 0.5, 0.8, 0.15)); + _initial_set("text_editor/theme/highlighting/line_length_guideline_color", Color(0.3, 0.5, 0.8, 0.1)); + _initial_set("text_editor/theme/highlighting/word_highlighted_color", Color(0.8, 0.9, 0.9, 0.15)); + _initial_set("text_editor/theme/highlighting/number_color", Color(0.92, 0.58, 0.2)); + _initial_set("text_editor/theme/highlighting/function_color", Color(0.4, 0.64, 0.81)); + _initial_set("text_editor/theme/highlighting/member_variable_color", Color(0.9, 0.31, 0.35)); + _initial_set("text_editor/theme/highlighting/mark_color", Color(1.0, 0.4, 0.4, 0.4)); + _initial_set("text_editor/theme/highlighting/bookmark_color", Color(0.08, 0.49, 0.98)); + _initial_set("text_editor/theme/highlighting/breakpoint_color", Color(0.9, 0.29, 0.3)); + _initial_set("text_editor/theme/highlighting/executing_line_color", Color(0.98, 0.89, 0.27)); + _initial_set("text_editor/theme/highlighting/code_folding_color", Color(0.8, 0.8, 0.8, 0.8)); + _initial_set("text_editor/theme/highlighting/search_result_color", Color(0.05, 0.25, 0.05, 1)); + _initial_set("text_editor/theme/highlighting/search_result_border_color", Color(0.41, 0.61, 0.91, 0.38)); } bool EditorSettings::_save_text_editor_theme(String p_file) { @@ -823,8 +828,8 @@ bool EditorSettings::_save_text_editor_theme(String p_file) { keys.sort(); for (const String &key : keys) { - if (key.begins_with("text_editor/highlighting/") && key.find("color") >= 0) { - cf->set_value(theme_section, key.replace("text_editor/highlighting/", ""), ((Color)props[key].variant).to_html()); + if (key.begins_with("text_editor/theme/highlighting/") && key.find("color") >= 0) { + cf->set_value(theme_section, key.replace("text_editor/theme/highlighting/", ""), ((Color)props[key].variant).to_html()); } } @@ -1340,10 +1345,10 @@ void EditorSettings::load_text_editor_theme() { String val = cf->get_value("color_theme", key); // don't load if it's not already there! - if (has_setting("text_editor/highlighting/" + key)) { + if (has_setting("text_editor/theme/highlighting/" + key)) { // make sure it is actually a color if (val.is_valid_html_color() && key.find("color") >= 0) { - props["text_editor/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam + props["text_editor/theme/highlighting/" + key].variant = Color::html(val); // change manually to prevent "Settings changed" console spam } } } diff --git a/editor/editor_settings.h b/editor/editor_settings.h index 6d28b26623..86e15f5ff5 100644 --- a/editor/editor_settings.h +++ b/editor/editor_settings.h @@ -31,13 +31,13 @@ #ifndef EDITOR_SETTINGS_H #define EDITOR_SETTINGS_H +#include "core/input/shortcut.h" #include "core/io/config_file.h" #include "core/io/resource.h" #include "core/object/class_db.h" #include "core/os/thread_safe.h" #include "core/string/translation.h" #include "editor/editor_paths.h" -#include "scene/gui/shortcut.h" class EditorPlugin; diff --git a/editor/editor_spin_slider.cpp b/editor/editor_spin_slider.cpp index a802afda0f..3f65b101f7 100644 --- a/editor/editor_spin_slider.cpp +++ b/editor/editor_spin_slider.cpp @@ -52,7 +52,7 @@ String EditorSpinSlider::get_text_value() const { return TS->format_number(String::num(get_value(), Math::range_step_decimals(get_step()))); } -void EditorSpinSlider::_gui_input(const Ref<InputEvent> &p_event) { +void EditorSpinSlider::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (read_only) { @@ -195,11 +195,11 @@ void EditorSpinSlider::_update_value_input_stylebox() { if (!value_input) { return; } + // Add a left margin to the stylebox to make the number align with the Label // when it's edited. The LineEdit "focus" stylebox uses the "normal" stylebox's // default margins. - Ref<StyleBoxFlat> stylebox = - EditorNode::get_singleton()->get_theme_base()->get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))->duplicate(); + Ref<StyleBox> stylebox = get_theme_stylebox(SNAME("normal"), SNAME("LineEdit"))->duplicate(); // EditorSpinSliders with a label have more space on the left, so add an // higher margin to match the location where the text begins. // The margin values below were determined by empirical testing. @@ -210,188 +210,197 @@ void EditorSpinSlider::_update_value_input_stylebox() { stylebox->set_default_margin(SIDE_LEFT, (get_label() != String() ? 23 : 16) * EDSCALE); stylebox->set_default_margin(SIDE_RIGHT, 0); } + value_input->add_theme_style_override("normal", stylebox); } -void EditorSpinSlider::_notification(int p_what) { - if (p_what == NOTIFICATION_WM_WINDOW_FOCUS_OUT || - p_what == NOTIFICATION_WM_WINDOW_FOCUS_IN || - p_what == NOTIFICATION_EXIT_TREE) { - if (grabbing_spinner) { - grabber->hide(); - Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); - grabbing_spinner = false; - grabbing_spinner_attempt = false; - } - } - if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_THEME_CHANGED) { - _update_value_input_stylebox(); - } +void EditorSpinSlider::_draw_spin_slider() { + updown_offset = -1; - if (p_what == NOTIFICATION_DRAW) { - updown_offset = -1; + RID ci = get_canvas_item(); + bool rtl = is_layout_rtl(); + Vector2 size = get_size(); - RID ci = get_canvas_item(); - bool rtl = is_layout_rtl(); - Vector2 size = get_size(); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"), SNAME("LineEdit")); + if (!flat) { + draw_style_box(sb, Rect2(Vector2(), size)); + } + Ref<Font> font = get_theme_font(SNAME("font"), SNAME("LineEdit")); + int font_size = get_theme_font_size(SNAME("font_size"), SNAME("LineEdit")); + int sep_base = 4 * EDSCALE; + int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better - Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"), SNAME("LineEdit")); - if (!flat) { - draw_style_box(sb, Rect2(Vector2(), size)); - } - Ref<Font> font = get_theme_font(SNAME("font"), SNAME("LineEdit")); - int font_size = get_theme_font_size(SNAME("font_size"), SNAME("LineEdit")); - int sep_base = 4 * EDSCALE; - int sep = sep_base + sb->get_offset().x; //make it have the same margin on both sides, looks better + int label_width = font->get_string_size(label, font_size).width; + int number_width = size.width - sb->get_minimum_size().width - label_width - sep; - int label_width = font->get_string_size(label, font_size).width; - int number_width = size.width - sb->get_minimum_size().width - label_width - sep; + Ref<Texture2D> updown = get_theme_icon(SNAME("updown"), SNAME("SpinBox")); - Ref<Texture2D> updown = get_theme_icon(SNAME("updown"), SNAME("SpinBox")); + if (get_step() == 1) { + number_width -= updown->get_width(); + } - if (get_step() == 1) { - number_width -= updown->get_width(); - } + String numstr = get_text_value(); - String numstr = get_text_value(); + int vofs = (size.height - font->get_height(font_size)) / 2 + font->get_ascent(font_size); - int vofs = (size.height - font->get_height(font_size)) / 2 + font->get_ascent(font_size); + Color fc = get_theme_color(SNAME("font_color"), SNAME("LineEdit")); + Color lc; + if (use_custom_label_color) { + lc = custom_label_color; + } else { + lc = fc; + } - Color fc = get_theme_color(SNAME("font_color"), SNAME("LineEdit")); - Color lc; - if (use_custom_label_color) { - lc = custom_label_color; + if (flat && label != String()) { + Color label_bg_color = get_theme_color(SNAME("dark_color_3"), SNAME("Editor")); + if (rtl) { + draw_rect(Rect2(Vector2(size.width - (sb->get_offset().x * 2 + label_width), 0), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); } else { - lc = fc; + draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); } + } - if (flat && label != String()) { - Color label_bg_color = get_theme_color(SNAME("dark_color_3"), SNAME("Editor")); - if (rtl) { - draw_rect(Rect2(Vector2(size.width - (sb->get_offset().x * 2 + label_width), 0), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); - } else { - draw_rect(Rect2(Vector2(), Vector2(sb->get_offset().x * 2 + label_width, size.height)), label_bg_color); - } - } + if (has_focus()) { + Ref<StyleBox> focus = get_theme_stylebox(SNAME("focus"), SNAME("LineEdit")); + draw_style_box(focus, Rect2(Vector2(), size)); + } + + if (rtl) { + draw_string(font, Vector2(Math::round(size.width - sb->get_offset().x - label_width), vofs), label, HALIGN_RIGHT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + } else { + draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + } - if (has_focus()) { - Ref<StyleBox> focus = get_theme_stylebox(SNAME("focus"), SNAME("LineEdit")); - draw_style_box(focus, Rect2(Vector2(), size)); + int suffix_start = numstr.length(); + RID num_rid = TS->create_shaped_text(); + TS->shaped_text_add_string(num_rid, numstr + U"\u2009" + suffix, font->get_rids(), font_size); + + float text_start = rtl ? Math::round(sb->get_offset().x) : Math::round(sb->get_offset().x + label_width + sep); + Vector2 text_ofs = rtl ? Vector2(text_start + (number_width - TS->shaped_text_get_width(num_rid)), vofs) : Vector2(text_start, vofs); + const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(num_rid); + int v_size = visual.size(); + const TextServer::Glyph *glyphs = visual.ptr(); + for (int i = 0; i < v_size; i++) { + for (int j = 0; j < glyphs[i].repeat; j++) { + if (text_ofs.x >= text_start && (text_ofs.x + glyphs[i].advance) <= (text_start + number_width)) { + Color color = fc; + if (glyphs[i].start >= suffix_start) { + color.a *= 0.4; + } + if (glyphs[i].font_rid != RID()) { + TS->font_draw_glyph(glyphs[i].font_rid, ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); + } else if ((glyphs[i].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { + TS->draw_hex_code_box(ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); + } + } + text_ofs.x += glyphs[i].advance; } + } + TS->free(num_rid); + if (get_step() == 1) { + Ref<Texture2D> updown2 = get_theme_icon(SNAME("updown"), SNAME("SpinBox")); + int updown_vofs = (size.height - updown2->get_height()) / 2; if (rtl) { - draw_string(font, Vector2(Math::round(size.width - sb->get_offset().x - label_width), vofs), label, HALIGN_RIGHT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + updown_offset = sb->get_margin(SIDE_LEFT); } else { - draw_string(font, Vector2(Math::round(sb->get_offset().x), vofs), label, HALIGN_LEFT, -1, font_size, lc * Color(1, 1, 1, 0.5)); + updown_offset = size.width - sb->get_margin(SIDE_RIGHT) - updown2->get_width(); } - - int suffix_start = numstr.length(); - RID num_rid = TS->create_shaped_text(); - TS->shaped_text_add_string(num_rid, numstr + U"\u2009" + suffix, font->get_rids(), font_size); - - float text_start = rtl ? Math::round(sb->get_offset().x) : Math::round(sb->get_offset().x + label_width + sep); - Vector2 text_ofs = rtl ? Vector2(text_start + (number_width - TS->shaped_text_get_width(num_rid)), vofs) : Vector2(text_start, vofs); - const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(num_rid); - int v_size = visual.size(); - const TextServer::Glyph *glyphs = visual.ptr(); - for (int i = 0; i < v_size; i++) { - for (int j = 0; j < glyphs[i].repeat; j++) { - if (text_ofs.x >= text_start && (text_ofs.x + glyphs[i].advance) <= (text_start + number_width)) { - Color color = fc; - if (glyphs[i].start >= suffix_start) { - color.a *= 0.4; - } - if (glyphs[i].font_rid != RID()) { - TS->font_draw_glyph(glyphs[i].font_rid, ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); - } else if ((glyphs[i].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) { - TS->draw_hex_code_box(ci, glyphs[i].font_size, text_ofs + Vector2(glyphs[i].x_off, glyphs[i].y_off), glyphs[i].index, color); - } - } - text_ofs.x += glyphs[i].advance; - } + Color c(1, 1, 1); + if (hover_updown) { + c *= Color(1.2, 1.2, 1.2); } - TS->free(num_rid); - - if (get_step() == 1) { - Ref<Texture2D> updown2 = get_theme_icon(SNAME("updown"), SNAME("SpinBox")); - int updown_vofs = (size.height - updown2->get_height()) / 2; - if (rtl) { - updown_offset = sb->get_margin(SIDE_LEFT); + draw_texture(updown2, Vector2(updown_offset, updown_vofs), c); + if (grabber->is_visible()) { + grabber->hide(); + } + } else if (!hide_slider) { + int grabber_w = 4 * EDSCALE; + int width = size.width - sb->get_minimum_size().width - grabber_w; + int ofs = sb->get_offset().x; + int svofs = (size.height + vofs) / 2 - 1; + Color c = fc; + c.a = 0.2; + + draw_rect(Rect2(ofs, svofs + 1, width, 2 * EDSCALE), c); + int gofs = get_as_ratio() * width; + c.a = 0.9; + Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); + draw_rect(grabber_rect, c); + + grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.position + grabber_rect.size * 0.5; + + bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible()); + if (grabber->is_visible() != display_grabber) { + if (display_grabber) { + grabber->show(); } else { - updown_offset = size.width - sb->get_margin(SIDE_RIGHT) - updown2->get_width(); - } - Color c(1, 1, 1); - if (hover_updown) { - c *= Color(1.2, 1.2, 1.2); - } - draw_texture(updown2, Vector2(updown_offset, updown_vofs), c); - if (grabber->is_visible()) { grabber->hide(); } - } else if (!hide_slider) { - int grabber_w = 4 * EDSCALE; - int width = size.width - sb->get_minimum_size().width - grabber_w; - int ofs = sb->get_offset().x; - int svofs = (size.height + vofs) / 2 - 1; - Color c = fc; - c.a = 0.2; - - draw_rect(Rect2(ofs, svofs + 1, width, 2 * EDSCALE), c); - int gofs = get_as_ratio() * width; - c.a = 0.9; - Rect2 grabber_rect = Rect2(ofs + gofs, svofs + 1, grabber_w, 2 * EDSCALE); - draw_rect(grabber_rect, c); - - grabbing_spinner_mouse_pos = get_global_position() + grabber_rect.position + grabber_rect.size * 0.5; - - bool display_grabber = (mouse_over_spin || mouse_over_grabber) && !grabbing_spinner && !(value_input_popup && value_input_popup->is_visible()); - if (grabber->is_visible() != display_grabber) { - if (display_grabber) { - grabber->show(); - } else { - grabber->hide(); - } - } - - if (display_grabber) { - Ref<Texture2D> grabber_tex; - if (mouse_over_grabber) { - grabber_tex = get_theme_icon(SNAME("grabber_highlight"), SNAME("HSlider")); - } else { - grabber_tex = get_theme_icon(SNAME("grabber"), SNAME("HSlider")); - } + } - if (grabber->get_texture() != grabber_tex) { - grabber->set_texture(grabber_tex); - } + if (display_grabber) { + Ref<Texture2D> grabber_tex; + if (mouse_over_grabber) { + grabber_tex = get_theme_icon(SNAME("grabber_highlight"), SNAME("HSlider")); + } else { + grabber_tex = get_theme_icon(SNAME("grabber"), SNAME("HSlider")); + } - Vector2 scale = get_global_transform_with_canvas().get_scale(); - grabber->set_scale(scale); - grabber->set_size(Size2(0, 0)); - grabber->set_position(get_global_position() + (grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5) * scale); + if (grabber->get_texture() != grabber_tex) { + grabber->set_texture(grabber_tex); + } - if (mousewheel_over_grabber) { - Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); - } + Vector2 scale = get_global_transform_with_canvas().get_scale(); + grabber->set_scale(scale); + grabber->set_size(Size2(0, 0)); + grabber->set_position(get_global_position() + (grabber_rect.position + grabber_rect.size * 0.5 - grabber->get_size() * 0.5) * scale); - grabber_range = width; + if (mousewheel_over_grabber) { + Input::get_singleton()->warp_mouse_position(grabber->get_position() + grabber_rect.size); } + + grabber_range = width; } } +} - if (p_what == NOTIFICATION_MOUSE_ENTER) { - mouse_over_spin = true; - update(); - } - if (p_what == NOTIFICATION_MOUSE_EXIT) { - mouse_over_spin = false; - update(); - } - if (p_what == NOTIFICATION_FOCUS_ENTER) { - if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { - _focus_entered(); - } - value_input_just_closed = false; +void EditorSpinSlider::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: + case NOTIFICATION_THEME_CHANGED: + _update_value_input_stylebox(); + break; + + case NOTIFICATION_DRAW: + _draw_spin_slider(); + break; + + case NOTIFICATION_WM_WINDOW_FOCUS_IN: + case NOTIFICATION_WM_WINDOW_FOCUS_OUT: + case NOTIFICATION_EXIT_TREE: + if (grabbing_spinner) { + grabber->hide(); + Input::get_singleton()->set_mouse_mode(Input::MOUSE_MODE_VISIBLE); + grabbing_spinner = false; + grabbing_spinner_attempt = false; + } + break; + + case NOTIFICATION_MOUSE_ENTER: + mouse_over_spin = true; + update(); + break; + case NOTIFICATION_MOUSE_EXIT: + mouse_over_spin = false; + update(); + break; + case NOTIFICATION_FOCUS_ENTER: + if ((Input::get_singleton()->is_action_pressed("ui_focus_next") || Input::get_singleton()->is_action_pressed("ui_focus_prev")) && !value_input_just_closed) { + _focus_entered(); + } + value_input_just_closed = false; + break; } } @@ -555,8 +564,6 @@ void EditorSpinSlider::_bind_methods() { ClassDB::bind_method(D_METHOD("set_flat", "flat"), &EditorSpinSlider::set_flat); ClassDB::bind_method(D_METHOD("is_flat"), &EditorSpinSlider::is_flat); - ClassDB::bind_method(D_METHOD("_gui_input"), &EditorSpinSlider::_gui_input); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "label"), "set_label", "get_label"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "read_only"), "set_read_only", "is_read_only"); @@ -567,8 +574,10 @@ void EditorSpinSlider::_ensure_input_popup() { if (value_input_popup) { return; } + value_input_popup = memnew(Popup); add_child(value_input_popup); + value_input = memnew(LineEdit); value_input_popup->add_child(value_input); value_input_popup->set_wrap_controls(true); @@ -576,6 +585,7 @@ void EditorSpinSlider::_ensure_input_popup() { value_input_popup->connect("popup_hide", callable_mp(this, &EditorSpinSlider::_value_input_closed)); value_input->connect("text_submitted", callable_mp(this, &EditorSpinSlider::_value_input_submitted)); value_input->connect("focus_exited", callable_mp(this, &EditorSpinSlider::_value_focus_exited)); + if (is_inside_tree()) { _update_value_input_stylebox(); } diff --git a/editor/editor_spin_slider.h b/editor/editor_spin_slider.h index 5b99f88505..1bf8e8eef9 100644 --- a/editor/editor_spin_slider.h +++ b/editor/editor_spin_slider.h @@ -81,10 +81,11 @@ class EditorSpinSlider : public Range { void _update_value_input_stylebox(); void _ensure_input_popup(); + void _draw_spin_slider(); protected: void _notification(int p_what); - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; static void _bind_methods(); void _grabber_mouse_entered(); void _grabber_mouse_exited(); diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index fe6c081922..8c348731d6 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -219,6 +219,7 @@ void editor_register_and_generate_icons(Ref<Theme> p_theme, bool p_dark_theme = exceptions.insert("DefaultProjectIcon"); exceptions.insert("GuiChecked"); exceptions.insert("GuiRadioChecked"); + exceptions.insert("GuiIndeterminate"); exceptions.insert("GuiCloseCustomizable"); exceptions.insert("GuiGraphNodePort"); exceptions.insert("GuiResizer"); @@ -595,6 +596,11 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_stylebox("panel", "PanelContainer", style_menu); theme->set_stylebox("MenuPanel", "EditorStyles", style_menu); + // CanvasItem Editor + Ref<StyleBoxFlat> style_canvas_editor_info = make_flat_stylebox(Color(0.0, 0.0, 0.0, 0.2)); + style_canvas_editor_info->set_expand_margin_size_all(4 * EDSCALE); + theme->set_stylebox("CanvasItemInfoOverlay", "EditorStyles", style_canvas_editor_info); + // Script Editor theme->set_stylebox("ScriptEditorPanel", "EditorStyles", make_empty_stylebox(default_margin_size, 0, default_margin_size, default_margin_size)); theme->set_stylebox("ScriptEditor", "EditorStyles", make_empty_stylebox(0, 0, 0, 0)); @@ -812,6 +818,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // Tree theme->set_icon("checked", "Tree", theme->get_icon("GuiChecked", "EditorIcons")); + theme->set_icon("indeterminate", "Tree", theme->get_icon("GuiIndeterminate", "EditorIcons")); theme->set_icon("unchecked", "Tree", theme->get_icon("GuiUnchecked", "EditorIcons")); theme->set_icon("arrow", "Tree", theme->get_icon("GuiTreeArrowDown", "EditorIcons")); theme->set_icon("arrow_collapsed", "Tree", theme->get_icon("GuiTreeArrowRight", "EditorIcons")); @@ -1051,19 +1058,17 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_constant("line_spacing", "TextEdit", 4 * EDSCALE); // CodeEdit + theme->set_font("font", "CodeEdit", theme->get_font("source", "EditorFonts")); + theme->set_font_size("font_size", "CodeEdit", theme->get_font_size("source_size", "EditorFonts")); theme->set_stylebox("normal", "CodeEdit", style_widget); theme->set_stylebox("focus", "CodeEdit", style_widget_hover); theme->set_stylebox("read_only", "CodeEdit", style_widget_disabled); - theme->set_constant("side_margin", "TabContainer", 0); theme->set_icon("tab", "CodeEdit", theme->get_icon("GuiTab", "EditorIcons")); theme->set_icon("space", "CodeEdit", theme->get_icon("GuiSpace", "EditorIcons")); theme->set_icon("folded", "CodeEdit", theme->get_icon("GuiTreeArrowRight", "EditorIcons")); theme->set_icon("can_fold", "CodeEdit", theme->get_icon("GuiTreeArrowDown", "EditorIcons")); theme->set_icon("executing_line", "CodeEdit", theme->get_icon("MainPlay", "EditorIcons")); - theme->set_color("font_color", "CodeEdit", font_color); - theme->set_color("caret_color", "CodeEdit", font_color); - theme->set_color("selection_color", "CodeEdit", selection_color); - theme->set_constant("line_spacing", "CodeEdit", 4 * EDSCALE); + theme->set_constant("line_spacing", "CodeEdit", EDITOR_DEF("text_editor/appearance/whitespace/line_spacing", 6)); // H/VSplitContainer theme->set_stylebox("bg", "VSplitContainer", make_stylebox(theme->get_icon("GuiVsplitBg", "EditorIcons"), 1, 1, 1, 1)); @@ -1356,7 +1361,7 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { theme->set_constant("label_width", "ColorPicker", 10 * EDSCALE); theme->set_icon("screen_picker", "ColorPicker", theme->get_icon("ColorPick", "EditorIcons")); theme->set_icon("add_preset", "ColorPicker", theme->get_icon("Add", "EditorIcons")); - theme->set_icon("preset_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); + theme->set_icon("sample_bg", "ColorPicker", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); theme->set_icon("overbright_indicator", "ColorPicker", theme->get_icon("OverbrightIndicator", "EditorIcons")); theme->set_icon("bar_arrow", "ColorPicker", theme->get_icon("ColorPickerBarArrow", "EditorIcons")); theme->set_icon("picker_cursor", "ColorPicker", theme->get_icon("PickerCursor", "EditorIcons")); @@ -1364,6 +1369,13 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { // ColorPickerButton theme->set_icon("bg", "ColorPickerButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); + // ColorPresetButton + Ref<StyleBoxFlat> preset_sb = make_flat_stylebox(Color(1, 1, 1), 2, 2, 2, 2, 2); + preset_sb->set_anti_aliased(false); + theme->set_stylebox("preset_fg", "ColorPresetButton", preset_sb); + theme->set_icon("preset_bg", "ColorPresetButton", theme->get_icon("GuiMiniCheckerboard", "EditorIcons")); + theme->set_icon("overbright_indicator", "ColorPresetButton", theme->get_icon("OverbrightIndicator", "EditorIcons")); + // Information on 3D viewport Ref<StyleBoxFlat> style_info_3d_viewport = style_default->duplicate(); style_info_3d_viewport->set_bg_color(style_info_3d_viewport->get_bg_color() * Color(1, 1, 1, 0.5)); @@ -1435,58 +1447,80 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) { EditorSettings *setting = EditorSettings::get_singleton(); String text_editor_color_theme = setting->get("text_editor/theme/color_theme"); if (text_editor_color_theme == "Default") { - setting->set_initial_value("text_editor/highlighting/symbol_color", symbol_color, true); - setting->set_initial_value("text_editor/highlighting/keyword_color", keyword_color, true); - setting->set_initial_value("text_editor/highlighting/control_flow_keyword_color", control_flow_keyword_color, true); - setting->set_initial_value("text_editor/highlighting/base_type_color", basetype_color, true); - setting->set_initial_value("text_editor/highlighting/engine_type_color", type_color, true); - setting->set_initial_value("text_editor/highlighting/user_type_color", usertype_color, true); - setting->set_initial_value("text_editor/highlighting/comment_color", comment_color, true); - setting->set_initial_value("text_editor/highlighting/string_color", string_color, true); - setting->set_initial_value("text_editor/highlighting/background_color", te_background_color, true); - setting->set_initial_value("text_editor/highlighting/completion_background_color", completion_background_color, true); - setting->set_initial_value("text_editor/highlighting/completion_selected_color", completion_selected_color, true); - setting->set_initial_value("text_editor/highlighting/completion_existing_color", completion_existing_color, true); - setting->set_initial_value("text_editor/highlighting/completion_scroll_color", completion_scroll_color, true); - setting->set_initial_value("text_editor/highlighting/completion_font_color", completion_font_color, true); - setting->set_initial_value("text_editor/highlighting/text_color", text_color, true); - setting->set_initial_value("text_editor/highlighting/line_number_color", line_number_color, true); - setting->set_initial_value("text_editor/highlighting/safe_line_number_color", safe_line_number_color, true); - setting->set_initial_value("text_editor/highlighting/caret_color", caret_color, true); - setting->set_initial_value("text_editor/highlighting/caret_background_color", caret_background_color, true); - setting->set_initial_value("text_editor/highlighting/text_selected_color", text_selected_color, true); - setting->set_initial_value("text_editor/highlighting/selection_color", selection_color, true); - setting->set_initial_value("text_editor/highlighting/brace_mismatch_color", brace_mismatch_color, true); - setting->set_initial_value("text_editor/highlighting/current_line_color", current_line_color, true); - setting->set_initial_value("text_editor/highlighting/line_length_guideline_color", line_length_guideline_color, true); - setting->set_initial_value("text_editor/highlighting/word_highlighted_color", word_highlighted_color, true); - setting->set_initial_value("text_editor/highlighting/number_color", number_color, true); - setting->set_initial_value("text_editor/highlighting/function_color", function_color, true); - setting->set_initial_value("text_editor/highlighting/member_variable_color", member_variable_color, true); - setting->set_initial_value("text_editor/highlighting/mark_color", mark_color, true); - setting->set_initial_value("text_editor/highlighting/bookmark_color", bookmark_color, true); - setting->set_initial_value("text_editor/highlighting/breakpoint_color", breakpoint_color, true); - setting->set_initial_value("text_editor/highlighting/executing_line_color", executing_line_color, true); - setting->set_initial_value("text_editor/highlighting/code_folding_color", code_folding_color, true); - setting->set_initial_value("text_editor/highlighting/search_result_color", search_result_color, true); - setting->set_initial_value("text_editor/highlighting/search_result_border_color", search_result_border_color, true); + setting->set_initial_value("text_editor/theme/highlighting/symbol_color", symbol_color, true); + setting->set_initial_value("text_editor/theme/highlighting/keyword_color", keyword_color, true); + setting->set_initial_value("text_editor/theme/highlighting/control_flow_keyword_color", control_flow_keyword_color, true); + setting->set_initial_value("text_editor/theme/highlighting/base_type_color", basetype_color, true); + setting->set_initial_value("text_editor/theme/highlighting/engine_type_color", type_color, true); + setting->set_initial_value("text_editor/theme/highlighting/user_type_color", usertype_color, true); + setting->set_initial_value("text_editor/theme/highlighting/comment_color", comment_color, true); + setting->set_initial_value("text_editor/theme/highlighting/string_color", string_color, true); + setting->set_initial_value("text_editor/theme/highlighting/background_color", te_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_background_color", completion_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_selected_color", completion_selected_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_existing_color", completion_existing_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_scroll_color", completion_scroll_color, true); + setting->set_initial_value("text_editor/theme/highlighting/completion_font_color", completion_font_color, true); + setting->set_initial_value("text_editor/theme/highlighting/text_color", text_color, true); + setting->set_initial_value("text_editor/theme/highlighting/line_number_color", line_number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/safe_line_number_color", safe_line_number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/caret_color", caret_color, true); + setting->set_initial_value("text_editor/theme/highlighting/caret_background_color", caret_background_color, true); + setting->set_initial_value("text_editor/theme/highlighting/text_selected_color", text_selected_color, true); + setting->set_initial_value("text_editor/theme/highlighting/selection_color", selection_color, true); + setting->set_initial_value("text_editor/theme/highlighting/brace_mismatch_color", brace_mismatch_color, true); + setting->set_initial_value("text_editor/theme/highlighting/current_line_color", current_line_color, true); + setting->set_initial_value("text_editor/theme/highlighting/line_length_guideline_color", line_length_guideline_color, true); + setting->set_initial_value("text_editor/theme/highlighting/word_highlighted_color", word_highlighted_color, true); + setting->set_initial_value("text_editor/theme/highlighting/number_color", number_color, true); + setting->set_initial_value("text_editor/theme/highlighting/function_color", function_color, true); + setting->set_initial_value("text_editor/theme/highlighting/member_variable_color", member_variable_color, true); + setting->set_initial_value("text_editor/theme/highlighting/mark_color", mark_color, true); + setting->set_initial_value("text_editor/theme/highlighting/bookmark_color", bookmark_color, true); + setting->set_initial_value("text_editor/theme/highlighting/breakpoint_color", breakpoint_color, true); + setting->set_initial_value("text_editor/theme/highlighting/executing_line_color", executing_line_color, true); + setting->set_initial_value("text_editor/theme/highlighting/code_folding_color", code_folding_color, true); + setting->set_initial_value("text_editor/theme/highlighting/search_result_color", search_result_color, true); + setting->set_initial_value("text_editor/theme/highlighting/search_result_border_color", search_result_border_color, true); } else if (text_editor_color_theme == "Godot 2") { setting->load_text_editor_theme(); } + // Now theme is loaded, apply it to CodeEdit. + theme->set_color("background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/background_color")); + theme->set_color("completion_background_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_background_color")); + theme->set_color("completion_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_selected_color")); + theme->set_color("completion_existing_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_existing_color")); + theme->set_color("completion_scroll_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_scroll_color")); + theme->set_color("completion_font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/completion_font_color")); + theme->set_color("font_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_color")); + theme->set_color("line_number_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_number_color")); + theme->set_color("caret_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/caret_color")); + theme->set_color("font_selected_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/text_selected_color")); + theme->set_color("selection_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/selection_color")); + theme->set_color("brace_mismatch_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/brace_mismatch_color")); + theme->set_color("current_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/current_line_color")); + theme->set_color("line_length_guideline_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/line_length_guideline_color")); + theme->set_color("word_highlighted_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/word_highlighted_color")); + theme->set_color("bookmark_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/bookmark_color")); + theme->set_color("breakpoint_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/breakpoint_color")); + theme->set_color("executing_line_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/executing_line_color")); + theme->set_color("code_folding_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/code_folding_color")); + theme->set_color("search_result_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_color")); + theme->set_color("search_result_border_color", "CodeEdit", EDITOR_GET("text_editor/theme/highlighting/search_result_border_color")); + return theme; } Ref<Theme> create_custom_theme(const Ref<Theme> p_theme) { - Ref<Theme> theme; + Ref<Theme> theme = create_editor_theme(p_theme); - const String custom_theme = EditorSettings::get_singleton()->get("interface/theme/custom_theme"); - if (custom_theme != "") { - theme = ResourceLoader::load(custom_theme); - } - - if (!theme.is_valid()) { - theme = create_editor_theme(p_theme); + const String custom_theme_path = EditorSettings::get_singleton()->get("interface/theme/custom_theme"); + if (custom_theme_path != "") { + Ref<Theme> custom_theme = ResourceLoader::load(custom_theme_path); + if (custom_theme.is_valid()) { + theme->merge_with(custom_theme); + } } return theme; diff --git a/editor/editor_translation_parser.cpp b/editor/editor_translation_parser.cpp index 27d428e682..df47b2d988 100644 --- a/editor/editor_translation_parser.cpp +++ b/editor/editor_translation_parser.cpp @@ -38,15 +38,10 @@ EditorTranslationParser *EditorTranslationParser::singleton = nullptr; Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural) { - if (!get_script_instance()) { - return ERR_UNAVAILABLE; - } - - if (get_script_instance()->has_method("_parse_file")) { - Array ids; - Array ids_ctx_plural; - get_script_instance()->call("_parse_file", p_path, ids, ids_ctx_plural); + Array ids; + Array ids_ctx_plural; + if (GDVIRTUAL_CALL(_parse_file, p_path, ids, ids_ctx_plural)) { // Add user's extracted translatable messages. for (int i = 0; i < ids.size(); i++) { r_ids->append(ids[i]); @@ -71,12 +66,8 @@ Error EditorTranslationParserPlugin::parse_file(const String &p_path, Vector<Str } void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_extensions) const { - if (!get_script_instance()) { - return; - } - - if (get_script_instance()->has_method("_get_recognized_extensions")) { - Array extensions = get_script_instance()->call("_get_recognized_extensions"); + Vector<String> extensions; + if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) { for (int i = 0; i < extensions.size(); i++) { r_extensions->push_back(extensions[i]); } @@ -86,8 +77,8 @@ void EditorTranslationParserPlugin::get_recognized_extensions(List<String> *r_ex } void EditorTranslationParserPlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::NIL, "_parse_file", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::ARRAY, "msgids"), PropertyInfo(Variant::ARRAY, "msgids_context_plural"))); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); + GDVIRTUAL_BIND(_parse_file, "path", "msgids", "msgids_context_plural"); + GDVIRTUAL_BIND(_get_recognized_extensions); } ///////////////////////// diff --git a/editor/editor_translation_parser.h b/editor/editor_translation_parser.h index 7013bbb8c4..242ba33b55 100644 --- a/editor/editor_translation_parser.h +++ b/editor/editor_translation_parser.h @@ -32,7 +32,9 @@ #define EDITOR_TRANSLATION_PARSER_H #include "core/error/error_list.h" +#include "core/object/gdvirtual.gen.inc" #include "core/object/ref_counted.h" +#include "core/object/script_language.h" class EditorTranslationParserPlugin : public RefCounted { GDCLASS(EditorTranslationParserPlugin, RefCounted); @@ -40,6 +42,9 @@ class EditorTranslationParserPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL3(_parse_file, String, Array, Array) + GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + public: virtual Error parse_file(const String &p_path, Vector<String> *r_ids, Vector<Vector<String>> *r_ids_ctx_plural); virtual void get_recognized_extensions(List<String> *r_extensions) const; diff --git a/editor/icons/GridLayout.svg b/editor/icons/GridLayout.svg index 71ad504477..f05bc239a9 100644 --- a/editor/icons/GridLayout.svg +++ b/editor/icons/GridLayout.svg @@ -1 +1 @@ -<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m14 2.1992188v2.6152343l-2.625 1.3125v-2.6152343zm-12 4.0644531 2.625 1.3125v2.5507811l-2.625-1.3124999zm12 0v2.5507812l-2.625 1.3124999v-2.5507811zm-8 1.4550781h4v2.640625h-4zm-4 2.560547 2.625 1.3125v2.521484l-2.625-1.3125zm12 0v2.521484l-2.625 1.3125v-2.521484zm-8 1.455078h4v2.640625h-4zm1.7014535-8.109375h2.2985465v2.734375h-4.15625s-.7487346.647119-.8746377.640625c-.1310411-.0067594-1.5097373-1.4558594-1.5097373-1.4558594l-1.459375-.7296875v-2.6152343l.068419.034223s.026411-.4573464.062111-.6760553c.0346282-.2121439.1970747-.59225724.1970747-.59225724l-1.0483078-.52372301c-.0795772-.04012218-.1668141-.06276382-.2558594-.06640625-.35427845-.01325803-.64865004.27047362-.6484375.625v12c.00021484.236623.13402736.45284.34570312.558594l3.99999998 2c.086686.043505.1823067.06624.2792969.066406h6c.09699-.000166.192611-.0229.279297-.06641l4-2c.211676-.10575.345488-.321967.345703-.55859v-12c-.000468-.46423753-.488958-.76598317-.904297-.55859375l-3.869141 1.93359375h-2.9709527s.033448.4166167.015891.625c-.029188.3464401-.1950466.625-.1950468.625z" fill="#b05b5b"/><path d="m5 6s-2.21875-2.1616704-2.21875-3.2425057c0-1.0808352 0-2.6072392 2.21875-2.6072392s2.21875 1.526404 2.21875 2.6072392c0 1.0808353-2.21875 3.2425057-2.21875 3.2425057z" fill="#fff" fill-opacity=".68627"/></svg> +<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round" stroke-miterlimit="1.5" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><g fill="none" stroke="#e0e0e0" stroke-width="1.3"><path d="m1.87 6.54123h2.917v2.917h-2.917z"/><path d="m6.53582 6.54123h2.917v2.917h-2.917z"/><path d="m11.20164 6.54123h2.917v2.917h-2.917z"/><g transform="matrix(.99999939 .00000001 -.00000005 1.00000043 -.000003 .000001)"><path d="m5.432 1.112-1.95 1.95 1.95 1.95" stroke-linejoin="miter" stroke-miterlimit="10"/><path d="m3.482 3.062h9.386"/></g><g transform="matrix(.99999939 .00000001 -.00000005 1.00000043 0 -.000005)"><path d="m10.731 11.112 1.95 1.95-1.95 1.95" stroke-linejoin="miter" stroke-miterlimit="10"/><path d="m3.294 13.062h9.387"/></g></g></svg> diff --git a/editor/icons/GuiIndeterminate.svg b/editor/icons/GuiIndeterminate.svg new file mode 100644 index 0000000000..79e5d95c9a --- /dev/null +++ b/editor/icons/GuiIndeterminate.svg @@ -0,0 +1 @@ +<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="m3.333 1c-1.288 0-2.333 1.045-2.333 2.333v9.334c0 1.288 1.045 2.333 2.333 2.333h9.334c1.288 0 2.333-1.045 2.333-2.333v-9.334c0-1.288-1.045-2.333-2.333-2.333z" fill="#699ce8" fill-rule="nonzero"/><path d="m3 7h10.058v2.12h-10.058z" fill="#fff" transform="matrix(.99428 0 0 .943295 .017161 .396936)"/></svg> diff --git a/editor/icons/SeparationRayShape2D.svg b/editor/icons/SeparationRayShape2D.svg new file mode 100644 index 0000000000..aa8cee1210 --- /dev/null +++ b/editor/icons/SeparationRayShape2D.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m8 1a1 1 0 0 0 -1 1v9.5859l-1.293-1.293a1 1 0 0 0 -.7207-.29102 1 1 0 0 0 -.69336.29102 1 1 0 0 0 0 1.4141l3 3a1.0001 1.0001 0 0 0 .0039062.003907 1 1 0 0 0 .050781.044921 1.0001 1.0001 0 0 0 .03125.027344 1 1 0 0 0 .048828.035156 1.0001 1.0001 0 0 0 .023438.015625 1 1 0 0 0 .076172.044922 1.0001 1.0001 0 0 0 .0058593.003906 1 1 0 0 0 .013672.007813 1.0001 1.0001 0 0 0 .078125.035156 1 1 0 0 0 .074219.025391 1.0001 1.0001 0 0 0 .025391.009766 1 1 0 0 0 .039062.009765 1.0001 1.0001 0 0 0 .068359.013672 1.0001 1.0001 0 0 0 .097656.011719 1.0001 1.0001 0 0 0 .0078125 0 1 1 0 0 0 .0625.003906 1 1 0 0 0 .015625-.001953 1.0001 1.0001 0 0 0 .083984-.003906 1 1 0 0 0 .015625-.001953 1.0001 1.0001 0 0 0 .083984-.013672 1.0001 1.0001 0 0 0 .052734-.013672 1 1 0 0 0 .058594-.015625 1.0001 1.0001 0 0 0 .078125-.029297 1 1 0 0 0 .013672-.00586 1.0001 1.0001 0 0 0 .076172-.037109 1 1 0 0 0 .013672-.007812 1.0001 1.0001 0 0 0 .072266-.044922 1 1 0 0 0 .011719-.007813 1.0001 1.0001 0 0 0 .068359-.052734 1 1 0 0 0 .011719-.009766 1.0001 1.0001 0 0 0 .050781-.046875l.0097657-.011719 2.9902-2.9883a1 1 0 0 0 0-1.4141 1 1 0 0 0 -1.4141 0l-1.293 1.293v-9.5859a1 1 0 0 0 -1-1z" fill="#68b6ff" fill-rule="evenodd"/></svg> diff --git a/editor/icons/SeparationRayShape3D.svg b/editor/icons/SeparationRayShape3D.svg new file mode 100644 index 0000000000..44d32fe83b --- /dev/null +++ b/editor/icons/SeparationRayShape3D.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill-rule="evenodd"><path d="m8 1-6 5 4 2.666v4.334l2 2v-5-2z" fill="#a2d2ff"/><path d="m8 1v7 2l-2-1.334v1.334l2 1.5v3.5l2-2v-4.334l4-2.666z" fill="#2998ff"/></g></svg> diff --git a/editor/icons/VisualScriptComment.svg b/editor/icons/VisualScriptComment.svg new file mode 100644 index 0000000000..3887853b58 --- /dev/null +++ b/editor/icons/VisualScriptComment.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m3 1v2h-2v2h2v4h-2v2h2v2h2v-2h4v2h2v-2h2v-2h-2v-4h2v-2h-2v-2h-2v2h-4v-2zm2 4h4v4h-4z" fill="#e0e0e0"/></svg> diff --git a/editor/icons/VisualScriptExpression.svg b/editor/icons/VisualScriptExpression.svg new file mode 100644 index 0000000000..d6a3c2d9a8 --- /dev/null +++ b/editor/icons/VisualScriptExpression.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#e0e0e0"><path d="m4.859536 3.0412379c-2.0539867 0-3.7190721 1.6650852-3.7190721 3.719072v6.1984521h2.4793814v-2.479381h2.4793814v-2.4793803h-2.4793814v-1.2396908c0-.6846622.5550285-1.2396907 1.2396907-1.2396907h1.2396907v-2.4793813z"/><path d="m7.5889175 3.0000003 2.5000005 4.9999997-2.5000005 5h2.5000005l1.135249-2.727 1.36475 2.727h2.499999l-2.499999-5 2.499999-4.9999997h-2.499999l-1.13525 2.7269998-1.364749-2.7269998zm7.4999985 9.9999997v-6.25z"/></g></svg> diff --git a/editor/icons/VisualShaderGraphTextureUniform.svg b/editor/icons/VisualShaderGraphTextureUniform.svg new file mode 100644 index 0000000000..ed9e084fd3 --- /dev/null +++ b/editor/icons/VisualShaderGraphTextureUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm0 2h10v10h-10zm9 2-4 4-2-2-2 3h8z" fill="#eae068"/></svg> diff --git a/editor/icons/VisualShaderNodeBooleanUniform.svg b/editor/icons/VisualShaderNodeBooleanUniform.svg new file mode 100644 index 0000000000..b4a7043fb3 --- /dev/null +++ b/editor/icons/VisualShaderNodeBooleanUniform.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><path d="m2 .02734375c-1.108 0-2 .892-2 2.00000005v1.9726562h2v2a3 3 0 0 1 2.5 1.3457031 3 3 0 0 1 2.5-1.3457031 3 3 0 0 1 2 .7675781 3 3 0 0 1 2-.7675781 3 3 0 0 1 2 .7695312v-2.7695312h2v5a1 1 0 0 0 1 1v-7.9726562c0-1.10800005-.892-2.00000005-2-2.00000005zm0 7.97265625v2a1 1 0 0 0 1-1 1 1 0 0 0 -1-1zm5 0a1 1 0 0 0 -1 1 1 1 0 0 0 1 1 1 1 0 0 0 1-1 1 1 0 0 0 -1-1zm4 0a1 1 0 0 0 -1 1 1 1 0 0 0 1 1 1 1 0 0 0 1-1 1 1 0 0 0 -1-1zm-6.5 2.654297a3 3 0 0 1 -2.5 1.345703h-2v2.027344c0 1.108.892 2 2 2h12c1.108 0 2-.892 2-2v-2.027344a3 3 0 0 1 -2.5-1.345703 3 3 0 0 1 -2.5 1.345703 3 3 0 0 1 -2-.767578 3 3 0 0 1 -2 .767578 3 3 0 0 1 -2.5-1.345703z" fill="#6f91f0" stroke-linecap="square" stroke-opacity=".75" stroke-width="2"/></svg> diff --git a/editor/icons/VisualShaderNodeColorConstant.svg b/editor/icons/VisualShaderNodeColorConstant.svg new file mode 100644 index 0000000000..cbc5b3a471 --- /dev/null +++ b/editor/icons/VisualShaderNodeColorConstant.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill-opacity=".392157" transform="translate(0 -1038.3622)"><path d="m7 1039.3622a4.0000172 4.0000172 0 0 0 -4 4 4.0000172 4.0000172 0 0 0 .03906.5195 4.0000172 4.0000172 0 0 0 -2.039062 3.4805 4.0000172 4.0000172 0 0 0 4 4 4.0000172 4.0000172 0 0 0 1.998047-.541 4.0000172 4.0000172 0 0 0 2.001953.541 4.0000172 4.0000172 0 0 0 4-4 4.0000172 4.0000172 0 0 0 -2.037109-3.4824 4.0000172 4.0000172 0 0 0 .03711-.5176 4.0000172 4.0000172 0 0 0 -4-4z" fill="#fff"/><path d="m7 1040.3622a3 3 0 0 0 -3 3 3 3 0 0 0 .210937 1.1055 3 3 0 0 0 -2.210937 2.8945 3 3 0 0 0 3 3 3 3 0 0 0 2-.7676 3 3 0 0 0 2 .7676 3 3 0 0 0 3-3 3 3 0 0 0 -2.2148438-2.8906 3 3 0 0 0 .2148438-1.1094 3 3 0 0 0 -3-3z" fill="#fff"/><circle cx="7" cy="1043.3622" fill="#f00" r="3"/><circle cx="5" cy="1047.3622" fill="#00f" r="3"/><circle cx="9" cy="1047.3622" fill="#0f0" r="3"/><circle cx="7" cy="1043.3622" fill="#f00" r="3"/><circle cx="5" cy="1047.3622" fill="#00f" r="3"/><circle cx="9" cy="1047.3622" fill="#0f0" r="3"/></g></svg> diff --git a/editor/icons/VisualShaderNodeColorOp.svg b/editor/icons/VisualShaderNodeColorOp.svg new file mode 100644 index 0000000000..7b6cd8149b --- /dev/null +++ b/editor/icons/VisualShaderNodeColorOp.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1038.3622)"><g fill="#fff"><path d="m4 1050.3622h6v-10h-6z" fill-rule="evenodd" stroke="#fff" stroke-linejoin="round" stroke-width="2"/><path d="m1 1041.3622h2v2h-2z"/><path d="m1 1047.3622h2v2h-2z"/><path d="m11 1044.3622h2v2h-2z"/></g><g fill-opacity=".862745"><path d="m5 1041.3622h4v2h-4z" fill="#ff4646"/><path d="m5 1044.3622h4v2h-4z" fill="#46ff46"/><path d="m5 1047.3622h4v2h-4z" fill="#4646ff"/></g></g></svg> diff --git a/editor/icons/VisualShaderNodeColorUniform.svg b/editor/icons/VisualShaderNodeColorUniform.svg new file mode 100644 index 0000000000..ce89b16583 --- /dev/null +++ b/editor/icons/VisualShaderNodeColorUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1038.3622)"><path d="m2 1038.3622c-1.10457 0-2 .8954-2 2v10c0 1.1046.89543 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2z" fill="#fff"/><g fill-opacity=".392157"><path d="m7 2a3 3 0 0 0 -3 3 3 3 0 0 0 .2109375 1.1054688 3 3 0 0 0 -2.2109375 2.8945312 3 3 0 0 0 3 3 3 3 0 0 0 2-.767578 3 3 0 0 0 2 .767578 3 3 0 0 0 3-3 3 3 0 0 0 -2.2148438-2.890625 3 3 0 0 0 .2148438-1.109375 3 3 0 0 0 -3-3z" fill="#fff" transform="translate(0 1038.3622)"/><circle cx="7" cy="1043.3622" fill="#f00" r="3"/><circle cx="5" cy="1047.3622" fill="#00f" r="3"/><circle cx="9" cy="1047.3622" fill="#0f0" r="3"/><circle cx="7" cy="1043.3622" fill="#f00" r="3"/><circle cx="5" cy="1047.3622" fill="#00f" r="3"/><circle cx="9" cy="1047.3622" fill="#0f0" r="3"/></g></g></svg> diff --git a/editor/icons/VisualShaderNodeComment.svg b/editor/icons/VisualShaderNodeComment.svg new file mode 100644 index 0000000000..3887853b58 --- /dev/null +++ b/editor/icons/VisualShaderNodeComment.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m3 1v2h-2v2h2v4h-2v2h2v2h2v-2h4v2h2v-2h2v-2h-2v-4h2v-2h-2v-2h-2v2h-4v-2zm2 4h4v4h-4z" fill="#e0e0e0"/></svg> diff --git a/editor/icons/VisualShaderNodeCubemap.svg b/editor/icons/VisualShaderNodeCubemap.svg new file mode 100644 index 0000000000..fecb4d1287 --- /dev/null +++ b/editor/icons/VisualShaderNodeCubemap.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m7 3.5136719-2.6894531 1.34375 2.6894531 1.34375 2.6894531-1.34375zm-3.5722656 2.4980469v2.6894531l2.8574218 1.4277341v-2.6874998zm7.1445316 0-2.8574222 1.4296874v2.6874998l2.8574222-1.4277341z" fill="#eac968"/></svg> diff --git a/editor/icons/VisualShaderNodeCubemapUniform.svg b/editor/icons/VisualShaderNodeCubemapUniform.svg new file mode 100644 index 0000000000..e3463de0a2 --- /dev/null +++ b/editor/icons/VisualShaderNodeCubemapUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm4.9726562 2a.71438238.71438238 0 0 1 .3476563.0742188l4.2851565 2.1425781a.71438238.71438238 0 0 1 .394531.640625v4.2851562a.71438238.71438238 0 0 1 -.394531.6386719l-4.2851565 2.142578a.71438238.71438238 0 0 1 -.640625 0l-4.2851563-2.142578a.71438238.71438238 0 0 1 -.3945312-.6386719v-4.2851562a.71438238.71438238 0 0 1 .3945312-.640625l4.2851563-2.1425781a.71438238.71438238 0 0 1 .2929687-.0742188zm.0273438 1.5136719-2.6894531 1.34375 2.6894531 1.34375 2.6894531-1.34375zm-3.5722656 2.4980469v2.6894531l2.8574218 1.4277341v-2.6874998zm7.1445316 0-2.8574222 1.4296874v2.6874998l2.8574222-1.4277341z" fill="#eac968"/></svg> diff --git a/editor/icons/VisualShaderNodeCurveTexture.svg b/editor/icons/VisualShaderNodeCurveTexture.svg new file mode 100644 index 0000000000..c0ee634ca4 --- /dev/null +++ b/editor/icons/VisualShaderNodeCurveTexture.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1038.3622)"><path d="m2 1049.3622c8 0 9 0 9-9" fill="none" stroke="#f6f6f6" stroke-linecap="round" stroke-width="2"/><path d="m11 4a2 2 0 0 0 -2 2 2 2 0 0 0 2 2 2 2 0 0 0 2-2 2 2 0 0 0 -2-2zm-5 5a2 2 0 0 0 -2 2 2 2 0 0 0 2 2 2 2 0 0 0 2-2 2 2 0 0 0 -2-2z" fill="#68d0ea" transform="translate(0 1038.3622)"/></g></svg> diff --git a/editor/icons/VisualShaderNodeCurveXYZTexture.svg b/editor/icons/VisualShaderNodeCurveXYZTexture.svg new file mode 100644 index 0000000000..c0ee634ca4 --- /dev/null +++ b/editor/icons/VisualShaderNodeCurveXYZTexture.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1038.3622)"><path d="m2 1049.3622c8 0 9 0 9-9" fill="none" stroke="#f6f6f6" stroke-linecap="round" stroke-width="2"/><path d="m11 4a2 2 0 0 0 -2 2 2 2 0 0 0 2 2 2 2 0 0 0 2-2 2 2 0 0 0 -2-2zm-5 5a2 2 0 0 0 -2 2 2 2 0 0 0 2 2 2 2 0 0 0 2-2 2 2 0 0 0 -2-2z" fill="#68d0ea" transform="translate(0 1038.3622)"/></g></svg> diff --git a/editor/icons/VisualShaderNodeExpression.svg b/editor/icons/VisualShaderNodeExpression.svg new file mode 100644 index 0000000000..8a930d4078 --- /dev/null +++ b/editor/icons/VisualShaderNodeExpression.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#ac73f1"><path d="m4.859536 3.0412379c-2.0539867 0-3.7190721 1.6650852-3.7190721 3.719072v6.1984521h2.4793814v-2.479381h2.4793814v-2.4793803h-2.4793814v-1.2396908c0-.6846622.5550285-1.2396907 1.2396907-1.2396907h1.2396907v-2.4793813z"/><path d="m7.5889175 3.0000003 2.5000005 4.9999997-2.5000005 5h2.5000005l1.135249-2.727 1.36475 2.727h2.499999l-2.499999-5 2.499999-4.9999997h-2.499999l-1.13525 2.7269998-1.364749-2.7269998zm7.4999985 9.9999997v-6.25z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeFloatFunc.svg b/editor/icons/VisualShaderNodeFloatFunc.svg new file mode 100644 index 0000000000..382c4e66af --- /dev/null +++ b/editor/icons/VisualShaderNodeFloatFunc.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill="#cf68ea" transform="translate(0 -1038.3622)"><path d="m6 1042.3622h2v4.999982h-2z"/><path d="m9.0703125 1a3 3 0 0 0 -1.5703125.4023438 3 3 0 0 0 -1.5 2.5976562h2a1 1 0 0 1 1-1 1 1 0 0 1 1 1h2a3 3 0 0 0 -1.5-2.5976562 3 3 0 0 0 -1.4296875-.4023438z" transform="translate(0 1038.3622)"/><path d="m10 1042.3622h2v1.000017h-2z"/><path d="m2 10a3 3 0 0 0 1.5 2.597656 3 3 0 0 0 3 0 3 3 0 0 0 1.5-2.597656h-2a1 1 0 0 1 -1 1 1 1 0 0 1 -1-1z" transform="translate(0 1038.3622)"/><path d="m6-1048.3622h2v1.000017h-2z" transform="scale(1 -1)"/><path d="m4 1044.3622h6v2h-6z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeFloatOp.svg b/editor/icons/VisualShaderNodeFloatOp.svg new file mode 100644 index 0000000000..546ffc148e --- /dev/null +++ b/editor/icons/VisualShaderNodeFloatOp.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill="#cf68ea" transform="translate(0 -1038.3622)"><path d="m4 1c-.5522619.0001-.9999448.4477-1 1v10c.0000552.5523.4477381.9999 1 1h6c.552262-.0001.999945-.4477 1-1v-10c-.000055-.5523-.447738-.9999-1-1zm1 3 4 3-4 3z" fill-rule="evenodd" transform="translate(0 1038.3622)"/><path d="m1 1041.3622h2v2h-2z"/><path d="m1 1047.3622h2v2h-2z"/><path d="m11 1044.3622h2v2h-2z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeFloatUniform.svg b/editor/icons/VisualShaderNodeFloatUniform.svg new file mode 100644 index 0000000000..dda5d098a3 --- /dev/null +++ b/editor/icons/VisualShaderNodeFloatUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-10a2 2 0 0 0 -2-2zm4 2h5v2h-5a1.0000174 1.0000174 0 0 0 -1 1 1.0000174 1.0000174 0 0 0 1 1h2c1.6568542 0 3 1.3431 3 3s-1.3431458 3-3 3h-5v-2h5a1.0000174 1.0000174 0 0 0 1-1 1.0000174 1.0000174 0 0 0 -1-1h-2c-1.6568542 0-3-1.3431-3-3s1.3431458-3 3-3z" fill="#cf68ea"/></svg> diff --git a/editor/icons/VisualShaderNodeGlobalExpression.svg b/editor/icons/VisualShaderNodeGlobalExpression.svg new file mode 100644 index 0000000000..0cafffb152 --- /dev/null +++ b/editor/icons/VisualShaderNodeGlobalExpression.svg @@ -0,0 +1 @@ +<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g fill="#35d4f4"><path d="m4.859536 3.0412379c-2.0539867 0-3.7190721 1.6650852-3.7190721 3.719072v6.1984521h2.4793814v-2.479381h2.4793814v-2.4793803h-2.4793814v-1.2396908c0-.6846622.5550285-1.2396907 1.2396907-1.2396907h1.2396907v-2.4793813z"/><path d="m7.5889175 3.0000003 2.5000005 4.9999997-2.5000005 5h2.5000005l1.135249-2.727 1.36475 2.727h2.499999l-2.499999-5 2.499999-4.9999997h-2.499999l-1.13525 2.7269998-1.364749-2.7269998zm7.4999985 9.9999997v-6.25z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeInput.svg b/editor/icons/VisualShaderNodeInput.svg new file mode 100644 index 0000000000..ec347100d7 --- /dev/null +++ b/editor/icons/VisualShaderNodeInput.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><circle cx="7" cy="7" fill="#f6f6f6" r="6"/></svg> diff --git a/editor/icons/VisualShaderNodeIntFunc.svg b/editor/icons/VisualShaderNodeIntFunc.svg new file mode 100644 index 0000000000..382c4e66af --- /dev/null +++ b/editor/icons/VisualShaderNodeIntFunc.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill="#cf68ea" transform="translate(0 -1038.3622)"><path d="m6 1042.3622h2v4.999982h-2z"/><path d="m9.0703125 1a3 3 0 0 0 -1.5703125.4023438 3 3 0 0 0 -1.5 2.5976562h2a1 1 0 0 1 1-1 1 1 0 0 1 1 1h2a3 3 0 0 0 -1.5-2.5976562 3 3 0 0 0 -1.4296875-.4023438z" transform="translate(0 1038.3622)"/><path d="m10 1042.3622h2v1.000017h-2z"/><path d="m2 10a3 3 0 0 0 1.5 2.597656 3 3 0 0 0 3 0 3 3 0 0 0 1.5-2.597656h-2a1 1 0 0 1 -1 1 1 1 0 0 1 -1-1z" transform="translate(0 1038.3622)"/><path d="m6-1048.3622h2v1.000017h-2z" transform="scale(1 -1)"/><path d="m4 1044.3622h6v2h-6z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeIntOp.svg b/editor/icons/VisualShaderNodeIntOp.svg new file mode 100644 index 0000000000..546ffc148e --- /dev/null +++ b/editor/icons/VisualShaderNodeIntOp.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill="#cf68ea" transform="translate(0 -1038.3622)"><path d="m4 1c-.5522619.0001-.9999448.4477-1 1v10c.0000552.5523.4477381.9999 1 1h6c.552262-.0001.999945-.4477 1-1v-10c-.000055-.5523-.447738-.9999-1-1zm1 3 4 3-4 3z" fill-rule="evenodd" transform="translate(0 1038.3622)"/><path d="m1 1041.3622h2v2h-2z"/><path d="m1 1047.3622h2v2h-2z"/><path d="m11 1044.3622h2v2h-2z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeIntUniform.svg b/editor/icons/VisualShaderNodeIntUniform.svg new file mode 100644 index 0000000000..dda5d098a3 --- /dev/null +++ b/editor/icons/VisualShaderNodeIntUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0a2 2 0 0 0 -2 2v10a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2v-10a2 2 0 0 0 -2-2zm4 2h5v2h-5a1.0000174 1.0000174 0 0 0 -1 1 1.0000174 1.0000174 0 0 0 1 1h2c1.6568542 0 3 1.3431 3 3s-1.3431458 3-3 3h-5v-2h5a1.0000174 1.0000174 0 0 0 1-1 1.0000174 1.0000174 0 0 0 -1-1h-2c-1.6568542 0-3-1.3431-3-3s1.3431458-3 3-3z" fill="#cf68ea"/></svg> diff --git a/editor/icons/VisualShaderNodeTexture2DArrayUniform.svg b/editor/icons/VisualShaderNodeTexture2DArrayUniform.svg new file mode 100644 index 0000000000..ed9e084fd3 --- /dev/null +++ b/editor/icons/VisualShaderNodeTexture2DArrayUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm0 2h10v10h-10zm9 2-4 4-2-2-2 3h8z" fill="#eae068"/></svg> diff --git a/editor/icons/VisualShaderNodeTexture3DUniform.svg b/editor/icons/VisualShaderNodeTexture3DUniform.svg new file mode 100644 index 0000000000..ed9e084fd3 --- /dev/null +++ b/editor/icons/VisualShaderNodeTexture3DUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm0 2h10v10h-10zm9 2-4 4-2-2-2 3h8z" fill="#eae068"/></svg> diff --git a/editor/icons/VisualShaderNodeTextureUniform.svg b/editor/icons/VisualShaderNodeTextureUniform.svg new file mode 100644 index 0000000000..ed9e084fd3 --- /dev/null +++ b/editor/icons/VisualShaderNodeTextureUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm0 2h10v10h-10zm9 2-4 4-2-2-2 3h8z" fill="#eae068"/></svg> diff --git a/editor/icons/VisualShaderNodeTextureUniformTriplanar.svg b/editor/icons/VisualShaderNodeTextureUniformTriplanar.svg new file mode 100644 index 0000000000..ed9e084fd3 --- /dev/null +++ b/editor/icons/VisualShaderNodeTextureUniformTriplanar.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm0 2h10v10h-10zm9 2-4 4-2-2-2 3h8z" fill="#eae068"/></svg> diff --git a/editor/icons/VisualShaderNodeTransformCompose.svg b/editor/icons/VisualShaderNodeTransformCompose.svg new file mode 100644 index 0000000000..6c7b28cda3 --- /dev/null +++ b/editor/icons/VisualShaderNodeTransformCompose.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="1.000747" x2="13.014989" y1="1045.3622" y2="1045.3622"><stop offset="0" stop-color="#b8ea68"/><stop offset="1" stop-color="#ea686c"/></linearGradient><path d="m1.9909808 1039.3524a1.0001 1.0001 0 0 0 -.697265 1.7168l3.2929683 3.293h-2.5859373a1.0001 1.0001 0 1 0 0 2h2.5859373l-3.2929683 3.293a1.0001 1.0001 0 1 0 1.414062 1.414l4.7070313-4.707h4.5859379a1.0001 1.0001 0 1 0 0-2h-4.5859379l-4.7070313-4.707a1.0001 1.0001 0 0 0 -.716797-.3028z" fill="url(#a)" fill-rule="evenodd" transform="translate(0 -1038.3622)"/></svg> diff --git a/editor/icons/VisualShaderNodeTransformDecompose.svg b/editor/icons/VisualShaderNodeTransformDecompose.svg new file mode 100644 index 0000000000..276b3ea7c8 --- /dev/null +++ b/editor/icons/VisualShaderNodeTransformDecompose.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientTransform="matrix(-1 0 0 1 13.999754 1038.3622)" gradientUnits="userSpaceOnUse" x1="1" x2="13.014242" y1="7" y2="7"><stop offset="0" stop-color="#b8ea68"/><stop offset="1" stop-color="#ea686c"/></linearGradient><path d="m12.00952 1039.3524a1.0001 1.0001 0 0 1 .697265 1.7168l-3.2929683 3.293h2.5859373a1.0001 1.0001 0 1 1 0 2h-2.5859373l3.2929683 3.293a1.0001 1.0001 0 1 1 -1.414062 1.414l-4.7070313-4.707h-4.5859377a1.0001 1.0001 0 1 1 0-2h4.5859377l4.7070313-4.707a1.0001 1.0001 0 0 1 .716797-.3028z" fill="url(#a)" fill-rule="evenodd" transform="translate(0 -1038.3622)"/></svg> diff --git a/editor/icons/VisualShaderNodeTransformUniform.svg b/editor/icons/VisualShaderNodeTransformUniform.svg new file mode 100644 index 0000000000..5d3e6977e0 --- /dev/null +++ b/editor/icons/VisualShaderNodeTransformUniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954-2 2v10c0 1.1046.8954305 2 2 2h10c1.104569 0 2-.8954 2-2v-10c0-1.1046-.895431-2-2-2zm-1 1h1 2v1h-2v10h2v1h-2-1v-1-10zm9 0h3v11 1h-3v-1h2v-10h-2zm-.0292969 2a1.0001 1.0001 0 0 1 1.0292969 1v7h-2v-4.5859375l-1.2929688 1.2929687a1.0001 1.0001 0 0 1 -1.4140624 0l-1.2929688-1.2929687v4.5859375h-2v-7a1.0001 1.0001 0 0 1 .984375-.9980469 1.0001 1.0001 0 0 1 .7226562.2910157l2.2929688 2.2929687 2.2929688-2.2929687a1.0001 1.0001 0 0 1 .6777343-.2929688z" fill="#ea686c"/></svg> diff --git a/editor/icons/VisualShaderNodeTransformVecMult.svg b/editor/icons/VisualShaderNodeTransformVecMult.svg new file mode 100644 index 0000000000..fe133b6ffe --- /dev/null +++ b/editor/icons/VisualShaderNodeTransformVecMult.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g transform="translate(0 -1038.3622)"><path d="m9 1042.3622 2 6 2-6" fill="none" stroke="#b8ea68" stroke-linejoin="round" stroke-width="2"/><circle cx="7" cy="1046.3622" fill="#b8ea68" r="1"/><path d="m1 1049.3621v-7l2 3 2-3v7" fill="none" stroke="#ea686c" stroke-linejoin="round" stroke-width="2"/></g></svg> diff --git a/editor/icons/VisualShaderNodeVec3Uniform.svg b/editor/icons/VisualShaderNodeVec3Uniform.svg new file mode 100644 index 0000000000..6e0175230c --- /dev/null +++ b/editor/icons/VisualShaderNodeVec3Uniform.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 0c-1.1045695 0-2 .8954305-2 2v10c0 1.104569.8954305 2 2 2h10c1.104569 0 2-.895431 2-2v-10c0-1.1045695-.895431-2-2-2zm6 0 3 3-3 3v-2h-5v-2h5zm-3.65625 5.6289062.5136719.8574219 2.1425781 3.5703129 2.1425781-3.5703129.5136719-.8574219 1.714844 1.0292969-.513672.8574219-3.0000001 5c-.3885014.647055-1.3263424.647055-1.7148438 0l-3-5-.5136719-.8574219z" fill="#b8ea68"/><path d="m23 0v2h-5v2h5v2l3-3zm-3.65625 5.6289062-1.714844 1.0292969.513672.8574219 3 5c.388501.647056 1.326343.647056 1.714844 0l3-5 .513672-.8574219-1.714844-1.0292969-.513672.8574219-2.142578 3.5703129-2.142578-3.5703129z" fill-rule="evenodd"/></svg> diff --git a/editor/icons/VisualShaderNodeVectorCompose.svg b/editor/icons/VisualShaderNodeVectorCompose.svg new file mode 100644 index 0000000000..8e12ab2ff6 --- /dev/null +++ b/editor/icons/VisualShaderNodeVectorCompose.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientUnits="userSpaceOnUse" x1="1" x2="13.014242" y1="7" y2="7"><stop offset="0" stop-color="#cf68ea"/><stop offset="1" stop-color="#b8ea68"/></linearGradient><path d="m1.9902344.99023438a1.0001 1.0001 0 0 0 -.6972656 1.71679682l3.2929687 3.2929688h-2.5859375a1.0001 1.0001 0 1 0 0 2h2.5859375l-3.2929687 3.292969a1.0001 1.0001 0 1 0 1.4140624 1.414062l4.7070313-4.707031h4.5859375a1.0001 1.0001 0 1 0 0-2h-4.5859375l-4.7070313-4.7070312a1.0001 1.0001 0 0 0 -.7167968-.30273442z" fill="url(#a)" fill-rule="evenodd"/></svg> diff --git a/editor/icons/VisualShaderNodeVectorDecompose.svg b/editor/icons/VisualShaderNodeVectorDecompose.svg new file mode 100644 index 0000000000..4bd2dc2138 --- /dev/null +++ b/editor/icons/VisualShaderNodeVectorDecompose.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><linearGradient id="a" gradientTransform="matrix(-1 0 0 1 13.999754 1038.3622)" gradientUnits="userSpaceOnUse" x1="1" x2="13.014242" y1="7" y2="7"><stop offset="0" stop-color="#cf68ea"/><stop offset="1" stop-color="#b8ea68"/></linearGradient><path d="m12.00952 1039.3524a1.0001 1.0001 0 0 1 .697265 1.7168l-3.2929685 3.293h2.5859375a1.0001 1.0001 0 1 1 0 2h-2.5859375l3.2929685 3.293a1.0001 1.0001 0 1 1 -1.414062 1.414l-4.7070315-4.707h-4.5859375a1.0001 1.0001 0 1 1 0-2h4.5859375l4.7070315-4.707a1.0001 1.0001 0 0 1 .716797-.3028z" fill="url(#a)" fill-rule="evenodd" transform="translate(0 -1038.3622)"/></svg> diff --git a/editor/icons/VisualShaderNodeVectorDistance.svg b/editor/icons/VisualShaderNodeVectorDistance.svg new file mode 100644 index 0000000000..74a46047bf --- /dev/null +++ b/editor/icons/VisualShaderNodeVectorDistance.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m2 1050.3622 10-10" fill="none" stroke="#b8ea68" stroke-linecap="round" stroke-width="2" transform="translate(0 -1038.3622)"/></svg> diff --git a/editor/icons/VisualShaderNodeVectorFunc.svg b/editor/icons/VisualShaderNodeVectorFunc.svg new file mode 100644 index 0000000000..dcd4cee3e4 --- /dev/null +++ b/editor/icons/VisualShaderNodeVectorFunc.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><g fill="#b8ea68" transform="translate(0 -1038.3622)"><path d="m6 1042.3622h2v4.999982h-2z"/><path d="m9.0703125 1a3 3 0 0 0 -1.5703125.4023438 3 3 0 0 0 -1.5 2.5976562h2a1 1 0 0 1 1-1 1 1 0 0 1 1 1h2a3 3 0 0 0 -1.5-2.5976562 3 3 0 0 0 -1.4296875-.4023438z" transform="translate(0 1038.3622)"/><path d="m10 1042.3622h2v1.000017h-2z"/><path d="m2 10a3 3 0 0 0 1.5 2.597656 3 3 0 0 0 3 0 3 3 0 0 0 1.5-2.597656h-2a1 1 0 0 1 -1 1 1 1 0 0 1 -1-1z" transform="translate(0 1038.3622)"/><path d="m6-1048.3622h2v1.000017h-2z" transform="scale(1 -1)"/><path d="m4 1044.3622h6v2h-6z"/></g></svg> diff --git a/editor/icons/VisualShaderNodeVectorLen.svg b/editor/icons/VisualShaderNodeVectorLen.svg new file mode 100644 index 0000000000..71faffdc3f --- /dev/null +++ b/editor/icons/VisualShaderNodeVectorLen.svg @@ -0,0 +1 @@ +<svg height="14" viewBox="0 0 14 14" width="14" xmlns="http://www.w3.org/2000/svg"><path d="m8 1038.3614v2h-5v2h5v2l3-3zm-3.65625 5.6289-1.714844 1.0293.513672.8574 3 5c.388501.647 1.326343.647 1.714844 0l3-5 .513672-.8574-1.714844-1.0293-.513672.8574-2.142578 3.5703-2.142578-3.5703z" fill="#b8ea68" fill-rule="evenodd" transform="translate(0 -1038.3622)"/></svg> diff --git a/editor/icons/LineShape2D.svg b/editor/icons/WorldMarginShape2D.svg index f1dbe97c6f..f1dbe97c6f 100644 --- a/editor/icons/LineShape2D.svg +++ b/editor/icons/WorldMarginShape2D.svg diff --git a/editor/import/collada.cpp b/editor/import/collada.cpp index aa9700716d..b6d0927ce6 100644 --- a/editor/import/collada.cpp +++ b/editor/import/collada.cpp @@ -287,7 +287,7 @@ void Collada::_parse_image(XMLParser &parser) { if (state.version < State::Version(1, 4, 0)) { /* <1.4 */ String path = parser.get_attribute_value("source").strip_edges(); - if (path.find("://") == -1 && path.is_rel_path()) { + if (path.find("://") == -1 && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path image.path = ProjectSettings::get_singleton()->localize_path(state.local_path.get_base_dir().plus_file(path.uri_decode())); } @@ -300,7 +300,7 @@ void Collada::_parse_image(XMLParser &parser) { parser.read(); String path = parser.get_node_data().strip_edges().uri_decode(); - if (path.find("://") == -1 && path.is_rel_path()) { + if (path.find("://") == -1 && path.is_relative_path()) { // path is relative to file being loaded, so convert to a resource path path = ProjectSettings::get_singleton()->localize_path(state.local_path.get_base_dir().plus_file(path)); @@ -960,6 +960,7 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name } else if (section == "vertices") { MeshData::Vertices vert; String id = parser.get_attribute_value("id"); + int last_ref = 0; while (parser.read() == OK) { if (parser.get_node_type() == XMLParser::NODE_ELEMENT) { @@ -967,6 +968,10 @@ void Collada::_parse_mesh_geometry(XMLParser &parser, String p_id, String p_name String semantic = parser.get_attribute_value("semantic"); String source = _uri_to_id(parser.get_attribute_value("source")); + if (semantic == "TEXCOORD") { + semantic = "TEXCOORD" + itos(last_ref++); + } + vert.sources[semantic] = source; COLLADA_PRINT(section + " input semantic: " + semantic + " source: " + source); diff --git a/editor/import/dynamicfont_import_settings.cpp b/editor/import/dynamicfont_import_settings.cpp new file mode 100644 index 0000000000..37ca40287f --- /dev/null +++ b/editor/import/dynamicfont_import_settings.cpp @@ -0,0 +1,1889 @@ +/*************************************************************************/ +/* dynamicfont_import_settings.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "dynamicfont_import_settings.h" + +#include "editor/editor_node.h" +#include "editor/editor_scale.h" + +/*************************************************************************/ +/* Settings data */ +/*************************************************************************/ + +class DynamicFontImportSettingsData : public RefCounted { + GDCLASS(DynamicFontImportSettingsData, RefCounted) + friend class DynamicFontImportSettings; + + Map<StringName, Variant> settings; + Map<StringName, Variant> defaults; + List<ResourceImporter::ImportOption> options; + DynamicFontImportSettings *owner = nullptr; + + bool _set(const StringName &p_name, const Variant &p_value) { + if (defaults.has(p_name) && defaults[p_name] == p_value) { + settings.erase(p_name); + } else { + settings[p_name] = p_value; + } + return true; + } + + bool _get(const StringName &p_name, Variant &r_ret) const { + if (settings.has(p_name)) { + r_ret = settings[p_name]; + return true; + } + if (defaults.has(p_name)) { + r_ret = defaults[p_name]; + return true; + } + return false; + } + + void _get_property_list(List<PropertyInfo> *p_list) const { + for (const List<ResourceImporter::ImportOption>::Element *E = options.front(); E; E = E->next()) { + if (owner && owner->import_settings_data.is_valid()) { + if (owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "size" || E->get().option.name == "outline_size" || E->get().option.name == "oversampling")) { + continue; + } + if (!owner->import_settings_data->get("multichannel_signed_distance_field") && (E->get().option.name == "msdf_pixel_range" || E->get().option.name == "msdf_size")) { + continue; + } + } + p_list->push_back(E->get().option); + } + } +}; + +/*************************************************************************/ +/* Glyph ranges */ +/*************************************************************************/ + +struct UniRange { + int32_t start; + int32_t end; + String name; +}; + +static UniRange unicode_ranges[] = { + { 0x0000, 0x007F, U"Basic Latin" }, + { 0x0080, 0x00FF, U"Latin-1 Supplement" }, + { 0x0100, 0x017F, U"Latin Extended-A" }, + { 0x0180, 0x024F, U"Latin Extended-B" }, + { 0x0250, 0x02AF, U"IPA Extensions" }, + { 0x02B0, 0x02FF, U"Spacing Modifier Letters" }, + { 0x0300, 0x036F, U"Combining Diacritical Marks" }, + { 0x0370, 0x03FF, U"Greek and Coptic" }, + { 0x0400, 0x04FF, U"Cyrillic" }, + { 0x0500, 0x052F, U"Cyrillic Supplement" }, + { 0x0530, 0x058F, U"Armenian" }, + { 0x0590, 0x05FF, U"Hebrew" }, + { 0x0600, 0x06FF, U"Arabic" }, + { 0x0700, 0x074F, U"Syriac" }, + { 0x0750, 0x077F, U"Arabic Supplement" }, + { 0x0780, 0x07BF, U"Thaana" }, + { 0x07C0, 0x07FF, U"N'Ko" }, + { 0x0800, 0x083F, U"Samaritan" }, + { 0x0840, 0x085F, U"Mandaic" }, + { 0x0860, 0x086F, U"Syriac Supplement" }, + { 0x08A0, 0x08FF, U"Arabic Extended-A" }, + { 0x0900, 0x097F, U"Devanagari" }, + { 0x0980, 0x09FF, U"Bengali" }, + { 0x0A00, 0x0A7F, U"Gurmukhi" }, + { 0x0A80, 0x0AFF, U"Gujarati" }, + { 0x0B00, 0x0B7F, U"Oriya" }, + { 0x0B80, 0x0BFF, U"Tamil" }, + { 0x0C00, 0x0C7F, U"Telugu" }, + { 0x0C80, 0x0CFF, U"Kannada" }, + { 0x0D00, 0x0D7F, U"Malayalam" }, + { 0x0D80, 0x0DFF, U"Sinhala" }, + { 0x0E00, 0x0E7F, U"Thai" }, + { 0x0E80, 0x0EFF, U"Lao" }, + { 0x0F00, 0x0FFF, U"Tibetan" }, + { 0x1000, 0x109F, U"Myanmar" }, + { 0x10A0, 0x10FF, U"Georgian" }, + { 0x1100, 0x11FF, U"Hangul Jamo" }, + { 0x1200, 0x137F, U"Ethiopic" }, + { 0x1380, 0x139F, U"Ethiopic Supplement" }, + { 0x13A0, 0x13FF, U"Cherokee" }, + { 0x1400, 0x167F, U"Unified Canadian Aboriginal Syllabics" }, + { 0x1680, 0x169F, U"Ogham" }, + { 0x16A0, 0x16FF, U"Runic" }, + { 0x1700, 0x171F, U"Tagalog" }, + { 0x1720, 0x173F, U"Hanunoo" }, + { 0x1740, 0x175F, U"Buhid" }, + { 0x1760, 0x177F, U"Tagbanwa" }, + { 0x1780, 0x17FF, U"Khmer" }, + { 0x1800, 0x18AF, U"Mongolian" }, + { 0x18B0, 0x18FF, U"Unified Canadian Aboriginal Syllabics Extended" }, + { 0x1900, 0x194F, U"Limbu" }, + { 0x1950, 0x197F, U"Tai Le" }, + { 0x1980, 0x19DF, U"New Tai Lue" }, + { 0x19E0, 0x19FF, U"Khmer Symbols" }, + { 0x1A00, 0x1A1F, U"Buginese" }, + { 0x1A20, 0x1AAF, U"Tai Tham" }, + { 0x1AB0, 0x1AFF, U"Combining Diacritical Marks Extended" }, + { 0x1B00, 0x1B7F, U"Balinese" }, + { 0x1B80, 0x1BBF, U"Sundanese" }, + { 0x1BC0, 0x1BFF, U"Batak" }, + { 0x1C00, 0x1C4F, U"Lepcha" }, + { 0x1C50, 0x1C7F, U"Ol Chiki" }, + { 0x1C80, 0x1C8F, U"Cyrillic Extended-C" }, + { 0x1C90, 0x1CBF, U"Georgian Extended" }, + { 0x1CC0, 0x1CCF, U"Sundanese Supplement" }, + { 0x1CD0, 0x1CFF, U"Vedic Extensions" }, + { 0x1D00, 0x1D7F, U"Phonetic Extensions" }, + { 0x1D80, 0x1DBF, U"Phonetic Extensions Supplement" }, + { 0x1DC0, 0x1DFF, U"Combining Diacritical Marks Supplement" }, + { 0x1E00, 0x1EFF, U"Latin Extended Additional" }, + { 0x1F00, 0x1FFF, U"Greek Extended" }, + { 0x2000, 0x206F, U"General Punctuation" }, + { 0x2070, 0x209F, U"Superscripts and Subscripts" }, + { 0x20A0, 0x20CF, U"Currency Symbols" }, + { 0x20D0, 0x20FF, U"Combining Diacritical Marks for Symbols" }, + { 0x2100, 0x214F, U"Letterlike Symbols" }, + { 0x2150, 0x218F, U"Number Forms" }, + { 0x2190, 0x21FF, U"Arrows" }, + { 0x2200, 0x22FF, U"Mathematical Operators" }, + { 0x2300, 0x23FF, U"Miscellaneous Technical" }, + { 0x2400, 0x243F, U"Control Pictures" }, + { 0x2440, 0x245F, U"Optical Character Recognition" }, + { 0x2460, 0x24FF, U"Enclosed Alphanumerics" }, + { 0x2500, 0x257F, U"Box Drawing" }, + { 0x2580, 0x259F, U"Block Elements" }, + { 0x25A0, 0x25FF, U"Geometric Shapes" }, + { 0x2600, 0x26FF, U"Miscellaneous Symbols" }, + { 0x2700, 0x27BF, U"Dingbats" }, + { 0x27C0, 0x27EF, U"Miscellaneous Mathematical Symbols-A" }, + { 0x27F0, 0x27FF, U"Supplemental Arrows-A" }, + { 0x2800, 0x28FF, U"Braille Patterns" }, + { 0x2900, 0x297F, U"Supplemental Arrows-B" }, + { 0x2980, 0x29FF, U"Miscellaneous Mathematical Symbols-B" }, + { 0x2A00, 0x2AFF, U"Supplemental Mathematical Operators" }, + { 0x2B00, 0x2BFF, U"Miscellaneous Symbols and Arrows" }, + { 0x2C00, 0x2C5F, U"Glagolitic" }, + { 0x2C60, 0x2C7F, U"Latin Extended-C" }, + { 0x2C80, 0x2CFF, U"Coptic" }, + { 0x2D00, 0x2D2F, U"Georgian Supplement" }, + { 0x2D30, 0x2D7F, U"Tifinagh" }, + { 0x2D80, 0x2DDF, U"Ethiopic Extended" }, + { 0x2DE0, 0x2DFF, U"Cyrillic Extended-A" }, + { 0x2E00, 0x2E7F, U"Supplemental Punctuation" }, + { 0x2E80, 0x2EFF, U"CJK Radicals Supplement" }, + { 0x2F00, 0x2FDF, U"Kangxi Radicals" }, + { 0x2FF0, 0x2FFF, U"Ideographic Description Characters" }, + { 0x3000, 0x303F, U"CJK Symbols and Punctuation" }, + { 0x3040, 0x309F, U"Hiragana" }, + { 0x30A0, 0x30FF, U"Katakana" }, + { 0x3100, 0x312F, U"Bopomofo" }, + { 0x3130, 0x318F, U"Hangul Compatibility Jamo" }, + { 0x3190, 0x319F, U"Kanbun" }, + { 0x31A0, 0x31BF, U"Bopomofo Extended" }, + { 0x31C0, 0x31EF, U"CJK Strokes" }, + { 0x31F0, 0x31FF, U"Katakana Phonetic Extensions" }, + { 0x3200, 0x32FF, U"Enclosed CJK Letters and Months" }, + { 0x3300, 0x33FF, U"CJK Compatibility" }, + { 0x3400, 0x4DBF, U"CJK Unified Ideographs Extension A" }, + { 0x4DC0, 0x4DFF, U"Yijing Hexagram Symbols" }, + { 0x4E00, 0x9FFF, U"CJK Unified Ideographs" }, + { 0xA000, 0xA48F, U"Yi Syllables" }, + { 0xA490, 0xA4CF, U"Yi Radicals" }, + { 0xA4D0, 0xA4FF, U"Lisu" }, + { 0xA500, 0xA63F, U"Vai" }, + { 0xA640, 0xA69F, U"Cyrillic Extended-B" }, + { 0xA6A0, 0xA6FF, U"Bamum" }, + { 0xA700, 0xA71F, U"Modifier Tone Letters" }, + { 0xA720, 0xA7FF, U"Latin Extended-D" }, + { 0xA800, 0xA82F, U"Syloti Nagri" }, + { 0xA830, 0xA83F, U"Common Indic Number Forms" }, + { 0xA840, 0xA87F, U"Phags-pa" }, + { 0xA880, 0xA8DF, U"Saurashtra" }, + { 0xA8E0, 0xA8FF, U"Devanagari Extended" }, + { 0xA900, 0xA92F, U"Kayah Li" }, + { 0xA930, 0xA95F, U"Rejang" }, + { 0xA960, 0xA97F, U"Hangul Jamo Extended-A" }, + { 0xA980, 0xA9DF, U"Javanese" }, + { 0xA9E0, 0xA9FF, U"Myanmar Extended-B" }, + { 0xAA00, 0xAA5F, U"Cham" }, + { 0xAA60, 0xAA7F, U"Myanmar Extended-A" }, + { 0xAA80, 0xAADF, U"Tai Viet" }, + { 0xAAE0, 0xAAFF, U"Meetei Mayek Extensions" }, + { 0xAB00, 0xAB2F, U"Ethiopic Extended-A" }, + { 0xAB30, 0xAB6F, U"Latin Extended-E" }, + { 0xAB70, 0xABBF, U"Cherokee Supplement" }, + { 0xABC0, 0xABFF, U"Meetei Mayek" }, + { 0xD7B0, 0xD7FF, U"Hangul Jamo Extended-B" }, + //{ 0xF800, 0xDFFF, U"Surrogates" }, + { 0xE000, 0xE2FE, U"Private Use Area" }, + { 0xF900, 0xFAFF, U"CJK Compatibility Ideographs" }, + { 0xFB00, 0xFB4F, U"Alphabetic Presentation Forms" }, + { 0xFB50, 0xFDFF, U"Arabic Presentation Forms-A" }, + //{ 0xFE00, 0xFE0F, U"Variation Selectors" }, + { 0xFE10, 0xFE1F, U"Vertical Forms" }, + { 0xFE20, 0xFE2F, U"Combining Half Marks" }, + { 0xFE30, 0xFE4F, U"CJK Compatibility Forms" }, + { 0xFE50, 0xFE6F, U"Small Form Variants" }, + { 0xFE70, 0xFEFF, U"Arabic Presentation Forms-B" }, + { 0xFF00, 0xFFEF, U"Halfwidth and Fullwidth Forms" }, + //{ 0xFFF0, 0xFFFF, U"Specials" }, + { 0x10000, 0x1007F, U"Linear B Syllabary" }, + { 0x10080, 0x100FF, U"Linear B Ideograms" }, + { 0x10100, 0x1013F, U"Aegean Numbers" }, + { 0x10140, 0x1018F, U"Ancient Greek Numbers" }, + { 0x10190, 0x101CF, U"Ancient Symbols" }, + { 0x101D0, 0x101FF, U"Phaistos Disc" }, + { 0x10280, 0x1029F, U"Lycian" }, + { 0x102A0, 0x102DF, U"Carian" }, + { 0x102E0, 0x102FF, U"Coptic Epact Numbers" }, + { 0x10300, 0x1032F, U"Old Italic" }, + { 0x10330, 0x1034F, U"Gothic" }, + { 0x10350, 0x1037F, U"Old Permic" }, + { 0x10380, 0x1039F, U"Ugaritic" }, + { 0x103A0, 0x103DF, U"Old Persian" }, + { 0x10400, 0x1044F, U"Deseret" }, + { 0x10450, 0x1047F, U"Shavian" }, + { 0x10480, 0x104AF, U"Osmanya" }, + { 0x104B0, 0x104FF, U"Osage" }, + { 0x10500, 0x1052F, U"Elbasan" }, + { 0x10530, 0x1056F, U"Caucasian Albanian" }, + { 0x10600, 0x1077F, U"Linear A" }, + { 0x10800, 0x1083F, U"Cypriot Syllabary" }, + { 0x10840, 0x1085F, U"Imperial Aramaic" }, + { 0x10860, 0x1087F, U"Palmyrene" }, + { 0x10880, 0x108AF, U"Nabataean" }, + { 0x108E0, 0x108FF, U"Hatran" }, + { 0x10900, 0x1091F, U"Phoenician" }, + { 0x10920, 0x1093F, U"Lydian" }, + { 0x10980, 0x1099F, U"Meroitic Hieroglyphs" }, + { 0x109A0, 0x109FF, U"Meroitic Cursive" }, + { 0x10A00, 0x10A5F, U"Kharoshthi" }, + { 0x10A60, 0x10A7F, U"Old South Arabian" }, + { 0x10A80, 0x10A9F, U"Old North Arabian" }, + { 0x10AC0, 0x10AFF, U"Manichaean" }, + { 0x10B00, 0x10B3F, U"Avestan" }, + { 0x10B40, 0x10B5F, U"Inscriptional Parthian" }, + { 0x10B60, 0x10B7F, U"Inscriptional Pahlavi" }, + { 0x10B80, 0x10BAF, U"Psalter Pahlavi" }, + { 0x10C00, 0x10C4F, U"Old Turkic" }, + { 0x10C80, 0x10CFF, U"Old Hungarian" }, + { 0x10D00, 0x10D3F, U"Hanifi Rohingya" }, + { 0x10E60, 0x10E7F, U"Rumi Numeral Symbols" }, + { 0x10E80, 0x10EBF, U"Yezidi" }, + { 0x10F00, 0x10F2F, U"Old Sogdian" }, + { 0x10F30, 0x10F6F, U"Sogdian" }, + { 0x10FB0, 0x10FDF, U"Chorasmian" }, + { 0x10FE0, 0x10FFF, U"Elymaic" }, + { 0x11000, 0x1107F, U"Brahmi" }, + { 0x11080, 0x110CF, U"Kaithi" }, + { 0x110D0, 0x110FF, U"Sora Sompeng" }, + { 0x11100, 0x1114F, U"Chakma" }, + { 0x11150, 0x1117F, U"Mahajani" }, + { 0x11180, 0x111DF, U"Sharada" }, + { 0x111E0, 0x111FF, U"Sinhala Archaic Numbers" }, + { 0x11200, 0x1124F, U"Khojki" }, + { 0x11280, 0x112AF, U"Multani" }, + { 0x112B0, 0x112FF, U"Khudawadi" }, + { 0x11300, 0x1137F, U"Grantha" }, + { 0x11400, 0x1147F, U"Newa" }, + { 0x11480, 0x114DF, U"Tirhuta" }, + { 0x11580, 0x115FF, U"Siddham" }, + { 0x11600, 0x1165F, U"Modi" }, + { 0x11660, 0x1167F, U"Mongolian Supplement" }, + { 0x11680, 0x116CF, U"Takri" }, + { 0x11700, 0x1173F, U"Ahom" }, + { 0x11800, 0x1184F, U"Dogra" }, + { 0x118A0, 0x118FF, U"Warang Citi" }, + { 0x11900, 0x1195F, U"Dives Akuru" }, + { 0x119A0, 0x119FF, U"Nandinagari" }, + { 0x11A00, 0x11A4F, U"Zanabazar Square" }, + { 0x11A50, 0x11AAF, U"Soyombo" }, + { 0x11AC0, 0x11AFF, U"Pau Cin Hau" }, + { 0x11C00, 0x11C6F, U"Bhaiksuki" }, + { 0x11C70, 0x11CBF, U"Marchen" }, + { 0x11D00, 0x11D5F, U"Masaram Gondi" }, + { 0x11D60, 0x11DAF, U"Gunjala Gondi" }, + { 0x11EE0, 0x11EFF, U"Makasar" }, + { 0x11FB0, 0x11FBF, U"Lisu Supplement" }, + { 0x11FC0, 0x11FFF, U"Tamil Supplement" }, + { 0x12000, 0x123FF, U"Cuneiform" }, + { 0x12400, 0x1247F, U"Cuneiform Numbers and Punctuation" }, + { 0x12480, 0x1254F, U"Early Dynastic Cuneiform" }, + { 0x13000, 0x1342F, U"Egyptian Hieroglyphs" }, + { 0x13430, 0x1343F, U"Egyptian Hieroglyph Format Controls" }, + { 0x14400, 0x1467F, U"Anatolian Hieroglyphs" }, + { 0x16800, 0x16A3F, U"Bamum Supplement" }, + { 0x16A40, 0x16A6F, U"Mro" }, + { 0x16AD0, 0x16AFF, U"Bassa Vah" }, + { 0x16B00, 0x16B8F, U"Pahawh Hmong" }, + { 0x16E40, 0x16E9F, U"Medefaidrin" }, + { 0x16F00, 0x16F9F, U"Miao" }, + { 0x16FE0, 0x16FFF, U"Ideographic Symbols and Punctuation" }, + { 0x17000, 0x187FF, U"Tangut" }, + { 0x18800, 0x18AFF, U"Tangut Components" }, + { 0x18B00, 0x18CFF, U"Khitan Small Script" }, + { 0x18D00, 0x18D8F, U"Tangut Supplement" }, + { 0x1B000, 0x1B0FF, U"Kana Supplement" }, + { 0x1B100, 0x1B12F, U"Kana Extended-A" }, + { 0x1B130, 0x1B16F, U"Small Kana Extension" }, + { 0x1B170, 0x1B2FF, U"Nushu" }, + { 0x1BC00, 0x1BC9F, U"Duployan" }, + { 0x1BCA0, 0x1BCAF, U"Shorthand Format Controls" }, + { 0x1D000, 0x1D0FF, U"Byzantine Musical Symbols" }, + { 0x1D100, 0x1D1FF, U"Musical Symbols" }, + { 0x1D200, 0x1D24F, U"Ancient Greek Musical Notation" }, + { 0x1D2E0, 0x1D2FF, U"Mayan Numerals" }, + { 0x1D300, 0x1D35F, U"Tai Xuan Jing Symbols" }, + { 0x1D360, 0x1D37F, U"Counting Rod Numerals" }, + { 0x1D400, 0x1D7FF, U"Mathematical Alphanumeric Symbols" }, + { 0x1D800, 0x1DAAF, U"Sutton SignWriting" }, + { 0x1E000, 0x1E02F, U"Glagolitic Supplement" }, + { 0x1E100, 0x1E14F, U"Nyiakeng Puachue Hmong" }, + { 0x1E2C0, 0x1E2FF, U"Wancho" }, + { 0x1E800, 0x1E8DF, U"Mende Kikakui" }, + { 0x1E900, 0x1E95F, U"Adlam" }, + { 0x1EC70, 0x1ECBF, U"Indic Siyaq Numbers" }, + { 0x1ED00, 0x1ED4F, U"Ottoman Siyaq Numbers" }, + { 0x1EE00, 0x1EEFF, U"Arabic Mathematical Alphabetic Symbols" }, + { 0x1F000, 0x1F02F, U"Mahjong Tiles" }, + { 0x1F030, 0x1F09F, U"Domino Tiles" }, + { 0x1F0A0, 0x1F0FF, U"Playing Cards" }, + { 0x1F100, 0x1F1FF, U"Enclosed Alphanumeric Supplement" }, + { 0x1F200, 0x1F2FF, U"Enclosed Ideographic Supplement" }, + { 0x1F300, 0x1F5FF, U"Miscellaneous Symbols and Pictographs" }, + { 0x1F600, 0x1F64F, U"Emoticons" }, + { 0x1F650, 0x1F67F, U"Ornamental Dingbats" }, + { 0x1F680, 0x1F6FF, U"Transport and Map Symbols" }, + { 0x1F700, 0x1F77F, U"Alchemical Symbols" }, + { 0x1F780, 0x1F7FF, U"Geometric Shapes Extended" }, + { 0x1F800, 0x1F8FF, U"Supplemental Arrows-C" }, + { 0x1F900, 0x1F9FF, U"Supplemental Symbols and Pictographs" }, + { 0x1FA00, 0x1FA6F, U"Chess Symbols" }, + { 0x1FA70, 0x1FAFF, U"Symbols and Pictographs Extended-A" }, + { 0x1FB00, 0x1FBFF, U"Symbols for Legacy Computing" }, + { 0x20000, 0x2A6DF, U"CJK Unified Ideographs Extension B" }, + { 0x2A700, 0x2B73F, U"CJK Unified Ideographs Extension C" }, + { 0x2B740, 0x2B81F, U"CJK Unified Ideographs Extension D" }, + { 0x2B820, 0x2CEAF, U"CJK Unified Ideographs Extension E" }, + { 0x2CEB0, 0x2EBEF, U"CJK Unified Ideographs Extension F" }, + { 0x2F800, 0x2FA1F, U"CJK Compatibility Ideographs Supplement" }, + { 0x30000, 0x3134F, U"CJK Unified Ideographs Extension G" }, + //{ 0xE0000, 0xE007F, U"Tags" }, + //{ 0xE0100, 0xE01EF, U"Variation Selectors Supplement" }, + { 0xF0000, 0xFFFFD, U"Supplementary Private Use Area-A" }, + { 0x100000, 0x10FFFD, U"Supplementary Private Use Area-B" }, + { 0x10FFFF, 0x10FFFF, String() } +}; + +void DynamicFontImportSettings::_add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name) { + const int page_size = 512; + int pages = (p_end - p_start) / page_size; + int remain = (p_end - p_start) % page_size; + + int32_t start = p_start; + for (int i = 0; i < pages; i++) { + TreeItem *item = glyph_tree->create_item(glyph_root); + ERR_FAIL_NULL(item); + item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(start + page_size, 16))); + item->set_text(1, p_name); + item->set_metadata(0, Vector2i(start, start + page_size)); + start += page_size; + } + if (remain > 0) { + TreeItem *item = glyph_tree->create_item(glyph_root); + ERR_FAIL_NULL(item); + item->set_text(0, _pad_zeros(String::num_int64(start, 16)) + " - " + _pad_zeros(String::num_int64(p_end, 16))); + item->set_text(1, p_name); + item->set_metadata(0, Vector2i(start, p_end)); + } +} + +/*************************************************************************/ +/* Languages and scripts */ +/*************************************************************************/ + +struct CodeInfo { + String name; + String code; +}; + +static CodeInfo langs[] = { + { U"Custom", U"xx" }, + { U"-", U"-" }, + { U"Abkhazian", U"ab" }, + { U"Afar", U"aa" }, + { U"Afrikaans", U"af" }, + { U"Akan", U"ak" }, + { U"Albanian", U"sq" }, + { U"Amharic", U"am" }, + { U"Arabic", U"ar" }, + { U"Aragonese", U"an" }, + { U"Armenian", U"hy" }, + { U"Assamese", U"as" }, + { U"Avaric", U"av" }, + { U"Avestan", U"ae" }, + { U"Aymara", U"ay" }, + { U"Azerbaijani", U"az" }, + { U"Bambara", U"bm" }, + { U"Bashkir", U"ba" }, + { U"Basque", U"eu" }, + { U"Belarusian", U"be" }, + { U"Bengali", U"bn" }, + { U"Bihari", U"bh" }, + { U"Bislama", U"bi" }, + { U"Bosnian", U"bs" }, + { U"Breton", U"br" }, + { U"Bulgarian", U"bg" }, + { U"Burmese", U"my" }, + { U"Catalan", U"ca" }, + { U"Chamorro", U"ch" }, + { U"Chechen", U"ce" }, + { U"Chichewa", U"ny" }, + { U"Chinese", U"zh" }, + { U"Chuvash", U"cv" }, + { U"Cornish", U"kw" }, + { U"Corsican", U"co" }, + { U"Cree", U"cr" }, + { U"Croatian", U"hr" }, + { U"Czech", U"cs" }, + { U"Danish", U"da" }, + { U"Divehi", U"dv" }, + { U"Dutch", U"nl" }, + { U"Dzongkha", U"dz" }, + { U"English", U"en" }, + { U"Esperanto", U"eo" }, + { U"Estonian", U"et" }, + { U"Ewe", U"ee" }, + { U"Faroese", U"fo" }, + { U"Fijian", U"fj" }, + { U"Finnish", U"fi" }, + { U"French", U"fr" }, + { U"Fulah", U"ff" }, + { U"Galician", U"gl" }, + { U"Georgian", U"ka" }, + { U"German", U"de" }, + { U"Greek", U"el" }, + { U"Guarani", U"gn" }, + { U"Gujarati", U"gu" }, + { U"Haitian", U"ht" }, + { U"Hausa", U"ha" }, + { U"Hebrew", U"he" }, + { U"Herero", U"hz" }, + { U"Hindi", U"hi" }, + { U"Hiri Motu", U"ho" }, + { U"Hungarian", U"hu" }, + { U"Interlingua", U"ia" }, + { U"Indonesian", U"id" }, + { U"Interlingue", U"ie" }, + { U"Irish", U"ga" }, + { U"Igbo", U"ig" }, + { U"Inupiaq", U"ik" }, + { U"Ido", U"io" }, + { U"Icelandic", U"is" }, + { U"Italian", U"it" }, + { U"Inuktitut", U"iu" }, + { U"Japanese", U"ja" }, + { U"Javanese", U"jv" }, + { U"Kalaallisut", U"kl" }, + { U"Kannada", U"kn" }, + { U"Kanuri", U"kr" }, + { U"Kashmiri", U"ks" }, + { U"Kazakh", U"kk" }, + { U"Central Khmer", U"km" }, + { U"Kikuyu", U"ki" }, + { U"Kinyarwanda", U"rw" }, + { U"Kirghiz", U"ky" }, + { U"Komi", U"kv" }, + { U"Kongo", U"kg" }, + { U"Korean", U"ko" }, + { U"Kurdish", U"ku" }, + { U"Kuanyama", U"kj" }, + { U"Latin", U"la" }, + { U"Luxembourgish", U"lb" }, + { U"Ganda", U"lg" }, + { U"Limburgan", U"li" }, + { U"Lingala", U"ln" }, + { U"Lao", U"lo" }, + { U"Lithuanian", U"lt" }, + { U"Luba-Katanga", U"lu" }, + { U"Latvian", U"lv" }, + { U"Man", U"gv" }, + { U"Macedonian", U"mk" }, + { U"Malagasy", U"mg" }, + { U"Malay", U"ms" }, + { U"Malayalam", U"ml" }, + { U"Maltese", U"mt" }, + { U"Maori", U"mi" }, + { U"Marathi", U"mr" }, + { U"Marshallese", U"mh" }, + { U"Mongolian", U"mn" }, + { U"Nauru", U"na" }, + { U"Navajo", U"nv" }, + { U"North Ndebele", U"nd" }, + { U"Nepali", U"ne" }, + { U"Ndonga", U"ng" }, + { U"Norwegian Bokmål", U"nb" }, + { U"Norwegian Nynorsk", U"nn" }, + { U"Norwegian", U"no" }, + { U"Sichuan Yi, Nuosu", U"ii" }, + { U"South Ndebele", U"nr" }, + { U"Occitan", U"oc" }, + { U"Ojibwa", U"oj" }, + { U"Church Slavic", U"cu" }, + { U"Oromo", U"om" }, + { U"Oriya", U"or" }, + { U"Ossetian", U"os" }, + { U"Punjabi", U"pa" }, + { U"Pali", U"pi" }, + { U"Persian", U"fa" }, + { U"Polish", U"pl" }, + { U"Pashto", U"ps" }, + { U"Portuguese", U"pt" }, + { U"Quechua", U"qu" }, + { U"Romansh", U"rm" }, + { U"Rundi", U"rn" }, + { U"Romanian", U"ro" }, + { U"Russian", U"ru" }, + { U"Sanskrit", U"sa" }, + { U"Sardinian", U"sc" }, + { U"Sindhi", U"sd" }, + { U"Northern Sami", U"se" }, + { U"Samoan", U"sm" }, + { U"Sango", U"sg" }, + { U"Serbian", U"sr" }, + { U"Gaelic", U"gd" }, + { U"Shona", U"sn" }, + { U"Sinhala", U"si" }, + { U"Slovak", U"sk" }, + { U"Slovenian", U"sl" }, + { U"Somali", U"so" }, + { U"Southern Sotho", U"st" }, + { U"Spanish", U"es" }, + { U"Sundanese", U"su" }, + { U"Swahili", U"sw" }, + { U"Swati", U"ss" }, + { U"Swedish", U"sv" }, + { U"Tamil", U"ta" }, + { U"Telugu", U"te" }, + { U"Tajik", U"tg" }, + { U"Thai", U"th" }, + { U"Tigrinya", U"ti" }, + { U"Tibetan", U"bo" }, + { U"Turkmen", U"tk" }, + { U"Tagalog", U"tl" }, + { U"Tswana", U"tn" }, + { U"Tonga", U"to" }, + { U"Turkish", U"tr" }, + { U"Tsonga", U"ts" }, + { U"Tatar", U"tt" }, + { U"Twi", U"tw" }, + { U"Tahitian", U"ty" }, + { U"Uighur", U"ug" }, + { U"Ukrainian", U"uk" }, + { U"Urdu", U"ur" }, + { U"Uzbek", U"uz" }, + { U"Venda", U"ve" }, + { U"Vietnamese", U"vi" }, + { U"Volapük", U"vo" }, + { U"Walloon", U"wa" }, + { U"Welsh", U"cy" }, + { U"Wolof", U"wo" }, + { U"Western Frisian", U"fy" }, + { U"Xhosa", U"xh" }, + { U"Yiddish", U"yi" }, + { U"Yoruba", U"yo" }, + { U"Zhuang", U"za" }, + { U"Zulu", U"zu" }, + { String(), String() } +}; + +static CodeInfo scripts[] = { + { U"Custom", U"Qaaa" }, + { U"-", U"-" }, + { U"Adlam", U"Adlm" }, + { U"Afaka", U"Afak" }, + { U"Caucasian Albanian", U"Aghb" }, + { U"Ahom", U"Ahom" }, + { U"Arabic", U"Arab" }, + { U"Imperial Aramaic", U"Armi" }, + { U"Armenian", U"Armn" }, + { U"Avestan", U"Avst" }, + { U"Balinese", U"Bali" }, + { U"Bamum", U"Bamu" }, + { U"Bassa Vah", U"Bass" }, + { U"Batak", U"Batk" }, + { U"Bengali", U"Beng" }, + { U"Bhaiksuki", U"Bhks" }, + { U"Blissymbols", U"Blis" }, + { U"Bopomofo", U"Bopo" }, + { U"Brahmi", U"Brah" }, + { U"Braille", U"Brai" }, + { U"Buginese", U"Bugi" }, + { U"Buhid", U"Buhd" }, + { U"Chakma", U"Cakm" }, + { U"Unified Canadian Aboriginal", U"Cans" }, + { U"Carian", U"Cari" }, + { U"Cham", U"Cham" }, + { U"Cherokee", U"Cher" }, + { U"Chorasmian", U"Chrs" }, + { U"Cirth", U"Cirt" }, + { U"Coptic", U"Copt" }, + { U"Cypro-Minoan", U"Cpmn" }, + { U"Cypriot", U"Cprt" }, + { U"Cyrillic", U"Cyrl" }, + { U"Devanagari", U"Deva" }, + { U"Dives Akuru", U"Diak" }, + { U"Dogra", U"Dogr" }, + { U"Deseret", U"Dsrt" }, + { U"Duployan", U"Dupl" }, + { U"Egyptian demotic", U"Egyd" }, + { U"Egyptian hieratic", U"Egyh" }, + { U"Egyptian hieroglyphs", U"Egyp" }, + { U"Elbasan", U"Elba" }, + { U"Elymaic", U"Elym" }, + { U"Ethiopic", U"Ethi" }, + { U"Khutsuri", U"Geok" }, + { U"Georgian", U"Geor" }, + { U"Glagolitic", U"Glag" }, + { U"Gunjala Gondi", U"Gong" }, + { U"Masaram Gondi", U"Gonm" }, + { U"Gothic", U"Goth" }, + { U"Grantha", U"Gran" }, + { U"Greek", U"Grek" }, + { U"Gujarati", U"Gujr" }, + { U"Gurmukhi", U"Guru" }, + { U"Hangul", U"Hang" }, + { U"Han", U"Hani" }, + { U"Hanunoo", U"Hano" }, + { U"Hatran", U"Hatr" }, + { U"Hebrew", U"Hebr" }, + { U"Hiragana", U"Hira" }, + { U"Anatolian Hieroglyphs", U"Hluw" }, + { U"Pahawh Hmong", U"Hmng" }, + { U"Nyiakeng Puachue Hmong", U"Hmnp" }, + { U"Old Hungarian", U"Hung" }, + { U"Indus", U"Inds" }, + { U"Old Italic", U"Ital" }, + { U"Javanese", U"Java" }, + { U"Jurchen", U"Jurc" }, + { U"Kayah Li", U"Kali" }, + { U"Katakana", U"Kana" }, + { U"Kharoshthi", U"Khar" }, + { U"Khmer", U"Khmr" }, + { U"Khojki", U"Khoj" }, + { U"Khitan large script", U"Kitl" }, + { U"Khitan small script", U"Kits" }, + { U"Kannada", U"Knda" }, + { U"Kpelle", U"Kpel" }, + { U"Kaithi", U"Kthi" }, + { U"Tai Tham", U"Lana" }, + { U"Lao", U"Laoo" }, + { U"Latin", U"Latn" }, + { U"Leke", U"Leke" }, + { U"Lepcha", U"Lepc" }, + { U"Limbu", U"Limb" }, + { U"Linear A", U"Lina" }, + { U"Linear B", U"Linb" }, + { U"Lisu", U"Lisu" }, + { U"Loma", U"Loma" }, + { U"Lycian", U"Lyci" }, + { U"Lydian", U"Lydi" }, + { U"Mahajani", U"Mahj" }, + { U"Makasar", U"Maka" }, + { U"Mandaic", U"Mand" }, + { U"Manichaean", U"Mani" }, + { U"Marchen", U"Marc" }, + { U"Mayan Hieroglyphs", U"Maya" }, + { U"Medefaidrin", U"Medf" }, + { U"Mende Kikakui", U"Mend" }, + { U"Meroitic Cursive", U"Merc" }, + { U"Meroitic Hieroglyphs", U"Mero" }, + { U"Malayalam", U"Mlym" }, + { U"Modi", U"Modi" }, + { U"Mongolian", U"Mong" }, + { U"Moon", U"Moon" }, + { U"Mro", U"Mroo" }, + { U"Meitei Mayek", U"Mtei" }, + { U"Multani", U"Mult" }, + { U"Myanmar (Burmese)", U"Mymr" }, + { U"Nandinagari", U"Nand" }, + { U"Old North Arabian", U"Narb" }, + { U"Nabataean", U"Nbat" }, + { U"Newa", U"Newa" }, + { U"Naxi Dongba", U"Nkdb" }, + { U"Nakhi Geba", U"Nkgb" }, + { U"N’Ko", U"Nkoo" }, + { U"Nüshu", U"Nshu" }, + { U"Ogham", U"Ogam" }, + { U"Ol Chiki", U"Olck" }, + { U"Old Turkic", U"Orkh" }, + { U"Oriya", U"Orya" }, + { U"Osage", U"Osge" }, + { U"Osmanya", U"Osma" }, + { U"Old Uyghur", U"Ougr" }, + { U"Palmyrene", U"Palm" }, + { U"Pau Cin Hau", U"Pauc" }, + { U"Proto-Cuneiform", U"Pcun" }, + { U"Proto-Elamite", U"Pelm" }, + { U"Old Permic", U"Perm" }, + { U"Phags-pa", U"Phag" }, + { U"Inscriptional Pahlavi", U"Phli" }, + { U"Psalter Pahlavi", U"Phlp" }, + { U"Book Pahlavi", U"Phlv" }, + { U"Phoenician", U"Phnx" }, + { U"Klingon", U"Piqd" }, + { U"Miao", U"Plrd" }, + { U"Inscriptional Parthian", U"Prti" }, + { U"Proto-Sinaitic", U"Psin" }, + { U"Ranjana", U"Ranj" }, + { U"Rejang", U"Rjng" }, + { U"Hanifi Rohingya", U"Rohg" }, + { U"Rongorongo", U"Roro" }, + { U"Runic", U"Runr" }, + { U"Samaritan", U"Samr" }, + { U"Sarati", U"Sara" }, + { U"Old South Arabian", U"Sarb" }, + { U"Saurashtra", U"Saur" }, + { U"SignWriting", U"Sgnw" }, + { U"Shavian", U"Shaw" }, + { U"Sharada", U"Shrd" }, + { U"Shuishu", U"Shui" }, + { U"Siddham", U"Sidd" }, + { U"Khudawadi", U"Sind" }, + { U"Sinhala", U"Sinh" }, + { U"Sogdian", U"Sogd" }, + { U"Old Sogdian", U"Sogo" }, + { U"Sora Sompeng", U"Sora" }, + { U"Soyombo", U"Soyo" }, + { U"Sundanese", U"Sund" }, + { U"Syloti Nagri", U"Sylo" }, + { U"Syriac", U"Syrc" }, + { U"Tagbanwa", U"Tagb" }, + { U"Takri", U"Takr" }, + { U"Tai Le", U"Tale" }, + { U"New Tai Lue", U"Talu" }, + { U"Tamil", U"Taml" }, + { U"Tangut", U"Tang" }, + { U"Tai Viet", U"Tavt" }, + { U"Telugu", U"Telu" }, + { U"Tengwar", U"Teng" }, + { U"Tifinagh", U"Tfng" }, + { U"Tagalog", U"Tglg" }, + { U"Thaana", U"Thaa" }, + { U"Thai", U"Thai" }, + { U"Tibetan", U"Tibt" }, + { U"Tirhuta", U"Tirh" }, + { U"Tangsa", U"Tnsa" }, + { U"Toto", U"Toto" }, + { U"Ugaritic", U"Ugar" }, + { U"Vai", U"Vaii" }, + { U"Visible Speech", U"Visp" }, + { U"Vithkuqi", U"Vith" }, + { U"Warang Citi", U"Wara" }, + { U"Wancho", U"Wcho" }, + { U"Woleai", U"Wole" }, + { U"Old Persian", U"Xpeo" }, + { U"Cuneiform", U"Xsux" }, + { U"Yezidi", U"Yezi" }, + { U"Yi", U"Yiii" }, + { U"Zanabazar Square", U"Zanb" }, + { String(), String() } +}; + +/*************************************************************************/ +/* Page 1 callbacks: Rendering Options */ +/*************************************************************************/ + +void DynamicFontImportSettings::_main_prop_changed(const String &p_edited_property) { + // Update font preview. + + if (p_edited_property == "antialiased") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_antialiased(import_settings_data->get("antialiased")); + } + } else if (p_edited_property == "multichannel_signed_distance_field") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field")); + } + _variation_selected(); + _variations_validate(); + } else if (p_edited_property == "msdf_pixel_range") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range")); + } + } else if (p_edited_property == "msdf_size") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_msdf_size(import_settings_data->get("msdf_size")); + } + } else if (p_edited_property == "force_autohinter") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_force_autohinter(import_settings_data->get("force_autohinter")); + } + } else if (p_edited_property == "hinting") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int()); + } + } else if (p_edited_property == "oversampling") { + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_oversampling(import_settings_data->get("oversampling")); + } + } + font_preview_label->add_theme_font_override("font", font_preview); + font_preview_label->update(); +} + +/*************************************************************************/ +/* Page 2 callbacks: Configurations */ +/*************************************************************************/ + +void DynamicFontImportSettings::_variation_add() { + TreeItem *vars_item = vars_list->create_item(vars_list_root); + ERR_FAIL_NULL(vars_item); + + vars_item->set_text(0, TTR("New configuration")); + vars_item->set_editable(0, true); + vars_item->add_button(1, vars_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove Variation")); + vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75)); + + Ref<DynamicFontImportSettingsData> import_variation_data; + import_variation_data.instantiate(); + import_variation_data->owner = this; + ERR_FAIL_NULL(import_variation_data); + + for (List<ResourceImporter::ImportOption>::Element *E = options_variations.front(); E; E = E->next()) { + import_variation_data->defaults[E->get().option.name] = E->get().default_value; + } + + import_variation_data->options = options_variations; + inspector_vars->edit(import_variation_data.ptr()); + import_variation_data->notify_property_list_changed(); + + vars_item->set_metadata(0, import_variation_data); + + _variations_validate(); +} + +void DynamicFontImportSettings::_variation_selected() { + TreeItem *vars_item = vars_list->get_selected(); + if (vars_item) { + Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0); + ERR_FAIL_NULL(import_variation_data); + + inspector_vars->edit(import_variation_data.ptr()); + import_variation_data->notify_property_list_changed(); + } +} + +void DynamicFontImportSettings::_variation_remove(Object *p_item, int p_column, int p_id) { + TreeItem *vars_item = (TreeItem *)p_item; + ERR_FAIL_NULL(vars_item); + + inspector_vars->edit(nullptr); + + vars_list_root->remove_child(vars_item); + memdelete(vars_item); + + if (vars_list_root->get_first_child()) { + Ref<DynamicFontImportSettingsData> import_variation_data = vars_list_root->get_first_child()->get_metadata(0); + inspector_vars->edit(import_variation_data.ptr()); + import_variation_data->notify_property_list_changed(); + } + + _variations_validate(); +} + +void DynamicFontImportSettings::_variation_changed(const String &p_edited_property) { + _variations_validate(); +} + +void DynamicFontImportSettings::_variations_validate() { + String warn; + if (!vars_list_root->get_first_child()) { + warn = TTR("Warinig: There are no configurations specified, no glyphs will be pre-rendered."); + } + for (TreeItem *vars_item_a = vars_list_root->get_first_child(); vars_item_a; vars_item_a = vars_item_a->get_next()) { + Ref<DynamicFontImportSettingsData> import_variation_data_a = vars_item_a->get_metadata(0); + ERR_FAIL_NULL(import_variation_data_a); + + for (TreeItem *vars_item_b = vars_list_root->get_first_child(); vars_item_b; vars_item_b = vars_item_b->get_next()) { + if (vars_item_b != vars_item_a) { + bool match = true; + for (Map<StringName, Variant>::Element *E = import_variation_data_a->settings.front(); E; E = E->next()) { + Ref<DynamicFontImportSettingsData> import_variation_data_b = vars_item_b->get_metadata(0); + ERR_FAIL_NULL(import_variation_data_b); + match = match && (import_variation_data_b->settings[E->key()] == E->get()); + } + if (match) { + warn = TTR("Warinig: Multiple configurations have identical settings. Duplicates will be ignored."); + break; + } + } + } + } + if (warn.is_empty()) { + label_warn->set_text(""); + label_warn->hide(); + } else { + label_warn->set_text(warn); + label_warn->show(); + } +} + +/*************************************************************************/ +/* Page 3 callbacks: Text to select glyphs */ +/*************************************************************************/ + +void DynamicFontImportSettings::_change_text_opts() { + Vector<String> ftr = ftr_edit->get_text().split(","); + for (int i = 0; i < ftr.size(); i++) { + Vector<String> tokens = ftr[i].split("="); + if (tokens.size() == 2) { + text_edit->set_opentype_feature(tokens[0], tokens[1].to_int()); + } else if (tokens.size() == 1) { + text_edit->set_opentype_feature(tokens[0], 1); + } + } + text_edit->set_language(lang_edit->get_text()); +} + +void DynamicFontImportSettings::_glyph_clear() { + selected_glyphs.clear(); + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); + _range_selected(); +} + +void DynamicFontImportSettings::_glyph_text_selected() { + Dictionary ftrs; + Vector<String> ftr = ftr_edit->get_text().split(","); + for (int i = 0; i < ftr.size(); i++) { + Vector<String> tokens = ftr[i].split("="); + if (tokens.size() == 2) { + ftrs[tokens[0]] = tokens[1].to_int(); + } else if (tokens.size() == 1) { + ftrs[tokens[0]] = 1; + } + } + + RID text_rid = TS->create_shaped_text(); + if (text_rid.is_valid()) { + TS->shaped_text_add_string(text_rid, text_edit->get_text(), font_main->get_rids(), 16, ftrs, text_edit->get_language()); + TS->shaped_text_shape(text_rid); + const Vector<TextServer::Glyph> &gl = TS->shaped_text_get_glyphs(text_rid); + + for (int i = 0; i < gl.size(); i++) { + if (gl[i].font_rid.is_valid() && gl[i].index != 0) { + selected_glyphs.insert(gl[i].index); + } + } + TS->free(text_rid); + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); + } + _range_selected(); +} + +/*************************************************************************/ +/* Page 4 callbacks: Character map */ +/*************************************************************************/ + +void DynamicFontImportSettings::_glyph_selected() { + TreeItem *item = glyph_table->get_selected(); + ERR_FAIL_NULL(item); + + Color scol = glyph_table->get_theme_color("box_selection_fill_color", "Editor"); + Color fcol = glyph_table->get_theme_color("font_selected_color", "Editor"); + scol.a = 1.f; + + int32_t c = item->get_metadata(glyph_table->get_selected_column()); + if (font_main->has_char(c)) { + if (_char_update(c)) { + item->set_custom_color(glyph_table->get_selected_column(), fcol); + item->set_custom_bg_color(glyph_table->get_selected_column(), scol); + } else { + item->clear_custom_color(glyph_table->get_selected_column()); + item->clear_custom_bg_color(glyph_table->get_selected_column()); + } + } + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); +} + +void DynamicFontImportSettings::_range_edited() { + TreeItem *item = glyph_tree->get_selected(); + ERR_FAIL_NULL(item); + Vector2i range = item->get_metadata(0); + _range_update(range.x, range.y); +} + +void DynamicFontImportSettings::_range_selected() { + TreeItem *item = glyph_tree->get_selected(); + if (item) { + Vector2i range = item->get_metadata(0); + _edit_range(range.x, range.y); + } +} + +void DynamicFontImportSettings::_edit_range(int32_t p_start, int32_t p_end) { + glyph_table->clear(); + + TreeItem *root = glyph_table->create_item(); + ERR_FAIL_NULL(root); + + Color scol = glyph_table->get_theme_color("box_selection_fill_color", "Editor"); + Color fcol = glyph_table->get_theme_color("font_selected_color", "Editor"); + scol.a = 1.f; + + TreeItem *item = nullptr; + int col = 0; + + for (int32_t c = p_start; c <= p_end; c++) { + if (col == 0) { + item = glyph_table->create_item(root); + ERR_FAIL_NULL(item); + item->set_text(0, _pad_zeros(String::num_int64(c, 16))); + item->set_text_align(0, TreeItem::ALIGN_LEFT); + item->set_selectable(0, false); + item->set_custom_bg_color(0, glyph_table->get_theme_color("dark_color_3", "Editor")); + } + if (font_main->has_char(c)) { + item->set_text(col + 1, String::chr(c)); + item->set_custom_color(col + 1, Color(1, 1, 1)); + if (selected_chars.has(c) || (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size("font_size") * 2, c)))) { + item->set_custom_color(col + 1, fcol); + item->set_custom_bg_color(col + 1, scol); + } else { + item->clear_custom_color(col + 1); + item->clear_custom_bg_color(col + 1); + } + } else { + item->set_custom_bg_color(col + 1, glyph_table->get_theme_color("dark_color_2", "Editor")); + } + item->set_metadata(col + 1, c); + item->set_text_align(col + 1, TreeItem::ALIGN_CENTER); + item->set_selectable(col + 1, true); + item->set_custom_font(col + 1, font_main); + item->set_custom_font_size(col + 1, get_theme_font_size("font_size") * 2); + + col++; + if (col == 16) { + col = 0; + } + } + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); +} + +bool DynamicFontImportSettings::_char_update(int32_t p_char) { + if (selected_chars.has(p_char)) { + selected_chars.erase(p_char); + return false; + } else if (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size("font_size") * 2, p_char))) { + selected_glyphs.erase(font_main->get_data(0)->get_glyph_index(get_theme_font_size("font_size") * 2, p_char)); + return false; + } else { + selected_chars.insert(p_char); + return true; + } + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); +} + +void DynamicFontImportSettings::_range_update(int32_t p_start, int32_t p_end) { + bool all_selected = true; + for (int32_t i = p_start; i <= p_end; i++) { + if (font_main->has_char(i)) { + if (font_main->get_data(0).is_valid()) { + all_selected = all_selected && (selected_chars.has(i) || (font_main->get_data(0).is_valid() && selected_glyphs.has(font_main->get_data(0)->get_glyph_index(get_theme_font_size("font_size") * 2, i)))); + } else { + all_selected = all_selected && selected_chars.has(i); + } + } + } + for (int32_t i = p_start; i <= p_end; i++) { + if (font_main->has_char(i)) { + if (!all_selected) { + selected_chars.insert(i); + } else { + selected_chars.erase(i); + if (font_main->get_data(0).is_valid()) { + selected_glyphs.erase(font_main->get_data(0)->get_glyph_index(get_theme_font_size("font_size") * 2, i)); + } + } + } + } + _edit_range(p_start, p_end); +} + +/*************************************************************************/ +/* Page 5 callbacks: CMetadata override */ +/*************************************************************************/ + +void DynamicFontImportSettings::_lang_add() { + menu_langs->set_position(lang_list->get_screen_transform().xform(lang_list->get_local_mouse_position())); + menu_langs->set_size(Vector2(1, 1)); + menu_langs->popup(); +} + +void DynamicFontImportSettings::_lang_add_item(int p_option) { + TreeItem *lang_item = lang_list->create_item(lang_list_root); + ERR_FAIL_NULL(lang_item); + + lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + lang_item->set_editable(0, true); + lang_item->set_checked(0, false); + lang_item->set_text(1, langs[p_option].code); + lang_item->set_editable(1, true); + lang_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + lang_item->set_button_color(2, 0, Color(1, 1, 1, 0.75)); +} + +void DynamicFontImportSettings::_lang_remove(Object *p_item, int p_column, int p_id) { + TreeItem *lang_item = (TreeItem *)p_item; + ERR_FAIL_NULL(lang_item); + + lang_list_root->remove_child(lang_item); + memdelete(lang_item); +} + +void DynamicFontImportSettings::_script_add() { + menu_scripts->set_position(script_list->get_screen_transform().xform(script_list->get_local_mouse_position())); + menu_scripts->set_size(Vector2(1, 1)); + menu_scripts->popup(); +} + +void DynamicFontImportSettings::_script_add_item(int p_option) { + TreeItem *script_item = script_list->create_item(script_list_root); + ERR_FAIL_NULL(script_item); + + script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + script_item->set_editable(0, true); + script_item->set_checked(0, false); + script_item->set_text(1, scripts[p_option].code); + script_item->set_editable(1, true); + script_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + script_item->set_button_color(2, 0, Color(1, 1, 1, 0.75)); +} + +void DynamicFontImportSettings::_script_remove(Object *p_item, int p_column, int p_id) { + TreeItem *script_item = (TreeItem *)p_item; + ERR_FAIL_NULL(script_item); + + script_list_root->remove_child(script_item); + memdelete(script_item); +} + +/*************************************************************************/ +/* Common */ +/*************************************************************************/ + +DynamicFontImportSettings *DynamicFontImportSettings::singleton = nullptr; + +String DynamicFontImportSettings::_pad_zeros(const String &p_hex) const { + int len = CLAMP(5 - p_hex.length(), 0, 5); + return String("0").repeat(len) + p_hex; +} + +void DynamicFontImportSettings::_notification(int p_what) { + if (p_what == NOTIFICATION_READY) { + connect("confirmed", callable_mp(this, &DynamicFontImportSettings::_re_import)); + } else if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { + add_lang->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + add_script->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + add_var->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + } +} + +void DynamicFontImportSettings::_re_import() { + Map<StringName, Variant> main_settings; + + main_settings["antialiased"] = import_settings_data->get("antialiased"); + main_settings["multichannel_signed_distance_field"] = import_settings_data->get("multichannel_signed_distance_field"); + main_settings["msdf_pixel_range"] = import_settings_data->get("msdf_pixel_range"); + main_settings["msdf_size"] = import_settings_data->get("msdf_size"); + main_settings["force_autohinter"] = import_settings_data->get("force_autohinter"); + main_settings["hinting"] = import_settings_data->get("hinting"); + main_settings["oversampling"] = import_settings_data->get("oversampling"); + main_settings["compress"] = import_settings_data->get("compress"); + + Vector<String> variations; + for (TreeItem *vars_item = vars_list_root->get_first_child(); vars_item; vars_item = vars_item->get_next()) { + String variation; + Ref<DynamicFontImportSettingsData> import_variation_data = vars_item->get_metadata(0); + ERR_FAIL_NULL(import_variation_data); + + String name = vars_item->get_text(0); + variation += ("name=" + name); + for (Map<StringName, Variant>::Element *E = import_variation_data->settings.front(); E; E = E->next()) { + if (!variation.is_empty()) { + variation += ","; + } + variation += (String(E->key()) + "=" + String(E->get())); + } + variations.push_back(variation); + } + main_settings["preload/configurations"] = variations; + + Vector<String> langs_enabled; + Vector<String> langs_disabled; + for (TreeItem *lang_item = lang_list_root->get_first_child(); lang_item; lang_item = lang_item->get_next()) { + bool selected = lang_item->is_checked(0); + String name = lang_item->get_text(1); + if (selected) { + langs_enabled.push_back(name); + } else { + langs_disabled.push_back(name); + } + } + main_settings["support_overrides/language_enabled"] = langs_enabled; + main_settings["support_overrides/language_disabled"] = langs_disabled; + + Vector<String> scripts_enabled; + Vector<String> scripts_disabled; + for (TreeItem *script_item = script_list_root->get_first_child(); script_item; script_item = script_item->get_next()) { + bool selected = script_item->is_checked(0); + String name = script_item->get_text(1); + if (selected) { + scripts_enabled.push_back(name); + } else { + scripts_disabled.push_back(name); + } + } + main_settings["support_overrides/script_enabled"] = scripts_enabled; + main_settings["support_overrides/script_disabled"] = scripts_disabled; + + if (!selected_chars.is_empty()) { + Vector<String> ranges; + char32_t start = selected_chars.front()->get(); + for (Set<char32_t>::Element *E = selected_chars.front()->next(); E; E = E->next()) { + if (E->prev() && ((E->prev()->get() + 1) != E->get())) { + ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(E->prev()->get(), 16)); + start = E->get(); + } + } + ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(selected_chars.back()->get(), 16)); + main_settings["preload/char_ranges"] = ranges; + } + + if (!selected_glyphs.is_empty()) { + Vector<String> ranges; + int32_t start = selected_glyphs.front()->get(); + for (Set<int32_t>::Element *E = selected_glyphs.front()->next(); E; E = E->next()) { + if (E->prev() && ((E->prev()->get() + 1) != E->get())) { + ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(E->prev()->get(), 16)); + start = E->get(); + } + } + ranges.push_back(String("0x") + String::num_int64(start, 16) + String("-0x") + String::num_int64(selected_glyphs.back()->get(), 16)); + main_settings["preload/glyph_ranges"] = ranges; + } + + if (OS::get_singleton()->is_stdout_verbose()) { + print_line("Import settings:"); + for (Map<StringName, Variant>::Element *E = main_settings.front(); E; E = E->next()) { + print_line(String(" ") + String(E->key()).utf8().get_data() + " == " + String(E->get()).utf8().get_data()); + } + } + + EditorFileSystem::get_singleton()->reimport_file_with_custom_parameters(base_path, "font_data_dynamic", main_settings); +} + +void DynamicFontImportSettings::open_settings(const String &p_path) { + // Load base font data. + Vector<uint8_t> data = FileAccess::get_file_as_array(p_path); + + // Load font for preview. + Ref<FontData> dfont_prev; + dfont_prev.instantiate(); + dfont_prev->set_data(data); + + font_preview.instantiate(); + font_preview->add_data(dfont_prev); + + String sample; + static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀"; + for (int i = 0; i < sample_base.length(); i++) { + if (dfont_prev->has_char(sample_base[i])) { + sample += sample_base[i]; + } + } + if (sample.is_empty()) { + sample = dfont_prev->get_supported_chars().substr(0, 6); + } + font_preview_label->set_text(sample); + + // Load second copy of font with MSDF disabled for the glyph table and metadata extraction. + Ref<FontData> dfont_main; + dfont_main.instantiate(); + dfont_main->set_data(data); + dfont_main->set_multichannel_signed_distance_field(false); + + font_main.instantiate(); + font_main->add_data(dfont_main); + text_edit->add_theme_font_override("font", font_main); + + base_path = p_path; + + inspector_vars->edit(nullptr); + inspector_general->edit(nullptr); + + int gww = get_theme_font("font")->get_string_size("00000", get_theme_font_size("font_size")).x + 50; + glyph_table->set_column_custom_minimum_width(0, gww); + + glyph_table->clear(); + vars_list->clear(); + lang_list->clear(); + script_list->clear(); + + selected_chars.clear(); + selected_glyphs.clear(); + text_edit->set_text(String()); + + vars_list_root = vars_list->create_item(); + lang_list_root = lang_list->create_item(); + script_list_root = script_list->create_item(); + + options_variations.clear(); + Dictionary var_list = dfont_main->get_supported_variation_list(); + for (int i = 0; i < var_list.size(); i++) { + int32_t tag = var_list.get_key_at_index(i); + Vector3i value = var_list.get_value_at_index(i); + options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, TS->tag_to_name(tag), PROPERTY_HINT_RANGE, itos(value.x) + "," + itos(value.y) + ",1"), value.z)); + } + options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "size", PROPERTY_HINT_RANGE, "0,127,1"), 16)); + options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "outline_size", PROPERTY_HINT_RANGE, "0,127,1"), 0)); + options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "extra_spacing_glyph"), 0)); + options_variations.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "extra_spacing_space"), 0)); + + import_settings_data->defaults.clear(); + for (List<ResourceImporter::ImportOption>::Element *E = options_general.front(); E; E = E->next()) { + import_settings_data->defaults[E->get().option.name] = E->get().default_value; + } + + Ref<ConfigFile> config; + config.instantiate(); + ERR_FAIL_NULL(config); + + Error err = config->load(p_path + ".import"); + print_verbose("Loading import settings:"); + if (err == OK) { + List<String> keys; + config->get_section_keys("params", &keys); + for (List<String>::Element *E = keys.front(); E; E = E->next()) { + String key = E->get(); + print_verbose(String(" ") + key + " == " + String(config->get_value("params", key))); + if (key == "preload/char_ranges") { + Vector<String> ranges = config->get_value("params", key); + for (int i = 0; i < ranges.size(); i++) { + int32_t start, end; + Vector<String> tokens = ranges[i].split("-"); + if (tokens.size() == 2) { + if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start) || !ResourceImporterDynamicFont::_decode_range(tokens[1], end)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + } else if (tokens.size() == 1) { + if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + end = start; + } else { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + for (int32_t j = start; j <= end; j++) { + selected_chars.insert(j); + } + } + } else if (key == "preload/glyph_ranges") { + Vector<String> ranges = config->get_value("params", key); + for (int i = 0; i < ranges.size(); i++) { + int32_t start, end; + Vector<String> tokens = ranges[i].split("-"); + if (tokens.size() == 2) { + if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start) || !ResourceImporterDynamicFont::_decode_range(tokens[1], end)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + } else if (tokens.size() == 1) { + if (!ResourceImporterDynamicFont::_decode_range(tokens[0], start)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + end = start; + } else { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + for (int32_t j = start; j <= end; j++) { + selected_glyphs.insert(j); + } + } + } else if (key == "preload/configurations") { + Vector<String> variations = config->get_value("params", key); + for (int i = 0; i < variations.size(); i++) { + TreeItem *vars_item = vars_list->create_item(vars_list_root); + ERR_FAIL_NULL(vars_item); + + vars_item->set_text(0, TTR("Configuration") + " " + itos(i)); + vars_item->set_editable(0, true); + vars_item->add_button(1, vars_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove Variation")); + vars_item->set_button_color(1, 0, Color(1, 1, 1, 0.75)); + + Ref<DynamicFontImportSettingsData> import_variation_data_custom; + import_variation_data_custom.instantiate(); + import_variation_data_custom->owner = this; + ERR_FAIL_NULL(import_variation_data_custom); + + for (List<ResourceImporter::ImportOption>::Element *F = options_variations.front(); F; F = F->next()) { + import_variation_data_custom->defaults[F->get().option.name] = F->get().default_value; + } + + import_variation_data_custom->options = options_variations; + + vars_item->set_metadata(0, import_variation_data_custom); + Vector<String> variation_tags = variations[i].split(","); + for (int j = 0; j < variation_tags.size(); j++) { + Vector<String> tokens = variation_tags[j].split("="); + if (tokens[0] == "name") { + vars_item->set_text(0, tokens[1]); + } else if (tokens[0] == "size" || tokens[0] == "outline_size" || tokens[0] == "extra_spacing_space" || tokens[0] == "extra_spacing_glyph") { + import_variation_data_custom->set(tokens[0], tokens[1].to_int()); + } else { + import_variation_data_custom->set(tokens[0], tokens[1].to_float()); + } + } + } + } else if (key == "support_overrides/language_enabled") { + PackedStringArray _langs = config->get_value("params", key); + for (int i = 0; i < _langs.size(); i++) { + TreeItem *lang_item = lang_list->create_item(lang_list_root); + ERR_FAIL_NULL(lang_item); + + lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + lang_item->set_editable(0, true); + lang_item->set_checked(0, true); + lang_item->set_text(1, _langs[i]); + lang_item->set_editable(1, true); + lang_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + } + } else if (key == "support_overrides/language_disabled") { + PackedStringArray _langs = config->get_value("params", key); + for (int i = 0; i < _langs.size(); i++) { + TreeItem *lang_item = lang_list->create_item(lang_list_root); + ERR_FAIL_NULL(lang_item); + + lang_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + lang_item->set_editable(0, true); + lang_item->set_checked(0, false); + lang_item->set_text(1, _langs[i]); + lang_item->set_editable(1, true); + lang_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + } + } else if (key == "support_overrides/script_enabled") { + PackedStringArray _scripts = config->get_value("params", key); + for (int i = 0; i < _scripts.size(); i++) { + TreeItem *script_item = script_list->create_item(script_list_root); + ERR_FAIL_NULL(script_item); + + script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + script_item->set_editable(0, true); + script_item->set_checked(0, true); + script_item->set_text(1, _scripts[i]); + script_item->set_editable(1, true); + script_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + } + } else if (key == "support_overrides/script_disabled") { + PackedStringArray _scripts = config->get_value("params", key); + for (int i = 0; i < _scripts.size(); i++) { + TreeItem *script_item = script_list->create_item(script_list_root); + ERR_FAIL_NULL(script_item); + + script_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + script_item->set_editable(0, true); + script_item->set_checked(0, false); + script_item->set_text(1, _scripts[i]); + script_item->set_editable(1, true); + script_item->add_button(2, lang_list->get_theme_icon("Remove", "EditorIcons"), BUTTON_REMOVE_VAR, false, TTR("Remove")); + } + } else { + Variant value = config->get_value("params", key); + import_settings_data->defaults[key] = value; + } + } + } + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(selected_glyphs.size())); + + import_settings_data->options = options_general; + inspector_general->edit(import_settings_data.ptr()); + import_settings_data->notify_property_list_changed(); + + if (font_preview->get_data_count() > 0) { + font_preview->get_data(0)->set_antialiased(import_settings_data->get("antialiased")); + font_preview->get_data(0)->set_multichannel_signed_distance_field(import_settings_data->get("multichannel_signed_distance_field")); + font_preview->get_data(0)->set_msdf_pixel_range(import_settings_data->get("msdf_pixel_range")); + font_preview->get_data(0)->set_msdf_size(import_settings_data->get("msdf_size")); + font_preview->get_data(0)->set_force_autohinter(import_settings_data->get("force_autohinter")); + font_preview->get_data(0)->set_hinting((TextServer::Hinting)import_settings_data->get("hinting").operator int()); + font_preview->get_data(0)->set_oversampling(import_settings_data->get("oversampling")); + } + font_preview_label->add_theme_font_override("font", font_preview); + font_preview_label->update(); + + _variations_validate(); + + popup_centered_ratio(); + + set_title(vformat(TTR("Advanced Import Settings for '%s'"), base_path.get_file())); +} + +DynamicFontImportSettings *DynamicFontImportSettings::get_singleton() { + return singleton; +} + +DynamicFontImportSettings::DynamicFontImportSettings() { + singleton = this; + + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "antialiased"), true)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), true)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0)); + options_general.push_back(ResourceImporter::ImportOption(PropertyInfo(Variant::BOOL, "compress", PROPERTY_HINT_NONE, ""), false)); + + // Popup menus + + menu_langs = memnew(PopupMenu); + menu_langs->set_name("Language"); + for (int i = 0; langs[i].name != String(); i++) { + if (langs[i].name == "-") { + menu_langs->add_separator(); + } else { + menu_langs->add_item(langs[i].name + " (" + langs[i].code + ")", i); + } + } + add_child(menu_langs); + menu_langs->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_lang_add_item)); + + menu_scripts = memnew(PopupMenu); + menu_scripts->set_name("Script"); + for (int i = 0; scripts[i].name != String(); i++) { + if (scripts[i].name == "-") { + menu_scripts->add_separator(); + } else { + menu_scripts->add_item(scripts[i].name + " (" + scripts[i].code + ")", i); + } + } + add_child(menu_scripts); + menu_scripts->connect("id_pressed", callable_mp(this, &DynamicFontImportSettings::_script_add_item)); + + Color warn_color = (EditorNode::get_singleton()) ? EditorNode::get_singleton()->get_gui_base()->get_theme_color("warning_color", "Editor") : Color(1, 1, 0); + + // Root layout + + VBoxContainer *root_vb = memnew(VBoxContainer); + add_child(root_vb); + + main_pages = memnew(TabContainer); + main_pages->set_v_size_flags(Control::SIZE_EXPAND_FILL); + main_pages->set_h_size_flags(Control::SIZE_EXPAND_FILL); + root_vb->add_child(main_pages); + + label_warn = memnew(Label); + label_warn->set_align(Label::ALIGN_CENTER); + label_warn->set_text(""); + root_vb->add_child(label_warn); + label_warn->add_theme_color_override("font_color", warn_color); + label_warn->hide(); + + // Page 1 layout: Rendering Options + + VBoxContainer *page1_vb = memnew(VBoxContainer); + page1_vb->set_meta("_tab_name", TTR("Rendering options")); + main_pages->add_child(page1_vb); + + page1_description = memnew(Label); + page1_description->set_text(TTR("Select font rendering options:")); + page1_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page1_vb->add_child(page1_description); + + HSplitContainer *page1_hb = memnew(HSplitContainer); + page1_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL); + page1_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page1_vb->add_child(page1_hb); + + font_preview_label = memnew(Label); + font_preview_label->add_theme_font_size_override("font_size", 200 * EDSCALE); + font_preview_label->set_align(Label::ALIGN_CENTER); + font_preview_label->set_valign(Label::VALIGN_CENTER); + font_preview_label->set_autowrap_mode(Label::AUTOWRAP_ARBITRARY); + font_preview_label->set_clip_text(true); + font_preview_label->set_v_size_flags(Control::SIZE_EXPAND_FILL); + font_preview_label->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page1_hb->add_child(font_preview_label); + + inspector_general = memnew(EditorInspector); + inspector_general->set_v_size_flags(Control::SIZE_EXPAND_FILL); + inspector_general->set_custom_minimum_size(Size2(300 * EDSCALE, 250 * EDSCALE)); + inspector_general->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_main_prop_changed)); + page1_hb->add_child(inspector_general); + + // Page 2 layout: Configurations + VBoxContainer *page2_vb = memnew(VBoxContainer); + page2_vb->set_meta("_tab_name", TTR("Sizes and variations")); + main_pages->add_child(page2_vb); + + page2_description = memnew(Label); + page2_description->set_text(TTR("Add font size, variation coordinates, and extra spacing combinations to pre-render:")); + page2_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page2_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); + page2_vb->add_child(page2_description); + + HSplitContainer *page2_hb = memnew(HSplitContainer); + page2_hb->set_v_size_flags(Control::SIZE_EXPAND_FILL); + page2_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page2_vb->add_child(page2_hb); + + VBoxContainer *page2_side_vb = memnew(VBoxContainer); + page2_hb->add_child(page2_side_vb); + + HBoxContainer *page2_hb_vars = memnew(HBoxContainer); + page2_side_vb->add_child(page2_hb_vars); + + label_vars = memnew(Label); + page2_hb_vars->add_child(label_vars); + label_vars->set_align(Label::ALIGN_CENTER); + label_vars->set_h_size_flags(Control::SIZE_EXPAND_FILL); + label_vars->set_text(TTR("Configuration:")); + + add_var = memnew(Button); + page2_hb_vars->add_child(add_var); + add_var->set_tooltip(TTR("Add configuration")); + add_var->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + add_var->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_variation_add)); + + vars_list = memnew(Tree); + page2_side_vb->add_child(vars_list); + vars_list->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); + vars_list->set_hide_root(true); + vars_list->set_columns(2); + vars_list->set_column_expand(0, true); + vars_list->set_column_custom_minimum_width(0, 80 * EDSCALE); + vars_list->set_column_expand(1, false); + vars_list->set_column_custom_minimum_width(1, 50 * EDSCALE); + vars_list->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_variation_selected)); + vars_list->connect("button_pressed", callable_mp(this, &DynamicFontImportSettings::_variation_remove)); + vars_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + + inspector_vars = memnew(EditorInspector); + inspector_vars->set_v_size_flags(Control::SIZE_EXPAND_FILL); + inspector_vars->connect("property_edited", callable_mp(this, &DynamicFontImportSettings::_variation_changed)); + page2_hb->add_child(inspector_vars); + + // Page 3 layout: Text to select glyphs + VBoxContainer *page3_vb = memnew(VBoxContainer); + page3_vb->set_meta("_tab_name", TTR("Glyphs from the text")); + main_pages->add_child(page3_vb); + + page3_description = memnew(Label); + page3_description->set_text(TTR("Enter a text to shape and add all required glyphs to pre-render list:")); + page3_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page3_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); + page3_vb->add_child(page3_description); + + HBoxContainer *ot_hb = memnew(HBoxContainer); + page3_vb->add_child(ot_hb); + ot_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + Label *label_ed_ftr = memnew(Label); + ot_hb->add_child(label_ed_ftr); + label_ed_ftr->set_text(TTR("OpenType features:")); + + ftr_edit = memnew(LineEdit); + ot_hb->add_child(ftr_edit); + ftr_edit->connect("text_changed", callable_mp(this, &DynamicFontImportSettings::_change_text_opts)); + ftr_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + Label *label_ed_lang = memnew(Label); + ot_hb->add_child(label_ed_lang); + label_ed_lang->set_text(TTR("Text language:")); + + lang_edit = memnew(LineEdit); + ot_hb->add_child(lang_edit); + lang_edit->connect("text_changed", callable_mp(this, &DynamicFontImportSettings::_change_text_opts)); + lang_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + text_edit = memnew(TextEdit); + page3_vb->add_child(text_edit); + text_edit->set_v_size_flags(Control::SIZE_EXPAND_FILL); + text_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + HBoxContainer *text_hb = memnew(HBoxContainer); + page3_vb->add_child(text_hb); + text_hb->set_h_size_flags(Control::SIZE_EXPAND_FILL); + + label_glyphs = memnew(Label); + text_hb->add_child(label_glyphs); + label_glyphs->set_text(TTR("Preloaded glyphs: ") + itos(0)); + label_glyphs->set_custom_minimum_size(Size2(50 * EDSCALE, 0)); + + Button *btn_fill = memnew(Button); + text_hb->add_child(btn_fill); + btn_fill->set_text(TTR("Shape text and add glyphs")); + btn_fill->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_glyph_text_selected)); + + Button *btn_clear = memnew(Button); + text_hb->add_child(btn_clear); + btn_clear->set_text(TTR("Clear glyph list")); + btn_clear->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_glyph_clear)); + + // Page 4 layout: Character map + VBoxContainer *page4_vb = memnew(VBoxContainer); + page4_vb->set_meta("_tab_name", TTR("Glyphs from the character map")); + main_pages->add_child(page4_vb); + + page4_description = memnew(Label); + page4_description->set_text(TTR("Add or remove additional glyphs from the character map to pre-render list:\nNote: Some stylistic alternatives and glyph variants do not have one-to-one correspondence to character, and not shown in this map, use \"Glyphs from the text\" to add these.")); + page4_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page4_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); + page4_vb->add_child(page4_description); + + HSplitContainer *glyphs_split = memnew(HSplitContainer); + glyphs_split->set_v_size_flags(Control::SIZE_EXPAND_FILL); + glyphs_split->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page4_vb->add_child(glyphs_split); + + glyph_table = memnew(Tree); + glyphs_split->add_child(glyph_table); + glyph_table->set_custom_minimum_size(Size2((30 * 16 + 100) * EDSCALE, 0)); + glyph_table->set_columns(17); + glyph_table->set_column_expand(0, false); + glyph_table->set_hide_root(true); + glyph_table->set_allow_reselect(true); + glyph_table->set_select_mode(Tree::SELECT_SINGLE); + glyph_table->connect("item_activated", callable_mp(this, &DynamicFontImportSettings::_glyph_selected)); + glyph_table->set_column_titles_visible(true); + for (int i = 0; i < 16; i++) { + glyph_table->set_column_title(i + 1, String::num_int64(i, 16)); + } + glyph_table->add_theme_style_override("selected", glyph_table->get_theme_stylebox("bg")); + glyph_table->add_theme_style_override("selected_focus", glyph_table->get_theme_stylebox("bg")); + glyph_table->add_theme_constant_override("hseparation", 0); + glyph_table->set_h_size_flags(Control::SIZE_EXPAND_FILL); + glyph_table->set_v_size_flags(Control::SIZE_EXPAND_FILL); + + glyph_tree = memnew(Tree); + glyphs_split->add_child(glyph_tree); + glyph_tree->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); + glyph_tree->set_columns(3); + glyph_tree->set_hide_root(true); + glyph_tree->set_column_expand(0, false); + glyph_tree->set_column_expand(1, true); + glyph_tree->set_column_custom_minimum_width(0, 120 * EDSCALE); + glyph_tree->connect("item_activated", callable_mp(this, &DynamicFontImportSettings::_range_edited)); + glyph_tree->connect("item_selected", callable_mp(this, &DynamicFontImportSettings::_range_selected)); + glyph_tree->set_v_size_flags(Control::SIZE_EXPAND_FILL); + glyph_root = glyph_tree->create_item(); + for (int i = 0; unicode_ranges[i].name != String(); i++) { + _add_glyph_range_item(unicode_ranges[i].start, unicode_ranges[i].end, unicode_ranges[i].name); + } + + // Page 4 layout: Metadata override + VBoxContainer *page5_vb = memnew(VBoxContainer); + page5_vb->set_meta("_tab_name", TTR("Metadata override")); + main_pages->add_child(page5_vb); + + page5_description = memnew(Label); + page5_description->set_text(TTR("Add or remove language and script support overrides, to control fallback font selection order:")); + page5_description->set_h_size_flags(Control::SIZE_EXPAND_FILL); + page5_description->set_autowrap_mode(Label::AUTOWRAP_WORD_SMART); + page5_vb->add_child(page5_description); + + HBoxContainer *hb_lang = memnew(HBoxContainer); + page5_vb->add_child(hb_lang); + + label_langs = memnew(Label); + label_langs->set_align(Label::ALIGN_CENTER); + label_langs->set_h_size_flags(Control::SIZE_EXPAND_FILL); + label_langs->set_text(TTR("Language support overrides")); + hb_lang->add_child(label_langs); + + add_lang = memnew(Button); + hb_lang->add_child(add_lang); + add_lang->set_tooltip(TTR("Add language override")); + add_lang->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + add_lang->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_lang_add)); + + lang_list = memnew(Tree); + page5_vb->add_child(lang_list); + lang_list->set_hide_root(true); + lang_list->set_columns(3); + lang_list->set_column_expand(0, false); // Check + lang_list->set_column_custom_minimum_width(0, 50 * EDSCALE); + lang_list->set_column_expand(1, true); + lang_list->set_column_custom_minimum_width(1, 80 * EDSCALE); + lang_list->set_column_expand(2, false); + lang_list->set_column_custom_minimum_width(2, 50 * EDSCALE); + lang_list->connect("button_pressed", callable_mp(this, &DynamicFontImportSettings::_lang_remove)); + lang_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + + HBoxContainer *hb_script = memnew(HBoxContainer); + page5_vb->add_child(hb_script); + + label_script = memnew(Label); + label_script->set_align(Label::ALIGN_CENTER); + label_script->set_h_size_flags(Control::SIZE_EXPAND_FILL); + label_script->set_text(TTR("Script support overrides")); + hb_script->add_child(label_script); + + add_script = memnew(Button); + hb_script->add_child(add_script); + add_script->set_tooltip(TTR("Add script override")); + add_script->set_icon(add_var->get_theme_icon("Add", "EditorIcons")); + add_script->connect("pressed", callable_mp(this, &DynamicFontImportSettings::_script_add)); + + script_list = memnew(Tree); + page5_vb->add_child(script_list); + script_list->set_hide_root(true); + script_list->set_columns(3); + script_list->set_column_expand(0, false); + script_list->set_column_custom_minimum_width(0, 50 * EDSCALE); + script_list->set_column_expand(1, true); + script_list->set_column_custom_minimum_width(1, 80 * EDSCALE); + script_list->set_column_expand(2, false); + script_list->set_column_custom_minimum_width(2, 50 * EDSCALE); + script_list->connect("button_pressed", callable_mp(this, &DynamicFontImportSettings::_script_remove)); + script_list->set_v_size_flags(Control::SIZE_EXPAND_FILL); + + // Common + + import_settings_data.instantiate(); + import_settings_data->owner = this; + + get_ok_button()->set_text(TTR("Reimport")); + get_cancel_button()->set_text(TTR("Close")); +} diff --git a/editor/import/dynamicfont_import_settings.h b/editor/import/dynamicfont_import_settings.h new file mode 100644 index 0000000000..05f5e8e00b --- /dev/null +++ b/editor/import/dynamicfont_import_settings.h @@ -0,0 +1,167 @@ +/*************************************************************************/ +/* dynamicfont_import_settings.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef FONTDATA_IMPORT_SETTINGS_H +#define FONTDATA_IMPORT_SETTINGS_H + +#include "editor/editor_file_dialog.h" +#include "editor/editor_inspector.h" + +#include "editor/import/resource_importer_dynamicfont.h" + +#include "scene/gui/dialogs.h" +#include "scene/gui/item_list.h" +#include "scene/gui/option_button.h" +#include "scene/gui/split_container.h" +#include "scene/gui/subviewport_container.h" +#include "scene/gui/tab_container.h" +#include "scene/gui/text_edit.h" +#include "scene/gui/tree.h" + +#include "scene/resources/font.h" +#include "servers/text_server.h" + +class DynamicFontImportSettingsData; + +class DynamicFontImportSettings : public ConfirmationDialog { + GDCLASS(DynamicFontImportSettings, ConfirmationDialog) + friend class DynamicFontImportSettingsData; + + enum ItemButton { + BUTTON_ADD_VAR, + BUTTON_REMOVE_VAR, + }; + + static DynamicFontImportSettings *singleton; + + String base_path; + + Ref<DynamicFontImportSettingsData> import_settings_data; + List<ResourceImporter::ImportOption> options_variations; + List<ResourceImporter::ImportOption> options_general; + + // Root layout + Label *label_warn = nullptr; + TabContainer *main_pages = nullptr; + + // Page 1 layout: Rendering Options + Label *page1_description = nullptr; + Label *font_preview_label = nullptr; + EditorInspector *inspector_general = nullptr; + + void _main_prop_changed(const String &p_edited_property); + + // Page 2 layout: Configurations + Label *page2_description = nullptr; + Label *label_vars = nullptr; + Button *add_var = nullptr; + Tree *vars_list = nullptr; + TreeItem *vars_list_root = nullptr; + EditorInspector *inspector_vars = nullptr; + + void _variation_add(); + void _variation_selected(); + void _variation_remove(Object *p_item, int p_column, int p_id); + void _variation_changed(const String &p_edited_property); + void _variations_validate(); + + // Page 3 layout: Text to select glyphs + Label *page3_description = nullptr; + Label *label_glyphs = nullptr; + TextEdit *text_edit = nullptr; + LineEdit *ftr_edit = nullptr; + LineEdit *lang_edit = nullptr; + + void _change_text_opts(); + void _glyph_text_selected(); + void _glyph_clear(); + + // Page 4 layout: Character map + Label *page4_description = nullptr; + Tree *glyph_table = nullptr; + Tree *glyph_tree = nullptr; + TreeItem *glyph_root = nullptr; + + void _glyph_selected(); + void _range_edited(); + void _range_selected(); + void _edit_range(int32_t p_start, int32_t p_end); + bool _char_update(int32_t p_char); + void _range_update(int32_t p_start, int32_t p_end); + + // Page 5 layout: Metadata override + Label *page5_description = nullptr; + Button *add_lang = nullptr; + Button *add_script = nullptr; + + PopupMenu *menu_langs = nullptr; + PopupMenu *menu_scripts = nullptr; + + Tree *lang_list = nullptr; + TreeItem *lang_list_root = nullptr; + + Tree *script_list = nullptr; + TreeItem *script_list_root = nullptr; + Label *label_langs = nullptr; + Label *label_script = nullptr; + + void _lang_add(); + void _lang_add_item(int p_option); + void _lang_remove(Object *p_item, int p_column, int p_id); + + void _script_add(); + void _script_add_item(int p_option); + void _script_remove(Object *p_item, int p_column, int p_id); + + // Common + + void _add_glyph_range_item(int32_t p_start, int32_t p_end, const String &p_name); + + Ref<Font> font_preview; + Ref<Font> font_main; + + Set<char32_t> selected_chars; + Set<int32_t> selected_glyphs; + + void _re_import(); + + String _pad_zeros(const String &p_hex) const; + +protected: + void _notification(int p_what); + +public: + void open_settings(const String &p_path); + static DynamicFontImportSettings *get_singleton(); + + DynamicFontImportSettings(); +}; + +#endif // FONTDATA_IMPORT_SETTINGS_H diff --git a/editor/import/editor_import_collada.cpp b/editor/import/editor_import_collada.cpp index 54b93edcdd..7ab80ac3b4 100644 --- a/editor/import/editor_import_collada.cpp +++ b/editor/import/editor_import_collada.cpp @@ -504,61 +504,121 @@ Error ColladaImport::_create_mesh_surfaces(bool p_optimize, Ref<EditorSceneImpor const Collada::MeshData::Source *normal_src = nullptr; int normal_ofs = 0; - if (p.sources.has("NORMAL")) { - String normal_source_id = p.sources["NORMAL"].source; - normal_ofs = p.sources["NORMAL"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA); - normal_src = &meshdata.sources[normal_source_id]; + { + String normal_source_id = ""; + + if (p.sources.has("NORMAL")) { + normal_source_id = p.sources["NORMAL"].source; + normal_ofs = p.sources["NORMAL"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("NORMAL")) { + normal_source_id = meshdata.vertices[vertex_src_id].sources["NORMAL"]; + normal_ofs = vertex_ofs; + } + + if (normal_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(normal_source_id), ERR_INVALID_DATA); + normal_src = &meshdata.sources[normal_source_id]; + } } const Collada::MeshData::Source *binormal_src = nullptr; int binormal_ofs = 0; - if (p.sources.has("TEXBINORMAL")) { - String binormal_source_id = p.sources["TEXBINORMAL"].source; - binormal_ofs = p.sources["TEXBINORMAL"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA); - binormal_src = &meshdata.sources[binormal_source_id]; + { + String binormal_source_id = ""; + + if (p.sources.has("TEXBINORMAL")) { + binormal_source_id = p.sources["TEXBINORMAL"].source; + binormal_ofs = p.sources["TEXBINORMAL"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("TEXBINORMAL")) { + binormal_source_id = meshdata.vertices[vertex_src_id].sources["TEXBINORMAL"]; + binormal_ofs = vertex_ofs; + } + + if (binormal_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(binormal_source_id), ERR_INVALID_DATA); + binormal_src = &meshdata.sources[binormal_source_id]; + } } const Collada::MeshData::Source *tangent_src = nullptr; int tangent_ofs = 0; - if (p.sources.has("TEXTANGENT")) { - String tangent_source_id = p.sources["TEXTANGENT"].source; - tangent_ofs = p.sources["TEXTANGENT"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA); - tangent_src = &meshdata.sources[tangent_source_id]; + { + String tangent_source_id = ""; + + if (p.sources.has("TEXTANGENT")) { + tangent_source_id = p.sources["TEXTANGENT"].source; + tangent_ofs = p.sources["TEXTANGENT"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("TEXTANGENT")) { + tangent_source_id = meshdata.vertices[vertex_src_id].sources["TEXTANGENT"]; + tangent_ofs = vertex_ofs; + } + + if (tangent_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(tangent_source_id), ERR_INVALID_DATA); + tangent_src = &meshdata.sources[tangent_source_id]; + } } const Collada::MeshData::Source *uv_src = nullptr; int uv_ofs = 0; - if (p.sources.has("TEXCOORD0")) { - String uv_source_id = p.sources["TEXCOORD0"].source; - uv_ofs = p.sources["TEXCOORD0"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA); - uv_src = &meshdata.sources[uv_source_id]; + { + String uv_source_id = ""; + + if (p.sources.has("TEXCOORD0")) { + uv_source_id = p.sources["TEXCOORD0"].source; + uv_ofs = p.sources["TEXCOORD0"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("TEXCOORD0")) { + uv_source_id = meshdata.vertices[vertex_src_id].sources["TEXCOORD0"]; + uv_ofs = vertex_ofs; + } + + if (uv_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(uv_source_id), ERR_INVALID_DATA); + uv_src = &meshdata.sources[uv_source_id]; + } } const Collada::MeshData::Source *uv2_src = nullptr; int uv2_ofs = 0; - if (p.sources.has("TEXCOORD1")) { - String uv2_source_id = p.sources["TEXCOORD1"].source; - uv2_ofs = p.sources["TEXCOORD1"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA); - uv2_src = &meshdata.sources[uv2_source_id]; + { + String uv2_source_id = ""; + + if (p.sources.has("TEXCOORD1")) { + uv2_source_id = p.sources["TEXCOORD1"].source; + uv2_ofs = p.sources["TEXCOORD1"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("TEXCOORD1")) { + uv2_source_id = meshdata.vertices[vertex_src_id].sources["TEXCOORD1"]; + uv2_ofs = vertex_ofs; + } + + if (uv2_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(uv2_source_id), ERR_INVALID_DATA); + uv2_src = &meshdata.sources[uv2_source_id]; + } } const Collada::MeshData::Source *color_src = nullptr; int color_ofs = 0; - if (p.sources.has("COLOR")) { - String color_source_id = p.sources["COLOR"].source; - color_ofs = p.sources["COLOR"].offset; - ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA); - color_src = &meshdata.sources[color_source_id]; + { + String color_source_id = ""; + + if (p.sources.has("COLOR")) { + color_source_id = p.sources["COLOR"].source; + color_ofs = p.sources["COLOR"].offset; + } else if (meshdata.vertices[vertex_src_id].sources.has("COLOR")) { + color_source_id = meshdata.vertices[vertex_src_id].sources["COLOR"]; + color_ofs = vertex_ofs; + } + + if (color_source_id != "") { + ERR_FAIL_COND_V(!meshdata.sources.has(color_source_id), ERR_INVALID_DATA); + color_src = &meshdata.sources[color_source_id]; + } } //find largest source.. diff --git a/editor/import/editor_import_plugin.cpp b/editor/import/editor_import_plugin.cpp index 8660289c40..d219f6e325 100644 --- a/editor/import/editor_import_plugin.cpp +++ b/editor/import/editor_import_plugin.cpp @@ -35,102 +35,131 @@ EditorImportPlugin::EditorImportPlugin() { } String EditorImportPlugin::get_importer_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_importer_name")), ""); - return get_script_instance()->call("_get_importer_name"); + String ret; + if (GDVIRTUAL_CALL(_get_importer_name, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_importer_name in add-on."); } String EditorImportPlugin::get_visible_name() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_visible_name")), ""); - return get_script_instance()->call("_get_visible_name"); + String ret; + if (GDVIRTUAL_CALL(_get_visible_name, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_visible_name in add-on."); } void EditorImportPlugin::get_recognized_extensions(List<String> *p_extensions) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_recognized_extensions"))); - Array extensions = get_script_instance()->call("_get_recognized_extensions"); - for (int i = 0; i < extensions.size(); i++) { - p_extensions->push_back(extensions[i]); + Vector<String> extensions; + + if (GDVIRTUAL_CALL(_get_recognized_extensions, extensions)) { + for (int i = 0; i < extensions.size(); i++) { + p_extensions->push_back(extensions[i]); + } } + ERR_FAIL_MSG("Unimplemented _get_recognized_extensions in add-on."); } String EditorImportPlugin::get_preset_name(int p_idx) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_name")), ""); - return get_script_instance()->call("_get_preset_name", p_idx); + String ret; + if (GDVIRTUAL_CALL(_get_preset_name, p_idx, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_preset_name in add-on."); } int EditorImportPlugin::get_preset_count() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_preset_count")), 0); - return get_script_instance()->call("_get_preset_count"); + int ret; + if (GDVIRTUAL_CALL(_get_preset_count, ret)) { + return ret; + } + ERR_FAIL_V_MSG(-1, "Unimplemented _get_preset_count in add-on."); } String EditorImportPlugin::get_save_extension() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_save_extension")), ""); - return get_script_instance()->call("_get_save_extension"); + String ret; + if (GDVIRTUAL_CALL(_get_save_extension, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_save_extension in add-on."); } String EditorImportPlugin::get_resource_type() const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_resource_type")), ""); - return get_script_instance()->call("_get_resource_type"); + String ret; + if (GDVIRTUAL_CALL(_get_resource_type, ret)) { + return ret; + } + ERR_FAIL_V_MSG(String(), "Unimplemented _get_resource_type in add-on."); } float EditorImportPlugin::get_priority() const { - if (!(get_script_instance() && get_script_instance()->has_method("_get_priority"))) { - return ResourceImporter::get_priority(); + float ret; + if (GDVIRTUAL_CALL(_get_priority, ret)) { + return ret; } - return get_script_instance()->call("_get_priority"); + ERR_FAIL_V_MSG(-1, "Unimplemented _get_priority in add-on."); } int EditorImportPlugin::get_import_order() const { - if (!(get_script_instance() && get_script_instance()->has_method("_get_import_order"))) { - return ResourceImporter::get_import_order(); + int ret; + if (GDVIRTUAL_CALL(_get_import_order, ret)) { + return ret; } - return get_script_instance()->call("_get_import_order"); + ERR_FAIL_V_MSG(-1, "Unimplemented _get_import_order in add-on."); } void EditorImportPlugin::get_import_options(List<ResourceImporter::ImportOption> *r_options, int p_preset) const { - ERR_FAIL_COND(!(get_script_instance() && get_script_instance()->has_method("_get_import_options"))); Array needed; needed.push_back("name"); needed.push_back("default_value"); - Array options = get_script_instance()->call("_get_import_options", p_preset); - for (int i = 0; i < options.size(); i++) { - Dictionary d = options[i]; - ERR_FAIL_COND(!d.has_all(needed)); - String name = d["name"]; - Variant default_value = d["default_value"]; - - PropertyHint hint = PROPERTY_HINT_NONE; - if (d.has("property_hint")) { - hint = (PropertyHint)d["property_hint"].operator int64_t(); - } - - String hint_string; - if (d.has("hint_string")) { - hint_string = d["hint_string"]; + Array options; + if (GDVIRTUAL_CALL(_get_import_options, p_preset, options)) { + for (int i = 0; i < options.size(); i++) { + Dictionary d = options[i]; + ERR_FAIL_COND(!d.has_all(needed)); + String name = d["name"]; + Variant default_value = d["default_value"]; + + PropertyHint hint = PROPERTY_HINT_NONE; + if (d.has("property_hint")) { + hint = (PropertyHint)d["property_hint"].operator int64_t(); + } + + String hint_string; + if (d.has("hint_string")) { + hint_string = d["hint_string"]; + } + + uint32_t usage = PROPERTY_USAGE_DEFAULT; + if (d.has("usage")) { + usage = d["usage"]; + } + + ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value); + r_options->push_back(option); } - - uint32_t usage = PROPERTY_USAGE_DEFAULT; - if (d.has("usage")) { - usage = d["usage"]; - } - - ImportOption option(PropertyInfo(default_value.get_type(), name, hint, hint_string, usage), default_value); - r_options->push_back(option); } + + ERR_FAIL_MSG("Unimplemented _get_import_options in add-on."); } bool EditorImportPlugin::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_get_option_visibility")), true); Dictionary d; Map<StringName, Variant>::Element *E = p_options.front(); while (E) { d[E->key()] = E->get(); E = E->next(); } - return get_script_instance()->call("_get_option_visibility", p_option, d); + bool visible; + if (GDVIRTUAL_CALL(_get_option_visibility, p_option, d, visible)) { + return visible; + } + + ERR_FAIL_V_MSG(false, "Unimplemented _get_option_visibility in add-on."); } Error EditorImportPlugin::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { - ERR_FAIL_COND_V(!(get_script_instance() && get_script_instance()->has_method("_import")), ERR_UNAVAILABLE); Dictionary options; Array platform_variants, gen_files; @@ -139,28 +168,33 @@ Error EditorImportPlugin::import(const String &p_source_file, const String &p_sa options[E->key()] = E->get(); E = E->next(); } - Error err = (Error)get_script_instance()->call("_import", p_source_file, p_save_path, options, platform_variants, gen_files).operator int64_t(); - for (int i = 0; i < platform_variants.size(); i++) { - r_platform_variants->push_back(platform_variants[i]); - } - for (int i = 0; i < gen_files.size(); i++) { - r_gen_files->push_back(gen_files[i]); + int err; + if (GDVIRTUAL_CALL(_import, p_source_file, p_save_path, options, platform_variants, gen_files, err)) { + Error ret_err = Error(err); + + for (int i = 0; i < platform_variants.size(); i++) { + r_platform_variants->push_back(platform_variants[i]); + } + for (int i = 0; i < gen_files.size(); i++) { + r_gen_files->push_back(gen_files[i]); + } + return ret_err; } - return err; + ERR_FAIL_V_MSG(ERR_METHOD_NOT_FOUND, "Unimplemented _import in add-on."); } void EditorImportPlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_importer_name")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_visible_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_preset_count")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_preset_name", PropertyInfo(Variant::INT, "preset"))); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_recognized_extensions")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_import_options", PropertyInfo(Variant::INT, "preset"))); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_save_extension")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_resource_type")); - BIND_VMETHOD(MethodInfo(Variant::FLOAT, "_get_priority")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_order")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_get_option_visibility", PropertyInfo(Variant::STRING, "option"), PropertyInfo(Variant::DICTIONARY, "options"))); - BIND_VMETHOD(MethodInfo(Variant::INT, "_import", PropertyInfo(Variant::STRING, "source_file"), PropertyInfo(Variant::STRING, "save_path"), PropertyInfo(Variant::DICTIONARY, "options"), PropertyInfo(Variant::ARRAY, "platform_variants"), PropertyInfo(Variant::ARRAY, "gen_files"))); + GDVIRTUAL_BIND(_get_importer_name) + GDVIRTUAL_BIND(_get_visible_name) + GDVIRTUAL_BIND(_get_preset_count) + GDVIRTUAL_BIND(_get_preset_name, "preset_index") + GDVIRTUAL_BIND(_get_recognized_extensions) + GDVIRTUAL_BIND(_get_import_options, "preset_index") + GDVIRTUAL_BIND(_get_save_extension) + GDVIRTUAL_BIND(_get_resource_type) + GDVIRTUAL_BIND(_get_priority) + GDVIRTUAL_BIND(_get_import_order) + GDVIRTUAL_BIND(_get_option_visibility, "option_name", "options") + GDVIRTUAL_BIND(_import, "source_file", "save_path", "options", "platform_variants", "gen_files"); } diff --git a/editor/import/editor_import_plugin.h b/editor/import/editor_import_plugin.h index 345a40e96d..49c959ab44 100644 --- a/editor/import/editor_import_plugin.h +++ b/editor/import/editor_import_plugin.h @@ -39,6 +39,19 @@ class EditorImportPlugin : public ResourceImporter { protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _get_importer_name) + GDVIRTUAL0RC(String, _get_visible_name) + GDVIRTUAL0RC(int, _get_preset_count) + GDVIRTUAL1RC(String, _get_preset_name, int) + GDVIRTUAL0RC(Vector<String>, _get_recognized_extensions) + GDVIRTUAL1RC(Array, _get_import_options, int) + GDVIRTUAL0RC(String, _get_save_extension) + GDVIRTUAL0RC(String, _get_resource_type) + GDVIRTUAL0RC(float, _get_priority) + GDVIRTUAL0RC(int, _get_import_order) + GDVIRTUAL2RC(bool, _get_option_visibility, StringName, Dictionary) + GDVIRTUAL5RC(int, _import, String, String, Dictionary, Array, Array) + public: EditorImportPlugin(); virtual String get_importer_name() const override; diff --git a/editor/import/resource_importer_bmfont.cpp b/editor/import/resource_importer_bmfont.cpp new file mode 100644 index 0000000000..2e7ef1402b --- /dev/null +++ b/editor/import/resource_importer_bmfont.cpp @@ -0,0 +1,797 @@ +/*************************************************************************/ +/* resource_importer_bmfont.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "resource_importer_bmfont.h" + +#include "core/io/image_loader.h" +#include "core/io/resource_saver.h" + +String ResourceImporterBMFont::get_importer_name() const { + return "font_data_bmfont"; +} + +String ResourceImporterBMFont::get_visible_name() const { + return "Font Data (AngelCode BMFont)"; +} + +void ResourceImporterBMFont::get_recognized_extensions(List<String> *p_extensions) const { + if (p_extensions) { + p_extensions->push_back("font"); + p_extensions->push_back("fnt"); + } +} + +String ResourceImporterBMFont::get_save_extension() const { + return "fontdata"; +} + +String ResourceImporterBMFont::get_resource_type() const { + return "FontData"; +} + +bool ResourceImporterBMFont::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + return true; +} + +void ResourceImporterBMFont::get_import_options(List<ImportOption> *r_options, int p_preset) const { + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true)); +} + +void _convert_packed_8bit(Ref<FontData> &r_font, Ref<Image> &p_source, int p_page, int p_sz) { + int w = p_source->get_width(); + int h = p_source->get_height(); + + PackedByteArray imgdata = p_source->get_data(); + const uint8_t *r = imgdata.ptr(); + + PackedByteArray imgdata_r; + imgdata_r.resize(w * h * 2); + uint8_t *wr = imgdata_r.ptrw(); + + PackedByteArray imgdata_g; + imgdata_g.resize(w * h * 2); + uint8_t *wg = imgdata_g.ptrw(); + + PackedByteArray imgdata_b; + imgdata_b.resize(w * h * 2); + uint8_t *wb = imgdata_b.ptrw(); + + PackedByteArray imgdata_a; + imgdata_a.resize(w * h * 2); + uint8_t *wa = imgdata_a.ptrw(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + int ofs_src = (i * w + j) * 4; + int ofs_dst = (i * w + j) * 2; + wr[ofs_dst + 0] = 255; + wr[ofs_dst + 1] = r[ofs_src + 0]; + wg[ofs_dst + 0] = 255; + wg[ofs_dst + 1] = r[ofs_src + 1]; + wb[ofs_dst + 0] = 255; + wb[ofs_dst + 1] = r[ofs_src + 2]; + wa[ofs_dst + 0] = 255; + wa[ofs_dst + 1] = r[ofs_src + 3]; + } + } + Ref<Image> img_r = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_r)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 0, img_r); + Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 1, img_g); + Ref<Image> img_b = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_b)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 2, img_b); + Ref<Image> img_a = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_a)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 3, img_a); +} + +void _convert_packed_4bit(Ref<FontData> &r_font, Ref<Image> &p_source, int p_page, int p_sz) { + int w = p_source->get_width(); + int h = p_source->get_height(); + + PackedByteArray imgdata = p_source->get_data(); + const uint8_t *r = imgdata.ptr(); + + PackedByteArray imgdata_r; + imgdata_r.resize(w * h * 2); + uint8_t *wr = imgdata_r.ptrw(); + + PackedByteArray imgdata_g; + imgdata_g.resize(w * h * 2); + uint8_t *wg = imgdata_g.ptrw(); + + PackedByteArray imgdata_b; + imgdata_b.resize(w * h * 2); + uint8_t *wb = imgdata_b.ptrw(); + + PackedByteArray imgdata_a; + imgdata_a.resize(w * h * 2); + uint8_t *wa = imgdata_a.ptrw(); + + PackedByteArray imgdata_ro; + imgdata_ro.resize(w * h * 2); + uint8_t *wro = imgdata_ro.ptrw(); + + PackedByteArray imgdata_go; + imgdata_go.resize(w * h * 2); + uint8_t *wgo = imgdata_go.ptrw(); + + PackedByteArray imgdata_bo; + imgdata_bo.resize(w * h * 2); + uint8_t *wbo = imgdata_bo.ptrw(); + + PackedByteArray imgdata_ao; + imgdata_ao.resize(w * h * 2); + uint8_t *wao = imgdata_ao.ptrw(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + int ofs_src = (i * w + j) * 4; + int ofs_dst = (i * w + j) * 2; + wr[ofs_dst + 0] = 255; + wro[ofs_dst + 0] = 255; + if (r[ofs_src + 0] > 0x0F) { + wr[ofs_dst + 1] = (r[ofs_src + 0] - 0x0F) * 2; + wro[ofs_dst + 1] = 0; + } else { + wr[ofs_dst + 1] = 0; + wro[ofs_dst + 1] = r[ofs_src + 0] * 2; + } + wg[ofs_dst + 0] = 255; + wgo[ofs_dst + 0] = 255; + if (r[ofs_src + 1] > 0x0F) { + wg[ofs_dst + 1] = (r[ofs_src + 1] - 0x0F) * 2; + wgo[ofs_dst + 1] = 0; + } else { + wg[ofs_dst + 1] = 0; + wgo[ofs_dst + 1] = r[ofs_src + 1] * 2; + } + wb[ofs_dst + 0] = 255; + wbo[ofs_dst + 0] = 255; + if (r[ofs_src + 2] > 0x0F) { + wb[ofs_dst + 1] = (r[ofs_src + 2] - 0x0F) * 2; + wbo[ofs_dst + 1] = 0; + } else { + wb[ofs_dst + 1] = 0; + wbo[ofs_dst + 1] = r[ofs_src + 2] * 2; + } + wa[ofs_dst + 0] = 255; + wao[ofs_dst + 0] = 255; + if (r[ofs_src + 3] > 0x0F) { + wa[ofs_dst + 1] = (r[ofs_src + 3] - 0x0F) * 2; + wao[ofs_dst + 1] = 0; + } else { + wa[ofs_dst + 1] = 0; + wao[ofs_dst + 1] = r[ofs_src + 3] * 2; + } + } + } + Ref<Image> img_r = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_r)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 0, img_r); + Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 1, img_g); + Ref<Image> img_b = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_b)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 2, img_b); + Ref<Image> img_a = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_a)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page * 4 + 3, img_a); + + Ref<Image> img_ro = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_ro)); + r_font->set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 0, img_ro); + Ref<Image> img_go = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_go)); + r_font->set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 1, img_go); + Ref<Image> img_bo = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_bo)); + r_font->set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 2, img_bo); + Ref<Image> img_ao = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_ao)); + r_font->set_texture_image(0, Vector2i(p_sz, 1), p_page * 4 + 3, img_ao); +} + +void _convert_rgba_4bit(Ref<FontData> &r_font, Ref<Image> &p_source, int p_page, int p_sz) { + int w = p_source->get_width(); + int h = p_source->get_height(); + + PackedByteArray imgdata = p_source->get_data(); + const uint8_t *r = imgdata.ptr(); + + PackedByteArray imgdata_g; + imgdata_g.resize(w * h * 4); + uint8_t *wg = imgdata_g.ptrw(); + + PackedByteArray imgdata_o; + imgdata_o.resize(w * h * 4); + uint8_t *wo = imgdata_o.ptrw(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + int ofs = (i * w + j) * 4; + + if (r[ofs + 0] > 0x7F) { + wg[ofs + 0] = r[ofs + 0]; + wo[ofs + 0] = 0; + } else { + wg[ofs + 0] = 0; + wo[ofs + 0] = r[ofs + 0] * 2; + } + if (r[ofs + 1] > 0x7F) { + wg[ofs + 1] = r[ofs + 1]; + wo[ofs + 1] = 0; + } else { + wg[ofs + 1] = 0; + wo[ofs + 1] = r[ofs + 1] * 2; + } + if (r[ofs + 2] > 0x7F) { + wg[ofs + 2] = r[ofs + 2]; + wo[ofs + 2] = 0; + } else { + wg[ofs + 2] = 0; + wo[ofs + 2] = r[ofs + 2] * 2; + } + if (r[ofs + 3] > 0x7F) { + wg[ofs + 3] = r[ofs + 3]; + wo[ofs + 3] = 0; + } else { + wg[ofs + 3] = 0; + wo[ofs + 3] = r[ofs + 3] * 2; + } + } + } + Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_RGBA8, imgdata_g)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page, img_g); + + Ref<Image> img_o = memnew(Image(w, h, 0, Image::FORMAT_RGBA8, imgdata_o)); + r_font->set_texture_image(0, Vector2i(p_sz, 1), p_page, img_o); +} + +void _convert_mono_8bit(Ref<FontData> &r_font, Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol) { + int w = p_source->get_width(); + int h = p_source->get_height(); + + PackedByteArray imgdata = p_source->get_data(); + const uint8_t *r = imgdata.ptr(); + + int size = 4; + if (p_source->get_format() == Image::FORMAT_L8) { + size = 1; + p_ch = 0; + } + + PackedByteArray imgdata_g; + imgdata_g.resize(w * h * 2); + uint8_t *wg = imgdata_g.ptrw(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + int ofs_src = (i * w + j) * size; + int ofs_dst = (i * w + j) * 2; + wg[ofs_dst + 0] = 255; + wg[ofs_dst + 1] = r[ofs_src + p_ch]; + } + } + Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g)); + r_font->set_texture_image(0, Vector2i(p_sz, p_ol), p_page, img_g); +} + +void _convert_mono_4bit(Ref<FontData> &r_font, Ref<Image> &p_source, int p_page, int p_ch, int p_sz, int p_ol) { + int w = p_source->get_width(); + int h = p_source->get_height(); + + PackedByteArray imgdata = p_source->get_data(); + const uint8_t *r = imgdata.ptr(); + + int size = 4; + if (p_source->get_format() == Image::FORMAT_L8) { + size = 1; + p_ch = 0; + } + + PackedByteArray imgdata_g; + imgdata_g.resize(w * h * 2); + uint8_t *wg = imgdata_g.ptrw(); + + PackedByteArray imgdata_o; + imgdata_o.resize(w * h * 2); + uint8_t *wo = imgdata_o.ptrw(); + + for (int i = 0; i < h; i++) { + for (int j = 0; j < w; j++) { + int ofs_src = (i * w + j) * size; + int ofs_dst = (i * w + j) * 2; + wg[ofs_dst + 0] = 255; + wo[ofs_dst + 0] = 255; + if (r[ofs_src + p_ch] > 0x7F) { + wg[ofs_dst + 1] = r[ofs_src + p_ch]; + wo[ofs_dst + 1] = 0; + } else { + wg[ofs_dst + 1] = 0; + wo[ofs_dst + 1] = r[ofs_src + p_ch] * 2; + } + } + } + Ref<Image> img_g = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_g)); + r_font->set_texture_image(0, Vector2i(p_sz, 0), p_page, img_g); + + Ref<Image> img_o = memnew(Image(w, h, 0, Image::FORMAT_LA8, imgdata_o)); + r_font->set_texture_image(0, Vector2i(p_sz, p_ol), p_page, img_o); +} + +Error ResourceImporterBMFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { + print_verbose("Importing BMFont font from: " + p_source_file); + + Ref<FontData> font; + font.instantiate(); + font->set_antialiased(false); + font->set_multichannel_signed_distance_field(false); + font->set_force_autohinter(false); + font->set_hinting(TextServer::HINTING_NONE); + font->set_oversampling(1.0f); + + FileAccessRef f = FileAccess::open(p_source_file, FileAccess::READ); + if (f == nullptr) { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Cannot open font from file ") + "\"" + p_source_file + "\"."); + } + + int base_size = 16; + int height = 0; + int ascent = 0; + int outline = 0; + + bool packed = false; + uint8_t ch[4] = { 0, 0, 0, 0 }; // RGBA + int first_gl_ch = -1; + int first_ol_ch = -1; + int first_cm_ch = -1; + + unsigned char magic[4]; + f->get_buffer((unsigned char *)&magic, 4); + if (magic[0] == 'B' && magic[1] == 'M' && magic[2] == 'F') { + // Binary BMFont file. + ERR_FAIL_COND_V_MSG(magic[3] != 3, ERR_CANT_CREATE, vformat(TTR("Version %d of BMFont is not supported."), (int)magic[3])); + + uint8_t block_type = f->get_8(); + uint32_t block_size = f->get_32(); + while (!f->eof_reached()) { + uint64_t off = f->get_position(); + switch (block_type) { + case 1: /* info */ { + ERR_FAIL_COND_V_MSG(block_size < 15, ERR_CANT_CREATE, TTR("Invalid BMFont info block size.")); + base_size = f->get_16(); + uint8_t flags = f->get_8(); + ERR_FAIL_COND_V_MSG(flags & 0x02, ERR_CANT_CREATE, TTR("Non-unicode version of BMFont is not supported.")); + f->get_8(); // non-unicode charset, skip + f->get_16(); // stretch_h, skip + f->get_8(); // aa, skip + f->get_32(); // padding, skip + f->get_16(); // spacing, skip + outline = f->get_8(); + // font name, skip + font->set_fixed_size(base_size); + } break; + case 2: /* common */ { + ERR_FAIL_COND_V_MSG(block_size != 15, ERR_CANT_CREATE, TTR("Invalid BMFont common block size.")); + height = f->get_16(); + ascent = f->get_16(); + f->get_32(); // scale, skip + f->get_16(); // pages, skip + uint8_t flags = f->get_8(); + packed = (flags & 0x01); + ch[3] = f->get_8(); + ch[0] = f->get_8(); + ch[1] = f->get_8(); + ch[2] = f->get_8(); + for (int i = 0; i < 4; i++) { + if (ch[i] == 0 && first_gl_ch == -1) { + first_gl_ch = i; + } + if (ch[i] == 1 && first_ol_ch == -1) { + first_ol_ch = i; + } + if (ch[i] == 2 && first_cm_ch == -1) { + first_cm_ch = i; + } + } + } break; + case 3: /* pages */ { + int page = 0; + CharString cs; + char32_t c = f->get_8(); + while (!f->eof_reached() && f->get_position() <= off + block_size) { + if (c == '\0') { + String base_dir = p_source_file.get_base_dir(); + String file = base_dir.plus_file(String::utf8(cs.ptr(), cs.length())); + if (RenderingServer::get_singleton() != nullptr) { + Ref<Image> img; + img.instantiate(); + Error err = ImageLoader::load_image(file, img); + ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_READ, TTR("Can't load font texture: ") + "\"" + file + "\"."); + + if (packed) { + if (ch[3] == 0) { // 4 x 8 bit monochrome, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_packed_8bit(font, img, page, base_size); + } else if ((ch[3] == 2) && (outline > 0)) { // 4 x 4 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_packed_4bit(font, img, page, base_size); + } else { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Unsupported BMFont texture format.")); + } + } else { + if ((ch[0] == 0) && (ch[1] == 0) && (ch[2] == 0) && (ch[3] == 0)) { // RGBA8 color, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + font->set_texture_image(0, Vector2i(base_size, 0), page, img); + } else if ((ch[0] == 2) && (ch[1] == 2) && (ch[2] == 2) && (ch[3] == 2) && (outline > 0)) { // RGBA4 color, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_rgba_4bit(font, img, page, base_size); + } else if ((first_gl_ch >= 0) && (first_ol_ch >= 0) && (outline > 0)) { // 1 x 8 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_8bit(font, img, page, first_gl_ch, base_size, 0); + _convert_mono_8bit(font, img, page, first_ol_ch, base_size, 1); + } else if ((first_cm_ch >= 0) && (outline > 0)) { // 1 x 4 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_4bit(font, img, page, first_cm_ch, base_size, 1); + } else if (first_gl_ch >= 0) { // 1 x 8 bit monochrome, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_8bit(font, img, page, first_gl_ch, base_size, 0); + } else { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Unsupported BMFont texture format.")); + } + } + } + page++; + cs = ""; + } else { + cs += c; + } + c = f->get_8(); + } + } break; + case 4: /* chars */ { + int char_count = block_size / 20; + for (int i = 0; i < char_count; i++) { + Vector2 advance; + Vector2 size; + Vector2 offset; + Rect2 uv_rect; + + char32_t idx = f->get_32(); + uv_rect.position.x = (int16_t)f->get_16(); + uv_rect.position.y = (int16_t)f->get_16(); + uv_rect.size.width = (int16_t)f->get_16(); + size.width = uv_rect.size.width; + uv_rect.size.height = (int16_t)f->get_16(); + size.height = uv_rect.size.height; + offset.x = (int16_t)f->get_16(); + offset.y = (int16_t)f->get_16() - ascent; + advance.x = (int16_t)f->get_16(); + if (advance.x < 0) { + advance.x = size.width + 1; + } + + int texture_idx = f->get_8(); + uint8_t channel = f->get_8(); + + ERR_FAIL_COND_V_MSG(!packed && channel != 15, ERR_CANT_CREATE, TTR("Invalid glyph channel.")); + int ch_off = 0; + switch (channel) { + case 1: + ch_off = 2; + break; // B + case 2: + ch_off = 1; + break; // G + case 4: + ch_off = 0; + break; // R + case 8: + ch_off = 3; + break; // A + default: + ch_off = 0; + break; + } + font->set_glyph_advance(0, base_size, idx, advance); + font->set_glyph_offset(0, Vector2i(base_size, 0), idx, offset); + font->set_glyph_size(0, Vector2i(base_size, 0), idx, size); + font->set_glyph_uv_rect(0, Vector2i(base_size, 0), idx, uv_rect); + font->set_glyph_texture_idx(0, Vector2i(base_size, 0), idx, texture_idx * (packed ? 4 : 1) + ch_off); + if (outline > 0) { + font->set_glyph_offset(0, Vector2i(base_size, 1), idx, offset); + font->set_glyph_size(0, Vector2i(base_size, 1), idx, size); + font->set_glyph_uv_rect(0, Vector2i(base_size, 1), idx, uv_rect); + font->set_glyph_texture_idx(0, Vector2i(base_size, 1), idx, texture_idx * (packed ? 4 : 1) + ch_off); + } + } + } break; + case 5: /* kerning */ { + int pair_count = block_size / 10; + for (int i = 0; i < pair_count; i++) { + Vector2i kpk; + kpk.x = f->get_32(); + kpk.y = f->get_32(); + font->set_kerning(0, base_size, kpk, Vector2((int16_t)f->get_16(), 0)); + } + } break; + default: { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Invalid BMFont block type.")); + } break; + } + f->seek(off + block_size); + block_type = f->get_8(); + block_size = f->get_32(); + } + + } else { + // Text BMFont file. + f->seek(0); + while (true) { + String line = f->get_line(); + + int delimiter = line.find(" "); + String type = line.substr(0, delimiter); + int pos = delimiter + 1; + Map<String, String> keys; + + while (pos < line.size() && line[pos] == ' ') { + pos++; + } + + while (pos < line.size()) { + int eq = line.find("=", pos); + if (eq == -1) { + break; + } + String key = line.substr(pos, eq - pos); + int end = -1; + String value; + if (line[eq + 1] == '"') { + end = line.find("\"", eq + 2); + if (end == -1) { + break; + } + value = line.substr(eq + 2, end - 1 - eq - 1); + pos = end + 1; + } else { + end = line.find(" ", eq + 1); + if (end == -1) { + end = line.size(); + } + value = line.substr(eq + 1, end - eq); + pos = end; + } + + while (pos < line.size() && line[pos] == ' ') { + pos++; + } + + keys[key] = value; + } + + if (type == "info") { + if (keys.has("size")) { + base_size = keys["size"].to_int(); + font->set_fixed_size(base_size); + } + if (keys.has("outline")) { + outline = keys["outline"].to_int(); + } + ERR_FAIL_COND_V_MSG((!keys.has("unicode") || keys["unicode"].to_int() != 1), ERR_CANT_CREATE, TTR("Non-unicode version of BMFont is not supported.")); + } else if (type == "common") { + if (keys.has("lineHeight")) { + height = keys["lineHeight"].to_int(); + } + if (keys.has("base")) { + ascent = keys["base"].to_int(); + } + if (keys.has("packed")) { + packed = (keys["packed"].to_int() == 1); + } + if (keys.has("alphaChnl")) { + ch[3] = keys["alphaChnl"].to_int(); + } + if (keys.has("redChnl")) { + ch[0] = keys["redChnl"].to_int(); + } + if (keys.has("greenChnl")) { + ch[1] = keys["greenChnl"].to_int(); + } + if (keys.has("blueChnl")) { + ch[2] = keys["blueChnl"].to_int(); + } + for (int i = 0; i < 4; i++) { + if (ch[i] == 0 && first_gl_ch == -1) { + first_gl_ch = i; + } + if (ch[i] == 1 && first_ol_ch == -1) { + first_ol_ch = i; + } + if (ch[i] == 2 && first_cm_ch == -1) { + first_cm_ch = i; + } + } + } else if (type == "page") { + int page = 0; + if (keys.has("id")) { + page = keys["id"].to_int(); + } + if (keys.has("file")) { + String base_dir = p_source_file.get_base_dir(); + String file = base_dir.plus_file(keys["file"]); + if (RenderingServer::get_singleton() != nullptr) { + Ref<Image> img; + img.instantiate(); + Error err = ImageLoader::load_image(file, img); + ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_READ, TTR("Can't load font texture: ") + "\"" + file + "\"."); + if (packed) { + if (ch[3] == 0) { // 4 x 8 bit monochrome, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_packed_8bit(font, img, page, base_size); + } else if ((ch[3] == 2) && (outline > 0)) { // 4 x 4 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_packed_4bit(font, img, page, base_size); + } else { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Unsupported BMFont texture format.")); + } + } else { + if ((ch[0] == 0) && (ch[1] == 0) && (ch[2] == 0) && (ch[3] == 0)) { // RGBA8 color, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + font->set_texture_image(0, Vector2i(base_size, 0), page, img); + } else if ((ch[0] == 2) && (ch[1] == 2) && (ch[2] == 2) && (ch[3] == 2) && (outline > 0)) { // RGBA4 color, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_rgba_4bit(font, img, page, base_size); + } else if ((first_gl_ch >= 0) && (first_ol_ch >= 0) && (outline > 0)) { // 1 x 8 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_8bit(font, img, page, first_gl_ch, base_size, 0); + _convert_mono_8bit(font, img, page, first_ol_ch, base_size, 1); + } else if ((first_cm_ch >= 0) && (outline > 0)) { // 1 x 4 bit monochrome, gl + outline + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_4bit(font, img, page, first_cm_ch, base_size, 1); + } else if (first_gl_ch >= 0) { // 1 x 8 bit monochrome, no outline + outline = 0; + ERR_FAIL_COND_V_MSG(img->get_format() != Image::FORMAT_RGBA8 && img->get_format() != Image::FORMAT_L8, ERR_FILE_CANT_READ, TTR("Unsupported BMFont texture format.")); + _convert_mono_8bit(font, img, page, first_gl_ch, base_size, 0); + } else { + ERR_FAIL_V_MSG(ERR_CANT_CREATE, TTR("Unsupported BMFont texture format.")); + } + } + } + } + } else if (type == "char") { + char32_t idx = 0; + Vector2 advance; + Vector2 size; + Vector2 offset; + Rect2 uv_rect; + int texture_idx = -1; + uint8_t channel = 15; + + if (keys.has("id")) { + idx = keys["id"].to_int(); + } + if (keys.has("x")) { + uv_rect.position.x = keys["x"].to_int(); + } + if (keys.has("y")) { + uv_rect.position.y = keys["y"].to_int(); + } + if (keys.has("width")) { + uv_rect.size.width = keys["width"].to_int(); + size.width = keys["width"].to_int(); + } + if (keys.has("height")) { + uv_rect.size.height = keys["height"].to_int(); + size.height = keys["height"].to_int(); + } + if (keys.has("xoffset")) { + offset.x = keys["xoffset"].to_int(); + } + if (keys.has("yoffset")) { + offset.y = keys["yoffset"].to_int() - ascent; + } + if (keys.has("page")) { + texture_idx = keys["page"].to_int(); + } + if (keys.has("xadvance")) { + advance.x = keys["xadvance"].to_int(); + } + if (advance.x < 0) { + advance.x = size.width + 1; + } + if (keys.has("chnl")) { + channel = keys["chnl"].to_int(); + } + + ERR_FAIL_COND_V_MSG(!packed && channel != 15, ERR_CANT_CREATE, TTR("Invalid glyph channel.")); + int ch_off = 0; + switch (channel) { + case 1: + ch_off = 2; + break; // B + case 2: + ch_off = 1; + break; // G + case 4: + ch_off = 0; + break; // R + case 8: + ch_off = 3; + break; // A + default: + ch_off = 0; + break; + } + font->set_glyph_advance(0, base_size, idx, advance); + font->set_glyph_offset(0, Vector2i(base_size, 0), idx, offset); + font->set_glyph_size(0, Vector2i(base_size, 0), idx, size); + font->set_glyph_uv_rect(0, Vector2i(base_size, 0), idx, uv_rect); + font->set_glyph_texture_idx(0, Vector2i(base_size, 0), idx, texture_idx * (packed ? 4 : 1) + ch_off); + if (outline > 0) { + font->set_glyph_offset(0, Vector2i(base_size, 1), idx, offset); + font->set_glyph_size(0, Vector2i(base_size, 1), idx, size); + font->set_glyph_uv_rect(0, Vector2i(base_size, 1), idx, uv_rect); + font->set_glyph_texture_idx(0, Vector2i(base_size, 1), idx, texture_idx * (packed ? 4 : 1) + ch_off); + } + } else if (type == "kerning") { + Vector2i kpk; + if (keys.has("first")) { + kpk.x = keys["first"].to_int(); + } + if (keys.has("second")) { + kpk.y = keys["second"].to_int(); + } + if (keys.has("amount")) { + font->set_kerning(0, base_size, kpk, Vector2(keys["amount"].to_int(), 0)); + } + } + + if (f->eof_reached()) { + break; + } + } + } + + font->set_ascent(0, base_size, ascent); + font->set_descent(0, base_size, height - ascent); + + int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; + if ((bool)p_options["compress"]) { + flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS; + } + + print_verbose("Saving to: " + p_save_path + ".fontdata"); + Error err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); + print_verbose("Done saving to: " + p_save_path + ".fontdata"); + return OK; +} + +ResourceImporterBMFont::ResourceImporterBMFont() { +} diff --git a/editor/import/resource_importer_bmfont.h b/editor/import/resource_importer_bmfont.h new file mode 100644 index 0000000000..065703132a --- /dev/null +++ b/editor/import/resource_importer_bmfont.h @@ -0,0 +1,56 @@ +/*************************************************************************/ +/* resource_importer_bmfont.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RESOURCE_IMPORTER_BMFONT_H +#define RESOURCE_IMPORTER_BMFONT_H + +#include "core/io/resource_importer.h" +#include "scene/resources/font.h" +#include "servers/text_server.h" + +class ResourceImporterBMFont : public ResourceImporter { + GDCLASS(ResourceImporterBMFont, ResourceImporter); + +public: + virtual String get_importer_name() const override; + virtual String get_visible_name() const override; + virtual void get_recognized_extensions(List<String> *p_extensions) const override; + virtual String get_save_extension() const override; + virtual String get_resource_type() const override; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override; + + ResourceImporterBMFont(); +}; + +#endif // RESOURCE_IMPORTER_BMFONT_H diff --git a/editor/import/resource_importer_dynamicfont.cpp b/editor/import/resource_importer_dynamicfont.cpp new file mode 100644 index 0000000000..8e01adbd56 --- /dev/null +++ b/editor/import/resource_importer_dynamicfont.cpp @@ -0,0 +1,304 @@ +/*************************************************************************/ +/* resource_importer_dynamicfont.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "resource_importer_dynamicfont.h" + +#include "dynamicfont_import_settings.h" + +#include "core/io/file_access.h" +#include "core/io/resource_saver.h" +#include "editor/editor_node.h" +#include "modules/modules_enabled.gen.h" + +String ResourceImporterDynamicFont::get_importer_name() const { + return "font_data_dynamic"; +} + +String ResourceImporterDynamicFont::get_visible_name() const { + return "Font Data (Dynamic Font)"; +} + +void ResourceImporterDynamicFont::get_recognized_extensions(List<String> *p_extensions) const { + if (p_extensions) { +#ifdef MODULE_FREETYPE_ENABLED + p_extensions->push_back("ttf"); + p_extensions->push_back("otf"); + p_extensions->push_back("woff"); + //p_extensions->push_back("woff2"); + p_extensions->push_back("pfb"); + p_extensions->push_back("pfm"); +#endif + } +} + +String ResourceImporterDynamicFont::get_save_extension() const { + return "fontdata"; +} + +String ResourceImporterDynamicFont::get_resource_type() const { + return "FontData"; +} + +bool ResourceImporterDynamicFont::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + if (p_option == "msdf_pixel_range" && !bool(p_options["multichannel_signed_distance_field"])) { + return false; + } + if (p_option == "msdf_size" && !bool(p_options["multichannel_signed_distance_field"])) { + return false; + } + if (p_option == "oversampling" && bool(p_options["multichannel_signed_distance_field"])) { + return false; + } + return true; +} + +int ResourceImporterDynamicFont::get_preset_count() const { + return PRESET_MAX; +} + +String ResourceImporterDynamicFont::get_preset_name(int p_idx) const { + switch (p_idx) { + case PRESET_DYNAMIC: + return TTR("Dynamically rendered TrueType/OpenType font"); + case PRESET_MSDF: + return TTR("Prerendered multichannel(+true) signed distance field"); + default: + return String(); + } +} + +void ResourceImporterDynamicFont::get_import_options(List<ImportOption> *r_options, int p_preset) const { + bool msdf = p_preset == PRESET_MSDF; + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "antialiased"), true)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED), (msdf) ? true : false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_RANGE, "1,100,1"), 8)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_RANGE, "1,250,1"), 48)); + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "force_autohinter"), false)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "hinting", PROPERTY_HINT_ENUM, "None,Light,Normal"), 1)); + r_options->push_back(ImportOption(PropertyInfo(Variant::FLOAT, "oversampling", PROPERTY_HINT_RANGE, "0,10,0.1"), 0.0)); + + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true)); + + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/char_ranges"), Vector<String>())); + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/glyph_ranges"), Vector<String>())); + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "preload/configurations"), Vector<String>())); + + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/language_enabled"), Vector<String>())); + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/language_disabled"), Vector<String>())); + + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/script_enabled"), Vector<String>())); + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "support_overrides/script_disabled"), Vector<String>())); +} + +bool ResourceImporterDynamicFont::_decode_variation(const String &p_token, Dictionary &r_variations, Vector2i &r_size, String &r_name, Vector2i &r_spacing) { + Vector<String> tokens = p_token.split("="); + if (tokens.size() == 2) { + if (tokens[0] == "name") { + r_name = tokens[1]; + } else if (tokens[0] == "size") { + r_size.x = tokens[1].to_int(); + } else if (tokens[0] == "outline_size") { + r_size.y = tokens[1].to_int(); + } else if (tokens[0] == "spacing_space") { + r_spacing.x = tokens[1].to_int(); + } else if (tokens[0] == "spacing_glyph") { + r_spacing.y = tokens[1].to_int(); + } else { + r_variations[tokens[0]] = tokens[1].to_float(); + } + return true; + } else { + WARN_PRINT("Invalid variation: '" + p_token + "'."); + return false; + } +} + +bool ResourceImporterDynamicFont::_decode_range(const String &p_token, int32_t &r_pos) { + if (p_token.begins_with("U+") || p_token.begins_with("u+") || p_token.begins_with("0x")) { + // Unicode character hex index. + r_pos = p_token.substr(2).hex_to_int(); + return true; + } else if (p_token.length() == 3 && p_token[0] == '\'' && p_token[2] == '\'') { + // Unicode character. + r_pos = p_token.unicode_at(1); + return true; + } else if (p_token.is_numeric()) { + // Unicode character decimal index. + r_pos = p_token.to_int(); + return true; + } else { + return false; + } +} + +bool ResourceImporterDynamicFont::has_advanced_options() const { + return true; +} +void ResourceImporterDynamicFont::show_advanced_options(const String &p_path) { + DynamicFontImportSettings::get_singleton()->open_settings(p_path); +} + +Error ResourceImporterDynamicFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { + print_verbose("Importing dynamic font from: " + p_source_file); + + bool antialiased = p_options["antialiased"]; + bool msdf = p_options["multichannel_signed_distance_field"]; + int px_range = p_options["msdf_pixel_range"]; + int px_size = p_options["msdf_size"]; + + bool autohinter = p_options["force_autohinter"]; + int hinting = p_options["hinting"]; + real_t oversampling = p_options["oversampling"]; + + // Load base font data. + Vector<uint8_t> data = FileAccess::get_file_as_array(p_source_file); + + // Create font. + Ref<FontData> font; + font.instantiate(); + font->set_data(data); + font->set_antialiased(antialiased); + font->set_multichannel_signed_distance_field(msdf); + font->set_msdf_pixel_range(px_range); + font->set_msdf_size(px_size); + font->set_fixed_size(0); + font->set_force_autohinter(autohinter); + font->set_hinting((TextServer::Hinting)hinting); + font->set_oversampling(oversampling); + + Vector<String> lang_en = p_options["support_overrides/language_enabled"]; + for (int i = 0; i < lang_en.size(); i++) { + font->set_language_support_override(lang_en[i], true); + } + + Vector<String> lang_dis = p_options["support_overrides/language_disabled"]; + for (int i = 0; i < lang_dis.size(); i++) { + font->set_language_support_override(lang_dis[i], false); + } + + Vector<String> scr_en = p_options["support_overrides/script_enabled"]; + for (int i = 0; i < scr_en.size(); i++) { + font->set_script_support_override(scr_en[i], true); + } + + Vector<String> scr_dis = p_options["support_overrides/script_disabled"]; + for (int i = 0; i < scr_dis.size(); i++) { + font->set_script_support_override(scr_dis[i], false); + } + + Vector<String> variations = p_options["preload/configurations"]; + Vector<String> char_ranges = p_options["preload/char_ranges"]; + Vector<String> gl_ranges = p_options["preload/glyph_ranges"]; + + for (int i = 0; i < variations.size(); i++) { + String name; + Dictionary var; + Vector2i size = Vector2(16, 0); + Vector2i spacing; + + Vector<String> variation_tags = variations[i].split(","); + for (int j = 0; j < variation_tags.size(); j++) { + if (!_decode_variation(variation_tags[j], var, size, name, spacing)) { + WARN_PRINT(vformat(TTR("Invalid variation: \"%s\""), variations[i])); + continue; + } + } + RID conf = font->find_cache(var); + + for (int j = 0; j < char_ranges.size(); j++) { + int32_t start, end; + Vector<String> tokens = char_ranges[j].split("-"); + if (tokens.size() == 2) { + if (!_decode_range(tokens[0], start) || !_decode_range(tokens[1], end)) { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j])); + continue; + } + } else if (tokens.size() == 1) { + if (!_decode_range(tokens[0], start)) { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j])); + continue; + } + end = start; + } else { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), char_ranges[j])); + continue; + } + + // Preload character ranges for each variations / sizes. + print_verbose(vformat(TTR("Pre-rendering range U+%s...%s from configuration \"%s\" (%d / %d)..."), String::num_int64(start, 16), String::num_int64(end, 16), name, i + 1, variations.size())); + TS->font_render_range(conf, size, start, end); + } + + for (int j = 0; j < gl_ranges.size(); j++) { + int32_t start, end; + Vector<String> tokens = gl_ranges[j].split("-"); + if (tokens.size() == 2) { + if (!_decode_range(tokens[0], start) || !_decode_range(tokens[1], end)) { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j])); + continue; + } + } else if (tokens.size() == 1) { + if (!_decode_range(tokens[0], start)) { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j])); + continue; + } + end = start; + } else { + WARN_PRINT(vformat(TTR("Invalid range: \"%s\""), gl_ranges[j])); + continue; + } + + // Preload glyph range for each variations / sizes. + print_verbose(vformat(TTR("Pre-rendering glyph range 0x%s...%s from configuration \"%s\" (%d / %d)..."), String::num_int64(start, 16), String::num_int64(end, 16), name, i + 1, variations.size())); + for (int32_t k = start; k <= end; k++) { + TS->font_render_glyph(conf, size, k); + } + } + + TS->font_set_spacing(conf, size.x, TextServer::SPACING_SPACE, spacing.x); + TS->font_set_spacing(conf, size.x, TextServer::SPACING_GLYPH, spacing.y); + } + + int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; + if ((bool)p_options["compress"]) { + flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS; + } + + print_verbose("Saving to: " + p_save_path + ".fontdata"); + Error err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); + print_verbose("Done saving to: " + p_save_path + ".fontdata"); + return OK; +} + +ResourceImporterDynamicFont::ResourceImporterDynamicFont() { +} diff --git a/editor/import/resource_importer_dynamicfont.h b/editor/import/resource_importer_dynamicfont.h new file mode 100644 index 0000000000..52f256ab96 --- /dev/null +++ b/editor/import/resource_importer_dynamicfont.h @@ -0,0 +1,71 @@ +/*************************************************************************/ +/* resource_importer_dynamicfont.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RESOURCE_IMPORTER_FONT_DATA_H +#define RESOURCE_IMPORTER_FONT_DATA_H + +#include "core/io/resource_importer.h" +#include "scene/resources/font.h" +#include "servers/text_server.h" + +class ResourceImporterDynamicFont : public ResourceImporter { + GDCLASS(ResourceImporterDynamicFont, ResourceImporter); + + enum Presets { + PRESET_DYNAMIC, + PRESET_MSDF, + PRESET_MAX + }; + +public: + static bool _decode_range(const String &p_token, int32_t &r_pos); + static bool _decode_variation(const String &p_token, Dictionary &r_variations, Vector2i &r_size, String &r_name, Vector2i &r_spacing); + + virtual String get_importer_name() const override; + virtual String get_visible_name() const override; + virtual void get_recognized_extensions(List<String> *p_extensions) const override; + virtual String get_save_extension() const override; + virtual String get_resource_type() const override; + + virtual int get_preset_count() const override; + virtual String get_preset_name(int p_idx) const override; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override; + + bool has_advanced_options() const override; + void show_advanced_options(const String &p_path) override; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override; + + ResourceImporterDynamicFont(); +}; + +#endif // RESOURCE_IMPORTER_FONTDATA_H diff --git a/editor/import/resource_importer_imagefont.cpp b/editor/import/resource_importer_imagefont.cpp new file mode 100644 index 0000000000..997280d1dd --- /dev/null +++ b/editor/import/resource_importer_imagefont.cpp @@ -0,0 +1,162 @@ +/*************************************************************************/ +/* resource_importer_imagefont.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "resource_importer_imagefont.h" + +#include "core/io/image_loader.h" +#include "core/io/resource_saver.h" + +String ResourceImporterImageFont::get_importer_name() const { + return "font_data_image"; +} + +String ResourceImporterImageFont::get_visible_name() const { + return "Font Data (Monospace Image Font)"; +} + +void ResourceImporterImageFont::get_recognized_extensions(List<String> *p_extensions) const { + if (p_extensions) { + ImageLoader::get_recognized_extensions(p_extensions); + } +} + +String ResourceImporterImageFont::get_save_extension() const { + return "fontdata"; +} + +String ResourceImporterImageFont::get_resource_type() const { + return "FontData"; +} + +bool ResourceImporterImageFont::get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const { + return true; +} + +void ResourceImporterImageFont::get_import_options(List<ImportOption> *r_options, int p_preset) const { + r_options->push_back(ImportOption(PropertyInfo(Variant::PACKED_STRING_ARRAY, "character_ranges"), Vector<String>())); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "columns"), 1)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "rows"), 1)); + r_options->push_back(ImportOption(PropertyInfo(Variant::INT, "font_size"), 14)); + r_options->push_back(ImportOption(PropertyInfo(Variant::BOOL, "compress"), true)); +} + +bool ResourceImporterImageFont::_decode_range(const String &p_token, int32_t &r_pos) { + if (p_token.begins_with("U+") || p_token.begins_with("u+") || p_token.begins_with("0x")) { + // Unicode character hex index. + r_pos = p_token.substr(2).hex_to_int(); + return true; + } else if (p_token.length() == 3 && p_token[0] == '\'' && p_token[2] == '\'') { + // Unicode character. + r_pos = p_token.unicode_at(1); + return true; + } else if (p_token.is_numeric()) { + // Unicode character decimal index. + r_pos = p_token.to_int(); + return true; + } else { + return false; + } +} + +Error ResourceImporterImageFont::import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) { + print_verbose("Importing image font from: " + p_source_file); + + int columns = p_options["columns"]; + int rows = p_options["rows"]; + int base_size = p_options["font_size"]; + Vector<String> ranges = p_options["character_ranges"]; + + Ref<FontData> font; + font.instantiate(); + font->set_antialiased(false); + font->set_multichannel_signed_distance_field(false); + font->set_fixed_size(base_size); + font->set_force_autohinter(false); + font->set_hinting(TextServer::HINTING_NONE); + font->set_oversampling(1.0f); + + Ref<Image> img; + img.instantiate(); + Error err = ImageLoader::load_image(p_source_file, img); + ERR_FAIL_COND_V_MSG(err != OK, ERR_FILE_CANT_READ, TTR("Can't load font texture: ") + "\"" + p_source_file + "\"."); + font->set_texture_image(0, Vector2i(base_size, 0), 0, img); + + int count = columns * rows; + int chr_width = img->get_width() / columns; + int chr_height = img->get_height() / rows; + int pos = 0; + + for (int i = 0; i < ranges.size(); i++) { + int32_t start, end; + Vector<String> tokens = ranges[i].split("-"); + if (tokens.size() == 2) { + if (!_decode_range(tokens[0], start) || !_decode_range(tokens[1], end)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + } else if (tokens.size() == 1) { + if (!_decode_range(tokens[0], start)) { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + end = start; + } else { + WARN_PRINT("Invalid range: \"" + ranges[i] + "\""); + continue; + } + for (int32_t idx = start; idx <= end; idx++) { + int x = pos % columns; + int y = pos / columns; + font->set_glyph_advance(0, base_size, idx, Vector2(chr_width, 0)); + font->set_glyph_offset(0, Vector2i(base_size, 0), idx, Vector2(0, -0.5 * chr_height)); + font->set_glyph_size(0, Vector2i(base_size, 0), idx, Vector2(chr_width, chr_height)); + font->set_glyph_uv_rect(0, Vector2i(base_size, 0), idx, Rect2(chr_width * x, chr_height * y, chr_width, chr_height)); + font->set_glyph_texture_idx(0, Vector2i(base_size, 0), idx, 0); + pos++; + ERR_FAIL_COND_V_MSG(pos >= count, ERR_CANT_CREATE, "Too many characters in range."); + } + } + font->set_ascent(0, base_size, 0.5 * chr_height); + font->set_descent(0, base_size, 0.5 * chr_height); + + int flg = ResourceSaver::SaverFlags::FLAG_BUNDLE_RESOURCES | ResourceSaver::FLAG_REPLACE_SUBRESOURCE_PATHS; + if ((bool)p_options["compress"]) { + flg |= ResourceSaver::SaverFlags::FLAG_COMPRESS; + } + + print_verbose("Saving to: " + p_save_path + ".fontdata"); + err = ResourceSaver::save(p_save_path + ".fontdata", font, flg); + ERR_FAIL_COND_V_MSG(err != OK, err, "Cannot save font to file \"" + p_save_path + ".res\"."); + print_verbose("Done saving to: " + p_save_path + ".fontdata"); + return OK; +} + +ResourceImporterImageFont::ResourceImporterImageFont() { +} diff --git a/editor/import/resource_importer_imagefont.h b/editor/import/resource_importer_imagefont.h new file mode 100644 index 0000000000..9b2b38596f --- /dev/null +++ b/editor/import/resource_importer_imagefont.h @@ -0,0 +1,58 @@ +/*************************************************************************/ +/* resource_importer_imagefont.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2021 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#ifndef RESOURCE_IMPORTER_IMAGE_FONT_H +#define RESOURCE_IMPORTER_IMAGE_FONT_H + +#include "core/io/resource_importer.h" +#include "scene/resources/font.h" +#include "servers/text_server.h" + +class ResourceImporterImageFont : public ResourceImporter { + GDCLASS(ResourceImporterImageFont, ResourceImporter); + +public: + static bool _decode_range(const String &p_token, int32_t &r_pos); + + virtual String get_importer_name() const override; + virtual String get_visible_name() const override; + virtual void get_recognized_extensions(List<String> *p_extensions) const override; + virtual String get_save_extension() const override; + virtual String get_resource_type() const override; + + virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const override; + virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const override; + + virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) override; + + ResourceImporterImageFont(); +}; + +#endif // RESOURCE_IMPORTER_IMAGE_FONT_H diff --git a/editor/import/resource_importer_scene.cpp b/editor/import/resource_importer_scene.cpp index 492fa3f965..c2244befa1 100644 --- a/editor/import/resource_importer_scene.cpp +++ b/editor/import/resource_importer_scene.cpp @@ -46,21 +46,23 @@ #include "scene/resources/box_shape_3d.h" #include "scene/resources/packed_scene.h" #include "scene/resources/resource_format_text.h" +#include "scene/resources/separation_ray_shape_3d.h" #include "scene/resources/sphere_shape_3d.h" #include "scene/resources/surface_tool.h" #include "scene/resources/world_margin_shape_3d.h" uint32_t EditorSceneImporter::get_import_flags() const { - if (get_script_instance()) { - return get_script_instance()->call("_get_import_flags"); + int ret; + if (GDVIRTUAL_CALL(_get_import_flags, ret)) { + return ret; } ERR_FAIL_V(0); } void EditorSceneImporter::get_extensions(List<String> *r_extensions) const { - if (get_script_instance()) { - Array arr = get_script_instance()->call("_get_extensions"); + Vector<String> arr; + if (GDVIRTUAL_CALL(_get_extensions, arr)) { for (int i = 0; i < arr.size(); i++) { r_extensions->push_back(arr[i]); } @@ -71,16 +73,18 @@ void EditorSceneImporter::get_extensions(List<String> *r_extensions) const { } Node *EditorSceneImporter::import_scene(const String &p_path, uint32_t p_flags, int p_bake_fps, List<String> *r_missing_deps, Error *r_err) { - if (get_script_instance()) { - return get_script_instance()->call("_import_scene", p_path, p_flags, p_bake_fps); + Object *ret; + if (GDVIRTUAL_CALL(_import_scene, p_path, p_flags, p_bake_fps, ret)) { + return Object::cast_to<Node>(ret); } ERR_FAIL_V(nullptr); } Ref<Animation> EditorSceneImporter::import_animation(const String &p_path, uint32_t p_flags, int p_bake_fps) { - if (get_script_instance()) { - return get_script_instance()->call("_import_animation", p_path, p_flags); + Ref<Animation> ret; + if (GDVIRTUAL_CALL(_import_animation, p_path, p_flags, p_bake_fps, ret)) { + return ret; } ERR_FAIL_V(nullptr); @@ -101,15 +105,10 @@ void EditorSceneImporter::_bind_methods() { ClassDB::bind_method(D_METHOD("import_scene_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_scene_from_other_importer); ClassDB::bind_method(D_METHOD("import_animation_from_other_importer", "path", "flags", "bake_fps"), &EditorSceneImporter::import_animation_from_other_importer); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_import_flags")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_extensions")); - - MethodInfo mi = MethodInfo(Variant::OBJECT, "_import_scene", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps")); - mi.return_val.class_name = "Node"; - BIND_VMETHOD(mi); - mi = MethodInfo(Variant::OBJECT, "_import_animation", PropertyInfo(Variant::STRING, "path"), PropertyInfo(Variant::INT, "flags"), PropertyInfo(Variant::INT, "bake_fps")); - mi.return_val.class_name = "Animation"; - BIND_VMETHOD(mi); + GDVIRTUAL_BIND(_get_import_flags); + GDVIRTUAL_BIND(_get_extensions); + GDVIRTUAL_BIND(_import_scene, "path", "flags", "bake_fps"); + GDVIRTUAL_BIND(_import_animation, "path", "flags", "bake_fps"); BIND_CONSTANT(IMPORT_SCENE); BIND_CONSTANT(IMPORT_ANIMATION); @@ -120,13 +119,14 @@ void EditorSceneImporter::_bind_methods() { ///////////////////////////////// void EditorScenePostImport::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_post_import", PropertyInfo(Variant::OBJECT, "scene"))); + GDVIRTUAL_BIND(_post_import, "scene") ClassDB::bind_method(D_METHOD("get_source_file"), &EditorScenePostImport::get_source_file); } Node *EditorScenePostImport::post_import(Node *p_scene) { - if (get_script_instance()) { - return get_script_instance()->call("_post_import", p_scene); + Object *ret; + if (GDVIRTUAL_CALL(_post_import, p_scene, ret)) { + return Object::cast_to<Node>(ret); } return p_scene; @@ -380,6 +380,11 @@ Node *ResourceImporterScene::_pre_fix_node(Node *p_node, Node *p_root, Map<Ref<E BoxShape3D *boxShape = memnew(BoxShape3D); boxShape->set_size(Vector3(2, 2, 2)); colshape->set_shape(boxShape); + } else if (empty_draw_type == "SINGLE_ARROW") { + SeparationRayShape3D *rayShape = memnew(SeparationRayShape3D); + rayShape->set_length(1); + colshape->set_shape(rayShape); + Object::cast_to<Node3D>(sb)->rotate_x(Math_PI / 2); } else if (empty_draw_type == "IMAGE") { WorldMarginShape3D *world_margin_shape = memnew(WorldMarginShape3D); colshape->set_shape(world_margin_shape); diff --git a/editor/import/resource_importer_scene.h b/editor/import/resource_importer_scene.h index 781beff689..542959be02 100644 --- a/editor/import/resource_importer_scene.h +++ b/editor/import/resource_importer_scene.h @@ -51,6 +51,11 @@ protected: Node *import_scene_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps); Ref<Animation> import_animation_from_other_importer(const String &p_path, uint32_t p_flags, int p_bake_fps); + GDVIRTUAL0RC(int, _get_import_flags) + GDVIRTUAL0RC(Vector<String>, _get_extensions) + GDVIRTUAL3R(Object *, _import_scene, String, uint32_t, uint32_t) + GDVIRTUAL3R(Ref<Animation>, _import_animation, String, uint32_t, uint32_t) + public: enum ImportFlags { IMPORT_SCENE = 1, @@ -77,6 +82,8 @@ class EditorScenePostImport : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL1R(Object *, _post_import, Node *) + public: String get_source_file() const; virtual Node *post_import(Node *p_scene); diff --git a/editor/import/resource_importer_shader_file.cpp b/editor/import/resource_importer_shader_file.cpp index 4d92490675..c01d8068da 100644 --- a/editor/import/resource_importer_shader_file.cpp +++ b/editor/import/resource_importer_shader_file.cpp @@ -78,7 +78,7 @@ static String _include_function(const String &p_path, void *userpointer) { String *base_path = (String *)userpointer; String include = p_path; - if (include.is_rel_path()) { + if (include.is_relative_path()) { include = base_path->plus_file(include); } diff --git a/editor/import/scene_importer_mesh.cpp b/editor/import/scene_importer_mesh.cpp index 0d14347225..06f373c54f 100644 --- a/editor/import/scene_importer_mesh.cpp +++ b/editor/import/scene_importer_mesh.cpp @@ -110,6 +110,12 @@ String EditorSceneImporterMesh::get_surface_name(int p_surface) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), String()); return surfaces[p_surface].name; } +void EditorSceneImporterMesh::set_surface_name(int p_surface, const String &p_name) { + ERR_FAIL_INDEX(p_surface, surfaces.size()); + surfaces.write[p_surface].name = p_name; + mesh.unref(); +} + Array EditorSceneImporterMesh::get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const { ERR_FAIL_INDEX_V(p_surface, surfaces.size(), Array()); ERR_FAIL_INDEX_V(p_blend_shape, surfaces[p_surface].blend_shape_data.size(), Array()); @@ -140,6 +146,7 @@ Ref<Material> EditorSceneImporterMesh::get_surface_material(int p_surface) const void EditorSceneImporterMesh::set_surface_material(int p_surface, const Ref<Material> &p_material) { ERR_FAIL_INDEX(p_surface, surfaces.size()); surfaces.write[p_surface].material = p_material; + mesh.unref(); } Basis EditorSceneImporterMesh::compute_rotation_matrix_from_ortho_6d(Vector3 p_x_raw, Vector3 p_y_raw) { @@ -244,7 +251,7 @@ bool EditorSceneImporterMesh::has_mesh() const { return mesh.is_valid(); } -Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh(const Ref<Mesh> &p_base) { +Ref<ArrayMesh> EditorSceneImporterMesh::get_mesh(const Ref<ArrayMesh> &p_base) { ERR_FAIL_COND_V(surfaces.size() == 0, Ref<ArrayMesh>()); if (mesh.is_null()) { @@ -838,7 +845,10 @@ void EditorSceneImporterMesh::_bind_methods() { ClassDB::bind_method(D_METHOD("get_surface_lod_indices", "surface_idx", "lod_idx"), &EditorSceneImporterMesh::get_surface_lod_indices); ClassDB::bind_method(D_METHOD("get_surface_material", "surface_idx"), &EditorSceneImporterMesh::get_surface_material); - ClassDB::bind_method(D_METHOD("get_mesh"), &EditorSceneImporterMesh::get_mesh); + ClassDB::bind_method(D_METHOD("set_surface_name", "surface_idx", "name"), &EditorSceneImporterMesh::set_surface_name); + ClassDB::bind_method(D_METHOD("set_surface_material", "surface_idx", "material"), &EditorSceneImporterMesh::set_surface_material); + + ClassDB::bind_method(D_METHOD("get_mesh", "base_mesh"), &EditorSceneImporterMesh::get_mesh, DEFVAL(Ref<ArrayMesh>())); ClassDB::bind_method(D_METHOD("clear"), &EditorSceneImporterMesh::clear); ClassDB::bind_method(D_METHOD("_set_data", "data"), &EditorSceneImporterMesh::_set_data); diff --git a/editor/import/scene_importer_mesh.h b/editor/import/scene_importer_mesh.h index 2488de7ed0..e57e479d8e 100644 --- a/editor/import/scene_importer_mesh.h +++ b/editor/import/scene_importer_mesh.h @@ -88,6 +88,7 @@ public: Mesh::PrimitiveType get_surface_primitive_type(int p_surface); String get_surface_name(int p_surface) const; + void set_surface_name(int p_surface, const String &p_name); Array get_surface_arrays(int p_surface) const; Array get_surface_blend_shape_arrays(int p_surface, int p_blend_shape) const; int get_surface_lod_count(int p_surface) const; @@ -112,7 +113,7 @@ public: Size2i get_lightmap_size_hint() const; bool has_mesh() const; - Ref<ArrayMesh> get_mesh(const Ref<Mesh> &p_base = Ref<Mesh>()); + Ref<ArrayMesh> get_mesh(const Ref<ArrayMesh> &p_base = Ref<ArrayMesh>()); void clear(); }; #endif // EDITOR_SCENE_IMPORTER_MESH_H diff --git a/editor/inspector_dock.cpp b/editor/inspector_dock.cpp index 952bec4d87..778046f45c 100644 --- a/editor/inspector_dock.cpp +++ b/editor/inspector_dock.cpp @@ -209,6 +209,12 @@ void InspectorDock::_paste_resource() { } } +void InspectorDock::_prepare_resource_extra_popup() { + RES r = EditorSettings::get_singleton()->get_resource_clipboard(); + PopupMenu *popup = resource_extra_button->get_popup(); + popup->set_item_disabled(popup->get_item_index(RESOURCE_EDIT_CLIPBOARD), r.is_null()); +} + void InspectorDock::_prepare_history() { EditorHistory *editor_history = EditorNode::get_singleton()->get_editor_history(); @@ -525,6 +531,7 @@ InspectorDock::InspectorDock(EditorNode *p_editor, EditorData &p_editor_data) { resource_extra_button->set_icon(get_theme_icon(SNAME("GuiTabMenuHl"), SNAME("EditorIcons"))); resource_extra_button->set_tooltip(TTR("Extra resource options.")); general_options_hb->add_child(resource_extra_button); + resource_extra_button->connect("about_to_popup", callable_mp(this, &InspectorDock::_prepare_resource_extra_popup)); resource_extra_button->get_popup()->add_icon_shortcut(get_theme_icon(SNAME("ActionPaste"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/paste_resource", TTR("Edit Resource from Clipboard")), RESOURCE_EDIT_CLIPBOARD); resource_extra_button->get_popup()->add_icon_shortcut(get_theme_icon(SNAME("ActionCopy"), SNAME("EditorIcons")), ED_SHORTCUT("property_editor/copy_resource", TTR("Copy Resource")), RESOURCE_COPY); resource_extra_button->get_popup()->set_item_disabled(1, true); diff --git a/editor/inspector_dock.h b/editor/inspector_dock.h index d50785d95c..6615845b66 100644 --- a/editor/inspector_dock.h +++ b/editor/inspector_dock.h @@ -102,6 +102,7 @@ class InspectorDock : public VBoxContainer { void _unref_resource(); void _copy_resource(); void _paste_resource(); + void _prepare_resource_extra_popup(); void _warning_pressed(); void _resource_created(); diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index df01ecd1be..36a814c30a 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -261,7 +261,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); Vector2 gpoint = mb->get_position(); - Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); + Vector2 cpoint = _get_node()->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); if (mode == MODE_EDIT || (_is_line() && mode == MODE_CREATE)) { if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { @@ -367,7 +367,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) edge_point = PosVertex(); return true; } else { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); if (!_is_line() && wip.size() > 1 && xform.xform(wip[0]).distance_to(xform.xform(cpoint)) < grab_threshold) { //wip closed @@ -396,7 +396,7 @@ bool AbstractPolygon2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) Vector2 gpoint = mm->get_position(); if (edited_point.valid() && (wip_active || (mm->get_button_mask() & MOUSE_BUTTON_MASK_LEFT))) { - Vector2 cpoint = _get_node()->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); + Vector2 cpoint = _get_node()->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(gpoint))); //Move the point in a single axis. Should only work when editing a polygon and while holding shift. if (mode == MODE_EDIT && mm->is_shift_pressed()) { @@ -502,7 +502,7 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl offset = _get_offset(j); } - if (!wip_active && j == edited_point.polygon && EDITOR_GET("editors/poly_editor/show_previous_outline")) { + if (!wip_active && j == edited_point.polygon && EDITOR_GET("editors/polygon_editor/show_previous_outline")) { const Color col = Color(0.5, 0.5, 0.5); // FIXME polygon->get_outline_color(); const int n = pre_move_edit.size(); for (int i = 0; i < n - (is_closed ? 0 : 1); i++) { @@ -625,7 +625,7 @@ AbstractPolygon2DEditor::Vertex AbstractPolygon2DEditor::get_active_point() cons } AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); const int n_polygons = _get_polygon_count(); const Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); @@ -653,7 +653,7 @@ AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_point(const } AbstractPolygon2DEditor::PosVertex AbstractPolygon2DEditor::closest_edge_point(const Vector2 &p_pos) const { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); const real_t eps = grab_threshold * 2; const real_t eps2 = eps * eps; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 69206daea8..030d90eeca 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -126,6 +126,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { graph->add_child(node); Ref<AnimationNode> agnode = blend_tree->get_node(E); + ERR_CONTINUE(!agnode.is_valid()); node->set_position_offset(blend_tree->get_node_position(E) * EDSCALE); diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index b4e9f468de..830b010d01 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -345,7 +345,7 @@ void AnimationPlayerEditor::_animation_rename() { void AnimationPlayerEditor::_animation_load() { ERR_FAIL_COND(!player); - file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE); + file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILES); file->clear_filters(); List<String> extensions; @@ -355,7 +355,6 @@ void AnimationPlayerEditor::_animation_load() { } file->popup_file_dialog(); - current_option = RESOURCE_LOAD; } void AnimationPlayerEditor::_animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path) { @@ -416,7 +415,6 @@ void AnimationPlayerEditor::_animation_save_as(const Ref<Resource> &p_resource) file->set_current_path(path); file->set_title(TTR("Save Resource As...")); file->popup_file_dialog(); - current_option = RESOURCE_SAVE; } void AnimationPlayerEditor::_animation_remove() { @@ -718,44 +716,48 @@ void AnimationPlayerEditor::_animation_edit() { } } -void AnimationPlayerEditor::_dialog_action(String p_path) { - switch (current_option) { - case RESOURCE_LOAD: { - ERR_FAIL_COND(!player); +void AnimationPlayerEditor::_save_animation(String p_file) { + String current = animation->get_item_text(animation->get_selected()); + if (current != "") { + Ref<Animation> anim = player->get_animation(current); - Ref<Resource> res = ResourceLoader::load(p_path, "Animation"); - ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + p_path + "'."); - ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + p_path + "' is not Animation."); + ERR_FAIL_COND(!Object::cast_to<Resource>(*anim)); - String anim_name = p_path.get_file(); - int ext_pos = anim_name.rfind("."); - if (ext_pos != -1) { - anim_name = anim_name.substr(0, ext_pos); - } + RES current_res = RES(Object::cast_to<Resource>(*anim)); - undo_redo->create_action(TTR("Load Animation")); - undo_redo->add_do_method(player, "add_animation", anim_name, res); - undo_redo->add_undo_method(player, "remove_animation", anim_name); - if (player->has_animation(anim_name)) { - undo_redo->add_undo_method(player, "add_animation", anim_name, player->get_animation(anim_name)); - } - undo_redo->add_do_method(this, "_animation_player_changed", player); - undo_redo->add_undo_method(this, "_animation_player_changed", player); - undo_redo->commit_action(); - break; - } - case RESOURCE_SAVE: { - String current = animation->get_item_text(animation->get_selected()); - if (current != "") { - Ref<Animation> anim = player->get_animation(current); + _animation_save_in_path(current_res, p_file); + } +} - ERR_FAIL_COND(!Object::cast_to<Resource>(*anim)); +void AnimationPlayerEditor::_load_animations(Vector<String> p_files) { + ERR_FAIL_COND(!player); - RES current_res = RES(Object::cast_to<Resource>(*anim)); + for (int i = 0; i < p_files.size(); i++) { + String file = p_files[i]; - _animation_save_in_path(current_res, p_path); - } + Ref<Resource> res = ResourceLoader::load(file, "Animation"); + ERR_FAIL_COND_MSG(res.is_null(), "Cannot load Animation from file '" + file + "'."); + ERR_FAIL_COND_MSG(!res->is_class("Animation"), "Loaded resource from file '" + file + "' is not Animation."); + if (file.rfind("/") != -1) { + file = file.substr(file.rfind("/") + 1, file.length()); + } + if (file.rfind("\\") != -1) { + file = file.substr(file.rfind("\\") + 1, file.length()); } + + if (file.find(".") != -1) { + file = file.substr(0, file.find(".")); + } + + undo_redo->create_action(TTR("Load Animation")); + undo_redo->add_do_method(player, "add_animation", file, res); + undo_redo->add_undo_method(player, "remove_animation", file); + if (player->has_animation(file)) { + undo_redo->add_undo_method(player, "add_animation", file, player->get_animation(file)); + } + undo_redo->add_do_method(this, "_animation_player_changed", player); + undo_redo->add_undo_method(this, "_animation_player_changed", player); + undo_redo->commit_action(); } } @@ -1220,7 +1222,7 @@ void AnimationPlayerEditor::_onion_skinning_menu(int p_option) { } } -void AnimationPlayerEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { +void AnimationPlayerEditor::unhandled_key_input(const Ref<InputEvent> &p_ev) { ERR_FAIL_COND(p_ev.is_null()); Ref<InputEventKey> k = p_ev; @@ -1497,7 +1499,6 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_animation_player_changed"), &AnimationPlayerEditor::_animation_player_changed); ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate); - ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &AnimationPlayerEditor::_unhandled_key_input); ClassDB::bind_method(D_METHOD("_prepare_onion_layers_1"), &AnimationPlayerEditor::_prepare_onion_layers_1); ClassDB::bind_method(D_METHOD("_prepare_onion_layers_2"), &AnimationPlayerEditor::_prepare_onion_layers_2); @@ -1696,7 +1697,8 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay animation->connect("item_selected", callable_mp(this, &AnimationPlayerEditor::_animation_selected)); - file->connect("file_selected", callable_mp(this, &AnimationPlayerEditor::_dialog_action)); + file->connect("file_selected", callable_mp(this, &AnimationPlayerEditor::_save_animation)); + file->connect("files_selected", callable_mp(this, &AnimationPlayerEditor::_load_animations)); frame->connect("value_changed", callable_mp(this, &AnimationPlayerEditor::_seek_value_changed), make_binds(true, false)); scale->connect("text_submitted", callable_mp(this, &AnimationPlayerEditor::_scale_changed)); @@ -1736,6 +1738,8 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay onion.capture.shader = Ref<Shader>(memnew(Shader)); onion.capture.shader->set_code(R"( +// Animation editor onion skinning shader. + shader_type canvas_item; uniform vec4 bkg_color; diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 5c2348f86b..be80b7f4e3 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -112,7 +112,6 @@ class AnimationPlayerEditor : public VBoxContainer { EditorFileDialog *file; ConfirmationDialog *delete_dialog; - int current_option; struct BlendEditor { AcceptDialog *dialog = nullptr; @@ -185,7 +184,8 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_duplicate(); void _animation_resource_edit(); void _scale_changed(const String &p_scale); - void _dialog_action(String p_file); + void _save_animation(String p_file); + void _load_animations(Vector<String> p_files); void _seek_frame_changed(const String &p_frame); void _seek_value_changed(float p_value, bool p_set = false, bool p_timeline_only = false); void _blend_editor_next_changed(const int p_idx); @@ -200,7 +200,7 @@ class AnimationPlayerEditor : public VBoxContainer { void _animation_key_editor_seek(float p_pos, bool p_drag, bool p_timeline_only = false); void _animation_key_editor_anim_len_changed(float p_len); - void _unhandled_key_input(const Ref<InputEvent> &p_ev); + virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override; void _animation_tool_menu(int p_option); void _onion_skinning_menu(int p_option); diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 785bab42cf..5405723d10 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -614,7 +614,7 @@ void EditorAssetLibrary::_update_repository_options() { } } -void EditorAssetLibrary::_unhandled_key_input(const Ref<InputEvent> &p_event) { +void EditorAssetLibrary::unhandled_key_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); const Ref<InputEventKey> key = p_event; @@ -1322,8 +1322,6 @@ void EditorAssetLibrary::disable_community_support() { } void EditorAssetLibrary::_bind_methods() { - ClassDB::bind_method("_unhandled_key_input", &EditorAssetLibrary::_unhandled_key_input); - ADD_SIGNAL(MethodInfo("install_asset", PropertyInfo(Variant::STRING, "zip_path"), PropertyInfo(Variant::STRING, "name"))); } diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index c6ca1ecd4f..286546f962 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -299,7 +299,7 @@ class EditorAssetLibrary : public PanelContainer { protected: static void _bind_methods(); void _notification(int p_what); - void _unhandled_key_input(const Ref<InputEvent> &p_event); + virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; public: void disable_community_support(); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 7fe12089c8..d96cc1cd18 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -41,6 +41,7 @@ #include "editor/editor_settings.h" #include "editor/plugins/animation_player_editor_plugin.h" #include "editor/plugins/script_editor_plugin.h" +#include "scene/2d/cpu_particles_2d.h" #include "scene/2d/gpu_particles_2d.h" #include "scene/2d/light_2d.h" #include "scene/2d/polygon_2d.h" @@ -471,7 +472,7 @@ real_t CanvasItemEditor::snap_angle(real_t p_target, real_t p_start) const { } } -void CanvasItemEditor::_unhandled_key_input(const Ref<InputEvent> &p_ev) { +void CanvasItemEditor::unhandled_key_input(const Ref<InputEvent> &p_ev) { ERR_FAIL_COND(p_ev.is_null()); Ref<InputEventKey> k = p_ev; @@ -589,7 +590,7 @@ void CanvasItemEditor::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_no return; } - const real_t grab_distance = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_distance = EDITOR_GET("editors/polygon_editor/point_grab_radius"); CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_node); for (int i = p_node->get_child_count() - 1; i >= 0; i--) { @@ -3908,6 +3909,11 @@ void CanvasItemEditor::_notification(int p_what) { anchors_popup->add_icon_item(get_theme_icon(SNAME("ControlAlignWide"), SNAME("EditorIcons")), TTR("Full Rect"), ANCHORS_PRESET_WIDE); anchor_mode_button->set_icon(get_theme_icon(SNAME("Anchor"), SNAME("EditorIcons"))); + + info_overlay->get_theme()->set_stylebox("normal", "Label", get_theme_stylebox(SNAME("CanvasItemInfoOverlay"), SNAME("EditorStyles"))); + warning_child_of_container->add_theme_color_override("font_color", get_theme_color(SNAME("warning_color"), SNAME("Editor"))); + warning_child_of_container->add_theme_font_override("font", get_theme_font(SNAME("main"), SNAME("EditorFonts"))); + warning_child_of_container->add_theme_font_size_override("font_size", get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts"))); } if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { @@ -4189,6 +4195,7 @@ void CanvasItemEditor::_zoom_on_position(real_t p_zoom, Point2 p_position) { p_zoom = CLAMP(p_zoom, MIN_ZOOM, MAX_ZOOM); if (p_zoom == zoom) { + zoom_widget->set_zoom(p_zoom); return; } @@ -4912,7 +4919,7 @@ void CanvasItemEditor::_focus_selection(int p_op) { void CanvasItemEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_update_override_camera_button", "game_running"), &CanvasItemEditor::_update_override_camera_button); ClassDB::bind_method("_get_editor_data", &CanvasItemEditor::_get_editor_data); - ClassDB::bind_method("_unhandled_key_input", &CanvasItemEditor::_unhandled_key_input); + ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state); ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport); ClassDB::bind_method(D_METHOD("_zoom_on_position"), &CanvasItemEditor::_zoom_on_position); @@ -5279,21 +5286,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { info_overlay->add_theme_constant_override("separation", 10); viewport_scrollable->add_child(info_overlay); + // Make sure all labels inside of the container are styled the same. Theme *info_overlay_theme = memnew(Theme); - info_overlay_theme->copy_default_theme(); info_overlay->set_theme(info_overlay_theme); - StyleBoxFlat *info_overlay_label_stylebox = memnew(StyleBoxFlat); - info_overlay_label_stylebox->set_bg_color(Color(0.0, 0.0, 0.0, 0.2)); - info_overlay_label_stylebox->set_expand_margin_size_all(4); - info_overlay_theme->set_stylebox("normal", "Label", info_overlay_label_stylebox); - warning_child_of_container = memnew(Label); warning_child_of_container->hide(); warning_child_of_container->set_text(TTR("Warning: Children of a container get their position and size determined only by their parent.")); - warning_child_of_container->add_theme_color_override("font_color", EditorNode::get_singleton()->get_gui_base()->get_theme_color(SNAME("warning_color"), SNAME("Editor"))); - warning_child_of_container->add_theme_font_override("font", EditorNode::get_singleton()->get_gui_base()->get_theme_font(SNAME("main"), SNAME("EditorFonts"))); - warning_child_of_container->add_theme_font_size_override("font_size", EditorNode::get_singleton()->get_gui_base()->get_theme_font_size(SNAME("main_size"), SNAME("EditorFonts"))); add_control_to_info_overlay(warning_child_of_container); h_scroll = memnew(HScrollBar); @@ -5740,7 +5739,7 @@ void CanvasItemEditorViewport::_on_change_type_confirmed() { } CheckBox *check = Object::cast_to<CheckBox>(button_group->get_pressed_button()); - default_type = check->get_text(); + default_texture_node_type = check->get_text(); _perform_drop_data(); selector->hide(); } @@ -5832,14 +5831,13 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & child->set_name(name); Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(ResourceCache::get(path))); - Size2 texture_size = texture->get_size(); if (parent) { editor_data->get_undo_redo().add_do_method(parent, "add_child", child); editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene()); editor_data->get_undo_redo().add_do_reference(child); editor_data->get_undo_redo().add_undo_method(parent, "remove_child", child); - } else { // if we haven't parent, lets try to make a child as a parent. + } else { // If no parent is selected, set as root node of the scene. editor_data->get_undo_redo().add_do_method(editor, "set_edited_scene", child); editor_data->get_undo_redo().add_do_method(child, "set_owner", editor->get_edited_scene()); editor_data->get_undo_redo().add_do_reference(child); @@ -5853,28 +5851,23 @@ void CanvasItemEditorViewport::_create_nodes(Node *parent, Node *child, String & editor_data->get_undo_redo().add_undo_method(ed, "live_debug_remove_node", NodePath(String(editor->get_edited_scene()->get_path_to(parent)) + "/" + new_name)); } - // handle with different property for texture - String property = "texture"; - List<PropertyInfo> props; - child->get_property_list(&props); - for (const PropertyInfo &E : props) { - if (E.name == "config/texture") { // Particles2D - property = "config/texture"; - break; - } else if (E.name == "texture/texture") { // Polygon2D - property = "texture/texture"; - break; - } else if (E.name == "normal") { // TouchScreenButton - property = "normal"; - break; - } + String node_class = child->get_class(); + if (node_class == "Polygon2D") { + editor_data->get_undo_redo().add_do_property(child, "texture/texture", texture); + } else if (node_class == "TouchScreenButton") { + editor_data->get_undo_redo().add_do_property(child, "normal", texture); + } else if (node_class == "TextureButton") { + editor_data->get_undo_redo().add_do_property(child, "texture_button", texture); + } else { + editor_data->get_undo_redo().add_do_property(child, "texture", texture); } - editor_data->get_undo_redo().add_do_property(child, property, texture); // make visible for certain node type - if (default_type == "NinePatchRect") { - editor_data->get_undo_redo().add_do_property(child, "rect/size", texture_size); - } else if (default_type == "Polygon2D") { + if (ClassDB::is_parent_class(node_class, "Control")) { + Size2 texture_size = texture->get_size(); + editor_data->get_undo_redo().add_do_property(child, "rect_size", texture_size); + } else if (node_class == "Polygon2D") { + Size2 texture_size = texture->get_size(); Vector<Vector2> list; list.push_back(Vector2(0, 0)); list.push_back(Vector2(texture_size.width, 0)); @@ -5975,23 +5968,7 @@ void CanvasItemEditorViewport::_perform_drop_data() { } else { Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); if (texture != nullptr && texture.is_valid()) { - Node *child; - if (default_type == "Light2D") { - child = memnew(Light2D); - } else if (default_type == "GPUParticles2D") { - child = memnew(GPUParticles2D); - } else if (default_type == "Polygon2D") { - child = memnew(Polygon2D); - } else if (default_type == "TouchScreenButton") { - child = memnew(TouchScreenButton); - } else if (default_type == "TextureRect") { - child = memnew(TextureRect); - } else if (default_type == "NinePatchRect") { - child = memnew(NinePatchRect); - } else { - child = memnew(Sprite2D); // default - } - + Node *child = _make_texture_node_type(default_texture_node_type); _create_nodes(target_node, child, path, drop_pos); } } @@ -6029,13 +6006,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian continue; } memdelete(instantiated_scene); - } else if (type == "Texture2D" || - type == "ImageTexture" || - type == "ViewportTexture" || - type == "CurveTexture" || - type == "GradientTexture" || - type == "StreamTexture2D" || - type == "AtlasTexture") { + } else if (ClassDB::is_parent_class(type, "Texture2D")) { Ref<Texture2D> texture = Ref<Texture2D>(Object::cast_to<Texture2D>(*res)); if (!texture.is_valid()) { continue; @@ -6052,7 +6023,7 @@ bool CanvasItemEditorViewport::can_drop_data(const Point2 &p_point, const Varian } Transform2D trans = canvas_item_editor->get_canvas_transform(); preview_node->set_position((p_point - trans.get_origin()) / trans.get_scale().x); - label->set_text(vformat(TTR("Adding %s..."), default_type)); + label->set_text(vformat(TTR("Adding %s..."), default_texture_node_type)); } return can_instantiate; } @@ -6068,9 +6039,9 @@ void CanvasItemEditorViewport::_show_resource_type_selector() { for (int i = 0; i < btn_list.size(); i++) { CheckBox *check = Object::cast_to<CheckBox>(btn_list[i]); - check->set_pressed(check->get_text() == default_type); + check->set_pressed(check->get_text() == default_texture_node_type); } - selector->set_title(vformat(TTR("Add %s"), default_type)); + selector->set_title(vformat(TTR("Add %s"), default_texture_node_type)); selector->popup_centered(); } @@ -6126,6 +6097,30 @@ void CanvasItemEditorViewport::drop_data(const Point2 &p_point, const Variant &p } } +Node *CanvasItemEditorViewport::_make_texture_node_type(String texture_node_type) { + Node *node = nullptr; + if (texture_node_type == "Sprite2D") { + node = memnew(Sprite2D); + } else if (texture_node_type == "PointLight2D") { + node = memnew(PointLight2D); + } else if (texture_node_type == "CPUParticles2D") { + node = memnew(CPUParticles2D); + } else if (texture_node_type == "GPUParticles2D") { + node = memnew(GPUParticles2D); + } else if (texture_node_type == "Polygon2D") { + node = memnew(Polygon2D); + } else if (texture_node_type == "TouchScreenButton") { + node = memnew(TouchScreenButton); + } else if (texture_node_type == "TextureRect") { + node = memnew(TextureRect); + } else if (texture_node_type == "TextureButton") { + node = memnew(TextureButton); + } else if (texture_node_type == "NinePatchRect") { + node = memnew(NinePatchRect); + } + return node; +} + void CanvasItemEditorViewport::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { @@ -6145,22 +6140,24 @@ void CanvasItemEditorViewport::_bind_methods() { } CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasItemEditor *p_canvas_item_editor) { - default_type = "Sprite2D"; + default_texture_node_type = "Sprite2D"; // Node2D - types.push_back("Sprite2D"); - types.push_back("Light2D"); - types.push_back("GPUParticles2D"); - types.push_back("Polygon2D"); - types.push_back("TouchScreenButton"); + texture_node_types.push_back("Sprite2D"); + texture_node_types.push_back("PointLight2D"); + texture_node_types.push_back("CPUParticles2D"); + texture_node_types.push_back("GPUParticles2D"); + texture_node_types.push_back("Polygon2D"); + texture_node_types.push_back("TouchScreenButton"); // Control - types.push_back("TextureRect"); - types.push_back("NinePatchRect"); + texture_node_types.push_back("TextureRect"); + texture_node_types.push_back("TextureButton"); + texture_node_types.push_back("NinePatchRect"); target_node = nullptr; editor = p_node; editor_data = editor->get_scene_tree_dock()->get_editor_data(); canvas_item_editor = p_canvas_item_editor; - preview_node = memnew(Node2D); + preview_node = memnew(Control); accept = memnew(AcceptDialog); editor->get_gui_base()->add_child(accept); @@ -6182,10 +6179,10 @@ CanvasItemEditorViewport::CanvasItemEditorViewport(EditorNode *p_node, CanvasIte btn_group->set_h_size_flags(0); button_group.instantiate(); - for (int i = 0; i < types.size(); i++) { + for (int i = 0; i < texture_node_types.size(); i++) { CheckBox *check = memnew(CheckBox); btn_group->add_child(check); - check->set_text(types[i]); + check->set_text(texture_node_types[i]); check->connect("button_down", callable_mp(this, &CanvasItemEditorViewport::_on_select_type), varray(check)); check->set_button_group(button_group); } diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 495cd5f515..1965efbf30 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -455,7 +455,7 @@ private: void _keying_changed(); - void _unhandled_key_input(const Ref<InputEvent> &p_ev); + virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override; void _draw_text_at_position(Point2 p_position, String p_string, Side p_side); void _draw_margin_at_position(int p_value, Point2 p_position, Side p_side); @@ -639,8 +639,10 @@ public: class CanvasItemEditorViewport : public Control { GDCLASS(CanvasItemEditorViewport, Control); - String default_type; - Vector<String> types; + // The type of node that will be created when dropping texture into the viewport. + String default_texture_node_type; + // Node types that are available to select from when dropping texture into viewport. + Vector<String> texture_node_types; Vector<String> selected_files; Node *target_node; @@ -649,7 +651,7 @@ class CanvasItemEditorViewport : public Control { EditorNode *editor; EditorData *editor_data; CanvasItemEditor *canvas_item_editor; - Node2D *preview_node; + Control *preview_node; AcceptDialog *accept; AcceptDialog *selector; Label *selector_label; @@ -662,6 +664,7 @@ class CanvasItemEditorViewport : public Control { void _on_select_type(Object *selected); void _on_change_type_confirmed(); void _on_change_type_closed(); + Node *_make_texture_node_type(String texture_node_type); void _create_preview(const Vector<String> &files) const; void _remove_preview(); diff --git a/editor/plugins/collision_polygon_3d_editor_plugin.cpp b/editor/plugins/collision_polygon_3d_editor_plugin.cpp index 5d5f78e0dc..8b354c33a1 100644 --- a/editor/plugins/collision_polygon_3d_editor_plugin.cpp +++ b/editor/plugins/collision_polygon_3d_editor_plugin.cpp @@ -138,7 +138,7 @@ bool CollisionPolygon3DEditor::forward_spatial_gui_input(Camera3D *p_camera, con Vector<Vector2> poly = node->call("get_polygon"); //first check if a point is to be added (segment split) - real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); switch (mode) { case MODE_CREATE: { diff --git a/editor/plugins/collision_shape_2d_editor_plugin.cpp b/editor/plugins/collision_shape_2d_editor_plugin.cpp index 4266e0f676..bfcc293625 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.cpp +++ b/editor/plugins/collision_shape_2d_editor_plugin.cpp @@ -36,9 +36,10 @@ #include "scene/resources/circle_shape_2d.h" #include "scene/resources/concave_polygon_shape_2d.h" #include "scene/resources/convex_polygon_shape_2d.h" -#include "scene/resources/line_shape_2d.h" #include "scene/resources/rectangle_shape_2d.h" #include "scene/resources/segment_shape_2d.h" +#include "scene/resources/separation_ray_shape_2d.h" +#include "scene/resources/world_margin_shape_2d.h" void CollisionShape2DEditor::_node_removed(Node *p_node) { if (p_node == node) { @@ -50,12 +51,7 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { switch (shape_type) { case CAPSULE_SHAPE: { Ref<CapsuleShape2D> capsule = node->get_shape(); - - if (idx == 0) { - return capsule->get_radius(); - } else if (idx == 1) { - return capsule->get_height(); - } + return Vector2(capsule->get_radius(), capsule->get_height()); } break; @@ -74,8 +70,8 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { - Ref<LineShape2D> line = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { return line->get_distance(); @@ -85,6 +81,15 @@ Variant CollisionShape2DEditor::get_handle_value(int idx) const { } break; + case SEPARATION_RAY_SHAPE: { + Ref<SeparationRayShape2D> ray = node->get_shape(); + + if (idx == 0) { + return ray->get_length(); + } + + } break; + case RECTANGLE_SHAPE: { Ref<RectangleShape2D> rect = node->get_shape(); @@ -142,9 +147,9 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { + case WORLD_MARGIN_SHAPE: { if (idx < 2) { - Ref<LineShape2D> line = node->get_shape(); + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { line->set_distance(p_point.length()); @@ -157,6 +162,15 @@ void CollisionShape2DEditor::set_handle(int idx, Point2 &p_point) { } break; + case SEPARATION_RAY_SHAPE: { + Ref<SeparationRayShape2D> ray = node->get_shape(); + + ray->set_length(Math::abs(p_point.y)); + + canvas_item_editor->update_viewport(); + + } break; + case RECTANGLE_SHAPE: { if (idx < 8) { Ref<RectangleShape2D> rect = node->get_shape(); @@ -209,17 +223,17 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { case CAPSULE_SHAPE: { Ref<CapsuleShape2D> capsule = node->get_shape(); + Vector2 values = p_org; + if (idx == 0) { undo_redo->add_do_method(capsule.ptr(), "set_radius", capsule->get_radius()); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); - undo_redo->add_undo_method(capsule.ptr(), "set_radius", p_org); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); } else if (idx == 1) { undo_redo->add_do_method(capsule.ptr(), "set_height", capsule->get_height()); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); - undo_redo->add_undo_method(capsule.ptr(), "set_height", p_org); - undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(capsule.ptr(), "set_radius", values[0]); + undo_redo->add_undo_method(capsule.ptr(), "set_height", values[1]); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); } break; @@ -241,8 +255,8 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { // Cannot be edited directly, use CollisionPolygon2D instead. } break; - case LINE_SHAPE: { - Ref<LineShape2D> line = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> line = node->get_shape(); if (idx == 0) { undo_redo->add_do_method(line.ptr(), "set_distance", line->get_distance()); @@ -258,6 +272,16 @@ void CollisionShape2DEditor::commit_handle(int idx, Variant &p_org) { } break; + case SEPARATION_RAY_SHAPE: { + Ref<SeparationRayShape2D> ray = node->get_shape(); + + undo_redo->add_do_method(ray.ptr(), "set_length", ray->get_length()); + undo_redo->add_do_method(canvas_item_editor, "update_viewport"); + undo_redo->add_undo_method(ray.ptr(), "set_length", p_org); + undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); + + } break; + case RECTANGLE_SHAPE: { Ref<RectangleShape2D> rect = node->get_shape(); @@ -397,8 +421,10 @@ void CollisionShape2DEditor::_get_current_shape_type() { shape_type = CONCAVE_POLYGON_SHAPE; } else if (Object::cast_to<ConvexPolygonShape2D>(*s)) { shape_type = CONVEX_POLYGON_SHAPE; - } else if (Object::cast_to<LineShape2D>(*s)) { - shape_type = LINE_SHAPE; + } else if (Object::cast_to<WorldMarginShape2D>(*s)) { + shape_type = WORLD_MARGIN_SHAPE; + } else if (Object::cast_to<SeparationRayShape2D>(*s)) { + shape_type = SEPARATION_RAY_SHAPE; } else if (Object::cast_to<RectangleShape2D>(*s)) { shape_type = RECTANGLE_SHAPE; } else if (Object::cast_to<SegmentShape2D>(*s)) { @@ -464,8 +490,8 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla case CONVEX_POLYGON_SHAPE: { } break; - case LINE_SHAPE: { - Ref<LineShape2D> shape = node->get_shape(); + case WORLD_MARGIN_SHAPE: { + Ref<WorldMarginShape2D> shape = node->get_shape(); handles.resize(2); handles.write[0] = shape->get_normal() * shape->get_distance(); @@ -476,6 +502,16 @@ void CollisionShape2DEditor::forward_canvas_draw_over_viewport(Control *p_overla } break; + case SEPARATION_RAY_SHAPE: { + Ref<SeparationRayShape2D> shape = node->get_shape(); + + handles.resize(1); + handles.write[0] = Point2(0, shape->get_length()); + + p_overlay->draw_texture(h, gt.xform(handles[0]) - size); + + } break; + case RECTANGLE_SHAPE: { Ref<RectangleShape2D> shape = node->get_shape(); diff --git a/editor/plugins/collision_shape_2d_editor_plugin.h b/editor/plugins/collision_shape_2d_editor_plugin.h index 130ec708cf..421e674df8 100644 --- a/editor/plugins/collision_shape_2d_editor_plugin.h +++ b/editor/plugins/collision_shape_2d_editor_plugin.h @@ -46,7 +46,8 @@ class CollisionShape2DEditor : public Control { CIRCLE_SHAPE, CONCAVE_POLYGON_SHAPE, CONVEX_POLYGON_SHAPE, - LINE_SHAPE, + WORLD_MARGIN_SHAPE, + SEPARATION_RAY_SHAPE, RECTANGLE_SHAPE, SEGMENT_SHAPE }; diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 07ff0eb346..4a22dc5b62 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -101,7 +101,7 @@ void CurveEditor::_notification(int p_what) { } } -void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { +void CurveEditor::gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb_ref = p_event; if (mb_ref.is_valid()) { const InputEventMouseButton &mb = **mb_ref; @@ -757,10 +757,6 @@ void CurveEditor::_draw() { } } -void CurveEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &CurveEditor::on_gui_input); -} - //--------------- bool EditorInspectorPluginCurve::can_handle(Object *p_object) { diff --git a/editor/plugins/curve_editor_plugin.h b/editor/plugins/curve_editor_plugin.h index 2e8dd43d7e..c351f6ebe9 100644 --- a/editor/plugins/curve_editor_plugin.h +++ b/editor/plugins/curve_editor_plugin.h @@ -74,10 +74,8 @@ public: protected: void _notification(int p_what); - static void _bind_methods(); - private: - void on_gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void on_preset_item_selected(int preset_id); void _curve_changed(); void on_context_menu_item_selected(int action_id); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index d47bd2d410..415832ab3b 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -505,12 +505,12 @@ Ref<Texture2D> EditorScriptPreviewPlugin::generate(const RES &p_from, const Size int thumbnail_size = MAX(p_size.x, p_size.y); img->create(thumbnail_size, thumbnail_size, false, Image::FORMAT_RGBA8); - Color bg_color = EditorSettings::get_singleton()->get("text_editor/highlighting/background_color"); - Color keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/keyword_color"); - Color control_flow_keyword_color = EditorSettings::get_singleton()->get("text_editor/highlighting/control_flow_keyword_color"); - Color text_color = EditorSettings::get_singleton()->get("text_editor/highlighting/text_color"); - Color symbol_color = EditorSettings::get_singleton()->get("text_editor/highlighting/symbol_color"); - Color comment_color = EditorSettings::get_singleton()->get("text_editor/highlighting/comment_color"); + Color bg_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/background_color"); + Color keyword_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/keyword_color"); + Color control_flow_keyword_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/control_flow_keyword_color"); + Color text_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/text_color"); + Color symbol_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/symbol_color"); + Color comment_color = EditorSettings::get_singleton()->get("text_editor/theme/highlighting/comment_color"); if (bg_color.a == 0) { bg_color = Color(0, 0, 0, 0); @@ -826,55 +826,6 @@ bool EditorFontPreviewPlugin::handles(const String &p_type) const { return ClassDB::is_parent_class(p_type, "FontData") || ClassDB::is_parent_class(p_type, "Font"); } -struct FSample { - String script; - String sample; -}; - -static FSample _samples[] = { - { "hani", U"漢字" }, - { "armn", U"Աբ" }, - { "copt", U"Αα" }, - { "cyrl", U"Аб" }, - { "grek", U"Αα" }, - { "hebr", U"אב" }, - { "arab", U"اب" }, - { "syrc", U"ܐܒ" }, - { "thaa", U"ހށ" }, - { "deva", U"आ" }, - { "beng", U"আ" }, - { "guru", U"ਆ" }, - { "gujr", U"આ" }, - { "orya", U"ଆ" }, - { "taml", U"ஆ" }, - { "telu", U"ఆ" }, - { "knda", U"ಆ" }, - { "mylm", U"ആ" }, - { "sinh", U"ආ" }, - { "thai", U"กิ" }, - { "laoo", U"ກິ" }, - { "tibt", U"ༀ" }, - { "mymr", U"က" }, - { "geor", U"Ⴀა" }, - { "hang", U"한글" }, - { "ethi", U"ሀ" }, - { "cher", U"Ꭳ" }, - { "cans", U"ᐁ" }, - { "ogam", U"ᚁ" }, - { "runr", U"ᚠ" }, - { "tglg", U"ᜀ" }, - { "hano", U"ᜠ" }, - { "buhd", U"ᝀ" }, - { "tagb", U"ᝠ" }, - { "khmr", U"ក" }, - { "mong", U"ᠠ" }, - { "limb", U"ᤁ" }, - { "tale", U"ᥐ" }, - { "latn", U"Ab" }, - { "zyyy", U"😀" }, - { "", U"" } -}; - Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, const Size2 &p_size) const { RES res = ResourceLoader::load(p_path); Ref<Font> sampled_font; @@ -886,15 +837,15 @@ Ref<Texture2D> EditorFontPreviewPlugin::generate_from_path(const String &p_path, } String sample; - for (int j = 0; j < sampled_font->get_data_count(); j++) { - for (int i = 0; _samples[i].script != String(); i++) { - if (sampled_font->get_data(j)->is_script_supported(_samples[i].script)) { - if (sampled_font->get_data(j)->has_char(_samples[i].sample[0])) { - sample += _samples[i].sample; - } - } + static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀"; + for (int i = 0; i < sample_base.length(); i++) { + if (sampled_font->has_char(sample_base[i])) { + sample += sample_base[i]; } } + if (sample.is_empty()) { + sample = sampled_font->get_supported_chars().substr(0, 6); + } Vector2 size = sampled_font->get_string_size(sample, 50); Vector2 pos; diff --git a/editor/plugins/font_editor_plugin.cpp b/editor/plugins/font_editor_plugin.cpp index 22c9cc9ab1..52fb5b69ea 100644 --- a/editor/plugins/font_editor_plugin.cpp +++ b/editor/plugins/font_editor_plugin.cpp @@ -50,70 +50,24 @@ Size2 FontDataPreview::get_minimum_size() const { return Vector2(64, 64) * EDSCALE; } -struct FSample { - String script; - String sample; -}; - -static FSample _samples[] = { - { "hani", U"漢字" }, - { "armn", U"Աբ" }, - { "copt", U"Αα" }, - { "cyrl", U"Аб" }, - { "grek", U"Αα" }, - { "hebr", U"אב" }, - { "arab", U"اب" }, - { "syrc", U"ܐܒ" }, - { "thaa", U"ހށ" }, - { "deva", U"आ" }, - { "beng", U"আ" }, - { "guru", U"ਆ" }, - { "gujr", U"આ" }, - { "orya", U"ଆ" }, - { "taml", U"ஆ" }, - { "telu", U"ఆ" }, - { "knda", U"ಆ" }, - { "mylm", U"ആ" }, - { "sinh", U"ආ" }, - { "thai", U"กิ" }, - { "laoo", U"ກິ" }, - { "tibt", U"ༀ" }, - { "mymr", U"က" }, - { "geor", U"Ⴀა" }, - { "hang", U"한글" }, - { "ethi", U"ሀ" }, - { "cher", U"Ꭳ" }, - { "cans", U"ᐁ" }, - { "ogam", U"ᚁ" }, - { "runr", U"ᚠ" }, - { "tglg", U"ᜀ" }, - { "hano", U"ᜠ" }, - { "buhd", U"ᝀ" }, - { "tagb", U"ᝠ" }, - { "khmr", U"ក" }, - { "mong", U"ᠠ" }, - { "limb", U"ᤁ" }, - { "tale", U"ᥐ" }, - { "latn", U"Ab" }, - { "zyyy", U"😀" }, - { "", U"" } -}; - void FontDataPreview::set_data(const Ref<FontData> &p_data) { Ref<Font> f = memnew(Font); f->add_data(p_data); line->clear(); - - String sample; - for (int i = 0; _samples[i].script != String(); i++) { - if (p_data->is_script_supported(_samples[i].script)) { - if (p_data->has_char(_samples[i].sample[0])) { - sample += _samples[i].sample; + if (p_data.is_valid()) { + String sample; + static const String sample_base = U"12漢字ԱբΑαАбΑαאבابܐܒހށआআਆઆଆஆఆಆആආกิກິༀကႠა한글ሀᎣᐁᚁᚠᜀᜠᝀᝠកᠠᤁᥐAb😀"; + for (int i = 0; i < sample_base.length(); i++) { + if (p_data->has_char(sample_base[i])) { + sample += sample_base[i]; } } + if (sample.is_empty()) { + sample = p_data->get_supported_chars().substr(0, 6); + } + line->add_string(sample, f, 72); } - line->add_string(sample, f, 72); update(); } @@ -124,159 +78,6 @@ FontDataPreview::FontDataPreview() { /*************************************************************************/ -void FontDataEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_SORT_CHILDREN) { - int split_width = get_name_split_ratio() * get_size().width; - button->set_size(Size2(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))->get_width(), get_size().height)); - if (is_layout_rtl()) { - if (le != nullptr) { - fit_child_in_rect(le, Rect2(Vector2(split_width, 0), Size2(split_width, get_size().height))); - } - fit_child_in_rect(chk, Rect2(Vector2(split_width - chk->get_size().x, 0), Size2(chk->get_size().x, get_size().height))); - fit_child_in_rect(button, Rect2(Vector2(0, 0), Size2(button->get_size().width, get_size().height))); - } else { - if (le != nullptr) { - fit_child_in_rect(le, Rect2(Vector2(0, 0), Size2(split_width, get_size().height))); - } - fit_child_in_rect(chk, Rect2(Vector2(split_width, 0), Size2(chk->get_size().x, get_size().height))); - fit_child_in_rect(button, Rect2(Vector2(get_size().width - button->get_size().width, 0), Size2(button->get_size().width, get_size().height))); - } - update(); - } - if (p_what == NOTIFICATION_DRAW) { - int split_width = get_name_split_ratio() * get_size().width; - Color dark_color = get_theme_color(SNAME("dark_color_2"), SNAME("Editor")); - if (is_layout_rtl()) { - draw_rect(Rect2(Vector2(0, 0), Size2(split_width, get_size().height)), dark_color); - } else { - draw_rect(Rect2(Vector2(split_width, 0), Size2(split_width, get_size().height)), dark_color); - } - } - if (p_what == NOTIFICATION_THEME_CHANGED) { - if (le != nullptr) { - button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - } else { - button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - } - queue_sort(); - } - if (p_what == NOTIFICATION_RESIZED) { - queue_sort(); - } -} - -void FontDataEditor::update_property() { - if (le == nullptr) { - bool c = get_edited_object()->get(get_edited_property()); - chk->set_pressed(c); - chk->set_disabled(is_read_only()); - } -} - -Size2 FontDataEditor::get_minimum_size() const { - return Size2(0, 60); -} - -void FontDataEditor::_bind_methods() { -} - -void FontDataEditor::init_lang_add() { - le = memnew(LineEdit); - le->set_placeholder("Language code"); - le->set_custom_minimum_size(Size2(get_size().width / 2, 0)); - le->set_editable(true); - add_child(le); - - button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - button->connect("pressed", callable_mp(this, &FontDataEditor::add_lang)); -} - -void FontDataEditor::init_lang_edit() { - button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - button->connect("pressed", callable_mp(this, &FontDataEditor::remove_lang)); - chk->connect("toggled", callable_mp(this, &FontDataEditor::toggle_lang)); -} - -void FontDataEditor::init_script_add() { - le = memnew(LineEdit); - le->set_placeholder("Script code"); - le->set_custom_minimum_size(Size2(get_size().width / 2, 0)); - le->set_editable(true); - add_child(le); - - button->set_icon(get_theme_icon(SNAME("Add"), SNAME("EditorIcons"))); - button->connect("pressed", callable_mp(this, &FontDataEditor::add_script)); -} - -void FontDataEditor::init_script_edit() { - button->set_icon(get_theme_icon(SNAME("Remove"), SNAME("EditorIcons"))); - button->connect("pressed", callable_mp(this, &FontDataEditor::remove_script)); - chk->connect("toggled", callable_mp(this, &FontDataEditor::toggle_script)); -} - -void FontDataEditor::add_lang() { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr && !le->get_text().is_empty()) { - fd->set_language_support_override(le->get_text(), chk->is_pressed()); - le->set_text(""); - chk->set_pressed(false); - } -} - -void FontDataEditor::add_script() { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr && le->get_text().length() == 4) { - fd->set_script_support_override(le->get_text(), chk->is_pressed()); - le->set_text(""); - chk->set_pressed(false); - } -} - -void FontDataEditor::toggle_lang(bool p_pressed) { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr) { - String lang = String(get_edited_property()).replace("language_support_override/", ""); - fd->set_language_support_override(lang, p_pressed); - } -} - -void FontDataEditor::toggle_script(bool p_pressed) { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr) { - String script = String(get_edited_property()).replace("script_support_override/", ""); - fd->set_script_support_override(script, p_pressed); - } -} - -void FontDataEditor::remove_lang() { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr) { - String lang = String(get_edited_property()).replace("language_support_override/", ""); - fd->remove_language_support_override(lang); - } -} - -void FontDataEditor::remove_script() { - FontData *fd = Object::cast_to<FontData>(get_edited_object()); - if (fd != nullptr) { - String script = String(get_edited_property()).replace("script_support_override/", ""); - fd->remove_script_support_override(script); - } -} - -FontDataEditor::FontDataEditor() { - chk = memnew(CheckBox); - chk->set_text(TTR("On")); - chk->set_flat(true); - add_child(chk); - - button = memnew(Button); - button->set_flat(true); - add_child(button); -} - -/*************************************************************************/ - bool EditorInspectorPluginFont::can_handle(Object *p_object) { return Object::cast_to<FontData>(p_object) != nullptr; } @@ -291,34 +92,6 @@ void EditorInspectorPluginFont::parse_begin(Object *p_object) { } bool EditorInspectorPluginFont::parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const uint32_t p_usage, const bool p_wide) { - if (p_path.begins_with("language_support_override/") && p_object->is_class("FontData")) { - String lang = p_path.replace("language_support_override/", ""); - - FontDataEditor *editor = memnew(FontDataEditor); - if (lang != "_new") { - editor->init_lang_edit(); - } else { - editor->init_lang_add(); - } - add_property_editor(p_path, editor); - - return true; - } - - if (p_path.begins_with("script_support_override/") && p_object->is_class("FontData")) { - String script = p_path.replace("script_support_override/", ""); - - FontDataEditor *editor = memnew(FontDataEditor); - if (script != "_new") { - editor->init_script_edit(); - } else { - editor->init_script_add(); - } - add_property_editor(p_path, editor); - - return true; - } - return false; } diff --git a/editor/plugins/font_editor_plugin.h b/editor/plugins/font_editor_plugin.h index 71464003a0..3530815872 100644 --- a/editor/plugins/font_editor_plugin.h +++ b/editor/plugins/font_editor_plugin.h @@ -55,39 +55,6 @@ public: /*************************************************************************/ -class FontDataEditor : public EditorProperty { - GDCLASS(FontDataEditor, EditorProperty); - - LineEdit *le = nullptr; - CheckBox *chk = nullptr; - Button *button = nullptr; - - void toggle_lang(bool p_pressed); - void toggle_script(bool p_pressed); - void add_lang(); - void add_script(); - void remove_lang(); - void remove_script(); - -protected: - void _notification(int p_what); - - static void _bind_methods(); - -public: - virtual Size2 get_minimum_size() const override; - virtual void update_property() override; - - void init_lang_add(); - void init_lang_edit(); - void init_script_add(); - void init_script_edit(); - - FontDataEditor(); -}; - -/*************************************************************************/ - class EditorInspectorPluginFont : public EditorInspectorPlugin { GDCLASS(EditorInspectorPluginFont, EditorInspectorPlugin); diff --git a/editor/plugins/gpu_particles_2d_editor_plugin.cpp b/editor/plugins/gpu_particles_2d_editor_plugin.cpp index efec5a709d..dd91df747a 100644 --- a/editor/plugins/gpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_2d_editor_plugin.cpp @@ -60,13 +60,16 @@ void GPUParticles2DEditorPlugin::_file_selected(const String &p_file) { void GPUParticles2DEditorPlugin::_menu_callback(int p_idx) { switch (p_idx) { case MENU_GENERATE_VISIBILITY_RECT: { - double gen_time = particles->get_lifetime(); - if (gen_time < 1.0) { - generate_seconds->set_value(1.0); + // Add one second to the default generation lifetime, since the progress is updated every second. + generate_seconds->set_value(MAX(1.0, trunc(particles->get_lifetime()) + 1.0)); + + if (generate_seconds->get_value() >= 11.0 + CMP_EPSILON) { + // Only pop up the time dialog if the particle's lifetime is long enough to warrant shortening it. + generate_visibility_rect->popup_centered(); } else { - generate_seconds->set_value(trunc(gen_time) + 1.0); + // Generate the visibility rect immediately. + _generate_visibility_rect(); } - generate_visibility_rect->popup_centered(); } break; case MENU_LOAD_EMISSION_MASK: { file->popup_file_dialog(); @@ -104,7 +107,7 @@ void GPUParticles2DEditorPlugin::_generate_visibility_rect() { float running = 0.0; - EditorProgress ep("gen_vrect", TTR("Generating Visibility Rect"), int(time)); + EditorProgress ep("gen_vrect", TTR("Generating Visibility Rect (Waiting for Particle Simulation)"), int(time)); bool was_emitting = particles->is_emitting(); if (!was_emitting) { diff --git a/editor/plugins/gpu_particles_3d_editor_plugin.cpp b/editor/plugins/gpu_particles_3d_editor_plugin.cpp index fff25b6f59..903a3689b0 100644 --- a/editor/plugins/gpu_particles_3d_editor_plugin.cpp +++ b/editor/plugins/gpu_particles_3d_editor_plugin.cpp @@ -238,14 +238,16 @@ void GPUParticles3DEditor::_notification(int p_notification) { void GPUParticles3DEditor::_menu_option(int p_option) { switch (p_option) { case MENU_OPTION_GENERATE_AABB: { - float gen_time = node->get_lifetime(); + // Add one second to the default generation lifetime, since the progress is updated every second. + generate_seconds->set_value(MAX(1.0, trunc(node->get_lifetime()) + 1.0)); - if (gen_time < 1.0) { - generate_seconds->set_value(1.0); + if (generate_seconds->get_value() >= 11.0 + CMP_EPSILON) { + // Only pop up the time dialog if the particle's lifetime is long enough to warrant shortening it. + generate_aabb->popup_centered(); } else { - generate_seconds->set_value(trunc(gen_time) + 1.0); + // Generate the visibility AABB immediately. + _generate_aabb(); } - generate_aabb->popup_centered(); } break; case MENU_OPTION_CREATE_EMISSION_VOLUME_FROM_NODE: { Ref<ParticlesMaterial> material = node->get_process_material(); @@ -286,7 +288,7 @@ void GPUParticles3DEditor::_generate_aabb() { double running = 0.0; - EditorProgress ep("gen_aabb", TTR("Generating AABB"), int(time)); + EditorProgress ep("gen_aabb", TTR("Generating Visibility AABB (Waiting for Particle Simulation)"), int(time)); bool was_emitting = node->is_emitting(); if (!was_emitting) { diff --git a/editor/plugins/mesh_editor_plugin.cpp b/editor/plugins/mesh_editor_plugin.cpp index 39ab3215ff..768f29e15a 100644 --- a/editor/plugins/mesh_editor_plugin.cpp +++ b/editor/plugins/mesh_editor_plugin.cpp @@ -32,7 +32,7 @@ #include "editor/editor_scale.h" -void MeshEditor::_gui_input(Ref<InputEvent> p_event) { +void MeshEditor::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseMotion> mm = p_event; @@ -103,10 +103,6 @@ void MeshEditor::_button_pressed(Node *p_button) { } } -void MeshEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &MeshEditor::_gui_input); -} - MeshEditor::MeshEditor() { viewport = memnew(SubViewport); Ref<World3D> world_3d; diff --git a/editor/plugins/mesh_editor_plugin.h b/editor/plugins/mesh_editor_plugin.h index 455fcb5fe9..1e88b70202 100644 --- a/editor/plugins/mesh_editor_plugin.h +++ b/editor/plugins/mesh_editor_plugin.h @@ -64,8 +64,7 @@ class MeshEditor : public SubViewportContainer { protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); - static void _bind_methods(); + void gui_input(const Ref<InputEvent> &p_event) override; public: void edit(Ref<Mesh> p_mesh); diff --git a/editor/plugins/node_3d_editor_gizmos.cpp b/editor/plugins/node_3d_editor_gizmos.cpp index dcea7b26f3..d04e88e915 100644 --- a/editor/plugins/node_3d_editor_gizmos.cpp +++ b/editor/plugins/node_3d_editor_gizmos.cpp @@ -66,6 +66,7 @@ #include "scene/resources/cylinder_shape_3d.h" #include "scene/resources/height_map_shape_3d.h" #include "scene/resources/primitive_meshes.h" +#include "scene/resources/separation_ray_shape_3d.h" #include "scene/resources/sphere_shape_3d.h" #include "scene/resources/surface_tool.h" #include "scene/resources/world_margin_shape_3d.h" @@ -105,9 +106,7 @@ void EditorNode3DGizmo::clear() { } void EditorNode3DGizmo::redraw() { - if (get_script_instance() && get_script_instance()->has_method("_redraw")) { - get_script_instance()->call("_redraw"); - } else { + if (!GDVIRTUAL_CALL(_redraw)) { ERR_FAIL_COND(!gizmo_plugin); gizmo_plugin->redraw(this); } @@ -118,8 +117,9 @@ void EditorNode3DGizmo::redraw() { } String EditorNode3DGizmo::get_handle_name(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_id); + String ret; + if (GDVIRTUAL_CALL(_get_handle_name, p_id, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, ""); @@ -127,8 +127,9 @@ String EditorNode3DGizmo::get_handle_name(int p_id) const { } bool EditorNode3DGizmo::is_handle_highlighted(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_id); + bool success; + if (GDVIRTUAL_CALL(_is_handle_highlighted, p_id, success)) { + return success; } ERR_FAIL_COND_V(!gizmo_plugin, false); @@ -136,8 +137,9 @@ bool EditorNode3DGizmo::is_handle_highlighted(int p_id) const { } Variant EditorNode3DGizmo::get_handle_value(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_id); + Variant value; + if (GDVIRTUAL_CALL(_get_handle_value, p_id, value)) { + return value; } ERR_FAIL_COND_V(!gizmo_plugin, Variant()); @@ -145,8 +147,7 @@ Variant EditorNode3DGizmo::get_handle_value(int p_id) const { } void EditorNode3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_id, p_camera, p_point); + if (GDVIRTUAL_CALL(_set_handle, p_id, p_camera, p_point)) { return; } @@ -155,8 +156,7 @@ void EditorNode3DGizmo::set_handle(int p_id, Camera3D *p_camera, const Point2 &p } void EditorNode3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_id, p_restore, p_cancel); + if (GDVIRTUAL_CALL(_commit_handle, p_id, p_restore, p_cancel)) { return; } @@ -165,8 +165,9 @@ void EditorNode3DGizmo::commit_handle(int p_id, const Variant &p_restore, bool p } int EditorNode3DGizmo::subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 &p_point) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { - return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + int id; + if (GDVIRTUAL_CALL(_subgizmos_intersect_ray, p_camera, p_point, id)) { + return id; } ERR_FAIL_COND_V(!gizmo_plugin, -1); @@ -174,12 +175,14 @@ int EditorNode3DGizmo::subgizmos_intersect_ray(Camera3D *p_camera, const Vector2 } Vector<int> EditorNode3DGizmo::subgizmos_intersect_frustum(const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { - Array frustum; - for (int i = 0; i < p_frustum.size(); i++) { - frustum[i] = p_frustum[i]; - } - return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + TypedArray<Plane> frustum; + frustum.resize(p_frustum.size()); + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + Vector<int> ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_frustum, p_camera, frustum, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, Vector<int>()); @@ -187,8 +190,9 @@ Vector<int> EditorNode3DGizmo::subgizmos_intersect_frustum(const Camera3D *p_cam } Transform3D EditorNode3DGizmo::get_subgizmo_transform(int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { - return get_script_instance()->call("_get_subgizmo_transform", p_id); + Transform3D ret; + if (GDVIRTUAL_CALL(_get_subgizmo_transform, p_id, ret)) { + return ret; } ERR_FAIL_COND_V(!gizmo_plugin, Transform3D()); @@ -196,8 +200,7 @@ Transform3D EditorNode3DGizmo::get_subgizmo_transform(int p_id) const { } void EditorNode3DGizmo::set_subgizmo_transform(int p_id, Transform3D p_transform) { - if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { - get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); + if (GDVIRTUAL_CALL(_set_subgizmo_transform, p_id, p_transform)) { return; } @@ -206,18 +209,13 @@ void EditorNode3DGizmo::set_subgizmo_transform(int p_id, Transform3D p_transform } void EditorNode3DGizmo::commit_subgizmos(const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { - Array ids; - for (int i = 0; i < p_ids.size(); i++) { - ids[i] = p_ids[i]; - } - - Array restore; - for (int i = 0; i < p_restore.size(); i++) { - restore[i] = p_restore[i]; - } + TypedArray<Transform3D> restore; + restore.resize(p_restore.size()); + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; + } - get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + if (GDVIRTUAL_CALL(_commit_subgizmos, p_ids, restore, p_cancel)) { return; } @@ -837,26 +835,19 @@ void EditorNode3DGizmo::_bind_methods() { ClassDB::bind_method(D_METHOD("is_subgizmo_selected"), &EditorNode3DGizmo::is_subgizmo_selected); ClassDB::bind_method(D_METHOD("get_subgizmo_selection"), &EditorNode3DGizmo::get_subgizmo_selection); - BIND_VMETHOD(MethodInfo("_redraw")); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", PropertyInfo(Variant::INT, "id"))); - - MethodInfo hvget(Variant::NIL, "_get_handle_value", PropertyInfo(Variant::INT, "id")); - hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(hvget); + GDVIRTUAL_BIND(_redraw); + GDVIRTUAL_BIND(_get_handle_name, "id"); + GDVIRTUAL_BIND(_is_handle_highlighted, "id"); - BIND_VMETHOD(MethodInfo("_set_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cm.default_arguments.push_back(false); - BIND_VMETHOD(cm); + GDVIRTUAL_BIND(_get_handle_value, "id"); + GDVIRTUAL_BIND(_set_handle, "id", "camera", "point"); + GDVIRTUAL_BIND(_commit_handle, "id", "restore", "cancel"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); - BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); - MethodInfo cs = MethodInfo("_commit_subgizmos", PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cs.default_arguments.push_back(false); - BIND_VMETHOD(cs); + GDVIRTUAL_BIND(_subgizmos_intersect_ray, "camera", "point"); + GDVIRTUAL_BIND(_subgizmos_intersect_frustum, "camera", "frustum"); + GDVIRTUAL_BIND(_set_subgizmo_transform, "id", "transform"); + GDVIRTUAL_BIND(_get_subgizmo_transform, "id"); + GDVIRTUAL_BIND(_commit_subgizmos, "ids", "restores", "cancel"); } EditorNode3DGizmo::EditorNode3DGizmo() { @@ -1042,11 +1033,6 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::get_gizmo(Node3D *p_spatial) { } void EditorNode3DGizmoPlugin::_bind_methods() { -#define GIZMO_REF PropertyInfo(Variant::OBJECT, "gizmo", PROPERTY_HINT_RESOURCE_TYPE, "EditorNode3DGizmo") - - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_has_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - BIND_VMETHOD(MethodInfo(GIZMO_REF, "_create_gizmo", PropertyInfo(Variant::OBJECT, "spatial", PROPERTY_HINT_RESOURCE_TYPE, "Node3D"))); - ClassDB::bind_method(D_METHOD("create_material", "name", "color", "billboard", "on_top", "use_vertex_color"), &EditorNode3DGizmoPlugin::create_material, DEFVAL(false), DEFVAL(false), DEFVAL(false)); ClassDB::bind_method(D_METHOD("create_icon_material", "name", "texture", "on_top", "color"), &EditorNode3DGizmoPlugin::create_icon_material, DEFVAL(false), DEFVAL(Color(1, 1, 1, 1))); ClassDB::bind_method(D_METHOD("create_handle_material", "name", "billboard", "texture"), &EditorNode3DGizmoPlugin::create_handle_material, DEFVAL(false), DEFVAL(Variant())); @@ -1054,45 +1040,42 @@ void EditorNode3DGizmoPlugin::_bind_methods() { ClassDB::bind_method(D_METHOD("get_material", "name", "gizmo"), &EditorNode3DGizmoPlugin::get_material, DEFVAL(Ref<EditorNode3DGizmo>())); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_gizmo_name")); - BIND_VMETHOD(MethodInfo(Variant::INT, "_get_priority")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_can_be_hidden")); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_selectable_when_hidden")); - - BIND_VMETHOD(MethodInfo("_redraw", GIZMO_REF)); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_handle_name", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo(Variant::BOOL, "_is_handle_highlighted", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); + GDVIRTUAL_BIND(_has_gizmo, "for_node_3d"); + GDVIRTUAL_BIND(_create_gizmo, "for_node_3d"); - MethodInfo hvget(Variant::NIL, "_get_handle_value", GIZMO_REF, PropertyInfo(Variant::INT, "id")); - hvget.return_val.usage |= PROPERTY_USAGE_NIL_IS_VARIANT; - BIND_VMETHOD(hvget); + GDVIRTUAL_BIND(_get_gizmo_name); + GDVIRTUAL_BIND(_get_priority); + GDVIRTUAL_BIND(_can_be_hidden); + GDVIRTUAL_BIND(_is_selectable_when_hidden); - BIND_VMETHOD(MethodInfo("_set_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - MethodInfo cm = MethodInfo("_commit_handle", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::NIL, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cm.default_arguments.push_back(false); - BIND_VMETHOD(cm); + GDVIRTUAL_BIND(_redraw, "gizmo"); + GDVIRTUAL_BIND(_get_handle_name, "gizmo", "handle_id"); + GDVIRTUAL_BIND(_is_handle_highlighted, "gizmo", "handle_id"); + GDVIRTUAL_BIND(_get_handle_value, "gizmo", "handle_id"); - BIND_VMETHOD(MethodInfo(Variant::INT, "_subgizmos_intersect_ray", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::VECTOR2, "point"))); - BIND_VMETHOD(MethodInfo(Variant::PACKED_INT32_ARRAY, "_subgizmos_intersect_frustum", GIZMO_REF, PropertyInfo(Variant::OBJECT, "camera", PROPERTY_HINT_RESOURCE_TYPE, "Camera3D"), PropertyInfo(Variant::ARRAY, "frustum"))); - BIND_VMETHOD(MethodInfo(Variant::TRANSFORM3D, "_get_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"))); - BIND_VMETHOD(MethodInfo("_set_subgizmo_transform", GIZMO_REF, PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::TRANSFORM3D, "transform"))); - MethodInfo cs = MethodInfo("_commit_subgizmos", GIZMO_REF, PropertyInfo(Variant::PACKED_INT32_ARRAY, "ids"), PropertyInfo(Variant::ARRAY, "restore"), PropertyInfo(Variant::BOOL, "cancel")); - cs.default_arguments.push_back(false); - BIND_VMETHOD(cs); + GDVIRTUAL_BIND(_set_handle, "gizmo", "handle_id", "camera", "screen_pos"); + GDVIRTUAL_BIND(_commit_handle, "gizmo", "handle_id", "restore", "cancel"); -#undef GIZMO_REF + GDVIRTUAL_BIND(_subgizmos_intersect_ray, "gizmo", "camera", "screen_pos"); + GDVIRTUAL_BIND(_subgizmos_intersect_frustum, "gizmo", "camera", "frustum_planes"); + GDVIRTUAL_BIND(_get_subgizmo_transform, "gizmo", "subgizmo_id"); + GDVIRTUAL_BIND(_set_subgizmo_transform, "gizmo", "subgizmo_id", "transform"); + GDVIRTUAL_BIND(_commit_subgizmos, "gizmo", "ids", "restores", "cancel"); + ; } bool EditorNode3DGizmoPlugin::has_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_has_gizmo")) { - return get_script_instance()->call("_has_gizmo", p_spatial); + bool success; + if (GDVIRTUAL_CALL(_has_gizmo, p_spatial, success)) { + return success; } return false; } Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) { - if (get_script_instance() && get_script_instance()->has_method("_create_gizmo")) { - return get_script_instance()->call("_create_gizmo", p_spatial); + Ref<EditorNode3DGizmo> ret; + if (GDVIRTUAL_CALL(_create_gizmo, p_spatial, ret)) { + return ret; } Ref<EditorNode3DGizmo> ref; @@ -1103,106 +1086,100 @@ Ref<EditorNode3DGizmo> EditorNode3DGizmoPlugin::create_gizmo(Node3D *p_spatial) } bool EditorNode3DGizmoPlugin::can_be_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_can_be_hidden")) { - return get_script_instance()->call("_can_be_hidden"); + bool ret; + if (GDVIRTUAL_CALL(_can_be_hidden, ret)) { + return ret; } return true; } bool EditorNode3DGizmoPlugin::is_selectable_when_hidden() const { - if (get_script_instance() && get_script_instance()->has_method("_is_selectable_when_hidden")) { - return get_script_instance()->call("_is_selectable_when_hidden"); + bool ret; + if (GDVIRTUAL_CALL(_is_selectable_when_hidden, ret)) { + return ret; } return false; } void EditorNode3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { - if (get_script_instance() && get_script_instance()->has_method("_redraw")) { - Ref<EditorNode3DGizmo> ref(p_gizmo); - get_script_instance()->call("_redraw", ref); - } + GDVIRTUAL_CALL(_redraw, p_gizmo); } bool EditorNode3DGizmoPlugin::is_handle_highlighted(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_is_handle_highlighted")) { - return get_script_instance()->call("_is_handle_highlighted", p_gizmo, p_id); + bool ret; + if (GDVIRTUAL_CALL(_is_handle_highlighted, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return false; } String EditorNode3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_name")) { - return get_script_instance()->call("_get_handle_name", p_gizmo, p_id); + String ret; + if (GDVIRTUAL_CALL(_get_handle_name, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return ""; } Variant EditorNode3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_handle_value")) { - return get_script_instance()->call("_get_handle_value", p_gizmo, p_id); + Variant ret; + if (GDVIRTUAL_CALL(_get_handle_value, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return Variant(); } void EditorNode3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, int p_id, Camera3D *p_camera, const Point2 &p_point) { - if (get_script_instance() && get_script_instance()->has_method("_set_handle")) { - get_script_instance()->call("_set_handle", p_gizmo, p_id, p_camera, p_point); - } + GDVIRTUAL_CALL(_set_handle, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_camera, p_point); } void EditorNode3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo, int p_id, const Variant &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_handle")) { - get_script_instance()->call("_commit_handle", p_gizmo, p_id, p_restore, p_cancel); - } + GDVIRTUAL_CALL(_commit_handle, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_restore, p_cancel); } int EditorNode3DGizmoPlugin::subgizmos_intersect_ray(const EditorNode3DGizmo *p_gizmo, Camera3D *p_camera, const Vector2 &p_point) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_ray")) { - return get_script_instance()->call("_subgizmos_intersect_ray", p_camera, p_point); + int ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_ray, Ref<EditorNode3DGizmo>(p_gizmo), p_camera, p_point, ret)) { + return ret; } return -1; } Vector<int> EditorNode3DGizmoPlugin::subgizmos_intersect_frustum(const EditorNode3DGizmo *p_gizmo, const Camera3D *p_camera, const Vector<Plane> &p_frustum) const { - if (get_script_instance() && get_script_instance()->has_method("_subgizmos_intersect_frustum")) { - Array frustum; - for (int i = 0; i < p_frustum.size(); i++) { - frustum[i] = p_frustum[i]; - } - return get_script_instance()->call("_subgizmos_intersect_frustum", p_camera, frustum); + TypedArray<Transform3D> frustum; + frustum.resize(p_frustum.size()); + for (int i = 0; i < p_frustum.size(); i++) { + frustum[i] = p_frustum[i]; + } + Vector<int> ret; + if (GDVIRTUAL_CALL(_subgizmos_intersect_frustum, Ref<EditorNode3DGizmo>(p_gizmo), p_camera, frustum, ret)) { + return ret; } return Vector<int>(); } Transform3D EditorNode3DGizmoPlugin::get_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id) const { - if (get_script_instance() && get_script_instance()->has_method("_get_subgizmo_transform")) { - return get_script_instance()->call("_get_subgizmo_transform", p_id); + Transform3D ret; + if (GDVIRTUAL_CALL(_get_subgizmo_transform, Ref<EditorNode3DGizmo>(p_gizmo), p_id, ret)) { + return ret; } return Transform3D(); } void EditorNode3DGizmoPlugin::set_subgizmo_transform(const EditorNode3DGizmo *p_gizmo, int p_id, Transform3D p_transform) { - if (get_script_instance() && get_script_instance()->has_method("_set_subgizmo_transform")) { - get_script_instance()->call("_set_subgizmo_transform", p_id, p_transform); - } + GDVIRTUAL_CALL(_set_subgizmo_transform, Ref<EditorNode3DGizmo>(p_gizmo), p_id, p_transform); } void EditorNode3DGizmoPlugin::commit_subgizmos(const EditorNode3DGizmo *p_gizmo, const Vector<int> &p_ids, const Vector<Transform3D> &p_restore, bool p_cancel) { - if (get_script_instance() && get_script_instance()->has_method("_commit_subgizmos")) { - Array ids; - for (int i = 0; i < p_ids.size(); i++) { - ids[i] = p_ids[i]; - } - - Array restore; - for (int i = 0; i < p_restore.size(); i++) { - restore[i] = p_restore[i]; - } - - get_script_instance()->call("_commit_subgizmos", ids, restore, p_cancel); + TypedArray<Transform3D> restore; + restore.resize(p_restore.size()); + for (int i = 0; i < p_restore.size(); i++) { + restore[i] = p_restore[i]; } + + GDVIRTUAL_CALL(_commit_subgizmos, Ref<EditorNode3DGizmo>(p_gizmo), p_ids, restore, p_cancel); } void EditorNode3DGizmoPlugin::set_state(int p_state) { @@ -2100,64 +2077,76 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { surface_tool->begin(Mesh::PRIMITIVE_LINES); surface_tool->set_material(material); - Vector<Transform3D> grests; + LocalVector<Transform3D> grests; grests.resize(skel->get_bone_count()); - Vector<int> bones; - Vector<float> weights; + LocalVector<int> bones; + LocalVector<float> weights; bones.resize(4); weights.resize(4); for (int i = 0; i < 4; i++) { - bones.write[i] = 0; - weights.write[i] = 0; + bones[i] = 0; + weights[i] = 0; } - weights.write[0] = 1; + weights[0] = 1; AABB aabb; Color bonecolor = Color(1.0, 0.4, 0.4, 0.3); Color rootcolor = Color(0.4, 1.0, 0.4, 0.1); - for (int i_bone = 0; i_bone < skel->get_bone_count(); i_bone++) { - int i = skel->get_process_order(i_bone); + //LocalVector<int> bones_to_process = skel->get_parentless_bones(); + LocalVector<int> bones_to_process; + bones_to_process = skel->get_parentless_bones(); - int parent = skel->get_bone_parent(i); + while (bones_to_process.size() > 0) { + int current_bone_idx = bones_to_process[0]; + bones_to_process.erase(current_bone_idx); - if (parent >= 0) { - grests.write[i] = grests[parent] * skel->get_bone_rest(i); + LocalVector<int> child_bones_vector; + child_bones_vector = skel->get_bone_children(current_bone_idx); + int child_bones_size = child_bones_vector.size(); - Vector3 v0 = grests[parent].origin; - Vector3 v1 = grests[i].origin; - Vector3 d = (v1 - v0).normalized(); - float dist = v0.distance_to(v1); + // You have children but no parent, then you must be a root/parentless bone. + if (child_bones_size >= 0 && skel->get_bone_parent(current_bone_idx) <= 0) { + grests[current_bone_idx] = skel->global_pose_to_local_pose(current_bone_idx, skel->get_bone_global_pose(current_bone_idx)); + } - //find closest axis - int closest = -1; - float closest_d = 0.0; + for (int i = 0; i < child_bones_size; i++) { + int child_bone_idx = child_bones_vector[i]; + grests[child_bone_idx] = skel->global_pose_to_local_pose(child_bone_idx, skel->get_bone_global_pose(child_bone_idx)); + Vector3 v0 = grests[current_bone_idx].origin; + Vector3 v1 = grests[child_bone_idx].origin; + Vector3 d = skel->get_bone_rest(child_bone_idx).origin.normalized(); + real_t dist = skel->get_bone_rest(child_bone_idx).origin.length(); + + // Find closest axis. + int closest = -1; + real_t closest_d = 0.0; for (int j = 0; j < 3; j++) { - float dp = Math::abs(grests[parent].basis[j].normalized().dot(d)); + real_t dp = Math::abs(grests[current_bone_idx].basis[j].normalized().dot(d)); if (j == 0 || dp > closest_d) { closest = j; } } - //find closest other + // Find closest other. Vector3 first; Vector3 points[4]; - int pointidx = 0; + int point_idx = 0; for (int j = 0; j < 3; j++) { - bones.write[0] = parent; + bones[0] = current_bone_idx; surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(rootcolor); - surface_tool->add_vertex(v0 - grests[parent].basis[j].normalized() * dist * 0.05); + surface_tool->add_vertex(v0 - grests[current_bone_idx].basis[j].normalized() * dist * 0.05); surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(rootcolor); - surface_tool->add_vertex(v0 + grests[parent].basis[j].normalized() * dist * 0.05); + surface_tool->add_vertex(v0 + grests[current_bone_idx].basis[j].normalized() * dist * 0.05); if (j == closest) { continue; @@ -2165,7 +2154,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 axis; if (first == Vector3()) { - axis = d.cross(d.cross(grests[parent].basis[j])).normalized(); + axis = d.cross(d.cross(grests[current_bone_idx].basis[j])).normalized(); first = axis; } else { axis = d.cross(first).normalized(); @@ -2178,7 +2167,7 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { Vector3 point = v0 + d * dist * 0.2; point += axis * dist * 0.1; - bones.write[0] = parent; + bones[0] = current_bone_idx; surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(bonecolor); @@ -2188,23 +2177,22 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { surface_tool->set_color(bonecolor); surface_tool->add_vertex(point); - bones.write[0] = parent; + bones[0] = current_bone_idx; surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(bonecolor); surface_tool->add_vertex(point); - bones.write[0] = i; + bones[0] = child_bone_idx; surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(bonecolor); surface_tool->add_vertex(v1); - points[pointidx++] = point; + points[point_idx++] = point; } } - SWAP(points[1], points[2]); for (int j = 0; j < 4; j++) { - bones.write[0] = parent; + bones[0] = current_bone_idx; surface_tool->set_bones(bones); surface_tool->set_weights(weights); surface_tool->set_color(bonecolor); @@ -2214,9 +2202,9 @@ void Skeleton3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { surface_tool->set_color(bonecolor); surface_tool->add_vertex(points[(j + 1) % 4]); } - } else { - grests.write[i] = skel->get_bone_rest(i); - bones.write[0] = i; + + // Add the bone's children to the list of bones to be processed. + bones_to_process.push_back(child_bones_vector[i]); } } @@ -4080,6 +4068,10 @@ String CollisionShape3DGizmoPlugin::get_handle_name(const EditorNode3DGizmo *p_g return p_id == 0 ? "Radius" : "Height"; } + if (Object::cast_to<SeparationRayShape3D>(*s)) { + return "Length"; + } + return ""; } @@ -4103,7 +4095,7 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p if (Object::cast_to<CapsuleShape3D>(*s)) { Ref<CapsuleShape3D> cs2 = s; - return p_id == 0 ? cs2->get_radius() : cs2->get_height(); + return Vector2(cs2->get_radius(), cs2->get_height()); } if (Object::cast_to<CylinderShape3D>(*s)) { @@ -4111,6 +4103,11 @@ Variant CollisionShape3DGizmoPlugin::get_handle_value(const EditorNode3DGizmo *p return p_id == 0 ? cs2->get_radius() : cs2->get_height(); } + if (Object::cast_to<SeparationRayShape3D>(*s)) { + Ref<SeparationRayShape3D> cs2 = s; + return cs2->get_length(); + } + return Variant(); } @@ -4146,6 +4143,22 @@ void CollisionShape3DGizmoPlugin::set_handle(const EditorNode3DGizmo *p_gizmo, i ss->set_radius(d); } + if (Object::cast_to<SeparationRayShape3D>(*s)) { + Ref<SeparationRayShape3D> rs = s; + Vector3 ra, rb; + Geometry3D::get_closest_points_between_segments(Vector3(), Vector3(0, 0, 4096), sg[0], sg[1], ra, rb); + float d = ra.z; + if (Node3DEditor::get_singleton()->is_snap_enabled()) { + d = Math::snapped(d, Node3DEditor::get_singleton()->get_translate_snap()); + } + + if (d < 0.001) { + d = 0.001; + } + + rs->set_length(d); + } + if (Object::cast_to<BoxShape3D>(*s)) { Vector3 axis; axis[p_id] = 1.0; @@ -4250,12 +4263,11 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo if (Object::cast_to<CapsuleShape3D>(*s)) { Ref<CapsuleShape3D> ss = s; + Vector2 values = p_restore; + if (p_cancel) { - if (p_id == 0) { - ss->set_radius(p_restore); - } else { - ss->set_height(p_restore); - } + ss->set_radius(values[0]); + ss->set_height(values[1]); return; } @@ -4263,12 +4275,12 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo if (p_id == 0) { ur->create_action(TTR("Change Capsule Shape Radius")); ur->add_do_method(ss.ptr(), "set_radius", ss->get_radius()); - ur->add_undo_method(ss.ptr(), "set_radius", p_restore); } else { ur->create_action(TTR("Change Capsule Shape Height")); ur->add_do_method(ss.ptr(), "set_height", ss->get_height()); - ur->add_undo_method(ss.ptr(), "set_height", p_restore); } + ur->add_undo_method(ss.ptr(), "set_radius", values[0]); + ur->add_undo_method(ss.ptr(), "set_height", values[1]); ur->commit_action(); } @@ -4301,6 +4313,20 @@ void CollisionShape3DGizmoPlugin::commit_handle(const EditorNode3DGizmo *p_gizmo ur->commit_action(); } + + if (Object::cast_to<SeparationRayShape3D>(*s)) { + Ref<SeparationRayShape3D> ss = s; + if (p_cancel) { + ss->set_length(p_restore); + return; + } + + UndoRedo *ur = Node3DEditor::get_singleton()->get_undo_redo(); + ur->create_action(TTR("Change Separation Ray Shape Length")); + ur->add_do_method(ss.ptr(), "set_length", ss->get_length()); + ur->add_undo_method(ss.ptr(), "set_length", p_restore); + ur->commit_action(); + } } void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { @@ -4571,6 +4597,19 @@ void CollisionShape3DGizmoPlugin::redraw(EditorNode3DGizmo *p_gizmo) { p_gizmo->add_collision_segments(cs2->get_debug_mesh_lines()); } + if (Object::cast_to<SeparationRayShape3D>(*s)) { + Ref<SeparationRayShape3D> rs = s; + + Vector<Vector3> points; + points.push_back(Vector3()); + points.push_back(Vector3(0, 0, rs->get_length())); + p_gizmo->add_lines(points, material); + p_gizmo->add_collision_segments(points); + Vector<Vector3> handles; + handles.push_back(Vector3(0, 0, rs->get_length())); + p_gizmo->add_handles(handles, handles_material); + } + if (Object::cast_to<HeightMapShape3D>(*s)) { Ref<HeightMapShape3D> hms = s; diff --git a/editor/plugins/node_3d_editor_gizmos.h b/editor/plugins/node_3d_editor_gizmos.h index 64f46f2b1a..415ed5da5c 100644 --- a/editor/plugins/node_3d_editor_gizmos.h +++ b/editor/plugins/node_3d_editor_gizmos.h @@ -31,11 +31,12 @@ #ifndef NODE_3D_EDITOR_GIZMOS_H #define NODE_3D_EDITOR_GIZMOS_H +#include "core/templates/local_vector.h" #include "core/templates/ordered_hash_map.h" +#include "scene/3d/camera_3d.h" #include "scene/3d/node_3d.h" #include "scene/3d/skeleton_3d.h" -class Camera3D; class Timer; class EditorNode3DGizmoPlugin; @@ -78,6 +79,19 @@ protected: EditorNode3DGizmoPlugin *gizmo_plugin; + GDVIRTUAL0(_redraw) + GDVIRTUAL1RC(String, _get_handle_name, int) + GDVIRTUAL1RC(bool, _is_handle_highlighted, int) + + GDVIRTUAL1RC(Variant, _get_handle_value, int) + GDVIRTUAL3(_set_handle, int, const Camera3D *, Vector2) + GDVIRTUAL3(_commit_handle, int, Variant, bool) + + GDVIRTUAL2RC(int, _subgizmos_intersect_ray, const Camera3D *, Vector2) + GDVIRTUAL2RC(Vector<int>, _subgizmos_intersect_frustum, const Camera3D *, TypedArray<Plane>) + GDVIRTUAL1RC(Transform3D, _get_subgizmo_transform, int) + GDVIRTUAL2(_set_subgizmo_transform, int, Transform3D) + GDVIRTUAL3(_commit_subgizmos, Vector<int>, TypedArray<Transform3D>, bool) public: void add_lines(const Vector<Vector3> &p_lines, const Ref<Material> &p_material, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); void add_vertices(const Vector<Vector3> &p_vertices, const Ref<Material> &p_material, Mesh::PrimitiveType p_primitive_type, bool p_billboard = false, const Color &p_modulate = Color(1, 1, 1)); @@ -144,6 +158,28 @@ protected: virtual bool has_gizmo(Node3D *p_spatial); virtual Ref<EditorNode3DGizmo> create_gizmo(Node3D *p_spatial); + GDVIRTUAL1RC(bool, _has_gizmo, Node3D *) + GDVIRTUAL1RC(Ref<EditorNode3DGizmo>, _create_gizmo, Node3D *) + + GDVIRTUAL0RC(String, _get_gizmo_name) + GDVIRTUAL0RC(int, _get_priority) + GDVIRTUAL0RC(bool, _can_be_hidden) + GDVIRTUAL0RC(bool, _is_selectable_when_hidden) + + GDVIRTUAL1(_redraw, Ref<EditorNode3DGizmo>) + GDVIRTUAL2RC(String, _get_handle_name, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL2RC(bool, _is_handle_highlighted, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL2RC(Variant, _get_handle_value, Ref<EditorNode3DGizmo>, int) + + GDVIRTUAL4(_set_handle, Ref<EditorNode3DGizmo>, int, const Camera3D *, Vector2) + GDVIRTUAL4(_commit_handle, Ref<EditorNode3DGizmo>, int, Variant, bool) + + GDVIRTUAL3RC(int, _subgizmos_intersect_ray, Ref<EditorNode3DGizmo>, const Camera3D *, Vector2) + GDVIRTUAL3RC(Vector<int>, _subgizmos_intersect_frustum, Ref<EditorNode3DGizmo>, const Camera3D *, TypedArray<Plane>) + GDVIRTUAL2RC(Transform3D, _get_subgizmo_transform, Ref<EditorNode3DGizmo>, int) + GDVIRTUAL3(_set_subgizmo_transform, Ref<EditorNode3DGizmo>, int, Transform3D) + GDVIRTUAL4(_commit_subgizmos, Ref<EditorNode3DGizmo>, Vector<int>, TypedArray<Transform3D>, bool) + public: void create_material(const String &p_name, const Color &p_color, bool p_billboard = false, bool p_on_top = false, bool p_use_vertex_color = false); void create_icon_material(const String &p_name, const Ref<Texture2D> &p_texture, bool p_on_top = false, const Color &p_albedo = Color(1, 1, 1, 1)); diff --git a/editor/plugins/node_3d_editor_plugin.cpp b/editor/plugins/node_3d_editor_plugin.cpp index 8f0359bd0f..291cafab2b 100644 --- a/editor/plugins/node_3d_editor_plugin.cpp +++ b/editor/plugins/node_3d_editor_plugin.cpp @@ -181,7 +181,7 @@ void ViewportRotationControl::_get_sorted_axis(Vector<Axis2D> &r_axis) { r_axis.sort_custom<Axis2DCompare>(); } -void ViewportRotationControl::_gui_input(Ref<InputEvent> p_event) { +void ViewportRotationControl::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); const Ref<InputEventMouseButton> mb = p_event; @@ -252,10 +252,6 @@ void ViewportRotationControl::set_viewport(Node3DEditorViewport *p_viewport) { viewport = p_viewport; } -void ViewportRotationControl::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &ViewportRotationControl::_gui_input); -} - void Node3DEditorViewport::_update_camera(real_t p_interp_delta) { bool is_orthogonal = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL; @@ -690,53 +686,55 @@ void Node3DEditorViewport::_select_region() { Node3D *single_selected = spatial_editor->get_single_selected_node(); Node3DEditorSelectedItem *se = editor_selection->get_node_editor_data<Node3DEditorSelectedItem>(single_selected); - Ref<EditorNode3DGizmo> old_gizmo; - if (!clicked_wants_append) { - se->subgizmos.clear(); - old_gizmo = se->gizmo; - se->gizmo.unref(); - } - - bool found_subgizmos = false; - Vector<Ref<Node3DGizmo>> gizmos = single_selected->get_gizmos(); - for (int j = 0; j < gizmos.size(); j++) { - Ref<EditorNode3DGizmo> seg = gizmos[j]; - if (!seg.is_valid()) { - continue; + if (se) { + Ref<EditorNode3DGizmo> old_gizmo; + if (!clicked_wants_append) { + se->subgizmos.clear(); + old_gizmo = se->gizmo; + se->gizmo.unref(); } - if (se->gizmo.is_valid() && se->gizmo != seg) { - continue; - } + bool found_subgizmos = false; + Vector<Ref<Node3DGizmo>> gizmos = single_selected->get_gizmos(); + for (int j = 0; j < gizmos.size(); j++) { + Ref<EditorNode3DGizmo> seg = gizmos[j]; + if (!seg.is_valid()) { + continue; + } - Vector<int> subgizmos = seg->subgizmos_intersect_frustum(camera, frustum); - if (!subgizmos.is_empty()) { - se->gizmo = seg; - for (int i = 0; i < subgizmos.size(); i++) { - int subgizmo_id = subgizmos[i]; - if (!se->subgizmos.has(subgizmo_id)) { - se->subgizmos.insert(subgizmo_id, se->gizmo->get_subgizmo_transform(subgizmo_id)); + if (se->gizmo.is_valid() && se->gizmo != seg) { + continue; + } + + Vector<int> subgizmos = seg->subgizmos_intersect_frustum(camera, frustum); + if (!subgizmos.is_empty()) { + se->gizmo = seg; + for (int i = 0; i < subgizmos.size(); i++) { + int subgizmo_id = subgizmos[i]; + if (!se->subgizmos.has(subgizmo_id)) { + se->subgizmos.insert(subgizmo_id, se->gizmo->get_subgizmo_transform(subgizmo_id)); + } } + found_subgizmos = true; + break; } - found_subgizmos = true; - break; } - } - if (!clicked_wants_append || found_subgizmos) { - if (se->gizmo.is_valid()) { - se->gizmo->redraw(); - } + if (!clicked_wants_append || found_subgizmos) { + if (se->gizmo.is_valid()) { + se->gizmo->redraw(); + } - if (old_gizmo != se->gizmo && old_gizmo.is_valid()) { - old_gizmo->redraw(); - } + if (old_gizmo != se->gizmo && old_gizmo.is_valid()) { + old_gizmo->redraw(); + } - spatial_editor->update_transform_gizmo(); - } + spatial_editor->update_transform_gizmo(); + } - if (found_subgizmos) { - return; + if (found_subgizmos) { + return; + } } } @@ -809,18 +807,66 @@ void Node3DEditorViewport::_select_region() { } void Node3DEditorViewport::_update_name() { - String view_mode = orthogonal ? TTR("Orthogonal") : TTR("Perspective"); + String name; - if (auto_orthogonal) { - view_mode += " [auto]"; + switch (view_type) { + case VIEW_TYPE_USER: { + if (orthogonal) { + name = TTR("Orthogonal"); + } else { + name = TTR("Perspective"); + } + } break; + case VIEW_TYPE_TOP: { + if (orthogonal) { + name = TTR("Top Orthogonal"); + } else { + name = TTR("Top Perspective"); + } + } break; + case VIEW_TYPE_BOTTOM: { + if (orthogonal) { + name = TTR("Bottom Orthogonal"); + } else { + name = TTR("Bottom Perspective"); + } + } break; + case VIEW_TYPE_LEFT: { + if (orthogonal) { + name = TTR("Left Orthogonal"); + } else { + name = TTR("Right Perspective"); + } + } break; + case VIEW_TYPE_RIGHT: { + if (orthogonal) { + name = TTR("Right Orthogonal"); + } else { + name = TTR("Right Perspective"); + } + } break; + case VIEW_TYPE_FRONT: { + if (orthogonal) { + name = TTR("Front Orthogonal"); + } else { + name = TTR("Front Perspective"); + } + } break; + case VIEW_TYPE_REAR: { + if (orthogonal) { + name = TTR("Rear Orthogonal"); + } else { + name = TTR("Rear Perspective"); + } + } break; } - if (name != "") { - view_menu->set_text(name + " " + view_mode); - } else { - view_menu->set_text(view_mode); + if (auto_orthogonal) { + // TRANSLATORS: This will be appended to the view name when Auto Orthogonal is enabled. + name += TTR(" [auto]"); } + view_menu->set_text(name); view_menu->set_size(Vector2(0, 0)); // resets the button size } @@ -1384,7 +1430,7 @@ void Node3DEditorViewport::_sinput(const Ref<InputEvent> &p_event) { case TRANSFORM_VIEW: { _edit.plane = TRANSFORM_X_AXIS; set_message(TTR("X-Axis Transform."), 2); - name = ""; + view_type = VIEW_TYPE_USER; _update_name(); } break; case TRANSFORM_X_AXIS: { @@ -2325,7 +2371,7 @@ void Node3DEditorViewport::_nav_orbit(Ref<InputEventWithModifiers> p_event, cons } else { cursor.y_rot += p_relative.x * radians_per_pixel; } - name = ""; + view_type = VIEW_TYPE_USER; _update_name(); } @@ -2363,7 +2409,7 @@ void Node3DEditorViewport::_nav_look(Ref<InputEventWithModifiers> p_event, const Vector3 diff = prev_pos - pos; cursor.pos += diff; - name = ""; + view_type = VIEW_TYPE_USER; _update_name(); } @@ -3008,7 +3054,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.y_rot = 0; cursor.x_rot = Math_PI / 2.0; set_message(TTR("Top View."), 2); - name = TTR("Top"); + view_type = VIEW_TYPE_TOP; _set_auto_orthogonal(); _update_name(); @@ -3017,7 +3063,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.y_rot = 0; cursor.x_rot = -Math_PI / 2.0; set_message(TTR("Bottom View."), 2); - name = TTR("Bottom"); + view_type = VIEW_TYPE_BOTTOM; _set_auto_orthogonal(); _update_name(); @@ -3026,7 +3072,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.x_rot = 0; cursor.y_rot = Math_PI / 2.0; set_message(TTR("Left View."), 2); - name = TTR("Left"); + view_type = VIEW_TYPE_LEFT; _set_auto_orthogonal(); _update_name(); @@ -3035,7 +3081,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.x_rot = 0; cursor.y_rot = -Math_PI / 2.0; set_message(TTR("Right View."), 2); - name = TTR("Right"); + view_type = VIEW_TYPE_RIGHT; _set_auto_orthogonal(); _update_name(); @@ -3044,7 +3090,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.x_rot = 0; cursor.y_rot = Math_PI; set_message(TTR("Front View."), 2); - name = TTR("Front"); + view_type = VIEW_TYPE_FRONT; _set_auto_orthogonal(); _update_name(); @@ -3053,7 +3099,7 @@ void Node3DEditorViewport::_menu_option(int p_option) { cursor.x_rot = 0; cursor.y_rot = 0; set_message(TTR("Rear View."), 2); - name = TTR("Rear"); + view_type = VIEW_TYPE_REAR; _set_auto_orthogonal(); _update_name(); @@ -3597,8 +3643,8 @@ void Node3DEditorViewport::set_state(const Dictionary &p_state) { _menu_option(VIEW_PERSPECTIVE); } } - if (p_state.has("view_name")) { - name = p_state["view_name"]; + if (p_state.has("view_type")) { + view_type = ViewType(p_state["view_type"].operator int()); _update_name(); } if (p_state.has("auto_orthogonal")) { @@ -3706,7 +3752,7 @@ Dictionary Node3DEditorViewport::get_state() const { d["distance"] = cursor.distance; d["use_environment"] = camera->get_environment().is_valid(); d["use_orthogonal"] = camera->get_projection() == Camera3D::PROJECTION_ORTHOGONAL; - d["view_name"] = name; + d["view_type"] = view_type; d["auto_orthogonal"] = auto_orthogonal; d["auto_orthogonal_enabled"] = view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_AUTO_ORTHOGONAL)); if (view_menu->get_popup()->is_item_checked(view_menu->get_popup()->get_item_index(VIEW_DISPLAY_NORMAL))) { @@ -3751,7 +3797,7 @@ void Node3DEditorViewport::reset() { message_time = 0; message = ""; last_message = ""; - name = ""; + view_type = VIEW_TYPE_USER; cursor = Cursor(); _update_name(); @@ -4030,7 +4076,7 @@ bool Node3DEditorViewport::can_drop_data_fw(const Point2 &p_point, const Variant continue; } memdelete(instantiated_scene); - } else if (type == "Mesh" || type == "ArrayMesh" || type == "PrimitiveMesh") { + } else if (ClassDB::is_parent_class(type, "Mesh")) { Ref<Mesh> mesh = ResourceLoader::load(files[i]); if (!mesh.is_valid()) { continue; @@ -4366,7 +4412,7 @@ Node3DEditorViewport::Node3DEditorViewport(Node3DEditor *p_spatial_editor, Edito viewport->set_as_audio_listener_3d(true); } - name = ""; + view_type = VIEW_TYPE_USER; _update_name(); EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &Node3DEditorViewport::update_transform_gizmo_view)); @@ -4378,7 +4424,7 @@ Node3DEditorViewport::~Node3DEditorViewport() { ////////////////////////////////////////////////////////////// -void Node3DEditorViewportContainer::_gui_input(const Ref<InputEvent> &p_event) { +void Node3DEditorViewportContainer::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseButton> mb = p_event; @@ -4670,10 +4716,6 @@ Node3DEditorViewportContainer::View Node3DEditorViewportContainer::get_view() { return view; } -void Node3DEditorViewportContainer::_bind_methods() { - ClassDB::bind_method("_gui_input", &Node3DEditorViewportContainer::_gui_input); -} - Node3DEditorViewportContainer::Node3DEditorViewportContainer() { set_clip_contents(true); view = VIEW_USE_1_VIEWPORT; @@ -4776,13 +4818,13 @@ void _update_all_gizmos(Node *p_node) { } void Node3DEditor::update_all_gizmos(Node *p_node) { + if (!p_node && get_tree()) { + p_node = get_tree()->get_edited_scene_root(); + } + if (!p_node) { - if (SceneTree::get_singleton()) { - p_node = SceneTree::get_singleton()->get_root(); - } else { - // No scene tree, so nothing to update. - return; - } + // No edited scene, so nothing to update. + return; } _update_all_gizmos(p_node); } @@ -5556,6 +5598,8 @@ void Node3DEditor::_init_indicators() { Ref<Shader> grid_shader = memnew(Shader); grid_shader->set_code(R"( +// 3D editor grid shader. + shader_type spatial; render_mode unshaded; @@ -5797,6 +5841,8 @@ void fragment() { Ref<Shader> rotate_shader = memnew(Shader); rotate_shader->set_code(R"( +// 3D editor rotation manipulator gizmo shader. + shader_type spatial; render_mode unshaded, depth_test_disabled; @@ -5845,6 +5891,8 @@ void fragment() { Ref<Shader> border_shader = memnew(Shader); border_shader->set_code(R"( +// 3D editor rotation manipulator gizmo shader (white outline). + shader_type spatial; render_mode unshaded, depth_test_disabled; @@ -6462,7 +6510,7 @@ void Node3DEditor::snap_selected_nodes_to_floor() { } } -void Node3DEditor::_unhandled_key_input(Ref<InputEvent> p_event) { +void Node3DEditor::unhandled_key_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (!is_visible_in_tree()) { @@ -6591,6 +6639,7 @@ void Node3DEditor::_notification(int p_what) { _register_all_gizmos(); _update_gizmos_menu(); _init_indicators(); + update_all_gizmos(); } break; case NOTIFICATION_EXIT_TREE: { _finish_indicators(); @@ -6839,7 +6888,6 @@ void Node3DEditor::_register_all_gizmos() { } void Node3DEditor::_bind_methods() { - ClassDB::bind_method("_unhandled_key_input", &Node3DEditor::_unhandled_key_input); ClassDB::bind_method("_get_editor_data", &Node3DEditor::_get_editor_data); ClassDB::bind_method("_request_gizmo", &Node3DEditor::_request_gizmo); ClassDB::bind_method("_clear_subgizmo_selection", &Node3DEditor::_clear_subgizmo_selection); @@ -7464,6 +7512,8 @@ Node3DEditor::Node3DEditor(EditorNode *p_editor) { sun_direction_shader.instantiate(); sun_direction_shader->set_code(R"( +// 3D editor Preview Sun direction shader. + shader_type canvas_item; uniform vec3 sun_direction; @@ -7724,7 +7774,6 @@ void Node3DEditor::add_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin) { gizmo_plugins_by_name.sort_custom<_GizmoPluginNameComparator>(); _update_gizmos_menu(); - Node3DEditor::get_singleton()->update_all_gizmos(); } void Node3DEditor::remove_gizmo_plugin(Ref<EditorNode3DGizmoPlugin> p_plugin) { diff --git a/editor/plugins/node_3d_editor_plugin.h b/editor/plugins/node_3d_editor_plugin.h index 094aa5662f..59f3ec6fcd 100644 --- a/editor/plugins/node_3d_editor_plugin.h +++ b/editor/plugins/node_3d_editor_plugin.h @@ -74,9 +74,8 @@ class ViewportRotationControl : public Control { const float AXIS_CIRCLE_RADIUS = 8.0f * EDSCALE; protected: - static void _bind_methods(); void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; void _draw(); void _draw_axis(const Axis2D &p_axis); void _get_sorted_axis(Vector<Axis2D> &r_axis); @@ -143,6 +142,16 @@ class Node3DEditorViewport : public Control { VIEW_MAX }; + enum ViewType { + VIEW_TYPE_USER, + VIEW_TYPE_TOP, + VIEW_TYPE_BOTTOM, + VIEW_TYPE_LEFT, + VIEW_TYPE_RIGHT, + VIEW_TYPE_FRONT, + VIEW_TYPE_REAR, + }; + public: enum { GIZMO_BASE_LAYER = 27, @@ -172,7 +181,7 @@ private: int gpu_time_history_index; int index; - String name; + ViewType view_type; void _menu_option(int p_option); void _set_auto_orthogonal(); Node3D *preview_node; @@ -460,11 +469,10 @@ private: Vector2 drag_begin_pos; Vector2 drag_begin_ratio; - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; protected: void _notification(int p_what); - static void _bind_methods(); public: void set_view(View p_view); @@ -522,7 +530,7 @@ private: bool grid_enable[3]; //should be always visible if true bool grid_enabled; bool grid_init_draw = false; - Camera3D::Projection grid_camera_last_update_perspective; + Camera3D::Projection grid_camera_last_update_perspective = Camera3D::PROJECTION_PERSPECTIVE; Vector3 grid_camera_last_update_position = Vector3(); Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[4], scale_gizmo[3], scale_plane_gizmo[3]; @@ -734,7 +742,7 @@ private: protected: void _notification(int p_what); //void _gui_input(InputEvent p_event); - void _unhandled_key_input(Ref<InputEvent> p_event); + virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; static void _bind_methods(); diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 8866e8c53e..119ecddf63 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -70,14 +70,14 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { return false; } - real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); Vector2 gpoint = mb->get_position(); - Vector2 cpoint = node->get_global_transform().affine_inverse().xform(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); + Vector2 cpoint = node->to_local(canvas_item_editor->snap_point(canvas_item_editor->get_canvas_transform().affine_inverse().xform(mb->get_position()))); if (mb->is_pressed() && action == ACTION_NONE) { Ref<Curve2D> curve = node->get_curve(); diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 9377395418..782152b002 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -1041,7 +1041,7 @@ void Polygon2DEditor::_uv_draw() { for (int i = 0; i < uvs.size(); i++) { int next = uv_draw_max > 0 ? (i + 1) % uv_draw_max : 0; - if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/poly_editor/show_previous_outline", true)) { + if (i < uv_draw_max && uv_drag && uv_move_current == UV_MODE_EDIT_POINT && EDITOR_DEF("editors/polygon_editor/show_previous_outline", true)) { uv_edit_draw->draw_line(mtx.xform(points_prev[i]), mtx.xform(points_prev[next]), prev_color, Math::round(EDSCALE)); } diff --git a/editor/plugins/resource_preloader_editor_plugin.cpp b/editor/plugins/resource_preloader_editor_plugin.cpp index cbea2405b8..eae6916a92 100644 --- a/editor/plugins/resource_preloader_editor_plugin.cpp +++ b/editor/plugins/resource_preloader_editor_plugin.cpp @@ -35,9 +35,6 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" -void ResourcePreloaderEditor::_gui_input(Ref<InputEvent> p_event) { -} - void ResourcePreloaderEditor::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { load->set_icon(get_theme_icon(SNAME("Folder"), SNAME("EditorIcons"))); @@ -335,7 +332,6 @@ void ResourcePreloaderEditor::drop_data_fw(const Point2 &p_point, const Variant } void ResourcePreloaderEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &ResourcePreloaderEditor::_gui_input); ClassDB::bind_method(D_METHOD("_update_library"), &ResourcePreloaderEditor::_update_library); ClassDB::bind_method(D_METHOD("_remove_resource", "to_remove"), &ResourcePreloaderEditor::_remove_resource); diff --git a/editor/plugins/resource_preloader_editor_plugin.h b/editor/plugins/resource_preloader_editor_plugin.h index bc10b48a16..04ab458eb5 100644 --- a/editor/plugins/resource_preloader_editor_plugin.h +++ b/editor/plugins/resource_preloader_editor_plugin.h @@ -75,7 +75,7 @@ class ResourcePreloaderEditor : public PanelContainer { protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); + static void _bind_methods(); public: diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index ff8582133b..7ef5993ec5 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -55,17 +55,17 @@ /*** SYNTAX HIGHLIGHTER ****/ String EditorSyntaxHighlighter::_get_name() const { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_get_name")) { - return si->call("_get_name"); + String ret; + if (GDVIRTUAL_CALL(_get_name, ret)) { + return ret; } return "Unnamed"; } Array EditorSyntaxHighlighter::_get_supported_languages() const { - ScriptInstance *si = get_script_instance(); - if (si && si->has_method("_get_supported_languages")) { - return si->call("_get_supported_languages"); + Array ret; + if (GDVIRTUAL_CALL(_get_supported_languages, ret)) { + return ret; } return Array(); } @@ -82,9 +82,8 @@ Ref<EditorSyntaxHighlighter> EditorSyntaxHighlighter::_create() const { void EditorSyntaxHighlighter::_bind_methods() { ClassDB::bind_method(D_METHOD("_get_edited_resource"), &EditorSyntaxHighlighter::_get_edited_resource); - BIND_VMETHOD(MethodInfo(Variant::STRING, "_get_name")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_languages")); - BIND_VMETHOD(MethodInfo(Variant::ARRAY, "_get_supported_extentions")); + GDVIRTUAL_BIND(_get_name) + GDVIRTUAL_BIND(_get_supported_languages) } //// @@ -95,25 +94,21 @@ void EditorStandardSyntaxHighlighter::_update_cache() { highlighter->clear_member_keyword_colors(); highlighter->clear_color_regions(); - highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color")); - highlighter->set_function_color(EDITOR_GET("text_editor/highlighting/function_color")); - highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color")); - highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color")); + highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color")); + highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color")); + highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color")); + highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color")); /* Engine types. */ - const Color type_color = EDITOR_GET("text_editor/highlighting/engine_type_color"); + const Color type_color = EDITOR_GET("text_editor/theme/highlighting/engine_type_color"); List<StringName> types; ClassDB::get_class_list(&types); for (const StringName &E : types) { - String n = E; - if (n.begins_with("_")) { - n = n.substr(1, n.length()); - } - highlighter->add_keyword_color(n, type_color); + highlighter->add_keyword_color(E, type_color); } /* User types. */ - const Color usertype_color = EDITOR_GET("text_editor/highlighting/user_type_color"); + const Color usertype_color = EDITOR_GET("text_editor/theme/highlighting/user_type_color"); List<StringName> global_classes; ScriptServer::get_global_class_list(&global_classes); for (const StringName &E : global_classes) { @@ -121,9 +116,9 @@ void EditorStandardSyntaxHighlighter::_update_cache() { } /* Autoloads. */ - Map<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); - for (Map<StringName, ProjectSettings::AutoloadInfo>::Element *E = autoloads.front(); E; E = E->next()) { - const ProjectSettings::AutoloadInfo &info = E->value(); + OrderedHashMap<StringName, ProjectSettings::AutoloadInfo> autoloads = ProjectSettings::get_singleton()->get_autoload_list(); + for (OrderedHashMap<StringName, ProjectSettings::AutoloadInfo>::Element E = autoloads.front(); E; E = E.next()) { + const ProjectSettings::AutoloadInfo &info = E.value(); if (info.is_singleton) { highlighter->add_keyword_color(info.name, usertype_color); } @@ -132,7 +127,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { const Ref<Script> script = _get_edited_resource(); if (script.is_valid()) { /* Core types. */ - const Color basetype_color = EDITOR_GET("text_editor/highlighting/base_type_color"); + const Color basetype_color = EDITOR_GET("text_editor/theme/highlighting/base_type_color"); List<String> core_types; script->get_language()->get_core_type_words(&core_types); for (const String &E : core_types) { @@ -140,8 +135,8 @@ void EditorStandardSyntaxHighlighter::_update_cache() { } /* Reserved words. */ - const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); - const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); + const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); + const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); List<String> keywords; script->get_language()->get_reserved_words(&keywords); for (const String &E : keywords) { @@ -153,7 +148,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { } /* Member types. */ - const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + const Color member_variable_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); StringName instance_base = script->get_instance_base_type(); if (instance_base != StringName()) { List<PropertyInfo> plist; @@ -177,7 +172,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { } /* Comments */ - const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); List<String> comments; script->get_language()->get_comment_delimiters(&comments); for (const String &comment : comments) { @@ -187,7 +182,7 @@ void EditorStandardSyntaxHighlighter::_update_cache() { } /* Strings */ - const Color string_color = EDITOR_GET("text_editor/highlighting/string_color"); + const Color string_color = EDITOR_GET("text_editor/theme/highlighting/string_color"); List<String> strings; script->get_language()->get_string_delimiters(&strings); for (const String &string : strings) { @@ -228,8 +223,6 @@ void ScriptEditorBase::_bind_methods() { // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); ADD_SIGNAL(MethodInfo("replace_in_files_requested", PropertyInfo(Variant::STRING, "text"))); - - BIND_VMETHOD(MethodInfo("_add_syntax_highlighter", PropertyInfo(Variant::OBJECT, "highlighter"))); } static bool _is_built_in_script(Script *p_script) { @@ -324,7 +317,7 @@ void ScriptEditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { k->get_keycode() == KEY_DOWN || k->get_keycode() == KEY_PAGEUP || k->get_keycode() == KEY_PAGEDOWN)) { - search_options->call("_gui_input", k); + search_options->gui_input(k); search_box->accept_event(); } } @@ -966,7 +959,10 @@ void ScriptEditor::_res_saved_callback(const Ref<Resource> &p_res) { } _update_script_names(); + _trigger_live_script_reload(); +} +void ScriptEditor::_trigger_live_script_reload() { if (!pending_auto_reload && auto_reload_running_scripts) { call_deferred(SNAME("_live_auto_reload_running_scripts")); pending_auto_reload = true; @@ -985,7 +981,7 @@ bool ScriptEditor::_test_script_times_on_disk(RES p_for_script) { bool need_ask = false; bool need_reload = false; - bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false)); + bool use_autoreload = bool(EDITOR_DEF("text_editor/behavior/files/auto_reload_scripts_on_external_change", false)); for (int i = 0; i < tab_container->get_child_count(); i++) { ScriptEditorBase *se = Object::cast_to<ScriptEditorBase>(tab_container->get_child(i)); @@ -1736,7 +1732,7 @@ void ScriptEditor::_update_members_overview_visibility() { } void ScriptEditor::_toggle_members_overview_alpha_sort(bool p_alphabetic_sort) { - EditorSettings::get_singleton()->set("text_editor/tools/sort_members_outline_alphabetically", p_alphabetic_sort); + EditorSettings::get_singleton()->set("text_editor/script_list/sort_members_outline_alphabetically", p_alphabetic_sort); _update_members_overview(); } @@ -1749,7 +1745,7 @@ void ScriptEditor::_update_members_overview() { } Vector<String> functions = se->get_functions(); - if (EditorSettings::get_singleton()->get("text_editor/tools/sort_members_outline_alphabetically")) { + if (EditorSettings::get_singleton()->get("text_editor/script_list/sort_members_outline_alphabetically")) { functions.sort(); } @@ -2128,7 +2124,7 @@ bool ScriptEditor::edit(const RES &p_resource, int p_line, int p_col, bool p_gra const bool use_external_editor = EditorSettings::get_singleton()->get("text_editor/external/use_external_editor") || (script.is_valid() && script->get_language()->overrides_external_editor()); - const bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); + const bool open_dominant = EditorSettings::get_singleton()->get("text_editor/behavior/files/open_dominant_script_on_scene_change"); const bool should_open = (open_dominant && !use_external_editor) || !EditorNode::get_singleton()->is_changing_scene(); @@ -2493,9 +2489,9 @@ void ScriptEditor::_save_layout() { } void ScriptEditor::_editor_settings_changed() { - trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save"); - convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); - use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); + trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/behavior/files/trim_trailing_whitespace_on_save"); + convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/behavior/files/convert_indent_on_save"); + use_space_indentation = EditorSettings::get_singleton()->get("text_editor/behavior/indent/type"); members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/script_list/show_members_overview"); help_overview_enabled = EditorSettings::get_singleton()->get("text_editor/help/show_help_index"); @@ -2522,7 +2518,7 @@ void ScriptEditor::_editor_settings_changed() { _update_script_colors(); _update_script_names(); - ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true)); + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true)); } void ScriptEditor::_filesystem_changed() { @@ -2561,7 +2557,7 @@ void ScriptEditor::_update_autosave_timer() { return; } - float autosave_time = EditorSettings::get_singleton()->get("text_editor/files/autosave_interval_secs"); + float autosave_time = EditorSettings::get_singleton()->get("text_editor/behavior/files/autosave_interval_secs"); if (autosave_time > 0) { autosave_timer->set_wait_time(autosave_time); autosave_timer->start(); @@ -2756,7 +2752,7 @@ void ScriptEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Co } } -void ScriptEditor::_unhandled_key_input(const Ref<InputEvent> &p_event) { +void ScriptEditor::unhandled_key_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (!is_visible_in_tree() || !p_event->is_pressed() || p_event->is_echo()) { @@ -2851,7 +2847,7 @@ void ScriptEditor::_make_script_list_context_menu() { } void ScriptEditor::set_window_layout(Ref<ConfigFile> p_layout) { - if (!bool(EDITOR_DEF("text_editor/files/restore_scripts_on_load", true))) { + if (!bool(EDITOR_DEF("text_editor/behavior/files/restore_scripts_on_load", true))) { return; } @@ -3144,7 +3140,7 @@ void ScriptEditor::set_scene_root_script(Ref<Script> p_script) { const bool use_external_editor = EditorSettings::get_singleton()->get("text_editor/external/use_external_editor") || (p_script.is_valid() && p_script->get_language()->overrides_external_editor()); - const bool open_dominant = EditorSettings::get_singleton()->get("text_editor/files/open_dominant_script_on_scene_change"); + const bool open_dominant = EditorSettings::get_singleton()->get("text_editor/behavior/files/open_dominant_script_on_scene_change"); if (open_dominant && !use_external_editor && p_script.is_valid()) { edit(p_script); @@ -3300,7 +3296,7 @@ void ScriptEditor::_bind_methods() { ClassDB::bind_method("_update_script_connections", &ScriptEditor::_update_script_connections); ClassDB::bind_method("_help_class_open", &ScriptEditor::_help_class_open); ClassDB::bind_method("_live_auto_reload_running_scripts", &ScriptEditor::_live_auto_reload_running_scripts); - ClassDB::bind_method("_unhandled_key_input", &ScriptEditor::_unhandled_key_input); + ClassDB::bind_method("_update_members_overview", &ScriptEditor::_update_members_overview); ClassDB::bind_method("_update_recent_scripts", &ScriptEditor::_update_recent_scripts); @@ -3391,7 +3387,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { members_overview_alphabeta_sort_button->set_flat(true); members_overview_alphabeta_sort_button->set_tooltip(TTR("Toggle alphabetical sorting of the method list.")); members_overview_alphabeta_sort_button->set_toggle_mode(true); - members_overview_alphabeta_sort_button->set_pressed(EditorSettings::get_singleton()->get("text_editor/tools/sort_members_outline_alphabetically")); + members_overview_alphabeta_sort_button->set_pressed(EditorSettings::get_singleton()->get("text_editor/script_list/sort_members_outline_alphabetically")); members_overview_alphabeta_sort_button->connect("toggled", callable_mp(this, &ScriptEditor::_toggle_members_overview_alpha_sort)); buttons_hbox->add_child(members_overview_alphabeta_sort_button); @@ -3433,8 +3429,8 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { ED_SHORTCUT("script_editor/window_sort", TTR("Sort")); ED_SHORTCUT("script_editor/window_move_up", TTR("Move Up"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_UP); ED_SHORTCUT("script_editor/window_move_down", TTR("Move Down"), KEY_MASK_SHIFT | KEY_MASK_ALT | KEY_DOWN); - ED_SHORTCUT("script_editor/next_script", TTR("Next script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work - ED_SHORTCUT("script_editor/prev_script", TTR("Previous script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); + ED_SHORTCUT("script_editor/next_script", TTR("Next Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_PERIOD); // these should be KEY_GREATER and KEY_LESS but those don't work + ED_SHORTCUT("script_editor/prev_script", TTR("Previous Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_COMMA); set_process_unhandled_key_input(true); file_menu = memnew(MenuButton); @@ -3630,9 +3626,9 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { history_pos = -1; edit_pass = 0; - trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/files/trim_trailing_whitespace_on_save"); - convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/indent/convert_indent_on_save"); - use_space_indentation = EditorSettings::get_singleton()->get("text_editor/indent/type"); + trim_trailing_whitespace_on_save = EditorSettings::get_singleton()->get("text_editor/behavior/files/trim_trailing_whitespace_on_save"); + convert_indent_on_save = EditorSettings::get_singleton()->get("text_editor/behavior/files/convert_indent_on_save"); + use_space_indentation = EditorSettings::get_singleton()->get("text_editor/behavior/indent/type"); ScriptServer::edit_request_func = _open_script_request; @@ -3729,9 +3725,9 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { script_editor->hide(); - EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", true); - ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/files/auto_reload_and_parse_scripts_on_save", true)); - EDITOR_DEF("text_editor/files/open_dominant_script_on_scene_change", true); + EDITOR_DEF("text_editor/behavior/files/auto_reload_scripts_on_external_change", true); + ScriptServer::set_reload_scripts_on_save(EDITOR_DEF("text_editor/behavior/files/auto_reload_and_parse_scripts_on_save", true)); + EDITOR_DEF("text_editor/behavior/files/open_dominant_script_on_scene_change", true); EDITOR_DEF("text_editor/external/use_external_editor", false); EDITOR_DEF("text_editor/external/exec_path", ""); EDITOR_DEF("text_editor/script_list/script_temperature_enabled", true); diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 209a96cbe6..e2420b4623 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -56,6 +56,9 @@ private: protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _get_name) + GDVIRTUAL0RC(Array, _get_supported_languages) + public: virtual String _get_name() const; virtual Array _get_supported_languages() const; @@ -74,7 +77,7 @@ private: public: virtual void _update_cache() override; - virtual Dictionary _get_line_syntax_highlighting(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } + virtual Dictionary _get_line_syntax_highlighting_impl(int p_line) override { return highlighter->get_line_syntax_highlighting(p_line); } virtual String _get_name() const override { return TTR("Standard"); } @@ -346,6 +349,7 @@ class ScriptEditor : public PanelContainer { bool pending_auto_reload; bool auto_reload_running_scripts; + void _trigger_live_script_reload(); void _live_auto_reload_running_scripts(); void _update_selected_editor_menu(); @@ -411,7 +415,7 @@ class ScriptEditor : public PanelContainer { bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); - void _unhandled_key_input(const Ref<InputEvent> &p_event); + virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; void _script_list_gui_input(const Ref<InputEvent> &ev); void _make_script_list_context_menu(); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index f7ad52da79..c44760807f 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -166,8 +166,8 @@ void ScriptTextEditor::enable_editor() { void ScriptTextEditor::_load_theme_settings() { CodeEdit *text_edit = code_editor->get_text_editor(); - Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color"); - Color updated_safe_line_number_color = EDITOR_GET("text_editor/highlighting/safe_line_number_color"); + Color updated_marked_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color"); + Color updated_safe_line_number_color = EDITOR_GET("text_editor/theme/highlighting/safe_line_number_color"); bool safe_line_number_color_updated = updated_safe_line_number_color != safe_line_number_color; bool marked_line_color_updated = updated_marked_line_color != marked_line_color; @@ -294,7 +294,7 @@ bool ScriptTextEditor::show_members_overview() { } void ScriptTextEditor::update_settings() { - code_editor->get_text_editor()->set_gutter_draw(connection_gutter, EditorSettings::get_singleton()->get("text_editor/appearance/show_info_gutter")); + code_editor->get_text_editor()->set_gutter_draw(connection_gutter, EditorSettings::get_singleton()->get("text_editor/appearance/gutters/show_info_gutter")); code_editor->update_editor_settings(); } @@ -506,7 +506,7 @@ void ScriptTextEditor::_validate_script() { } errors_panel->pop(); // Table - bool highlight_safe = EDITOR_DEF("text_editor/highlighting/highlight_type_safe_lines", true); + bool highlight_safe = EDITOR_DEF("text_editor/appearance/gutters/highlight_type_safe_lines", true); bool last_is_safe = false; for (int i = 0; i < te->get_line_count(); i++) { if (errors.is_empty()) { @@ -666,6 +666,8 @@ void ScriptEditor::_update_modified_scripts_for_external_editor(Ref<Script> p_fo script->set_source_code(rel_script->get_source_code()); script->set_last_modified_time(rel_script->get_last_modified_time()); script->update_exports(); + + _trigger_live_script_reload(); } } } @@ -756,8 +758,6 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c } else if (script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK) { _goto_line(p_row); - result.class_name = result.class_name.trim_prefix("_"); - switch (result.type) { case ScriptLanguage::LookupResult::RESULT_SCRIPT_LOCATION: { if (result.script.is_valid()) { @@ -831,7 +831,7 @@ void ScriptTextEditor::_lookup_symbol(const String &p_symbol, int p_row, int p_c if (info.is_singleton) { EditorNode::get_singleton()->load_scene(info.path); } - } else if (p_symbol.is_rel_path()) { + } else if (p_symbol.is_relative_path()) { // Every symbol other than absolute path is relative path so keep this condition at last. String path = _get_absolute_path(p_symbol); if (FileAccess::exists(path)) { @@ -858,7 +858,7 @@ void ScriptTextEditor::_validate_symbol(const String &p_symbol) { ScriptLanguage::LookupResult result; if (ScriptServer::is_global_class(p_symbol) || p_symbol.is_resource_file() || script->get_language()->lookup_code(code_editor->get_text_editor()->get_text_for_symbol_lookup(), p_symbol, script->get_path(), base, result) == OK || (ProjectSettings::get_singleton()->has_autoload(p_symbol) && ProjectSettings::get_singleton()->get_autoload(p_symbol).is_singleton)) { text_edit->set_symbol_lookup_word_as_valid(true); - } else if (p_symbol.is_rel_path()) { + } else if (p_symbol.is_relative_path()) { String path = _get_absolute_path(p_symbol); if (FileAccess::exists(path)) { text_edit->set_symbol_lookup_word_as_valid(true); @@ -1398,6 +1398,7 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_ if (d.has("type") && (String(d["type"]) == "resource" || String(d["type"]) == "files" || String(d["type"]) == "nodes" || + String(d["type"]) == "obj_property" || String(d["type"]) == "files_and_dirs")) { return true; } @@ -1427,10 +1428,11 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const } void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { + const String quote_style = EDITOR_GET("text_editor/completion/use_single_quotes") ? "'" : "\""; + Dictionary d = p_data; CodeEdit *te = code_editor->get_text_editor(); - Point2i pos = te->get_line_column_at_pos(p_point); int row = pos.y; int col = pos.x; @@ -1452,7 +1454,6 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } if (d.has("type") && (String(d["type"]) == "files" || String(d["type"]) == "files_and_dirs")) { - const String quote_style = EDITOR_DEF("text_editor/completion/use_single_quotes", false) ? "'" : "\""; Array files = d["files"]; String text_to_drop; @@ -1496,13 +1497,21 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data } String path = sn->get_path_to(node); - text_to_drop += "\"" + path.c_escape() + "\""; + text_to_drop += path.c_escape().quote(quote_style); } te->set_caret_line(row); te->set_caret_column(col); te->insert_text_at_caret(text_to_drop); } + + if (d.has("type") && String(d["type"]) == "obj_property") { + const String text_to_drop = String(d["property"]).c_escape().quote(quote_style); + + te->set_caret_line(row); + te->set_caret_column(col); + te->insert_text_at_caret(text_to_drop); + } } void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { @@ -1526,7 +1535,7 @@ void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int row = pos.y; int col = pos.x; - tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/move_caret_on_right_click")); if (tx->is_move_caret_on_right_click_enabled()) { if (tx->has_selection()) { int from_line = tx->get_selection_from_line(); @@ -1627,6 +1636,13 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { code_editor->get_text_editor()->update(); } +void ScriptTextEditor::_prepare_edit_menu() { + const CodeEdit *tx = code_editor->get_text_editor(); + PopupMenu *popup = edit_menu->get_popup(); + popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo()); + popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo()); +} + void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos) { context_menu->clear(); context_menu->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO); @@ -1666,6 +1682,10 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p } } + const CodeEdit *tx = code_editor->get_text_editor(); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo()); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo()); + context_menu->set_position(get_global_transform().xform(p_pos)); context_menu->set_size(Vector2(1, 1)); context_menu->popup(); @@ -1751,6 +1771,7 @@ void ScriptTextEditor::_enable_code_editor() { search_menu->get_popup()->connect("id_pressed", callable_mp(this, &ScriptTextEditor::_edit_option)); edit_hb->add_child(edit_menu); + edit_menu->connect("about_to_popup", callable_mp(this, &ScriptTextEditor::_prepare_edit_menu)); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_redo"), EDIT_REDO); edit_menu->get_popup()->add_separator(); diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 030d34acd4..4208d67f17 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -178,6 +178,7 @@ protected: void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition, Vector2 p_pos); void _text_edit_gui_input(const Ref<InputEvent> &ev); void _color_changed(const Color &p_color); + void _prepare_edit_menu(); void _goto_line(int p_line) { goto_line(p_line); } void _lookup_symbol(const String &p_symbol, int p_row, int p_column); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 29436e32b2..22ca5592bd 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -96,7 +96,7 @@ void ShaderTextEditor::set_warnings_panel(RichTextLabel *p_warnings_panel) { void ShaderTextEditor::_load_theme_settings() { CodeEdit *text_editor = get_text_editor(); - Color updated_marked_line_color = EDITOR_GET("text_editor/highlighting/mark_color"); + Color updated_marked_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color"); if (updated_marked_line_color != marked_line_color) { for (int i = 0; i < text_editor->get_line_count(); i++) { if (text_editor->get_line_background_color(i) == marked_line_color) { @@ -106,17 +106,17 @@ void ShaderTextEditor::_load_theme_settings() { marked_line_color = updated_marked_line_color; } - syntax_highlighter->set_number_color(EDITOR_GET("text_editor/highlighting/number_color")); - syntax_highlighter->set_symbol_color(EDITOR_GET("text_editor/highlighting/symbol_color")); - syntax_highlighter->set_function_color(EDITOR_GET("text_editor/highlighting/function_color")); - syntax_highlighter->set_member_variable_color(EDITOR_GET("text_editor/highlighting/member_variable_color")); + syntax_highlighter->set_number_color(EDITOR_GET("text_editor/theme/highlighting/number_color")); + syntax_highlighter->set_symbol_color(EDITOR_GET("text_editor/theme/highlighting/symbol_color")); + syntax_highlighter->set_function_color(EDITOR_GET("text_editor/theme/highlighting/function_color")); + syntax_highlighter->set_member_variable_color(EDITOR_GET("text_editor/theme/highlighting/member_variable_color")); syntax_highlighter->clear_keyword_colors(); List<String> keywords; ShaderLanguage::get_keyword_list(&keywords); - const Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); - const Color control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); + const Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); + const Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); for (const String &E : keywords) { if (ShaderLanguage::is_control_flow_keyword(E)) { @@ -142,14 +142,14 @@ void ShaderTextEditor::_load_theme_settings() { } } - const Color member_variable_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + const Color member_variable_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); for (const String &E : built_ins) { syntax_highlighter->add_keyword_color(E, member_variable_color); } // Colorize comments. - const Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + const Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); syntax_highlighter->clear_color_regions(); syntax_highlighter->add_color_region("/*", "*/", comment_color, false); syntax_highlighter->add_color_region("//", "", comment_color, true); @@ -397,7 +397,7 @@ void ShaderEditor::_notification(int p_what) { void ShaderEditor::_editor_settings_changed() { shader_editor->update_editor_settings(); - shader_editor->get_text_editor()->add_theme_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing")); + shader_editor->get_text_editor()->add_theme_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/appearance/whitespace/line_spacing")); shader_editor->get_text_editor()->set_draw_breakpoints_gutter(false); shader_editor->get_text_editor()->set_draw_executing_lines_gutter(false); } @@ -483,7 +483,7 @@ void ShaderEditor::_check_for_external_edit() { return; } - bool use_autoreload = bool(EDITOR_DEF("text_editor/files/auto_reload_scripts_on_external_change", false)); + bool use_autoreload = bool(EDITOR_DEF("text_editor/behavior/files/auto_reload_scripts_on_external_change", false)); if (shader->get_last_modified_time() != FileAccess::get_modified_time(shader->get_path())) { if (use_autoreload) { _reload_shader_from_disk(); @@ -555,7 +555,7 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { Point2i pos = tx->get_line_column_at_pos(mb->get_global_position() - tx->get_global_position()); int row = pos.y; int col = pos.x; - tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/move_caret_on_right_click")); if (tx->is_move_caret_on_right_click_enabled()) { if (tx->has_selection()) { diff --git a/editor/plugins/skeleton_3d_editor_plugin.cpp b/editor/plugins/skeleton_3d_editor_plugin.cpp index 0bb0bfde6f..309821b3dc 100644 --- a/editor/plugins/skeleton_3d_editor_plugin.cpp +++ b/editor/plugins/skeleton_3d_editor_plugin.cpp @@ -551,22 +551,30 @@ void Skeleton3DEditor::update_joint_tree() { items.insert(-1, root); - const Vector<int> &joint_porder = skeleton->get_bone_process_orders(); Ref<Texture> bone_icon = get_theme_icon(SNAME("BoneAttachment3D"), SNAME("EditorIcons")); - for (int i = 0; i < joint_porder.size(); ++i) { - const int b_idx = joint_porder[i]; + Vector<int> bones_to_process = skeleton->get_parentless_bones(); + while (bones_to_process.size() > 0) { + int current_bone_idx = bones_to_process[0]; + bones_to_process.erase(current_bone_idx); - const int p_idx = skeleton->get_bone_parent(b_idx); - TreeItem *p_item = items.find(p_idx)->get(); + const int parent_idx = skeleton->get_bone_parent(current_bone_idx); + TreeItem *parent_item = items.find(parent_idx)->get(); - TreeItem *joint_item = joint_tree->create_item(p_item); - items.insert(b_idx, joint_item); + TreeItem *joint_item = joint_tree->create_item(parent_item); + items.insert(current_bone_idx, joint_item); - joint_item->set_text(0, skeleton->get_bone_name(b_idx)); + joint_item->set_text(0, skeleton->get_bone_name(current_bone_idx)); joint_item->set_icon(0, bone_icon); joint_item->set_selectable(0, true); - joint_item->set_metadata(0, "bones/" + itos(b_idx)); + joint_item->set_metadata(0, "bones/" + itos(current_bone_idx)); + + // Add the bone's children to the list of bones to be processed + Vector<int> current_bone_child_bones = skeleton->get_bone_children(current_bone_idx); + int child_bone_size = current_bone_child_bones.size(); + for (int i = 0; i < child_bone_size; i++) { + bones_to_process.push_back(current_bone_child_bones[i]); + } } } diff --git a/editor/plugins/sprite_frames_editor_plugin.cpp b/editor/plugins/sprite_frames_editor_plugin.cpp index 42f7d23da2..400f9f560f 100644 --- a/editor/plugins/sprite_frames_editor_plugin.cpp +++ b/editor/plugins/sprite_frames_editor_plugin.cpp @@ -40,7 +40,7 @@ #include "scene/gui/margin_container.h" #include "scene/gui/panel_container.h" -void SpriteFramesEditor::_gui_input(Ref<InputEvent> p_event) { +void SpriteFramesEditor::gui_input(const Ref<InputEvent> &p_event) { } void SpriteFramesEditor::_open_sprite_sheet() { @@ -200,34 +200,36 @@ void SpriteFramesEditor::_sheet_scroll_input(const Ref<InputEvent> &p_event) { void SpriteFramesEditor::_sheet_add_frames() { Size2i size = split_sheet_preview->get_texture()->get_size(); - int h = split_sheet_h->get_value(); - int v = split_sheet_v->get_value(); + int frame_count_x = split_sheet_h->get_value(); + int frame_count_y = split_sheet_v->get_value(); + Size2 frame_size(size.width / frame_count_x, size.height / frame_count_y); undo_redo->create_action(TTR("Add Frame")); int fc = frames->get_frame_count(edited_anim); - AtlasTexture *atlas_source = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture()); - - Rect2 region_rect = Rect2(); + Point2 src_origin; + Rect2 src_region(Point2(), size); - if (atlas_source && atlas_source->get_atlas().is_valid()) { - region_rect = atlas_source->get_region(); + AtlasTexture *src_atlas = Object::cast_to<AtlasTexture>(*split_sheet_preview->get_texture()); + if (src_atlas && src_atlas->get_atlas().is_valid()) { + src_origin = src_atlas->get_region().position - src_atlas->get_margin().position; + src_region = src_atlas->get_region(); } for (Set<int>::Element *E = frames_selected.front(); E; E = E->next()) { int idx = E->get(); - int width = size.width / h; - int height = size.height / v; - int xp = idx % h; - int yp = (idx - xp) / h; - int x = (xp * width) + region_rect.position.x; - int y = (yp * height) + region_rect.position.y; + Point2 frame_coords(idx % frame_count_x, idx / frame_count_x); + + Rect2 frame(frame_coords * frame_size + src_origin, frame_size); + Rect2 region = frame.intersection(src_region); + Rect2 margin(region == Rect2() ? Point2() : region.position - frame.position, frame.size - region.size); Ref<AtlasTexture> at; at.instantiate(); at->set_atlas(split_sheet_preview->get_texture()); - at->set_region(Rect2(x, y, width, height)); + at->set_region(region); + at->set_margin(margin); undo_redo->add_do_method(frames, "add_frame", edited_anim, at, -1); undo_redo->add_undo_method(frames, "remove_frame", edited_anim, fc); diff --git a/editor/plugins/sprite_frames_editor_plugin.h b/editor/plugins/sprite_frames_editor_plugin.h index e6c59e3533..17e30f0cab 100644 --- a/editor/plugins/sprite_frames_editor_plugin.h +++ b/editor/plugins/sprite_frames_editor_plugin.h @@ -147,7 +147,7 @@ class SpriteFramesEditor : public HSplitContainer { protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; static void _bind_methods(); public: diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index cfccf90499..32bcc1a4e6 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -433,7 +433,7 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int row = pos.y; int col = pos.x; - tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + tx->set_move_caret_on_right_click_enabled(EditorSettings::get_singleton()->get("text_editor/behavior/navigation/move_caret_on_right_click")); bool can_fold = tx->can_fold_line(row); bool is_folded = tx->is_line_folded(row); @@ -471,6 +471,13 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } } +void TextEditor::_prepare_edit_menu() { + const CodeEdit *tx = code_editor->get_text_editor(); + PopupMenu *popup = edit_menu->get_popup(); + popup->set_item_disabled(popup->get_item_index(EDIT_UNDO), !tx->has_undo()); + popup->set_item_disabled(popup->get_item_index(EDIT_REDO), !tx->has_redo()); +} + void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position) { context_menu->clear(); if (p_selection) { @@ -497,6 +504,10 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); } + const CodeEdit *tx = code_editor->get_text_editor(); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_UNDO), !tx->has_undo()); + context_menu->set_item_disabled(context_menu->get_item_index(EDIT_REDO), !tx->has_redo()); + context_menu->set_position(get_global_transform().xform(p_position)); context_menu->set_size(Vector2(1, 1)); context_menu->popup(); @@ -542,6 +553,7 @@ TextEditor::TextEditor() { edit_hb->add_child(edit_menu); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); + edit_menu->connect("about_to_popup", callable_mp(this, &TextEditor::_prepare_edit_menu)); edit_menu->get_popup()->connect("id_pressed", callable_mp(this, &TextEditor::_edit_option)); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("ui_undo"), EDIT_UNDO); diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 18e30e2549..6bf0042393 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -92,6 +92,7 @@ protected: void _edit_option(int p_op); void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded, Vector2 p_position); void _text_edit_gui_input(const Ref<InputEvent> &ev); + void _prepare_edit_menu(); Map<String, Ref<EditorSyntaxHighlighter>> highlighters; void _change_syntax_highlighter(int p_idx); diff --git a/editor/plugins/texture_3d_editor_plugin.cpp b/editor/plugins/texture_3d_editor_plugin.cpp index 3987cdd6a0..bd1923f4ab 100644 --- a/editor/plugins/texture_3d_editor_plugin.cpp +++ b/editor/plugins/texture_3d_editor_plugin.cpp @@ -34,9 +34,6 @@ #include "core/io/resource_loader.h" #include "editor/editor_settings.h" -void Texture3DEditor::_gui_input(Ref<InputEvent> p_event) { -} - void Texture3DEditor::_texture_rect_draw() { texture_rect->draw_rect(Rect2(Point2(), texture_rect->get_size()), Color(1, 1, 1, 1)); } @@ -79,6 +76,8 @@ void Texture3DEditor::_update_material() { void Texture3DEditor::_make_shaders() { shader.instantiate(); shader->set_code(R"( +// Texture3DEditor preview shader. + shader_type canvas_item; uniform sampler3D tex; @@ -145,7 +144,6 @@ void Texture3DEditor::edit(Ref<Texture3D> p_texture) { } void Texture3DEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &Texture3DEditor::_gui_input); ClassDB::bind_method(D_METHOD("_layer_changed"), &Texture3DEditor::_layer_changed); } diff --git a/editor/plugins/texture_3d_editor_plugin.h b/editor/plugins/texture_3d_editor_plugin.h index 9d90d3653f..855194e644 100644 --- a/editor/plugins/texture_3d_editor_plugin.h +++ b/editor/plugins/texture_3d_editor_plugin.h @@ -65,7 +65,6 @@ class Texture3DEditor : public Control { protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); static void _bind_methods(); diff --git a/editor/plugins/texture_layered_editor_plugin.cpp b/editor/plugins/texture_layered_editor_plugin.cpp index 80359452ac..424e018a47 100644 --- a/editor/plugins/texture_layered_editor_plugin.cpp +++ b/editor/plugins/texture_layered_editor_plugin.cpp @@ -34,7 +34,7 @@ #include "core/io/resource_loader.h" #include "editor/editor_settings.h" -void TextureLayeredEditor::_gui_input(Ref<InputEvent> p_event) { +void TextureLayeredEditor::gui_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseMotion> mm = p_event; @@ -106,6 +106,8 @@ void TextureLayeredEditor::_update_material() { void TextureLayeredEditor::_make_shaders() { shaders[0].instantiate(); shaders[0]->set_code(R"( +// TextureLayeredEditor preview shader (2D array). + shader_type canvas_item; uniform sampler2DArray tex; @@ -118,6 +120,8 @@ void fragment() { shaders[1].instantiate(); shaders[1]->set_code(R"( +// TextureLayeredEditor preview shader (cubemap). + shader_type canvas_item; uniform samplerCube tex; @@ -132,6 +136,8 @@ void fragment() { shaders[2].instantiate(); shaders[2]->set_code(R"( +// TextureLayeredEditor preview shader (cubemap array). + shader_type canvas_item; uniform samplerCubeArray tex; @@ -214,7 +220,6 @@ void TextureLayeredEditor::edit(Ref<TextureLayered> p_texture) { } void TextureLayeredEditor::_bind_methods() { - ClassDB::bind_method(D_METHOD("_gui_input"), &TextureLayeredEditor::_gui_input); ClassDB::bind_method(D_METHOD("_layer_changed"), &TextureLayeredEditor::_layer_changed); } diff --git a/editor/plugins/texture_layered_editor_plugin.h b/editor/plugins/texture_layered_editor_plugin.h index c4ced62fb9..a7fe4b94e9 100644 --- a/editor/plugins/texture_layered_editor_plugin.h +++ b/editor/plugins/texture_layered_editor_plugin.h @@ -67,7 +67,7 @@ class TextureLayeredEditor : public Control { protected: void _notification(int p_what); - void _gui_input(Ref<InputEvent> p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; static void _bind_methods(); public: diff --git a/editor/plugins/tiles/tile_atlas_view.cpp b/editor/plugins/tiles/tile_atlas_view.cpp index 13f04cb804..0add83f64d 100644 --- a/editor/plugins/tiles/tile_atlas_view.cpp +++ b/editor/plugins/tiles/tile_atlas_view.cpp @@ -41,7 +41,7 @@ #include "editor/editor_scale.h" #include "editor/editor_settings.h" -void TileAtlasView::_gui_input(const Ref<InputEvent> &p_event) { +void TileAtlasView::gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { drag_type = DRAG_TYPE_NONE; @@ -548,8 +548,6 @@ void TileAtlasView::_notification(int p_what) { } void TileAtlasView::_bind_methods() { - ClassDB::bind_method("_gui_input", &TileAtlasView::_gui_input); - ADD_SIGNAL(MethodInfo("transform_changed", PropertyInfo(Variant::FLOAT, "zoom"), PropertyInfo(Variant::VECTOR2, "scroll"))); } @@ -582,7 +580,7 @@ TileAtlasView::TileAtlasView() { center_container = memnew(CenterContainer); center_container->set_mouse_filter(Control::MOUSE_FILTER_IGNORE); center_container->set_anchors_preset(Control::PRESET_CENTER); - center_container->connect("gui_input", callable_mp(this, &TileAtlasView::_gui_input)); + center_container->connect("gui_input", callable_mp(this, &TileAtlasView::gui_input)); panel->add_child(center_container); missing_source_label = memnew(Label); diff --git a/editor/plugins/tiles/tile_atlas_view.h b/editor/plugins/tiles/tile_atlas_view.h index b2046f4322..5b0df366ae 100644 --- a/editor/plugins/tiles/tile_atlas_view.h +++ b/editor/plugins/tiles/tile_atlas_view.h @@ -62,7 +62,7 @@ private: void _update_zoom_and_panning(bool p_zoom_on_mouse_pos = false); void _zoom_widget_changed(); void _center_view(); - void _gui_input(const Ref<InputEvent> &p_event); + virtual void gui_input(const Ref<InputEvent> &p_event) override; Map<Vector2, Map<int, Rect2i>> alternative_tiles_rect_cache; void _update_alternative_tiles_rect_cache(); diff --git a/editor/plugins/tiles/tile_data_editors.cpp b/editor/plugins/tiles/tile_data_editors.cpp index bab55df65a..d406c2514c 100644 --- a/editor/plugins/tiles/tile_data_editors.cpp +++ b/editor/plugins/tiles/tile_data_editors.cpp @@ -110,7 +110,7 @@ void DummyObject::clear_dummy_properties() { void GenericTilePolygonEditor::_base_control_draw() { ERR_FAIL_COND(!tile_set.is_valid()); - real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); Color grid_color = EditorSettings::get_singleton()->get("editors/tiles_editor/grid_color"); const Ref<Texture2D> handle = get_theme_icon(SNAME("EditorPathSharpHandle"), SNAME("EditorIcons")); @@ -262,7 +262,7 @@ void GenericTilePolygonEditor::_advanced_menu_item_pressed(int p_item_pressed) { } void GenericTilePolygonEditor::_grab_polygon_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_point_index) { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); r_polygon_index = -1; r_point_index = -1; float closest_distance = grab_threshold + 1.0; @@ -280,7 +280,7 @@ void GenericTilePolygonEditor::_grab_polygon_point(Vector2 p_pos, const Transfor } void GenericTilePolygonEditor::_grab_polygon_segment_point(Vector2 p_pos, const Transform2D &p_polygon_xform, int &r_polygon_index, int &r_segment_index, Vector2 &r_point) { - const real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + const real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); Point2 point = p_polygon_xform.affine_inverse().xform(p_pos); r_polygon_index = -1; @@ -340,7 +340,7 @@ void GenericTilePolygonEditor::_snap_to_half_pixel(Point2 &r_point) { } void GenericTilePolygonEditor::_base_control_gui_input(Ref<InputEvent> p_event) { - real_t grab_threshold = EDITOR_GET("editors/poly_editor/point_grab_radius"); + real_t grab_threshold = EDITOR_GET("editors/polygon_editor/point_grab_radius"); hovered_polygon_index = -1; hovered_point_index = -1; diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index d6ac238414..50808a25af 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -70,14 +70,15 @@ const int MAX_FLOAT_CONST_DEFS = sizeof(float_constant_defs) / sizeof(FloatConst /////////////////// 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_parent_resource, p_node); + Object *ret; + if (GDVIRTUAL_CALL(_create_editor, p_parent_resource, p_node, ret)) { + return Object::cast_to<Control>(ret); } return nullptr; } void VisualShaderNodePlugin::_bind_methods() { - 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"))); + GDVIRTUAL_BIND(_create_editor, "parent_resource", "visual_shader_node"); } /////////////////// @@ -110,7 +111,6 @@ void VisualShaderGraphPlugin::_bind_methods() { ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression); ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve); ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz); - ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant); } void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) { @@ -237,18 +237,6 @@ int VisualShaderGraphPlugin::get_constant_index(float p_constant) const { return 0; } -void VisualShaderGraphPlugin::update_constant(VisualShader::Type p_type, int p_node_id) { - if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].const_op) { - return; - } - VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(links[p_node_id].visual_node); - if (!float_const) { - return; - } - links[p_node_id].const_op->select(get_constant_index(float_const->get_constant())); - links[p_node_id].graph_node->set_size(Size2(-1, -1)); -} - void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) { if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) { return; @@ -267,10 +255,6 @@ void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p links[p_node_id].input_ports.insert(p_port_id, { p_button }); } -void VisualShaderGraphPlugin::register_constant_option_btn(int p_node_id, OptionButton *p_button) { - links[p_node_id].const_op = p_button; -} - void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) { links[p_node_id].expression_edit = p_expression_edit; } @@ -322,7 +306,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) { } void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) { - links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); + links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } }); } void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) { @@ -498,23 +482,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { custom_editor = hbox; } - Ref<VisualShaderNodeFloatConstant> float_const = vsnode; - if (float_const.is_valid()) { - HBoxContainer *hbox = memnew(HBoxContainer); - - hbox->add_child(custom_editor); - OptionButton *btn = memnew(OptionButton); - hbox->add_child(btn); - register_constant_option_btn(p_id, btn); - btn->add_item(""); - for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { - btn->add_item(float_constant_defs[i].name); - } - btn->select(get_constant_index(float_const->get_constant())); - btn->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_float_constant_selected), varray(p_id)); - custom_editor = hbox; - } - if (custom_editor && !vsnode->is_use_prop_slots() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) { //will be embedded in first port } else if (custom_editor) { @@ -893,15 +860,15 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { node->add_child(expression_box); register_expression_edit(p_id, expression_box); - 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 control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); - Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); - Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); - Color function_color = EDITOR_GET("text_editor/highlighting/function_color"); - Color number_color = EDITOR_GET("text_editor/highlighting/number_color"); - Color members_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color"); + Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color"); + Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); + Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); + Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); + Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color"); + Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color"); + Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color"); + Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); expression_box->set_syntax_highlighter(expression_syntax_highlighter); expression_box->add_theme_color_override("background_color", background_color); @@ -1253,8 +1220,88 @@ void VisualShaderEditor::_update_options_menu() { Vector<AddOption> custom_options; Vector<AddOption> embedded_options; + static Vector<String> type_filter_exceptions; + if (type_filter_exceptions.is_empty()) { + type_filter_exceptions.append("VisualShaderNodeExpression"); + } + for (int i = 0; i < add_options.size(); i++) { if (!use_filter || add_options[i].name.findn(filter) != -1) { + // port type filtering + if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX || members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { + Ref<VisualShaderNode> vsn; + int check_result = 0; + + if (!add_options[i].is_custom) { + vsn = Ref<VisualShaderNode>(Object::cast_to<VisualShaderNode>(ClassDB::instantiate(add_options[i].type))); + if (!vsn.is_valid()) { + continue; + } + + if (type_filter_exceptions.has(add_options[i].type)) { + check_result = 1; + } + + Ref<VisualShaderNodeInput> input = Object::cast_to<VisualShaderNodeInput>(vsn.ptr()); + if (input.is_valid()) { + input->set_shader_mode(visual_shader->get_mode()); + input->set_shader_type(visual_shader->get_shader_type()); + input->set_input_name(add_options[i].sub_func_str); + } + + Ref<VisualShaderNodeExpression> expression = Object::cast_to<VisualShaderNodeExpression>(vsn.ptr()); + if (expression.is_valid()) { + if (members_input_port_type == VisualShaderNode::PORT_TYPE_SAMPLER) { + check_result = -1; // expressions creates a port with required type automatically (except for sampler output) + } + } + + Ref<VisualShaderNodeUniformRef> uniform_ref = Object::cast_to<VisualShaderNodeUniformRef>(vsn.ptr()); + if (uniform_ref.is_valid()) { + check_result = -1; + + if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { + for (int j = 0; j < uniform_ref->get_uniforms_count(); j++) { + if (visual_shader->is_port_types_compatible(uniform_ref->get_port_type_by_index(j), members_input_port_type)) { + check_result = 1; + break; + } + } + } + } + } else { + check_result = 1; + } + + if (members_output_port_type != VisualShaderNode::PORT_TYPE_MAX) { + if (check_result == 0) { + for (int j = 0; j < vsn->get_input_port_count(); j++) { + if (visual_shader->is_port_types_compatible(vsn->get_input_port_type(j), members_output_port_type)) { + check_result = 1; + break; + } + } + } + + if (check_result != 1) { + continue; + } + } + if (members_input_port_type != VisualShaderNode::PORT_TYPE_MAX) { + if (check_result == 0) { + for (int j = 0; j < vsn->get_output_port_count(); j++) { + if (visual_shader->is_port_types_compatible(vsn->get_output_port_type(j), members_input_port_type)) { + check_result = 1; + break; + } + } + } + + if (check_result != 1) { + continue; + } + } + } if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) { continue; } @@ -2182,6 +2229,16 @@ void VisualShaderEditor::_setup_node(VisualShaderNode *p_node, int p_op_idx) { } } + // TRANSFORM_OP + { + VisualShaderNodeTransformOp *matOp = Object::cast_to<VisualShaderNodeTransformOp>(p_node); + + if (matOp) { + matOp->set_operator((VisualShaderNodeTransformOp::Operator)p_op_idx); + return; + } + } + // TRANSFORM_FUNC { VisualShaderNodeTransformFunc *matFunc = Object::cast_to<VisualShaderNodeTransformFunc>(p_node); @@ -2490,6 +2547,7 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx, String p_resource_pa } } } + _member_cancel(); VisualShaderNodeUniform *uniform = Object::cast_to<VisualShaderNodeUniform>(vsnode.ptr()); if (uniform) { @@ -2612,13 +2670,25 @@ void VisualShaderEditor::_disconnection_request(const String &p_from, int p_from void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position) { from_node = p_from.to_int(); from_slot = p_from_slot; - _show_members_dialog(true); + VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX; + VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX; + Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), from_node); + if (node.is_valid()) { + output_port_type = node->get_output_port_type(from_slot); + } + _show_members_dialog(true, input_port_type, output_port_type); } void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) { to_node = p_to.to_int(); to_slot = p_to_slot; - _show_members_dialog(true); + VisualShaderNode::PortType input_port_type = VisualShaderNode::PORT_TYPE_MAX; + VisualShaderNode::PortType output_port_type = VisualShaderNode::PORT_TYPE_MAX; + Ref<VisualShaderNode> node = visual_shader->get_node(get_current_shader_type(), to_node); + if (node.is_valid()) { + input_port_type = node->get_input_port_type(to_slot); + } + _show_members_dialog(true, input_port_type, output_port_type); } void VisualShaderEditor::_delete_nodes(int p_type, const List<int> &p_nodes) { @@ -2944,6 +3014,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { selected_constants.clear(); selected_uniforms.clear(); selected_comment = -1; + selected_float_constant = -1; List<int> to_change; for (int i = 0; i < graph->get_child_count(); i++) { @@ -2963,6 +3034,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (constant_node != nullptr) { selected_constants.insert(id); } + VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr()); + if (float_constant_node != nullptr) { + selected_float_constant = id; + } VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr()); if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) { selected_uniforms.insert(id); @@ -2973,6 +3048,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (to_change.size() > 1) { selected_comment = -1; + selected_float_constant = -1; } if (to_change.is_empty() && copy_nodes_buffer.is_empty()) { @@ -2987,6 +3063,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { if (temp != -1) { popup_menu->remove_item(temp); } + temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS); + if (temp != -1) { + popup_menu->remove_item(temp); + } temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS); if (temp != -1) { popup_menu->remove_item(temp); @@ -3008,14 +3088,23 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { popup_menu->remove_item(temp); } - if (selected_comment != -1) { + if (selected_constants.size() > 0 || selected_uniforms.size() > 0) { popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2); - popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE); - popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION); - } - if (selected_constants.size() > 0 || selected_uniforms.size() > 0) { - popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3); + if (selected_float_constant != -1) { + popup_menu->add_submenu_item(TTR("Float Constants"), "FloatConstants", int(NodeMenuOptions::FLOAT_CONSTANTS)); + + if (!constants_submenu) { + constants_submenu = memnew(PopupMenu); + constants_submenu->set_name("FloatConstants"); + + for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) { + constants_submenu->add_item(float_constant_defs[i].name, i); + } + popup_menu->add_child(constants_submenu); + constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected)); + } + } if (selected_constants.size() > 0) { popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS); @@ -3026,6 +3115,12 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } } + if (selected_comment != -1) { + popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3); + popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE); + popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION); + } + menu_point = graph->get_local_mouse_position(); Point2 gpos = Input::get_singleton()->get_mouse_position(); popup_menu->set_position(gpos); @@ -3035,7 +3130,13 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) { } } -void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos) { +void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) { + if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) { + members_input_port_type = p_input_port_type; + members_output_port_type = p_output_port_type; + _update_options_menu(); + } + if (at_mouse_pos) { saved_node_pos_dirty = true; saved_node_pos = graph->get_local_mouse_position(); @@ -3071,7 +3172,7 @@ void VisualShaderEditor::_sbox_input(const Ref<InputEvent> &p_ie) { ie->get_keycode() == KEY_DOWN || ie->get_keycode() == KEY_ENTER || ie->get_keycode() == KEY_KP_ENTER)) { - members->call("_gui_input", ie); + members->gui_input(ie); node_filter->accept_event(); } } @@ -3111,15 +3212,15 @@ void VisualShaderEditor::_notification(int p_what) { preview_shader->set_icon(Control::get_theme_icon(SNAME("Shader"), SNAME("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 control_flow_keyword_color = EDITOR_GET("text_editor/highlighting/control_flow_keyword_color"); - Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); - Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); - Color function_color = EDITOR_GET("text_editor/highlighting/function_color"); - Color number_color = EDITOR_GET("text_editor/highlighting/number_color"); - Color members_color = EDITOR_GET("text_editor/highlighting/member_variable_color"); + Color background_color = EDITOR_GET("text_editor/theme/highlighting/background_color"); + Color text_color = EDITOR_GET("text_editor/theme/highlighting/text_color"); + Color keyword_color = EDITOR_GET("text_editor/theme/highlighting/keyword_color"); + Color control_flow_keyword_color = EDITOR_GET("text_editor/theme/highlighting/control_flow_keyword_color"); + Color comment_color = EDITOR_GET("text_editor/theme/highlighting/comment_color"); + Color symbol_color = EDITOR_GET("text_editor/theme/highlighting/symbol_color"); + Color function_color = EDITOR_GET("text_editor/theme/highlighting/function_color"); + Color number_color = EDITOR_GET("text_editor/theme/highlighting/number_color"); + Color members_color = EDITOR_GET("text_editor/theme/highlighting/member_variable_color"); preview_text->add_theme_color_override("background_color", background_color); @@ -3495,27 +3596,20 @@ void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_ undo_redo->commit_action(); } -void VisualShaderEditor::_float_constant_selected(int p_index, int p_node) { - if (p_index == 0) { - graph_plugin->update_node_size(p_node); - return; - } - - --p_index; - - ERR_FAIL_INDEX(p_index, MAX_FLOAT_CONST_DEFS); +void VisualShaderEditor::_float_constant_selected(int p_which) { + ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS); VisualShader::Type type = get_current_shader_type(); - Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, p_node); - if (!node.is_valid()) { - return; + Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant); + ERR_FAIL_COND(!node.is_valid()); + + if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) { + return; // same } - undo_redo->create_action(TTR("Set constant")); - undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_index].value); + undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name)); + undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value); undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant()); - undo_redo->add_do_method(graph_plugin.ptr(), "update_constant", type, p_node); - undo_redo->add_undo_method(graph_plugin.ptr(), "update_constant", type, p_node); undo_redo->commit_action(); } @@ -3792,7 +3886,7 @@ void VisualShaderEditor::_update_preview() { preview_text->set_line_background_color(i, Color(0, 0, 0, 0)); } if (err != OK) { - Color error_line_color = EDITOR_GET("text_editor/highlighting/mark_color"); + Color error_line_color = EDITOR_GET("text_editor/theme/highlighting/mark_color"); preview_text->set_line_background_color(sl.get_error_line() - 1, error_line_color); error_panel->show(); @@ -4460,6 +4554,7 @@ VisualShaderEditor::VisualShaderEditor() { // TRANSFORM add_options.push_back(AddOption("TransformFunc", "Transform", "Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("TransformOp", "Transform", "Common", "VisualShaderNodeTransformOp", TTR("Transform operator."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("OuterProduct", "Transform", "Composition", "VisualShaderNodeOuterProduct", TTR("Calculate the outer product of a pair of vectors.\n\nOuterProduct treats the first parameter 'c' as a column vector (matrix with one column) and the second parameter 'r' as a row vector (matrix with one row) and does a linear algebraic matrix multiply 'c * r', yielding a matrix whose number of rows is the number of components in 'c' and whose number of columns is the number of components in 'r'."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("TransformCompose", "Transform", "Composition", "VisualShaderNodeTransformCompose", TTR("Composes transform from four vectors."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); @@ -4470,7 +4565,11 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Inverse", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), VisualShaderNodeTransformFunc::FUNC_INVERSE, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("Transpose", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), VisualShaderNodeTransformFunc::FUNC_TRANSPOSE, VisualShaderNode::PORT_TYPE_TRANSFORM)); - add_options.push_back(AddOption("TransformMult", "Transform", "Operators", "VisualShaderNodeTransformMult", TTR("Multiplies transform by transform."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Add", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Sums two transforms."), VisualShaderNodeTransformOp::OP_ADD, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Divide", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Divides two transforms."), VisualShaderNodeTransformOp::OP_A_DIV_B, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Multiply", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Multiplies two transforms."), VisualShaderNodeTransformOp::OP_AxB, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("MultiplyComp", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Performs per-component multiplication of two transforms."), VisualShaderNodeTransformOp::OP_AxB_COMP, VisualShaderNode::PORT_TYPE_TRANSFORM)); + add_options.push_back(AddOption("Subtract", "Transform", "Operators", "VisualShaderNodeTransformOp", TTR("Subtracts two transforms."), VisualShaderNodeTransformOp::OP_A_MINUS_B, VisualShaderNode::PORT_TYPE_TRANSFORM)); add_options.push_back(AddOption("TransformVectorMult", "Transform", "Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("TransformConstant", "Transform", "Variables", "VisualShaderNodeTransformConstant", TTR("Transform constant."), -1, VisualShaderNode::PORT_TYPE_TRANSFORM)); @@ -4753,9 +4852,6 @@ public: if (p_property != "constant") { undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id); undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id); - } else { - undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id); - undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id); } undo_redo->commit_action(); diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index f53726edb9..9f24c5af72 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -47,6 +47,8 @@ class VisualShaderNodePlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL2RC(Object *, _create_editor, RES, Ref<VisualShaderNode>) + public: virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; @@ -73,7 +75,6 @@ private: Map<int, Port> output_ports; VBoxContainer *preview_box = nullptr; LineEdit *uniform_name = nullptr; - OptionButton *const_op = nullptr; CodeEdit *expression_edit = nullptr; CurveEditor *curve_editors[3] = { nullptr, nullptr, nullptr }; }; @@ -95,7 +96,6 @@ public: void register_output_port(int p_id, int p_port, TextureButton *p_button); void register_uniform_name(int p_id, LineEdit *p_uniform_name); void register_default_input_button(int p_node_id, int p_port_id, Button *p_button); - void register_constant_option_btn(int p_node_id, OptionButton *p_button); void register_expression_edit(int p_node_id, CodeEdit *p_expression_edit); void register_curve_editor(int p_node_id, int p_index, CurveEditor *p_curve_editor); void clear_links(); @@ -118,7 +118,6 @@ public: void set_uniform_name(VisualShader::Type p_type, int p_node_id, const String &p_name); void update_curve(int p_node_id); void update_curve_xyz(int p_node_id); - void update_constant(VisualShader::Type p_type, int p_node_id); void set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression); int get_constant_index(float p_constant) const; void update_node_size(int p_node_id); @@ -163,7 +162,10 @@ class VisualShaderEditor : public VBoxContainer { bool saved_node_pos_dirty; ConfirmationDialog *members_dialog; + VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX; + VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX; PopupMenu *popup_menu; + PopupMenu *constants_submenu = nullptr; MenuButton *tools; PopupPanel *comment_title_change_popup = nullptr; @@ -214,6 +216,7 @@ class VisualShaderEditor : public VBoxContainer { DELETE, DUPLICATE, SEPARATOR2, // ignore + FLOAT_CONSTANTS, CONVERT_CONSTANTS_TO_UNIFORMS, CONVERT_UNIFORMS_TO_CONSTANTS, SEPARATOR3, // ignore @@ -228,7 +231,7 @@ class VisualShaderEditor : public VBoxContainer { Label *highend_label; void _tools_menu_option(int p_idx); - void _show_members_dialog(bool at_mouse_pos); + void _show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX); void _update_graph(); @@ -347,6 +350,7 @@ class VisualShaderEditor : public VBoxContainer { Set<int> selected_constants; Set<int> selected_uniforms; int selected_comment = -1; + int selected_float_constant = -1; void _convert_constants_to_uniforms(bool p_vice_versa); void _replace_node(VisualShader::Type p_type_id, int p_node_id, const StringName &p_from, const StringName &p_to); @@ -396,7 +400,7 @@ class VisualShaderEditor : public VBoxContainer { void _input_select_item(Ref<VisualShaderNodeInput> input, String name); void _uniform_select_item(Ref<VisualShaderNodeUniformRef> p_uniform, String p_name); - void _float_constant_selected(int p_index, int p_node); + void _float_constant_selected(int p_which); VisualShader::Type get_current_shader_type() const; diff --git a/editor/project_manager.cpp b/editor/project_manager.cpp index 8d425a1e51..05cf3791f4 100644 --- a/editor/project_manager.cpp +++ b/editor/project_manager.cpp @@ -1887,7 +1887,7 @@ void ProjectManager::_update_project_buttons() { erase_missing_btn->set_disabled(!_project_list->is_any_project_missing()); } -void ProjectManager::_unhandled_key_input(const Ref<InputEvent> &p_ev) { +void ProjectManager::unhandled_key_input(const Ref<InputEvent> &p_ev) { ERR_FAIL_COND(p_ev.is_null()); Ref<InputEventKey> k = p_ev; @@ -2364,7 +2364,6 @@ void ProjectManager::_on_search_term_changed(const String &p_term) { } void ProjectManager::_bind_methods() { - ClassDB::bind_method("_unhandled_key_input", &ProjectManager::_unhandled_key_input); ClassDB::bind_method("_update_project_buttons", &ProjectManager::_update_project_buttons); ClassDB::bind_method("_version_button_pressed", &ProjectManager::_version_button_pressed); } diff --git a/editor/project_manager.h b/editor/project_manager.h index 0fc69bd313..f45d34d461 100644 --- a/editor/project_manager.h +++ b/editor/project_manager.h @@ -121,7 +121,7 @@ class ProjectManager : public Control { void _install_project(const String &p_zip_path, const String &p_title); void _dim_window(); - void _unhandled_key_input(const Ref<InputEvent> &p_ev); + virtual void unhandled_key_input(const Ref<InputEvent> &p_ev) override; void _files_dropped(PackedStringArray p_files, int p_screen); void _version_button_pressed(); diff --git a/editor/property_editor.cpp b/editor/property_editor.cpp index 7338588d56..6ea9b9dfae 100644 --- a/editor/property_editor.cpp +++ b/editor/property_editor.cpp @@ -59,42 +59,33 @@ #include "scene/scene_string_names.h" void EditorResourceConversionPlugin::_bind_methods() { - MethodInfo mi; - mi.name = "_convert"; - mi.return_val.type = Variant::OBJECT; - mi.return_val.class_name = "Resource"; - mi.return_val.hint = PROPERTY_HINT_RESOURCE_TYPE; - mi.return_val.hint_string = "Resource"; - mi.arguments.push_back(mi.return_val); - mi.arguments[0].name = "resource"; - - BIND_VMETHOD(mi) - - mi.name = "_handles"; - mi.return_val = PropertyInfo(Variant::BOOL, ""); - - BIND_VMETHOD(MethodInfo(Variant::STRING, "_converts_to")); + GDVIRTUAL_BIND(_converts_to); + GDVIRTUAL_BIND(_handles, "resource"); + GDVIRTUAL_BIND(_convert, "resource"); } String EditorResourceConversionPlugin::converts_to() const { - if (get_script_instance()) { - return get_script_instance()->call("_converts_to"); + String ret; + if (GDVIRTUAL_CALL(_converts_to, ret)) { + return ret; } return ""; } bool EditorResourceConversionPlugin::handles(const Ref<Resource> &p_resource) const { - if (get_script_instance()) { - return get_script_instance()->call("_handles", p_resource); + bool ret; + if (GDVIRTUAL_CALL(_handles, p_resource, ret)) { + return ret; } return false; } Ref<Resource> EditorResourceConversionPlugin::convert(const Ref<Resource> &p_resource) const { - if (get_script_instance()) { - return get_script_instance()->call("_convert", p_resource); + RES ret; + if (GDVIRTUAL_CALL(_convert, p_resource, ret)) { + return ret; } return Ref<Resource>(); diff --git a/editor/property_editor.h b/editor/property_editor.h index 8a587b50b0..23771b7494 100644 --- a/editor/property_editor.h +++ b/editor/property_editor.h @@ -56,6 +56,10 @@ class EditorResourceConversionPlugin : public RefCounted { protected: static void _bind_methods(); + GDVIRTUAL0RC(String, _converts_to) + GDVIRTUAL1RC(bool, _handles, RES) + GDVIRTUAL1RC(RES, _convert, RES) + public: virtual String converts_to() const; virtual bool handles(const Ref<Resource> &p_resource) const; diff --git a/editor/property_selector.cpp b/editor/property_selector.cpp index 1272d064a0..f167ded4e7 100644 --- a/editor/property_selector.cpp +++ b/editor/property_selector.cpp @@ -48,7 +48,7 @@ void PropertySelector::_sbox_input(const Ref<InputEvent> &p_ie) { case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); + search_options->gui_input(k); search_box->accept_event(); TreeItem *root = search_options->get_root(); diff --git a/editor/quick_open.cpp b/editor/quick_open.cpp index f8af3e8f36..fc3abbb87e 100644 --- a/editor/quick_open.cpp +++ b/editor/quick_open.cpp @@ -130,12 +130,6 @@ float EditorQuickOpen::_score_path(const String &p_search, const String &p_path) return score * (1.0f - 0.1f * (float(pos) / file.length())); } - // Positive bias for matches close to the end of the path. - pos = p_path.rfindn(p_search); - if (pos != -1) { - return 1.1f + 0.09 / (p_path.length() - pos + 1); - } - // Similarity return p_path.to_lower().similarity(p_search.to_lower()); } @@ -170,7 +164,7 @@ void EditorQuickOpen::_sbox_input(const Ref<InputEvent> &p_ie) { case KEY_DOWN: case KEY_PAGEUP: case KEY_PAGEDOWN: { - search_options->call("_gui_input", k); + search_options->gui_input(k); search_box->accept_event(); if (allow_multi_select) { diff --git a/editor/scene_tree_dock.cpp b/editor/scene_tree_dock.cpp index 0b228c2695..2ec4a088a2 100644 --- a/editor/scene_tree_dock.cpp +++ b/editor/scene_tree_dock.cpp @@ -62,7 +62,7 @@ void SceneTreeDock::_quick_open() { instantiate_scenes(quick_open->get_selected_files(), scene_tree->get_selected()); } -void SceneTreeDock::_input(Ref<InputEvent> p_event) { +void SceneTreeDock::input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); Ref<InputEventMouseButton> mb = p_event; @@ -72,7 +72,7 @@ void SceneTreeDock::_input(Ref<InputEvent> p_event) { } } -void SceneTreeDock::_unhandled_key_input(Ref<InputEvent> p_event) { +void SceneTreeDock::unhandled_key_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); if (get_focus_owner() && get_focus_owner()->is_text_field()) { @@ -3163,8 +3163,7 @@ void SceneTreeDock::_create_remap_for_resource(RES p_resource, Map<RES, RES> &r_ void SceneTreeDock::_bind_methods() { ClassDB::bind_method(D_METHOD("_set_owners"), &SceneTreeDock::_set_owners); - ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &SceneTreeDock::_unhandled_key_input); - ClassDB::bind_method(D_METHOD("_input"), &SceneTreeDock::_input); + ClassDB::bind_method(D_METHOD("_update_script_button"), &SceneTreeDock::_update_script_button); ClassDB::bind_method(D_METHOD("instantiate"), &SceneTreeDock::instantiate); diff --git a/editor/scene_tree_dock.h b/editor/scene_tree_dock.h index ccdc0a3786..387a35acbb 100644 --- a/editor/scene_tree_dock.h +++ b/editor/scene_tree_dock.h @@ -210,8 +210,8 @@ class SceneTreeDock : public VBoxContainer { void _node_prerenamed(Node *p_node, const String &p_new_name); void _nodes_drag_begin(); - void _input(Ref<InputEvent> p_event); - void _unhandled_key_input(Ref<InputEvent> p_event); + virtual void input(const Ref<InputEvent> &p_event) override; + virtual void unhandled_key_input(const Ref<InputEvent> &p_event) override; void _import_subscene(); diff --git a/editor/scene_tree_editor.cpp b/editor/scene_tree_editor.cpp index 83b0203f32..e7ba80677d 100644 --- a/editor/scene_tree_editor.cpp +++ b/editor/scene_tree_editor.cpp @@ -1206,11 +1206,10 @@ SceneTreeEditor::SceneTreeEditor(bool p_label, bool p_can_rename, bool p_can_ope } tree->connect("cell_selected", callable_mp(this, &SceneTreeEditor::_selected_changed)); - tree->connect("item_edited", callable_mp(this, &SceneTreeEditor::_renamed), varray(), CONNECT_DEFERRED); + tree->connect("item_edited", callable_mp(this, &SceneTreeEditor::_renamed)); tree->connect("multi_selected", callable_mp(this, &SceneTreeEditor::_cell_multi_selected)); tree->connect("button_pressed", callable_mp(this, &SceneTreeEditor::_cell_button_pressed)); tree->connect("nothing_selected", callable_mp(this, &SceneTreeEditor::_deselect_items)); - //tree->connect("item_edited", this,"_renamed",Vector<Variant>(),true); error = memnew(AcceptDialog); add_child(error); diff --git a/editor/settings_config_dialog.cpp b/editor/settings_config_dialog.cpp index 5c77c9f124..649caf5373 100644 --- a/editor/settings_config_dialog.cpp +++ b/editor/settings_config_dialog.cpp @@ -59,7 +59,7 @@ void EditorSettingsDialog::_settings_property_edited(const String &p_name) { if (full_name == "interface/theme/accent_color" || full_name == "interface/theme/base_color" || full_name == "interface/theme/contrast") { EditorSettings::get_singleton()->set_manually("interface/theme/preset", "Custom"); // set preset to Custom - } else if (full_name.begins_with("text_editor/highlighting")) { + } else if (full_name.begins_with("text_editor/theme/highlighting")) { EditorSettings::get_singleton()->set_manually("text_editor/theme/color_theme", "Custom"); } } @@ -138,7 +138,7 @@ void EditorSettingsDialog::_notification(int p_what) { } } -void EditorSettingsDialog::_unhandled_input(const Ref<InputEvent> &p_event) { +void EditorSettingsDialog::unhandled_input(const Ref<InputEvent> &p_event) { ERR_FAIL_COND(p_event.is_null()); const Ref<InputEventKey> k = p_event; @@ -250,6 +250,8 @@ void EditorSettingsDialog::_update_shortcuts() { sections["Common"] = common_section; common_section->set_text(0, TTR("Common")); + common_section->set_selectable(0, false); + common_section->set_selectable(1, false); if (collapsed.has("Common")) { common_section->set_collapsed(collapsed["Common"]); } @@ -343,14 +345,16 @@ void EditorSettingsDialog::_update_shortcuts() { String item_name = section_name.capitalize(); section->set_text(0, item_name); + section->set_selectable(0, false); + section->set_selectable(1, false); + section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); + section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); if (collapsed.has(item_name)) { section->set_collapsed(collapsed[item_name]); } sections[section_name] = section; - section->set_custom_bg_color(0, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); - section->set_custom_bg_color(1, shortcuts->get_theme_color(SNAME("prop_subsection"), SNAME("Editor"))); } // Don't match unassigned shortcuts when searching for assigned keys in search results. @@ -538,7 +542,6 @@ void EditorSettingsDialog::_editor_restart_close() { } void EditorSettingsDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input"), &EditorSettingsDialog::_unhandled_input); ClassDB::bind_method(D_METHOD("_update_shortcuts"), &EditorSettingsDialog::_update_shortcuts); ClassDB::bind_method(D_METHOD("_settings_changed"), &EditorSettingsDialog::_settings_changed); } diff --git a/editor/settings_config_dialog.h b/editor/settings_config_dialog.h index c38fceedf1..2b6c9b3e1d 100644 --- a/editor/settings_config_dialog.h +++ b/editor/settings_config_dialog.h @@ -83,7 +83,7 @@ class EditorSettingsDialog : public AcceptDialog { void _settings_property_edited(const String &p_name); void _settings_save(); - void _unhandled_input(const Ref<InputEvent> &p_event); + virtual void unhandled_input(const Ref<InputEvent> &p_event) override; void _notification(int p_what); void _update_icons(); diff --git a/editor/translations/el.po b/editor/translations/el.po index 93b5941f64..e773b011a4 100644 --- a/editor/translations/el.po +++ b/editor/translations/el.po @@ -6,7 +6,7 @@ # Georgios Katsanakis <geo.elgeo@gmail.com>, 2019. # Overloaded <manoschool@yahoo.gr>, 2019. # Eternal Death <eternaldeath0001@gmail.com>, 2019. -# Overloaded @ Orama Interactive http://orama-interactive.com/ <manoschool@yahoo.gr>, 2020. +# Overloaded @ Orama Interactive https://orama-interactive.com/ <manoschool@yahoo.gr>, 2020. # pandektis <pandektis@gmail.com>, 2020. # KostasMSC <kargyris@athtech.gr>, 2020. # lawfulRobot <czavantias@gmail.com>, 2020, 2021. |