From 29919540dbeb4c9d5f44947a3ac15e23ed5acd4a Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 19 Jun 2022 16:54:12 +0200 Subject: [PATCH] Also handle udpating the GradientEditor when the edited resource changes. --- .../gradient_editor/gradient_cursor.cpp | 2 ++ .../gradient_editor/gradient_editor.cpp | 20 +++++++++++++++++++ .../widgets/gradient_editor/gradient_editor.h | 3 +-- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/modules/material_maker/editor/widgets/gradient_editor/gradient_cursor.cpp b/modules/material_maker/editor/widgets/gradient_editor/gradient_cursor.cpp index 6130380b3..e1ff1bc34 100644 --- a/modules/material_maker/editor/widgets/gradient_editor/gradient_cursor.cpp +++ b/modules/material_maker/editor/widgets/gradient_editor/gradient_cursor.cpp @@ -1,5 +1,6 @@ #include "gradient_cursor.h" +#include "core/print_string.h" #include "gradient_editor.h" #include "scene/gui/label.h" @@ -65,6 +66,7 @@ void GradientCursor::_gui_input(const Ref &ev) { //ged->save_color_state(); sliding = true; label->set_visible(true); + label->set_text(String::num(get_cursor_position(), 3)); } else { if (sliding) { diff --git a/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.cpp b/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.cpp index 731cf3c8a..a4220c45f 100644 --- a/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.cpp +++ b/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.cpp @@ -33,8 +33,20 @@ Ref MMGradientEditor::get_value() { } void MMGradientEditor::set_value(const Ref &val) { + if (value == val) { + return; + } + + if (value.is_valid()) { + value->disconnect("changed", this, "on_value_changed"); + } + value = val; + if (value.is_valid()) { + value->connect("changed", this, "on_value_changed"); + } + _update_preview_queued = true; _update_cursors_queued = true; @@ -308,6 +320,13 @@ void MMGradientEditor::on_color_selector_closed() { _selecting_color = false; } +void MMGradientEditor::on_value_changed() { + if (!graph_node->get_ignore_change_event()) { + _color_selection_done = true; + _selecting_color = false; + } +} + MMGradientEditor::MMGradientEditor() { graph_node = nullptr; embedded = false; @@ -535,4 +554,5 @@ void MMGradientEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("_on_Interpolation_item_selected", "ID"), &MMGradientEditor::_on_Interpolation_item_selected); ClassDB::bind_method(D_METHOD("on_resized"), &MMGradientEditor::on_resized); ClassDB::bind_method(D_METHOD("on_color_selector_closed"), &MMGradientEditor::on_color_selector_closed); + ClassDB::bind_method(D_METHOD("on_value_changed"), &MMGradientEditor::on_value_changed); } diff --git a/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.h b/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.h index f91de9aae..77bc6e0b4 100644 --- a/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.h +++ b/modules/material_maker/editor/widgets/gradient_editor/gradient_editor.h @@ -21,8 +21,6 @@ class MMMaterial; class MMGradientEditor : public Control { GDCLASS(MMGradientEditor, Control); - //todo mmnode changed event sub + handle - public: MMGraphNode *get_graph_node(); void set_graph_node(MMGraphNode *val); @@ -68,6 +66,7 @@ public: void apply_new_interpolation(); void on_resized(); void on_color_selector_closed(); + void on_value_changed(); MMGradientEditor(); ~MMGradientEditor();