animation_player_editor_plugin.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. /**
  40. @author Juan Linietsky <reduzio@gmail.com>
  41. */
  42. class AnimationTrackEditor;
  43. class AnimationPlayerEditorPlugin;
  44. class AnimationPlayerEditor : public VBoxContainer {
  45. GDCLASS(AnimationPlayerEditor, VBoxContainer);
  46. EditorNode *editor;
  47. AnimationPlayerEditorPlugin *plugin;
  48. AnimationPlayer *player;
  49. enum {
  50. TOOL_NEW_ANIM,
  51. TOOL_LOAD_ANIM,
  52. TOOL_SAVE_ANIM,
  53. TOOL_SAVE_AS_ANIM,
  54. TOOL_DUPLICATE_ANIM,
  55. TOOL_RENAME_ANIM,
  56. TOOL_EDIT_TRANSITIONS,
  57. TOOL_REMOVE_ANIM,
  58. TOOL_COPY_ANIM,
  59. TOOL_PASTE_ANIM,
  60. TOOL_EDIT_RESOURCE
  61. };
  62. enum {
  63. ONION_SKINNING_ENABLE,
  64. ONION_SKINNING_PAST,
  65. ONION_SKINNING_FUTURE,
  66. ONION_SKINNING_1_STEP,
  67. ONION_SKINNING_2_STEPS,
  68. ONION_SKINNING_3_STEPS,
  69. ONION_SKINNING_LAST_STEPS_OPTION = ONION_SKINNING_3_STEPS,
  70. ONION_SKINNING_DIFFERENCES_ONLY,
  71. ONION_SKINNING_FORCE_WHITE_MODULATE,
  72. ONION_SKINNING_INCLUDE_GIZMOS,
  73. };
  74. enum {
  75. ANIM_OPEN,
  76. ANIM_SAVE,
  77. ANIM_SAVE_AS
  78. };
  79. enum {
  80. RESOURCE_LOAD,
  81. RESOURCE_SAVE
  82. };
  83. OptionButton *animation;
  84. Button *stop;
  85. Button *play;
  86. Button *play_from;
  87. Button *play_bw;
  88. Button *play_bw_from;
  89. //Button *pause;
  90. Button *autoplay;
  91. MenuButton *tool_anim;
  92. MenuButton *onion_skinning;
  93. ToolButton *pin;
  94. SpinBox *frame;
  95. LineEdit *scale;
  96. LineEdit *name;
  97. Label *name_title;
  98. UndoRedo *undo_redo;
  99. Ref<Texture> autoplay_icon;
  100. bool last_active;
  101. EditorFileDialog *file;
  102. AcceptDialog *accept;
  103. ConfirmationDialog *delete_dialog;
  104. int current_option;
  105. struct BlendEditor {
  106. AcceptDialog *dialog;
  107. Tree *tree;
  108. OptionButton *next;
  109. } blend_editor;
  110. ConfirmationDialog *name_dialog;
  111. ConfirmationDialog *error_dialog;
  112. bool renaming;
  113. bool updating;
  114. bool updating_blends;
  115. AnimationTrackEditor *track_editor;
  116. // Onion skinning
  117. struct {
  118. // Settings
  119. bool enabled;
  120. bool past;
  121. bool future;
  122. int steps;
  123. bool differences_only;
  124. bool force_white_modulate;
  125. bool include_gizmos;
  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;
  132. int can_overlay;
  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. void _play_pressed();
  145. void _play_from_pressed();
  146. void _play_bw_pressed();
  147. void _play_bw_from_pressed();
  148. void _autoplay_pressed();
  149. void _stop_pressed();
  150. void _pause_pressed();
  151. void _animation_selected(int p_which);
  152. void _animation_new();
  153. void _animation_rename();
  154. void _animation_name_edited();
  155. void _animation_load();
  156. void _animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path);
  157. void _animation_save(const Ref<Resource> &p_resource);
  158. void _animation_save_as(const Ref<Resource> &p_resource);
  159. void _animation_remove();
  160. void _animation_remove_confirmed();
  161. void _animation_blend();
  162. void _animation_edit();
  163. void _animation_duplicate();
  164. void _animation_resource_edit();
  165. void _scale_changed(const String &p_scale);
  166. void _dialog_action(String p_file);
  167. void _seek_frame_changed(const String &p_frame);
  168. void _seek_value_changed(float p_value, bool p_set = false);
  169. void _blend_editor_next_changed(const int p_idx);
  170. void _list_changed();
  171. void _update_animation();
  172. void _update_player();
  173. void _blend_edited();
  174. void _hide_anim_editors();
  175. void _animation_player_changed(Object *p_pl);
  176. void _animation_key_editor_seek(float p_pos, bool p_drag);
  177. void _animation_key_editor_anim_len_changed(float p_len);
  178. void _animation_key_editor_anim_step_changed(float p_len);
  179. void _unhandled_key_input(const Ref<InputEvent> &p_ev);
  180. void _animation_tool_menu(int p_option);
  181. void _onion_skinning_menu(int p_option);
  182. void _animation_about_to_show_menu();
  183. void _editor_visibility_changed();
  184. bool _are_onion_layers_valid();
  185. void _allocate_onion_layers();
  186. void _free_onion_layers();
  187. void _prepare_onion_layers_1();
  188. void _prepare_onion_layers_2();
  189. void _start_onion_skinning();
  190. void _stop_onion_skinning();
  191. void _pin_pressed();
  192. AnimationPlayerEditor();
  193. ~AnimationPlayerEditor();
  194. protected:
  195. void _notification(int p_what);
  196. void _gui_input(Ref<InputEvent> p_event);
  197. void _node_removed(Node *p_node);
  198. static void _bind_methods();
  199. public:
  200. AnimationPlayer *get_player() const;
  201. static AnimationPlayerEditor *singleton;
  202. bool is_pinned() const { return pin->is_pressed(); }
  203. void unpin() { pin->set_pressed(false); }
  204. AnimationTrackEditor *get_track_editor() { return track_editor; }
  205. Dictionary get_state() const;
  206. void set_state(const Dictionary &p_state);
  207. void ensure_visibility();
  208. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  209. void edit(AnimationPlayer *p_player);
  210. void forward_canvas_force_draw_over_viewport(Control *p_overlay);
  211. AnimationPlayerEditor(EditorNode *p_editor, AnimationPlayerEditorPlugin *p_plugin);
  212. };
  213. class AnimationPlayerEditorPlugin : public EditorPlugin {
  214. GDCLASS(AnimationPlayerEditorPlugin, EditorPlugin);
  215. AnimationPlayerEditor *anim_editor;
  216. EditorNode *editor;
  217. protected:
  218. void _notification(int p_what);
  219. public:
  220. virtual Dictionary get_state() const { return anim_editor->get_state(); }
  221. virtual void set_state(const Dictionary &p_state) { anim_editor->set_state(p_state); }
  222. virtual String get_name() const { return "Anim"; }
  223. bool has_main_screen() const { return false; }
  224. virtual void edit(Object *p_object);
  225. virtual bool handles(Object *p_object) const;
  226. virtual void make_visible(bool p_visible);
  227. virtual void forward_canvas_force_draw_over_viewport(Control *p_overlay) { anim_editor->forward_canvas_force_draw_over_viewport(p_overlay); }
  228. AnimationPlayerEditorPlugin(EditorNode *p_node);
  229. ~AnimationPlayerEditorPlugin();
  230. };
  231. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H