animation_player_editor_plugin.h 8.0 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-2019 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2019 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/editor_node.h"
  33. #include "editor/editor_plugin.h"
  34. #include "scene/animation/animation_player.h"
  35. #include "scene/gui/dialogs.h"
  36. #include "scene/gui/slider.h"
  37. #include "scene/gui/spin_box.h"
  38. #include "scene/gui/texture_button.h"
  39. class AnimationTrackEditor;
  40. class AnimationPlayerEditorPlugin;
  41. class AnimationPlayerEditor : public VBoxContainer {
  42. GDCLASS(AnimationPlayerEditor, VBoxContainer);
  43. EditorNode *editor;
  44. AnimationPlayerEditorPlugin *plugin;
  45. AnimationPlayer *player;
  46. enum {
  47. TOOL_NEW_ANIM,
  48. TOOL_LOAD_ANIM,
  49. TOOL_SAVE_ANIM,
  50. TOOL_SAVE_AS_ANIM,
  51. TOOL_DUPLICATE_ANIM,
  52. TOOL_RENAME_ANIM,
  53. TOOL_EDIT_TRANSITIONS,
  54. TOOL_REMOVE_ANIM,
  55. TOOL_COPY_ANIM,
  56. TOOL_PASTE_ANIM,
  57. TOOL_EDIT_RESOURCE
  58. };
  59. enum {
  60. ONION_SKINNING_ENABLE,
  61. ONION_SKINNING_PAST,
  62. ONION_SKINNING_FUTURE,
  63. ONION_SKINNING_1_STEP,
  64. ONION_SKINNING_2_STEPS,
  65. ONION_SKINNING_3_STEPS,
  66. ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
  67. ONION_SKINNING_DIFFERENCES_ONLY,
  68. ONION_SKINNING_FORCE_WHITE_MODULATE,
  69. ONION_SKINNING_INCLUDE_GIZMOS,
  70. };
  71. enum {
  72. ANIM_OPEN,
  73. ANIM_SAVE,
  74. ANIM_SAVE_AS
  75. };
  76. enum {
  77. RESOURCE_LOAD,
  78. RESOURCE_SAVE
  79. };
  80. OptionButton *animation;
  81. Button *stop;
  82. Button *play;
  83. Button *play_from;
  84. Button *play_bw;
  85. Button *play_bw_from;
  86. Button *autoplay;
  87. MenuButton *tool_anim;
  88. ToolButton *onion_toggle;
  89. MenuButton *onion_skinning;
  90. ToolButton *pin;
  91. SpinBox *frame;
  92. LineEdit *scale;
  93. LineEdit *name;
  94. Label *name_title;
  95. UndoRedo *undo_redo;
  96. Ref<Texture> autoplay_icon;
  97. bool last_active;
  98. EditorFileDialog *file;
  99. AcceptDialog *accept;
  100. ConfirmationDialog *delete_dialog;
  101. int current_option;
  102. struct BlendEditor {
  103. AcceptDialog *dialog;
  104. Tree *tree;
  105. OptionButton *next;
  106. } blend_editor;
  107. ConfirmationDialog *name_dialog;
  108. ConfirmationDialog *error_dialog;
  109. bool renaming;
  110. bool updating;
  111. bool updating_blends;
  112. AnimationTrackEditor *track_editor;
  113. // Onion skinning
  114. struct {
  115. // Settings
  116. bool enabled;
  117. bool past;
  118. bool future;
  119. int steps;
  120. bool differences_only;
  121. bool force_white_modulate;
  122. bool include_gizmos;
  123. int get_needed_capture_count() const {
  124. // 'Differences only' needs a capture of the present
  125. return (past && future ? 2 * steps : steps) + (differences_only ? 1 : 0);
  126. }
  127. // Rendering
  128. int64_t last_frame;
  129. int can_overlay;
  130. Size2 capture_size;
  131. Vector<RID> captures;
  132. Vector<bool> captures_valid;
  133. struct {
  134. RID canvas;
  135. RID canvas_item;
  136. Ref<ShaderMaterial> material;
  137. Ref<Shader> shader;
  138. } capture;
  139. } onion;
  140. void _select_anim_by_name(const String &p_anim);
  141. void _play_pressed();
  142. void _play_from_pressed();
  143. void _play_bw_pressed();
  144. void _play_bw_from_pressed();
  145. void _autoplay_pressed();
  146. void _stop_pressed();
  147. void _animation_selected(int p_which);
  148. void _animation_new();
  149. void _animation_rename();
  150. void _animation_name_edited();
  151. void _animation_load();
  152. void _animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path);
  153. void _animation_save(const Ref<Resource> &p_resource);
  154. void _animation_save_as(const Ref<Resource> &p_resource);
  155. void _animation_remove();
  156. void _animation_remove_confirmed();
  157. void _animation_blend();
  158. void _animation_edit();
  159. void _animation_duplicate();
  160. void _animation_resource_edit();
  161. void _scale_changed(const String &p_scale);
  162. void _dialog_action(String p_file);
  163. void _seek_frame_changed(const String &p_frame);
  164. void _seek_value_changed(float p_value, bool p_set = false);
  165. void _blend_editor_next_changed(const int p_idx);
  166. void _list_changed();
  167. void _update_animation();
  168. void _update_player();
  169. void _blend_edited();
  170. void _hide_anim_editors();
  171. void _animation_player_changed(Object *p_pl);
  172. void _animation_key_editor_seek(float p_pos, bool p_drag);
  173. void _animation_key_editor_anim_len_changed(float p_len);
  174. void _unhandled_key_input(const Ref<InputEvent> &p_ev);
  175. void _animation_tool_menu(int p_option);
  176. void _onion_skinning_menu(int p_option);
  177. void _animation_about_to_show_menu();
  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_2();
  184. void _start_onion_skinning();
  185. void _stop_onion_skinning();
  186. void _pin_pressed();
  187. AnimationPlayerEditor();
  188. ~AnimationPlayerEditor();
  189. protected:
  190. void _notification(int p_what);
  191. void _node_removed(Node *p_node);
  192. static void _bind_methods();
  193. public:
  194. AnimationPlayer *get_player() const;
  195. static AnimationPlayerEditor *singleton;
  196. bool is_pinned() const { return pin->is_pressed(); }
  197. void unpin() { pin->set_pressed(false); }
  198. AnimationTrackEditor *get_track_editor() { return track_editor; }
  199. Dictionary get_state() const;
  200. void set_state(const Dictionary &p_state);
  201. void ensure_visibility();
  202. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  203. void edit(AnimationPlayer *p_player);
  204. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  205. AnimationPlayerEditor(EditorNode *p_editor, AnimationPlayerEditorPlugin *p_plugin);
  206. };
  207. class AnimationPlayerEditorPlugin : public EditorPlugin {
  208. GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
  209. AnimationPlayerEditor *anim_editor;
  210. EditorNode *editor;
  211. protected:
  212. void _notification(int p_what);
  213. public:
  214. virtual Dictionary get_state() const { return anim_editor->get_state(); }
  215. virtual void set_state(const Dictionary &p_state) { anim_editor->set_state(p_state); }
  216. virtual String get_name() const { return "Anim"; }
  217. bool has_main_screen() const { return false; }
  218. virtual void edit(Object *p_object);
  219. virtual bool handles(Object *p_object) const;
  220. virtual void make_visible(bool p_visible);
  221. virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) { anim_editor->forward_canvas_force_draw_over_viewport(p_overlay); }
  222. AnimationPlayerEditorPlugin(EditorNode *p_node);
  223. ~AnimationPlayerEditorPlugin();
  224. };
  225. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H