Skip to content
0.2.0-dev Download ZIP
177 lines ·6.1 KB Raw
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) 2014-present Godot Engine contributors (see AUTHORS.md). */
9/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
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#pragma once
32
33#include "editor/animation/animation_tree_editor_plugin.h"
34#include "editor/plugins/editor_plugin.h"
35#include "scene/animation/animation_blend_space_2d.h"
36#include "scene/gui/graph_edit.h"
37
38class Button;
39class CheckBox;
40class LineEdit;
41class OptionButton;
42class PanelContainer;
43class SpinBox;
44class Timer;
45class VSeparator;
46
47class AnimationNodeBlendSpace2DEditor : public AnimationTreeNodeEditorPlugin {
48 GDCLASS(AnimationNodeBlendSpace2DEditor, AnimationTreeNodeEditorPlugin);
49
50 Ref<AnimationNodeBlendSpace2D> blend_space;
51 bool read_only = false;
52
53 static constexpr float POINT_MARGIN = 6.0f;
54 static constexpr double STEP_UNIT = 0.01;
55 static constexpr double ABS_MAX = 10000;
56
57 PanelContainer *panel = nullptr;
58 Button *tool_blend = nullptr;
59 Button *tool_select = nullptr;
60 Button *tool_create = nullptr;
61 Button *tool_triangle = nullptr;
62 VSeparator *tool_erase_sep = nullptr;
63 Button *tool_erase = nullptr;
64 Button *snap = nullptr;
65 SpinBox *snap_x = nullptr;
66 SpinBox *snap_y = nullptr;
67 OptionButton *sync = nullptr;
68 SpinBox *cyclic_length_value = nullptr;
69 OptionButton *interpolation = nullptr;
70
71 Button *auto_triangles = nullptr;
72
73 LineEdit *label_x = nullptr;
74 LineEdit *label_y = nullptr;
75 SpinBox *max_x_value = nullptr;
76 SpinBox *min_x_value = nullptr;
77 SpinBox *max_y_value = nullptr;
78 SpinBox *min_y_value = nullptr;
79
80 HBoxContainer *edit_hb = nullptr;
81 SpinBox *edit_x = nullptr;
82 SpinBox *edit_y = nullptr;
83 Button *open_editor = nullptr;
84 VSeparator *open_editor_sep = nullptr;
85 SpinBox *index_edit = nullptr;
86
87 int selected_point;
88 int selected_triangle;
89
90 Control *blend_space_draw = nullptr;
91
92 bool updating;
93
94 static AnimationNodeBlendSpace2DEditor *singleton;
95
96 void _blend_space_gui_input(const Ref<InputEvent> &p_event);
97 void _blend_space_draw();
98
99 void _update_space();
100
101 void _config_changed(double);
102 void _labels_changed(String);
103 void _snap_toggled();
104
105 PopupMenu *menu = nullptr;
106 PopupMenu *animations_menu = nullptr;
107 Vector<StringName> animations_to_add;
108 Vector2 add_point_pos;
109 Vector<Vector2> points;
110
111 bool dragging_blend_position;
112 bool dragging_selected_attempt;
113 bool dragging_selected;
114 Vector2 drag_from;
115 Vector2 drag_ofs;
116
117 Vector<Rect2> text_rects;
118 int editing_point = -1;
119 LineEdit *inline_editor = nullptr;
120 float inline_editor_point_x = 0.0f;
121 bool index_edit_has_focus = false;
122 bool show_indices = false;
123 Timer *index_focus_cooldown_timer = nullptr;
124
125 Vector<int> making_triangle;
126
127 void _add_menu_type(int p_index);
128 void _add_animation_type(int p_index);
129
130 void _tool_switch(int p_tool);
131 void _update_edited_point_pos();
132 void _update_edited_point_name();
133 void _update_tool_erase();
134 void _erase_selected();
135 void _edit_point_pos(double);
136 void _edit_point_name(const String &p_name);
137 void _edit_point_index(double p_index);
138 void _set_selected_point(int p_index);
139 void _start_inline_edit(int p_point);
140 void _finish_inline_edit();
141 void _finish_inline_edit_with_text(const String &p_text);
142 void _cancel_inline_edit();
143 void _inline_editor_text_changed(const String &p_text);
144 void _open_editor();
145 void _index_edit_focus_entered();
146 void _index_edit_focus_exited();
147 void _index_focus_cooldown_timeout();
148 void _show_indices_with_cooldown();
149
150 void _auto_triangles_toggled();
151
152 StringName get_blend_position_path() const;
153 String _get_safe_name(const Ref<AnimationNodeBlendSpace2D> &p_blend_space, const String &p_name);
154
155 EditorFileDialog *open_file = nullptr;
156 Ref<AnimationNode> file_loaded;
157 void _file_opened(const String &p_file);
158
159 enum {
160 MENU_LOAD_FILE = 1000,
161 MENU_PASTE = 1001,
162 MENU_LOAD_FILE_CONFIRM = 1002
163 };
164
165 void _blend_space_changed();
166
167protected:
168 void _notification(int p_what);
169 static void _bind_methods();
170
171public:
172 static AnimationNodeBlendSpace2DEditor *get_singleton() { return singleton; }
173 void refresh_editor() { _update_space(); }
174 virtual bool can_edit(const Ref<AnimationNode> &p_node) override;
175 virtual void edit(const Ref<AnimationNode> &p_node) override;
176 AnimationNodeBlendSpace2DEditor();
177};