Also handle udpating the GradientEditor when the edited resource changes.

This commit is contained in:
Relintai 2022-06-19 16:54:12 +02:00
parent 91b87ce9ef
commit 29919540db
3 changed files with 23 additions and 2 deletions

View File

@ -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<InputEvent> &ev) {
//ged->save_color_state();
sliding = true;
label->set_visible(true);
label->set_text(String::num(get_cursor_position(), 3));
} else {
if (sliding) {

View File

@ -33,8 +33,20 @@ Ref<GradientBase> MMGradientEditor::get_value() {
}
void MMGradientEditor::set_value(const Ref<GradientBase> &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);
}

View File

@ -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();