Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/editor/animation/animation_blend_space_2d_editor.cpp
9902 views
1
/**************************************************************************/
2
/* animation_blend_space_2d_editor.cpp */
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
#include "animation_blend_space_2d_editor.h"
32
33
#include "core/io/resource_loader.h"
34
#include "core/math/geometry_2d.h"
35
#include "core/os/keyboard.h"
36
#include "editor/editor_node.h"
37
#include "editor/editor_string_names.h"
38
#include "editor/editor_undo_redo_manager.h"
39
#include "editor/gui/editor_file_dialog.h"
40
#include "editor/settings/editor_settings.h"
41
#include "editor/themes/editor_scale.h"
42
#include "scene/animation/animation_blend_tree.h"
43
#include "scene/animation/animation_player.h"
44
#include "scene/gui/button.h"
45
#include "scene/gui/check_box.h"
46
#include "scene/gui/grid_container.h"
47
#include "scene/gui/line_edit.h"
48
#include "scene/gui/menu_button.h"
49
#include "scene/gui/option_button.h"
50
#include "scene/gui/panel.h"
51
#include "scene/gui/panel_container.h"
52
#include "scene/gui/separator.h"
53
#include "scene/gui/spin_box.h"
54
#include "scene/main/window.h"
55
56
bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) {
57
Ref<AnimationNodeBlendSpace2D> bs2d = p_node;
58
return bs2d.is_valid();
59
}
60
61
void AnimationNodeBlendSpace2DEditor::_blend_space_changed() {
62
blend_space_draw->queue_redraw();
63
}
64
65
void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) {
66
if (blend_space.is_valid()) {
67
blend_space->disconnect("triangles_updated", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_changed));
68
}
69
blend_space = p_node;
70
read_only = false;
71
72
if (blend_space.is_valid()) {
73
read_only = EditorNode::get_singleton()->is_resource_read_only(blend_space);
74
75
blend_space->connect("triangles_updated", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_changed));
76
_update_space();
77
}
78
79
tool_create->set_disabled(read_only);
80
max_x_value->set_editable(!read_only);
81
min_x_value->set_editable(!read_only);
82
max_y_value->set_editable(!read_only);
83
min_y_value->set_editable(!read_only);
84
label_x->set_editable(!read_only);
85
label_y->set_editable(!read_only);
86
edit_x->set_editable(!read_only);
87
edit_y->set_editable(!read_only);
88
tool_triangle->set_disabled(read_only);
89
auto_triangles->set_disabled(read_only);
90
sync->set_disabled(read_only);
91
interpolation->set_disabled(read_only);
92
}
93
94
StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const {
95
StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position";
96
return path;
97
}
98
99
void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) {
100
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
101
if (!tree) {
102
return;
103
}
104
105
Ref<InputEventKey> k = p_event;
106
if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) {
107
if (selected_point != -1 || selected_triangle != -1) {
108
if (!read_only) {
109
_erase_selected();
110
}
111
accept_event();
112
}
113
}
114
115
Ref<InputEventMouseButton> mb = p_event;
116
117
if (mb.is_valid() && mb->is_pressed() && ((tool_select->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) || (mb->get_button_index() == MouseButton::LEFT && tool_create->is_pressed()))) {
118
if (!read_only) {
119
menu->clear(false);
120
animations_menu->clear();
121
animations_to_add.clear();
122
123
LocalVector<StringName> classes;
124
ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
125
classes.sort_custom<StringName::AlphCompare>();
126
127
menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);
128
129
List<StringName> names;
130
tree->get_animation_list(&names);
131
for (const StringName &E : names) {
132
animations_menu->add_icon_item(get_editor_theme_icon(SNAME("Animation")), E);
133
animations_to_add.push_back(E);
134
}
135
136
for (const StringName &E : classes) {
137
String name = String(E).replace_first("AnimationNode", "");
138
if (name == "Animation" || name == "StartState" || name == "EndState") {
139
continue; // nope
140
}
141
int idx = menu->get_item_count();
142
menu->add_item(vformat(TTR("Add %s"), name), idx);
143
menu->set_item_metadata(idx, E);
144
}
145
146
Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
147
if (clipb.is_valid()) {
148
menu->add_separator();
149
menu->add_item(TTR("Paste"), MENU_PASTE);
150
}
151
menu->add_separator();
152
menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
153
154
menu->set_position(blend_space_draw->get_screen_position() + mb->get_position());
155
menu->reset_size();
156
menu->popup();
157
add_point_pos = (mb->get_position() / blend_space_draw->get_size());
158
add_point_pos.y = 1.0 - add_point_pos.y;
159
add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
160
add_point_pos += blend_space->get_min_space();
161
162
if (snap->is_pressed()) {
163
add_point_pos = add_point_pos.snapped(blend_space->get_snap());
164
}
165
}
166
}
167
168
if (mb.is_valid() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
169
blend_space_draw->queue_redraw(); //update anyway
170
//try to see if a point can be selected
171
selected_point = -1;
172
selected_triangle = -1;
173
_update_tool_erase();
174
175
for (int i = 0; i < points.size(); i++) {
176
if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
177
selected_point = i;
178
Ref<AnimationNode> node = blend_space->get_blend_point_node(i);
179
EditorNode::get_singleton()->push_item(node.ptr(), "", true);
180
dragging_selected_attempt = true;
181
drag_from = mb->get_position();
182
_update_tool_erase();
183
_update_edited_point_pos();
184
return;
185
}
186
}
187
188
//then try to see if a triangle can be selected
189
if (!blend_space->get_auto_triangles()) { //if autotriangles use, disable this
190
for (int i = 0; i < blend_space->get_triangle_count(); i++) {
191
Vector<Vector2> triangle;
192
193
for (int j = 0; j < 3; j++) {
194
int idx = blend_space->get_triangle_point(i, j);
195
ERR_FAIL_INDEX(idx, points.size());
196
triangle.push_back(points[idx]);
197
}
198
199
if (Geometry2D::is_point_in_triangle(mb->get_position(), triangle[0], triangle[1], triangle[2])) {
200
selected_triangle = i;
201
_update_tool_erase();
202
return;
203
}
204
}
205
}
206
}
207
208
if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
209
blend_space_draw->queue_redraw(); //update anyway
210
//try to see if a point can be selected
211
selected_point = -1;
212
213
for (int i = 0; i < points.size(); i++) {
214
if (making_triangle.has(i)) {
215
continue;
216
}
217
218
if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
219
making_triangle.push_back(i);
220
if (making_triangle.size() == 3) {
221
//add triangle!
222
if (blend_space->has_triangle(making_triangle[0], making_triangle[1], making_triangle[2])) {
223
making_triangle.clear();
224
EditorNode::get_singleton()->show_warning(TTR("Triangle already exists."));
225
return;
226
}
227
228
updating = true;
229
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
230
undo_redo->create_action(TTR("Add Triangle"));
231
undo_redo->add_do_method(blend_space.ptr(), "add_triangle", making_triangle[0], making_triangle[1], making_triangle[2]);
232
undo_redo->add_undo_method(blend_space.ptr(), "remove_triangle", blend_space->get_triangle_count());
233
undo_redo->add_do_method(this, "_update_space");
234
undo_redo->add_undo_method(this, "_update_space");
235
undo_redo->commit_action();
236
updating = false;
237
making_triangle.clear();
238
}
239
return;
240
}
241
}
242
}
243
244
if (mb.is_valid() && !mb->is_pressed() && dragging_selected_attempt && mb->get_button_index() == MouseButton::LEFT) {
245
if (dragging_selected) {
246
//move
247
Vector2 point = blend_space->get_blend_point_position(selected_point);
248
point += drag_ofs;
249
if (snap->is_pressed()) {
250
point = point.snapped(blend_space->get_snap());
251
}
252
253
if (!read_only) {
254
updating = true;
255
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
256
undo_redo->create_action(TTR("Move Node Point"));
257
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
258
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
259
undo_redo->add_do_method(this, "_update_space");
260
undo_redo->add_undo_method(this, "_update_space");
261
undo_redo->add_do_method(this, "_update_edited_point_pos");
262
undo_redo->add_undo_method(this, "_update_edited_point_pos");
263
undo_redo->commit_action();
264
updating = false;
265
}
266
}
267
dragging_selected_attempt = false;
268
dragging_selected = false;
269
blend_space_draw->queue_redraw();
270
}
271
272
if (mb.is_valid() && mb->is_pressed() && tool_blend->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
273
Vector2 blend_pos = (mb->get_position() / blend_space_draw->get_size());
274
blend_pos.y = 1.0 - blend_pos.y;
275
blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
276
blend_pos += blend_space->get_min_space();
277
278
tree->set(get_blend_position_path(), blend_pos);
279
280
blend_space_draw->queue_redraw();
281
}
282
283
Ref<InputEventMouseMotion> mm = p_event;
284
285
if (mm.is_valid() && dragging_selected_attempt) {
286
dragging_selected = true;
287
if (!read_only) {
288
drag_ofs = ((mm->get_position() - drag_from) / blend_space_draw->get_size()) * (blend_space->get_max_space() - blend_space->get_min_space()) * Vector2(1, -1);
289
}
290
blend_space_draw->queue_redraw();
291
_update_edited_point_pos();
292
}
293
294
if (mm.is_valid() && tool_triangle->is_pressed() && making_triangle.size()) {
295
blend_space_draw->queue_redraw();
296
}
297
298
if (mm.is_valid() && !tool_triangle->is_pressed() && making_triangle.size()) {
299
making_triangle.clear();
300
blend_space_draw->queue_redraw();
301
}
302
303
if (mm.is_valid() && tool_blend->is_pressed() && (mm->get_button_mask().has_flag(MouseButtonMask::LEFT))) {
304
Vector2 blend_pos = (mm->get_position() / blend_space_draw->get_size());
305
blend_pos.y = 1.0 - blend_pos.y;
306
blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
307
blend_pos += blend_space->get_min_space();
308
309
tree->set(get_blend_position_path(), blend_pos);
310
311
blend_space_draw->queue_redraw();
312
}
313
}
314
315
void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) {
316
file_loaded = ResourceLoader::load(p_file);
317
if (file_loaded.is_valid()) {
318
_add_menu_type(MENU_LOAD_FILE_CONFIRM);
319
} else {
320
EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only animation nodes are allowed."));
321
}
322
}
323
324
void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) {
325
Ref<AnimationRootNode> node;
326
if (p_index == MENU_LOAD_FILE) {
327
open_file->clear_filters();
328
List<String> filters;
329
ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters);
330
for (const String &E : filters) {
331
open_file->add_filter("*." + E);
332
}
333
open_file->popup_file_dialog();
334
return;
335
} else if (p_index == MENU_LOAD_FILE_CONFIRM) {
336
node = file_loaded;
337
file_loaded.unref();
338
} else if (p_index == MENU_PASTE) {
339
node = EditorSettings::get_singleton()->get_resource_clipboard();
340
} else {
341
String type = menu->get_item_metadata(p_index);
342
343
Object *obj = ClassDB::instantiate(type);
344
ERR_FAIL_NULL(obj);
345
AnimationNode *an = Object::cast_to<AnimationNode>(obj);
346
ERR_FAIL_NULL(an);
347
348
node = Ref<AnimationNode>(an);
349
}
350
351
if (node.is_null()) {
352
EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed."));
353
return;
354
}
355
356
updating = true;
357
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
358
undo_redo->create_action(TTR("Add Node Point"));
359
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
360
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
361
undo_redo->add_do_method(this, "_update_space");
362
undo_redo->add_undo_method(this, "_update_space");
363
undo_redo->commit_action();
364
updating = false;
365
366
blend_space_draw->queue_redraw();
367
}
368
369
void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) {
370
Ref<AnimationNodeAnimation> anim;
371
anim.instantiate();
372
373
anim->set_animation(animations_to_add[p_index]);
374
375
updating = true;
376
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
377
undo_redo->create_action(TTR("Add Animation Point"));
378
undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
379
undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
380
undo_redo->add_do_method(this, "_update_space");
381
undo_redo->add_undo_method(this, "_update_space");
382
undo_redo->commit_action();
383
updating = false;
384
385
blend_space_draw->queue_redraw();
386
}
387
388
void AnimationNodeBlendSpace2DEditor::_update_tool_erase() {
389
tool_erase->set_disabled(
390
(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count())) ||
391
read_only);
392
393
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
394
Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
395
if (AnimationTreeEditor::get_singleton()->can_edit(an)) {
396
open_editor->show();
397
} else {
398
open_editor->hide();
399
}
400
if (!read_only) {
401
edit_hb->show();
402
} else {
403
edit_hb->hide();
404
}
405
} else {
406
edit_hb->hide();
407
}
408
}
409
410
void AnimationNodeBlendSpace2DEditor::_tool_switch(int p_tool) {
411
making_triangle.clear();
412
413
if (p_tool == 2) {
414
Vector<Vector2> bl_points;
415
for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
416
bl_points.push_back(blend_space->get_blend_point_position(i));
417
}
418
Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(bl_points);
419
for (int i = 0; i < tr.size(); i++) {
420
blend_space->add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);
421
}
422
}
423
424
if (p_tool == 0) {
425
tool_erase->show();
426
tool_erase_sep->show();
427
} else {
428
tool_erase->hide();
429
tool_erase_sep->hide();
430
}
431
_update_tool_erase();
432
blend_space_draw->queue_redraw();
433
}
434
435
void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
436
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
437
if (!tree) {
438
return;
439
}
440
441
Color linecolor = get_theme_color(SceneStringName(font_color), SNAME("Label"));
442
Color linecolor_soft = linecolor;
443
linecolor_soft.a *= 0.5;
444
Ref<Font> font = get_theme_font(SceneStringName(font), SNAME("Label"));
445
int font_size = get_theme_font_size(SceneStringName(font_size), SNAME("Label"));
446
Ref<Texture2D> icon = get_editor_theme_icon(SNAME("KeyValue"));
447
Ref<Texture2D> icon_selected = get_editor_theme_icon(SNAME("KeySelected"));
448
449
Size2 s = blend_space_draw->get_size();
450
451
if (blend_space_draw->has_focus()) {
452
Color color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
453
blend_space_draw->draw_rect(Rect2(Point2(), s), color, false);
454
}
455
blend_space_draw->draw_line(Point2(1, 0), Point2(1, s.height - 1), linecolor, Math::round(EDSCALE));
456
blend_space_draw->draw_line(Point2(1, s.height - 1), Point2(s.width - 1, s.height - 1), linecolor, Math::round(EDSCALE));
457
458
blend_space_draw->draw_line(Point2(0, 0), Point2(5 * EDSCALE, 0), linecolor, Math::round(EDSCALE));
459
if (blend_space->get_min_space().y < 0) {
460
int y = (blend_space->get_max_space().y / (blend_space->get_max_space().y - blend_space->get_min_space().y)) * s.height;
461
blend_space_draw->draw_line(Point2(0, y), Point2(5 * EDSCALE, y), linecolor, Math::round(EDSCALE));
462
blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height(font_size) + font->get_ascent(font_size)), "0", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, linecolor);
463
blend_space_draw->draw_line(Point2(5 * EDSCALE, y), Point2(s.width, y), linecolor_soft, Math::round(EDSCALE));
464
}
465
466
if (blend_space->get_min_space().x < 0) {
467
int x = (-blend_space->get_min_space().x / (blend_space->get_max_space().x - blend_space->get_min_space().x)) * s.width;
468
blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor, Math::round(EDSCALE));
469
blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height(font_size) + font->get_ascent(font_size)), "0", HORIZONTAL_ALIGNMENT_LEFT, -1, font_size, linecolor);
470
blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft, Math::round(EDSCALE));
471
}
472
473
if (snap->is_pressed()) {
474
linecolor_soft.a = linecolor.a * 0.1;
475
476
if (blend_space->get_snap().x > 0) {
477
int prev_idx = 0;
478
for (int i = 0; i < s.x; i++) {
479
float v = blend_space->get_min_space().x + i * (blend_space->get_max_space().x - blend_space->get_min_space().x) / s.x;
480
int idx = int(v / blend_space->get_snap().x);
481
482
if (i > 0 && prev_idx != idx) {
483
blend_space_draw->draw_line(Point2(i, 0), Point2(i, s.height), linecolor_soft, Math::round(EDSCALE));
484
}
485
486
prev_idx = idx;
487
}
488
}
489
490
if (blend_space->get_snap().y > 0) {
491
int prev_idx = 0;
492
for (int i = 0; i < s.y; i++) {
493
float v = blend_space->get_max_space().y - i * (blend_space->get_max_space().y - blend_space->get_min_space().y) / s.y;
494
int idx = int(v / blend_space->get_snap().y);
495
496
if (i > 0 && prev_idx != idx) {
497
blend_space_draw->draw_line(Point2(0, i), Point2(s.width, i), linecolor_soft, Math::round(EDSCALE));
498
}
499
500
prev_idx = idx;
501
}
502
}
503
}
504
505
//triangles first
506
for (int i = 0; i < blend_space->get_triangle_count(); i++) {
507
Vector<Vector2> bl_points;
508
bl_points.resize(3);
509
510
for (int j = 0; j < 3; j++) {
511
int point_idx = blend_space->get_triangle_point(i, j);
512
Vector2 point = blend_space->get_blend_point_position(point_idx);
513
if (dragging_selected && selected_point == point_idx) {
514
point += drag_ofs;
515
if (snap->is_pressed()) {
516
point = point.snapped(blend_space->get_snap());
517
}
518
}
519
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
520
point *= s;
521
point.y = s.height - point.y;
522
bl_points.write[j] = point;
523
}
524
525
for (int j = 0; j < 3; j++) {
526
blend_space_draw->draw_line(bl_points[j], bl_points[(j + 1) % 3], linecolor, Math::round(EDSCALE), true);
527
}
528
529
Color color;
530
if (i == selected_triangle) {
531
color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
532
color.a *= 0.5;
533
} else {
534
color = linecolor;
535
color.a *= 0.2;
536
}
537
538
Vector<Color> colors = {
539
color,
540
color,
541
color
542
};
543
blend_space_draw->draw_primitive(bl_points, colors, Vector<Vector2>());
544
}
545
546
points.clear();
547
for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
548
Vector2 point = blend_space->get_blend_point_position(i);
549
if (!read_only) {
550
if (dragging_selected && selected_point == i) {
551
point += drag_ofs;
552
if (snap->is_pressed()) {
553
point = point.snapped(blend_space->get_snap());
554
}
555
}
556
}
557
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
558
point *= s;
559
point.y = s.height - point.y;
560
561
points.push_back(point);
562
point -= (icon->get_size() / 2);
563
point = point.floor();
564
565
if (i == selected_point) {
566
blend_space_draw->draw_texture(icon_selected, point);
567
} else {
568
blend_space_draw->draw_texture(icon, point);
569
}
570
}
571
572
if (making_triangle.size()) {
573
Vector<Vector2> bl_points;
574
for (int i = 0; i < making_triangle.size(); i++) {
575
Vector2 point = blend_space->get_blend_point_position(making_triangle[i]);
576
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
577
point *= s;
578
point.y = s.height - point.y;
579
bl_points.push_back(point);
580
}
581
582
for (int i = 0; i < bl_points.size() - 1; i++) {
583
blend_space_draw->draw_line(bl_points[i], bl_points[i + 1], linecolor, Math::round(2 * EDSCALE), true);
584
}
585
blend_space_draw->draw_line(bl_points[bl_points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, Math::round(2 * EDSCALE), true);
586
}
587
588
///draw cursor position
589
590
{
591
Color color;
592
if (tool_blend->is_pressed()) {
593
color = get_theme_color(SNAME("accent_color"), EditorStringName(Editor));
594
} else {
595
color = linecolor;
596
color.a *= 0.5;
597
}
598
599
Vector2 blend_pos = tree->get(get_blend_position_path());
600
Vector2 point = blend_pos;
601
602
point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
603
point *= s;
604
point.y = s.height - point.y;
605
606
if (blend_space->get_triangle_count()) {
607
Vector2 closest = blend_space->get_closest_point(blend_pos);
608
closest = (closest - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
609
closest *= s;
610
closest.y = s.height - closest.y;
611
612
Color lcol = color;
613
lcol.a *= 0.4;
614
blend_space_draw->draw_line(point, closest, lcol, Math::round(2 * EDSCALE), true);
615
}
616
617
float mind = 5 * EDSCALE;
618
float maxd = 15 * EDSCALE;
619
blend_space_draw->draw_line(point + Vector2(mind, 0), point + Vector2(maxd, 0), color, Math::round(2 * EDSCALE));
620
blend_space_draw->draw_line(point + Vector2(-mind, 0), point + Vector2(-maxd, 0), color, Math::round(2 * EDSCALE));
621
blend_space_draw->draw_line(point + Vector2(0, mind), point + Vector2(0, maxd), color, Math::round(2 * EDSCALE));
622
blend_space_draw->draw_line(point + Vector2(0, -mind), point + Vector2(0, -maxd), color, Math::round(2 * EDSCALE));
623
}
624
}
625
626
void AnimationNodeBlendSpace2DEditor::_snap_toggled() {
627
blend_space_draw->queue_redraw();
628
}
629
630
void AnimationNodeBlendSpace2DEditor::_update_space() {
631
if (updating) {
632
return;
633
}
634
635
updating = true;
636
637
if (blend_space->get_auto_triangles()) {
638
tool_triangle->hide();
639
} else {
640
tool_triangle->show();
641
}
642
643
auto_triangles->set_pressed(blend_space->get_auto_triangles());
644
645
sync->set_pressed(blend_space->is_using_sync());
646
interpolation->select(blend_space->get_blend_mode());
647
648
max_x_value->set_value(blend_space->get_max_space().x);
649
max_y_value->set_value(blend_space->get_max_space().y);
650
651
min_x_value->set_value(blend_space->get_min_space().x);
652
min_y_value->set_value(blend_space->get_min_space().y);
653
654
label_x->set_text(blend_space->get_x_label());
655
label_y->set_text(blend_space->get_y_label());
656
657
snap_x->set_value(blend_space->get_snap().x);
658
snap_y->set_value(blend_space->get_snap().y);
659
660
blend_space_draw->queue_redraw();
661
662
updating = false;
663
}
664
665
void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
666
if (updating) {
667
return;
668
}
669
670
updating = true;
671
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
672
undo_redo->create_action(TTR("Change BlendSpace2D Config"));
673
undo_redo->add_do_method(blend_space.ptr(), "set_max_space", Vector2(max_x_value->get_value(), max_y_value->get_value()));
674
undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
675
undo_redo->add_do_method(blend_space.ptr(), "set_min_space", Vector2(min_x_value->get_value(), min_y_value->get_value()));
676
undo_redo->add_undo_method(blend_space.ptr(), "set_min_space", blend_space->get_min_space());
677
undo_redo->add_do_method(blend_space.ptr(), "set_snap", Vector2(snap_x->get_value(), snap_y->get_value()));
678
undo_redo->add_undo_method(blend_space.ptr(), "set_snap", blend_space->get_snap());
679
undo_redo->add_do_method(blend_space.ptr(), "set_use_sync", sync->is_pressed());
680
undo_redo->add_undo_method(blend_space.ptr(), "set_use_sync", blend_space->is_using_sync());
681
undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected());
682
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode());
683
undo_redo->add_do_method(this, "_update_space");
684
undo_redo->add_undo_method(this, "_update_space");
685
undo_redo->commit_action();
686
updating = false;
687
688
blend_space_draw->queue_redraw();
689
}
690
691
void AnimationNodeBlendSpace2DEditor::_labels_changed(String) {
692
if (updating) {
693
return;
694
}
695
696
updating = true;
697
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
698
undo_redo->create_action(TTR("Change BlendSpace2D Labels"), UndoRedo::MERGE_ENDS);
699
undo_redo->add_do_method(blend_space.ptr(), "set_x_label", label_x->get_text());
700
undo_redo->add_undo_method(blend_space.ptr(), "set_x_label", blend_space->get_x_label());
701
undo_redo->add_do_method(blend_space.ptr(), "set_y_label", label_y->get_text());
702
undo_redo->add_undo_method(blend_space.ptr(), "set_y_label", blend_space->get_y_label());
703
undo_redo->add_do_method(this, "_update_space");
704
undo_redo->add_undo_method(this, "_update_space");
705
undo_redo->commit_action();
706
updating = false;
707
}
708
709
void AnimationNodeBlendSpace2DEditor::_erase_selected() {
710
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
711
if (selected_point != -1) {
712
updating = true;
713
undo_redo->create_action(TTR("Remove BlendSpace2D Point"));
714
undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
715
undo_redo->add_undo_method(blend_space.ptr(), "add_blend_point", blend_space->get_blend_point_node(selected_point), blend_space->get_blend_point_position(selected_point), selected_point);
716
717
//restore triangles using this point
718
for (int i = 0; i < blend_space->get_triangle_count(); i++) {
719
for (int j = 0; j < 3; j++) {
720
if (blend_space->get_triangle_point(i, j) == selected_point) {
721
undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(i, 0), blend_space->get_triangle_point(i, 1), blend_space->get_triangle_point(i, 2), i);
722
break;
723
}
724
}
725
}
726
727
undo_redo->add_do_method(this, "_update_space");
728
undo_redo->add_undo_method(this, "_update_space");
729
undo_redo->commit_action();
730
updating = false;
731
732
blend_space_draw->queue_redraw();
733
} else if (selected_triangle != -1) {
734
updating = true;
735
undo_redo->create_action(TTR("Remove BlendSpace2D Triangle"));
736
undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle);
737
undo_redo->add_undo_method(blend_space.ptr(), "add_triangle", blend_space->get_triangle_point(selected_triangle, 0), blend_space->get_triangle_point(selected_triangle, 1), blend_space->get_triangle_point(selected_triangle, 2), selected_triangle);
738
739
undo_redo->add_do_method(this, "_update_space");
740
undo_redo->add_undo_method(this, "_update_space");
741
undo_redo->commit_action();
742
updating = false;
743
744
blend_space_draw->queue_redraw();
745
}
746
}
747
748
void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
749
if (updating) {
750
return;
751
}
752
753
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
754
Vector2 pos = blend_space->get_blend_point_position(selected_point);
755
if (dragging_selected) {
756
pos += drag_ofs;
757
if (snap->is_pressed()) {
758
pos = pos.snapped(blend_space->get_snap());
759
}
760
}
761
updating = true;
762
edit_x->set_value(pos.x);
763
edit_y->set_value(pos.y);
764
updating = false;
765
}
766
}
767
768
void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
769
if (updating) {
770
return;
771
}
772
updating = true;
773
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
774
undo_redo->create_action(TTR("Move Node Point"));
775
undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
776
undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
777
undo_redo->add_do_method(this, "_update_space");
778
undo_redo->add_undo_method(this, "_update_space");
779
undo_redo->add_do_method(this, "_update_edited_point_pos");
780
undo_redo->add_undo_method(this, "_update_edited_point_pos");
781
undo_redo->commit_action();
782
updating = false;
783
784
blend_space_draw->queue_redraw();
785
}
786
787
void AnimationNodeBlendSpace2DEditor::_notification(int p_what) {
788
switch (p_what) {
789
case NOTIFICATION_THEME_CHANGED: {
790
error_panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
791
error_label->add_theme_color_override(SceneStringName(font_color), get_theme_color(SNAME("error_color"), EditorStringName(Editor)));
792
panel->add_theme_style_override(SceneStringName(panel), get_theme_stylebox(SceneStringName(panel), SNAME("Tree")));
793
tool_blend->set_button_icon(get_editor_theme_icon(SNAME("EditPivot")));
794
tool_select->set_button_icon(get_editor_theme_icon(SNAME("ToolSelect")));
795
tool_create->set_button_icon(get_editor_theme_icon(SNAME("EditKey")));
796
tool_triangle->set_button_icon(get_editor_theme_icon(SNAME("ToolTriangle")));
797
tool_erase->set_button_icon(get_editor_theme_icon(SNAME("Remove")));
798
snap->set_button_icon(get_editor_theme_icon(SNAME("SnapGrid")));
799
open_editor->set_button_icon(get_editor_theme_icon(SNAME("Edit")));
800
auto_triangles->set_button_icon(get_editor_theme_icon(SNAME("AutoTriangle")));
801
interpolation->clear();
802
interpolation->add_icon_item(get_editor_theme_icon(SNAME("TrackContinuous")), TTR("Continuous"), 0);
803
interpolation->add_icon_item(get_editor_theme_icon(SNAME("TrackDiscrete")), TTR("Discrete"), 1);
804
interpolation->add_icon_item(get_editor_theme_icon(SNAME("TrackCapture")), TTR("Capture"), 2);
805
} break;
806
807
case NOTIFICATION_PROCESS: {
808
AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
809
if (!tree) {
810
return;
811
}
812
813
String error;
814
815
if (!tree->is_active()) {
816
error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
817
} else if (tree->is_state_invalid()) {
818
error = tree->get_invalid_state_reason();
819
} else if (blend_space->get_triangle_count() == 0) {
820
error = TTR("No triangles exist, so no blending can take place.");
821
}
822
823
if (error != error_label->get_text()) {
824
error_label->set_text(error);
825
if (!error.is_empty()) {
826
error_panel->show();
827
} else {
828
error_panel->hide();
829
}
830
}
831
} break;
832
833
case NOTIFICATION_VISIBILITY_CHANGED: {
834
set_process(is_visible_in_tree());
835
} break;
836
}
837
}
838
839
void AnimationNodeBlendSpace2DEditor::_open_editor() {
840
if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
841
Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
842
ERR_FAIL_COND(an.is_null());
843
AnimationTreeEditor::get_singleton()->enter_editor(itos(selected_point));
844
}
845
}
846
847
void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
848
EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
849
undo_redo->create_action(TTR("Toggle Auto Triangles"));
850
undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed());
851
undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles());
852
undo_redo->add_do_method(this, "_update_space");
853
undo_redo->add_undo_method(this, "_update_space");
854
undo_redo->commit_action();
855
}
856
857
void AnimationNodeBlendSpace2DEditor::_bind_methods() {
858
ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace2DEditor::_update_space);
859
ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpace2DEditor::_update_tool_erase);
860
861
ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace2DEditor::_update_edited_point_pos);
862
}
863
864
AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = nullptr;
865
866
AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
867
singleton = this;
868
updating = false;
869
870
HBoxContainer *top_hb = memnew(HBoxContainer);
871
add_child(top_hb);
872
873
Ref<ButtonGroup> bg;
874
bg.instantiate();
875
876
tool_blend = memnew(Button);
877
tool_blend->set_theme_type_variation(SceneStringName(FlatButton));
878
tool_blend->set_toggle_mode(true);
879
tool_blend->set_button_group(bg);
880
top_hb->add_child(tool_blend);
881
tool_blend->set_pressed(true);
882
tool_blend->set_tooltip_text(TTR("Set the blending position within the space"));
883
tool_blend->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(3));
884
885
tool_select = memnew(Button);
886
tool_select->set_theme_type_variation(SceneStringName(FlatButton));
887
tool_select->set_toggle_mode(true);
888
tool_select->set_button_group(bg);
889
top_hb->add_child(tool_select);
890
tool_select->set_tooltip_text(TTR("Select and move points, create points with RMB."));
891
tool_select->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(0));
892
893
tool_create = memnew(Button);
894
tool_create->set_theme_type_variation(SceneStringName(FlatButton));
895
tool_create->set_toggle_mode(true);
896
tool_create->set_button_group(bg);
897
top_hb->add_child(tool_create);
898
tool_create->set_tooltip_text(TTR("Create points."));
899
tool_create->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(1));
900
901
tool_triangle = memnew(Button);
902
tool_triangle->set_theme_type_variation(SceneStringName(FlatButton));
903
tool_triangle->set_toggle_mode(true);
904
tool_triangle->set_button_group(bg);
905
top_hb->add_child(tool_triangle);
906
tool_triangle->set_tooltip_text(TTR("Create triangles by connecting points."));
907
tool_triangle->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_tool_switch).bind(2));
908
909
tool_erase_sep = memnew(VSeparator);
910
top_hb->add_child(tool_erase_sep);
911
tool_erase = memnew(Button);
912
tool_erase->set_theme_type_variation(SceneStringName(FlatButton));
913
top_hb->add_child(tool_erase);
914
tool_erase->set_tooltip_text(TTR("Erase points and triangles."));
915
tool_erase->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_erase_selected));
916
tool_erase->set_disabled(true);
917
918
top_hb->add_child(memnew(VSeparator));
919
920
auto_triangles = memnew(Button);
921
auto_triangles->set_theme_type_variation(SceneStringName(FlatButton));
922
top_hb->add_child(auto_triangles);
923
auto_triangles->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled));
924
auto_triangles->set_toggle_mode(true);
925
auto_triangles->set_tooltip_text(TTR("Generate blend triangles automatically (instead of manually)"));
926
927
top_hb->add_child(memnew(VSeparator));
928
929
snap = memnew(Button);
930
snap->set_theme_type_variation(SceneStringName(FlatButton));
931
snap->set_toggle_mode(true);
932
top_hb->add_child(snap);
933
snap->set_pressed(true);
934
snap->set_tooltip_text(TTR("Enable snap and show grid."));
935
snap->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_snap_toggled));
936
937
snap_x = memnew(SpinBox);
938
top_hb->add_child(snap_x);
939
snap_x->set_prefix("x:");
940
snap_x->set_min(0.01);
941
snap_x->set_step(0.01);
942
snap_x->set_max(1000);
943
snap_x->set_accessibility_name(TTRC("Grid X Step"));
944
945
snap_y = memnew(SpinBox);
946
top_hb->add_child(snap_y);
947
snap_y->set_prefix("y:");
948
snap_y->set_min(0.01);
949
snap_y->set_step(0.01);
950
snap_y->set_max(1000);
951
snap_y->set_accessibility_name(TTRC("Grid Y Step"));
952
953
top_hb->add_child(memnew(VSeparator));
954
955
top_hb->add_child(memnew(Label(TTR("Sync:"))));
956
sync = memnew(CheckBox);
957
top_hb->add_child(sync);
958
sync->connect(SceneStringName(toggled), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
959
960
top_hb->add_child(memnew(VSeparator));
961
962
top_hb->add_child(memnew(Label(TTR("Blend:"))));
963
interpolation = memnew(OptionButton);
964
top_hb->add_child(interpolation);
965
interpolation->connect(SceneStringName(item_selected), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
966
967
edit_hb = memnew(HBoxContainer);
968
top_hb->add_child(edit_hb);
969
edit_hb->add_child(memnew(VSeparator));
970
edit_hb->add_child(memnew(Label(TTR("Point"))));
971
edit_x = memnew(SpinBox);
972
edit_hb->add_child(edit_x);
973
edit_x->set_min(-1000);
974
edit_x->set_step(0.01);
975
edit_x->set_max(1000);
976
edit_x->set_accessibility_name(TTRC("Blend X Value"));
977
edit_x->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_edit_point_pos));
978
edit_y = memnew(SpinBox);
979
edit_hb->add_child(edit_y);
980
edit_y->set_min(-1000);
981
edit_y->set_step(0.01);
982
edit_y->set_max(1000);
983
edit_y->set_accessibility_name(TTRC("Blend X Value"));
984
edit_y->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_edit_point_pos));
985
open_editor = memnew(Button);
986
edit_hb->add_child(open_editor);
987
open_editor->set_text(TTR("Open Editor"));
988
open_editor->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_open_editor), CONNECT_DEFERRED);
989
edit_hb->hide();
990
open_editor->hide();
991
992
HBoxContainer *main_hb = memnew(HBoxContainer);
993
add_child(main_hb);
994
main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
995
996
GridContainer *main_grid = memnew(GridContainer);
997
main_grid->set_columns(2);
998
main_hb->add_child(main_grid);
999
main_grid->set_h_size_flags(SIZE_EXPAND_FILL);
1000
{
1001
VBoxContainer *left_vbox = memnew(VBoxContainer);
1002
main_grid->add_child(left_vbox);
1003
left_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
1004
max_y_value = memnew(SpinBox);
1005
max_y_value->set_accessibility_name(TTRC("Max Y"));
1006
left_vbox->add_child(max_y_value);
1007
left_vbox->add_spacer();
1008
label_y = memnew(LineEdit);
1009
label_y->set_accessibility_name(TTRC("Y Value"));
1010
left_vbox->add_child(label_y);
1011
label_y->set_expand_to_text_length_enabled(true);
1012
left_vbox->add_spacer();
1013
min_y_value = memnew(SpinBox);
1014
min_y_value->set_accessibility_name(TTRC("Min Y"));
1015
left_vbox->add_child(min_y_value);
1016
1017
max_y_value->set_max(10000);
1018
max_y_value->set_min(0.01);
1019
max_y_value->set_step(0.01);
1020
1021
min_y_value->set_min(-10000);
1022
min_y_value->set_max(0);
1023
min_y_value->set_step(0.01);
1024
}
1025
1026
panel = memnew(PanelContainer);
1027
panel->set_clip_contents(true);
1028
main_grid->add_child(panel);
1029
panel->set_h_size_flags(SIZE_EXPAND_FILL);
1030
1031
blend_space_draw = memnew(Control);
1032
blend_space_draw->connect(SceneStringName(gui_input), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_gui_input));
1033
blend_space_draw->connect(SceneStringName(draw), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_blend_space_draw));
1034
blend_space_draw->set_focus_mode(FOCUS_ALL);
1035
1036
panel->add_child(blend_space_draw);
1037
main_grid->add_child(memnew(Control)); //empty bottom left
1038
1039
{
1040
HBoxContainer *bottom_vbox = memnew(HBoxContainer);
1041
main_grid->add_child(bottom_vbox);
1042
bottom_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
1043
min_x_value = memnew(SpinBox);
1044
min_x_value->set_accessibility_name(TTRC("Min X"));
1045
bottom_vbox->add_child(min_x_value);
1046
bottom_vbox->add_spacer();
1047
label_x = memnew(LineEdit);
1048
label_y->set_accessibility_name(TTRC("X Value"));
1049
bottom_vbox->add_child(label_x);
1050
label_x->set_expand_to_text_length_enabled(true);
1051
bottom_vbox->add_spacer();
1052
max_x_value = memnew(SpinBox);
1053
max_x_value->set_accessibility_name(TTRC("Max Y"));
1054
bottom_vbox->add_child(max_x_value);
1055
1056
max_x_value->set_max(10000);
1057
max_x_value->set_min(0.01);
1058
max_x_value->set_step(0.01);
1059
1060
min_x_value->set_min(-10000);
1061
min_x_value->set_max(0);
1062
min_x_value->set_step(0.01);
1063
}
1064
1065
snap_x->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1066
snap_y->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1067
max_x_value->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1068
min_x_value->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1069
max_y_value->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1070
min_y_value->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_config_changed));
1071
label_x->connect(SceneStringName(text_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_labels_changed));
1072
label_y->connect(SceneStringName(text_changed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_labels_changed));
1073
1074
error_panel = memnew(PanelContainer);
1075
add_child(error_panel);
1076
error_label = memnew(Label);
1077
error_label->set_focus_mode(FOCUS_ACCESSIBILITY);
1078
error_panel->add_child(error_label);
1079
error_panel->hide();
1080
1081
set_custom_minimum_size(Size2(0, 300 * EDSCALE));
1082
1083
menu = memnew(PopupMenu);
1084
add_child(menu);
1085
menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeBlendSpace2DEditor::_add_menu_type));
1086
1087
animations_menu = memnew(PopupMenu);
1088
animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
1089
menu->add_child(animations_menu);
1090
animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_add_animation_type));
1091
1092
open_file = memnew(EditorFileDialog);
1093
add_child(open_file);
1094
open_file->set_title(TTR("Open Animation Node"));
1095
open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
1096
open_file->connect("file_selected", callable_mp(this, &AnimationNodeBlendSpace2DEditor::_file_opened));
1097
1098
selected_point = -1;
1099
selected_triangle = -1;
1100
1101
dragging_selected = false;
1102
dragging_selected_attempt = false;
1103
}
1104
1105