EditorUI.as 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738
  1. // Urho3D editor user interface
  2. XMLFile@ uiStyle;
  3. XMLFile@ iconStyle;
  4. UIElement@ uiMenuBar;
  5. UIElement@ quickMenu;
  6. Menu@ recentSceneMenu;
  7. Window@ mruScenesPopup;
  8. Array<QuickMenuItem@> quickMenuItems;
  9. FileSelector@ uiFileSelector;
  10. String consoleCommandInterpreter;
  11. Window@ contextMenu;
  12. const StringHash UI_ELEMENT_TYPE("UIElement");
  13. const StringHash WINDOW_TYPE("Window");
  14. const StringHash MENU_TYPE("Menu");
  15. const StringHash TEXT_TYPE("Text");
  16. const StringHash CURSOR_TYPE("Cursor");
  17. const String AUTO_STYLE(""); // Empty string means auto style, i.e. applying style according to UI-element's type automatically
  18. const String TEMP_SCENE_NAME("_tempscene_.xml");
  19. const StringHash CALLBACK_VAR("Callback");
  20. const StringHash INDENT_MODIFIED_BY_ICON_VAR("IconIndented");
  21. const StringHash VAR_CONTEXT_MENU_HANDLER("ContextMenuHandler");
  22. const int SHOW_POPUP_INDICATOR = -1;
  23. const uint MAX_QUICK_MENU_ITEMS = 10;
  24. const uint maxRecentSceneCount = 5;
  25. Array<String> uiSceneFilters = {"*.xml", "*.bin", "*.*"};
  26. Array<String> uiElementFilters = {"*.xml"};
  27. Array<String> uiAllFilters = {"*.*"};
  28. Array<String> uiScriptFilters = {"*.as", "*.*"};
  29. Array<String> uiParticleFilters = {"*.xml"};
  30. Array<String> uiRenderPathFilters = {"*.xml"};
  31. uint uiSceneFilter = 0;
  32. uint uiElementFilter = 0;
  33. uint uiNodeFilter = 0;
  34. uint uiImportFilter = 0;
  35. uint uiScriptFilter = 0;
  36. uint uiParticleFilter = 0;
  37. uint uiRenderPathFilter = 0;
  38. String uiScenePath = fileSystem.programDir + "Data/Scenes";
  39. String uiElementPath = fileSystem.programDir + "Data/UI";
  40. String uiNodePath = fileSystem.programDir + "Data/Objects";
  41. String uiImportPath;
  42. String uiScriptPath = fileSystem.programDir + "Data/Scripts";
  43. String uiParticlePath = fileSystem.programDir + "Data/Particles";
  44. String uiRenderPathPath = fileSystem.programDir + "CoreData/RenderPaths";
  45. Array<String> uiRecentScenes;
  46. String screenshotDir = fileSystem.programDir + "Screenshots";
  47. bool uiFaded = false;
  48. float uiMinOpacity = 0.3;
  49. float uiMaxOpacity = 0.7;
  50. bool uiHidden = false;
  51. bool uiMmbPan = false;
  52. void CreateUI()
  53. {
  54. // Remove all existing UI content in case we are reloading the editor script
  55. /// \todo The console will not be properly recreated as it has already been created once
  56. ui.root.RemoveAllChildren();
  57. uiStyle = GetEditorUIXMLFile("UI/DefaultStyle.xml");
  58. ui.root.defaultStyle = uiStyle;
  59. iconStyle = GetEditorUIXMLFile("UI/EditorIcons.xml");
  60. CreateCursor();
  61. CreateMenuBar();
  62. CreateToolBar();
  63. CreateSecondaryToolBar();
  64. CreateQuickMenu();
  65. CreateContextMenu();
  66. CreateHierarchyWindow();
  67. CreateAttributeInspectorWindow();
  68. CreateEditorSettingsDialog();
  69. CreateEditorPreferencesDialog();
  70. CreateMaterialEditor();
  71. CreateParticleEffectEditor();
  72. CreateSpawnEditor();
  73. CreateSoundTypeEditor();
  74. CreateStatsBar();
  75. CreateConsole();
  76. CreateDebugHud();
  77. CreateResourceBrowser();
  78. CreateCamera();
  79. CreateLayerEditor();
  80. SubscribeToEvent("ScreenMode", "ResizeUI");
  81. SubscribeToEvent("MenuSelected", "HandleMenuSelected");
  82. SubscribeToEvent("KeyDown", "HandleKeyDown");
  83. SubscribeToEvent("KeyUp", "UnfadeUI");
  84. SubscribeToEvent("MouseButtonUp", "UnfadeUI");
  85. }
  86. void ResizeUI()
  87. {
  88. // Resize menu bar
  89. uiMenuBar.SetFixedWidth(graphics.width);
  90. // Resize tool bar
  91. toolBar.SetFixedWidth(graphics.width);
  92. // Resize secondary tool bar
  93. secondaryToolBar.SetFixedHeight(graphics.height);
  94. // Relayout stats bar
  95. Font@ font = cache.GetResource("Font", "Fonts/Anonymous Pro.ttf");
  96. if (graphics.width >= 1200)
  97. {
  98. SetupStatsBarText(editorModeText, font, 35, 64, HA_LEFT, VA_TOP);
  99. SetupStatsBarText(renderStatsText, font, -4, 64, HA_RIGHT, VA_TOP);
  100. }
  101. else
  102. {
  103. SetupStatsBarText(editorModeText, font, 35, 64, HA_LEFT, VA_TOP);
  104. SetupStatsBarText(renderStatsText, font, 35, 78, HA_LEFT, VA_TOP);
  105. }
  106. // Relayout windows
  107. Array<UIElement@> children = ui.root.GetChildren();
  108. for (uint i = 0; i < children.length; ++i)
  109. {
  110. if (children[i].type == WINDOW_TYPE)
  111. AdjustPosition(children[i]);
  112. }
  113. // Relayout root UI element
  114. editorUIElement.SetSize(graphics.width, graphics.height);
  115. // Set new viewport area and reset the viewport layout
  116. viewportArea = IntRect(0, 0, graphics.width, graphics.height);
  117. SetViewportMode(viewportMode);
  118. }
  119. void AdjustPosition(Window@ window)
  120. {
  121. IntVector2 position = window.position;
  122. IntVector2 size = window.size;
  123. IntVector2 extend = position + size;
  124. if (extend.x > graphics.width)
  125. position.x = Max(10, graphics.width - size.x - 10);
  126. if (extend.y > graphics.height)
  127. position.y = Max(100, graphics.height - size.y - 10);
  128. window.position = position;
  129. }
  130. void CreateCursor()
  131. {
  132. Cursor@ cursor = Cursor("Cursor");
  133. cursor.SetStyleAuto(uiStyle);
  134. cursor.SetPosition(graphics.width / 2, graphics.height / 2);
  135. ui.cursor = cursor;
  136. if (GetPlatform() == "Android" || GetPlatform() == "iOS")
  137. ui.cursor.visible = false;
  138. }
  139. // AngelScript does not support closures (yet), but funcdef should do just fine as a workaround for a few cases here for now
  140. funcdef bool MENU_CALLBACK();
  141. Array<MENU_CALLBACK@> menuCallbacks;
  142. MENU_CALLBACK@ messageBoxCallback;
  143. void HandleQuickSearchChange(StringHash eventType, VariantMap& eventData)
  144. {
  145. LineEdit@ search = eventData["Element"].GetPtr();
  146. if (search is null)
  147. return;
  148. PerformQuickMenuSearch(search.text.ToLower().Trimmed());
  149. }
  150. void PerformQuickMenuSearch(const String&in query)
  151. {
  152. Menu@ menu = quickMenu.GetChild("ResultsMenu", true);
  153. if (menu is null)
  154. return;
  155. menu.RemoveAllChildren();
  156. uint limit = 0;
  157. if (query.length > 0)
  158. {
  159. int lastIndex = 0;
  160. uint score = 0;
  161. int index = 0;
  162. Array<QuickMenuItem@> filtered;
  163. {
  164. QuickMenuItem@ qi;
  165. for (uint x=0; x < quickMenuItems.length; x++)
  166. {
  167. @qi = quickMenuItems[x];
  168. int find = qi.action.Find(query, 0, false);
  169. if (find > -1)
  170. {
  171. qi.sortScore = find;
  172. filtered.Push(qi);
  173. }
  174. }
  175. }
  176. filtered.Sort();
  177. {
  178. QuickMenuItem@ qi;
  179. limit = filtered.length > MAX_QUICK_MENU_ITEMS ? MAX_QUICK_MENU_ITEMS : filtered.length;
  180. for (uint x=0; x < limit; x++)
  181. {
  182. @qi = filtered[x];
  183. Menu@ item = CreateMenuItem(qi.action, qi.callback);
  184. item.SetMaxSize(1000,16);
  185. menu.AddChild(item);
  186. }
  187. }
  188. }
  189. menu.visible = limit > 0;
  190. menu.SetFixedHeight(limit * 16);
  191. quickMenu.BringToFront();
  192. quickMenu.SetFixedHeight(limit*16 + 62 + (menu.visible ? 6 : 0));
  193. }
  194. class QuickMenuItem
  195. {
  196. String action;
  197. MENU_CALLBACK@ callback;
  198. uint sortScore = 0;
  199. QuickMenuItem(){}
  200. QuickMenuItem(String action, MENU_CALLBACK@ callback)
  201. {
  202. this.action = action;
  203. this.callback = callback;
  204. }
  205. int opCmp(QuickMenuItem@ b)
  206. {
  207. return sortScore - b.sortScore;
  208. }
  209. }
  210. /// Create popup search menu.
  211. void CreateQuickMenu()
  212. {
  213. if (quickMenu !is null)
  214. return;
  215. quickMenu = LoadEditorUI("UI/EditorQuickMenu.xml");
  216. quickMenu.enabled = false;
  217. quickMenu.visible = false;
  218. quickMenu.opacity = uiMaxOpacity;
  219. // Handle a dummy search in the quick menu to finalize its initial size to empty
  220. PerformQuickMenuSearch("");
  221. ui.root.AddChild(quickMenu);
  222. LineEdit@ search = quickMenu.GetChild("Search", true);
  223. SubscribeToEvent(search, "TextChanged", "HandleQuickSearchChange");
  224. UIElement@ closeButton = quickMenu.GetChild("CloseButton", true);
  225. SubscribeToEvent(closeButton, "Pressed", "ToggleQuickMenu");
  226. }
  227. void ToggleQuickMenu()
  228. {
  229. quickMenu.enabled = !quickMenu.enabled && ui.cursor.visible;
  230. quickMenu.visible = quickMenu.enabled;
  231. if (quickMenu.enabled)
  232. {
  233. quickMenu.position = ui.cursorPosition - IntVector2(20,70);
  234. LineEdit@ search = quickMenu.GetChild("Search", true);
  235. search.text = "";
  236. search.focus = true;
  237. }
  238. }
  239. /// Create top menu bar.
  240. void CreateMenuBar()
  241. {
  242. uiMenuBar = BorderImage("MenuBar");
  243. ui.root.AddChild(uiMenuBar);
  244. uiMenuBar.enabled = true;
  245. uiMenuBar.style = "EditorMenuBar";
  246. uiMenuBar.SetLayout(LM_HORIZONTAL);
  247. uiMenuBar.opacity = uiMaxOpacity;
  248. uiMenuBar.SetFixedWidth(graphics.width);
  249. {
  250. Menu@ menu = CreateMenu("File");
  251. Window@ popup = menu.popup;
  252. popup.AddChild(CreateMenuItem("New scene", @ResetScene, 'N', QUAL_SHIFT | QUAL_CTRL));
  253. popup.AddChild(CreateMenuItem("Open scene...", @PickFile, 'O', QUAL_CTRL));
  254. popup.AddChild(CreateMenuItem("Save scene", @SaveSceneWithExistingName, 'S', QUAL_CTRL));
  255. popup.AddChild(CreateMenuItem("Save scene as...", @PickFile, 'S', QUAL_SHIFT | QUAL_CTRL));
  256. recentSceneMenu = CreateMenuItem("Open recent scene", null, SHOW_POPUP_INDICATOR);
  257. popup.AddChild(recentSceneMenu);
  258. mruScenesPopup = CreatePopup(recentSceneMenu);
  259. PopulateMruScenes();
  260. CreateChildDivider(popup);
  261. Menu@ childMenu = CreateMenuItem("Load node", null, SHOW_POPUP_INDICATOR);
  262. Window@ childPopup = CreatePopup(childMenu);
  263. childPopup.AddChild(CreateMenuItem("As replicated...", @PickFile, 0, 0, true, "Load node as replicated..."));
  264. childPopup.AddChild(CreateMenuItem("As local...", @PickFile, 0, 0, true, "Load node as local..."));
  265. popup.AddChild(childMenu);
  266. popup.AddChild(CreateMenuItem("Save node as...", @PickFile));
  267. CreateChildDivider(popup);
  268. popup.AddChild(CreateMenuItem("Import model...", @PickFile));
  269. popup.AddChild(CreateMenuItem("Import scene...", @PickFile));
  270. CreateChildDivider(popup);
  271. popup.AddChild(CreateMenuItem("Run script...", @PickFile));
  272. popup.AddChild(CreateMenuItem("Set resource path...", @PickFile));
  273. CreateChildDivider(popup);
  274. popup.AddChild(CreateMenuItem("Exit", @Exit));
  275. FinalizedPopupMenu(popup);
  276. uiMenuBar.AddChild(menu);
  277. }
  278. {
  279. Menu@ menu = CreateMenu("Edit");
  280. Window@ popup = menu.popup;
  281. popup.AddChild(CreateMenuItem("Undo", @Undo, 'Z', QUAL_CTRL));
  282. popup.AddChild(CreateMenuItem("Redo", @Redo, 'Y', QUAL_CTRL));
  283. CreateChildDivider(popup);
  284. popup.AddChild(CreateMenuItem("Cut", @Cut, 'X', QUAL_CTRL));
  285. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  286. popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, 'D', QUAL_CTRL));
  287. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  288. popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, 'D', QUAL_SHIFT ));
  289. popup.AddChild(CreateMenuItem("Copy", @Copy, 'C', QUAL_CTRL));
  290. popup.AddChild(CreateMenuItem("Paste", @Paste, 'V', QUAL_CTRL));
  291. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  292. popup.AddChild(CreateMenuItem("Delete", @Delete, KEY_DELETE, QUAL_ANY));
  293. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  294. popup.AddChild(CreateMenuItem("Delete", @Delete, 'X', QUAL_ANY));
  295. popup.AddChild(CreateMenuItem("Select all", @SelectAll, 'A', QUAL_CTRL));
  296. popup.AddChild(CreateMenuItem("Deselect all", @DeselectAll, 'A', QUAL_SHIFT | QUAL_CTRL));
  297. CreateChildDivider(popup);
  298. popup.AddChild(CreateMenuItem("Reset to default", @ResetToDefault));
  299. CreateChildDivider(popup);
  300. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  301. {
  302. popup.AddChild(CreateMenuItem("Reset position", @SceneResetPosition));
  303. popup.AddChild(CreateMenuItem("Reset rotation", @SceneResetRotation));
  304. popup.AddChild(CreateMenuItem("Reset scale", @SceneResetScale));
  305. }
  306. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  307. {
  308. popup.AddChild(CreateMenuItem("Reset position", @SceneResetPosition, 'G' , QUAL_ALT));
  309. popup.AddChild(CreateMenuItem("Reset rotation", @SceneResetRotation, 'R', QUAL_ALT ));
  310. popup.AddChild(CreateMenuItem("Reset scale", @SceneResetScale, 'S', QUAL_ALT));
  311. }
  312. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  313. {
  314. popup.AddChild(CreateMenuItem("Enable/disable", @SceneToggleEnable, 'E', QUAL_CTRL));
  315. popup.AddChild(CreateMenuItem("Enable all", @SceneEnableAllNodes, 'E', QUAL_ALT));
  316. }
  317. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  318. {
  319. popup.AddChild(CreateMenuItem("Enable/disable", @SceneToggleEnable, 'H'));
  320. popup.AddChild(CreateMenuItem("Enable all", @SceneEnableAllNodes, 'H', QUAL_ALT));
  321. }
  322. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  323. popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, 'U', QUAL_CTRL));
  324. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  325. popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, 'P', QUAL_ALT));
  326. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  327. popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, 'U'));
  328. else if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  329. popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, 'P', QUAL_CTRL));
  330. CreateChildDivider(popup);
  331. if ( hotKeyMode == HOTKEYS_MODE_STANDARD )
  332. popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
  333. //else if ( hotKeyMode == HOT_KEYS_MODE_BLENDER )
  334. // popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, 'P', QUAL_CTRL));
  335. if ( hotKeyMode == HOTKEYS_MODE_BLENDER )
  336. popup.AddChild(CreateMenuItem("Move to layer", @ShowLayerMover, 'M'));
  337. popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
  338. CreateChildDivider(popup);
  339. popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));
  340. popup.AddChild(CreateMenuItem("Add children to SM-group", @SceneAddChildrenStaticModelGroup));
  341. Menu@ childMenu = CreateMenuItem("Set children as spline path", null, SHOW_POPUP_INDICATOR);
  342. Window@ childPopup = CreatePopup(childMenu);
  343. childPopup.AddChild(CreateMenuItem("Non-cyclic", @SetSplinePath, 0, 0, true, "Set non-cyclic spline path"));
  344. childPopup.AddChild(CreateMenuItem("Cyclic", @SetSplinePath, 0, 0, true, "Set cyclic spline path"));
  345. popup.AddChild(childMenu);
  346. FinalizedPopupMenu(popup);
  347. uiMenuBar.AddChild(menu);
  348. }
  349. {
  350. Menu@ menu = CreateMenu("Create");
  351. Window@ popup = menu.popup;
  352. popup.AddChild(CreateMenuItem("Replicated node", @PickNode, 0, 0, true, "Create Replicated node"));
  353. popup.AddChild(CreateMenuItem("Local node", @PickNode, 0, 0, true, "Create Local node"));
  354. CreateChildDivider(popup);
  355. Menu@ childMenu = CreateMenuItem("Component", null, SHOW_POPUP_INDICATOR);
  356. Window@ childPopup = CreatePopup(childMenu);
  357. String[] objectCategories = GetObjectCategories();
  358. for (uint i = 0; i < objectCategories.length; ++i)
  359. {
  360. // Skip the UI category for the component menus
  361. if (objectCategories[i] == "UI")
  362. continue;
  363. Menu@ menu = CreateMenuItem(objectCategories[i], null, SHOW_POPUP_INDICATOR);
  364. Window@ popup = CreatePopup(menu);
  365. String[] componentTypes = GetObjectsByCategory(objectCategories[i]);
  366. for (uint j = 0; j < componentTypes.length; ++j)
  367. popup.AddChild(CreateIconizedMenuItem(componentTypes[j], @PickComponent, 0, 0, "", true, "Create " + componentTypes[j]));
  368. childPopup.AddChild(menu);
  369. }
  370. FinalizedPopupMenu(childPopup);
  371. popup.AddChild(childMenu);
  372. childMenu = CreateMenuItem("Builtin object", null, SHOW_POPUP_INDICATOR);
  373. childPopup = CreatePopup(childMenu);
  374. String[] objects = { "Box", "Cone", "Cylinder", "Plane", "Pyramid", "Sphere", "TeaPot", "Torus" };
  375. for (uint i = 0; i < objects.length; ++i)
  376. childPopup.AddChild(CreateIconizedMenuItem(objects[i], @PickBuiltinObject, 0, 0, "Node", true, "Create " + objects[i]));
  377. popup.AddChild(childMenu);
  378. CreateChildDivider(popup);
  379. childMenu = CreateMenuItem("UI-element", null, SHOW_POPUP_INDICATOR);
  380. childPopup = CreatePopup(childMenu);
  381. String[] uiElementTypes = GetObjectsByCategory("UI");
  382. for (uint i = 0; i < uiElementTypes.length; ++i)
  383. {
  384. if (uiElementTypes[i] != "UIElement")
  385. childPopup.AddChild(CreateIconizedMenuItem(uiElementTypes[i], @PickUIElement, 0, 0, "", true, "Create " + uiElementTypes[i]));
  386. }
  387. CreateChildDivider(childPopup);
  388. childPopup.AddChild(CreateIconizedMenuItem("UIElement", @PickUIElement));
  389. popup.AddChild(childMenu);
  390. FinalizedPopupMenu(popup);
  391. uiMenuBar.AddChild(menu);
  392. }
  393. {
  394. Menu@ menu = CreateMenu("UI-layout");
  395. Window@ popup = menu.popup;
  396. popup.AddChild(CreateMenuItem("Open UI-layout...", @PickFile, 'O', QUAL_ALT));
  397. popup.AddChild(CreateMenuItem("Save UI-layout", @SaveUILayoutWithExistingName, 'S', QUAL_ALT));
  398. popup.AddChild(CreateMenuItem("Save UI-layout as...", @PickFile));
  399. CreateChildDivider(popup);
  400. popup.AddChild(CreateMenuItem("Close UI-layout", @CloseUILayout, 'C', QUAL_ALT));
  401. popup.AddChild(CreateMenuItem("Close all UI-layouts", @CloseAllUILayouts));
  402. CreateChildDivider(popup);
  403. popup.AddChild(CreateMenuItem("Load child element...", @PickFile));
  404. popup.AddChild(CreateMenuItem("Save child element as...", @PickFile));
  405. CreateChildDivider(popup);
  406. popup.AddChild(CreateMenuItem("Set default style...", @PickFile));
  407. FinalizedPopupMenu(popup);
  408. uiMenuBar.AddChild(menu);
  409. }
  410. {
  411. Menu@ menu = CreateMenu("View");
  412. Window@ popup = menu.popup;
  413. popup.AddChild(CreateMenuItem("Hierarchy", @ShowHierarchyWindow, 'H', QUAL_CTRL));
  414. popup.AddChild(CreateMenuItem("Attribute inspector", @ShowAttributeInspectorWindow, 'I', QUAL_CTRL));
  415. popup.AddChild(CreateMenuItem("Resource browser", @ShowResourceBrowserWindow, 'B', QUAL_CTRL));
  416. popup.AddChild(CreateMenuItem("Material editor", @ShowMaterialEditor));
  417. popup.AddChild(CreateMenuItem("Particle editor", @ShowParticleEffectEditor));
  418. popup.AddChild(CreateMenuItem("Spawn editor", @ShowSpawnEditor));
  419. popup.AddChild(CreateMenuItem("Sound Type editor", @ShowSoundTypeEditor));
  420. popup.AddChild(CreateMenuItem("Editor settings", @ShowEditorSettingsDialog));
  421. popup.AddChild(CreateMenuItem("Editor preferences", @ShowEditorPreferencesDialog));
  422. CreateChildDivider(popup);
  423. popup.AddChild(CreateMenuItem("Hide editor", @ToggleUI, KEY_F12, QUAL_ANY));
  424. FinalizedPopupMenu(popup);
  425. uiMenuBar.AddChild(menu);
  426. }
  427. BorderImage@ spacer = BorderImage("MenuBarSpacer");
  428. uiMenuBar.AddChild(spacer);
  429. spacer.style = "EditorMenuBar";
  430. BorderImage@ logo = BorderImage("Logo");
  431. logo.texture = cache.GetResource("Texture2D", "Textures/Logo.png");
  432. logo.SetFixedWidth(64);
  433. uiMenuBar.AddChild(logo);
  434. }
  435. bool Exit()
  436. {
  437. ui.cursor.shape = CS_BUSY;
  438. if (messageBoxCallback is null)
  439. {
  440. String message;
  441. if (sceneModified)
  442. message = "Scene has been modified.\n";
  443. bool uiLayoutModified = false;
  444. for (uint i = 0; i < editorUIElement.numChildren; ++i)
  445. {
  446. UIElement@ element = editorUIElement.children[i];
  447. if (element !is null && element.vars[MODIFIED_VAR].GetBool())
  448. {
  449. uiLayoutModified = true;
  450. message += "UI layout has been modified.\n";
  451. break;
  452. }
  453. }
  454. if (sceneModified || uiLayoutModified)
  455. {
  456. MessageBox@ messageBox = MessageBox(message + "Continue to exit?", "Warning");
  457. if (messageBox.window !is null)
  458. {
  459. Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
  460. cancelButton.visible = true;
  461. cancelButton.focus = true;
  462. SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
  463. messageBoxCallback = @Exit;
  464. return false;
  465. }
  466. }
  467. }
  468. else
  469. messageBoxCallback = null;
  470. engine.Exit();
  471. return true;
  472. }
  473. void HandleExitRequested()
  474. {
  475. if (!ui.HasModalElement())
  476. Exit();
  477. }
  478. bool PickFile()
  479. {
  480. Menu@ menu = GetEventSender();
  481. if (menu is null)
  482. return false;
  483. String action = menu.name;
  484. if (action.empty)
  485. return false;
  486. // File (Scene related)
  487. if (action == "Open scene...")
  488. {
  489. CreateFileSelector("Open scene", "Open", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
  490. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleOpenSceneFile");
  491. }
  492. else if (action == "Save scene as..." || action == "Save scene")
  493. {
  494. CreateFileSelector("Save scene as", "Save", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
  495. uiFileSelector.fileName = GetFileNameAndExtension(editorScene.fileName);
  496. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveSceneFile");
  497. }
  498. else if (action == "As replicated..." || action == "Load node as replicated...")
  499. {
  500. instantiateMode = REPLICATED;
  501. CreateFileSelector("Load node", "Load", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  502. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadNodeFile");
  503. }
  504. else if (action == "As local..." || action == "Load node as local...")
  505. {
  506. instantiateMode = LOCAL;
  507. CreateFileSelector("Load node", "Load", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  508. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadNodeFile");
  509. }
  510. else if (action == "Save node as...")
  511. {
  512. if (editNode !is null && editNode !is editorScene)
  513. {
  514. CreateFileSelector("Save node", "Save", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  515. uiFileSelector.fileName = GetFileNameAndExtension(instantiateFileName);
  516. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveNodeFile");
  517. }
  518. }
  519. else if (action == "Import model...")
  520. {
  521. CreateFileSelector("Import model", "Import", "Cancel", uiImportPath, uiAllFilters, uiImportFilter);
  522. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleImportModel");
  523. }
  524. else if (action == "Import scene...")
  525. {
  526. CreateFileSelector("Import scene", "Import", "Cancel", uiImportPath, uiAllFilters, uiImportFilter);
  527. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleImportScene");
  528. }
  529. else if (action == "Run script...")
  530. {
  531. CreateFileSelector("Run script", "Run", "Cancel", uiScriptPath, uiScriptFilters, uiScriptFilter);
  532. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleRunScript");
  533. }
  534. else if (action == "Set resource path...")
  535. {
  536. CreateFileSelector("Set resource path", "Set", "Cancel", sceneResourcePath, uiAllFilters, 0);
  537. uiFileSelector.directoryMode = true;
  538. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleResourcePath");
  539. }
  540. // UI-element
  541. else if (action == "Open UI-layout...")
  542. {
  543. CreateFileSelector("Open UI-layout", "Open", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  544. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleOpenUILayoutFile");
  545. }
  546. else if (action == "Save UI-layout as..." || action == "Save UI-layout")
  547. {
  548. if (editUIElement !is null)
  549. {
  550. UIElement@ element = GetTopLevelUIElement(editUIElement);
  551. if (element is null)
  552. return false;
  553. CreateFileSelector("Save UI-layout as", "Save", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  554. uiFileSelector.fileName = GetFileNameAndExtension(element.GetVar(FILENAME_VAR).GetString());
  555. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveUILayoutFile");
  556. }
  557. }
  558. else if (action == "Load child element...")
  559. {
  560. if (editUIElement !is null)
  561. {
  562. CreateFileSelector("Load child element", "Load", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  563. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadChildUIElementFile");
  564. }
  565. }
  566. else if (action == "Save child element as...")
  567. {
  568. if (editUIElement !is null)
  569. {
  570. CreateFileSelector("Save child element", "Save", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  571. uiFileSelector.fileName = GetFileNameAndExtension(editUIElement.GetVar(CHILD_ELEMENT_FILENAME_VAR).GetString());
  572. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveChildUIElementFile");
  573. }
  574. }
  575. else if (action == "Set default style...")
  576. {
  577. CreateFileSelector("Set default style", "Set", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  578. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleUIElementDefaultStyle");
  579. }
  580. return true;
  581. }
  582. bool PickNode()
  583. {
  584. Menu@ menu = GetEventSender();
  585. if (menu is null)
  586. return false;
  587. String action = GetActionName(menu.name);
  588. if (action.empty)
  589. return false;
  590. CreateNode(action == "Replicated node" ? REPLICATED : LOCAL);
  591. return true;
  592. }
  593. bool PickComponent()
  594. {
  595. if (editNodes.empty)
  596. return false;
  597. Menu@ menu = GetEventSender();
  598. if (menu is null)
  599. return false;
  600. String action = GetActionName(menu.name);
  601. if (action.empty)
  602. return false;
  603. CreateComponent(action);
  604. return true;
  605. }
  606. bool PickBuiltinObject()
  607. {
  608. Menu@ menu = GetEventSender();
  609. if (menu is null)
  610. return false;
  611. String action = GetActionName(menu.name);
  612. if (action.empty)
  613. return false;
  614. CreateBuiltinObject(action);
  615. return true;
  616. }
  617. bool PickUIElement()
  618. {
  619. Menu@ menu = GetEventSender();
  620. if (menu is null)
  621. return false;
  622. String action = GetActionName(menu.name);
  623. if (action.empty)
  624. return false;
  625. return NewUIElement(action);
  626. }
  627. // When calling items from the quick menu, they have "Create" prepended for clarity. Strip that now to get the object name to create
  628. String GetActionName(const String&in name)
  629. {
  630. if (name.StartsWith("Create"))
  631. return name.Substring(7);
  632. else
  633. return name;
  634. }
  635. void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
  636. {
  637. Menu@ menu = eventData["Element"].GetPtr();
  638. if (menu is null)
  639. return;
  640. HandlePopup(menu);
  641. quickMenu.visible = false;
  642. quickMenu.enabled = false;
  643. // Execute the callback if available
  644. Variant variant = menu.GetVar(CALLBACK_VAR);
  645. if (!variant.empty)
  646. menuCallbacks[variant.GetUInt()]();
  647. }
  648. Menu@ CreateMenuItem(const String&in title, MENU_CALLBACK@ callback = null, int accelKey = 0, int accelQual = 0, bool addToQuickMenu = true, String quickMenuText="")
  649. {
  650. Menu@ menu = Menu(title);
  651. menu.defaultStyle = uiStyle;
  652. menu.style = AUTO_STYLE;
  653. menu.SetLayout(LM_HORIZONTAL, 0, IntRect(8, 2, 8, 2));
  654. if (accelKey > 0)
  655. menu.SetAccelerator(accelKey, accelQual);
  656. if (callback !is null)
  657. {
  658. menu.vars[CALLBACK_VAR] = menuCallbacks.length;
  659. menuCallbacks.Push(callback);
  660. }
  661. Text@ menuText = Text();
  662. menu.AddChild(menuText);
  663. menuText.style = "EditorMenuText";
  664. menuText.text = title;
  665. if (addToQuickMenu)
  666. AddQuickMenuItem(callback, quickMenuText.empty ? title : quickMenuText);
  667. if (accelKey != 0)
  668. {
  669. UIElement@ spacer = UIElement();
  670. spacer.minWidth = menuText.indentSpacing;
  671. spacer.height = menuText.height;
  672. menu.AddChild(spacer);
  673. menu.AddChild(CreateAccelKeyText(accelKey, accelQual));
  674. }
  675. return menu;
  676. }
  677. void AddQuickMenuItem(MENU_CALLBACK@ callback, String text)
  678. {
  679. if (callback is null)
  680. return;
  681. bool exists = false;
  682. for (uint i=0;i<quickMenuItems.length;++i)
  683. {
  684. if (quickMenuItems[i].action == text)
  685. {
  686. exists = true;
  687. break;
  688. }
  689. }
  690. if (!exists)
  691. quickMenuItems.Push(QuickMenuItem(text, callback));
  692. }
  693. Menu@ CreateIconizedMenuItem(const String&in title, MENU_CALLBACK@ callback = null, int accelKey = 0, int accelQual = 0, const String&in iconType = "", bool addToQuickMenu=true, String quickMenuText="")
  694. {
  695. Menu@ menu = Menu(title);
  696. menu.defaultStyle = uiStyle;
  697. menu.style = AUTO_STYLE;
  698. menu.SetLayout(LM_VERTICAL, 0, IntRect(8, 2, 8, 2));
  699. if (accelKey > 0)
  700. menu.SetAccelerator(accelKey, accelQual);
  701. if (callback !is null)
  702. {
  703. menu.vars[CALLBACK_VAR] = menuCallbacks.length;
  704. menuCallbacks.Push(callback);
  705. }
  706. Text@ menuText = Text();
  707. menu.AddChild(menuText);
  708. menuText.style = "EditorMenuText";
  709. menuText.text = title;
  710. // If icon type is not provided, use the title instead
  711. IconizeUIElement(menuText, iconType.empty ? title : iconType);
  712. if (addToQuickMenu)
  713. AddQuickMenuItem(callback, quickMenuText.empty ? title : quickMenuText);
  714. if (accelKey != 0)
  715. {
  716. menuText.layoutMode = LM_HORIZONTAL;
  717. menuText.AddChild(CreateAccelKeyText(accelKey, accelQual));
  718. }
  719. return menu;
  720. }
  721. /// Create a child divider in parent with vertical layout mode. It works on other parent element as well, not just parent menu.
  722. void CreateChildDivider(UIElement@ parent)
  723. {
  724. BorderImage@ divider = parent.CreateChild("BorderImage", "Divider");
  725. divider.style = "EditorDivider";
  726. }
  727. Window@ CreatePopup(Menu@ baseMenu)
  728. {
  729. Window@ popup = Window();
  730. popup.defaultStyle = uiStyle;
  731. popup.style = AUTO_STYLE;
  732. popup.SetLayout(LM_VERTICAL, 1, IntRect(2, 6, 2, 6));
  733. baseMenu.popup = popup;
  734. baseMenu.popupOffset = IntVector2(0, baseMenu.height);
  735. return popup;
  736. }
  737. Menu@ CreateMenu(const String&in title)
  738. {
  739. Menu@ menu = CreateMenuItem(title);
  740. menu.SetFixedWidth(menu.width);
  741. CreatePopup(menu);
  742. return menu;
  743. }
  744. Text@ CreateAccelKeyText(int accelKey, int accelQual)
  745. {
  746. Text@ accelKeyText = Text();
  747. accelKeyText.defaultStyle = uiStyle;
  748. accelKeyText.style = "EditorMenuText";
  749. accelKeyText.textAlignment = HA_RIGHT;
  750. String text;
  751. if (accelKey == KEY_DELETE)
  752. text = "Del";
  753. else if (accelKey == KEY_SPACE)
  754. text = "Space";
  755. // Cannot use range as the key constants below do not appear to be in sequence
  756. else if (accelKey == KEY_F1)
  757. text = "F1";
  758. else if (accelKey == KEY_F2)
  759. text = "F2";
  760. else if (accelKey == KEY_F3)
  761. text = "F3";
  762. else if (accelKey == KEY_F4)
  763. text = "F4";
  764. else if (accelKey == KEY_F5)
  765. text = "F5";
  766. else if (accelKey == KEY_F6)
  767. text = "F6";
  768. else if (accelKey == KEY_F7)
  769. text = "F7";
  770. else if (accelKey == KEY_F8)
  771. text = "F8";
  772. else if (accelKey == KEY_F9)
  773. text = "F9";
  774. else if (accelKey == KEY_F10)
  775. text = "F10";
  776. else if (accelKey == KEY_F11)
  777. text = "F11";
  778. else if (accelKey == KEY_F12)
  779. text = "F12";
  780. else if (accelKey == SHOW_POPUP_INDICATOR)
  781. text = ">";
  782. else
  783. text.AppendUTF8(accelKey);
  784. if (accelQual & QUAL_ALT > 0)
  785. text = "Alt+" + text;
  786. if (accelQual & QUAL_SHIFT > 0)
  787. text = "Shift+" + text;
  788. if (accelQual & QUAL_CTRL > 0)
  789. text = "Ctrl+" + text;
  790. accelKeyText.text = text;
  791. return accelKeyText;
  792. }
  793. void FinalizedPopupMenu(Window@ popup)
  794. {
  795. // Find the maximum menu text width
  796. Array<UIElement@> children = popup.GetChildren();
  797. int maxWidth = 0;
  798. for (uint i = 0; i < children.length; ++i)
  799. {
  800. UIElement@ element = children[i];
  801. if (element.type != MENU_TYPE) // Skip if not menu item
  802. continue;
  803. int width = element.children[0].width;
  804. if (width > maxWidth)
  805. maxWidth = width;
  806. }
  807. // Adjust the indent spacing to slightly wider than the maximum width
  808. maxWidth += 20;
  809. for (uint i = 0; i < children.length; ++i)
  810. {
  811. UIElement@ element = children[i];
  812. if (element.type != MENU_TYPE)
  813. continue;
  814. Menu@ menu = element;
  815. Text@ menuText = menu.children[0];
  816. if (menuText.numChildren == 1) // Skip if menu text does not have accel
  817. menuText.children[0].indentSpacing = maxWidth;
  818. // Adjust the popup offset taking the indentation into effect
  819. if (menu.popup !is null)
  820. menu.popupOffset = IntVector2(menu.width, 0);
  821. }
  822. }
  823. void CreateFileSelector(const String&in title, const String&in ok, const String&in cancel, const String&in initialPath, Array<String>@ filters,
  824. uint initialFilter)
  825. {
  826. // Within the editor UI, the file selector is a kind of a "singleton". When the previous one is overwritten, also
  827. // the events subscribed from it are disconnected, so new ones are safe to subscribe.
  828. uiFileSelector = FileSelector();
  829. uiFileSelector.defaultStyle = uiStyle;
  830. uiFileSelector.title = title;
  831. uiFileSelector.path = initialPath;
  832. uiFileSelector.SetButtonTexts(ok, cancel);
  833. uiFileSelector.SetFilters(filters, initialFilter);
  834. CenterDialog(uiFileSelector.window);
  835. }
  836. void CloseFileSelector(uint&out filterIndex, String&out path)
  837. {
  838. // Save filter & path for next time
  839. filterIndex = uiFileSelector.filterIndex;
  840. path = uiFileSelector.path;
  841. uiFileSelector = null;
  842. }
  843. void CloseFileSelector()
  844. {
  845. uiFileSelector = null;
  846. }
  847. void CreateConsole()
  848. {
  849. Console@ console = engine.CreateConsole();
  850. console.defaultStyle = uiStyle;
  851. console.commandInterpreter = consoleCommandInterpreter;
  852. console.numBufferedRows = 100;
  853. console.autoVisibleOnError = true;
  854. }
  855. void CreateDebugHud()
  856. {
  857. engine.CreateDebugHud();
  858. debugHud.defaultStyle = uiStyle;
  859. debugHud.mode = DEBUGHUD_SHOW_NONE;
  860. }
  861. void CenterDialog(UIElement@ element)
  862. {
  863. IntVector2 size = element.size;
  864. element.SetPosition((graphics.width - size.x) / 2, (graphics.height - size.y) / 2);
  865. }
  866. void CreateContextMenu()
  867. {
  868. contextMenu = LoadEditorUI("UI/EditorContextMenu.xml");
  869. ui.root.AddChild(contextMenu);
  870. }
  871. void UpdateWindowTitle()
  872. {
  873. String sceneName = GetFileNameAndExtension(editorScene.fileName);
  874. if (sceneName.empty || sceneName == TEMP_SCENE_NAME)
  875. sceneName = "Untitled";
  876. if (sceneModified)
  877. sceneName += "*";
  878. graphics.windowTitle = "Urho3D editor - " + sceneName;
  879. }
  880. void HandlePopup(Menu@ menu)
  881. {
  882. // Close the top level menu now unless the selected menu item has another popup
  883. if (menu.popup !is null)
  884. return;
  885. for (;;)
  886. {
  887. UIElement@ menuParent = menu.parent;
  888. if (menuParent is null)
  889. break;
  890. Menu@ nextMenu = menuParent.vars["Origin"].GetPtr();
  891. if (nextMenu is null)
  892. break;
  893. else
  894. menu = nextMenu;
  895. }
  896. if (menu.parent is uiMenuBar)
  897. menu.showPopup = false;
  898. }
  899. String ExtractFileName(VariantMap& eventData, bool forSave = false)
  900. {
  901. String fileName;
  902. // Check for OK
  903. if (eventData["OK"].GetBool())
  904. {
  905. String filter = eventData["Filter"].GetString();
  906. fileName = eventData["FileName"].GetString();
  907. // Add default extension for saving if not specified
  908. if (GetExtension(fileName).empty && forSave && filter != "*.*")
  909. fileName = fileName + filter.Substring(1);
  910. }
  911. return fileName;
  912. }
  913. void HandleOpenSceneFile(StringHash eventType, VariantMap& eventData)
  914. {
  915. CloseFileSelector(uiSceneFilter, uiScenePath);
  916. LoadScene(ExtractFileName(eventData));
  917. }
  918. void HandleSaveSceneFile(StringHash eventType, VariantMap& eventData)
  919. {
  920. CloseFileSelector(uiSceneFilter, uiScenePath);
  921. SaveScene(ExtractFileName(eventData, true));
  922. }
  923. void HandleLoadNodeFile(StringHash eventType, VariantMap& eventData)
  924. {
  925. CloseFileSelector(uiNodeFilter, uiNodePath);
  926. LoadNode(ExtractFileName(eventData));
  927. }
  928. void HandleSaveNodeFile(StringHash eventType, VariantMap& eventData)
  929. {
  930. CloseFileSelector(uiNodeFilter, uiNodePath);
  931. SaveNode(ExtractFileName(eventData, true));
  932. }
  933. void HandleImportModel(StringHash eventType, VariantMap& eventData)
  934. {
  935. CloseFileSelector(uiImportFilter, uiImportPath);
  936. ImportModel(ExtractFileName(eventData));
  937. }
  938. void HandleImportScene(StringHash eventType, VariantMap& eventData)
  939. {
  940. CloseFileSelector(uiImportFilter, uiImportPath);
  941. ImportScene(ExtractFileName(eventData));
  942. }
  943. void ExecuteScript(const String&in fileName)
  944. {
  945. if (fileName.empty)
  946. return;
  947. File@ file = File(fileName, FILE_READ);
  948. if (file.open)
  949. {
  950. String scriptCode;
  951. while (!file.eof)
  952. scriptCode += file.ReadLine() + "\n";
  953. file.Close();
  954. if (script.Execute(scriptCode))
  955. log.Info("Script " + fileName + " ran successfully");
  956. }
  957. }
  958. void HandleRunScript(StringHash eventType, VariantMap& eventData)
  959. {
  960. CloseFileSelector(uiScriptFilter, uiScriptPath);
  961. ExecuteScript(ExtractFileName(eventData));
  962. }
  963. void HandleResourcePath(StringHash eventType, VariantMap& eventData)
  964. {
  965. String pathName = uiFileSelector.path;
  966. CloseFileSelector();
  967. if (eventData["OK"].GetBool())
  968. SetResourcePath(pathName, false);
  969. }
  970. void HandleOpenUILayoutFile(StringHash eventType, VariantMap& eventData)
  971. {
  972. CloseFileSelector(uiElementFilter, uiElementPath);
  973. OpenUILayout(ExtractFileName(eventData));
  974. }
  975. void HandleSaveUILayoutFile(StringHash eventType, VariantMap& eventData)
  976. {
  977. CloseFileSelector(uiElementFilter, uiElementPath);
  978. SaveUILayout(ExtractFileName(eventData, true));
  979. }
  980. void HandleLoadChildUIElementFile(StringHash eventType, VariantMap& eventData)
  981. {
  982. CloseFileSelector(uiElementFilter, uiElementPath);
  983. LoadChildUIElement(ExtractFileName(eventData));
  984. }
  985. void HandleSaveChildUIElementFile(StringHash eventType, VariantMap& eventData)
  986. {
  987. CloseFileSelector(uiElementFilter, uiElementPath);
  988. SaveChildUIElement(ExtractFileName(eventData, true));
  989. }
  990. void HandleUIElementDefaultStyle(StringHash eventType, VariantMap& eventData)
  991. {
  992. CloseFileSelector(uiElementFilter, uiElementPath);
  993. SetUIElementDefaultStyle(ExtractFileName(eventData));
  994. }
  995. void HandleHotKeysBlender( VariantMap& eventData )
  996. {
  997. int key = eventData["Key"].GetInt();
  998. int viewDirection = eventData["Qualifiers"].GetInt() == QUAL_CTRL ? -1 : 1;
  999. if (key == KEY_ESC)
  1000. {
  1001. if (uiHidden)
  1002. UnhideUI();
  1003. else if (console.visible)
  1004. console.visible = false;
  1005. else if (contextMenu.visible)
  1006. CloseContextMenu();
  1007. else if (quickMenu.visible)
  1008. {
  1009. quickMenu.visible = false;
  1010. quickMenu.enabled = false;
  1011. }
  1012. else
  1013. {
  1014. UIElement@ front = ui.frontElement;
  1015. if (front is settingsDialog || front is preferencesDialog)
  1016. {
  1017. ui.focusElement = null;
  1018. front.visible = false;
  1019. }
  1020. }
  1021. }
  1022. // Ignore other keys when UI has a modal element
  1023. else if (ui.HasModalElement())
  1024. return;
  1025. else if (key == KEY_F1)
  1026. console.Toggle();
  1027. else if (key == KEY_F2)
  1028. ToggleRenderingDebug();
  1029. else if (key == KEY_F3)
  1030. TogglePhysicsDebug();
  1031. else if (key == KEY_F4)
  1032. ToggleOctreeDebug();
  1033. else if (key == KEY_F11)
  1034. {
  1035. Image@ screenshot = Image();
  1036. graphics.TakeScreenShot(screenshot);
  1037. if (!fileSystem.DirExists(screenshotDir))
  1038. fileSystem.CreateDir(screenshotDir);
  1039. screenshot.SavePNG(screenshotDir + "/Screenshot_" +
  1040. time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
  1041. }
  1042. else if (key == KEY_KP_1 && ui.focusElement is null) // Front view
  1043. {
  1044. Vector3 center = Vector3(0,0,0);
  1045. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1046. center = SelectedNodesCenterPoint();
  1047. Vector3 pos = cameraNode.worldPosition - center;
  1048. cameraNode.worldPosition = center - Vector3(0.0, 0.0, pos.length * viewDirection);
  1049. cameraNode.direction = Vector3(0, 0, viewDirection);
  1050. ReacquireCameraYawPitch();
  1051. }
  1052. else if (key == KEY_KP_3 && ui.focusElement is null) // Side view
  1053. {
  1054. Vector3 center = Vector3(0,0,0);
  1055. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1056. center = SelectedNodesCenterPoint();
  1057. Vector3 pos = cameraNode.worldPosition - center;
  1058. cameraNode.worldPosition = center - Vector3(pos.length * -viewDirection, 0.0, 0.0);
  1059. cameraNode.direction = Vector3(-viewDirection, 0, 0);
  1060. ReacquireCameraYawPitch();
  1061. }
  1062. else if (key == KEY_KP_7 && ui.focusElement is null) // Top view
  1063. {
  1064. Vector3 center = Vector3(0,0,0);
  1065. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1066. center = SelectedNodesCenterPoint();
  1067. Vector3 pos = cameraNode.worldPosition - center;
  1068. cameraNode.worldPosition = center - Vector3(0.0, pos.length * -viewDirection, 0.0);
  1069. cameraNode.direction = Vector3(0, -viewDirection, 0);
  1070. ReacquireCameraYawPitch();
  1071. }
  1072. else if (key == KEY_KP_5 && ui.focusElement is null)
  1073. {
  1074. activeViewport.ToggleOrthographic();
  1075. }
  1076. else if (key == '4')
  1077. editMode = EDIT_SELECT;
  1078. else if (key == '5')
  1079. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1080. else if (key == '6')
  1081. {
  1082. --pickMode;
  1083. if (pickMode < PICK_GEOMETRIES)
  1084. pickMode = MAX_PICK_MODES - 1;
  1085. }
  1086. else if (key == '7')
  1087. {
  1088. ++pickMode;
  1089. if (pickMode >= MAX_PICK_MODES)
  1090. pickMode = PICK_GEOMETRIES;
  1091. }
  1092. else if (key == 'Z' && eventData["Qualifiers"].GetInt() != QUAL_CTRL)
  1093. {
  1094. fillMode = FillMode(fillMode + 1);
  1095. if (fillMode > FILL_POINT)
  1096. fillMode = FILL_SOLID;
  1097. // Update camera fill mode
  1098. SetFillMode(fillMode);
  1099. }
  1100. else if (key == KEY_SPACE)
  1101. {
  1102. if (ui.cursor.visible && ui.focusElement is null)
  1103. ToggleQuickMenu();
  1104. }
  1105. else
  1106. {
  1107. SteppedObjectManipulation(key);
  1108. }
  1109. if ((ui.focusElement is null) && (selectedNodes.length > 0) && !cameraFlyMode)
  1110. {
  1111. if (eventData["Qualifiers"].GetInt() == QUAL_ALT) // reset transformations
  1112. {
  1113. if (key == KEY_G)
  1114. SceneResetPosition();
  1115. else if (key == KEY_R)
  1116. SceneResetRotation();
  1117. else if (key == KEY_S)
  1118. SceneResetScale();
  1119. else if (key == KEY_F)
  1120. {
  1121. Vector3 center = Vector3(0,0,0);
  1122. if (selectedNodes.length > 0)
  1123. center = SelectedNodesCenterPoint();
  1124. cameraNode.LookAt(center);
  1125. ReacquireCameraYawPitch();
  1126. }
  1127. }
  1128. else if ( eventData["Qualifiers"].GetInt() != QUAL_CTRL) // set transformations
  1129. {
  1130. if (key == KEY_G)
  1131. {
  1132. editMode = EDIT_MOVE;
  1133. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1134. }
  1135. else if (key == KEY_R)
  1136. {
  1137. editMode = EDIT_ROTATE;
  1138. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1139. }
  1140. else if (key == KEY_S)
  1141. {
  1142. editMode = EDIT_SCALE;
  1143. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1144. }
  1145. else if (key == KEY_F)
  1146. {
  1147. Vector3 center = Vector3(0,0,0);
  1148. if (selectedNodes.length > 0)
  1149. center = SelectedNodesCenterPoint();
  1150. cameraNode.LookAt(center);
  1151. ReacquireCameraYawPitch();
  1152. }
  1153. }
  1154. }
  1155. toolBarDirty = true;
  1156. }
  1157. void HandleHotKeysStandart ( VariantMap& eventData)
  1158. {
  1159. int key = eventData["Key"].GetInt();
  1160. int viewDirection = eventData["Qualifiers"].GetInt() == QUAL_CTRL ? -1 : 1;
  1161. if (key == KEY_ESC)
  1162. {
  1163. if (uiHidden)
  1164. UnhideUI();
  1165. else if (console.visible)
  1166. console.visible = false;
  1167. else if (contextMenu.visible)
  1168. CloseContextMenu();
  1169. else if (quickMenu.visible)
  1170. {
  1171. quickMenu.visible = false;
  1172. quickMenu.enabled = false;
  1173. }
  1174. else
  1175. {
  1176. UIElement@ front = ui.frontElement;
  1177. if (front is settingsDialog || front is preferencesDialog)
  1178. {
  1179. ui.focusElement = null;
  1180. front.visible = false;
  1181. }
  1182. }
  1183. }
  1184. // Ignore other keys when UI has a modal element
  1185. else if (ui.HasModalElement())
  1186. return;
  1187. else if (key == KEY_F1)
  1188. console.Toggle();
  1189. else if (key == KEY_F2)
  1190. ToggleRenderingDebug();
  1191. else if (key == KEY_F3)
  1192. TogglePhysicsDebug();
  1193. else if (key == KEY_F4)
  1194. ToggleOctreeDebug();
  1195. else if (key == KEY_F11)
  1196. {
  1197. Image@ screenshot = Image();
  1198. graphics.TakeScreenShot(screenshot);
  1199. if (!fileSystem.DirExists(screenshotDir))
  1200. fileSystem.CreateDir(screenshotDir);
  1201. screenshot.SavePNG(screenshotDir + "/Screenshot_" +
  1202. time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
  1203. }
  1204. else if (key == KEY_KP_1 && ui.focusElement is null) // Front view
  1205. {
  1206. Vector3 center = Vector3(0,0,0);
  1207. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1208. center = SelectedNodesCenterPoint();
  1209. Vector3 pos = cameraNode.worldPosition - center;
  1210. cameraNode.worldPosition = center - Vector3(0.0, 0.0, pos.length * viewDirection);
  1211. cameraNode.direction = Vector3(0, 0, viewDirection);
  1212. ReacquireCameraYawPitch();
  1213. }
  1214. else if (key == KEY_KP_3 && ui.focusElement is null) // Side view
  1215. {
  1216. Vector3 center = Vector3(0,0,0);
  1217. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1218. center = SelectedNodesCenterPoint();
  1219. Vector3 pos = cameraNode.worldPosition - center;
  1220. cameraNode.worldPosition = center - Vector3(pos.length * -viewDirection, 0.0, 0.0);
  1221. cameraNode.direction = Vector3(-viewDirection, 0, 0);
  1222. ReacquireCameraYawPitch();
  1223. }
  1224. else if (key == KEY_KP_7 && ui.focusElement is null) // Top view
  1225. {
  1226. Vector3 center = Vector3(0,0,0);
  1227. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1228. center = SelectedNodesCenterPoint();
  1229. Vector3 pos = cameraNode.worldPosition - center;
  1230. cameraNode.worldPosition = center - Vector3(0.0, pos.length * -viewDirection, 0.0);
  1231. cameraNode.direction = Vector3(0, -viewDirection, 0);
  1232. ReacquireCameraYawPitch();
  1233. }
  1234. else if (key == KEY_KP_5 && ui.focusElement is null)
  1235. {
  1236. activeViewport.ToggleOrthographic();
  1237. }
  1238. else if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
  1239. {
  1240. if (key == '1')
  1241. editMode = EDIT_MOVE;
  1242. else if (key == '2')
  1243. editMode = EDIT_ROTATE;
  1244. else if (key == '3')
  1245. editMode = EDIT_SCALE;
  1246. else if (key == '4')
  1247. editMode = EDIT_SELECT;
  1248. else if (key == '5')
  1249. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1250. else if (key == '6')
  1251. {
  1252. --pickMode;
  1253. if (pickMode < PICK_GEOMETRIES)
  1254. pickMode = MAX_PICK_MODES - 1;
  1255. }
  1256. else if (key == '7')
  1257. {
  1258. ++pickMode;
  1259. if (pickMode >= MAX_PICK_MODES)
  1260. pickMode = PICK_GEOMETRIES;
  1261. }
  1262. else if (key == 'W')
  1263. {
  1264. fillMode = FillMode(fillMode + 1);
  1265. if (fillMode > FILL_POINT)
  1266. fillMode = FILL_SOLID;
  1267. // Update camera fill mode
  1268. SetFillMode(fillMode);
  1269. }
  1270. else if (key == KEY_SPACE)
  1271. {
  1272. if (ui.cursor.visible)
  1273. ToggleQuickMenu();
  1274. }
  1275. else
  1276. SteppedObjectManipulation(key);
  1277. toolBarDirty = true;
  1278. }
  1279. }
  1280. void HandleKeyDown(StringHash eventType, VariantMap& eventData)
  1281. {
  1282. if ( hotKeyMode == HOTKEYS_MODE_STANDARD)
  1283. {
  1284. HandleHotKeysStandart( eventData );
  1285. }
  1286. else if( hotKeyMode == HOTKEYS_MODE_BLENDER )
  1287. {
  1288. HandleHotKeysBlender ( eventData );
  1289. }
  1290. }
  1291. void UnfadeUI()
  1292. {
  1293. FadeUI(false);
  1294. }
  1295. void FadeUI(bool fade = true)
  1296. {
  1297. if (uiHidden || uiFaded == fade)
  1298. return;
  1299. float opacity = (uiFaded = fade) ? uiMinOpacity : uiMaxOpacity;
  1300. Array<UIElement@> children = ui.root.GetChildren();
  1301. for (uint i = 0; i < children.length; ++i)
  1302. {
  1303. // Texts, popup&modal windows (which are anyway only in ui.modalRoot), and editorUIElement are excluded
  1304. if (children[i].type != TEXT_TYPE && children[i] !is editorUIElement)
  1305. children[i].opacity = opacity;
  1306. }
  1307. }
  1308. bool ToggleUI()
  1309. {
  1310. HideUI(!uiHidden);
  1311. return true;
  1312. }
  1313. void UnhideUI()
  1314. {
  1315. HideUI(false);
  1316. }
  1317. void HideUI(bool hide = true)
  1318. {
  1319. if (uiHidden == hide)
  1320. return;
  1321. bool visible = !(uiHidden = hide);
  1322. Array<UIElement@> children = ui.root.GetChildren();
  1323. for (uint i = 0; i < children.length; ++i)
  1324. {
  1325. // Cursor and editorUIElement are excluded
  1326. if (children[i].type != CURSOR_TYPE && children[i] !is editorUIElement)
  1327. {
  1328. if (visible)
  1329. {
  1330. if (!children[i].visible)
  1331. children[i].visible = children[i].vars["HideUI"].GetBool();
  1332. }
  1333. else
  1334. {
  1335. children[i].vars["HideUI"] = children[i].visible;
  1336. children[i].visible = false;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. void IconizeUIElement(UIElement@ element, const String&in iconType)
  1342. {
  1343. // Check if the icon has been created before
  1344. BorderImage@ icon = element.GetChild("Icon");
  1345. // If iconType is empty, it is a request to remove the existing icon
  1346. if (iconType.empty)
  1347. {
  1348. // Remove the icon if it exists
  1349. if (icon !is null)
  1350. icon.Remove();
  1351. // Revert back the indent but only if it is indented by this function
  1352. if (element.vars[INDENT_MODIFIED_BY_ICON_VAR].GetBool())
  1353. element.indent = 0;
  1354. return;
  1355. }
  1356. // The UI element must itself has been indented to reserve the space for the icon
  1357. if (element.indent == 0)
  1358. {
  1359. element.indent = 1;
  1360. element.vars[INDENT_MODIFIED_BY_ICON_VAR] = true;
  1361. }
  1362. // If no icon yet then create one with the correct indent and size in respect to the UI element
  1363. if (icon is null)
  1364. {
  1365. // The icon is placed at one indent level less than the UI element
  1366. icon = BorderImage("Icon");
  1367. icon.indent = element.indent - 1;
  1368. icon.SetFixedSize(element.indentWidth - 2, 14);
  1369. element.InsertChild(0, icon); // Ensure icon is added as the first child
  1370. }
  1371. // Set the icon type
  1372. if (!icon.SetStyle(iconType, iconStyle))
  1373. icon.SetStyle("Unknown", iconStyle); // If fails then use an 'unknown' icon type
  1374. icon.color = Color(1,1,1,1); // Reset to enabled color
  1375. }
  1376. void SetIconEnabledColor(UIElement@ element, bool enabled, bool partial = false)
  1377. {
  1378. BorderImage@ icon = element.GetChild("Icon");
  1379. if (icon !is null)
  1380. {
  1381. if (partial)
  1382. {
  1383. icon.colors[C_TOPLEFT] = Color(1,1,1,1);
  1384. icon.colors[C_BOTTOMLEFT] = Color(1,1,1,1);
  1385. icon.colors[C_TOPRIGHT] = Color(1,0,0,1);
  1386. icon.colors[C_BOTTOMRIGHT] = Color(1,0,0,1);
  1387. }
  1388. else
  1389. icon.color = enabled ? Color(1,1,1,1) : Color(1,0,0,1);
  1390. }
  1391. }
  1392. void UpdateDirtyUI()
  1393. {
  1394. UpdateDirtyToolBar();
  1395. // Perform hierarchy selection latently after the new selections are finalized (used in undo/redo action)
  1396. if (!hierarchyUpdateSelections.empty)
  1397. {
  1398. hierarchyList.SetSelections(hierarchyUpdateSelections);
  1399. hierarchyUpdateSelections.Clear();
  1400. }
  1401. // Perform some event-triggered updates latently in case a large hierarchy was changed
  1402. if (attributesFullDirty || attributesDirty)
  1403. UpdateAttributeInspector(attributesFullDirty);
  1404. }
  1405. void HandleMessageAcknowledgement(StringHash eventType, VariantMap& eventData)
  1406. {
  1407. if (eventData["Ok"].GetBool())
  1408. messageBoxCallback();
  1409. else
  1410. messageBoxCallback = null;
  1411. }
  1412. void PopulateMruScenes()
  1413. {
  1414. mruScenesPopup.RemoveAllChildren();
  1415. if (uiRecentScenes.length > 0)
  1416. {
  1417. recentSceneMenu.enabled = true;
  1418. for (uint i=0; i < uiRecentScenes.length; ++i)
  1419. mruScenesPopup.AddChild(CreateMenuItem(uiRecentScenes[i], @LoadMostRecentScene, 0, 0, false));
  1420. }
  1421. else
  1422. recentSceneMenu.enabled = false;
  1423. }
  1424. bool LoadMostRecentScene()
  1425. {
  1426. Menu@ menu = GetEventSender();
  1427. if (menu is null)
  1428. return false;
  1429. Text@ text = menu.GetChildren()[0];
  1430. if (text is null)
  1431. return false;
  1432. return LoadScene(text.text);
  1433. }
  1434. // Set from click to false if opening menu procedurally.
  1435. void OpenContextMenu(bool fromClick=true)
  1436. {
  1437. if (contextMenu is null)
  1438. return;
  1439. contextMenu.enabled = true;
  1440. contextMenu.visible = true;
  1441. contextMenu.BringToFront();
  1442. if (fromClick)
  1443. contextMenuActionWaitFrame=true;
  1444. }
  1445. void CloseContextMenu()
  1446. {
  1447. if (contextMenu is null)
  1448. return;
  1449. contextMenu.enabled = false;
  1450. contextMenu.visible = false;
  1451. }
  1452. void ActivateContextMenu(Array<UIElement@> actions)
  1453. {
  1454. contextMenu.RemoveAllChildren();
  1455. for (uint i=0; i< actions.length; ++i)
  1456. {
  1457. contextMenu.AddChild(actions[i]);
  1458. }
  1459. contextMenu.SetFixedHeight(24*actions.length+6);
  1460. contextMenu.position = ui.cursor.screenPosition + IntVector2(10,-10);
  1461. OpenContextMenu();
  1462. }
  1463. Menu@ CreateContextMenuItem(String text, String handler)
  1464. {
  1465. Menu@ menu = Menu();
  1466. menu.defaultStyle = uiStyle;
  1467. menu.style = AUTO_STYLE;
  1468. menu.SetLayout(LM_HORIZONTAL, 0, IntRect(8, 2, 8, 2));
  1469. Text@ menuText = Text();
  1470. menuText.style = "EditorMenuText";
  1471. menu.AddChild(menuText);
  1472. menuText.text = text;
  1473. menu.vars[VAR_CONTEXT_MENU_HANDLER] = handler;
  1474. SubscribeToEvent(menu, "Released", "ContextMenuEventWrapper");
  1475. return menu;
  1476. }
  1477. void ContextMenuEventWrapper(StringHash eventType, VariantMap& eventData)
  1478. {
  1479. UIElement@ uiElement = eventData["Element"].GetPtr();
  1480. if (uiElement is null)
  1481. return;
  1482. String handler = uiElement.vars[VAR_CONTEXT_MENU_HANDLER].GetString();
  1483. if (!handler.empty)
  1484. {
  1485. SubscribeToEvent(uiElement, "Released", handler);
  1486. uiElement.SendEvent("Released", eventData);
  1487. }
  1488. CloseContextMenu();
  1489. }
  1490. /// Load a UI XML file used by the editor
  1491. XMLFile@ GetEditorUIXMLFile(const String&in fileName)
  1492. {
  1493. // Prefer the executable path to avoid using the user's resource path, which may point
  1494. // to an outdated Urho installation
  1495. String fullFileName = fileSystem.programDir + "Data/" + fileName;
  1496. if (fileSystem.FileExists(fullFileName))
  1497. {
  1498. File@ file = File(fullFileName, FILE_READ);
  1499. XMLFile@ xml = XMLFile();
  1500. xml.name = fileName;
  1501. if (xml.Load(file))
  1502. return xml;
  1503. }
  1504. // Fallback to resource system
  1505. return cache.GetResource("XMLFile", fileName);
  1506. }
  1507. /// Load an UI layout used by the editor
  1508. UIElement@ LoadEditorUI(const String&in fileName)
  1509. {
  1510. return ui.LoadLayout(GetEditorUIXMLFile(fileName));
  1511. }
  1512. /// Set node children as a spline path, either cyclic or non-cyclic
  1513. bool SetSplinePath()
  1514. {
  1515. Menu@ menu = GetEventSender();
  1516. if (menu is null)
  1517. return false;
  1518. return SceneSetChildrenSplinePath(menu.name == "Cyclic");
  1519. }