animation_blend_space_2d_editor.h 5.1 KB

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