Skip to content

Commit

Permalink
Merge pull request #79307 from Geometror/remove-graph-node-comment
Browse files Browse the repository at this point in the history
Remove GraphNode's comment property and related functionality
  • Loading branch information
YuriSizov authored Jul 24, 2023
2 parents 6588a4a + 662d8c7 commit 91258e5
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 156 deletions.
9 changes: 0 additions & 9 deletions doc/classes/GraphNode.xml
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@
</method>
</methods>
<members>
<member name="comment" type="bool" setter="set_comment" getter="is_comment" default="false">
If [code]true[/code], the GraphNode is a comment node.
</member>
<member name="draggable" type="bool" setter="set_draggable" getter="is_draggable" default="true">
If [code]true[/code], the user can drag the GraphNode.
</member>
Expand Down Expand Up @@ -373,12 +370,6 @@
<theme_item name="breakpoint" data_type="style" type="StyleBox">
The background used when [member overlay] is set to [constant OVERLAY_BREAKPOINT].
</theme_item>
<theme_item name="comment" data_type="style" type="StyleBox">
The [StyleBox] used when [member comment] is enabled.
</theme_item>
<theme_item name="comment_focus" data_type="style" type="StyleBox">
The [StyleBox] used when [member comment] is enabled and the [GraphNode] is focused.
</theme_item>
<theme_item name="frame" data_type="style" type="StyleBox">
The default background for [GraphNode].
</theme_item>
Expand Down
2 changes: 0 additions & 2 deletions editor/editor_themes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1895,8 +1895,6 @@ Ref<Theme> create_editor_theme(const Ref<Theme> p_theme) {

theme->set_stylebox("frame", "GraphNode", graphsb);
theme->set_stylebox("selected_frame", "GraphNode", graphsbselected);
theme->set_stylebox("comment", "GraphNode", graphsbcomment);
theme->set_stylebox("comment_focus", "GraphNode", graphsbcommentselected);
theme->set_stylebox("breakpoint", "GraphNode", graphsbbreakpoint);
theme->set_stylebox("position", "GraphNode", graphsbposition);
theme->set_stylebox("slot", "GraphNode", graphsbslot);
Expand Down
19 changes: 6 additions & 13 deletions editor/plugins/visual_shader_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
Ref<VisualShaderNodeGroupBase> group_node = Object::cast_to<VisualShaderNodeGroupBase>(vsnode.ptr());
bool is_group = !group_node.is_null();

bool is_comment = false;
Ref<VisualShaderNodeComment> comment_node = Object::cast_to<VisualShaderNodeComment>(vsnode.ptr());
bool is_comment = comment_node.is_valid();

Ref<VisualShaderNodeExpression> expression_node = Object::cast_to<VisualShaderNodeExpression>(group_node.ptr());
bool is_expression = !expression_node.is_null();
Expand Down Expand Up @@ -467,6 +468,10 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
expression = expression_node->get_expression();
}

if (is_comment) {
node->set_visible(false);
}

node->set_position_offset(visual_shader->get_node_position(p_type, p_id));
node->set_title(vsnode->get_caption());
node->set_name(itos(p_id));
Expand All @@ -490,17 +495,6 @@ void VisualShaderGraphPlugin::add_node(VisualShader::Type p_type, int p_id, bool
}

if (is_resizable) {
Ref<VisualShaderNodeComment> comment_node = Object::cast_to<VisualShaderNodeComment>(vsnode.ptr());
if (comment_node.is_valid()) {
is_comment = true;
node->set_comment(true);

Label *comment_label = memnew(Label);
node->add_child(comment_label);
comment_label->set_h_size_flags(Control::SIZE_EXPAND_FILL);
comment_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
comment_label->set_text(comment_node->get_description());
}
editor->call_deferred(SNAME("_set_node_size"), (int)p_type, p_id, size);
}

