diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2021-10-15 19:31:05 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-15 19:31:05 +0200 |
commit | b5ece7c36367e74eb93fb3625eb77a848487f9fd (patch) | |
tree | 98f85360bc5cdbea62305f9aa9a7e6ca63f577a9 | |
parent | fe4ca9e4df90cf01fe5a1f7a663a7a9e3e8d701d (diff) | |
parent | e270644b2061fa43c61c6b8c3e4218b95dcd4d74 (diff) |
Merge pull request #53764 from Chaosus/vs_curve_input_port_default
-rw-r--r-- | editor/plugins/visual_shader_editor_plugin.cpp | 30 | ||||
-rw-r--r-- | scene/resources/visual_shader_nodes.cpp | 2 |
2 files changed, 32 insertions, 0 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 48f64e041c..0a067dfc17 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -491,6 +491,35 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { bool is_curve = curve.is_valid() || curve_xyz.is_valid(); if (is_curve) { + // a default value handling + { + Variant default_value; + bool port_left_used = false; + + for (const VisualShader::Connection &E : connections) { + if (E.to_node == p_id && E.to_port == 0) { + port_left_used = true; + break; + } + } + + if (!port_left_used) { + default_value = vsnode->get_input_port_default_value(0); + } + + Button *button = memnew(Button); + custom_editor->add_child(button); + register_default_input_button(p_id, 0, button); + custom_editor->move_child(button, 0); + + button->connect("pressed", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_edit_port_default_input), varray(button, p_id, 0)); + if (default_value.get_type() != Variant::NIL) { + set_input_port_default_value(p_type, p_id, 0, default_value); + } else { + button->hide(); + } + } + VisualShaderEditor::get_singleton()->graph->add_child(node); VisualShaderEditor::get_singleton()->_update_created_node(node); @@ -643,6 +672,7 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) { for (const VisualShader::Connection &E : connections) { if (E.to_node == p_id && E.to_port == j) { port_left_used = true; + break; } } } diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index e45dfdcb1b..c3d9ef7b04 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -918,6 +918,7 @@ bool VisualShaderNodeCurveTexture::is_use_prop_slots() const { } VisualShaderNodeCurveTexture::VisualShaderNodeCurveTexture() { + set_input_port_default_value(0, 0.0); simple_decl = true; allow_v_resize = false; } @@ -1002,6 +1003,7 @@ bool VisualShaderNodeCurveXYZTexture::is_use_prop_slots() const { } VisualShaderNodeCurveXYZTexture::VisualShaderNodeCurveXYZTexture() { + set_input_port_default_value(0, 0.0); simple_decl = true; allow_v_resize = false; } |