EditorUI.as 79 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266
  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. uint stepColoringGroupUpdate = 100; // ms
  13. uint timeToNextColoringGroupUpdate = 0;
  14. const StringHash UI_ELEMENT_TYPE("UIElement");
  15. const StringHash WINDOW_TYPE("Window");
  16. const StringHash MENU_TYPE("Menu");
  17. const StringHash TEXT_TYPE("Text");
  18. const StringHash CURSOR_TYPE("Cursor");
  19. const String AUTO_STYLE(""); // Empty string means auto style, i.e. applying style according to UI-element's type automatically
  20. const String TEMP_SCENE_NAME("_tempscene_.xml");
  21. const String TEMP_BINARY_SCENE_NAME("_tempscene_.bin");
  22. const StringHash CALLBACK_VAR("Callback");
  23. const StringHash INDENT_MODIFIED_BY_ICON_VAR("IconIndented");
  24. const StringHash VAR_CONTEXT_MENU_HANDLER("ContextMenuHandler");
  25. const int SHOW_POPUP_INDICATOR = -1;
  26. const uint MAX_QUICK_MENU_ITEMS = 10;
  27. const uint maxRecentSceneCount = 5;
  28. Array<String> uiSceneFilters = {"*.xml", "*.json", "*.bin", "*.*"};
  29. Array<String> uiElementFilters = {"*.xml"};
  30. Array<String> uiAllFilters = {"*.*"};
  31. Array<String> uiScriptFilters = {"*.as", "*.*"};
  32. Array<String> uiParticleFilters = {"*.xml"};
  33. Array<String> uiRenderPathFilters = {"*.xml"};
  34. Array<String> uiExportPathFilters = {"*.obj"};
  35. uint uiSceneFilter = 0;
  36. uint uiElementFilter = 0;
  37. uint uiNodeFilter = 0;
  38. uint uiImportFilter = 0;
  39. uint uiScriptFilter = 0;
  40. uint uiParticleFilter = 0;
  41. uint uiRenderPathFilter = 0;
  42. uint uiExportFilter = 0;
  43. String uiScenePath = fileSystem.programDir + "Data/Scenes";
  44. String uiElementPath = fileSystem.programDir + "Data/UI";
  45. String uiNodePath = fileSystem.programDir + "Data/Objects";
  46. String uiImportPath;
  47. String uiExportPath;
  48. String uiScriptPath = fileSystem.programDir + "Data/Scripts";
  49. String uiParticlePath = fileSystem.programDir + "Data/Particles";
  50. String uiRenderPathPath = fileSystem.programDir + "CoreData/RenderPaths";
  51. Array<String> uiRecentScenes;
  52. String screenshotDir = fileSystem.programDir + "Screenshots";
  53. bool uiFaded = false;
  54. float uiMinOpacity = 0.3;
  55. float uiMaxOpacity = 0.7;
  56. bool uiHidden = false;
  57. TerrainEditor terrainEditor;
  58. void CreateUI()
  59. {
  60. // Remove all existing UI content in case we are reloading the editor script
  61. /// \todo The console will not be properly recreated as it has already been created once
  62. ui.root.RemoveAllChildren();
  63. uiStyle = GetEditorUIXMLFile("UI/DefaultStyle.xml");
  64. ui.root.defaultStyle = uiStyle;
  65. iconStyle = GetEditorUIXMLFile("UI/EditorIcons.xml");
  66. graphics.windowIcon = cache.GetResource("Image", "Textures/UrhoIcon.png");
  67. CreateCursor();
  68. CreateMenuBar();
  69. CreateToolBar();
  70. CreateSecondaryToolBar();
  71. CreateQuickMenu();
  72. CreateContextMenu();
  73. CreateHierarchyWindow();
  74. CreateAttributeInspectorWindow();
  75. CreateEditorSettingsDialog();
  76. CreateEditorPreferencesDialog();
  77. CreateMaterialEditor();
  78. CreateParticleEffectEditor();
  79. CreateSpawnEditor();
  80. CreateSoundTypeEditor();
  81. CreateStatsBar();
  82. CreateConsole();
  83. CreateDebugHud();
  84. CreateResourceBrowser();
  85. CreateCamera();
  86. CreateLayerEditor();
  87. CreateColorWheel();
  88. terrainEditor.Create();
  89. SubscribeToEvent("ScreenMode", "ResizeUI");
  90. SubscribeToEvent("MenuSelected", "HandleMenuSelected");
  91. SubscribeToEvent("ChangeLanguage", "HandleChangeLanguage");
  92. SubscribeToEvent("WheelChangeColor", "HandleWheelChangeColor");
  93. SubscribeToEvent("WheelSelectColor", "HandleWheelSelectColor");
  94. SubscribeToEvent("WheelDiscardColor", "HandleWheelDiscardColor");
  95. }
  96. void ResizeUI()
  97. {
  98. // Resize menu bar
  99. uiMenuBar.SetFixedWidth(graphics.width);
  100. // Resize tool bar
  101. toolBar.SetFixedWidth(graphics.width);
  102. // Resize secondary tool bar
  103. secondaryToolBar.SetFixedHeight(graphics.height);
  104. // Relayout windows
  105. Array<UIElement@> children = ui.root.GetChildren();
  106. for (uint i = 0; i < children.length; ++i)
  107. {
  108. if (children[i].type == WINDOW_TYPE)
  109. AdjustPosition(children[i]);
  110. }
  111. // Relayout root UI element
  112. editorUIElement.SetSize(graphics.width, graphics.height);
  113. // Set new viewport area and reset the viewport layout
  114. viewportArea = IntRect(0, 0, graphics.width, graphics.height);
  115. SetViewportMode(viewportMode);
  116. }
  117. void AdjustPosition(Window@ window)
  118. {
  119. IntVector2 position = window.position;
  120. IntVector2 size = window.size;
  121. IntVector2 extend = position + size;
  122. if (extend.x > graphics.width)
  123. position.x = Max(10, graphics.width - size.x - 10);
  124. if (extend.y > graphics.height)
  125. position.y = Max(100, graphics.height - size.y - 10);
  126. window.position = position;
  127. }
  128. void CreateCursor()
  129. {
  130. Cursor@ cursor = Cursor("Cursor");
  131. cursor.SetStyleAuto(uiStyle);
  132. cursor.SetPosition(graphics.width / 2, graphics.height / 2);
  133. ui.cursor = cursor;
  134. if (GetPlatform() == "Android" || GetPlatform() == "iOS")
  135. ui.cursor.visible = false;
  136. }
  137. // AngelScript does not support closures (yet), but funcdef should do just fine as a workaround for a few cases here for now
  138. funcdef bool MENU_CALLBACK();
  139. Array<MENU_CALLBACK@> menuCallbacks;
  140. MENU_CALLBACK@ messageBoxCallback;
  141. void HandleQuickSearchChange(StringHash eventType, VariantMap& eventData)
  142. {
  143. LineEdit@ search = eventData["Element"].GetPtr();
  144. if (search is null)
  145. return;
  146. PerformQuickMenuSearch(search.text.ToLower().Trimmed());
  147. }
  148. void HandleQuickSearchFinish(StringHash eventType, VariantMap& eventData)
  149. {
  150. Menu@ menu = quickMenu.GetChild("ResultsMenu", true);
  151. if (menu is null)
  152. return;
  153. String query = eventData["Text"].GetString();
  154. if (query.length <= 0)
  155. return;
  156. Array<QuickMenuItem@> filtered;
  157. {
  158. QuickMenuItem@ qi;
  159. for (uint x=0; x < quickMenuItems.length; x++)
  160. {
  161. @qi = quickMenuItems[x];
  162. int find = qi.action.Find(query, 0, false);
  163. if (find > -1)
  164. {
  165. qi.sortScore = find;
  166. filtered.Push(qi);
  167. }
  168. }
  169. }
  170. filtered.Sort();
  171. if (!filtered.empty)
  172. {
  173. VariantMap data;
  174. Menu@ item = CreateMenuItem(filtered[0].action, filtered[0].callback);
  175. data["Element"] = item;
  176. item.SendEvent("MenuSelected", data);
  177. }
  178. }
  179. void PerformQuickMenuSearch(const String&in query)
  180. {
  181. Menu@ menu = quickMenu.GetChild("ResultsMenu", true);
  182. if (menu is null)
  183. return;
  184. menu.RemoveAllChildren();
  185. uint limit = 0;
  186. if (query.length > 0)
  187. {
  188. int lastIndex = 0;
  189. uint score = 0;
  190. int index = 0;
  191. Array<QuickMenuItem@> filtered;
  192. {
  193. QuickMenuItem@ qi;
  194. for (uint x=0; x < quickMenuItems.length; x++)
  195. {
  196. @qi = quickMenuItems[x];
  197. int find = qi.action.Find(query, 0, false);
  198. if (find > -1)
  199. {
  200. qi.sortScore = find;
  201. filtered.Push(qi);
  202. }
  203. }
  204. }
  205. filtered.Sort();
  206. {
  207. QuickMenuItem@ qi;
  208. limit = filtered.length > MAX_QUICK_MENU_ITEMS ? MAX_QUICK_MENU_ITEMS : filtered.length;
  209. for (uint x=0; x < limit; x++)
  210. {
  211. @qi = filtered[x];
  212. Menu@ item = CreateMenuItem(qi.action, qi.callback);
  213. item.SetMaxSize(1000,16);
  214. menu.AddChild(item);
  215. }
  216. }
  217. }
  218. menu.visible = limit > 0;
  219. menu.SetFixedHeight(limit * 16);
  220. quickMenu.BringToFront();
  221. quickMenu.SetFixedHeight(limit*16 + 62 + (menu.visible ? 6 : 0));
  222. }
  223. class QuickMenuItem
  224. {
  225. String action;
  226. MENU_CALLBACK@ callback;
  227. uint sortScore = 0;
  228. QuickMenuItem(){}
  229. QuickMenuItem(String action, MENU_CALLBACK@ callback)
  230. {
  231. this.action = action;
  232. this.callback = callback;
  233. }
  234. int opCmp(QuickMenuItem@ b)
  235. {
  236. return sortScore - b.sortScore;
  237. }
  238. }
  239. /// Create popup search menu.
  240. void CreateQuickMenu()
  241. {
  242. if (quickMenu !is null)
  243. return;
  244. quickMenu = LoadEditorUI("UI/EditorQuickMenu.xml");
  245. quickMenu.enabled = false;
  246. quickMenu.visible = false;
  247. quickMenu.opacity = uiMaxOpacity;
  248. // Handle a dummy search in the quick menu to finalize its initial size to empty
  249. PerformQuickMenuSearch("");
  250. ui.root.AddChild(quickMenu);
  251. LineEdit@ search = quickMenu.GetChild("Search", true);
  252. SubscribeToEvent(search, "TextChanged", "HandleQuickSearchChange");
  253. SubscribeToEvent(search, "TextFinished", "HandleQuickSearchFinish");
  254. UIElement@ closeButton = quickMenu.GetChild("CloseButton", true);
  255. SubscribeToEvent(closeButton, "Pressed", "ToggleQuickMenu");
  256. }
  257. void ToggleQuickMenu()
  258. {
  259. quickMenu.enabled = !quickMenu.enabled && ui.cursor.visible;
  260. quickMenu.visible = quickMenu.enabled;
  261. if (quickMenu.enabled)
  262. {
  263. quickMenu.position = ui.cursorPosition - IntVector2(20,70);
  264. LineEdit@ search = quickMenu.GetChild("Search", true);
  265. search.text = "";
  266. search.focus = true;
  267. }
  268. }
  269. /// Create top menu bar.
  270. void CreateMenuBar()
  271. {
  272. uiMenuBar = BorderImage("MenuBar");
  273. ui.root.AddChild(uiMenuBar);
  274. uiMenuBar.enabled = true;
  275. uiMenuBar.style = "EditorMenuBar";
  276. uiMenuBar.SetLayout(LM_HORIZONTAL);
  277. uiMenuBar.opacity = uiMaxOpacity;
  278. uiMenuBar.SetFixedWidth(graphics.width);
  279. {
  280. Menu@ menu = CreateMenu("File");
  281. Window@ popup = menu.popup;
  282. popup.AddChild(CreateMenuItem("New scene", @ResetScene, KEY_N, QUAL_SHIFT | QUAL_CTRL));
  283. popup.AddChild(CreateMenuItem("Open scene...", @PickFile, KEY_O, QUAL_CTRL));
  284. popup.AddChild(CreateMenuItem("Save scene", @SaveSceneWithExistingName, KEY_S, QUAL_CTRL));
  285. popup.AddChild(CreateMenuItem("Save scene as...", @PickFile, KEY_S, QUAL_SHIFT | QUAL_CTRL));
  286. recentSceneMenu = CreateMenuItem("Open recent scene", null, SHOW_POPUP_INDICATOR);
  287. popup.AddChild(recentSceneMenu);
  288. mruScenesPopup = CreatePopup(recentSceneMenu);
  289. PopulateMruScenes();
  290. CreateChildDivider(popup);
  291. Menu@ childMenu = CreateMenuItem("menu Load node", null, SHOW_POPUP_INDICATOR);
  292. Window@ childPopup = CreatePopup(childMenu);
  293. childPopup.AddChild(CreateMenuItem("As replicated...", @PickFile, 0, 0, true, "Load node as replicated..."));
  294. childPopup.AddChild(CreateMenuItem("As local...", @PickFile, 0, 0, true, "Load node as local..."));
  295. popup.AddChild(childMenu);
  296. popup.AddChild(CreateMenuItem("Save node as...", @PickFile));
  297. CreateChildDivider(popup);
  298. popup.AddChild(CreateMenuItem("Import model...", @PickFile));
  299. popup.AddChild(CreateMenuItem("Import scene...", @PickFile));
  300. popup.AddChild(CreateMenuItem("Import animation...", @PickFile));
  301. CreateChildDivider(popup);
  302. popup.AddChild(CreateMenuItem("Export scene to OBJ...", @PickFile));
  303. popup.AddChild(CreateMenuItem("Export selected to OBJ...", @PickFile));
  304. CreateChildDivider(popup);
  305. popup.AddChild(CreateMenuItem("Run script...", @PickFile));
  306. popup.AddChild(CreateMenuItem("Set resource path...", @PickFile));
  307. CreateChildDivider(popup);
  308. popup.AddChild(CreateMenuItem("Exit", @Exit));
  309. FinalizedPopupMenu(popup);
  310. uiMenuBar.AddChild(menu);
  311. }
  312. {
  313. Menu@ menu = CreateMenu("Edit");
  314. Window@ popup = menu.popup;
  315. popup.AddChild(CreateMenuItem("Undo", @Undo, KEY_Z, QUAL_CTRL));
  316. popup.AddChild(CreateMenuItem("Redo", @Redo, KEY_Y, QUAL_CTRL));
  317. CreateChildDivider(popup);
  318. popup.AddChild(CreateMenuItem("Cut", @Cut, KEY_X, QUAL_CTRL));
  319. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  320. popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, KEY_D, QUAL_CTRL));
  321. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  322. popup.AddChild(CreateMenuItem("Duplicate", @Duplicate, KEY_D, QUAL_SHIFT));
  323. popup.AddChild(CreateMenuItem("Copy", @Copy, KEY_C, QUAL_CTRL));
  324. popup.AddChild(CreateMenuItem("Paste", @Paste, KEY_V, QUAL_CTRL));
  325. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  326. popup.AddChild(CreateMenuItem("Delete", @Delete, KEY_DELETE, QUAL_ANY));
  327. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  328. popup.AddChild(CreateMenuItem("Delete", @BlenderModeDelete, KEY_X, QUAL_ANY));
  329. popup.AddChild(CreateMenuItem("Select all", @SelectAll, KEY_A, QUAL_CTRL));
  330. popup.AddChild(CreateMenuItem("Deselect all", @DeselectAll, KEY_A, QUAL_SHIFT | QUAL_CTRL));
  331. CreateChildDivider(popup);
  332. popup.AddChild(CreateMenuItem("Reset to default", @ResetToDefault));
  333. CreateChildDivider(popup);
  334. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  335. {
  336. popup.AddChild(CreateMenuItem("Reset position", @SceneResetPosition, '1' , QUAL_ALT));
  337. popup.AddChild(CreateMenuItem("Reset rotation", @SceneResetRotation, '2' , QUAL_ALT));
  338. popup.AddChild(CreateMenuItem("Reset scale", @SceneResetScale, '3' , QUAL_ALT));
  339. popup.AddChild(CreateMenuItem("Reset transform", @SceneResetTransform, KEY_Q , QUAL_ALT));
  340. }
  341. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  342. {
  343. popup.AddChild(CreateMenuItem("Reset position", @SceneResetPosition, KEY_G , QUAL_ALT));
  344. popup.AddChild(CreateMenuItem("Reset rotation", @SceneResetRotation, KEY_R, QUAL_ALT));
  345. popup.AddChild(CreateMenuItem("Reset scale", @SceneResetScale, KEY_S, QUAL_ALT));
  346. popup.AddChild(CreateMenuItem("Reset transform", @SceneResetTransform, KEY_Q , QUAL_ALT));
  347. }
  348. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  349. {
  350. popup.AddChild(CreateMenuItem("Enable/disable", @SceneToggleEnable, KEY_E, QUAL_CTRL));
  351. popup.AddChild(CreateMenuItem("Enable all", @SceneEnableAllNodes, KEY_E, QUAL_ALT));
  352. }
  353. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  354. {
  355. popup.AddChild(CreateMenuItem("Enable/disable", @SceneToggleEnable, KEY_H));
  356. popup.AddChild(CreateMenuItem("Enable all", @SceneEnableAllNodes, KEY_H, QUAL_ALT));
  357. }
  358. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  359. popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, KEY_U, QUAL_CTRL));
  360. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  361. popup.AddChild(CreateMenuItem("Unparent", @SceneUnparent, KEY_P, QUAL_ALT));
  362. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  363. popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, KEY_U));
  364. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  365. popup.AddChild(CreateMenuItem("Parent to last", @NodesParentToLastSelected, KEY_P, QUAL_CTRL));
  366. CreateChildDivider(popup);
  367. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  368. popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, KEY_P, QUAL_CTRL));
  369. //else if (hotKeyMode == HOT_KEYS_MODE_BLENDER)
  370. // popup.AddChild(CreateMenuItem("Toggle update", @ToggleSceneUpdate, KEY_P, QUAL_CTRL));
  371. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  372. {
  373. popup.AddChild(CreateMenuItem("View closer", @ViewCloser, KEY_F));
  374. }
  375. else if (hotKeyMode == HOTKEYS_MODE_BLENDER)
  376. {
  377. popup.AddChild(CreateMenuItem("Move to layer", @ShowLayerMover, KEY_M));
  378. popup.AddChild(CreateMenuItem("Smart Duplicate", @SceneSmartDuplicateNode, KEY_D, QUAL_ALT));
  379. popup.AddChild(CreateMenuItem("View closer", @ViewCloser, KEY_KP_PERIOD));
  380. }
  381. popup.AddChild(CreateMenuItem("Color wheel", @ColorWheelBuildMenuSelectTypeColor, KEY_W, QUAL_ALT));
  382. popup.AddChild(CreateMenuItem("Show components icons", @ViewDebugIcons, KEY_I, QUAL_ALT));
  383. CreateChildDivider(popup);
  384. popup.AddChild(CreateMenuItem("Stop test animation", @StopTestAnimation));
  385. CreateChildDivider(popup);
  386. popup.AddChild(CreateMenuItem("Rebuild navigation data", @SceneRebuildNavigation));
  387. popup.AddChild(CreateMenuItem("Render Zone Cubemap", @SceneRenderZoneCubemaps));
  388. popup.AddChild(CreateMenuItem("Add children to SM-group", @SceneAddChildrenStaticModelGroup));
  389. Menu@ childMenu = CreateMenuItem("Set children as spline path", null, SHOW_POPUP_INDICATOR);
  390. Window@ childPopup = CreatePopup(childMenu);
  391. childPopup.AddChild(CreateMenuItem("Non-cyclic", @SetSplinePath, 0, 0, true, "Set non-cyclic spline path"));
  392. childPopup.AddChild(CreateMenuItem("Cyclic", @SetSplinePath, 0, 0, true, "Set cyclic spline path"));
  393. popup.AddChild(childMenu);
  394. FinalizedPopupMenu(popup);
  395. uiMenuBar.AddChild(menu);
  396. }
  397. {
  398. Menu@ menu = CreateMenu("Create");
  399. Window@ popup = menu.popup;
  400. popup.AddChild(CreateMenuItem("Replicated node", @PickNode, 0, 0, true, "Create Replicated node"));
  401. popup.AddChild(CreateMenuItem("Local node", @PickNode, 0, 0, true, "Create Local node"));
  402. CreateChildDivider(popup);
  403. Menu@ childMenu = CreateMenuItem("Component", null, SHOW_POPUP_INDICATOR);
  404. Window@ childPopup = CreatePopup(childMenu);
  405. String[] objectCategories = GetObjectCategories();
  406. for (uint i = 0; i < objectCategories.length; ++i)
  407. {
  408. // Skip the UI category for the component menus
  409. if (objectCategories[i] == "UI")
  410. continue;
  411. Menu@ m = CreateMenuItem(objectCategories[i], null, SHOW_POPUP_INDICATOR);
  412. Window@ p = CreatePopup(m);
  413. String[] componentTypes = GetObjectsByCategory(objectCategories[i]);
  414. for (uint j = 0; j < componentTypes.length; ++j)
  415. p.AddChild(CreateIconizedMenuItem(componentTypes[j], @PickComponent, 0, 0, "", true, "Create " + componentTypes[j]));
  416. childPopup.AddChild(m);
  417. }
  418. FinalizedPopupMenu(childPopup);
  419. popup.AddChild(childMenu);
  420. childMenu = CreateMenuItem("Builtin object", null, SHOW_POPUP_INDICATOR);
  421. childPopup = CreatePopup(childMenu);
  422. String[] objects = { "Box", "Cone", "Cylinder", "Plane", "Pyramid", "Sphere", "TeaPot", "Torus" };
  423. for (uint i = 0; i < objects.length; ++i)
  424. childPopup.AddChild(CreateIconizedMenuItem(objects[i], @PickBuiltinObject, 0, 0, "Node", true, "Create " + objects[i]));
  425. popup.AddChild(childMenu);
  426. CreateChildDivider(popup);
  427. childMenu = CreateMenuItem("UI-element", null, SHOW_POPUP_INDICATOR);
  428. childPopup = CreatePopup(childMenu);
  429. String[] uiElementTypes = GetObjectsByCategory("UI");
  430. for (uint i = 0; i < uiElementTypes.length; ++i)
  431. {
  432. if (uiElementTypes[i] != "UIElement")
  433. childPopup.AddChild(CreateIconizedMenuItem(uiElementTypes[i], @PickUIElement, 0, 0, "", true, "Create " + uiElementTypes[i]));
  434. }
  435. CreateChildDivider(childPopup);
  436. childPopup.AddChild(CreateIconizedMenuItem("UIElement", @PickUIElement));
  437. popup.AddChild(childMenu);
  438. FinalizedPopupMenu(popup);
  439. uiMenuBar.AddChild(menu);
  440. }
  441. {
  442. Menu@ menu = CreateMenu("UI-layout");
  443. Window@ popup = menu.popup;
  444. popup.AddChild(CreateMenuItem("Open UI-layout...", @PickFile, KEY_O, QUAL_ALT));
  445. popup.AddChild(CreateMenuItem("Save UI-layout", @SaveUILayoutWithExistingName, KEY_S, QUAL_ALT));
  446. popup.AddChild(CreateMenuItem("Save UI-layout as...", @PickFile));
  447. CreateChildDivider(popup);
  448. popup.AddChild(CreateMenuItem("Close UI-layout", @CloseUILayout, KEY_C, QUAL_ALT));
  449. popup.AddChild(CreateMenuItem("Close all UI-layouts", @CloseAllUILayouts));
  450. CreateChildDivider(popup);
  451. popup.AddChild(CreateMenuItem("Load child element...", @PickFile));
  452. popup.AddChild(CreateMenuItem("Save child element as...", @PickFile));
  453. CreateChildDivider(popup);
  454. popup.AddChild(CreateMenuItem("Set default style...", @PickFile));
  455. FinalizedPopupMenu(popup);
  456. uiMenuBar.AddChild(menu);
  457. }
  458. {
  459. Menu@ menu = CreateMenu("View");
  460. Window@ popup = menu.popup;
  461. popup.AddChild(CreateMenuItem("Hierarchy", @ToggleHierarchyWindow, KEY_H, QUAL_CTRL));
  462. popup.AddChild(CreateMenuItem("Attribute inspector", @ToggleAttributeInspectorWindow, KEY_I, QUAL_CTRL));
  463. popup.AddChild(CreateMenuItem("Resource browser", @ToggleResourceBrowserWindow, KEY_B, QUAL_CTRL));
  464. popup.AddChild(CreateMenuItem("Material editor", @ToggleMaterialEditor));
  465. popup.AddChild(CreateMenuItem("Particle editor", @ToggleParticleEffectEditor));
  466. popup.AddChild(CreateMenuItem("Terrain editor", TerrainEditorShowCallback(terrainEditor.Show)));
  467. popup.AddChild(CreateMenuItem("Spawn editor", @ToggleSpawnEditor));
  468. popup.AddChild(CreateMenuItem("Sound Type editor", @ToggleSoundTypeEditor));
  469. popup.AddChild(CreateMenuItem("Editor settings", @ToggleEditorSettingsDialog));
  470. popup.AddChild(CreateMenuItem("Editor preferences", @ToggleEditorPreferencesDialog));
  471. CreateChildDivider(popup);
  472. popup.AddChild(CreateMenuItem("Hide editor", @ToggleUI, KEY_F12, QUAL_ANY));
  473. FinalizedPopupMenu(popup);
  474. uiMenuBar.AddChild(menu);
  475. }
  476. BorderImage@ spacer = BorderImage("MenuBarSpacer");
  477. uiMenuBar.AddChild(spacer);
  478. spacer.style = "EditorMenuBar";
  479. }
  480. bool Exit()
  481. {
  482. ui.cursor.shape = CS_BUSY;
  483. if (messageBoxCallback is null)
  484. {
  485. String message;
  486. if (sceneModified)
  487. message = "Scene has been modified.\n";
  488. bool uiLayoutModified = false;
  489. for (uint i = 0; i < editorUIElement.numChildren; ++i)
  490. {
  491. UIElement@ element = editorUIElement.children[i];
  492. if (element !is null && element.vars[MODIFIED_VAR].GetBool())
  493. {
  494. uiLayoutModified = true;
  495. message += "UI layout has been modified.\n";
  496. break;
  497. }
  498. }
  499. if (sceneModified || uiLayoutModified)
  500. {
  501. MessageBox@ messageBox = MessageBox(message + "Continue to exit?", "Warning");
  502. if (messageBox.window !is null)
  503. {
  504. Button@ cancelButton = messageBox.window.GetChild("CancelButton", true);
  505. cancelButton.visible = true;
  506. cancelButton.focus = true;
  507. SubscribeToEvent(messageBox, "MessageACK", "HandleMessageAcknowledgement");
  508. messageBoxCallback = @Exit;
  509. return false;
  510. }
  511. }
  512. }
  513. else
  514. messageBoxCallback = null;
  515. engine.Exit();
  516. return true;
  517. }
  518. void HandleExitRequested()
  519. {
  520. if (!ui.HasModalElement())
  521. Exit();
  522. }
  523. bool PickFile()
  524. {
  525. Menu@ menu = GetEventSender();
  526. if (menu is null)
  527. return false;
  528. String action = menu.name;
  529. if (action.empty)
  530. return false;
  531. // File (Scene related)
  532. if (action == "Open scene...")
  533. {
  534. CreateFileSelector("Open scene", "Open", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
  535. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleOpenSceneFile");
  536. }
  537. else if (action == "Save scene as..." || action == "Save scene")
  538. {
  539. CreateFileSelector("Save scene as", "Save", "Cancel", uiScenePath, uiSceneFilters, uiSceneFilter);
  540. uiFileSelector.fileName = GetFileNameAndExtension(editorScene.fileName);
  541. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveSceneFile");
  542. }
  543. else if (action == "As replicated..." || action == "Load node as replicated...")
  544. {
  545. instantiateMode = REPLICATED;
  546. CreateFileSelector("fileSelector Load node", "Load", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  547. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadNodeFile");
  548. }
  549. else if (action == "As local..." || action == "Load node as local...")
  550. {
  551. instantiateMode = LOCAL;
  552. CreateFileSelector("Load node", "Load", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  553. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadNodeFile");
  554. }
  555. else if (action == "Save node as...")
  556. {
  557. if (editNode !is null && editNode !is editorScene)
  558. {
  559. CreateFileSelector("Save node", "Save", "Cancel", uiNodePath, uiSceneFilters, uiNodeFilter);
  560. uiFileSelector.fileName = GetFileNameAndExtension(instantiateFileName);
  561. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveNodeFile");
  562. }
  563. }
  564. else if (action == "Import model...")
  565. {
  566. CreateFileSelector("Import model", "Import", "Cancel", uiImportPath, uiAllFilters, uiImportFilter);
  567. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleImportModel");
  568. }
  569. else if (action == "Import animation...")
  570. {
  571. CreateFileSelector("Import animation", "Import", "Cancel", uiImportPath, uiAllFilters, uiImportFilter);
  572. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleImportAnimation");
  573. }
  574. else if (action == "Import scene...")
  575. {
  576. CreateFileSelector("Import scene", "Import", "Cancel", uiImportPath, uiAllFilters, uiImportFilter);
  577. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleImportScene");
  578. }
  579. else if (action == "Export scene to OBJ..." || action == "Export selected to OBJ...")
  580. {
  581. // Set these up together to share the "export settings" options
  582. if (action == "Export scene to OBJ...")
  583. {
  584. CreateFileSelector("Export scene to OBJ", "Save", "Cancel", uiExportPath, uiExportPathFilters, uiExportFilter);
  585. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleExportSceneOBJ");
  586. }
  587. else if (action == "Export selected to OBJ...")
  588. {
  589. CreateFileSelector("Export selected to OBJ", "Save", "Cancel", uiExportPath, uiExportPathFilters, uiExportFilter);
  590. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleExportSelectedOBJ");
  591. }
  592. Window@ window = uiFileSelector.window;
  593. UIElement@ optionsGroup = UIElement();
  594. optionsGroup.maxHeight = 30;
  595. optionsGroup.layoutMode = LM_HORIZONTAL;
  596. window.defaultStyle = uiStyle;
  597. window.style = AUTO_STYLE;
  598. CheckBox@ checkRightHanded = CheckBox();
  599. checkRightHanded.checked = objExportRightHanded_;
  600. checkRightHanded.defaultStyle = uiStyle;
  601. checkRightHanded.style = AUTO_STYLE;
  602. SubscribeToEvent(checkRightHanded, "Toggled", "HandleOBJRightHandedChanged");
  603. optionsGroup.AddChild(checkRightHanded);
  604. Text@ lblRightHanded = Text();
  605. lblRightHanded.defaultStyle = uiStyle;
  606. lblRightHanded.style = AUTO_STYLE;
  607. lblRightHanded.text = " Right handed";
  608. optionsGroup.AddChild(lblRightHanded);
  609. CheckBox@ checkZUp = CheckBox();
  610. checkZUp.checked = objExportZUp_;
  611. checkZUp.defaultStyle = uiStyle;
  612. checkZUp.style = AUTO_STYLE;
  613. SubscribeToEvent(checkZUp, "Toggled", "HandleOBJZUpChanged");
  614. optionsGroup.AddChild(checkZUp);
  615. Text@ lblZUp = Text();
  616. lblZUp.defaultStyle = uiStyle;
  617. lblZUp.style = AUTO_STYLE;
  618. lblZUp.text = " Z Axis Up";
  619. optionsGroup.AddChild(lblZUp);
  620. window.AddChild(optionsGroup);
  621. }
  622. else if (action == "Run script...")
  623. {
  624. CreateFileSelector("Run script", "Run", "Cancel", uiScriptPath, uiScriptFilters, uiScriptFilter);
  625. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleRunScript");
  626. }
  627. else if (action == "Set resource path...")
  628. {
  629. CreateFileSelector("Set resource path", "Set", "Cancel", sceneResourcePath, uiAllFilters, 0);
  630. uiFileSelector.directoryMode = true;
  631. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleResourcePath");
  632. }
  633. // UI-element
  634. else if (action == "Open UI-layout...")
  635. {
  636. CreateFileSelector("Open UI-layout", "Open", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  637. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleOpenUILayoutFile");
  638. }
  639. else if (action == "Save UI-layout as..." || action == "Save UI-layout")
  640. {
  641. if (editUIElement !is null)
  642. {
  643. UIElement@ element = GetTopLevelUIElement(editUIElement);
  644. if (element is null)
  645. return false;
  646. CreateFileSelector("Save UI-layout as", "Save", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  647. uiFileSelector.fileName = GetFileNameAndExtension(element.GetVar(FILENAME_VAR).GetString());
  648. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveUILayoutFile");
  649. }
  650. }
  651. else if (action == "Load child element...")
  652. {
  653. if (editUIElement !is null)
  654. {
  655. CreateFileSelector("Load child element", "Load", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  656. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleLoadChildUIElementFile");
  657. }
  658. }
  659. else if (action == "Save child element as...")
  660. {
  661. if (editUIElement !is null)
  662. {
  663. CreateFileSelector("Save child element", "Save", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  664. uiFileSelector.fileName = GetFileNameAndExtension(editUIElement.GetVar(CHILD_ELEMENT_FILENAME_VAR).GetString());
  665. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleSaveChildUIElementFile");
  666. }
  667. }
  668. else if (action == "Set default style...")
  669. {
  670. CreateFileSelector("Set default style", "Set", "Cancel", uiElementPath, uiElementFilters, uiElementFilter);
  671. SubscribeToEvent(uiFileSelector, "FileSelected", "HandleUIElementDefaultStyle");
  672. }
  673. return true;
  674. }
  675. bool PickNode()
  676. {
  677. Menu@ menu = GetEventSender();
  678. if (menu is null)
  679. return false;
  680. String action = GetActionName(menu.name);
  681. if (action.empty)
  682. return false;
  683. CreateNode(action == "Replicated node" ? REPLICATED : LOCAL);
  684. return true;
  685. }
  686. bool PickComponent()
  687. {
  688. if (editNodes.empty)
  689. return false;
  690. Menu@ menu = GetEventSender();
  691. if (menu is null)
  692. return false;
  693. String action = GetActionName(menu.name);
  694. if (action.empty)
  695. return false;
  696. CreateComponent(action);
  697. return true;
  698. }
  699. bool PickBuiltinObject()
  700. {
  701. Menu@ menu = GetEventSender();
  702. if (menu is null)
  703. return false;
  704. String action = GetActionName(menu.name);
  705. if (action.empty)
  706. return false;
  707. CreateBuiltinObject(action);
  708. return true;
  709. }
  710. bool PickUIElement()
  711. {
  712. Menu@ menu = GetEventSender();
  713. if (menu is null)
  714. return false;
  715. String action = GetActionName(menu.name);
  716. if (action.empty)
  717. return false;
  718. return NewUIElement(action);
  719. }
  720. // When calling items from the quick menu, they have "Create" prepended for clarity. Strip that now to get the object name to create
  721. String GetActionName(const String&in name)
  722. {
  723. if (name.StartsWith("Create"))
  724. return name.Substring(7);
  725. else
  726. return name;
  727. }
  728. void HandleMenuSelected(StringHash eventType, VariantMap& eventData)
  729. {
  730. Menu@ menu = eventData["Element"].GetPtr();
  731. if (menu is null)
  732. return;
  733. HandlePopup(menu);
  734. quickMenu.visible = false;
  735. quickMenu.enabled = false;
  736. // Execute the callback if available
  737. Variant variant = menu.GetVar(CALLBACK_VAR);
  738. if (!variant.empty)
  739. menuCallbacks[variant.GetUInt()]();
  740. }
  741. Menu@ CreateMenuItem(const String&in title, MENU_CALLBACK@ callback = null, int accelKey = 0, int accelQual = 0, bool addToQuickMenu = true, String quickMenuText="", bool autoLocalize = true)
  742. {
  743. Menu@ menu = Menu(title);
  744. menu.defaultStyle = uiStyle;
  745. menu.style = AUTO_STYLE;
  746. menu.SetLayout(LM_HORIZONTAL, 0, IntRect(8, 2, 8, 2));
  747. if (accelKey > 0)
  748. menu.SetAccelerator(accelKey, accelQual);
  749. if (callback !is null)
  750. {
  751. menu.vars[CALLBACK_VAR] = menuCallbacks.length;
  752. menuCallbacks.Push(callback);
  753. }
  754. Text@ menuText = Text();
  755. menu.AddChild(menuText);
  756. menuText.style = "EditorMenuText";
  757. menuText.text = title;
  758. menuText.autoLocalizable = autoLocalize;
  759. if (addToQuickMenu)
  760. AddQuickMenuItem(callback, quickMenuText.empty ? title : quickMenuText);
  761. if (accelKey != 0)
  762. {
  763. UIElement@ spacer = UIElement();
  764. spacer.minWidth = menuText.indentSpacing;
  765. spacer.height = menuText.height;
  766. menu.AddChild(spacer);
  767. menu.AddChild(CreateAccelKeyText(accelKey, accelQual));
  768. }
  769. return menu;
  770. }
  771. void AddQuickMenuItem(MENU_CALLBACK@ callback, String text)
  772. {
  773. if (callback is null)
  774. return;
  775. bool exists = false;
  776. for (uint i=0;i<quickMenuItems.length;++i)
  777. {
  778. if (quickMenuItems[i].action == text)
  779. {
  780. exists = true;
  781. break;
  782. }
  783. }
  784. if (!exists)
  785. quickMenuItems.Push(QuickMenuItem(text, callback));
  786. }
  787. 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="")
  788. {
  789. Menu@ menu = Menu(title);
  790. menu.defaultStyle = uiStyle;
  791. menu.style = AUTO_STYLE;
  792. menu.SetLayout(LM_VERTICAL, 0, IntRect(8, 2, 8, 2));
  793. if (accelKey > 0)
  794. menu.SetAccelerator(accelKey, accelQual);
  795. if (callback !is null)
  796. {
  797. menu.vars[CALLBACK_VAR] = menuCallbacks.length;
  798. menuCallbacks.Push(callback);
  799. }
  800. Text@ menuText = Text();
  801. menu.AddChild(menuText);
  802. menuText.style = "EditorMenuText";
  803. menuText.text = title;
  804. // If icon type is not provided, use the title instead
  805. IconizeUIElement(menuText, iconType.empty ? title : iconType);
  806. if (addToQuickMenu)
  807. AddQuickMenuItem(callback, quickMenuText.empty ? title : quickMenuText);
  808. if (accelKey != 0)
  809. {
  810. menuText.layoutMode = LM_HORIZONTAL;
  811. menuText.AddChild(CreateAccelKeyText(accelKey, accelQual));
  812. }
  813. return menu;
  814. }
  815. /// Create a child divider in parent with vertical layout mode. It works on other parent element as well, not just parent menu.
  816. void CreateChildDivider(UIElement@ parent)
  817. {
  818. BorderImage@ divider = parent.CreateChild("BorderImage", "Divider");
  819. divider.style = "EditorDivider";
  820. }
  821. Window@ CreatePopup(Menu@ baseMenu)
  822. {
  823. Window@ popup = Window();
  824. popup.defaultStyle = uiStyle;
  825. popup.style = AUTO_STYLE;
  826. popup.SetLayout(LM_VERTICAL, 1, IntRect(2, 6, 2, 6));
  827. baseMenu.popup = popup;
  828. baseMenu.popupOffset = IntVector2(0, baseMenu.height);
  829. return popup;
  830. }
  831. Menu@ CreateMenu(const String&in title)
  832. {
  833. Menu@ menu = CreateMenuItem(title);
  834. Text@ text = menu.children[0];
  835. menu.maxWidth = text.width + 20;
  836. CreatePopup(menu);
  837. return menu;
  838. }
  839. void HandleChangeLanguage(StringHash eventType, VariantMap& eventData)
  840. {
  841. Array<UIElement@> children = uiMenuBar.GetChildren();
  842. for (uint i = 0; i < children.length - 2; ++i) // last 2 elements is not menu
  843. {
  844. // dirty hack: force recalc text size
  845. children[i].maxWidth = 1000;
  846. Text@ text = children[i].children[0];
  847. text.minWidth = 0;
  848. text.maxWidth = 1;
  849. text.ApplyAttributes();
  850. children[i].maxWidth = text.width + 20;
  851. }
  852. RebuildResourceDatabase();
  853. }
  854. Text@ CreateAccelKeyText(int accelKey, int accelQual)
  855. {
  856. Text@ accelKeyText = Text();
  857. accelKeyText.defaultStyle = uiStyle;
  858. accelKeyText.style = "EditorMenuText";
  859. accelKeyText.textAlignment = HA_RIGHT;
  860. String text;
  861. if (accelKey == KEY_DELETE)
  862. text = "Del";
  863. else if (accelKey == KEY_SPACE)
  864. text = "Space";
  865. // Cannot use range as the key constants below do not appear to be in sequence
  866. else if (accelKey == KEY_F1)
  867. text = "F1";
  868. else if (accelKey == KEY_F2)
  869. text = "F2";
  870. else if (accelKey == KEY_F3)
  871. text = "F3";
  872. else if (accelKey == KEY_F4)
  873. text = "F4";
  874. else if (accelKey == KEY_F5)
  875. text = "F5";
  876. else if (accelKey == KEY_F6)
  877. text = "F6";
  878. else if (accelKey == KEY_F7)
  879. text = "F7";
  880. else if (accelKey == KEY_F8)
  881. text = "F8";
  882. else if (accelKey == KEY_F9)
  883. text = "F9";
  884. else if (accelKey == KEY_F10)
  885. text = "F10";
  886. else if (accelKey == KEY_F11)
  887. text = "F11";
  888. else if (accelKey == KEY_F12)
  889. text = "F12";
  890. else if (accelKey == SHOW_POPUP_INDICATOR)
  891. text = ">";
  892. else if (accelKey == KEY_KP_PERIOD)
  893. text = "NumPad .";
  894. else
  895. text.AppendUTF8(accelKey);
  896. if (accelQual & QUAL_ALT > 0)
  897. text = "Alt+" + text;
  898. if (accelQual & QUAL_SHIFT > 0)
  899. text = "Shift+" + text;
  900. if (accelQual & QUAL_CTRL > 0)
  901. text = "Ctrl+" + text;
  902. accelKeyText.text = text;
  903. return accelKeyText;
  904. }
  905. void FinalizedPopupMenu(Window@ popup)
  906. {
  907. // Find the maximum menu text width
  908. Array<UIElement@> children = popup.GetChildren();
  909. int maxWidth = 0;
  910. for (uint i = 0; i < children.length; ++i)
  911. {
  912. UIElement@ element = children[i];
  913. if (element.type != MENU_TYPE) // Skip if not menu item
  914. continue;
  915. int width = element.children[0].width;
  916. if (width > maxWidth)
  917. maxWidth = width;
  918. }
  919. // Adjust the indent spacing to slightly wider than the maximum width
  920. maxWidth += 20;
  921. for (uint i = 0; i < children.length; ++i)
  922. {
  923. UIElement@ element = children[i];
  924. if (element.type != MENU_TYPE)
  925. continue;
  926. Menu@ menu = element;
  927. Text@ menuText = menu.children[0];
  928. if (menuText.numChildren == 1) // Skip if menu text does not have accel
  929. menuText.children[0].indentSpacing = maxWidth;
  930. // Adjust the popup offset taking the indentation into effect
  931. if (menu.popup !is null)
  932. menu.popupOffset = IntVector2(menu.width, 0);
  933. }
  934. }
  935. void CreateFileSelector(const String&in title, const String&in ok, const String&in cancel, const String&in initialPath, Array<String>@ filters,
  936. uint initialFilter, bool autoLocalizeTitle = true)
  937. {
  938. // Within the editor UI, the file selector is a kind of a "singleton". When the previous one is overwritten, also
  939. // the events subscribed from it are disconnected, so new ones are safe to subscribe.
  940. uiFileSelector = FileSelector();
  941. uiFileSelector.defaultStyle = uiStyle;
  942. uiFileSelector.title = title;
  943. uiFileSelector.titleText.autoLocalizable = autoLocalizeTitle;
  944. uiFileSelector.path = initialPath;
  945. uiFileSelector.SetButtonTexts(ok, cancel);
  946. Text@ okText = cast<Text>(uiFileSelector.okButton.children[0]);
  947. okText.autoLocalizable = true;
  948. Text@ cancelText = cast<Text>(uiFileSelector.cancelButton.children[0]);
  949. cancelText.autoLocalizable = true;
  950. uiFileSelector.SetFilters(filters, initialFilter);
  951. CenterDialog(uiFileSelector.window);
  952. }
  953. void CloseFileSelector(uint&out filterIndex, String&out path)
  954. {
  955. // Save filter & path for next time
  956. filterIndex = uiFileSelector.filterIndex;
  957. path = uiFileSelector.path;
  958. uiFileSelector = null;
  959. }
  960. void CloseFileSelector()
  961. {
  962. uiFileSelector = null;
  963. }
  964. void CreateConsole()
  965. {
  966. Console@ console = engine.CreateConsole();
  967. console.defaultStyle = uiStyle;
  968. console.commandInterpreter = consoleCommandInterpreter;
  969. console.numBufferedRows = 100;
  970. console.autoVisibleOnError = true;
  971. }
  972. void CreateDebugHud()
  973. {
  974. engine.CreateDebugHud();
  975. debugHud.defaultStyle = uiStyle;
  976. debugHud.mode = DEBUGHUD_SHOW_NONE;
  977. }
  978. void CenterDialog(UIElement@ element)
  979. {
  980. IntVector2 size = element.size;
  981. element.SetPosition((ui.root.width - size.x) / 2, (ui.root.height - size.y) / 2);
  982. }
  983. void CreateContextMenu()
  984. {
  985. contextMenu = LoadEditorUI("UI/EditorContextMenu.xml");
  986. ui.root.AddChild(contextMenu);
  987. }
  988. void UpdateWindowTitle()
  989. {
  990. String sceneName = GetFileNameAndExtension(editorScene.fileName);
  991. if (sceneName.empty || sceneName == TEMP_SCENE_NAME || sceneName == TEMP_BINARY_SCENE_NAME)
  992. sceneName = "Untitled";
  993. if (sceneModified)
  994. sceneName += "*";
  995. graphics.windowTitle = "Urho3D editor - " + sceneName;
  996. }
  997. void HandlePopup(Menu@ menu)
  998. {
  999. // Close the top level menu now unless the selected menu item has another popup
  1000. if (menu.popup !is null)
  1001. return;
  1002. for (;;)
  1003. {
  1004. UIElement@ menuParent = menu.parent;
  1005. if (menuParent is null)
  1006. break;
  1007. Menu@ nextMenu = menuParent.vars["Origin"].GetPtr();
  1008. if (nextMenu is null)
  1009. break;
  1010. else
  1011. menu = nextMenu;
  1012. }
  1013. if (menu.parent is uiMenuBar)
  1014. menu.showPopup = false;
  1015. }
  1016. String ExtractFileName(VariantMap& eventData, bool forSave = false)
  1017. {
  1018. String fileName;
  1019. // Check for OK
  1020. if (eventData["OK"].GetBool())
  1021. {
  1022. String filter = eventData["Filter"].GetString();
  1023. fileName = eventData["FileName"].GetString();
  1024. // Add default extension for saving if not specified
  1025. if (GetExtension(fileName).empty && forSave && filter != "*.*")
  1026. fileName = fileName + filter.Substring(1);
  1027. }
  1028. return fileName;
  1029. }
  1030. void HandleOpenSceneFile(StringHash eventType, VariantMap& eventData)
  1031. {
  1032. CloseFileSelector(uiSceneFilter, uiScenePath);
  1033. LoadScene(ExtractFileName(eventData));
  1034. SendEvent(EDITOR_EVENT_SCENE_LOADED);
  1035. }
  1036. void HandleSaveSceneFile(StringHash eventType, VariantMap& eventData)
  1037. {
  1038. CloseFileSelector(uiSceneFilter, uiScenePath);
  1039. SaveScene(ExtractFileName(eventData, true));
  1040. }
  1041. void HandleLoadNodeFile(StringHash eventType, VariantMap& eventData)
  1042. {
  1043. CloseFileSelector(uiNodeFilter, uiNodePath);
  1044. LoadNode(ExtractFileName(eventData));
  1045. }
  1046. void HandleSaveNodeFile(StringHash eventType, VariantMap& eventData)
  1047. {
  1048. CloseFileSelector(uiNodeFilter, uiNodePath);
  1049. SaveNode(ExtractFileName(eventData, true));
  1050. }
  1051. void HandleImportModel(StringHash eventType, VariantMap& eventData)
  1052. {
  1053. CloseFileSelector(uiImportFilter, uiImportPath);
  1054. ImportModel(ExtractFileName(eventData));
  1055. }
  1056. void HandleImportAnimation(StringHash eventType, VariantMap& eventData)
  1057. {
  1058. CloseFileSelector(uiImportFilter, uiImportPath);
  1059. ImportAnimation(ExtractFileName(eventData));
  1060. }
  1061. void HandleImportScene(StringHash eventType, VariantMap& eventData)
  1062. {
  1063. CloseFileSelector(uiImportFilter, uiImportPath);
  1064. ImportScene(ExtractFileName(eventData));
  1065. }
  1066. void HandleExportSceneOBJ(StringHash eventType, VariantMap& eventData)
  1067. {
  1068. CloseFileSelector(uiExportFilter, uiExportPath);
  1069. ExportSceneToOBJ(ExtractFileName(eventData));
  1070. }
  1071. void HandleExportSelectedOBJ(StringHash eventType, VariantMap& eventData)
  1072. {
  1073. CloseFileSelector(uiExportFilter, uiExportPath);
  1074. ExportSelectedToOBJ(ExtractFileName(eventData));
  1075. }
  1076. void ExecuteScript(const String&in fileName)
  1077. {
  1078. if (fileName.empty)
  1079. return;
  1080. File@ file = File(fileName, FILE_READ);
  1081. if (file.open)
  1082. {
  1083. String scriptCode;
  1084. while (!file.eof)
  1085. scriptCode += file.ReadLine() + "\n";
  1086. file.Close();
  1087. if (script.Execute(scriptCode))
  1088. log.Info("Script " + fileName + " ran successfully");
  1089. }
  1090. }
  1091. void HandleRunScript(StringHash eventType, VariantMap& eventData)
  1092. {
  1093. CloseFileSelector(uiScriptFilter, uiScriptPath);
  1094. suppressSceneChanges = true;
  1095. ExecuteScript(ExtractFileName(eventData));
  1096. suppressSceneChanges = false;
  1097. UpdateHierarchyItem(editorScene, true);
  1098. UpdateHierarchyItem(editorUIElement, true);
  1099. }
  1100. void HandleResourcePath(StringHash eventType, VariantMap& eventData)
  1101. {
  1102. String pathName = uiFileSelector.path;
  1103. CloseFileSelector();
  1104. if (eventData["OK"].GetBool())
  1105. SetResourcePath(pathName, false);
  1106. }
  1107. void HandleOpenUILayoutFile(StringHash eventType, VariantMap& eventData)
  1108. {
  1109. CloseFileSelector(uiElementFilter, uiElementPath);
  1110. OpenUILayout(ExtractFileName(eventData));
  1111. }
  1112. void HandleSaveUILayoutFile(StringHash eventType, VariantMap& eventData)
  1113. {
  1114. CloseFileSelector(uiElementFilter, uiElementPath);
  1115. SaveUILayout(ExtractFileName(eventData, true));
  1116. }
  1117. void HandleLoadChildUIElementFile(StringHash eventType, VariantMap& eventData)
  1118. {
  1119. CloseFileSelector(uiElementFilter, uiElementPath);
  1120. LoadChildUIElement(ExtractFileName(eventData));
  1121. }
  1122. void HandleSaveChildUIElementFile(StringHash eventType, VariantMap& eventData)
  1123. {
  1124. CloseFileSelector(uiElementFilter, uiElementPath);
  1125. SaveChildUIElement(ExtractFileName(eventData, true));
  1126. }
  1127. void HandleUIElementDefaultStyle(StringHash eventType, VariantMap& eventData)
  1128. {
  1129. CloseFileSelector(uiElementFilter, uiElementPath);
  1130. SetUIElementDefaultStyle(ExtractFileName(eventData));
  1131. }
  1132. void HandleHotKeysBlender( VariantMap& eventData)
  1133. {
  1134. int key = eventData["Key"].GetInt();
  1135. int viewDirection = eventData["Qualifiers"].GetInt() == QUAL_CTRL ? -1 : 1;
  1136. if (key == KEY_ESCAPE)
  1137. {
  1138. if (uiHidden)
  1139. UnhideUI();
  1140. else if (console.visible)
  1141. console.visible = false;
  1142. else if (contextMenu.visible)
  1143. CloseContextMenu();
  1144. else if (quickMenu.visible)
  1145. {
  1146. quickMenu.visible = false;
  1147. quickMenu.enabled = false;
  1148. }
  1149. else
  1150. {
  1151. UIElement@ front = ui.frontElement;
  1152. if (front is settingsDialog || front is preferencesDialog)
  1153. {
  1154. ui.focusElement = null;
  1155. front.visible = false;
  1156. }
  1157. }
  1158. }
  1159. // Ignore other keys when UI has a modal element
  1160. else if (ui.HasModalElement())
  1161. return;
  1162. else if (key == KEY_F1)
  1163. console.Toggle();
  1164. else if (key == KEY_F2)
  1165. ToggleRenderingDebug();
  1166. else if (key == KEY_F3)
  1167. TogglePhysicsDebug();
  1168. else if (key == KEY_F4)
  1169. ToggleOctreeDebug();
  1170. else if (key == KEY_F5)
  1171. ToggleNavigationDebug();
  1172. else if (key == KEY_F11)
  1173. {
  1174. Image@ screenshot = Image();
  1175. graphics.TakeScreenShot(screenshot);
  1176. if (!fileSystem.DirExists(screenshotDir))
  1177. fileSystem.CreateDir(screenshotDir);
  1178. screenshot.SavePNG(screenshotDir + "/Screenshot_" +
  1179. time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
  1180. }
  1181. // In Blender, HOME key is for locating the selected objects by pan and
  1182. // the PERIOD key of keypad is for moving the camera to focus the selected.
  1183. // Here we ignore the difference.
  1184. else if ((key == KEY_HOME || key == KEY_KP_PERIOD) && ui.focusElement is null)
  1185. {
  1186. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1187. {
  1188. LocateNodesAndComponents(selectedNodes, selectedComponents);
  1189. }
  1190. }
  1191. else if (key == KEY_KP_1 && ui.focusElement is null) // Front view
  1192. {
  1193. cameraSmoothInterpolate.Finish();
  1194. Vector3 pos = -Vector3(0.0, 0.0, cameraNode.position.length * viewDirection);
  1195. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(0, 0, viewDirection));
  1196. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1197. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1198. cameraSmoothInterpolate.Start(0.5f);
  1199. }
  1200. else if ((key == KEY_KP_3 || key == KEY_KP_9) && ui.focusElement is null) // Side view
  1201. {
  1202. cameraSmoothInterpolate.Finish();
  1203. Vector3 pos = -Vector3(cameraNode.position.length * -viewDirection, 0.0, 0.0);
  1204. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(-viewDirection, 0, 0));
  1205. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1206. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1207. cameraSmoothInterpolate.Start(0.5f);
  1208. }
  1209. else if (key == KEY_KP_7 && ui.focusElement is null) // Top view
  1210. {
  1211. cameraSmoothInterpolate.Finish();
  1212. Vector3 pos = -Vector3(0.0, cameraNode.position.length * -viewDirection, 0.0);
  1213. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(0, -viewDirection, 0));
  1214. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1215. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1216. cameraSmoothInterpolate.Start(0.5f);
  1217. }
  1218. else if (key == KEY_KP_5 && ui.focusElement is null)
  1219. {
  1220. activeViewport.ToggleOrthographic();
  1221. }
  1222. else if (key == '4' && ui.focusElement is null)
  1223. editMode = EDIT_SELECT;
  1224. else if (key == '5' && ui.focusElement is null)
  1225. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1226. else if (key == '6' && ui.focusElement is null)
  1227. {
  1228. --pickMode;
  1229. if (pickMode < PICK_GEOMETRIES)
  1230. pickMode = MAX_PICK_MODES - 1;
  1231. }
  1232. else if (key == '7' && ui.focusElement is null)
  1233. {
  1234. ++pickMode;
  1235. if (pickMode >= MAX_PICK_MODES)
  1236. pickMode = PICK_GEOMETRIES;
  1237. }
  1238. else if (key == KEY_Z && eventData["Qualifiers"].GetInt() != QUAL_CTRL)
  1239. {
  1240. if (ui.focusElement is null)
  1241. {
  1242. fillMode = FillMode(fillMode + 1);
  1243. if (fillMode > FILL_POINT)
  1244. fillMode = FILL_SOLID;
  1245. // Update camera fill mode
  1246. SetFillMode(fillMode);
  1247. }
  1248. }
  1249. else if (key == KEY_SPACE)
  1250. {
  1251. if (ui.cursor.visible && ui.focusElement is null)
  1252. ToggleQuickMenu();
  1253. }
  1254. else
  1255. {
  1256. SteppedObjectManipulation(key);
  1257. }
  1258. if ((ui.focusElement is null) && (selectedNodes.length > 0) && !cameraFlyMode)
  1259. {
  1260. if (eventData["Qualifiers"].GetInt() == QUAL_ALT) // reset transformations
  1261. {
  1262. if (key == KEY_G)
  1263. SceneResetPosition();
  1264. else if (key == KEY_R)
  1265. SceneResetRotation();
  1266. else if (key == KEY_S)
  1267. SceneResetScale();
  1268. }
  1269. else if (eventData["Qualifiers"].GetInt() != QUAL_CTRL) // set transformations
  1270. {
  1271. if (key == KEY_G)
  1272. {
  1273. editMode = EDIT_MOVE;
  1274. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1275. }
  1276. else if (key == KEY_R)
  1277. {
  1278. editMode = EDIT_ROTATE;
  1279. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1280. }
  1281. else if (key == KEY_S)
  1282. {
  1283. editMode = EDIT_SCALE;
  1284. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1285. }
  1286. }
  1287. }
  1288. toolBarDirty = true;
  1289. }
  1290. void HandleHotKeysStandard(VariantMap& eventData)
  1291. {
  1292. int key = eventData["Key"].GetInt();
  1293. int viewDirection = eventData["Qualifiers"].GetInt() == QUAL_CTRL ? -1 : 1;
  1294. if (key == KEY_ESCAPE)
  1295. {
  1296. if (uiHidden)
  1297. UnhideUI();
  1298. else if (console.visible)
  1299. console.visible = false;
  1300. else if (contextMenu.visible)
  1301. CloseContextMenu();
  1302. else if (quickMenu.visible)
  1303. {
  1304. quickMenu.visible = false;
  1305. quickMenu.enabled = false;
  1306. }
  1307. else
  1308. {
  1309. UIElement@ front = ui.frontElement;
  1310. if (front is settingsDialog || front is preferencesDialog)
  1311. {
  1312. ui.focusElement = null;
  1313. front.visible = false;
  1314. }
  1315. }
  1316. }
  1317. // Ignore other keys when UI has a modal element
  1318. else if (ui.HasModalElement())
  1319. return;
  1320. else if (key == KEY_F1)
  1321. console.Toggle();
  1322. else if (key == KEY_F2)
  1323. ToggleRenderingDebug();
  1324. else if (key == KEY_F3)
  1325. TogglePhysicsDebug();
  1326. else if (key == KEY_F4)
  1327. ToggleOctreeDebug();
  1328. else if (key == KEY_F5)
  1329. ToggleNavigationDebug();
  1330. else if (key == KEY_F11)
  1331. {
  1332. Image@ screenshot = Image();
  1333. graphics.TakeScreenShot(screenshot);
  1334. if (!fileSystem.DirExists(screenshotDir))
  1335. fileSystem.CreateDir(screenshotDir);
  1336. screenshot.SavePNG(screenshotDir + "/Screenshot_" +
  1337. time.timeStamp.Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
  1338. }
  1339. else if ((key == KEY_HOME || key == KEY_F) && ui.focusElement is null)
  1340. {
  1341. if (selectedNodes.length > 0 || selectedComponents.length > 0)
  1342. {
  1343. LocateNodesAndComponents(selectedNodes, selectedComponents);
  1344. }
  1345. }
  1346. else if (key == KEY_KP_1 && ui.focusElement is null) // Front view
  1347. {
  1348. cameraSmoothInterpolate.Finish();
  1349. Vector3 pos = -Vector3(0.0, 0.0, cameraNode.position.length * viewDirection);
  1350. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(0, 0, viewDirection));
  1351. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1352. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1353. cameraSmoothInterpolate.Start(0.5f);
  1354. }
  1355. else if ((key == KEY_KP_3 || key == KEY_KP_9) && ui.focusElement is null) // Side view
  1356. {
  1357. cameraSmoothInterpolate.Finish();
  1358. Vector3 pos = -Vector3(cameraNode.position.length * -viewDirection, 0.0, 0.0);
  1359. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(-viewDirection, 0, 0));
  1360. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1361. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1362. cameraSmoothInterpolate.Start(0.5f);
  1363. }
  1364. else if (key == KEY_KP_7 && ui.focusElement is null) // Top view
  1365. {
  1366. cameraSmoothInterpolate.Finish();
  1367. Vector3 pos = -Vector3(0.0, cameraNode.position.length * -viewDirection, 0.0);
  1368. Quaternion rot = Quaternion(Vector3::FORWARD, Vector3(0, -viewDirection, 0));
  1369. cameraSmoothInterpolate.SetCameraNodePosition(cameraNode.position, pos);
  1370. cameraSmoothInterpolate.SetCameraNodeRotation(cameraNode.rotation, rot);
  1371. cameraSmoothInterpolate.Start(0.5f);
  1372. }
  1373. else if (key == KEY_KP_5 && ui.focusElement is null)
  1374. {
  1375. activeViewport.ToggleOrthographic();
  1376. }
  1377. else if (eventData["Qualifiers"].GetInt() == QUAL_CTRL)
  1378. {
  1379. if (key == '1')
  1380. editMode = EDIT_MOVE;
  1381. else if (key == '2')
  1382. editMode = EDIT_ROTATE;
  1383. else if (key == '3')
  1384. editMode = EDIT_SCALE;
  1385. else if (key == '4')
  1386. editMode = EDIT_SELECT;
  1387. else if (key == '5')
  1388. axisMode = AxisMode(axisMode ^ AXIS_LOCAL);
  1389. else if (key == '6')
  1390. {
  1391. --pickMode;
  1392. if (pickMode < PICK_GEOMETRIES)
  1393. pickMode = MAX_PICK_MODES - 1;
  1394. }
  1395. else if (key == '7')
  1396. {
  1397. ++pickMode;
  1398. if (pickMode >= MAX_PICK_MODES)
  1399. pickMode = PICK_GEOMETRIES;
  1400. }
  1401. else if (key == KEY_W)
  1402. {
  1403. fillMode = FillMode(fillMode + 1);
  1404. if (fillMode > FILL_POINT)
  1405. fillMode = FILL_SOLID;
  1406. // Update camera fill mode
  1407. SetFillMode(fillMode);
  1408. }
  1409. else if (key == KEY_SPACE)
  1410. {
  1411. if (ui.cursor.visible)
  1412. ToggleQuickMenu();
  1413. }
  1414. else
  1415. SteppedObjectManipulation(key);
  1416. toolBarDirty = true;
  1417. }
  1418. }
  1419. void HandleKeyDown(StringHash eventType, VariantMap& eventData)
  1420. {
  1421. if (hotKeyMode == HOTKEYS_MODE_STANDARD)
  1422. {
  1423. HandleHotKeysStandard(eventData);
  1424. }
  1425. else if( hotKeyMode == HOTKEYS_MODE_BLENDER)
  1426. {
  1427. HandleHotKeysBlender(eventData);
  1428. }
  1429. }
  1430. void UnfadeUI()
  1431. {
  1432. FadeUI(false);
  1433. }
  1434. void FadeUI(bool fade = true)
  1435. {
  1436. if (uiHidden || uiFaded == fade)
  1437. return;
  1438. float opacity = (uiFaded = fade) ? uiMinOpacity : uiMaxOpacity;
  1439. Array<UIElement@> children = ui.root.GetChildren();
  1440. for (uint i = 0; i < children.length; ++i)
  1441. {
  1442. // Texts, popup&modal windows (which are anyway only in ui.modalRoot), and editorUIElement are excluded
  1443. if (children[i].type != TEXT_TYPE && children[i] !is editorUIElement)
  1444. children[i].opacity = opacity;
  1445. }
  1446. }
  1447. bool ToggleUI()
  1448. {
  1449. HideUI(!uiHidden);
  1450. return true;
  1451. }
  1452. void UnhideUI()
  1453. {
  1454. HideUI(false);
  1455. }
  1456. void HideUI(bool hide = true)
  1457. {
  1458. if (uiHidden == hide)
  1459. return;
  1460. // Note: we could set ui.root.visible = false and it would hide the whole hierarchy.
  1461. // However in this case we need the editorUIElement to stay visible
  1462. bool visible = !(uiHidden = hide);
  1463. Array<UIElement@> children = ui.root.GetChildren();
  1464. for (uint i = 0; i < children.length; ++i)
  1465. {
  1466. // Cursor and editorUIElement are excluded
  1467. if (children[i].type != CURSOR_TYPE && children[i] !is editorUIElement)
  1468. {
  1469. if (visible)
  1470. {
  1471. if (!children[i].visible)
  1472. children[i].visible = children[i].vars["HideUI"].GetBool();
  1473. }
  1474. else
  1475. {
  1476. children[i].vars["HideUI"] = children[i].visible;
  1477. children[i].visible = false;
  1478. }
  1479. }
  1480. }
  1481. }
  1482. void IconizeUIElement(UIElement@ element, const String&in iconType)
  1483. {
  1484. // Check if the icon has been created before
  1485. BorderImage@ icon = element.GetChild("Icon");
  1486. // If iconType is empty, it is a request to remove the existing icon
  1487. if (iconType.empty)
  1488. {
  1489. // Remove the icon if it exists
  1490. if (icon !is null)
  1491. icon.Remove();
  1492. // Revert back the indent but only if it is indented by this function
  1493. if (element.vars[INDENT_MODIFIED_BY_ICON_VAR].GetBool())
  1494. element.indent = 0;
  1495. return;
  1496. }
  1497. // The UI element must itself has been indented to reserve the space for the icon
  1498. if (element.indent == 0)
  1499. {
  1500. element.indent = 1;
  1501. element.vars[INDENT_MODIFIED_BY_ICON_VAR] = true;
  1502. }
  1503. // If no icon yet then create one with the correct indent and size in respect to the UI element
  1504. if (icon is null)
  1505. {
  1506. // The icon is placed at one indent level less than the UI element
  1507. icon = BorderImage("Icon");
  1508. icon.indent = element.indent - 1;
  1509. icon.SetFixedSize(element.indentWidth - 2, 14);
  1510. element.InsertChild(0, icon); // Ensure icon is added as the first child
  1511. }
  1512. // Set the icon type
  1513. if (!icon.SetStyle(iconType, iconStyle))
  1514. icon.SetStyle("Unknown", iconStyle); // If fails then use an 'unknown' icon type
  1515. icon.color = Color(1,1,1,1); // Reset to enabled color
  1516. }
  1517. void SetIconEnabledColor(UIElement@ element, bool enabled, bool partial = false)
  1518. {
  1519. BorderImage@ icon = element.GetChild("Icon");
  1520. if (icon !is null)
  1521. {
  1522. if (partial)
  1523. {
  1524. icon.colors[C_TOPLEFT] = Color(1,1,1,1);
  1525. icon.colors[C_BOTTOMLEFT] = Color(1,1,1,1);
  1526. icon.colors[C_TOPRIGHT] = Color(1,0,0,1);
  1527. icon.colors[C_BOTTOMRIGHT] = Color(1,0,0,1);
  1528. }
  1529. else
  1530. icon.color = enabled ? Color(1,1,1,1) : Color(1,0,0,1);
  1531. }
  1532. }
  1533. void UpdateDirtyUI()
  1534. {
  1535. UpdateDirtyToolBar();
  1536. terrainEditor.UpdateDirty();
  1537. // Perform hierarchy selection latently after the new selections are finalized (used in undo/redo action)
  1538. if (!hierarchyUpdateSelections.empty)
  1539. {
  1540. hierarchyList.SetSelections(hierarchyUpdateSelections);
  1541. hierarchyUpdateSelections.Clear();
  1542. }
  1543. // Perform some event-triggered updates latently in case a large hierarchy was changed
  1544. if (attributesFullDirty || attributesDirty)
  1545. UpdateAttributeInspector(attributesFullDirty);
  1546. }
  1547. void HandleMessageAcknowledgement(StringHash eventType, VariantMap& eventData)
  1548. {
  1549. if (eventData["OK"].GetBool())
  1550. messageBoxCallback();
  1551. else
  1552. messageBoxCallback = null;
  1553. }
  1554. void PopulateMruScenes()
  1555. {
  1556. mruScenesPopup.RemoveAllChildren();
  1557. if (uiRecentScenes.length > 0)
  1558. {
  1559. recentSceneMenu.enabled = true;
  1560. for (uint i=0; i < uiRecentScenes.length; ++i)
  1561. mruScenesPopup.AddChild(CreateMenuItem(uiRecentScenes[i], @LoadMostRecentScene, 0, 0, false, "", false));
  1562. }
  1563. else
  1564. recentSceneMenu.enabled = false;
  1565. }
  1566. bool LoadMostRecentScene()
  1567. {
  1568. Menu@ menu = GetEventSender();
  1569. if (menu is null)
  1570. return false;
  1571. Text@ text = menu.GetChildren()[0];
  1572. if (text is null)
  1573. return false;
  1574. return LoadScene(text.text);
  1575. }
  1576. // Set from click to false if opening menu procedurally.
  1577. void OpenContextMenu(bool fromClick=true)
  1578. {
  1579. if (contextMenu is null)
  1580. return;
  1581. contextMenu.enabled = true;
  1582. contextMenu.visible = true;
  1583. contextMenu.BringToFront();
  1584. if (fromClick)
  1585. contextMenuActionWaitFrame=true;
  1586. }
  1587. void CloseContextMenu()
  1588. {
  1589. if (contextMenu is null)
  1590. return;
  1591. contextMenu.enabled = false;
  1592. contextMenu.visible = false;
  1593. }
  1594. void ActivateContextMenu(Array<UIElement@> actions)
  1595. {
  1596. contextMenu.RemoveAllChildren();
  1597. for (uint i=0; i< actions.length; ++i)
  1598. {
  1599. contextMenu.AddChild(actions[i]);
  1600. }
  1601. contextMenu.SetFixedHeight(24*actions.length+6);
  1602. contextMenu.position = ui.cursor.screenPosition + IntVector2(10,-10);
  1603. OpenContextMenu();
  1604. }
  1605. Menu@ CreateContextMenuItem(String text, String handler, String menuName = "", bool autoLocalize = true)
  1606. {
  1607. Menu@ menu = Menu();
  1608. menu.defaultStyle = uiStyle;
  1609. menu.style = AUTO_STYLE;
  1610. menu.name = menuName;
  1611. menu.SetLayout(LM_HORIZONTAL, 0, IntRect(8, 2, 8, 2));
  1612. Text@ menuText = Text();
  1613. menuText.style = "EditorMenuText";
  1614. menu.AddChild(menuText);
  1615. menuText.text = text;
  1616. menuText.autoLocalizable = autoLocalize;
  1617. menu.vars[VAR_CONTEXT_MENU_HANDLER] = handler;
  1618. SubscribeToEvent(menu, "Released", "ContextMenuEventWrapper");
  1619. return menu;
  1620. }
  1621. void ContextMenuEventWrapper(StringHash eventType, VariantMap& eventData)
  1622. {
  1623. UIElement@ uiElement = eventData["Element"].GetPtr();
  1624. if (uiElement is null)
  1625. return;
  1626. String handler = uiElement.vars[VAR_CONTEXT_MENU_HANDLER].GetString();
  1627. if (!handler.empty)
  1628. {
  1629. SubscribeToEvent(uiElement, "Released", handler);
  1630. uiElement.SendEvent("Released", eventData);
  1631. }
  1632. CloseContextMenu();
  1633. }
  1634. /// Load a UI XML file used by the editor
  1635. XMLFile@ GetEditorUIXMLFile(const String&in fileName)
  1636. {
  1637. // Prefer the executable path to avoid using the user's resource path, which may point
  1638. // to an outdated Urho installation
  1639. String fullFileName = fileSystem.programDir + "Data/" + fileName;
  1640. if (fileSystem.FileExists(fullFileName))
  1641. {
  1642. File@ file = File(fullFileName, FILE_READ);
  1643. XMLFile@ xml = XMLFile();
  1644. xml.name = fileName;
  1645. if (xml.Load(file))
  1646. return xml;
  1647. }
  1648. // Fallback to resource system
  1649. return cache.GetResource("XMLFile", fileName);
  1650. }
  1651. /// Load an UI layout used by the editor
  1652. UIElement@ LoadEditorUI(const String&in fileName)
  1653. {
  1654. return ui.LoadLayout(GetEditorUIXMLFile(fileName));
  1655. }
  1656. /// Set node children as a spline path, either cyclic or non-cyclic
  1657. bool SetSplinePath()
  1658. {
  1659. Menu@ menu = GetEventSender();
  1660. if (menu is null)
  1661. return false;
  1662. return SceneSetChildrenSplinePath(menu.name == "Cyclic");
  1663. }
  1664. bool ColorWheelBuildMenuSelectTypeColor()
  1665. {
  1666. if (selectedNodes.empty && selectedComponents.empty) return false;
  1667. editMode = EDIT_SELECT;
  1668. // do coloring only for single selected object
  1669. // start with trying to find single component
  1670. if (selectedComponents.length == 1)
  1671. {
  1672. coloringComponent = selectedComponents[0];
  1673. }
  1674. // else try to get first component from selected node
  1675. else if (selectedNodes.length == 1)
  1676. {
  1677. Array<Component@> components = selectedNodes[0].GetComponents();
  1678. if (components.length > 0)
  1679. {
  1680. coloringComponent = components[0];
  1681. }
  1682. }
  1683. else
  1684. return false;
  1685. if (coloringComponent is null) return false;
  1686. Array<UIElement@> actions;
  1687. if (coloringComponent.typeName == "Light")
  1688. {
  1689. actions.Push(CreateContextMenuItem("Light color", "HandleColorWheelMenu", "menuLightColor"));
  1690. actions.Push(CreateContextMenuItem("Specular intensity", "HandleColorWheelMenu", "menuSpecularIntensity"));
  1691. actions.Push(CreateContextMenuItem("Brightness multiplier", "HandleColorWheelMenu", "menuBrightnessMultiplier"));
  1692. actions.Push(CreateContextMenuItem("Cancel", "HandleColorWheelMenu", "menuCancel"));
  1693. }
  1694. else if (coloringComponent.typeName == "StaticModel")
  1695. {
  1696. actions.Push(CreateContextMenuItem("Diffuse color", "HandleColorWheelMenu", "menuDiffuseColor"));
  1697. actions.Push(CreateContextMenuItem("Specular color", "HandleColorWheelMenu", "menuSpecularColor"));
  1698. actions.Push(CreateContextMenuItem("Emissive color", "HandleColorWheelMenu", "menuEmissiveColor"));
  1699. actions.Push(CreateContextMenuItem("Environment map color", "HandleColorWheelMenu", "menuEnvironmentMapColor"));
  1700. actions.Push(CreateContextMenuItem("Cancel", "HandleColorWheelMenu", "menuCancel"));
  1701. }
  1702. else if (coloringComponent.typeName == "Zone")
  1703. {
  1704. actions.Push(CreateContextMenuItem("Ambient color", "HandleColorWheelMenu", "menuAmbientColor"));
  1705. actions.Push(CreateContextMenuItem("Fog color", "HandleColorWheelMenu", "menuFogColor"));
  1706. actions.Push(CreateContextMenuItem("Cancel", "HandleColorWheelMenu", "menuCancel"));
  1707. }
  1708. else if (coloringComponent.typeName == "Text3D")
  1709. {
  1710. actions.Push(CreateContextMenuItem("Color", "HandleColorWheelMenu", "c"));
  1711. actions.Push(CreateContextMenuItem("Top left color", "HandleColorWheelMenu", "tl"));
  1712. actions.Push(CreateContextMenuItem("Top right color", "HandleColorWheelMenu", "tr"));
  1713. actions.Push(CreateContextMenuItem("Bottom left color", "HandleColorWheelMenu", "bl"));
  1714. actions.Push(CreateContextMenuItem("Bottom right color", "HandleColorWheelMenu", "br"));
  1715. actions.Push(CreateContextMenuItem("Cancel", "HandleColorWheelMenu", "menuCancel"));
  1716. }
  1717. if (actions.length > 0) {
  1718. ActivateContextMenu(actions);
  1719. return true;
  1720. }
  1721. return false;
  1722. }
  1723. void HandleColorWheelMenu()
  1724. {
  1725. ColorWheelSetupBehaviorForColoring();
  1726. }
  1727. // color was changed, update color of all colorGroup for immediate preview;
  1728. void HandleWheelChangeColor(StringHash eventType, VariantMap& eventData)
  1729. {
  1730. if (timeToNextColoringGroupUpdate > time.systemTime) return;
  1731. if (coloringComponent !is null)
  1732. {
  1733. Color c = eventData["Color"].GetColor(); // current ColorWheel
  1734. // preview new color
  1735. if (coloringComponent.typeName == "Light")
  1736. {
  1737. Light@ light = cast<Light>(coloringComponent);
  1738. if (light !is null)
  1739. {
  1740. if (coloringPropertyName == "menuLightColor")
  1741. {
  1742. light.color = c;
  1743. }
  1744. else if (coloringPropertyName == "menuSpecularIntensity")
  1745. {
  1746. // multiply out
  1747. light.specularIntensity = c.Value() * 10.0f;
  1748. }
  1749. else if (coloringPropertyName == "menuBrightnessMultiplier")
  1750. {
  1751. light.brightness = c.Value() * 10.0f;
  1752. }
  1753. attributesDirty = true;
  1754. }
  1755. }
  1756. else if (coloringComponent.typeName == "StaticModel")
  1757. {
  1758. StaticModel@ model = cast<StaticModel>(coloringComponent);
  1759. if (model !is null)
  1760. {
  1761. Material@ mat = model.materials[0];
  1762. if (mat !is null)
  1763. {
  1764. if (coloringPropertyName == "menuDiffuseColor")
  1765. {
  1766. Variant oldValue = mat.shaderParameters["MatDiffColor"];
  1767. Variant newValue;
  1768. String valueString;
  1769. valueString += String(c.r).Substring(0,5);
  1770. valueString += " ";
  1771. valueString += String(c.g).Substring(0,5);
  1772. valueString += " ";
  1773. valueString += String(c.b).Substring(0,5);
  1774. valueString += " ";
  1775. valueString += String(c.a).Substring(0,5);
  1776. newValue.FromString(oldValue.type, valueString);
  1777. mat.shaderParameters["MatDiffColor"] = newValue;
  1778. }
  1779. else if (coloringPropertyName == "menuSpecularColor")
  1780. {
  1781. Variant oldValue = mat.shaderParameters["MatSpecColor"];
  1782. Variant newValue;
  1783. String valueString;
  1784. valueString += String(c.r).Substring(0,5);
  1785. valueString += " ";
  1786. valueString += String(c.g).Substring(0,5);
  1787. valueString += " ";
  1788. valueString += String(c.b).Substring(0,5);
  1789. valueString += " ";
  1790. valueString += String(c.a * 128).Substring(0,5);
  1791. newValue.FromString(oldValue.type, valueString);
  1792. mat.shaderParameters["MatSpecColor"] = newValue;
  1793. }
  1794. else if (coloringPropertyName == "menuEmissiveColor")
  1795. {
  1796. Variant oldValue = mat.shaderParameters["MatEmissiveColor"];
  1797. Variant newValue;
  1798. String valueString;
  1799. valueString += String(c.r).Substring(0,5);
  1800. valueString += " ";
  1801. valueString += String(c.g).Substring(0,5);
  1802. valueString += " ";
  1803. valueString += String(c.b).Substring(0,5);
  1804. valueString += " ";
  1805. valueString += String(c.a).Substring(0,5);
  1806. newValue.FromString(oldValue.type, valueString);
  1807. mat.shaderParameters["MatEmissiveColor"] = newValue;
  1808. }
  1809. else if (coloringPropertyName == "menuEnvironmentMapColor")
  1810. {
  1811. Variant oldValue = mat.shaderParameters["MatEnvMapColor"];
  1812. Variant newValue;
  1813. String valueString;
  1814. valueString += String(c.r).Substring(0,5);
  1815. valueString += " ";
  1816. valueString += String(c.g).Substring(0,5);
  1817. valueString += " ";
  1818. valueString += String(c.b).Substring(0,5);
  1819. valueString += " ";
  1820. valueString += String(c.a).Substring(0,5);
  1821. newValue.FromString(oldValue.type, valueString);
  1822. mat.shaderParameters["MatEnvMapColor"] = newValue;
  1823. }
  1824. }
  1825. }
  1826. }
  1827. else if (coloringComponent.typeName == "Zone")
  1828. {
  1829. Zone@ zone = cast<Zone>(coloringComponent);
  1830. if (zone !is null)
  1831. {
  1832. if (coloringPropertyName == "menuAmbientColor")
  1833. {
  1834. zone.ambientColor = c;
  1835. }
  1836. else if (coloringPropertyName == "menuFogColor")
  1837. {
  1838. zone.fogColor = c;
  1839. }
  1840. attributesDirty = true;
  1841. }
  1842. }
  1843. else if (coloringComponent.typeName == "Text3D")
  1844. {
  1845. Text3D@ txt = cast<Text3D>(coloringComponent);
  1846. if (txt !is null)
  1847. {
  1848. if (coloringPropertyName == "c")
  1849. txt.color = c;
  1850. else if (coloringPropertyName == "tl")
  1851. txt.colors[C_TOPLEFT] = c;
  1852. else if (coloringPropertyName == "tr")
  1853. txt.colors[C_TOPRIGHT] = c;
  1854. else if (coloringPropertyName == "bl")
  1855. txt.colors[C_BOTTOMLEFT] = c;
  1856. else if (coloringPropertyName == "br")
  1857. txt.colors[C_BOTTOMRIGHT] = c;
  1858. attributesDirty = true;
  1859. }
  1860. }
  1861. }
  1862. timeToNextColoringGroupUpdate = time.systemTime + stepColoringGroupUpdate;
  1863. }
  1864. // Return old colors, wheel was closed or color discarded
  1865. void HandleWheelDiscardColor(StringHash eventType, VariantMap& eventData)
  1866. {
  1867. if (coloringComponent !is null)
  1868. {
  1869. //Color oldColor = eventData["Color"].GetColor(); //Old color from ColorWheel from ShowColorWheelWithColor(old)
  1870. Color oldColor = coloringOldColor;
  1871. // preview new color
  1872. if (coloringComponent.typeName == "Light")
  1873. {
  1874. Light@ light = cast<Light>(coloringComponent);
  1875. if (light !is null)
  1876. {
  1877. if (coloringPropertyName == "menuLightColor")
  1878. {
  1879. light.color = oldColor;
  1880. }
  1881. else if (coloringPropertyName == "menuSpecularIntensity")
  1882. {
  1883. light.specularIntensity = coloringOldScalar * 10.0f;
  1884. }
  1885. else if (coloringPropertyName == "menuBrightnessMultiplier")
  1886. {
  1887. light.brightness = coloringOldScalar * 10.0f;
  1888. }
  1889. attributesDirty = true;
  1890. }
  1891. }
  1892. else if (coloringComponent.typeName == "StaticModel")
  1893. {
  1894. StaticModel@ model = cast<StaticModel>(coloringComponent);
  1895. if (model !is null)
  1896. {
  1897. Material@ mat = model.materials[0];
  1898. if (mat !is null)
  1899. {
  1900. if (coloringPropertyName == "menuDiffuseColor")
  1901. {
  1902. Variant oldValue = mat.shaderParameters["MatDiffColor"];
  1903. Variant newValue;
  1904. String valueString;
  1905. valueString += String(oldColor.r).Substring(0,5);
  1906. valueString += " ";
  1907. valueString += String(oldColor.g).Substring(0,5);
  1908. valueString += " ";
  1909. valueString += String(oldColor.b).Substring(0,5);
  1910. valueString += " ";
  1911. valueString += String(oldColor.a).Substring(0,5);
  1912. newValue.FromString(oldValue.type, valueString);
  1913. mat.shaderParameters["MatDiffColor"] = newValue;
  1914. }
  1915. else if (coloringPropertyName == "menuSpecularColor")
  1916. {
  1917. Variant oldValue = mat.shaderParameters["MatSpecColor"];
  1918. Variant newValue;
  1919. String valueString;
  1920. valueString += String(oldColor.r).Substring(0,5);
  1921. valueString += " ";
  1922. valueString += String(oldColor.g).Substring(0,5);
  1923. valueString += " ";
  1924. valueString += String(oldColor.b).Substring(0,5);
  1925. valueString += " ";
  1926. valueString += String(coloringOldScalar).Substring(0,5);
  1927. newValue.FromString(oldValue.type, valueString);
  1928. mat.shaderParameters["MatSpecColor"] = newValue;
  1929. }
  1930. else if (coloringPropertyName == "menuEmissiveColor")
  1931. {
  1932. Variant oldValue = mat.shaderParameters["MatEmissiveColor"];
  1933. Variant newValue;
  1934. String valueString;
  1935. valueString += String(oldColor.r).Substring(0,5);
  1936. valueString += " ";
  1937. valueString += String(oldColor.g).Substring(0,5);
  1938. valueString += " ";
  1939. valueString += String(oldColor.b).Substring(0,5);
  1940. valueString += " ";
  1941. valueString += String(oldColor.a).Substring(0,5);
  1942. newValue.FromString(oldValue.type, valueString);
  1943. mat.shaderParameters["MatEmissiveColor"] = newValue;
  1944. }
  1945. else if (coloringPropertyName == "menuEnvironmentMapColor")
  1946. {
  1947. Variant oldValue = mat.shaderParameters["MatEnvMapColor"];
  1948. Variant newValue;
  1949. String valueString;
  1950. valueString += String(oldColor.r).Substring(0,5);
  1951. valueString += " ";
  1952. valueString += String(oldColor.g).Substring(0,5);
  1953. valueString += " ";
  1954. valueString += String(oldColor.b).Substring(0,5);
  1955. valueString += " ";
  1956. valueString += String(oldColor.a).Substring(0,5);
  1957. newValue.FromString(oldValue.type, valueString);
  1958. mat.shaderParameters["MatEnvMapColor"] = newValue;
  1959. }
  1960. }
  1961. }
  1962. }
  1963. else if (coloringComponent.typeName == "Zone")
  1964. {
  1965. Zone@ zone = cast<Zone>(coloringComponent);
  1966. if (zone !is null)
  1967. {
  1968. if (coloringPropertyName == "menuAmbientColor")
  1969. {
  1970. zone.ambientColor = oldColor;
  1971. }
  1972. else if (coloringPropertyName == "menuFogColor")
  1973. {
  1974. zone.fogColor = oldColor;
  1975. }
  1976. attributesDirty = true;
  1977. }
  1978. }
  1979. }
  1980. }
  1981. // Applying color wheel changes to material
  1982. void HandleWheelSelectColor(StringHash eventType, VariantMap& eventData)
  1983. {
  1984. if (coloringComponent !is null)
  1985. if (coloringComponent.typeName == "StaticModel")
  1986. {
  1987. Color c = eventData["Color"].GetColor(); //Selected color from ColorWheel
  1988. StaticModel@ model = cast<StaticModel>(coloringComponent);
  1989. if (model !is null)
  1990. {
  1991. Material@ mat = model.materials[0];
  1992. if (mat !is null)
  1993. {
  1994. editMaterial = mat;
  1995. SaveMaterial();
  1996. }
  1997. }
  1998. }
  1999. }
  2000. bool ViewDebugIcons()
  2001. {
  2002. debugIconsShow = !debugIconsShow;
  2003. return true;
  2004. }