animation_player_editor_plugin.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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-2020 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2020 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 AnimationKeyEditor;
  43. class AnimationPlayerEditor : public VBoxContainer {
  44. OBJ_TYPE(AnimationPlayerEditor, VBoxContainer);
  45. EditorNode *editor;
  46. AnimationPlayer *player;
  47. enum {
  48. TOOL_COPY_ANIM,
  49. TOOL_PASTE_ANIM,
  50. TOOL_EDIT_RESOURCE
  51. };
  52. enum {
  53. ANIM_SAVE,
  54. ANIM_SAVE_AS
  55. };
  56. enum {
  57. RESOURCE_LOAD,
  58. RESOURCE_SAVE
  59. };
  60. OptionButton *animation;
  61. Button *stop;
  62. Button *play;
  63. Button *play_from;
  64. Button *play_bw;
  65. Button *play_bw_from;
  66. // Button *pause;
  67. Button *add_anim;
  68. Button *autoplay;
  69. Button *rename_anim;
  70. Button *duplicate_anim;
  71. Button *resource_edit_anim;
  72. Button *load_anim;
  73. MenuButton *save_anim;
  74. Button *blend_anim;
  75. Button *remove_anim;
  76. MenuButton *tool_anim;
  77. ToolButton *pin;
  78. Button *nodename;
  79. SpinBox *frame;
  80. LineEdit *scale;
  81. LineEdit *name;
  82. Label *name_title;
  83. UndoRedo *undo_redo;
  84. Ref<Texture> autoplay_icon;
  85. bool last_active;
  86. EditorFileDialog *file;
  87. AcceptDialog *accept;
  88. ConfirmationDialog *delete_dialog;
  89. int current_option;
  90. struct BlendEditor {
  91. AcceptDialog *dialog;
  92. Tree *tree;
  93. OptionButton *next;
  94. } blend_editor;
  95. ConfirmationDialog *name_dialog;
  96. ConfirmationDialog *error_dialog;
  97. bool renaming;
  98. bool updating;
  99. bool updating_blends;
  100. AnimationKeyEditor *key_editor;
  101. void _select_anim_by_name(const String &p_anim);
  102. void _play_pressed();
  103. void _play_from_pressed();
  104. void _play_bw_pressed();
  105. void _play_bw_from_pressed();
  106. void _autoplay_pressed();
  107. void _stop_pressed();
  108. void _pause_pressed();
  109. void _animation_selected(int p_which);
  110. void _animation_new();
  111. void _animation_rename();
  112. void _animation_name_edited();
  113. void _animation_load();
  114. void _animation_save_in_path(const Ref<Resource> &p_resource, const String &p_path);
  115. void _animation_save(const Ref<Resource> &p_resource);
  116. void _animation_save_as(const Ref<Resource> &p_resource);
  117. void _animation_remove();
  118. void _animation_remove_confirmed();
  119. void _animation_blend();
  120. void _animation_edit();
  121. void _animation_duplicate();
  122. void _animation_resource_edit();
  123. void _scale_changed(const String &p_scale);
  124. void _dialog_action(String p_file);
  125. void _seek_frame_changed(const String &p_frame);
  126. void _seek_value_changed(float p_value, bool p_set = false);
  127. void _blend_editor_next_changed(const int p_idx);
  128. void _list_changed();
  129. void _update_animation();
  130. void _update_player();
  131. void _blend_edited();
  132. void _hide_anim_editors();
  133. void _animation_player_changed(Object *p_pl);
  134. void _animation_key_editor_seek(float p_pos, bool p_drag);
  135. void _animation_key_editor_anim_len_changed(float p_new);
  136. void _animation_key_editor_anim_step_changed(float p_len);
  137. void _unhandled_key_input(const InputEvent &p_ev);
  138. void _animation_tool_menu(int p_option);
  139. void _animation_save_menu(int p_option);
  140. AnimationPlayerEditor();
  141. protected:
  142. void _notification(int p_what);
  143. void _input_event(InputEvent p_event);
  144. void _node_removed(Node *p_node);
  145. static void _bind_methods();
  146. public:
  147. AnimationPlayer *get_player() const;
  148. static AnimationPlayerEditor *singleton;
  149. AnimationKeyEditor *get_key_editor() { return key_editor; }
  150. Dictionary get_state() const;
  151. void set_state(const Dictionary &p_state);
  152. void ensure_visibility();
  153. void set_undo_redo(UndoRedo *p_undo_redo) { undo_redo = p_undo_redo; }
  154. void edit(AnimationPlayer *p_player);
  155. AnimationPlayerEditor(EditorNode *p_editor);
  156. };
  157. class AnimationPlayerEditorPlugin : public EditorPlugin {
  158. OBJ_TYPE(AnimationPlayerEditorPlugin, EditorPlugin);
  159. AnimationPlayerEditor *anim_editor;
  160. EditorNode *editor;
  161. public:
  162. virtual Dictionary get_state() const { return anim_editor->get_state(); }
  163. virtual void set_state(const Dictionary &p_state) { anim_editor->set_state(p_state); }
  164. virtual String get_name() const { return "Anim"; }
  165. bool has_main_screen() const { return false; }
  166. virtual void edit(Object *p_node);
  167. virtual bool handles(Object *p_node) const;
  168. virtual void make_visible(bool p_visible);
  169. AnimationPlayerEditorPlugin(EditorNode *p_node);
  170. ~AnimationPlayerEditorPlugin();
  171. };
  172. #endif // ANIMATION_PLAYER_EDITOR_PLUGIN_H