diff options
Diffstat (limited to 'editor/plugins')
52 files changed, 2648 insertions, 1012 deletions
diff --git a/editor/plugins/abstract_polygon_2d_editor.cpp b/editor/plugins/abstract_polygon_2d_editor.cpp index 574b47d770..7f023af848 100644 --- a/editor/plugins/abstract_polygon_2d_editor.cpp +++ b/editor/plugins/abstract_polygon_2d_editor.cpp @@ -571,7 +571,8 @@ void AbstractPolygon2DEditor::forward_canvas_draw_over_viewport(Control *p_overl return; Transform2D xform = canvas_item_editor->get_canvas_transform() * _get_node()->get_global_transform(); - const Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); + // All polygon points are sharp, so use the sharp handle icon + const Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); const Vertex active_point = get_active_point(); const int n_polygons = _get_polygon_count(); diff --git a/editor/plugins/abstract_polygon_2d_editor.h b/editor/plugins/abstract_polygon_2d_editor.h index 97244fa4e9..a00cdd0cf6 100644 --- a/editor/plugins/abstract_polygon_2d_editor.h +++ b/editor/plugins/abstract_polygon_2d_editor.h @@ -36,9 +36,6 @@ #include "scene/2d/polygon_2d.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditor; class AbstractPolygon2DEditor : public HBoxContainer { diff --git a/editor/plugins/animation_blend_space_2d_editor.h b/editor/plugins/animation_blend_space_2d_editor.h index 74186791e1..850a6201bb 100644 --- a/editor/plugins/animation_blend_space_2d_editor.h +++ b/editor/plugins/animation_blend_space_2d_editor.h @@ -40,9 +40,6 @@ #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index 574f906cfa..235c204265 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -249,6 +249,7 @@ void AnimationNodeBlendTreeEditor::_update_graph() { node->add_color_override("title_color", c); c.a = 0.7; node->add_color_override("close_color", c); + node->add_color_override("resizer_color", c); } } diff --git a/editor/plugins/animation_blend_tree_editor_plugin.h b/editor/plugins/animation_blend_tree_editor_plugin.h index cb40159a40..77b57a50d0 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.h +++ b/editor/plugins/animation_blend_tree_editor_plugin.h @@ -40,9 +40,6 @@ #include "scene/gui/graph_edit.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin { diff --git a/editor/plugins/animation_player_editor_plugin.cpp b/editor/plugins/animation_player_editor_plugin.cpp index 5163b372b2..d7451849a1 100644 --- a/editor/plugins/animation_player_editor_plugin.cpp +++ b/editor/plugins/animation_player_editor_plugin.cpp @@ -32,12 +32,13 @@ #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" +#include "core/os/input.h" #include "core/os/keyboard.h" #include "core/project_settings.h" #include "editor/animation_track_editor.h" #include "editor/editor_settings.h" -// For onion skinning +// For onion skinning. #include "editor/plugins/canvas_item_editor_plugin.h" #include "editor/plugins/spatial_editor_plugin.h" #include "scene/main/viewport.h" @@ -293,10 +294,6 @@ void AnimationPlayerEditor::_animation_selected(int p_which) { } } frame->set_max(anim->get_length()); - if (anim->get_step()) - frame->set_step(anim->get_step()); - else - frame->set_step(0.00001); } else { track_editor->set_animation(Ref<Animation>()); @@ -480,6 +477,19 @@ void AnimationPlayerEditor::_select_anim_by_name(const String &p_anim) { _animation_selected(idx); } +double AnimationPlayerEditor::_get_editor_step() const { + + // Returns the effective snapping value depending on snapping modifiers, or 0 if snapping is disabled. + if (track_editor->is_snap_enabled()) { + const String current = player->get_assigned_animation(); + const Ref<Animation> anim = player->get_animation(current); + // Use more precise snapping when holding Shift + return Input::get_singleton()->is_key_pressed(KEY_SHIFT) ? anim->get_step() * 0.25 : anim->get_step(); + } + + return 0.0; +} + void AnimationPlayerEditor::_animation_name_edited() { player->stop(); @@ -680,8 +690,10 @@ void AnimationPlayerEditor::set_state(const Dictionary &p_state) { if (p_state.has("animation")) { String anim = p_state["animation"]; - _select_anim_by_name(anim); - _animation_edit(); + if (!anim.empty() && player->has_animation(anim)) { + _select_anim_by_name(anim); + _animation_edit(); + } } } } @@ -1008,7 +1020,7 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { }; updating = true; - String current = player->get_assigned_animation(); //animation->get_item_text( animation->get_selected() ); + String current = player->get_assigned_animation(); if (current == "" || !player->has_animation(current)) { updating = false; current = ""; @@ -1018,14 +1030,9 @@ void AnimationPlayerEditor::_seek_value_changed(float p_value, bool p_set) { Ref<Animation> anim; anim = player->get_animation(current); - float pos = anim->get_length() * (p_value / frame->get_max()); - float step = anim->get_step(); - if (step) { - pos = Math::stepify(pos, step); - if (pos < 0) - pos = 0; - if (pos >= anim->get_length()) - pos = anim->get_length(); + float pos = CLAMP(anim->get_length() * (p_value / frame->get_max()), 0, anim->get_length()); + if (track_editor->is_snap_enabled()) { + pos = Math::stepify(pos, _get_editor_step()); } if (player->is_valid() && !p_set) { @@ -1063,14 +1070,6 @@ void AnimationPlayerEditor::_animation_key_editor_anim_len_changed(float p_len) frame->set_max(p_len); } -void AnimationPlayerEditor::_animation_key_editor_anim_step_changed(float p_len) { - - if (p_len) - frame->set_step(p_len); - else - frame->set_step(0.00001); -} - void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) { if (!is_visible_in_tree()) @@ -1081,28 +1080,16 @@ void AnimationPlayerEditor::_animation_key_editor_seek(float p_pos, bool p_drag) if (player->is_playing()) return; + Ref<Animation> anim = player->get_animation(player->get_assigned_animation()); + updating = true; - frame->set_value(p_pos); + frame->set_value(Math::stepify(p_pos, _get_editor_step())); updating = false; _seek_value_changed(p_pos, !p_drag); EditorNode::get_singleton()->get_inspector()->refresh(); } -void AnimationPlayerEditor::_hide_anim_editors() { - - player = NULL; - hide(); - set_process(false); - - track_editor->set_animation(Ref<Animation>()); - track_editor->set_root(NULL); - track_editor->show_select_node_warning(true); -} - -void AnimationPlayerEditor::_animation_about_to_show_menu() { -} - void AnimationPlayerEditor::_animation_tool_menu(int p_option) { String current; @@ -1490,7 +1477,7 @@ void AnimationPlayerEditor::_prepare_onion_layers_2() { player->seek(cpos, false); player->restore_animated_values(values_backup); - // Restor state of main editors. + // Restore state of main editors. if (SpatialEditor::get_singleton()->is_visible()) { // 3D SpatialEditor::get_singleton()->set_state(spatial_edit_state); @@ -1520,7 +1507,7 @@ void AnimationPlayerEditor::_stop_onion_skinning() { _free_onion_layers(); - // Clean up the overlay + // Clean up the overlay. onion.can_overlay = false; plugin->update_overlays(); } @@ -1558,8 +1545,6 @@ void AnimationPlayerEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_list_changed"), &AnimationPlayerEditor::_list_changed); ClassDB::bind_method(D_METHOD("_animation_key_editor_seek"), &AnimationPlayerEditor::_animation_key_editor_seek); ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_len_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_len_changed); - ClassDB::bind_method(D_METHOD("_animation_key_editor_anim_step_changed"), &AnimationPlayerEditor::_animation_key_editor_anim_step_changed); - ClassDB::bind_method(D_METHOD("_hide_anim_editors"), &AnimationPlayerEditor::_hide_anim_editors); ClassDB::bind_method(D_METHOD("_animation_duplicate"), &AnimationPlayerEditor::_animation_duplicate); ClassDB::bind_method(D_METHOD("_blend_editor_next_changed"), &AnimationPlayerEditor::_blend_editor_next_changed); ClassDB::bind_method(D_METHOD("_unhandled_key_input"), &AnimationPlayerEditor::_unhandled_key_input); @@ -1621,6 +1606,7 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay hb->add_child(frame); frame->set_custom_minimum_size(Size2(60, 0)); frame->set_stretch_ratio(2); + frame->set_step(0.0001); frame->set_tooltip(TTR("Animation position (in seconds).")); hb->add_child(memnew(VSeparator)); @@ -1774,11 +1760,10 @@ AnimationPlayerEditor::AnimationPlayerEditor(EditorNode *p_editor, AnimationPlay track_editor->set_v_size_flags(SIZE_EXPAND_FILL); track_editor->connect("timeline_changed", this, "_animation_key_editor_seek"); track_editor->connect("animation_len_changed", this, "_animation_key_editor_anim_len_changed"); - track_editor->connect("animation_step_changed", this, "_animation_key_editor_anim_step_changed"); _update_player(); - // Onion skinning + // Onion skinning. track_editor->connect("visibility_changed", this, "_editor_visibility_changed"); diff --git a/editor/plugins/animation_player_editor_plugin.h b/editor/plugins/animation_player_editor_plugin.h index 398ef6ff14..eed7344395 100644 --- a/editor/plugins/animation_player_editor_plugin.h +++ b/editor/plugins/animation_player_editor_plugin.h @@ -39,9 +39,6 @@ #include "scene/gui/spin_box.h" #include "scene/gui/texture_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationTrackEditor; class AnimationPlayerEditorPlugin; @@ -133,9 +130,9 @@ class AnimationPlayerEditor : public VBoxContainer { AnimationTrackEditor *track_editor; - // Onion skinning + // Onion skinning. struct { - // Settings + // Settings. bool enabled; bool past; bool future; @@ -145,11 +142,11 @@ class AnimationPlayerEditor : public VBoxContainer { bool include_gizmos; int get_needed_capture_count() const { - // 'Differences only' needs a capture of the present + // 'Differences only' needs a capture of the present. return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0); } - // Rendering + // Rendering. int64_t last_frame; int can_overlay; Size2 capture_size; @@ -164,6 +161,7 @@ class AnimationPlayerEditor : public VBoxContainer { } onion; void _select_anim_by_name(const String &p_anim); + double _get_editor_step() const; void _play_pressed(); void _play_from_pressed(); void _play_bw_pressed(); @@ -197,18 +195,14 @@ class AnimationPlayerEditor : public VBoxContainer { void _update_player(); void _blend_edited(); - void _hide_anim_editors(); - void _animation_player_changed(Object *p_pl); void _animation_key_editor_seek(float p_pos, bool p_drag); void _animation_key_editor_anim_len_changed(float p_len); - void _animation_key_editor_anim_step_changed(float p_len); void _unhandled_key_input(const Ref<InputEvent> &p_ev); void _animation_tool_menu(int p_option); void _onion_skinning_menu(int p_option); - void _animation_about_to_show_menu(); void _editor_visibility_changed(); bool _are_onion_layers_valid(); diff --git a/editor/plugins/animation_tree_player_editor_plugin.h b/editor/plugins/animation_tree_player_editor_plugin.h index f4bfe58909..03bc559b86 100644 --- a/editor/plugins/animation_tree_player_editor_plugin.h +++ b/editor/plugins/animation_tree_player_editor_plugin.h @@ -38,9 +38,6 @@ #include "scene/gui/button.h" #include "scene/gui/popup.h" #include "scene/gui/tree.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class AnimationTreePlayerEditor : public Control { diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 31b11d8bea..3d161dc5b9 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -101,7 +101,7 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() { add_style_override("panel", border); HBoxContainer *hb = memnew(HBoxContainer); - // Add some spacing to visually separate the icon from the asset details + // Add some spacing to visually separate the icon from the asset details. hb->add_constant_override("separation", 15 * EDSCALE); add_child(hb); @@ -118,25 +118,21 @@ EditorAssetLibraryItem::EditorAssetLibraryItem() { vb->set_h_size_flags(SIZE_EXPAND_FILL); title = memnew(LinkButton); - title->set_text("My Awesome Addon"); title->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); title->connect("pressed", this, "_asset_clicked"); vb->add_child(title); category = memnew(LinkButton); - category->set_text("Editor Tools"); category->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); category->connect("pressed", this, "_category_clicked"); vb->add_child(category); author = memnew(LinkButton); - author->set_text("Johny Tolengo"); author->set_underline_mode(LinkButton::UNDERLINE_MODE_ON_HOVER); author->connect("pressed", this, "_author_clicked"); vb->add_child(author); price = memnew(Label); - price->set_text(TTR("Free")); vb->add_child(price); set_custom_minimum_size(Size2(250, 100) * EDSCALE); @@ -200,14 +196,15 @@ void EditorAssetLibraryItemDescription::set_image(int p_type, int p_index, const } break; } } + void EditorAssetLibraryItemDescription::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { previews_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); - desc_bg->add_style_override("panel", get_stylebox("normal", "TextEdit")); } break; } } + void EditorAssetLibraryItemDescription::_bind_methods() { ClassDB::bind_method(D_METHOD("set_image"), &EditorAssetLibraryItemDescription::set_image); ClassDB::bind_method(D_METHOD("_link_click"), &EditorAssetLibraryItemDescription::_link_click); @@ -270,20 +267,16 @@ void EditorAssetLibraryItemDescription::add_preview(int p_id, bool p_video, cons if (!p_video) { preview.image = get_icon("ThumbnailWait", "EditorIcons"); } - if (preview_images.size() == 0 && !p_video) { + preview_images.push_back(preview); + if (preview_images.size() == 1 && !p_video) { _preview_click(p_id); } - preview_images.push_back(preview); } EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { - VBoxContainer *vbox = memnew(VBoxContainer); - add_child(vbox); - HBoxContainer *hbox = memnew(HBoxContainer); - vbox->add_child(hbox); - vbox->add_constant_override("separation", 15 * EDSCALE); + add_child(hbox); VBoxContainer *desc_vbox = memnew(VBoxContainer); hbox->add_child(desc_vbox); hbox->add_constant_override("separation", 15 * EDSCALE); @@ -291,24 +284,24 @@ EditorAssetLibraryItemDescription::EditorAssetLibraryItemDescription() { item = memnew(EditorAssetLibraryItem); desc_vbox->add_child(item); - desc_vbox->set_custom_minimum_size(Size2(300 * EDSCALE, 0)); - - desc_bg = memnew(PanelContainer); - desc_vbox->add_child(desc_bg); - desc_bg->set_v_size_flags(SIZE_EXPAND_FILL); + desc_vbox->set_custom_minimum_size(Size2(440 * EDSCALE, 0)); description = memnew(RichTextLabel); + desc_vbox->add_child(description); + description->set_v_size_flags(SIZE_EXPAND_FILL); description->connect("meta_clicked", this, "_link_click"); - description->set_custom_minimum_size(Size2(440 * EDSCALE, 300 * EDSCALE)); - desc_bg->add_child(description); + description->add_constant_override("line_separation", Math::round(5 * EDSCALE)); VBoxContainer *previews_vbox = memnew(VBoxContainer); hbox->add_child(previews_vbox); previews_vbox->add_constant_override("separation", 15 * EDSCALE); + previews_vbox->set_v_size_flags(SIZE_EXPAND_FILL); preview = memnew(TextureRect); - preview->set_custom_minimum_size(Size2(640 * EDSCALE, 345 * EDSCALE)); previews_vbox->add_child(preview); + preview->set_expand(true); + preview->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED); + preview->set_custom_minimum_size(Size2(640 * EDSCALE, 345 * EDSCALE)); previews_bg = memnew(PanelContainer); previews_vbox->add_child(previews_bg); @@ -333,18 +326,14 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int switch (p_status) { - case HTTPRequest::RESULT_CANT_RESOLVE: { - error_text = TTR("Can't resolve hostname:") + " " + host; - status->set_text(TTR("Can't resolve.")); - } break; - case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: + case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: case HTTPRequest::RESULT_CONNECTION_ERROR: - case HTTPRequest::RESULT_CHUNKED_BODY_SIZE_MISMATCH: { + case HTTPRequest::RESULT_BODY_SIZE_LIMIT_EXCEEDED: { error_text = TTR("Connection error, please try again."); status->set_text(TTR("Can't connect.")); } break; - case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: - case HTTPRequest::RESULT_CANT_CONNECT: { + case HTTPRequest::RESULT_CANT_CONNECT: + case HTTPRequest::RESULT_SSL_HANDSHAKE_ERROR: { error_text = TTR("Can't connect to host:") + " " + host; status->set_text(TTR("Can't connect.")); } break; @@ -352,13 +341,26 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int error_text = TTR("No response from host:") + " " + host; status->set_text(TTR("No response.")); } break; + case HTTPRequest::RESULT_CANT_RESOLVE: { + error_text = TTR("Can't resolve hostname:") + " " + host; + status->set_text(TTR("Can't resolve.")); + } break; case HTTPRequest::RESULT_REQUEST_FAILED: { error_text = TTR("Request failed, return code:") + " " + itos(p_code); - status->set_text(TTR("Request Failed.")); + status->set_text(TTR("Request failed.")); + } break; + case HTTPRequest::RESULT_DOWNLOAD_FILE_CANT_OPEN: + case HTTPRequest::RESULT_DOWNLOAD_FILE_WRITE_ERROR: { + error_text = TTR("Cannot save response to:") + " " + download->get_download_file(); + status->set_text(TTR("Write error.")); } break; case HTTPRequest::RESULT_REDIRECT_LIMIT_REACHED: { error_text = TTR("Request failed, too many redirects"); - status->set_text(TTR("Redirect Loop.")); + status->set_text(TTR("Redirect loop.")); + } break; + case HTTPRequest::RESULT_TIMEOUT: { + error_text = TTR("Request failed, timeout"); + status->set_text(TTR("Timeout.")); } break; default: { if (p_code != 200) { @@ -383,7 +385,7 @@ void EditorAssetLibraryItemDownload::_http_download_completed(int p_status, int install->set_disabled(false); status->set_text(TTR("Success!")); - // Make the progress bar invisible but don't reflow other Controls around it + // Make the progress bar invisible but don't reflow other Controls around it. progress->set_modulate(Color(0, 0, 0, 0)); set_process(false); @@ -395,11 +397,9 @@ void EditorAssetLibraryItemDownload::configure(const String &p_title, int p_asse icon->set_texture(p_preview); asset_id = p_asset_id; if (!p_preview.is_valid()) - icon->set_texture(get_icon("DefaultProjectIcon", "EditorIcons")); + icon->set_texture(get_icon("FileBrokenBigThumb", "EditorIcons")); host = p_download_url; sha256 = p_sha256_hash; - asset_installer->connect("confirmed", this, "_close"); - dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); _make_request(); } @@ -407,9 +407,11 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { switch (p_what) { - case NOTIFICATION_READY: { + // FIXME: The editor crashes if 'NOTICATION_THEME_CHANGED' is used. + case NOTIFICATION_ENTER_TREE: { add_style_override("panel", get_stylebox("panel", "TabContainer")); + dismiss->set_normal_texture(get_icon("Close", "EditorIcons")); } break; case NOTIFICATION_PROCESS: { @@ -463,9 +465,8 @@ void EditorAssetLibraryItemDownload::_notification(int p_what) { } void EditorAssetLibraryItemDownload::_close() { - DirAccess *da = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); - da->remove(download->get_download_file()); //clean up removed file - memdelete(da); + // Clean up downloaded file. + DirAccess::remove_file_or_error(download->get_download_file()); queue_delete(); } @@ -562,6 +563,7 @@ EditorAssetLibraryItemDownload::EditorAssetLibraryItemDownload() { asset_installer = memnew(EditorAssetInstaller); add_child(asset_installer); + asset_installer->connect("confirmed", this, "_close"); prev_status = -1; @@ -576,7 +578,6 @@ void EditorAssetLibrary::_notification(int p_what) { case NOTIFICATION_READY: { error_tr->set_texture(get_icon("Error", "EditorIcons")); - reverse->set_icon(get_icon("Sort", "EditorIcons")); filter->set_right_icon(get_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); @@ -584,40 +585,22 @@ void EditorAssetLibrary::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { - if (is_visible()) { + if (is_visible() && initial_loading) { _repository_changed(0); // Update when shown for the first time. } } break; case NOTIFICATION_PROCESS: { HTTPClient::Status s = request->get_http_client_status(); - bool visible = s != HTTPClient::STATUS_DISCONNECTED; - - if (visible != load_status->is_visible()) { - load_status->set_visible(visible); - } + const bool loading = s != HTTPClient::STATUS_DISCONNECTED; - if (visible) { - switch (s) { - - case HTTPClient::STATUS_RESOLVING: { - load_status->set_value(0.1); - } break; - case HTTPClient::STATUS_CONNECTING: { - load_status->set_value(0.2); - } break; - case HTTPClient::STATUS_REQUESTING: { - load_status->set_value(0.3); - } break; - case HTTPClient::STATUS_BODY: { - load_status->set_value(0.4); - } break; - default: { - } - } + if (loading) { + library_scroll->set_modulate(Color(1, 1, 1, 0.5)); + } else { + library_scroll->set_modulate(Color(1, 1, 1, 1)); } - bool no_downloads = downloads_hb->get_child_count() == 0; + const bool no_downloads = downloads_hb->get_child_count() == 0; if (no_downloads == downloads_scroll->is_visible()) { downloads_scroll->set_visible(!no_downloads); } @@ -628,7 +611,6 @@ void EditorAssetLibrary::_notification(int p_what) { library_scroll_bg->add_style_override("panel", get_stylebox("bg", "Tree")); downloads_scroll->add_style_override("bg", get_stylebox("bg", "Tree")); error_tr->set_texture(get_icon("Error", "EditorIcons")); - reverse->set_icon(get_icon("Sort", "EditorIcons")); filter->set_right_icon(get_icon("Search", "EditorIcons")); filter->set_clear_button_enabled(true); } break; @@ -661,28 +643,32 @@ void EditorAssetLibrary::_install_asset() { } const char *EditorAssetLibrary::sort_key[SORT_MAX] = { - "downloads", + "updated", + "updated", "name", + "name", + "cost", "cost", - "updated" }; const char *EditorAssetLibrary::sort_text[SORT_MAX] = { - "Downloads", - "Name", - "License", // "cost" stores the SPDX license name in the Godot Asset Library - "Updated" + "Recently Updated", + "Least Recently Updated", + "Name (A-Z)", + "Name (Z-A)", + "License (A-Z)", // "cost" stores the SPDX license name in the Godot Asset Library. + "License (Z-A)", // "cost" stores the SPDX license name in the Godot Asset Library. }; const char *EditorAssetLibrary::support_key[SUPPORT_MAX] = { "official", "community", - "testing" + "testing", }; void EditorAssetLibrary::_select_author(int p_id) { - // Open author window + // Open author window. } void EditorAssetLibrary::_select_category(int p_id) { @@ -749,7 +735,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt switch (image_queue[p_queue_id].image_type) { case IMAGE_QUEUE_ICON: - image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_CUBIC); + image->resize(64 * EDSCALE, 64 * EDSCALE, Image::INTERPOLATE_LANCZOS); break; case IMAGE_QUEUE_THUMBNAIL: { @@ -779,7 +765,7 @@ void EditorAssetLibrary::_image_update(bool use_cache, bool final, const PoolByt } if (!image_set && final) { - obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("DefaultProjectIcon", "EditorIcons")); + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("FileBrokenBigThumb", "EditorIcons")); } } } @@ -824,7 +810,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons WARN_PRINTS("Error getting image file from URL: " + image_queue[p_queue_id].image_url); Object *obj = ObjectDB::get_instance(image_queue[p_queue_id].target); if (obj) { - obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("DefaultProjectIcon", "EditorIcons")); + obj->call("set_image", image_queue[p_queue_id].image_type, image_queue[p_queue_id].image_index, get_icon("FileBrokenBigThumb", "EditorIcons")); } } @@ -836,7 +822,7 @@ void EditorAssetLibrary::_image_request_completed(int p_status, int p_code, cons void EditorAssetLibrary::_update_image_queue() { - int max_images = 2; + const int max_images = 6; int current_images = 0; List<int> to_delete; @@ -944,8 +930,8 @@ void EditorAssetLibrary::_search(int p_page) { args += "&category=" + itos(categories->get_item_metadata(categories->get_selected())); } - if (reverse->is_pressed()) { - + // Sorting options with an odd index are always the reverse of the previous one + if (sort->get_selected() % 2 == 1) { args += "&reverse=true"; } @@ -1148,6 +1134,12 @@ void EditorAssetLibrary::_http_request_completed(int p_status, int p_code, const _search(); } break; case REQUESTING_SEARCH: { + + initial_loading = false; + + // The loading text only needs to be displayed before the first page is loaded + library_loading->hide(); + if (asset_items) { memdelete(asset_items); } @@ -1340,6 +1332,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { requesting = REQUESTING_NONE; templates_only = p_templates_only; + initial_loading = true; VBoxContainer *library_main = memnew(VBoxContainer); @@ -1350,7 +1343,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_main->add_child(search_hb); library_main->add_constant_override("separation", 10 * EDSCALE); - search_hb->add_child(memnew(Label(TTR("Search:") + " "))); filter = memnew(LineEdit); search_hb->add_child(filter); filter->set_h_size_flags(SIZE_EXPAND_FILL); @@ -1363,12 +1355,12 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { search_hb->add_child(memnew(VSeparator)); Button *open_asset = memnew(Button); - open_asset->set_text(TTR("Import")); + open_asset->set_text(TTR("Import...")); search_hb->add_child(open_asset); open_asset->connect("pressed", this, "_asset_open"); Button *plugins = memnew(Button); - plugins->set_text(TTR("Plugins")); + plugins->set_text(TTR("Plugins...")); search_hb->add_child(plugins); plugins->connect("pressed", this, "_manage_plugins"); @@ -1391,12 +1383,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { sort->set_h_size_flags(SIZE_EXPAND_FILL); sort->connect("item_selected", this, "_rerun_search"); - reverse = memnew(ToolButton); - reverse->set_toggle_mode(true); - reverse->connect("toggled", this, "_rerun_search"); - reverse->set_tooltip(TTR("Reverse sorting.")); - search_hb2->add_child(reverse); - search_hb2->add_child(memnew(VSeparator)); search_hb2->add_child(memnew(Label(TTR("Category:") + " "))); @@ -1425,7 +1411,7 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { support = memnew(MenuButton); search_hb2->add_child(support); - support->set_text(TTR("Support...")); + support->set_text(TTR("Support")); support->get_popup()->add_check_item(TTR("Official"), SUPPORT_OFFICIAL); support->get_popup()->add_check_item(TTR("Community"), SUPPORT_COMMUNITY); support->get_popup()->add_check_item(TTR("Testing"), SUPPORT_TESTING); @@ -1463,6 +1449,10 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_vb_border->add_child(library_vb); + library_loading = memnew(Label(TTR("Loading..."))); + library_loading->set_align(Label::ALIGN_CENTER); + library_vb->add_child(library_loading); + asset_top_page = memnew(HBoxContainer); library_vb->add_child(asset_top_page); @@ -1485,12 +1475,6 @@ EditorAssetLibrary::EditorAssetLibrary(bool p_templates_only) { library_vb->add_constant_override("separation", 20 * EDSCALE); - load_status = memnew(ProgressBar); - load_status->set_min(0); - load_status->set_max(1); - load_status->set_step(0.001); - library_main->add_child(load_status); - error_hb = memnew(HBoxContainer); library_main->add_child(error_hb); error_label = memnew(Label); diff --git a/editor/plugins/asset_library_editor_plugin.h b/editor/plugins/asset_library_editor_plugin.h index 81288ae831..7e934ac6cb 100644 --- a/editor/plugins/asset_library_editor_plugin.h +++ b/editor/plugins/asset_library_editor_plugin.h @@ -91,7 +91,6 @@ class EditorAssetLibraryItemDescription : public ConfirmationDialog { ScrollContainer *previews; HBoxContainer *preview_hb; PanelContainer *previews_bg; - PanelContainer *desc_bg; struct Preview { int id; @@ -186,13 +185,12 @@ class EditorAssetLibrary : public PanelContainer { PanelContainer *library_scroll_bg; ScrollContainer *library_scroll; VBoxContainer *library_vb; + Label *library_loading; LineEdit *filter; OptionButton *categories; OptionButton *repository; OptionButton *sort; - ToolButton *reverse; Button *search; - ProgressBar *load_status; HBoxContainer *error_hb; TextureRect *error_tr; Label *error_label; @@ -207,6 +205,7 @@ class EditorAssetLibrary : public PanelContainer { HTTPRequest *request; bool templates_only; + bool initial_loading; enum Support { SUPPORT_OFFICIAL, @@ -216,10 +215,12 @@ class EditorAssetLibrary : public PanelContainer { }; enum SortOrder { - SORT_DOWNLOADS, + SORT_UPDATED, + SORT_UPDATED_REVERSE, SORT_NAME, + SORT_NAME_REVERSE, SORT_COST, - SORT_UPDATED, + SORT_COST_REVERSE, SORT_MAX }; diff --git a/editor/plugins/camera_editor_plugin.h b/editor/plugins/camera_editor_plugin.h index eac9acab93..400aee132d 100644 --- a/editor/plugins/camera_editor_plugin.h +++ b/editor/plugins/camera_editor_plugin.h @@ -35,10 +35,6 @@ #include "editor/editor_plugin.h" #include "scene/3d/camera.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class CameraEditor : public Control { GDCLASS(CameraEditor, Control); diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 19199f37ef..6f612b5c79 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -174,15 +174,6 @@ public: } }; -void CanvasItemEditor::_snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius) { - float radius = p_radius / zoom; - float dist = Math::abs(p_value - p_target_snap); - if ((p_radius < 0 || dist < radius) && (!r_snapped || dist < Math::abs(r_current_snap - p_value))) { - r_current_snap = p_target_snap; - r_snapped = true; - } -} - bool CanvasItemEditor::_is_node_locked(const Node *p_node) { return p_node->has_meta("_edit_lock_") && p_node->get_meta("_edit_lock_"); } @@ -200,108 +191,174 @@ bool CanvasItemEditor::_is_node_movable(const Node *p_node, bool p_popup_warning return true; } -void CanvasItemEditor::_snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation, float p_radius) { +void CanvasItemEditor::_snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius) { + + float radius = p_radius / zoom; + float dist = Math::abs(p_value - p_target_value); + if ((p_radius < 0 || dist < radius) && (r_current_snap_target == SNAP_TARGET_NONE || dist < Math::abs(r_current_snap - p_value))) { + r_current_snap = p_target_value; + r_current_snap_target = p_snap_target; + } +} + +void CanvasItemEditor::_snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation, + float p_radius) { + Transform2D rot_trans = Transform2D(rotation, Point2()); p_value = rot_trans.inverse().xform(p_value); - p_target_snap = rot_trans.inverse().xform(p_target_snap); + p_target_value = rot_trans.inverse().xform(p_target_value); r_current_snap = rot_trans.inverse().xform(r_current_snap); - _snap_if_closer_float(p_value.x, p_target_snap.x, r_current_snap.x, r_snapped[0], p_radius); - _snap_if_closer_float(p_value.y, p_target_snap.y, r_current_snap.y, r_snapped[1], p_radius); + _snap_if_closer_float( + p_value.x, + r_current_snap.x, + r_current_snap_target[0], + p_target_value.x, + p_snap_target, + p_radius); + + _snap_if_closer_float( + p_value.y, + r_current_snap.y, + r_current_snap_target[1], + p_target_value.y, + p_snap_target, + p_radius); r_current_snap = rot_trans.xform(r_current_snap); } -void CanvasItemEditor::_snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap) { +void CanvasItemEditor::_snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current) { const CanvasItem *canvas_item = Object::cast_to<CanvasItem>(p_current); - if (canvas_item && (!p_to_snap || p_current != p_to_snap)) { + + // Check if the element is in the exception + bool exception = false; + for (List<const CanvasItem *>::Element *E = p_exceptions.front(); E; E = E->next()) { + if (E->get() == p_current) { + exception = true; + break; + } + }; + + if (canvas_item && !exception) { Transform2D ci_transform = canvas_item->get_global_transform_with_canvas(); - Transform2D to_snap_transform = p_to_snap ? p_to_snap->get_global_transform_with_canvas() : Transform2D(); - if (fmod(ci_transform.get_rotation() - to_snap_transform.get_rotation(), (real_t)360.0) == 0.0) { + if (fmod(ci_transform.get_rotation() - p_transform_to_snap.get_rotation(), (real_t)360.0) == 0.0) { if (canvas_item->_edit_use_rect()) { Point2 begin = ci_transform.xform(canvas_item->_edit_get_rect().get_position()); Point2 end = ci_transform.xform(canvas_item->_edit_get_rect().get_position() + canvas_item->_edit_get_rect().get_size()); - _snap_if_closer_point(p_value, begin, r_current_snap, r_snapped, ci_transform.get_rotation()); - _snap_if_closer_point(p_value, end, r_current_snap, r_snapped, ci_transform.get_rotation()); + + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, begin, p_snap_target, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, end, p_snap_target, ci_transform.get_rotation()); } else { Point2 position = ci_transform.xform(Point2()); - _snap_if_closer_point(p_value, position, r_current_snap, r_snapped, ci_transform.get_rotation()); + _snap_if_closer_point(p_value, r_current_snap, r_current_snap_target, position, p_snap_target, ci_transform.get_rotation()); } } } for (int i = 0; i < p_current->get_child_count(); i++) { - _snap_other_nodes(p_value, r_current_snap, r_snapped, p_current->get_child(i), p_to_snap); + _snap_other_nodes(p_value, p_transform_to_snap, r_current_snap, r_current_snap_target, p_snap_target, p_exceptions, p_current->get_child(i)); } } -Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const CanvasItem *p_canvas_item, unsigned int p_forced_modes) { - bool snapped[2] = { false, false }; +Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, unsigned int p_forced_modes, const CanvasItem *p_self_canvas_item, List<CanvasItem *> p_other_nodes_exceptions) { + + snap_target[0] = SNAP_TARGET_NONE; + snap_target[1] = SNAP_TARGET_NONE; + bool is_snap_active = snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); // Smart snap using the canvas position Vector2 output = p_target; real_t rotation = 0.0; - if (p_canvas_item) { - rotation = p_canvas_item->get_global_transform_with_canvas().get_rotation(); + if (p_self_canvas_item) { + rotation = p_self_canvas_item->get_global_transform_with_canvas().get_rotation(); // Parent sides and center if ((is_snap_active && snap_node_parent && (p_modes & SNAP_NODE_PARENT)) || (p_forced_modes & SNAP_NODE_PARENT)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); - } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_canvas_item->get_parent())) { + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(0, 0))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(1, 1))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); + } else if (const CanvasItem *parent_ci = Object::cast_to<CanvasItem>(p_self_canvas_item->get_parent())) { if (parent_ci->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); - Point2 end = p_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, (begin + end) / 2.0, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + Point2 begin = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_transform().affine_inverse().xform(parent_ci->_edit_get_rect().get_position() + parent_ci->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, (begin + end) / 2.0, SNAP_TARGET_PARENT, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_PARENT, rotation); } else { - Point2 position = p_canvas_item->get_transform().affine_inverse().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_transform().affine_inverse().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_PARENT, rotation); } } } // Self anchors if ((is_snap_active && snap_node_anchors && (p_modes & SNAP_NODE_ANCHORS)) || (p_forced_modes & SNAP_NODE_ANCHORS)) { - if (const Control *c = Object::cast_to<Control>(p_canvas_item)) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + if (const Control *c = Object::cast_to<Control>(p_self_canvas_item)) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_LEFT), c->get_anchor(MARGIN_TOP)))); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(_anchor_to_position(c, Point2(c->get_anchor(MARGIN_RIGHT), c->get_anchor(MARGIN_BOTTOM)))); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF_ANCHORS, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF_ANCHORS, rotation); } } // Self sides if ((is_snap_active && snap_node_sides && (p_modes & SNAP_NODE_SIDES)) || (p_forced_modes & SNAP_NODE_SIDES)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 begin = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position()); - Point2 end = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size()); - _snap_if_closer_point(p_target, begin, output, snapped, rotation); - _snap_if_closer_point(p_target, end, output, snapped, rotation); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 begin = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position()); + Point2 end = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size()); + _snap_if_closer_point(p_target, output, snap_target, begin, SNAP_TARGET_SELF, rotation); + _snap_if_closer_point(p_target, output, snap_target, end, SNAP_TARGET_SELF, rotation); } } // Self center if ((is_snap_active && snap_node_center && (p_modes & SNAP_NODE_CENTER)) || (p_forced_modes & SNAP_NODE_CENTER)) { - if (p_canvas_item->_edit_use_rect()) { - Point2 center = p_canvas_item->get_global_transform_with_canvas().xform(p_canvas_item->_edit_get_rect().get_position() + p_canvas_item->_edit_get_rect().get_size() / 2.0); - _snap_if_closer_point(p_target, center, output, snapped, rotation); + if (p_self_canvas_item->_edit_use_rect()) { + Point2 center = p_self_canvas_item->get_global_transform_with_canvas().xform(p_self_canvas_item->_edit_get_rect().get_position() + p_self_canvas_item->_edit_get_rect().get_size() / 2.0); + _snap_if_closer_point(p_target, output, snap_target, center, SNAP_TARGET_SELF, rotation); } else { - Point2 position = p_canvas_item->get_global_transform_with_canvas().xform(Point2()); - _snap_if_closer_point(p_target, position, output, snapped, rotation); + Point2 position = p_self_canvas_item->get_global_transform_with_canvas().xform(Point2()); + _snap_if_closer_point(p_target, output, snap_target, position, SNAP_TARGET_SELF, rotation); } } } // Other nodes sides if ((is_snap_active && snap_other_nodes && (p_modes & SNAP_OTHER_NODES)) || (p_forced_modes & SNAP_OTHER_NODES)) { - _snap_other_nodes(p_target, output, snapped, get_tree()->get_edited_scene_root(), p_canvas_item); + Transform2D to_snap_transform = Transform2D(); + List<const CanvasItem *> exceptions = List<const CanvasItem *>(); + for (List<CanvasItem *>::Element *E = p_other_nodes_exceptions.front(); E; E = E->next()) { + exceptions.push_back(E->get()); + } + if (p_self_canvas_item) { + exceptions.push_back(p_self_canvas_item); + to_snap_transform = p_self_canvas_item->get_global_transform_with_canvas(); + } + + _snap_other_nodes( + p_target, to_snap_transform, + output, snap_target, + SNAP_TARGET_OTHER_NODE, + exceptions, + get_tree()->get_edited_scene_root()); } if (((is_snap_active && snap_guides && (p_modes & SNAP_GUIDES)) || (p_forced_modes & SNAP_GUIDES)) && fmod(rotation, (real_t)360.0) == 0.0) { @@ -309,14 +366,14 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_"); for (int i = 0; i < vguides.size(); i++) { - _snap_if_closer_float(p_target.x, vguides[i], output.x, snapped[0]); + _snap_if_closer_float(p_target.x, output.x, snap_target[0], vguides[i], SNAP_TARGET_GUIDE); } } if (EditorNode::get_singleton()->get_edited_scene() && EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) { Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_"); for (int i = 0; i < hguides.size(); i++) { - _snap_if_closer_float(p_target.y, hguides[i], output.y, snapped[1]); + _snap_if_closer_float(p_target.y, output.y, snap_target[1], hguides[i], SNAP_TARGET_GUIDE); } } } @@ -335,7 +392,7 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const Point2 grid_output; grid_output.x = Math::stepify(p_target.x - offset.x, grid_step.x * Math::pow(2.0, grid_step_multiplier)) + offset.x; grid_output.y = Math::stepify(p_target.y - offset.y, grid_step.y * Math::pow(2.0, grid_step_multiplier)) + offset.y; - _snap_if_closer_point(p_target, grid_output, output, snapped, 0.0, -1.0); + _snap_if_closer_point(p_target, output, snap_target, grid_output, SNAP_TARGET_GRID, 0.0, -1.0); } if (((snap_pixel && (p_modes & SNAP_PIXEL)) || (p_forced_modes & SNAP_PIXEL)) && rotation == 0.0) { @@ -343,6 +400,8 @@ Point2 CanvasItemEditor::snap_point(Point2 p_target, unsigned int p_modes, const output = output.snapped(Size2(1, 1)); } + snap_transform = Transform2D(rotation, output); + return output; } @@ -1058,9 +1117,9 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve return false; } -bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { +bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bool p_already_accepted) { Ref<InputEventMouseButton> b = p_event; - if (b.is_valid()) { + if (b.is_valid() && !p_already_accepted) { bool pan_on_scroll = bool(EditorSettings::get_singleton()->get("editors/2d/scroll_to_pan")) && !b->get_control(); if (b->is_pressed() && b->get_button_index() == BUTTON_WHEEL_DOWN) { @@ -1162,14 +1221,14 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event) { } Ref<InputEventMagnifyGesture> magnify_gesture = p_event; - if (magnify_gesture.is_valid()) { + if (magnify_gesture.is_valid() && !p_already_accepted) { // Zoom gesture _zoom_on_position(zoom * magnify_gesture->get_factor(), magnify_gesture->get_position()); return true; } Ref<InputEventPanGesture> pan_gesture = p_event; - if (pan_gesture.is_valid()) { + if (pan_gesture.is_valid() && !p_already_accepted) { // Pan gesture const Vector2 delta = (int(EditorSettings::get_singleton()->get("editors/2d/pan_speed")) / zoom) * pan_gesture->get_delta(); view_offset.x += delta.x; @@ -1205,10 +1264,11 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { if (drag_selection.size() > 0) { drag_from = transform.affine_inverse().xform((b.is_valid()) ? b->get_position() : viewport->get_local_mouse_position()); Vector2 new_pos; - if (drag_selection.size() == 1) - new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); - else - new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); + if (drag_selection.size() == 1) { + new_pos = snap_point(drag_from, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); + } else { + new_pos = snap_point(drag_from, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, NULL, drag_selection); + } for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { CanvasItem *canvas_item = E->get(); canvas_item->_edit_set_pivot(canvas_item->get_global_transform_with_canvas().affine_inverse().xform(new_pos)); @@ -1228,7 +1288,7 @@ bool CanvasItemEditor::_gui_input_pivot(const Ref<InputEvent> &p_event) { _restore_canvas_item_state(drag_selection); Vector2 new_pos; if (drag_selection.size() == 1) - new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, drag_selection[0]); + new_pos = snap_point(drag_to, SNAP_NODE_SIDES | SNAP_NODE_CENTER | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, drag_selection[0]); else new_pos = snap_point(drag_to, SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL); for (List<CanvasItem *>::Element *E = drag_selection.front(); E; E = E->next()) { @@ -1478,7 +1538,7 @@ bool CanvasItemEditor::_gui_input_anchors(const Ref<InputEvent> &p_event) { previous_anchor.y = (drag_type == DRAG_ANCHOR_TOP_LEFT || drag_type == DRAG_ANCHOR_TOP_RIGHT) ? control->get_anchor(MARGIN_TOP) : control->get_anchor(MARGIN_BOTTOM); previous_anchor = xform.affine_inverse().xform(_anchor_to_position(control, previous_anchor)); - Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, control, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER)); + Vector2 new_anchor = xform.xform(snap_point(previous_anchor + (drag_to - drag_from), SNAP_GRID | SNAP_OTHER_NODES, SNAP_NODE_PARENT | SNAP_NODE_SIDES | SNAP_NODE_CENTER, control)); new_anchor = _position_to_anchor(control, new_anchor).snapped(Vector2(0.001, 0.001)); bool use_single_axis = m->get_shift(); @@ -1624,8 +1684,8 @@ bool CanvasItemEditor::_gui_input_resize(const Ref<InputEvent> &p_event) { Transform2D xform = canvas_item->get_global_transform_with_canvas().affine_inverse(); - Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); - Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, canvas_item); + Point2 drag_to_snapped_begin = snap_point(xform.affine_inverse().xform(current_begin) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); + Point2 drag_to_snapped_end = snap_point(xform.affine_inverse().xform(current_end) + (drag_to - drag_from), SNAP_NODE_ANCHORS | SNAP_NODE_PARENT | SNAP_OTHER_NODES | SNAP_GRID | SNAP_PIXEL, 0, canvas_item); Point2 drag_begin = xform.xform(drag_to_snapped_begin); Point2 drag_end = xform.xform(drag_to_snapped_end); @@ -1866,7 +1926,7 @@ bool CanvasItemEditor::_gui_input_move(const Ref<InputEvent> &p_event) { } else { previous_pos = _get_encompassing_rect_from_list(drag_selection).position; } - Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES); + Point2 new_pos = snap_point(previous_pos + (drag_to - drag_from), SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL | SNAP_NODE_PARENT | SNAP_NODE_ANCHORS | SNAP_OTHER_NODES, 0, NULL, drag_selection); bool single_axis = m->get_shift(); if (single_axis) { if (ABS(new_pos.x - previous_pos.x) > ABS(new_pos.y - previous_pos.y)) { @@ -2186,6 +2246,40 @@ bool CanvasItemEditor::_gui_input_select(const Ref<InputEvent> &p_event) { return false; } +bool CanvasItemEditor::_gui_input_ruler_tool(const Ref<InputEvent> &p_event) { + + if (tool != TOOL_RULER) + return false; + + Ref<InputEventMouseButton> b = p_event; + Ref<InputEventMouseMotion> m = p_event; + + Point2 previous_origin = ruler_tool_origin; + if (!ruler_tool_active) + ruler_tool_origin = snap_point(viewport->get_local_mouse_position() / zoom + view_offset) * zoom; + + if (b.is_valid() && b->get_button_index() == BUTTON_LEFT) { + if (b->is_pressed()) { + ruler_tool_active = true; + } else { + ruler_tool_active = false; + } + + viewport->update(); + return true; + } + + bool is_snap_active = snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); + + if (m.is_valid() && (ruler_tool_active || (is_snap_active && previous_origin != ruler_tool_origin))) { + + viewport->update(); + return true; + } + + return false; +} + bool CanvasItemEditor::_gui_input_hover(const Ref<InputEvent> &p_event) { Ref<InputEventMouseMotion> m = p_event; @@ -2263,12 +2357,14 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { //printf("Anchors\n"); } else if ((accepted = _gui_input_select(p_event))) { //printf("Selection\n"); + } else if ((accepted = _gui_input_ruler_tool(p_event))) { + //printf("Measure\n"); } else { //printf("Not accepted\n"); } } - accepted = (_gui_input_zoom_or_pan(p_event) || accepted); + accepted = (_gui_input_zoom_or_pan(p_event, accepted) || accepted); if (accepted) accept_event(); @@ -2290,6 +2386,9 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { case TOOL_PAN: c = CURSOR_DRAG; break; + case TOOL_RULER: + c = CURSOR_CROSS; + break; default: break; } @@ -2421,6 +2520,20 @@ void CanvasItemEditor::_draw_guides() { } } +void CanvasItemEditor::_draw_smart_snapping() { + Color line_color = EditorSettings::get_singleton()->get("editors/2d/smart_snapping_line_color"); + if (snap_target[0] != SNAP_TARGET_NONE && snap_target[0] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(0, -1.0e+10F), Point2(0, 1.0e+10F), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } + if (snap_target[1] != SNAP_TARGET_NONE && snap_target[1] != SNAP_TARGET_GRID) { + viewport->draw_set_transform_matrix(viewport->get_transform() * transform * snap_transform); + viewport->draw_line(Point2(-1.0e+10F, 0), Point2(1.0e+10F, 0), line_color); + viewport->draw_set_transform_matrix(viewport->get_transform()); + } +} + void CanvasItemEditor::_draw_rulers() { Color bg_color = get_color("dark_color_2", "Editor"); Color graduation_color = get_color("font_color", "Editor").linear_interpolate(bg_color, 0.5); @@ -2505,6 +2618,8 @@ void CanvasItemEditor::_draw_rulers() { } } } + + // Draw the top left corner viewport->draw_rect(Rect2(Point2(), Size2(RULER_WIDTH, RULER_WIDTH)), graduation_color); } @@ -2550,6 +2665,83 @@ void CanvasItemEditor::_draw_grid() { } } +void CanvasItemEditor::_draw_ruler_tool() { + + if (tool != TOOL_RULER) + return; + + bool is_snap_active = snap_active ^ Input::get_singleton()->is_key_pressed(KEY_CONTROL); + + if (ruler_tool_active) { + Color ruler_primary_color = get_color("accent_color", "Editor"); + Color ruler_secondary_color = ruler_primary_color; + ruler_secondary_color.a = 0.5; + + Point2 begin = ruler_tool_origin - view_offset * zoom; + Point2 end = snap_point(viewport->get_local_mouse_position() / zoom + view_offset) * zoom - view_offset * zoom; + Point2 corner = Point2(begin.x, end.y); + Vector2 length_vector = (begin - end).abs() / zoom; + + bool draw_secondary_lines = (begin.y != corner.y && end.x != corner.x); + + viewport->draw_line(begin, end, ruler_primary_color, Math::round(EDSCALE * 3), true); + if (draw_secondary_lines) { + viewport->draw_line(begin, corner, ruler_secondary_color, Math::round(EDSCALE)); + viewport->draw_line(corner, end, ruler_secondary_color, Math::round(EDSCALE)); + } + + Ref<Font> font = get_font("bold", "EditorFonts"); + Color font_color = get_color("font_color", "Editor"); + Color font_secondary_color = font_color; + font_secondary_color.a = 0.5; + float text_height = font->get_height(); + const float text_width = 76; + + Point2 text_pos = (begin + end) / 2 - Vector2(text_width / 2, text_height / 2); + text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5); + text_pos.y = CLAMP(text_pos.y, text_height * 1.5, viewport->get_rect().size.y - text_height * 1.5); + viewport->draw_string(font, text_pos, vformat("%.2f px", length_vector.length()), font_color); + + if (draw_secondary_lines) { + + Point2 text_pos2 = text_pos; + text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); + viewport->draw_string(font, text_pos2, vformat("%.2f px", length_vector.y), font_secondary_color); + + text_pos2 = text_pos; + text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y - text_height / 2) : MAX(text_pos.y + text_height * 2, end.y - text_height / 2); + viewport->draw_string(font, text_pos2, vformat("%.2f px", length_vector.x), font_secondary_color); + } + + if (is_snap_active) { + + text_pos = (begin + end) / 2 + Vector2(-text_width / 2, text_height / 2); + text_pos.x = CLAMP(text_pos.x, text_width / 2, viewport->get_rect().size.x - text_width * 1.5); + text_pos.y = CLAMP(text_pos.y, text_height * 2.5, viewport->get_rect().size.y - text_height / 2); + + if (draw_secondary_lines) { + viewport->draw_string(font, text_pos, vformat("%.2f units", (length_vector / grid_step).length()), font_color); + + Point2 text_pos2 = text_pos; + text_pos2.x = begin.x < text_pos.x ? MIN(text_pos.x - text_width, begin.x - text_width / 2) : MAX(text_pos.x + text_width, begin.x - text_width / 2); + viewport->draw_string(font, text_pos2, vformat("%d units", (int)(length_vector.y / grid_step.y)), font_secondary_color); + + text_pos2 = text_pos; + text_pos2.y = end.y < text_pos.y ? MIN(text_pos.y - text_height * 2, end.y + text_height / 2) : MAX(text_pos.y + text_height * 2, end.y + text_height / 2); + viewport->draw_string(font, text_pos2, vformat("%d units", (int)(length_vector.x / grid_step.x)), font_secondary_color); + } else { + viewport->draw_string(font, text_pos, vformat("%d units", roundf((length_vector / grid_step).length())), font_color); + } + } + } else { + + if (is_snap_active) { + Ref<Texture> position_icon = get_icon("EditorPosition", "EditorIcons"); + viewport->draw_texture(get_icon("EditorPosition", "EditorIcons"), ruler_tool_origin - view_offset * zoom - position_icon->get_size() / 2); + } + } +} + void CanvasItemEditor::_draw_control_anchors(Control *control) { Transform2D xform = transform * control->get_global_transform_with_canvas(); RID ci = viewport->get_canvas_item(); @@ -2623,7 +2815,7 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { if (dragged_anchor >= 0) { // Draw the 4 lines when dragged - bool snapped; + bool anchor_snapped; Color color_snapped = Color(0.64, 0.93, 0.67, 0.5); Vector2 corners_pos[4]; @@ -2637,14 +2829,8 @@ void CanvasItemEditor::_draw_control_helpers(Control *control) { float anchor_val = (i >= 2) ? ANCHOR_END - anchors_values[i] : anchors_values[i]; line_starts[i] = Vector2::linear_interpolate(corners_pos[i], corners_pos[(i + 1) % 4], anchor_val); line_ends[i] = Vector2::linear_interpolate(corners_pos[(i + 3) % 4], corners_pos[(i + 2) % 4], anchor_val); - snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; - int line_width; - if (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) { - line_width = 2; - } else { - line_width = 1; - } - viewport->draw_line(line_starts[i], line_ends[i], snapped ? color_snapped : color_base, Math::round(line_width * EDSCALE)); + anchor_snapped = anchors_values[i] == 0.0 || anchors_values[i] == 0.5 || anchors_values[i] == 1.0; + viewport->draw_line(line_starts[i], line_ends[i], anchor_snapped ? color_snapped : color_base, (i == dragged_anchor || (i + 3) % 4 == dragged_anchor) ? 2 : 1); } // Display the percentages next to the lines @@ -2918,10 +3104,15 @@ void CanvasItemEditor::_draw_selection() { Point2 bsfrom = transform.xform(drag_from); Point2 bsto = transform.xform(box_selecting_to); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, + viewport->draw_rect( + Rect2(bsfrom, bsto - bsfrom), + get_color("box_selection_fill_color", "Editor")); + + viewport->draw_rect( Rect2(bsfrom, bsto - bsfrom), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } if (drag_type == DRAG_ROTATE) { @@ -3283,6 +3474,7 @@ void CanvasItemEditor::_draw_viewport() { info_overlay->set_margin(MARGIN_LEFT, (show_rulers ? RULER_WIDTH : 0) + 10); _draw_grid(); + _draw_ruler_tool(); _draw_selection(); _draw_axis(); if (editor->get_edited_scene()) { @@ -3307,6 +3499,7 @@ void CanvasItemEditor::_draw_viewport() { _draw_rulers(); if (show_guides) _draw_guides(); + _draw_smart_snapping(); _draw_focus(); _draw_hover(); } @@ -3316,6 +3509,10 @@ void CanvasItemEditor::update_viewport() { viewport->update(); } +void CanvasItemEditor::set_current_tool(Tool p_tool) { + _button_tool_select(p_tool); +} + void CanvasItemEditor::_notification(int p_what) { if (p_what == NOTIFICATION_PHYSICS_PROCESS) { @@ -3466,6 +3663,7 @@ void CanvasItemEditor::_notification(int p_what) { snap_config_menu->set_icon(get_icon("GuiMiniTabMenu", "EditorIcons")); skeleton_menu->set_icon(get_icon("Bone", "EditorIcons")); pan_button->set_icon(get_icon("ToolPan", "EditorIcons")); + ruler_button->set_icon(get_icon("Ruler", "EditorIcons")); pivot_button->set_icon(get_icon("EditPivot", "EditorIcons")); select_handle = get_icon("EditorHandle", "EditorIcons"); anchor_handle = get_icon("EditorControlAnchor", "EditorIcons"); @@ -3480,7 +3678,6 @@ void CanvasItemEditor::_notification(int p_what) { key_auto_insert_button->set_icon(get_icon("AutoKey", "EditorIcons")); zoom_minus->set_icon(get_icon("ZoomLess", "EditorIcons")); - zoom_reset->set_icon(get_icon("ZoomReset", "EditorIcons")); zoom_plus->set_icon(get_icon("ZoomMore", "EditorIcons")); presets_menu->set_icon(get_icon("ControlLayout", "EditorIcons")); @@ -3838,11 +4035,24 @@ void CanvasItemEditor::_zoom_on_position(float p_zoom, Point2 p_position) { view_offset.x = Math::round(view_offset.x + ofs.x); view_offset.y = Math::round(view_offset.y + ofs.y); + _update_zoom_label(); update_viewport(); } +void CanvasItemEditor::_update_zoom_label() { + String zoom_text; + if (zoom >= 10) { + // Don't show a decimal when the zoom level is higher than 1000 % + zoom_text = rtos(Math::round(zoom * 100)) + " %"; + } else { + zoom_text = rtos(Math::stepify(zoom * 100, 0.1)) + " %"; + } + + zoom_reset->set_text(zoom_text); +} + void CanvasItemEditor::_button_zoom_minus() { - _zoom_on_position(zoom / 1.5, viewport_scrollable->get_size() / 2.0); + _zoom_on_position(zoom / Math_SQRT2, viewport_scrollable->get_size() / 2.0); } void CanvasItemEditor::_button_zoom_reset() { @@ -3850,7 +4060,7 @@ void CanvasItemEditor::_button_zoom_reset() { } void CanvasItemEditor::_button_zoom_plus() { - _zoom_on_position(zoom * 1.5, viewport_scrollable->get_size() / 2.0); + _zoom_on_position(zoom * Math_SQRT2, viewport_scrollable->get_size() / 2.0); } void CanvasItemEditor::_button_toggle_snap(bool p_status) { @@ -3860,13 +4070,13 @@ void CanvasItemEditor::_button_toggle_snap(bool p_status) { void CanvasItemEditor::_button_tool_select(int p_index) { - ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button }; + ToolButton *tb[TOOL_MAX] = { select_button, list_select_button, move_button, scale_button, rotate_button, pivot_button, pan_button, ruler_button }; for (int i = 0; i < TOOL_MAX; i++) { tb[i]->set_pressed(i == p_index); } - viewport->update(); tool = (Tool)p_index; + viewport->update(); } void CanvasItemEditor::_insert_animation_keys(bool p_location, bool p_rotation, bool p_scale, bool p_on_existing) { @@ -4349,6 +4559,27 @@ void CanvasItemEditor::_popup_callback(int p_op) { } } break; + case CLEAR_GUIDES: { + + if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_") || EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { + undo_redo->create_action(TTR("Clear Guides")); + if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) { + Array hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_"); + + undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", Array()); + undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides); + } + if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) { + Array vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_"); + + undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", Array()); + undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides); + } + undo_redo->add_undo_method(viewport, "update"); + undo_redo->commit_action(); + } + + } break; case VIEW_CENTER_TO_SELECTION: case VIEW_FRAME_TO_SELECTION: { @@ -4592,6 +4823,7 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { Dictionary state = p_state; if (state.has("zoom")) { zoom = p_state["zoom"]; + _update_zoom_label(); } if (state.has("ofs")) { @@ -4825,6 +5057,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { panning = false; pan_pressed = false; + ruler_tool_active = false; + ruler_tool_origin = Point2(); + bone_last_frame = 0; bone_list_dirty = false; @@ -4906,6 +5141,8 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_hb = memnew(HBoxContainer); viewport->add_child(zoom_hb); zoom_hb->set_begin(Point2(5, 5)); + // Bring the zoom percentage closer to the zoom buttons + zoom_hb->add_constant_override("separation", Math::round(-8 * EDSCALE)); zoom_minus = memnew(ToolButton); zoom_hb->add_child(zoom_minus); @@ -4918,6 +5155,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { zoom_reset->connect("pressed", this, "_button_zoom_reset"); zoom_reset->set_shortcut(ED_SHORTCUT("canvas_item_editor/zoom_reset", TTR("Zoom Reset"), KEY_MASK_CMD | KEY_0)); zoom_reset->set_focus_mode(FOCUS_NONE); + zoom_reset->set_text_align(Button::TextAlign::ALIGN_CENTER); + // Prevent the button's size from changing when the text size changes + zoom_reset->set_custom_minimum_size(Size2(75 * EDSCALE, 0)); zoom_plus = memnew(ToolButton); zoom_hb->add_child(zoom_plus); @@ -4978,6 +5218,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { pan_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_PAN)); pan_button->set_tooltip(TTR("Pan Mode")); + ruler_button = memnew(ToolButton); + hb->add_child(ruler_button); + ruler_button->set_toggle_mode(true); + ruler_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_RULER)); + ruler_button->set_shortcut(ED_SHORTCUT("canvas_item_editor/ruler_mode", TTR("Ruler Mode"), KEY_R)); + ruler_button->set_tooltip(TTR("Ruler Mode")); + hb->add_child(memnew(VSeparator)); snap_button = memnew(ToolButton); @@ -4998,11 +5245,13 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->set_hide_on_checkable_item_selection(false); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_grid", TTR("Snap to Grid")), SNAP_USE_GRID); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_rotation_snap", TTR("Use Rotation Snap")), SNAP_USE_ROTATION); - p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap...")), SNAP_CONFIGURE); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/snap_relative", TTR("Snap Relative")), SNAP_RELATIVE); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/use_pixel_snap", TTR("Use Pixel Snap")), SNAP_USE_PIXEL); p->add_submenu_item(TTR("Smart Snapping"), "SmartSnapping"); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/configure_snap", TTR("Configure Snap...")), SNAP_CONFIGURE); + smartsnap_config_popup = memnew(PopupMenu); p->add_child(smartsnap_config_popup); smartsnap_config_popup->set_name("SmartSnapping"); @@ -5068,7 +5317,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->set_hide_on_checkable_item_selection(false); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_grid", TTR("Show Grid"), KEY_G), SHOW_GRID); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_helpers", TTR("Show Helpers"), KEY_H), SHOW_HELPERS); - p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers"), KEY_R), SHOW_RULERS); + p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_rulers", TTR("Show Rulers"), KEY_MASK_CMD | KEY_R), SHOW_RULERS); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_origin", TTR("Show Origin")), SHOW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_viewport", TTR("Show Viewport")), SHOW_VIEWPORT); @@ -5077,6 +5326,7 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/frame_selection", TTR("Frame Selection"), KEY_MASK_SHIFT | KEY_F), VIEW_FRAME_TO_SELECTION); + p->add_shortcut(ED_SHORTCUT("canvas_item_editor/clear_guides", TTR("Clear Guides")), CLEAR_GUIDES); p->add_separator(); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale"), KEY_MASK_SHIFT | KEY_MASK_CMD | KEY_P), PREVIEW_CANVAS_SCALE); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 2a85b20424..6cce1ca10e 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -39,9 +39,6 @@ #include "scene/gui/label.h" #include "scene/gui/panel_container.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditorViewport; @@ -83,12 +80,24 @@ public: TOOL_ROTATE, TOOL_EDIT_PIVOT, TOOL_PAN, + TOOL_RULER, TOOL_MAX }; private: EditorNode *editor; + enum SnapTarget { + SNAP_TARGET_NONE = 0, + SNAP_TARGET_PARENT, + SNAP_TARGET_SELF_ANCHORS, + SNAP_TARGET_SELF, + SNAP_TARGET_OTHER_NODE, + SNAP_TARGET_GUIDE, + SNAP_TARGET_GRID, + SNAP_TARGET_PIXEL + }; + enum MenuOption { SNAP_USE, SNAP_USE_NODE_PARENT, @@ -170,6 +179,7 @@ private: ANIM_COPY_POSE, ANIM_PASTE_POSE, ANIM_CLEAR_POSE, + CLEAR_GUIDES, VIEW_CENTER_TO_SELECTION, VIEW_FRAME_TO_SELECTION, PREVIEW_CANVAS_SCALE, @@ -267,6 +277,9 @@ private: bool panning; bool pan_pressed; + bool ruler_tool_active; + Point2 ruler_tool_origin; + MenuOption last_option; struct _SelectResult { @@ -332,6 +345,8 @@ private: ToolButton *pivot_button; ToolButton *pan_button; + ToolButton *ruler_button; + ToolButton *snap_button; MenuButton *snap_config_menu; PopupMenu *smartsnap_config_popup; @@ -443,10 +458,12 @@ private: void _draw_percentage_at_position(float p_value, Point2 p_position, Margin p_side); void _draw_straight_line(Point2 p_from, Point2 p_to, Color p_color); + void _draw_smart_snapping(); void _draw_rulers(); void _draw_guides(); void _draw_focus(); void _draw_grid(); + void _draw_ruler_tool(); void _draw_control_anchors(Control *control); void _draw_control_helpers(Control *control); void _draw_selection(); @@ -466,7 +483,8 @@ private: bool _gui_input_resize(const Ref<InputEvent> &p_event); bool _gui_input_rotate(const Ref<InputEvent> &p_event); bool _gui_input_select(const Ref<InputEvent> &p_event); - bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event); + bool _gui_input_ruler_tool(const Ref<InputEvent> &p_event); + bool _gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bool p_already_accepted); bool _gui_input_rulers_and_guides(const Ref<InputEvent> &p_event); bool _gui_input_hover(const Ref<InputEvent> &p_event); @@ -478,9 +496,25 @@ private: void _solve_IK(Node2D *leaf_node, Point2 target_position); - void _snap_if_closer_float(float p_value, float p_target_snap, float &r_current_snap, bool &r_snapped, float p_radius = 10.0); - void _snap_if_closer_point(Point2 p_value, Point2 p_target_snap, Point2 &r_current_snap, bool (&r_snapped)[2], real_t rotation = 0.0, float p_radius = 10.0); - void _snap_other_nodes(Point2 p_value, Point2 &r_current_snap, bool (&r_snapped)[2], const Node *p_current, const CanvasItem *p_to_snap = NULL); + SnapTarget snap_target[2]; + Transform2D snap_transform; + void _snap_if_closer_float( + float p_value, + float &r_current_snap, SnapTarget &r_current_snap_target, + float p_target_value, SnapTarget p_snap_target, + float p_radius = 10.0); + void _snap_if_closer_point( + Point2 p_value, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + Point2 p_target_value, SnapTarget p_snap_target, + real_t rotation = 0.0, + float p_radius = 10.0); + void _snap_other_nodes( + const Point2 p_value, + const Transform2D p_transform_to_snap, + Point2 &r_current_snap, SnapTarget (&r_current_snap_target)[2], + const SnapTarget p_snap_target, List<const CanvasItem *> p_exceptions, + const Node *p_current); void _set_anchors_preset(Control::LayoutPreset p_preset); void _set_margins_preset(Control::LayoutPreset p_preset); @@ -491,6 +525,7 @@ private: HBoxContainer *zoom_hb; void _zoom_on_position(float p_zoom, Point2 p_position = Point2()); + void _update_zoom_label(); void _button_zoom_minus(); void _button_zoom_reset(); void _button_zoom_plus(); @@ -561,7 +596,7 @@ public: SNAP_DEFAULT = SNAP_GRID | SNAP_GUIDES | SNAP_PIXEL, }; - Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, const CanvasItem *p_canvas_item = NULL, unsigned int p_forced_modes = 0); + Point2 snap_point(Point2 p_target, unsigned int p_modes = SNAP_DEFAULT, unsigned int p_forced_modes = 0, const CanvasItem *p_self_canvas_item = NULL, List<CanvasItem *> p_other_nodes_exceptions = List<CanvasItem *>()); float snap_angle(float p_target, float p_start = 0) const; Transform2D get_canvas_transform() const { return transform; } @@ -584,6 +619,7 @@ public: void update_viewport(); Tool get_current_tool() { return tool; } + void set_current_tool(Tool p_tool); void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; } void edit(CanvasItem *p_canvas_item); diff --git a/editor/plugins/collision_polygon_2d_editor_plugin.h b/editor/plugins/collision_polygon_2d_editor_plugin.h index e15360d4e5..3f0734fb19 100644 --- a/editor/plugins/collision_polygon_2d_editor_plugin.h +++ b/editor/plugins/collision_polygon_2d_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/collision_polygon_2d.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CollisionPolygon2DEditor : public AbstractPolygon2DEditor { GDCLASS(CollisionPolygon2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/collision_polygon_editor_plugin.h b/editor/plugins/collision_polygon_editor_plugin.h index a699641aba..2a904a53ba 100644 --- a/editor/plugins/collision_polygon_editor_plugin.h +++ b/editor/plugins/collision_polygon_editor_plugin.h @@ -38,10 +38,6 @@ #include "scene/3d/mesh_instance.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class CanvasItemEditor; class Polygon3DEditor : public HBoxContainer { diff --git a/editor/plugins/cpu_particles_2d_editor_plugin.cpp b/editor/plugins/cpu_particles_2d_editor_plugin.cpp index 7c2116f06b..9d625af959 100644 --- a/editor/plugins/cpu_particles_2d_editor_plugin.cpp +++ b/editor/plugins/cpu_particles_2d_editor_plugin.cpp @@ -87,8 +87,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_EXPLAIN(TTR("Error loading image:") + " " + source_emission_file); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); if (img->is_compressed()) { img->decompress(); @@ -196,8 +195,7 @@ void CPUParticles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image...")); - ERR_FAIL_COND(valid_positions.size() == 0); + ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); if (capture_colors) { PoolColorArray pca; diff --git a/editor/plugins/curve_editor_plugin.cpp b/editor/plugins/curve_editor_plugin.cpp index 5d3cef4c34..c2b6031e60 100644 --- a/editor/plugins/curve_editor_plugin.cpp +++ b/editor/plugins/curve_editor_plugin.cpp @@ -167,10 +167,20 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { _has_undo_data = true; } + const float curve_amplitude = curve.get_max_value() - curve.get_min_value(); + // Snap to "round" coordinates when holding Ctrl. + // Be more precise when holding Shift as well. + float snap_threshold; + if (mm.get_control()) { + snap_threshold = mm.get_shift() ? 0.025 : 0.1; + } else { + snap_threshold = 0.0; + } + if (_selected_tangent == TANGENT_NONE) { // Drag point - Vector2 point_pos = get_world_pos(mpos); + Vector2 point_pos = get_world_pos(mpos).snapped(Vector2(snap_threshold, snap_threshold * curve_amplitude)); int i = curve.set_point_offset(_selected_point, point_pos.x); // The index may change if the point is dragged across another one @@ -188,8 +198,8 @@ void CurveEditor::on_gui_input(const Ref<InputEvent> &p_event) { } else { // Drag tangent - Vector2 point_pos = curve.get_point_position(_selected_point); - Vector2 control_pos = get_world_pos(mpos); + const Vector2 point_pos = curve.get_point_position(_selected_point); + const Vector2 control_pos = get_world_pos(mpos).snapped(Vector2(snap_threshold, snap_threshold * curve_amplitude)); Vector2 dir = (control_pos - point_pos).normalized(); diff --git a/editor/plugins/editor_preview_plugins.cpp b/editor/plugins/editor_preview_plugins.cpp index c8ffc2744a..8acc41a2c7 100644 --- a/editor/plugins/editor_preview_plugins.cpp +++ b/editor/plugins/editor_preview_plugins.cpp @@ -624,6 +624,7 @@ Ref<Texture> EditorAudioStreamPreviewPlugin::generate(const RES &p_from, const S uint8_t *imgw = imgdata.ptr(); Ref<AudioStreamPlayback> playback = stream->instance_playback(); + ERR_FAIL_COND_V(playback.is_null(), Ref<Texture>()); float len_s = stream->get_length(); if (len_s == 0) { diff --git a/editor/plugins/item_list_editor_plugin.h b/editor/plugins/item_list_editor_plugin.h index 701632e576..78b176620e 100644 --- a/editor/plugins/item_list_editor_plugin.h +++ b/editor/plugins/item_list_editor_plugin.h @@ -39,10 +39,6 @@ #include "scene/gui/option_button.h" #include "scene/gui/popup_menu.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class ItemListPlugin : public Object { GDCLASS(ItemListPlugin, Object); diff --git a/editor/plugins/light_occluder_2d_editor_plugin.h b/editor/plugins/light_occluder_2d_editor_plugin.h index 633fda7091..95fa0df2c1 100644 --- a/editor/plugins/light_occluder_2d_editor_plugin.h +++ b/editor/plugins/light_occluder_2d_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/light_occluder_2d.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class LightOccluder2DEditor : public AbstractPolygon2DEditor { GDCLASS(LightOccluder2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/multimesh_editor_plugin.cpp b/editor/plugins/multimesh_editor_plugin.cpp index d59efe49e7..3ea014a38d 100644 --- a/editor/plugins/multimesh_editor_plugin.cpp +++ b/editor/plugins/multimesh_editor_plugin.cpp @@ -147,9 +147,8 @@ void MultiMeshEditor::_populate() { w.release(); PoolVector<Face3> faces = geometry; - ERR_EXPLAIN(TTR("Parent has no solid faces to populate.")); int facecount = faces.size(); - ERR_FAIL_COND(!facecount); + ERR_FAIL_COND_MSG(!facecount, "Parent has no solid faces to populate."); PoolVector<Face3>::Read r = faces.read(); @@ -164,10 +163,8 @@ void MultiMeshEditor::_populate() { area_accum += area; } - ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(triangle_area_map.size() == 0); - ERR_EXPLAIN(TTR("Couldn't map area.")); - ERR_FAIL_COND(area_accum == 0); + ERR_FAIL_COND_MSG(triangle_area_map.size() == 0, "Couldn't map area."); + ERR_FAIL_COND_MSG(area_accum == 0, "Couldn't map area."); Ref<MultiMesh> multimesh = memnew(MultiMesh); multimesh->set_mesh(mesh); diff --git a/editor/plugins/multimesh_editor_plugin.h b/editor/plugins/multimesh_editor_plugin.h index fe87a2b9cb..5323441bd8 100644 --- a/editor/plugins/multimesh_editor_plugin.h +++ b/editor/plugins/multimesh_editor_plugin.h @@ -36,10 +36,6 @@ #include "scene/3d/multimesh_instance.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class MultiMeshEditor : public Control { GDCLASS(MultiMeshEditor, Control); diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 336c28d642..2a387a8b1e 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -34,9 +34,6 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/2d/navigation_polygon.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class NavigationPolygonEditor : public AbstractPolygon2DEditor { GDCLASS(NavigationPolygonEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/particles_2d_editor_plugin.cpp b/editor/plugins/particles_2d_editor_plugin.cpp index e68bca55cb..8025e12885 100644 --- a/editor/plugins/particles_2d_editor_plugin.cpp +++ b/editor/plugins/particles_2d_editor_plugin.cpp @@ -160,8 +160,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { Ref<Image> img; img.instance(); Error err = ImageLoader::load_image(source_emission_file, img); - ERR_EXPLAIN(TTR("Error loading image:") + " " + source_emission_file); - ERR_FAIL_COND(err != OK); + ERR_FAIL_COND_MSG(err != OK, "Error loading image: " + source_emission_file + "."); if (img->is_compressed()) { img->decompress(); @@ -269,8 +268,7 @@ void Particles2DEditorPlugin::_generate_emission_mask() { valid_normals.resize(vpc); } - ERR_EXPLAIN(TTR("No pixels with transparency > 128 in image...")); - ERR_FAIL_COND(valid_positions.size() == 0); + ERR_FAIL_COND_MSG(valid_positions.size() == 0, "No pixels with transparency > 128 in image..."); PoolVector<uint8_t> texdata; diff --git a/editor/plugins/particles_editor_plugin.cpp b/editor/plugins/particles_editor_plugin.cpp index 75d31459e8..31b0539bfe 100644 --- a/editor/plugins/particles_editor_plugin.cpp +++ b/editor/plugins/particles_editor_plugin.cpp @@ -55,8 +55,7 @@ bool ParticlesEditorBase::_generate(PoolVector<Vector3> &points, PoolVector<Vect if (!triangle_area_map.size() || area_accum == 0) { - err_dialog->set_text(TTR("Faces contain no area!")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(TTR("The geometry's faces don't contain any area.")); return false; } @@ -90,8 +89,7 @@ bool ParticlesEditorBase::_generate(PoolVector<Vector3> &points, PoolVector<Vect if (gcount == 0) { - err_dialog->set_text(TTR("No faces!")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(TTR("The geometry doesn't contain any faces.")); return false; } @@ -169,11 +167,16 @@ void ParticlesEditorBase::_node_selected(const NodePath &p_path) { if (!sel) return; + if (!sel->is_class("Spatial")) { + + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't inherit from Spatial."), sel->get_name())); + return; + } + VisualInstance *vi = Object::cast_to<VisualInstance>(sel); if (!vi) { - err_dialog->set_text(TTR("Node does not contain geometry.")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain geometry."), sel->get_name())); return; } @@ -181,8 +184,7 @@ void ParticlesEditorBase::_node_selected(const NodePath &p_path) { if (geometry.size() == 0) { - err_dialog->set_text(TTR("Node does not contain geometry (faces).")); - err_dialog->popup_centered_minsize(); + EditorNode::get_singleton()->show_warning(vformat(TTR("\"%s\" doesn't contain face geometry."), sel->get_name())); return; } @@ -231,9 +233,6 @@ ParticlesEditorBase::ParticlesEditorBase() { emission_dialog->get_ok()->set_text(TTR("Create")); emission_dialog->connect("confirmed", this, "_generate_emission_points"); - err_dialog = memnew(ConfirmationDialog); - add_child(err_dialog); - emission_file_dialog = memnew(EditorFileDialog); add_child(emission_file_dialog); emission_file_dialog->connect("file_selected", this, "_resource_seleted"); diff --git a/editor/plugins/particles_editor_plugin.h b/editor/plugins/particles_editor_plugin.h index 5d05fbd4ac..1b3a1877a4 100644 --- a/editor/plugins/particles_editor_plugin.h +++ b/editor/plugins/particles_editor_plugin.h @@ -36,10 +36,6 @@ #include "scene/3d/particles.h" #include "scene/gui/spin_box.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class ParticlesEditorBase : public Control { GDCLASS(ParticlesEditorBase, Control); @@ -53,8 +49,6 @@ protected: EditorFileDialog *emission_file_dialog; SceneTreeDialog *emission_tree_dialog; - ConfirmationDialog *err_dialog; - ConfirmationDialog *emission_dialog; SpinBox *emission_amount; OptionButton *emission_fill; diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index b87bd29cbd..f02dc0bd6d 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -367,18 +367,18 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node) + if (!node || !node->is_visible_in_tree() || !node->get_curve().is_valid()) return; - if (!node->is_visible_in_tree()) - return; + Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - if (!node->get_curve().is_valid()) - return; + const Ref<Texture> path_sharp_handle = get_icon("EditorPathSharpHandle", "EditorIcons"); + const Ref<Texture> path_smooth_handle = get_icon("EditorPathSmoothHandle", "EditorIcons"); + // Both handle icons must be of the same size + const Size2 handle_size = path_sharp_handle->get_size(); - Transform2D xform = canvas_item_editor->get_canvas_transform() * node->get_global_transform(); - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - Size2 handle_size = handle->get_size(); + const Ref<Texture> curve_handle = get_icon("EditorCurveHandle", "EditorIcons"); + const Size2 curve_handle_size = curve_handle->get_size(); Ref<Curve2D> curve = node->get_curve(); @@ -387,19 +387,35 @@ void Path2DEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { for (int i = 0; i < len; i++) { Vector2 point = xform.xform(curve->get_point_position(i)); - vpc->draw_texture_rect(handle, Rect2(point - handle_size * 0.5, handle_size), false, Color(1, 1, 1, 1)); + // Determines the point icon to be used + bool smooth = false; if (i < len - 1) { Vector2 pointout = xform.xform(curve->get_point_position(i) + curve->get_point_out(i)); - vpc->draw_line(point, pointout, Color(0.5, 0.5, 1.0, 0.8), 1.0); - vpc->draw_texture_rect(handle, Rect2(pointout - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); + if (point != pointout) { + smooth = true; + // Draw the line with a dark and light color to be visible on all backgrounds + vpc->draw_line(point, pointout, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointout, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_texture_rect(curve_handle, Rect2(pointout - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); + } } if (i > 0) { Vector2 pointin = xform.xform(curve->get_point_position(i) + curve->get_point_in(i)); - vpc->draw_line(point, pointin, Color(0.5, 0.5, 1.0, 0.8), 1.0); - vpc->draw_texture_rect(handle, Rect2(pointin - handle_size * 0.5, handle_size), false, Color(1, 0.5, 1, 0.3)); + if (point != pointin) { + smooth = true; + // Draw the line with a dark and light color to be visible on all backgrounds + vpc->draw_line(point, pointin, Color(0, 0, 0, 0.5), Math::round(EDSCALE), true); + vpc->draw_line(point, pointin, Color(1, 1, 1, 0.5), Math::round(EDSCALE), true); + vpc->draw_texture_rect(curve_handle, Rect2(pointin - curve_handle_size * 0.5, curve_handle_size), false, Color(1, 1, 1, 0.75)); + } } + + vpc->draw_texture_rect( + smooth ? path_smooth_handle : path_sharp_handle, + Rect2(point - handle_size * 0.5, handle_size), + false); } if (on_edge) { diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index 44472f7a81..ecec5f5253 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -36,9 +36,6 @@ #include "scene/2d/path_2d.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class CanvasItemEditor; class Path2DEditor : public HBoxContainer { diff --git a/editor/plugins/path_editor_plugin.cpp b/editor/plugins/path_editor_plugin.cpp index 1ae5acc5ff..2493380585 100644 --- a/editor/plugins/path_editor_plugin.cpp +++ b/editor/plugins/path_editor_plugin.cpp @@ -652,7 +652,6 @@ PathSpatialGizmoPlugin::PathSpatialGizmoPlugin() { Color path_color = EDITOR_DEF("editors/3d_gizmos/gizmo_colors/path", Color(0.5, 0.5, 1.0, 0.8)); create_material("path_material", path_color); - path_color.a = 0.4; - create_material("path_thin_material", path_color); + create_material("path_thin_material", Color(0.5, 0.5, 0.5)); create_handle_material("handles"); } diff --git a/editor/plugins/polygon_2d_editor_plugin.cpp b/editor/plugins/polygon_2d_editor_plugin.cpp index 59004a08c0..bd532a6418 100644 --- a/editor/plugins/polygon_2d_editor_plugin.cpp +++ b/editor/plugins/polygon_2d_editor_plugin.cpp @@ -1045,8 +1045,8 @@ void Polygon2DEditor::_uv_draw() { } } - Ref<Texture> handle = get_icon("EditorHandle", "EditorIcons"); - Ref<Texture> internal_handle = get_icon("EditorInternalHandle", "EditorIcons"); + // All UV points are sharp, so use the sharp handle icon + Ref<Texture> handle = get_icon("EditorPathSharpHandle", "EditorIcons"); Color poly_line_color = Color(0.9, 0.5, 0.5); if (polygons.size() || polygon_create.size()) { @@ -1120,7 +1120,8 @@ void Polygon2DEditor::_uv_draw() { if (i < uv_draw_max) { uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5); } else { - uv_edit_draw->draw_texture(internal_handle, mtx.xform(uvs[i]) - internal_handle->get_size() * 0.5); + // Internal vertex + uv_edit_draw->draw_texture(handle, mtx.xform(uvs[i]) - handle->get_size() * 0.5, Color(0.6, 0.8, 1)); } } } diff --git a/editor/plugins/polygon_2d_editor_plugin.h b/editor/plugins/polygon_2d_editor_plugin.h index 24ca2ea3f4..009501a70c 100644 --- a/editor/plugins/polygon_2d_editor_plugin.h +++ b/editor/plugins/polygon_2d_editor_plugin.h @@ -33,9 +33,7 @@ #include "editor/plugins/abstract_polygon_2d_editor.h" #include "scene/gui/scroll_container.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ + class Polygon2DEditor : public AbstractPolygon2DEditor { GDCLASS(Polygon2DEditor, AbstractPolygon2DEditor); diff --git a/editor/plugins/script_editor_plugin.cpp b/editor/plugins/script_editor_plugin.cpp index 9cf889c5b0..f79c9d5062 100644 --- a/editor/plugins/script_editor_plugin.cpp +++ b/editor/plugins/script_editor_plugin.cpp @@ -44,6 +44,7 @@ #include "editor/script_editor_debugger.h" #include "scene/main/viewport.h" #include "script_text_editor.h" +#include "text_editor.h" /*** SCRIPT EDITOR ****/ @@ -55,7 +56,7 @@ void ScriptEditorBase::_bind_methods() { ADD_SIGNAL(MethodInfo("request_open_script_at_line", PropertyInfo(Variant::OBJECT, "script"), PropertyInfo(Variant::INT, "line"))); ADD_SIGNAL(MethodInfo("request_save_history")); ADD_SIGNAL(MethodInfo("go_to_help", PropertyInfo(Variant::STRING, "what"))); - // TODO This signal is no use for VisualScript... + // TODO: This signal is no use for VisualScript. ADD_SIGNAL(MethodInfo("search_in_files_requested", PropertyInfo(Variant::STRING, "text"))); } @@ -204,11 +205,13 @@ void ScriptEditorQuickOpen::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - connect("confirmed", this, "_confirmed"); - search_box->set_right_icon(get_icon("Search", "EditorIcons")); search_box->set_clear_button_enabled(true); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + search_box->set_right_icon(get_icon("Search", "EditorIcons")); } break; case NOTIFICATION_EXIT_TREE: { disconnect("confirmed", this, "_confirmed"); @@ -241,6 +244,8 @@ ScriptEditorQuickOpen::ScriptEditorQuickOpen() { set_hide_on_ok(false); search_options->connect("item_activated", this, "_confirmed"); search_options->set_hide_root(true); + search_options->set_hide_folding(true); + search_options->add_constant_override("draw_guides", 1); } ///////////////////////////////// @@ -485,9 +490,6 @@ void ScriptEditor::_update_recent_scripts() { Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); recent_scripts->clear(); - recent_scripts->add_shortcut(ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T)); - recent_scripts->add_separator(); - String path; for (int i = 0; i < rc.size(); i++) { @@ -510,11 +512,6 @@ void ScriptEditor::_open_recent_script(int p_idx) { return; } - // take two for the open recent button - if (p_idx > 0) { - p_idx -= 2; - } - Array rc = EditorSettings::get_singleton()->get_project_metadata("recent_files", "scripts", Array()); ERR_FAIL_INDEX(p_idx, rc.size()); @@ -541,6 +538,14 @@ void ScriptEditor::_open_recent_script(int p_idx) { // if it's a path then it's most likely a deleted file not help } else if (path.find("::") != -1) { // built-in script + String res_path = path.get_slice("::", 0); + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + } + } else { + EditorNode::get_singleton()->load_resource(res_path); + } Ref<Script> script = ResourceLoader::load(path); if (script.is_valid()) { edit(script, true); @@ -579,6 +584,7 @@ void ScriptEditor::_close_tab(int p_idx, bool p_save, bool p_history_back) { Ref<Script> script = current->get_edited_resource(); if (script != NULL) { + previous_scripts.push_back(script->get_path()); notify_script_close(script); } } @@ -907,7 +913,7 @@ void ScriptEditor::_file_dialog_action(String p_file) { if (extensions.find(p_file.get_extension())) { Ref<Script> scr = ResourceLoader::load(p_file); if (!scr.is_valid()) { - editor->show_warning(TTR("Error: could not load file."), TTR("Error!")); + editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!")); file_dialog_option = -1; return; } @@ -920,7 +926,7 @@ void ScriptEditor::_file_dialog_action(String p_file) { Error error; Ref<TextFile> text_file = _load_text_file(p_file, &error); if (error != OK) { - editor->show_warning(TTR("Error could not load file."), TTR("Error!")); + editor->show_warning(TTR("Could not load file at:") + "\n\n" + p_file, TTR("Error!")); } if (text_file.is_valid()) { @@ -994,7 +1000,7 @@ void ScriptEditor::_menu_option(int p_option) { file_dialog->clear_filters(); file_dialog->popup_centered_ratio(); - file_dialog->set_title(TTR("New TextFile...")); + file_dialog->set_title(TTR("New Text File...")); } break; case FILE_OPEN: { file_dialog->set_mode(EditorFileDialog::MODE_OPEN_FILE); @@ -1012,6 +1018,56 @@ void ScriptEditor::_menu_option(int p_option) { file_dialog->set_title(TTR("Open File")); return; } break; + case FILE_REOPEN_CLOSED: { + + if (previous_scripts.empty()) + return; + + String path = previous_scripts.back()->get(); + previous_scripts.pop_back(); + + List<String> extensions; + ResourceLoader::get_recognized_extensions_for_type("Script", &extensions); + bool built_in = !path.is_resource_file(); + + if (extensions.find(path.get_extension()) || built_in) { + if (built_in) { + String res_path = path.get_slice("::", 0); + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + script_editor->call_deferred("_menu_option", p_option); + previous_scripts.push_back(path); //repeat the operation + return; + } + } else { + EditorNode::get_singleton()->load_resource(res_path); + } + } + + Ref<Script> scr = ResourceLoader::load(path); + if (!scr.is_valid()) { + editor->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!")); + file_dialog_option = -1; + return; + } + + edit(scr); + file_dialog_option = -1; + return; + } else { + Error error; + Ref<TextFile> text_file = _load_text_file(path, &error); + if (error != OK) + editor->show_warning(TTR("Could not load file at:") + "\n\n" + path, TTR("Error!")); + + if (text_file.is_valid()) { + edit(text_file); + file_dialog_option = -1; + return; + } + } + } break; case FILE_SAVE_ALL: { if (_test_script_times_on_disk()) @@ -1020,6 +1076,7 @@ void ScriptEditor::_menu_option(int p_option) { save_all_scripts(); } break; case SEARCH_IN_FILES: { + _on_find_in_files_requested(""); } break; case SEARCH_HELP: { @@ -1372,15 +1429,25 @@ void ScriptEditor::_notification(int p_what) { } EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); + FALLTHROUGH; + } + case NOTIFICATION_THEME_CHANGED: { + help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); site_search->set_icon(get_icon("Instance", "EditorIcons")); request_docs->set_icon(get_icon("Issue", "EditorIcons")); script_forward->set_icon(get_icon("Forward", "EditorIcons")); script_back->set_icon(get_icon("Back", "EditorIcons")); + members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons")); + filter_scripts->set_right_icon(get_icon("Search", "EditorIcons")); filter_methods->set_right_icon(get_icon("Search", "EditorIcons")); + + filename->add_style_override("normal", editor->get_gui_base()->get_stylebox("normal", "LineEdit")); + + recent_scripts->set_as_minsize(); } break; case NOTIFICATION_READY: { @@ -1403,20 +1470,6 @@ void ScriptEditor::_notification(int p_what) { _update_modified_scripts_for_external_editor(); } break; - case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - - help_search->set_icon(get_icon("HelpSearch", "EditorIcons")); - site_search->set_icon(get_icon("Instance", "EditorIcons")); - - script_forward->set_icon(get_icon("Forward", "EditorIcons")); - script_back->set_icon(get_icon("Back", "EditorIcons")); - - members_overview_alphabeta_sort_button->set_icon(get_icon("Sort", "EditorIcons")); - filename->add_style_override("normal", editor->get_gui_base()->get_stylebox("normal", "LineEdit")); - - recent_scripts->set_as_minsize(); - } break; - case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { @@ -1700,10 +1753,10 @@ void ScriptEditor::_update_help_overview() { void ScriptEditor::_update_script_colors() { - bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_enabled"); - bool highlight_current = EditorSettings::get_singleton()->get("text_editor/open_scripts/highlight_current_script"); + bool script_temperature_enabled = EditorSettings::get_singleton()->get("text_editor/script_list/script_temperature_enabled"); + bool highlight_current = EditorSettings::get_singleton()->get("text_editor/script_list/highlight_current_script"); - int hist_size = EditorSettings::get_singleton()->get("text_editor/open_scripts/script_temperature_history_size"); + int hist_size = EditorSettings::get_singleton()->get("text_editor/script_list/script_temperature_history_size"); Color hot_color = get_color("accent_color", "Editor"); Color cold_color = get_color("font_color", "Editor"); @@ -1718,7 +1771,7 @@ void ScriptEditor::_update_script_colors() { bool current = tab_container->get_current_tab() == c; if (current && highlight_current) { - script_list->set_item_custom_bg_color(i, EditorSettings::get_singleton()->get("text_editor/open_scripts/current_script_background_color")); + script_list->set_item_custom_bg_color(i, EditorSettings::get_singleton()->get("text_editor/script_list/current_script_background_color")); } else if (script_temperature_enabled) { @@ -1751,9 +1804,9 @@ void ScriptEditor::_update_script_names() { } script_list->clear(); - bool split_script_help = EditorSettings::get_singleton()->get("text_editor/open_scripts/group_help_pages"); - ScriptSortBy sort_by = (ScriptSortBy)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/sort_scripts_by"); - ScriptListName display_as = (ScriptListName)(int)EditorSettings::get_singleton()->get("text_editor/open_scripts/list_script_names_as"); + bool split_script_help = EditorSettings::get_singleton()->get("text_editor/script_list/group_help_pages"); + ScriptSortBy sort_by = (ScriptSortBy)(int)EditorSettings::get_singleton()->get("text_editor/script_list/sort_scripts_by"); + ScriptListName display_as = (ScriptListName)(int)EditorSettings::get_singleton()->get("text_editor/script_list/list_script_names_as"); Vector<_ScriptEditorItemData> sedata; @@ -1894,6 +1947,8 @@ void ScriptEditor::_update_script_names() { _update_members_overview_visibility(); _update_help_overview_visibility(); _update_script_colors(); + + file_menu->get_popup()->set_item_disabled(file_menu->get_popup()->get_item_index(FILE_REOPEN_CLOSED), previous_scripts.empty()); } void ScriptEditor::_update_script_connections() { @@ -2275,7 +2330,7 @@ void ScriptEditor::_editor_settings_changed() { 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"); - members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); + 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"); _update_members_overview_visibility(); _update_help_overview_visibility(); @@ -2939,18 +2994,38 @@ void ScriptEditor::_on_find_in_files_requested(String text) { void ScriptEditor::_on_find_in_files_result_selected(String fpath, int line_number, int begin, int end) { - RES res = ResourceLoader::load(fpath); - if (fpath.get_extension() == "shader") { - ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); - shader_editor->edit(res.ptr()); - shader_editor->make_visible(true); - shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); - } else { - edit(res); + if (ResourceLoader::exists(fpath)) { + RES res = ResourceLoader::load(fpath); - ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); - if (ste) { - ste->goto_line_selection(line_number - 1, begin, end); + if (fpath.get_extension() == "shader") { + ShaderEditorPlugin *shader_editor = Object::cast_to<ShaderEditorPlugin>(EditorNode::get_singleton()->get_editor_data().get_editor("Shader")); + shader_editor->edit(res.ptr()); + shader_editor->make_visible(true); + shader_editor->get_shader_editor()->goto_line_selection(line_number - 1, begin, end); + return; + } else { + Ref<Script> script = res; + if (script.is_valid()) { + edit(script); + + ScriptTextEditor *ste = Object::cast_to<ScriptTextEditor>(_get_current_editor()); + if (ste) { + ste->goto_line_selection(line_number - 1, begin, end); + } + return; + } + } + } + + // If the file is not a valid resource/script, load it as a text file. + Error err; + Ref<TextFile> text_file = _load_text_file(fpath, &err); + if (text_file.is_valid()) { + edit(text_file); + + TextEditor *te = Object::cast_to<TextEditor>(_get_current_editor()); + if (te) { + te->goto_line_selection(line_number - 1, begin, end); } } } @@ -3066,7 +3141,7 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { waiting_update_names = false; pending_auto_reload = false; auto_reload_running_scripts = true; - members_overview_enabled = EditorSettings::get_singleton()->get("text_editor/open_scripts/show_members_overview"); + 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"); editor = p_editor; @@ -3170,8 +3245,9 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { file_menu->set_switch_on_hover(true); file_menu->get_popup()->set_hide_on_window_lose_focus(true); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new", TTR("New Script...")), FILE_NEW); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New TextFile...")), FILE_NEW_TEXTFILE); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/new_textfile", TTR("New Text File...")), FILE_NEW_TEXTFILE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/open", TTR("Open...")), FILE_OPEN); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/reopen_closed_script", TTR("Reopen Closed Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T), FILE_REOPEN_CLOSED); file_menu->get_popup()->add_submenu_item(TTR("Open Recent"), "RecentScripts", FILE_OPEN_RECENT); recent_scripts = memnew(PopupMenu); @@ -3202,17 +3278,20 @@ ScriptEditor::ScriptEditor(EditorNode *p_editor) { theme_submenu->connect("id_pressed", this, "_theme_option"); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/import_theme", TTR("Import Theme...")), THEME_IMPORT); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/reload_theme", TTR("Reload Theme")), THEME_RELOAD); + theme_submenu->add_separator(); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme", TTR("Save Theme")), THEME_SAVE); theme_submenu->add_shortcut(ED_SHORTCUT("script_editor/save_theme_as", TTR("Save Theme As...")), THEME_SAVE_AS); file_menu->get_popup()->add_separator(); - file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_file", TTR("Close"), KEY_MASK_CMD | KEY_W), FILE_CLOSE); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_all", TTR("Close All")), CLOSE_ALL); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_other_tabs", TTR("Close Other Tabs")), CLOSE_OTHER_TABS); + file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/close_docs", TTR("Close Docs")), CLOSE_DOCS); + file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/run_file", TTR("Run"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_X), FILE_RUN); + file_menu->get_popup()->add_separator(); file_menu->get_popup()->add_shortcut(ED_SHORTCUT("script_editor/toggle_scripts_panel", TTR("Toggle Scripts Panel"), KEY_MASK_CMD | KEY_BACKSLASH), TOGGLE_SCRIPTS_PANEL); file_menu->get_popup()->connect("id_pressed", this, "_menu_option"); @@ -3392,15 +3471,18 @@ void ScriptEditorPlugin::edit(Object *p_object) { if (Object::cast_to<Script>(p_object)) { Script *p_script = Object::cast_to<Script>(p_object); - String scene_path = p_script->get_path().get_slice("::", 0); + String res_path = p_script->get_path().get_slice("::", 0); - if (_is_built_in_script(p_script) && !EditorNode::get_singleton()->is_scene_open(scene_path)) { - EditorNode::get_singleton()->load_scene(scene_path); - - script_editor->call_deferred("edit", p_script); - } else { - script_editor->edit(p_script); + if (_is_built_in_script(p_script)) { + if (ResourceLoader::get_resource_type(res_path) == "PackedScene") { + if (!EditorNode::get_singleton()->is_scene_open(res_path)) { + EditorNode::get_singleton()->load_scene(res_path); + } + } else { + EditorNode::get_singleton()->load_resource(res_path); + } } + script_editor->edit(p_script); } else if (Object::cast_to<TextFile>(p_object)) { script_editor->edit(Object::cast_to<TextFile>(p_object)); } @@ -3487,21 +3569,21 @@ ScriptEditorPlugin::ScriptEditorPlugin(EditorNode *p_node) { EDITOR_DEF("text_editor/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/open_scripts/script_temperature_enabled", true); - EDITOR_DEF("text_editor/open_scripts/highlight_current_script", true); - EDITOR_DEF("text_editor/open_scripts/script_temperature_history_size", 15); - EDITOR_DEF("text_editor/open_scripts/current_script_background_color", Color(1, 1, 1, 0.3)); - EDITOR_DEF("text_editor/open_scripts/group_help_pages", true); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path,None")); - EDITOR_DEF("text_editor/open_scripts/sort_scripts_by", 0); - EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/open_scripts/list_script_names_as", PROPERTY_HINT_ENUM, "Name,Parent Directory And Name,Full Path")); - EDITOR_DEF("text_editor/open_scripts/list_script_names_as", 0); + EDITOR_DEF("text_editor/script_list/script_temperature_enabled", true); + EDITOR_DEF("text_editor/script_list/highlight_current_script", true); + EDITOR_DEF("text_editor/script_list/script_temperature_history_size", 15); + EDITOR_DEF("text_editor/script_list/current_script_background_color", Color(1, 1, 1, 0.3)); + EDITOR_DEF("text_editor/script_list/group_help_pages", true); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/script_list/sort_scripts_by", PROPERTY_HINT_ENUM, "Name,Path,None")); + EDITOR_DEF("text_editor/script_list/sort_scripts_by", 0); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "text_editor/script_list/list_script_names_as", PROPERTY_HINT_ENUM, "Name,Parent Directory And Name,Full Path")); + EDITOR_DEF("text_editor/script_list/list_script_names_as", 0); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_path", PROPERTY_HINT_GLOBAL_FILE)); EDITOR_DEF("text_editor/external/exec_flags", "{file}"); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::STRING, "text_editor/external/exec_flags", PROPERTY_HINT_PLACEHOLDER_TEXT, "Call flags with placeholders: {project}, {file}, {col}, {line}.")); - ED_SHORTCUT("script_editor/open_recent", TTR("Open Recent"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T); - ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Files")); + ED_SHORTCUT("script_editor/reopen_closed_script", TTR("Reopen Closed Script"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_T); + ED_SHORTCUT("script_editor/clear_recent", TTR("Clear Recent Scripts")); } ScriptEditorPlugin::~ScriptEditorPlugin() { diff --git a/editor/plugins/script_editor_plugin.h b/editor/plugins/script_editor_plugin.h index 4ad2156779..0c876108a5 100644 --- a/editor/plugins/script_editor_plugin.h +++ b/editor/plugins/script_editor_plugin.h @@ -139,6 +139,7 @@ class ScriptEditor : public PanelContainer { FILE_NEW, FILE_NEW_TEXTFILE, FILE_OPEN, + FILE_REOPEN_CLOSED, FILE_OPEN_RECENT, FILE_SAVE, FILE_SAVE_AS, @@ -265,7 +266,7 @@ class ScriptEditor : public PanelContainer { Vector<ScriptHistory> history; int history_pos; - Vector<String> previous_scripts; + List<String> previous_scripts; void _tab_changed(int p_which); void _menu_option(int p_option); diff --git a/editor/plugins/script_text_editor.cpp b/editor/plugins/script_text_editor.cpp index 07303da2ff..073e6f74e9 100644 --- a/editor/plugins/script_text_editor.cpp +++ b/editor/plugins/script_text_editor.cpp @@ -30,6 +30,7 @@ #include "script_text_editor.h" +#include "core/math/expression.h" #include "core/os/keyboard.h" #include "editor/editor_node.h" #include "editor/editor_settings.h" @@ -1147,6 +1148,32 @@ void ScriptTextEditor::_edit_option(int p_op) { _convert_case(CodeTextEditor::CAPITALIZE); } break; + case EDIT_EVALUATE: { + + Expression expression; + Vector<String> lines = code_editor->get_text_edit()->get_selection_text().split("\n"); + PoolStringArray results; + + for (int i = 0; i < lines.size(); i++) { + String line = lines[i]; + String whitespace = line.substr(0, line.size() - line.strip_edges(true, false).size()); //extract the whitespace at the beginning + + if (expression.parse(line) == OK) { + Variant result = expression.execute(Array(), Variant(), false); + if (expression.get_error_text() == "") { + results.append(whitespace + (String)result); + } else { + results.append(line); + } + } else { + results.append(line); + } + } + + code_editor->get_text_edit()->begin_complex_operation(); //prevents creating a two-step undo + code_editor->get_text_edit()->insert_text_at_cursor(results.join("\n")); + code_editor->get_text_edit()->end_complex_operation(); + } break; case SEARCH_FIND: { code_editor->get_find_replace_bar()->popup_search(); @@ -1170,7 +1197,6 @@ void ScriptTextEditor::_edit_option(int p_op) { // Yep, because it doesn't make sense to instance this dialog for every single script open... // So this will be delegated to the ScriptEditor. emit_signal("search_in_files_requested", selected_text); - } break; case SEARCH_LOCATE_FUNCTION: { @@ -1410,8 +1436,6 @@ bool ScriptTextEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_ return false; } -#ifdef TOOLS_ENABLED - static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { if (p_edited_scene != p_current_node && p_current_node->get_owner() != p_edited_scene) @@ -1431,14 +1455,6 @@ static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const return NULL; } -#else - -static Node *_find_script_node(Node *p_edited_scene, Node *p_current_node, const Ref<Script> &script) { - - return NULL; -} -#endif - void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { Dictionary d = p_data; @@ -1516,91 +1532,98 @@ void ScriptTextEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data void ScriptTextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { Ref<InputEventMouseButton> mb = ev; + Ref<InputEventKey> k = ev; + Point2 local_pos; + bool create_menu = false; - if (mb.is_valid()) { - - if (mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { - int col, row; - TextEdit *tx = code_editor->get_text_edit(); - tx->_get_mouse_pos(mb->get_global_position() - tx->get_global_position(), row, col); - Vector2 mpos = mb->get_global_position() - tx->get_global_position(); - - tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); - if (tx->is_right_click_moving_caret()) { - if (tx->is_selection_active()) { + TextEdit *tx = code_editor->get_text_edit(); + if (mb.is_valid() && mb->get_button_index() == BUTTON_RIGHT && mb->is_pressed()) { + local_pos = mb->get_global_position() - tx->get_global_position(); + create_menu = true; + } else if (k.is_valid() && k->get_scancode() == KEY_MENU) { + local_pos = tx->_get_cursor_pixel_pos(); + create_menu = true; + } - int from_line = tx->get_selection_from_line(); - int to_line = tx->get_selection_to_line(); - int from_column = tx->get_selection_from_column(); - int to_column = tx->get_selection_to_column(); + if (create_menu) { + int col, row; + tx->_get_mouse_pos(local_pos, row, col); - if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { - // Right click is outside the selected text - tx->deselect(); - } - } - if (!tx->is_selection_active()) { - tx->cursor_set_line(row, true, false); - tx->cursor_set_column(col); + tx->set_right_click_moves_caret(EditorSettings::get_singleton()->get("text_editor/cursor/right_click_moves_caret")); + if (tx->is_right_click_moving_caret()) { + if (tx->is_selection_active()) { + int from_line = tx->get_selection_from_line(); + int to_line = tx->get_selection_to_line(); + int from_column = tx->get_selection_from_column(); + int to_column = tx->get_selection_to_column(); + + if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { + // Right click is outside the selected text + tx->deselect(); } } + if (!tx->is_selection_active()) { + tx->cursor_set_line(row, true, false); + tx->cursor_set_column(col); + } + } - String word_at_mouse = tx->get_word_at_pos(mpos); - if (word_at_mouse == "") - word_at_mouse = tx->get_word_under_cursor(); - if (word_at_mouse == "") - word_at_mouse = tx->get_selection_text(); + String word_at_pos = tx->get_word_at_pos(local_pos); + if (word_at_pos == "") + word_at_pos = tx->get_word_under_cursor(); + if (word_at_pos == "") + word_at_pos = tx->get_selection_text(); - bool has_color = (word_at_mouse == "Color"); - bool foldable = tx->can_fold(row) || tx->is_folded(row); - bool open_docs = false; - bool goto_definition = false; + bool has_color = (word_at_pos == "Color"); + bool foldable = tx->can_fold(row) || tx->is_folded(row); + bool open_docs = false; + bool goto_definition = false; - if (word_at_mouse.is_resource_file()) { + if (word_at_pos.is_resource_file()) { + open_docs = true; + } else { + Node *base = get_tree()->get_edited_scene_root(); + if (base) { + base = _find_node_for_script(base, base, script); + } + ScriptLanguage::LookupResult result; + if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), word_at_pos, script->get_path(), base, result) == OK) { open_docs = true; - } else { - - Node *base = get_tree()->get_edited_scene_root(); - if (base) { - base = _find_node_for_script(base, base, script); - } - ScriptLanguage::LookupResult result; - if (script->get_language()->lookup_code(code_editor->get_text_edit()->get_text_for_lookup_completion(), word_at_mouse, script->get_path(), base, result) == OK) { - open_docs = true; - } } + } - if (has_color) { - String line = tx->get_line(row); - color_line = row; - int begin = 0; - int end = 0; - bool valid = false; - for (int i = col; i < line.length(); i++) { - if (line[i] == '(') { - begin = i; - continue; - } else if (line[i] == ')') { - end = i + 1; - valid = true; - break; - } + if (has_color) { + String line = tx->get_line(row); + color_position.x = row; + color_position.y = col; + + int begin = 0; + int end = 0; + bool valid = false; + for (int i = col; i < line.length(); i++) { + if (line[i] == '(') { + begin = i; + continue; + } else if (line[i] == ')') { + end = i + 1; + valid = true; + break; } - if (valid) { - color_args = line.substr(begin, end - begin); - String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); - Vector<float> color = stripped.split_floats(","); - if (color.size() > 2) { - float alpha = color.size() > 3 ? color[3] : 1.0f; - color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); - } - color_panel->set_position(get_global_transform().xform(get_local_mouse_position())); - } else { - has_color = false; + } + if (valid) { + color_args = line.substr(begin, end - begin); + String stripped = color_args.replace(" ", "").replace("(", "").replace(")", ""); + Vector<float> color = stripped.split_floats(","); + if (color.size() > 2) { + float alpha = color.size() > 3 ? color[3] : 1.0f; + color_picker->set_pick_color(Color(color[0], color[1], color[2], alpha)); } + color_panel->set_position(get_global_transform().xform(local_pos)); + } else { + has_color = false; } - _make_context_menu(tx->is_selection_active(), has_color, foldable, open_docs, goto_definition); } + _make_context_menu(tx->is_selection_active(), has_color, foldable, open_docs, goto_definition, local_pos); } } @@ -1612,25 +1635,33 @@ void ScriptTextEditor::_color_changed(const Color &p_color) { new_args = String("(" + rtos(p_color.r) + ", " + rtos(p_color.g) + ", " + rtos(p_color.b) + ", " + rtos(p_color.a) + ")"); } - String line = code_editor->get_text_edit()->get_line(color_line); - String new_line = line.replace(color_args, new_args); + String line = code_editor->get_text_edit()->get_line(color_position.x); + int color_args_pos = line.find(color_args, color_position.y); + String line_with_replaced_args = line; + line_with_replaced_args.erase(color_args_pos, color_args.length()); + line_with_replaced_args = line_with_replaced_args.insert(color_args_pos, new_args); + color_args = new_args; - code_editor->get_text_edit()->set_line(color_line, new_line); + code_editor->get_text_edit()->begin_complex_operation(); + code_editor->get_text_edit()->set_line(color_position.x, line_with_replaced_args); + code_editor->get_text_edit()->end_complex_operation(); + code_editor->get_text_edit()->update(); } -void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition) { +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(); - if (p_selection) { - context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); - context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY); - } + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); + context_menu->add_separator(); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/cut"), EDIT_CUT); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/copy"), EDIT_COPY); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/paste"), EDIT_PASTE); + context_menu->add_separator(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/select_all"), EDIT_SELECT_ALL); - context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); - context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); + context_menu->add_separator(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_left"), EDIT_INDENT_LEFT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/indent_right"), EDIT_INDENT_RIGHT); @@ -1641,6 +1672,7 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p context_menu->add_separator(); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_uppercase"), EDIT_TO_UPPERCASE); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_to_lowercase"), EDIT_TO_LOWERCASE); + context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); } if (p_foldable) context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); @@ -1653,7 +1685,7 @@ void ScriptTextEditor::_make_context_menu(bool p_selection, bool p_color, bool p context_menu->add_item(TTR("Pick Color"), EDIT_PICK_COLOR); } - context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); + context_menu->set_position(get_global_transform().xform(p_pos)); context_menu->set_size(Vector2(1, 1)); context_menu->popup(); } @@ -1710,9 +1742,17 @@ ScriptTextEditor::ScriptTextEditor() { color_panel = memnew(PopupPanel); add_child(color_panel); color_picker = memnew(ColorPicker); + color_picker->set_deferred_mode(true); color_panel->add_child(color_picker); color_picker->connect("color_changed", this, "_color_changed"); + // get default color picker mode from editor settings + int default_color_mode = EDITOR_GET("interface/inspector/default_color_picker_mode"); + if (default_color_mode == 1) + color_picker->set_hsv_mode(true); + else if (default_color_mode == 2) + color_picker->set_raw_mode(true); + edit_hb = memnew(HBoxContainer); edit_menu = memnew(MenuButton); @@ -1740,6 +1780,7 @@ ScriptTextEditor::ScriptTextEditor() { edit_menu->get_popup()->add_separator(); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/clone_down"), EDIT_CLONE_DOWN); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/complete_symbol"), EDIT_COMPLETE); + edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/evaluate_selection"), EDIT_EVALUATE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/trim_trailing_whitespace"), EDIT_TRIM_TRAILING_WHITESAPCE); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_spaces"), EDIT_CONVERT_INDENT_TO_SPACES); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/convert_indent_to_tabs"), EDIT_CONVERT_INDENT_TO_TABS); @@ -1776,11 +1817,7 @@ ScriptTextEditor::ScriptTextEditor() { search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - search_menu->get_popup()->add_separator(); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/contextual_help"), HELP_CONTEXTUAL); - search_menu->get_popup()->connect("id_pressed", this, "_edit_option"); edit_hb->add_child(edit_menu); @@ -1789,6 +1826,11 @@ ScriptTextEditor::ScriptTextEditor() { edit_hb->add_child(goto_menu); goto_menu->set_text(TTR("Go To")); goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_function"), SEARCH_LOCATE_FUNCTION); + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); bookmarks_menu = memnew(PopupMenu); bookmarks_menu->set_name("Bookmarks"); @@ -1848,16 +1890,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/move_down", TTR("Move Down"), KEY_MASK_ALT | KEY_DOWN); ED_SHORTCUT("script_text_editor/delete_line", TTR("Delete Line"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_K); - //leave these at zero, same can be accomplished with tab/shift-tab, including selection - //the next/previous in history shortcut in this case makes a lot more sene. + // Leave these at zero, same can be accomplished with tab/shift-tab, including selection. + // The next/previous in history shortcut in this case makes a lot more sense. ED_SHORTCUT("script_text_editor/indent_left", TTR("Indent Left"), 0); ED_SHORTCUT("script_text_editor/indent_right", TTR("Indent Right"), 0); ED_SHORTCUT("script_text_editor/toggle_comment", TTR("Toggle Comment"), KEY_MASK_CMD | KEY_K); - ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); - ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); - ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); - ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); ED_SHORTCUT("script_text_editor/toggle_fold_line", TTR("Fold/Unfold Line"), KEY_MASK_ALT | KEY_F); ED_SHORTCUT("script_text_editor/fold_all_lines", TTR("Fold All Lines"), 0); ED_SHORTCUT("script_text_editor/unfold_all_lines", TTR("Unfold All Lines"), 0); @@ -1868,20 +1906,12 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/clone_down", TTR("Clone Down"), KEY_MASK_CMD | KEY_D); ED_SHORTCUT("script_text_editor/complete_symbol", TTR("Complete Symbol"), KEY_MASK_CMD | KEY_SPACE); #endif + ED_SHORTCUT("script_text_editor/evaluate_selection", TTR("Evaluate Selection"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_E); ED_SHORTCUT("script_text_editor/trim_trailing_whitespace", TTR("Trim Trailing Whitespace"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_T); ED_SHORTCUT("script_text_editor/convert_indent_to_spaces", TTR("Convert Indent to Spaces"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_Y); ED_SHORTCUT("script_text_editor/convert_indent_to_tabs", TTR("Convert Indent to Tabs"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_I); ED_SHORTCUT("script_text_editor/auto_indent", TTR("Auto Indent"), KEY_MASK_CMD | KEY_I); -#ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); -#else - ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); -#endif - ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); - ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); - ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); - ED_SHORTCUT("script_text_editor/find", TTR("Find..."), KEY_MASK_CMD | KEY_F); #ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/find_next", TTR("Find Next"), KEY_MASK_CMD | KEY_G); @@ -1896,6 +1926,17 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/find_in_files", TTR("Find in Files..."), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F); #ifdef OSX_ENABLED + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); +#else + ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); +#endif + + ED_SHORTCUT("script_text_editor/toggle_bookmark", TTR("Toggle Bookmark"), KEY_MASK_CMD | KEY_MASK_ALT | KEY_B); + ED_SHORTCUT("script_text_editor/goto_next_bookmark", TTR("Go to Next Bookmark"), KEY_MASK_CMD | KEY_B); + ED_SHORTCUT("script_text_editor/goto_previous_bookmark", TTR("Go to Previous Bookmark"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); + ED_SHORTCUT("script_text_editor/remove_all_bookmarks", TTR("Remove All Bookmarks"), 0); + +#ifdef OSX_ENABLED ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_CTRL | KEY_MASK_CMD | KEY_J); #else ED_SHORTCUT("script_text_editor/goto_function", TTR("Go to Function..."), KEY_MASK_ALT | KEY_MASK_CMD | KEY_F); @@ -1903,10 +1944,13 @@ void ScriptTextEditor::register_editor() { ED_SHORTCUT("script_text_editor/goto_line", TTR("Go to Line..."), KEY_MASK_CMD | KEY_L); #ifdef OSX_ENABLED - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_MASK_SHIFT | KEY_SPACE); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_B); #else - ED_SHORTCUT("script_text_editor/contextual_help", TTR("Contextual Help"), KEY_MASK_ALT | KEY_F1); + ED_SHORTCUT("script_text_editor/toggle_breakpoint", TTR("Toggle Breakpoint"), KEY_F9); #endif + ED_SHORTCUT("script_text_editor/remove_all_breakpoints", TTR("Remove All Breakpoints"), KEY_MASK_CMD | KEY_MASK_SHIFT | KEY_F9); + ED_SHORTCUT("script_text_editor/goto_next_breakpoint", TTR("Go to Next Breakpoint"), KEY_MASK_CMD | KEY_PERIOD); + ED_SHORTCUT("script_text_editor/goto_previous_breakpoint", TTR("Go to Previous Breakpoint"), KEY_MASK_CMD | KEY_COMMA); ScriptEditor::register_create_script_editor_function(create_editor); } diff --git a/editor/plugins/script_text_editor.h b/editor/plugins/script_text_editor.h index 4dbade472c..0ea8726ecc 100644 --- a/editor/plugins/script_text_editor.h +++ b/editor/plugins/script_text_editor.h @@ -81,7 +81,7 @@ class ScriptTextEditor : public ScriptEditorBase { PopupPanel *color_panel; ColorPicker *color_picker; - int color_line; + Vector2 color_position; String color_args; void _update_member_keywords(); @@ -120,6 +120,7 @@ class ScriptTextEditor : public ScriptEditorBase { EDIT_TO_UPPERCASE, EDIT_TO_LOWERCASE, EDIT_CAPITALIZE, + EDIT_EVALUATE, EDIT_TOGGLE_FOLD_LINE, EDIT_FOLD_ALL_LINES, EDIT_UNFOLD_ALL_LINES, @@ -168,7 +169,7 @@ protected: void _edit_option(int p_op); void _edit_option_toggle_inline_comment(); - void _make_context_menu(bool p_selection, bool p_color, bool p_foldable, bool p_open_docs, bool p_goto_definition); + 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); diff --git a/editor/plugins/shader_editor_plugin.cpp b/editor/plugins/shader_editor_plugin.cpp index 994c542187..df3e23a9e9 100644 --- a/editor/plugins/shader_editor_plugin.cpp +++ b/editor/plugins/shader_editor_plugin.cpp @@ -55,6 +55,7 @@ void ShaderTextEditor::set_edited_shader(const Ref<Shader> &p_shader) { _load_theme_settings(); get_text_edit()->set_text(p_shader->get_code()); + get_text_edit()->clear_undo_history(); _validate_script(); _line_col_changed(); @@ -342,6 +343,9 @@ void ShaderEditor::_menu_option(int p_option) { shader_editor->remove_all_bookmarks(); } break; + case HELP_DOCS: { + OS::get_singleton()->shell_open("https://docs.godotengine.org/en/stable/tutorials/shading/shading_reference/index.html"); + } break; } if (p_option != SEARCH_FIND && p_option != SEARCH_REPLACE && p_option != SEARCH_GOTO_LINE) { shader_editor->get_text_edit()->call_deferred("grab_focus"); @@ -368,7 +372,7 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->set_indent_using_spaces(EditorSettings::get_singleton()->get("text_editor/indent/type")); shader_editor->get_text_edit()->set_auto_indent(EditorSettings::get_singleton()->get("text_editor/indent/auto_indent")); shader_editor->get_text_edit()->set_draw_tabs(EditorSettings::get_singleton()->get("text_editor/indent/draw_tabs")); - shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/line_numbers/show_line_numbers")); + shader_editor->get_text_edit()->set_show_line_numbers(EditorSettings::get_singleton()->get("text_editor/appearance/show_line_numbers")); shader_editor->get_text_edit()->set_syntax_coloring(EditorSettings::get_singleton()->get("text_editor/highlighting/syntax_highlighting")); shader_editor->get_text_edit()->set_highlight_all_occurrences(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_all_occurrences")); shader_editor->get_text_edit()->set_highlight_current_line(EditorSettings::get_singleton()->get("text_editor/highlighting/highlight_current_line")); @@ -376,8 +380,8 @@ void ShaderEditor::_editor_settings_changed() { shader_editor->get_text_edit()->cursor_set_blink_speed(EditorSettings::get_singleton()->get("text_editor/cursor/caret_blink_speed")); shader_editor->get_text_edit()->add_constant_override("line_spacing", EditorSettings::get_singleton()->get("text_editor/theme/line_spacing")); shader_editor->get_text_edit()->cursor_set_block_mode(EditorSettings::get_singleton()->get("text_editor/cursor/block_caret")); - shader_editor->get_text_edit()->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/open_scripts/smooth_scrolling")); - shader_editor->get_text_edit()->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/open_scripts/v_scroll_speed")); + shader_editor->get_text_edit()->set_smooth_scroll_enabled(EditorSettings::get_singleton()->get("text_editor/navigation/smooth_scrolling")); + shader_editor->get_text_edit()->set_v_scroll_speed(EditorSettings::get_singleton()->get("text_editor/navigation/v_scroll_speed")); } void ShaderEditor::_bind_methods() { @@ -519,26 +523,33 @@ void ShaderEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { tx->cursor_set_column(col); } } - _make_context_menu(tx->is_selection_active()); + _make_context_menu(tx->is_selection_active(), get_local_mouse_position()); } } + + Ref<InputEventKey> k = ev; + if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_MENU) { + TextEdit *tx = shader_editor->get_text_edit(); + _make_context_menu(tx->is_selection_active(), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos())); + context_menu->grab_focus(); + } } void ShaderEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = shader_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = shader_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -547,21 +558,21 @@ void ShaderEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void ShaderEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _menu_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _menu_option(bookmarks_menu->get_item_id(p_idx)); } else { - shader_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + shader_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } -void ShaderEditor::_make_context_menu(bool p_selection) { +void ShaderEditor::_make_context_menu(bool p_selection, Vector2 p_position) { context_menu->clear(); if (p_selection) { @@ -581,7 +592,7 @@ void ShaderEditor::_make_context_menu(bool p_selection) { context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_comment"), EDIT_TOGGLE_COMMENT); context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); + context_menu->set_position(get_global_transform().xform(p_position)); context_menu->set_size(Vector2(1, 1)); context_menu->popup(); } @@ -646,22 +657,36 @@ ShaderEditor::ShaderEditor(EditorNode *p_node) { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_next"), SEARCH_FIND_NEXT); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); - search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); search_menu->get_popup()->connect("id_pressed", this, "_menu_option"); - bookmarks_menu = memnew(MenuButton); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_menu_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name("Bookmarks"); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); + + help_menu = memnew(MenuButton); + help_menu->set_text(TTR("Help")); + help_menu->set_switch_on_hover(true); + help_menu->get_popup()->add_icon_item(p_node->get_gui_base()->get_icon("Instance", "EditorIcons"), TTR("Online Docs"), HELP_DOCS); + help_menu->get_popup()->connect("id_pressed", this, "_menu_option"); add_child(main_container); main_container->add_child(hbc); hbc->add_child(search_menu); hbc->add_child(edit_menu); - hbc->add_child(bookmarks_menu); + hbc->add_child(goto_menu); + hbc->add_child(help_menu); hbc->add_style_override("panel", p_node->get_gui_base()->get_stylebox("ScriptEditorPanel", "EditorStyles")); main_container->add_child(shader_editor); diff --git a/editor/plugins/shader_editor_plugin.h b/editor/plugins/shader_editor_plugin.h index 8e55a1ad70..ca9f489713 100644 --- a/editor/plugins/shader_editor_plugin.h +++ b/editor/plugins/shader_editor_plugin.h @@ -94,13 +94,13 @@ class ShaderEditor : public PanelContainer { BOOKMARK_GOTO_NEXT, BOOKMARK_GOTO_PREV, BOOKMARK_REMOVE_ALL, - + HELP_DOCS, }; MenuButton *edit_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; - MenuButton *settings_menu; + PopupMenu *bookmarks_menu; + MenuButton *help_menu; PopupMenu *context_menu; uint64_t idle; @@ -122,7 +122,7 @@ class ShaderEditor : public PanelContainer { protected: void _notification(int p_what); static void _bind_methods(); - void _make_context_menu(bool p_selection); + void _make_context_menu(bool p_selection, Vector2 p_position); void _text_edit_gui_input(const Ref<InputEvent> &ev); void _update_bookmark_list(); diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index 630f3ba9e1..18049e62b4 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -74,14 +74,6 @@ #define MIN_FOV 0.01 #define MAX_FOV 179 -#ifdef TOOLS_ENABLED -#define get_global_gizmo_transform get_global_gizmo_transform -#define get_local_gizmo_transform get_local_gizmo_transform -#else -#define get_global_gizmo_transform get_global_transform -#define get_local_gizmo_transform get_transform -#endif - void SpatialEditorViewport::_update_camera(float p_interp_delta) { bool is_orthogonal = camera->get_projection() == Camera::PROJECTION_ORTHOGONAL; @@ -250,15 +242,7 @@ Vector3 SpatialEditorViewport::_get_ray(const Vector2 &p_pos) const { return camera->project_ray_normal(p_pos / viewport_container->get_stretch_shrink()); } -/* -void SpatialEditorViewport::_clear_id(Spatial *p_node) { - - - editor_selection->remove_node(p_node); - -} -*/ void SpatialEditorViewport::_clear_selected() { editor_selection->clear(); @@ -2381,16 +2365,22 @@ void SpatialEditorViewport::_draw() { get_stylebox("Focus", "EditorStyles")->draw(surface->get_canvas_item(), r); } - RID ci = surface->get_canvas_item(); - if (cursor.region_select) { + const Rect2 selection_rect = Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin); - VisualServer::get_singleton()->canvas_item_add_rect( - ci, - Rect2(cursor.region_begin, cursor.region_end - cursor.region_begin), - get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375)); + surface->draw_rect( + selection_rect, + get_color("box_selection_fill_color", "Editor")); + + surface->draw_rect( + selection_rect, + get_color("box_selection_stroke_color", "Editor"), + false, + Math::round(EDSCALE)); } + RID ci = surface->get_canvas_item(); + if (message_time > 0) { Ref<Font> font = get_font("font", "Label"); Point2 msgpos = Point2(5, get_size().y - 20); @@ -2930,8 +2920,14 @@ void SpatialEditorViewport::update_transform_gizmo_view() { if (dd == 0) dd = 0.0001; - float gsize = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); - gizmo_scale = (gsize / Math::abs(dd)) * MAX(1, EDSCALE) / viewport_container->get_stretch_shrink(); + float gizmo_size = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_size"); + // At low viewport heights, multiply the gizmo scale based on the viewport height. + // This prevents the gizmo from growing very large and going outside the viewport. + const int viewport_base_height = 400 * MAX(1, EDSCALE); + gizmo_scale = + (gizmo_size / Math::abs(dd)) * MAX(1, EDSCALE) * + MIN(viewport_base_height, viewport_container->get_size().height) / viewport_base_height / + viewport_container->get_stretch_shrink(); Vector3 scale = Vector3(1, 1, 1) * gizmo_scale; xform.basis.scale(scale); @@ -3553,7 +3549,7 @@ SpatialEditorViewport::SpatialEditorViewport(SpatialEditor *p_spatial_editor, Ed view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_half_resolution", TTR("Half Resolution")), VIEW_HALF_RESOLUTION); view_menu->get_popup()->add_separator(); view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_listener", TTR("Audio Listener")), VIEW_AUDIO_LISTENER); - view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Doppler Enable")), VIEW_AUDIO_DOPPLER); + view_menu->get_popup()->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_audio_doppler", TTR("Enable Doppler")), VIEW_AUDIO_DOPPLER); view_menu->get_popup()->set_item_checked(view_menu->get_popup()->get_item_index(VIEW_GIZMOS), true); view_menu->get_popup()->add_separator(); @@ -4001,11 +3997,11 @@ void SpatialEditor::select_gizmo_highlight_axis(int p_axis) { for (int i = 0; i < 3; i++) { - move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_hl : gizmo_color[i]); - move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? gizmo_hl : plane_gizmo_color[i]); - rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_hl : gizmo_color[i]); - scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_hl : gizmo_color[i]); - scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? gizmo_hl : plane_gizmo_color[i]); + move_gizmo[i]->surface_set_material(0, i == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); + move_plane_gizmo[i]->surface_set_material(0, (i + 6) == p_axis ? plane_gizmo_color_hl[i] : plane_gizmo_color[i]); + rotate_gizmo[i]->surface_set_material(0, (i + 3) == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); + scale_gizmo[i]->surface_set_material(0, (i + 9) == p_axis ? gizmo_color_hl[i] : gizmo_color[i]); + scale_plane_gizmo[i]->surface_set_material(0, (i + 12) == p_axis ? plane_gizmo_color_hl[i] : plane_gizmo_color[i]); } } @@ -4084,6 +4080,23 @@ Object *SpatialEditor::_get_editor_data(Object *p_what) { return si; } +Color SpatialEditor::_get_axis_color(int axis) { + + switch (axis) { + case 0: + // X axis + return Color(0.96, 0.20, 0.32); + case 1: + // Y axis + return Color(0.53, 0.84, 0.01); + case 2: + // Z axis + return Color(0.16, 0.55, 0.96); + default: + return Color(0, 0, 0); + } +} + void SpatialEditor::_generate_selection_box() { AABB aabb(Vector3(), Vector3(1, 1, 1)); @@ -4097,11 +4110,6 @@ void SpatialEditor::_generate_selection_box() { Vector3 a, b; aabb.get_edge(i, a, b); - /*Vector<Vector3> points; - Vector<Color> colors; - points.push_back(a); - points.push_back(b);*/ - st->add_color(Color(1.0, 1.0, 0.8, 0.8)); st->add_vertex(a); st->add_color(Color(1.0, 1.0, 0.8, 0.4)); @@ -4640,12 +4648,13 @@ void SpatialEditor::_init_indicators() { for (int i = 0; i < 3; i++) { Vector3 axis; axis[i] = 1; + Color origin_color = _get_axis_color(i); grid_enable[i] = false; grid_visible[i] = false; - origin_colors.push_back(Color(axis.x, axis.y, axis.z)); - origin_colors.push_back(Color(axis.x, axis.y, axis.z)); + origin_colors.push_back(origin_color); + origin_colors.push_back(origin_color); origin_points.push_back(axis * 4096); origin_points.push_back(axis * -4096); } @@ -4674,17 +4683,11 @@ void SpatialEditor::_init_indicators() { //move gizmo - float gizmo_alph = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_opacity"); - - gizmo_hl = Ref<SpatialMaterial>(memnew(SpatialMaterial)); - gizmo_hl->set_flag(SpatialMaterial::FLAG_UNSHADED, true); - gizmo_hl->set_on_top_of_alpha(); - gizmo_hl->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - gizmo_hl->set_albedo(Color(1, 1, 1, gizmo_alph + 0.2f)); - gizmo_hl->set_cull_mode(SpatialMaterial::CULL_DISABLED); - for (int i = 0; i < 3; i++) { + Color col = _get_axis_color(i); + col.a = EditorSettings::get_singleton()->get("editors/3d/manipulator_gizmo_opacity"); + move_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); move_plane_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); rotate_gizmo[i] = Ref<ArrayMesh>(memnew(ArrayMesh)); @@ -4695,13 +4698,13 @@ void SpatialEditor::_init_indicators() { mat->set_flag(SpatialMaterial::FLAG_UNSHADED, true); mat->set_on_top_of_alpha(); mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); - Color col; - col[i] = 1.0; - col.a = gizmo_alph; mat->set_albedo(col); - gizmo_color[i] = mat; + Ref<SpatialMaterial> mat_hl = mat->duplicate(); + mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + gizmo_color_hl[i] = mat_hl; + Vector3 ivec; ivec[i] = 1; Vector3 nivec; @@ -4791,13 +4794,14 @@ void SpatialEditor::_init_indicators() { plane_mat->set_on_top_of_alpha(); plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); - Color col2; - col2[i] = 1.0; - col2.a = gizmo_alph; - plane_mat->set_albedo(col2); + plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(move_plane_gizmo[i]); + + Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } // Rotate @@ -4920,13 +4924,14 @@ void SpatialEditor::_init_indicators() { plane_mat->set_on_top_of_alpha(); plane_mat->set_feature(SpatialMaterial::FEATURE_TRANSPARENT, true); plane_mat->set_cull_mode(SpatialMaterial::CULL_DISABLED); - Color col2; - col2[i] = 1.0; - col2.a = gizmo_alph; - plane_mat->set_albedo(col2); + plane_mat->set_albedo(col); plane_gizmo_color[i] = plane_mat; // needed, so we can draw planes from both sides surftool->set_material(plane_mat); surftool->commit(scale_plane_gizmo[i]); + + Ref<SpatialMaterial> plane_mat_hl = plane_mat->duplicate(); + plane_mat_hl->set_albedo(Color(col.r, col.g, col.b, 1.0)); + plane_gizmo_color_hl[i] = plane_mat_hl; // needed, so we can draw planes from both sides } } } @@ -5163,7 +5168,7 @@ void SpatialEditor::snap_selected_nodes_to_floor() { // We add a bit of margin to the from position to avoid it from snapping // when the spatial is already on a floor and there's another floor under // it - from = from + Vector3(0.0, 0.1, 0.0); + from = from + Vector3(0.0, 0.2, 0.0); Dictionary d; @@ -5178,31 +5183,56 @@ void SpatialEditor::snap_selected_nodes_to_floor() { Array keys = snap_data.keys(); - if (keys.size()) { - undo_redo->create_action(TTR("Snap Nodes To Floor")); + // The maximum height an object can travel to be snapped + const float max_snap_height = 20.0; + + // Will be set to `true` if at least one node from the selection was successfully snapped + bool snapped_to_floor = false; + if (keys.size()) { + // For snapping to be performed, there must be solid geometry under at least one of the selected nodes. + // We need to check this before snapping to register the undo/redo action only if needed. for (int i = 0; i < keys.size(); i++) { Node *node = keys[i]; Spatial *sp = Object::cast_to<Spatial>(node); - Dictionary d = snap_data[node]; Vector3 from = d["from"]; - Vector3 position_offset = d["position_offset"]; - - Vector3 to = from - Vector3(0.0, 10.0, 0.0); + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); Set<RID> excluded = _get_physics_bodies_rid(sp); if (ss->intersect_ray(from, to, result, excluded)) { - Transform new_transform = sp->get_global_transform(); - new_transform.origin.y = result.position.y; - new_transform.origin = new_transform.origin - position_offset; - - undo_redo->add_do_method(sp, "set_global_transform", new_transform); - undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + snapped_to_floor = true; } } - undo_redo->commit_action(); + if (snapped_to_floor) { + undo_redo->create_action(TTR("Snap Nodes To Floor")); + + // Perform snapping if at least one node can be snapped + for (int i = 0; i < keys.size(); i++) { + Node *node = keys[i]; + Spatial *sp = Object::cast_to<Spatial>(node); + Dictionary d = snap_data[node]; + Vector3 from = d["from"]; + Vector3 to = from - Vector3(0.0, max_snap_height, 0.0); + Set<RID> excluded = _get_physics_bodies_rid(sp); + + if (ss->intersect_ray(from, to, result, excluded)) { + Vector3 position_offset = d["position_offset"]; + Transform new_transform = sp->get_global_transform(); + + new_transform.origin.y = result.position.y; + new_transform.origin = new_transform.origin - position_offset; + + undo_redo->add_do_method(sp, "set_global_transform", new_transform); + undo_redo->add_undo_method(sp, "set_global_transform", sp->get_global_transform()); + } + } + + undo_redo->commit_action(); + } else { + EditorNode::get_singleton()->show_warning(TTR("Couldn't find a solid floor to snap the selection to.")); + } } } @@ -5212,42 +5242,6 @@ void SpatialEditor::_unhandled_key_input(Ref<InputEvent> p_event) { return; snap_key_enabled = Input::get_singleton()->is_key_pressed(KEY_CONTROL); - - Ref<InputEventKey> k = p_event; - - if (k.is_valid()) { - - // Note: need to check is_echo because first person movement keys might still be held - if (!is_any_freelook_active() && !p_event->is_echo()) { - - if (!k->is_pressed()) - return; - - if (ED_IS_SHORTCUT("spatial_editor/tool_select", p_event)) { - _menu_item_pressed(MENU_TOOL_SELECT); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_move", p_event)) { - _menu_item_pressed(MENU_TOOL_MOVE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_rotate", p_event)) { - _menu_item_pressed(MENU_TOOL_ROTATE); - } else if (ED_IS_SHORTCUT("spatial_editor/tool_scale", p_event)) { - _menu_item_pressed(MENU_TOOL_SCALE); - } else if (ED_IS_SHORTCUT("spatial_editor/snap_to_floor", p_event)) { - snap_selected_nodes_to_floor(); - } else if (ED_IS_SHORTCUT("spatial_editor/local_coords", p_event)) { - if (are_local_coords_enabled()) { - _menu_item_toggled(false, MENU_TOOL_LOCAL_COORDS); - } else { - _menu_item_toggled(true, MENU_TOOL_LOCAL_COORDS); - } - } else if (ED_IS_SHORTCUT("spatial_editor/snap", p_event)) { - if (is_snap_enabled()) { - _menu_item_toggled(false, MENU_TOOL_USE_SNAP); - } else { - _menu_item_toggled(true, MENU_TOOL_USE_SNAP); - } - } - } - } } void SpatialEditor::_notification(int p_what) { @@ -5296,6 +5290,10 @@ void SpatialEditor::_notification(int p_what) { tool_button[SpatialEditor::TOOL_MODE_ROTATE]->set_icon(get_icon("ToolRotate", "EditorIcons")); tool_button[SpatialEditor::TOOL_MODE_SCALE]->set_icon(get_icon("ToolScale", "EditorIcons")); tool_button[SpatialEditor::TOOL_MODE_LIST_SELECT]->set_icon(get_icon("ListSelect", "EditorIcons")); + tool_button[SpatialEditor::TOOL_LOCK_SELECTED]->set_icon(get_icon("Lock", "EditorIcons")); + tool_button[SpatialEditor::TOOL_UNLOCK_SELECTED]->set_icon(get_icon("Unlock", "EditorIcons")); + tool_button[SpatialEditor::TOOL_GROUP_SELECTED]->set_icon(get_icon("Group", "EditorIcons")); + tool_button[SpatialEditor::TOOL_UNGROUP_SELECTED]->set_icon(get_icon("Ungroup", "EditorIcons")); tool_option_button[SpatialEditor::TOOL_OPT_LOCAL_COORDS]->set_icon(get_icon("Object", "EditorIcons")); tool_option_button[SpatialEditor::TOOL_OPT_USE_SNAP]->set_icon(get_icon("Snap", "EditorIcons")); @@ -5431,6 +5429,7 @@ void SpatialEditor::_register_all_gizmos() { add_gizmo_plugin(Ref<VehicleWheelSpatialGizmoPlugin>(memnew(VehicleWheelSpatialGizmoPlugin))); add_gizmo_plugin(Ref<VisibilityNotifierGizmoPlugin>(memnew(VisibilityNotifierGizmoPlugin))); add_gizmo_plugin(Ref<ParticlesGizmoPlugin>(memnew(ParticlesGizmoPlugin))); + add_gizmo_plugin(Ref<CPUParticlesGizmoPlugin>(memnew(CPUParticlesGizmoPlugin))); add_gizmo_plugin(Ref<ReflectionProbeGizmoPlugin>(memnew(ReflectionProbeGizmoPlugin))); add_gizmo_plugin(Ref<GIProbeGizmoPlugin>(memnew(GIProbeGizmoPlugin))); add_gizmo_plugin(Ref<BakedIndirectLightGizmoPlugin>(memnew(BakedIndirectLightGizmoPlugin))); @@ -5520,7 +5519,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SELECT]->set_pressed(true); button_binds.write[0] = MENU_TOOL_SELECT; tool_button[TOOL_MODE_SELECT]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SELECT]->set_tooltip(TTR("Select Mode (Q)") + "\n" + keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); + tool_button[TOOL_MODE_SELECT]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_select", TTR("Select Mode"), KEY_Q)); + tool_button[TOOL_MODE_SELECT]->set_tooltip(keycode_get_string(KEY_MASK_CMD) + TTR("Drag: Rotate\nAlt+Drag: Move\nAlt+RMB: Depth list selection")); hbc_menu->add_child(memnew(VSeparator)); @@ -5530,7 +5530,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_MOVE]->set_flat(true); button_binds.write[0] = MENU_TOOL_MOVE; tool_button[TOOL_MODE_MOVE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_MOVE]->set_tooltip(TTR("Move Mode (W)")); + tool_button[TOOL_MODE_MOVE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_move", TTR("Move Mode"), KEY_W)); tool_button[TOOL_MODE_ROTATE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_ROTATE]); @@ -5538,7 +5538,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_ROTATE]->set_flat(true); button_binds.write[0] = MENU_TOOL_ROTATE; tool_button[TOOL_MODE_ROTATE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_ROTATE]->set_tooltip(TTR("Rotate Mode (E)")); + tool_button[TOOL_MODE_ROTATE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Rotate Mode"), KEY_E)); tool_button[TOOL_MODE_SCALE] = memnew(ToolButton); hbc_menu->add_child(tool_button[TOOL_MODE_SCALE]); @@ -5546,7 +5546,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_button[TOOL_MODE_SCALE]->set_flat(true); button_binds.write[0] = MENU_TOOL_SCALE; tool_button[TOOL_MODE_SCALE]->connect("pressed", this, "_menu_item_pressed", button_binds); - tool_button[TOOL_MODE_SCALE]->set_tooltip(TTR("Scale Mode (R)")); + tool_button[TOOL_MODE_SCALE]->set_shortcut(ED_SHORTCUT("spatial_editor/tool_scale", TTR("Scale Mode"), KEY_R)); hbc_menu->add_child(memnew(VSeparator)); @@ -5590,9 +5590,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_flat(true); button_binds.write[0] = MENU_TOOL_LOCAL_COORDS; tool_option_button[TOOL_OPT_LOCAL_COORDS]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/local_coords", TTR("Local Coords"), KEY_T); - sct = ED_GET_SHORTCUT("spatial_editor/local_coords").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_tooltip(vformat(TTR("Local Space Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_LOCAL_COORDS]->set_shortcut(ED_SHORTCUT("spatial_editor/local_coords", TTR("Use Local Space"), KEY_T)); tool_option_button[TOOL_OPT_USE_SNAP] = memnew(ToolButton); hbc_menu->add_child(tool_option_button[TOOL_OPT_USE_SNAP]); @@ -5600,9 +5598,7 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { tool_option_button[TOOL_OPT_USE_SNAP]->set_flat(true); button_binds.write[0] = MENU_TOOL_USE_SNAP; tool_option_button[TOOL_OPT_USE_SNAP]->connect("toggled", this, "_menu_item_toggled", button_binds); - ED_SHORTCUT("spatial_editor/snap", TTR("Snap"), KEY_Y); - sct = ED_GET_SHORTCUT("spatial_editor/snap").ptr()->get_as_text(); - tool_option_button[TOOL_OPT_USE_SNAP]->set_tooltip(vformat(TTR("Snap Mode (%s)"), sct)); + tool_option_button[TOOL_OPT_USE_SNAP]->set_shortcut(ED_SHORTCUT("spatial_editor/snap", TTR("Use Snap"), KEY_Y)); hbc_menu->add_child(memnew(VSeparator)); @@ -5622,12 +5618,6 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { ED_SHORTCUT("spatial_editor/focus_selection", TTR("Focus Selection"), KEY_F); ED_SHORTCUT("spatial_editor/align_transform_with_view", TTR("Align Transform with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_M); ED_SHORTCUT("spatial_editor/align_rotation_with_view", TTR("Align Rotation with View"), KEY_MASK_ALT + KEY_MASK_CMD + KEY_F); - - ED_SHORTCUT("spatial_editor/tool_select", TTR("Tool Select"), KEY_Q); - ED_SHORTCUT("spatial_editor/tool_move", TTR("Tool Move"), KEY_W); - ED_SHORTCUT("spatial_editor/tool_rotate", TTR("Tool Rotate"), KEY_E); - ED_SHORTCUT("spatial_editor/tool_scale", TTR("Tool Scale"), KEY_R); - ED_SHORTCUT("spatial_editor/freelook_toggle", TTR("Toggle Freelook"), KEY_MASK_SHIFT + KEY_F); PopupMenu *p; @@ -5639,10 +5629,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p = transform_menu->get_popup(); p->add_shortcut(ED_SHORTCUT("spatial_editor/snap_to_floor", TTR("Snap Object to Floor"), KEY_PAGEDOWN), MENU_SNAP_TO_FLOOR); - p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); - p->add_separator(); p->add_shortcut(ED_SHORTCUT("spatial_editor/transform_dialog", TTR("Transform Dialog...")), MENU_TRANSFORM_DIALOG); + p->add_separator(); + p->add_shortcut(ED_SHORTCUT("spatial_editor/configure_snap", TTR("Configure Snap...")), MENU_TRANSFORM_CONFIGURE_SNAP); + p->connect("id_pressed", this, "_menu_item_pressed"); view_menu = memnew(MenuButton); @@ -5666,11 +5657,11 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { p->add_submenu_item(TTR("Gizmos"), "GizmosMenu"); p->add_separator(); - p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_origin", TTR("View Origin")), MENU_VIEW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("spatial_editor/view_grid", TTR("View Grid")), MENU_VIEW_GRID); + p->add_separator(); - p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings")), MENU_VIEW_CAMERA_SETTINGS); + p->add_shortcut(ED_SHORTCUT("spatial_editor/settings", TTR("Settings...")), MENU_VIEW_CAMERA_SETTINGS); p->set_item_checked(p->get_item_index(MENU_VIEW_ORIGIN), true); p->set_item_checked(p->get_item_index(MENU_VIEW_GRID), true); @@ -5824,7 +5815,8 @@ SpatialEditor::SpatialEditor(EditorNode *p_editor) { EDITOR_DEF("editors/3d/manipulator_gizmo_size", 80); EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::INT, "editors/3d/manipulator_gizmo_size", PROPERTY_HINT_RANGE, "16,1024,1")); - EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.2); + EDITOR_DEF("editors/3d/manipulator_gizmo_opacity", 0.4); + EditorSettings::get_singleton()->add_property_hint(PropertyInfo(Variant::REAL, "editors/3d/manipulator_gizmo_opacity", PROPERTY_HINT_RANGE, "0,1,0.01")); over_gizmo_handle = -1; } diff --git a/editor/plugins/spatial_editor_plugin.h b/editor/plugins/spatial_editor_plugin.h index dde402c0ff..728b67f6fa 100644 --- a/editor/plugins/spatial_editor_plugin.h +++ b/editor/plugins/spatial_editor_plugin.h @@ -37,9 +37,6 @@ #include "scene/3d/light.h" #include "scene/3d/visual_instance.h" #include "scene/gui/panel_container.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ class Camera; class SpatialEditor; @@ -528,7 +525,8 @@ private: Ref<ArrayMesh> move_gizmo[3], move_plane_gizmo[3], rotate_gizmo[3], scale_gizmo[3], scale_plane_gizmo[3]; Ref<SpatialMaterial> gizmo_color[3]; Ref<SpatialMaterial> plane_gizmo_color[3]; - Ref<SpatialMaterial> gizmo_hl; + Ref<SpatialMaterial> gizmo_color_hl[3]; + Ref<SpatialMaterial> plane_gizmo_color_hl[3]; int over_gizmo_handle; @@ -635,6 +633,7 @@ private: Node *custom_camera; Object *_get_editor_data(Object *p_what); + Color _get_axis_color(int axis); Ref<Environment> viewport_environment; diff --git a/editor/plugins/text_editor.cpp b/editor/plugins/text_editor.cpp index 34d8e6aff5..d0320bcd8b 100644 --- a/editor/plugins/text_editor.cpp +++ b/editor/plugins/text_editor.cpp @@ -30,6 +30,7 @@ #include "text_editor.h" +#include "core/os/keyboard.h" #include "editor_node.h" void TextEditor::add_syntax_highlighter(SyntaxHighlighter *p_highlighter) { @@ -221,19 +222,19 @@ void TextEditor::_validate_script() { void TextEditor::_update_bookmark_list() { - bookmarks_menu->get_popup()->clear(); + bookmarks_menu->clear(); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); - bookmarks_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_bookmark"), BOOKMARK_TOGGLE); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/remove_all_bookmarks"), BOOKMARK_REMOVE_ALL); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_next_bookmark"), BOOKMARK_GOTO_NEXT); + bookmarks_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_previous_bookmark"), BOOKMARK_GOTO_PREV); Array bookmark_list = code_editor->get_text_edit()->get_bookmarks_array(); if (bookmark_list.size() == 0) { return; } - bookmarks_menu->get_popup()->add_separator(); + bookmarks_menu->add_separator(); for (int i = 0; i < bookmark_list.size(); i++) { String line = code_editor->get_text_edit()->get_line(bookmark_list[i]).strip_edges(); @@ -242,17 +243,17 @@ void TextEditor::_update_bookmark_list() { line = line.substr(0, 50); } - bookmarks_menu->get_popup()->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); - bookmarks_menu->get_popup()->set_item_metadata(bookmarks_menu->get_popup()->get_item_count() - 1, bookmark_list[i]); + bookmarks_menu->add_item(String::num((int)bookmark_list[i] + 1) + " - \"" + line + "\""); + bookmarks_menu->set_item_metadata(bookmarks_menu->get_item_count() - 1, bookmark_list[i]); } } void TextEditor::_bookmark_item_pressed(int p_idx) { if (p_idx < 4) { // Any item before the separator. - _edit_option(bookmarks_menu->get_popup()->get_item_id(p_idx)); + _edit_option(bookmarks_menu->get_item_id(p_idx)); } else { - code_editor->goto_line(bookmarks_menu->get_popup()->get_item_metadata(p_idx)); + code_editor->goto_line(bookmarks_menu->get_item_metadata(p_idx)); } } @@ -313,6 +314,11 @@ void TextEditor::goto_line(int p_line, bool p_with_error) { code_editor->goto_line(p_line); } +void TextEditor::goto_line_selection(int p_line, int p_begin, int p_end) { + + code_editor->goto_line_selection(p_line, p_begin, p_end); +} + void TextEditor::set_executing_line(int p_line) { code_editor->set_executing_line(p_line); @@ -477,6 +483,14 @@ void TextEditor::_edit_option(int p_op) { code_editor->get_find_replace_bar()->popup_replace(); } break; + case SEARCH_IN_FILES: { + + String selected_text = code_editor->get_text_edit()->get_selection_text(); + + // Yep, because it doesn't make sense to instance this dialog for every single script open... + // So this will be delegated to the ScriptEditor. + emit_signal("search_in_files_requested", selected_text); + } break; case SEARCH_GOTO_LINE: { goto_line_dialog->popup_find_line(tx); @@ -553,7 +567,7 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { int to_column = tx->get_selection_to_column(); if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { - // Right click is outside the selected text + // Right click is outside the selected text. tx->deselect(); } } @@ -564,13 +578,21 @@ void TextEditor::_text_edit_gui_input(const Ref<InputEvent> &ev) { } if (!mb->is_pressed()) { - _make_context_menu(tx->is_selection_active(), can_fold, is_folded); + _make_context_menu(tx->is_selection_active(), can_fold, is_folded, get_local_mouse_position()); } } } + + Ref<InputEventKey> k = ev; + if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_MENU) { + TextEdit *tx = code_editor->get_text_edit(); + int line = tx->cursor_get_line(); + _make_context_menu(tx->is_selection_active(), tx->can_fold(line), tx->is_folded(line), (get_global_transform().inverse() * tx->get_global_transform()).xform(tx->_get_cursor_pixel_pos())); + context_menu->grab_focus(); + } } -void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded) { +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) { @@ -596,7 +618,7 @@ void TextEditor::_make_context_menu(bool p_selection, bool p_can_fold, bool p_is if (p_can_fold || p_is_folded) context_menu->add_shortcut(ED_GET_SHORTCUT("script_text_editor/toggle_fold_line"), EDIT_TOGGLE_FOLD_LINE); - context_menu->set_position(get_global_transform().xform(get_local_mouse_position())); + context_menu->set_position(get_global_transform().xform(p_position)); context_menu->set_size(Vector2(1, 1)); context_menu->popup(); } @@ -632,17 +654,14 @@ TextEditor::TextEditor() { search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_previous"), SEARCH_FIND_PREV); search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/replace"), SEARCH_REPLACE); search_menu->get_popup()->add_separator(); - search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); - - goto_line_dialog = memnew(GotoLineDialog); - add_child(goto_line_dialog); + search_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/find_in_files"), SEARCH_IN_FILES); edit_menu = memnew(MenuButton); + edit_hb->add_child(edit_menu); edit_menu->set_text(TTR("Edit")); edit_menu->set_switch_on_hover(true); edit_menu->get_popup()->connect("id_pressed", this, "_edit_option"); - edit_hb->add_child(edit_menu); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/undo"), EDIT_UNDO); edit_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/redo"), EDIT_REDO); edit_menu->get_popup()->add_separator(); @@ -684,13 +703,25 @@ TextEditor::TextEditor() { highlighter_menu->add_radio_check_item(TTR("Standard")); highlighter_menu->connect("id_pressed", this, "_change_syntax_highlighter"); - bookmarks_menu = memnew(MenuButton); - edit_hb->add_child(bookmarks_menu); - bookmarks_menu->set_text(TTR("Bookmarks")); - bookmarks_menu->set_switch_on_hover(true); + MenuButton *goto_menu = memnew(MenuButton); + edit_hb->add_child(goto_menu); + goto_menu->set_text(TTR("Go To")); + goto_menu->set_switch_on_hover(true); + goto_menu->get_popup()->connect("id_pressed", this, "_edit_option"); + + goto_menu->get_popup()->add_shortcut(ED_GET_SHORTCUT("script_text_editor/goto_line"), SEARCH_GOTO_LINE); + goto_menu->get_popup()->add_separator(); + + bookmarks_menu = memnew(PopupMenu); + bookmarks_menu->set_name(TTR("Bookmarks")); + goto_menu->get_popup()->add_child(bookmarks_menu); + goto_menu->get_popup()->add_submenu_item(TTR("Bookmarks"), "Bookmarks"); _update_bookmark_list(); bookmarks_menu->connect("about_to_show", this, "_update_bookmark_list"); - bookmarks_menu->get_popup()->connect("index_pressed", this, "_bookmark_item_pressed"); + bookmarks_menu->connect("index_pressed", this, "_bookmark_item_pressed"); + + goto_line_dialog = memnew(GotoLineDialog); + add_child(goto_line_dialog); code_editor->get_text_edit()->set_drag_forwarding(this); } diff --git a/editor/plugins/text_editor.h b/editor/plugins/text_editor.h index 3a330576ae..7d441a187d 100644 --- a/editor/plugins/text_editor.h +++ b/editor/plugins/text_editor.h @@ -46,7 +46,7 @@ private: MenuButton *edit_menu; PopupMenu *highlighter_menu; MenuButton *search_menu; - MenuButton *bookmarks_menu; + PopupMenu *bookmarks_menu; PopupMenu *context_menu; GotoLineDialog *goto_line_dialog; @@ -87,6 +87,7 @@ private: SEARCH_FIND_NEXT, SEARCH_FIND_PREV, SEARCH_REPLACE, + SEARCH_IN_FILES, SEARCH_GOTO_LINE, BOOKMARK_TOGGLE, BOOKMARK_GOTO_NEXT, @@ -100,7 +101,7 @@ protected: void _notification(int p_what); void _edit_option(int p_op); - void _make_context_menu(bool p_selection, bool p_can_fold, bool p_is_folded); + 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); Map<String, SyntaxHighlighter *> highlighters; @@ -131,6 +132,7 @@ public: virtual Vector<String> get_functions(); virtual void get_breakpoints(List<int> *p_breakpoints); virtual void goto_line(int p_line, bool p_with_error = false); + void goto_line_selection(int p_line, int p_begin, int p_end); virtual void set_executing_line(int p_line); virtual void clear_executing_line(); virtual void trim_trailing_whitespace(); diff --git a/editor/plugins/texture_region_editor_plugin.cpp b/editor/plugins/texture_region_editor_plugin.cpp index 4d349f06b7..21eebf9ca2 100644 --- a/editor/plugins/texture_region_editor_plugin.cpp +++ b/editor/plugins/texture_region_editor_plugin.cpp @@ -625,9 +625,12 @@ void TextureRegionEditor::_update_rect() { rect = node_sprite->get_region_rect(); else if (node_sprite_3d) rect = node_sprite_3d->get_region_rect(); - else if (node_ninepatch) + else if (node_ninepatch) { rect = node_ninepatch->get_region_rect(); - else if (obj_styleBox.is_valid()) + if (rect == Rect2()) { + rect = Rect2(Vector2(), node_ninepatch->get_texture()->get_size()); + } + } else if (obj_styleBox.is_valid()) rect = obj_styleBox->get_region_rect(); else if (atlas_tex.is_valid()) rect = atlas_tex->get_region(); diff --git a/editor/plugins/theme_editor_plugin.cpp b/editor/plugins/theme_editor_plugin.cpp index 5b67d259ba..3055a9382c 100644 --- a/editor/plugins/theme_editor_plugin.cpp +++ b/editor/plugins/theme_editor_plugin.cpp @@ -36,6 +36,7 @@ void ThemeEditor::edit(const Ref<Theme> &p_theme) { theme = p_theme; + main_panel->set_theme(p_theme); main_container->set_theme(p_theme); } @@ -53,6 +54,7 @@ void ThemeEditor::_propagate_redraw(Control *p_at) { void ThemeEditor::_refresh_interval() { + _propagate_redraw(main_panel); _propagate_redraw(main_container); } @@ -130,14 +132,14 @@ void ThemeEditor::_save_template_cbk(String fname) { Map<String, _TECategory> categories; - //fill types + // Fill types. List<StringName> type_list; Theme::get_default()->get_type_list(&type_list); for (List<StringName>::Element *E = type_list.front(); E; E = E->next()) { categories.insert(E->get(), _TECategory()); } - //fill default theme + // Fill default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); @@ -189,11 +191,9 @@ void ThemeEditor::_save_template_cbk(String fname) { } FileAccess *file = FileAccess::open(filename, FileAccess::WRITE); - if (!file) { - ERR_EXPLAIN(TTR("Can't save theme to file:") + " " + filename); - return; - } + ERR_FAIL_COND_MSG(!file, "Can't save theme to file: " + filename + "."); + file->store_line("; ******************* "); file->store_line("; Template Theme File "); file->store_line("; ******************* "); @@ -256,7 +256,7 @@ void ThemeEditor::_save_template_cbk(String fname) { file->store_line(""); file->store_line(""); - //write default theme + // Write default theme. for (Map<String, _TECategory>::Element *E = categories.front(); E; E = E->next()) { _TECategory &tc = E->get(); @@ -501,7 +501,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { type_select_label->show(); type_select->show(); - if (p_option == POPUP_ADD) { //add + if (p_option == POPUP_ADD) { // Add. add_del_dialog->set_title(TTR("Add Item")); add_del_dialog->get_ok()->set_text(TTR("Add")); @@ -509,7 +509,7 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { base_theme = Theme::get_default(); - } else if (p_option == POPUP_CLASS_ADD) { //add + } else if (p_option == POPUP_CLASS_ADD) { // Add. add_del_dialog->set_title(TTR("Add All Items")); add_del_dialog->get_ok()->set_text(TTR("Add All")); @@ -552,12 +552,10 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { type_menu->get_popup()->clear(); - if (p_option == 0 || p_option == 1) { //add + if (p_option == 0 || p_option == 1) { // Add. List<StringName> new_types; theme->get_type_list(&new_types); - - //uh kind of sucks for (List<StringName>::Element *F = new_types.front(); F; F = F->next()) { bool found = false; @@ -583,15 +581,17 @@ void ThemeEditor::_theme_menu_cbk(int p_option) { void ThemeEditor::_notification(int p_what) { - if (p_what == NOTIFICATION_PROCESS) { - - time_left -= get_process_delta_time(); - if (time_left < 0) { - time_left = 1.5; - _refresh_interval(); - } - } else if (p_what == NOTIFICATION_THEME_CHANGED) { - theme_menu->set_icon(get_icon("Theme", "EditorIcons")); + switch (p_what) { + case NOTIFICATION_PROCESS: { + time_left -= get_process_delta_time(); + if (time_left < 0) { + time_left = 1.5; + _refresh_interval(); + } + } break; + case NOTIFICATION_THEME_CHANGED: { + theme_menu->set_icon(get_icon("Theme", "EditorIcons")); + } break; } } @@ -629,35 +629,34 @@ ThemeEditor::ThemeEditor() { top_menu->add_child(theme_menu); theme_menu->get_popup()->connect("id_pressed", this, "_theme_menu_cbk"); - scroll = memnew(ScrollContainer); + ScrollContainer *scroll = memnew(ScrollContainer); add_child(scroll); - scroll->set_theme(Theme::get_default()); scroll->set_enable_v_scroll(true); scroll->set_enable_h_scroll(false); scroll->set_v_size_flags(SIZE_EXPAND_FILL); - main_container = memnew(MarginContainer); - scroll->add_child(main_container); - main_container->set_theme(Theme::get_default()); - main_container->set_clip_contents(true); - main_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE); - main_container->set_v_size_flags(SIZE_EXPAND_FILL); - main_container->set_h_size_flags(SIZE_EXPAND_FILL); + MarginContainer *root_container = memnew(MarginContainer); + scroll->add_child(root_container); + root_container->set_theme(Theme::get_default()); + root_container->set_clip_contents(true); + root_container->set_custom_minimum_size(Size2(700, 0) * EDSCALE); + root_container->set_v_size_flags(SIZE_EXPAND_FILL); + root_container->set_h_size_flags(SIZE_EXPAND_FILL); //// Preview Controls //// - Panel *panel = memnew(Panel); - main_container->add_child(panel); + main_panel = memnew(Panel); + root_container->add_child(main_panel); - MarginContainer *mc = memnew(MarginContainer); - main_container->add_child(mc); - mc->add_constant_override("margin_right", 4 * EDSCALE); - mc->add_constant_override("margin_top", 4 * EDSCALE); - mc->add_constant_override("margin_left", 4 * EDSCALE); - mc->add_constant_override("margin_bottom", 4 * EDSCALE); + main_container = memnew(MarginContainer); + root_container->add_child(main_container); + main_container->add_constant_override("margin_right", 4 * EDSCALE); + main_container->add_constant_override("margin_top", 4 * EDSCALE); + main_container->add_constant_override("margin_left", 4 * EDSCALE); + main_container->add_constant_override("margin_bottom", 4 * EDSCALE); HBoxContainer *main_hb = memnew(HBoxContainer); - mc->add_child(main_hb); + main_container->add_child(main_hb); VBoxContainer *first_vb = memnew(VBoxContainer); main_hb->add_child(first_vb); @@ -695,19 +694,19 @@ ThemeEditor::ThemeEditor() { test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_check_item(TTR("Check Item")); test_menu_button->get_popup()->add_check_item(TTR("Checked Item")); - test_menu_button->get_popup()->set_item_checked(3, true); + test_menu_button->get_popup()->set_item_checked(4, true); test_menu_button->get_popup()->add_separator(); test_menu_button->get_popup()->add_radio_check_item(TTR("Radio Item")); test_menu_button->get_popup()->add_radio_check_item(TTR("Checked Radio Item")); - test_menu_button->get_popup()->set_item_checked(6, true); + test_menu_button->get_popup()->set_item_checked(7, true); test_menu_button->get_popup()->add_separator(TTR("Named Sep.")); PopupMenu *test_submenu = memnew(PopupMenu); test_menu_button->get_popup()->add_child(test_submenu); test_submenu->set_name("submenu"); test_menu_button->get_popup()->add_submenu_item(TTR("Submenu"), "submenu"); - test_submenu->add_item(TTR("Item 1")); - test_submenu->add_item(TTR("Item 2")); + test_submenu->add_item(TTR("Subitem 1")); + test_submenu->add_item(TTR("Subitem 2")); first_vb->add_child(test_menu_button); OptionButton *test_option_button = memnew(OptionButton); diff --git a/editor/plugins/theme_editor_plugin.h b/editor/plugins/theme_editor_plugin.h index cc236907a9..6ffee46569 100644 --- a/editor/plugins/theme_editor_plugin.h +++ b/editor/plugins/theme_editor_plugin.h @@ -45,7 +45,7 @@ class ThemeEditor : public VBoxContainer { GDCLASS(ThemeEditor, VBoxContainer); - ScrollContainer *scroll; + Panel *main_panel; MarginContainer *main_container; Ref<Theme> theme; diff --git a/editor/plugins/tile_map_editor_plugin.cpp b/editor/plugins/tile_map_editor_plugin.cpp index 766890242f..90276041a8 100644 --- a/editor/plugins/tile_map_editor_plugin.cpp +++ b/editor/plugins/tile_map_editor_plugin.cpp @@ -376,7 +376,7 @@ void TileMapEditor::_sbox_input(const Ref<InputEvent> &p_ie) { } // Implementation detail of TileMapEditor::_update_palette(); -// in modern C++ this could have been inside its body +// In modern C++ this could have been inside its body. namespace { struct _PaletteEntry { int id; @@ -393,10 +393,10 @@ void TileMapEditor::_update_palette() { if (!node) return; - // Update the clear button + // Update the clear button. clear_transform_button->set_disabled(!flip_h && !flip_v && !transpose); - // Update the palette + // Update the palette. Vector<int> selected = get_selected_tiles(); int selected_single = palette->get_current(); int selected_manual = manual_palette->get_current(); @@ -405,8 +405,15 @@ void TileMapEditor::_update_palette() { manual_palette->hide(); Ref<TileSet> tileset = node->get_tileset(); - if (tileset.is_null()) + if (tileset.is_null()) { + search_box->set_text(""); + search_box->set_editable(false); + info_message->show(); return; + } + + search_box->set_editable(true); + info_message->hide(); List<int> tiles; tileset->get_tile_list(&tiles); @@ -421,7 +428,6 @@ void TileMapEditor::_update_palette() { bool sort_by_name = bool(EDITOR_DEF("editors/tile_map/sort_tiles_by_name", true)); palette->add_constant_override("hseparation", hseparation * EDSCALE); - palette->add_constant_override("vseparation", 8 * EDSCALE); palette->set_fixed_icon_size(Size2(min_size, min_size)); palette->set_fixed_column_width(min_size * MAX(size_slider->get_value(), 1)); @@ -479,7 +485,7 @@ void TileMapEditor::_update_palette() { region.position += (region.size + Vector2(spacing, spacing)) * tileset->autotile_get_icon_coordinate(entries[i].id); } - // Transpose and flip + // Transpose and flip. palette->set_item_icon_transposed(palette->get_item_count() - 1, transpose); if (flip_h) { region.size.x = -region.size.x; @@ -488,14 +494,14 @@ void TileMapEditor::_update_palette() { region.size.y = -region.size.y; } - // Set region + // Set region. if (region.size != Size2()) palette->set_item_icon_region(palette->get_item_count() - 1, region); - // Set icon + // Set icon. palette->set_item_icon(palette->get_item_count() - 1, tex); - // Modulation + // Modulation. Color color = tileset->tile_get_modulate(entries[i].id); palette->set_item_icon_modulate(palette->get_item_count() - 1, color); } @@ -511,44 +517,47 @@ void TileMapEditor::_update_palette() { palette->select(0); } - if (sel_tile != TileMap::INVALID_CELL) { - if ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || - (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE)) { + if (sel_tile != TileMap::INVALID_CELL && ((manual_autotile && tileset->tile_get_tile_mode(sel_tile) == TileSet::AUTO_TILE) || (!priority_atlastile && tileset->tile_get_tile_mode(sel_tile) == TileSet::ATLAS_TILE))) { - const Map<Vector2, uint32_t> &tiles2 = tileset->autotile_get_bitmask_map(sel_tile); + const Map<Vector2, uint32_t> &tiles2 = tileset->autotile_get_bitmask_map(sel_tile); - Vector<Vector2> entries2; - for (const Map<Vector2, uint32_t>::Element *E = tiles2.front(); E; E = E->next()) { - entries2.push_back(E->key()); + Vector<Vector2> entries2; + for (const Map<Vector2, uint32_t>::Element *E = tiles2.front(); E; E = E->next()) { + entries2.push_back(E->key()); + } + // Sort tiles in row-major order. + struct SwapComparator { + _FORCE_INLINE_ bool operator()(const Vector2 &v_l, const Vector2 &v_r) const { + return v_l.y != v_r.y ? v_l.y < v_r.y : v_l.x < v_r.x; } - entries2.sort(); - - Ref<Texture> tex = tileset->tile_get_texture(sel_tile); + }; + entries2.sort_custom<SwapComparator>(); - for (int i = 0; i < entries2.size(); i++) { + Ref<Texture> tex = tileset->tile_get_texture(sel_tile); - manual_palette->add_item(String()); + for (int i = 0; i < entries2.size(); i++) { - if (tex.is_valid()) { + manual_palette->add_item(String()); - Rect2 region = tileset->tile_get_region(sel_tile); - int spacing = tileset->autotile_get_spacing(sel_tile); - region.size = tileset->autotile_get_size(sel_tile); // !! - region.position += (region.size + Vector2(spacing, spacing)) * entries2[i]; + if (tex.is_valid()) { - if (!region.has_no_area()) - manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region); + Rect2 region = tileset->tile_get_region(sel_tile); + int spacing = tileset->autotile_get_spacing(sel_tile); + region.size = tileset->autotile_get_size(sel_tile); // !! + region.position += (region.size + Vector2(spacing, spacing)) * entries2[i]; - manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex); - } + if (!region.has_no_area()) + manual_palette->set_item_icon_region(manual_palette->get_item_count() - 1, region); - manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries2[i]); + manual_palette->set_item_icon(manual_palette->get_item_count() - 1, tex); } + + manual_palette->set_item_metadata(manual_palette->get_item_count() - 1, entries2[i]); } } if (manual_palette->get_item_count() > 0) { - // Only show the manual palette if at least tile exists in it + // Only show the manual palette if at least tile exists in it. if (selected_manual == -1 || selected_single != palette->get_current()) selected_manual = 0; if (selected_manual < manual_palette->get_item_count()) @@ -966,7 +975,7 @@ static inline Vector<Point2i> line(int x0, int x1, int y0, int y1) { bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { - if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree()) + if (!node || !node->get_tileset().is_valid() || !node->is_visible_in_tree() || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return false; Transform2D xform = CanvasItemEditor::get_singleton()->get_canvas_transform() * node->get_global_transform(); @@ -1527,7 +1536,7 @@ bool TileMapEditor::forward_gui_input(const Ref<InputEvent> &p_event) { void TileMapEditor::forward_canvas_draw_over_viewport(Control *p_overlay) { - if (!node) + if (!node || CanvasItemEditor::get_singleton()->get_current_tool() != CanvasItemEditor::TOOL_SELECT) return; Transform2D cell_xf = node->get_cell_transform(); @@ -1945,6 +1954,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { add_child(priority_button); search_box = memnew(LineEdit); + search_box->set_placeholder(TTR("Filter tiles")); search_box->set_h_size_flags(SIZE_EXPAND_FILL); search_box->connect("text_entered", this, "_text_entered"); search_box->connect("text_changed", this, "_text_changed"); @@ -1967,7 +1977,7 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { palette_container->set_custom_minimum_size(Size2(mw, 0)); add_child(palette_container); - // Add tile palette + // Add tile palette. palette = memnew(ItemList); palette->set_h_size_flags(SIZE_EXPAND_FILL); palette->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1975,11 +1985,21 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { palette->set_icon_mode(ItemList::ICON_MODE_TOP); palette->set_max_text_lines(2); palette->set_select_mode(ItemList::SELECT_MULTI); + palette->add_constant_override("vseparation", 8 * EDSCALE); palette->connect("item_selected", this, "_palette_selected"); palette->connect("multi_selected", this, "_palette_multi_selected"); palette_container->add_child(palette); - // Add autotile override palette + // Add message for when no texture is selected. + info_message = memnew(Label); + info_message->set_text(TTR("Give a TileSet resource to this TileMap to use its tiles.")); + info_message->set_valign(Label::VALIGN_CENTER); + info_message->set_align(Label::ALIGN_CENTER); + info_message->set_autowrap(true); + info_message->set_anchors_and_margins_preset(PRESET_WIDE, PRESET_MODE_KEEP_SIZE, 8 * EDSCALE); + palette->add_child(info_message); + + // Add autotile override palette. manual_palette = memnew(ItemList); manual_palette->set_h_size_flags(SIZE_EXPAND_FILL); manual_palette->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1989,18 +2009,17 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { manual_palette->hide(); palette_container->add_child(manual_palette); - // Add menu items + // Add menu items. toolbar = memnew(HBoxContainer); toolbar->hide(); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar); - // Separator toolbar->add_child(memnew(VSeparator)); - // Tools + // Tools. paint_button = memnew(ToolButton); paint_button->set_shortcut(ED_SHORTCUT("tile_map_editor/paint_tile", TTR("Paint Tile"), KEY_P)); - paint_button->set_tooltip(TTR("Shift+RMB: Line Draw\nShift+Ctrl+RMB: Rectangle Paint")); + paint_button->set_tooltip(TTR("Shift+LMB: Line Draw\nShift+Ctrl+LMB: Rectangle Paint")); paint_button->connect("pressed", this, "_button_tool_select", make_binds(TOOL_NONE)); paint_button->set_toggle_mode(true); toolbar->add_child(paint_button); @@ -2025,18 +2044,18 @@ TileMapEditor::TileMapEditor(EditorNode *p_editor) { _update_button_tool(); - // Container to the right of the toolbar + // Container to the right of the toolbar. toolbar_right = memnew(HBoxContainer); toolbar_right->hide(); toolbar_right->set_h_size_flags(SIZE_EXPAND_FILL); toolbar_right->set_alignment(BoxContainer::ALIGN_END); CanvasItemEditor::get_singleton()->add_control_to_menu_panel(toolbar_right); - // Tile position + // Tile position. tile_info = memnew(Label); toolbar_right->add_child(tile_info); - // Menu + // Menu. options = memnew(MenuButton); options->set_text("TileMap"); options->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("TileMap", "EditorIcons")); @@ -2130,6 +2149,8 @@ void TileMapEditorPlugin::make_visible(bool p_visible) { tile_map_editor->show(); tile_map_editor->get_toolbar()->show(); tile_map_editor->get_toolbar_right()->show(); + // Change to TOOL_SELECT when TileMap node is selected, to prevent accidental movement. + CanvasItemEditor::get_singleton()->set_current_tool(CanvasItemEditor::TOOL_SELECT); } else { tile_map_editor->hide(); diff --git a/editor/plugins/tile_map_editor_plugin.h b/editor/plugins/tile_map_editor_plugin.h index 3331fb971f..e3d678c2fd 100644 --- a/editor/plugins/tile_map_editor_plugin.h +++ b/editor/plugins/tile_map_editor_plugin.h @@ -41,10 +41,6 @@ #include "scene/gui/menu_button.h" #include "scene/gui/tool_button.h" -/** - @author Juan Linietsky <reduzio@gmail.com> -*/ - class TileMapEditor : public VBoxContainer { GDCLASS(TileMapEditor, VBoxContainer); @@ -86,6 +82,8 @@ class TileMapEditor : public VBoxContainer { ItemList *palette; ItemList *manual_palette; + Label *info_message; + HBoxContainer *toolbar; HBoxContainer *toolbar_right; diff --git a/editor/plugins/tile_set_editor_plugin.cpp b/editor/plugins/tile_set_editor_plugin.cpp index f135becf5f..e0bf8dfdb2 100644 --- a/editor/plugins/tile_set_editor_plugin.cpp +++ b/editor/plugins/tile_set_editor_plugin.cpp @@ -176,6 +176,86 @@ Error TileSetEditor::update_library_file(Node *p_base_scene, Ref<TileSet> ml, bo return OK; } +Variant TileSetEditor::get_drag_data_fw(const Point2 &p_point, Control *p_from) { + + return false; +} + +bool TileSetEditor::can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const { + + Dictionary d = p_data; + + if (!d.has("type")) + return false; + + if (d.has("from") && (Object *)(d["from"]) == texture_list) + return false; + + if (String(d["type"]) == "resource" && d.has("resource")) { + RES r = d["resource"]; + + Ref<Texture> texture = r; + + if (texture.is_valid()) { + + return true; + } + } + + if (String(d["type"]) == "files") { + + Vector<String> files = d["files"]; + + if (files.size() == 0) + return false; + + for (int i = 0; i < files.size(); i++) { + String file = files[i]; + String ftype = EditorFileSystem::get_singleton()->get_file_type(file); + + if (!ClassDB::is_parent_class(ftype, "Texture")) { + return false; + } + } + + return true; + } + return false; +} + +void TileSetEditor::drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) { + + if (!can_drop_data_fw(p_point, p_data, p_from)) + return; + + Dictionary d = p_data; + + if (!d.has("type")) + return; + + if (String(d["type"]) == "resource" && d.has("resource")) { + RES r = d["resource"]; + + Ref<Texture> texture = r; + + if (texture.is_valid()) + add_texture(texture); + + if (texture_list->get_item_count() > 0) { + update_texture_list_icon(); + texture_list->select(texture_list->get_item_count() - 1); + _on_texture_list_selected(texture_list->get_item_count() - 1); + } + } + + if (String(d["type"]) == "files") { + + PoolVector<String> files = d["files"]; + + _on_textures_added(files); + } +} + void TileSetEditor::_bind_methods() { ClassDB::bind_method("_undo_redo_import_scene", &TileSetEditor::_undo_redo_import_scene); @@ -203,6 +283,10 @@ void TileSetEditor::_bind_methods() { ClassDB::bind_method("_select_edited_shape_coord", &TileSetEditor::_select_edited_shape_coord); ClassDB::bind_method("_sort_tiles", &TileSetEditor::_sort_tiles); + ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &TileSetEditor::get_drag_data_fw); + ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &TileSetEditor::can_drop_data_fw); + ClassDB::bind_method(D_METHOD("drop_data_fw"), &TileSetEditor::drop_data_fw); + ClassDB::bind_method("edit", &TileSetEditor::edit); ClassDB::bind_method("add_texture", &TileSetEditor::add_texture); ClassDB::bind_method("remove_texture", &TileSetEditor::remove_texture); @@ -274,6 +358,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { texture_list->set_v_size_flags(SIZE_EXPAND_FILL); texture_list->set_custom_minimum_size(Size2(200, 0)); texture_list->connect("item_selected", this, "_on_texture_list_selected"); + texture_list->set_drag_forwarding(this); HBoxContainer *tileset_toolbar_container = memnew(HBoxContainer); left_container->add_child(tileset_toolbar_container); @@ -494,6 +579,14 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { scroll->set_v_size_flags(SIZE_EXPAND_FILL); scroll->set_clip_contents(true); + empty_message = memnew(Label); + empty_message->set_text(TTR("Add or select a texture on the left panel to edit the tiles bound to it.")); + empty_message->set_valign(Label::VALIGN_CENTER); + empty_message->set_align(Label::ALIGN_CENTER); + empty_message->set_autowrap(true); + empty_message->set_v_size_flags(SIZE_EXPAND_FILL); + main_vb->add_child(empty_message); + workspace_container = memnew(Control); scroll->add_child(workspace_container); @@ -542,7 +635,7 @@ TileSetEditor::TileSetEditor(EditorNode *p_editor) { helper = memnew(TilesetEditorContext(this)); tile_names_visible = false; - // config scale + // Config scale. max_scale = 10.0f; min_scale = 0.1f; scale_ratio = 1.2f; @@ -646,8 +739,7 @@ void TileSetEditor::_on_textures_added(const PoolStringArray &p_paths) { for (int i = 0; i < p_paths.size(); i++) { Ref<Texture> t = Ref<Texture>(ResourceLoader::load(p_paths[i])); - ERR_EXPLAIN("'" + p_paths[i] + "' is not a valid texture."); - ERR_CONTINUE(!t.is_valid()); + ERR_CONTINUE_MSG(!t.is_valid(), "'" + p_paths[i] + "' is not a valid texture."); if (texture_map.has(t->get_rid())) { invalid_count++; @@ -924,8 +1016,7 @@ void TileSetEditor::_on_workspace_draw() { case EDITMODE_OCCLUSION: case EDITMODE_NAVIGATION: { if (tileset->tile_get_tile_mode(get_current_tile()) == TileSet::AUTO_TILE || tileset->tile_get_tile_mode(get_current_tile()) == TileSet::ATLAS_TILE) { - Vector2 coord = edited_shape_coord; - draw_highlight_subtile(coord); + draw_highlight_subtile(edited_shape_coord); } draw_polygon_shapes(); draw_grid_snap(); @@ -1519,6 +1610,8 @@ void TileSetEditor::_on_workspace_input(const Ref<InputEvent> &p_ie) { undo_redo->create_action(TTR("Edit Navigation Polygon")); undo_redo->add_do_method(edited_navigation_shape.ptr(), "set_vertices", polygon); undo_redo->add_undo_method(edited_navigation_shape.ptr(), "set_vertices", edited_navigation_shape->get_vertices()); + undo_redo->add_do_method(edited_navigation_shape.ptr(), "clear_polygons"); + undo_redo->add_undo_method(edited_navigation_shape.ptr(), "clear_polygons"); undo_redo->add_do_method(edited_navigation_shape.ptr(), "add_polygon", indices); undo_redo->add_undo_method(edited_navigation_shape.ptr(), "add_polygon", edited_navigation_shape->get_polygon(0)); undo_redo->add_do_method(this, "_select_edited_shape_coord"); @@ -1872,7 +1965,7 @@ void TileSetEditor::_update_tile_data() { } else { int spacing = tileset->autotile_get_spacing(get_current_tile()); Vector2 size = tileset->tile_get_region(get_current_tile()).size; - Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing)); + Vector2 cell_count = (size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing))).floor(); for (int y = 0; y < cell_count.y; y++) { for (int x = 0; x < cell_count.x; x++) { SubtileData data; @@ -1974,7 +2067,7 @@ void TileSetEditor::_select_previous_tile() { case EDITMODE_Z_INDEX: { int spacing = tileset->autotile_get_spacing(get_current_tile()); Vector2 size = tileset->tile_get_region(get_current_tile()).size; - Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing)); + Vector2 cell_count = (size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing))).floor(); cell_count -= Vector2(1, 1); edited_shape_coord = cell_count; _select_edited_shape_coord(); @@ -2031,7 +2124,7 @@ void TileSetEditor::_select_next_subtile() { } else { int spacing = tileset->autotile_get_spacing(get_current_tile()); Vector2 size = tileset->tile_get_region(get_current_tile()).size; - Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing)); + Vector2 cell_count = (size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing))).floor(); if (edited_shape_coord.x >= cell_count.x - 1 && edited_shape_coord.y >= cell_count.y - 1) { _select_next_tile(); } else { @@ -2057,7 +2150,7 @@ void TileSetEditor::_select_previous_subtile() { } else { int spacing = tileset->autotile_get_spacing(get_current_tile()); Vector2 size = tileset->tile_get_region(get_current_tile()).size; - Vector2i cell_count = size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing)); + Vector2 cell_count = (size / (tileset->autotile_get_size(get_current_tile()) + Vector2(spacing, spacing))).floor(); if (edited_shape_coord.x <= 0 && edited_shape_coord.y <= 0) { _select_previous_tile(); } else { @@ -2077,9 +2170,9 @@ void TileSetEditor::_select_next_shape() { } else if (edit_mode != EDITMODE_COLLISION) { _select_next_subtile(); } else { - Vector2i edited_coord = Vector2(); + Vector2i edited_coord = Vector2i(); if (tileset->tile_get_tile_mode(get_current_tile()) != TileSet::SINGLE_TILE) { - edited_coord = edited_shape_coord; + edited_coord = Vector2i(edited_shape_coord); } SubtileData data = current_tile_data[edited_coord]; if (data.collisions.size() == 0) { @@ -2130,9 +2223,9 @@ void TileSetEditor::_select_previous_shape() { } else if (edit_mode != EDITMODE_COLLISION) { _select_previous_subtile(); } else { - Vector2i edited_coord = Vector2(); + Vector2i edited_coord = Vector2i(); if (tileset->tile_get_tile_mode(get_current_tile()) != TileSet::SINGLE_TILE) { - edited_coord = edited_shape_coord; + edited_coord = Vector2i(edited_shape_coord); } SubtileData data = current_tile_data[edited_coord]; if (data.collisions.size() == 0) { @@ -3038,12 +3131,28 @@ void TileSetEditor::update_workspace_tile_mode() { } tools[SELECT_NEXT]->set_disabled(true); tools[SELECT_PREVIOUS]->set_disabled(true); + + tools[ZOOM_OUT]->hide(); + tools[ZOOM_1]->hide(); + tools[ZOOM_IN]->hide(); + tools[VISIBLE_INFO]->hide(); + + scroll->hide(); + empty_message->show(); } else { for (int i = 1; i < WORKSPACE_MODE_MAX; i++) { tool_workspacemode[i]->set_disabled(false); } tools[SELECT_NEXT]->set_disabled(false); tools[SELECT_PREVIOUS]->set_disabled(false); + + tools[ZOOM_OUT]->show(); + tools[ZOOM_1]->show(); + tools[ZOOM_IN]->show(); + tools[VISIBLE_INFO]->show(); + + scroll->show(); + empty_message->hide(); } if (workspace_mode != WORKSPACE_EDIT) { diff --git a/editor/plugins/tile_set_editor_plugin.h b/editor/plugins/tile_set_editor_plugin.h index 69ad8205a4..944dc04e4e 100644 --- a/editor/plugins/tile_set_editor_plugin.h +++ b/editor/plugins/tile_set_editor_plugin.h @@ -138,6 +138,7 @@ class TileSetEditor : public HSplitContainer { int current_item_index; Sprite *preview; ScrollContainer *scroll; + Label *empty_message; Control *workspace_container; bool draw_handles; Control *workspace_overlay; @@ -173,6 +174,12 @@ class TileSetEditor : public HSplitContainer { static void _import_scene(Node *p_scene, Ref<TileSet> p_library, bool p_merge); void _undo_redo_import_scene(Node *p_scene, bool p_merge); + bool _is_drop_valid(const Dictionary &p_drag_data, const Dictionary &p_item_data) const; + Variant get_drag_data_fw(const Point2 &p_point, Control *p_from); + bool can_drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from) const; + void drop_data_fw(const Point2 &p_point, const Variant &p_data, Control *p_from); + void _file_load_request(const PoolVector<String> &p_path, int p_at_pos = -1); + protected: static void _bind_methods(); void _notification(int p_what); diff --git a/editor/plugins/version_control_editor_plugin.cpp b/editor/plugins/version_control_editor_plugin.cpp new file mode 100644 index 0000000000..e8cd7692b6 --- /dev/null +++ b/editor/plugins/version_control_editor_plugin.cpp @@ -0,0 +1,597 @@ +/*************************************************************************/ +/* version_control_editor_plugin.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 "version_control_editor_plugin.h" +#include "core/script_language.h" +#include "editor/editor_file_system.h" +#include "editor/editor_node.h" + +VersionControlEditorPlugin *VersionControlEditorPlugin::singleton = NULL; + +void VersionControlEditorPlugin::_bind_methods() { + + ClassDB::bind_method(D_METHOD("_selected_a_vcs"), &VersionControlEditorPlugin::_selected_a_vcs); + ClassDB::bind_method(D_METHOD("_initialize_vcs"), &VersionControlEditorPlugin::_initialize_vcs); + ClassDB::bind_method(D_METHOD("_send_commit_msg"), &VersionControlEditorPlugin::_send_commit_msg); + ClassDB::bind_method(D_METHOD("_refresh_stage_area"), &VersionControlEditorPlugin::_refresh_stage_area); + ClassDB::bind_method(D_METHOD("_stage_all"), &VersionControlEditorPlugin::_stage_all); + ClassDB::bind_method(D_METHOD("_stage_selected"), &VersionControlEditorPlugin::_stage_selected); + ClassDB::bind_method(D_METHOD("_view_file_diff"), &VersionControlEditorPlugin::_view_file_diff); + ClassDB::bind_method(D_METHOD("_refresh_file_diff"), &VersionControlEditorPlugin::_refresh_file_diff); + ClassDB::bind_method(D_METHOD("popup_vcs_set_up_dialog"), &VersionControlEditorPlugin::popup_vcs_set_up_dialog); + + // Used to track the status of files in the staging area + BIND_ENUM_CONSTANT(CHANGE_TYPE_NEW); + BIND_ENUM_CONSTANT(CHANGE_TYPE_MODIFIED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_RENAMED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_DELETED); + BIND_ENUM_CONSTANT(CHANGE_TYPE_TYPECHANGE); +} + +void VersionControlEditorPlugin::_selected_a_vcs(int p_id) { + + List<StringName> available_addons = get_available_vcs_names(); + const StringName selected_vcs = set_up_choice->get_item_text(p_id); +} + +void VersionControlEditorPlugin::_populate_available_vcs_names() { + + static bool called = false; + + if (!called) { + + List<StringName> available_addons = get_available_vcs_names(); + for (int i = 0; i < available_addons.size(); i++) { + + set_up_choice->add_item(available_addons[i]); + } + + called = true; + } +} + +VersionControlEditorPlugin *VersionControlEditorPlugin::get_singleton() { + + return singleton ? singleton : memnew(VersionControlEditorPlugin); +} + +void VersionControlEditorPlugin::popup_vcs_set_up_dialog(const Control *p_gui_base) { + + fetch_available_vcs_addon_names(); + List<StringName> available_addons = get_available_vcs_names(); + if (available_addons.size() >= 1) { + + Size2 popup_size = Size2(400, 100); + Size2 window_size = p_gui_base->get_viewport_rect().size; + popup_size.x = MIN(window_size.x * 0.5, popup_size.x); + popup_size.y = MIN(window_size.y * 0.5, popup_size.y); + + _populate_available_vcs_names(); + + set_up_dialog->popup_centered_clamped(popup_size * EDSCALE); + } else { + + EditorNode::get_singleton()->show_warning(TTR("No VCS addons are available."), TTR("Error")); + } +} + +void VersionControlEditorPlugin::_initialize_vcs() { + + register_editor(); + + if (EditorVCSInterface::get_singleton()) { + + ERR_EXPLAIN(EditorVCSInterface::get_singleton()->get_vcs_name() + " is already active"); + return; + } + + const int id = set_up_choice->get_selected_id(); + String selected_addon = set_up_choice->get_item_text(id); + + String path = ScriptServer::get_global_class_path(selected_addon); + Ref<Script> script = ResourceLoader::load(path); + if (!script.is_valid()) { + + ERR_EXPLAIN("VCS Addon path is invalid"); + } + + EditorVCSInterface *vcs_interface = memnew(EditorVCSInterface); + ScriptInstance *addon_script_instance = script->instance_create(vcs_interface); + if (!addon_script_instance) { + + ERR_FAIL_NULL(addon_script_instance); + return; + } + + // The addon is attached as a script to the VCS interface as a proxy end-point + vcs_interface->set_script_and_instance(script.get_ref_ptr(), addon_script_instance); + + EditorVCSInterface::set_singleton(vcs_interface); + EditorFileSystem::get_singleton()->connect("filesystem_changed", this, "_refresh_stage_area"); + + String res_dir = OS::get_singleton()->get_resource_dir(); + if (!EditorVCSInterface::get_singleton()->initialize(res_dir)) { + + ERR_EXPLAIN("VCS was not initialized"); + } + + _refresh_stage_area(); +} + +void VersionControlEditorPlugin::_send_commit_msg() { + + String msg = commit_message->get_text(); + if (msg == "") { + + commit_status->set_text(TTR("No commit message was provided")); + return; + } + + if (EditorVCSInterface::get_singleton()) { + + if (staged_files_count == 0) { + + commit_status->set_text(TTR("No files added to stage")); + return; + } + + EditorVCSInterface::get_singleton()->commit(msg); + + commit_message->set_text(""); + version_control_dock_button->set_pressed(false); + } else { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + } + + _update_commit_status(); + _refresh_stage_area(); + _clear_file_diff(); +} + +void VersionControlEditorPlugin::_refresh_stage_area() { + + if (EditorVCSInterface::get_singleton()) { + + staged_files_count = 0; + clear_stage_area(); + + Dictionary modified_file_paths = EditorVCSInterface::get_singleton()->get_modified_files_data(); + String file_path; + for (int i = 0; i < modified_file_paths.size(); i++) { + + file_path = modified_file_paths.get_key_at_index(i); + TreeItem *found = stage_files->search_item_text(file_path, 0, true); + if (!found) { + + ChangeType change_index = (ChangeType)(int)modified_file_paths.get_value_at_index(i); + String change_text = file_path + " (" + change_type_to_strings[change_index] + ")"; + Color &change_color = change_type_to_color[change_index]; + TreeItem *new_item = stage_files->create_item(stage_files->get_root()); + new_item->set_cell_mode(0, TreeItem::CELL_MODE_CHECK); + new_item->set_text(0, change_text); + new_item->set_metadata(0, file_path); + new_item->set_custom_color(0, change_color); + new_item->set_checked(0, true); + new_item->set_editable(0, true); + } else { + + if (found->get_metadata(0) == diff_file_name->get_text()) { + + _refresh_file_diff(); + } + } + commit_status->set_text("New changes detected"); + } + } else { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu.") + } +} + +void VersionControlEditorPlugin::_stage_selected() { + + if (!EditorVCSInterface::get_singleton()) { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + return; + } + + staged_files_count = 0; + TreeItem *root = stage_files->get_root(); + if (root) { + + TreeItem *file_entry = root->get_children(); + while (file_entry) { + + if (file_entry->is_checked(0)) { + + EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + staged_files_count++; + } else { + + EditorVCSInterface::get_singleton()->unstage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + } + + file_entry = file_entry->get_next(); + } + } + + _update_stage_status(); +} + +void VersionControlEditorPlugin::_stage_all() { + + if (!EditorVCSInterface::get_singleton()) { + + WARN_PRINT("No VCS addon is initialized. Select a Version Control Addon from Project menu"); + return; + } + + staged_files_count = 0; + TreeItem *root = stage_files->get_root(); + if (root) { + + TreeItem *file_entry = root->get_children(); + while (file_entry) { + + EditorVCSInterface::get_singleton()->stage_file(file_entry->get_metadata(0)); + file_entry->set_icon_modulate(0, EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + file_entry->set_checked(0, true); + staged_files_count++; + + file_entry = file_entry->get_next(); + } + } + + _update_stage_status(); +} + +void VersionControlEditorPlugin::_view_file_diff() { + + version_control_dock_button->set_pressed(true); + + String file_path = stage_files->get_selected()->get_metadata(0); + + _display_file_diff(file_path); +} + +void VersionControlEditorPlugin::_display_file_diff(String p_file_path) { + + Array diff_content = EditorVCSInterface::get_singleton()->get_file_diff(p_file_path); + + diff_file_name->set_text(p_file_path); + + diff->clear(); + diff->push_font(EditorNode::get_singleton()->get_gui_base()->get_font("source", "EditorFonts")); + for (int i = 0; i < diff_content.size(); i++) { + + Dictionary line_result = diff_content[i]; + + if (line_result["status"] == "+") { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor")); + } else if (line_result["status"] == "-") { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor")); + } else { + + diff->push_color(EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Label")); + } + + diff->add_text((String)line_result["content"]); + + diff->pop(); + } + diff->pop(); +} + +void VersionControlEditorPlugin::_refresh_file_diff() { + + String open_file = diff_file_name->get_text(); + if (open_file != "") { + + _display_file_diff(diff_file_name->get_text()); + } +} + +void VersionControlEditorPlugin::_clear_file_diff() { + + diff->clear(); + diff_file_name->set_text(""); + version_control_dock_button->set_pressed(false); +} + +void VersionControlEditorPlugin::_update_stage_status() { + + String status; + if (staged_files_count == 1) { + + status = "Stage contains 1 file"; + } else { + + status = "Stage contains " + String::num_int64(staged_files_count) + " files"; + } + commit_status->set_text(status); +} + +void VersionControlEditorPlugin::_update_commit_status() { + + String status; + if (staged_files_count == 1) { + + status = "Committed 1 file"; + } else { + + status = "Committed " + String::num_int64(staged_files_count) + " files "; + } + commit_status->set_text(status); + staged_files_count = 0; +} + +void VersionControlEditorPlugin::register_editor() { + + if (!EditorVCSInterface::get_singleton()) { + + EditorNode::get_singleton()->add_control_to_dock(EditorNode::DOCK_SLOT_RIGHT_UL, version_commit_dock); + TabContainer *dock_vbc = (TabContainer *)version_commit_dock->get_parent_control(); + dock_vbc->set_tab_title(version_commit_dock->get_index(), TTR("Commit")); + + ToolButton *vc = EditorNode::get_singleton()->add_bottom_panel_item(TTR("Version Control"), version_control_dock); + set_version_control_tool_button(vc); + } +} + +void VersionControlEditorPlugin::fetch_available_vcs_addon_names() { + + List<StringName> global_classes; + ScriptServer::get_global_class_list(&global_classes); + + for (int i = 0; i != global_classes.size(); i++) { + + String path = ScriptServer::get_global_class_path(global_classes[i]); + Ref<Script> script = ResourceLoader::load(path); + + if (script->get_instance_base_type() == "EditorVCSInterface") { + + available_addons.push_back(global_classes[i]); + } + } +} + +void VersionControlEditorPlugin::clear_stage_area() { + + stage_files->get_root()->clear_children(); +} + +void VersionControlEditorPlugin::shut_down() { + + if (EditorVCSInterface::get_singleton()) { + + EditorFileSystem::get_singleton()->disconnect("filesystem_changed", this, "_refresh_stage_area"); + EditorVCSInterface::get_singleton()->shut_down(); + memdelete(EditorVCSInterface::get_singleton()); + EditorVCSInterface::set_singleton(NULL); + + EditorNode::get_singleton()->remove_control_from_dock(version_commit_dock); + EditorNode::get_singleton()->remove_bottom_panel_item(version_control_dock); + } +} + +bool VersionControlEditorPlugin::get_is_vcs_intialized() const { + + return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_is_vcs_intialized() : false; +} + +const String VersionControlEditorPlugin::get_vcs_name() const { + + return EditorVCSInterface::get_singleton() ? EditorVCSInterface::get_singleton()->get_vcs_name() : ""; +} + +VersionControlEditorPlugin::VersionControlEditorPlugin() { + + singleton = this; + staged_files_count = 0; + + version_control_actions = memnew(PopupMenu); + version_control_actions->set_v_size_flags(BoxContainer::SIZE_SHRINK_CENTER); + + set_up_dialog = memnew(AcceptDialog); + set_up_dialog->set_title(TTR("Set Up Version Control")); + set_up_dialog->set_custom_minimum_size(Size2(400, 100)); + version_control_actions->add_child(set_up_dialog); + + set_up_ok_button = set_up_dialog->get_ok(); + set_up_ok_button->set_text(TTR("Close")); + + set_up_vbc = memnew(VBoxContainer); + set_up_vbc->set_alignment(VBoxContainer::ALIGN_CENTER); + set_up_dialog->add_child(set_up_vbc); + + set_up_hbc = memnew(HBoxContainer); + set_up_hbc->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL); + set_up_vbc->add_child(set_up_hbc); + + set_up_vcs_status = memnew(RichTextLabel); + set_up_vcs_status->set_text(TTR("VCS Addon is not initialized")); + set_up_vbc->add_child(set_up_vcs_status); + + set_up_vcs_label = memnew(Label); + set_up_vcs_label->set_text(TTR("Version Control System")); + set_up_hbc->add_child(set_up_vcs_label); + + set_up_choice = memnew(OptionButton); + set_up_choice->set_h_size_flags(HBoxContainer::SIZE_EXPAND_FILL); + set_up_choice->connect("item_selected", this, "_selected_a_vcs"); + set_up_hbc->add_child(set_up_choice); + + set_up_init_settings = NULL; + + set_up_init_button = memnew(Button); + set_up_init_button->set_text(TTR("Initialize")); + set_up_init_button->connect("pressed", this, "_initialize_vcs"); + set_up_vbc->add_child(set_up_init_button); + + version_control_actions->set_v_size_flags(PopupMenu::SIZE_EXPAND_FILL); + version_control_actions->set_h_size_flags(PopupMenu::SIZE_EXPAND_FILL); + + version_commit_dock = memnew(VBoxContainer); + version_commit_dock->set_visible(false); + + commit_box_vbc = memnew(VBoxContainer); + commit_box_vbc->set_alignment(VBoxContainer::ALIGN_BEGIN); + commit_box_vbc->set_h_size_flags(VBoxContainer::SIZE_EXPAND_FILL); + commit_box_vbc->set_v_size_flags(VBoxContainer::SIZE_EXPAND_FILL); + version_commit_dock->add_child(commit_box_vbc); + + stage_tools = memnew(HSplitContainer); + stage_tools->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED); + commit_box_vbc->add_child(stage_tools); + + staging_area_label = memnew(Label); + staging_area_label->set_h_size_flags(Label::SIZE_EXPAND_FILL); + staging_area_label->set_text(TTR("Staging area")); + stage_tools->add_child(staging_area_label); + + refresh_button = memnew(Button); + refresh_button->set_tooltip(TTR("Detect new changes")); + refresh_button->set_text(TTR("Refresh")); + refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons")); + refresh_button->connect("pressed", this, "_refresh_stage_area"); + stage_tools->add_child(refresh_button); + + stage_files = memnew(Tree); + stage_files->set_h_size_flags(Tree::SIZE_EXPAND_FILL); + stage_files->set_v_size_flags(Tree::SIZE_EXPAND_FILL); + stage_files->set_columns(1); + stage_files->set_column_title(0, TTR("Changes")); + stage_files->set_column_titles_visible(true); + stage_files->set_allow_reselect(true); + stage_files->set_allow_rmb_select(true); + stage_files->set_select_mode(Tree::SelectMode::SELECT_MULTI); + stage_files->set_edit_checkbox_cell_only_when_checkbox_is_pressed(true); + stage_files->connect("cell_selected", this, "_view_file_diff"); + stage_files->create_item(); + stage_files->set_hide_root(true); + commit_box_vbc->add_child(stage_files); + + change_type_to_strings[CHANGE_TYPE_NEW] = TTR("New"); + change_type_to_strings[CHANGE_TYPE_MODIFIED] = TTR("Modified"); + change_type_to_strings[CHANGE_TYPE_RENAMED] = TTR("Renamed"); + change_type_to_strings[CHANGE_TYPE_DELETED] = TTR("Deleted"); + change_type_to_strings[CHANGE_TYPE_TYPECHANGE] = TTR("Typechange"); + + change_type_to_color[CHANGE_TYPE_NEW] = EditorNode::get_singleton()->get_gui_base()->get_color("success_color", "Editor"); + change_type_to_color[CHANGE_TYPE_MODIFIED] = EditorNode::get_singleton()->get_gui_base()->get_color("warning_color", "Editor"); + change_type_to_color[CHANGE_TYPE_RENAMED] = EditorNode::get_singleton()->get_gui_base()->get_color("disabled_font_color", "Editor"); + change_type_to_color[CHANGE_TYPE_DELETED] = EditorNode::get_singleton()->get_gui_base()->get_color("error_color", "Editor"); + change_type_to_color[CHANGE_TYPE_TYPECHANGE] = EditorNode::get_singleton()->get_gui_base()->get_color("font_color", "Editor"); + + stage_buttons = memnew(HSplitContainer); + stage_buttons->set_dragger_visibility(SplitContainer::DRAGGER_HIDDEN_COLLAPSED); + commit_box_vbc->add_child(stage_buttons); + + stage_selected_button = memnew(Button); + stage_selected_button->set_h_size_flags(Button::SIZE_EXPAND_FILL); + stage_selected_button->set_text(TTR("Stage Selected")); + stage_selected_button->connect("pressed", this, "_stage_selected"); + stage_buttons->add_child(stage_selected_button); + + stage_all_button = memnew(Button); + stage_all_button->set_text(TTR("Stage All")); + stage_all_button->connect("pressed", this, "_stage_all"); + stage_buttons->add_child(stage_all_button); + + commit_box_vbc->add_child(memnew(HSeparator)); + + commit_message = memnew(TextEdit); + commit_message->set_h_size_flags(Control::SIZE_EXPAND_FILL); + commit_message->set_h_grow_direction(Control::GrowDirection::GROW_DIRECTION_BEGIN); + commit_message->set_v_grow_direction(Control::GrowDirection::GROW_DIRECTION_END); + commit_message->set_custom_minimum_size(Size2(200, 100)); + commit_message->set_wrap_enabled(true); + commit_message->set_text(TTR("Add a commit message")); + commit_box_vbc->add_child(commit_message); + + commit_button = memnew(Button); + commit_button->set_text(TTR("Commit Changes")); + commit_button->connect("pressed", this, "_send_commit_msg"); + commit_box_vbc->add_child(commit_button); + + commit_status = memnew(Label); + commit_status->set_align(Label::ALIGN_CENTER); + commit_box_vbc->add_child(commit_status); + + version_control_dock = memnew(PanelContainer); + version_control_dock->set_v_size_flags(Control::SIZE_EXPAND_FILL); + version_control_dock->hide(); + + diff_vbc = memnew(VBoxContainer); + diff_vbc->set_h_size_flags(HBoxContainer::SIZE_FILL); + diff_vbc->set_v_size_flags(HBoxContainer::SIZE_FILL); + version_control_dock->add_child(diff_vbc); + + diff_hbc = memnew(HBoxContainer); + diff_hbc->set_h_size_flags(HBoxContainer::SIZE_FILL); + diff_vbc->add_child(diff_hbc); + + diff_heading = memnew(Label); + diff_heading->set_text(TTR("Status")); + diff_heading->set_tooltip(TTR("View file diffs before committing them to the latest version")); + diff_hbc->add_child(diff_heading); + + diff_file_name = memnew(Label); + diff_file_name->set_text(TTR("No file diff is active")); + diff_file_name->set_h_size_flags(Label::SIZE_EXPAND_FILL); + diff_file_name->set_align(Label::ALIGN_RIGHT); + diff_hbc->add_child(diff_file_name); + + diff_refresh_button = memnew(Button); + diff_refresh_button->set_tooltip(TTR("Detect changes in file diff")); + diff_refresh_button->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Reload", "EditorIcons")); + diff_refresh_button->connect("pressed", this, "_refresh_file_diff"); + diff_hbc->add_child(diff_refresh_button); + + diff = memnew(RichTextLabel); + diff->set_h_size_flags(TextEdit::SIZE_EXPAND_FILL); + diff->set_v_size_flags(TextEdit::SIZE_EXPAND_FILL); + diff->set_selection_enabled(true); + diff_vbc->add_child(diff); +} + +VersionControlEditorPlugin::~VersionControlEditorPlugin() { + + shut_down(); + memdelete(version_control_dock); + memdelete(version_commit_dock); + memdelete(version_control_actions); +} diff --git a/editor/plugins/version_control_editor_plugin.h b/editor/plugins/version_control_editor_plugin.h new file mode 100644 index 0000000000..450ebccce1 --- /dev/null +++ b/editor/plugins/version_control_editor_plugin.h @@ -0,0 +1,146 @@ +/*************************************************************************/ +/* version_control_editor_plugin.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2019 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 VERSION_CONTROL_EDITOR_PLUGIN_H +#define VERSION_CONTROL_EDITOR_PLUGIN_H + +#include "editor/editor_plugin.h" +#include "editor/editor_vcs_interface.h" +#include "scene/gui/container.h" +#include "scene/gui/rich_text_label.h" +#include "scene/gui/text_edit.h" +#include "scene/gui/tree.h" + +class VersionControlEditorPlugin : public EditorPlugin { + + GDCLASS(VersionControlEditorPlugin, EditorPlugin) + +public: + enum ChangeType { + + CHANGE_TYPE_NEW = 0, + CHANGE_TYPE_MODIFIED = 1, + CHANGE_TYPE_RENAMED = 2, + CHANGE_TYPE_DELETED = 3, + CHANGE_TYPE_TYPECHANGE = 4 + }; + +private: + static VersionControlEditorPlugin *singleton; + + int staged_files_count; + List<StringName> available_addons; + + PopupMenu *version_control_actions; + AcceptDialog *set_up_dialog; + VBoxContainer *set_up_vbc; + HBoxContainer *set_up_hbc; + Label *set_up_vcs_label; + OptionButton *set_up_choice; + PanelContainer *set_up_init_settings; + Button *set_up_init_button; + RichTextLabel *set_up_vcs_status; + Button *set_up_ok_button; + + HashMap<ChangeType, String> change_type_to_strings; + HashMap<ChangeType, Color> change_type_to_color; + + VBoxContainer *version_commit_dock; + VBoxContainer *commit_box_vbc; + HSplitContainer *stage_tools; + Tree *stage_files; + TreeItem *new_files; + TreeItem *modified_files; + TreeItem *renamed_files; + TreeItem *deleted_files; + TreeItem *typechange_files; + Label *staging_area_label; + HSplitContainer *stage_buttons; + Button *stage_all_button; + Button *stage_selected_button; + Button *refresh_button; + TextEdit *commit_message; + Button *commit_button; + Label *commit_status; + + PanelContainer *version_control_dock; + ToolButton *version_control_dock_button; + VBoxContainer *diff_vbc; + HBoxContainer *diff_hbc; + Button *diff_refresh_button; + Label *diff_file_name; + Label *diff_heading; + RichTextLabel *diff; + + void _populate_available_vcs_names(); + void _selected_a_vcs(int p_id); + void _initialize_vcs(); + void _send_commit_msg(); + void _refresh_stage_area(); + void _stage_selected(); + void _stage_all(); + void _view_file_diff(); + void _display_file_diff(String p_file_path); + void _refresh_file_diff(); + void _clear_file_diff(); + void _update_stage_status(); + void _update_commit_status(); + + friend class EditorVCSInterface; + +protected: + static void _bind_methods(); + +public: + static VersionControlEditorPlugin *get_singleton(); + + void popup_vcs_set_up_dialog(const Control *p_gui_base); + void set_version_control_tool_button(ToolButton *p_button) { version_control_dock_button = p_button; } + + PopupMenu *get_version_control_actions_panel() const { return version_control_actions; } + VBoxContainer *get_version_commit_dock() const { return version_commit_dock; } + PanelContainer *get_version_control_dock() const { return version_control_dock; } + + List<StringName> get_available_vcs_names() const { return available_addons; } + bool get_is_vcs_intialized() const; + const String get_vcs_name() const; + + void register_editor(); + void fetch_available_vcs_addon_names(); + void clear_stage_area(); + void shut_down(); + + VersionControlEditorPlugin(); + ~VersionControlEditorPlugin(); +}; + +VARIANT_ENUM_CAST(VersionControlEditorPlugin::ChangeType); + +#endif // !VERSION_CONTROL_EDITOR_PLUGIN_H diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 28719d9e3e..82baa99da2 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -41,18 +41,19 @@ #include "scene/gui/panel.h" #include "scene/main/viewport.h" #include "scene/resources/visual_shader_nodes.h" +#include "servers/visual/shader_types.h" -Control *VisualShaderNodePlugin::create_editor(const Ref<VisualShaderNode> &p_node) { +Control *VisualShaderNodePlugin::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { if (get_script_instance()) { - return get_script_instance()->call("create_editor", p_node); + return get_script_instance()->call("create_editor", p_parent_resource, p_node); } return NULL; } void VisualShaderNodePlugin::_bind_methods() { - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); + BIND_VMETHOD(MethodInfo(Variant::OBJECT, "create_editor", PropertyInfo(Variant::OBJECT, "parent_resource", PROPERTY_HINT_RESOURCE_TYPE, "Resource"), PropertyInfo(Variant::OBJECT, "for_node", PROPERTY_HINT_RESOURCE_TYPE, "VisualShaderNode"))); } /////////////////// @@ -69,8 +70,16 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { } } visual_shader = Ref<VisualShader>(p_visual_shader); + if (!visual_shader->is_connected("changed", this, "_update_preview")) { + visual_shader->connect("changed", this, "_update_preview"); + } visual_shader->set_graph_offset(graph->get_scroll_ofs() / EDSCALE); } else { + if (visual_shader.is_valid()) { + if (visual_shader->is_connected("changed", this, "")) { + visual_shader->disconnect("changed", this, "_update_preview"); + } + } visual_shader.unref(); } @@ -78,7 +87,10 @@ void VisualShaderEditor::edit(VisualShader *p_visual_shader) { hide(); } else { if (changed) { // to avoid tree collapse + _clear_buffer(); + _update_custom_nodes(); _update_options_menu(); + _update_preview(); } _update_graph(); } @@ -94,31 +106,36 @@ void VisualShaderEditor::remove_plugin(const Ref<VisualShaderNodePlugin> &p_plug plugins.erase(p_plugin); } -void VisualShaderEditor::add_custom_type(const String &p_name, const String &p_category, const Ref<Script> &p_script) { - +void VisualShaderEditor::clear_custom_types() { for (int i = 0; i < add_options.size(); i++) { - ERR_FAIL_COND(add_options[i].script == p_script); + if (add_options[i].is_custom) { + add_options.remove(i); + } } - - AddOption ao; - ao.name = p_name; - ao.script = p_script; - ao.category = p_category; - add_options.push_back(ao); - - _update_options_menu(); } -void VisualShaderEditor::remove_custom_type(const Ref<Script> &p_script) { +void VisualShaderEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_sub_category) { + + ERR_FAIL_COND(!p_name.is_valid_identifier()); + ERR_FAIL_COND(!p_script.is_valid()); for (int i = 0; i < add_options.size(); i++) { - if (add_options[i].script == p_script) { - add_options.remove(i); - return; + if (add_options[i].is_custom) { + if (add_options[i].script == p_script) + return; } } - _update_options_menu(); + AddOption ao; + ao.name = p_name; + ao.script = p_script; + ao.return_type = p_return_icon_type; + ao.description = p_description; + ao.category = p_category; + ao.sub_category = p_sub_category; + ao.is_custom = true; + + add_options.push_back(ao); } bool VisualShaderEditor::_is_available(int p_mode) { @@ -161,6 +178,66 @@ bool VisualShaderEditor::_is_available(int p_mode) { return (p_mode == -1 || (p_mode & current_mode) != 0); } +void VisualShaderEditor::_update_custom_nodes() { + clear_custom_types(); + List<StringName> class_list; + ScriptServer::get_global_class_list(&class_list); + for (int i = 0; i < class_list.size(); i++) { + if (ScriptServer::get_global_class_native_base(class_list[i]) == "VisualShaderNodeCustom") { + + String script_path = ScriptServer::get_global_class_path(class_list[i]); + Ref<Resource> res = ResourceLoader::load(script_path); + ERR_FAIL_COND(res.is_null()); + ERR_FAIL_COND(!res->is_class("Script")); + Ref<Script> script = Ref<Script>(res); + + Ref<VisualShaderNodeCustom> ref; + ref.instance(); + ref->set_script(script.get_ref_ptr()); + + String name; + if (ref->has_method("_get_name")) { + name = (String)ref->call("_get_name"); + } else { + name = "Unnamed"; + } + + String description = ""; + if (ref->has_method("_get_description")) { + description = (String)ref->call("_get_description"); + } + + int return_icon_type = -1; + if (ref->has_method("_get_return_icon_type")) { + return_icon_type = (int)ref->call("_get_return_icon_type"); + } + + String category = ""; + if (ref->has_method("_get_category")) { + category = (String)ref->call("_get_category"); + } + if (category == "") { + category = "Custom"; + } + + String sub_category = ""; + if (ref->has_method("_get_subcategory")) { + sub_category = (String)ref->call("_get_subcategory"); + } + + add_custom_type(name, script, description, return_icon_type, category, sub_category); + } + } +} + +String VisualShaderEditor::_get_description(int p_idx) { + if (add_options[p_idx].highend) { + return TTR("(GLES3 only)") + " " + add_options[p_idx].description; // TODO: change it to (Vulkan Only) when its ready + } else { + return add_options[p_idx].description; + } +} + void VisualShaderEditor::_update_options_menu() { node_desc->set_text(""); @@ -210,6 +287,9 @@ void VisualShaderEditor::_update_options_menu() { if (!use_filter || add_options[i].name.findn(filter) != -1) { + if ((add_options[i].func != current_func && add_options[i].func != -1) || !_is_available(add_options[i].mode)) + continue; + if (prev_category != add_options[i].category) { if (category != NULL && item_count == 0) { memdelete(category); @@ -240,73 +320,52 @@ void VisualShaderEditor::_update_options_menu() { sub_category->set_collapsed(true); } } - if (sub_category != NULL) { - if ((add_options[i].func == current_func || add_options[i].func == -1) && _is_available(add_options[i].mode)) { - ++item_count2; - TreeItem *item = members->create_item(sub_category); - if (add_options[i].highend && low_driver) - item->set_custom_color(0, unsupported_color); - else if (add_options[i].highend) - item->set_custom_color(0, supported_color); - item->set_text(0, add_options[i].name); - if (is_first_item) { - item->select(0); - is_first_item = false; - } - switch (add_options[i].return_type) { - case VisualShaderNode::PORT_TYPE_SCALAR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_VECTOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_BOOLEAN: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_TRANSFORM: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_COLOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); - break; - default: - break; - } - item->set_meta("id", i); - } - } } else { - if (category != NULL) { - if ((add_options[i].func == current_func || add_options[i].func == -1) && _is_available(add_options[i].mode)) { - ++item_count; - TreeItem *item = members->create_item(category); - if (add_options[i].highend && low_driver) - item->set_custom_color(0, unsupported_color); - else if (add_options[i].highend) - item->set_custom_color(0, supported_color); - item->set_text(0, add_options[i].name); - switch (add_options[i].return_type) { - case VisualShaderNode::PORT_TYPE_SCALAR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_VECTOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_BOOLEAN: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_TRANSFORM: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); - break; - case VisualShaderNode::PORT_TYPE_COLOR: - item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); - break; - default: - break; - } - item->set_meta("id", i); - } + sub_category = NULL; + } + + TreeItem *p_category = NULL; + + if (sub_category != NULL) { + p_category = sub_category; + ++item_count2; + } else if (category != NULL) { + p_category = category; + ++item_count; + } + + if (p_category != NULL) { + TreeItem *item = members->create_item(p_category); + if (add_options[i].highend && low_driver) + item->set_custom_color(0, unsupported_color); + else if (add_options[i].highend) + item->set_custom_color(0, supported_color); + item->set_text(0, add_options[i].name); + if (is_first_item && use_filter) { + item->select(0); + node_desc->set_text(_get_description(i)); + is_first_item = false; + } + switch (add_options[i].return_type) { + case VisualShaderNode::PORT_TYPE_SCALAR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("float", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_VECTOR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Vector3", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_BOOLEAN: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("bool", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_TRANSFORM: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Transform", "EditorIcons")); + break; + case VisualShaderNode::PORT_TYPE_ICON_COLOR: + item->set_icon(0, EditorNode::get_singleton()->get_gui_base()->get_icon("Color", "EditorIcons")); + break; + default: + break; } + item->set_meta("id", i); } prev_sub_category = add_options[i].sub_category; @@ -351,6 +410,7 @@ void VisualShaderEditor::_update_created_node(GraphNode *node) { node->add_color_override("title_color", c); c.a = 0.7; node->add_color_override("close_color", c); + node->add_color_override("resizer_color", c); } } @@ -438,7 +498,7 @@ void VisualShaderEditor::_update_graph() { int port_offset = 0; if (is_group) { - port_offset++; + port_offset += 2; } Ref<VisualShaderNodeUniform> uniform = vsnode; @@ -462,7 +522,7 @@ void VisualShaderEditor::_update_graph() { } for (int i = 0; i < plugins.size(); i++) { - custom_editor = plugins.write[i]->create_editor(vsnode); + custom_editor = plugins.write[i]->create_editor(visual_shader, vsnode); if (custom_editor) { break; } @@ -477,21 +537,28 @@ void VisualShaderEditor::_update_graph() { } if (is_group) { - HBoxContainer *hb2 = memnew(HBoxContainer); - Button *add_input_btn = memnew(Button); - add_input_btn->set_text(TTR("Add input +")); - add_input_btn->connect("pressed", this, "_add_input_port", varray(nodes[n_i], group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "input" + itos(group_node->get_free_input_port_id())), CONNECT_DEFERRED); - hb2->add_child(add_input_btn); + offset = memnew(Control); + offset->set_custom_minimum_size(Size2(0, 6 * EDSCALE)); + node->add_child(offset); + + if (group_node->is_editable()) { + HBoxContainer *hb2 = memnew(HBoxContainer); + + Button *add_input_btn = memnew(Button); + add_input_btn->set_text(TTR("Add input +")); + add_input_btn->connect("pressed", this, "_add_input_port", varray(nodes[n_i], group_node->get_free_input_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "input" + itos(group_node->get_free_input_port_id())), CONNECT_DEFERRED); + hb2->add_child(add_input_btn); - hb2->add_spacer(); + hb2->add_spacer(); - Button *add_output_btn = memnew(Button); - add_output_btn->set_text(TTR("Add output +")); - add_output_btn->connect("pressed", this, "_add_output_port", varray(nodes[n_i], group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "output" + itos(group_node->get_free_output_port_id())), CONNECT_DEFERRED); - hb2->add_child(add_output_btn); + Button *add_output_btn = memnew(Button); + add_output_btn->set_text(TTR("Add output +")); + add_output_btn->connect("pressed", this, "_add_output_port", varray(nodes[n_i], group_node->get_free_output_port_id(), VisualShaderNode::PORT_TYPE_VECTOR, "output" + itos(group_node->get_free_output_port_id())), CONNECT_DEFERRED); + hb2->add_child(add_output_btn); - node->add_child(hb2); + node->add_child(hb2); + } } for (int i = 0; i < MAX(vsnode->get_input_port_count(), vsnode->get_output_port_count()); i++) { @@ -524,6 +591,7 @@ void VisualShaderEditor::_update_graph() { } HBoxContainer *hb = memnew(HBoxContainer); + hb->add_constant_override("separation", 7 * EDSCALE); Variant default_value; @@ -559,7 +627,6 @@ void VisualShaderEditor::_update_graph() { } if (i == 0 && custom_editor) { - hb->add_child(custom_editor); custom_editor->set_h_size_flags(SIZE_EXPAND_FILL); } else { @@ -567,7 +634,6 @@ void VisualShaderEditor::_update_graph() { if (valid_left) { if (is_group) { - OptionButton *type_box = memnew(OptionButton); hb->add_child(type_box); type_box->add_item(TTR("Scalar")); @@ -580,9 +646,9 @@ void VisualShaderEditor::_update_graph() { LineEdit *name_box = memnew(LineEdit); hb->add_child(name_box); - name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0)); + name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0)); + name_box->set_h_size_flags(SIZE_EXPAND_FILL); name_box->set_text(name_left); - name_box->set_expand_to_text_length(true); name_box->connect("text_entered", this, "_change_input_port_name", varray(name_box, nodes[n_i], i)); name_box->connect("focus_exited", this, "_port_name_focus_out", varray(name_box, nodes[n_i], i, false)); @@ -600,7 +666,9 @@ void VisualShaderEditor::_update_graph() { } } - hb->add_spacer(); + if (!is_group) { + hb->add_spacer(); + } if (valid_right) { if (is_group) { @@ -612,9 +680,9 @@ void VisualShaderEditor::_update_graph() { LineEdit *name_box = memnew(LineEdit); hb->add_child(name_box); - name_box->set_custom_minimum_size(Size2(60 * EDSCALE, 0)); + name_box->set_custom_minimum_size(Size2(65 * EDSCALE, 0)); + name_box->set_h_size_flags(SIZE_EXPAND_FILL); name_box->set_text(name_right); - name_box->set_expand_to_text_length(true); name_box->connect("text_entered", this, "_change_output_port_name", varray(name_box, nodes[n_i], i)); name_box->connect("focus_exited", this, "_port_name_focus_out", varray(name_box, nodes[n_i], i, true)); @@ -675,7 +743,7 @@ void VisualShaderEditor::_update_graph() { } offset = memnew(Control); - offset->set_custom_minimum_size(Size2(0, 5 * EDSCALE)); + offset->set_custom_minimum_size(Size2(0, 4 * EDSCALE)); node->add_child(offset); String error = vsnode->get_warning(visual_shader->get_mode(), type); @@ -692,12 +760,14 @@ void VisualShaderEditor::_update_graph() { expression_node->set_control(expression_box, 0); node->add_child(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 comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); expression_box->set_syntax_coloring(true); + expression_box->add_color_override("background_color", background_color); for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { @@ -950,8 +1020,10 @@ void VisualShaderEditor::_expression_focus_out(Object *text_edit, int p_node) { } void VisualShaderEditor::_rebuild() { - EditorNode::get_singleton()->get_log()->clear(); - visual_shader->rebuild(); + if (visual_shader != NULL) { + EditorNode::get_singleton()->get_log()->clear(); + visual_shader->rebuild(); + } } void VisualShaderEditor::_set_node_size(int p_type, int p_node, const Vector2 &p_size) { @@ -1010,7 +1082,7 @@ void VisualShaderEditor::_node_resized(const Vector2 &p_new_size, int p_type, in } undo_redo->create_action(TTR("Resize VisualShader node"), UndoRedo::MERGE_ENDS); - undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, p_new_size / EDSCALE); + undo_redo->add_do_method(this, "_set_node_size", p_type, p_node, p_new_size); undo_redo->add_undo_method(this, "_set_node_size", p_type, p_node, node->get_size()); undo_redo->commit_action(); } @@ -1147,7 +1219,9 @@ void VisualShaderEditor::_add_node(int p_idx, int p_op_idx) { Ref<VisualShaderNode> vsnode; - if (add_options[p_idx].type != String()) { + bool is_custom = add_options[p_idx].is_custom; + + if (!is_custom && add_options[p_idx].type != String()) { VisualShaderNode *vsn = Object::cast_to<VisualShaderNode>(ClassDB::instance(add_options[p_idx].type)); ERR_FAIL_COND(!vsn); @@ -1379,6 +1453,9 @@ void VisualShaderEditor::_delete_request(int which) { undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, which); undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, which), which); + undo_redo->add_do_method(this, "_clear_buffer"); + undo_redo->add_undo_method(this, "_clear_buffer"); + // restore size, inputs and outputs if node is group VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr()); if (group) { @@ -1509,6 +1586,32 @@ void VisualShaderEditor::_notification(int p_what) { node_filter->set_right_icon(Control::get_icon("Search", "EditorIcons")); + preview_shader->set_icon(Control::get_icon("Shader", "EditorIcons")); + + { + Color background_color = EDITOR_GET("text_editor/highlighting/background_color"); + Color text_color = EDITOR_GET("text_editor/highlighting/text_color"); + Color keyword_color = EDITOR_GET("text_editor/highlighting/keyword_color"); + Color comment_color = EDITOR_GET("text_editor/highlighting/comment_color"); + Color symbol_color = EDITOR_GET("text_editor/highlighting/symbol_color"); + + preview_text->add_color_override("background_color", background_color); + + for (List<String>::Element *E = keyword_list.front(); E; E = E->next()) { + + preview_text->add_keyword_color(E->get(), keyword_color); + } + + preview_text->add_font_override("font", get_font("expression", "EditorFonts")); + preview_text->add_color_override("font_color", text_color); + preview_text->add_color_override("symbol_color", symbol_color); + preview_text->add_color_region("/*", "*/", comment_color, false); + preview_text->add_color_region("//", "", comment_color, false); + + error_text->add_font_override("font", get_font("status_source", "EditorFonts")); + error_text->add_color_override("font_color", get_color("error_color", "Editor")); + } + tools->set_icon(EditorNode::get_singleton()->get_gui_base()->get_icon("Tools", "EditorIcons")); if (p_what == NOTIFICATION_THEME_CHANGED && is_visible_in_tree()) @@ -1533,12 +1636,32 @@ void VisualShaderEditor::_node_changed(int p_id) { } } -void VisualShaderEditor::_duplicate_nodes() { +void VisualShaderEditor::_dup_update_excluded(int p_type, Set<int> &r_excluded) { + r_excluded.clear(); + VisualShader::Type type = (VisualShader::Type)p_type; - VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); + for (int i = 0; i < graph->get_child_count(); i++) { - List<int> nodes; - Set<int> excluded; + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); + if (gn) { + int id = String(gn->get_name()).to_int(); + Ref<VisualShaderNode> node = visual_shader->get_node(type, id); + Ref<VisualShaderNodeOutput> output = node; + if (output.is_valid()) { + r_excluded.insert(id); + continue; + } + r_excluded.insert(id); + } + } +} + +void VisualShaderEditor::_dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded) { + + VisualShader::Type type = (VisualShader::Type)p_type; + + selection_center.x = 0.0f; + selection_center.y = 0.0f; for (int i = 0; i < graph->get_child_count(); i++) { @@ -1548,33 +1671,53 @@ void VisualShaderEditor::_duplicate_nodes() { Ref<VisualShaderNode> node = visual_shader->get_node(type, id); Ref<VisualShaderNodeOutput> output = node; if (output.is_valid()) { // can't duplicate output - excluded.insert(id); + r_excluded.insert(id); continue; } if (node.is_valid() && gn->is_selected()) { - nodes.push_back(id); + Vector2 pos = visual_shader->get_node_position(type, id); + selection_center += pos; + r_nodes.push_back(id); } - excluded.insert(id); + r_excluded.insert(id); } } - if (nodes.empty()) - return; + selection_center /= (float)r_nodes.size(); +} - undo_redo->create_action(TTR("Duplicate Nodes")); +void VisualShaderEditor::_dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select) { + + VisualShader::Type type = (VisualShader::Type)p_type; + VisualShader::Type pasted_type = (VisualShader::Type)p_pasted_type; int base_id = visual_shader->get_valid_node_id(type); int id_from = base_id; Map<int, int> connection_remap; + Set<int> unsupported_set; - for (List<int>::Element *E = nodes.front(); E; E = E->next()) { + for (List<int>::Element *E = r_nodes.front(); E; E = E->next()) { connection_remap[E->get()] = id_from; - Ref<VisualShaderNode> node = visual_shader->get_node(type, E->get()); + Ref<VisualShaderNode> node = visual_shader->get_node(pasted_type, E->get()); + + bool unsupported = false; + for (int i = 0; i < add_options.size(); i++) { + if (add_options[i].type == node->get_class_name()) { + if (!_is_available(add_options[i].mode)) { + unsupported = true; + } + break; + } + } + if (unsupported) { + unsupported_set.insert(E->get()); + continue; + } Ref<VisualShaderNode> dupli = node->duplicate(); - undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(type, E->get()) + Vector2(10, 10) * EDSCALE, id_from); + undo_redo->add_do_method(visual_shader.ptr(), "add_node", type, dupli, visual_shader->get_node_position(pasted_type, E->get()) + p_offset, id_from); undo_redo->add_undo_method(visual_shader.ptr(), "remove_node", type, id_from); // duplicate size, inputs and outputs if node is group @@ -1594,9 +1737,12 @@ void VisualShaderEditor::_duplicate_nodes() { } List<VisualShader::Connection> conns; - visual_shader->get_node_connections(type, &conns); + visual_shader->get_node_connections(pasted_type, &conns); for (List<VisualShader::Connection>::Element *E = conns.front(); E; E = E->next()) { + if (unsupported_set.has(E->get().from_node) || unsupported_set.has(E->get().to_node)) { + continue; + } if (connection_remap.has(E->get().from_node) && connection_remap.has(E->get().to_node)) { undo_redo->add_do_method(visual_shader.ptr(), "connect_nodes_forced", type, connection_remap[E->get().from_node], E->get().from_port, connection_remap[E->get().to_node], E->get().to_port); } @@ -1606,21 +1752,71 @@ void VisualShaderEditor::_duplicate_nodes() { undo_redo->add_undo_method(this, "_update_graph"); undo_redo->commit_action(); - // reselect duplicated nodes by excluding the other ones - for (int i = 0; i < graph->get_child_count(); i++) { - - GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); - if (gn) { - int id = String(gn->get_name()).to_int(); - if (!excluded.has(id)) { - gn->set_selected(true); - } else { - gn->set_selected(false); + if (p_select) { + // reselect duplicated nodes by excluding the other ones + for (int i = 0; i < graph->get_child_count(); i++) { + + GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child(i)); + if (gn) { + int id = String(gn->get_name()).to_int(); + if (!r_excluded.has(id)) { + gn->set_selected(true); + } else { + gn->set_selected(false); + } } } } } +void VisualShaderEditor::_clear_buffer() { + + copy_nodes_buffer.clear(); + copy_nodes_excluded_buffer.clear(); +} + +void VisualShaderEditor::_duplicate_nodes() { + + int type = edit_type->get_selected(); + + List<int> nodes; + Set<int> excluded; + + _dup_copy_nodes(type, nodes, excluded); + + if (nodes.empty()) + return; + + undo_redo->create_action(TTR("Duplicate Nodes")); + + _dup_paste_nodes(type, type, nodes, excluded, Vector2(10, 10) * EDSCALE, true); +} + +void VisualShaderEditor::_copy_nodes() { + + copy_type = edit_type->get_selected(); + + _clear_buffer(); + + _dup_copy_nodes(copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer); +} + +void VisualShaderEditor::_paste_nodes() { + + if (copy_nodes_buffer.empty()) + return; + + int type = edit_type->get_selected(); + + undo_redo->create_action(TTR("Paste Nodes")); + + float scale = graph->get_zoom(); + + _dup_paste_nodes(type, copy_type, copy_nodes_buffer, copy_nodes_excluded_buffer, (graph->get_scroll_ofs() / scale + graph->get_local_mouse_position() / scale - selection_center), false); + + _dup_update_excluded(type, copy_nodes_excluded_buffer); // to prevent selection of previous copies at new paste +} + void VisualShaderEditor::_on_nodes_delete() { VisualShader::Type type = VisualShader::Type(edit_type->get_selected()); @@ -1647,6 +1843,9 @@ void VisualShaderEditor::_on_nodes_delete() { undo_redo->add_do_method(visual_shader.ptr(), "remove_node", type, F->get()); undo_redo->add_undo_method(visual_shader.ptr(), "add_node", type, node, visual_shader->get_node_position(type, F->get()), F->get()); + undo_redo->add_do_method(this, "_clear_buffer"); + undo_redo->add_undo_method(this, "_clear_buffer"); + // restore size, inputs and outputs if node is group VisualShaderNodeGroupBase *group = Object::cast_to<VisualShaderNodeGroupBase>(node.ptr()); if (group) { @@ -1691,6 +1890,7 @@ void VisualShaderEditor::_on_nodes_delete() { } void VisualShaderEditor::_mode_selected(int p_id) { + _update_options_menu(); _update_graph(); } @@ -1738,11 +1938,7 @@ void VisualShaderEditor::_member_selected() { if (item != NULL && item->has_meta("id")) { members_dialog->get_ok()->set_disabled(false); - if (add_options[item->get_meta("id")].highend) { - node_desc->set_text(TTR("(GLES3 only)") + " " + add_options[item->get_meta("id")].description); // TODO: change it to (Vulkan Only) when its ready - } else { - node_desc->set_text(add_options[item->get_meta("id")].description); - } + node_desc->set_text(_get_description(item->get_meta("id"))); } else { members_dialog->get_ok()->set_disabled(true); node_desc->set_text(""); @@ -1862,6 +2058,48 @@ void VisualShaderEditor::drop_data_fw(const Point2 &p_point, const Variant &p_da } } +void VisualShaderEditor::_show_preview_text() { + preview_showed = !preview_showed; + preview_vbox->set_visible(preview_showed); + if (preview_showed) { + if (pending_update_preview) { + _update_preview(); + pending_update_preview = false; + } + } +} + +void VisualShaderEditor::_update_preview() { + + if (!preview_showed) { + pending_update_preview = true; + return; + } + + String code = visual_shader->get_code(); + + preview_text->set_text(code); + + ShaderLanguage sl; + + Error err = sl.compile(code, ShaderTypes::get_singleton()->get_functions(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_modes(VisualServer::ShaderMode(visual_shader->get_mode())), ShaderTypes::get_singleton()->get_types()); + + for (int i = 0; i < preview_text->get_line_count(); i++) { + preview_text->set_line_as_marked(i, false); + } + if (err != OK) { + preview_text->set_line_as_marked(sl.get_error_line() - 1, true); + error_text->set_visible(true); + + String text = "error(" + itos(sl.get_error_line()) + "): " + sl.get_error_text(); + error_text->set_text(text); + shader_error = true; + } else { + error_text->set_visible(false); + shader_error = false; + } +} + void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_rebuild", &VisualShaderEditor::_rebuild); ClassDB::bind_method("_update_graph", &VisualShaderEditor::_update_graph); @@ -1884,6 +2122,8 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_line_edit_changed", &VisualShaderEditor::_line_edit_changed); ClassDB::bind_method("_port_name_focus_out", &VisualShaderEditor::_port_name_focus_out); ClassDB::bind_method("_duplicate_nodes", &VisualShaderEditor::_duplicate_nodes); + ClassDB::bind_method("_copy_nodes", &VisualShaderEditor::_copy_nodes); + ClassDB::bind_method("_paste_nodes", &VisualShaderEditor::_paste_nodes); ClassDB::bind_method("_mode_selected", &VisualShaderEditor::_mode_selected); ClassDB::bind_method("_input_select_item", &VisualShaderEditor::_input_select_item); ClassDB::bind_method("_preview_select_port", &VisualShaderEditor::_preview_select_port); @@ -1898,6 +2138,9 @@ void VisualShaderEditor::_bind_methods() { ClassDB::bind_method("_remove_output_port", &VisualShaderEditor::_remove_output_port); ClassDB::bind_method("_node_resized", &VisualShaderEditor::_node_resized); ClassDB::bind_method("_set_node_size", &VisualShaderEditor::_set_node_size); + ClassDB::bind_method("_clear_buffer", &VisualShaderEditor::_clear_buffer); + ClassDB::bind_method("_show_preview_text", &VisualShaderEditor::_show_preview_text); + ClassDB::bind_method("_update_preview", &VisualShaderEditor::_update_preview); ClassDB::bind_method(D_METHOD("get_drag_data_fw"), &VisualShaderEditor::get_drag_data_fw); ClassDB::bind_method(D_METHOD("can_drop_data_fw"), &VisualShaderEditor::can_drop_data_fw); @@ -1924,13 +2167,25 @@ VisualShaderEditor::VisualShaderEditor() { saved_node_pos = Point2(0, 0); ShaderLanguage::get_keyword_list(&keyword_list); + preview_showed = false; + pending_update_preview = false; + shader_error = false; + to_node = -1; to_slot = -1; from_node = -1; from_slot = -1; + main_box = memnew(HSplitContainer); + main_box->set_v_size_flags(SIZE_EXPAND_FILL); + main_box->set_h_size_flags(SIZE_EXPAND_FILL); + add_child(main_box); + graph = memnew(GraphEdit); - add_child(graph); + graph->get_zoom_hbox()->set_h_size_flags(SIZE_EXPAND_FILL); + graph->set_v_size_flags(SIZE_EXPAND_FILL); + graph->set_h_size_flags(SIZE_EXPAND_FILL); + main_box->add_child(graph); graph->set_drag_forwarding(this); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN); @@ -1943,6 +2198,8 @@ VisualShaderEditor::VisualShaderEditor() { graph->connect("node_selected", this, "_node_selected"); graph->connect("scroll_offset_changed", this, "_scroll_changed"); graph->connect("duplicate_nodes_request", this, "_duplicate_nodes"); + graph->connect("copy_nodes_request", this, "_copy_nodes"); + graph->connect("paste_nodes_request", this, "_paste_nodes"); graph->connect("delete_nodes_request", this, "_on_nodes_delete"); graph->connect("gui_input", this, "_graph_gui_input"); graph->connect("connection_to_empty", this, "_connection_to_empty"); @@ -1977,6 +2234,32 @@ VisualShaderEditor::VisualShaderEditor() { graph->get_zoom_hbox()->move_child(add_node, 0); add_node->connect("pressed", this, "_show_members_dialog", varray(false)); + preview_shader = memnew(ToolButton); + preview_shader->set_toggle_mode(true); + preview_shader->set_tooltip(TTR("Show resulted shader code.")); + graph->get_zoom_hbox()->add_child(preview_shader); + preview_shader->connect("pressed", this, "_show_preview_text"); + + /////////////////////////////////////// + // PREVIEW PANEL + /////////////////////////////////////// + + preview_vbox = memnew(VBoxContainer); + preview_vbox->set_visible(preview_showed); + main_box->add_child(preview_vbox); + preview_text = memnew(TextEdit); + preview_vbox->add_child(preview_text); + preview_text->set_h_size_flags(SIZE_EXPAND_FILL); + preview_text->set_v_size_flags(SIZE_EXPAND_FILL); + preview_text->set_custom_minimum_size(Size2(400 * EDSCALE, 0)); + preview_text->set_syntax_coloring(true); + preview_text->set_show_line_numbers(true); + preview_text->set_readonly(true); + + error_text = memnew(Label); + preview_vbox->add_child(error_text); + error_text->set_visible(false); + /////////////////////////////////////// // SHADER NODES TREE /////////////////////////////////////// @@ -2067,8 +2350,8 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Screen", "Color", "Operators", "VisualShaderNodeColorOp", TTR("Screen operator."), VisualShaderNodeColorOp::OP_SCREEN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("SoftLight", "Color", "Operators", "VisualShaderNodeColorOp", TTR("SoftLight operator."), VisualShaderNodeColorOp::OP_SOFT_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("ColorConstant", "Color", "Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, VisualShaderNode::PORT_TYPE_COLOR)); + add_options.push_back(AddOption("ColorConstant", "Color", "Variables", "VisualShaderNodeColorConstant", TTR("Color constant."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("ColorUniform", "Color", "Variables", "VisualShaderNodeColorUniform", TTR("Color uniform."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); // CONDITIONAL @@ -2078,15 +2361,16 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("GreaterThan", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than (>)")), VisualShaderNodeCompare::FUNC_GREATER_THAN, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("GreaterThanEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Greater Than or Equal (>=)")), VisualShaderNodeCompare::FUNC_GREATER_THAN_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("If", "Conditional", "Functions", "VisualShaderNodeIf", TTR("Returns an associated vector if the provided scalars are equal, greater or less."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("IsInf", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_INF, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, -1, -1, true)); - add_options.push_back(AddOption("IsNaN", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between NaN and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_NAN, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, -1, -1, true)); + add_options.push_back(AddOption("IsInf", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_INF, VisualShaderNode::PORT_TYPE_BOOLEAN)); + add_options.push_back(AddOption("IsNaN", "Conditional", "Functions", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between NaN and a scalar parameter."), VisualShaderNodeIs::FUNC_IS_NAN, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("LessThan", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than (<)")), VisualShaderNodeCompare::FUNC_LESS_THAN, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("LessThanEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Less Than or Equal (<=)")), VisualShaderNodeCompare::FUNC_LESS_THAN_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("NotEqual", "Conditional", "Functions", "VisualShaderNodeCompare", vformat(compare_func_desc, TTR("Not Equal (!=)")), VisualShaderNodeCompare::FUNC_NOT_EQUAL, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("Switch", "Conditional", "Functions", "VisualShaderNodeSwitch", TTR("Returns an associated vector if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SwitchS", "Conditional", "Functions", "VisualShaderNodeScalarSwitch", TTR("Returns an associated scalar if the provided boolean value is true or false."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Compare", "Conditional", "Common", "VisualShaderNodeCompare", TTR("Returns the boolean result of the comparison between two parameters."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); - add_options.push_back(AddOption("Is", "Conditional", "Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN, -1, -1, -1, true)); + add_options.push_back(AddOption("Is", "Conditional", "Common", "VisualShaderNodeIs", TTR("Returns the boolean result of the comparison between INF (or NaN) and a scalar parameter."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("BooleanConstant", "Conditional", "Variables", "VisualShaderNodeBooleanConstant", TTR("Boolean constant."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); add_options.push_back(AddOption("BooleanUniform", "Conditional", "Variables", "VisualShaderNodeBooleanUniform", TTR("Boolean uniform."), -1, VisualShaderNode::PORT_TYPE_BOOLEAN)); @@ -2099,6 +2383,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("InvCamera", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_camera"), "inv_camera", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("InvProjection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "inv_projection"), "inv_projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Normal", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "normal"), "normal", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("OutputIsSRGB", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "output_is_srgb"), "output_is_srgb", VisualShaderNode::PORT_TYPE_BOOLEAN, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Projection", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "camera"), "projection", VisualShaderNode::PORT_TYPE_TRANSFORM, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Time", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "time"), "time", VisualShaderNode::PORT_TYPE_SCALAR, -1, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("ViewportSize", "Input", "All", "VisualShaderNodeInput", vformat(input_param_shader_modes, "viewport_size"), "viewport_size", VisualShaderNode::PORT_TYPE_VECTOR, -1, Shader::MODE_SPATIAL)); @@ -2129,6 +2414,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Binormal", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "binormal"), "binormal", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Color", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_vertex_and_fragment_shader_modes, "color"), "color", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("FragCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_and_light_shader_modes, "fragcoord"), "fragcoord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("FrontFacing", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "front_facing"), "front_facing", VisualShaderNode::PORT_TYPE_BOOLEAN, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("PointCoord", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "point_coord"), "point_coord", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("ScreenUV", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "screen_uv"), "screen_uv", VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); add_options.push_back(AddOption("Side", "Input", "Fragment", "VisualShaderNodeInput", vformat(input_param_for_fragment_shader_mode, "side"), "side", VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT, Shader::MODE_SPATIAL)); @@ -2221,16 +2507,16 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Abs", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the absolute value of the parameter."), VisualShaderNodeScalarFunc::FUNC_ABS, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("ACos", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the arc-cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ACOS, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("ACosH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("ACosH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("ASin", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the arc-sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ASIN, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("ASinH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("ASinH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("ATan", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the arc-tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_ATAN, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("ATan2", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeScalarOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("ATanH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("ATanH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Ceil", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), VisualShaderNodeScalarFunc::FUNC_CEIL, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Clamp", "Scalar", "Functions", "VisualShaderNodeScalarClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Cos", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("CosH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("CosH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeScalarFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Degrees", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Converts a quantity in radians to degrees."), VisualShaderNodeScalarFunc::FUNC_DEGREES, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Exp", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Base-e Exponential."), VisualShaderNodeScalarFunc::FUNC_EXP, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Exp2", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Base-2 Exponential."), VisualShaderNodeScalarFunc::FUNC_EXP2, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -2247,18 +2533,18 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Pow", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Returns the value of the first parameter raised to the power of the second."), VisualShaderNodeScalarOp::OP_POW, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Radians", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Converts a quantity in degrees to radians."), VisualShaderNodeScalarFunc::FUNC_RADIANS, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Reciprocal", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("1.0 / scalar"), VisualShaderNodeScalarFunc::FUNC_RECIPROCAL, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("Round", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeScalarFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); - add_options.push_back(AddOption("RoundEven", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeScalarFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("Round", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeScalarFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("RoundEven", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeScalarFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Saturate", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Clamps the value between 0.0 and 1.0."), VisualShaderNodeScalarFunc::FUNC_SATURATE, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Sign", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Extracts the sign of the parameter."), VisualShaderNodeScalarFunc::FUNC_SIGN, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Sin", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("SinH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("SinH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeScalarFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Sqrt", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeScalarFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), VisualShaderNodeScalarOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("SmoothStep", "Scalar", "Functions", "VisualShaderNodeScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if x is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("Step", "Scalar", "Functions", "VisualShaderNodeScalarOp", TTR("Step function( scalar(edge), scalar(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeScalarOp::OP_STEP, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Tan", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_SCALAR)); - add_options.push_back(AddOption("TanH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); - add_options.push_back(AddOption("Trunc", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeScalarFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); + add_options.push_back(AddOption("TanH", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeScalarFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("Trunc", "Scalar", "Functions", "VisualShaderNodeScalarFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeScalarFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Add", "Scalar", "Operators", "VisualShaderNodeScalarOp", TTR("Adds scalar to scalar."), VisualShaderNodeScalarOp::OP_ADD, VisualShaderNode::PORT_TYPE_SCALAR)); add_options.push_back(AddOption("Divide", "Scalar", "Operators", "VisualShaderNodeScalarOp", TTR("Divides scalar by scalar."), VisualShaderNodeScalarOp::OP_DIV, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -2271,24 +2557,24 @@ VisualShaderEditor::VisualShaderEditor() { // TEXTURES - add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); + add_options.push_back(AddOption("CubeMap", "Textures", "Functions", "VisualShaderNodeCubeMap", TTR("Perform the cubic texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("Texture", "Textures", "Functions", "VisualShaderNodeTexture", TTR("Perform the texture lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); - add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_COLOR)); - add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, VisualShaderNode::PORT_TYPE_COLOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); + add_options.push_back(AddOption("CubeMapUniform", "Textures", "Variables", "VisualShaderNodeCubeMapUniform", TTR("Cubic texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("TextureUniform", "Textures", "Variables", "VisualShaderNodeTextureUniform", TTR("2D texture uniform lookup."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR)); + add_options.push_back(AddOption("TextureUniformTriplanar", "Textures", "Variables", "VisualShaderNodeTextureUniformTriplanar", TTR("2D texture uniform lookup with triplanar."), -1, VisualShaderNode::PORT_TYPE_ICON_COLOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, Shader::MODE_SPATIAL)); // TRANSFORM add_options.push_back(AddOption("TransformFunc", "Transform", "Common", "VisualShaderNodeTransformFunc", TTR("Transform function."), -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, -1, -1, -1, true)); + 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)); add_options.push_back(AddOption("TransformDecompose", "Transform", "Composition", "VisualShaderNodeTransformDecompose", TTR("Decomposes transform to four vectors."))); - add_options.push_back(AddOption("Determinant", "Transform", "Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), -1, VisualShaderNode::PORT_TYPE_SCALAR, -1, -1, -1, true)); - add_options.push_back(AddOption("Inverse", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the inverse of a transform."), VisualShaderNodeTransformFunc::FUNC_INVERSE, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, -1, -1, true)); - add_options.push_back(AddOption("Transpose", "Transform", "Functions", "VisualShaderNodeTransformFunc", TTR("Calculates the transpose of a transform."), VisualShaderNodeTransformFunc::FUNC_TRANSPOSE, VisualShaderNode::PORT_TYPE_TRANSFORM, -1, -1, -1, true)); + add_options.push_back(AddOption("Determinant", "Transform", "Functions", "VisualShaderNodeDeterminant", TTR("Calculates the determinant of a transform."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); + 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("TransformVectorMult", "Transform", "Operators", "VisualShaderNodeTransformVecMult", TTR("Multiplies vector by transform."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); @@ -2306,16 +2592,16 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Abs", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the absolute value of the parameter."), VisualShaderNodeVectorFunc::FUNC_ABS, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("ACos", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ACOS, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("ACosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("ACosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ACOSH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("ASin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ASIN, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("ASinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("ASinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_ASINH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("ATan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the arc-tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATAN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("ATan2", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the arc-tangent of the parameters."), VisualShaderNodeVectorOp::OP_ATAN2, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("ATanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("ATanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the inverse hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_ATANH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Ceil", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer that is greater than or equal to the parameter."), VisualShaderNodeVectorFunc::FUNC_CEIL, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Clamp", "Vector", "Functions", "VisualShaderNodeVectorClamp", TTR("Constrains a value to lie between two further values."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Cos", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COS, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("CosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("CosH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic cosine of the parameter."), VisualShaderNodeVectorFunc::FUNC_COSH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Cross", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Calculates the cross product of two vectors."), VisualShaderNodeVectorOp::OP_CROSS, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Degrees", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Converts a quantity in radians to degrees."), VisualShaderNodeVectorFunc::FUNC_DEGREES, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Distance", "Vector", "Functions", "VisualShaderNodeVectorDistance", TTR("Returns the distance between two points."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); @@ -2332,6 +2618,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Max", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the greater of two values."), VisualShaderNodeVectorOp::OP_MAX, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Min", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the lesser of two values."), VisualShaderNodeVectorOp::OP_MIN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Mix", "Vector", "Functions", "VisualShaderNodeVectorInterp", TTR("Linear interpolation between two vectors."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("MixS", "Vector", "Functions", "VisualShaderNodeVectorScalarMix", TTR("Linear interpolation between two vectors using scalar."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Negate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the opposite value of the parameter."), VisualShaderNodeVectorFunc::FUNC_NEGATE, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Normalize", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Calculates the normalize product of vector."), VisualShaderNodeVectorFunc::FUNC_NORMALIZE, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("OneMinus", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 - vector"), VisualShaderNodeVectorFunc::FUNC_ONEMINUS, VisualShaderNode::PORT_TYPE_VECTOR)); @@ -2340,20 +2627,20 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Reciprocal", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("1.0 / vector"), VisualShaderNodeVectorFunc::FUNC_RECIPROCAL, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Reflect", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Returns the vector that points in the direction of reflection ( a : incident vector, b : normal vector )."), VisualShaderNodeVectorOp::OP_REFLECT, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Refract", "Vector", "Functions", "VisualShaderNodeVectorRefract", TTR("Returns the vector that points in the direction of refraction."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("Round", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); - add_options.push_back(AddOption("RoundEven", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("Round", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUND, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("RoundEven", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the nearest even integer to the parameter."), VisualShaderNodeVectorFunc::FUNC_ROUNDEVEN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Saturate", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Clamps the value between 0.0 and 1.0."), VisualShaderNodeVectorFunc::FUNC_SATURATE, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Sign", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Extracts the sign of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIGN, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Sin", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SIN, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("SinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("SinH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic sine of the parameter."), VisualShaderNodeVectorFunc::FUNC_SINH, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Sqrt", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the square root of the parameter."), VisualShaderNodeVectorFunc::FUNC_SQRT, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller then 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SmoothStep", "Vector", "Functions", "VisualShaderNodeVectorSmoothStep", TTR("SmoothStep function( vector(edge0), vector(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("SmoothStepS", "Vector", "Functions", "VisualShaderNodeVectorScalarSmoothStep", TTR("SmoothStep function( scalar(edge0), scalar(edge1), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge0' and 1.0 if 'x' is larger than 'edge1'. Otherwise the return value is interpolated between 0.0 and 1.0 using Hermite polynomials."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("Step", "Vector", "Functions", "VisualShaderNodeVectorOp", TTR("Step function( vector(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), VisualShaderNodeVectorOp::OP_STEP, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("StepS", "Vector", "Functions", "VisualShaderNodeVectorScalarStep", TTR("Step function( scalar(edge), vector(x) ).\n\nReturns 0.0 if 'x' is smaller than 'edge' and otherwise 1.0."), -1, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Tan", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TAN, VisualShaderNode::PORT_TYPE_VECTOR)); - add_options.push_back(AddOption("TanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); - add_options.push_back(AddOption("Trunc", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_VECTOR, -1, -1, -1, true)); + add_options.push_back(AddOption("TanH", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Returns the hyperbolic tangent of the parameter."), VisualShaderNodeVectorFunc::FUNC_TANH, VisualShaderNode::PORT_TYPE_VECTOR)); + add_options.push_back(AddOption("Trunc", "Vector", "Functions", "VisualShaderNodeVectorFunc", TTR("Finds the truncated value of the parameter."), VisualShaderNodeVectorFunc::FUNC_TRUNC, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Add", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Adds vector to vector."), VisualShaderNodeVectorOp::OP_ADD, VisualShaderNode::PORT_TYPE_VECTOR)); add_options.push_back(AddOption("Divide", "Vector", "Operators", "VisualShaderNodeVectorOp", TTR("Divides vector by vector."), VisualShaderNodeVectorOp::OP_DIV, VisualShaderNode::PORT_TYPE_VECTOR)); @@ -2368,6 +2655,7 @@ VisualShaderEditor::VisualShaderEditor() { add_options.push_back(AddOption("Expression", "Special", "", "VisualShaderNodeExpression", TTR("Custom Godot Shader Language expression, with custom amount of input and output ports. This is a direct injection of code into the vertex/fragment/light function, do not use it to write the function declarations inside."))); add_options.push_back(AddOption("Fresnel", "Special", "", "VisualShaderNodeFresnel", TTR("Returns falloff based on the dot product of surface normal and view direction of camera (pass associated inputs to it)."), -1, VisualShaderNode::PORT_TYPE_SCALAR)); + add_options.push_back(AddOption("GlobalExpression", "Special", "", "VisualShaderNodeGlobalExpression", TTR("Custom Godot Shader Language expression, which placed on top of the resulted shader. You can place various function definitions inside and call it later in the Expressions. You can also declare varyings, uniforms and constants."))); add_options.push_back(AddOption("ScalarDerivativeFunc", "Special", "Common", "VisualShaderNodeScalarDerivativeFunc", TTR("(Fragment/Light mode only) Scalar derivative function."), -1, VisualShaderNode::PORT_TYPE_SCALAR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, -1, -1, true)); add_options.push_back(AddOption("VectorDerivativeFunc", "Special", "Common", "VisualShaderNodeVectorDerivativeFunc", TTR("(Fragment/Light mode only) Vector derivative function."), -1, VisualShaderNode::PORT_TYPE_VECTOR, VisualShader::TYPE_FRAGMENT | VisualShader::TYPE_LIGHT, -1, -1, true)); @@ -2493,6 +2781,7 @@ public: class VisualShaderNodePluginDefaultEditor : public VBoxContainer { GDCLASS(VisualShaderNodePluginDefaultEditor, VBoxContainer); + Ref<Resource> parent_resource; public: void _property_changed(const String &prop, const Variant &p_value, const String &p_field, bool p_changing = false) { @@ -2506,7 +2795,27 @@ public: undo_redo->create_action(TTR("Edit Visual Property") + ": " + prop, UndoRedo::MERGE_ENDS); undo_redo->add_do_property(node.ptr(), prop, p_value); undo_redo->add_undo_property(node.ptr(), prop, node->get(prop)); + + if (p_value.get_type() == Variant::OBJECT) { + + RES prev_res = node->get(prop); + RES curr_res = p_value; + + if (curr_res.is_null()) { + undo_redo->add_do_method(this, "_open_inspector", (RES)parent_resource.ptr()); + } else { + undo_redo->add_do_method(this, "_open_inspector", (RES)curr_res.ptr()); + } + if (!prev_res.is_null()) { + undo_redo->add_undo_method(this, "_open_inspector", (RES)prev_res.ptr()); + } else { + undo_redo->add_undo_method(this, "_open_inspector", (RES)parent_resource.ptr()); + } + undo_redo->add_do_method(this, "_refresh_request"); + undo_redo->add_undo_method(this, "_refresh_request"); + } undo_redo->commit_action(); + updating = false; } @@ -2522,11 +2831,20 @@ public: VisualShaderEditor::get_singleton()->call_deferred("_update_graph"); } + void _resource_selected(const String &p_path, RES p_resource) { + _open_inspector(p_resource); + } + + void _open_inspector(RES p_resource) { + EditorNode::get_singleton()->get_inspector()->edit(p_resource.ptr()); + } + bool updating; Ref<VisualShaderNode> node; Vector<EditorProperty *> properties; - void setup(Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) { + void setup(Ref<Resource> p_parent_resource, Vector<EditorProperty *> p_properties, const Vector<StringName> &p_names, Ref<VisualShaderNode> p_node) { + parent_resource = p_parent_resource; updating = false; node = p_node; properties = p_properties; @@ -2535,6 +2853,11 @@ public: add_child(p_properties[i]); + bool res_prop = Object::cast_to<EditorPropertyResource>(p_properties[i]); + if (res_prop) { + p_properties[i]->connect("resource_selected", this, "_resource_selected"); + } + properties[i]->connect("property_changed", this, "_property_changed"); properties[i]->set_object_and_property(node.ptr(), p_names[i]); properties[i]->update_property(); @@ -2548,10 +2871,12 @@ public: ClassDB::bind_method("_property_changed", &VisualShaderNodePluginDefaultEditor::_property_changed, DEFVAL(String()), DEFVAL(false)); ClassDB::bind_method("_node_changed", &VisualShaderNodePluginDefaultEditor::_node_changed); ClassDB::bind_method("_refresh_request", &VisualShaderNodePluginDefaultEditor::_refresh_request); + ClassDB::bind_method("_resource_selected", &VisualShaderNodePluginDefaultEditor::_resource_selected); + ClassDB::bind_method("_open_inspector", &VisualShaderNodePluginDefaultEditor::_open_inspector); } }; -Control *VisualShaderNodePluginDefault::create_editor(const Ref<VisualShaderNode> &p_node) { +Control *VisualShaderNodePluginDefault::create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node) { if (p_node->is_class("VisualShaderNodeInput")) { //create input @@ -2609,7 +2934,7 @@ Control *VisualShaderNodePluginDefault::create_editor(const Ref<VisualShaderNode properties.push_back(pinfo[i].name); } VisualShaderNodePluginDefaultEditor *editor = memnew(VisualShaderNodePluginDefaultEditor); - editor->setup(editors, properties, p_node); + editor->setup(p_parent_resource, editors, properties, p_node); return editor; } diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 100bc53d00..cd5efc366b 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -48,7 +48,7 @@ protected: static void _bind_methods(); public: - virtual Control *create_editor(const Ref<VisualShaderNode> &p_node); + virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; class VisualShaderEditor : public VBoxContainer { @@ -60,14 +60,22 @@ class VisualShaderEditor : public VBoxContainer { int editing_port; Ref<VisualShader> visual_shader; + HSplitContainer *main_box; GraphEdit *graph; ToolButton *add_node; + ToolButton *preview_shader; OptionButton *edit_type; PanelContainer *error_panel; Label *error_label; + bool pending_update_preview; + bool shader_error; + VBoxContainer *preview_vbox; + TextEdit *preview_text; + Label *error_text; + UndoRedo *undo_redo; Point2 saved_node_pos; bool saved_node_pos_dirty; @@ -75,6 +83,8 @@ class VisualShaderEditor : public VBoxContainer { ConfirmationDialog *members_dialog; MenuButton *tools; + bool preview_showed; + enum ToolsMenuOptions { EXPAND_ALL, COLLAPSE_ALL @@ -104,6 +114,7 @@ class VisualShaderEditor : public VBoxContainer { int func; float value; bool highend; + bool is_custom; AddOption(const String &p_name = String(), const String &p_category = String(), const String &p_sub_category = String(), const String &p_type = String(), const String &p_description = String(), int p_sub_func = -1, int p_return_type = -1, int p_mode = -1, int p_func = -1, float p_value = -1, bool p_highend = false) { name = p_name; @@ -117,6 +128,7 @@ class VisualShaderEditor : public VBoxContainer { func = p_func; value = p_value; highend = p_highend; + is_custom = false; } AddOption(const String &p_name, const String &p_category, const String &p_sub_category, const String &p_type, const String &p_description, const String &p_sub_func, int p_return_type = -1, int p_mode = -1, int p_func = -1, float p_value = -1, bool p_highend = false) { @@ -131,6 +143,7 @@ class VisualShaderEditor : public VBoxContainer { func = p_func; value = p_value; highend = p_highend; + is_custom = false; } }; @@ -140,8 +153,13 @@ class VisualShaderEditor : public VBoxContainer { void _draw_color_over_button(Object *obj, Color p_color); void _add_node(int p_idx, int p_op_idx = -1); + void _update_custom_nodes(); void _update_options_menu(); + void _show_preview_text(); + void _update_preview(); + String _get_description(int p_idx); + static VisualShaderEditor *singleton; void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, int p_node); @@ -176,8 +194,21 @@ class VisualShaderEditor : public VBoxContainer { void _port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output); + void _dup_copy_nodes(int p_type, List<int> &r_nodes, Set<int> &r_excluded); + void _dup_update_excluded(int p_type, Set<int> &r_excluded); + void _dup_paste_nodes(int p_type, int p_pasted_type, List<int> &r_nodes, Set<int> &r_excluded, const Vector2 &p_offset, bool p_select); + void _duplicate_nodes(); + Vector2 selection_center; + int copy_type; // shader type + List<int> copy_nodes_buffer; + Set<int> copy_nodes_excluded_buffer; + + void _clear_buffer(); + void _copy_nodes(); + void _paste_nodes(); + Vector<Ref<VisualShaderNodePlugin> > plugins; void _mode_selected(int p_id); @@ -227,8 +258,8 @@ public: static VisualShaderEditor *get_singleton() { return singleton; } - void add_custom_type(const String &p_name, const String &p_category, const Ref<Script> &p_script); - void remove_custom_type(const Ref<Script> &p_script); + void clear_custom_types(); + void add_custom_type(const String &p_name, const Ref<Script> &p_script, const String &p_description, int p_return_icon_type, const String &p_category, const String &p_sub_category); virtual Size2 get_minimum_size() const; void edit(VisualShader *p_visual_shader); @@ -259,7 +290,7 @@ class VisualShaderNodePluginDefault : public VisualShaderNodePlugin { GDCLASS(VisualShaderNodePluginDefault, VisualShaderNodePlugin); public: - virtual Control *create_editor(const Ref<VisualShaderNode> &p_node); + virtual Control *create_editor(const Ref<Resource> &p_parent_resource, const Ref<VisualShaderNode> &p_node); }; class EditorPropertyShaderMode : public EditorProperty { |