summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuri Roubinsky <chaosus89@gmail.com>2020-09-22 10:29:06 +0300
committerGitHub <noreply@github.com>2020-09-22 10:29:06 +0300
commit6f89db3d8c14ba996429d2287f285915f38fb84e (patch)
tree12f8ccdb5c09d511f7c7015749eb9785ef5496d9
parent160ad23e5d07234e17032e8158ed48a2148fc668 (diff)
parent477f6c880e5c58c697c5a170c8bf498b5f93658f (diff)
Merge pull request #42243 from Chaosus/vs_fix_bug
Fix UniformRef invalid updating when LineEdit focus out
-rw-r--r--editor/plugins/visual_shader_editor_plugin.cpp15
-rw-r--r--editor/plugins/visual_shader_editor_plugin.h4
2 files changed, 11 insertions, 8 deletions
diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp
index 975e6814cc..6a70f973c3 100644
--- a/editor/plugins/visual_shader_editor_plugin.cpp
+++ b/editor/plugins/visual_shader_editor_plugin.cpp
@@ -309,8 +309,8 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
register_uniform_name(p_id, uniform_name);
uniform_name->set_text(uniform->get_uniform_name());
node->add_child(uniform_name);
- uniform_name->connect("text_entered", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_line_edit_changed), varray(uniform_name, p_id));
- uniform_name->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_line_edit_focus_out), varray(uniform_name, p_id));
+ uniform_name->connect("text_entered", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_uniform_line_edit_changed), varray(p_id));
+ uniform_name->connect("focus_exited", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_uniform_line_edit_focus_out), varray(uniform_name, p_id));
if (vsnode->get_input_port_count() == 0 && vsnode->get_output_port_count() == 1 && vsnode->get_output_port_name(0) == "") {
//shortcut
@@ -1420,7 +1420,7 @@ void VisualShaderEditor::_preview_select_port(int p_node, int p_port) {
undo_redo->commit_action();
}
-void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_edit, int p_node_id) {
+void VisualShaderEditor::_uniform_line_edit_changed(const String &p_text, int p_node_id) {
VisualShader::Type type = get_current_shader_type();
Ref<VisualShaderNodeUniform> node = visual_shader->get_node(type, p_node_id);
@@ -1428,6 +1428,10 @@ void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_e
String validated_name = visual_shader->validate_uniform_name(p_text, node);
+ if (validated_name == node->get_uniform_name()) {
+ return;
+ }
+
undo_redo->create_action(TTR("Set Uniform Name"));
undo_redo->add_do_method(node.ptr(), "set_uniform_name", validated_name);
undo_redo->add_undo_method(node.ptr(), "set_uniform_name", node->get_uniform_name());
@@ -1444,9 +1448,8 @@ void VisualShaderEditor::_line_edit_changed(const String &p_text, Object *line_e
undo_redo->commit_action();
}
-void VisualShaderEditor::_line_edit_focus_out(Object *line_edit, int p_node_id) {
- String text = Object::cast_to<LineEdit>(line_edit)->get_text();
- _line_edit_changed(text, line_edit, p_node_id);
+void VisualShaderEditor::_uniform_line_edit_focus_out(Object *line_edit, int p_node_id) {
+ _uniform_line_edit_changed(Object::cast_to<LineEdit>(line_edit)->get_text(), p_node_id);
}
void VisualShaderEditor::_port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output) {
diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h
index 03f0f32e9f..c7443c67f2 100644
--- a/editor/plugins/visual_shader_editor_plugin.h
+++ b/editor/plugins/visual_shader_editor_plugin.h
@@ -288,8 +288,8 @@ class VisualShaderEditor : public VBoxContainer {
void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
- void _line_edit_changed(const String &p_text, Object *line_edit, int p_node_id);
- void _line_edit_focus_out(Object *line_edit, int p_node_id);
+ void _uniform_line_edit_changed(const String &p_text, int p_node_id);
+ void _uniform_line_edit_focus_out(Object *line_edit, int p_node_id);
void _port_name_focus_out(Object *line_edit, int p_node_id, int p_port_id, bool p_output);