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