animation_blend_tree_editor_plugin.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /**************************************************************************/
  2. /* animation_blend_tree_editor_plugin.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
  31. #define ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H
  32. #include "core/object/script_language.h"
  33. #include "editor/editor_inspector.h"
  34. #include "editor/plugins/animation_tree_editor_plugin.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"
  41. class AcceptDialog;
  42. class CheckBox;
  43. class ProgressBar;
  44. class EditorFileDialog;
  45. class EditorProperty;
  46. class MenuButton;
  47. class PanelContainer;
  48. class EditorInspectorPluginAnimationNodeAnimation;
  49. class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
  50. GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);
  51. Ref<AnimationNodeBlendTree> blend_tree;
  52. bool read_only = false;
  53. GraphEdit *graph = nullptr;
  54. MenuButton *add_node = nullptr;
  55. Vector2 position_from_popup_menu;
  56. bool use_position_from_popup_menu;
  57. PanelContainer *error_panel = nullptr;
  58. Label *error_label = nullptr;
  59. AcceptDialog *filter_dialog = nullptr;
  60. Tree *filters = nullptr;
  61. CheckBox *filter_enabled = nullptr;
  62. Button *filter_fill_selection = nullptr;
  63. Button *filter_invert_selection = nullptr;
  64. Button *filter_clear_selection = nullptr;
  65. HashMap<StringName, ProgressBar *> animations;
  66. Vector<EditorProperty *> visible_properties;
  67. String to_node = "";
  68. int to_slot = -1;
  69. String from_node = "";
  70. struct AddOption {
  71. String name;
  72. String type;
  73. Ref<Script> script;
  74. int input_port_count;
  75. AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) :
  76. name(p_name),
  77. type(p_type),
  78. input_port_count(p_input_port_count) {
  79. }
  80. };
  81. Vector<AddOption> add_options;
  82. void _add_node(int p_idx);
  83. void _update_options_menu(bool p_has_input_ports = false);
  84. static AnimationNodeBlendTreeEditor *singleton;
  85. void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
  86. void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
  87. void _node_renamed_focus_out(Ref<AnimationNode> p_node);
  88. void _node_rename_lineedit_changed(const String &p_text);
  89. void _node_changed(const StringName &p_node_name);
  90. String current_node_rename_text;
  91. bool updating;
  92. void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  93. void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  94. void _scroll_changed(const Vector2 &p_scroll);
  95. void _node_selected(Object *p_node);
  96. void _open_in_editor(const String &p_which);
  97. void _anim_selected(int p_index, const Array &p_options, const String &p_node);
  98. void _delete_node_request(const String &p_which);
  99. void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
  100. bool _update_filters(const Ref<AnimationNode> &anode);
  101. void _inspect_filters(const String &p_which);
  102. void _filter_edited();
  103. void _filter_toggled();
  104. void _filter_fill_selection();
  105. void _filter_invert_selection();
  106. void _filter_clear_selection();
  107. void _filter_fill_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item, bool p_parent_filtered);
  108. void _filter_invert_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
  109. void _filter_clear_selection_recursive(EditorUndoRedoManager *p_undo_redo, TreeItem *p_item);
  110. Ref<AnimationNode> _filter_edit;
  111. void _popup(bool p_has_input_ports, const Vector2 &p_node_position);
  112. void _popup_request(const Vector2 &p_position);
  113. void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
  114. void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
  115. void _popup_hide();
  116. void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
  117. void _update_editor_settings();
  118. EditorFileDialog *open_file = nullptr;
  119. Ref<AnimationNode> file_loaded;
  120. void _file_opened(const String &p_file);
  121. enum {
  122. MENU_LOAD_FILE = 1000,
  123. MENU_PASTE = 1001,
  124. MENU_LOAD_FILE_CONFIRM = 1002
  125. };
  126. Ref<EditorInspectorPluginAnimationNodeAnimation> animation_node_inspector_plugin;
  127. protected:
  128. void _notification(int p_what);
  129. static void _bind_methods();
  130. public:
  131. static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }
  132. void add_custom_type(const String &p_name, const Ref<Script> &p_script);
  133. void remove_custom_type(const Ref<Script> &p_script);
  134. virtual Size2 get_minimum_size() const override;
  135. virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
  136. virtual void edit(const Ref<AnimationNode> &p_node) override;
  137. void update_graph();
  138. AnimationNodeBlendTreeEditor();
  139. ~AnimationNodeBlendTreeEditor();
  140. };
  141. // EditorPluginAnimationNodeAnimation
  142. class EditorInspectorPluginAnimationNodeAnimation : public EditorInspectorPlugin {
  143. GDCLASS(EditorInspectorPluginAnimationNodeAnimation, EditorInspectorPlugin);
  144. public:
  145. virtual bool can_handle(Object *p_object) override;
  146. virtual 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;
  147. };
  148. class AnimationNodeAnimationEditorDialog : public ConfirmationDialog {
  149. GDCLASS(AnimationNodeAnimationEditorDialog, ConfirmationDialog);
  150. friend class AnimationNodeAnimationEditor;
  151. OptionButton *select_start = nullptr;
  152. OptionButton *select_end = nullptr;
  153. public:
  154. AnimationNodeAnimationEditorDialog();
  155. ~AnimationNodeAnimationEditorDialog();
  156. };
  157. class AnimationNodeAnimationEditor : public VBoxContainer {
  158. GDCLASS(AnimationNodeAnimationEditor, VBoxContainer);
  159. Ref<AnimationNodeAnimation> animation_node_animation;
  160. Button *button = nullptr;
  161. AnimationNodeAnimationEditorDialog *dialog = nullptr;
  162. void _open_set_custom_timeline_from_marker_dialog();
  163. void _validate_markers(int p_id);
  164. void _confirm_set_custom_timeline_from_marker_dialog();
  165. public:
  166. AnimationNodeAnimationEditor(Ref<AnimationNodeAnimation> p_animation_node_animation);
  167. ~AnimationNodeAnimationEditor();
  168. protected:
  169. void _notification(int p_what);
  170. };
  171. #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H