Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/animation/animation_player_editor_plugin.h
9896 views
1
/**************************************************************************/
2
/* animation_player_editor_plugin.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/animation/animation_library_editor.h"
34
#include "editor/animation/animation_track_editor.h"
35
#include "editor/plugins/editor_plugin.h"
36
#include "scene/animation/animation_player.h"
37
#include "scene/gui/dialogs.h"
38
#include "scene/gui/slider.h"
39
#include "scene/gui/spin_box.h"
40
#include "scene/gui/texture_button.h"
41
#include "scene/gui/tree.h"
42
43
class AnimationPlayerEditorPlugin;
44
class ImageTexture;
45
46
class AnimationPlayerEditor : public VBoxContainer {
47
GDCLASS(AnimationPlayerEditor, VBoxContainer);
48
49
friend AnimationPlayerEditorPlugin;
50
51
AnimationPlayerEditorPlugin *plugin = nullptr;
52
AnimationMixer *original_node = nullptr; // For pinned mark in SceneTree.
53
AnimationPlayer *player = nullptr; // For AnimationPlayerEditor, could be dummy.
54
ObjectID cached_root_node_id;
55
bool is_dummy = false;
56
57
enum {
58
TOOL_NEW_ANIM,
59
TOOL_ANIM_LIBRARY,
60
TOOL_DUPLICATE_ANIM,
61
TOOL_RENAME_ANIM,
62
TOOL_EDIT_TRANSITIONS,
63
TOOL_REMOVE_ANIM,
64
TOOL_EDIT_RESOURCE
65
};
66
67
enum {
68
ONION_SKINNING_ENABLE,
69
ONION_SKINNING_PAST,
70
ONION_SKINNING_FUTURE,
71
ONION_SKINNING_1_STEP,
72
ONION_SKINNING_2_STEPS,
73
ONION_SKINNING_3_STEPS,
74
ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
75
ONION_SKINNING_DIFFERENCES_ONLY,
76
ONION_SKINNING_FORCE_WHITE_MODULATE,
77
ONION_SKINNING_INCLUDE_GIZMOS,
78
};
79
80
enum {
81
ANIM_OPEN,
82
ANIM_SAVE,
83
ANIM_SAVE_AS
84
};
85
86
enum {
87
RESOURCE_LOAD,
88
RESOURCE_SAVE
89
};
90
91
OptionButton *animation = nullptr;
92
Button *stop = nullptr;
93
Button *play = nullptr;
94
Button *play_from = nullptr;
95
Button *play_bw = nullptr;
96
Button *play_bw_from = nullptr;
97
Button *autoplay = nullptr;
98
99
MenuButton *tool_anim = nullptr;
100
Button *onion_toggle = nullptr;
101
MenuButton *onion_skinning = nullptr;
102
Button *pin = nullptr;
103
SpinBox *frame = nullptr;
104
LineEdit *scale = nullptr;
105
LineEdit *name = nullptr;
106
OptionButton *library = nullptr;
107
Label *name_title = nullptr;
108
109
Ref<Texture2D> stop_icon;
110
Ref<Texture2D> pause_icon;
111
Ref<Texture2D> autoplay_icon;
112
Ref<Texture2D> reset_icon;
113
Ref<ImageTexture> autoplay_reset_icon;
114
115
bool finishing = false;
116
bool last_active = false;
117
float timeline_position = 0;
118
119
EditorFileDialog *file = nullptr;
120
ConfirmationDialog *delete_dialog = nullptr;
121
122
AnimationLibraryEditor *library_editor = nullptr;
123
124
struct BlendEditor {
125
AcceptDialog *dialog = nullptr;
126
Tree *tree = nullptr;
127
OptionButton *next = nullptr;
128
129
} blend_editor;
130
131
ConfirmationDialog *name_dialog = nullptr;
132
AcceptDialog *error_dialog = nullptr;
133
int name_dialog_op = TOOL_NEW_ANIM;
134
135
bool updating = false;
136
bool updating_blends = false;
137
138
AnimationTrackEditor *track_editor = nullptr;
139
static AnimationPlayerEditor *singleton;
140
141
// Onion skinning.
142
struct {
143
// Settings.
144
bool enabled = false;
145
bool past = true;
146
bool future = false;
147
uint32_t steps = 1;
148
bool differences_only = false;
149
bool force_white_modulate = false;
150
bool include_gizmos = false;
151
152
uint32_t get_capture_count() const {
153
// 'Differences only' needs a capture of the present.
154
return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
155
}
156
157
// Rendering.
158
int64_t last_frame = 0;
159
int can_overlay = 0;
160
Size2 capture_size;
161
LocalVector<RID> captures;
162
LocalVector<bool> captures_valid;
163
struct {
164
RID canvas;
165
RID canvas_item;
166
Ref<ShaderMaterial> material;
167
Ref<Shader> shader;
168
} capture;
169
170
// Cross-call state.
171
struct {
172
double anim_player_position = 0.0;
173
Ref<AnimatedValuesBackup> anim_values_backup;
174
Rect2 screen_rect;
175
Dictionary canvas_edit_state;
176
Dictionary spatial_edit_state;
177
} temp;
178
} onion;
179
180
void _select_anim_by_name(const String &p_anim);
181
float _get_editor_step() const;
182
void _go_to_nearest_keyframe(bool p_backward);
183
void _play_pressed();
184
void _play_from_pressed();
185
void _play_bw_pressed();
186
void _play_bw_from_pressed();
187
void _autoplay_pressed();
188
void _stop_pressed();
189
void _animation_selected(int p_which);
190
void _animation_new();
191
void _animation_rename();
192
void _animation_name_edited();
193
194
void _animation_remove();
195
void _animation_remove_confirmed();
196
void _animation_edit();
197
void _animation_duplicate();
198
Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
199
void _animation_resource_edit();
200
void _scale_changed(const String &p_scale);
201
void _seek_value_changed(float p_value, bool p_timeline_only = false);
202
void _blend_editor_next_changed(const int p_idx);
203
204
void _edit_animation_blend();
205
void _update_animation_blend();
206
207
void _list_changed();
208
void _animation_finished(const String &p_name);
209
void _current_animation_changed(const String &p_name);
210
void _update_animation();
211
void _update_player();
212
void _set_controls_disabled(bool p_disabled);
213
void _update_animation_list_icons();
214
void _update_name_dialog_library_dropdown();
215
void _blend_edited();
216
217
void _animation_player_changed(Object *p_pl);
218
void _animation_libraries_updated();
219
220
void _animation_key_editor_seek(float p_pos, bool p_timeline_only = false, bool p_update_position_only = false);
221
void _animation_key_editor_anim_len_changed(float p_len);
222
void _animation_update_key_frame();
223
224
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
225
void _animation_tool_menu(int p_option);
226
void _onion_skinning_menu(int p_option);
227
228
void _editor_visibility_changed();
229
bool _are_onion_layers_valid();
230
void _allocate_onion_layers();
231
void _free_onion_layers();
232
void _prepare_onion_layers_1();
233
void _prepare_onion_layers_2_prolog();
234
void _prepare_onion_layers_2_step_prepare(int p_step_offset, uint32_t p_capture_idx);
235
void _prepare_onion_layers_2_step_capture(int p_step_offset, uint32_t p_capture_idx);
236
void _prepare_onion_layers_2_epilog();
237
void _start_onion_skinning();
238
void _stop_onion_skinning();
239
240
bool _validate_tracks(const Ref<Animation> p_anim);
241
242
void _pin_pressed();
243
String _get_current() const;
244
245
void _ensure_dummy_player();
246
247
~AnimationPlayerEditor();
248
249
protected:
250
void _notification(int p_what);
251
void _node_removed(Node *p_node);
252
static void _bind_methods();
253
254
public:
255
AnimationMixer *get_editing_node() const;
256
AnimationPlayer *get_player() const;
257
AnimationMixer *fetch_mixer_for_library() const;
258
Node *get_cached_root_node() const;
259
260
static AnimationPlayerEditor *get_singleton() { return singleton; }
261
262
bool is_pinned() const { return pin->is_pressed(); }
263
void unpin() {
264
pin->set_pressed(false);
265
_pin_pressed();
266
}
267
AnimationTrackEditor *get_track_editor() { return track_editor; }
268
Dictionary get_state() const;
269
void set_state(const Dictionary &p_state);
270
void clear();
271
272
void ensure_visibility();
273
274
void edit(AnimationMixer *p_node, AnimationPlayer *p_player, bool p_is_dummy);
275
void forward_force_draw_over_viewport(Control *p_overlay);
276
277
AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);
278
};
279
280
class AnimationPlayerEditorPlugin : public EditorPlugin {
281
GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
282
283
friend AnimationPlayerEditor;
284
285
AnimationPlayerEditor *anim_editor = nullptr;
286
AnimationPlayer *player = nullptr;
287
AnimationPlayer *dummy_player = nullptr;
288
ObjectID last_mixer;
289
290
void _update_dummy_player(AnimationMixer *p_mixer);
291
void _clear_dummy_player();
292
293
protected:
294
void _notification(int p_what);
295
296
void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);
297
void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);
298
void _update_keying();
299
300
public:
301
virtual Dictionary get_state() const override { return anim_editor->get_state(); }
302
virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
303
virtual void clear() override { anim_editor->clear(); }
304
305
virtual String get_plugin_name() const override { return "Anim"; }
306
bool has_main_screen() const override { return false; }
307
virtual void edit(Object *p_object) override;
308
virtual bool handles(Object *p_object) const override;
309
virtual void make_visible(bool p_visible) override;
310
311
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
312
virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
313
314
AnimationPlayerEditorPlugin();
315
~AnimationPlayerEditorPlugin();
316
};
317
318
// AnimationTrackKeyEditEditorPlugin
319
320
class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin {
321
GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin);
322
323
AnimationTrackKeyEditEditor *atk_editor = nullptr;
324
325
public:
326
virtual bool can_handle(Object *p_object) override;
327
virtual void parse_begin(Object *p_object) override;
328
};
329
330
class AnimationTrackKeyEditEditorPlugin : public EditorPlugin {
331
GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin);
332
333
EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr;
334
335
public:
336
bool has_main_screen() const override { return false; }
337
virtual bool handles(Object *p_object) const override;
338
339
virtual String get_plugin_name() const override { return "AnimationTrackKeyEdit"; }
340
341
AnimationTrackKeyEditEditorPlugin();
342
};
343
344
// AnimationMarkerKeyEditEditorPlugin
345
346
class EditorInspectorPluginAnimationMarkerKeyEdit : public EditorInspectorPlugin {
347
GDCLASS(EditorInspectorPluginAnimationMarkerKeyEdit, EditorInspectorPlugin);
348
349
AnimationMarkerKeyEditEditor *amk_editor = nullptr;
350
351
public:
352
virtual bool can_handle(Object *p_object) override;
353
virtual void parse_begin(Object *p_object) override;
354
};
355
356
class AnimationMarkerKeyEditEditorPlugin : public EditorPlugin {
357
GDCLASS(AnimationMarkerKeyEditEditorPlugin, EditorPlugin);
358
359
EditorInspectorPluginAnimationMarkerKeyEdit *amk_plugin = nullptr;
360
361
public:
362
bool has_main_screen() const override { return false; }
363
virtual bool handles(Object *p_object) const override;
364
365
virtual String get_plugin_name() const override { return "AnimationMarkerKeyEdit"; }
366
367
AnimationMarkerKeyEditEditorPlugin();
368
};
369
370