animation_player_editor_plugin.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  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. #ifndef ANIMATION_PLAYER_EDITOR_PLUGIN_H
  31. #define ANIMATION_PLAYER_EDITOR_PLUGIN_H
  32. #include "editor/animation_track_editor.h"
  33. #include "editor/editor_plugin.h"
  34. #include "editor/plugins/animation_library_editor.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"
  41. class EditorUndoRedoManager;
  42. class AnimationPlayerEditorPlugin;
  43. class AnimationPlayerEditor : public VBoxContainer {
  44. GDCLASS(AnimationPlayerEditor, VBoxContainer);
  45. AnimationPlayerEditorPlugin *plugin = nullptr;
  46. AnimationPlayer *player = nullptr;
  47. enum {
  48. TOOL_NEW_ANIM,
  49. TOOL_ANIM_LIBRARY,
  50. TOOL_DUPLICATE_ANIM,
  51. TOOL_RENAME_ANIM,
  52. TOOL_EDIT_TRANSITIONS,
  53. TOOL_REMOVE_ANIM,
  54. TOOL_EDIT_RESOURCE
  55. };
  56. enum {
  57. ONION_SKINNING_ENABLE,
  58. ONION_SKINNING_PAST,
  59. ONION_SKINNING_FUTURE,
  60. ONION_SKINNING_1_STEP,
  61. ONION_SKINNING_2_STEPS,
  62. ONION_SKINNING_3_STEPS,
  63. ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
  64. ONION_SKINNING_DIFFERENCES_ONLY,
  65. ONION_SKINNING_FORCE_WHITE_MODULATE,
  66. ONION_SKINNING_INCLUDE_GIZMOS,
  67. };
  68. enum {
  69. ANIM_OPEN,
  70. ANIM_SAVE,
  71. ANIM_SAVE_AS
  72. };
  73. enum {
  74. RESOURCE_LOAD,
  75. RESOURCE_SAVE
  76. };
  77. OptionButton *animation = nullptr;
  78. Button *stop = nullptr;
  79. Button *play = nullptr;
  80. Button *play_from = nullptr;
  81. Button *play_bw = nullptr;
  82. Button *play_bw_from = nullptr;
  83. Button *autoplay = nullptr;
  84. MenuButton *tool_anim = nullptr;
  85. Button *onion_toggle = nullptr;
  86. MenuButton *onion_skinning = nullptr;
  87. Button *pin = nullptr;
  88. SpinBox *frame = nullptr;
  89. LineEdit *scale = nullptr;
  90. LineEdit *name = nullptr;
  91. OptionButton *library = nullptr;
  92. Label *name_title = nullptr;
  93. Ref<EditorUndoRedoManager> undo_redo;
  94. Ref<Texture2D> autoplay_icon;
  95. Ref<Texture2D> reset_icon;
  96. Ref<ImageTexture> autoplay_reset_icon;
  97. bool last_active;
  98. float timeline_position;
  99. EditorFileDialog *file = nullptr;
  100. ConfirmationDialog *delete_dialog = nullptr;
  101. AnimationLibraryEditor *library_editor = nullptr;
  102. struct BlendEditor {
  103. AcceptDialog *dialog = nullptr;
  104. Tree *tree = nullptr;
  105. OptionButton *next = nullptr;
  106. } blend_editor;
  107. ConfirmationDialog *name_dialog = nullptr;
  108. ConfirmationDialog *error_dialog = nullptr;
  109. int name_dialog_op = TOOL_NEW_ANIM;
  110. bool updating;
  111. bool updating_blends;
  112. AnimationTrackEditor *track_editor = nullptr;
  113. static AnimationPlayerEditor *singleton;
  114. // Onion skinning.
  115. struct {
  116. // Settings.
  117. bool enabled = false;
  118. bool past = false;
  119. bool future = false;
  120. int steps = 0;
  121. bool differences_only = false;
  122. bool force_white_modulate = false;
  123. bool include_gizmos = false;
  124. int get_needed_capture_count() const {
  125. // 'Differences only' needs a capture of the present.
  126. return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
  127. }
  128. // Rendering.
  129. int64_t last_frame = 0;
  130. int can_overlay = 0;
  131. Size2 capture_size;
  132. Vector<RID> captures;
  133. Vector<bool> captures_valid;
  134. struct {
  135. RID canvas;
  136. RID canvas_item;
  137. Ref<ShaderMaterial> material;
  138. Ref<Shader> shader;
  139. } capture;
  140. } onion;
  141. void _select_anim_by_name(const String &p_anim);
  142. double _get_editor_step() const;
  143. void _play_pressed();
  144. void _play_from_pressed();
  145. void _play_bw_pressed();
  146. void _play_bw_from_pressed();
  147. void _autoplay_pressed();
  148. void _stop_pressed();
  149. void _animation_selected(int p_which);
  150. void _animation_new();
  151. void _animation_rename();
  152. void _animation_name_edited();
  153. void _animation_remove();
  154. void _animation_remove_confirmed();
  155. void _animation_blend();
  156. void _animation_edit();
  157. void _animation_duplicate();
  158. Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
  159. void _animation_resource_edit();
  160. void _scale_changed(const String &p_scale);
  161. void _seek_value_changed(float p_value, bool p_set = false, bool p_timeline_only = false);
  162. void _blend_editor_next_changed(const int p_idx);
  163. void _list_changed();
  164. void _update_animation();
  165. void _update_player();
  166. void _update_animation_list_icons();
  167. void _update_name_dialog_library_dropdown();
  168. void _blend_edited();
  169. void _animation_player_changed(Object *p_pl);
  170. void _animation_key_editor_seek(float p_pos, bool p_drag, bool p_timeline_only = false);
  171. void _animation_key_editor_anim_len_changed(float p_len);
  172. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  173. void _animation_tool_menu(int p_option);
  174. void _onion_skinning_menu(int p_option);
  175. void _editor_visibility_changed();
  176. bool _are_onion_layers_valid();
  177. void _allocate_onion_layers();
  178. void _free_onion_layers();
  179. void _prepare_onion_layers_1();
  180. void _prepare_onion_layers_1_deferred();
  181. void _prepare_onion_layers_2();
  182. void _start_onion_skinning();
  183. void _stop_onion_skinning();
  184. void _pin_pressed();
  185. String _get_current() const;
  186. ~AnimationPlayerEditor();
  187. protected:
  188. void _notification(int p_what);
  189. void _node_removed(Node *p_node);
  190. static void _bind_methods();
  191. public:
  192. AnimationPlayer *get_player() const;
  193. static AnimationPlayerEditor *get_singleton() { return singleton; }
  194. bool is_pinned() const { return pin->is_pressed(); }
  195. void unpin() { pin->set_pressed(false); }
  196. AnimationTrackEditor *get_track_editor() { return track_editor; }
  197. Dictionary get_state() const;
  198. void set_state(const Dictionary &p_state);
  199. void ensure_visibility();
  200. void set_undo_redo(Ref<EditorUndoRedoManager> p_undo_redo);
  201. void edit(AnimationPlayer *p_player);
  202. void forward_force_draw_over_viewport(Control *p_overlay);
  203. AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);
  204. };
  205. class AnimationPlayerEditorPlugin : public EditorPlugin {
  206. GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
  207. AnimationPlayerEditor *anim_editor = nullptr;
  208. protected:
  209. void _notification(int p_what);
  210. void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);
  211. void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);
  212. void _update_keying();
  213. public:
  214. virtual Dictionary get_state() const override { return anim_editor->get_state(); }
  215. virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
  216. virtual String get_name() const override { return "Anim"; }
  217. bool has_main_screen() const override { return false; }
  218. virtual void edit(Object *p_object) override;
  219. virtual bool handles(Object *p_object) const override;
  220. virtual void make_visible(bool p_visible) override;
  221. virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  222. virtual void forward_spatial_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  223. AnimationPlayerEditorPlugin();
  224. ~AnimationPlayerEditorPlugin();
  225. };
  226. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H