animation_track_editor.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /**************************************************************************/
  2. /* animation_track_editor.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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_TRACK_EDITOR_H
  31. #define ANIMATION_TRACK_EDITOR_H
  32. #include "editor/editor_data.h"
  33. #include "editor/editor_properties.h"
  34. #include "editor/property_selector.h"
  35. #include "scene/3d/node_3d.h"
  36. #include "scene/gui/control.h"
  37. #include "scene/gui/menu_button.h"
  38. #include "scene/gui/scroll_bar.h"
  39. #include "scene/gui/tree.h"
  40. #include "scene/resources/animation.h"
  41. class AnimationTrackEditor;
  42. class AnimationTrackEdit;
  43. class CheckBox;
  44. class EditorSpinSlider;
  45. class HSlider;
  46. class OptionButton;
  47. class PanelContainer;
  48. class SceneTreeDialog;
  49. class SpinBox;
  50. class TextureRect;
  51. class ViewPanner;
  52. class AnimationTrackKeyEdit : public Object {
  53. GDCLASS(AnimationTrackKeyEdit, Object);
  54. public:
  55. bool setting = false;
  56. bool animation_read_only = false;
  57. Ref<Animation> animation;
  58. int track = -1;
  59. float key_ofs = 0;
  60. Node *root_path = nullptr;
  61. PropertyInfo hint;
  62. NodePath base;
  63. bool use_fps = false;
  64. bool _hide_script_from_inspector() { return true; }
  65. bool _hide_metadata_from_inspector() { return true; }
  66. bool _dont_undo_redo() { return true; }
  67. bool _is_read_only() { return animation_read_only; }
  68. void notify_change();
  69. Node *get_root_path();
  70. void set_use_fps(bool p_enable);
  71. protected:
  72. static void _bind_methods();
  73. void _fix_node_path(Variant &value);
  74. void _update_obj(const Ref<Animation> &p_anim);
  75. void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to);
  76. bool _set(const StringName &p_name, const Variant &p_value);
  77. bool _get(const StringName &p_name, Variant &r_ret) const;
  78. void _get_property_list(List<PropertyInfo> *p_list) const;
  79. };
  80. class AnimationMultiTrackKeyEdit : public Object {
  81. GDCLASS(AnimationMultiTrackKeyEdit, Object);
  82. public:
  83. bool setting = false;
  84. bool animation_read_only = false;
  85. Ref<Animation> animation;
  86. RBMap<int, List<float>> key_ofs_map;
  87. RBMap<int, NodePath> base_map;
  88. PropertyInfo hint;
  89. Node *root_path = nullptr;
  90. bool use_fps = false;
  91. bool _hide_script_from_inspector() { return true; }
  92. bool _hide_metadata_from_inspector() { return true; }
  93. bool _dont_undo_redo() { return true; }
  94. bool _is_read_only() { return animation_read_only; }
  95. void notify_change();
  96. Node *get_root_path();
  97. void set_use_fps(bool p_enable);
  98. protected:
  99. static void _bind_methods();
  100. void _fix_node_path(Variant &value, NodePath &base);
  101. void _update_obj(const Ref<Animation> &p_anim);
  102. void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to);
  103. bool _set(const StringName &p_name, const Variant &p_value);
  104. bool _get(const StringName &p_name, Variant &r_ret) const;
  105. void _get_property_list(List<PropertyInfo> *p_list) const;
  106. };
  107. class AnimationTimelineEdit : public Range {
  108. GDCLASS(AnimationTimelineEdit, Range);
  109. Ref<Animation> animation;
  110. bool read_only = false;
  111. AnimationTrackEdit *track_edit = nullptr;
  112. int name_limit = 0;
  113. Range *zoom = nullptr;
  114. Range *h_scroll = nullptr;
  115. float play_position_pos = 0.0f;
  116. HBoxContainer *len_hb = nullptr;
  117. EditorSpinSlider *length = nullptr;
  118. Button *loop = nullptr;
  119. TextureRect *time_icon = nullptr;
  120. MenuButton *add_track = nullptr;
  121. Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
  122. HScrollBar *hscroll = nullptr;
  123. void _zoom_changed(double);
  124. void _anim_length_changed(double p_new_len);
  125. void _anim_loop_pressed();
  126. void _play_position_draw();
  127. Rect2 hsize_rect;
  128. bool editing = false;
  129. bool use_fps = false;
  130. Ref<ViewPanner> panner;
  131. void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
  132. void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
  133. bool dragging_timeline = false;
  134. bool dragging_hsize = false;
  135. float dragging_hsize_from = 0.0f;
  136. float dragging_hsize_at = 0.0f;
  137. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  138. void _track_added(int p_track);
  139. protected:
  140. static void _bind_methods();
  141. void _notification(int p_what);
  142. public:
  143. int get_name_limit() const;
  144. int get_buttons_width() const;
  145. float get_zoom_scale() const;
  146. virtual Size2 get_minimum_size() const override;
  147. void set_animation(const Ref<Animation> &p_animation, bool p_read_only);
  148. void set_track_edit(AnimationTrackEdit *p_track_edit);
  149. void set_zoom(Range *p_zoom);
  150. Range *get_zoom() const { return zoom; }
  151. void set_play_position(float p_pos);
  152. float get_play_position() const;
  153. void update_play_position();
  154. void update_values();
  155. void set_use_fps(bool p_use_fps);
  156. bool is_using_fps() const;
  157. void set_hscroll(HScrollBar *p_hscroll);
  158. virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
  159. AnimationTimelineEdit();
  160. };
  161. class AnimationTrackEdit : public Control {
  162. GDCLASS(AnimationTrackEdit, Control);
  163. friend class AnimationTimelineEdit;
  164. enum {
  165. MENU_CALL_MODE_CONTINUOUS,
  166. MENU_CALL_MODE_DISCRETE,
  167. MENU_CALL_MODE_CAPTURE,
  168. MENU_INTERPOLATION_NEAREST,
  169. MENU_INTERPOLATION_LINEAR,
  170. MENU_INTERPOLATION_CUBIC,
  171. MENU_INTERPOLATION_LINEAR_ANGLE,
  172. MENU_INTERPOLATION_CUBIC_ANGLE,
  173. MENU_LOOP_WRAP,
  174. MENU_LOOP_CLAMP,
  175. MENU_KEY_INSERT,
  176. MENU_KEY_DUPLICATE,
  177. MENU_KEY_ADD_RESET,
  178. MENU_KEY_DELETE,
  179. MENU_USE_BLEND_ENABLED,
  180. MENU_USE_BLEND_DISABLED,
  181. };
  182. AnimationTimelineEdit *timeline = nullptr;
  183. Popup *path_popup = nullptr;
  184. LineEdit *path = nullptr;
  185. Node *root = nullptr;
  186. Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
  187. float play_position_pos = 0.0f;
  188. NodePath node_path;
  189. Ref<Animation> animation;
  190. bool read_only = false;
  191. int track = 0;
  192. Rect2 check_rect;
  193. Rect2 path_rect;
  194. Rect2 update_mode_rect;
  195. Rect2 interp_mode_rect;
  196. Rect2 loop_wrap_rect;
  197. Rect2 remove_rect;
  198. Ref<Texture2D> type_icon;
  199. Ref<Texture2D> selected_icon;
  200. PopupMenu *menu = nullptr;
  201. bool hovered = false;
  202. bool clicking_on_name = false;
  203. int hovering_key_idx = -1;
  204. void _zoom_changed();
  205. Ref<Texture2D> icon_cache;
  206. String path_cache;
  207. void _menu_selected(int p_index);
  208. void _path_submitted(const String &p_text);
  209. void _play_position_draw();
  210. bool _is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const;
  211. Ref<Texture2D> _get_key_type_icon() const;
  212. mutable int dropping_at = 0;
  213. float insert_at_pos = 0.0f;
  214. bool moving_selection_attempt = false;
  215. int select_single_attempt = -1;
  216. bool moving_selection = false;
  217. float moving_selection_from_ofs = 0.0f;
  218. bool in_group = false;
  219. AnimationTrackEditor *editor = nullptr;
  220. protected:
  221. static void _bind_methods();
  222. void _notification(int p_what);
  223. virtual void gui_input(const Ref<InputEvent> &p_event) override;
  224. public:
  225. virtual Variant get_drag_data(const Point2 &p_point) override;
  226. virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
  227. virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
  228. virtual String get_tooltip(const Point2 &p_pos) const override;
  229. virtual int get_key_height() const;
  230. virtual Rect2 get_key_rect(int p_index, float p_pixels_sec);
  231. virtual bool is_key_selectable_by_distance() const;
  232. virtual void draw_key_link(int p_index, float p_pixels_sec, int p_x, int p_next_x, int p_clip_left, int p_clip_right);
  233. virtual void draw_key(int p_index, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right);
  234. virtual void draw_bg(int p_clip_left, int p_clip_right);
  235. virtual void draw_fg(int p_clip_left, int p_clip_right);
  236. //helper
  237. void draw_texture_region_clipped(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_region);
  238. void draw_rect_clipped(const Rect2 &p_rect, const Color &p_color, bool p_filled = true);
  239. int get_track() const;
  240. Ref<Animation> get_animation() const;
  241. AnimationTimelineEdit *get_timeline() const { return timeline; }
  242. AnimationTrackEditor *get_editor() const { return editor; }
  243. NodePath get_path() const;
  244. void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
  245. virtual Size2 get_minimum_size() const override;
  246. void set_timeline(AnimationTimelineEdit *p_timeline);
  247. void set_editor(AnimationTrackEditor *p_editor);
  248. void set_root(Node *p_root);
  249. void set_play_position(float p_pos);
  250. void update_play_position();
  251. void cancel_drop();
  252. void set_in_group(bool p_enable);
  253. void append_to_selection(const Rect2 &p_box, bool p_deselection);
  254. AnimationTrackEdit();
  255. };
  256. class AnimationTrackEditPlugin : public RefCounted {
  257. GDCLASS(AnimationTrackEditPlugin, RefCounted);
  258. public:
  259. virtual AnimationTrackEdit *create_value_track_edit(Object *p_object, Variant::Type p_type, const String &p_property, PropertyHint p_hint, const String &p_hint_string, int p_usage);
  260. virtual AnimationTrackEdit *create_audio_track_edit();
  261. virtual AnimationTrackEdit *create_animation_track_edit(Object *p_object);
  262. };
  263. class AnimationTrackKeyEdit;
  264. class AnimationMultiTrackKeyEdit;
  265. class AnimationBezierTrackEdit;
  266. class AnimationTrackEditGroup : public Control {
  267. GDCLASS(AnimationTrackEditGroup, Control);
  268. Ref<Texture2D> icon;
  269. String node_name;
  270. NodePath node;
  271. Node *root = nullptr;
  272. AnimationTimelineEdit *timeline = nullptr;
  273. void _zoom_changed();
  274. protected:
  275. void _notification(int p_what);
  276. public:
  277. void set_type_and_name(const Ref<Texture2D> &p_type, const String &p_name, const NodePath &p_node);
  278. virtual Size2 get_minimum_size() const override;
  279. void set_timeline(AnimationTimelineEdit *p_timeline);
  280. void set_root(Node *p_root);
  281. AnimationTrackEditGroup();
  282. };
  283. class AnimationTrackEditor : public VBoxContainer {
  284. GDCLASS(AnimationTrackEditor, VBoxContainer);
  285. friend class AnimationTimelineEdit;
  286. Ref<Animation> animation;
  287. bool read_only = false;
  288. Node *root = nullptr;
  289. MenuButton *edit = nullptr;
  290. PanelContainer *main_panel = nullptr;
  291. HScrollBar *hscroll = nullptr;
  292. ScrollContainer *scroll = nullptr;
  293. VBoxContainer *track_vbox = nullptr;
  294. AnimationBezierTrackEdit *bezier_edit = nullptr;
  295. Label *info_message = nullptr;
  296. AnimationTimelineEdit *timeline = nullptr;
  297. HSlider *zoom = nullptr;
  298. EditorSpinSlider *step = nullptr;
  299. TextureRect *zoom_icon = nullptr;
  300. Button *snap = nullptr;
  301. Button *bezier_edit_icon = nullptr;
  302. OptionButton *snap_mode = nullptr;
  303. Button *imported_anim_warning = nullptr;
  304. void _show_imported_anim_warning();
  305. void _snap_mode_changed(int p_mode);
  306. Vector<AnimationTrackEdit *> track_edits;
  307. Vector<AnimationTrackEditGroup *> groups;
  308. bool animation_changing_awaiting_update = false;
  309. void _animation_update(); // Updated by AnimationTrackEditor(this)
  310. int _get_track_selected();
  311. void _animation_changed();
  312. void _update_tracks();
  313. void _redraw_tracks();
  314. void _redraw_groups();
  315. void _check_bezier_exist();
  316. void _name_limit_changed();
  317. void _timeline_changed(float p_new_pos, bool p_drag, bool p_timeline_only);
  318. void _track_remove_request(int p_track);
  319. void _animation_track_remove_request(int p_track, Ref<Animation> p_from_animation);
  320. void _track_grab_focus(int p_track);
  321. void _update_scroll(double);
  322. void _update_step(double p_new_step);
  323. void _update_length(double p_new_len);
  324. void _dropped_track(int p_from_track, int p_to_track);
  325. void _add_track(int p_type);
  326. void _new_track_node_selected(NodePath p_path);
  327. void _new_track_property_selected(String p_name);
  328. void _update_step_spinbox();
  329. PropertySelector *prop_selector = nullptr;
  330. PropertySelector *method_selector = nullptr;
  331. SceneTreeDialog *pick_track = nullptr;
  332. int adding_track_type = 0;
  333. NodePath adding_track_path;
  334. bool keying = false;
  335. struct InsertData {
  336. Animation::TrackType type;
  337. NodePath path;
  338. int track_idx = 0;
  339. Variant value;
  340. String query;
  341. bool advance = false;
  342. };
  343. Label *insert_confirm_text = nullptr;
  344. CheckBox *insert_confirm_bezier = nullptr;
  345. CheckBox *insert_confirm_reset = nullptr;
  346. ConfirmationDialog *insert_confirm = nullptr;
  347. bool insert_queue = false;
  348. List<InsertData> insert_data;
  349. void _query_insert(const InsertData &p_id);
  350. Ref<Animation> _create_and_get_reset_animation();
  351. void _confirm_insert_list();
  352. struct TrackIndices {
  353. int normal;
  354. int reset;
  355. TrackIndices(const Animation *p_anim = nullptr, const Animation *p_reset_anim = nullptr) {
  356. normal = p_anim ? p_anim->get_track_count() : 0;
  357. reset = p_reset_anim ? p_reset_anim->get_track_count() : 0;
  358. }
  359. };
  360. TrackIndices _confirm_insert(InsertData p_id, TrackIndices p_next_tracks, bool p_reset_wanted, Ref<Animation> p_reset_anim, bool p_create_beziers);
  361. void _insert_track(bool p_reset_wanted, bool p_create_beziers);
  362. void _root_removed();
  363. PropertyInfo _find_hint_for_track(int p_idx, NodePath &r_base_path, Variant *r_current_val = nullptr);
  364. Ref<ViewPanner> panner;
  365. void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
  366. void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
  367. void _timeline_value_changed(double);
  368. float insert_key_from_track_call_ofs = 0.0f;
  369. int insert_key_from_track_call_track = 0;
  370. void _insert_key_from_track(float p_ofs, int p_track);
  371. void _add_method_key(const String &p_method);
  372. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  373. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  374. //selection
  375. struct SelectedKey {
  376. int track = 0;
  377. int key = 0;
  378. bool operator<(const SelectedKey &p_key) const { return track == p_key.track ? key < p_key.key : track < p_key.track; };
  379. };
  380. struct KeyInfo {
  381. float pos = 0;
  382. };
  383. RBMap<SelectedKey, KeyInfo> selection;
  384. bool moving_selection = false;
  385. float moving_selection_offset = 0.0f;
  386. void _move_selection_begin();
  387. void _move_selection(float p_offset);
  388. void _move_selection_commit();
  389. void _move_selection_cancel();
  390. AnimationTrackKeyEdit *key_edit = nullptr;
  391. AnimationMultiTrackKeyEdit *multi_key_edit = nullptr;
  392. void _update_key_edit();
  393. void _clear_key_edit();
  394. Control *box_selection = nullptr;
  395. void _box_selection_draw();
  396. bool box_selecting = false;
  397. Vector2 box_selecting_from;
  398. Rect2 box_select_rect;
  399. void _scroll_input(const Ref<InputEvent> &p_event);
  400. Vector<Ref<AnimationTrackEditPlugin>> track_edit_plugins;
  401. void _toggle_bezier_edit();
  402. void _cancel_bezier_edit();
  403. void _bezier_edit(int p_for_track);
  404. void _bezier_track_set_key_handle_mode(Animation *p_anim, int p_track, int p_index, Animation::HandleMode p_mode, Animation::HandleSetMode p_set_mode = Animation::HANDLE_SET_MODE_NONE);
  405. ////////////// edit menu stuff
  406. ConfirmationDialog *bake_dialog = nullptr;
  407. CheckBox *bake_trs = nullptr;
  408. CheckBox *bake_blendshape = nullptr;
  409. CheckBox *bake_value = nullptr;
  410. SpinBox *bake_fps = nullptr;
  411. ConfirmationDialog *optimize_dialog = nullptr;
  412. SpinBox *optimize_velocity_error = nullptr;
  413. SpinBox *optimize_angular_error = nullptr;
  414. SpinBox *optimize_precision_error = nullptr;
  415. ConfirmationDialog *cleanup_dialog = nullptr;
  416. CheckBox *cleanup_keys = nullptr;
  417. CheckBox *cleanup_tracks = nullptr;
  418. CheckBox *cleanup_all = nullptr;
  419. ConfirmationDialog *scale_dialog = nullptr;
  420. SpinBox *scale = nullptr;
  421. ConfirmationDialog *ease_dialog = nullptr;
  422. OptionButton *transition_selection = nullptr;
  423. OptionButton *ease_selection = nullptr;
  424. SpinBox *ease_fps = nullptr;
  425. void _select_all_tracks_for_copy();
  426. void _edit_menu_about_to_popup();
  427. void _edit_menu_pressed(int p_option);
  428. int last_menu_track_opt = 0;
  429. void _cleanup_animation(Ref<Animation> p_animation);
  430. void _anim_duplicate_keys(bool transpose);
  431. void _view_group_toggle();
  432. Button *view_group = nullptr;
  433. Button *selected_filter = nullptr;
  434. void _selection_changed();
  435. ConfirmationDialog *track_copy_dialog = nullptr;
  436. Tree *track_copy_select = nullptr;
  437. struct TrackClipboard {
  438. NodePath full_path;
  439. NodePath base_path;
  440. Animation::TrackType track_type = Animation::TYPE_ANIMATION;
  441. Animation::InterpolationType interp_type = Animation::INTERPOLATION_CUBIC_ANGLE;
  442. Animation::UpdateMode update_mode = Animation::UPDATE_CAPTURE;
  443. Animation::LoopMode loop_mode = Animation::LOOP_PINGPONG;
  444. bool loop_wrap = false;
  445. bool enabled = false;
  446. bool use_blend = false;
  447. struct Key {
  448. float time = 0;
  449. float transition = 0;
  450. Variant value;
  451. };
  452. Vector<Key> keys;
  453. };
  454. Vector<TrackClipboard> track_clipboard;
  455. void _insert_animation_key(NodePath p_path, const Variant &p_value);
  456. void _pick_track_filter_text_changed(const String &p_newtext);
  457. void _pick_track_select_recursive(TreeItem *p_item, const String &p_filter, Vector<Node *> &p_select_candidates);
  458. void _pick_track_filter_input(const Ref<InputEvent> &p_ie);
  459. protected:
  460. static void _bind_methods();
  461. void _notification(int p_what);
  462. public:
  463. // Public for use with callable_mp.
  464. void _clear_selection(bool p_update = false);
  465. void _key_selected(int p_key, bool p_single, int p_track);
  466. void _key_deselected(int p_key, int p_track);
  467. enum {
  468. EDIT_COPY_TRACKS,
  469. EDIT_COPY_TRACKS_CONFIRM,
  470. EDIT_PASTE_TRACKS,
  471. EDIT_SCALE_SELECTION,
  472. EDIT_SCALE_FROM_CURSOR,
  473. EDIT_SCALE_CONFIRM,
  474. EDIT_EASE_SELECTION,
  475. EDIT_EASE_CONFIRM,
  476. EDIT_DUPLICATE_SELECTION,
  477. EDIT_DUPLICATE_TRANSPOSED,
  478. EDIT_ADD_RESET_KEY,
  479. EDIT_DELETE_SELECTION,
  480. EDIT_GOTO_NEXT_STEP,
  481. EDIT_GOTO_NEXT_STEP_TIMELINE_ONLY, // Next step without updating animation.
  482. EDIT_GOTO_PREV_STEP,
  483. EDIT_APPLY_RESET,
  484. EDIT_BAKE_ANIMATION,
  485. EDIT_BAKE_ANIMATION_CONFIRM,
  486. EDIT_OPTIMIZE_ANIMATION,
  487. EDIT_OPTIMIZE_ANIMATION_CONFIRM,
  488. EDIT_CLEAN_UP_ANIMATION,
  489. EDIT_CLEAN_UP_ANIMATION_CONFIRM
  490. };
  491. void add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
  492. void remove_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
  493. void set_animation(const Ref<Animation> &p_anim, bool p_read_only);
  494. Ref<Animation> get_current_animation() const;
  495. void set_root(Node *p_root);
  496. Node *get_root() const;
  497. void update_keying();
  498. bool has_keying() const;
  499. Dictionary get_state() const;
  500. void set_state(const Dictionary &p_state);
  501. void cleanup();
  502. void set_anim_pos(float p_pos);
  503. void insert_node_value_key(Node *p_node, const String &p_property, const Variant &p_value, bool p_only_if_exists = false);
  504. void insert_value_key(const String &p_property, const Variant &p_value, bool p_advance);
  505. void insert_transform_key(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type, const Variant p_value);
  506. bool has_track(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type);
  507. void make_insert_queue();
  508. void commit_insert_queue();
  509. void show_select_node_warning(bool p_show);
  510. bool is_key_selected(int p_track, int p_key) const;
  511. bool is_selection_active() const;
  512. bool is_moving_selection() const;
  513. bool is_snap_enabled() const;
  514. float get_moving_selection_offset() const;
  515. float snap_time(float p_value, bool p_relative = false);
  516. bool is_grouping_tracks();
  517. /** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
  518. void goto_prev_step(bool p_from_mouse_event);
  519. /** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
  520. void goto_next_step(bool p_from_mouse_event, bool p_timeline_only = false);
  521. MenuButton *get_edit_menu();
  522. AnimationTrackEditor();
  523. ~AnimationTrackEditor();
  524. };
  525. // AnimationTrackKeyEditEditorPlugin
  526. class AnimationTrackKeyEditEditor : public EditorProperty {
  527. GDCLASS(AnimationTrackKeyEditEditor, EditorProperty);
  528. Ref<Animation> animation;
  529. int track = -1;
  530. real_t key_ofs = 0.0;
  531. bool use_fps = false;
  532. EditorSpinSlider *spinner = nullptr;
  533. struct KeyDataCache {
  534. real_t time = 0.0;
  535. float transition = 0.0;
  536. Variant value;
  537. } key_data_cache;
  538. void _time_edit_entered();
  539. void _time_edit_exited();
  540. public:
  541. AnimationTrackKeyEditEditor(Ref<Animation> p_animation, int p_track, real_t p_key_ofs, bool p_use_fps);
  542. ~AnimationTrackKeyEditEditor();
  543. };
  544. #endif // ANIMATION_TRACK_EDITOR_H