2023-01-05 12:25:55 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* animation_player_editor_plugin.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
2018-01-04 23:50:27 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#ifndef ANIMATION_PLAYER_EDITOR_PLUGIN_H
|
|
|
|
#define ANIMATION_PLAYER_EDITOR_PLUGIN_H
|
|
|
|
|
2022-02-14 13:00:03 +00:00
|
|
|
#include "editor/animation_track_editor.h"
|
2017-03-05 13:21:25 +00:00
|
|
|
#include "editor/editor_plugin.h"
|
2022-04-07 11:49:28 +00:00
|
|
|
#include "editor/plugins/animation_library_editor.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
#include "scene/animation/animation_player.h"
|
|
|
|
#include "scene/gui/dialogs.h"
|
|
|
|
#include "scene/gui/slider.h"
|
|
|
|
#include "scene/gui/spin_box.h"
|
|
|
|
#include "scene/gui/texture_button.h"
|
2022-02-12 01:46:22 +00:00
|
|
|
#include "scene/gui/tree.h"
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-10-30 18:43:19 +00:00
|
|
|
class AnimationPlayerEditorPlugin;
|
2023-07-11 20:29:09 +00:00
|
|
|
class ImageTexture;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
class AnimationPlayerEditor : public VBoxContainer {
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(AnimationPlayerEditor, VBoxContainer);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
friend AnimationPlayerEditorPlugin;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
AnimationPlayerEditorPlugin *plugin = nullptr;
|
2023-07-20 15:34:06 +00:00
|
|
|
AnimationMixer *original_node = nullptr; // For pinned mark in SceneTree.
|
|
|
|
AnimationPlayer *player = nullptr; // For AnimationPlayerEditor, could be dummy.
|
|
|
|
bool is_dummy = false;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2015-05-25 04:46:45 +00:00
|
|
|
enum {
|
2018-06-07 15:46:14 +00:00
|
|
|
TOOL_NEW_ANIM,
|
2022-04-07 11:49:28 +00:00
|
|
|
TOOL_ANIM_LIBRARY,
|
2018-06-07 15:46:14 +00:00
|
|
|
TOOL_DUPLICATE_ANIM,
|
|
|
|
TOOL_RENAME_ANIM,
|
|
|
|
TOOL_EDIT_TRANSITIONS,
|
|
|
|
TOOL_REMOVE_ANIM,
|
2015-05-25 04:46:45 +00:00
|
|
|
TOOL_EDIT_RESOURCE
|
|
|
|
};
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-10-30 18:43:19 +00:00
|
|
|
enum {
|
|
|
|
ONION_SKINNING_ENABLE,
|
|
|
|
ONION_SKINNING_PAST,
|
|
|
|
ONION_SKINNING_FUTURE,
|
|
|
|
ONION_SKINNING_1_STEP,
|
|
|
|
ONION_SKINNING_2_STEPS,
|
|
|
|
ONION_SKINNING_3_STEPS,
|
|
|
|
ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
|
|
|
|
ONION_SKINNING_DIFFERENCES_ONLY,
|
|
|
|
ONION_SKINNING_FORCE_WHITE_MODULATE,
|
|
|
|
ONION_SKINNING_INCLUDE_GIZMOS,
|
|
|
|
};
|
|
|
|
|
2015-10-19 19:40:24 +00:00
|
|
|
enum {
|
2018-06-07 15:46:14 +00:00
|
|
|
ANIM_OPEN,
|
2015-10-19 19:40:24 +00:00
|
|
|
ANIM_SAVE,
|
|
|
|
ANIM_SAVE_AS
|
|
|
|
};
|
|
|
|
|
|
|
|
enum {
|
|
|
|
RESOURCE_LOAD,
|
|
|
|
RESOURCE_SAVE
|
|
|
|
};
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
OptionButton *animation = nullptr;
|
|
|
|
Button *stop = nullptr;
|
|
|
|
Button *play = nullptr;
|
|
|
|
Button *play_from = nullptr;
|
|
|
|
Button *play_bw = nullptr;
|
|
|
|
Button *play_bw_from = nullptr;
|
|
|
|
Button *autoplay = nullptr;
|
|
|
|
|
|
|
|
MenuButton *tool_anim = nullptr;
|
|
|
|
Button *onion_toggle = nullptr;
|
|
|
|
MenuButton *onion_skinning = nullptr;
|
|
|
|
Button *pin = nullptr;
|
|
|
|
SpinBox *frame = nullptr;
|
|
|
|
LineEdit *scale = nullptr;
|
|
|
|
LineEdit *name = nullptr;
|
2022-04-07 11:49:28 +00:00
|
|
|
OptionButton *library = nullptr;
|
2022-04-04 13:06:57 +00:00
|
|
|
Label *name_title = nullptr;
|
2022-04-07 11:49:28 +00:00
|
|
|
|
2019-11-19 13:39:10 +00:00
|
|
|
Ref<Texture2D> stop_icon;
|
|
|
|
Ref<Texture2D> pause_icon;
|
2019-06-11 18:43:37 +00:00
|
|
|
Ref<Texture2D> autoplay_icon;
|
2020-12-20 10:46:44 +00:00
|
|
|
Ref<Texture2D> reset_icon;
|
|
|
|
Ref<ImageTexture> autoplay_reset_icon;
|
2014-02-10 01:10:30 +00:00
|
|
|
bool last_active;
|
2019-10-01 16:38:03 +00:00
|
|
|
float timeline_position;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
EditorFileDialog *file = nullptr;
|
|
|
|
ConfirmationDialog *delete_dialog = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-04-07 11:49:28 +00:00
|
|
|
AnimationLibraryEditor *library_editor = nullptr;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
struct BlendEditor {
|
2020-11-24 09:12:55 +00:00
|
|
|
AcceptDialog *dialog = nullptr;
|
|
|
|
Tree *tree = nullptr;
|
|
|
|
OptionButton *next = nullptr;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
} blend_editor;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
ConfirmationDialog *name_dialog = nullptr;
|
|
|
|
ConfirmationDialog *error_dialog = nullptr;
|
2022-02-14 06:28:42 +00:00
|
|
|
int name_dialog_op = TOOL_NEW_ANIM;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
bool updating;
|
|
|
|
bool updating_blends;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
AnimationTrackEditor *track_editor = nullptr;
|
2021-02-04 08:20:26 +00:00
|
|
|
static AnimationPlayerEditor *singleton;
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2019-09-04 05:20:57 +00:00
|
|
|
// Onion skinning.
|
2017-10-30 18:43:19 +00:00
|
|
|
struct {
|
2019-09-04 05:20:57 +00:00
|
|
|
// Settings.
|
2020-11-24 09:12:55 +00:00
|
|
|
bool enabled = false;
|
2023-09-27 14:37:26 +00:00
|
|
|
bool past = true;
|
2020-11-24 09:12:55 +00:00
|
|
|
bool future = false;
|
2023-09-27 14:37:26 +00:00
|
|
|
uint32_t steps = 1;
|
2020-11-24 09:12:55 +00:00
|
|
|
bool differences_only = false;
|
|
|
|
bool force_white_modulate = false;
|
|
|
|
bool include_gizmos = false;
|
2017-10-30 18:43:19 +00:00
|
|
|
|
2023-09-27 14:37:26 +00:00
|
|
|
uint32_t get_capture_count() const {
|
2019-09-04 05:20:57 +00:00
|
|
|
// 'Differences only' needs a capture of the present.
|
2017-10-30 18:43:19 +00:00
|
|
|
return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2019-09-04 05:20:57 +00:00
|
|
|
// Rendering.
|
2020-11-24 09:12:55 +00:00
|
|
|
int64_t last_frame = 0;
|
|
|
|
int can_overlay = 0;
|
2017-10-30 18:43:19 +00:00
|
|
|
Size2 capture_size;
|
2023-09-27 14:37:26 +00:00
|
|
|
LocalVector<RID> captures;
|
|
|
|
LocalVector<bool> captures_valid;
|
2017-10-30 18:43:19 +00:00
|
|
|
struct {
|
|
|
|
RID canvas;
|
|
|
|
RID canvas_item;
|
|
|
|
Ref<ShaderMaterial> material;
|
|
|
|
Ref<Shader> shader;
|
|
|
|
} capture;
|
2023-09-27 14:37:26 +00:00
|
|
|
|
|
|
|
// Cross-call state.
|
|
|
|
struct {
|
|
|
|
double anim_player_position = 0.0;
|
|
|
|
Ref<AnimatedValuesBackup> anim_values_backup;
|
|
|
|
Rect2 screen_rect;
|
|
|
|
Dictionary canvas_edit_state;
|
|
|
|
Dictionary spatial_edit_state;
|
|
|
|
} temp;
|
2017-10-30 18:43:19 +00:00
|
|
|
} onion;
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _select_anim_by_name(const String &p_anim);
|
2022-12-08 12:38:01 +00:00
|
|
|
float _get_editor_step() const;
|
2014-02-10 01:10:30 +00:00
|
|
|
void _play_pressed();
|
2015-05-25 04:46:45 +00:00
|
|
|
void _play_from_pressed();
|
|
|
|
void _play_bw_pressed();
|
|
|
|
void _play_bw_from_pressed();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _autoplay_pressed();
|
|
|
|
void _stop_pressed();
|
|
|
|
void _animation_selected(int p_which);
|
|
|
|
void _animation_new();
|
|
|
|
void _animation_rename();
|
|
|
|
void _animation_name_edited();
|
2015-10-19 19:40:24 +00:00
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void _animation_remove();
|
2017-01-25 20:22:16 +00:00
|
|
|
void _animation_remove_confirmed();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _animation_blend();
|
|
|
|
void _animation_edit();
|
|
|
|
void _animation_duplicate();
|
2019-11-02 00:52:54 +00:00
|
|
|
Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _animation_resource_edit();
|
|
|
|
void _scale_changed(const String &p_scale);
|
2020-07-14 23:05:04 +00:00
|
|
|
void _seek_value_changed(float p_value, bool p_set = false, bool p_timeline_only = false);
|
2016-05-07 16:27:52 +00:00
|
|
|
void _blend_editor_next_changed(const int p_idx);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
void _list_changed();
|
2023-07-20 15:34:06 +00:00
|
|
|
void _current_animation_changed(const String &p_name);
|
2014-02-10 01:10:30 +00:00
|
|
|
void _update_animation();
|
|
|
|
void _update_player();
|
2022-03-10 05:46:05 +00:00
|
|
|
void _update_animation_list_icons();
|
2022-05-14 16:54:14 +00:00
|
|
|
void _update_name_dialog_library_dropdown();
|
2014-02-10 01:10:30 +00:00
|
|
|
void _blend_edited();
|
|
|
|
|
|
|
|
void _animation_player_changed(Object *p_pl);
|
2022-05-05 03:53:47 +00:00
|
|
|
void _animation_libraries_updated();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2020-07-14 23:05:04 +00:00
|
|
|
void _animation_key_editor_seek(float p_pos, bool p_drag, bool p_timeline_only = false);
|
2017-08-12 16:52:50 +00:00
|
|
|
void _animation_key_editor_anim_len_changed(float p_len);
|
2016-01-17 23:03:57 +00:00
|
|
|
|
2022-01-11 13:59:52 +00:00
|
|
|
virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
|
2015-05-25 04:46:45 +00:00
|
|
|
void _animation_tool_menu(int p_option);
|
2017-10-30 18:43:19 +00:00
|
|
|
void _onion_skinning_menu(int p_option);
|
|
|
|
|
|
|
|
void _editor_visibility_changed();
|
|
|
|
bool _are_onion_layers_valid();
|
|
|
|
void _allocate_onion_layers();
|
|
|
|
void _free_onion_layers();
|
|
|
|
void _prepare_onion_layers_1();
|
2023-09-27 14:37:26 +00:00
|
|
|
void _prepare_onion_layers_2_prolog();
|
|
|
|
void _prepare_onion_layers_2_step_prepare(int p_step_offset, uint32_t p_capture_idx);
|
|
|
|
void _prepare_onion_layers_2_step_capture(int p_step_offset, uint32_t p_capture_idx);
|
|
|
|
void _prepare_onion_layers_2_epilog();
|
2017-10-30 18:43:19 +00:00
|
|
|
void _start_onion_skinning();
|
|
|
|
void _stop_onion_skinning();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2022-11-17 06:24:00 +00:00
|
|
|
bool _validate_tracks(const Ref<Animation> p_anim);
|
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
void _pin_pressed();
|
2022-04-07 11:49:28 +00:00
|
|
|
String _get_current() const;
|
2018-06-07 15:46:14 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
void _ensure_dummy_player();
|
|
|
|
|
2017-10-30 18:43:19 +00:00
|
|
|
~AnimationPlayerEditor();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
void _node_removed(Node *p_node);
|
|
|
|
static void _bind_methods();
|
|
|
|
|
2017-03-05 15:44:50 +00:00
|
|
|
public:
|
2023-07-20 15:34:06 +00:00
|
|
|
AnimationMixer *get_editing_node() const;
|
2015-12-05 17:18:22 +00:00
|
|
|
AnimationPlayer *get_player() const;
|
2023-07-20 15:34:06 +00:00
|
|
|
AnimationMixer *fetch_mixer_for_library() const;
|
2021-02-04 08:20:26 +00:00
|
|
|
|
|
|
|
static AnimationPlayerEditor *get_singleton() { return singleton; }
|
2015-12-05 17:18:22 +00:00
|
|
|
|
2018-06-07 15:46:14 +00:00
|
|
|
bool is_pinned() const { return pin->is_pressed(); }
|
2023-07-20 15:34:06 +00:00
|
|
|
void unpin() {
|
|
|
|
pin->set_pressed(false);
|
|
|
|
_pin_pressed();
|
|
|
|
}
|
2018-06-07 15:46:14 +00:00
|
|
|
AnimationTrackEditor *get_track_editor() { return track_editor; }
|
2015-08-30 01:59:25 +00:00
|
|
|
Dictionary get_state() const;
|
|
|
|
void set_state(const Dictionary &p_state);
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
void ensure_visibility();
|
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
void edit(AnimationMixer *p_node, AnimationPlayer *p_player, bool p_is_dummy);
|
2021-09-14 12:51:50 +00:00
|
|
|
void forward_force_draw_over_viewport(Control *p_overlay);
|
2017-10-30 18:43:19 +00:00
|
|
|
|
2022-01-27 09:36:51 +00:00
|
|
|
AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);
|
2014-02-10 01:10:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class AnimationPlayerEditorPlugin : public EditorPlugin {
|
2017-01-03 02:03:46 +00:00
|
|
|
GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2023-07-20 15:34:06 +00:00
|
|
|
friend AnimationPlayerEditor;
|
|
|
|
|
2022-04-04 13:06:57 +00:00
|
|
|
AnimationPlayerEditor *anim_editor = nullptr;
|
2023-07-20 15:34:06 +00:00
|
|
|
AnimationPlayer *player = nullptr;
|
|
|
|
AnimationPlayer *dummy_player = nullptr;
|
|
|
|
ObjectID last_mixer;
|
|
|
|
|
|
|
|
void _update_dummy_player(AnimationMixer *p_mixer);
|
|
|
|
void _clear_dummy_player();
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2017-10-30 18:43:19 +00:00
|
|
|
protected:
|
|
|
|
void _notification(int p_what);
|
|
|
|
|
2021-12-02 11:01:38 +00:00
|
|
|
void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);
|
|
|
|
void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);
|
|
|
|
void _update_keying();
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
public:
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual Dictionary get_state() const override { return anim_editor->get_state(); }
|
|
|
|
virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
|
2015-08-30 01:59:25 +00:00
|
|
|
|
2020-07-10 10:34:39 +00:00
|
|
|
virtual String get_name() const override { return "Anim"; }
|
|
|
|
bool has_main_screen() const override { return false; }
|
|
|
|
virtual void edit(Object *p_object) override;
|
|
|
|
virtual bool handles(Object *p_object) const override;
|
|
|
|
virtual void make_visible(bool p_visible) override;
|
2014-02-10 01:10:30 +00:00
|
|
|
|
2021-09-14 12:51:50 +00:00
|
|
|
virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
|
2022-09-08 16:38:33 +00:00
|
|
|
virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
|
2017-10-30 18:43:19 +00:00
|
|
|
|
2022-01-27 09:36:51 +00:00
|
|
|
AnimationPlayerEditorPlugin();
|
2014-02-10 01:10:30 +00:00
|
|
|
~AnimationPlayerEditorPlugin();
|
|
|
|
};
|
|
|
|
|
2022-12-08 12:38:01 +00:00
|
|
|
// AnimationTrackKeyEditEditorPlugin
|
|
|
|
|
|
|
|
class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin {
|
|
|
|
GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin);
|
|
|
|
|
|
|
|
AnimationTrackKeyEditEditor *atk_editor = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
virtual bool can_handle(Object *p_object) override;
|
|
|
|
virtual void parse_begin(Object *p_object) override;
|
|
|
|
};
|
|
|
|
|
|
|
|
class AnimationTrackKeyEditEditorPlugin : public EditorPlugin {
|
|
|
|
GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin);
|
|
|
|
|
|
|
|
EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr;
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool has_main_screen() const override { return false; }
|
|
|
|
virtual bool handles(Object *p_object) const override;
|
|
|
|
|
|
|
|
virtual String get_name() const override { return "AnimationTrackKeyEdit"; }
|
|
|
|
|
|
|
|
AnimationTrackKeyEditEditorPlugin();
|
|
|
|
};
|
|
|
|
|
2014-02-10 01:10:30 +00:00
|
|
|
#endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H
|