|
@@ -110,7 +110,6 @@ void VisualShaderGraphPlugin::_bind_methods() {
|
|
ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
|
|
ClassDB::bind_method("set_expression", &VisualShaderGraphPlugin::set_expression);
|
|
ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
|
|
ClassDB::bind_method("update_curve", &VisualShaderGraphPlugin::update_curve);
|
|
ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
|
|
ClassDB::bind_method("update_curve_xyz", &VisualShaderGraphPlugin::update_curve_xyz);
|
|
- ClassDB::bind_method("update_constant", &VisualShaderGraphPlugin::update_constant);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
|
|
void VisualShaderGraphPlugin::register_shader(VisualShader *p_shader) {
|
|
@@ -237,18 +236,6 @@ int VisualShaderGraphPlugin::get_constant_index(float p_constant) const {
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void VisualShaderGraphPlugin::update_constant(VisualShader::Type p_type, int p_node_id) {
|
|
|
|
- if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].const_op) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- VisualShaderNodeFloatConstant *float_const = Object::cast_to<VisualShaderNodeFloatConstant>(links[p_node_id].visual_node);
|
|
|
|
- if (!float_const) {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
- links[p_node_id].const_op->select(get_constant_index(float_const->get_constant()));
|
|
|
|
- links[p_node_id].graph_node->set_size(Size2(-1, -1));
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
|
|
void VisualShaderGraphPlugin::set_expression(VisualShader::Type p_type, int p_node_id, const String &p_expression) {
|
|
if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
|
|
if (p_type != visual_shader->get_shader_type() || !links.has(p_node_id) || !links[p_node_id].expression_edit) {
|
|
return;
|
|
return;
|
|
@@ -267,10 +254,6 @@ void VisualShaderGraphPlugin::register_default_input_button(int p_node_id, int p
|
|
links[p_node_id].input_ports.insert(p_port_id, { p_button });
|
|
links[p_node_id].input_ports.insert(p_port_id, { p_button });
|
|
}
|
|
}
|
|
|
|
|
|
-void VisualShaderGraphPlugin::register_constant_option_btn(int p_node_id, OptionButton *p_button) {
|
|
|
|
- links[p_node_id].const_op = p_button;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
|
|
void VisualShaderGraphPlugin::register_expression_edit(int p_node_id, CodeEdit *p_expression_edit) {
|
|
links[p_node_id].expression_edit = p_expression_edit;
|
|
links[p_node_id].expression_edit = p_expression_edit;
|
|
}
|
|
}
|
|
@@ -322,7 +305,7 @@ void VisualShaderGraphPlugin::make_dirty(bool p_enabled) {
|
|
}
|
|
}
|
|
|
|
|
|
void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
|
|
void VisualShaderGraphPlugin::register_link(VisualShader::Type p_type, int p_id, VisualShaderNode *p_visual_node, GraphNode *p_graph_node) {
|
|
- links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
|
|
|
|
|
|
+ links.insert(p_id, { p_type, p_visual_node, p_graph_node, p_visual_node->get_output_port_for_preview() != -1, -1, Map<int, InputPort>(), Map<int, Port>(), nullptr, nullptr, nullptr, { nullptr, nullptr, nullptr } });
|
|
}
|
|
}
|
|
|
|
|
|
void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
|
|
void VisualShaderGraphPlugin::register_output_port(int p_node_id, int p_port, TextureButton *p_button) {
|
|
@@ -498,23 +481,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id) {
|
|
custom_editor = hbox;
|
|
custom_editor = hbox;
|
|
}
|
|
}
|
|
|
|
|
|
- Ref<VisualShaderNodeFloatConstant> float_const = vsnode;
|
|
|
|
- if (float_const.is_valid()) {
|
|
|
|
- HBoxContainer *hbox = memnew(HBoxContainer);
|
|
|
|
-
|
|
|
|
- hbox->add_child(custom_editor);
|
|
|
|
- OptionButton *btn = memnew(OptionButton);
|
|
|
|
- hbox->add_child(btn);
|
|
|
|
- register_constant_option_btn(p_id, btn);
|
|
|
|
- btn->add_item("");
|
|
|
|
- for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
|
|
|
|
- btn->add_item(float_constant_defs[i].name);
|
|
|
|
- }
|
|
|
|
- btn->select(get_constant_index(float_const->get_constant()));
|
|
|
|
- btn->connect("item_selected", callable_mp(VisualShaderEditor::get_singleton(), &VisualShaderEditor::_float_constant_selected), varray(p_id));
|
|
|
|
- custom_editor = hbox;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
if (custom_editor && !vsnode->is_use_prop_slots() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) {
|
|
if (custom_editor && !vsnode->is_use_prop_slots() && vsnode->get_output_port_count() > 0 && vsnode->get_output_port_name(0) == "" && (vsnode->get_input_port_count() == 0 || vsnode->get_input_port_name(0) == "")) {
|
|
//will be embedded in first port
|
|
//will be embedded in first port
|
|
} else if (custom_editor) {
|
|
} else if (custom_editor) {
|
|
@@ -2954,6 +2920,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
selected_constants.clear();
|
|
selected_constants.clear();
|
|
selected_uniforms.clear();
|
|
selected_uniforms.clear();
|
|
selected_comment = -1;
|
|
selected_comment = -1;
|
|
|
|
+ selected_float_constant = -1;
|
|
|
|
|
|
List<int> to_change;
|
|
List<int> to_change;
|
|
for (int i = 0; i < graph->get_child_count(); i++) {
|
|
for (int i = 0; i < graph->get_child_count(); i++) {
|
|
@@ -2973,6 +2940,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
if (constant_node != nullptr) {
|
|
if (constant_node != nullptr) {
|
|
selected_constants.insert(id);
|
|
selected_constants.insert(id);
|
|
}
|
|
}
|
|
|
|
+ VisualShaderNodeFloatConstant *float_constant_node = Object::cast_to<VisualShaderNodeFloatConstant>(node.ptr());
|
|
|
|
+ if (float_constant_node != nullptr) {
|
|
|
|
+ selected_float_constant = id;
|
|
|
|
+ }
|
|
VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
|
|
VisualShaderNodeUniform *uniform_node = Object::cast_to<VisualShaderNodeUniform>(node.ptr());
|
|
if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) {
|
|
if (uniform_node != nullptr && uniform_node->is_convertible_to_constant()) {
|
|
selected_uniforms.insert(id);
|
|
selected_uniforms.insert(id);
|
|
@@ -2983,6 +2954,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
|
|
|
|
if (to_change.size() > 1) {
|
|
if (to_change.size() > 1) {
|
|
selected_comment = -1;
|
|
selected_comment = -1;
|
|
|
|
+ selected_float_constant = -1;
|
|
}
|
|
}
|
|
|
|
|
|
if (to_change.is_empty() && copy_nodes_buffer.is_empty()) {
|
|
if (to_change.is_empty() && copy_nodes_buffer.is_empty()) {
|
|
@@ -2997,6 +2969,10 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
if (temp != -1) {
|
|
if (temp != -1) {
|
|
popup_menu->remove_item(temp);
|
|
popup_menu->remove_item(temp);
|
|
}
|
|
}
|
|
|
|
+ temp = popup_menu->get_item_index(NodeMenuOptions::FLOAT_CONSTANTS);
|
|
|
|
+ if (temp != -1) {
|
|
|
|
+ popup_menu->remove_item(temp);
|
|
|
|
+ }
|
|
temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
|
|
temp = popup_menu->get_item_index(NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
|
|
if (temp != -1) {
|
|
if (temp != -1) {
|
|
popup_menu->remove_item(temp);
|
|
popup_menu->remove_item(temp);
|
|
@@ -3018,14 +2994,23 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
popup_menu->remove_item(temp);
|
|
popup_menu->remove_item(temp);
|
|
}
|
|
}
|
|
|
|
|
|
- if (selected_comment != -1) {
|
|
|
|
|
|
+ if (selected_constants.size() > 0 || selected_uniforms.size() > 0) {
|
|
popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
|
|
popup_menu->add_separator("", NodeMenuOptions::SEPARATOR2);
|
|
- popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE);
|
|
|
|
- popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- if (selected_constants.size() > 0 || selected_uniforms.size() > 0) {
|
|
|
|
- popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
|
|
|
|
|
|
+ if (selected_float_constant != -1) {
|
|
|
|
+ popup_menu->add_submenu_item(TTR("Float Constants"), "FloatConstants", int(NodeMenuOptions::FLOAT_CONSTANTS));
|
|
|
|
+
|
|
|
|
+ if (!constants_submenu) {
|
|
|
|
+ constants_submenu = memnew(PopupMenu);
|
|
|
|
+ constants_submenu->set_name("FloatConstants");
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < MAX_FLOAT_CONST_DEFS; i++) {
|
|
|
|
+ constants_submenu->add_item(float_constant_defs[i].name, i);
|
|
|
|
+ }
|
|
|
|
+ popup_menu->add_child(constants_submenu);
|
|
|
|
+ constants_submenu->connect("index_pressed", callable_mp(this, &VisualShaderEditor::_float_constant_selected));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
|
|
if (selected_constants.size() > 0) {
|
|
if (selected_constants.size() > 0) {
|
|
popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
|
|
popup_menu->add_item(TTR("Convert Constant(s) to Uniform(s)"), NodeMenuOptions::CONVERT_CONSTANTS_TO_UNIFORMS);
|
|
@@ -3036,6 +3021,12 @@ void VisualShaderEditor::_graph_gui_input(const Ref<InputEvent> &p_event) {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (selected_comment != -1) {
|
|
|
|
+ popup_menu->add_separator("", NodeMenuOptions::SEPARATOR3);
|
|
|
|
+ popup_menu->add_item(TTR("Set Comment Title"), NodeMenuOptions::SET_COMMENT_TITLE);
|
|
|
|
+ popup_menu->add_item(TTR("Set Comment Description"), NodeMenuOptions::SET_COMMENT_DESCRIPTION);
|
|
|
|
+ }
|
|
|
|
+
|
|
menu_point = graph->get_local_mouse_position();
|
|
menu_point = graph->get_local_mouse_position();
|
|
Point2 gpos = Input::get_singleton()->get_mouse_position();
|
|
Point2 gpos = Input::get_singleton()->get_mouse_position();
|
|
popup_menu->set_position(gpos);
|
|
popup_menu->set_position(gpos);
|
|
@@ -3505,27 +3496,20 @@ void VisualShaderEditor::_uniform_select_item(Ref<VisualShaderNodeUniformRef> p_
|
|
undo_redo->commit_action();
|
|
undo_redo->commit_action();
|
|
}
|
|
}
|
|
|
|
|
|
-void VisualShaderEditor::_float_constant_selected(int p_index, int p_node) {
|
|
|
|
- if (p_index == 0) {
|
|
|
|
- graph_plugin->update_node_size(p_node);
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- --p_index;
|
|
|
|
-
|
|
|
|
- ERR_FAIL_INDEX(p_index, MAX_FLOAT_CONST_DEFS);
|
|
|
|
|
|
+void VisualShaderEditor::_float_constant_selected(int p_which) {
|
|
|
|
+ ERR_FAIL_INDEX(p_which, MAX_FLOAT_CONST_DEFS);
|
|
|
|
|
|
VisualShader::Type type = get_current_shader_type();
|
|
VisualShader::Type type = get_current_shader_type();
|
|
- Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, p_node);
|
|
|
|
- if (!node.is_valid()) {
|
|
|
|
- return;
|
|
|
|
|
|
+ Ref<VisualShaderNodeFloatConstant> node = visual_shader->get_node(type, selected_float_constant);
|
|
|
|
+ ERR_FAIL_COND(!node.is_valid());
|
|
|
|
+
|
|
|
|
+ if (Math::is_equal_approx(node->get_constant(), float_constant_defs[p_which].value)) {
|
|
|
|
+ return; // same
|
|
}
|
|
}
|
|
|
|
|
|
- undo_redo->create_action(TTR("Set constant"));
|
|
|
|
- undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_index].value);
|
|
|
|
|
|
+ undo_redo->create_action(vformat(TTR("Set Constant: %s"), float_constant_defs[p_which].name));
|
|
|
|
+ undo_redo->add_do_method(node.ptr(), "set_constant", float_constant_defs[p_which].value);
|
|
undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
|
|
undo_redo->add_undo_method(node.ptr(), "set_constant", node->get_constant());
|
|
- undo_redo->add_do_method(graph_plugin.ptr(), "update_constant", type, p_node);
|
|
|
|
- undo_redo->add_undo_method(graph_plugin.ptr(), "update_constant", type, p_node);
|
|
|
|
undo_redo->commit_action();
|
|
undo_redo->commit_action();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -4768,9 +4752,6 @@ public:
|
|
if (p_property != "constant") {
|
|
if (p_property != "constant") {
|
|
undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
|
|
undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
|
|
undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
|
|
undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_node_deferred", shader_type, node_id);
|
|
- } else {
|
|
|
|
- undo_redo->add_do_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id);
|
|
|
|
- undo_redo->add_undo_method(VisualShaderEditor::get_singleton()->get_graph_plugin(), "update_constant", shader_type, node_id);
|
|
|
|
}
|
|
}
|
|
undo_redo->commit_action();
|
|
undo_redo->commit_action();
|
|
|
|
|