animation_track_editor.h 22 KB

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