animation_editor.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. /*************************************************************************/
  2. /* animation_editor.h */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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_EDITOR_H
  31. #define ANIMATION_EDITOR_H
  32. #include "scene/gui/control.h"
  33. #include "scene/gui/file_dialog.h"
  34. #include "scene/gui/menu_button.h"
  35. #include "scene/gui/scroll_bar.h"
  36. #include "scene/gui/slider.h"
  37. #include "scene/gui/spin_box.h"
  38. #include "scene/gui/tab_container.h"
  39. #include "scene/gui/texture_frame.h"
  40. #include "scene/gui/tool_button.h"
  41. #include "editor_data.h"
  42. #include "property_editor.h"
  43. #include "scene/animation/animation_cache.h"
  44. #include "scene/resources/animation.h"
  45. #include "scene_tree_editor.h"
  46. class AnimationKeyEdit;
  47. class AnimationCurveEdit;
  48. class AnimationKeyEditor : public VBoxContainer {
  49. OBJ_TYPE(AnimationKeyEditor, VBoxContainer);
  50. /*
  51. enum {
  52. MENU_NEW_ANIMATION,
  53. MENU_OPEN_ANIMATION,
  54. MENU_EDIT_ANIMATION,
  55. MENU_CLOSE_ANIMATION,
  56. MENU_KEYING_ACTIVE,
  57. MENU_SET_ROOT_NODE,
  58. MENU_SYNC_TO_PLAYER,
  59. MENU_ANIM_BASE=100,
  60. };
  61. */
  62. enum {
  63. ADD_TRACK_MENU_ADD_VALUE_TRACK,
  64. ADD_TRACK_MENU_ADD_TRANSFORM_TRACK,
  65. ADD_TRACK_MENU_ADD_CALL_TRACK,
  66. TRACK_MENU_SCALE,
  67. TRACK_MENU_SCALE_PIVOT,
  68. TRACK_MENU_MOVE_UP,
  69. TRACK_MENU_MOVE_DOWN,
  70. TRACK_MENU_REMOVE,
  71. TRACK_MENU_DUPLICATE,
  72. TRACK_MENU_DUPLICATE_TRANSPOSE,
  73. TRACK_MENU_SET_ALL_TRANS_LINEAR,
  74. TRACK_MENU_SET_ALL_TRANS_CONSTANT,
  75. TRACK_MENU_SET_ALL_TRANS_OUT,
  76. TRACK_MENU_SET_ALL_TRANS_IN,
  77. TRACK_MENU_SET_ALL_TRANS_INOUT,
  78. TRACK_MENU_SET_ALL_TRANS_OUTIN,
  79. TRACK_MENU_NEXT_STEP,
  80. TRACK_MENU_PREV_STEP,
  81. TRACK_MENU_OPTIMIZE,
  82. TRACK_MENU_CLEAN_UP,
  83. TRACK_MENU_CLEAN_UP_CONFIRM,
  84. CURVE_SET_LINEAR,
  85. CURVE_SET_IN,
  86. CURVE_SET_OUT,
  87. CURVE_SET_INOUT,
  88. CURVE_SET_OUTIN,
  89. CURVE_SET_CONSTANT
  90. };
  91. enum {
  92. RIGHT_MENU_DUPLICATE,
  93. RIGHT_MENU_DUPLICATE_TRANSPOSE,
  94. RIGHT_MENU_REMOVE
  95. };
  96. struct MouseOver {
  97. enum Over {
  98. OVER_NONE,
  99. OVER_NAME,
  100. OVER_KEY,
  101. OVER_VALUE,
  102. OVER_INTERP,
  103. OVER_UP,
  104. OVER_DOWN,
  105. OVER_REMOVE,
  106. OVER_ADD_KEY,
  107. };
  108. Over over;
  109. int track;
  110. int over_key;
  111. } mouse_over;
  112. struct SelectedKey {
  113. int track;
  114. int key;
  115. bool operator<(const SelectedKey &p_key) const { return track == p_key.track ? key < p_key.key : track < p_key.track; };
  116. };
  117. struct KeyInfo {
  118. float pos;
  119. };
  120. Map<SelectedKey, KeyInfo> selection;
  121. struct ClickOver {
  122. enum Click {
  123. CLICK_NONE,
  124. CLICK_RESIZE_NAMES,
  125. CLICK_DRAG_TIMELINE,
  126. CLICK_MOVE_KEYS,
  127. CLICK_SELECT_KEYS
  128. };
  129. SelectedKey selk;
  130. bool shift;
  131. Click click;
  132. Point2 at;
  133. Point2 to;
  134. } click;
  135. float timeline_pos;
  136. float name_column_ratio;
  137. int track_name_editing;
  138. int interp_editing;
  139. int cont_editing;
  140. int selected_track;
  141. int last_menu_track_opt;
  142. LineEdit *track_name;
  143. PopupMenu *track_menu;
  144. PopupMenu *type_menu;
  145. Control *ec;
  146. TextureFrame *zoomicon;
  147. HSlider *zoom;
  148. //MenuButton *menu;
  149. SpinBox *length;
  150. Button *loop;
  151. bool keying;
  152. ToolButton *edit_button;
  153. ToolButton *move_up_button;
  154. ToolButton *move_down_button;
  155. ToolButton *remove_button;
  156. ToolButton *curve_linear;
  157. ToolButton *curve_in;
  158. ToolButton *curve_out;
  159. ToolButton *curve_inout;
  160. ToolButton *curve_outin;
  161. ToolButton *curve_constant;
  162. ConfirmationDialog *optimize_dialog;
  163. SpinBox *optimize_linear_error;
  164. SpinBox *optimize_angular_error;
  165. SpinBox *optimize_max_angle;
  166. ConfirmationDialog *cleanup_dialog;
  167. CheckButton *cleanup_keys;
  168. CheckButton *cleanup_tracks;
  169. CheckButton *cleanup_all;
  170. SpinBox *step;
  171. MenuButton *menu_add_track;
  172. MenuButton *menu_track;
  173. HScrollBar *h_scroll;
  174. VScrollBar *v_scroll;
  175. Control *track_editor;
  176. Control *track_pos;
  177. TabContainer *key_editor_tab;
  178. ConfirmationDialog *scale_dialog;
  179. SpinBox *scale;
  180. PropertyEditor *key_editor;
  181. SceneTreeDialog *call_select;
  182. Ref<Animation> animation;
  183. void _update_paths();
  184. int last_idx;
  185. Node *root;
  186. UndoRedo *undo_redo;
  187. EditorHistory *history;
  188. ConfirmationDialog *insert_confirm;
  189. AnimationKeyEdit *key_edit;
  190. AnimationCurveEdit *curve_edit;
  191. bool inserting;
  192. bool updating;
  193. bool te_drawing;
  194. void _animation_len_changed(float p_len);
  195. void _animation_loop_changed();
  196. void _step_changed(float p_len);
  197. struct InsertData {
  198. Animation::TrackType type;
  199. NodePath path;
  200. int track_idx;
  201. Variant value;
  202. String query;
  203. bool advance;
  204. }; /* insert_data;*/
  205. bool insert_query;
  206. List<InsertData> insert_data;
  207. uint64_t insert_frame;
  208. int cvi_track;
  209. float cvi_pos;
  210. int right_data_size_cache;
  211. EditorSelection *editor_selection;
  212. Label *select_anim_warning;
  213. float _get_zoom_scale() const;
  214. void _track_editor_draw();
  215. void _track_editor_input_event(const InputEvent &p_input);
  216. void _track_pos_draw();
  217. void _track_name_changed(const String &p_name);
  218. void _track_menu_selected(int p_idx);
  219. void _confirm_insert_list();
  220. int _confirm_insert(InsertData p_id, int p_at_track = -1);
  221. void _query_insert(const InsertData &p_id);
  222. void _update_menu();
  223. bool insert_queue;
  224. void _insert_delay();
  225. void _scale();
  226. void _clear_selection();
  227. //void _browse_path();
  228. StringName alc;
  229. void _animation_changed();
  230. void _animation_optimize();
  231. void _cleanup_animation(Ref<Animation> p_animation);
  232. void _scroll_changed(double);
  233. void _menu_add_track(int p_type);
  234. void _menu_track(int p_type);
  235. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  236. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  237. void _curve_transition_changed(float p_what);
  238. PropertyInfo _find_hint_for_track(int p_idx, NodePath &r_base_path);
  239. void _create_value_item(int p_type);
  240. void _pane_drag(const Point2 &p_delta);
  241. bool _edit_if_single_selection();
  242. void _toggle_edit_curves();
  243. void _animation_len_update();
  244. void _add_call_track(const NodePath &p_base);
  245. void _anim_duplicate_keys(bool transpose = false);
  246. void _anim_delete_keys();
  247. void _root_removed();
  248. protected:
  249. void _notification(int p_what);
  250. static void _bind_methods();
  251. public:
  252. void set_animation(const Ref<Animation> &p_anim);
  253. Ref<Animation> get_current_animation() const;
  254. void set_root(Node *p_root);
  255. Node *get_root() const;
  256. void update_keying();
  257. bool has_keying() const;
  258. void cleanup();
  259. void set_anim_pos(float p_pos);
  260. void insert_node_value_key(Node *p_node, const String &p_property, const Variant &p_value, bool p_only_if_exists = false);
  261. void insert_value_key(const String &p_property, const Variant &p_value, bool p_advance);
  262. void insert_transform_key(Spatial *p_node, const String &p_sub, const Transform &p_xform);
  263. void show_select_node_warning(bool p_show) { select_anim_warning->set_hidden(!p_show); }
  264. AnimationKeyEditor();
  265. ~AnimationKeyEditor();
  266. };
  267. #endif // ANIMATION_EDITOR_H