Skip to content

Commit

Permalink
CraterCrashGH-427 Support custom icons for comment nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Naros committed Aug 19, 2024
1 parent ed31e69 commit 97a5e95
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/editor/graph/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <godot_cpp/classes/input_event_mouse_button.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/margin_container.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/script_editor_base.hpp>
#include <godot_cpp/classes/style_box_flat.hpp>

Expand Down Expand Up @@ -306,15 +307,21 @@ void OrchestratorGraphNode::_update_titlebar()
{
Ref<Texture2D> icon_texture;
if (!_node->get_icon().is_empty())
icon_texture = SceneUtils::get_editor_icon(_node->get_icon());
{
if (_node->get_icon().begins_with("res://"))
icon_texture = ResourceLoader::get_singleton()->load(_node->get_icon());
else
icon_texture = SceneUtils::get_editor_icon(_node->get_icon());
}

TextureRect* rect = Object::cast_to<TextureRect>(titlebar->get_child(0));
if (!rect && icon_texture.is_valid())
{
// Add node's icon to the UI
rect = memnew(TextureRect);
rect->set_custom_minimum_size(Vector2(0, 24));
rect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
rect->set_expand_mode(TextureRect::EXPAND_FIT_WIDTH_PROPORTIONAL);
rect->set_size(Vector2(24, 24));
rect->set_texture(icon_texture);

// Add the icon and move it to the start of the HBox.
Expand Down
16 changes: 15 additions & 1 deletion src/script/nodes/utilities/comment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,14 @@
//
#include "comment.h"

#include "common/string_utils.h"

void OScriptNodeComment::_get_property_list(List<PropertyInfo>* r_list) const
{
const String movement_modes = "Group Movement,Comment";

r_list->push_back(PropertyInfo(Variant::STRING, "title"));
r_list->push_back(PropertyInfo(Variant::STRING, "icon", PROPERTY_HINT_FILE));
r_list->push_back(PropertyInfo(Variant::BOOL, "align_center"));
r_list->push_back(PropertyInfo(Variant::COLOR, "background_color"));
r_list->push_back(PropertyInfo(Variant::INT, "font_size", PROPERTY_HINT_RANGE, "0,64"));
Expand Down Expand Up @@ -60,6 +63,11 @@ bool OScriptNodeComment::_get(const StringName& p_name, Variant& r_value) const
r_value = _title;
return true;
}
else if (p_name.match("icon"))
{
r_value = _icon;
return true;
}
return false;
}

Expand Down Expand Up @@ -101,6 +109,12 @@ bool OScriptNodeComment::_set(const StringName& p_name, const Variant& p_value)
_notify_pins_changed();
return true;
}
else if (p_name.match("icon"))
{
_icon = p_value;
_notify_pins_changed();
return true;
}
return false;
}

Expand All @@ -119,5 +133,5 @@ String OScriptNodeComment::get_node_title() const

String OScriptNodeComment::get_icon() const
{
return "VisualShaderNodeComment";
return StringUtils::default_if_empty(_icon, "VisualShaderNodeComment");
}
1 change: 1 addition & 0 deletions src/script/nodes/utilities/comment.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class OScriptNodeComment : public OScriptNode
protected:
String _comments;
String _title{ "Comment" };
String _icon;
bool _align_center{ false };
Color _background_color{ 0.6, 0.6, 0.6, 0.05 };
Color _text_color{ 1.0, 1.0, 1.0, 1.0 };
Expand Down

0 comments on commit 97a5e95

Please sign in to comment.