Path: blob/master/editor/animation/animation_player_editor_plugin.h
9896 views
/**************************************************************************/1/* animation_player_editor_plugin.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "editor/animation/animation_library_editor.h"33#include "editor/animation/animation_track_editor.h"34#include "editor/plugins/editor_plugin.h"35#include "scene/animation/animation_player.h"36#include "scene/gui/dialogs.h"37#include "scene/gui/slider.h"38#include "scene/gui/spin_box.h"39#include "scene/gui/texture_button.h"40#include "scene/gui/tree.h"4142class AnimationPlayerEditorPlugin;43class ImageTexture;4445class AnimationPlayerEditor : public VBoxContainer {46GDCLASS(AnimationPlayerEditor, VBoxContainer);4748friend AnimationPlayerEditorPlugin;4950AnimationPlayerEditorPlugin *plugin = nullptr;51AnimationMixer *original_node = nullptr; // For pinned mark in SceneTree.52AnimationPlayer *player = nullptr; // For AnimationPlayerEditor, could be dummy.53ObjectID cached_root_node_id;54bool is_dummy = false;5556enum {57TOOL_NEW_ANIM,58TOOL_ANIM_LIBRARY,59TOOL_DUPLICATE_ANIM,60TOOL_RENAME_ANIM,61TOOL_EDIT_TRANSITIONS,62TOOL_REMOVE_ANIM,63TOOL_EDIT_RESOURCE64};6566enum {67ONION_SKINNING_ENABLE,68ONION_SKINNING_PAST,69ONION_SKINNING_FUTURE,70ONION_SKINNING_1_STEP,71ONION_SKINNING_2_STEPS,72ONION_SKINNING_3_STEPS,73ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,74ONION_SKINNING_DIFFERENCES_ONLY,75ONION_SKINNING_FORCE_WHITE_MODULATE,76ONION_SKINNING_INCLUDE_GIZMOS,77};7879enum {80ANIM_OPEN,81ANIM_SAVE,82ANIM_SAVE_AS83};8485enum {86RESOURCE_LOAD,87RESOURCE_SAVE88};8990OptionButton *animation = nullptr;91Button *stop = nullptr;92Button *play = nullptr;93Button *play_from = nullptr;94Button *play_bw = nullptr;95Button *play_bw_from = nullptr;96Button *autoplay = nullptr;9798MenuButton *tool_anim = nullptr;99Button *onion_toggle = nullptr;100MenuButton *onion_skinning = nullptr;101Button *pin = nullptr;102SpinBox *frame = nullptr;103LineEdit *scale = nullptr;104LineEdit *name = nullptr;105OptionButton *library = nullptr;106Label *name_title = nullptr;107108Ref<Texture2D> stop_icon;109Ref<Texture2D> pause_icon;110Ref<Texture2D> autoplay_icon;111Ref<Texture2D> reset_icon;112Ref<ImageTexture> autoplay_reset_icon;113114bool finishing = false;115bool last_active = false;116float timeline_position = 0;117118EditorFileDialog *file = nullptr;119ConfirmationDialog *delete_dialog = nullptr;120121AnimationLibraryEditor *library_editor = nullptr;122123struct BlendEditor {124AcceptDialog *dialog = nullptr;125Tree *tree = nullptr;126OptionButton *next = nullptr;127128} blend_editor;129130ConfirmationDialog *name_dialog = nullptr;131AcceptDialog *error_dialog = nullptr;132int name_dialog_op = TOOL_NEW_ANIM;133134bool updating = false;135bool updating_blends = false;136137AnimationTrackEditor *track_editor = nullptr;138static AnimationPlayerEditor *singleton;139140// Onion skinning.141struct {142// Settings.143bool enabled = false;144bool past = true;145bool future = false;146uint32_t steps = 1;147bool differences_only = false;148bool force_white_modulate = false;149bool include_gizmos = false;150151uint32_t get_capture_count() const {152// 'Differences only' needs a capture of the present.153return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);154}155156// Rendering.157int64_t last_frame = 0;158int can_overlay = 0;159Size2 capture_size;160LocalVector<RID> captures;161LocalVector<bool> captures_valid;162struct {163RID canvas;164RID canvas_item;165Ref<ShaderMaterial> material;166Ref<Shader> shader;167} capture;168169// Cross-call state.170struct {171double anim_player_position = 0.0;172Ref<AnimatedValuesBackup> anim_values_backup;173Rect2 screen_rect;174Dictionary canvas_edit_state;175Dictionary spatial_edit_state;176} temp;177} onion;178179void _select_anim_by_name(const String &p_anim);180float _get_editor_step() const;181void _go_to_nearest_keyframe(bool p_backward);182void _play_pressed();183void _play_from_pressed();184void _play_bw_pressed();185void _play_bw_from_pressed();186void _autoplay_pressed();187void _stop_pressed();188void _animation_selected(int p_which);189void _animation_new();190void _animation_rename();191void _animation_name_edited();192193void _animation_remove();194void _animation_remove_confirmed();195void _animation_edit();196void _animation_duplicate();197Ref<Animation> _animation_clone(const Ref<Animation> p_anim);198void _animation_resource_edit();199void _scale_changed(const String &p_scale);200void _seek_value_changed(float p_value, bool p_timeline_only = false);201void _blend_editor_next_changed(const int p_idx);202203void _edit_animation_blend();204void _update_animation_blend();205206void _list_changed();207void _animation_finished(const String &p_name);208void _current_animation_changed(const String &p_name);209void _update_animation();210void _update_player();211void _set_controls_disabled(bool p_disabled);212void _update_animation_list_icons();213void _update_name_dialog_library_dropdown();214void _blend_edited();215216void _animation_player_changed(Object *p_pl);217void _animation_libraries_updated();218219void _animation_key_editor_seek(float p_pos, bool p_timeline_only = false, bool p_update_position_only = false);220void _animation_key_editor_anim_len_changed(float p_len);221void _animation_update_key_frame();222223virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;224void _animation_tool_menu(int p_option);225void _onion_skinning_menu(int p_option);226227void _editor_visibility_changed();228bool _are_onion_layers_valid();229void _allocate_onion_layers();230void _free_onion_layers();231void _prepare_onion_layers_1();232void _prepare_onion_layers_2_prolog();233void _prepare_onion_layers_2_step_prepare(int p_step_offset, uint32_t p_capture_idx);234void _prepare_onion_layers_2_step_capture(int p_step_offset, uint32_t p_capture_idx);235void _prepare_onion_layers_2_epilog();236void _start_onion_skinning();237void _stop_onion_skinning();238239bool _validate_tracks(const Ref<Animation> p_anim);240241void _pin_pressed();242String _get_current() const;243244void _ensure_dummy_player();245246~AnimationPlayerEditor();247248protected:249void _notification(int p_what);250void _node_removed(Node *p_node);251static void _bind_methods();252253public:254AnimationMixer *get_editing_node() const;255AnimationPlayer *get_player() const;256AnimationMixer *fetch_mixer_for_library() const;257Node *get_cached_root_node() const;258259static AnimationPlayerEditor *get_singleton() { return singleton; }260261bool is_pinned() const { return pin->is_pressed(); }262void unpin() {263pin->set_pressed(false);264_pin_pressed();265}266AnimationTrackEditor *get_track_editor() { return track_editor; }267Dictionary get_state() const;268void set_state(const Dictionary &p_state);269void clear();270271void ensure_visibility();272273void edit(AnimationMixer *p_node, AnimationPlayer *p_player, bool p_is_dummy);274void forward_force_draw_over_viewport(Control *p_overlay);275276AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);277};278279class AnimationPlayerEditorPlugin : public EditorPlugin {280GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);281282friend AnimationPlayerEditor;283284AnimationPlayerEditor *anim_editor = nullptr;285AnimationPlayer *player = nullptr;286AnimationPlayer *dummy_player = nullptr;287ObjectID last_mixer;288289void _update_dummy_player(AnimationMixer *p_mixer);290void _clear_dummy_player();291292protected:293void _notification(int p_what);294295void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);296void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);297void _update_keying();298299public:300virtual Dictionary get_state() const override { return anim_editor->get_state(); }301virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }302virtual void clear() override { anim_editor->clear(); }303304virtual String get_plugin_name() const override { return "Anim"; }305bool has_main_screen() const override { return false; }306virtual void edit(Object *p_object) override;307virtual bool handles(Object *p_object) const override;308virtual void make_visible(bool p_visible) override;309310virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }311virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }312313AnimationPlayerEditorPlugin();314~AnimationPlayerEditorPlugin();315};316317// AnimationTrackKeyEditEditorPlugin318319class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin {320GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin);321322AnimationTrackKeyEditEditor *atk_editor = nullptr;323324public:325virtual bool can_handle(Object *p_object) override;326virtual void parse_begin(Object *p_object) override;327};328329class AnimationTrackKeyEditEditorPlugin : public EditorPlugin {330GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin);331332EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr;333334public:335bool has_main_screen() const override { return false; }336virtual bool handles(Object *p_object) const override;337338virtual String get_plugin_name() const override { return "AnimationTrackKeyEdit"; }339340AnimationTrackKeyEditEditorPlugin();341};342343// AnimationMarkerKeyEditEditorPlugin344345class EditorInspectorPluginAnimationMarkerKeyEdit : public EditorInspectorPlugin {346GDCLASS(EditorInspectorPluginAnimationMarkerKeyEdit, EditorInspectorPlugin);347348AnimationMarkerKeyEditEditor *amk_editor = nullptr;349350public:351virtual bool can_handle(Object *p_object) override;352virtual void parse_begin(Object *p_object) override;353};354355class AnimationMarkerKeyEditEditorPlugin : public EditorPlugin {356GDCLASS(AnimationMarkerKeyEditEditorPlugin, EditorPlugin);357358EditorInspectorPluginAnimationMarkerKeyEdit *amk_plugin = nullptr;359360public:361bool has_main_screen() const override { return false; }362virtual bool handles(Object *p_object) const override;363364virtual String get_plugin_name() const override { return "AnimationMarkerKeyEdit"; }365366AnimationMarkerKeyEditEditorPlugin();367};368369370