animation_player_editor_plugin.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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/plugins/animation_library_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"
  41. class AnimationPlayerEditorPlugin;
  42. class ImageTexture;
  43. class AnimationPlayerEditor : public VBoxContainer {
  44. GDCLASS(AnimationPlayerEditor, VBoxContainer);
  45. friend AnimationPlayerEditorPlugin;
  46. AnimationPlayerEditorPlugin *plugin = nullptr;
  47. AnimationMixer *original_node = nullptr; // For pinned mark in SceneTree.
  48. AnimationPlayer *player = nullptr; // For AnimationPlayerEditor, could be dummy.
  49. ObjectID cached_root_node_id;
  50. bool is_dummy = false;
  51. enum {
  52. TOOL_NEW_ANIM,
  53. TOOL_ANIM_LIBRARY,
  54. TOOL_DUPLICATE_ANIM,
  55. TOOL_RENAME_ANIM,
  56. TOOL_EDIT_TRANSITIONS,
  57. TOOL_REMOVE_ANIM,
  58. TOOL_EDIT_RESOURCE
  59. };
  60. enum {
  61. ONION_SKINNING_ENABLE,
  62. ONION_SKINNING_PAST,
  63. ONION_SKINNING_FUTURE,
  64. ONION_SKINNING_1_STEP,
  65. ONION_SKINNING_2_STEPS,
  66. ONION_SKINNING_3_STEPS,
  67. ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
  68. ONION_SKINNING_DIFFERENCES_ONLY,
  69. ONION_SKINNING_FORCE_WHITE_MODULATE,
  70. ONION_SKINNING_INCLUDE_GIZMOS,
  71. };
  72. enum {
  73. ANIM_OPEN,
  74. ANIM_SAVE,
  75. ANIM_SAVE_AS
  76. };
  77. enum {
  78. RESOURCE_LOAD,
  79. RESOURCE_SAVE
  80. };
  81. OptionButton *animation = nullptr;
  82. Button *stop = nullptr;
  83. Button *play = nullptr;
  84. Button *play_from = nullptr;
  85. Button *play_bw = nullptr;
  86. Button *play_bw_from = nullptr;
  87. Button *autoplay = nullptr;
  88. MenuButton *tool_anim = nullptr;
  89. Button *onion_toggle = nullptr;
  90. MenuButton *onion_skinning = nullptr;
  91. Button *pin = nullptr;
  92. SpinBox *frame = nullptr;
  93. LineEdit *scale = nullptr;
  94. LineEdit *name = nullptr;
  95. OptionButton *library = nullptr;
  96. Label *name_title = nullptr;
  97. Ref<Texture2D> stop_icon;
  98. Ref<Texture2D> pause_icon;
  99. Ref<Texture2D> autoplay_icon;
  100. Ref<Texture2D> reset_icon;
  101. Ref<ImageTexture> autoplay_reset_icon;
  102. bool last_active = false;
  103. float timeline_position = 0;
  104. EditorFileDialog *file = nullptr;
  105. ConfirmationDialog *delete_dialog = nullptr;
  106. AnimationLibraryEditor *library_editor = nullptr;
  107. struct BlendEditor {
  108. AcceptDialog *dialog = nullptr;
  109. Tree *tree = nullptr;
  110. OptionButton *next = nullptr;
  111. } blend_editor;
  112. ConfirmationDialog *name_dialog = nullptr;
  113. AcceptDialog *error_dialog = nullptr;
  114. int name_dialog_op = TOOL_NEW_ANIM;
  115. bool updating = false;
  116. bool updating_blends = false;
  117. AnimationTrackEditor *track_editor = nullptr;
  118. static AnimationPlayerEditor *singleton;
  119. // Onion skinning.
  120. struct {
  121. // Settings.
  122. bool enabled = false;
  123. bool past = true;
  124. bool future = false;
  125. uint32_t steps = 1;
  126. bool differences_only = false;
  127. bool force_white_modulate = false;
  128. bool include_gizmos = false;
  129. uint32_t get_capture_count() const {
  130. // 'Differences only' needs a capture of the present.
  131. return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
  132. }
  133. // Rendering.
  134. int64_t last_frame = 0;
  135. int can_overlay = 0;
  136. Size2 capture_size;
  137. LocalVector<RID> captures;
  138. LocalVector<bool> captures_valid;
  139. struct {
  140. RID canvas;
  141. RID canvas_item;
  142. Ref<ShaderMaterial> material;
  143. Ref<Shader> shader;
  144. } capture;
  145. // Cross-call state.
  146. struct {
  147. double anim_player_position = 0.0;
  148. Ref<AnimatedValuesBackup> anim_values_backup;
  149. Rect2 screen_rect;
  150. Dictionary canvas_edit_state;
  151. Dictionary spatial_edit_state;
  152. } temp;
  153. } onion;
  154. void _select_anim_by_name(const String &p_anim);
  155. float _get_editor_step() const;
  156. void _go_to_nearest_keyframe(bool p_backward);
  157. void _play_pressed();
  158. void _play_from_pressed();
  159. void _play_bw_pressed();
  160. void _play_bw_from_pressed();
  161. void _autoplay_pressed();
  162. void _stop_pressed();
  163. void _animation_selected(int p_which);
  164. void _animation_new();
  165. void _animation_rename();
  166. void _animation_name_edited();
  167. void _animation_remove();
  168. void _animation_remove_confirmed();
  169. void _animation_edit();
  170. void _animation_duplicate();
  171. Ref<Animation> _animation_clone(const Ref<Animation> p_anim);
  172. void _animation_resource_edit();
  173. void _scale_changed(const String &p_scale);
  174. void _seek_value_changed(float p_value, bool p_timeline_only = false);
  175. void _blend_editor_next_changed(const int p_idx);
  176. void _edit_animation_blend();
  177. void _update_animation_blend();
  178. void _list_changed();
  179. void _current_animation_changed(const String &p_name);
  180. void _update_animation();
  181. void _update_player();
  182. void _set_controls_disabled(bool p_disabled);
  183. void _update_animation_list_icons();
  184. void _update_name_dialog_library_dropdown();
  185. void _blend_edited();
  186. void _animation_player_changed(Object *p_pl);
  187. void _animation_libraries_updated();
  188. void _animation_key_editor_seek(float p_pos, bool p_timeline_only = false, bool p_update_position_only = false);
  189. void _animation_key_editor_anim_len_changed(float p_len);
  190. void _animation_update_key_frame();
  191. virtual void shortcut_input(const Ref<InputEvent> &p_ev) override;
  192. void _animation_tool_menu(int p_option);
  193. void _onion_skinning_menu(int p_option);
  194. void _editor_visibility_changed();
  195. bool _are_onion_layers_valid();
  196. void _allocate_onion_layers();
  197. void _free_onion_layers();
  198. void _prepare_onion_layers_1();
  199. void _prepare_onion_layers_2_prolog();
  200. void _prepare_onion_layers_2_step_prepare(int p_step_offset, uint32_t p_capture_idx);
  201. void _prepare_onion_layers_2_step_capture(int p_step_offset, uint32_t p_capture_idx);
  202. void _prepare_onion_layers_2_epilog();
  203. void _start_onion_skinning();
  204. void _stop_onion_skinning();
  205. bool _validate_tracks(const Ref<Animation> p_anim);
  206. void _pin_pressed();
  207. String _get_current() const;
  208. void _ensure_dummy_player();
  209. ~AnimationPlayerEditor();
  210. protected:
  211. void _notification(int p_what);
  212. void _node_removed(Node *p_node);
  213. static void _bind_methods();
  214. public:
  215. AnimationMixer *get_editing_node() const;
  216. AnimationPlayer *get_player() const;
  217. AnimationMixer *fetch_mixer_for_library() const;
  218. Node *get_cached_root_node() const;
  219. static AnimationPlayerEditor *get_singleton() { return singleton; }
  220. bool is_pinned() const { return pin->is_pressed(); }
  221. void unpin() {
  222. pin->set_pressed(false);
  223. _pin_pressed();
  224. }
  225. AnimationTrackEditor *get_track_editor() { return track_editor; }
  226. Dictionary get_state() const;
  227. void set_state(const Dictionary &p_state);
  228. void ensure_visibility();
  229. void edit(AnimationMixer *p_node, AnimationPlayer *p_player, bool p_is_dummy);
  230. void forward_force_draw_over_viewport(Control *p_overlay);
  231. AnimationPlayerEditor(AnimationPlayerEditorPlugin *p_plugin);
  232. };
  233. class AnimationPlayerEditorPlugin : public EditorPlugin {
  234. GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
  235. friend AnimationPlayerEditor;
  236. AnimationPlayerEditor *anim_editor = nullptr;
  237. AnimationPlayer *player = nullptr;
  238. AnimationPlayer *dummy_player = nullptr;
  239. ObjectID last_mixer;
  240. void _update_dummy_player(AnimationMixer *p_mixer);
  241. void _clear_dummy_player();
  242. protected:
  243. void _notification(int p_what);
  244. void _property_keyed(const String &p_keyed, const Variant &p_value, bool p_advance);
  245. void _transform_key_request(Object *sp, const String &p_sub, const Transform3D &p_key);
  246. void _update_keying();
  247. public:
  248. virtual Dictionary get_state() const override { return anim_editor->get_state(); }
  249. virtual void set_state(const Dictionary &p_state) override { anim_editor->set_state(p_state); }
  250. virtual String get_plugin_name() const override { return "Anim"; }
  251. bool has_main_screen() const override { return false; }
  252. virtual void edit(Object *p_object) override;
  253. virtual bool handles(Object *p_object) const override;
  254. virtual void make_visible(bool p_visible) override;
  255. virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  256. virtual void forward_3d_force_draw_over_viewport(Control *p_overlay) override { anim_editor->forward_force_draw_over_viewport(p_overlay); }
  257. AnimationPlayerEditorPlugin();
  258. ~AnimationPlayerEditorPlugin();
  259. };
  260. // AnimationTrackKeyEditEditorPlugin
  261. class EditorInspectorPluginAnimationTrackKeyEdit : public EditorInspectorPlugin {
  262. GDCLASS(EditorInspectorPluginAnimationTrackKeyEdit, EditorInspectorPlugin);
  263. AnimationTrackKeyEditEditor *atk_editor = nullptr;
  264. public:
  265. virtual bool can_handle(Object *p_object) override;
  266. virtual void parse_begin(Object *p_object) override;
  267. };
  268. class AnimationTrackKeyEditEditorPlugin : public EditorPlugin {
  269. GDCLASS(AnimationTrackKeyEditEditorPlugin, EditorPlugin);
  270. EditorInspectorPluginAnimationTrackKeyEdit *atk_plugin = nullptr;
  271. public:
  272. bool has_main_screen() const override { return false; }
  273. virtual bool handles(Object *p_object) const override;
  274. virtual String get_plugin_name() const override { return "AnimationTrackKeyEdit"; }
  275. AnimationTrackKeyEditEditorPlugin();
  276. };
  277. // AnimationMarkerKeyEditEditorPlugin
  278. class EditorInspectorPluginAnimationMarkerKeyEdit : public EditorInspectorPlugin {
  279. GDCLASS(EditorInspectorPluginAnimationMarkerKeyEdit, EditorInspectorPlugin);
  280. AnimationMarkerKeyEditEditor *amk_editor = nullptr;
  281. public:
  282. virtual bool can_handle(Object *p_object) override;
  283. virtual void parse_begin(Object *p_object) override;
  284. };
  285. class AnimationMarkerKeyEditEditorPlugin : public EditorPlugin {
  286. GDCLASS(AnimationMarkerKeyEditEditorPlugin, EditorPlugin);
  287. EditorInspectorPluginAnimationMarkerKeyEdit *amk_plugin = nullptr;
  288. public:
  289. bool has_main_screen() const override { return false; }
  290. virtual bool handles(Object *p_object) const override;
  291. virtual String get_plugin_name() const override { return "AnimationMarkerKeyEdit"; }
  292. AnimationMarkerKeyEditEditorPlugin();
  293. };
  294. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H