animation_player_editor_plugin.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 AnimationPlayerEditorPlugin;
  42. class ImageTexture;
  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<Texture2D> stop_icon;
  94. Ref<Texture2D> pause_icon;
  95. Ref<Texture2D> autoplay_icon;
  96. Ref<Texture2D> reset_icon;
  97. Ref<ImageTexture> autoplay_reset_icon;
  98. bool last_active;
  99. float timeline_position;
  100. EditorFileDialog *file = nullptr;
  101. ConfirmationDialog *delete_dialog = nullptr;
  102. AnimationLibraryEditor *library_editor = nullptr;
  103. struct BlendEditor {
  104. AcceptDialog *dialog = nullptr;
  105. Tree *tree = nullptr;
  106. OptionButton *next = nullptr;
  107. } blend_editor;
  108. ConfirmationDialog *name_dialog = nullptr;
  109. ConfirmationDialog *error_dialog = nullptr;
  110. int name_dialog_op = TOOL_NEW_ANIM;
  111. bool updating;
  112. bool updating_blends;
  113. AnimationTrackEditor *track_editor = nullptr;
  114. static AnimationPlayerEditor *singleton;
  115. bool hack_disable_onion_skinning = true; // Temporary hack for GH-53870.
  116. // Onion skinning.
  117. struct {
  118. // Settings.
  119. bool enabled = false;
  120. bool past = false;
  121. bool future = false;
  122. int steps = 0;
  123. bool differences_only = false;
  124. bool force_white_modulate = false;
  125. bool include_gizmos = false;
  126. int get_needed_capture_count() const {
  127. // 'Differences only' needs a capture of the present.
  128. return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
  129. }
  130. // Rendering.
  131. int64_t last_frame = 0;
  132. int can_overlay = 0;
  133. Size2 capture_size;
  134. Vector<RID> captures;
  135. Vector<bool> captures_valid;
  136. struct {
  137. RID canvas;
  138. RID canvas_item;
  139. Ref<ShaderMaterial> material;
  140. Ref<Shader> shader;
  141. } capture;
  142. } onion;
  143. void _select_anim_by_name(const String &p_anim);
  144. float _get_editor_step() const;
  145. void _play_pressed();
  146. void _play_from_pressed();
  147. void _play_bw_pressed();
  148. void _play_bw_from_pressed();
  149. void _autoplay_pressed();
  150. void _stop_pressed();
  151. void _animation_selected(int p_which);
  152. void _animation_new();
  153. void _animation_rename();
  154. void _animation_name_edited();
  155. void _animation_remove();
  156. void _animation_remove_confirmed();
  157. void _animation_blend();
  158. void _animation_edit();
  159. void _animation_duplicate();
  160. Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
  161. void _animation_resource_edit();
  162. void _scale_changed(const String &p_scale);
  163. void _seek_value_changed(float p_value, bool p_set = false, bool p_timeline_only = false);
  164. void _blend_editor_next_changed(const int p_idx);
  165. void _list_changed();
  166. void _update_animation();
  167. void _update_player();
  168. void _update_animation_list_icons();
  169. void _update_name_dialog_library_dropdown();
  170. void _blend_edited();
  171. void _animation_player_changed(Object *p_pl);
  172. void _animation_libraries_updated();
  173. void _animation_key_editor_seek(float p_pos, bool p_drag, bool p_timeline_only = false);
  174. void _animation_key_editor_anim_len_changed(float p_len);
  175. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  176. void _animation_tool_menu(int p_option);
  177. void _onion_skinning_menu(int p_option);
  178. void _editor_visibility_changed();
  179. bool _are_onion_layers_valid();
  180. void _allocate_onion_layers();
  181. void _free_onion_layers();
  182. void _prepare_onion_layers_1();
  183. void _prepare_onion_layers_1_deferred();
  184. void _prepare_onion_layers_2();
  185. void _start_onion_skinning();
  186. void _stop_onion_skinning();
  187. bool _validate_tracks(const Ref<Animation> p_anim);
  188. void _pin_pressed();
  189. String _get_current() const;
  190. ~AnimationPlayerEditor();
  191. protected:
  192. void _notification(int p_what);
  193. void _node_removed(Node *p_node);
  194. static void _bind_methods();
  195. public:
  196. AnimationPlayer *get_player() const;
  197. static AnimationPlayerEditor *get_singleton() { return singleton; }
  198. bool is_pinned() const { return pin->is_pressed(); }
  199. void unpin() { pin->set_pressed(false); }
  200. AnimationTrackEditor *get_track_editor() { return track_editor; }
  201. Dictionary get_state() const;
  202. void set_state(const Dictionary &p_state);
  203. void ensure_visibility();
  204. void edit(AnimationPlayer *p_player);
  205. void forward_force_draw_over_viewport(Control *p_overlay);
  206. AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);
  207. };
  208. class AnimationPlayerEditorPlugin : public EditorPlugin {
  209. GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
  210. AnimationPlayerEditor *anim_editor = nullptr;
  211. protected:
  212. void _notification(int p_what);
  213. void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);
  214. void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);
  215. void _update_keying();
  216. public:
  217. virtual Dictionary get_state() const override { return anim_editor->get_state(); }
  218. virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
  219. virtual String get_name() const override { return "Anim"; }
  220. bool has_main_screen() const override { return false; }
  221. virtual void edit(Object *p_object) override;
  222. virtual bool handles(Object *p_object) const override;
  223. virtual void make_visible(bool p_visible) override;
  224. virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  225. virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  226. AnimationPlayerEditorPlugin();
  227. ~AnimationPlayerEditorPlugin();
  228. };
  229. // AnimationTrackKeyEditEditorPlugin
  230. class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin {
  231. GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin);
  232. AnimationTrackKeyEditEditor *atk_editor = nullptr;
  233. public:
  234. virtual bool can_handle(Object *p_object) override;
  235. virtual void parse_begin(Object *p_object) override;
  236. };
  237. class AnimationTrackKeyEditEditorPlugin : public EditorPlugin {
  238. GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin);
  239. EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr;
  240. public:
  241. bool has_main_screen() const override { return false; }
  242. virtual bool handles(Object *p_object) const override;
  243. virtual String get_name() const override { return "AnimationTrackKeyEdit"; }
  244. AnimationTrackKeyEditEditorPlugin();
  245. };
  246. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H