Skip to content

Commit e53cbad

Browse files
committed
Merge pull request #109322 from 4d49/graph-node-slot-meta
Add metadata for slots in `GraphNode`
2 parents e658d2a + 4066281 commit e53cbad

File tree

3 files changed

+70
-0
lines changed

3 files changed

+70
-0
lines changed

doc/classes/GraphNode.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,20 @@
130130
Returns the right (output) custom [Texture2D] of the slot with the given [param slot_index].
131131
</description>
132132
</method>
133+
<method name="get_slot_metadata_left" qualifiers="const">
134+
<return type="Variant" />
135+
<param index="0" name="slot_index" type="int" />
136+
<description>
137+
Returns the left (input) metadata of the slot with the given [param slot_index].
138+
</description>
139+
</method>
140+
<method name="get_slot_metadata_right" qualifiers="const">
141+
<return type="Variant" />
142+
<param index="0" name="slot_index" type="int" />
143+
<description>
144+
Returns the right (output) metadata of the slot with the given [param slot_index].
145+
</description>
146+
</method>
133147
<method name="get_slot_type_left" qualifiers="const">
134148
<return type="int" />
135149
<param index="0" name="slot_index" type="int" />
@@ -249,6 +263,22 @@
249263
Toggles the right (output) side of the slot with the given [param slot_index]. If [param enable] is [code]true[/code], a port will appear on the right side and the slot will be able to be connected from this side.
250264
</description>
251265
</method>
266+
<method name="set_slot_metadata_left">
267+
<return type="void" />
268+
<param index="0" name="slot_index" type="int" />
269+
<param index="1" name="value" type="Variant" />
270+
<description>
271+
Sets the custom metadata for the left (input) side of the slot with the given [param slot_index] to [param value].
272+
</description>
273+
</method>
274+
<method name="set_slot_metadata_right">
275+
<return type="void" />
276+
<param index="0" name="slot_index" type="int" />
277+
<param index="1" name="value" type="Variant" />
278+
<description>
279+
Sets the custom metadata for the right (output) side of the slot with the given [param slot_index] to [param value].
280+
</description>
281+
</method>
252282
<method name="set_slot_type_left">
253283
<return type="void" />
254284
<param index="0" name="slot_index" type="int" />

scene/gui/graph_node.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,19 @@ Ref<Texture2D> GraphNode::get_slot_custom_icon_left(int p_slot_index) const {
835835
return slot_table[p_slot_index].custom_port_icon_left;
836836
}
837837

838+
void GraphNode::set_slot_metadata_left(int p_slot_index, const Variant &p_value) {
839+
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set left metadata for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
840+
slot_table[p_slot_index].metadata_left = p_value;
841+
}
842+
843+
Variant GraphNode::get_slot_metadata_left(int p_slot_index) const {
844+
const Slot *slot = slot_table.getptr(p_slot_index);
845+
if (slot == nullptr) {
846+
return Variant();
847+
}
848+
return slot->metadata_left;
849+
}
850+
838851
bool GraphNode::is_slot_enabled_right(int p_slot_index) const {
839852
if (!slot_table.has(p_slot_index)) {
840853
return false;
@@ -923,6 +936,19 @@ Ref<Texture2D> GraphNode::get_slot_custom_icon_right(int p_slot_index) const {
923936
return slot_table[p_slot_index].custom_port_icon_right;
924937
}
925938

939+
void GraphNode::set_slot_metadata_right(int p_slot_index, const Variant &p_value) {
940+
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set right metadata for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
941+
slot_table[p_slot_index].metadata_right = p_value;
942+
}
943+
944+
Variant GraphNode::get_slot_metadata_right(int p_slot_index) const {
945+
const Slot *slot = slot_table.getptr(p_slot_index);
946+
if (slot == nullptr) {
947+
return Variant();
948+
}
949+
return slot->metadata_right;
950+
}
951+
926952
bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const {
927953
if (!slot_table.has(p_slot_index)) {
928954
return false;
@@ -1229,6 +1255,9 @@ void GraphNode::_bind_methods() {
12291255
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_left", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_left);
12301256
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_left", "slot_index"), &GraphNode::get_slot_custom_icon_left);
12311257

1258+
ClassDB::bind_method(D_METHOD("set_slot_metadata_left", "slot_index", "value"), &GraphNode::set_slot_metadata_left);
1259+
ClassDB::bind_method(D_METHOD("get_slot_metadata_left", "slot_index"), &GraphNode::get_slot_metadata_left);
1260+
12321261
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
12331262
ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
12341263

@@ -1241,6 +1270,9 @@ void GraphNode::_bind_methods() {
12411270
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_right", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_right);
12421271
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_right", "slot_index"), &GraphNode::get_slot_custom_icon_right);
12431272

1273+
ClassDB::bind_method(D_METHOD("set_slot_metadata_right", "slot_index", "value"), &GraphNode::set_slot_metadata_right);
1274+
ClassDB::bind_method(D_METHOD("get_slot_metadata_right", "slot_index"), &GraphNode::get_slot_metadata_right);
1275+
12441276
ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
12451277
ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
12461278

scene/gui/graph_node.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ class GraphNode : public GraphElement {
4444
int type_left = 0;
4545
Color color_left = Color(1, 1, 1, 1);
4646
Ref<Texture2D> custom_port_icon_left;
47+
Variant metadata_left;
4748

4849
bool enable_right = false;
4950
int type_right = 0;
5051
Color color_right = Color(1, 1, 1, 1);
5152
Ref<Texture2D> custom_port_icon_right;
53+
Variant metadata_right;
5254

5355
bool draw_stylebox = true;
5456
};
@@ -150,6 +152,9 @@ class GraphNode : public GraphElement {
150152
void set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
151153
Ref<Texture2D> get_slot_custom_icon_left(int p_slot_index) const;
152154

155+
void set_slot_metadata_left(int p_slot_index, const Variant &p_value);
156+
Variant get_slot_metadata_left(int p_slot_index) const;
157+
153158
bool is_slot_enabled_right(int p_slot_index) const;
154159
void set_slot_enabled_right(int p_slot_index, bool p_enable);
155160

@@ -162,6 +167,9 @@ class GraphNode : public GraphElement {
162167
void set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
163168
Ref<Texture2D> get_slot_custom_icon_right(int p_slot_index) const;
164169

170+
void set_slot_metadata_right(int p_slot_index, const Variant &p_value);
171+
Variant get_slot_metadata_right(int p_slot_index) const;
172+
165173
bool is_slot_draw_stylebox(int p_slot_index) const;
166174
void set_slot_draw_stylebox(int p_slot_index, bool p_enable);
167175

0 commit comments

Comments
 (0)