Expand Down Expand Up @@ -6127,7 +6121,6 @@ VisualShaderEditor::VisualShaderEditor() {

// SPECIAL

add_options.push_back(AddOption("Comment", "Special", "VisualShaderNodeComment", TTR("A rectangular area with a description string for better graph organization.")));
add_options.push_back(AddOption("Expression", "Special", "VisualShaderNodeExpression", TTR("Custom Godot Shader Language expression, with custom amount of input and output ports. This is a direct injection of code into the vertex/fragment/light function, do not use it to write the function declarations inside.")));
add_options.push_back(AddOption("GlobalExpression", "Special", "VisualShaderNodeGlobalExpression", TTR("Custom Godot Shader Language expression, which is placed on top of the resulted shader. You can place various function definitions inside and call it later in the Expressions. You can also declare varyings, parameters and constants.")));
add_options.push_back(AddOption("ParameterRef", "Special", "VisualShaderNodeParameterRef", TTR("A reference to an existing parameter.")));
Expand Down
80 changes: 3 additions & 77 deletions scene/gui/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,11 +374,8 @@ void GraphEdit::_update_scroll() {
void GraphEdit::_graph_node_raised(Node *p_gn) {
GraphNode *gn = Object::cast_to<GraphNode>(p_gn);
ERR_FAIL_NULL(gn);
if (gn->is_comment()) {
move_child(gn, 0);
} else {
gn->move_to_front();
}

gn->move_to_front();
}

void GraphEdit::_graph_node_selected(Node *p_gn) {
Expand Down Expand Up @@ -549,44 +546,6 @@ void GraphEdit::_notification(int p_what) {
}
}

void GraphEdit::_update_comment_enclosed_nodes_list(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes) {
Rect2 comment_node_rect = p_node->get_rect();

Vector<GraphNode *> enclosed_nodes;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (!gn || gn->is_selected()) {
continue;
}

Rect2 node_rect = gn->get_rect();

bool included = comment_node_rect.encloses(node_rect);
if (included) {
enclosed_nodes.push_back(gn);
}
}

p_comment_enclosed_nodes.insert(p_node->get_name(), enclosed_nodes);
}

void GraphEdit::_set_drag_comment_enclosed_nodes(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes, bool p_drag) {
for (int i = 0; i < p_comment_enclosed_nodes[p_node->get_name()].size(); i++) {
p_comment_enclosed_nodes[p_node->get_name()][i]->set_drag(p_drag);
}
}

void GraphEdit::_set_position_of_comment_enclosed_nodes(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes, Vector2 p_drag_accum) {
for (int i = 0; i < p_comment_enclosed_nodes[p_node->get_name()].size(); i++) {
Vector2 pos = (p_comment_enclosed_nodes[p_node->get_name()][i]->get_drag_from() * zoom + drag_accum) / zoom;
if (is_using_snap() ^ Input::get_singleton()->is_key_pressed(Key::CTRL)) {
const int snap = get_snap();
pos = pos.snapped(Vector2(snap, snap));
}
p_comment_enclosed_nodes[p_node->get_name()][i]->set_position_offset(pos);
}
}

bool GraphEdit::_filter_input(const Point2 &p_point) {
Ref<Texture2D> port_icon = get_theme_icon(SNAME("port"), SNAME("GraphNode"));

Expand Down Expand Up @@ -1040,33 +999,10 @@ void GraphEdit::_minimap_draw() {
Vector2 graph_offset = minimap->_get_graph_offset();
Vector2 minimap_offset = minimap->minimap_offset;

// Draw comment graph nodes.
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (!gn || !gn->is_comment()) {
continue;
}

Vector2 node_position = minimap->_convert_from_graph_position(gn->get_position_offset() * zoom - graph_offset) + minimap_offset;
Vector2 node_size = minimap->_convert_from_graph_position(gn->get_size() * zoom);
Rect2 node_rect = Rect2(node_position, node_size);

Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate();

// Override default values with colors provided by the GraphNode's stylebox, if possible.
Ref<StyleBoxFlat> sbf = gn->get_theme_stylebox(gn->is_selected() ? "comment_focus" : "comment");
if (sbf.is_valid()) {
Color node_color = sbf->get_bg_color();
sb_minimap->set_bg_color(node_color);
}

minimap->draw_style_box(sb_minimap, node_rect);
}

// Draw regular graph nodes.
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (!gn || gn->is_comment()) {
if (!gn) {
continue;
}

Expand Down Expand Up @@ -1165,9 +1101,6 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
}

gn->set_position_offset(pos);
if (gn->is_comment()) {
_set_position_of_comment_enclosed_nodes(gn, comment_enclosed_nodes, drag_accum);
}
}
}
}
Expand Down Expand Up @@ -1241,9 +1174,6 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (gn && gn->is_selected()) {
gn->set_drag(false);
if (gn->is_comment()) {
_set_drag_comment_enclosed_nodes(gn, comment_enclosed_nodes, false);
}
}
}
}
Expand Down Expand Up @@ -1310,10 +1240,6 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
}
if (o_gn->is_selected()) {
o_gn->set_drag(true);
if (o_gn->is_comment()) {
_update_comment_enclosed_nodes_list(o_gn, comment_enclosed_nodes);
_set_drag_comment_enclosed_nodes(o_gn, comment_enclosed_nodes, true);
}
}
}

