animation_blend_space_2d_editor.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*************************************************************************/
  2. /* animation_blend_space_2d_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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_SPACE_2D_EDITOR_H
  31. #define ANIMATION_BLEND_SPACE_2D_EDITOR_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_space_2d.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. class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
  42. GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin);
  43. Ref<AnimationNodeBlendSpace2D> blend_space;
  44. PanelContainer *panel;
  45. ToolButton *tool_blend;
  46. ToolButton *tool_select;
  47. ToolButton *tool_create;
  48. ToolButton *tool_triangle;
  49. VSeparator *tool_erase_sep;
  50. ToolButton *tool_erase;
  51. ToolButton *snap;
  52. SpinBox *snap_x;
  53. SpinBox *snap_y;
  54. OptionButton *interpolation;
  55. ToolButton *auto_triangles;
  56. LineEdit *label_x;
  57. LineEdit *label_y;
  58. SpinBox *max_x_value;
  59. SpinBox *min_x_value;
  60. SpinBox *max_y_value;
  61. SpinBox *min_y_value;
  62. HBoxContainer *edit_hb;
  63. SpinBox *edit_x;
  64. SpinBox *edit_y;
  65. Button *open_editor;
  66. int selected_point;
  67. int selected_triangle;
  68. Control *blend_space_draw;
  69. PanelContainer *error_panel;
  70. Label *error_label;
  71. bool updating;
  72. UndoRedo *undo_redo;
  73. static AnimationNodeBlendSpace2DEditor *singleton;
  74. void _blend_space_gui_input(const Ref<InputEvent> &p_event);
  75. void _blend_space_draw();
  76. void _update_space();
  77. void _config_changed(double);
  78. void _labels_changed(String);
  79. void _snap_toggled();
  80. PopupMenu *menu;
  81. PopupMenu *animations_menu;
  82. Vector<String> animations_to_add;
  83. Vector2 add_point_pos;
  84. Vector<Vector2> points;
  85. bool dragging_selected_attempt;
  86. bool dragging_selected;
  87. Vector2 drag_from;
  88. Vector2 drag_ofs;
  89. Vector<int> making_triangle;
  90. void _add_menu_type(int p_index);
  91. void _add_animation_type(int p_index);
  92. void _tool_switch(int p_tool);
  93. void _update_edited_point_pos();
  94. void _update_tool_erase();
  95. void _erase_selected();
  96. void _edit_point_pos(double);
  97. void _open_editor();
  98. void _removed_from_graph();
  99. void _auto_triangles_toggled();
  100. StringName get_blend_position_path() const;
  101. EditorFileDialog *open_file;
  102. Ref<AnimationNode> file_loaded;
  103. void _file_opened(const String &p_file);
  104. enum {
  105. MENU_LOAD_FILE = 1000,
  106. MENU_PASTE = 1001,
  107. MENU_LOAD_FILE_CONFIRM = 1002
  108. };
  109. void _blend_space_changed();
  110. protected:
  111. void _notification(int p_what);
  112. static void _bind_methods();
  113. public:
  114. static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; }
  115. virtual bool can_edit(const Ref<AnimationNode> &p_node);
  116. virtual void edit(const Ref<AnimationNode> &p_node);
  117. AnimationNodeBlendSpace2DEditor();
  118. };
  119. #endif // ANIMATION_BLEND_SPACE_2D_EDITOR_H