summaryrefslogtreecommitdiffstats
path: root/scene/gui/graph_node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/graph_node.cpp')
-rw-r--r--scene/gui/graph_node.cpp53
1 files changed, 34 insertions, 19 deletions
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 1b960a9b62..d804f83e1c 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -175,9 +175,8 @@ void GraphNode::_resort() {
HashMap<Control *, _MinSizeCache> min_size_cache;
for (int i = 0; i < get_child_count(false); i++) {
- Control *child = Object::cast_to<Control>(get_child(i, false));
-
- if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) {
+ Control *child = as_sortable_control(get_child(i, false));
+ if (!child) {
continue;
}
@@ -218,8 +217,8 @@ void GraphNode::_resort() {
bool refit_successful = true;
for (int i = 0; i < get_child_count(false); i++) {
- Control *child = Object::cast_to<Control>(get_child(i, false));
- if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) {
+ Control *child = as_sortable_control(get_child(i, false));
+ if (!child) {
continue;
}
@@ -256,8 +255,8 @@ void GraphNode::_resort() {
int width = new_size.width - sb_panel->get_minimum_size().width;
int valid_children_idx = 0;
for (int i = 0; i < get_child_count(false); i++) {
- Control *child = Object::cast_to<Control>(get_child(i, false));
- if (!child || !child->is_visible_in_tree() || child->is_set_as_top_level()) {
+ Control *child = as_sortable_control(get_child(i, false));
+ if (!child) {
continue;
}
@@ -336,7 +335,8 @@ void GraphNode::_notification(int p_what) {
int width = get_size().width - sb_panel->get_minimum_size().x;
- if (get_child_count() > 0) {
+ // Take the HboxContainer child into account.
+ if (get_child_count(false) > 0) {
int slot_index = 0;
for (const KeyValue<int, Slot> &E : slot_table) {
if (E.key < 0 || E.key >= slot_y_cache.size()) {
@@ -604,6 +604,14 @@ void GraphNode::set_slot_draw_stylebox(int p_slot_index, bool p_enable) {
emit_signal(SNAME("slot_updated"), p_slot_index);
}
+void GraphNode::set_ignore_invalid_connection_type(bool p_ignore) {
+ ignore_invalid_connection_type = p_ignore;
+}
+
+bool GraphNode::is_ignoring_valid_connection_type() const {
+ return ignore_invalid_connection_type;
+}
+
Size2 GraphNode::get_minimum_size() const {
Ref<StyleBox> sb_panel = theme_cache.panel;
Ref<StyleBox> sb_titlebar = theme_cache.titlebar;
@@ -613,8 +621,8 @@ Size2 GraphNode::get_minimum_size() const {
Size2 minsize = titlebar_hbox->get_minimum_size() + sb_titlebar->get_minimum_size();
for (int i = 0; i < get_child_count(false); i++) {
- Control *child = Object::cast_to<Control>(get_child(i, false));
- if (!child || !child->is_visible() || child->is_set_as_top_level()) {
+ Control *child = as_sortable_control(get_child(i, false));
+ if (!child) {
continue;
}
@@ -647,6 +655,7 @@ void GraphNode::_port_pos_update() {
left_port_cache.clear();
right_port_cache.clear();
int vertical_ofs = titlebar_hbox->get_size().height + sb_titlebar->get_minimum_size().height + sb_panel->get_margin(SIDE_TOP);
+ int slot_index = 0;
for (int i = 0; i < get_child_count(false); i++) {
Control *child = Object::cast_to<Control>(get_child(i, false));
@@ -656,27 +665,28 @@ void GraphNode::_port_pos_update() {
Size2i size = child->get_rect().size;
- if (slot_table.has(i)) {
- if (slot_table[i].enable_left) {
+ if (slot_table.has(slot_index)) {
+ if (slot_table[slot_index].enable_left) {
PortCache port_cache;
port_cache.pos = Point2i(edgeofs, vertical_ofs + size.height / 2);
- port_cache.type = slot_table[i].type_left;
- port_cache.color = slot_table[i].color_left;
- port_cache.slot_index = child->get_index(false);
+ port_cache.type = slot_table[slot_index].type_left;
+ port_cache.color = slot_table[slot_index].color_left;
+ port_cache.slot_index = slot_index;
left_port_cache.push_back(port_cache);
}
- if (slot_table[i].enable_right) {
+ if (slot_table[slot_index].enable_right) {
PortCache port_cache;
port_cache.pos = Point2i(get_size().width - edgeofs, vertical_ofs + size.height / 2);
- port_cache.type = slot_table[i].type_right;
- port_cache.color = slot_table[i].color_right;
- port_cache.slot_index = child->get_index(false);
+ port_cache.type = slot_table[slot_index].type_right;
+ port_cache.color = slot_table[slot_index].color_right;
+ port_cache.slot_index = slot_index;
right_port_cache.push_back(port_cache);
}
}
vertical_ofs += separation;
vertical_ofs += size.height;
+ slot_index++;
}
port_pos_dirty = false;
@@ -857,6 +867,9 @@ void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
+ ClassDB::bind_method(D_METHOD("set_ignore_invalid_connection_type", "ignore"), &GraphNode::set_ignore_invalid_connection_type);
+ ClassDB::bind_method(D_METHOD("is_ignoring_valid_connection_type"), &GraphNode::is_ignoring_valid_connection_type);
+
ClassDB::bind_method(D_METHOD("get_input_port_count"), &GraphNode::get_input_port_count);
ClassDB::bind_method(D_METHOD("get_input_port_position", "port_idx"), &GraphNode::get_input_port_position);
ClassDB::bind_method(D_METHOD("get_input_port_type", "port_idx"), &GraphNode::get_input_port_type);
@@ -872,6 +885,8 @@ void GraphNode::_bind_methods() {
GDVIRTUAL_BIND(_draw_port, "slot_index", "position", "left", "color")
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "ignore_invalid_connection_type"), "set_ignore_invalid_connection_type", "is_ignoring_valid_connection_type");
+
ADD_SIGNAL(MethodInfo("slot_updated", PropertyInfo(Variant::INT, "slot_index")));
BIND_THEME_ITEM(Theme::DATA_TYPE_STYLEBOX, GraphNode, panel);