animation_track_editor.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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. float time = FLT_MAX; // Defaults to current timeline position.
  368. Variant value;
  369. String query;
  370. bool advance = false;
  371. };
  372. Label *insert_confirm_text = nullptr;
  373. CheckBox *insert_confirm_bezier = nullptr;
  374. CheckBox *insert_confirm_reset = nullptr;
  375. ConfirmationDialog *insert_confirm = nullptr;
  376. bool insert_queue = false;
  377. List<InsertData> insert_data;
  378. void _query_insert(const InsertData &p_id);
  379. Ref<Animation> _create_and_get_reset_animation();
  380. void _confirm_insert_list();
  381. struct TrackIndices {
  382. int normal;
  383. int reset;
  384. TrackIndices(const Animation *p_anim = nullptr, const Animation *p_reset_anim = nullptr) {
  385. normal = p_anim ? p_anim->get_track_count() : 0;
  386. reset = p_reset_anim ? p_reset_anim->get_track_count() : 0;
  387. }
  388. };
  389. TrackIndices _confirm_insert(InsertData p_id, TrackIndices p_next_tracks, bool p_reset_wanted, Ref<Animation> p_reset_anim, bool p_create_beziers);
  390. void _insert_track(bool p_reset_wanted, bool p_create_beziers);
  391. void _root_removed();
  392. PropertyInfo _find_hint_for_track(int p_idx, NodePath &r_base_path, Variant *r_current_val = nullptr);
  393. Ref<ViewPanner> panner;
  394. void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
  395. void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
  396. void _timeline_value_changed(double);
  397. float insert_key_from_track_call_ofs = 0.0f;
  398. int insert_key_from_track_call_track = 0;
  399. void _insert_key_from_track(float p_ofs, int p_track);
  400. void _add_method_key(const String &p_method);
  401. void _fetch_value_track_options(const NodePath &p_path, Animation::UpdateMode *r_update_mode, Animation::InterpolationType *r_interpolation_type, bool *r_loop_wrap);
  402. void _clear_selection_for_anim(const Ref<Animation> &p_anim);
  403. void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
  404. //selection
  405. struct SelectedKey {
  406. int track = 0;
  407. int key = 0;
  408. bool operator<(const SelectedKey &p_key) const { return track == p_key.track ? key < p_key.key : track < p_key.track; };
  409. };
  410. struct KeyInfo {
  411. float pos = 0;
  412. };
  413. RBMap<SelectedKey, KeyInfo> selection;
  414. bool moving_selection = false;
  415. float moving_selection_offset = 0.0f;
  416. void _move_selection_begin();
  417. void _move_selection(float p_offset);
  418. void _move_selection_commit();
  419. void _move_selection_cancel();
  420. AnimationTrackKeyEdit *key_edit = nullptr;
  421. AnimationMultiTrackKeyEdit *multi_key_edit = nullptr;
  422. void _update_key_edit();
  423. void _clear_key_edit();
  424. Control *box_selection = nullptr;
  425. void _box_selection_draw();
  426. bool box_selecting = false;
  427. Vector2 box_selecting_from;
  428. Rect2 box_select_rect;
  429. void _scroll_input(const Ref<InputEvent> &p_event);
  430. Vector<Ref<AnimationTrackEditPlugin>> track_edit_plugins;
  431. void _toggle_bezier_edit();
  432. void _cancel_bezier_edit();
  433. void _bezier_edit(int p_for_track);
  434. 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);
  435. ////////////// edit menu stuff
  436. ConfirmationDialog *bake_dialog = nullptr;
  437. CheckBox *bake_trs = nullptr;
  438. CheckBox *bake_blendshape = nullptr;
  439. CheckBox *bake_value = nullptr;
  440. SpinBox *bake_fps = nullptr;
  441. ConfirmationDialog *optimize_dialog = nullptr;
  442. SpinBox *optimize_velocity_error = nullptr;
  443. SpinBox *optimize_angular_error = nullptr;
  444. SpinBox *optimize_precision_error = nullptr;
  445. ConfirmationDialog *cleanup_dialog = nullptr;
  446. CheckBox *cleanup_keys_with_trimming_head = nullptr;
  447. CheckBox *cleanup_keys_with_trimming_end = nullptr;
  448. CheckBox *cleanup_keys = nullptr;
  449. CheckBox *cleanup_tracks = nullptr;
  450. CheckBox *cleanup_all = nullptr;
  451. ConfirmationDialog *scale_dialog = nullptr;
  452. SpinBox *scale = nullptr;
  453. ConfirmationDialog *ease_dialog = nullptr;
  454. OptionButton *transition_selection = nullptr;
  455. OptionButton *ease_selection = nullptr;
  456. SpinBox *ease_fps = nullptr;
  457. void _select_all_tracks_for_copy();
  458. void _edit_menu_about_to_popup();
  459. void _edit_menu_pressed(int p_option);
  460. int last_menu_track_opt = 0;
  461. void _cleanup_animation(Ref<Animation> p_animation);
  462. void _anim_duplicate_keys(float p_ofs, bool p_ofs_valid, int p_track);
  463. void _anim_copy_keys(bool p_cut);
  464. bool _is_track_compatible(int p_target_track_idx, Variant::Type p_source_value_type, Animation::TrackType p_source_track_type);
  465. void _anim_paste_keys(float p_ofs, bool p_ofs_valid, int p_track);
  466. void _view_group_toggle();
  467. Button *view_group = nullptr;
  468. Button *selected_filter = nullptr;
  469. void _auto_fit();
  470. void _auto_fit_bezier();
  471. void _selection_changed();
  472. ConfirmationDialog *track_copy_dialog = nullptr;
  473. Tree *track_copy_select = nullptr;
  474. struct TrackClipboard {
  475. NodePath full_path;
  476. NodePath base_path;
  477. Animation::TrackType track_type = Animation::TYPE_ANIMATION;
  478. Animation::InterpolationType interp_type = Animation::INTERPOLATION_CUBIC_ANGLE;
  479. Animation::UpdateMode update_mode = Animation::UPDATE_CAPTURE;
  480. Animation::LoopMode loop_mode = Animation::LOOP_PINGPONG;
  481. bool loop_wrap = false;
  482. bool enabled = false;
  483. bool use_blend = false;
  484. struct Key {
  485. float time = 0;
  486. float transition = 0;
  487. Variant value;
  488. };
  489. Vector<Key> keys;
  490. };
  491. struct KeyClipboard {
  492. int top_track;
  493. struct Key {
  494. Animation::TrackType track_type;
  495. int track;
  496. float time = 0;
  497. float transition = 0;
  498. Variant value;
  499. };
  500. Vector<Key> keys;
  501. };
  502. Vector<TrackClipboard> track_clipboard;
  503. KeyClipboard key_clipboard;
  504. void _set_key_clipboard(int p_top_track, float p_top_time, RBMap<SelectedKey, KeyInfo> &p_keymap);
  505. void _insert_animation_key(NodePath p_path, const Variant &p_value);
  506. void _pick_track_filter_text_changed(const String &p_newtext);
  507. void _pick_track_select_recursive(TreeItem *p_item, const String &p_filter, Vector<Node *> &p_select_candidates);
  508. void _pick_track_filter_input(const Ref<InputEvent> &p_ie);
  509. double snap_unit;
  510. void _update_snap_unit();
  511. protected:
  512. static void _bind_methods();
  513. void _notification(int p_what);
  514. public:
  515. // Public for use with callable_mp.
  516. void _clear_selection(bool p_update = false);
  517. void _key_selected(int p_key, bool p_single, int p_track);
  518. void _key_deselected(int p_key, int p_track);
  519. enum {
  520. EDIT_COPY_TRACKS,
  521. EDIT_COPY_TRACKS_CONFIRM,
  522. EDIT_PASTE_TRACKS,
  523. EDIT_CUT_KEYS,
  524. EDIT_COPY_KEYS,
  525. EDIT_PASTE_KEYS,
  526. EDIT_SCALE_SELECTION,
  527. EDIT_SCALE_FROM_CURSOR,
  528. EDIT_SCALE_CONFIRM,
  529. EDIT_SET_START_OFFSET,
  530. EDIT_SET_END_OFFSET,
  531. EDIT_EASE_SELECTION,
  532. EDIT_EASE_CONFIRM,
  533. EDIT_DUPLICATE_SELECTED_KEYS,
  534. EDIT_DUPLICATE_SELECTION,
  535. EDIT_DUPLICATE_TRANSPOSED,
  536. EDIT_MOVE_FIRST_SELECTED_KEY_TO_CURSOR,
  537. EDIT_MOVE_LAST_SELECTED_KEY_TO_CURSOR,
  538. EDIT_ADD_RESET_KEY,
  539. EDIT_DELETE_SELECTION,
  540. EDIT_GOTO_NEXT_STEP,
  541. EDIT_GOTO_NEXT_STEP_TIMELINE_ONLY, // Next step without updating animation.
  542. EDIT_GOTO_PREV_STEP,
  543. EDIT_APPLY_RESET,
  544. EDIT_BAKE_ANIMATION,
  545. EDIT_BAKE_ANIMATION_CONFIRM,
  546. EDIT_OPTIMIZE_ANIMATION,
  547. EDIT_OPTIMIZE_ANIMATION_CONFIRM,
  548. EDIT_CLEAN_UP_ANIMATION,
  549. EDIT_CLEAN_UP_ANIMATION_CONFIRM
  550. };
  551. void add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
  552. void remove_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
  553. void set_animation(const Ref<Animation> &p_anim, bool p_read_only);
  554. Ref<Animation> get_current_animation() const;
  555. void set_root(Node *p_root);
  556. Node *get_root() const;
  557. void update_keying();
  558. bool has_keying() const;
  559. Dictionary get_state() const;
  560. void set_state(const Dictionary &p_state);
  561. void cleanup();
  562. void set_anim_pos(float p_pos);
  563. void insert_node_value_key(Node *p_node, const String &p_property, const Variant &p_value, bool p_only_if_exists = false);
  564. void insert_value_key(const String &p_property, const Variant &p_value, bool p_advance);
  565. void insert_transform_key(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type, const Variant &p_value);
  566. bool has_track(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type);
  567. void make_insert_queue();
  568. void commit_insert_queue();
  569. void show_select_node_warning(bool p_show);
  570. void show_dummy_player_warning(bool p_show);
  571. void show_inactive_player_warning(bool p_show);
  572. bool is_key_selected(int p_track, int p_key) const;
  573. bool is_selection_active() const;
  574. bool is_key_clipboard_active() const;
  575. bool is_moving_selection() const;
  576. bool is_snap_enabled() const;
  577. bool can_add_reset_key() const;
  578. float get_moving_selection_offset() const;
  579. float snap_time(float p_value, bool p_relative = false);
  580. bool is_grouping_tracks();
  581. /** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
  582. void goto_prev_step(bool p_from_mouse_event);
  583. /** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
  584. void goto_next_step(bool p_from_mouse_event, bool p_timeline_only = false);
  585. MenuButton *get_edit_menu();
  586. AnimationTrackEditor();
  587. ~AnimationTrackEditor();
  588. };
  589. // AnimationTrackKeyEditEditorPlugin
  590. class AnimationTrackKeyEditEditor : public EditorProperty {
  591. GDCLASS(AnimationTrackKeyEditEditor, EditorProperty);
  592. Ref<Animation> animation;
  593. int track = -1;
  594. real_t key_ofs = 0.0;
  595. bool use_fps = false;
  596. EditorSpinSlider *spinner = nullptr;
  597. struct KeyDataCache {
  598. real_t time = 0.0;
  599. float transition = 0.0;
  600. Variant value;
  601. } key_data_cache;
  602. void _time_edit_entered();
  603. void _time_edit_exited();
  604. public:
  605. AnimationTrackKeyEditEditor(Ref<Animation> p_animation, int p_track, real_t p_key_ofs, bool p_use_fps);
  606. ~AnimationTrackKeyEditEditor();
  607. };
  608. #endif // ANIMATION_TRACK_EDITOR_H