Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-410 Add friendly names for Graph/Function component panels #411

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/common/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ void OrchestratorSettings::_register_settings()

_settings.emplace_back(BOOL_SETTING("ui/actions_menu/center_on_mouse", true));

_settings.emplace_back(BOOL_SETTING("ui/components_panel/show_graph_friendly_names", true));
_settings.emplace_back(BOOL_SETTING("ui/components_panel/show_function_friendly_names", true));

_settings.emplace_back(BOOL_SETTING("ui/graph/disconnect_control_flow_when_dragged", true));
_settings.emplace_back(BOOL_SETTING("ui/graph/show_autowire_selection_dialog", true));
_settings.emplace_back(BOOL_SETTING("ui/graph/show_minimap", false));
Expand Down
40 changes: 38 additions & 2 deletions src/editor/component_panels/component_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <godot_cpp/classes/label.hpp>
#include <godot_cpp/classes/panel_container.hpp>
#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/project_settings.hpp>
#include <godot_cpp/classes/scene_tree.hpp>
#include <godot_cpp/classes/scene_tree_timer.hpp>
#include <godot_cpp/classes/style_box_flat.hpp>
Expand Down Expand Up @@ -72,7 +73,10 @@ void OrchestratorScriptComponentPanel::_tree_item_edited()

// Nothing to edit if they're identical
if (old_name.match(new_name))
{
item->set_text(0, item->get_meta("__rollback_name"));
return;
}

_handle_item_renamed(old_name, new_name);

Expand Down Expand Up @@ -137,13 +141,30 @@ Variant OrchestratorScriptComponentPanel::_tree_drag_data(const Vector2& p_posit
hbc->add_child(rect);

Label* label = memnew(Label);
label->set_text(_tree->get_selected()->get_text(0));
label->set_text(_get_tree_item_name(_tree->get_selected()));
hbc->add_child(label);

set_drag_preview(container);
return data;
}

TreeItem* OrchestratorScriptComponentPanel::_create_item(TreeItem* p_parent, const String& p_text, const String& p_item_name, const String& p_icon_name)
{
TreeItem* item = p_parent->create_child();
item->set_text(0, p_text);
item->set_meta("__name", p_item_name);
item->set_meta("__rollback_name", p_text);
if (!p_icon_name.is_empty())
item->set_icon(0, SceneUtils::get_editor_icon(p_icon_name));

return item;
}

String OrchestratorScriptComponentPanel::_get_tree_item_name(TreeItem* p_item)
{
return p_item ? p_item->get_meta("__name") : "";
}

void OrchestratorScriptComponentPanel::_update_theme()
{
if (!_theme_changing)
Expand Down Expand Up @@ -183,6 +204,17 @@ void OrchestratorScriptComponentPanel::_clear_tree()
_tree->create_item();
}

void OrchestratorScriptComponentPanel::_edit_selected_tree_item()
{
TreeItem* selected = _tree->get_selected();
if (selected)
{
const String item_name = _get_tree_item_name(selected);
_tree->get_selected()->set_text(0, item_name);
_tree->edit_selected(true);
}
}

