From a9552cefa201f99c341fee76374a7332bffc4018 Mon Sep 17 00:00:00 2001 From: Yuri Sizov Date: Mon, 25 Jan 2021 18:17:21 +0300 Subject: [PATCH] Fix minimap capturing events and improve its theme Add an editor setting for minimap opacity in visual editors --- editor/editor_settings.cpp | 4 ++++ editor/editor_themes.cpp | 19 +++++++++++++++---- .../animation_blend_tree_editor_plugin.cpp | 5 +++++ .../plugins/visual_shader_editor_plugin.cpp | 5 +++++ .../visual_script/visual_script_editor.cpp | 6 ++++++ scene/gui/graph_edit.cpp | 6 +++++- .../resources/default_theme/default_theme.cpp | 1 + 7 files changed, 41 insertions(+), 5 deletions(-) diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 7c76c3f302d..1c61da7b21b 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -607,6 +607,10 @@ void EditorSettings::_load_defaults(Ref p_extra_config) { _initial_set("editors/animation/onion_layers_past_color", Color(1, 0, 0)); _initial_set("editors/animation/onion_layers_future_color", Color(0, 1, 0)); + // Visual editors + _initial_set("editors/visual_editors/minimap_opacity", 0.85); + hints["editors/visual_editors/minimap_opacity"] = PropertyInfo(Variant::REAL, "editors/visual_editors/minimap_opacity", PROPERTY_HINT_RANGE, "0.0,1.0,0.01", PROPERTY_USAGE_DEFAULT); + /* Run */ // Window placement diff --git a/editor/editor_themes.cpp b/editor/editor_themes.cpp index 4e3dfbc5e1a..949862ea097 100644 --- a/editor/editor_themes.cpp +++ b/editor/editor_themes.cpp @@ -91,6 +91,7 @@ static Ref flip_icon(Ref p_texture, bool p_flip_y = false, boo Ref texture(memnew(ImageTexture)); Ref img = p_texture->get_data(); + img = img->duplicate(); if (p_flip_y) { img->flip_y(); @@ -1076,7 +1077,11 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_constant("bezier_len_neg", "GraphEdit", 160 * EDSCALE); // GraphEditMinimap - theme->set_stylebox("bg", "GraphEditMinimap", make_flat_stylebox(dark_color_1, 0, 0, 0, 0)); + Ref style_minimap_bg = make_flat_stylebox(dark_color_1, 0, 0, 0, 0); + style_minimap_bg->set_border_color(dark_color_3); + style_minimap_bg->set_border_width_all(1); + theme->set_stylebox("bg", "GraphEditMinimap", style_minimap_bg); + Ref style_minimap_camera; Ref style_minimap_node; if (dark_theme) { @@ -1093,9 +1098,15 @@ Ref create_editor_theme(const Ref p_theme) { theme->set_stylebox("camera", "GraphEditMinimap", style_minimap_camera); theme->set_stylebox("node", "GraphEditMinimap", style_minimap_node); - Ref resizer_icon = theme->get_icon("GuiResizer", "EditorIcons"); - theme->set_icon("resizer", "GraphEditMinimap", flip_icon(resizer_icon, true, true)); - theme->set_color("resizer_color", "GraphEditMinimap", Color(1, 1, 1, 0.65)); + Ref minimap_resizer_icon = theme->get_icon("GuiResizer", "EditorIcons"); + Color minimap_resizer_color; + if (dark_theme) { + minimap_resizer_color = Color(1, 1, 1, 0.65); + } else { + minimap_resizer_color = Color(0, 0, 0, 0.65); + } + theme->set_icon("resizer", "GraphEditMinimap", flip_icon(minimap_resizer_icon, true, true)); + theme->set_color("resizer_color", "GraphEditMinimap", minimap_resizer_color); // GraphNode const float mv = dark_theme ? 0.0 : 1.0; diff --git a/editor/plugins/animation_blend_tree_editor_plugin.cpp b/editor/plugins/animation_blend_tree_editor_plugin.cpp index ababf43f975..883f9fda91b 100644 --- a/editor/plugins/animation_blend_tree_editor_plugin.cpp +++ b/editor/plugins/animation_blend_tree_editor_plugin.cpp @@ -266,6 +266,9 @@ void AnimationNodeBlendTreeEditor::_update_graph() { graph->connect_node(from, 0, to, to_idx); } + + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); } void AnimationNodeBlendTreeEditor::_file_opened(const String &p_file) { @@ -942,6 +945,8 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() { graph->connect("scroll_offset_changed", this, "_scroll_changed"); graph->connect("delete_nodes_request", this, "_delete_nodes_request"); graph->connect("popup_request", this, "_popup_request"); + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); VSeparator *vs = memnew(VSeparator); graph->get_zoom_hbox()->add_child(vs); diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index a8ac2bd139e..9debfca073e 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -908,6 +908,9 @@ void VisualShaderEditor::_update_graph() { graph->connect_node(itos(from), from_idx, itos(to), to_idx); } + + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); } void VisualShaderEditor::_add_input_port(int p_node, int p_port, int p_port_type, const String &p_name) { @@ -2391,6 +2394,8 @@ VisualShaderEditor::VisualShaderEditor() { graph->set_h_size_flags(SIZE_EXPAND_FILL); main_box->add_child(graph); graph->set_drag_forwarding(this); + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_SCALAR); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_BOOLEAN); graph->add_valid_right_disconnect_type(VisualShaderNode::PORT_TYPE_VECTOR); diff --git a/modules/visual_script/visual_script_editor.cpp b/modules/visual_script/visual_script_editor.cpp index c6ca56d83a3..5d18d961ab1 100644 --- a/modules/visual_script/visual_script_editor.cpp +++ b/modules/visual_script/visual_script_editor.cpp @@ -875,6 +875,10 @@ void VisualScriptEditor::_update_graph(int p_only_id) { } } _update_graph_connections(); + + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); + // use default_func instead of default_func for now I think that should be good stop gap solution to ensure not breaking anything graph->call_deferred("set_scroll_ofs", script->get_function_scroll(default_func) * EDSCALE); updating_graph = false; @@ -4785,6 +4789,8 @@ VisualScriptEditor::VisualScriptEditor() { graph->connect("duplicate_nodes_request", this, "_on_nodes_duplicate"); graph->connect("gui_input", this, "_graph_gui_input"); graph->set_drag_forwarding(this); + float graph_minimap_opacity = EditorSettings::get_singleton()->get("editors/visual_editors/minimap_opacity"); + graph->set_minimap_opacity(graph_minimap_opacity); graph->hide(); graph->connect("scroll_offset_changed", this, "_graph_ofs_changed"); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 8173ec85970..4ea0c22ddb9 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -155,6 +155,10 @@ Vector2 GraphEditMinimap::_convert_to_graph_position(const Vector2 &p_position) } void GraphEditMinimap::_gui_input(const Ref &p_ev) { + if (!ge->is_minimap_enabled()) { + return; + } + Ref mb = p_ev; Ref mm = p_ev; @@ -1799,7 +1803,7 @@ GraphEdit::GraphEdit() { top_layer->add_child(minimap); minimap->set_name("_minimap"); minimap->set_modulate(Color(1, 1, 1, minimap_opacity)); - minimap->set_mouse_filter(MOUSE_FILTER_STOP); + minimap->set_mouse_filter(MOUSE_FILTER_PASS); minimap->set_custom_minimum_size(Vector2(50, 50)); minimap->set_size(minimap_size); minimap->set_anchors_preset(Control::PRESET_BOTTOM_RIGHT); diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp index db967897831..6dabe74c531 100644 --- a/scene/resources/default_theme/default_theme.cpp +++ b/scene/resources/default_theme/default_theme.cpp @@ -138,6 +138,7 @@ static Ref flip_icon(Ref p_texture, bool p_flip_y = false, boo Ref texture(memnew(ImageTexture)); Ref img = p_texture->get_data(); + img = img->duplicate(); if (p_flip_y) { img->flip_y();