animation_blend_space_2d_editor.cpp 38 KB

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