animation_track_editor.h 24 KB

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