Path: blob/master/editor/animation/animation_blend_tree_editor_plugin.h
9903 views
/**************************************************************************/1/* animation_blend_tree_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/script_language.h"33#include "editor/animation/animation_tree_editor_plugin.h"34#include "editor/inspector/editor_inspector.h"35#include "scene/animation/animation_blend_tree.h"36#include "scene/gui/button.h"37#include "scene/gui/dialogs.h"38#include "scene/gui/graph_edit.h"39#include "scene/gui/panel_container.h"40#include "scene/gui/tree.h"4142class AcceptDialog;43class CheckBox;44class ProgressBar;45class EditorFileDialog;46class EditorProperty;47class MenuButton;48class PanelContainer;49class EditorInspectorPluginAnimationNodeAnimation;5051class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {52GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);5354Ref<AnimationNodeBlendTree> blend_tree;5556bool read_only = false;5758GraphEdit *graph = nullptr;59MenuButton *add_node = nullptr;60Vector2 position_from_popup_menu;61bool use_position_from_popup_menu;6263PanelContainer *error_panel = nullptr;64Label *error_label = nullptr;6566AcceptDialog *filter_dialog = nullptr;67Tree *filters = nullptr;68CheckBox *filter_enabled = nullptr;69Button *filter_fill_selection = nullptr;70Button *filter_invert_selection = nullptr;71Button *filter_clear_selection = nullptr;7273HashMap<StringName, ProgressBar *> animations;74Vector<EditorProperty *> visible_properties;7576String to_node = "";77int to_slot = -1;78String from_node = "";7980struct AddOption {81String name;82String type;83Ref<Script> script;84int input_port_count;85AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) :86name(p_name),87type(p_type),88input_port_count(p_input_port_count) {89}90};9192Vector<AddOption> add_options;9394void _add_node(int p_idx);95void _update_options_menu(bool p_has_input_ports = false);9697static AnimationNodeBlendTreeEditor *singleton;9899void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);100void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);101void _node_renamed_focus_out(Ref<AnimationNode> p_node);102void _node_rename_lineedit_changed(const String &p_text);103void _node_changed(const StringName &p_node_name);104105String current_node_rename_text;106bool updating;107108void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);109void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);110111void _scroll_changed(const Vector2 &p_scroll);112void _node_selected(Object *p_node);113void _open_in_editor(const String &p_which);114void _anim_selected(int p_index, const Array &p_options, const String &p_node);115void _delete_node_request(const String &p_which);116void _delete_nodes_request(const TypedArray<StringName> &p_nodes);117118bool _update_filters(const Ref<AnimationNode> &anode);119void _inspect_filters(const String &p_which);120void _filter_edited();121void _filter_toggled();122void _filter_fill_selection();123void _filter_invert_selection();124void _filter_clear_selection();125void _filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered);126void _filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);127void _filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);128Ref<AnimationNode> _filter_edit;129130void _popup(bool p_has_input_ports, const Vector2 &p_node_position);131void _popup_request(const Vector2 &p_position);132void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);133void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);134void _popup_hide();135136void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);137138void _update_editor_settings();139140EditorFileDialog *open_file = nullptr;141Ref<AnimationNode> file_loaded;142void _file_opened(const String &p_file);143144enum {145MENU_LOAD_FILE = 1000,146MENU_PASTE = 1001,147MENU_LOAD_FILE_CONFIRM = 1002148};149150Ref<EditorInspectorPluginAnimationNodeAnimation> animation_node_inspector_plugin;151152protected:153void _notification(int p_what);154static void _bind_methods();155156public:157static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }158159void add_custom_type(const String &p_name, const Ref<Script> &p_script);160void remove_custom_type(const Ref<Script> &p_script);161162virtual Size2 get_minimum_size() const override;163164virtual bool can_edit(const Ref<AnimationNode> &p_node) override;165virtual void edit(const Ref<AnimationNode> &p_node) override;166167void update_graph();168169AnimationNodeBlendTreeEditor();170};171172// EditorPluginAnimationNodeAnimation173174class EditorInspectorPluginAnimationNodeAnimation : public EditorInspectorPlugin {175GDCLASS(EditorInspectorPluginAnimationNodeAnimation, EditorInspectorPlugin);176177public:178virtual bool can_handle(Object *p_object) override;179virtual bool parse_property(Object *p_object, const Variant::Type p_type, const String &p_path, const PropertyHint p_hint, const String &p_hint_text, const BitField<PropertyUsageFlags> p_usage, const bool p_wide) override;180};181182class AnimationNodeAnimationEditorDialog : public ConfirmationDialog {183GDCLASS(AnimationNodeAnimationEditorDialog, ConfirmationDialog);184185friend class AnimationNodeAnimationEditor;186187OptionButton *select_start = nullptr;188OptionButton *select_end = nullptr;189190public:191AnimationNodeAnimationEditorDialog();192};193194class AnimationNodeAnimationEditor : public VBoxContainer {195GDCLASS(AnimationNodeAnimationEditor, VBoxContainer);196197Ref<AnimationNodeAnimation> animation_node_animation;198Button *button = nullptr;199AnimationNodeAnimationEditorDialog *dialog = nullptr;200void _open_set_custom_timeline_from_marker_dialog();201void _validate_markers(int p_id);202void _confirm_set_custom_timeline_from_marker_dialog();203204public:205AnimationNodeAnimationEditor(Ref<AnimationNodeAnimation> p_animation_node_animation);206207protected:208void _notification(int p_what);209};210211212