EditorUI.as 79 KB

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