animation_state_machine_editor.cpp 74 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029
  1. /**************************************************************************/
  2. /* animation_state_machine_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_state_machine_editor.h"
  31. #include "core/io/resource_loader.h"
  32. #include "core/math/geometry_2d.h"
  33. #include "core/os/keyboard.h"
  34. #include "editor/editor_node.h"
  35. #include "editor/editor_settings.h"
  36. #include "editor/editor_undo_redo_manager.h"
  37. #include "editor/gui/editor_file_dialog.h"
  38. #include "editor/themes/editor_scale.h"
  39. #include "scene/animation/animation_blend_tree.h"
  40. #include "scene/gui/option_button.h"
  41. #include "scene/gui/panel_container.h"
  42. #include "scene/gui/separator.h"
  43. #include "scene/gui/tree.h"
  44. #include "scene/main/viewport.h"
  45. #include "scene/main/window.h"
  46. #include "scene/resources/style_box_flat.h"
  47. #include "scene/theme/theme_db.h"
  48. bool AnimationNodeStateMachineEditor::can_edit(const Ref<AnimationNode> &p_node) {
  49. Ref<AnimationNodeStateMachine> ansm = p_node;
  50. return ansm.is_valid();
  51. }
  52. void AnimationNodeStateMachineEditor::edit(const Ref<AnimationNode> &p_node) {
  53. state_machine = p_node;
  54. read_only = false;
  55. if (state_machine.is_valid()) {
  56. read_only = EditorNode::get_singleton()->is_resource_read_only(state_machine);
  57. selected_transition_from = StringName();
  58. selected_transition_to = StringName();
  59. selected_transition_index = -1;
  60. selected_node = StringName();
  61. selected_nodes.clear();
  62. connected_nodes.clear();
  63. _update_mode();
  64. _update_graph();
  65. }
  66. if (read_only) {
  67. tool_create->set_pressed(false);
  68. tool_connect->set_pressed(false);
  69. }
  70. tool_create->set_disabled(read_only);
  71. tool_connect->set_disabled(read_only);
  72. }
  73. String AnimationNodeStateMachineEditor::_get_root_playback_path(String &r_node_directory) {
  74. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  75. Vector<String> edited_path = AnimationTreeEditor::get_singleton()->get_edited_path();
  76. String base_path;
  77. Vector<String> node_directory_path;
  78. bool is_playable_anodesm_found = false;
  79. if (edited_path.size()) {
  80. while (!is_playable_anodesm_found) {
  81. base_path = String("/").join(edited_path);
  82. Ref<AnimationNodeStateMachine> anodesm = !edited_path.size() ? Ref<AnimationNode>(tree->get_root_animation_node().ptr()) : tree->get_root_animation_node()->find_node_by_path(base_path);
  83. if (anodesm.is_null()) {
  84. break;
  85. } else {
  86. if (anodesm->get_state_machine_type() != AnimationNodeStateMachine::STATE_MACHINE_TYPE_GROUPED) {
  87. is_playable_anodesm_found = true;
  88. } else {
  89. int idx = edited_path.size() - 1;
  90. node_directory_path.push_back(edited_path[idx]);
  91. edited_path.remove_at(idx);
  92. }
  93. }
  94. }
  95. }
  96. if (is_playable_anodesm_found) {
  97. // Return Root/Nested state machine playback.
  98. node_directory_path.reverse();
  99. r_node_directory = String("/").join(node_directory_path);
  100. if (node_directory_path.size()) {
  101. r_node_directory += "/";
  102. }
  103. base_path = !edited_path.size() ? Animation::PARAMETERS_BASE_PATH + "playback" : Animation::PARAMETERS_BASE_PATH + base_path + "/playback";
  104. } else {
  105. // Hmmm, we have to return Grouped state machine playback...
  106. // It will give the user the error that Root/Nested state machine should be retrieved, that would be kind :-)
  107. r_node_directory = String();
  108. base_path = AnimationTreeEditor::get_singleton()->get_base_path() + "playback";
  109. }
  110. return base_path;
  111. }
  112. void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Ref<InputEvent> &p_event) {
  113. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  114. if (!tree) {
  115. return;
  116. }
  117. String node_directory;
  118. Ref<AnimationNodeStateMachinePlayback> playback = tree->get(_get_root_playback_path(node_directory));
  119. if (playback.is_null()) {
  120. return;
  121. }
  122. Ref<InputEventKey> k = p_event;
  123. if (tool_select->is_pressed() && k.is_valid() && k->is_pressed() && k->get_keycode() == Key::KEY_DELETE && !k->is_echo()) {
  124. if (selected_node != StringName() || !selected_nodes.is_empty() || selected_transition_to != StringName() || selected_transition_from != StringName()) {
  125. if (!read_only) {
  126. _erase_selected();
  127. }
  128. accept_event();
  129. }
  130. }
  131. Ref<InputEventMouseButton> mb = p_event;
  132. // Add new node
  133. if (!read_only) {
  134. if (mb.is_valid() && mb->is_pressed() && !box_selecting && !connecting && ((tool_select->is_pressed() && mb->get_button_index() == MouseButton::RIGHT) || (tool_create->is_pressed() && mb->get_button_index() == MouseButton::LEFT))) {
  135. connecting_from = StringName();
  136. _open_menu(mb->get_position());
  137. }
  138. }
  139. // Select node or push a field inside
  140. if (mb.is_valid() && !mb->is_shift_pressed() && !mb->is_command_or_control_pressed() && mb->is_pressed() && tool_select->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
  141. selected_transition_from = StringName();
  142. selected_transition_to = StringName();
  143. selected_transition_index = -1;
  144. selected_node = StringName();
  145. for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order
  146. if (node_rects[i].play.has_point(mb->get_position())) { //edit name
  147. if (play_mode->get_selected() == 1 || !playback->is_playing()) {
  148. // Start
  149. playback->start(node_directory + String(node_rects[i].node_name));
  150. } else {
  151. // Travel
  152. playback->travel(node_directory + String(node_rects[i].node_name));
  153. }
  154. state_machine_draw->queue_redraw();
  155. return;
  156. }
  157. if (!read_only) {
  158. if (node_rects[i].name.has_point(mb->get_position()) && state_machine->can_edit_node(node_rects[i].node_name)) { // edit name
  159. // TODO: Avoid using strings, expose a method on LineEdit.
  160. Ref<StyleBox> line_sb = name_edit->get_theme_stylebox(CoreStringName(normal));
  161. Rect2 edit_rect = node_rects[i].name;
  162. edit_rect.position -= line_sb->get_offset();
  163. edit_rect.size += line_sb->get_minimum_size();
  164. name_edit_popup->set_position(state_machine_draw->get_screen_position() + edit_rect.position);
  165. name_edit_popup->set_size(edit_rect.size);
  166. name_edit->set_text(node_rects[i].node_name);
  167. name_edit_popup->popup();
  168. name_edit->grab_focus();
  169. name_edit->select_all();
  170. prev_name = node_rects[i].node_name;
  171. return;
  172. }
  173. }
  174. if (node_rects[i].edit.has_point(mb->get_position())) { //edit name
  175. callable_mp(this, &AnimationNodeStateMachineEditor::_open_editor).call_deferred(node_rects[i].node_name);
  176. return;
  177. }
  178. if (node_rects[i].node.has_point(mb->get_position())) { //select node since nothing else was selected
  179. selected_node = node_rects[i].node_name;
  180. if (!selected_nodes.has(selected_node)) {
  181. selected_nodes.clear();
  182. }
  183. selected_nodes.insert(selected_node);
  184. _update_connected_nodes(selected_node);
  185. Ref<AnimationNode> anode = state_machine->get_node(selected_node);
  186. EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
  187. state_machine_draw->queue_redraw();
  188. dragging_selected_attempt = true;
  189. dragging_selected = false;
  190. drag_from = mb->get_position();
  191. snap_x = StringName();
  192. snap_y = StringName();
  193. _update_mode();
  194. return;
  195. }
  196. }
  197. // Test the transition lines.
  198. int closest = -1;
  199. float closest_d = 1e20;
  200. Vector<int> close_candidates;
  201. // First find closest lines using point-to-segment distance.
  202. for (int i = 0; i < transition_lines.size(); i++) {
  203. Vector2 cpoint = Geometry2D::get_closest_point_to_segment(mb->get_position(), transition_lines[i].from, transition_lines[i].to);
  204. float d = cpoint.distance_to(mb->get_position());
  205. if (d > transition_lines[i].width) {
  206. continue;
  207. }
  208. // If this is very close to our current closest distance, add it to candidates.
  209. if (Math::abs(d - closest_d) < 2.0) { // Within 2 pixels.
  210. close_candidates.push_back(i);
  211. } else if (d < closest_d) {
  212. closest_d = d;
  213. closest = i;
  214. close_candidates.clear();
  215. close_candidates.push_back(i);
  216. }
  217. }
  218. // Use midpoint distance as bias.
  219. if (close_candidates.size() > 1) {
  220. float best_midpoint_dist = 1e20;
  221. for (int idx : close_candidates) {
  222. Vector2 midpoint = (transition_lines[idx].from + transition_lines[idx].to) / 2.0;
  223. float midpoint_dist = midpoint.distance_to(mb->get_position());
  224. if (midpoint_dist < best_midpoint_dist) {
  225. best_midpoint_dist = midpoint_dist;
  226. closest = idx;
  227. }
  228. }
  229. }
  230. if (closest >= 0) {
  231. selected_transition_from = transition_lines[closest].from_node;
  232. selected_transition_to = transition_lines[closest].to_node;
  233. selected_transition_index = closest;
  234. // Update connected_nodes for the selected transition.
  235. connected_nodes.clear();
  236. connected_nodes.insert(selected_transition_from);
  237. connected_nodes.insert(selected_transition_to);
  238. Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(closest);
  239. if (!state_machine->is_transition_across_group(closest)) {
  240. EditorNode::get_singleton()->push_item(tr.ptr(), "", true);
  241. } else {
  242. EditorNode::get_singleton()->push_item(tr.ptr(), "", true);
  243. EditorNode::get_singleton()->push_item(nullptr, "", true);
  244. }
  245. }
  246. state_machine_draw->queue_redraw();
  247. _update_mode();
  248. }
  249. // End moving node
  250. if (mb.is_valid() && dragging_selected_attempt && mb->get_button_index() == MouseButton::LEFT && !mb->is_pressed()) {
  251. if (dragging_selected) {
  252. Ref<AnimationNode> an = state_machine->get_node(selected_node);
  253. updating = true;
  254. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  255. undo_redo->create_action(TTR("Move Node"));
  256. for (int i = 0; i < node_rects.size(); i++) {
  257. if (!selected_nodes.has(node_rects[i].node_name)) {
  258. continue;
  259. }
  260. undo_redo->add_do_method(state_machine.ptr(), "set_node_position", node_rects[i].node_name, state_machine->get_node_position(node_rects[i].node_name) + drag_ofs / EDSCALE);
  261. undo_redo->add_undo_method(state_machine.ptr(), "set_node_position", node_rects[i].node_name, state_machine->get_node_position(node_rects[i].node_name));
  262. }
  263. undo_redo->add_do_method(this, "_update_graph");
  264. undo_redo->add_undo_method(this, "_update_graph");
  265. undo_redo->commit_action();
  266. updating = false;
  267. }
  268. snap_x = StringName();
  269. snap_y = StringName();
  270. dragging_selected_attempt = false;
  271. dragging_selected = false;
  272. state_machine_draw->queue_redraw();
  273. }
  274. // Connect nodes
  275. if (mb.is_valid() && ((tool_select->is_pressed() && mb->is_shift_pressed()) || tool_connect->is_pressed()) && mb->get_button_index() == MouseButton::LEFT && mb->is_pressed()) {
  276. for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order
  277. if (node_rects[i].node.has_point(mb->get_position())) { //select node since nothing else was selected
  278. connecting = true;
  279. connection_follows_cursor = true;
  280. connecting_from = node_rects[i].node_name;
  281. connecting_to = mb->get_position();
  282. connecting_to_node = StringName();
  283. return;
  284. }
  285. }
  286. }
  287. // End connecting nodes
  288. if (mb.is_valid() && connecting && mb->get_button_index() == MouseButton::LEFT && !mb->is_pressed()) {
  289. if (connecting_to_node != StringName()) {
  290. Ref<AnimationNode> node = state_machine->get_node(connecting_to_node);
  291. Ref<AnimationNodeStateMachine> anodesm = node;
  292. Ref<AnimationNodeEndState> end_node = node;
  293. if (state_machine->has_transition(connecting_from, connecting_to_node) && state_machine->can_edit_node(connecting_to_node) && anodesm.is_null()) {
  294. EditorNode::get_singleton()->show_warning(TTR("Transition exists!"));
  295. connecting = false;
  296. } else {
  297. _add_transition();
  298. }
  299. } else {
  300. _open_menu(mb->get_position());
  301. }
  302. connecting_to_node = StringName();
  303. connection_follows_cursor = false;
  304. state_machine_draw->queue_redraw();
  305. }
  306. // Start box selecting
  307. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && tool_select->is_pressed()) {
  308. box_selecting = true;
  309. box_selecting_from = box_selecting_to = state_machine_draw->get_local_mouse_position();
  310. box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs());
  311. if (mb->is_command_or_control_pressed() || mb->is_shift_pressed()) {
  312. previous_selected = selected_nodes;
  313. } else {
  314. selected_nodes.clear();
  315. previous_selected.clear();
  316. }
  317. }
  318. // End box selecting
  319. if (mb.is_valid() && mb->get_button_index() == MouseButton::LEFT && !mb->is_pressed() && box_selecting) {
  320. box_selecting = false;
  321. state_machine_draw->queue_redraw();
  322. _update_mode();
  323. }
  324. if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) {
  325. StringName clicked_node;
  326. for (int i = node_rects.size() - 1; i >= 0; i--) {
  327. if (node_rects[i].node.has_point(mb->get_position())) {
  328. clicked_node = node_rects[i].node_name;
  329. break;
  330. }
  331. }
  332. if (clicked_node != StringName()) {
  333. if (selected_nodes.has(clicked_node) && mb->is_shift_pressed()) {
  334. selected_nodes.erase(clicked_node);
  335. } else {
  336. if (!mb->is_shift_pressed()) {
  337. selected_nodes.clear();
  338. }
  339. selected_nodes.insert(clicked_node);
  340. }
  341. selected_node = clicked_node;
  342. } else {
  343. // Clicked on empty space.
  344. selected_nodes.clear();
  345. selected_node = StringName();
  346. }
  347. _update_connected_nodes(selected_node);
  348. state_machine_draw->queue_redraw();
  349. _update_mode();
  350. if (clicked_node != StringName()) {
  351. Ref<AnimationNode> anode = state_machine->get_node(clicked_node);
  352. EditorNode::get_singleton()->push_item(anode.ptr(), "", true);
  353. dragging_selected_attempt = true;
  354. dragging_selected = false;
  355. drag_from = mb->get_position();
  356. snap_x = StringName();
  357. snap_y = StringName();
  358. }
  359. return;
  360. }
  361. Ref<InputEventMouseMotion> mm = p_event;
  362. // Pan window
  363. if (mm.is_valid() && mm->get_button_mask().has_flag(MouseButtonMask::MIDDLE)) {
  364. h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x);
  365. v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y);
  366. }
  367. // Move mouse while connecting
  368. if (mm.is_valid() && connecting && connection_follows_cursor && !read_only) {
  369. connecting_to = mm->get_position();
  370. connecting_to_node = StringName();
  371. state_machine_draw->queue_redraw();
  372. for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order
  373. if (node_rects[i].node_name != connecting_from && node_rects[i].node.has_point(connecting_to)) { //select node since nothing else was selected
  374. connecting_to_node = node_rects[i].node_name;
  375. return;
  376. }
  377. }
  378. }
  379. // Move mouse while moving a node
  380. if (mm.is_valid() && dragging_selected_attempt && !read_only) {
  381. dragging_selected = true;
  382. drag_ofs = mm->get_position() - drag_from;
  383. snap_x = StringName();
  384. snap_y = StringName();
  385. {
  386. //snap
  387. Vector2 cpos = state_machine->get_node_position(selected_node) + drag_ofs / EDSCALE;
  388. List<StringName> nodes;
  389. state_machine->get_node_list(&nodes);
  390. float best_d_x = 1e20;
  391. float best_d_y = 1e20;
  392. for (const StringName &E : nodes) {
  393. if (E == selected_node) {
  394. continue;
  395. }
  396. Vector2 npos = state_machine->get_node_position(E);
  397. float d_x = Math::abs(npos.x - cpos.x);
  398. if (d_x < MIN(5, best_d_x)) {
  399. drag_ofs.x -= cpos.x - npos.x;
  400. best_d_x = d_x;
  401. snap_x = E;
  402. }
  403. float d_y = Math::abs(npos.y - cpos.y);
  404. if (d_y < MIN(5, best_d_y)) {
  405. drag_ofs.y -= cpos.y - npos.y;
  406. best_d_y = d_y;
  407. snap_y = E;
  408. }
  409. }
  410. }
  411. state_machine_draw->queue_redraw();
  412. }
  413. // Move mouse while moving box select
  414. if (mm.is_valid() && box_selecting) {
  415. box_selecting_to = state_machine_draw->get_local_mouse_position();
  416. box_selecting_rect = Rect2(box_selecting_from.min(box_selecting_to), (box_selecting_from - box_selecting_to).abs());
  417. for (int i = 0; i < node_rects.size(); i++) {
  418. bool in_box = node_rects[i].node.intersects(box_selecting_rect);
  419. if (in_box) {
  420. if (previous_selected.has(node_rects[i].node_name)) {
  421. selected_nodes.erase(node_rects[i].node_name);
  422. } else {
  423. selected_nodes.insert(node_rects[i].node_name);
  424. }
  425. } else {
  426. if (previous_selected.has(node_rects[i].node_name)) {
  427. selected_nodes.insert(node_rects[i].node_name);
  428. } else {
  429. selected_nodes.erase(node_rects[i].node_name);
  430. }
  431. }
  432. }
  433. state_machine_draw->queue_redraw();
  434. }
  435. if (mm.is_valid()) {
  436. state_machine_draw->grab_focus();
  437. String new_hovered_node_name;
  438. HoveredNodeArea new_hovered_node_area = HOVER_NODE_NONE;
  439. if (tool_select->is_pressed()) {
  440. for (int i = node_rects.size() - 1; i >= 0; i--) { // Inverse to draw order.
  441. if (!state_machine->can_edit_node(node_rects[i].node_name)) {
  442. continue; // start/end node can't be edited
  443. }
  444. if (node_rects[i].node.has_point(mm->get_position())) {
  445. new_hovered_node_name = node_rects[i].node_name;
  446. if (node_rects[i].play.has_point(mm->get_position())) {
  447. new_hovered_node_area = HOVER_NODE_PLAY;
  448. } else if (node_rects[i].edit.has_point(mm->get_position())) {
  449. new_hovered_node_area = HOVER_NODE_EDIT;
  450. }
  451. break;
  452. }
  453. }
  454. }
  455. if (new_hovered_node_name != hovered_node_name || new_hovered_node_area != hovered_node_area) {
  456. hovered_node_name = new_hovered_node_name;
  457. hovered_node_area = new_hovered_node_area;
  458. state_machine_draw->queue_redraw();
  459. }
  460. // set tooltip for transition
  461. if (tool_select->is_pressed()) {
  462. int closest = -1;
  463. float closest_d = 1e20;
  464. for (int i = 0; i < transition_lines.size(); i++) {
  465. Vector2 cpoint = Geometry2D::get_closest_point_to_segment(mm->get_position(), transition_lines[i].from, transition_lines[i].to);
  466. float d = cpoint.distance_to(mm->get_position());
  467. if (d > transition_lines[i].width) {
  468. continue;
  469. }
  470. if (d < closest_d) {
  471. closest = i;
  472. closest_d = d;
  473. }
  474. }
  475. if (closest >= 0) {
  476. String from = String(transition_lines[closest].from_node);
  477. String to = String(transition_lines[closest].to_node);
  478. String tooltip = from + " -> " + to;
  479. state_machine_draw->set_tooltip_text(tooltip);
  480. } else {
  481. state_machine_draw->set_tooltip_text("");
  482. }
  483. }
  484. }
  485. Ref<InputEventPanGesture> pan_gesture = p_event;
  486. if (pan_gesture.is_valid()) {
  487. h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * pan_gesture->get_delta().x / 8);
  488. v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * pan_gesture->get_delta().y / 8);
  489. }
  490. }
  491. Control::CursorShape AnimationNodeStateMachineEditor::get_cursor_shape(const Point2 &p_pos) const {
  492. Control::CursorShape cursor_shape = get_default_cursor_shape();
  493. if (!read_only) {
  494. // Put ibeam (text cursor) over names to make it clearer that they are editable.
  495. Transform2D xform = panel->get_transform() * state_machine_draw->get_transform();
  496. Point2 pos = xform.xform_inv(p_pos);
  497. for (int i = node_rects.size() - 1; i >= 0; i--) { // Inverse to draw order.
  498. if (node_rects[i].node.has_point(pos)) {
  499. if (node_rects[i].name.has_point(pos)) {
  500. if (state_machine->can_edit_node(node_rects[i].node_name)) {
  501. cursor_shape = Control::CURSOR_IBEAM;
  502. }
  503. }
  504. break;
  505. }
  506. }
  507. }
  508. return cursor_shape;
  509. }
  510. String AnimationNodeStateMachineEditor::get_tooltip(const Point2 &p_pos) const {
  511. if (hovered_node_name == StringName()) {
  512. return AnimationTreeNodeEditorPlugin::get_tooltip(p_pos);
  513. }
  514. String tooltip_text;
  515. if (hovered_node_area == HOVER_NODE_PLAY) {
  516. tooltip_text = vformat(TTR("Play/Travel to %s"), hovered_node_name);
  517. } else if (hovered_node_area == HOVER_NODE_EDIT) {
  518. tooltip_text = vformat(TTR("Edit %s"), hovered_node_name);
  519. } else {
  520. tooltip_text = hovered_node_name;
  521. }
  522. return tooltip_text;
  523. }
  524. void AnimationNodeStateMachineEditor::_open_menu(const Vector2 &p_position) {
  525. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  526. if (!tree) {
  527. return;
  528. }
  529. menu->clear(false);
  530. animations_menu->clear();
  531. animations_to_add.clear();
  532. List<StringName> animation_names;
  533. tree->get_animation_list(&animation_names);
  534. menu->add_submenu_node_item(TTR("Add Animation"), animations_menu);
  535. if (animation_names.is_empty()) {
  536. menu->set_item_disabled(menu->get_item_idx_from_text(TTR("Add Animation")), true);
  537. } else {
  538. for (const StringName &name : animation_names) {
  539. animations_menu->add_icon_item(theme_cache.animation_icon, name);
  540. animations_to_add.push_back(name);
  541. }
  542. }
  543. LocalVector<StringName> classes;
  544. ClassDB::get_inheriters_from_class("AnimationRootNode", classes);
  545. classes.sort_custom<StringName::AlphCompare>();
  546. for (const StringName &class_name : classes) {
  547. String name = String(class_name).replace_first("AnimationNode", "");
  548. if (name == "Animation" || name == "StartState" || name == "EndState") {
  549. continue; // nope
  550. }
  551. int idx = menu->get_item_count();
  552. menu->add_item(vformat(TTR("Add %s"), name), idx);
  553. menu->set_item_metadata(idx, class_name);
  554. }
  555. Ref<AnimationNode> clipb = EditorSettings::get_singleton()->get_resource_clipboard();
  556. if (clipb.is_valid()) {
  557. menu->add_separator();
  558. menu->add_item(TTR("Paste"), MENU_PASTE);
  559. }
  560. menu->add_separator();
  561. menu->add_item(TTR("Load..."), MENU_LOAD_FILE);
  562. menu->set_position(state_machine_draw->get_screen_transform().xform(p_position));
  563. menu->popup();
  564. add_node_pos = p_position / EDSCALE + state_machine->get_graph_offset();
  565. }
  566. bool AnimationNodeStateMachineEditor::_create_submenu(PopupMenu *p_menu, Ref<AnimationNodeStateMachine> p_nodesm, const StringName &p_name, const StringName &p_path) {
  567. String prev_path;
  568. List<StringName> nodes;
  569. p_nodesm->get_node_list(&nodes);
  570. PopupMenu *nodes_menu = memnew(PopupMenu);
  571. nodes_menu->set_name(p_name);
  572. nodes_menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_connect_to));
  573. p_menu->add_child(nodes_menu);
  574. bool node_added = false;
  575. for (const StringName &E : nodes) {
  576. if (p_nodesm->can_edit_node(E)) {
  577. Ref<AnimationNodeStateMachine> ansm = p_nodesm->get_node(E);
  578. String path = String(p_path) + "/" + E;
  579. if (ansm == state_machine) {
  580. end_menu->add_item(E, nodes_to_connect.size());
  581. nodes_to_connect.push_back(SceneStringName(End));
  582. continue;
  583. }
  584. if (ansm.is_valid()) {
  585. state_machine_menu->add_item(E, nodes_to_connect.size());
  586. nodes_to_connect.push_back(path);
  587. if (_create_submenu(nodes_menu, ansm, E, path)) {
  588. nodes_menu->add_submenu_item(E, E);
  589. node_added = true;
  590. }
  591. } else {
  592. nodes_menu->add_item(E, nodes_to_connect.size());
  593. nodes_to_connect.push_back(path);
  594. node_added = true;
  595. }
  596. }
  597. }
  598. return node_added;
  599. }
  600. void AnimationNodeStateMachineEditor::_stop_connecting() {
  601. connecting = false;
  602. state_machine_draw->queue_redraw();
  603. }
  604. void AnimationNodeStateMachineEditor::_delete_selected() {
  605. TreeItem *item = delete_tree->get_next_selected(nullptr);
  606. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  607. while (item) {
  608. if (!updating) {
  609. updating = true;
  610. undo_redo->create_action("Transition(s) Removed");
  611. }
  612. Vector<String> path = item->get_text(0).split(" -> ");
  613. selected_transition_from = path[0];
  614. selected_transition_to = path[1];
  615. _erase_selected(true);
  616. item = delete_tree->get_next_selected(item);
  617. }
  618. if (updating) {
  619. undo_redo->commit_action();
  620. updating = false;
  621. }
  622. }
  623. void AnimationNodeStateMachineEditor::_delete_all() {
  624. updating = true;
  625. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  626. undo_redo->create_action("Transition(s) Removed");
  627. _erase_selected(true);
  628. undo_redo->commit_action();
  629. updating = false;
  630. delete_window->hide();
  631. }
  632. void AnimationNodeStateMachineEditor::_delete_tree_draw() {
  633. TreeItem *item = delete_tree->get_next_selected(nullptr);
  634. while (item) {
  635. delete_window->get_cancel_button()->set_disabled(false);
  636. return;
  637. }
  638. delete_window->get_cancel_button()->set_disabled(true);
  639. }
  640. void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) {
  641. file_loaded = ResourceLoader::load(p_file);
  642. if (file_loaded.is_valid()) {
  643. _add_menu_type(MENU_LOAD_FILE_CONFIRM);
  644. } else {
  645. EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only animation nodes are allowed."));
  646. }
  647. }
  648. void AnimationNodeStateMachineEditor::_add_menu_type(int p_index) {
  649. String base_name;
  650. Ref<AnimationRootNode> node;
  651. if (p_index == MENU_LOAD_FILE) {
  652. open_file->clear_filters();
  653. List<String> filters;
  654. ResourceLoader::get_recognized_extensions_for_type("AnimationRootNode", &filters);
  655. for (const String &E : filters) {
  656. open_file->add_filter("*." + E);
  657. }
  658. open_file->popup_file_dialog();
  659. return;
  660. } else if (p_index == MENU_LOAD_FILE_CONFIRM) {
  661. node = file_loaded;
  662. file_loaded.unref();
  663. } else if (p_index == MENU_PASTE) {
  664. node = EditorSettings::get_singleton()->get_resource_clipboard();
  665. } else {
  666. String type = menu->get_item_metadata(p_index);
  667. Object *obj = ClassDB::instantiate(type);
  668. ERR_FAIL_NULL(obj);
  669. AnimationNode *an = Object::cast_to<AnimationNode>(obj);
  670. ERR_FAIL_NULL(an);
  671. node = Ref<AnimationNode>(an);
  672. base_name = type.replace_first("AnimationNode", "");
  673. }
  674. if (node.is_null()) {
  675. EditorNode::get_singleton()->show_warning(TTR("This type of node can't be used. Only root nodes are allowed."));
  676. return;
  677. }
  678. if (base_name.is_empty()) {
  679. base_name = node->get_class().replace_first("AnimationNode", "");
  680. }
  681. int base = 1;
  682. String name = base_name;
  683. while (state_machine->has_node(name)) {
  684. base++;
  685. name = base_name + " " + itos(base);
  686. }
  687. updating = true;
  688. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  689. undo_redo->create_action(TTR("Add Node and Transition"));
  690. undo_redo->add_do_method(state_machine.ptr(), "add_node", name, node, add_node_pos);
  691. undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name);
  692. connecting_to_node = name;
  693. _add_transition(true);
  694. undo_redo->commit_action();
  695. updating = false;
  696. state_machine_draw->queue_redraw();
  697. }
  698. void AnimationNodeStateMachineEditor::_add_animation_type(int p_index) {
  699. Ref<AnimationNodeAnimation> anim;
  700. anim.instantiate();
  701. anim->set_animation(animations_to_add[p_index]);
  702. String base_name = animations_to_add[p_index].validate_node_name();
  703. int base = 1;
  704. String name = base_name;
  705. while (state_machine->has_node(name)) {
  706. base++;
  707. name = base_name + " " + itos(base);
  708. }
  709. updating = true;
  710. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  711. undo_redo->create_action(TTR("Add Node and Transition"));
  712. undo_redo->add_do_method(state_machine.ptr(), "add_node", name, anim, add_node_pos);
  713. undo_redo->add_undo_method(state_machine.ptr(), "remove_node", name);
  714. connecting_to_node = name;
  715. _add_transition(true);
  716. undo_redo->commit_action();
  717. updating = false;
  718. state_machine_draw->queue_redraw();
  719. }
  720. void AnimationNodeStateMachineEditor::_connect_to(int p_index) {
  721. connecting_to_node = nodes_to_connect[p_index];
  722. _add_transition();
  723. }
  724. void AnimationNodeStateMachineEditor::_add_transition(const bool p_nested_action) {
  725. if (connecting_from != StringName() && connecting_to_node != StringName()) {
  726. if (state_machine->has_transition(connecting_from, connecting_to_node)) {
  727. EditorNode::get_singleton()->show_warning("Transition exists!");
  728. connecting = false;
  729. return;
  730. }
  731. Ref<AnimationNodeStateMachineTransition> tr;
  732. tr.instantiate();
  733. tr->set_advance_mode(auto_advance->is_pressed() ? AnimationNodeStateMachineTransition::AdvanceMode::ADVANCE_MODE_AUTO : AnimationNodeStateMachineTransition::AdvanceMode::ADVANCE_MODE_ENABLED);
  734. tr->set_switch_mode(AnimationNodeStateMachineTransition::SwitchMode(switch_mode->get_selected()));
  735. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  736. if (!p_nested_action) {
  737. updating = true;
  738. undo_redo->create_action(TTR("Add Transition"));
  739. }
  740. undo_redo->add_do_method(state_machine.ptr(), "add_transition", connecting_from, connecting_to_node, tr);
  741. undo_redo->add_undo_method(state_machine.ptr(), "remove_transition", connecting_from, connecting_to_node);
  742. undo_redo->add_do_method(this, "_update_graph");
  743. undo_redo->add_undo_method(this, "_update_graph");
  744. if (!p_nested_action) {
  745. undo_redo->commit_action();
  746. updating = false;
  747. }
  748. selected_transition_from = connecting_from;
  749. selected_transition_to = connecting_to_node;
  750. selected_transition_index = transition_lines.size();
  751. if (!state_machine->is_transition_across_group(selected_transition_index)) {
  752. EditorNode::get_singleton()->push_item(tr.ptr(), "", true);
  753. } else {
  754. EditorNode::get_singleton()->push_item(tr.ptr(), "", true);
  755. EditorNode::get_singleton()->push_item(nullptr, "", true);
  756. }
  757. _update_mode();
  758. }
  759. connecting = false;
  760. }
  761. void AnimationNodeStateMachineEditor::_connection_draw(const Vector2 &p_from, const Vector2 &p_to, AnimationNodeStateMachineTransition::SwitchMode p_mode, bool p_enabled, bool p_selected, bool p_travel, float p_fade_ratio, bool p_auto_advance, bool p_is_across_group, float p_opacity) {
  762. Color line_color = p_enabled ? theme_cache.transition_color : theme_cache.transition_disabled_color;
  763. Color icon_color = p_enabled ? theme_cache.transition_icon_color : theme_cache.transition_icon_disabled_color;
  764. Color highlight_color = p_enabled ? theme_cache.highlight_color : theme_cache.highlight_disabled_color;
  765. line_color.a *= p_opacity;
  766. icon_color.a *= p_opacity;
  767. highlight_color.a *= p_opacity;
  768. if (p_travel) {
  769. line_color = highlight_color;
  770. }
  771. if (p_selected) {
  772. state_machine_draw->draw_line(p_from, p_to, highlight_color, 6, true);
  773. }
  774. state_machine_draw->draw_line(p_from, p_to, line_color, 2, true);
  775. if (p_fade_ratio > 0.0) {
  776. Color fade_line_color = highlight_color;
  777. fade_line_color.set_hsv(1.0, fade_line_color.get_s(), fade_line_color.get_v());
  778. fade_line_color.a *= p_opacity;
  779. state_machine_draw->draw_line(p_from, p_from.lerp(p_to, p_fade_ratio), fade_line_color, 2);
  780. }
  781. const int ICON_COUNT = std::size(theme_cache.transition_icons);
  782. int icon_index = p_mode + (p_auto_advance ? ICON_COUNT / 2 : 0);
  783. ERR_FAIL_COND(icon_index >= ICON_COUNT);
  784. Ref<Texture2D> icon = theme_cache.transition_icons[icon_index];
  785. Transform2D xf;
  786. xf.columns[0] = (p_to - p_from).normalized();
  787. xf.columns[1] = xf.columns[0].orthogonal();
  788. xf.columns[2] = (p_from + p_to) * 0.5 - xf.columns[1] * icon->get_height() * 0.5 - xf.columns[0] * icon->get_height() * 0.5;
  789. state_machine_draw->draw_set_transform_matrix(xf);
  790. if (!p_is_across_group) {
  791. state_machine_draw->draw_texture(icon, Vector2(), icon_color);
  792. }
  793. state_machine_draw->draw_set_transform_matrix(Transform2D());
  794. }
  795. void AnimationNodeStateMachineEditor::_clip_src_line_to_rect(Vector2 &r_from, const Vector2 &p_to, const Rect2 &p_rect) {
  796. if (p_to == r_from) {
  797. return;
  798. }
  799. //this could be optimized...
  800. Vector2 n = (p_to - r_from).normalized();
  801. while (p_rect.has_point(r_from)) {
  802. r_from += n;
  803. }
  804. }
  805. void AnimationNodeStateMachineEditor::_clip_dst_line_to_rect(const Vector2 &p_from, Vector2 &r_to, const Rect2 &p_rect) {
  806. if (r_to == p_from) {
  807. return;
  808. }
  809. //this could be optimized...
  810. Vector2 n = (r_to - p_from).normalized();
  811. while (p_rect.has_point(r_to)) {
  812. r_to -= n;
  813. }
  814. }
  815. Ref<StyleBox> AnimationNodeStateMachineEditor::_adjust_stylebox_opacity(Ref<StyleBox> p_style, float p_opacity) {
  816. Ref<StyleBox> style = p_style->duplicate();
  817. if (style->is_class("StyleBoxFlat")) {
  818. Ref<StyleBoxFlat> flat_style = style;
  819. Color bg_color = flat_style->get_bg_color();
  820. Color border_color = flat_style->get_border_color();
  821. Color shadow_color = flat_style->get_shadow_color();
  822. bg_color.a *= p_opacity;
  823. border_color.a *= p_opacity;
  824. shadow_color.a *= p_opacity;
  825. flat_style->set_bg_color(bg_color);
  826. flat_style->set_border_color(border_color);
  827. flat_style->set_shadow_color(shadow_color);
  828. }
  829. return style;
  830. }
  831. void AnimationNodeStateMachineEditor::_state_machine_draw() {
  832. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  833. if (!tree) {
  834. return;
  835. }
  836. bool playing = false;
  837. StringName current;
  838. StringName blend_from;
  839. Vector<StringName> travel_path;
  840. Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
  841. if (playback.is_valid()) {
  842. playing = playback->is_playing();
  843. current = playback->get_current_node();
  844. blend_from = playback->get_fading_from_node();
  845. travel_path = playback->get_travel_path();
  846. }
  847. if (state_machine_draw->has_focus()) {
  848. state_machine_draw->draw_rect(Rect2(Point2(), state_machine_draw->get_size()), theme_cache.focus_color, false);
  849. }
  850. int sep = 3 * EDSCALE;
  851. List<StringName> nodes;
  852. state_machine->get_node_list(&nodes);
  853. node_rects.clear();
  854. Rect2 scroll_range;
  855. //snap lines
  856. if (dragging_selected) {
  857. Vector2 from = (state_machine->get_node_position(selected_node) * EDSCALE) + drag_ofs - state_machine->get_graph_offset() * EDSCALE;
  858. if (snap_x != StringName()) {
  859. Vector2 to = (state_machine->get_node_position(snap_x) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE;
  860. state_machine_draw->draw_line(from, to, theme_cache.guideline_color, 2);
  861. }
  862. if (snap_y != StringName()) {
  863. Vector2 to = (state_machine->get_node_position(snap_y) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE;
  864. state_machine_draw->draw_line(from, to, theme_cache.guideline_color, 2);
  865. }
  866. }
  867. //pre pass nodes so we know the rectangles
  868. for (const StringName &E : nodes) {
  869. String name = E;
  870. int name_string_size = theme_cache.node_title_font->get_string_size(name, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.node_title_font_size).width;
  871. Ref<AnimationNode> anode = state_machine->get_node(name);
  872. bool needs_editor = AnimationTreeEditor::get_singleton()->can_edit(anode);
  873. bool is_selected = selected_nodes.has(name);
  874. Size2 s = (is_selected ? theme_cache.node_frame_selected : theme_cache.node_frame)->get_minimum_size();
  875. s.width += name_string_size;
  876. s.height += MAX(theme_cache.node_title_font->get_height(theme_cache.node_title_font_size), theme_cache.play_node->get_height());
  877. s.width += sep + theme_cache.play_node->get_width();
  878. if (needs_editor) {
  879. s.width += sep + theme_cache.edit_node->get_width();
  880. }
  881. Vector2 offset;
  882. offset += state_machine->get_node_position(E) * EDSCALE;
  883. if (selected_nodes.has(E) && dragging_selected) {
  884. offset += drag_ofs;
  885. }
  886. offset -= s / 2;
  887. offset = offset.floor();
  888. //prepre rect
  889. NodeRect nr;
  890. nr.node = Rect2(offset, s);
  891. nr.node_name = E;
  892. scroll_range = scroll_range.merge(nr.node); //merge with range
  893. //now scroll it to draw
  894. nr.node.position -= state_machine->get_graph_offset() * EDSCALE;
  895. node_rects.push_back(nr);
  896. }
  897. transition_lines.clear();
  898. //draw connecting line for potential new transition
  899. if (connecting) {
  900. Vector2 from = (state_machine->get_node_position(connecting_from) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE;
  901. Vector2 to;
  902. if (connecting_to_node != StringName()) {
  903. to = (state_machine->get_node_position(connecting_to_node) * EDSCALE) - state_machine->get_graph_offset() * EDSCALE;
  904. } else {
  905. to = connecting_to;
  906. }
  907. for (int i = 0; i < node_rects.size(); i++) {
  908. if (node_rects[i].node_name == connecting_from) {
  909. _clip_src_line_to_rect(from, to, node_rects[i].node);
  910. }
  911. if (node_rects[i].node_name == connecting_to_node) {
  912. _clip_dst_line_to_rect(from, to, node_rects[i].node);
  913. }
  914. }
  915. _connection_draw(from, to, AnimationNodeStateMachineTransition::SwitchMode(switch_mode->get_selected()), true, false, false, 0.0, false, false);
  916. }
  917. // TransitionImmediateBig
  918. float tr_bidi_offset = int(theme_cache.transition_icons[0]->get_height() * 0.8);
  919. //draw transition lines
  920. for (int i = 0; i < state_machine->get_transition_count(); i++) {
  921. TransitionLine tl;
  922. tl.transition_index = i;
  923. tl.from_node = state_machine->get_transition_from(i);
  924. Vector2 ofs_from = (dragging_selected && selected_nodes.has(tl.from_node)) ? drag_ofs : Vector2();
  925. tl.from = (state_machine->get_node_position(tl.from_node) * EDSCALE) + ofs_from - state_machine->get_graph_offset() * EDSCALE;
  926. tl.to_node = state_machine->get_transition_to(i);
  927. Vector2 ofs_to = (dragging_selected && selected_nodes.has(tl.to_node)) ? drag_ofs : Vector2();
  928. tl.to = (state_machine->get_node_position(tl.to_node) * EDSCALE) + ofs_to - state_machine->get_graph_offset() * EDSCALE;
  929. Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(i);
  930. tl.disabled = bool(tr->get_advance_mode() == AnimationNodeStateMachineTransition::ADVANCE_MODE_DISABLED);
  931. tl.auto_advance = bool(tr->get_advance_mode() == AnimationNodeStateMachineTransition::ADVANCE_MODE_AUTO);
  932. tl.advance_condition_name = tr->get_advance_condition_name();
  933. tl.advance_condition_state = false;
  934. tl.mode = tr->get_switch_mode();
  935. tl.width = tr_bidi_offset;
  936. tl.travel = false;
  937. tl.fade_ratio = 0.0;
  938. tl.hidden = false;
  939. tl.is_across_group = state_machine->is_transition_across_group(i);
  940. if (state_machine->has_transition(tl.to_node, tl.from_node)) { //offset if same exists
  941. Vector2 offset = -(tl.from - tl.to).normalized().orthogonal() * tr_bidi_offset;
  942. tl.from += offset;
  943. tl.to += offset;
  944. }
  945. for (int j = 0; j < node_rects.size(); j++) {
  946. if (node_rects[j].node_name == tl.from_node) {
  947. _clip_src_line_to_rect(tl.from, tl.to, node_rects[j].node);
  948. }
  949. if (node_rects[j].node_name == tl.to_node) {
  950. _clip_dst_line_to_rect(tl.from, tl.to, node_rects[j].node);
  951. }
  952. }
  953. tl.selected = selected_transition_from == tl.from_node && selected_transition_to == tl.to_node;
  954. if (blend_from == tl.from_node && current == tl.to_node) {
  955. tl.travel = true;
  956. tl.fade_ratio = MIN(1.0, fading_pos / fading_time);
  957. }
  958. if (travel_path.size()) {
  959. if (current == tl.from_node && travel_path[0] == tl.to_node) {
  960. tl.travel = true;
  961. } else {
  962. for (int j = 0; j < travel_path.size() - 1; j++) {
  963. if (travel_path[j] == tl.from_node && travel_path[j + 1] == tl.to_node) {
  964. tl.travel = true;
  965. break;
  966. }
  967. }
  968. }
  969. }
  970. StringName fullpath = AnimationTreeEditor::get_singleton()->get_base_path() + String(tl.advance_condition_name);
  971. if (tl.advance_condition_name != StringName() && bool(tree->get(fullpath))) {
  972. tl.advance_condition_state = true;
  973. tl.auto_advance = true;
  974. }
  975. // check if already have this transition
  976. for (int j = 0; j < transition_lines.size(); j++) {
  977. if (transition_lines[j].from_node == tl.from_node && transition_lines[j].to_node == tl.to_node) {
  978. tl.hidden = true;
  979. transition_lines.write[j].disabled = transition_lines[j].disabled && tl.disabled;
  980. }
  981. }
  982. transition_lines.push_back(tl);
  983. }
  984. for (int i = 0; i < transition_lines.size(); i++) {
  985. TransitionLine tl = transition_lines[i];
  986. if (!tl.hidden) {
  987. float opacity = 0.2; // Default to reduced opacity.
  988. if (selected_transition_from != StringName() && selected_transition_to != StringName()) {
  989. // A transition is selected.
  990. if ((tl.from_node == selected_transition_from && tl.to_node == selected_transition_to) || (tl.from_node == selected_transition_to && tl.to_node == selected_transition_from)) {
  991. opacity = 1.0; // Full opacity for the selected transition pair.
  992. }
  993. } else if (!connected_nodes.is_empty()) {
  994. // A node is selected.
  995. if (connected_nodes.has(selected_node)) {
  996. // Only keep full opacity for transitions directly connected to the selected node.
  997. if (tl.from_node == selected_node || tl.to_node == selected_node) {
  998. opacity = 1.0;
  999. }
  1000. } else {
  1001. // If no node is selected, all transitions are at full opacity.
  1002. opacity = 1.0;
  1003. }
  1004. } else {
  1005. // If nothing is selected, all transitions are at full opacity.
  1006. opacity = 1.0;
  1007. }
  1008. _connection_draw(tl.from, tl.to, tl.mode, !tl.disabled, tl.selected, tl.travel, tl.fade_ratio, tl.auto_advance, tl.is_across_group, opacity);
  1009. }
  1010. }
  1011. //draw actual nodes
  1012. for (int i = 0; i < node_rects.size(); i++) {
  1013. String name = node_rects[i].node_name;
  1014. int name_string_size = theme_cache.node_title_font->get_string_size(name, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.node_title_font_size).width;
  1015. Ref<AnimationNode> anode = state_machine->get_node(name);
  1016. bool needs_editor = AnimationTreeEditor::get_singleton()->can_edit(anode);
  1017. bool is_selected = selected_nodes.has(name);
  1018. NodeRect &nr = node_rects.write[i];
  1019. Vector2 offset = nr.node.position;
  1020. int h = nr.node.size.height;
  1021. float opacity = 1.0;
  1022. if (selected_transition_from != StringName() && selected_transition_to != StringName()) {
  1023. // A transition is selected.
  1024. if (name != selected_transition_from && name != selected_transition_to) {
  1025. opacity = 0.2;
  1026. }
  1027. } else if (!connected_nodes.is_empty() && !connected_nodes.has(name)) {
  1028. // A node is selected.
  1029. opacity = 0.2;
  1030. }
  1031. Ref<StyleBox> original_style = is_selected ? theme_cache.node_frame_selected : theme_cache.node_frame;
  1032. Ref<StyleBox> node_style = _adjust_stylebox_opacity(original_style, opacity);
  1033. state_machine_draw->draw_style_box(node_style, nr.node);
  1034. if (!is_selected && SceneStringName(Start) == name) {
  1035. Ref<StyleBox> start_style = _adjust_stylebox_opacity(theme_cache.node_frame_start, opacity);
  1036. state_machine_draw->draw_style_box(start_style, nr.node);
  1037. }
  1038. if (!is_selected && SceneStringName(End) == name) {
  1039. Ref<StyleBox> end_style = _adjust_stylebox_opacity(theme_cache.node_frame_end, opacity);
  1040. state_machine_draw->draw_style_box(end_style, nr.node);
  1041. }
  1042. if (playing && (blend_from == name || current == name || travel_path.has(name))) {
  1043. Ref<StyleBox> playing_style = _adjust_stylebox_opacity(theme_cache.node_frame_playing, opacity);
  1044. state_machine_draw->draw_style_box(playing_style, nr.node);
  1045. }
  1046. offset.x += original_style->get_offset().x;
  1047. nr.play.position = offset + Vector2(0, (h - theme_cache.play_node->get_height()) / 2).floor();
  1048. nr.play.size = theme_cache.play_node->get_size();
  1049. Color color_mod = Color(1, 1, 1, opacity);
  1050. if (hovered_node_name == name && hovered_node_area == HOVER_NODE_PLAY) {
  1051. state_machine_draw->draw_texture(theme_cache.play_node, nr.play.position, theme_cache.highlight_color * color_mod);
  1052. } else {
  1053. state_machine_draw->draw_texture(theme_cache.play_node, nr.play.position, color_mod);
  1054. }
  1055. offset.x += sep + theme_cache.play_node->get_width();
  1056. nr.name.position = offset + Vector2(0, (h - theme_cache.node_title_font->get_height(theme_cache.node_title_font_size)) / 2).floor();
  1057. nr.name.size = Vector2(name_string_size, theme_cache.node_title_font->get_height(theme_cache.node_title_font_size));
  1058. Color font_color = theme_cache.node_title_font_color;
  1059. font_color.a *= opacity;
  1060. state_machine_draw->draw_string(theme_cache.node_title_font, nr.name.position + Vector2(0, theme_cache.node_title_font->get_ascent(theme_cache.node_title_font_size)), name, HORIZONTAL_ALIGNMENT_LEFT, -1, theme_cache.node_title_font_size, font_color);
  1061. offset.x += name_string_size + sep;
  1062. nr.can_edit = needs_editor;
  1063. if (needs_editor) {
  1064. nr.edit.position = offset + Vector2(0, (h - theme_cache.edit_node->get_height()) / 2).floor();
  1065. nr.edit.size = theme_cache.edit_node->get_size();
  1066. if (hovered_node_name == name && hovered_node_area == HOVER_NODE_EDIT) {
  1067. state_machine_draw->draw_texture(theme_cache.edit_node, nr.edit.position, theme_cache.highlight_color * color_mod);
  1068. } else {
  1069. state_machine_draw->draw_texture(theme_cache.edit_node, nr.edit.position, color_mod);
  1070. }
  1071. }
  1072. }
  1073. //draw box select
  1074. if (box_selecting) {
  1075. state_machine_draw->draw_rect(box_selecting_rect, Color(0.7, 0.7, 1.0, 0.3));
  1076. }
  1077. scroll_range.position -= state_machine_draw->get_size();
  1078. scroll_range.size += state_machine_draw->get_size() * 2.0;
  1079. //adjust scrollbars
  1080. updating = true;
  1081. h_scroll->set_min(scroll_range.position.x);
  1082. h_scroll->set_max(scroll_range.position.x + scroll_range.size.x);
  1083. h_scroll->set_page(state_machine_draw->get_size().x);
  1084. h_scroll->set_value(state_machine->get_graph_offset().x);
  1085. v_scroll->set_min(scroll_range.position.y);
  1086. v_scroll->set_max(scroll_range.position.y + scroll_range.size.y);
  1087. v_scroll->set_page(state_machine_draw->get_size().y);
  1088. v_scroll->set_value(state_machine->get_graph_offset().y);
  1089. updating = false;
  1090. state_machine_play_pos->queue_redraw();
  1091. }
  1092. void AnimationNodeStateMachineEditor::_update_connected_nodes(const StringName &p_node) {
  1093. connected_nodes.clear();
  1094. if (p_node != StringName()) {
  1095. connected_nodes.insert(p_node);
  1096. Vector<StringName> nodes_to = state_machine->get_nodes_with_transitions_to(p_node);
  1097. for (const StringName &node_to : nodes_to) {
  1098. connected_nodes.insert(node_to);
  1099. }
  1100. Vector<StringName> nodes_from = state_machine->get_nodes_with_transitions_from(p_node);
  1101. for (const StringName &node_from : nodes_from) {
  1102. connected_nodes.insert(node_from);
  1103. }
  1104. }
  1105. }
  1106. void AnimationNodeStateMachineEditor::_state_machine_pos_draw_individual(const String &p_name, float p_ratio) {
  1107. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  1108. if (!tree) {
  1109. return;
  1110. }
  1111. Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
  1112. if (playback.is_null() || !playback->is_playing()) {
  1113. return;
  1114. }
  1115. if (p_name == SceneStringName(Start) || p_name == SceneStringName(End) || p_name.is_empty()) {
  1116. return;
  1117. }
  1118. int idx = -1;
  1119. for (int i = 0; i < node_rects.size(); i++) {
  1120. if (node_rects[i].node_name == p_name) {
  1121. idx = i;
  1122. break;
  1123. }
  1124. }
  1125. if (idx == -1) {
  1126. return;
  1127. }
  1128. const NodeRect &nr = node_rects[idx];
  1129. if (nr.can_edit) {
  1130. return; // It is not AnimationNodeAnimation.
  1131. }
  1132. Vector2 from;
  1133. from.x = nr.play.position.x;
  1134. from.y = (nr.play.position.y + nr.play.size.y + nr.node.position.y + nr.node.size.y) * 0.5;
  1135. Vector2 to;
  1136. if (nr.edit.size.x) {
  1137. to.x = nr.edit.position.x + nr.edit.size.x;
  1138. } else {
  1139. to.x = nr.name.position.x + nr.name.size.x;
  1140. }
  1141. to.y = from.y;
  1142. state_machine_play_pos->draw_line(from, to, theme_cache.playback_background_color, 2);
  1143. to = from.lerp(to, p_ratio);
  1144. state_machine_play_pos->draw_line(from, to, theme_cache.playback_color, 2);
  1145. }
  1146. void AnimationNodeStateMachineEditor::_state_machine_pos_draw_all() {
  1147. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  1148. if (!tree) {
  1149. return;
  1150. }
  1151. Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
  1152. if (playback.is_null() || !playback->is_playing()) {
  1153. return;
  1154. }
  1155. {
  1156. float len = MAX(0.0001, current_length);
  1157. float pos = CLAMP(current_play_pos, 0, len);
  1158. float c = pos / len;
  1159. _state_machine_pos_draw_individual(playback->get_current_node(), c);
  1160. }
  1161. {
  1162. float len = MAX(0.0001, fade_from_length);
  1163. float pos = CLAMP(fade_from_current_play_pos, 0, len);
  1164. float c = pos / len;
  1165. _state_machine_pos_draw_individual(playback->get_fading_from_node(), c);
  1166. }
  1167. }
  1168. void AnimationNodeStateMachineEditor::_update_graph() {
  1169. if (updating) {
  1170. return;
  1171. }
  1172. updating = true;
  1173. state_machine_draw->queue_redraw();
  1174. updating = false;
  1175. }
  1176. void AnimationNodeStateMachineEditor::_notification(int p_what) {
  1177. switch (p_what) {
  1178. case NOTIFICATION_THEME_CHANGED: {
  1179. panel->add_theme_style_override(SceneStringName(panel), theme_cache.panel_style);
  1180. error_panel->add_theme_style_override(SceneStringName(panel), theme_cache.error_panel_style);
  1181. error_label->add_theme_color_override(SceneStringName(font_color), theme_cache.error_color);
  1182. tool_select->set_button_icon(theme_cache.tool_icon_select);
  1183. tool_create->set_button_icon(theme_cache.tool_icon_create);
  1184. tool_connect->set_button_icon(theme_cache.tool_icon_connect);
  1185. switch_mode->clear();
  1186. switch_mode->add_icon_item(theme_cache.transition_icon_immediate, TTR("Immediate"));
  1187. switch_mode->add_icon_item(theme_cache.transition_icon_sync, TTR("Sync"));
  1188. switch_mode->add_icon_item(theme_cache.transition_icon_end, TTR("At End"));
  1189. auto_advance->set_button_icon(theme_cache.play_icon_auto);
  1190. tool_erase->set_button_icon(theme_cache.tool_icon_erase);
  1191. play_mode->clear();
  1192. play_mode->add_icon_item(theme_cache.play_icon_travel, TTR("Travel"));
  1193. play_mode->add_icon_item(theme_cache.play_icon_start, TTR("Immediate"));
  1194. } break;
  1195. case NOTIFICATION_PROCESS: {
  1196. AnimationTree *tree = AnimationTreeEditor::get_singleton()->get_animation_tree();
  1197. if (!tree) {
  1198. return;
  1199. }
  1200. String error;
  1201. Ref<AnimationNodeStateMachinePlayback> playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
  1202. if (error_time > 0) {
  1203. error = error_text;
  1204. error_time -= get_process_delta_time();
  1205. } else if (!tree->is_active()) {
  1206. error = TTR("AnimationTree is inactive.\nActivate to enable playback, check node warnings if activation fails.");
  1207. } else if (tree->is_state_invalid()) {
  1208. error = tree->get_invalid_state_reason();
  1209. } else if (playback.is_null()) {
  1210. error = vformat(TTR("No playback resource set at path: %s."), AnimationTreeEditor::get_singleton()->get_base_path() + "playback");
  1211. }
  1212. if (error != error_label->get_text()) {
  1213. error_label->set_text(error);
  1214. if (!error.is_empty()) {
  1215. error_panel->show();
  1216. } else {
  1217. error_panel->hide();
  1218. }
  1219. }
  1220. for (int i = 0; i < transition_lines.size(); i++) {
  1221. int tidx = -1;
  1222. for (int j = 0; j < state_machine->get_transition_count(); j++) {
  1223. if (transition_lines[i].from_node == state_machine->get_transition_from(j) && transition_lines[i].to_node == state_machine->get_transition_to(j)) {
  1224. tidx = j;
  1225. break;
  1226. }
  1227. }
  1228. if (tidx == -1) { //missing transition, should redraw
  1229. state_machine_draw->queue_redraw();
  1230. break;
  1231. }
  1232. if (transition_lines[i].disabled != bool(state_machine->get_transition(tidx)->get_advance_mode() == AnimationNodeStateMachineTransition::ADVANCE_MODE_DISABLED)) {
  1233. state_machine_draw->queue_redraw();
  1234. break;
  1235. }
  1236. if (transition_lines[i].auto_advance != bool(state_machine->get_transition(tidx)->get_advance_mode() == AnimationNodeStateMachineTransition::ADVANCE_MODE_AUTO)) {
  1237. state_machine_draw->queue_redraw();
  1238. break;
  1239. }
  1240. if (transition_lines[i].advance_condition_name != state_machine->get_transition(tidx)->get_advance_condition_name()) {
  1241. state_machine_draw->queue_redraw();
  1242. break;
  1243. }
  1244. if (transition_lines[i].mode != state_machine->get_transition(tidx)->get_switch_mode()) {
  1245. state_machine_draw->queue_redraw();
  1246. break;
  1247. }
  1248. bool acstate = transition_lines[i].advance_condition_name != StringName() && bool(tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + String(transition_lines[i].advance_condition_name)));
  1249. if (transition_lines[i].advance_condition_state != acstate) {
  1250. state_machine_draw->queue_redraw();
  1251. break;
  1252. }
  1253. }
  1254. bool same_travel_path = true;
  1255. Vector<StringName> tp;
  1256. bool is_playing = false;
  1257. StringName current_node;
  1258. StringName fading_from_node;
  1259. current_play_pos = 0;
  1260. current_length = 0;
  1261. fade_from_current_play_pos = 0;
  1262. fade_from_length = 0;
  1263. fading_time = 0;
  1264. fading_pos = 0;
  1265. if (playback.is_valid()) {
  1266. tp = playback->get_travel_path();
  1267. is_playing = playback->is_playing();
  1268. current_node = playback->get_current_node();
  1269. fading_from_node = playback->get_fading_from_node();
  1270. current_play_pos = playback->get_current_play_pos();
  1271. current_length = playback->get_current_length();
  1272. fade_from_current_play_pos = playback->get_fade_from_play_pos();
  1273. fade_from_length = playback->get_fade_from_length();
  1274. fading_time = playback->get_fading_time();
  1275. fading_pos = playback->get_fading_pos();
  1276. }
  1277. {
  1278. if (last_travel_path.size() != tp.size()) {
  1279. same_travel_path = false;
  1280. } else {
  1281. for (int i = 0; i < last_travel_path.size(); i++) {
  1282. if (last_travel_path[i] != tp[i]) {
  1283. same_travel_path = false;
  1284. break;
  1285. }
  1286. }
  1287. }
  1288. }
  1289. //redraw if travel state changed
  1290. if (!same_travel_path ||
  1291. last_active != is_playing ||
  1292. last_current_node != current_node ||
  1293. last_fading_from_node != fading_from_node ||
  1294. last_fading_time != fading_time ||
  1295. last_fading_pos != fading_pos) {
  1296. state_machine_draw->queue_redraw();
  1297. last_travel_path = tp;
  1298. last_current_node = current_node;
  1299. last_active = is_playing;
  1300. last_fading_from_node = fading_from_node;
  1301. last_fading_time = fading_time;
  1302. last_fading_pos = fading_pos;
  1303. state_machine_play_pos->queue_redraw();
  1304. }
  1305. {
  1306. if (current_node != StringName() && state_machine->has_node(current_node)) {
  1307. String next = current_node;
  1308. Ref<AnimationNodeStateMachine> anodesm = state_machine->get_node(next);
  1309. Ref<AnimationNodeStateMachinePlayback> current_node_playback;
  1310. while (anodesm.is_valid()) {
  1311. current_node_playback = tree->get(AnimationTreeEditor::get_singleton()->get_base_path() + next + "/playback");
  1312. StringName cnode = current_node_playback->get_current_node();
  1313. next += "/" + cnode;
  1314. if (!anodesm->has_node(cnode)) {
  1315. break;
  1316. }
  1317. anodesm = anodesm->get_node(cnode);
  1318. }
  1319. // when current_node is a state machine, use playback of current_node to set play_pos
  1320. if (current_node_playback.is_valid()) {
  1321. current_play_pos = current_node_playback->get_current_play_pos();
  1322. current_length = current_node_playback->get_current_length();
  1323. }
  1324. }
  1325. }
  1326. if (last_play_pos != current_play_pos || fade_from_last_play_pos != fade_from_current_play_pos) {
  1327. last_play_pos = current_play_pos;
  1328. fade_from_last_play_pos = fade_from_current_play_pos;
  1329. state_machine_play_pos->queue_redraw();
  1330. }
  1331. } break;
  1332. case NOTIFICATION_VISIBILITY_CHANGED: {
  1333. hovered_node_name = StringName();
  1334. hovered_node_area = HOVER_NODE_NONE;
  1335. set_process(is_visible_in_tree());
  1336. } break;
  1337. }
  1338. }
  1339. void AnimationNodeStateMachineEditor::_open_editor(const String &p_name) {
  1340. AnimationTreeEditor::get_singleton()->enter_editor(p_name);
  1341. }
  1342. void AnimationNodeStateMachineEditor::_name_edited(const String &p_text) {
  1343. const String &new_name = p_text;
  1344. ERR_FAIL_COND(new_name.is_empty() || new_name.contains_char('.') || new_name.contains_char('/'));
  1345. if (new_name == prev_name) {
  1346. return; // Nothing to do.
  1347. }
  1348. const String &base_name = new_name;
  1349. int base = 1;
  1350. String name = base_name;
  1351. while (state_machine->has_node(name)) {
  1352. if (name == prev_name) {
  1353. name_edit_popup->hide(); // The old name wins, the name doesn't change, just hide the popup.
  1354. return;
  1355. }
  1356. base++;
  1357. name = base_name + " " + itos(base);
  1358. }
  1359. updating = true;
  1360. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1361. undo_redo->create_action(TTR("Node Renamed"));
  1362. undo_redo->add_do_method(state_machine.ptr(), "rename_node", prev_name, name);
  1363. undo_redo->add_undo_method(state_machine.ptr(), "rename_node", name, prev_name);
  1364. undo_redo->add_do_method(this, "_update_graph");
  1365. undo_redo->add_undo_method(this, "_update_graph");
  1366. undo_redo->commit_action();
  1367. name_edit_popup->hide();
  1368. updating = false;
  1369. state_machine_draw->queue_redraw();
  1370. }
  1371. void AnimationNodeStateMachineEditor::_name_edited_focus_out() {
  1372. if (updating) {
  1373. return;
  1374. }
  1375. _name_edited(name_edit->get_text());
  1376. }
  1377. void AnimationNodeStateMachineEditor::_scroll_changed(double) {
  1378. if (updating) {
  1379. return;
  1380. }
  1381. state_machine->set_graph_offset(Vector2(h_scroll->get_value(), v_scroll->get_value()));
  1382. state_machine_draw->queue_redraw();
  1383. }
  1384. void AnimationNodeStateMachineEditor::_erase_selected(const bool p_nested_action) {
  1385. if (!selected_nodes.is_empty()) {
  1386. if (!p_nested_action) {
  1387. updating = true;
  1388. }
  1389. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1390. undo_redo->create_action(TTR("Node Removed"));
  1391. for (int i = 0; i < node_rects.size(); i++) {
  1392. if (node_rects[i].node_name == SceneStringName(Start) || node_rects[i].node_name == SceneStringName(End)) {
  1393. continue;
  1394. }
  1395. if (!selected_nodes.has(node_rects[i].node_name)) {
  1396. continue;
  1397. }
  1398. undo_redo->add_do_method(state_machine.ptr(), "remove_node", node_rects[i].node_name);
  1399. undo_redo->add_undo_method(state_machine.ptr(), "add_node", node_rects[i].node_name,
  1400. state_machine->get_node(node_rects[i].node_name),
  1401. state_machine->get_node_position(node_rects[i].node_name));
  1402. for (int j = 0; j < state_machine->get_transition_count(); j++) {
  1403. String from = state_machine->get_transition_from(j);
  1404. String to = state_machine->get_transition_to(j);
  1405. if (from == node_rects[i].node_name || to == node_rects[i].node_name) {
  1406. undo_redo->add_undo_method(state_machine.ptr(), "add_transition", from, to, state_machine->get_transition(j));
  1407. }
  1408. }
  1409. }
  1410. undo_redo->add_do_method(this, "_update_graph");
  1411. undo_redo->add_undo_method(this, "_update_graph");
  1412. undo_redo->commit_action();
  1413. if (!p_nested_action) {
  1414. updating = false;
  1415. }
  1416. selected_nodes.clear();
  1417. }
  1418. if (selected_transition_to != StringName() && selected_transition_from != StringName() && state_machine->has_transition(selected_transition_from, selected_transition_to)) {
  1419. Ref<AnimationNodeStateMachineTransition> tr = state_machine->get_transition(state_machine->find_transition(selected_transition_from, selected_transition_to));
  1420. if (!p_nested_action) {
  1421. updating = true;
  1422. }
  1423. EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton();
  1424. undo_redo->create_action(TTR("Transition Removed"));
  1425. undo_redo->add_do_method(state_machine.ptr(), "remove_transition", selected_transition_from, selected_transition_to);
  1426. undo_redo->add_undo_method(state_machine.ptr(), "add_transition", selected_transition_from, selected_transition_to, tr);
  1427. undo_redo->add_do_method(this, "_update_graph");
  1428. undo_redo->add_undo_method(this, "_update_graph");
  1429. undo_redo->commit_action();
  1430. if (!p_nested_action) {
  1431. updating = false;
  1432. }
  1433. selected_transition_from = StringName();
  1434. selected_transition_to = StringName();
  1435. selected_transition_index = -1;
  1436. }
  1437. state_machine_draw->queue_redraw();
  1438. }
  1439. void AnimationNodeStateMachineEditor::_update_mode() {
  1440. if (tool_select->is_pressed()) {
  1441. selection_tools_hb->show();
  1442. bool nothing_selected = selected_nodes.is_empty() && selected_transition_from == StringName() && selected_transition_to == StringName();
  1443. bool start_end_selected = selected_nodes.size() == 1 && (*selected_nodes.begin() == SceneStringName(Start) || *selected_nodes.begin() == SceneStringName(End));
  1444. tool_erase->set_disabled(nothing_selected || start_end_selected || read_only);
  1445. } else {
  1446. selection_tools_hb->hide();
  1447. }
  1448. if (read_only) {
  1449. tool_create->set_pressed(false);
  1450. tool_connect->set_pressed(false);
  1451. }
  1452. if (tool_connect->is_pressed()) {
  1453. transition_tools_hb->show();
  1454. } else {
  1455. transition_tools_hb->hide();
  1456. }
  1457. }
  1458. void AnimationNodeStateMachineEditor::_bind_methods() {
  1459. ClassDB::bind_method("_update_graph", &AnimationNodeStateMachineEditor::_update_graph);
  1460. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, panel_style, "panel", "GraphStateMachine");
  1461. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, error_panel_style, "error_panel", "GraphStateMachine");
  1462. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, error_color, "error_color", "GraphStateMachine");
  1463. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, tool_icon_select, "ToolSelect", "EditorIcons");
  1464. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, tool_icon_create, "ToolAddNode", "EditorIcons");
  1465. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, tool_icon_connect, "ToolConnect", "EditorIcons");
  1466. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, tool_icon_erase, "Remove", "EditorIcons");
  1467. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icon_immediate, "TransitionImmediate", "EditorIcons");
  1468. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icon_sync, "TransitionSync", "EditorIcons");
  1469. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icon_end, "TransitionEnd", "EditorIcons");
  1470. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, play_icon_start, "Play", "EditorIcons");
  1471. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, play_icon_travel, "PlayTravel", "EditorIcons");
  1472. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, play_icon_auto, "AutoPlay", "EditorIcons");
  1473. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, animation_icon, "Animation", "EditorIcons");
  1474. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, node_frame, "node_frame", "GraphStateMachine");
  1475. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, node_frame_selected, "node_frame_selected", "GraphStateMachine");
  1476. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, node_frame_playing, "node_frame_playing", "GraphStateMachine");
  1477. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, node_frame_start, "node_frame_start", "GraphStateMachine");
  1478. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_STYLEBOX, AnimationNodeStateMachineEditor, node_frame_end, "node_frame_end", "GraphStateMachine");
  1479. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_FONT, AnimationNodeStateMachineEditor, node_title_font, "node_title_font", "GraphStateMachine");
  1480. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_FONT_SIZE, AnimationNodeStateMachineEditor, node_title_font_size, "node_title_font_size", "GraphStateMachine");
  1481. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, node_title_font_color, "node_title_font_color", "GraphStateMachine");
  1482. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, play_node, "Play", "EditorIcons");
  1483. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, edit_node, "Edit", "EditorIcons");
  1484. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, transition_color, "transition_color", "GraphStateMachine");
  1485. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, transition_disabled_color, "transition_disabled_color", "GraphStateMachine");
  1486. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, transition_icon_color, "transition_icon_color", "GraphStateMachine");
  1487. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, transition_icon_disabled_color, "transition_icon_disabled_color", "GraphStateMachine");
  1488. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, highlight_color, "highlight_color", "GraphStateMachine");
  1489. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, highlight_disabled_color, "highlight_disabled_color", "GraphStateMachine");
  1490. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, focus_color, "focus_color", "GraphStateMachine");
  1491. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, guideline_color, "guideline_color", "GraphStateMachine");
  1492. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[0], "TransitionImmediateBig", "EditorIcons");
  1493. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[1], "TransitionSyncBig", "EditorIcons");
  1494. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[2], "TransitionEndBig", "EditorIcons");
  1495. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[3], "TransitionImmediateAutoBig", "EditorIcons");
  1496. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[4], "TransitionSyncAutoBig", "EditorIcons");
  1497. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_ICON, AnimationNodeStateMachineEditor, transition_icons[5], "TransitionEndAutoBig", "EditorIcons");
  1498. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, playback_color, "playback_color", "GraphStateMachine");
  1499. BIND_THEME_ITEM_EXT(Theme::DATA_TYPE_COLOR, AnimationNodeStateMachineEditor, playback_background_color, "playback_background_color", "GraphStateMachine");
  1500. }
  1501. AnimationNodeStateMachineEditor *AnimationNodeStateMachineEditor::singleton = nullptr;
  1502. AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() {
  1503. singleton = this;
  1504. HBoxContainer *top_hb = memnew(HBoxContainer);
  1505. add_child(top_hb);
  1506. Ref<ButtonGroup> bg;
  1507. bg.instantiate();
  1508. tool_select = memnew(Button);
  1509. tool_select->set_theme_type_variation(SceneStringName(FlatButton));
  1510. top_hb->add_child(tool_select);
  1511. tool_select->set_toggle_mode(true);
  1512. tool_select->set_button_group(bg);
  1513. tool_select->set_pressed(true);
  1514. tool_select->set_tooltip_text(TTR("Select and move nodes.\nRMB: Add node at position clicked.\nShift+LMB+Drag: Connects the selected node with another node or creates a new node if you select an area without nodes."));
  1515. tool_select->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_update_mode), CONNECT_DEFERRED);
  1516. tool_create = memnew(Button);
  1517. tool_create->set_theme_type_variation(SceneStringName(FlatButton));
  1518. top_hb->add_child(tool_create);
  1519. tool_create->set_toggle_mode(true);
  1520. tool_create->set_button_group(bg);
  1521. tool_create->set_tooltip_text(TTR("Create new nodes."));
  1522. tool_create->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_update_mode), CONNECT_DEFERRED);
  1523. tool_connect = memnew(Button);
  1524. tool_connect->set_theme_type_variation(SceneStringName(FlatButton));
  1525. top_hb->add_child(tool_connect);
  1526. tool_connect->set_toggle_mode(true);
  1527. tool_connect->set_button_group(bg);
  1528. tool_connect->set_tooltip_text(TTR("Connect nodes."));
  1529. tool_connect->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_update_mode), CONNECT_DEFERRED);
  1530. // Context-sensitive selection tools:
  1531. selection_tools_hb = memnew(HBoxContainer);
  1532. top_hb->add_child(selection_tools_hb);
  1533. selection_tools_hb->add_child(memnew(VSeparator));
  1534. tool_erase = memnew(Button);
  1535. tool_erase->set_theme_type_variation(SceneStringName(FlatButton));
  1536. tool_erase->set_tooltip_text(TTR("Remove selected node or transition."));
  1537. tool_erase->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_erase_selected).bind(false));
  1538. tool_erase->set_disabled(true);
  1539. selection_tools_hb->add_child(tool_erase);
  1540. transition_tools_hb = memnew(HBoxContainer);
  1541. top_hb->add_child(transition_tools_hb);
  1542. transition_tools_hb->add_child(memnew(VSeparator));
  1543. transition_tools_hb->add_child(memnew(Label(TTR("Transition:"))));
  1544. switch_mode = memnew(OptionButton);
  1545. transition_tools_hb->add_child(switch_mode);
  1546. auto_advance = memnew(Button);
  1547. auto_advance->set_theme_type_variation(SceneStringName(FlatButton));
  1548. auto_advance->set_tooltip_text(TTR("New Transitions Should Auto Advance"));
  1549. auto_advance->set_toggle_mode(true);
  1550. auto_advance->set_pressed(true);
  1551. transition_tools_hb->add_child(auto_advance);
  1552. //
  1553. top_hb->add_spacer();
  1554. top_hb->add_child(memnew(Label(TTR("Play Mode:"))));
  1555. play_mode = memnew(OptionButton);
  1556. top_hb->add_child(play_mode);
  1557. panel = memnew(PanelContainer);
  1558. panel->set_clip_contents(true);
  1559. panel->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1560. add_child(panel);
  1561. panel->set_v_size_flags(SIZE_EXPAND_FILL);
  1562. state_machine_draw = memnew(Control);
  1563. panel->add_child(state_machine_draw);
  1564. state_machine_draw->connect(SceneStringName(gui_input), callable_mp(this, &AnimationNodeStateMachineEditor::_state_machine_gui_input));
  1565. state_machine_draw->connect(SceneStringName(draw), callable_mp(this, &AnimationNodeStateMachineEditor::_state_machine_draw));
  1566. state_machine_draw->set_focus_mode(FOCUS_ALL);
  1567. state_machine_draw->set_mouse_filter(Control::MOUSE_FILTER_PASS);
  1568. state_machine_play_pos = memnew(Control);
  1569. state_machine_draw->add_child(state_machine_play_pos);
  1570. state_machine_play_pos->set_mouse_filter(MOUSE_FILTER_PASS); //pass all to parent
  1571. state_machine_play_pos->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
  1572. state_machine_play_pos->connect(SceneStringName(draw), callable_mp(this, &AnimationNodeStateMachineEditor::_state_machine_pos_draw_all));
  1573. v_scroll = memnew(VScrollBar);
  1574. state_machine_draw->add_child(v_scroll);
  1575. v_scroll->set_anchors_and_offsets_preset(PRESET_RIGHT_WIDE);
  1576. v_scroll->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeStateMachineEditor::_scroll_changed));
  1577. h_scroll = memnew(HScrollBar);
  1578. state_machine_draw->add_child(h_scroll);
  1579. h_scroll->set_anchors_and_offsets_preset(PRESET_BOTTOM_WIDE);
  1580. h_scroll->set_offset(SIDE_RIGHT, -v_scroll->get_size().x * EDSCALE);
  1581. h_scroll->connect(SceneStringName(value_changed), callable_mp(this, &AnimationNodeStateMachineEditor::_scroll_changed));
  1582. error_panel = memnew(PanelContainer);
  1583. add_child(error_panel);
  1584. error_label = memnew(Label);
  1585. error_panel->add_child(error_label);
  1586. error_panel->hide();
  1587. set_custom_minimum_size(Size2(0, 300 * EDSCALE));
  1588. menu = memnew(PopupMenu);
  1589. add_child(menu);
  1590. menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_add_menu_type));
  1591. menu->connect("popup_hide", callable_mp(this, &AnimationNodeStateMachineEditor::_stop_connecting));
  1592. animations_menu = memnew(PopupMenu);
  1593. animations_menu->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1594. menu->add_child(animations_menu);
  1595. animations_menu->connect("index_pressed", callable_mp(this, &AnimationNodeStateMachineEditor::_add_animation_type));
  1596. connect_menu = memnew(PopupMenu);
  1597. add_child(connect_menu);
  1598. connect_menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_connect_to));
  1599. connect_menu->connect("popup_hide", callable_mp(this, &AnimationNodeStateMachineEditor::_stop_connecting));
  1600. state_machine_menu = memnew(PopupMenu);
  1601. state_machine_menu->set_name("state_machines");
  1602. state_machine_menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_connect_to));
  1603. connect_menu->add_child(state_machine_menu);
  1604. end_menu = memnew(PopupMenu);
  1605. end_menu->set_name("end_nodes");
  1606. end_menu->connect(SceneStringName(id_pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_connect_to));
  1607. connect_menu->add_child(end_menu);
  1608. name_edit_popup = memnew(Popup);
  1609. add_child(name_edit_popup);
  1610. name_edit = memnew(LineEdit);
  1611. name_edit_popup->add_child(name_edit);
  1612. name_edit->set_anchors_and_offsets_preset(PRESET_FULL_RECT);
  1613. name_edit->connect(SceneStringName(text_submitted), callable_mp(this, &AnimationNodeStateMachineEditor::_name_edited));
  1614. name_edit->connect(SceneStringName(focus_exited), callable_mp(this, &AnimationNodeStateMachineEditor::_name_edited_focus_out));
  1615. open_file = memnew(EditorFileDialog);
  1616. add_child(open_file);
  1617. open_file->set_title(TTR("Open Animation Node"));
  1618. open_file->set_file_mode(EditorFileDialog::FILE_MODE_OPEN_FILE);
  1619. open_file->connect("file_selected", callable_mp(this, &AnimationNodeStateMachineEditor::_file_opened));
  1620. delete_window = memnew(ConfirmationDialog);
  1621. delete_window->set_flag(Window::FLAG_RESIZE_DISABLED, true);
  1622. add_child(delete_window);
  1623. delete_tree = memnew(Tree);
  1624. delete_tree->set_auto_translate_mode(AUTO_TRANSLATE_MODE_DISABLED);
  1625. delete_tree->set_hide_root(true);
  1626. delete_tree->connect(SceneStringName(draw), callable_mp(this, &AnimationNodeStateMachineEditor::_delete_tree_draw));
  1627. delete_window->add_child(delete_tree);
  1628. Button *ok = delete_window->get_cancel_button();
  1629. ok->set_text(TTR("Delete Selected"));
  1630. ok->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_delete_selected));
  1631. Button *delete_all = delete_window->add_button(TTR("Delete All"), true);
  1632. delete_all->connect(SceneStringName(pressed), callable_mp(this, &AnimationNodeStateMachineEditor::_delete_all));
  1633. }
  1634. void EditorAnimationMultiTransitionEdit::add_transition(const StringName &p_from, const StringName &p_to, Ref<AnimationNodeStateMachineTransition> p_transition) {
  1635. Transition tr;
  1636. tr.from = p_from;
  1637. tr.to = p_to;
  1638. tr.transition = p_transition;
  1639. transitions.push_back(tr);
  1640. }
  1641. bool EditorAnimationMultiTransitionEdit::_set(const StringName &p_name, const Variant &p_property) {
  1642. int index = String(p_name).get_slicec('/', 0).to_int();
  1643. StringName prop = String(p_name).get_slicec('/', 1);
  1644. bool found;
  1645. transitions.write[index].transition->set(prop, p_property, &found);
  1646. if (found) {
  1647. return true;
  1648. }
  1649. return false;
  1650. }
  1651. bool EditorAnimationMultiTransitionEdit::_get(const StringName &p_name, Variant &r_property) const {
  1652. int index = String(p_name).get_slicec('/', 0).to_int();
  1653. StringName prop = String(p_name).get_slicec('/', 1);
  1654. if (prop == "transition_path") {
  1655. r_property = String(transitions[index].from) + " -> " + transitions[index].to;
  1656. return true;
  1657. }
  1658. bool found;
  1659. r_property = transitions[index].transition->get(prop, &found);
  1660. if (found) {
  1661. return true;
  1662. }
  1663. return false;
  1664. }
  1665. void EditorAnimationMultiTransitionEdit::_get_property_list(List<PropertyInfo> *p_list) const {
  1666. for (int i = 0; i < transitions.size(); i++) {
  1667. List<PropertyInfo> plist;
  1668. transitions[i].transition->get_property_list(&plist, true);
  1669. PropertyInfo prop_transition_path;
  1670. prop_transition_path.type = Variant::STRING;
  1671. prop_transition_path.name = itos(i) + "/" + "transition_path";
  1672. p_list->push_back(prop_transition_path);
  1673. for (const PropertyInfo &pi : plist) {
  1674. if (pi.name == "script" || pi.name == "resource_name" || pi.name == "resource_path" || pi.name == "resource_local_to_scene") {
  1675. continue;
  1676. }
  1677. if (pi.usage != PROPERTY_USAGE_DEFAULT) {
  1678. continue;
  1679. }
  1680. PropertyInfo prop = pi;
  1681. prop.name = itos(i) + "/" + prop.name;
  1682. p_list->push_back(prop);
  1683. }
  1684. }
  1685. }