diff options
Diffstat (limited to 'editor/animation_track_editor.h')
-rw-r--r-- | editor/animation_track_editor.h | 182 |
1 files changed, 136 insertions, 46 deletions
diff --git a/editor/animation_track_editor.h b/editor/animation_track_editor.h index ac69b88e99..ef06445011 100644 --- a/editor/animation_track_editor.h +++ b/editor/animation_track_editor.h @@ -1,32 +1,32 @@ -/*************************************************************************/ -/* animation_track_editor.h */ -/*************************************************************************/ -/* This file is part of: */ -/* GODOT ENGINE */ -/* https://godotengine.org */ -/*************************************************************************/ -/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ -/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ -/* */ -/* 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. */ -/*************************************************************************/ +/**************************************************************************/ +/* animation_track_editor.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. */ +/**************************************************************************/ #ifndef ANIMATION_TRACK_EDITOR_H #define ANIMATION_TRACK_EDITOR_H @@ -50,9 +50,83 @@ #include "scene/resources/animation.h" #include "scene_tree_editor.h" +class AnimationTrackEditor; class AnimationTrackEdit; class ViewPanner; +class AnimationTrackKeyEdit : public Object { + GDCLASS(AnimationTrackKeyEdit, Object); + +public: + bool setting = false; + bool animation_read_only = false; + + Ref<Animation> animation; + int track = -1; + float key_ofs = 0; + Node *root_path = nullptr; + + PropertyInfo hint; + NodePath base; + bool use_fps = false; + + bool _hide_script_from_inspector() { return true; } + bool _hide_metadata_from_inspector() { return true; } + bool _dont_undo_redo() { return true; } + + bool _is_read_only() { return animation_read_only; } + + void notify_change(); + Node *get_root_path(); + void set_use_fps(bool p_enable); + +protected: + static void _bind_methods(); + void _fix_node_path(Variant &value); + void _update_obj(const Ref<Animation> &p_anim); + void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; +}; + +class AnimationMultiTrackKeyEdit : public Object { + GDCLASS(AnimationMultiTrackKeyEdit, Object); + +public: + bool setting = false; + bool animation_read_only = false; + + Ref<Animation> animation; + + RBMap<int, List<float>> key_ofs_map; + RBMap<int, NodePath> base_map; + PropertyInfo hint; + + Node *root_path = nullptr; + + bool use_fps = false; + + bool _hide_script_from_inspector() { return true; } + bool _hide_metadata_from_inspector() { return true; } + bool _dont_undo_redo() { return true; } + + bool _is_read_only() { return animation_read_only; } + + void notify_change(); + Node *get_root_path(); + void set_use_fps(bool p_enable); + +protected: + static void _bind_methods(); + void _fix_node_path(Variant &value, NodePath &base); + void _update_obj(const Ref<Animation> &p_anim); + void _key_ofs_changed(const Ref<Animation> &p_anim, float from, float to); + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; +}; + class AnimationTimelineEdit : public Range { GDCLASS(AnimationTimelineEdit, Range); @@ -79,7 +153,6 @@ class AnimationTimelineEdit : public Range { void _anim_loop_pressed(); void _play_position_draw(); - Ref<EditorUndoRedoManager> undo_redo; Rect2 hsize_rect; bool editing = false; @@ -113,7 +186,6 @@ public: void set_track_edit(AnimationTrackEdit *p_track_edit); void set_zoom(Range *p_zoom); Range *get_zoom() const { return zoom; } - void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo); void set_play_position(float p_pos); float get_play_position() const; @@ -131,15 +203,13 @@ public: AnimationTimelineEdit(); }; -class AnimationTrackEditor; - class AnimationTrackEdit : public Control { GDCLASS(AnimationTrackEdit, Control); + friend class AnimationTimelineEdit; enum { MENU_CALL_MODE_CONTINUOUS, MENU_CALL_MODE_DISCRETE, - MENU_CALL_MODE_TRIGGER, MENU_CALL_MODE_CAPTURE, MENU_INTERPOLATION_NEAREST, MENU_INTERPOLATION_LINEAR, @@ -155,7 +225,6 @@ class AnimationTrackEdit : public Control { }; AnimationTimelineEdit *timeline = nullptr; - Ref<EditorUndoRedoManager> undo_redo; Popup *path_popup = nullptr; LineEdit *path = nullptr; Node *root = nullptr; @@ -236,12 +305,10 @@ public: Ref<Animation> get_animation() const; AnimationTimelineEdit *get_timeline() const { return timeline; } AnimationTrackEditor *get_editor() const { return editor; } - Ref<EditorUndoRedoManager> get_undo_redo() const; NodePath get_path() const; void set_animation_and_track(const Ref<Animation> &p_animation, int p_track, bool p_read_only); virtual Size2 get_minimum_size() const override; - void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo); void set_timeline(AnimationTimelineEdit *p_timeline); void set_editor(AnimationTrackEditor *p_editor); void set_root(Node *p_root); @@ -280,7 +347,6 @@ class AnimationTrackEditGroup : public Control { void _zoom_changed(); protected: - static void _bind_methods(); void _notification(int p_what); public: @@ -294,6 +360,7 @@ public: class AnimationTrackEditor : public VBoxContainer { GDCLASS(AnimationTrackEditor, VBoxContainer); + friend class AnimationTimelineEdit; Ref<Animation> animation; bool read_only = false; @@ -327,7 +394,6 @@ class AnimationTrackEditor : public VBoxContainer { bool animation_changing_awaiting_update = false; void _animation_update(); // Updated by AnimationTrackEditor(this) int _get_track_selected(); - void _sync_animation_change(); void _animation_changed(); void _update_tracks(); void _redraw_tracks(); @@ -339,8 +405,6 @@ class AnimationTrackEditor : public VBoxContainer { void _animation_track_remove_request(int p_track, Ref<Animation> p_from_animation); void _track_grab_focus(int p_track); - Ref<EditorUndoRedoManager> undo_redo; - void _update_scroll(double); void _update_step(double p_new_step); void _update_length(double p_new_len); @@ -407,7 +471,6 @@ class AnimationTrackEditor : public VBoxContainer { void _insert_key_from_track(float p_ofs, int p_track); void _add_method_key(const String &p_method); - void _clear_selection(bool p_update = false); void _clear_selection_for_anim(const Ref<Animation> &p_anim); void _select_at_anim(const Ref<Animation> &p_anim, int p_track, float p_pos); @@ -425,9 +488,6 @@ class AnimationTrackEditor : public VBoxContainer { RBMap<SelectedKey, KeyInfo> selection; - void _key_selected(int p_key, bool p_single, int p_track); - void _key_deselected(int p_key, int p_track); - bool moving_selection = false; float moving_selection_offset = 0.0f; void _move_selection_begin(); @@ -438,7 +498,6 @@ class AnimationTrackEditor : public VBoxContainer { AnimationTrackKeyEdit *key_edit = nullptr; AnimationMultiTrackKeyEdit *multi_key_edit = nullptr; void _update_key_edit(); - void _clear_key_edit(); Control *box_selection = nullptr; @@ -531,6 +590,11 @@ protected: void _notification(int p_what); public: + // Public for use with callable_mp. + void _clear_selection(bool p_update = false); + void _key_selected(int p_key, bool p_single, int p_track); + void _key_deselected(int p_key, int p_track); + enum { EDIT_COPY_TRACKS, EDIT_COPY_TRACKS_CONFIRM, @@ -600,4 +664,30 @@ public: ~AnimationTrackEditor(); }; +// AnimationTrackKeyEditEditorPlugin + +class AnimationTrackKeyEditEditor : public EditorProperty { + GDCLASS(AnimationTrackKeyEditEditor, EditorProperty); + + Ref<Animation> animation; + int track = -1; + real_t key_ofs = 0.0; + bool use_fps = false; + + EditorSpinSlider *spinner = nullptr; + + struct KeyDataCache { + real_t time = 0.0; + float transition = 0.0; + Variant value; + } key_data_cache; + + void _time_edit_entered(); + void _time_edit_exited(); + +public: + AnimationTrackKeyEditEditor(Ref<Animation> p_animation, int p_track, real_t p_key_ofs, bool p_use_fps); + ~AnimationTrackKeyEditEditor(); +}; + #endif // ANIMATION_TRACK_EDITOR_H |