| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 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 |
|
| 44 |
class AnimationPlayerEditorPlugin; |
| 45 |
class ImageTexture; |
| 46 |
|
| 47 |
class AnimationPlayerEditor : public EditorDock { |
| 48 |
GDCLASS(AnimationPlayerEditor, EditorDock); |
| 49 |
|
| 50 |
friend AnimationPlayerEditorPlugin; |
| 51 |
|
| 52 |
AnimationPlayerEditorPlugin *plugin = nullptr; |
| 53 |
AnimationMixer *original_node = nullptr; |
| 54 |
AnimationPlayer *player = nullptr; |
| 55 |
ObjectID cached_root_node_id; |
| 56 |
bool is_dummy = false; |
| 57 |
|
| 58 |
enum { |
| 59 |
TOOL_NEW_ANIM, |
| 60 |
TOOL_ANIM_LIBRARY, |
| 61 |
TOOL_DUPLICATE_ANIM, |
| 62 |
TOOL_RENAME_ANIM, |
| 63 |
TOOL_EDIT_TRANSITIONS, |
| 64 |
TOOL_REMOVE_ANIM, |
| 65 |
TOOL_EDIT_RESOURCE |
| 66 |
}; |
| 67 |
|
| 68 |
enum { |
| 69 |
ONION_SKINNING_ENABLE, |
| 70 |
ONION_SKINNING_PAST, |
| 71 |
ONION_SKINNING_FUTURE, |
| 72 |
ONION_SKINNING_1_STEP, |
| 73 |
ONION_SKINNING_2_STEPS, |
| 74 |
ONION_SKINNING_3_STEPS, |
| 75 |
ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS, |
| 76 |
ONION_SKINNING_DIFFERENCES_ONLY, |
| 77 |
ONION_SKINNING_FORCE_WHITE_MODULATE, |
| 78 |
ONION_SKINNING_INCLUDE_GIZMOS, |
| 79 |
}; |
| 80 |
|
| 81 |
enum { |
| 82 |
ANIM_OPEN, |
| 83 |
ANIM_SAVE, |
| 84 |
ANIM_SAVE_AS |
| 85 |
}; |
| 86 |
|
| 87 |
enum { |
| 88 |
RESOURCE_LOAD, |
| 89 |
RESOURCE_SAVE |
| 90 |
}; |
| 91 |
|
| 92 |
OptionButton *animation = nullptr; |
| 93 |
Button *stop = nullptr; |
| 94 |
Button *play = nullptr; |
| 95 |
Button *play_from = nullptr; |
| 96 |
Button *play_bw = nullptr; |
| 97 |
Button *play_bw_from = nullptr; |
| 98 |
Button *autoplay = nullptr; |
| 99 |
|
| 100 |
MenuButton *tool_anim = nullptr; |
| 101 |
Button *onion_toggle = nullptr; |
| 102 |
MenuButton *onion_skinning = nullptr; |
| 103 |
Button *pin = nullptr; |
| 104 |
SpinBox *frame = nullptr; |
| 105 |
LineEdit *scale = nullptr; |
| 106 |
LineEdit *name = nullptr; |
| 107 |
OptionButton *library = nullptr; |
| 108 |
Label *name_title = nullptr; |
| 109 |
|
| 110 |
Ref<Texture2D> stop_icon; |
| 111 |
Ref<Texture2D> pause_icon; |
| 112 |
Ref<Texture2D> autoplay_icon; |
| 113 |
Ref<Texture2D> reset_icon; |
| 114 |
Ref<ImageTexture> autoplay_reset_icon; |
| 115 |
|
| 116 |
bool finishing = false; |
| 117 |
bool last_active = false; |
| 118 |
float timeline_position = 0; |
| 119 |
|
| 120 |
EditorFileDialog *file = nullptr; |
| 121 |
ConfirmationDialog *delete_dialog = nullptr; |
| 122 |
|
| 123 |
AnimationLibraryEditor *library_editor = nullptr; |
| 124 |
|
| 125 |
struct BlendEditor { |
| 126 |
AcceptDialog *dialog = nullptr; |
| 127 |
Tree *tree = nullptr; |
| 128 |
OptionButton *next = nullptr; |
| 129 |
|
| 130 |
} blend_editor; |
| 131 |
|
| 132 |
ConfirmationDialog *name_dialog = nullptr; |
| 133 |
AcceptDialog *error_dialog = nullptr; |
| 134 |
int name_dialog_op = TOOL_NEW_ANIM; |
| 135 |
|
| 136 |
bool updating = false; |
| 137 |
bool updating_blends = false; |
| 138 |
|
| 139 |
AnimationTrackEditor *track_editor = nullptr; |
| 140 |
static AnimationPlayerEditor *singleton; |
| 141 |
|
| 142 |
|
| 143 |
struct { |
| 144 |
|
| 145 |
bool enabled = false; |
| 146 |
bool past = true; |
| 147 |
bool future = false; |
| 148 |
uint32_t steps = 1; |
| 149 |
bool differences_only = false; |
| 150 |
bool force_white_modulate = false; |
| 151 |
bool include_gizmos = false; |
| 152 |
|
| 153 |
uint32_t get_capture_count() const { |
| 154 |
|
| 155 |
return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
int64_t last_frame = 0; |
| 160 |
int can_overlay = 0; |
| 161 |
Size2 capture_size; |
| 162 |
LocalVector<RID> captures; |
| 163 |
LocalVector<bool> captures_valid; |
| 164 |
struct { |
| 165 |
RID canvas; |
| 166 |
RID canvas_item; |
| 167 |
Ref<ShaderMaterial> material; |
| 168 |
Ref<Shader> shader; |
| 169 |
} capture; |
| 170 |
|
| 171 |
|
| 172 |
struct { |
| 173 |
double anim_player_position = 0.0; |
| 174 |
Ref<AnimatedValuesBackup> anim_values_backup; |
| 175 |
Rect2 screen_rect; |
| 176 |
Dictionary canvas_edit_state; |
| 177 |
Dictionary spatial_edit_state; |
| 178 |
} temp; |
| 179 |
} onion; |
| 180 |
|
| 181 |
void _select_anim_by_name(const String &p_anim); |
| 182 |
float _get_editor_step() const; |
| 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 StringName &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 _update_playback_tooltips(); |
| 216 |
void _blend_edited(); |
| 217 |
|
| 218 |
void _animation_player_changed(Object *p_pl); |
| 219 |
void _animation_libraries_updated(); |
| 220 |
|
| 221 |
void _animation_key_editor_seek(float p_pos, bool p_timeline_only = false, bool p_update_position_only = false); |
| 222 |
void _animation_key_editor_anim_len_changed(float p_len); |
| 223 |
void _animation_update_key_frame(); |
| 224 |
|
| 225 |
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override; |
| 226 |
void _animation_tool_menu(int p_option); |
| 227 |
void _onion_skinning_menu(int p_option); |
| 228 |
|
| 229 |
void _editor_visibility_changed(); |
| 230 |
bool _are_onion_layers_valid(); |
| 231 |
void _allocate_onion_layers(); |
| 232 |
void _free_onion_layers(); |
| 233 |
void _prepare_onion_layers_1(); |
| 234 |
void _prepare_onion_layers_2_prolog(); |
| 235 |
void _prepare_onion_layers_2_step_prepare(int p_step_offset, uint32_t p_capture_idx); |
| 236 |
void _prepare_onion_layers_2_step_capture(int p_step_offset, uint32_t p_capture_idx); |
| 237 |
void _prepare_onion_layers_2_epilog(); |
| 238 |
void _start_onion_skinning(); |
| 239 |
void _stop_onion_skinning(); |
| 240 |
|
| 241 |
bool _validate_tracks(const Ref<Animation> p_anim); |
| 242 |
|
| 243 |
void _pin_pressed(); |
| 244 |
String _get_current() const; |
| 245 |
|
| 246 |
void _ensure_dummy_player(); |
| 247 |
|
| 248 |
~AnimationPlayerEditor(); |
| 249 |
|
| 250 |
protected: |
| 251 |
void _notification(int p_what); |
| 252 |
void _node_removed(Node *p_node); |
| 253 |
void _find_player(); |
| 254 |
static void _bind_methods(); |
| 255 |
|
| 256 |
public: |
| 257 |
AnimationMixer *get_editing_node() const; |
| 258 |
AnimationPlayer *get_player() const; |
| 259 |
AnimationMixer *fetch_mixer_for_library() const; |
| 260 |
Node *get_cached_root_node() const; |
| 261 |
|
| 262 |
static AnimationPlayerEditor *get_singleton() { return singleton; } |
| 263 |
|
| 264 |
bool is_pinned() const { return pin->is_pressed(); } |
| 265 |
void unpin() { |
| 266 |
pin->set_pressed(false); |
| 267 |
_pin_pressed(); |
| 268 |
} |
| 269 |
AnimationTrackEditor *get_track_editor() { return track_editor; } |
| 270 |
Dictionary get_state() const; |
| 271 |
void set_state(const Dictionary &p_state); |
| 272 |
void clear(); |
| 273 |
|
| 274 |
void ensure_visibility(); |
| 275 |
void go_to_nearest_keyframe(bool p_backward); |
| 276 |
|
| 277 |
void edit(AnimationMixer *p_node, AnimationPlayer *p_player, bool p_is_dummy); |
| 278 |
void forward_force_draw_over_viewport(Control *p_overlay); |
| 279 |
|
| 280 |
AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin); |
| 281 |
}; |
| 282 |
|
| 283 |
class AnimationPlayerEditorPlugin : public EditorPlugin { |
| 284 |
GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin); |
| 285 |
|
| 286 |
friend AnimationPlayerEditor; |
| 287 |
|
| 288 |
AnimationPlayerEditor *anim_editor = nullptr; |
| 289 |
AnimationPlayer *player = nullptr; |
| 290 |
AnimationPlayer *dummy_player = nullptr; |
| 291 |
ObjectID last_mixer; |
| 292 |
|
| 293 |
void _update_dummy_player(AnimationMixer *p_mixer); |
| 294 |
void _clear_dummy_player(); |
| 295 |
|
| 296 |
protected: |
| 297 |
void _notification(int p_what); |
| 298 |
|
| 299 |
void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance); |
| 300 |
void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key); |
| 301 |
void _update_keying(); |
| 302 |
|
| 303 |
public: |
| 304 |
virtual Dictionary get_state() const override { return anim_editor->get_state(); } |
| 305 |
virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); } |
| 306 |
virtual void clear() override { anim_editor->clear(); } |
| 307 |
|
| 308 |
virtual String get_plugin_name() const override { return "Anim"; } |
| 309 |
bool has_main_screen() const override { return false; } |
| 310 |
virtual void edit(Object *p_object) override; |
| 311 |
virtual bool handles(Object *p_object) const override; |
| 312 |
virtual void make_visible(bool p_visible) override; |
| 313 |
|
| 314 |
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); } |
| 315 |
virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); } |
| 316 |
|
| 317 |
AnimationPlayerEditorPlugin(); |
| 318 |
~AnimationPlayerEditorPlugin(); |
| 319 |
}; |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin { |
| 324 |
GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin); |
| 325 |
|
| 326 |
AnimationTrackKeyEditEditor *atk_editor = nullptr; |
| 327 |
|
| 328 |
public: |
| 329 |
virtual bool can_handle(Object *p_object) override; |
| 330 |
virtual void parse_begin(Object *p_object) override; |
| 331 |
}; |
| 332 |
|
| 333 |
class AnimationTrackKeyEditEditorPlugin : public EditorPlugin { |
| 334 |
GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin); |
| 335 |
|
| 336 |
EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr; |
| 337 |
|
| 338 |
public: |
| 339 |
bool has_main_screen() const override { return false; } |
| 340 |
virtual bool handles(Object *p_object) const override; |
| 341 |
|
| 342 |
virtual String get_plugin_name() const override { return "AnimationTrackKeyEdit"; } |
| 343 |
|
| 344 |
AnimationTrackKeyEditEditorPlugin(); |
| 345 |
}; |
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
class EditorInspectorPluginAnimationMarkerKeyEdit : public EditorInspectorPlugin { |
| 350 |
GDCLASS(EditorInspectorPluginAnimationMarkerKeyEdit, EditorInspectorPlugin); |
| 351 |
|
| 352 |
AnimationMarkerKeyEditEditor *amk_editor = nullptr; |
| 353 |
|
| 354 |
public: |
| 355 |
virtual bool can_handle(Object *p_object) override; |
| 356 |
virtual void parse_begin(Object *p_object) override; |
| 357 |
}; |
| 358 |
|
| 359 |
class AnimationMarkerKeyEditEditorPlugin : public EditorPlugin { |
| 360 |
GDCLASS(AnimationMarkerKeyEditEditorPlugin, EditorPlugin); |
| 361 |
|
| 362 |
EditorInspectorPluginAnimationMarkerKeyEdit *amk_plugin = nullptr; |
| 363 |
|
| 364 |
public: |
| 365 |
bool has_main_screen() const override { return false; } |
| 366 |
virtual bool handles(Object *p_object) const override; |
| 367 |
|
| 368 |
virtual String get_plugin_name() const override { return "AnimationMarkerKeyEdit"; } |
| 369 |
|
| 370 |
AnimationMarkerKeyEditEditorPlugin(); |
| 371 |
}; |