animation_blend_tree_editor_plugin.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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 "editor/editor_plugin.h"
  33. #include "editor/plugins/animation_tree_editor_plugin.h"
  34. #include "scene/animation/animation_blend_tree.h"
  35. #include "scene/gui/button.h"
  36. #include "scene/gui/graph_edit.h"
  37. #include "scene/gui/popup.h"
  38. #include "scene/gui/tree.h"
  39. class ProgressBar;
  40. class EditorFileDialog;
  41. class EditorUndoRedoManager;
  42. class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
  43. GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);
  44. Ref<AnimationNodeBlendTree> blend_tree;
  45. bool read_only = false;
  46. GraphEdit *graph = nullptr;
  47. MenuButton *add_node = nullptr;
  48. Vector2 position_from_popup_menu;
  49. bool use_position_from_popup_menu;
  50. PanelContainer *error_panel = nullptr;
  51. Label *error_label = nullptr;
  52. Ref<EditorUndoRedoManager> undo_redo;
  53. AcceptDialog *filter_dialog = nullptr;
  54. Tree *filters = nullptr;
  55. CheckBox *filter_enabled = nullptr;
  56. HashMap<StringName, ProgressBar *> animations;
  57. Vector<EditorProperty *> visible_properties;
  58. String to_node = "";
  59. int to_slot = -1;
  60. String from_node = "";
  61. void _update_graph();
  62. struct AddOption {
  63. String name;
  64. String type;
  65. Ref<Script> script;
  66. int input_port_count;
  67. AddOption(const String &p_name = String(), const String &p_type = String(), int p_input_port_count = 0) :
  68. name(p_name),
  69. type(p_type),
  70. input_port_count(p_input_port_count) {
  71. }
  72. };
  73. Vector<AddOption> add_options;
  74. void _add_node(int p_idx);
  75. void _update_options_menu(bool p_has_input_ports = false);
  76. static AnimationNodeBlendTreeEditor *singleton;
  77. void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
  78. void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
  79. void _node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node);
  80. bool updating;
  81. void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  82. void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  83. void _scroll_changed(const Vector2 &p_scroll);
  84. void _node_selected(Object *p_node);
  85. void _open_in_editor(const String &p_which);
  86. void _anim_selected(int p_index, Array p_options, const String &p_node);
  87. void _delete_request(const String &p_which);
  88. void _delete_nodes_request(const TypedArray<StringName> &p_nodes);
  89. bool _update_filters(const Ref<AnimationNode> &anode);
  90. void _inspect_filters(const String &p_which);
  91. void _filter_edited();
  92. void _filter_toggled();
  93. Ref<AnimationNode> _filter_edit;
  94. void _popup(bool p_has_input_ports, const Vector2 &p_popup_position, const Vector2 &p_node_position);
  95. void _popup_request(const Vector2 &p_position);
  96. void _connection_to_empty(const String &p_from, int p_from_slot, const Vector2 &p_release_position);
  97. void _connection_from_empty(const String &p_to, int p_to_slot, const Vector2 &p_release_position);
  98. void _property_changed(const StringName &p_property, const Variant &p_value, const String &p_field, bool p_changing);
  99. void _removed_from_graph();
  100. void _update_editor_settings();
  101. void _update_theme();
  102. EditorFileDialog *open_file = nullptr;
  103. Ref<AnimationNode> file_loaded;
  104. void _file_opened(const String &p_file);
  105. enum {
  106. MENU_LOAD_FILE = 1000,
  107. MENU_PASTE = 1001,
  108. MENU_LOAD_FILE_CONFIRM = 1002
  109. };
  110. protected:
  111. void _notification(int p_what);
  112. static void _bind_methods();
  113. public:
  114. static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }
  115. void add_custom_type(const String &p_name, const Ref<Script> &p_script);
  116. void remove_custom_type(const Ref<Script> &p_script);
  117. virtual Size2 get_minimum_size() const override;
  118. virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
  119. virtual void edit(const Ref<AnimationNode> &p_node) override;
  120. AnimationNodeBlendTreeEditor();
  121. };
  122. #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H