void OrchestratorScriptComponentPanel::_update_collapse_button_icon()
{
const String icon_name = _expanded ? "GuiTreeArrowDown" : "GuiTreeArrowRight";
Expand Down Expand Up @@ -218,7 +250,7 @@ bool OrchestratorScriptComponentPanel::_find_child_and_activate(const String& p_
{
if (TreeItem* child = Object::cast_to<TreeItem>(root->get_child(i)))
{
if (child->get_text(0).match(p_name))
if (_get_tree_item_name(child).match(p_name))
{
emit_signal("scroll_to_item", child);
_tree->call_deferred("set_selected", child, 0);
Expand Down Expand Up @@ -318,6 +350,10 @@ void OrchestratorScriptComponentPanel::_notification(int p_what)
_notify->set_title("Message");
add_child(_notify);

// For handling friendly name changes
ProjectSettings* settings = ProjectSettings::get_singleton();
settings->connect("settings_changed", callable_mp(this, &OrchestratorScriptComponentPanel::update));

// Connections
_collapse_button->connect("pressed", callable_mp(this, &OrchestratorScriptComponentPanel::_toggle));
_add_button->connect("pressed", callable_mp(this, &OrchestratorScriptComponentPanel::_tree_add_item));
Expand Down
15 changes: 15 additions & 0 deletions src/editor/component_panels/component_panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,27 @@ class OrchestratorScriptComponentPanel : public VBoxContainer
Variant _tree_drag_data(const Vector2& p_position);
//~ End Signal handlers

/// Creates an item in the tree.
/// @param p_parent the parent
/// @param p_text the display text
/// @param p_item_name the item name
/// @param p_icon_name the icon
TreeItem* _create_item(TreeItem* p_parent, const String& p_text, const String& p_item_name, const String& p_icon_name);

/// Get the item's real name
/// @param p_item the tree item
/// @return the item's real name
String _get_tree_item_name(TreeItem* p_item);

/// Updates the control's theme.
void _update_theme();

/// Clears the tree of all items but the root.
void _clear_tree();

/// Edit the selected tree item
void _edit_selected_tree_item();

/// Updates the state of the collapse button.
void _update_collapse_button_icon();

Expand Down
24 changes: 14 additions & 10 deletions src/editor/component_panels/functions_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "common/callable_lambda.h"
#include "common/dictionary_utils.h"
#include "common/scene_utils.h"
#include "common/settings.h"
#include "editor/plugins/orchestrator_editor_plugin.h"
#include "editor/script_connections.h"
#include "editor/script_view.h"
Expand All @@ -32,7 +33,7 @@
void OrchestratorScriptFunctionsComponentPanel::_show_function_graph(TreeItem* p_item)
{
// Function name and graph names are synonymous
const String function_name = p_item->get_text(0);
const String function_name = _get_tree_item_name(p_item);
emit_signal("show_graph_requested", function_name);
emit_signal("focus_node_requested", function_name, _orchestration->get_function_node_id(function_name));
_tree->deselect_all();
Expand Down Expand Up @@ -75,7 +76,7 @@ void OrchestratorScriptFunctionsComponentPanel::_handle_context_menu(int p_id)
_show_function_graph(_tree->get_selected());
break;
case CM_RENAME_FUNCTION:
_tree->edit_selected(true);
_edit_selected_tree_item();
break;
case CM_REMOVE_FUNCTION:
_confirm_removal(_tree->get_selected());
Expand All @@ -90,10 +91,10 @@ bool OrchestratorScriptFunctionsComponentPanel::_handle_add_new_item(const Strin

void OrchestratorScriptFunctionsComponentPanel::_handle_item_selected()
{
const TreeItem* item = _tree->get_selected();
TreeItem* item = _tree->get_selected();
if (item)
{
const Ref<OScriptFunction> function = _orchestration->find_function(StringName(item->get_text(0)));
const Ref<OScriptFunction> function = _orchestration->find_function(StringName(_get_tree_item_name(item)));
if (function.is_valid())
{
const Ref<OScriptNode> node = function->get_owning_node();
Expand Down Expand Up @@ -124,7 +125,7 @@ bool OrchestratorScriptFunctionsComponentPanel::_handle_item_renamed(const Strin
void OrchestratorScriptFunctionsComponentPanel::_handle_remove(TreeItem* p_item)
{
// Function name and graph names are synonymous
const String function_name = p_item->get_text(0);
const String function_name = _get_tree_item_name(p_item);
emit_signal("close_graph_requested", function_name);

_orchestration->remove_function(function_name);
Expand All @@ -151,7 +152,7 @@ Dictionary OrchestratorScriptFunctionsComponentPanel::_handle_drag_data(const Ve
TreeItem* selected = _tree->get_selected();
if (selected)
{
Ref<OScriptFunction> function = _orchestration->find_function(StringName(selected->get_text(0)));
Ref<OScriptFunction> function = _orchestration->find_function(StringName(_get_tree_item_name(selected)));
if (function.is_valid())
{
data["type"] = "function";
Expand All @@ -175,16 +176,19 @@ void OrchestratorScriptFunctionsComponentPanel::update()
base_type = script->get_instance_base_type();
}

OrchestratorSettings* settings = OrchestratorSettings::get_singleton();
bool use_friendly_names = settings->get_setting("ui/components_panel/show_function_friendly_names", true);

for (const Ref<OScriptGraph>& graph : _orchestration->get_graphs())
{
if (!(graph->get_flags().has_flag(OScriptGraph::GraphFlags::GF_FUNCTION)))
continue;

TreeItem* item = _tree->get_root()->create_child();
item->set_text(0, graph->get_graph_name());
item->set_meta("__name", graph->get_graph_name()); // Used for renames
item->set_icon(0, SceneUtils::get_editor_icon("MemberMethod"));
String friendly_name = graph->get_graph_name();
if (use_friendly_names)
friendly_name = graph->get_graph_name().capitalize();

TreeItem* item = _create_item(_tree->get_root(), friendly_name, graph->get_graph_name(), "MemberMethod");
if (SceneUtils::has_any_signals_connected_to_function(graph->get_graph_name(), base_type, script_nodes))
item->add_button(0, SceneUtils::get_editor_icon("Slot"));
}
Expand Down
41 changes: 21 additions & 20 deletions src/editor/component_panels/graphs_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,43 +17,39 @@
#include "editor/component_panels/graphs_panel.h"

#include "common/scene_utils.h"
#include "common/settings.h"
#include "editor/script_connections.h"

#include <godot_cpp/classes/popup_menu.hpp>
#include <godot_cpp/classes/tree.hpp>

void OrchestratorScriptGraphsComponentPanel::_show_graph_item(TreeItem* p_item)
{
const String graph_name = p_item->get_text(0);

// Graph
emit_signal("show_graph_requested", graph_name);
emit_signal("show_graph_requested", _get_tree_item_name(p_item));
_tree->deselect_all();
}

void OrchestratorScriptGraphsComponentPanel::_focus_graph_function(TreeItem* p_item)
{
const String graph_name = p_item->get_parent()->get_text(0);
const int node_id = _orchestration->get_function_node_id(p_item->get_text(0));
const int node_id = _orchestration->get_function_node_id(_get_tree_item_name(p_item));

// Specific event node
emit_signal("focus_node_requested", graph_name, node_id);
emit_signal("focus_node_requested", _get_tree_item_name(p_item->get_parent()), node_id);
_tree->deselect_all();
}

void OrchestratorScriptGraphsComponentPanel::_remove_graph(TreeItem* p_item)
{
const String graph_name = p_item->get_text(0);
const String graph_name = _get_tree_item_name(p_item);
emit_signal("close_graph_requested", graph_name);

_orchestration->remove_graph(graph_name);
}

void OrchestratorScriptGraphsComponentPanel::_remove_graph_function(TreeItem* p_item)
{
const String function_name = p_item->get_text(0);

_orchestration->remove_function(function_name);
_orchestration->remove_function(_get_tree_item_name(p_item));
update();
}

Expand Down Expand Up @@ -88,7 +84,7 @@ bool OrchestratorScriptGraphsComponentPanel::_populate_context_menu(TreeItem* p_
if (p_item->get_parent() == _tree->get_root())
{
// Graph
Ref<OScriptGraph> graph = _orchestration->get_graph(p_item->get_text(0));
Ref<OScriptGraph> graph = _orchestration->get_graph(_get_tree_item_name(p_item));
bool rename_disabled = !graph->get_flags().has_flag(OScriptGraph::GraphFlags::GF_RENAMABLE);
bool delete_disabled = !graph->get_flags().has_flag(OScriptGraph::GraphFlags::GF_DELETABLE);
_context_menu->add_item("Open Graph", CM_OPEN_GRAPH);
Expand All @@ -114,7 +110,7 @@ void OrchestratorScriptGraphsComponentPanel::_handle_context_menu(int p_id)
_show_graph_item(_tree->get_selected());
break;
case CM_RENAME_GRAPH:
_tree->edit_selected(true);
_edit_selected_tree_item();
break;
case CM_REMOVE_GRAPH:
_confirm_removal(_tree->get_selected());
Expand Down Expand Up @@ -172,7 +168,7 @@ void OrchestratorScriptGraphsComponentPanel::_handle_button_clicked(TreeItem* p_

OrchestratorScriptConnectionsDialog* dialog = memnew(OrchestratorScriptConnectionsDialog);
add_child(dialog);
dialog->popup_connections(p_item->get_text(0), nodes);
dialog->popup_connections(_get_tree_item_name(p_item), nodes);
}

void OrchestratorScriptGraphsComponentPanel::update()
Expand All @@ -198,26 +194,31 @@ void OrchestratorScriptGraphsComponentPanel::update()
base_type = script->get_instance_base_type();
}

OrchestratorSettings* settings = OrchestratorSettings::get_singleton();
bool use_friendly_names = settings->get_setting("ui/components_panel/show_graph_friendly_names", true);

const PackedStringArray functions = _orchestration->get_function_names();
for (const Ref<OScriptGraph>& graph : graphs)
{
if (!(graph->get_flags().has_flag(OScriptGraph::GraphFlags::GF_EVENT)))
continue;

TreeItem* item = _tree->get_root()->create_child();
item->set_text(0, graph->get_graph_name());
item->set_meta("__name", graph->get_graph_name()); // Used for renames
item->set_icon(0, SceneUtils::get_editor_icon("ClassList"));
String friendly_name = graph->get_graph_name();
if (use_friendly_names)
friendly_name = friendly_name.capitalize();

TreeItem* item = _create_item(_tree->get_root(), friendly_name, graph->get_graph_name(), "ClassList");

for (const String& function_name : functions)
{
int function_id = _orchestration->get_function_node_id(function_name);
if (graph->has_node(function_id))
{
TreeItem* func = item->create_child();
func->set_text(0, function_name);
func->set_icon(0, SceneUtils::get_editor_icon("PlayStart"));
friendly_name = function_name;
if (use_friendly_names)
friendly_name = vformat("%s Event", function_name.capitalize());

TreeItem* func = _create_item(item, friendly_name, function_name, "PlayStart");
if (SceneUtils::has_any_signals_connected_to_function(function_name, base_type, script_nodes))
func->add_button(0, SceneUtils::get_editor_icon("Slot"));
}
Expand Down
17 changes: 7 additions & 10 deletions src/editor/component_panels/signals_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "common/dictionary_utils.h"
#include "common/scene_utils.h"
#include "common/settings.h"
#include "editor/plugins/orchestrator_editor_plugin.h"

#include <godot_cpp/classes/popup_menu.hpp>
Expand Down Expand Up @@ -53,7 +54,7 @@ void OrchestratorScriptSignalsComponentPanel::_handle_context_menu(int p_id)
switch (p_id)
{
case CM_RENAME_SIGNAL:
_tree->edit_selected(true);
_edit_selected_tree_item();
break;
case CM_REMOVE_SIGNAL:
_confirm_removal(_tree->get_selected());
Expand All @@ -71,13 +72,13 @@ void OrchestratorScriptSignalsComponentPanel::_handle_item_selected()
{
TreeItem* item = _tree->get_selected();

Ref<OScriptSignal> signal = _orchestration->get_custom_signal(item->get_text(0));
Ref<OScriptSignal> signal = _orchestration->get_custom_signal(_get_tree_item_name(item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(signal);
}

void OrchestratorScriptSignalsComponentPanel::_handle_item_activated(TreeItem* p_item)
{
Ref<OScriptSignal> signal = _orchestration->get_custom_signal(p_item->get_text(0));
Ref<OScriptSignal> signal = _orchestration->get_custom_signal(_get_tree_item_name(p_item));
OrchestratorPlugin::get_singleton()->get_editor_interface()->edit_resource(signal);
}

Expand All @@ -95,8 +96,7 @@ bool OrchestratorScriptSignalsComponentPanel::_handle_item_renamed(const String&

void OrchestratorScriptSignalsComponentPanel::_handle_remove(TreeItem* p_item)
{
const String signal_name = p_item->get_text(0);
_orchestration->remove_custom_signal(signal_name);
_orchestration->remove_custom_signal(_get_tree_item_name(p_item));
}

Dictionary OrchestratorScriptSignalsComponentPanel::_handle_drag_data(const Vector2& p_position)
Expand All @@ -106,7 +106,7 @@ Dictionary OrchestratorScriptSignalsComponentPanel::_handle_drag_data(const Vect
TreeItem* selected = _tree->get_selected();
if (selected)
{
Ref<OScriptSignal> signal = _orchestration->find_custom_signal(StringName(selected->get_text(0)));
Ref<OScriptSignal> signal = _orchestration->find_custom_signal(StringName(_get_tree_item_name(selected)));
if (signal.is_valid())
{
data["type"] = "signal";
Expand All @@ -128,10 +128,7 @@ void OrchestratorScriptSignalsComponentPanel::update()
{
Ref<OScriptSignal> signal = _orchestration->get_custom_signal(signal_name);

TreeItem* item = _tree->get_root()->create_child();
item->set_text(0, signal_name);
item->set_meta("__name", signal_name);
item->set_icon(0, SceneUtils::get_editor_icon("MemberSignal"));
_create_item(_tree->get_root(), signal_name, signal_name, "MemberSignal");
}
}

Expand Down
Loading
Loading