EditorUI.as 79 KB

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