animation_blend_tree_editor_plugin.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "editor/plugins/animation_tree_editor_plugin.h"
  35. #include "editor/property_editor.h"
  36. #include "scene/animation/animation_blend_tree.h"
  37. #include "scene/gui/button.h"
  38. #include "scene/gui/graph_edit.h"
  39. #include "scene/gui/popup.h"
  40. #include "scene/gui/tree.h"
  41. /**
  42. @author Juan Linietsky <reduzio@gmail.com>
  43. */
  44. class AnimationNodeBlendTreeEditor : public AnimationTreeNodeEditorPlugin {
  45. GDCLASS(AnimationNodeBlendTreeEditor, AnimationTreeNodeEditorPlugin);
  46. Ref<AnimationNodeBlendTree> blend_tree;
  47. GraphEdit *graph;
  48. MenuButton *add_node;
  49. PanelContainer *error_panel;
  50. Label *error_label;
  51. UndoRedo *undo_redo;
  52. AcceptDialog *filter_dialog;
  53. Tree *filters;
  54. CheckBox *filter_enabled;
  55. Map<StringName, ProgressBar *> animations;
  56. Vector<EditorProperty *> visible_properties;
  57. void _update_graph();
  58. struct AddOption {
  59. String name;
  60. String type;
  61. Ref<Script> script;
  62. AddOption(const String &p_name = String(), const String &p_type = String()) :
  63. name(p_name),
  64. type(p_type) {
  65. }
  66. };
  67. Vector<AddOption> add_options;
  68. void _add_node(int p_idx);
  69. void _update_options_menu();
  70. static AnimationNodeBlendTreeEditor *singleton;
  71. void _node_dragged(const Vector2 &p_from, const Vector2 &p_to, const StringName &p_which);
  72. void _node_renamed(const String &p_text, Ref<AnimationNode> p_node);
  73. void _node_renamed_focus_out(Node *le, Ref<AnimationNode> p_node);
  74. bool updating;
  75. void _connection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  76. void _disconnection_request(const String &p_from, int p_from_index, const String &p_to, int p_to_index);
  77. void _scroll_changed(const Vector2 &p_scroll);
  78. void _node_selected(Object *p_node);
  79. void _open_in_editor(const String &p_which);
  80. void _anim_selected(int p_index, Array p_options, const String &p_node);
  81. void _delete_request(const String &p_which);
  82. bool _update_filters(const Ref<AnimationNode> &anode);
  83. void _edit_filters(const String &p_which);
  84. void _filter_edited();
  85. void _filter_toggled();
  86. Ref<AnimationNode> _filter_edit;
  87. void _property_changed(const StringName &p_property, const Variant &p_value);
  88. void _removed_from_graph();
  89. EditorFileDialog *open_file;
  90. Ref<AnimationNode> file_loaded;
  91. void _file_opened(const String &p_file);
  92. enum {
  93. MENU_LOAD_FILE = 1000,
  94. MENU_PASTE = 1001,
  95. MENU_LOAD_FILE_CONFIRM = 1002
  96. };
  97. protected:
  98. void _notification(int p_what);
  99. static void _bind_methods();
  100. public:
  101. static AnimationNodeBlendTreeEditor *get_singleton() { return singleton; }
  102. void add_custom_type(const String &p_name, const Ref<Script> &p_script);
  103. void remove_custom_type(const Ref<Script> &p_script);
  104. virtual Size2 get_minimum_size() const;
  105. virtual bool can_edit(const Ref<AnimationNode> &p_node);
  106. virtual void edit(const Ref<AnimationNode> &p_node);
  107. AnimationNodeBlendTreeEditor();
  108. };
  109. #endif // ANIMATION_BLEND_TREE_EDITOR_PLUGIN_H