EditorHierarchyWindow.as 61 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938
  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(uint8(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.id >= FIRST_LOCAL_ID)
  395. ret += " (Local " + String(node.id) + ")";
  396. else
  397. ret += " (" + 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.id >= FIRST_LOCAL_ID)
  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. infoStr += "\n Geometry " + g + "\n Lods: " + model.numGeometryLodLevels[g];
  560. }
  561. modelInfoText.text = infoStr;
  562. }
  563. void HandleHierarchyListSelectionChange()
  564. {
  565. if (inSelectionModify)
  566. return;
  567. ClearSceneSelection();
  568. ClearUIElementSelection();
  569. Array<uint> indices = hierarchyList.selections;
  570. // Enable Expand/Collapse button when there is selection
  571. EnableExpandCollapseButtons(indices.length > 0);
  572. for (uint i = 0; i < indices.length; ++i)
  573. {
  574. uint index = indices[i];
  575. UIElement@ item = hierarchyList.items[index];
  576. int type = item.vars[TYPE_VAR].GetInt();
  577. if (type == ITEM_COMPONENT)
  578. {
  579. Component@ comp = GetListComponent(index);
  580. if (comp !is null)
  581. selectedComponents.Push(comp);
  582. }
  583. else if (type == ITEM_NODE)
  584. {
  585. Node@ node = GetListNode(index);
  586. if (node !is null)
  587. selectedNodes.Push(node);
  588. }
  589. else if (type == ITEM_UI_ELEMENT)
  590. {
  591. UIElement@ element = GetListUIElement(index);
  592. if (element !is null && element !is editorUIElement)
  593. selectedUIElements.Push(element);
  594. }
  595. }
  596. // If only one node/UIElement selected, use it for editing
  597. if (selectedNodes.length == 1)
  598. editNode = selectedNodes[0];
  599. if (selectedUIElements.length == 1)
  600. editUIElement = selectedUIElements[0];
  601. // If selection contains only components, and they have a common node, use it for editing
  602. if (selectedNodes.empty && !selectedComponents.empty)
  603. {
  604. Node@ commonNode;
  605. for (uint i = 0; i < selectedComponents.length; ++i)
  606. {
  607. if (i == 0)
  608. commonNode = selectedComponents[i].node;
  609. else
  610. {
  611. if (selectedComponents[i].node !is commonNode)
  612. commonNode = null;
  613. }
  614. }
  615. editNode = commonNode;
  616. }
  617. UpdateModelInfo(FindFirstSelectedModel());
  618. // Now check if the component(s) can be edited. If many selected, must have same type or have same edit node
  619. if (!selectedComponents.empty)
  620. {
  621. if (editNode is null)
  622. {
  623. StringHash compType = selectedComponents[0].type;
  624. bool sameType = true;
  625. for (uint i = 1; i < selectedComponents.length; ++i)
  626. {
  627. if (selectedComponents[i].type != compType)
  628. {
  629. sameType = false;
  630. break;
  631. }
  632. }
  633. if (sameType)
  634. editComponents = selectedComponents;
  635. }
  636. else
  637. {
  638. editComponents = selectedComponents;
  639. numEditableComponentsPerNode = selectedComponents.length;
  640. }
  641. }
  642. // If just nodes selected, and no components, show as many matching components for editing as possible
  643. if (!selectedNodes.empty && selectedComponents.empty && selectedNodes[0].numComponents > 0)
  644. {
  645. uint count = 0;
  646. for (uint j = 0; j < selectedNodes[0].numComponents; ++j)
  647. {
  648. StringHash compType = selectedNodes[0].components[j].type;
  649. bool sameType = true;
  650. for (uint i = 1; i < selectedNodes.length; ++i)
  651. {
  652. if (selectedNodes[i].numComponents <= j || selectedNodes[i].components[j].type != compType)
  653. {
  654. sameType = false;
  655. break;
  656. }
  657. }
  658. if (sameType)
  659. {
  660. ++count;
  661. for (uint i = 0; i < selectedNodes.length; ++i)
  662. editComponents.Push(selectedNodes[i].components[j]);
  663. }
  664. }
  665. if (count > 1)
  666. numEditableComponentsPerNode = count;
  667. }
  668. if (selectedNodes.empty && editNode !is null)
  669. editNodes.Push(editNode);
  670. else
  671. {
  672. editNodes = selectedNodes;
  673. // Cannot multi-edit on scene and node(s) together as scene and node do not share identical attributes,
  674. // editing via gizmo does not make too much sense either
  675. if (editNodes.length > 1 && editNodes[0] is editorScene)
  676. editNodes.Erase(0);
  677. }
  678. if (selectedUIElements.empty && editUIElement !is null)
  679. editUIElements.Push(editUIElement);
  680. else
  681. editUIElements = selectedUIElements;
  682. PositionGizmo();
  683. UpdateAttributeInspector();
  684. UpdateCameraPreview();
  685. }
  686. void HandleHierarchyListDoubleClick(StringHash eventType, VariantMap& eventData)
  687. {
  688. UIElement@ item = eventData["Item"].GetPtr();
  689. int type = item.vars[TYPE_VAR].GetInt();
  690. // Locate nodes from the scene by double-clicking
  691. if (type == ITEM_NODE)
  692. {
  693. Node@ node = editorScene.GetNode(item.vars[NODE_ID_VAR].GetUInt());
  694. Array<Node@> nodes;
  695. nodes.Push(node);
  696. LocateNodes(nodes);
  697. }
  698. else if (type == ITEM_COMPONENT)
  699. {
  700. Component@ component = editorScene.GetComponent(item.vars[COMPONENT_ID_VAR].GetUInt());
  701. Array<Component@> components;
  702. components.Push(component);
  703. LocateComponents(components);
  704. }
  705. bool isExpanded = hierarchyList.IsExpanded(hierarchyList.selection);
  706. if (!isExpanded && eventData["Button"].GetInt() == MOUSEB_LEFT)
  707. {
  708. isExpanded = !isExpanded;
  709. hierarchyList.Expand(hierarchyList.selection, isExpanded, false);
  710. }
  711. }
  712. void HandleHierarchyItemClick(StringHash eventType, VariantMap& eventData)
  713. {
  714. if (eventData["Button"].GetInt() != MOUSEB_RIGHT)
  715. return;
  716. UIElement@ uiElement = eventData["Item"].GetPtr();
  717. int selectionIndex = eventData["Selection"].GetInt();
  718. Array<UIElement@> actions;
  719. int type = uiElement.vars[TYPE_VAR].GetInt();
  720. // Adds left clicked items to selection which is not normal listview behavior
  721. if (type == ITEM_COMPONENT || type == ITEM_NODE)
  722. {
  723. if (input.keyDown[KEY_LSHIFT])
  724. hierarchyList.AddSelection(selectionIndex);
  725. else
  726. {
  727. hierarchyList.ClearSelection();
  728. hierarchyList.AddSelection(selectionIndex);
  729. }
  730. }
  731. if (type == ITEM_COMPONENT)
  732. {
  733. Component@ targetComponent = editorScene.GetComponent(uiElement.vars[COMPONENT_ID_VAR].GetUInt());
  734. if (targetComponent is null)
  735. return;
  736. actions.Push(CreateContextMenuItem("Copy", "HandleHierarchyContextCopy"));
  737. actions.Push(CreateContextMenuItem("Cut", "HandleHierarchyContextCut"));
  738. actions.Push(CreateContextMenuItem("Delete", "HandleHierarchyContextDelete"));
  739. actions.Push(CreateContextMenuItem("Paste", "HandleHierarchyContextPaste"));
  740. actions.Push(CreateContextMenuItem("Enable/disable", "HandleHierarchyContextEnableDisable"));
  741. /* actions.Push(CreateBrowserFileActionMenu("Edit", "HandleBrowserEditResource", file)); */
  742. }
  743. else if (type == ITEM_NODE)
  744. {
  745. actions.Push(CreateContextMenuItem("Create Replicated Node", "HandleHierarchyContextCreateReplicatedNode"));
  746. actions.Push(CreateContextMenuItem("Create Local Node", "HandleHierarchyContextCreateLocalNode"));
  747. actions.Push(CreateContextMenuItem("Duplicate", "HandleHierarchyContextDuplicate"));
  748. actions.Push(CreateContextMenuItem("Copy", "HandleHierarchyContextCopy"));
  749. actions.Push(CreateContextMenuItem("Cut", "HandleHierarchyContextCut"));
  750. actions.Push(CreateContextMenuItem("Delete", "HandleHierarchyContextDelete"));
  751. actions.Push(CreateContextMenuItem("Paste", "HandleHierarchyContextPaste"));
  752. actions.Push(CreateContextMenuItem("Reset to default", "HandleHierarchyContextResetToDefault"));
  753. actions.Push(CreateContextMenuItem("Reset position", "HandleHierarchyContextResetPosition"));
  754. actions.Push(CreateContextMenuItem("Reset rotation", "HandleHierarchyContextResetRotation"));
  755. actions.Push(CreateContextMenuItem("Reset scale", "HandleHierarchyContextResetScale"));
  756. actions.Push(CreateContextMenuItem("Enable/disable", "HandleHierarchyContextEnableDisable"));
  757. actions.Push(CreateContextMenuItem("Unparent", "HandleHierarchyContextUnparent"));
  758. }
  759. else if (type == ITEM_UI_ELEMENT)
  760. {
  761. // close ui element
  762. actions.Push(CreateContextMenuItem("Close UI-Layout", "HandleHierarchyContextUIElementCloseUILayout"));
  763. actions.Push(CreateContextMenuItem("Close all UI-layouts", "HandleHierarchyContextUIElementCloseAllUILayouts"));
  764. }
  765. if (actions.length > 0)
  766. ActivateContextMenu(actions);
  767. }
  768. void HandleDragDropTest(StringHash eventType, VariantMap& eventData)
  769. {
  770. UIElement@ source = eventData["Source"].GetPtr();
  771. UIElement@ target = eventData["Target"].GetPtr();
  772. int itemType;
  773. eventData["Accept"] = TestDragDrop(source, target, itemType);
  774. }
  775. void HandleDragDropFinish(StringHash eventType, VariantMap& eventData)
  776. {
  777. UIElement@ source = eventData["Source"].GetPtr();
  778. UIElement@ target = eventData["Target"].GetPtr();
  779. int itemType = ITEM_NONE;
  780. bool accept = TestDragDrop(source, target, itemType);
  781. eventData["Accept"] = accept;
  782. if (!accept)
  783. return;
  784. // Resource browser
  785. if (source !is null && source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt() > 0)
  786. {
  787. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  788. BrowserFile@ browserFile = GetBrowserFileFromId(source.vars[TEXT_VAR_FILE_ID].GetUInt());
  789. if (browserFile is null)
  790. return;
  791. Component@ createdComponent;
  792. if (itemType == ITEM_NODE)
  793. {
  794. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  795. if (targetNode is null)
  796. return;
  797. if (type == RESOURCE_TYPE_PREFAB)
  798. {
  799. LoadNode(browserFile.GetFullPath(), targetNode);
  800. }
  801. else if(type == RESOURCE_TYPE_SCRIPTFILE)
  802. {
  803. // TODO: not sure what to do here. lots of choices.
  804. }
  805. else if(type == RESOURCE_TYPE_MODEL)
  806. {
  807. CreateModelWithStaticModel(browserFile.resourceKey, targetNode);
  808. return;
  809. }
  810. else if (type == RESOURCE_TYPE_PARTICLEEFFECT)
  811. {
  812. if (browserFile.extension == "xml")
  813. {
  814. ParticleEffect@ effect = cache.GetResource("ParticleEffect", browserFile.resourceKey);
  815. if (effect is null)
  816. return;
  817. ParticleEmitter@ emitter = targetNode.CreateComponent("ParticleEmitter");
  818. emitter.effect = effect;
  819. createdComponent = emitter;
  820. }
  821. }
  822. else if (type == RESOURCE_TYPE_2D_PARTICLE_EFFECT)
  823. {
  824. if (browserFile.extension == "xml")
  825. {
  826. Resource@ effect = cache.GetResource("ParticleEffect2D", browserFile.resourceKey);
  827. if (effect is null)
  828. return;
  829. ResourceRef effectRef;
  830. effectRef.type = effect.type;
  831. effectRef.name = effect.name;
  832. Component@ emitter = targetNode.CreateComponent("ParticleEmitter2D");
  833. emitter.SetAttribute("Particle Effect", Variant(effectRef));
  834. createdComponent = emitter;
  835. }
  836. }
  837. }
  838. else if (itemType == ITEM_COMPONENT)
  839. {
  840. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  841. if (targetComponent is null)
  842. return;
  843. if (type == RESOURCE_TYPE_MATERIAL)
  844. {
  845. StaticModel@ model = cast<StaticModel>(targetComponent);
  846. if (model is null)
  847. return;
  848. AssignMaterial(model, browserFile.resourceKey);
  849. }
  850. else if (type == RESOURCE_TYPE_MODEL)
  851. {
  852. StaticModel@ staticModel = cast<StaticModel>(targetComponent);
  853. if (staticModel is null)
  854. return;
  855. AssignModel(staticModel, browserFile.resourceKey);
  856. }
  857. }
  858. else
  859. {
  860. LineEdit@ text = cast<LineEdit>(target);
  861. if (text is null)
  862. return;
  863. text.text = browserFile.resourceKey;
  864. VariantMap data();
  865. data["Element"] = text;
  866. data["Text"] = text.text;
  867. text.SendEvent("TextFinished", data);
  868. }
  869. if (createdComponent !is null)
  870. {
  871. CreateLoadedComponent(createdComponent);
  872. }
  873. return;
  874. }
  875. if (itemType == ITEM_NODE)
  876. {
  877. Node@ targetNode = editorScene.GetNode(target.vars[NODE_ID_VAR].GetUInt());
  878. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  879. if (sourceNodes.length > 0)
  880. {
  881. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  882. SceneReorder(sourceNodes[0], targetNode);
  883. else
  884. {
  885. // If target is null, parent to scene
  886. if (targetNode is null)
  887. targetNode = editorScene;
  888. if (sourceNodes.length > 1)
  889. SceneChangeParent(sourceNodes[0], sourceNodes, targetNode);
  890. else
  891. SceneChangeParent(sourceNodes[0], targetNode);
  892. }
  893. // Focus the node at its new position in the list which in turn should trigger a refresh in attribute inspector
  894. FocusNode(sourceNodes[0]);
  895. }
  896. }
  897. else if (itemType == ITEM_UI_ELEMENT)
  898. {
  899. UIElement@ sourceElement = GetUIElementByID(source.vars[UI_ELEMENT_ID_VAR].GetUInt());
  900. UIElement@ targetElement = GetUIElementByID(target.vars[UI_ELEMENT_ID_VAR].GetUInt());
  901. // If target is null, cannot proceed
  902. if (targetElement is null)
  903. return;
  904. if (input.qualifierDown[QUAL_CTRL])
  905. {
  906. if (!UIElementReorder(sourceElement, targetElement))
  907. return;
  908. }
  909. else
  910. {
  911. if (!UIElementChangeParent(sourceElement, targetElement))
  912. return;
  913. }
  914. // Focus the element at its new position in the list which in turn should trigger a refresh in attribute inspector
  915. FocusUIElement(sourceElement);
  916. }
  917. else if (itemType == ITEM_COMPONENT)
  918. {
  919. Component@ targetComponent = editorScene.GetComponent(target.vars[COMPONENT_ID_VAR].GetUInt());
  920. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  921. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  922. {
  923. // Reorder components within node
  924. Component@ sourceComponent = editorScene.GetComponent(source.vars[COMPONENT_ID_VAR].GetUInt());
  925. SceneReorder(sourceComponent, targetComponent);
  926. }
  927. else
  928. {
  929. if (targetComponent !is null && sourceNodes.length > 0)
  930. {
  931. // Drag node to StaticModelGroup to make it an instance
  932. StaticModelGroup@ smg = cast<StaticModelGroup>(targetComponent);
  933. if (smg !is null)
  934. {
  935. // Save undo action
  936. EditAttributeAction action;
  937. uint attrIndex = GetAttributeIndex(smg, "Instance Nodes");
  938. Variant oldIDs = smg.attributes[attrIndex];
  939. for (uint i = 0; i < sourceNodes.length; ++i)
  940. smg.AddInstanceNode(sourceNodes[i]);
  941. action.Define(smg, attrIndex, oldIDs);
  942. SaveEditAction(action);
  943. SetSceneModified();
  944. UpdateAttributeInspector(false);
  945. }
  946. // Drag node to SplinePath to make it a control point
  947. SplinePath@ spline = cast<SplinePath>(targetComponent);
  948. if (spline !is null)
  949. {
  950. // Save undo action
  951. EditAttributeAction action;
  952. uint attrIndex = GetAttributeIndex(spline, "Control Points");
  953. Variant oldIDs = spline.attributes[attrIndex];
  954. for (uint i = 0; i < sourceNodes.length; ++i)
  955. spline.AddControlPoint(sourceNodes[i]);
  956. action.Define(spline, attrIndex, oldIDs);
  957. SaveEditAction(action);
  958. SetSceneModified();
  959. UpdateAttributeInspector(false);
  960. }
  961. // Drag a node to Constraint to make it the remote end of the constraint
  962. Constraint@ constraint = cast<Constraint>(targetComponent);
  963. RigidBody@ rigidBody = sourceNodes[0].GetComponent("RigidBody");
  964. if (constraint !is null && rigidBody !is null)
  965. {
  966. // Save undo action
  967. EditAttributeAction action;
  968. uint attrIndex = GetAttributeIndex(constraint, "Other Body NodeID");
  969. Variant oldID = constraint.attributes[attrIndex];
  970. constraint.otherBody = rigidBody;
  971. action.Define(constraint, attrIndex, oldID);
  972. SaveEditAction(action);
  973. SetSceneModified();
  974. UpdateAttributeInspector(false);
  975. }
  976. }
  977. }
  978. }
  979. }
  980. Array<Node@> GetMultipleSourceNodes(UIElement@ source)
  981. {
  982. Array<Node@> nodeList;
  983. Node@ node = editorScene.GetNode(source.vars[NODE_ID_VAR].GetUInt());
  984. if (node !is null)
  985. nodeList.Push(node);
  986. // Handle additional selected children from a ListView
  987. if (source.parent !is null && source.parent.typeName == "HierarchyContainer")
  988. {
  989. ListView@ listView_ = cast<ListView>(source.parent.parent.parent);
  990. if (listView_ is null)
  991. return nodeList;
  992. bool sourceIsSelected = false;
  993. for (uint i = 0; i < listView_.selectedItems.length; ++i)
  994. {
  995. if (listView_.selectedItems[i] is source)
  996. {
  997. sourceIsSelected = true;
  998. break;
  999. }
  1000. }
  1001. if (sourceIsSelected)
  1002. {
  1003. for (uint i = 0; i < listView_.selectedItems.length; ++i)
  1004. {
  1005. UIElement@ item_ = listView_.selectedItems[i];
  1006. // The source item is already added
  1007. if (item_ is source)
  1008. continue;
  1009. if (item_.vars[TYPE_VAR] == ITEM_NODE)
  1010. {
  1011. Node@ n = editorScene.GetNode(item_.vars[NODE_ID_VAR].GetUInt());
  1012. if (n !is null)
  1013. nodeList.Push(n);
  1014. }
  1015. }
  1016. }
  1017. }
  1018. return nodeList;
  1019. }
  1020. bool TestDragDrop(UIElement@ source, UIElement@ target, int& itemType)
  1021. {
  1022. int targetItemType = target.GetVar(TYPE_VAR).GetInt();
  1023. if (targetItemType == ITEM_NODE)
  1024. {
  1025. Node@ sourceNode;
  1026. Node@ targetNode;
  1027. Variant variant = source.GetVar(NODE_ID_VAR);
  1028. if (!variant.empty)
  1029. sourceNode = editorScene.GetNode(variant.GetUInt());
  1030. variant = target.GetVar(NODE_ID_VAR);
  1031. if (!variant.empty)
  1032. targetNode = editorScene.GetNode(variant.GetUInt());
  1033. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  1034. if (sourceNode !is null && targetNode !is null)
  1035. {
  1036. itemType = ITEM_NODE;
  1037. // Ctrl pressed: reorder
  1038. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  1039. {
  1040. // Must be within the same parent
  1041. if (sourceNode.parent is null || sourceNode.parent !is targetNode.parent)
  1042. return false;
  1043. }
  1044. // No ctrl: Reparent
  1045. else
  1046. {
  1047. if (sourceNode.parent is targetNode)
  1048. return false;
  1049. if (targetNode.parent is sourceNode)
  1050. return false;
  1051. }
  1052. }
  1053. // Resource browser
  1054. if (sourceNode is null && targetNode !is null)
  1055. {
  1056. itemType = ITEM_NODE;
  1057. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1058. return type == RESOURCE_TYPE_PREFAB ||
  1059. type == RESOURCE_TYPE_SCRIPTFILE ||
  1060. type == RESOURCE_TYPE_MODEL ||
  1061. type == RESOURCE_TYPE_PARTICLEEFFECT ||
  1062. type == RESOURCE_TYPE_2D_PARTICLE_EFFECT;
  1063. }
  1064. return true;
  1065. }
  1066. else if (targetItemType == ITEM_UI_ELEMENT)
  1067. {
  1068. UIElement@ sourceElement;
  1069. UIElement@ targetElement;
  1070. Variant variant = source.GetVar(UI_ELEMENT_ID_VAR);
  1071. if (!variant.empty)
  1072. sourceElement = GetUIElementByID(variant.GetUInt());
  1073. variant = target.GetVar(UI_ELEMENT_ID_VAR);
  1074. if (!variant.empty)
  1075. targetElement = GetUIElementByID(variant.GetUInt());
  1076. if (sourceElement !is null && targetElement !is null)
  1077. {
  1078. itemType = ITEM_UI_ELEMENT;
  1079. // Ctrl pressed: reorder
  1080. if (input.qualifierDown[QUAL_CTRL])
  1081. {
  1082. // Must be within the same parent
  1083. if (sourceElement.parent is null || sourceElement.parent !is targetElement.parent)
  1084. return false;
  1085. }
  1086. // No ctrl: reparent
  1087. else
  1088. {
  1089. if (sourceElement.parent is targetElement)
  1090. return false;
  1091. if (targetElement.parent is sourceElement)
  1092. return false;
  1093. }
  1094. }
  1095. return true;
  1096. }
  1097. else if (targetItemType == ITEM_COMPONENT)
  1098. {
  1099. Node@ sourceNode;
  1100. Component@ sourceComponent;
  1101. Component@ targetComponent;
  1102. Variant variant = source.GetVar(NODE_ID_VAR);
  1103. if (!variant.empty)
  1104. sourceNode = editorScene.GetNode(variant.GetUInt());
  1105. variant = target.GetVar(COMPONENT_ID_VAR);
  1106. if (!variant.empty)
  1107. targetComponent = editorScene.GetComponent(variant.GetUInt());
  1108. variant = source.GetVar(COMPONENT_ID_VAR);
  1109. if (!variant.empty)
  1110. sourceComponent = editorScene.GetComponent(variant.GetUInt());
  1111. Array<Node@> sourceNodes = GetMultipleSourceNodes(source);
  1112. itemType = ITEM_COMPONENT;
  1113. if (input.qualifierDown[QUAL_CTRL] && sourceNodes.length == 1)
  1114. {
  1115. // Reorder components within node
  1116. if (sourceComponent !is null && targetComponent !is null && sourceComponent.node is targetComponent.node)
  1117. return true;
  1118. }
  1119. else
  1120. {
  1121. // Dragging of nodes to StaticModelGroup, SplinePath or Constraint
  1122. if (sourceNode !is null && targetComponent !is null && (targetComponent.type == STATICMODELGROUP_TYPE ||
  1123. targetComponent.type == CONSTRAINT_TYPE || targetComponent.type == SPLINEPATH_TYPE))
  1124. return true;
  1125. // Resource browser
  1126. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1127. if (targetComponent.type == STATICMODEL_TYPE || targetComponent.type == ANIMATEDMODEL_TYPE)
  1128. return type == RESOURCE_TYPE_MATERIAL || type == RESOURCE_TYPE_MODEL;
  1129. }
  1130. return false;
  1131. }
  1132. else if (source.vars.Contains(TEXT_VAR_RESOURCE_TYPE)) // only testing resource browser ui elements
  1133. {
  1134. int type = source.GetVar(TEXT_VAR_RESOURCE_TYPE).GetInt();
  1135. // Test against resource pickers
  1136. LineEdit@ lineEdit = cast<LineEdit>(target);
  1137. if (lineEdit !is null)
  1138. {
  1139. StringHash resourceType = GetResourceTypeFromPickerLineEdit(lineEdit);
  1140. if (resourceType == StringHash("Material") && type == RESOURCE_TYPE_MATERIAL)
  1141. return true;
  1142. else if (resourceType == StringHash("Model") && type == RESOURCE_TYPE_MODEL)
  1143. return true;
  1144. else if (resourceType == StringHash("Animation") && type == RESOURCE_TYPE_ANIMATION)
  1145. return true;
  1146. }
  1147. }
  1148. return true;
  1149. }
  1150. StringHash GetResourceTypeFromPickerLineEdit(UIElement@ lineEdit)
  1151. {
  1152. Array<Serializable@>@ targets = GetAttributeEditorTargets(lineEdit);
  1153. if (!targets.empty)
  1154. {
  1155. resourcePickIndex = lineEdit.vars["Index"].GetUInt();
  1156. resourcePickSubIndex = lineEdit.vars["SubIndex"].GetUInt();
  1157. AttributeInfo info = targets[0].attributeInfos[resourcePickIndex];
  1158. StringHash resourceType;
  1159. if (info.type == VAR_RESOURCEREF)
  1160. return targets[0].attributes[resourcePickIndex].GetResourceRef().type;
  1161. else if (info.type == VAR_RESOURCEREFLIST)
  1162. return targets[0].attributes[resourcePickIndex].GetResourceRefList().type;
  1163. else if (info.type == VAR_VARIANTVECTOR)
  1164. return targets[0].attributes[resourcePickIndex].GetVariantVector()[resourcePickSubIndex].GetResourceRef().type;
  1165. }
  1166. return StringHash();
  1167. }
  1168. void FocusNode(Node@ node)
  1169. {
  1170. uint index = GetListIndex(node);
  1171. hierarchyList.selection = index;
  1172. }
  1173. void FocusComponent(Component@ component)
  1174. {
  1175. uint index = GetComponentListIndex(component);
  1176. hierarchyList.selection = index;
  1177. }
  1178. void FocusUIElement(UIElement@ element)
  1179. {
  1180. uint index = GetListIndex(element);
  1181. hierarchyList.selection = index;
  1182. }
  1183. void CreateBuiltinObject(const String& name)
  1184. {
  1185. Node@ newNode = editorScene.CreateChild(name, REPLICATED);
  1186. // Set the new node a certain distance from the camera
  1187. newNode.position = GetNewNodePosition();
  1188. StaticModel@ object = newNode.CreateComponent("StaticModel");
  1189. object.model = cache.GetResource("Model", "Models/" + name + ".mdl");
  1190. // Create an undo action for the create
  1191. CreateNodeAction action;
  1192. action.Define(newNode);
  1193. SaveEditAction(action);
  1194. SetSceneModified();
  1195. FocusNode(newNode);
  1196. }
  1197. bool CheckHierarchyWindowFocus()
  1198. {
  1199. // When we do edit operations based on key shortcuts, make sure the hierarchy list is focused
  1200. return ui.focusElement is hierarchyList || ui.focusElement is null;
  1201. }
  1202. bool CheckForExistingGlobalComponent(Node@ node, const String&in typeName)
  1203. {
  1204. if (typeName != "Octree" && typeName != "PhysicsWorld" && typeName != "DebugRenderer")
  1205. return false;
  1206. else
  1207. return node.HasComponent(typeName);
  1208. }
  1209. void HandleNodeAdded(StringHash eventType, VariantMap& eventData)
  1210. {
  1211. if (suppressSceneChanges)
  1212. return;
  1213. Node@ node = eventData["Node"].GetPtr();
  1214. if (showTemporaryObject || !node.temporary)
  1215. UpdateHierarchyItem(node);
  1216. }
  1217. void HandleNodeRemoved(StringHash eventType, VariantMap& eventData)
  1218. {
  1219. if (suppressSceneChanges)
  1220. return;
  1221. Node@ node = eventData["Node"].GetPtr();
  1222. if (showTemporaryObject || !node.temporary)
  1223. UpdateHierarchyItem(GetListIndex(node), null, null);
  1224. }
  1225. void HandleComponentAdded(StringHash eventType, VariantMap& eventData)
  1226. {
  1227. if (suppressSceneChanges)
  1228. return;
  1229. // Insert the newly added component at last component position but before the first child node position of the parent node
  1230. Node@ node = eventData["Node"].GetPtr();
  1231. Component@ component = eventData["Component"].GetPtr();
  1232. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1233. {
  1234. uint nodeIndex = GetListIndex(node);
  1235. if (nodeIndex != NO_ITEM)
  1236. {
  1237. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  1238. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  1239. }
  1240. }
  1241. }
  1242. void HandleComponentRemoved(StringHash eventType, VariantMap& eventData)
  1243. {
  1244. if (suppressSceneChanges)
  1245. return;
  1246. Node@ node = eventData["Node"].GetPtr();
  1247. Component@ component = eventData["Component"].GetPtr();
  1248. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1249. {
  1250. uint index = GetComponentListIndex(component);
  1251. if (index != NO_ITEM)
  1252. hierarchyList.RemoveItem(index);
  1253. }
  1254. }
  1255. void HandleNodeNameChanged(StringHash eventType, VariantMap& eventData)
  1256. {
  1257. if (suppressSceneChanges)
  1258. return;
  1259. Node@ node = eventData["Node"].GetPtr();
  1260. if (showTemporaryObject || !node.temporary)
  1261. UpdateHierarchyItemText(GetListIndex(node), node.enabled, GetNodeTitle(node));
  1262. }
  1263. void HandleNodeEnabledChanged(StringHash eventType, VariantMap& eventData)
  1264. {
  1265. if (suppressSceneChanges)
  1266. return;
  1267. Node@ node = eventData["Node"].GetPtr();
  1268. if (showTemporaryObject || !node.temporary)
  1269. {
  1270. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  1271. attributesDirty = true;
  1272. }
  1273. }
  1274. void HandleComponentEnabledChanged(StringHash eventType, VariantMap& eventData)
  1275. {
  1276. if (suppressSceneChanges)
  1277. return;
  1278. Node@ node = eventData["Node"].GetPtr();
  1279. Component@ component = eventData["Component"].GetPtr();
  1280. if (showTemporaryObject || (!node.temporary && !component.temporary))
  1281. {
  1282. UpdateHierarchyItemText(GetComponentListIndex(component), component.enabledEffective);
  1283. attributesDirty = true;
  1284. }
  1285. }
  1286. void HandleUIElementAdded(StringHash eventType, VariantMap& eventData)
  1287. {
  1288. if (suppressUIElementChanges)
  1289. return;
  1290. UIElement@ element = eventData["Element"].GetPtr();
  1291. if ((showInternalUIElement || !element.internal) && (showTemporaryObject || !element.temporary))
  1292. UpdateHierarchyItem(element);
  1293. }
  1294. void HandleUIElementRemoved(StringHash eventType, VariantMap& eventData)
  1295. {
  1296. if (suppressUIElementChanges)
  1297. return;
  1298. UIElement@ element = eventData["Element"].GetPtr();
  1299. UpdateHierarchyItem(GetListIndex(element), null, null);
  1300. }
  1301. void HandleElementNameChanged(StringHash eventType, VariantMap& eventData)
  1302. {
  1303. if (suppressUIElementChanges)
  1304. return;
  1305. UIElement@ element = eventData["Element"].GetPtr();
  1306. UpdateHierarchyItemText(GetListIndex(element), element.visible, GetUIElementTitle(element));
  1307. }
  1308. void HandleElementVisibilityChanged(StringHash eventType, VariantMap& eventData)
  1309. {
  1310. if (suppressUIElementChanges)
  1311. return;
  1312. UIElement@ element = eventData["Element"].GetPtr();
  1313. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  1314. }
  1315. void HandleElementAttributeChanged(StringHash eventType, VariantMap& eventData)
  1316. {
  1317. // Do not refresh the attribute inspector while the attribute is being edited via the attribute-editors
  1318. if (suppressUIElementChanges || inEditAttribute)
  1319. return;
  1320. UIElement@ element = eventData["Element"].GetPtr();
  1321. for (uint i = 0; i < editUIElements.length; ++i)
  1322. {
  1323. if (editUIElements[i] is element)
  1324. attributesDirty = true;
  1325. }
  1326. }
  1327. void HandleTemporaryChanged(StringHash eventType, VariantMap& eventData)
  1328. {
  1329. if (suppressSceneChanges || suppressUIElementChanges)
  1330. return;
  1331. Serializable@ serializable = cast<Serializable>(GetEventSender());
  1332. Node@ node = cast<Node>(serializable);
  1333. if (node !is null && node.scene is editorScene)
  1334. {
  1335. if (showTemporaryObject)
  1336. UpdateHierarchyItemText(GetListIndex(node), node.enabled);
  1337. else if (!node.temporary && GetListIndex(node) == NO_ITEM)
  1338. UpdateHierarchyItem(node);
  1339. else if (node.temporary)
  1340. UpdateHierarchyItem(GetListIndex(node), null, null);
  1341. return;
  1342. }
  1343. Component@ component = cast<Component>(serializable);
  1344. if (component !is null && component.node !is null && component.node.scene is editorScene)
  1345. {
  1346. node = component.node;
  1347. if (showTemporaryObject)
  1348. UpdateHierarchyItemText(GetComponentListIndex(component), node.enabled);
  1349. else if (!component.temporary && GetComponentListIndex(component) == NO_ITEM)
  1350. {
  1351. uint nodeIndex = GetListIndex(node);
  1352. if (nodeIndex != NO_ITEM)
  1353. {
  1354. uint index = node.numChildren > 0 ? GetListIndex(node.children[0]) : M_MAX_UNSIGNED;
  1355. UpdateHierarchyItem(index, component, hierarchyList.items[nodeIndex]);
  1356. }
  1357. }
  1358. else if (component.temporary)
  1359. {
  1360. uint index = GetComponentListIndex(component);
  1361. if (index != NO_ITEM)
  1362. hierarchyList.RemoveItem(index);
  1363. }
  1364. return;
  1365. }
  1366. UIElement@ element = cast<UIElement>(serializable);
  1367. if (element !is null)
  1368. {
  1369. if (showTemporaryObject)
  1370. UpdateHierarchyItemText(GetListIndex(element), element.visible);
  1371. else if (!element.temporary && GetListIndex(element) == NO_ITEM)
  1372. UpdateHierarchyItem(element);
  1373. else if (element.temporary)
  1374. UpdateHierarchyItem(GetListIndex(element), null, null);
  1375. return;
  1376. }
  1377. }
  1378. // Hierarchy window edit functions
  1379. bool Undo()
  1380. {
  1381. if (undoStackPos > 0)
  1382. {
  1383. --undoStackPos;
  1384. // Undo commands in reverse order
  1385. for (int i = int(undoStack[undoStackPos].actions.length - 1); i >= 0; --i)
  1386. undoStack[undoStackPos].actions[i].Undo();
  1387. }
  1388. return true;
  1389. }
  1390. bool Redo()
  1391. {
  1392. if (undoStackPos < undoStack.length)
  1393. {
  1394. // Redo commands in same order as stored
  1395. for (uint i = 0; i < undoStack[undoStackPos].actions.length; ++i)
  1396. undoStack[undoStackPos].actions[i].Redo();
  1397. ++undoStackPos;
  1398. }
  1399. return true;
  1400. }
  1401. bool Cut()
  1402. {
  1403. if (CheckHierarchyWindowFocus())
  1404. {
  1405. bool ret = true;
  1406. if (!selectedNodes.empty || !selectedComponents.empty)
  1407. ret = ret && SceneCut();
  1408. // Not mutually exclusive
  1409. if (!selectedUIElements.empty)
  1410. ret = ret && UIElementCut();
  1411. return ret;
  1412. }
  1413. return false;
  1414. }
  1415. bool Duplicate()
  1416. {
  1417. if (CheckHierarchyWindowFocus())
  1418. {
  1419. bool ret = true;
  1420. if (!selectedNodes.empty || !selectedComponents.empty)
  1421. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneDuplicate() : false); // Node and component is mutually exclusive for copy action
  1422. // Not mutually exclusive
  1423. if (!selectedUIElements.empty)
  1424. ret = ret && UIElementDuplicate();
  1425. return ret;
  1426. }
  1427. return false;
  1428. }
  1429. bool Copy()
  1430. {
  1431. if (CheckHierarchyWindowFocus())
  1432. {
  1433. bool ret = true;
  1434. if (!selectedNodes.empty || !selectedComponents.empty)
  1435. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneCopy() : false); // Node and component is mutually exclusive for copy action
  1436. // Not mutually exclusive
  1437. if (!selectedUIElements.empty)
  1438. ret = ret && UIElementCopy();
  1439. return ret;
  1440. }
  1441. return false;
  1442. }
  1443. bool Paste()
  1444. {
  1445. if (CheckHierarchyWindowFocus())
  1446. {
  1447. bool ret = true;
  1448. if (editNode !is null && !sceneCopyBuffer.empty)
  1449. ret = ret && ScenePaste();
  1450. // Not mutually exclusive
  1451. if (editUIElement !is null && !uiElementCopyBuffer.empty)
  1452. ret = ret && UIElementPaste();
  1453. return ret;
  1454. }
  1455. return false;
  1456. }
  1457. bool BlenderModeDelete()
  1458. {
  1459. if (ui.focusElement is null)
  1460. {
  1461. Array<UIElement@> actions;
  1462. actions.Push(CreateContextMenuItem("Delete?", "HandleBlenderModeDelete"));
  1463. actions.Push(CreateContextMenuItem("Cancel", "HandleEmpty"));
  1464. if (actions.length > 0)
  1465. {
  1466. ActivateContextMenu(actions);
  1467. return true;
  1468. }
  1469. }
  1470. return false;
  1471. }
  1472. bool Delete()
  1473. {
  1474. if (CheckHierarchyWindowFocus())
  1475. {
  1476. bool ret = true;
  1477. if (!selectedNodes.empty || !selectedComponents.empty)
  1478. ret = ret && SceneDelete();
  1479. // Not mutually exclusive
  1480. if (!selectedUIElements.empty)
  1481. ret = ret && UIElementDelete();
  1482. return ret;
  1483. }
  1484. return false;
  1485. }
  1486. bool SelectAll()
  1487. {
  1488. if (CheckHierarchyWindowFocus())
  1489. {
  1490. if (!selectedNodes.empty || !selectedComponents.empty)
  1491. return SceneSelectAll();
  1492. else if (!selectedUIElements.empty || hierarchyList.items[GetListIndex(editorUIElement)].selected)
  1493. return UIElementSelectAll();
  1494. else
  1495. return SceneSelectAll(); // If nothing is selected yet, fall back to scene select all
  1496. }
  1497. return false;
  1498. }
  1499. bool DeselectAll()
  1500. {
  1501. if (CheckHierarchyWindowFocus())
  1502. {
  1503. BeginSelectionModify();
  1504. hierarchyList.ClearSelection();
  1505. EndSelectionModify();
  1506. return true;
  1507. }
  1508. return false;
  1509. }
  1510. bool ResetToDefault()
  1511. {
  1512. if (CheckHierarchyWindowFocus())
  1513. {
  1514. bool ret = true;
  1515. if (!selectedNodes.empty || !selectedComponents.empty)
  1516. ret = ret && (selectedNodes.empty || selectedComponents.empty ? SceneResetToDefault() : false); // Node and component is mutually exclusive for reset-to-default action
  1517. // Not mutually exclusive
  1518. if (!selectedUIElements.empty)
  1519. ret = ret && UIElementResetToDefault();
  1520. return ret;
  1521. }
  1522. return false;
  1523. }
  1524. void ClearEditActions()
  1525. {
  1526. undoStack.Clear();
  1527. undoStackPos = 0;
  1528. }
  1529. void SaveEditAction(EditAction@ action)
  1530. {
  1531. // Create a group with 1 action
  1532. EditActionGroup group;
  1533. group.actions.Push(action);
  1534. SaveEditActionGroup(group);
  1535. }
  1536. void SaveEditActionGroup(EditActionGroup@ group)
  1537. {
  1538. if (group.actions.empty)
  1539. return;
  1540. // Truncate the stack first to current pos
  1541. undoStack.Resize(undoStackPos);
  1542. undoStack.Push(group);
  1543. ++undoStackPos;
  1544. // Limit maximum undo steps
  1545. if (undoStack.length > MAX_UNDOSTACK_SIZE)
  1546. {
  1547. undoStack.Erase(0);
  1548. --undoStackPos;
  1549. }
  1550. }
  1551. void BeginSelectionModify()
  1552. {
  1553. // A large operation on selected nodes is about to begin. Disable intermediate selection updates
  1554. inSelectionModify = true;
  1555. // Cursor shape reverts back to normal automatically after the large operation is completed
  1556. ui.cursor.shape = CS_BUSY;
  1557. }
  1558. void EndSelectionModify()
  1559. {
  1560. // The large operation on selected nodes has ended. Update node/component selection now
  1561. inSelectionModify = false;
  1562. HandleHierarchyListSelectionChange();
  1563. }
  1564. void HandleHierarchyContextCreateReplicatedNode()
  1565. {
  1566. CreateNode(REPLICATED);
  1567. }
  1568. void HandleHierarchyContextCreateLocalNode()
  1569. {
  1570. CreateNode(LOCAL);
  1571. }
  1572. void HandleHierarchyContextDuplicate()
  1573. {
  1574. Duplicate();
  1575. }
  1576. void HandleHierarchyContextCopy()
  1577. {
  1578. Copy();
  1579. }
  1580. void HandleHierarchyContextCut()
  1581. {
  1582. Cut();
  1583. }
  1584. void HandleHierarchyContextDelete()
  1585. {
  1586. Delete();
  1587. }
  1588. void HandleBlenderModeDelete()
  1589. {
  1590. Delete();
  1591. }
  1592. void HandleEmpty()
  1593. {
  1594. //just doing nothing
  1595. }
  1596. void HandleHierarchyContextPaste()
  1597. {
  1598. Paste();
  1599. }
  1600. void HandleHierarchyContextResetToDefault()
  1601. {
  1602. ResetToDefault();
  1603. }
  1604. void HandleHierarchyContextResetPosition()
  1605. {
  1606. SceneResetPosition();
  1607. }
  1608. void HandleHierarchyContextResetRotation()
  1609. {
  1610. SceneResetRotation();
  1611. }
  1612. void HandleHierarchyContextResetScale()
  1613. {
  1614. SceneResetScale();
  1615. }
  1616. void HandleHierarchyContextEnableDisable()
  1617. {
  1618. SceneToggleEnable();
  1619. }
  1620. void HandleHierarchyContextUnparent()
  1621. {
  1622. SceneUnparent();
  1623. }
  1624. void HandleHierarchyContextUIElementCloseUILayout()
  1625. {
  1626. CloseUILayout();
  1627. }
  1628. void HandleHierarchyContextUIElementCloseAllUILayouts()
  1629. {
  1630. CloseAllUILayouts();
  1631. }
  1632. void CollapseHierarchy()
  1633. {
  1634. Array<uint> oldSelections = hierarchyList.selections;
  1635. Array<uint> selections = {0};
  1636. hierarchyList.SetSelections(selections);
  1637. for (uint i = 0; i < selections.length; ++i)
  1638. hierarchyList.Expand(selections[i], false, true);
  1639. // only scene's scope expand by default
  1640. hierarchyList.Expand(0, true, false);
  1641. hierarchyList.SetSelections(oldSelections);
  1642. }
  1643. void CollapseHierarchy(StringHash eventType, VariantMap& eventData)
  1644. {
  1645. CollapseHierarchy();
  1646. }
  1647. void HandleShowID(StringHash eventType, VariantMap& eventData)
  1648. {
  1649. CheckBox@ checkBox = eventData["Element"].GetPtr();
  1650. showID = checkBox.checked;
  1651. UpdateHierarchyItem(editorScene, false);
  1652. CollapseHierarchy();
  1653. }