animation_blend_space_2d_editor.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072
  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) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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. #include "animation_blend_space_2d_editor.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/math/delaunay.h"
  33. #include "core/os/input.h"
  34. #include "core/os/keyboard.h"
  35. #include "core/project_settings.h"
  36. #include "editor/editor_scale.h"
  37. #include "scene/animation/animation_blend_tree.h"
  38. #include "scene/animation/animation_player.h"
  39. #include "scene/gui/menu_button.h"
  40. #include "scene/gui/panel.h"
  41. #include "scene/main/viewport.h"
  42. bool AnimationNodeBlendSpace2DEditor::can_edit(const Ref<AnimationNode> &p_node) {
  43. Ref<AnimationNodeBlendSpace2D> bs2d = p_node;
  44. return bs2d.is_valid();
  45. }
  46. void AnimationNodeBlendSpace2DEditor::_blend_space_changed() {
  47. blend_space_draw->update();
  48. }
  49. void AnimationNodeBlendSpace2DEditor::edit(const Ref<AnimationNode> &p_node) {
  50. if (blend_space.is_valid()) {
  51. blend_space->disconnect("triangles_updated", this, "_blend_space_changed");
  52. }
  53. blend_space = p_node;
  54. if (!blend_space.is_null()) {
  55. blend_space->connect("triangles_updated", this, "_blend_space_changed");
  56. _update_space();
  57. }
  58. }
  59. StringName AnimationNodeBlendSpace2DEditor::get_blend_position_path() const {
  60. StringName path = AnimationTreeEditor::get_singleton()->get_base_path() + "blend_position";
  61. return path;
  62. }
  63. void AnimationNodeBlendSpace2DEditor::_blend_space_gui_input(const Ref<InputEvent> &p_event) {
  64. Ref<InputEventKey> k = p_event;
  65. if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && !k->is_echo()) {
  66. if (selected_point != -1 || selected_triangle != -1) {
  67. _erase_selected();
  68. accept_event();
  69. }
  70. }
  71. Ref<InputEventMouseButton> mb = p_event;
  72. if (mb.is_valid() && mb->is_pressed() && ((tool_select->is_pressed() && mb->get_button_index() == BUTTON_RIGHT) || (mb->get_button_index() == BUTTON_LEFT && tool_create->is_pressed()))) {
  73. menu->clear();
  74. animations_menu->clear();
  75. animations_to_add.clear();
  76. List<StringName> classes;
  77. classes.sort_custom<StringName::AlphCompare>();
  78. ClassDB::get_inheriters_from_class("AnimationRootNode", &classes);
  79. menu->add_submenu_item(TTR("Add Animation"), "animations");
  80. AnimationTree *gp = AnimationTreeEditor::get_singleton()->get_tree();
  81. ERR_FAIL_COND(!gp);
  82. if (gp && gp->has_node(gp->get_animation_player())) {
  83. AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(gp->get_node(gp->get_animation_player()));
  84. if (ap) {
  85. List<StringName> names;
  86. ap->get_animation_list(&names);
  87. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  88. animations_menu->add_icon_item(get_icon("Animation", "EditorIcons"), E->get());
  89. animations_to_add.push_back(E->get());
  90. }
  91. }
  92. }
  93. for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
  94. String name = String(E->get()).replace_first("AnimationNode", "");
  95. if (name == "Animation")
  96. continue; // nope
  97. int idx = menu->get_item_count();
  98. menu->add_item(vformat("Add %s", name), idx);
  99. menu->set_item_metadata(idx, E->get());
  100. }
  101. Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
  102. if (clipb.is_valid()) {
  103. menu->add_separator();
  104. menu->add_item(TTR("Paste"), MENU_PASTE);
  105. }
  106. menu->add_separator();
  107. menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
  108. menu->set_global_position(blend_space_draw->get_global_transform().xform(mb->get_position()));
  109. menu->popup();
  110. add_point_pos = (mb->get_position() / blend_space_draw->get_size());
  111. add_point_pos.y = 1.0 - add_point_pos.y;
  112. add_point_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  113. add_point_pos += blend_space->get_min_space();
  114. if (snap->is_pressed()) {
  115. add_point_pos.x = Math::stepify(add_point_pos.x, blend_space->get_snap().x);
  116. add_point_pos.y = Math::stepify(add_point_pos.y, blend_space->get_snap().y);
  117. }
  118. }
  119. if (mb.is_valid() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  120. blend_space_draw->update(); //update anyway
  121. //try to see if a point can be selected
  122. selected_point = -1;
  123. selected_triangle = -1;
  124. _update_tool_erase();
  125. for (int i = 0; i < points.size(); i++) {
  126. if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
  127. selected_point = i;
  128. Ref<AnimationNode> node = blend_space->get_blend_point_node(i);
  129. EditorNode::get_singleton()->push_item(node.ptr(), "", true);
  130. dragging_selected_attempt = true;
  131. drag_from = mb->get_position();
  132. _update_tool_erase();
  133. _update_edited_point_pos();
  134. return;
  135. }
  136. }
  137. //then try to see if a triangle can be selected
  138. if (!blend_space->get_auto_triangles()) { //if autotriangles use, disable this
  139. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  140. Vector<Vector2> triangle;
  141. for (int j = 0; j < 3; j++) {
  142. int idx = blend_space->get_triangle_point(i, j);
  143. ERR_FAIL_INDEX(idx, points.size());
  144. triangle.push_back(points[idx]);
  145. }
  146. if (Geometry::is_point_in_triangle(mb->get_position(), triangle[0], triangle[1], triangle[2])) {
  147. selected_triangle = i;
  148. _update_tool_erase();
  149. return;
  150. }
  151. }
  152. }
  153. }
  154. if (mb.is_valid() && mb->is_pressed() && tool_triangle->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  155. blend_space_draw->update(); //update anyway
  156. //try to see if a point can be selected
  157. selected_point = -1;
  158. for (int i = 0; i < points.size(); i++) {
  159. if (making_triangle.find(i) != -1)
  160. continue;
  161. if (points[i].distance_to(mb->get_position()) < 10 * EDSCALE) {
  162. making_triangle.push_back(i);
  163. if (making_triangle.size() == 3) {
  164. //add triangle!
  165. if (blend_space->has_triangle(making_triangle[0], making_triangle[1], making_triangle[2])) {
  166. making_triangle.clear();
  167. EditorNode::get_singleton()->show_warning(TTR("Triangle already exists."));
  168. return;
  169. }
  170. updating = true;
  171. undo_redo->create_action(TTR("Add Triangle"));
  172. undo_redo->add_do_method(blend_space.ptr(), "add_triangle", making_triangle[0], making_triangle[1], making_triangle[2]);
  173. undo_redo->add_undo_method(blend_space.ptr(), "remove_triangle", blend_space->get_triangle_count());
  174. undo_redo->add_do_method(this, "_update_space");
  175. undo_redo->add_undo_method(this, "_update_space");
  176. undo_redo->commit_action();
  177. updating = false;
  178. making_triangle.clear();
  179. }
  180. return;
  181. }
  182. }
  183. }
  184. if (mb.is_valid() && !mb->is_pressed() && dragging_selected_attempt && mb->get_button_index() == BUTTON_LEFT) {
  185. if (dragging_selected) {
  186. //move
  187. Vector2 point = blend_space->get_blend_point_position(selected_point);
  188. point += drag_ofs;
  189. if (snap->is_pressed()) {
  190. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  191. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  192. }
  193. updating = true;
  194. undo_redo->create_action(TTR("Move Node Point"));
  195. undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, point);
  196. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
  197. undo_redo->add_do_method(this, "_update_space");
  198. undo_redo->add_undo_method(this, "_update_space");
  199. undo_redo->add_do_method(this, "_update_edited_point_pos");
  200. undo_redo->add_undo_method(this, "_update_edited_point_pos");
  201. undo_redo->commit_action();
  202. updating = false;
  203. _update_edited_point_pos();
  204. }
  205. dragging_selected_attempt = false;
  206. dragging_selected = false;
  207. blend_space_draw->update();
  208. }
  209. if (mb.is_valid() && mb->is_pressed() && tool_blend->is_pressed() && mb->get_button_index() == BUTTON_LEFT) {
  210. Vector2 blend_pos = (mb->get_position() / blend_space_draw->get_size());
  211. blend_pos.y = 1.0 - blend_pos.y;
  212. blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  213. blend_pos += blend_space->get_min_space();
  214. AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos);
  215. blend_space_draw->update();
  216. }
  217. Ref<InputEventMouseMotion> mm = p_event;
  218. if (mm.is_valid() && !blend_space_draw->has_focus()) {
  219. blend_space_draw->grab_focus();
  220. blend_space_draw->update();
  221. }
  222. if (mm.is_valid() && dragging_selected_attempt) {
  223. dragging_selected = true;
  224. 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);
  225. blend_space_draw->update();
  226. _update_edited_point_pos();
  227. }
  228. if (mm.is_valid() && tool_triangle->is_pressed() && making_triangle.size()) {
  229. blend_space_draw->update();
  230. }
  231. if (mm.is_valid() && !tool_triangle->is_pressed() && making_triangle.size()) {
  232. making_triangle.clear();
  233. blend_space_draw->update();
  234. }
  235. if (mm.is_valid() && tool_blend->is_pressed() && mm->get_button_mask() & BUTTON_MASK_LEFT) {
  236. Vector2 blend_pos = (mm->get_position() / blend_space_draw->get_size());
  237. blend_pos.y = 1.0 - blend_pos.y;
  238. blend_pos *= (blend_space->get_max_space() - blend_space->get_min_space());
  239. blend_pos += blend_space->get_min_space();
  240. AnimationTreeEditor::get_singleton()->get_tree()->set(get_blend_position_path(), blend_pos);
  241. blend_space_draw->update();
  242. }
  243. }
  244. void AnimationNodeBlendSpace2DEditor::_file_opened(const String &p_file) {
  245. file_loaded = ResourceLoader::load(p_file);
  246. if (file_loaded.is_valid()) {
  247. _add_menu_type(MENU_LOAD_FILE_CONFIRM);
  248. }
  249. }
  250. void AnimationNodeBlendSpace2DEditor::_add_menu_type(int p_index) {
  251. Ref<AnimationRootNode> node;
  252. if (p_index == MENU_LOAD_FILE) {
  253. open_file->clear_filters();
  254. List<String> filters;
  255. ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters);
  256. for (List<String>::Element *E = filters.front(); E; E = E->next()) {
  257. open_file->add_filter("*." + E->get());
  258. }
  259. open_file->popup_centered_ratio();
  260. return;
  261. } else if (p_index == MENU_LOAD_FILE_CONFIRM) {
  262. node = file_loaded;
  263. file_loaded.unref();
  264. } else if (p_index == MENU_PASTE) {
  265. node = EditorSettings::get_singleton()->get_resource_clipboard();
  266. } else {
  267. String type = menu->get_item_metadata(p_index);
  268. Object *obj = ClassDB::instance(type);
  269. ERR_FAIL_COND(!obj);
  270. AnimationNode *an = Object::cast_to<AnimationNode>(obj);
  271. ERR_FAIL_COND(!an);
  272. node = Ref<AnimationNode>(an);
  273. }
  274. if (!node.is_valid()) {
  275. EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed."));
  276. return;
  277. }
  278. updating = true;
  279. undo_redo->create_action(TTR("Add Node Point"));
  280. undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", node, add_point_pos);
  281. undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
  282. undo_redo->add_do_method(this, "_update_space");
  283. undo_redo->add_undo_method(this, "_update_space");
  284. undo_redo->commit_action();
  285. updating = false;
  286. blend_space_draw->update();
  287. }
  288. void AnimationNodeBlendSpace2DEditor::_add_animation_type(int p_index) {
  289. Ref<AnimationNodeAnimation> anim;
  290. anim.instance();
  291. anim->set_animation(animations_to_add[p_index]);
  292. updating = true;
  293. undo_redo->create_action(TTR("Add Animation Point"));
  294. undo_redo->add_do_method(blend_space.ptr(), "add_blend_point", anim, add_point_pos);
  295. undo_redo->add_undo_method(blend_space.ptr(), "remove_blend_point", blend_space->get_blend_point_count());
  296. undo_redo->add_do_method(this, "_update_space");
  297. undo_redo->add_undo_method(this, "_update_space");
  298. undo_redo->commit_action();
  299. updating = false;
  300. blend_space_draw->update();
  301. }
  302. void AnimationNodeBlendSpace2DEditor::_update_tool_erase() {
  303. tool_erase->set_disabled(!(selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) && !(selected_triangle >= 0 && selected_triangle < blend_space->get_triangle_count()));
  304. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  305. Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
  306. if (AnimationTreeEditor::get_singleton()->can_edit(an)) {
  307. open_editor->show();
  308. } else {
  309. open_editor->hide();
  310. }
  311. edit_hb->show();
  312. } else {
  313. edit_hb->hide();
  314. }
  315. }
  316. void AnimationNodeBlendSpace2DEditor::_tool_switch(int p_tool) {
  317. making_triangle.clear();
  318. if (p_tool == 2) {
  319. Vector<Vector2> points;
  320. for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
  321. points.push_back(blend_space->get_blend_point_position(i));
  322. }
  323. Vector<Delaunay2D::Triangle> tr = Delaunay2D::triangulate(points);
  324. for (int i = 0; i < tr.size(); i++) {
  325. blend_space->add_triangle(tr[i].points[0], tr[i].points[1], tr[i].points[2]);
  326. }
  327. }
  328. if (p_tool == 0) {
  329. tool_erase->show();
  330. tool_erase_sep->show();
  331. } else {
  332. tool_erase->hide();
  333. tool_erase_sep->hide();
  334. }
  335. _update_tool_erase();
  336. blend_space_draw->update();
  337. }
  338. void AnimationNodeBlendSpace2DEditor::_blend_space_draw() {
  339. Color linecolor = get_color("font_color", "Label");
  340. Color linecolor_soft = linecolor;
  341. linecolor_soft.a *= 0.5;
  342. Ref<Font> font = get_font("font", "Label");
  343. Ref<Texture> icon = get_icon("KeyValue", "EditorIcons");
  344. Ref<Texture> icon_selected = get_icon("KeySelected", "EditorIcons");
  345. Size2 s = blend_space_draw->get_size();
  346. if (blend_space_draw->has_focus()) {
  347. Color color = get_color("accent_color", "Editor");
  348. blend_space_draw->draw_rect(Rect2(Point2(), s), color, false);
  349. }
  350. blend_space_draw->draw_line(Point2(1, 0), Point2(1, s.height - 1), linecolor);
  351. blend_space_draw->draw_line(Point2(1, s.height - 1), Point2(s.width - 1, s.height - 1), linecolor);
  352. blend_space_draw->draw_line(Point2(0, 0), Point2(5 * EDSCALE, 0), linecolor);
  353. if (blend_space->get_min_space().y < 0) {
  354. int y = (blend_space->get_max_space().y / (blend_space->get_max_space().y - blend_space->get_min_space().y)) * s.height;
  355. blend_space_draw->draw_line(Point2(0, y), Point2(5 * EDSCALE, y), linecolor);
  356. blend_space_draw->draw_string(font, Point2(2 * EDSCALE, y - font->get_height() + font->get_ascent()), "0", linecolor);
  357. blend_space_draw->draw_line(Point2(5 * EDSCALE, y), Point2(s.width, y), linecolor_soft);
  358. }
  359. if (blend_space->get_min_space().x < 0) {
  360. int x = (-blend_space->get_min_space().x / (blend_space->get_max_space().x - blend_space->get_min_space().x)) * s.width;
  361. blend_space_draw->draw_line(Point2(x, s.height - 1), Point2(x, s.height - 5 * EDSCALE), linecolor);
  362. blend_space_draw->draw_string(font, Point2(x + 2 * EDSCALE, s.height - 2 * EDSCALE - font->get_height() + font->get_ascent()), "0", linecolor);
  363. blend_space_draw->draw_line(Point2(x, s.height - 5 * EDSCALE), Point2(x, 0), linecolor_soft);
  364. }
  365. if (snap->is_pressed()) {
  366. linecolor_soft.a = linecolor.a * 0.1;
  367. if (blend_space->get_snap().x > 0) {
  368. int prev_idx = 0;
  369. for (int i = 0; i < s.x; i++) {
  370. float v = blend_space->get_min_space().x + i * (blend_space->get_max_space().x - blend_space->get_min_space().x) / s.x;
  371. int idx = int(v / blend_space->get_snap().x);
  372. if (i > 0 && prev_idx != idx) {
  373. blend_space_draw->draw_line(Point2(i, 0), Point2(i, s.height), linecolor_soft);
  374. }
  375. prev_idx = idx;
  376. }
  377. }
  378. if (blend_space->get_snap().y > 0) {
  379. int prev_idx = 0;
  380. for (int i = 0; i < s.y; i++) {
  381. float v = blend_space->get_max_space().y - i * (blend_space->get_max_space().y - blend_space->get_min_space().y) / s.y;
  382. int idx = int(v / blend_space->get_snap().y);
  383. if (i > 0 && prev_idx != idx) {
  384. blend_space_draw->draw_line(Point2(0, i), Point2(s.width, i), linecolor_soft);
  385. }
  386. prev_idx = idx;
  387. }
  388. }
  389. }
  390. //triangles first
  391. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  392. Vector<Vector2> points;
  393. points.resize(3);
  394. for (int j = 0; j < 3; j++) {
  395. int point_idx = blend_space->get_triangle_point(i, j);
  396. Vector2 point = blend_space->get_blend_point_position(point_idx);
  397. if (dragging_selected && selected_point == point_idx) {
  398. point += drag_ofs;
  399. if (snap->is_pressed()) {
  400. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  401. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  402. }
  403. }
  404. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  405. point *= s;
  406. point.y = s.height - point.y;
  407. points.write[j] = point;
  408. }
  409. for (int j = 0; j < 3; j++) {
  410. blend_space_draw->draw_line(points[j], points[(j + 1) % 3], linecolor, 1, true);
  411. }
  412. Color color;
  413. if (i == selected_triangle) {
  414. color = get_color("accent_color", "Editor");
  415. color.a *= 0.5;
  416. } else {
  417. color = linecolor;
  418. color.a *= 0.2;
  419. }
  420. Vector<Color> colors;
  421. colors.push_back(color);
  422. colors.push_back(color);
  423. colors.push_back(color);
  424. blend_space_draw->draw_primitive(points, colors, Vector<Vector2>());
  425. }
  426. points.clear();
  427. for (int i = 0; i < blend_space->get_blend_point_count(); i++) {
  428. Vector2 point = blend_space->get_blend_point_position(i);
  429. if (dragging_selected && selected_point == i) {
  430. point += drag_ofs;
  431. if (snap->is_pressed()) {
  432. point.x = Math::stepify(point.x, blend_space->get_snap().x);
  433. point.y = Math::stepify(point.y, blend_space->get_snap().y);
  434. }
  435. }
  436. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  437. point *= s;
  438. point.y = s.height - point.y;
  439. points.push_back(point);
  440. point -= (icon->get_size() / 2);
  441. point = point.floor();
  442. if (i == selected_point) {
  443. blend_space_draw->draw_texture(icon_selected, point);
  444. } else {
  445. blend_space_draw->draw_texture(icon, point);
  446. }
  447. }
  448. if (making_triangle.size()) {
  449. Vector<Vector2> points;
  450. for (int i = 0; i < making_triangle.size(); i++) {
  451. Vector2 point = blend_space->get_blend_point_position(making_triangle[i]);
  452. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  453. point *= s;
  454. point.y = s.height - point.y;
  455. points.push_back(point);
  456. }
  457. for (int i = 0; i < points.size() - 1; i++) {
  458. blend_space_draw->draw_line(points[i], points[i + 1], linecolor, 2, true);
  459. }
  460. blend_space_draw->draw_line(points[points.size() - 1], blend_space_draw->get_local_mouse_position(), linecolor, 2, true);
  461. }
  462. ///draw cursor position
  463. {
  464. Color color;
  465. if (tool_blend->is_pressed()) {
  466. color = get_color("accent_color", "Editor");
  467. } else {
  468. color = linecolor;
  469. color.a *= 0.5;
  470. }
  471. Vector2 blend_pos = AnimationTreeEditor::get_singleton()->get_tree()->get(get_blend_position_path());
  472. Vector2 point = blend_pos;
  473. point = (point - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  474. point *= s;
  475. point.y = s.height - point.y;
  476. if (blend_space->get_triangle_count()) {
  477. Vector2 closest = blend_space->get_closest_point(blend_pos);
  478. closest = (closest - blend_space->get_min_space()) / (blend_space->get_max_space() - blend_space->get_min_space());
  479. closest *= s;
  480. closest.y = s.height - closest.y;
  481. Color lcol = color;
  482. lcol.a *= 0.4;
  483. blend_space_draw->draw_line(point, closest, lcol, 2);
  484. }
  485. float mind = 5 * EDSCALE;
  486. float maxd = 15 * EDSCALE;
  487. blend_space_draw->draw_line(point + Vector2(mind, 0), point + Vector2(maxd, 0), color, 2);
  488. blend_space_draw->draw_line(point + Vector2(-mind, 0), point + Vector2(-maxd, 0), color, 2);
  489. blend_space_draw->draw_line(point + Vector2(0, mind), point + Vector2(0, maxd), color, 2);
  490. blend_space_draw->draw_line(point + Vector2(0, -mind), point + Vector2(0, -maxd), color, 2);
  491. }
  492. }
  493. void AnimationNodeBlendSpace2DEditor::_snap_toggled() {
  494. blend_space_draw->update();
  495. }
  496. void AnimationNodeBlendSpace2DEditor::_update_space() {
  497. if (updating)
  498. return;
  499. updating = true;
  500. if (blend_space->get_auto_triangles()) {
  501. tool_triangle->hide();
  502. } else {
  503. tool_triangle->show();
  504. }
  505. auto_triangles->set_pressed(blend_space->get_auto_triangles());
  506. interpolation->select(blend_space->get_blend_mode());
  507. max_x_value->set_value(blend_space->get_max_space().x);
  508. max_y_value->set_value(blend_space->get_max_space().y);
  509. min_x_value->set_value(blend_space->get_min_space().x);
  510. min_y_value->set_value(blend_space->get_min_space().y);
  511. label_x->set_text(blend_space->get_x_label());
  512. label_y->set_text(blend_space->get_y_label());
  513. snap_x->set_value(blend_space->get_snap().x);
  514. snap_y->set_value(blend_space->get_snap().y);
  515. blend_space_draw->update();
  516. updating = false;
  517. }
  518. void AnimationNodeBlendSpace2DEditor::_config_changed(double) {
  519. if (updating)
  520. return;
  521. updating = true;
  522. undo_redo->create_action(TTR("Change BlendSpace2D Limits"));
  523. undo_redo->add_do_method(blend_space.ptr(), "set_max_space", Vector2(max_x_value->get_value(), max_y_value->get_value()));
  524. undo_redo->add_undo_method(blend_space.ptr(), "set_max_space", blend_space->get_max_space());
  525. undo_redo->add_do_method(blend_space.ptr(), "set_min_space", Vector2(min_x_value->get_value(), min_y_value->get_value()));
  526. undo_redo->add_undo_method(blend_space.ptr(), "set_min_space", blend_space->get_min_space());
  527. undo_redo->add_do_method(blend_space.ptr(), "set_snap", Vector2(snap_x->get_value(), snap_y->get_value()));
  528. undo_redo->add_undo_method(blend_space.ptr(), "set_snap", blend_space->get_snap());
  529. undo_redo->add_do_method(blend_space.ptr(), "set_blend_mode", interpolation->get_selected());
  530. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_mode", blend_space->get_blend_mode());
  531. undo_redo->add_do_method(this, "_update_space");
  532. undo_redo->add_undo_method(this, "_update_space");
  533. undo_redo->commit_action();
  534. updating = false;
  535. blend_space_draw->update();
  536. }
  537. void AnimationNodeBlendSpace2DEditor::_labels_changed(String) {
  538. if (updating)
  539. return;
  540. updating = true;
  541. undo_redo->create_action(TTR("Change BlendSpace2D Labels"), UndoRedo::MERGE_ENDS);
  542. undo_redo->add_do_method(blend_space.ptr(), "set_x_label", label_x->get_text());
  543. undo_redo->add_undo_method(blend_space.ptr(), "set_x_label", blend_space->get_x_label());
  544. undo_redo->add_do_method(blend_space.ptr(), "set_y_label", label_y->get_text());
  545. undo_redo->add_undo_method(blend_space.ptr(), "set_y_label", blend_space->get_y_label());
  546. undo_redo->add_do_method(this, "_update_space");
  547. undo_redo->add_undo_method(this, "_update_space");
  548. undo_redo->commit_action();
  549. updating = false;
  550. }
  551. void AnimationNodeBlendSpace2DEditor::_erase_selected() {
  552. if (selected_point != -1) {
  553. updating = true;
  554. undo_redo->create_action(TTR("Remove BlendSpace2D Point"));
  555. undo_redo->add_do_method(blend_space.ptr(), "remove_blend_point", selected_point);
  556. 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);
  557. //restore triangles using this point
  558. for (int i = 0; i < blend_space->get_triangle_count(); i++) {
  559. for (int j = 0; j < 3; j++) {
  560. if (blend_space->get_triangle_point(i, j) == selected_point) {
  561. 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);
  562. break;
  563. }
  564. }
  565. }
  566. undo_redo->add_do_method(this, "_update_space");
  567. undo_redo->add_undo_method(this, "_update_space");
  568. undo_redo->commit_action();
  569. updating = false;
  570. blend_space_draw->update();
  571. } else if (selected_triangle != -1) {
  572. updating = true;
  573. undo_redo->create_action(TTR("Remove BlendSpace2D Triangle"));
  574. undo_redo->add_do_method(blend_space.ptr(), "remove_triangle", selected_triangle);
  575. 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);
  576. undo_redo->add_do_method(this, "_update_space");
  577. undo_redo->add_undo_method(this, "_update_space");
  578. undo_redo->commit_action();
  579. updating = false;
  580. blend_space_draw->update();
  581. }
  582. }
  583. void AnimationNodeBlendSpace2DEditor::_update_edited_point_pos() {
  584. if (updating)
  585. return;
  586. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  587. Vector2 pos = blend_space->get_blend_point_position(selected_point);
  588. if (dragging_selected) {
  589. pos += drag_ofs;
  590. if (snap->is_pressed()) {
  591. pos.x = Math::stepify(pos.x, blend_space->get_snap().x);
  592. pos.y = Math::stepify(pos.y, blend_space->get_snap().y);
  593. }
  594. }
  595. updating = true;
  596. edit_x->set_value(pos.x);
  597. edit_y->set_value(pos.y);
  598. updating = false;
  599. }
  600. }
  601. void AnimationNodeBlendSpace2DEditor::_edit_point_pos(double) {
  602. if (updating)
  603. return;
  604. updating = true;
  605. undo_redo->create_action(TTR("Move Node Point"));
  606. undo_redo->add_do_method(blend_space.ptr(), "set_blend_point_position", selected_point, Vector2(edit_x->get_value(), edit_y->get_value()));
  607. undo_redo->add_undo_method(blend_space.ptr(), "set_blend_point_position", selected_point, blend_space->get_blend_point_position(selected_point));
  608. undo_redo->add_do_method(this, "_update_space");
  609. undo_redo->add_undo_method(this, "_update_space");
  610. undo_redo->add_do_method(this, "_update_edited_point_pos");
  611. undo_redo->add_undo_method(this, "_update_edited_point_pos");
  612. undo_redo->commit_action();
  613. updating = false;
  614. blend_space_draw->update();
  615. }
  616. void AnimationNodeBlendSpace2DEditor::_notification(int p_what) {
  617. if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
  618. error_panel->add_style_override("panel", get_stylebox("bg", "Tree"));
  619. error_label->add_color_override("font_color", get_color("error_color", "Editor"));
  620. panel->add_style_override("panel", get_stylebox("bg", "Tree"));
  621. tool_blend->set_icon(get_icon("EditPivot", "EditorIcons"));
  622. tool_select->set_icon(get_icon("ToolSelect", "EditorIcons"));
  623. tool_create->set_icon(get_icon("EditKey", "EditorIcons"));
  624. tool_triangle->set_icon(get_icon("ToolTriangle", "EditorIcons"));
  625. tool_erase->set_icon(get_icon("Remove", "EditorIcons"));
  626. snap->set_icon(get_icon("SnapGrid", "EditorIcons"));
  627. open_editor->set_icon(get_icon("Edit", "EditorIcons"));
  628. auto_triangles->set_icon(get_icon("AutoTriangle", "EditorIcons"));
  629. interpolation->clear();
  630. interpolation->add_icon_item(get_icon("TrackContinuous", "EditorIcons"), "", 0);
  631. interpolation->add_icon_item(get_icon("TrackDiscrete", "EditorIcons"), "", 1);
  632. interpolation->add_icon_item(get_icon("TrackCapture", "EditorIcons"), "", 2);
  633. }
  634. if (p_what == NOTIFICATION_PROCESS) {
  635. String error;
  636. if (!AnimationTreeEditor::get_singleton()->get_tree()) {
  637. error = TTR("BlendSpace2D does not belong to an AnimationTree node.");
  638. } else if (!AnimationTreeEditor::get_singleton()->get_tree()->is_active()) {
  639. error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
  640. } else if (AnimationTreeEditor::get_singleton()->get_tree()->is_state_invalid()) {
  641. error = AnimationTreeEditor::get_singleton()->get_tree()->get_invalid_state_reason();
  642. } else if (blend_space->get_triangle_count() == 0) {
  643. error = TTR("No triangles exist, so no blending can take place.");
  644. }
  645. if (error != error_label->get_text()) {
  646. error_label->set_text(error);
  647. if (error != String()) {
  648. error_panel->show();
  649. } else {
  650. error_panel->hide();
  651. }
  652. }
  653. }
  654. if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
  655. set_process(is_visible_in_tree());
  656. }
  657. }
  658. void AnimationNodeBlendSpace2DEditor::_open_editor() {
  659. if (selected_point >= 0 && selected_point < blend_space->get_blend_point_count()) {
  660. Ref<AnimationNode> an = blend_space->get_blend_point_node(selected_point);
  661. ERR_FAIL_COND(an.is_null());
  662. AnimationTreeEditor::get_singleton()->enter_editor(itos(selected_point));
  663. }
  664. }
  665. void AnimationNodeBlendSpace2DEditor::_removed_from_graph() {
  666. EditorNode::get_singleton()->edit_item(NULL);
  667. }
  668. void AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled() {
  669. undo_redo->create_action(TTR("Toggle Auto Triangles"));
  670. undo_redo->add_do_method(blend_space.ptr(), "set_auto_triangles", auto_triangles->is_pressed());
  671. undo_redo->add_undo_method(blend_space.ptr(), "set_auto_triangles", blend_space->get_auto_triangles());
  672. undo_redo->add_do_method(this, "_update_space");
  673. undo_redo->add_undo_method(this, "_update_space");
  674. undo_redo->commit_action();
  675. }
  676. void AnimationNodeBlendSpace2DEditor::_bind_methods() {
  677. ClassDB::bind_method("_blend_space_gui_input", &AnimationNodeBlendSpace2DEditor::_blend_space_gui_input);
  678. ClassDB::bind_method("_blend_space_draw", &AnimationNodeBlendSpace2DEditor::_blend_space_draw);
  679. ClassDB::bind_method("_config_changed", &AnimationNodeBlendSpace2DEditor::_config_changed);
  680. ClassDB::bind_method("_labels_changed", &AnimationNodeBlendSpace2DEditor::_labels_changed);
  681. ClassDB::bind_method("_update_space", &AnimationNodeBlendSpace2DEditor::_update_space);
  682. ClassDB::bind_method("_snap_toggled", &AnimationNodeBlendSpace2DEditor::_snap_toggled);
  683. ClassDB::bind_method("_tool_switch", &AnimationNodeBlendSpace2DEditor::_tool_switch);
  684. ClassDB::bind_method("_erase_selected", &AnimationNodeBlendSpace2DEditor::_erase_selected);
  685. ClassDB::bind_method("_update_tool_erase", &AnimationNodeBlendSpace2DEditor::_update_tool_erase);
  686. ClassDB::bind_method("_edit_point_pos", &AnimationNodeBlendSpace2DEditor::_edit_point_pos);
  687. ClassDB::bind_method("_add_menu_type", &AnimationNodeBlendSpace2DEditor::_add_menu_type);
  688. ClassDB::bind_method("_add_animation_type", &AnimationNodeBlendSpace2DEditor::_add_animation_type);
  689. ClassDB::bind_method("_update_edited_point_pos", &AnimationNodeBlendSpace2DEditor::_update_edited_point_pos);
  690. ClassDB::bind_method("_open_editor", &AnimationNodeBlendSpace2DEditor::_open_editor);
  691. ClassDB::bind_method("_removed_from_graph", &AnimationNodeBlendSpace2DEditor::_removed_from_graph);
  692. ClassDB::bind_method("_auto_triangles_toggled", &AnimationNodeBlendSpace2DEditor::_auto_triangles_toggled);
  693. ClassDB::bind_method("_blend_space_changed", &AnimationNodeBlendSpace2DEditor::_blend_space_changed);
  694. ClassDB::bind_method("_file_opened", &AnimationNodeBlendSpace2DEditor::_file_opened);
  695. }
  696. AnimationNodeBlendSpace2DEditor *AnimationNodeBlendSpace2DEditor::singleton = NULL;
  697. AnimationNodeBlendSpace2DEditor::AnimationNodeBlendSpace2DEditor() {
  698. singleton = this;
  699. updating = false;
  700. HBoxContainer *top_hb = memnew(HBoxContainer);
  701. add_child(top_hb);
  702. Ref<ButtonGroup> bg;
  703. bg.instance();
  704. tool_blend = memnew(ToolButton);
  705. tool_blend->set_toggle_mode(true);
  706. tool_blend->set_button_group(bg);
  707. top_hb->add_child(tool_blend);
  708. tool_blend->set_pressed(true);
  709. tool_blend->set_tooltip(TTR("Set the blending position within the space"));
  710. tool_blend->connect("pressed", this, "_tool_switch", varray(3));
  711. tool_select = memnew(ToolButton);
  712. tool_select->set_toggle_mode(true);
  713. tool_select->set_button_group(bg);
  714. top_hb->add_child(tool_select);
  715. tool_select->set_tooltip(TTR("Select and move points, create points with RMB."));
  716. tool_select->connect("pressed", this, "_tool_switch", varray(0));
  717. tool_create = memnew(ToolButton);
  718. tool_create->set_toggle_mode(true);
  719. tool_create->set_button_group(bg);
  720. top_hb->add_child(tool_create);
  721. tool_create->set_tooltip(TTR("Create points."));
  722. tool_create->connect("pressed", this, "_tool_switch", varray(1));
  723. tool_triangle = memnew(ToolButton);
  724. tool_triangle->set_toggle_mode(true);
  725. tool_triangle->set_button_group(bg);
  726. top_hb->add_child(tool_triangle);
  727. tool_triangle->set_tooltip(TTR("Create triangles by connecting points."));
  728. tool_triangle->connect("pressed", this, "_tool_switch", varray(2));
  729. tool_erase_sep = memnew(VSeparator);
  730. top_hb->add_child(tool_erase_sep);
  731. tool_erase = memnew(ToolButton);
  732. top_hb->add_child(tool_erase);
  733. tool_erase->set_tooltip(TTR("Erase points and triangles."));
  734. tool_erase->connect("pressed", this, "_erase_selected");
  735. tool_erase->set_disabled(true);
  736. top_hb->add_child(memnew(VSeparator));
  737. auto_triangles = memnew(ToolButton);
  738. top_hb->add_child(auto_triangles);
  739. auto_triangles->connect("pressed", this, "_auto_triangles_toggled");
  740. auto_triangles->set_toggle_mode(true);
  741. auto_triangles->set_tooltip(TTR("Generate blend triangles automatically (instead of manually)"));
  742. top_hb->add_child(memnew(VSeparator));
  743. snap = memnew(ToolButton);
  744. snap->set_toggle_mode(true);
  745. top_hb->add_child(snap);
  746. snap->set_pressed(true);
  747. snap->set_tooltip(TTR("Enable snap and show grid."));
  748. snap->connect("pressed", this, "_snap_toggled");
  749. snap_x = memnew(SpinBox);
  750. top_hb->add_child(snap_x);
  751. snap_x->set_prefix("x:");
  752. snap_x->set_min(0.01);
  753. snap_x->set_step(0.01);
  754. snap_x->set_max(1000);
  755. snap_y = memnew(SpinBox);
  756. top_hb->add_child(snap_y);
  757. snap_y->set_prefix("y:");
  758. snap_y->set_min(0.01);
  759. snap_y->set_step(0.01);
  760. snap_y->set_max(1000);
  761. top_hb->add_child(memnew(VSeparator));
  762. top_hb->add_child(memnew(Label(TTR("Blend:"))));
  763. interpolation = memnew(OptionButton);
  764. top_hb->add_child(interpolation);
  765. interpolation->connect("item_selected", this, "_config_changed");
  766. edit_hb = memnew(HBoxContainer);
  767. top_hb->add_child(edit_hb);
  768. edit_hb->add_child(memnew(VSeparator));
  769. edit_hb->add_child(memnew(Label(TTR("Point"))));
  770. edit_x = memnew(SpinBox);
  771. edit_hb->add_child(edit_x);
  772. edit_x->set_min(-1000);
  773. edit_x->set_step(0.01);
  774. edit_x->set_max(1000);
  775. edit_x->connect("value_changed", this, "_edit_point_pos");
  776. edit_y = memnew(SpinBox);
  777. edit_hb->add_child(edit_y);
  778. edit_y->set_min(-1000);
  779. edit_y->set_step(0.01);
  780. edit_y->set_max(1000);
  781. edit_y->connect("value_changed", this, "_edit_point_pos");
  782. open_editor = memnew(Button);
  783. edit_hb->add_child(open_editor);
  784. open_editor->set_text(TTR("Open Editor"));
  785. open_editor->connect("pressed", this, "_open_editor", varray(), CONNECT_DEFERRED);
  786. edit_hb->hide();
  787. open_editor->hide();
  788. HBoxContainer *main_hb = memnew(HBoxContainer);
  789. add_child(main_hb);
  790. main_hb->set_v_size_flags(SIZE_EXPAND_FILL);
  791. GridContainer *main_grid = memnew(GridContainer);
  792. main_grid->set_columns(2);
  793. main_hb->add_child(main_grid);
  794. main_grid->set_h_size_flags(SIZE_EXPAND_FILL);
  795. {
  796. VBoxContainer *left_vbox = memnew(VBoxContainer);
  797. main_grid->add_child(left_vbox);
  798. left_vbox->set_v_size_flags(SIZE_EXPAND_FILL);
  799. max_y_value = memnew(SpinBox);
  800. left_vbox->add_child(max_y_value);
  801. left_vbox->add_spacer();
  802. label_y = memnew(LineEdit);
  803. left_vbox->add_child(label_y);
  804. label_y->set_expand_to_text_length(true);
  805. left_vbox->add_spacer();
  806. min_y_value = memnew(SpinBox);
  807. left_vbox->add_child(min_y_value);
  808. max_y_value->set_max(10000);
  809. max_y_value->set_min(0.01);
  810. max_y_value->set_step(0.01);
  811. min_y_value->set_min(-10000);
  812. min_y_value->set_max(0);
  813. min_y_value->set_step(0.01);
  814. }
  815. panel = memnew(PanelContainer);
  816. panel->set_clip_contents(true);
  817. main_grid->add_child(panel);
  818. panel->set_h_size_flags(SIZE_EXPAND_FILL);
  819. blend_space_draw = memnew(Control);
  820. blend_space_draw->connect("gui_input", this, "_blend_space_gui_input");
  821. blend_space_draw->connect("draw", this, "_blend_space_draw");
  822. blend_space_draw->set_focus_mode(FOCUS_ALL);
  823. panel->add_child(blend_space_draw);
  824. main_grid->add_child(memnew(Control)); //empty bottom left
  825. {
  826. HBoxContainer *bottom_vbox = memnew(HBoxContainer);
  827. main_grid->add_child(bottom_vbox);
  828. bottom_vbox->set_h_size_flags(SIZE_EXPAND_FILL);
  829. min_x_value = memnew(SpinBox);
  830. bottom_vbox->add_child(min_x_value);
  831. bottom_vbox->add_spacer();
  832. label_x = memnew(LineEdit);
  833. bottom_vbox->add_child(label_x);
  834. label_x->set_expand_to_text_length(true);
  835. bottom_vbox->add_spacer();
  836. max_x_value = memnew(SpinBox);
  837. bottom_vbox->add_child(max_x_value);
  838. max_x_value->set_max(10000);
  839. max_x_value->set_min(0.01);
  840. max_x_value->set_step(0.01);
  841. min_x_value->set_min(-10000);
  842. min_x_value->set_max(0);
  843. min_x_value->set_step(0.01);
  844. }
  845. snap_x->connect("value_changed", this, "_config_changed");
  846. snap_y->connect("value_changed", this, "_config_changed");
  847. max_x_value->connect("value_changed", this, "_config_changed");
  848. min_x_value->connect("value_changed", this, "_config_changed");
  849. max_y_value->connect("value_changed", this, "_config_changed");
  850. min_y_value->connect("value_changed", this, "_config_changed");
  851. label_x->connect("text_changed", this, "_labels_changed");
  852. label_y->connect("text_changed", this, "_labels_changed");
  853. error_panel = memnew(PanelContainer);
  854. add_child(error_panel);
  855. error_label = memnew(Label);
  856. error_panel->add_child(error_label);
  857. error_label->set_text("eh");
  858. undo_redo = EditorNode::get_undo_redo();
  859. set_custom_minimum_size(Size2(0, 300 * EDSCALE));
  860. menu = memnew(PopupMenu);
  861. add_child(menu);
  862. menu->connect("id_pressed", this, "_add_menu_type");
  863. animations_menu = memnew(PopupMenu);
  864. menu->add_child(animations_menu);
  865. animations_menu->set_name("animations");
  866. animations_menu->connect("index_pressed", this, "_add_animation_type");
  867. open_file = memnew(EditorFileDialog);
  868. add_child(open_file);
  869. open_file->set_title(TTR("Open Animation Node"));
  870. open_file->set_mode(EditorFileDialog::MODE_OPEN_FILE);
  871. open_file->connect("file_selected", this, "_file_opened");
  872. undo_redo = EditorNode::get_undo_redo();
  873. selected_point = -1;
  874. selected_triangle = -1;
  875. dragging_selected = false;
  876. dragging_selected_attempt = false;
  877. }