EditorHierarchyWindow.as 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  1. // Urho3D editor hierarchy window handling
  2. const int ITEM_NONE = 0;
  3. const int ITEM_NODE = 1;
  4. const int ITEM_COMPONENT = 2;
  5. const int ITEM_UI_ELEMENT = 3;
  6. const uint NO_ITEM = M_MAX_UNSIGNED;
  7. const StringHash SCENE_TYPE("Scene");
  8. const StringHash NODE_TYPE("Node");
  9. const StringHash STATICMODEL_TYPE("StaticModel");
  10. const StringHash ANIMATEDMODEL_TYPE("AnimatedModel");
  11. const StringHash STATICMODELGROUP_TYPE("StaticModelGroup");
  12. const StringHash SPLINEPATH_TYPE("SplinePath");
  13. const StringHash CONSTRAINT_TYPE("Constraint");
  14. const String NO_CHANGE(0);
  15. const StringHash TYPE_VAR("Type");
  16. const StringHash NODE_ID_VAR("NodeID");
  17. const StringHash COMPONENT_ID_VAR("ComponentID");
  18. const StringHash UI_ELEMENT_ID_VAR("UIElementID");
  19. const StringHash DRAGDROPCONTENT_VAR("DragDropContent");
  20. const StringHash[] ID_VARS = { StringHash(""), NODE_ID_VAR, COMPONENT_ID_VAR, UI_ELEMENT_ID_VAR };
  21. Color nodeTextColor(1.0f, 1.0f, 1.0f);
  22. Color componentTextColor(0.7f, 1.0f, 0.7f);
  23. Window@ hierarchyWindow;
  24. ListView@ hierarchyList;
  25. bool showID = true;
  26. // UIElement does not have unique ID, so use a running number to generate a new ID each time an item is inserted into hierarchy list
  27. const uint UI_ELEMENT_BASE_ID = 1;
  28. uint uiElementNextID = UI_ELEMENT_BASE_ID;
  29. bool showInternalUIElement = false;
  30. bool showTemporaryObject = false;
  31. Array<uint> hierarchyUpdateSelections;
  32. Variant GetUIElementID(UIElement@ element)
  33. {
  34. Variant elementID = element.GetVar(UI_ELEMENT_ID_VAR);
  35. if (elementID.empty)
  36. {
  37. // Generate new ID
  38. elementID = uiElementNextID++;
  39. // Store the generated ID
  40. element.vars[UI_ELEMENT_ID_VAR] = elementID;
  41. }
  42. return elementID;
  43. }
  44. UIElement@ GetUIElementByID(const Variant&in id)
  45. {
  46. return id == UI_ELEMENT_BASE_ID ? editorUIElement : editorUIElement.GetChild(UI_ELEMENT_ID_VAR, id, true);
  47. }
  48. void CreateHierarchyWindow()
  49. {
  50. if (hierarchyWindow !is null)
  51. return;
  52. hierarchyWindow = LoadEditorUI("UI/EditorHierarchyWindow.xml");
  53. hierarchyList = hierarchyWindow.GetChild("HierarchyList");
  54. ui.root.AddChild(hierarchyWindow);
  55. int height = Min(ui.root.height - 60, 500);
  56. hierarchyWindow.SetSize(300, height);
  57. hierarchyWindow.SetPosition(35, 100);
  58. hierarchyWindow.opacity = uiMaxOpacity;
  59. hierarchyWindow.BringToFront();
  60. UpdateHierarchyItem(editorScene);
  61. // Set selection to happen on click end, so that we can drag nodes to the inspector without resetting the inspector view
  62. hierarchyList.selectOnClickEnd = true;
  63. // Set drag & drop target mode on the node list background, which is used to parent nodes back to the root node
  64. hierarchyList.contentElement.dragDropMode = DD_TARGET;
  65. hierarchyList.scrollPanel.dragDropMode = DD_TARGET;
  66. SubscribeToEvent(hierarchyWindow.GetChild("CloseButton", true), "Released", "HideHierarchyWindow");
  67. SubscribeToEvent(hierarchyWindow.GetChild("ExpandButton", true), "Released", "ExpandCollapseHierarchy");
  68. SubscribeToEvent(hierarchyWindow.GetChild("CollapseButton", true), "Released", "ExpandCollapseHierarchy");
  69. SubscribeToEvent(hierarchyWindow.GetChild("ResetButton", true), "Released", "CollapseHierarchy");
  70. SubscribeToEvent(hierarchyWindow.GetChild("ShowID", true), "Toggled", "HandleShowID");
  71. SubscribeToEvent(hierarchyList, "SelectionChanged", "HandleHierarchyListSelectionChange");
  72. SubscribeToEvent(hierarchyList, "ItemDoubleClicked", "HandleHierarchyListDoubleClick");
  73. SubscribeToEvent(hierarchyList, "ItemClicked", "HandleHierarchyItemClick");
  74. SubscribeToEvent("DragDropTest", "HandleDragDropTest");
  75. SubscribeToEvent("DragDropFinish", "HandleDragDropFinish");
  76. SubscribeToEvent(editorScene, "ComponentAdded", "HandleComponentAdded");
  77. SubscribeToEvent(editorScene, "ComponentRemoved", "HandleComponentRemoved");
  78. SubscribeToEvent(editorScene, "NodeEnabledChanged", "HandleNodeEnabledChanged");
  79. SubscribeToEvent(editorScene, "ComponentEnabledChanged", "HandleComponentEnabledChanged");
  80. SubscribeToEvent("TemporaryChanged", "HandleTemporaryChanged");
  81. }
  82. bool ToggleHierarchyWindow()
  83. {
  84. if (hierarchyWindow.visible == false)
  85. ShowHierarchyWindow();
  86. else
  87. HideHierarchyWindow();
  88. return true;
  89. }
  90. void ShowHierarchyWindow()
  91. {
  92. hierarchyWindow.visible = true;
  93. hierarchyWindow.BringToFront();
  94. }
  95. void HideHierarchyWindow()
  96. {
  97. if(viewportMode == VIEWPORT_COMPACT)
  98. return;
  99. hierarchyWindow.visible = false;
  100. }
  101. void ExpandCollapseHierarchy(StringHash eventType, VariantMap& eventData)
  102. {
  103. Button@ button = eventData["Element"].GetPtr();
  104. bool enable = button.name == "ExpandButton";
  105. CheckBox@ checkBox = hierarchyWindow.GetChild("AllCheckBox", true);
  106. bool all = checkBox.checked;
  107. checkBox.checked = false; // Auto-reset
  108. Array<uint> selections = hierarchyList.selections;
  109. for (uint i = 0; i < selections.length; ++i)
  110. hierarchyList.Expand(selections[i], enable, all);
  111. }
  112. void EnableExpandCollapseButtons(bool enable)
  113. {
  114. String[] buttons = { "ExpandButton", "CollapseButton", "AllCheckBox" };
  115. for (uint i = 0; i < buttons.length; ++i)
  116. {
  117. UIElement@ element = hierarchyWindow.GetChild(buttons[i], true);
  118. element.enabled = enable;
  119. element.children[0].color = enable ? normalTextColor : nonEditableTextColor;
  120. }
  121. }
  122. void UpdateHierarchyItem(Serializable@ serializable, bool clear = false)
  123. {
  124. if (clear)
  125. {
  126. // Remove the current selection before updating the list item (in turn trigger an update on the attribute editor)
  127. hierarchyList.ClearSelection();
  128. // Clear copybuffer when whole window refreshed
  129. sceneCopyBuffer.Clear();
  130. uiElementCopyBuffer.Clear();
  131. }
  132. // In case of item's parent is not found in the hierarchy list then the item will be inserted at the list root level
  133. Serializable@ parent;
  134. switch (GetType(serializable))
  135. {
  136. case ITEM_NODE:
  137. parent = cast<Node>(serializable).parent;
  138. break;
  139. case ITEM_COMPONENT:
  140. parent = cast<Component>(serializable).node;
  141. break;
  142. case ITEM_UI_ELEMENT:
  143. parent = cast<UIElement>(serializable).parent;
  144. break;
  145. default:
  146. break;
  147. }
  148. UIElement@ parentItem = hierarchyList.items[GetListIndex(parent)];
  149. UpdateHierarchyItem(GetListIndex(serializable), serializable, parentItem);
  150. }
  151. uint UpdateHierarchyItem(uint itemIndex, Serializable@ serializable, UIElement@ parentItem)
  152. {
  153. // Whenever we're updating, disable layout update to optimize speed
  154. hierarchyList.contentElement.DisableLayoutUpdate();
  155. if (serializable is null)
  156. {
  157. hierarchyList.RemoveItem(itemIndex);
  158. hierarchyList.contentElement.EnableLayoutUpdate();
  159. hierarchyList.contentElement.UpdateLayout();
  160. return itemIndex;
  161. }
  162. int itemType = GetType(serializable);
  163. Variant id = GetID(serializable, itemType);
  164. // Remove old item if exists
  165. if (itemIndex < hierarchyList.numItems && MatchID(hierarchyList.items[itemIndex], id, itemType))
  166. hierarchyList.RemoveItem(itemIndex);
  167. Text@ text = Text();
  168. hierarchyList.InsertItem(itemIndex, text, parentItem);
  169. text.style = "FileSelectorListText";
  170. if (serializable.type == SCENE_TYPE || serializable is editorUIElement)
  171. // The root node (scene) and editor's root UIElement cannot be moved by drag and drop
  172. text.dragDropMode = DD_TARGET;
  173. else
  174. // Internal UIElement is not able to participate in drag and drop action
  175. text.dragDropMode = itemType == ITEM_UI_ELEMENT && cast<UIElement>(serializable).internal ? DD_DISABLED : DD_SOURCE_AND_TARGET;
  176. // Advance the index for the child items
  177. if (itemIndex == M_MAX_UNSIGNED)
  178. itemIndex = hierarchyList.numItems;
  179. else
  180. ++itemIndex;
  181. String iconType = serializable.typeName;
  182. if (serializable is editorUIElement)
  183. iconType = "Root" + iconType;
  184. IconizeUIElement(text, iconType);
  185. SetID(text, serializable, itemType);
  186. switch (itemType)
  187. {
  188. case ITEM_NODE:
  189. {
  190. Node@ node = cast<Node>(serializable);
  191. text.text = GetNodeTitle(node);
  192. text.color = nodeTextColor;
  193. SetIconEnabledColor(text, node.enabled);
  194. // Update components first
  195. for (uint i = 0; i < node.numComponents; ++i)
  196. {
  197. Component@ component = node.components[i];
  198. if (showTemporaryObject || !component.temporary)
  199. AddComponentItem(itemIndex++, component, text);
  200. }
  201. // Then update child nodes recursively
  202. for (uint i = 0; i < node.numChildren; ++i)
  203. {
  204. Node@ childNode = node.children[i];
  205. if (showTemporaryObject || !childNode.temporary)
  206. itemIndex = UpdateHierarchyItem(itemIndex, childNode, text);
  207. }
  208. break;
  209. }
  210. case ITEM_COMPONENT:
  211. {
  212. Component@ component = cast<Component>(serializable);
  213. text.text = GetComponentTitle(component);
  214. text.color = componentTextColor;
  215. SetIconEnabledColor(text, component.enabledEffective);
  216. break;
  217. }
  218. case ITEM_UI_ELEMENT:
  219. {
  220. UIElement@ element = cast<UIElement>(serializable);
  221. text.text = GetUIElementTitle(element);
  222. SetIconEnabledColor(text, element.visible);
  223. // Update child elements recursively
  224. for (uint i = 0; i < element.numChildren; ++i)
  225. {
  226. UIElement@ childElement = element.children[i];
  227. if ((showInternalUIElement || !childElement.internal) && (showTemporaryObject || !childElement.temporary))
  228. itemIndex = UpdateHierarchyItem(itemIndex, childElement, text);
  229. }
  230. break;
  231. }
  232. default:
  233. break;
  234. }
  235. // Re-enable layout update (and do manual layout) now
  236. hierarchyList.contentElement.EnableLayoutUpdate();
  237. hierarchyList.contentElement.UpdateLayout();
  238. return itemIndex;
  239. }
  240. void UpdateHierarchyItemText(uint itemIndex, bool iconEnabled, const String&in textTitle = NO_CHANGE)
  241. {
  242. Text@ text = hierarchyList.items[itemIndex];
  243. if (text is null)
  244. return;
  245. SetIconEnabledColor(text, iconEnabled);
  246. if (textTitle != NO_CHANGE)
  247. text.text = textTitle;
  248. }
  249. void AddComponentItem(uint compItemIndex, Component@ component, UIElement@ parentItem)
  250. {
  251. Text@ text = Text();
  252. hierarchyList.InsertItem(compItemIndex, text, parentItem);
  253. text.style = "FileSelectorListText";
  254. text.vars[TYPE_VAR] = ITEM_COMPONENT;
  255. text.vars[NODE_ID_VAR] = component.node.id;
  256. text.vars[COMPONENT_ID_VAR] = component.id;
  257. text.text = GetComponentTitle(component);
  258. text.color = componentTextColor;
  259. text.dragDropMode = DD_SOURCE_AND_TARGET;
  260. IconizeUIElement(text, component.typeName);
  261. SetIconEnabledColor(text, component.enabledEffective);
  262. }
  263. int GetType(Serializable@ serializable)
  264. {
  265. if (cast<Node>(serializable) !is null)
  266. return ITEM_NODE;
  267. else if (cast<Component>(serializable) !is null)
  268. return ITEM_COMPONENT;
  269. else if (cast<UIElement>(serializable) !is null)
  270. return ITEM_UI_ELEMENT;
  271. else
  272. return ITEM_NONE;
  273. }
  274. void SetID(Text@ text, Serializable@ serializable, int itemType = ITEM_NONE)
  275. {
  276. // If item type is not provided, auto detect it
  277. if (itemType == ITEM_NONE)
  278. itemType = GetType(serializable);
  279. text.vars[TYPE_VAR] = itemType;
  280. text.vars[ID_VARS[itemType]] = GetID(serializable, itemType);
  281. // Set node ID as drag and drop content for node ID editing
  282. if (itemType == ITEM_NODE)
  283. text.vars[DRAGDROPCONTENT_VAR] = String(text.vars[NODE_ID_VAR].GetUInt());
  284. switch (itemType)
  285. {
  286. case ITEM_COMPONENT:
  287. text.vars[NODE_ID_VAR] = cast<Component>(serializable).node.id;
  288. break;
  289. case ITEM_UI_ELEMENT:
  290. // Subscribe to UI-element events
  291. SubscribeToEvent(serializable, "NameChanged", "HandleElementNameChanged");
  292. SubscribeToEvent(serializable, "VisibleChanged", "HandleElementVisibilityChanged");
  293. SubscribeToEvent(serializable, "Resized", "HandleElementAttributeChanged");
  294. SubscribeToEvent(serializable, "Positioned", "HandleElementAttributeChanged");
  295. break;
  296. default:
  297. break;
  298. }
  299. }
  300. uint GetID(Serializable@ serializable, int itemType = ITEM_NONE)
  301. {
  302. // If item type is not provided, auto detect it
  303. if (itemType == ITEM_NONE)
  304. itemType = GetType(serializable);
  305. switch (itemType)
  306. {
  307. case ITEM_NODE:
  308. return cast<Node>(serializable).id;
  309. case ITEM_COMPONENT:
  310. return cast<Component>(serializable).id;
  311. case ITEM_UI_ELEMENT:
  312. return GetUIElementID(cast<UIElement>(serializable)).GetUInt();
  313. }
  314. return M_MAX_UNSIGNED;
  315. }
  316. bool MatchID(UIElement@ element, const Variant&in id, int itemType)
  317. {
  318. return element.GetVar(TYPE_VAR).GetInt() == itemType && element.GetVar(ID_VARS[itemType]) == id;
  319. }
  320. uint GetListIndex(Serializable@ serializable)
  321. {
  322. if (serializable is null)
  323. return NO_ITEM;
  324. int itemType = GetType(serializable);
  325. Variant id = GetID(serializable, itemType);
  326. uint numItems = hierarchyList.numItems;
  327. for (uint i = 0; i < numItems; ++i)
  328. {
  329. if (MatchID(hierarchyList.items[i], id, itemType))
  330. return i;
  331. }
  332. return NO_ITEM;
  333. }
  334. UIElement@ GetListUIElement(uint index)
  335. {
  336. UIElement@ item = hierarchyList.items[index];
  337. if (item is null)
  338. return null;
  339. // Get the text item's ID and use it to retrieve the actual UIElement the text item is associated to
  340. return GetUIElementByID(GetUIElementID(item));
  341. }
  342. Node@ GetListNode(uint index)
  343. {
  344. UIElement@ item = hierarchyList.items[index];
  345. if (item is null)
  346. return null;
  347. return editorScene.GetNode(item.vars[NODE_ID_VAR].GetUInt());
  348. }
  349. Component@ GetListComponent(uint index)
  350. {
  351. UIElement@ item = hierarchyList.items[index];
  352. return GetListComponent(item);
  353. }
  354. Component@ GetListComponent(UIElement@ item)
  355. {
  356. if (item is null)
  357. return null;
  358. if (item.vars[TYPE_VAR].GetInt() != ITEM_COMPONENT)
  359. return null;
  360. return editorScene.GetComponent(item.vars[COMPONENT_ID_VAR].GetUInt());
  361. }
  362. uint GetComponentListIndex(Component@ component)
  363. {
  364. if (component is null)
  365. return NO_ITEM;
  366. uint numItems = hierarchyList.numItems;
  367. for (uint i = 0; i < numItems; ++i)
  368. {
  369. UIElement@ item = hierarchyList.items[i];
  370. if (item.vars[TYPE_VAR].GetInt() == ITEM_COMPONENT && item.vars[COMPONENT_ID_VAR].GetUInt() == component.id)
  371. return i;
  372. }
  373. return NO_ITEM;
  374. }
  375. String GetUIElementTitle(UIElement@ element)
  376. {
  377. String ret;
  378. // Only top level UI-element has this variable
  379. String modifiedStr = element.GetVar(MODIFIED_VAR).GetBool() ? "*" : "";
  380. ret = (element.name.empty ? element.typeName : element.name) + modifiedStr + " [" + GetUIElementID(element).ToString() + "]";
  381. if (element.temporary)
  382. ret += " (Temp)";
  383. return ret;
  384. }
  385. String GetNodeTitle(Node@ node)
  386. {
  387. String ret;
  388. if (node.name.empty)
  389. ret = node.typeName;
  390. else
  391. ret = node.name;
  392. if (showID)
  393. {
  394. if (node.replicated)
  395. ret += " (" + String(node.id) + ")";
  396. else
  397. ret += " (Local " + String(node.id) + ")";
  398. if (node.temporary)
  399. ret += " (Temp)";
  400. }
  401. return ret;
  402. }
  403. String GetComponentTitle(Component@ component)
  404. {
  405. String ret = component.typeName;
  406. if (showID)
  407. {
  408. if (!component.replicated)
  409. ret += " (Local)";
  410. if (component.temporary)
  411. ret += " (Temp)";
  412. }
  413. return ret;
  414. }
  415. void SelectNode(Node@ node, bool multiselect)
  416. {
  417. if (node is null && !multiselect)
  418. {
  419. hierarchyList.ClearSelection();
  420. return;
  421. }
  422. lastSelectedNode = node;
  423. uint index = GetListIndex(node);
  424. uint numItems = hierarchyList.numItems;
  425. if (index < numItems)
  426. {
  427. // Expand the node chain now
  428. if (!multiselect || !hierarchyList.IsSelected(index))
  429. {
  430. // Go in the parent chain up to make sure the chain is expanded
  431. Node@ current = node;
  432. do
  433. {
  434. hierarchyList.Expand(GetListIndex(current), true);
  435. current = current.parent;
  436. }
  437. while (current !is null);
  438. }
  439. // This causes an event to be sent, in response we set the node/component selections, and refresh editors
  440. if (!multiselect)
  441. hierarchyList.selection = index;
  442. else
  443. hierarchyList.ToggleSelection(index);
  444. }
  445. else if (!multiselect)
  446. hierarchyList.ClearSelection();
  447. }
  448. void DeselectNode(Node@ node)
  449. {
  450. if (node is null)
  451. {
  452. hierarchyList.ClearSelection();
  453. return;
  454. }
  455. uint index = GetListIndex(node);
  456. uint numItems = hierarchyList.numItems;
  457. if (index < numItems)
  458. {
  459. hierarchyList.ToggleSelection(index);
  460. }
  461. }
  462. void SelectComponent(Component@ component, bool multiselect)
  463. {
  464. if (component is null && !multiselect)
  465. {
  466. hierarchyList.ClearSelection();
  467. return;
  468. }
  469. Node@ node = component.node;
  470. if (node is null && !multiselect)
  471. {
  472. hierarchyList.ClearSelection();
  473. return;
  474. }
  475. uint nodeIndex = GetListIndex(node);
  476. uint componentIndex = GetComponentListIndex(component);
  477. uint numItems = hierarchyList.numItems;
  478. if (nodeIndex < numItems && componentIndex < numItems)
  479. {
  480. // Expand the node chain now
  481. if (!multiselect || !hierarchyList.IsSelected(componentIndex))
  482. {
  483. // Go in the parent chain up to make sure the chain is expanded
  484. Node@ current = node;
  485. do
  486. {
  487. hierarchyList.Expand(GetListIndex(current), true);
  488. current = current.parent;
  489. }
  490. while (current !is null);
  491. }
  492. // This causes an event to be sent, in response we set the node/component selections, and refresh editors
  493. if (!multiselect)
  494. hierarchyList.selection = componentIndex;
  495. else
  496. hierarchyList.ToggleSelection(componentIndex);
  497. }
  498. else if (!multiselect)
  499. hierarchyList.ClearSelection();
  500. }
  501. void SelectUIElement(UIElement@ element, bool multiselect)
  502. {
  503. uint index = GetListIndex(element);
  504. uint numItems = hierarchyList.numItems;
  505. if (index < numItems)
  506. {
  507. // Expand the node chain now
  508. if (!multiselect || !hierarchyList.IsSelected(index))
  509. {
  510. // Go in the parent chain up to make sure the chain is expanded
  511. UIElement@ current = element;
  512. do
  513. {
  514. hierarchyList.Expand(GetListIndex(current), true);
  515. current = current.parent;
  516. }
  517. while (current !is null);
  518. }
  519. if (!multiselect)
  520. hierarchyList.selection = index;
  521. else
  522. hierarchyList.ToggleSelection(index);
  523. }
  524. else if (!multiselect)
  525. hierarchyList.ClearSelection();
  526. }
  527. // Find the first selected StaticModel/AtimatedModel component or node with it
  528. Model@ FindFirstSelectedModel()
  529. {
  530. for (uint i = 0; i < selectedComponents.length; ++i)
  531. {
  532. // Get SM, but also works well for AnimatedModel
  533. StaticModel@ sm = cast<StaticModel>(selectedComponents[i]);
  534. if (sm !is null && sm.model !is null)
  535. return sm.model;
  536. }
  537. for (uint i = 0; i < selectedNodes.length; ++i)
  538. {
  539. for (uint j = 0; j < selectedNodes[i].numComponents; ++j)
  540. {
  541. StaticModel@ sm = cast<StaticModel>(selectedNodes[i].components[j]);
  542. if (sm !is null && sm.model !is null)
  543. return sm.model;
  544. }
  545. }
  546. return null;
  547. }
  548. void UpdateModelInfo(Model@ model)
  549. {
  550. if (model is null)
  551. {
  552. modelInfoText.text = "";
  553. return;
  554. }
  555. String infoStr = "Model: " + model.name;
  556. infoStr += "\n Morphs: " + model.numMorphs;
  557. for (uint g = 0; g < model.numGeometries; ++g)
  558. {
  559. uint numLods = model.numGeometryLodLevels[g];
  560. infoStr += "\n Geometry " + g + "\n Lods: " + numLods;
  561. for (uint l = 0; l < numLods; l++)
  562. {
  563. Geometry@ geom = model.GetGeometry(g, l);
  564. infoStr += "\n Vertex Count: " + geom.vertexCount;
  565. infoStr += "\n Index Count: " + geom.indexCount;
  566. }
  567. }
  568. modelInfoText.text = infoStr;
  569. }
  570. void HandleHierarchyListSelectionChange()
  571. {
  572. if (inSelectionModify)
  573. return;
  574. ClearSceneSelection();
  575. ClearUIElementSelection();
  576. Array<uint> indices = hierarchyList.selections;
  577. // Enable Expand/Collapse button when there is selection
  578. EnableExpandCollapseButtons(indices.length > 0);
  579. for (uint i = 0; i < indices.length; ++i)
  580. {
  581. uint index = indices[i];
  582. UIElement@ item = hierarchyList.items[index];
  583. int type = item.vars[TYPE_VAR].GetInt();
  584. if (type == ITEM_COMPONENT)
  585. {
  586. Component@ comp = GetListComponent(index);
  587. if (comp !is null)
  588. selectedComponents.Push(comp);
  589. }
  590. else if (type == ITEM_NODE)
  591. {
  592. Node@ node = GetListNode(index);
  593. if (node !is null)
  594. selectedNodes.Push(node);
  595. }
  596. else if (type == ITEM_UI_ELEMENT)
  597. {
  598. UIElement@ element = GetListUIElement(index);
  599. if (element !is null && element !is editorUIElement)
  600. selectedUIElements.Push(element);
  601. }
  602. }
  603. // If only one node/UIElement selected, use it for editing
  604. if (selectedNodes.length == 1)
  605. editNode = selectedNodes[0];
  606. if (selectedUIElements.length == 1)
  607. editUIElement = selectedUIElements[0];
  608. // If selection contains only components, and they have a common node, use it for editing
  609. if (selectedNodes.empty && !selectedComponents.empty)
  610. {
  611. Node@ commonNode;
  612. for (uint i = 0; i < selectedComponents.length; ++i)
  613. {
  614. if (i == 0)
  615. commonNode = selectedComponents[i].node;
  616. else
  617. {
  618. if (selectedComponents[i].node !is commonNode)
  619. commonNode = null;
  620. }
  621. }
  622. editNode = commonNode;
  623. }
  624. UpdateModelInfo(FindFirstSelectedModel());
  625. // Now check if the component(s) can be edited. If many selected, must have same type or have same edit node
  626. if (!selectedComponents.empty)
  627. {
  628. if (editNode is null)
  629. {
  630. StringHash compType = selectedComponents[0].type;
  631. bool sameType = true;
  632. for (uint i = 1; i < selectedComponents.length; ++i)
  633. {
  634. if (selectedComponents[i].type != compType)
  635. {
  636. sameType = false;
  637. break;
  638. }
  639. }
  640. if (sameType)
  641. editComponents = selectedComponents;
  642. }
  643. else
  644. {
  645. editComponents = selectedComponents;
  646. numEditableComponentsPerNode = selectedComponents.length;
  647. }
  648. }
  649. // If just nodes selected, and no components, show as many matching components for editing as possible
  650. if (!selectedNodes.empty && selectedComponents.empty && selectedNodes[0].numComponents > 0)
  651. {
  652. uint count = 0;
  653. for (uint j = 0; j < selectedNodes[0].numComponents; ++j)
  654. {
  655. StringHash compType = selectedNodes[0].components[j].type;
  656. bool sameType = true;
  657. for (uint i = 1; i < selectedNodes.length; ++i)
  658. {
  659. if (selectedNodes[i].numComponents <= j || selectedNodes[i].components[j].type != compType)
  660. {
  661. sameType = false;
  662. break;
  663. }
  664. }
  665. if (sameType)
  666. {
  667. ++count;
  668. for (uint i = 0; i < selectedNodes.length; ++i)
  669. editComponents.Push(selectedNodes[i].components[j]);
  670. }
  671. }
  672. if (count > 1)
  673. numEditableComponentsPerNode = count;
  674. }
  675. if (selectedNodes.empty && editNode !is null)
  676. editNodes.Push(editNode);
  677. else
  678. {
  679. editNodes = selectedNodes;
  680. // Cannot multi-edit on scene and node(s) together as scene and node do not share identical attributes,
  681. // editing via gizmo does not make too much sense either
  682. if (editNodes.length > 1 && editNodes[0] is editorScene)
  683. editNodes.Erase(0);
  684. }
  685. if (selectedUIElements.empty && editUIElement !is null)
  686. editUIElements.Push(editUIElement);
  687. else
  688. editUIElements = selectedUIElements;
  689. PositionGizmo();
  690. UpdateAttributeInspector();
  691. UpdateCameraPreview();
  692. }
  693. void HandleHierarchyListDoubleClick(StringHash eventType, VariantMap& eventData)
  694. {
  695. UIElement@ item = eventData["Item"].GetPtr();
  696. int type = item.vars[TYPE_VAR].GetInt();
  697. // Locate nodes from the scene by double-clicking
  698. if (type == ITEM_NODE)
  699. {
  700. Node@ node = editorScene.GetNode(item.vars[NODE_ID_VAR].GetUInt());
  701. Array<Node@> nodes;
  702. nodes.Push(node);
  703. LocateNodes(nodes);
  704. }
  705. else if (type == ITEM_COMPONENT)
  706. {
  707. Component@ component = editorScene.GetComponent(item.vars[COMPONENT_ID_VAR].GetUInt());
  708. Array<Component@> components;
  709. components.Push(component);
  710. LocateComponents(components);
  711. }
  712. bool isExpanded = hierarchyList.IsExpanded(hierarchyList.selection);
  713. if (!isExpanded && eventData["Button"].GetInt() == MOUSEB_LEFT)
  714. {
  715. isExpanded = !isExpanded;
  716. hierarchyList.Expand(hierarchyList.selection, isExpanded, false);
  717. }
  718. }
  719. void HandleHierarchyItemClick(StringHash eventType, VariantMap& eventData)
  720. {
  721. if (eventData["Button"].GetInt() != MOUSEB_RIGHT)
  722. return;
  723. UIElement@ uiElement = eventData["Item"].GetPtr();
  724. int selectionIndex = eventData["Selection"].GetInt();
  725. Array<UIElement@> actions;
  726. int type = uiElement.vars[TYPE_VAR].GetInt();
  727. // Adds left clicked items to selection which is not normal listview behavior
  728. if (type == ITEM_COMPONENT || type == ITEM_NODE)
  729. {
  730. if (input.keyDown[KEY_LSHIFT])
  731. hierarchyList.AddSelection(selectionIndex);
  732. else
  733. {
  734. hierarchyList.ClearSelection();
  735. hierarchyList.AddSelection(selectionIndex);
  736. }
  737. }
  738. if (type == ITEM_COMPONENT)
  739. {
  740. Component@ targetComponent = editorScene.GetComponent(uiElement.vars[COMPONENT_ID_VAR].GetUInt());
  741. if (targetComponent is null)
  742. return;
  743. actions.Push(CreateContextMenuItem("Copy", "HandleHierarchyContextCopy"));
  744. actions.Push(CreateContextMenuItem("Cut", "HandleHierarchyContextCut"));
  745. actions.Push(CreateContextMenuItem("Delete", "HandleHierarchyContextDelete"));
  746. actions.Push(CreateContextMenuItem("Paste", "HandleHierarchyContextPaste"));
  747. actions.Push(CreateContextMenuItem("Enable/disable", "HandleHierarchyContextEnableDisable"));
  748. /* actions.Push(CreateBrowserFileActionMenu("Edit", "HandleBrowserEditResource", file)); */
  749. }
  750. else if (type == ITEM_NODE)
  751. {
  752. actions.Push(CreateContextMenuItem("Create Replicated Node", "HandleHierarchyContextCreateReplicatedNode"));
  753. actions.Push(CreateContextMenuItem("Create Local Node", "HandleHierarchyContextCreateLocalNode"));
  754. actions.Push(CreateContextMenuItem("Duplicate", "HandleHierarchyContextDuplicate"));
  755. actions.Push(CreateContextMenuItem("Copy", "HandleHierarchyContextCopy"));
  756. actions.Push(CreateContextMenuItem("Cut", "HandleHierarchyContextCut"));
  757. actions.Push(CreateContextMenuItem("Delete", "HandleHierarchyContextDelete"));
  758. actions.Push(CreateContextMenuItem("Paste", "HandleHierarchyContextPaste"));
  759. actions.Push(CreateContextMenuItem("Reset to default", "HandleHierarchyContextResetToDefault"));
  760. actions.Push(CreateContextMenuItem("Reset position", "HandleHierarchyContextResetPosition"));
  761. actions.Push(CreateContextMenuItem("Reset rotation", "HandleHierarchyContextResetRotation"));
  762. actions.Push(CreateContextMenuItem("Reset scale", "HandleHierarchyContextResetScale"));
  763. actions.Push(CreateContextMenuItem("Enable/disable", "HandleHierarchyContextEnableDisable"));
  764. actions.Push(CreateContextMenuItem("Unparent", "HandleHierarchyContextUnparent"));
  765. }
  766. else if (type == ITEM_UI_ELEMENT)
  767. {
  768. // close ui element
  769. actions.Push(CreateContextMenuItem("Close UI-Layout", "HandleHierarchyContextUIElementCloseUILayout"));
  770. actions.Push(CreateContextMenuItem("Close all UI-layouts", "HandleHierarchyContextUIElementCloseAllUILayouts"));
  771. }
  772. if (actions.length > 0)
  773. ActivateContextMenu(actions);
  774. }
  775. void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
  776. {
  777. UIElement@ source = eventData["Source"].GetPtr();
  778. UIElement@ target = eventData["Target"].GetPtr();
  779. int itemType;
  780. eventData["Accept"] = TestDragDrop(source, target, itemType);
  781. }
  782. void HandleDragDropFinish(StringHash eventType, VariantMap& eventData)
  783. {
  784. UIElement@ source = eventData["Source"].GetPtr();
  785. UIElement@ target = eventData["Target"].GetPtr();
  786. int itemType = ITEM_NONE;
  787. bool accept = TestDragDrop(source, target, itemType);
  788. eventData["Accept"] = accept;
  789. if (!accept)
  790. return;
  791. // Resource browser
  792. if (source !is null && source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt() > 0)
  793. {
  794. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  795. BrowserFile@ browserFile = GetBrowserFileFromId(source.vars[TEXT_VAR_FILE_ID].GetUInt());
  796. if (browserFile is null)
  797. return;
  798. Component@ createdComponent;
  799. if (itemType == ITEM_NODE)
  800. {
  801. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  802. if (targetNode is null)
  803. return;
  804. if (type == RESOURCE_TYPE_PREFAB)
  805. {
  806. LoadNode(browserFile.GetFullPath(), targetNode);
  807. }
  808. else if(type == RESOURCE_TYPE_SCRIPTFILE)
  809. {
  810. // TODO: not sure what to do here. lots of choices.
  811. }
  812. else if(type == RESOURCE_TYPE_MODEL)
  813. {
  814. CreateModelWithStaticModel(browserFile.resourceKey, targetNode);
  815. return;
  816. }
  817. else if (type == RESOURCE_TYPE_PARTICLEEFFECT)
  818. {
  819. if (browserFile.extension == "xml")
  820. {
  821. ParticleEffect@ effect = cache.GetResource("ParticleEffect", browserFile.resourceKey);
  822. if (effect is null)
  823. return;
  824. ParticleEmitter@ emitter = targetNode.CreateComponent("ParticleEmitter");
  825. emitter.effect = effect;
  826. createdComponent = emitter;
  827. }
  828. }
  829. else if (type == RESOURCE_TYPE_2D_PARTICLE_EFFECT)
  830. {
  831. if (browserFile.extension == "xml")
  832. {
  833. Resource@ effect = cache.GetResource("ParticleEffect2D", browserFile.resourceKey);
  834. if (effect is null)
  835. return;
  836. ResourceRef effectRef;
  837. effectRef.type = effect.type;
  838. effectRef.name = effect.name;
  839. Component@ emitter = targetNode.CreateComponent("ParticleEmitter2D");
  840. emitter.SetAttribute("Particle Effect", Variant(effectRef));
  841. createdComponent = emitter;
  842. }
  843. }
  844. }
  845. else if (itemType == ITEM_COMPONENT)
  846. {
  847. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  848. if (targetComponent is null)
  849. return;
  850. if (type == RESOURCE_TYPE_MATERIAL)
  851. {
  852. StaticModel@ model = cast<StaticModel>(targetComponent);
  853. if (model is null)
  854. return;
  855. AssignMaterial(model, browserFile.resourceKey);
  856. }
  857. else if (type == RESOURCE_TYPE_MODEL)
  858. {
  859. StaticModel@ staticModel = cast<StaticModel>(targetComponent);
  860. if (staticModel is null)
  861. return;
  862. AssignModel(staticModel, browserFile.resourceKey);
  863. }
  864. }
  865. else
  866. {
  867. LineEdit@ text = cast<LineEdit>(target);
  868. if (text is null)
  869. return;
  870. text.text = browserFile.resourceKey;
  871. VariantMap data();
  872. data["Element"] = text;
  873. data["Text"] = text.text;
  874. text.SendEvent("TextFinished", data);
  875. }
  876. if (createdComponent !is null)
  877. {
  878. CreateLoadedComponent(createdComponent);
  879. }
  880. return;
  881. }
  882. if (itemType == ITEM_NODE)
  883. {
  884. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  885. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  886. if (sourceNodes.length > 0)
  887. {
  888. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  889. SceneReorder(sourceNodes[0], targetNode);
  890. else
  891. {
  892. // If target is null, parent to scene
  893. if (targetNode is null)
  894. targetNode = editorScene;
  895. if (sourceNodes.length > 1)
  896. SceneChangeParent(sourceNodes[0], sourceNodes, targetNode);
  897. else
  898. SceneChangeParent(sourceNodes[0], targetNode);
  899. }
  900. // Focus the node at its new position in the list which in turn should trigger a refresh in attribute inspector
  901. FocusNode(sourceNodes[0]);
  902. }
  903. }
  904. else if (itemType == ITEM_UI_ELEMENT)
  905. {
  906. UIElement@ sourceElement = GetUIElementByID(source.vars[UI_ELEMENT_ID_VAR].GetUInt());
  907. UIElement@ targetElement = GetUIElementByID(target.vars[UI_ELEMENT_ID_VAR].GetUInt());
  908. // If target is null, cannot proceed
  909. if (targetElement is null)
  910. return;
  911. if (input.qualifierDown[QUAL_CTRL])
  912. {
  913. if (!UIElementReorder(sourceElement, targetElement))
  914. return;
  915. }
  916. else
  917. {
  918. if (!UIElementChangeParent(sourceElement, targetElement))
  919. return;
  920. }
  921. // Focus the element at its new position in the list which in turn should trigger a refresh in attribute inspector
  922. FocusUIElement(sourceElement);
  923. }
  924. else if (itemType == ITEM_COMPONENT)
  925. {
  926. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  927. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  928. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  929. {
  930. // Reorder components within node
  931. Component@ sourceComponent = editorScene.GetComponent(source.vars[COMPONENT_ID_VAR].GetUInt());
  932. SceneReorder(sourceComponent, targetComponent);
  933. }
  934. else
  935. {
  936. if (targetComponent !is null && sourceNodes.length > 0)
  937. {
  938. // Drag node to StaticModelGroup to make it an instance
  939. StaticModelGroup@ smg = cast<StaticModelGroup>(targetComponent);
  940. if (smg !is null)
  941. {
  942. // Save undo action
  943. EditAttributeAction action;
  944. uint attrIndex = GetAttributeIndex(smg, "Instance Nodes");
  945. Variant oldIDs = smg.attributes[attrIndex];
  946. for (uint i = 0; i < sourceNodes.length; ++i)
  947. smg.AddInstanceNode(sourceNodes[i]);
  948. action.Define(smg, attrIndex, oldIDs);
  949. SaveEditAction(action);
  950. SetSceneModified();
  951. UpdateAttributeInspector(false);
  952. }
  953. // Drag node to SplinePath to make it a control point
  954. SplinePath@ spline = cast<SplinePath>(targetComponent);
  955. if (spline !is null)
  956. {
  957. // Save undo action
  958. EditAttributeAction action;
  959. uint attrIndex = GetAttributeIndex(spline, "Control Points");
  960. Variant oldIDs = spline.attributes[attrIndex];
  961. for (uint i = 0; i < sourceNodes.length; ++i)
  962. spline.AddControlPoint(sourceNodes[i]);
  963. action.Define(spline, attrIndex, oldIDs);
  964. SaveEditAction(action);
  965. SetSceneModified();
  966. UpdateAttributeInspector(false);
  967. }
  968. // Drag a node to Constraint to make it the remote end of the constraint
  969. Constraint@ constraint = cast<Constraint>(targetComponent);
  970. RigidBody@ rigidBody = sourceNodes[0].GetComponent("RigidBody");
  971. if (constraint !is null && rigidBody !is null)
  972. {
  973. // Save undo action
  974. EditAttributeAction action;
  975. uint attrIndex = GetAttributeIndex(constraint, "Other Body NodeID");
  976. Variant oldID = constraint.attributes[attrIndex];
  977. constraint.otherBody = rigidBody;
  978. action.Define(constraint, attrIndex, oldID);
  979. SaveEditAction(action);
  980. SetSceneModified();
  981. UpdateAttributeInspector(false);
  982. }
  983. }
  984. }
  985. }
  986. }
  987. Array<Node@> GetMultipleSourceNodes(UIElement@ source)
  988. {
  989. Array<Node@> nodeList;
  990. Node@ node = editorScene.GetNode(source.vars[NODE_ID_VAR].GetUInt());
  991. if (node !is null)
  992. nodeList.Push(node);
  993. // Handle additional selected children from a ListView
  994. if (source.parent !is null && source.parent.typeName == "HierarchyContainer")
  995. {
  996. ListView@ listView_ = cast<ListView>(source.parent.parent.parent);
  997. if (listView_ is null)
  998. return nodeList;
  999. bool sourceIsSelected = false;
  1000. for (uint i = 0; i < listView_.selectedItems.length; ++i)
  1001. {
  1002. if (listView_.selectedItems[i] is source)
  1003. {
  1004. sourceIsSelected = true;
  1005. break;
  1006. }
  1007. }
  1008. if (sourceIsSelected)
  1009. {
  1010. for (uint i = 0; i < listView_.selectedItems.length; ++i)
  1011. {
  1012. UIElement@ item_ = listView_.selectedItems[i];
  1013. // The source item is already added
  1014. if (item_ is source)
  1015. continue;
  1016. if (item_.vars[TYPE_VAR] == ITEM_NODE)
  1017. {
  1018. Node@ n = editorScene.GetNode(item_.vars[NODE_ID_VAR].GetUInt());
  1019. if (n !is null)
  1020. nodeList.Push(n);
  1021. }
  1022. }
  1023. }
  1024. }
  1025. return nodeList;
  1026. }
  1027. bool TestDragDrop(UIElement@ source, UIElement@ target, int& itemType)
  1028. {
  1029. int targetItemType = target.GetVar(TYPE_VAR).GetInt();
  1030. if (targetItemType == ITEM_NODE)
  1031. {
  1032. Node@ sourceNode;
  1033. Node@ targetNode;
  1034. Variant variant = source.GetVar(NODE_ID_VAR);
  1035. if (!variant.empty)
  1036. sourceNode = editorScene.GetNode(variant.GetUInt());
  1037. variant = target.GetVar(NODE_ID_VAR);
  1038. if (!variant.empty)
  1039. targetNode = editorScene.GetNode(variant.GetUInt());
  1040. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  1041. if (sourceNode !is null && targetNode !is null)
  1042. {
  1043. itemType = ITEM_NODE;
  1044. // Ctrl pressed: reorder
  1045. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  1046. {
  1047. // Must be within the same parent
  1048. if (sourceNode.parent is null || sourceNode.parent !is targetNode.parent)
  1049. return false;
  1050. }
  1051. // No ctrl: Reparent
  1052. else
  1053. {
  1054. if (sourceNode.parent is targetNode)
  1055. return false;
  1056. if (targetNode.parent is sourceNode)
  1057. return false;
  1058. }
  1059. }
  1060. // Resource browser
  1061. if (sourceNode is null && targetNode !is null)
  1062. {
  1063. itemType = ITEM_NODE;
  1064. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1065. return type == RESOURCE_TYPE_PREFAB ||
  1066. type == RESOURCE_TYPE_SCRIPTFILE ||
  1067. type == RESOURCE_TYPE_MODEL ||
  1068. type == RESOURCE_TYPE_PARTICLEEFFECT ||
  1069. type == RESOURCE_TYPE_2D_PARTICLE_EFFECT;
  1070. }
  1071. return true;
  1072. }
  1073. else if (targetItemType == ITEM_UI_ELEMENT)
  1074. {
  1075. UIElement@ sourceElement;
  1076. UIElement@ targetElement;
  1077. Variant variant = source.GetVar(UI_ELEMENT_ID_VAR);
  1078. if (!variant.empty)
  1079. sourceElement = GetUIElementByID(variant.GetUInt());
  1080. variant = target.GetVar(UI_ELEMENT_ID_VAR);
  1081. if (!variant.empty)
  1082. targetElement = GetUIElementByID(variant.GetUInt());
  1083. if (sourceElement !is null && targetElement !is null)
  1084. {
  1085. itemType = ITEM_UI_ELEMENT;
  1086. // Ctrl pressed: reorder
  1087. if (input.qualifierDown[QUAL_CTRL])
  1088. {
  1089. // Must be within the same parent
  1090. if (sourceElement.parent is null || sourceElement.parent !is targetElement.parent)
  1091. return false;
  1092. }
  1093. // No ctrl: reparent
  1094. else
  1095. {
  1096. if (sourceElement.parent is targetElement)
  1097. return false;
  1098. if (targetElement.parent is sourceElement)
  1099. return false;
  1100. }
  1101. }
  1102. return true;
  1103. }
  1104. else if (targetItemType == ITEM_COMPONENT)
  1105. {
  1106. Node@ sourceNode;
  1107. Component@ sourceComponent;
  1108. Component@ targetComponent;
  1109. Variant variant = source.GetVar(NODE_ID_VAR);
  1110. if (!variant.empty)
  1111. sourceNode = editorScene.GetNode(variant.GetUInt());
  1112. variant = target.GetVar(COMPONENT_ID_VAR);
  1113. if (!variant.empty)
  1114. targetComponent = editorScene.GetComponent(variant.GetUInt());
  1115. variant = source.GetVar(COMPONENT_ID_VAR);
  1116. if (!variant.empty)
  1117. sourceComponent = editorScene.GetComponent(variant.GetUInt());
  1118. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  1119. itemType = ITEM_COMPONENT;
  1120. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  1121. {
  1122. // Reorder components within node
  1123. if (sourceComponent !is null && targetComponent !is null && sourceComponent.node is targetComponent.node)
  1124. return true;
  1125. }
  1126. else
  1127. {
  1128. // Dragging of nodes to StaticModelGroup, SplinePath or Constraint
  1129. if (sourceNode !is null && targetComponent !is null && (targetComponent.type == STATICMODELGROUP_TYPE ||
  1130. targetComponent.type == CONSTRAINT_TYPE || targetComponent.type == SPLINEPATH_TYPE))
  1131. return true;
  1132. // Resource browser
  1133. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1134. if (targetComponent.type == STATICMODEL_TYPE || targetComponent.type == ANIMATEDMODEL_TYPE)
  1135. return type == RESOURCE_TYPE_MATERIAL || type == RESOURCE_TYPE_MODEL;
  1136. }
  1137. return false;
  1138. }
  1139. else if (source.vars.Contains(TEXT_VAR_RESOURCE_TYPE)) // only testing resource browser ui elements
  1140. {
  1141. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1142. // Test against resource pickers
  1143. LineEdit@ lineEdit = cast<LineEdit>(target);
  1144. if (lineEdit !is null)
  1145. {
  1146. StringHash resourceType = GetResourceTypeFromPickerLineEdit(lineEdit);
  1147. if (resourceType == StringHash("Material") && type == RESOURCE_TYPE_MATERIAL)
  1148. return true;
  1149. else if (resourceType == StringHash("Model") && type == RESOURCE_TYPE_MODEL)
  1150. return true;
  1151. else if (resourceType == StringHash("Animation") && type == RESOURCE_TYPE_ANIMATION)
  1152. return true;
  1153. }
  1154. }
  1155. return true;
  1156. }
  1157. StringHash GetResourceTypeFromPickerLineEdit(UIElement@ lineEdit)
  1158. {
  1159. Array<Serializable@>@ targets = GetAttributeEditorTargets(lineEdit);
  1160. if (!targets.empty)
  1161. {
  1162. resourcePickIndex = lineEdit.vars["Index"].GetUInt();
  1163. resourcePickSubIndex = lineEdit.vars["SubIndex"].GetUInt();
  1164. AttributeInfo info = targets[0].attributeInfos[resourcePickIndex];
  1165. StringHash resourceType;
  1166. if (info.type == VAR_RESOURCEREF)
  1167. return targets[0].attributes[resourcePickIndex].GetResourceRef().type;
  1168. else if (info.type == VAR_RESOURCEREFLIST)
  1169. return targets[0].attributes[resourcePickIndex].GetResourceRefList().type;
  1170. else if (info.type == VAR_VARIANTVECTOR)
  1171. return targets[0].attributes[resourcePickIndex].GetVariantVector()[resourcePickSubIndex].GetResourceRef().type;
  1172. }
  1173. return StringHash();
  1174. }
  1175. void FocusNode(Node@ node)
  1176. {
  1177. uint index = GetListIndex(node);
  1178. hierarchyList.selection = index;
  1179. }
  1180. void FocusComponent(Component@ component)
  1181. {
  1182. uint index = GetComponentListIndex(component);
  1183. hierarchyList.selection = index;
  1184. }
  1185. void FocusUIElement(UIElement@ element)
  1186. {
  1187. uint index = GetListIndex(element);
  1188. hierarchyList.selection = index;
  1189. }
  1190. void CreateBuiltinObject(const String& name)
  1191. {
  1192. Node@ newNode = editorScene.CreateChild(name, REPLICATED);
  1193. // Set the new node a certain distance from the camera
  1194. newNode.position = GetNewNodePosition();
  1195. StaticModel@ object = newNode.CreateComponent("StaticModel");
  1196. object.model = cache.GetResource("Model", "Models/" + name + ".mdl");
  1197. // Create an undo action for the create
  1198. CreateNodeAction action;
  1199. action.Define(newNode);
  1200. SaveEditAction(action);
  1201. SetSceneModified();
  1202. FocusNode(newNode);
  1203. }
  1204. bool CheckHierarchyWindowFocus()
  1205. {
  1206. // When we do edit operations based on key shortcuts, make sure the hierarchy list is focused
  1207. return ui.focusElement is hierarchyList || ui.focusElement is null;
  1208. }
  1209. bool CheckForExistingGlobalComponent(Node@ node, const String&in typeName)
  1210. {
  1211. if (typeName != "Octree" && typeName != "PhysicsWorld" && typeName != "DebugRenderer")
  1212. return false;
  1213. else
  1214. return node.HasComponent(typeName);
  1215. }
  1216. void HandleNodeAdded(StringHash eventType, VariantMap& eventData)
  1217. {
  1218. if (suppressSceneChanges)
  1219. return;
  1220. Node@ node = eventData["Node"].GetPtr();
  1221. if (showTemporaryObject || !node.temporary)
  1222. UpdateHierarchyItem(node);
  1223. }
  1224. void HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  1225. {
  1226. if (suppressSceneChanges)
  1227. return;
  1228. Node@ node = eventData["Node"].GetPtr();
  1229. if (showTemporaryObject || !node.temporary)
  1230. UpdateHierarchyItem(GetListIndex(node), null, null);
  1231. }
  1232. void HandleComponentAdded(StringHash eventType, VariantMap& eventData)
  1233. {
  1234. if (suppressSceneChanges)
  1235. return;
  1236. // Insert the newly added component at last component position but before the first child node position of the parent node
  1237. Node@ node = eventData["Node"].GetPtr();
  1238. Component@ component = eventData["Component"].GetPtr();
  1239. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1240. {
  1241. uint nodeIndex = GetListIndex(node);
  1242. if (nodeIndex != NO_ITEM)
  1243. {
  1244. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  1245. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  1246. }
  1247. }
  1248. }
  1249. void HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
  1250. {
  1251. if (suppressSceneChanges)
  1252. return;
  1253. Node@ node = eventData["Node"].GetPtr();
  1254. Component@ component = eventData["Component"].GetPtr();
  1255. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1256. {
  1257. uint index = GetComponentListIndex(component);
  1258. if (index != NO_ITEM)
  1259. hierarchyList.RemoveItem(index);
  1260. }
  1261. }
  1262. void HandleNodeNameChanged(StringHash eventType, VariantMap& eventData)
  1263. {
  1264. if (suppressSceneChanges)
  1265. return;
  1266. Node@ node = eventData["Node"].GetPtr();
  1267. if (showTemporaryObject || !node.temporary)
  1268. UpdateHierarchyItemText(GetListIndex(node), node.enabled, GetNodeTitle(node));
  1269. }
  1270. void HandleNodeEnabledChanged(StringHash eventType, VariantMap& eventData)
  1271. {
  1272. if (suppressSceneChanges)
  1273. return;
  1274. Node@ node = eventData["Node"].GetPtr();
  1275. if (showTemporaryObject || !node.temporary)
  1276. {
  1277. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  1278. attributesDirty = true;
  1279. }
  1280. }
  1281. void HandleComponentEnabledChanged(StringHash eventType, VariantMap& eventData)
  1282. {
  1283. if (suppressSceneChanges)
  1284. return;
  1285. Node@ node = eventData["Node"].GetPtr();
  1286. Component@ component = eventData["Component"].GetPtr();
  1287. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1288. {
  1289. UpdateHierarchyItemText(GetComponentListIndex(component), component.enabledEffective);
  1290. attributesDirty = true;
  1291. }
  1292. }
  1293. void HandleUIElementAdded(StringHash eventType, VariantMap& eventData)
  1294. {
  1295. if (suppressUIElementChanges)
  1296. return;
  1297. UIElement@ element = eventData["Element"].GetPtr();
  1298. if ((showInternalUIElement || !element.internal) && (showTemporaryObject || !element.temporary))
  1299. UpdateHierarchyItem(element);
  1300. }
  1301. void HandleUIElementRemoved(StringHash eventType, VariantMap& eventData)
  1302. {
  1303. if (suppressUIElementChanges)
  1304. return;
  1305. UIElement@ element = eventData["Element"].GetPtr();
  1306. UpdateHierarchyItem(GetListIndex(element), null, null);
  1307. }
  1308. void HandleElementNameChanged(StringHash eventType, VariantMap& eventData)
  1309. {
  1310. if (suppressUIElementChanges)
  1311. return;
  1312. UIElement@ element = eventData["Element"].GetPtr();
  1313. UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
  1314. }
  1315. void HandleElementVisibilityChanged(StringHash eventType, VariantMap& eventData)
  1316. {
  1317. if (suppressUIElementChanges)
  1318. return;
  1319. UIElement@ element = eventData["Element"].GetPtr();
  1320. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  1321. }
  1322. void HandleElementAttributeChanged(StringHash eventType, VariantMap& eventData)
  1323. {
  1324. // Do not refresh the attribute inspector while the attribute is being edited via the attribute-editors
  1325. if (suppressUIElementChanges || inEditAttribute)
  1326. return;
  1327. UIElement@ element = eventData["Element"].GetPtr();
  1328. for (uint i = 0; i < editUIElements.length; ++i)
  1329. {
  1330. if (editUIElements[i] is element)
  1331. attributesDirty = true;
  1332. }
  1333. }
  1334. void HandleTemporaryChanged(StringHash eventType, VariantMap& eventData)
  1335. {
  1336. if (suppressSceneChanges || suppressUIElementChanges)
  1337. return;
  1338. Serializable@ serializable = cast<Serializable>(GetEventSender());
  1339. Node@ node = cast<Node>(serializable);
  1340. if (node !is null && node.scene is editorScene)
  1341. {
  1342. if (showTemporaryObject)
  1343. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  1344. else if (!node.temporary && GetListIndex(node) == NO_ITEM)
  1345. UpdateHierarchyItem(node);
  1346. else if (node.temporary)
  1347. UpdateHierarchyItem(GetListIndex(node), null, null);
  1348. return;
  1349. }
  1350. Component@ component = cast<Component>(serializable);
  1351. if (component !is null && component.node !is null && component.node.scene is editorScene)
  1352. {
  1353. node = component.node;
  1354. if (showTemporaryObject)
  1355. UpdateHierarchyItemText(GetComponentListIndex(component), node.enabled);
  1356. else if (!component.temporary && GetComponentListIndex(component) == NO_ITEM)
  1357. {
  1358. uint nodeIndex = GetListIndex(node);
  1359. if (nodeIndex != NO_ITEM)
  1360. {
  1361. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  1362. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  1363. }
  1364. }
  1365. else if (component.temporary)
  1366. {
  1367. uint index = GetComponentListIndex(component);
  1368. if (index != NO_ITEM)
  1369. hierarchyList.RemoveItem(index);
  1370. }
  1371. return;
  1372. }
  1373. UIElement@ element = cast<UIElement>(serializable);
  1374. if (element !is null)
  1375. {
  1376. if (showTemporaryObject)
  1377. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  1378. else if (!element.temporary && GetListIndex(element) == NO_ITEM)
  1379. UpdateHierarchyItem(element);
  1380. else if (element.temporary)
  1381. UpdateHierarchyItem(GetListIndex(element), null, null);
  1382. return;
  1383. }
  1384. }
  1385. // Hierarchy window edit functions
  1386. bool Undo()
  1387. {
  1388. if (undoStackPos > 0)
  1389. {
  1390. --undoStackPos;
  1391. // Undo commands in reverse order
  1392. for (int i = int(undoStack[undoStackPos].actions.length - 1); i >= 0; --i)
  1393. undoStack[undoStackPos].actions[i].Undo();
  1394. }
  1395. return true;
  1396. }
  1397. bool Redo()
  1398. {
  1399. if (undoStackPos < undoStack.length)
  1400. {
  1401. // Redo commands in same order as stored
  1402. for (uint i = 0; i < undoStack[undoStackPos].actions.length; ++i)
  1403. undoStack[undoStackPos].actions[i].Redo();
  1404. ++undoStackPos;
  1405. }
  1406. return true;
  1407. }
  1408. bool Cut()
  1409. {
  1410. if (CheckHierarchyWindowFocus())
  1411. {
  1412. bool ret = true;
  1413. if (!selectedNodes.empty || !selectedComponents.empty)
  1414. ret = ret && SceneCut();
  1415. // Not mutually exclusive
  1416. if (!selectedUIElements.empty)
  1417. ret = ret && UIElementCut();
  1418. return ret;
  1419. }
  1420. return false;
  1421. }
  1422. bool Duplicate()
  1423. {
  1424. if (CheckHierarchyWindowFocus())
  1425. {
  1426. bool ret = true;
  1427. if (!selectedNodes.empty || !selectedComponents.empty)
  1428. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneDuplicate() : false); // Node and component is mutually exclusive for copy action
  1429. // Not mutually exclusive
  1430. if (!selectedUIElements.empty)
  1431. ret = ret && UIElementDuplicate();
  1432. return ret;
  1433. }
  1434. return false;
  1435. }
  1436. bool Copy()
  1437. {
  1438. if (CheckHierarchyWindowFocus())
  1439. {
  1440. bool ret = true;
  1441. if (!selectedNodes.empty || !selectedComponents.empty)
  1442. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneCopy() : false); // Node and component is mutually exclusive for copy action
  1443. // Not mutually exclusive
  1444. if (!selectedUIElements.empty)
  1445. ret = ret && UIElementCopy();
  1446. return ret;
  1447. }
  1448. return false;
  1449. }
  1450. bool Paste()
  1451. {
  1452. if (CheckHierarchyWindowFocus())
  1453. {
  1454. bool ret = true;
  1455. if (editNode !is null && !sceneCopyBuffer.empty)
  1456. ret = ret && ScenePaste();
  1457. // Not mutually exclusive
  1458. if (editUIElement !is null && !uiElementCopyBuffer.empty)
  1459. ret = ret && UIElementPaste();
  1460. return ret;
  1461. }
  1462. return false;
  1463. }
  1464. bool BlenderModeDelete()
  1465. {
  1466. if (ui.focusElement is null)
  1467. {
  1468. Array<UIElement@> actions;
  1469. actions.Push(CreateContextMenuItem("Delete?", "HandleBlenderModeDelete"));
  1470. actions.Push(CreateContextMenuItem("Cancel", "HandleEmpty"));
  1471. if (actions.length > 0)
  1472. {
  1473. ActivateContextMenu(actions);
  1474. return true;
  1475. }
  1476. }
  1477. return false;
  1478. }
  1479. bool Delete()
  1480. {
  1481. if (CheckHierarchyWindowFocus())
  1482. {
  1483. bool ret = true;
  1484. if (!selectedNodes.empty || !selectedComponents.empty)
  1485. ret = ret && SceneDelete();
  1486. // Not mutually exclusive
  1487. if (!selectedUIElements.empty)
  1488. ret = ret && UIElementDelete();
  1489. return ret;
  1490. }
  1491. return false;
  1492. }
  1493. bool SelectAll()
  1494. {
  1495. if (CheckHierarchyWindowFocus())
  1496. {
  1497. if (!selectedNodes.empty || !selectedComponents.empty)
  1498. return SceneSelectAll();
  1499. else if (!selectedUIElements.empty || hierarchyList.items[GetListIndex(editorUIElement)].selected)
  1500. return UIElementSelectAll();
  1501. else
  1502. return SceneSelectAll(); // If nothing is selected yet, fall back to scene select all
  1503. }
  1504. return false;
  1505. }
  1506. bool DeselectAll()
  1507. {
  1508. if (CheckHierarchyWindowFocus())
  1509. {
  1510. BeginSelectionModify();
  1511. hierarchyList.ClearSelection();
  1512. EndSelectionModify();
  1513. return true;
  1514. }
  1515. return false;
  1516. }
  1517. bool ResetToDefault()
  1518. {
  1519. if (CheckHierarchyWindowFocus())
  1520. {
  1521. bool ret = true;
  1522. if (!selectedNodes.empty || !selectedComponents.empty)
  1523. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneResetToDefault() : false); // Node and component is mutually exclusive for reset-to-default action
  1524. // Not mutually exclusive
  1525. if (!selectedUIElements.empty)
  1526. ret = ret && UIElementResetToDefault();
  1527. return ret;
  1528. }
  1529. return false;
  1530. }
  1531. void ClearEditActions()
  1532. {
  1533. undoStack.Clear();
  1534. undoStackPos = 0;
  1535. }
  1536. void SaveEditAction(EditAction@ action)
  1537. {
  1538. // Create a group with 1 action
  1539. EditActionGroup group;
  1540. group.actions.Push(action);
  1541. SaveEditActionGroup(group);
  1542. }
  1543. void SaveEditActionGroup(EditActionGroup@ group)
  1544. {
  1545. if (group.actions.empty)
  1546. return;
  1547. // Truncate the stack first to current pos
  1548. undoStack.Resize(undoStackPos);
  1549. undoStack.Push(group);
  1550. ++undoStackPos;
  1551. // Limit maximum undo steps
  1552. if (undoStack.length > MAX_UNDOSTACK_SIZE)
  1553. {
  1554. undoStack.Erase(0);
  1555. --undoStackPos;
  1556. }
  1557. }
  1558. void BeginSelectionModify()
  1559. {
  1560. // A large operation on selected nodes is about to begin. Disable intermediate selection updates
  1561. inSelectionModify = true;
  1562. // Cursor shape reverts back to normal automatically after the large operation is completed
  1563. ui.cursor.shape = CS_BUSY;
  1564. }
  1565. void EndSelectionModify()
  1566. {
  1567. // The large operation on selected nodes has ended. Update node/component selection now
  1568. inSelectionModify = false;
  1569. HandleHierarchyListSelectionChange();
  1570. }
  1571. void HandleHierarchyContextCreateReplicatedNode()
  1572. {
  1573. CreateNode(REPLICATED);
  1574. }
  1575. void HandleHierarchyContextCreateLocalNode()
  1576. {
  1577. CreateNode(LOCAL);
  1578. }
  1579. void HandleHierarchyContextDuplicate()
  1580. {
  1581. Duplicate();
  1582. }
  1583. void HandleHierarchyContextCopy()
  1584. {
  1585. Copy();
  1586. }
  1587. void HandleHierarchyContextCut()
  1588. {
  1589. Cut();
  1590. }
  1591. void HandleHierarchyContextDelete()
  1592. {
  1593. Delete();
  1594. }
  1595. void HandleBlenderModeDelete()
  1596. {
  1597. Delete();
  1598. }
  1599. void HandleEmpty()
  1600. {
  1601. //just doing nothing
  1602. }
  1603. void HandleHierarchyContextPaste()
  1604. {
  1605. Paste();
  1606. }
  1607. void HandleHierarchyContextResetToDefault()
  1608. {
  1609. ResetToDefault();
  1610. }
  1611. void HandleHierarchyContextResetPosition()
  1612. {
  1613. SceneResetPosition();
  1614. }
  1615. void HandleHierarchyContextResetRotation()
  1616. {
  1617. SceneResetRotation();
  1618. }
  1619. void HandleHierarchyContextResetScale()
  1620. {
  1621. SceneResetScale();
  1622. }
  1623. void HandleHierarchyContextEnableDisable()
  1624. {
  1625. SceneToggleEnable();
  1626. }
  1627. void HandleHierarchyContextUnparent()
  1628. {
  1629. SceneUnparent();
  1630. }
  1631. void HandleHierarchyContextUIElementCloseUILayout()
  1632. {
  1633. CloseUILayout();
  1634. }
  1635. void HandleHierarchyContextUIElementCloseAllUILayouts()
  1636. {
  1637. CloseAllUILayouts();
  1638. }
  1639. void CollapseHierarchy()
  1640. {
  1641. Array<uint> oldSelections = hierarchyList.selections;
  1642. Array<uint> selections = {0};
  1643. hierarchyList.SetSelections(selections);
  1644. for (uint i = 0; i < selections.length; ++i)
  1645. hierarchyList.Expand(selections[i], false, true);
  1646. // only scene's scope expand by default
  1647. hierarchyList.Expand(0, true, false);
  1648. hierarchyList.SetSelections(oldSelections);
  1649. }
  1650. void CollapseHierarchy(StringHash eventType, VariantMap& eventData)
  1651. {
  1652. CollapseHierarchy();
  1653. }
  1654. void HandleShowID(StringHash eventType, VariantMap& eventData)
  1655. {
  1656. CheckBox@ checkBox = eventData["Element"].GetPtr();
  1657. showID = checkBox.checked;
  1658. UpdateHierarchyItem(editorScene, false);
  1659. CollapseHierarchy();
  1660. }