From 6a6fce515cf23fbd282ce47a26bcf00599440899 Mon Sep 17 00:00:00 2001 From: Bad Sector Date: Sat, 23 Nov 2024 03:06:24 +0200 Subject: [PATCH] Make visual shader editor create node window a popup --- .../plugins/visual_shader_editor_plugin.cpp | 51 ++++++++----------- editor/plugins/visual_shader_editor_plugin.h | 4 +- 2 files changed, 23 insertions(+), 32 deletions(-) diff --git a/editor/plugins/visual_shader_editor_plugin.cpp b/editor/plugins/visual_shader_editor_plugin.cpp index 31e158bba73e..3461b5bd184a 100644 --- a/editor/plugins/visual_shader_editor_plugin.cpp +++ b/editor/plugins/visual_shader_editor_plugin.cpp @@ -2209,7 +2209,6 @@ String VisualShaderEditor::_get_description(int p_idx) { void VisualShaderEditor::_update_options_menu() { node_desc->set_text(""); highend_label->set_visible(false); - members_dialog->get_ok_button()->set_disabled(true); members->clear(); TreeItem *root = members->create_item(); @@ -2373,8 +2372,6 @@ void VisualShaderEditor::_update_options_menu() { item->select(0); node_desc->set_text(options[i].description); is_first_item = false; - - members_dialog->get_ok_button()->set_disabled(false); } switch (options[i].return_type) { case VisualShaderNode::PORT_TYPE_SCALAR: @@ -4206,7 +4203,7 @@ void VisualShaderEditor::_connection_to_empty(const String &p_from, int p_from_s if (node.is_valid()) { output_port_type = node->get_output_port_type(from_slot); } - _show_members_dialog(true, input_port_type, output_port_type); + _show_members_popup(true, input_port_type, output_port_type); } void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position) { @@ -4218,7 +4215,7 @@ void VisualShaderEditor::_connection_from_empty(const String &p_to, int p_to_slo if (node.is_valid()) { input_port_type = node->get_input_port_type(to_slot); } - _show_members_dialog(true, input_port_type, output_port_type); + _show_members_popup(true, input_port_type, output_port_type); } bool VisualShaderEditor::_check_node_drop_on_connection(const Vector2 &p_position, Ref *r_closest_connection, int *r_from_port, int *r_to_port) { @@ -4874,7 +4871,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref &p_event) { connection_popup_menu->reset_size(); connection_popup_menu->popup(); } else if (selected_graph_elements.is_empty() && copy_buffer_empty) { - _show_members_dialog(true); + _show_members_popup(true); } else { popup_menu->set_item_disabled(NodeMenuOptions::CUT, selected_deletable_graph_elements.is_empty()); popup_menu->set_item_disabled(NodeMenuOptions::COPY, selected_deletable_graph_elements.is_empty()); @@ -4987,7 +4984,7 @@ void VisualShaderEditor::_graph_gui_input(const Ref &p_event) { } } -void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) { +void VisualShaderEditor::_show_members_popup(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type, VisualShaderNode::PortType p_output_port_type) { if (members_input_port_type != p_input_port_type || members_output_port_type != p_output_port_type) { members_input_port_type = p_input_port_type; members_output_port_type = p_output_port_type; @@ -4999,24 +4996,24 @@ void VisualShaderEditor::_show_members_dialog(bool at_mouse_pos, VisualShaderNod saved_node_pos = graph->get_local_mouse_position(); Point2 gpos = get_screen_position() + get_local_mouse_position(); - members_dialog->set_position(gpos); + members_popup->set_position(gpos); } else { saved_node_pos_dirty = false; - members_dialog->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); + members_popup->set_position(graph->get_screen_position() + Point2(5 * EDSCALE, 65 * EDSCALE)); } - if (members_dialog->is_visible()) { - members_dialog->grab_focus(); + if (members_popup->is_visible()) { + members_popup->grab_focus(); return; } - members_dialog->popup(); + members_popup->popup(); // Keep dialog within window bounds. Rect2 window_rect = Rect2(get_window()->get_position(), get_window()->get_size()); - Rect2 dialog_rect = Rect2(members_dialog->get_position(), members_dialog->get_size()); + Rect2 dialog_rect = Rect2(members_popup->get_position(), members_popup->get_size()); Vector2 difference = (dialog_rect.get_end() - window_rect.get_end()).maxf(0); - members_dialog->set_position(members_dialog->get_position() - difference); + members_popup->set_position(members_popup->get_position() - difference); node_filter->grab_focus(); node_filter->select_all(); @@ -5067,7 +5064,7 @@ void VisualShaderEditor::_sbox_input(const Ref &p_event) { // Redirect navigational key events to the tree. Ref key = p_event; if (key.is_valid()) { - if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down")) { + if (key->is_action("ui_up", true) || key->is_action("ui_down", true) || key->is_action("ui_page_up") || key->is_action("ui_page_down") || key->is_action("ui_accept")) { members->gui_input(key); node_filter->accept_event(); } @@ -5795,12 +5792,10 @@ void VisualShaderEditor::_member_selected() { TreeItem *item = members->get_selected(); if (item != nullptr && item->has_meta("id")) { - members_dialog->get_ok_button()->set_disabled(false); highend_label->set_visible(add_options[item->get_meta("id")].highend); node_desc->set_text(_get_description(item->get_meta("id"))); } else { highend_label->set_visible(false); - members_dialog->get_ok_button()->set_disabled(true); node_desc->set_text(""); } } @@ -5831,7 +5826,7 @@ void VisualShaderEditor::_member_create() { saved_node_pos = 0.5 * (from_graph_element->get_position() + zoom * from_graph_element->get_output_port_position(from_slot) + to_graph_element->get_position() + zoom * to_graph_element->get_input_port_position(to_slot)); } _add_node(idx, add_options[idx].ops); - members_dialog->hide(); + members_popup->hide(); } } @@ -5975,7 +5970,7 @@ void VisualShaderEditor::_tools_menu_option(int p_idx) { void VisualShaderEditor::_node_menu_id_pressed(int p_idx) { switch (p_idx) { case NodeMenuOptions::ADD: - _show_members_dialog(true); + _show_members_popup(true); break; case NodeMenuOptions::CUT: _copy_nodes(true); @@ -6045,7 +6040,7 @@ void VisualShaderEditor::_connection_menu_id_pressed(int p_idx) { } connection_node_insert_requested = true; - _show_members_dialog(true, input_port_type, output_port_type); + _show_members_popup(true, input_port_type, output_port_type); } break; case ConnectionMenuOptions::INSERT_NEW_REROUTE: { from_node = String(clicked_connection->from_node).to_int(); @@ -6532,7 +6527,7 @@ VisualShaderEditor::VisualShaderEditor() { add_node->set_text(TTR("Add Node...")); toolbar->add_child(add_node); toolbar->move_child(add_node, 0); - add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_dialog).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX)); + add_node->connect(SceneStringName(pressed), callable_mp(this, &VisualShaderEditor::_show_members_popup).bind(false, VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PORT_TYPE_MAX)); graph->connect("graph_elements_linked_to_frame_request", callable_mp(this, &VisualShaderEditor::_nodes_linked_to_frame_request)); graph->connect("frame_rect_changed", callable_mp(this, &VisualShaderEditor::_frame_rect_changed)); @@ -6752,15 +6747,11 @@ VisualShaderEditor::VisualShaderEditor() { node_desc->set_v_size_flags(SIZE_FILL); node_desc->set_custom_minimum_size(Size2(0, 70 * EDSCALE)); - members_dialog = memnew(ConfirmationDialog); - members_dialog->set_title(TTR("Create Shader Node")); - members_dialog->add_child(members_vb); - members_dialog->set_ok_button_text(TTR("Create")); - members_dialog->connect(SceneStringName(confirmed), callable_mp(this, &VisualShaderEditor::_member_create)); - members_dialog->get_ok_button()->set_disabled(true); - members_dialog->connect("canceled", callable_mp(this, &VisualShaderEditor::_member_cancel)); - members_dialog->register_text_enter(node_filter); - add_child(members_dialog); + members_popup = memnew(PopupPanel); + members_popup->set_title(TTR("Create Shader Node")); + members_popup->add_child(members_vb); + members_popup->set_min_size(Size2i(300 * EDSCALE, members_popup->get_min_size().y)); + add_child(members_popup); // add varyings dialog { diff --git a/editor/plugins/visual_shader_editor_plugin.h b/editor/plugins/visual_shader_editor_plugin.h index 6b7c07e5a74e..d1246fa2e31a 100644 --- a/editor/plugins/visual_shader_editor_plugin.h +++ b/editor/plugins/visual_shader_editor_plugin.h @@ -251,7 +251,7 @@ class VisualShaderEditor : public ShaderEditor { Point2 saved_node_pos; bool saved_node_pos_dirty = false; - ConfirmationDialog *members_dialog = nullptr; + PopupPanel *members_popup = nullptr; VisualShaderNode::PortType members_input_port_type = VisualShaderNode::PORT_TYPE_MAX; VisualShaderNode::PortType members_output_port_type = VisualShaderNode::PORT_TYPE_MAX; PopupMenu *popup_menu = nullptr; @@ -371,7 +371,7 @@ class VisualShaderEditor : public ShaderEditor { Label *highend_label = nullptr; void _tools_menu_option(int p_idx); - void _show_members_dialog(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX); + void _show_members_popup(bool at_mouse_pos, VisualShaderNode::PortType p_input_port_type = VisualShaderNode::PORT_TYPE_MAX, VisualShaderNode::PortType p_output_port_type = VisualShaderNode::PORT_TYPE_MAX); void _varying_menu_id_pressed(int p_idx); void _show_add_varying_dialog();