Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/animation/animation_track_editor.h
9912 views
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
31
#pragma once
32
33
#include "editor/editor_data.h"
34
#include "editor/inspector/editor_properties.h"
35
#include "editor/inspector/property_selector.h"
36
#include "scene/3d/node_3d.h"
37
#include "scene/gui/control.h"
38
#include "scene/gui/menu_button.h"
39
#include "scene/gui/scroll_bar.h"
40
#include "scene/gui/tree.h"
41
#include "scene/resources/animation.h"
42
43
class AnimationMarkerEdit;
44
class AnimationTrackEditor;
45
class AnimationTrackEdit;
46
class CheckBox;
47
class ColorPickerButton;
48
class EditorSpinSlider;
49
class HSlider;
50
class OptionButton;
51
class PanelContainer;
52
class SceneTreeDialog;
53
class SpinBox;
54
class TextureRect;
55
class ViewPanner;
56
class EditorValidationPanel;
57
58
class AnimationTrackKeyEdit : public Object {
59
GDCLASS(AnimationTrackKeyEdit, Object);
60
61
public:
62
bool setting = false;
63
bool animation_read_only = false;
64
65
Ref<Animation> animation;
66
int track = -1;
67
float key_ofs = 0;
68
Node *root_path = nullptr;
69
70
PropertyInfo hint;
71
NodePath base;
72
bool use_fps = false;
73
AnimationTrackEditor *editor = nullptr;
74
75
bool _hide_script_from_inspector() { return true; }
76
bool _hide_metadata_from_inspector() { return true; }
77
bool _dont_undo_redo() { return true; }
78
79
bool _is_read_only() { return animation_read_only; }
80
81
void notify_change();
82
Node *get_root_path();
83
void set_use_fps(bool p_enable);
84
85
protected:
86
static void _bind_methods();
87
void _fix_node_path(Variant &value);
88
void _update_obj(const Ref<Animation> &p_anim);
89
void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to);
90
bool _set(const StringName &p_name, const Variant &p_value);
91
bool _get(const StringName &p_name, Variant &r_ret) const;
92
void _get_property_list(List<PropertyInfo> *p_list) const;
93
};
94
95
class AnimationMultiTrackKeyEdit : public Object {
96
GDCLASS(AnimationMultiTrackKeyEdit, Object);
97
98
public:
99
bool setting = false;
100
bool animation_read_only = false;
101
102
Ref<Animation> animation;
103
104
RBMap<int, List<float>> key_ofs_map;
105
RBMap<int, NodePath> base_map;
106
PropertyInfo hint;
107
108
Node *root_path = nullptr;
109
110
bool use_fps = false;
111
AnimationTrackEditor *editor = nullptr;
112
113
bool _hide_script_from_inspector() { return true; }
114
bool _hide_metadata_from_inspector() { return true; }
115
bool _dont_undo_redo() { return true; }
116
117
bool _is_read_only() { return animation_read_only; }
118
119
void notify_change();
120
Node *get_root_path();
121
void set_use_fps(bool p_enable);
122
123
protected:
124
static void _bind_methods();
125
void _fix_node_path(Variant &value, NodePath &base);
126
void _update_obj(const Ref<Animation> &p_anim);
127
void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to);
128
bool _set(const StringName &p_name, const Variant &p_value);
129
bool _get(const StringName &p_name, Variant &r_ret) const;
130
void _get_property_list(List<PropertyInfo> *p_list) const;
131
};
132
133
class AnimationMarkerKeyEdit : public Object {
134
GDCLASS(AnimationMarkerKeyEdit, Object);
135
136
public:
137
bool animation_read_only = false;
138
139
Ref<Animation> animation;
140
StringName marker_name;
141
bool use_fps = false;
142
143
AnimationMarkerEdit *marker_edit = nullptr;
144
145
bool _hide_script_from_inspector() { return true; }
146
bool _hide_metadata_from_inspector() { return true; }
147
bool _dont_undo_redo() { return true; }
148
149
bool _is_read_only() { return animation_read_only; }
150
151
float get_time() const;
152
153
protected:
154
static void _bind_methods();
155
void _set_marker_name(const StringName &p_name);
156
bool _set(const StringName &p_name, const Variant &p_value);
157
bool _get(const StringName &p_name, Variant &r_ret) const;
158
void _get_property_list(List<PropertyInfo> *p_list) const;
159
};
160
161
class AnimationMultiMarkerKeyEdit : public Object {
162
GDCLASS(AnimationMultiMarkerKeyEdit, Object);
163
164
public:
165
bool animation_read_only = false;
166
167
Ref<Animation> animation;
168
Vector<StringName> marker_names;
169
170
AnimationMarkerEdit *marker_edit = nullptr;
171
172
bool _hide_script_from_inspector() { return true; }
173
bool _hide_metadata_from_inspector() { return true; }
174
bool _dont_undo_redo() { return true; }
175
176
bool _is_read_only() { return animation_read_only; }
177
178
protected:
179
static void _bind_methods();
180
bool _set(const StringName &p_name, const Variant &p_value);
181
bool _get(const StringName &p_name, Variant &r_ret) const;
182
void _get_property_list(List<PropertyInfo> *p_list) const;
183
};
184
185
class AnimationTimelineEdit : public Range {
186
GDCLASS(AnimationTimelineEdit, Range);
187
188
friend class AnimationBezierTrackEdit;
189
friend class AnimationTrackEditor;
190
191
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.
192
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.
193
194
Ref<Animation> animation;
195
bool read_only = false;
196
197
AnimationTrackEdit *track_edit = nullptr;
198
int name_limit = 0;
199
Range *zoom = nullptr;
200
Range *h_scroll = nullptr;
201
float play_position_pos = 0.0f;
202
203
HBoxContainer *add_track_hb = nullptr;
204
HBoxContainer *len_hb = nullptr;
205
EditorSpinSlider *length = nullptr;
206
Button *loop = nullptr;
207
TextureRect *time_icon = nullptr;
208
209
MenuButton *add_track = nullptr;
210
LineEdit *filter_track = nullptr;
211
Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
212
HScrollBar *hscroll = nullptr;
213
214
void _zoom_changed(double);
215
void _anim_length_changed(double p_new_len);
216
void _anim_loop_pressed();
217
218
void _play_position_draw();
219
Rect2 hsize_rect;
220
221
bool editing = false;
222
bool use_fps = false;
223
224
Ref<ViewPanner> panner;
225
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
226
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
227
228
bool dragging_timeline = false;
229
bool dragging_hsize = false;
230
float dragging_hsize_from = 0.0f;
231
float dragging_hsize_at = 0.0f;
232
double last_zoom_scale = 1.0;
233
double hscroll_on_zoom_buffer = -1.0;
234
235
Vector2 zoom_scroll_origin;
236
bool zoom_callback_occurred = false;
237
238
virtual void gui_input(const Ref<InputEvent> &p_event) override;
239
void _track_added(int p_track);
240
241
float _get_zoom_scale(double p_zoom_value) const;
242
void _scroll_to_start();
243
244
protected:
245
static void _bind_methods();
246
void _notification(int p_what);
247
248
public:
249
int get_name_limit() const;
250
int get_buttons_width() const;
251
252
float get_zoom_scale() const;
253
254
virtual Size2 get_minimum_size() const override;
255
void set_animation(const Ref<Animation> &p_animation, bool p_read_only);
256
void set_track_edit(AnimationTrackEdit *p_track_edit);
257
void set_zoom(Range *p_zoom);
258
Range *get_zoom() const { return zoom; }
259
void auto_fit();
260
261
void set_play_position(float p_pos);
262
float get_play_position() const;
263
void update_play_position();
264
265
void update_values();
266
267
void set_use_fps(bool p_use_fps);
268
bool is_using_fps() const;
269
270
void set_hscroll(HScrollBar *p_hscroll);
271
272
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
273
274
AnimationTimelineEdit();
275
};
276
277
class AnimationMarkerEdit : public Control {
278
GDCLASS(AnimationMarkerEdit, Control);
279
friend class AnimationTimelineEdit;
280
281
enum {
282
MENU_KEY_INSERT,
283
MENU_KEY_RENAME,
284
MENU_KEY_DELETE,
285
MENU_KEY_TOGGLE_MARKER_NAMES,
286
};
287
288
AnimationTimelineEdit *timeline = nullptr;
289
Control *play_position = nullptr; // Separate control used to draw so updates for only position changed are much faster.
290
float play_position_pos = 0.0f;
291
292
HashSet<StringName> selection;
293
294
Ref<Animation> animation;
295
bool read_only = false;
296
297
Ref<Texture2D> type_icon;
298
Ref<Texture2D> selected_icon;
299
300
PopupMenu *menu = nullptr;
301
302
bool hovered = false;
303
StringName hovering_marker;
304
305
void _zoom_changed();
306
307
Ref<Texture2D> icon_cache;
308
309
void _menu_selected(int p_index);
310
311
void _play_position_draw();
312
bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);
313
bool _is_ui_pos_in_current_section(const Point2 &p_pos);
314
315
float insert_at_pos = 0.0f;
316
bool moving_selection_attempt = false;
317
bool moving_selection_effective = false;
318
float moving_selection_offset = 0.0f;
319
float moving_selection_pivot = 0.0f;
320
float moving_selection_mouse_begin_x = 0.0f;
321
float moving_selection_mouse_begin_y = 0.0f;
322
StringName select_single_attempt;
323
bool moving_selection = false;
324
void _move_selection_begin();
325
void _move_selection(float p_offset);
326
void _move_selection_commit();
327
void _move_selection_cancel();
328
329
void _clear_selection_for_anim(const Ref<Animation> &p_anim);
330
void _select_key(const StringName &p_name, bool is_single = false);
331
void _deselect_key(const StringName &p_name);
332
333
void _insert_marker(float p_ofs);
334
void _rename_marker(const StringName &p_name);
335
void _delete_selected_markers();
336
337
ConfirmationDialog *marker_insert_confirm = nullptr;
338
LineEdit *marker_insert_new_name = nullptr;
339
ColorPickerButton *marker_insert_color = nullptr;
340
AcceptDialog *marker_insert_error_dialog = nullptr;
341
float marker_insert_ofs = 0;
342
343
ConfirmationDialog *marker_rename_confirm = nullptr;
344
LineEdit *marker_rename_new_name = nullptr;
345
StringName marker_rename_prev_name;
346
347
AcceptDialog *marker_rename_error_dialog = nullptr;
348
349
bool should_show_all_marker_names = false;
350
351
////////////// edit menu stuff
352
353
void _marker_insert_confirmed();
354
void _marker_insert_new_name_changed(const String &p_text);
355
void _marker_rename_confirmed();
356
void _marker_rename_new_name_changed(const String &p_text);
357
358
AnimationTrackEditor *editor = nullptr;
359
360
HBoxContainer *_create_hbox_labeled_control(const String &p_text, Control *p_control) const;
361
362
void _update_key_edit();
363
void _clear_key_edit();
364
365
AnimationMarkerKeyEdit *key_edit = nullptr;
366
AnimationMultiMarkerKeyEdit *multi_key_edit = nullptr;
367
368
protected:
369
static void _bind_methods();
370
void _notification(int p_what);
371
372
virtual void gui_input(const Ref<InputEvent> &p_event) override;
373
374
public:
375
virtual String get_tooltip(const Point2 &p_pos) const override;
376
377
virtual int get_key_height() const;
378
virtual Rect2 get_key_rect(float p_pixels_sec) const;
379
virtual bool is_key_selectable_by_distance() const;
380
virtual void draw_key(const StringName &p_name, float p_pixels_sec, int p_x, bool p_selected, int p_clip_left, int p_clip_right);
381
virtual void draw_bg(int p_clip_left, int p_clip_right);
382
virtual void draw_fg(int p_clip_left, int p_clip_right);
383
384
Ref<Animation> get_animation() const;
385
AnimationTimelineEdit *get_timeline() const { return timeline; }
386
AnimationTrackEditor *get_editor() const { return editor; }
387
bool is_selection_active() const { return !selection.is_empty(); }
388
bool is_moving_selection() const { return moving_selection; }
389
float get_moving_selection_offset() const { return moving_selection_offset; }
390
void set_animation(const Ref<Animation> &p_animation, bool p_read_only);
391
virtual Size2 get_minimum_size() const override;
392
393
void set_timeline(AnimationTimelineEdit *p_timeline);
394
void set_editor(AnimationTrackEditor *p_editor);
395
396
void set_play_position(float p_pos);
397
void update_play_position();
398
399
void set_use_fps(bool p_use_fps);
400
401
PackedStringArray get_selected_section() const;
402
bool is_marker_selected(const StringName &p_marker) const;
403
404
// For use by AnimationTrackEditor.
405
void _clear_selection(bool p_update);
406
407
AnimationMarkerEdit();
408
};
409
410
class AnimationTrackEdit : public Control {
411
GDCLASS(AnimationTrackEdit, Control);
412
friend class AnimationTimelineEdit;
413
414
enum {
415
MENU_CALL_MODE_CONTINUOUS,
416
MENU_CALL_MODE_DISCRETE,
417
MENU_CALL_MODE_CAPTURE,
418
MENU_INTERPOLATION_NEAREST,
419
MENU_INTERPOLATION_LINEAR,
420
MENU_INTERPOLATION_CUBIC,
421
MENU_INTERPOLATION_LINEAR_ANGLE,
422
MENU_INTERPOLATION_CUBIC_ANGLE,
423
MENU_LOOP_WRAP,
424
MENU_LOOP_CLAMP,
425
MENU_KEY_INSERT,
426
MENU_KEY_DUPLICATE,
427
MENU_KEY_CUT,
428
MENU_KEY_COPY,
429
MENU_KEY_PASTE,
430
MENU_KEY_ADD_RESET,
431
MENU_KEY_DELETE,
432
MENU_KEY_LOOKUP,
433
MENU_USE_BLEND_ENABLED,
434
MENU_USE_BLEND_DISABLED,
435
};
436
437
AnimationTimelineEdit *timeline = nullptr;
438
Popup *path_popup = nullptr;
439
LineEdit *path = nullptr;
440
Node *root = nullptr;
441
Control *play_position = nullptr; //separate control used to draw so updates for only position changed are much faster
442
float play_position_pos = 0.0f;
443
NodePath node_path;
444
445
Ref<Animation> animation;
446
bool read_only = false;
447
int track = 0;
448
449
Rect2 check_rect;
450
Rect2 icon_rect;
451
Rect2 path_rect;
452
453
Rect2 update_mode_rect;
454
Rect2 interp_mode_rect;
455
Rect2 loop_wrap_rect;
456
Rect2 remove_rect;
457
458
Ref<Texture2D> type_icon;
459
Ref<Texture2D> selected_icon;
460
461
PopupMenu *menu = nullptr;
462
463
bool hovered = false;
464
bool clicking_on_name = false;
465
int hovering_key_idx = -1;
466
467
void _zoom_changed();
468
469
Ref<Texture2D> icon_cache;
470
String path_cache;
471
472
void _menu_selected(int p_index);
473
474
void _path_submitted(const String &p_text);
475
void _play_position_draw();
476
bool _is_value_key_valid(const Variant &p_key_value, Variant::Type &r_valid_type) const;
477
bool _try_select_at_ui_pos(const Point2 &p_pos, bool p_aggregate, bool p_deselectable);
478
479
int lookup_key_idx = -1;
480
bool _lookup_key(int p_key_idx) const;
481
482
Ref<Texture2D> _get_key_type_icon() const;
483
484
mutable int dropping_at = 0;
485
float insert_at_pos = 0.0f;
486
bool moving_selection_attempt = false;
487
bool moving_selection_effective = false;
488
float moving_selection_pivot = 0.0f;
489
float moving_selection_mouse_begin_x = 0.0f;
490
int select_single_attempt = -1;
491
bool moving_selection = false;
492
493
bool command_or_control_pressed = false;
494
495
bool in_group = false;
496
AnimationTrackEditor *editor = nullptr;
497
498
protected:
499
static void _bind_methods();
500
void _notification(int p_what);
501
502
virtual void gui_input(const Ref<InputEvent> &p_event) override;
503
504
public:
505
virtual Variant get_drag_data(const Point2 &p_point) override;
506
virtual bool can_drop_data(const Point2 &p_point, const Variant &p_data) const override;
507
virtual void drop_data(const Point2 &p_point, const Variant &p_data) override;
508
509
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
510
virtual String get_tooltip(const Point2 &p_pos) const override;
511
512
virtual int get_key_height() const;
513
virtual Rect2 get_key_rect(int p_index, float p_pixels_sec);
514
virtual bool is_key_selectable_by_distance() const;
515
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);
516
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);
517
virtual void draw_bg(int p_clip_left, int p_clip_right);
518
virtual void draw_fg(int p_clip_left, int p_clip_right);
519
520
//helper
521
void draw_texture_region_clipped(const Ref<Texture2D> &p_texture, const Rect2 &p_rect, const Rect2 &p_region);
522
void draw_rect_clipped(const Rect2 &p_rect, const Color &p_color, bool p_filled = true);
523
524
int get_track() const;
525
Ref<Animation> get_animation() const;
526
AnimationTimelineEdit *get_timeline() const { return timeline; }
527
AnimationTrackEditor *get_editor() const { return editor; }
528
NodePath get_path() const;
529
void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only);
530
virtual Size2 get_minimum_size() const override;
531
532
void set_timeline(AnimationTimelineEdit *p_timeline);
533
void set_editor(AnimationTrackEditor *p_editor);
534
void set_root(Node *p_root);
535
536
void set_play_position(float p_pos);
537
void update_play_position();
538
void cancel_drop();
539
540
void set_in_group(bool p_enable);
541
void append_to_selection(const Rect2 &p_box, bool p_deselection);
542
543
AnimationTrackEdit();
544
};
545
546
class AnimationTrackEditPlugin : public RefCounted {
547
GDCLASS(AnimationTrackEditPlugin, RefCounted);
548
549
public:
550
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);
551
virtual AnimationTrackEdit *create_audio_track_edit();
552
virtual AnimationTrackEdit *create_animation_track_edit(Object *p_object);
553
};
554
555
class AnimationTrackKeyEdit;
556
class AnimationMultiTrackKeyEdit;
557
class AnimationBezierTrackEdit;
558
559
class AnimationTrackEditGroup : public Control {
560
GDCLASS(AnimationTrackEditGroup, Control);
561
Ref<Texture2D> icon;
562
Vector2 icon_size;
563
String node_name;
564
NodePath node;
565
Node *root = nullptr;
566
AnimationTimelineEdit *timeline = nullptr;
567
AnimationTrackEditor *editor = nullptr;
568
569
void _zoom_changed();
570
571
protected:
572
void _notification(int p_what);
573
574
virtual void gui_input(const Ref<InputEvent> &p_event) override;
575
576
public:
577
void set_type_and_name(const Ref<Texture2D> &p_type, const String &p_name, const NodePath &p_node);
578
virtual Size2 get_minimum_size() const override;
579
void set_timeline(AnimationTimelineEdit *p_timeline);
580
void set_root(Node *p_root);
581
void set_editor(AnimationTrackEditor *p_editor);
582
String get_node_name() const;
583
584
AnimationTrackEditGroup();
585
};
586
587
class AnimationTrackEditor : public VBoxContainer {
588
GDCLASS(AnimationTrackEditor, VBoxContainer);
589
friend class AnimationTimelineEdit;
590
friend class AnimationBezierTrackEdit;
591
friend class AnimationMarkerKeyEditEditor;
592
593
Ref<Animation> animation;
594
bool read_only = false;
595
Node *root = nullptr;
596
597
MenuButton *edit = nullptr;
598
599
PanelContainer *main_panel = nullptr;
600
HScrollBar *hscroll = nullptr;
601
ScrollContainer *scroll = nullptr;
602
VBoxContainer *track_vbox = nullptr;
603
AnimationBezierTrackEdit *bezier_edit = nullptr;
604
VBoxContainer *timeline_vbox = nullptr;
605
606
Label *info_message = nullptr;
607
608
AnimationTimelineEdit *timeline = nullptr;
609
AnimationMarkerEdit *marker_edit = nullptr;
610
HSlider *zoom = nullptr;
611
EditorSpinSlider *step = nullptr;
612
Button *fps_compat = nullptr;
613
Label *nearest_fps_label = nullptr;
614
TextureRect *zoom_icon = nullptr;
615
Button *snap_keys = nullptr;
616
Button *snap_timeline = nullptr;
617
Button *bezier_edit_icon = nullptr;
618
OptionButton *snap_mode = nullptr;
619
Button *auto_fit = nullptr;
620
Button *auto_fit_bezier = nullptr;
621
OptionButton *bezier_key_mode = nullptr;
622
623
Button *imported_anim_warning = nullptr;
624
void _show_imported_anim_warning();
625
626
Button *dummy_player_warning = nullptr;
627
void _show_dummy_player_warning();
628
629
Button *inactive_player_warning = nullptr;
630
void _show_inactive_player_warning();
631
632
void _snap_mode_changed(int p_mode);
633
Vector<AnimationTrackEdit *> track_edits;
634
Vector<AnimationTrackEditGroup *> groups;
635
636
bool animation_changing_awaiting_update = false;
637
void _animation_update(); // Updated by AnimationTrackEditor(this)
638
int _get_track_selected();
639
void _animation_changed();
640
void _update_tracks();
641
void _redraw_tracks();
642
void _redraw_groups();
643
void _check_bezier_exist();
644
645
void _name_limit_changed();
646
void _timeline_changed(float p_new_pos, bool p_timeline_only);
647
void _track_remove_request(int p_track);
648
void _animation_track_remove_request(int p_track, Ref<Animation> p_from_animation);
649
void _track_grab_focus(int p_track);
650
651
void _update_scroll(double);
652
void _update_nearest_fps_label();
653
void _update_fps_compat_mode(bool p_enabled);
654
void _update_step(double p_new_step);
655
void _update_length(double p_new_len);
656
void _dropped_track(int p_from_track, int p_to_track);
657
658
void _add_track(int p_type);
659
void _new_track_node_selected(NodePath p_path);
660
void _new_track_property_selected(const String &p_name);
661
662
void _update_step_spinbox();
663
664
PropertySelector *prop_selector = nullptr;
665
PropertySelector *method_selector = nullptr;
666
SceneTreeDialog *pick_track = nullptr;
667
int adding_track_type = 0;
668
NodePath adding_track_path;
669
670
bool keying = false;
671
672
struct InsertData {
673
Animation::TrackType type;
674
NodePath path;
675
int track_idx = 0;
676
float time = FLT_MAX; // Defaults to current timeline position.
677
Variant value;
678
String query;
679
bool advance = false;
680
};
681
682
Label *insert_confirm_text = nullptr;
683
CheckBox *insert_confirm_bezier = nullptr;
684
CheckBox *insert_confirm_reset = nullptr;
685
ConfirmationDialog *insert_confirm = nullptr;
686
bool insert_queue = false;
687
List<InsertData> insert_data;
688
689
void _query_insert(const InsertData &p_id);
690
Ref<Animation> _create_and_get_reset_animation();
691
void _confirm_insert_list();
692
struct TrackIndices {
693
int normal;
694
int reset;
695
696
TrackIndices(const Animation *p_anim = nullptr, const Animation *p_reset_anim = nullptr) {
697
normal = p_anim ? p_anim->get_track_count() : 0;
698
reset = p_reset_anim ? p_reset_anim->get_track_count() : 0;
699
}
700
};
701
TrackIndices _confirm_insert(InsertData p_id, TrackIndices p_next_tracks, bool p_reset_wanted, Ref<Animation> p_reset_anim, bool p_create_beziers);
702
void _insert_track(bool p_reset_wanted, bool p_create_beziers);
703
704
void _root_removed();
705
706
PropertyInfo _find_hint_for_track(int p_idx, NodePath &r_base_path, Variant *r_current_val = nullptr);
707
708
void _scroll_changed(const Vector2 &p_val);
709
void _v_scroll_changed(float p_val);
710
void _h_scroll_changed(float p_val);
711
712
Ref<ViewPanner> panner;
713
void _pan_callback(Vector2 p_scroll_vec, Ref<InputEvent> p_event);
714
void _zoom_callback(float p_zoom_factor, Vector2 p_origin, Ref<InputEvent> p_event);
715
716
void _timeline_value_changed(double);
717
718
float insert_key_from_track_call_ofs = 0.0f;
719
int insert_key_from_track_call_track = 0;
720
void _insert_key_from_track(float p_ofs, int p_track);
721
void _add_method_key(const String &p_method);
722
723
void _fetch_value_track_options(const NodePath &p_path, Animation::UpdateMode *r_update_mode, Animation::InterpolationType *r_interpolation_type, bool *r_loop_wrap);
724
725
void _clear_selection_for_anim(const Ref<Animation> &p_anim);
726
void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos);
727
728
//selection
729
730
struct SelectedKey {
731
int track = 0;
732
int key = 0;
733
bool operator<(const SelectedKey &p_key) const { return track == p_key.track ? key < p_key.key : track < p_key.track; }
734
};
735
736
struct KeyInfo {
737
float pos = 0;
738
};
739
740
RBMap<SelectedKey, KeyInfo> selection;
741
742
bool moving_selection = false;
743
float moving_selection_offset = 0.0f;
744
void _move_selection_begin();
745
void _move_selection(float p_offset);
746
void _move_selection_commit();
747
void _move_selection_cancel();
748
749
AnimationTrackKeyEdit *key_edit = nullptr;
750
AnimationMultiTrackKeyEdit *multi_key_edit = nullptr;
751
void _update_key_edit();
752
void _clear_key_edit();
753
754
Control *box_selection_container = nullptr;
755
756
Control *box_selection = nullptr;
757
void _box_selection_draw();
758
bool box_selecting = false;
759
Vector2 box_selecting_from;
760
Vector2 box_selecting_to;
761
Rect2 box_select_rect;
762
Vector2 prev_scroll_position;
763
void _scroll_input(const Ref<InputEvent> &p_event);
764
765
Vector<Ref<AnimationTrackEditPlugin>> track_edit_plugins;
766
767
void _toggle_bezier_edit();
768
void _cancel_bezier_edit();
769
void _bezier_edit(int p_for_track);
770
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);
771
void _bezier_track_set_key_handle_mode_at_time(Animation *p_anim, int p_track, float p_time, Animation::HandleMode p_mode, Animation::HandleSetMode p_set_mode = Animation::HANDLE_SET_MODE_NONE);
772
773
////////////// edit menu stuff
774
775
ConfirmationDialog *bake_dialog = nullptr;
776
CheckBox *bake_trs = nullptr;
777
CheckBox *bake_blendshape = nullptr;
778
CheckBox *bake_value = nullptr;
779
SpinBox *bake_fps = nullptr;
780
781
ConfirmationDialog *optimize_dialog = nullptr;
782
SpinBox *optimize_velocity_error = nullptr;
783
SpinBox *optimize_angular_error = nullptr;
784
SpinBox *optimize_precision_error = nullptr;
785
786
ConfirmationDialog *cleanup_dialog = nullptr;
787
CheckBox *cleanup_keys_with_trimming_head = nullptr;
788
CheckBox *cleanup_keys_with_trimming_end = nullptr;
789
CheckBox *cleanup_keys = nullptr;
790
CheckBox *cleanup_tracks = nullptr;
791
CheckBox *cleanup_all = nullptr;
792
793
ConfirmationDialog *scale_dialog = nullptr;
794
SpinBox *scale = nullptr;
795
796
ConfirmationDialog *ease_dialog = nullptr;
797
OptionButton *transition_selection = nullptr;
798
OptionButton *ease_selection = nullptr;
799
SpinBox *ease_fps = nullptr;
800
801
void _select_all_tracks_for_copy();
802
803
void _edit_menu_about_to_popup();
804
void _edit_menu_pressed(int p_option);
805
bool scale_from_cursor = false;
806
807
void _cleanup_animation(Ref<Animation> p_animation);
808
809
void _anim_duplicate_keys(float p_ofs, bool p_ofs_valid, int p_track);
810
811
void _anim_copy_keys(bool p_cut);
812
813
bool _is_track_compatible(int p_target_track_idx, Variant::Type p_source_value_type, Animation::TrackType p_source_track_type);
814
815
void _anim_paste_keys(float p_ofs, bool p_ofs_valid, int p_track);
816
817
void _toggle_function_names();
818
Button *function_name_toggler = nullptr;
819
820
void _view_group_toggle();
821
822
Button *view_group = nullptr;
823
Button *selected_filter = nullptr;
824
Button *alphabetic_sorting = nullptr;
825
826
void _auto_fit();
827
void _auto_fit_bezier();
828
829
void _selection_changed();
830
831
ConfirmationDialog *track_copy_dialog = nullptr;
832
Tree *track_copy_select = nullptr;
833
834
struct TrackClipboard {
835
NodePath full_path;
836
NodePath base_path;
837
Animation::TrackType track_type = Animation::TYPE_ANIMATION;
838
Animation::InterpolationType interp_type = Animation::INTERPOLATION_CUBIC_ANGLE;
839
Animation::UpdateMode update_mode = Animation::UPDATE_CAPTURE;
840
Animation::LoopMode loop_mode = Animation::LOOP_PINGPONG;
841
bool loop_wrap = false;
842
bool enabled = false;
843
bool use_blend = false;
844
845
struct Key {
846
float time = 0;
847
float transition = 0;
848
Variant value;
849
};
850
Vector<Key> keys;
851
};
852
853
struct KeyClipboard {
854
int top_track;
855
856
struct Key {
857
Animation::TrackType track_type;
858
int track;
859
float time = 0;
860
float transition = 0;
861
Variant value;
862
};
863
Vector<Key> keys;
864
};
865
866
Vector<TrackClipboard> track_clipboard;
867
KeyClipboard key_clipboard;
868
869
void _set_key_clipboard(int p_top_track, float p_top_time, RBMap<SelectedKey, KeyInfo> &p_keymap);
870
void _insert_animation_key(NodePath p_path, const Variant &p_value);
871
872
void _pick_track_filter_text_changed(const String &p_newtext);
873
void _pick_track_select_recursive(TreeItem *p_item, const String &p_filter, Vector<Node *> &p_select_candidates);
874
875
double snap_unit;
876
bool fps_compatible = true;
877
int nearest_fps = 0;
878
void _update_snap_unit();
879
880
protected:
881
static void _bind_methods();
882
void _notification(int p_what);
883
884
public:
885
// Public for use with callable_mp.
886
void _clear_selection(bool p_update = false);
887
void _key_selected(int p_key, bool p_single, int p_track);
888
void _key_deselected(int p_key, int p_track);
889
890
enum {
891
EDIT_COPY_TRACKS,
892
EDIT_COPY_TRACKS_CONFIRM,
893
EDIT_PASTE_TRACKS,
894
EDIT_CUT_KEYS,
895
EDIT_COPY_KEYS,
896
EDIT_PASTE_KEYS,
897
EDIT_SCALE_SELECTION,
898
EDIT_SCALE_FROM_CURSOR,
899
EDIT_SCALE_CONFIRM,
900
EDIT_SET_START_OFFSET,
901
EDIT_SET_END_OFFSET,
902
EDIT_EASE_SELECTION,
903
EDIT_EASE_CONFIRM,
904
EDIT_DUPLICATE_SELECTED_KEYS,
905
EDIT_DUPLICATE_SELECTION,
906
EDIT_DUPLICATE_TRANSPOSED,
907
EDIT_MOVE_FIRST_SELECTED_KEY_TO_CURSOR,
908
EDIT_MOVE_LAST_SELECTED_KEY_TO_CURSOR,
909
EDIT_ADD_RESET_KEY,
910
EDIT_DELETE_SELECTION,
911
EDIT_GOTO_NEXT_STEP,
912
EDIT_GOTO_NEXT_STEP_TIMELINE_ONLY, // Next step without updating animation.
913
EDIT_GOTO_PREV_STEP,
914
EDIT_APPLY_RESET,
915
EDIT_BAKE_ANIMATION,
916
EDIT_BAKE_ANIMATION_CONFIRM,
917
EDIT_OPTIMIZE_ANIMATION,
918
EDIT_OPTIMIZE_ANIMATION_CONFIRM,
919
EDIT_CLEAN_UP_ANIMATION,
920
EDIT_CLEAN_UP_ANIMATION_CONFIRM
921
};
922
923
void add_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
924
void remove_track_edit_plugin(const Ref<AnimationTrackEditPlugin> &p_plugin);
925
926
void set_animation(const Ref<Animation> &p_anim, bool p_read_only);
927
Ref<Animation> get_current_animation() const;
928
void set_root(Node *p_root);
929
Node *get_root() const;
930
void update_keying();
931
bool has_keying() const;
932
933
Dictionary get_state() const;
934
void set_state(const Dictionary &p_state);
935
void clear();
936
937
void cleanup();
938
939
void set_anim_pos(float p_pos);
940
void insert_node_value_key(Node *p_node, const String &p_property, bool p_only_if_exists = false, bool p_advance = false);
941
void insert_value_key(const String &p_property, bool p_advance);
942
void insert_transform_key(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type, const Variant &p_value);
943
bool has_track(Node3D *p_node, const String &p_sub, const Animation::TrackType p_type);
944
void make_insert_queue();
945
void commit_insert_queue();
946
947
void show_select_node_warning(bool p_show);
948
void show_dummy_player_warning(bool p_show);
949
void show_inactive_player_warning(bool p_show);
950
951
bool is_key_selected(int p_track, int p_key) const;
952
bool is_selection_active() const;
953
bool is_key_clipboard_active() const;
954
bool is_moving_selection() const;
955
bool is_snap_timeline_enabled() const;
956
bool is_snap_keys_enabled() const;
957
bool is_bezier_editor_active() const;
958
bool can_add_reset_key() const;
959
void _on_filter_updated(const String &p_filter);
960
float get_moving_selection_offset() const;
961
float snap_time(float p_value, bool p_relative = false);
962
float get_snap_unit();
963
bool is_grouping_tracks();
964
bool is_sorting_alphabetically();
965
PackedStringArray get_selected_section() const;
966
bool is_marker_selected(const StringName &p_marker) const;
967
bool is_marker_moving_selection() const;
968
float get_marker_moving_selection_offset() const;
969
bool is_function_name_pressed();
970
971
/** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
972
void goto_prev_step(bool p_from_mouse_event);
973
974
/** If `p_from_mouse_event` is `true`, handle Shift key presses for precise snapping. */
975
void goto_next_step(bool p_from_mouse_event, bool p_timeline_only = false);
976
977
MenuButton *get_edit_menu();
978
AnimationTrackEditor();
979
~AnimationTrackEditor();
980
};
981
982
// AnimationTrackKeyEditEditorPlugin
983
984
class AnimationTrackKeyEditEditor : public EditorProperty {
985
GDCLASS(AnimationTrackKeyEditEditor, EditorProperty);
986
987
Ref<Animation> animation;
988
int track = -1;
989
real_t key_ofs = 0.0;
990
bool use_fps = false;
991
992
EditorSpinSlider *spinner = nullptr;
993
994
struct KeyDataCache {
995
real_t time = 0.0;
996
float transition = 0.0;
997
Variant value;
998
} key_data_cache;
999
1000
void _time_edit_spun();
1001
void _time_edit_entered();
1002
void _time_edit_exited();
1003
1004
public:
1005
AnimationTrackKeyEditEditor(Ref<Animation> p_animation, int p_track, real_t p_key_ofs, bool p_use_fps);
1006
};
1007
1008
// AnimationMarkerKeyEditEditorPlugin
1009
1010
class AnimationMarkerKeyEditEditor : public EditorProperty {
1011
GDCLASS(AnimationMarkerKeyEditEditor, EditorProperty);
1012
1013
Ref<Animation> animation;
1014
StringName marker_name;
1015
bool use_fps = false;
1016
1017
EditorSpinSlider *spinner = nullptr;
1018
1019
void _time_edit_exited();
1020
1021
public:
1022
AnimationMarkerKeyEditEditor(Ref<Animation> p_animation, const StringName &p_name, bool p_use_fps);
1023
};
1024
1025