Skip to content

Commit

Permalink
GH-343 Improve node styles, fidelity, and usability
Browse files Browse the repository at this point in the history
* Use the same msdf editor font as the Visual Shader, improving the text fidelity at higher zoom levels.
* Move node resizing to a togglable feature using off as the default, with an on/off by default setting in project settings.
* Improve the responsiveness of theme changes.
* Apply the border color uniformly around the entire node, like the visual shader UI.
* Make the node background, border color, and selected border colors configurable.
* Adjust the default border color to be charcoal grey rather than black.
* Configure whether the minimap is shown or hidden by default in the project settings.
* Border width is also configurable
  • Loading branch information
Naros committed May 11, 2024
1 parent cbd5444 commit 6b219c4
Show file tree
Hide file tree
Showing 17 changed files with 413 additions and 77 deletions.
14 changes: 13 additions & 1 deletion src/common/scene_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
#include <godot_cpp/classes/engine.hpp>
#include <godot_cpp/classes/font.hpp>
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/resource_loader.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/style_box.hpp>
#include <godot_cpp/classes/theme.hpp>
#include <godot_cpp/classes/theme_db.hpp>
#include <godot_cpp/classes/v_box_container.hpp>
Expand Down Expand Up @@ -65,6 +65,18 @@ namespace SceneUtils
return vbox->get_theme_icon(p_icon_name, "EditorIcons");
}

Ref<Font> get_editor_font(const String& p_font_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
return vbox->get_theme_font(p_font_name, "EditorFonts");
}

Ref<StyleBox> get_editor_stylebox(const String& p_stylebox_name, const String& p_class_name)
{
VBoxContainer* vbox = OrchestratorPlugin::get_singleton()->get_editor_interface()->get_editor_main_screen();
return vbox->get_theme_stylebox(p_stylebox_name, p_class_name);
}