Expand Down
5 changes: 0 additions & 5 deletions scene/gui/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,6 @@ class GraphEdit : public Control {
HashSet<int> valid_left_disconnect_types;
HashSet<int> valid_right_disconnect_types;

HashMap<StringName, Vector<GraphNode *>> comment_enclosed_nodes;
void _update_comment_enclosed_nodes_list(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes);
void _set_drag_comment_enclosed_nodes(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes, bool p_drag);
void _set_position_of_comment_enclosed_nodes(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes, Vector2 p_pos);

HBoxContainer *zoom_hb = nullptr;

friend class GraphEditFilter;
Expand Down
44 changes: 1 addition & 43 deletions scene/gui/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,37 +286,12 @@ void GraphNode::_resort() {
connpos_dirty = true;
}

bool GraphNode::has_point(const Point2 &p_point) const {
if (comment) {
Ref<StyleBox> comment_sb = get_theme_stylebox(SNAME("comment"));
Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer"));

if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) {
return true;
}

if (Rect2(0, 0, get_size().width, comment_sb->get_margin(SIDE_TOP)).has_point(p_point)) {
return true;
}

return false;

} else {
return Control::has_point(p_point);
}
}

void GraphNode::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW: {
Ref<StyleBox> sb;

if (comment) {
sb = get_theme_stylebox(selected ? SNAME("comment_focus") : SNAME("comment"));

} else {
sb = get_theme_stylebox(selected ? SNAME("selected_frame") : SNAME("frame"));
}
sb = get_theme_stylebox(selected ? SNAME("selected_frame") : SNAME("frame"));

Ref<StyleBox> sb_slot = get_theme_stylebox(SNAME("slot"));

Expand Down Expand Up @@ -1003,19 +978,6 @@ GraphNode::Overlay GraphNode::get_overlay() const {
return overlay;
}

void GraphNode::set_comment(bool p_enable) {
if (comment == p_enable) {
return;
}

comment = p_enable;
queue_redraw();
}

bool GraphNode::is_comment() const {
return comment;
}

void GraphNode::set_resizable(bool p_enable) {
if (resizable == p_enable) {
return;
Expand Down Expand Up @@ -1115,9 +1077,6 @@ void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_position_offset", "offset"), &GraphNode::set_position_offset);
ClassDB::bind_method(D_METHOD("get_position_offset"), &GraphNode::get_position_offset);

ClassDB::bind_method(D_METHOD("set_comment", "comment"), &GraphNode::set_comment);
ClassDB::bind_method(D_METHOD("is_comment"), &GraphNode::is_comment);

ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &GraphNode::set_resizable);
ClassDB::bind_method(D_METHOD("is_resizable"), &GraphNode::is_resizable);

Expand Down Expand Up @@ -1157,7 +1116,6 @@ void GraphNode::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draggable"), "set_draggable", "is_draggable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selectable"), "set_selectable", "is_selectable");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selected"), "set_selected", "is_selected");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "comment"), "set_comment", "is_comment");
ADD_PROPERTY(PropertyInfo(Variant::INT, "overlay", PROPERTY_HINT_ENUM, "Disabled,Breakpoint,Position"), "set_overlay", "get_overlay");

ADD_GROUP("BiDi", "");
Expand Down
5 changes: 0 additions & 5 deletions scene/gui/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ class GraphNode : public Container {
void _validate_property(PropertyInfo &p_property) const;

public:
bool has_point(const Point2 &p_point) const override;

void set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left = Ref<Texture2D>(), const Ref<Texture2D> &p_custom_right = Ref<Texture2D>(), bool p_draw_stylebox = true);
void clear_slot(int p_idx);
void clear_all_slots();
Expand Down Expand Up @@ -189,9 +187,6 @@ class GraphNode : public Container {
void set_overlay(Overlay p_overlay);
Overlay get_overlay() const;

void set_comment(bool p_enable);
bool is_comment() const;

void set_resizable(bool p_enable);
bool is_resizable() const;

Expand Down
2 changes: 0 additions & 2 deletions scene/resources/default_theme/default_theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const

theme->set_stylebox("frame", "GraphNode", graphnode_normal);
theme->set_stylebox("selected_frame", "GraphNode", graphnode_selected);
theme->set_stylebox("comment", "GraphNode", graphnode_comment_normal);
theme->set_stylebox("comment_focus", "GraphNode", graphnode_comment_selected);
theme->set_stylebox("breakpoint", "GraphNode", graphnode_breakpoint);
theme->set_stylebox("position", "GraphNode", graphnode_position);
theme->set_stylebox("slot", "GraphNode", graphnode_slot);
Expand Down

0 comments on commit 91258e5

Please sign in to comment.