animation_blend_space_2d_editor.h 4.9 KB

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