Ref<Texture2D> get_class_icon(const String& p_class_name, const String& p_fallback)
{
Ref<Script> script;
Expand Down
10 changes: 10 additions & 0 deletions src/common/scene_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#define ORCHESTRATOR_SCENE_UTILS_H

#include <godot_cpp/classes/control.hpp>
#include <godot_cpp/classes/font.hpp>
#include <godot_cpp/classes/margin_container.hpp>
#include <godot_cpp/classes/node.hpp>
#include <godot_cpp/classes/script.hpp>
Expand All @@ -39,6 +40,15 @@ namespace SceneUtils
/// @return a reference to the texture or an invalid reference if the texture isn't loaded
Ref<Texture2D> get_editor_icon(const String& p_icon_name);

/// Get an editor font
/// @param p_font_name the font name
/// @return the font reference or an invalid reference if the font isn't found
Ref<Font> get_editor_font(const String& p_font_name);

/// Get an editor stylebox
/// @return the stylebox or an invalid reference if it wasn't found
Ref<StyleBox> get_editor_stylebox(const String& p_stylebox_name, const String& p_class_type);

/// Loads the class icon
///
/// @param p_class_name the class name
Expand Down
42 changes: 40 additions & 2 deletions src/editor/graph/graph_edit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

#include "common/dictionary_utils.h"
#include "common/logger.h"
#include "common/scene_utils.h"
#include "common/version.h"
#include "editor/graph/factories/graph_node_factory.h"
#include "editor/graph/graph_node_pin.h"
#include "editor/graph/graph_node_spawner.h"
Expand All @@ -38,6 +40,7 @@
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/script_editor.hpp>
#include <godot_cpp/classes/style_box_flat.hpp>
#include <godot_cpp/classes/theme.hpp>
#include <godot_cpp/classes/tween.hpp>

OrchestratorGraphEdit::Clipboard* OrchestratorGraphEdit::_clipboard = nullptr;
Expand Down Expand Up @@ -85,7 +88,7 @@ EPinDirection OrchestratorGraphEdit::DragContext::get_direction() const
OrchestratorGraphEdit::OrchestratorGraphEdit(OrchestratorPlugin* p_plugin, Ref<OScript> p_script, const String& p_name)
{
set_name(p_name);
set_minimap_enabled(false);
set_minimap_enabled(OrchestratorSettings::get_singleton()->get_setting("ui/graph/show_minimap", false));
set_right_disconnects(true);
set_show_arrange_button(false);

Expand Down Expand Up @@ -125,6 +128,8 @@ void OrchestratorGraphEdit::_notification(int p_what)
{
if (p_what == NOTIFICATION_READY)
{
_update_theme();

_drag_hint = memnew(Label);
_drag_hint->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, 0);
_drag_hint->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -50);
Expand Down Expand Up @@ -152,6 +157,11 @@ void OrchestratorGraphEdit::_notification(int p_what)
_drag_hint_timer->connect("timeout", callable_mp(this, &OrchestratorGraphEdit::_hide_drag_hint));
add_child(_drag_hint_timer);

_theme_update_timer = memnew(Timer);
_theme_update_timer->set_wait_time(.5);
_theme_update_timer->set_one_shot(true);
add_child(_theme_update_timer);

#if GODOT_VERSION >= 0x040300
_grid_pattern = memnew(OptionButton);
_grid_pattern->add_item("Lines");
Expand Down Expand Up @@ -499,6 +509,20 @@ void OrchestratorGraphEdit::_drop_data(const Vector2& p_position, const Variant&
}
}

void OrchestratorGraphEdit::_update_theme()
{
Ref<Font> label_font = SceneUtils::get_editor_font("main_msdf");
Ref<Font> label_bold_font = SceneUtils::get_editor_font("main_bold_msdf");

Ref<Theme> theme(memnew(Theme));
theme->set_font("font", "Label", label_font);
theme->set_font("font", "GraphNodeTitleLabel", label_bold_font);
theme->set_font("font", "LineEdit", label_font);
theme->set_font("font", "Button", label_font);

set_theme(theme);
}

void OrchestratorGraphEdit::_focus_node(int p_node_id, bool p_animated)
{
if (p_node_id >= 0)
Expand Down Expand Up @@ -1143,7 +1167,21 @@ void OrchestratorGraphEdit::_on_context_menu_selection(int p_id)

void OrchestratorGraphEdit::_on_project_settings_changed()
{
_synchronize_graph_with_script();
if (_theme_update_timer->is_stopped())
{
_theme_update_timer->start();

OrchestratorSettings* os = OrchestratorSettings::get_singleton();
bool show_icons = os->get_setting("ui/nodes/show_type_icons", true);
bool node_resizable = os->get_setting("ui/nodes/resizable_by_default", false);

set_minimap_enabled(os->get_setting("ui/graph/show_minimap", false));

for_each_graph_node([&](OrchestratorGraphNode* node) {
node->show_icons(show_icons);
node->set_resizable(node_resizable);
});
}
}

void OrchestratorGraphEdit::_on_inspect_script()
Expand Down
4 changes: 4 additions & 0 deletions src/editor/graph/graph_edit.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class OrchestratorGraphEdit : public GraphEdit
Control* _status{ nullptr }; //! Displays status in the center of graphs
Label* _drag_hint{ nullptr }; //! Displays the drag status at the bottom of the graph
Timer* _drag_hint_timer{ nullptr }; //! Timer for drag hint messages
Timer* _theme_update_timer{ nullptr };
OrchestratorGraphEdit() = default;

protected:
Expand Down Expand Up @@ -196,6 +197,9 @@ class OrchestratorGraphEdit : public GraphEdit
//~ End GraphEdit overrides

private:
/// Updates the GraphEdit theme
void _update_theme();

/// Moves the center of the graph to the node, optionally animating the movement.
/// @param p_node_id the node's unique id, should be greater or equal-to 0.
/// @param p_animated whether to animate the movement, enabled by default.
Expand Down
75 changes: 18 additions & 57 deletions src/editor/graph/graph_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
#include "common/scene_utils.h"
#include "graph_edit.h"
#include "graph_node_pin.h"
#include "plugin/plugin.h"
#include "plugin/settings.h"
#include "plugin/theme_cache.h"
#include "script/nodes/editable_pin_node.h"
#include "script/nodes/functions/call_function.h"
#include "script/script.h"
Expand All @@ -42,7 +44,7 @@ OrchestratorGraphNode::OrchestratorGraphNode(OrchestratorGraphEdit* p_graph, con

// Setup defaults
set_name(itos(_node->get_id()));
set_resizable(true);
set_resizable(OrchestratorSettings::get_singleton()->get_setting("ui/nodes/resizable_by_default", false));
set_h_size_flags(SIZE_EXPAND_FILL);
set_v_size_flags(SIZE_EXPAND_FILL);
set_meta("__script_node", p_node);
Expand Down Expand Up @@ -328,63 +330,16 @@ void OrchestratorGraphNode::_update_titlebar()

void OrchestratorGraphNode::_update_styles()
{
const String color_name = _node->get_node_title_color_name();
if (!color_name.is_empty())
Ref<OrchestratorThemeCache> cache = OrchestratorPlugin::get_singleton()->get_theme_cache();
if (cache.is_valid())
{
OrchestratorSettings* os = OrchestratorSettings::get_singleton();
const String key = vformat("ui/node_colors/%s", color_name);
if (os->has_setting(key))
{
Color color = os->get_setting(key);

Ref<StyleBoxFlat> panel = get_theme_stylebox("panel");
if (panel.is_valid())
{
Ref<StyleBoxFlat> new_panel = panel->duplicate(true);
if (new_panel.is_valid())
{
new_panel->set_border_color(Color(0.f, 0.f, 0.f));
new_panel->set_border_width_all(2);
new_panel->set_border_width(Side::SIDE_TOP, 0);
new_panel->set_content_margin_all(2);
new_panel->set_content_margin(Side::SIDE_BOTTOM, 6);
add_theme_stylebox_override("panel", new_panel);

Ref<StyleBoxFlat> panel_selected = new_panel->duplicate();
if (panel_selected.is_valid())
{
panel_selected->set_border_color(_get_selection_color());
add_theme_stylebox_override("panel_selected", panel_selected);
}
}
}

Ref<StyleBoxFlat> titlebar = get_theme_stylebox("titlebar");
if (titlebar.is_valid())
{
Ref<StyleBoxFlat> new_titlebar = titlebar->duplicate(true);
if (new_titlebar.is_valid())
{
new_titlebar->set_bg_color(color);
new_titlebar->set_border_width_all(2);
new_titlebar->set_border_width(Side::SIDE_BOTTOM, 0);

new_titlebar->set_content_margin_all(4);
new_titlebar->set_content_margin(Side::SIDE_LEFT, 12);
new_titlebar->set_content_margin(Side::SIDE_RIGHT, 12);
new_titlebar->set_border_color(color);

add_theme_stylebox_override("titlebar", new_titlebar);

Ref<StyleBoxFlat> titlebar_selected = new_titlebar->duplicate();
if (titlebar_selected.is_valid())
{
titlebar_selected->set_border_color(_get_selection_color());
add_theme_stylebox_override("titlebar_selected", titlebar_selected);
}
}
}
}
const String type_name = vformat("GraphNode_%s", _node->get_node_title_color_name());
begin_bulk_theme_override();
add_theme_stylebox_override("panel", cache->get_theme_stylebox("panel", "GraphNode"));
add_theme_stylebox_override("panel_selected", cache->get_theme_stylebox("panel_selected", "GraphNode"));
add_theme_stylebox_override("titlebar", cache->get_theme_stylebox("titlebar", type_name));
add_theme_stylebox_override("titlebar_selected", cache->get_theme_stylebox("titlebar_selected", type_name));
end_bulk_theme_override();
}
}

Expand Down Expand Up @@ -473,6 +428,7 @@ void OrchestratorGraphNode::_show_context_menu(const Vector2& p_position)
_context_menu->add_icon_item(SceneUtils::get_editor_icon("ActionCut"), "Cut", CM_CUT, Key(KEY_MASK_CTRL | KEY_X));
_context_menu->add_icon_item(SceneUtils::get_editor_icon("ActionCopy"), "Copy", CM_COPY, Key(KEY_MASK_CTRL | KEY_C));
_context_menu->add_icon_item(SceneUtils::get_editor_icon("Duplicate"), "Duplicate", CM_DUPLICATE, Key(KEY_MASK_CTRL | KEY_D));
_context_menu->add_icon_item(SceneUtils::get_editor_icon("DistractionFree"), "Toggle Resizer", CM_RESIZABLE);

_context_menu->add_icon_item(SceneUtils::get_editor_icon("Loop"), "Refresh Nodes", CM_REFRESH);
_context_menu->add_icon_item(SceneUtils::get_editor_icon("Unlinked"), "Break Node Link(s)", CM_BREAK_LINKS);
Expand Down Expand Up @@ -655,6 +611,11 @@ void OrchestratorGraphNode::_on_context_menu_selection(int p_id)
get_graph()->goto_class_help(_node->get_class());
break;
}
case CM_RESIZABLE:
{
set_resizable(!is_resizable());
break;
}
case CM_SELECT_GROUP:
{
select_group();
Expand Down
4 changes: 4 additions & 0 deletions src/editor/graph/graph_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class OrchestratorGraphNode : public GraphNode
CM_TOGGLE_BREAKPOINT,
CM_ADD_BREAKPOINT,
CM_VIEW_DOCUMENTATION,
CM_RESIZABLE,
#ifdef _DEBUG
CM_SHOW_DETAILS = 999,
#endif
Expand Down Expand Up @@ -142,6 +143,9 @@ class OrchestratorGraphNode : public GraphNode
/// Unlinks all connections to all pins on this node
void unlink_all();

/// Set whether node icons are shown
virtual void show_icons(bool p_show_icons) { }

/// Get a list of nodes within this node's global rect.
List<OrchestratorGraphNode*> get_nodes_within_global_rect();

Expand Down
32 changes: 19 additions & 13 deletions src/editor/graph/graph_node_pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,12 @@ void OrchestratorGraphNodePin::set_default_value_control_visibility(bool p_visib
_default_value->set_visible(p_visible);
}

void OrchestratorGraphNodePin::show_icon(bool p_visible)
{
if (_icon)
_icon->set_visible(p_visible);
}

void OrchestratorGraphNodePin::_remove_editable_pin()
{
Ref<OScriptEditablePinNode> editable = _node->get_script_node();
Expand Down Expand Up @@ -307,8 +313,8 @@ void OrchestratorGraphNodePin::_create_widgets()
HBoxContainer* row0 = memnew(HBoxContainer);
vbox->add_child(row0);

if (!is_execution() && show_icons)
row0->add_child(_create_type_icon());
if (!is_execution())
row0->add_child(_create_type_icon(true));

Label* label = _create_label();
label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
Expand All @@ -328,8 +334,8 @@ void OrchestratorGraphNodePin::_create_widgets()
}
else
{
if (!is_execution() && show_icons)
add_child(_create_type_icon());
if (!is_execution())
add_child(_create_type_icon(show_icons));

Label* label = _create_label();
label->set_horizontal_alignment(HORIZONTAL_ALIGNMENT_LEFT);
Expand All @@ -356,22 +362,22 @@ void OrchestratorGraphNodePin::_create_widgets()
label->set_v_size_flags(SIZE_SHRINK_CENTER);
add_child(label);

if (!is_execution() && show_icons)
add_child(_create_type_icon());
if (!is_execution())
add_child(_create_type_icon(show_icons));
}
}

TextureRect* OrchestratorGraphNodePin::_create_type_icon()
TextureRect* OrchestratorGraphNodePin::_create_type_icon(bool p_visible)
{
TextureRect* rect = memnew(TextureRect);
_icon = memnew(TextureRect);
String value_type_name = _pin->get_pin_type_name();
rect->set_texture(SceneUtils::get_editor_icon(value_type_name));
rect->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);
_icon->set_texture(SceneUtils::get_editor_icon(value_type_name));
_icon->set_stretch_mode(TextureRect::STRETCH_KEEP_ASPECT_CENTERED);

if (_pin->get_flags().has_flag(OScriptNodePin::Flags::HIDDEN))
rect->set_visible(false);
if (_pin->get_flags().has_flag(OScriptNodePin::Flags::HIDDEN) || !p_visible)
_icon->set_visible(false);

return rect;
return _icon;
}

Label* OrchestratorGraphNodePin::_create_label()
Expand Down
8 changes: 7 additions & 1 deletion src/editor/graph/graph_node_pin.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ class OrchestratorGraphNodePin : public HBoxContainer
};

OrchestratorGraphNode* _node{ nullptr }; //! The owning node
TextureRect* _icon{ nullptr }; //! The pin's icon
Control* _default_value{ nullptr }; //! The default value control
PopupMenu* _context_menu{ nullptr }; //! The context menu
Ref<OScriptNodePin> _pin; //! The script pin reference
Expand Down Expand Up @@ -197,6 +198,10 @@ class OrchestratorGraphNodePin : public HBoxContainer
/// @param p_visible whether the control is visible
void set_default_value_control_visibility(bool p_visible);

/// Whether the icons are shown
/// @param p_visible whether to show the icon
void show_icon(bool p_visible);

private:

void _select_nodes_for_pin(const Ref<OScriptNodePin>& p_pin);
Expand All @@ -213,8 +218,9 @@ class OrchestratorGraphNodePin : public HBoxContainer
String _create_promoted_variable_name();

/// Creates the pin's rendered icon
/// @param p_visible whether the icon is visible
/// @return the icon texture rect
TextureRect* _create_type_icon();
TextureRect* _create_type_icon(bool p_visible);

/// Creates the pin's label
/// @return the label
Expand Down
Loading

0 comments on commit 6b219c4

Please sign in to comment.