From 4517cc0c78d603dbff6863c9b919b5204648d47d Mon Sep 17 00:00:00 2001 From: Relintai Date: Sun, 19 Jun 2022 04:41:53 +0200 Subject: [PATCH] Use the popup closed event for color slots in MMGraphNode. --- .../material_maker/editor/mm_graph_node.cpp | 19 ++++++++++++++++++- modules/material_maker/editor/mm_graph_node.h | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/modules/material_maker/editor/mm_graph_node.cpp b/modules/material_maker/editor/mm_graph_node.cpp index 0b109d606..8c14075a2 100644 --- a/modules/material_maker/editor/mm_graph_node.cpp +++ b/modules/material_maker/editor/mm_graph_node.cpp @@ -191,7 +191,9 @@ int MMGraphNode::add_slot_color(const String &getter, const String &setter) { ColorPickerButton *cp = memnew(ColorPickerButton); int slot_idx = add_slot(MMNodeUniversalProperty::SLOT_TYPE_NONE, MMNodeUniversalProperty::SLOT_TYPE_NONE, getter, setter, cp); cp->set_pick_color(_node->call(getter)); - cp->connect("color_changed", _node.ptr(), setter); + Vector bindings; + bindings.push_back(slot_idx); + cp->connect("popup_closed", this, "on_color_picker_popup_closed", bindings); return slot_idx; } @@ -784,6 +786,20 @@ void MMGraphNode::on_slot_line_edit_text_entered(const String &text, const int s ignore_changes(false); } +void MMGraphNode::on_color_picker_popup_closed(const int slot_idx) { + //properties[slot_idx][6].set_default_value(c); + ignore_changes(true); + _undo_redo->create_action("MMGD: value changed"); + + ColorPickerButton *btn = Object::cast_to(properties[slot_idx].control); + ERR_FAIL_COND(!btn); + + _undo_redo->add_do_method(*_node, properties[slot_idx].setter, btn->get_pick_color()); + _undo_redo->add_undo_method(*_node, properties[slot_idx].setter, _node->call(properties[slot_idx].getter)); + _undo_redo->commit_action(); + ignore_changes(false); +} + void MMGraphNode::on_universal_color_changed(const Color &c, const int slot_idx) { //properties[slot_idx][6].set_default_value(c); ignore_changes(true); @@ -937,6 +953,7 @@ void MMGraphNode::_bind_methods() { ClassDB::bind_method(D_METHOD("on_universal_texture_changed", "slot_idx"), &MMGraphNode::on_universal_texture_changed); ClassDB::bind_method(D_METHOD("on_universal_texture_changed_image_picker", "slot_idx"), &MMGraphNode::on_universal_texture_changed_image_picker); ClassDB::bind_method(D_METHOD("on_slot_line_edit_text_entered", "text", "slot_idx"), &MMGraphNode::on_slot_line_edit_text_entered); + ClassDB::bind_method(D_METHOD("on_color_picker_popup_closed", "slot_idx"), &MMGraphNode::on_color_picker_popup_closed); ClassDB::bind_method(D_METHOD("on_universal_color_changed", "c", "slot_idx"), &MMGraphNode::on_universal_color_changed); ClassDB::bind_method(D_METHOD("on_universal_image_path_changed", "f", "slot_idx"), &MMGraphNode::on_universal_image_path_changed); ClassDB::bind_method(D_METHOD("on_close_request"), &MMGraphNode::on_close_request); diff --git a/modules/material_maker/editor/mm_graph_node.h b/modules/material_maker/editor/mm_graph_node.h index f9be7697f..595d91eec 100644 --- a/modules/material_maker/editor/mm_graph_node.h +++ b/modules/material_maker/editor/mm_graph_node.h @@ -92,6 +92,7 @@ public: void on_universal_texture_changed(const int slot_idx); void on_universal_texture_changed_image_picker(const int slot_idx); void on_slot_line_edit_text_entered(const String &text, const int slot_idx); + void on_color_picker_popup_closed(const int slot_idx); void on_universal_color_changed(const Color &c, const int slot_idx); void on_universal_image_path_changed(const String &f, const int slot_idx);