Ported: Add node list param to GraphEdit::delete_nodes_request signal - Chaosus

32b9818965
This commit is contained in:
Relintai 2022-07-27 20:01:38 +02:00
parent ced2f890b6
commit 53f8707713
4 changed files with 27 additions and 15 deletions

View File

@ -208,8 +208,9 @@
</description>
</signal>
<signal name="delete_nodes_request">
<argument index="0" name="nodes" type="Array" />
<description>
Emitted when a GraphNode is attempted to be removed from the GraphEdit.
Emitted when a GraphNode is attempted to be removed from the GraphEdit. Provides a list of node names to be removed (all selected nodes, excluding nodes without closing button).
</description>
</signal>
<signal name="disconnection_request">

View File

@ -30,19 +30,12 @@
#include "animation_blend_tree_editor_plugin.h"
#include "core/io/resource_loader.h"
#include "editor/editor_inspector.h"
#include "editor/editor_scale.h"
#include "scene/3d/skeleton.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/graph_node.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/progress_bar.h"
#include "core/array.h"
#include "core/class_db.h"
#include "core/color.h"
#include "core/error_macros.h"
#include "core/hash_map.h"
#include "core/io/resource_loader.h"
#include "core/list.h"
#include "core/node_path.h"
#include "core/os/memory.h"
@ -50,25 +43,32 @@
#include "core/typedefs.h"
#include "core/undo_redo.h"
#include "editor/editor_file_dialog.h"
#include "editor/editor_inspector.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/2d/canvas_item.h"
#include "scene/3d/skeleton.h"
#include "scene/animation/animation_blend_tree.h"
#include "scene/animation/animation_player.h"
#include "scene/gui/box_container.h"
#include "scene/gui/button.h"
#include "scene/gui/check_box.h"
#include "scene/gui/control.h"
#include "scene/gui/dialogs.h"
#include "scene/gui/graph_edit.h"
#include "scene/gui/graph_node.h"
#include "scene/gui/label.h"
#include "scene/gui/line_edit.h"
#include "scene/gui/menu_button.h"
#include "scene/gui/panel_container.h"
#include "scene/gui/popup_menu.h"
#include "scene/gui/progress_bar.h"
#include "scene/gui/separator.h"
#include "scene/gui/tree.h"
#include "scene/main/node.h"
#include "scene/resources/animation.h"
#include "scene/resources/style_box.h"
#include "scene/animation/animation_blend_tree.h"
void AnimationNodeBlendTreeEditor::add_custom_type(const String &p_name, const Ref<Script> &p_script) {
for (int i = 0; i < add_options.size(); i++) {
@ -484,7 +484,7 @@ void AnimationNodeBlendTreeEditor::_delete_request(const String &p_which) {
undo_redo->commit_action();
}
void AnimationNodeBlendTreeEditor::_delete_nodes_request() {
void AnimationNodeBlendTreeEditor::_delete_nodes_request(const Array &p_nodes) {
List<StringName> to_erase;
for (int i = 0; i < graph->get_child_count(); i++) {
@ -852,7 +852,7 @@ void AnimationNodeBlendTreeEditor::_bind_methods() {
ClassDB::bind_method("_open_in_editor", &AnimationNodeBlendTreeEditor::_open_in_editor);
ClassDB::bind_method("_scroll_changed", &AnimationNodeBlendTreeEditor::_scroll_changed);
ClassDB::bind_method("_delete_request", &AnimationNodeBlendTreeEditor::_delete_request);
ClassDB::bind_method("_delete_nodes_request", &AnimationNodeBlendTreeEditor::_delete_nodes_request);
ClassDB::bind_method("_delete_nodes_request", "nodes", &AnimationNodeBlendTreeEditor::_delete_nodes_request);
ClassDB::bind_method("_popup_request", &AnimationNodeBlendTreeEditor::_popup_request);
ClassDB::bind_method("_edit_filters", &AnimationNodeBlendTreeEditor::_edit_filters);
ClassDB::bind_method("_update_filters", &AnimationNodeBlendTreeEditor::_update_filters);

View File

@ -117,7 +117,7 @@ class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
void _open_in_editor(const String &p_which);
void _anim_selected(int p_index, Array p_options, const String &p_node);
void _delete_request(const String &p_which);
void _delete_nodes_request();
void _delete_nodes_request(const Array &p_nodes);
bool _update_filters(const Ref<AnimationNode> &anode);
void _edit_filters(const String &p_which);

View File

@ -1378,7 +1378,18 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
}
if (k->get_scancode() == KEY_DELETE && k->is_pressed()) {
emit_signal("delete_nodes_request");
Array nodes;
for (int i = 0; i < get_child_count(); i++) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
if (gn) {
if (gn->is_selected() && gn->is_close_button_visible()) {
nodes.push_back(gn->get_name());
}
}
}
emit_signal("delete_nodes_request", nodes);
accept_event();
}
}
@ -1754,7 +1765,7 @@ void GraphEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("node_unselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("delete_nodes_request"));
ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes")));
ADD_SIGNAL(MethodInfo("_begin_node_move"));
ADD_SIGNAL(MethodInfo("_end_node_move"));
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "ofs")));