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