Skip to content

Commit 4066281

Browse files
committed
Add metadata for slots in GraphNode
1 parent c2202d3 commit 4066281

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
@@ -838,6 +838,19 @@ Ref<Texture2D> GraphNode::get_slot_custom_icon_left(int p_slot_index) const {
838838
return slot_table[p_slot_index].custom_port_icon_left;
839839
}
840840

841+
void GraphNode::set_slot_metadata_left(int p_slot_index, const Variant &p_value) {
842+
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));
843+
slot_table[p_slot_index].metadata_left = p_value;
844+
}
845+
846+
Variant GraphNode::get_slot_metadata_left(int p_slot_index) const {
847+
const Slot *slot = slot_table.getptr(p_slot_index);
848+
if (slot == nullptr) {
849+
return Variant();
850+
}
851+
return slot->metadata_left;
852+
}
853+
841854
bool GraphNode::is_slot_enabled_right(int p_slot_index) const {
842855
if (!slot_table.has(p_slot_index)) {
843856
return false;
@@ -926,6 +939,19 @@ Ref<Texture2D> GraphNode::get_slot_custom_icon_right(int p_slot_index) const {
926939
return slot_table[p_slot_index].custom_port_icon_right;
927940
}
928941

942+
void GraphNode::set_slot_metadata_right(int p_slot_index, const Variant &p_value) {
943+
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));
944+
slot_table[p_slot_index].metadata_right = p_value;
945+
}
946+
947+
Variant GraphNode::get_slot_metadata_right(int p_slot_index) const {
948+
const Slot *slot = slot_table.getptr(p_slot_index);
949+
if (slot == nullptr) {
950+
return Variant();
951+
}
952+
return slot->metadata_right;
953+
}
954+
929955
bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const {
930956
if (!slot_table.has(p_slot_index)) {
931957
return false;
@@ -1232,6 +1258,9 @@ void GraphNode::_bind_methods() {
12321258
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_left", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_left);
12331259
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_left", "slot_index"), &GraphNode::get_slot_custom_icon_left);
12341260

1261+
ClassDB::bind_method(D_METHOD("set_slot_metadata_left", "slot_index", "value"), &GraphNode::set_slot_metadata_left);
1262+
ClassDB::bind_method(D_METHOD("get_slot_metadata_left", "slot_index"), &GraphNode::get_slot_metadata_left);
1263+
12351264
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
12361265
ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
12371266

@@ -1244,6 +1273,9 @@ void GraphNode::_bind_methods() {
12441273
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_right", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_right);
12451274
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_right", "slot_index"), &GraphNode::get_slot_custom_icon_right);
12461275

1276+
ClassDB::bind_method(D_METHOD("set_slot_metadata_right", "slot_index", "value"), &GraphNode::set_slot_metadata_right);
1277+
ClassDB::bind_method(D_METHOD("get_slot_metadata_right", "slot_index"), &GraphNode::get_slot_metadata_right);
1278+
12471279
ClassDB::bind_method(D_METHOD("is_slot_draw_stylebox", "slot_index"), &GraphNode::is_slot_draw_stylebox);
12481280
ClassDB::bind_method(D_METHOD("set_slot_draw_stylebox", "slot_index", "enable"), &GraphNode::set_slot_draw_stylebox);
12491281

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)