Merge pull request #82669 from 4d49/graph-node-slot-custom-icon

Add `set_slot_custom_icon` and `get_slot_custom_icon` to GraphNode
This commit is contained in:
Rémi Verschelde 2024-01-08 11:49:46 +01:00
commit df29fc91ed
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 84 additions and 0 deletions

View file

@ -116,6 +116,20 @@
Returns the right (output) [Color] of the slot with the given [param slot_index].
</description>
</method>
<method name="get_slot_custom_icon_left" qualifiers="const">
<return type="Texture2D" />
<param index="0" name="slot_index" type="int" />
<description>
Returns the left (input) custom [Texture2D] of the slot with the given [param slot_index].
</description>
</method>
<method name="get_slot_custom_icon_right" qualifiers="const">
<return type="Texture2D" />
<param index="0" name="slot_index" type="int" />
<description>
Returns the right (output) custom [Texture2D] of the slot with the given [param slot_index].
</description>
</method>
<method name="get_slot_type_left" qualifiers="const">
<return type="int" />
<param index="0" name="slot_index" type="int" />
@ -195,6 +209,22 @@
Sets the [Color] of the right (output) side of the slot with the given [param slot_index] to [param color].
</description>
</method>
<method name="set_slot_custom_icon_left">
<return type="void" />
<param index="0" name="slot_index" type="int" />
<param index="1" name="custom_icon" type="Texture2D" />
<description>
Sets the custom [Texture2D] of the left (input) side of the slot with the given [param slot_index] to [param custom_icon].
</description>
</method>
<method name="set_slot_custom_icon_right">
<return type="void" />
<param index="0" name="slot_index" type="int" />
<param index="1" name="custom_icon" type="Texture2D" />
<description>
Sets the custom [Texture2D] of the right (output) side of the slot with the given [param slot_index] to [param custom_icon].
</description>
</method>
<method name="set_slot_draw_stylebox">
<return type="void" />
<param index="0" name="slot_index" type="int" />

View file

@ -482,6 +482,27 @@ Color GraphNode::get_slot_color_left(int p_slot_index) const {
return slot_table[p_slot_index].color_left;
}
void GraphNode::set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set custom_port_icon_left for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
if (slot_table[p_slot_index].custom_port_icon_left == p_custom_icon) {
return;
}
slot_table[p_slot_index].custom_port_icon_left = p_custom_icon;
queue_redraw();
port_pos_dirty = true;
emit_signal(SNAME("slot_updated"), p_slot_index);
}
Ref<Texture2D> GraphNode::get_slot_custom_icon_left(int p_slot_index) const {
if (!slot_table.has(p_slot_index)) {
return Ref<Texture2D>();
}
return slot_table[p_slot_index].custom_port_icon_left;
}
bool GraphNode::is_slot_enabled_right(int p_slot_index) const {
if (!slot_table.has(p_slot_index)) {
return false;
@ -545,6 +566,27 @@ Color GraphNode::get_slot_color_right(int p_slot_index) const {
return slot_table[p_slot_index].color_right;
}
void GraphNode::set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon) {
ERR_FAIL_COND_MSG(!slot_table.has(p_slot_index), vformat("Cannot set custom_port_icon_right for the slot with index '%d' because it hasn't been enabled.", p_slot_index));
if (slot_table[p_slot_index].custom_port_icon_right == p_custom_icon) {
return;
}
slot_table[p_slot_index].custom_port_icon_right = p_custom_icon;
queue_redraw();
port_pos_dirty = true;
emit_signal(SNAME("slot_updated"), p_slot_index);
}
Ref<Texture2D> GraphNode::get_slot_custom_icon_right(int p_slot_index) const {
if (!slot_table.has(p_slot_index)) {
return Ref<Texture2D>();
}
return slot_table[p_slot_index].custom_port_icon_right;
}
bool GraphNode::is_slot_draw_stylebox(int p_slot_index) const {
if (!slot_table.has(p_slot_index)) {
return false;
@ -797,6 +839,9 @@ void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_slot_color_left", "slot_index", "color"), &GraphNode::set_slot_color_left);
ClassDB::bind_method(D_METHOD("get_slot_color_left", "slot_index"), &GraphNode::get_slot_color_left);
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_left", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_left);
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_left", "slot_index"), &GraphNode::get_slot_custom_icon_left);
ClassDB::bind_method(D_METHOD("is_slot_enabled_right", "slot_index"), &GraphNode::is_slot_enabled_right);
ClassDB::bind_method(D_METHOD("set_slot_enabled_right", "slot_index", "enable"), &GraphNode::set_slot_enabled_right);
@ -806,6 +851,9 @@ void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_slot_color_right", "slot_index", "color"), &GraphNode::set_slot_color_right);
ClassDB::bind_method(D_METHOD("get_slot_color_right", "slot_index"), &GraphNode::get_slot_color_right);
ClassDB::bind_method(D_METHOD("set_slot_custom_icon_right", "slot_index", "custom_icon"), &GraphNode::set_slot_custom_icon_right);
ClassDB::bind_method(D_METHOD("get_slot_custom_icon_right", "slot_index"), &GraphNode::get_slot_custom_icon_right);
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);

View file

@ -129,6 +129,9 @@ public:
void set_slot_color_left(int p_slot_index, const Color &p_color);
Color get_slot_color_left(int p_slot_index) const;
void set_slot_custom_icon_left(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
Ref<Texture2D> get_slot_custom_icon_left(int p_slot_index) const;
bool is_slot_enabled_right(int p_slot_index) const;
void set_slot_enabled_right(int p_slot_index, bool p_enable);
@ -138,6 +141,9 @@ public:
void set_slot_color_right(int p_slot_index, const Color &p_color);
Color get_slot_color_right(int p_slot_index) const;
void set_slot_custom_icon_right(int p_slot_index, const Ref<Texture2D> &p_custom_icon);
Ref<Texture2D> get_slot_custom_icon_right(int p_slot_index) const;
bool is_slot_draw_stylebox(int p_slot_index) const;
void set_slot_draw_stylebox(int p_slot_index, bool p_enable);