1 /*************************************************************************/ 2 /* animation_blend_space_2d_editor.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 31 #ifndef ANIMATION_BLEND_SPACE_2D_EDITOR_H 32 #define ANIMATION_BLEND_SPACE_2D_EDITOR_H 33 34 #include "editor/editor_node.h" 35 #include "editor/editor_plugin.h" 36 #include "editor/plugins/animation_tree_editor_plugin.h" 37 #include "editor/property_editor.h" 38 #include "scene/animation/animation_blend_space_2d.h" 39 #include "scene/gui/button.h" 40 #include "scene/gui/graph_edit.h" 41 #include "scene/gui/popup.h" 42 #include "scene/gui/tree.h" 43 44 class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin { 45 46 GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin); 47 48 Ref<AnimationNodeBlendSpace2D> blend_space; 49 50 PanelContainer *panel; 51 ToolButton *tool_blend; 52 ToolButton *tool_select; 53 ToolButton *tool_create; 54 ToolButton *tool_triangle; 55 VSeparator *tool_erase_sep; 56 ToolButton *tool_erase; 57 ToolButton *snap; 58 SpinBox *snap_x; 59 SpinBox *snap_y; 60 OptionButton *interpolation; 61 62 ToolButton *auto_triangles; 63 64 LineEdit *label_x; 65 LineEdit *label_y; 66 SpinBox *max_x_value; 67 SpinBox *min_x_value; 68 SpinBox *max_y_value; 69 SpinBox *min_y_value; 70 71 HBoxContainer *edit_hb; 72 SpinBox *edit_x; 73 SpinBox *edit_y; 74 Button *open_editor; 75 76 int selected_point; 77 int selected_triangle; 78 79 Control *blend_space_draw; 80 81 PanelContainer *error_panel; 82 Label *error_label; 83 84 bool updating; 85 86 UndoRedo *undo_redo; 87 88 static AnimationNodeBlendSpace2DEditor *singleton; 89 90 void _blend_space_gui_input(const Ref<InputEvent> &p_event); 91 void _blend_space_draw(); 92 93 void _update_space(); 94 95 void _config_changed(double); 96 void _labels_changed(String); 97 void _snap_toggled(); 98 99 PopupMenu *menu; 100 PopupMenu *animations_menu; 101 Vector<String> animations_to_add; 102 Vector2 add_point_pos; 103 Vector<Vector2> points; 104 105 bool dragging_selected_attempt; 106 bool dragging_selected; 107 Vector2 drag_from; 108 Vector2 drag_ofs; 109 110 Vector<int> making_triangle; 111 112 void _add_menu_type(int p_index); 113 void _add_animation_type(int p_index); 114 115 void _tool_switch(int p_tool); 116 void _update_edited_point_pos(); 117 void _update_tool_erase(); 118 void _erase_selected(); 119 void _edit_point_pos(double); 120 void _open_editor(); 121 122 void _removed_from_graph(); 123 124 void _auto_triangles_toggled(); 125 126 StringName get_blend_position_path() const; 127 128 EditorFileDialog *open_file; 129 Ref<AnimationNode> file_loaded; 130 void _file_opened(const String &p_file); 131 132 enum { 133 MENU_LOAD_FILE = 1000, 134 MENU_PASTE = 1001, 135 MENU_LOAD_FILE_CONFIRM = 1002 136 }; 137 138 void _blend_space_changed(); 139 140 protected: 141 void _notification(int p_what); 142 static void _bind_methods(); 143 144 public: get_singleton()145 static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; } 146 virtual bool can_edit(const Ref<AnimationNode> &p_node); 147 virtual void edit(const Ref<AnimationNode> &p_node); 148 AnimationNodeBlendSpace2DEditor(); 149 }; 150 151 #endif // ANIMATION_BLEND_SPACE_2D_EDITOR_H 152