container.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313
  1. class Container extends LayoutHolder
  2. {
  3. protected ref array<ref LayoutHolder> m_Body;
  4. protected ref array<LayoutHolder> m_OpenedContainers;
  5. protected int m_ActiveIndex = 0;
  6. protected bool m_LastIndex; //deprecated
  7. protected bool m_Closed;
  8. protected Container m_FocusedContainer;
  9. protected float m_PrevAlpha;
  10. const int ITEMS_IN_ROW = 8;
  11. //protected int m_RowCount;
  12. protected int m_ColumnCount;
  13. protected int m_FocusedColumn = 0;
  14. protected bool m_ForcedHide;
  15. protected bool m_ForcedShow; //used to override displayability condition, but 'm_ForcedHide' takes preference
  16. protected SlotsIcon m_SlotIcon;
  17. protected EntityAI m_Entity;
  18. const int SORT_ATTACHMENTS_OWN = 1; //direct attachments of the parent item
  19. const int SORT_CARGO_OWN = 2; //cargo of the parent item
  20. const int SORT_ATTACHMENTS_NEXT_OFFSET = 2;
  21. const int SORT_CARGO_NEXT_OFFSET = 3;
  22. void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver );
  23. void DraggingOver( Widget w, int x, int y, Widget receiver );
  24. void DraggingOverHeader( Widget w, int x, int y, Widget receiver );
  25. void UpdateSpacer();
  26. Header GetHeader();
  27. void SetHeader(Header header);
  28. void CheckHeaderDragability();
  29. void Container( LayoutHolder parent )
  30. {
  31. m_Body = new array<ref LayoutHolder>;
  32. m_OpenedContainers = new array<LayoutHolder>;
  33. m_PrevAlpha = m_RootWidget.GetAlpha();
  34. m_SlotIcon = null;
  35. m_ForcedHide = false;
  36. m_ForcedShow = false;
  37. m_ActiveIndex = 0;
  38. m_IsActive = false;
  39. }
  40. Container GetFocusedContainer()
  41. {
  42. if (m_ActiveIndex < m_OpenedContainers.Count())
  43. {
  44. return Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  45. }
  46. return null;
  47. }
  48. Container GetContainer(int index)
  49. {
  50. if (index < m_Body.Count())
  51. {
  52. return Container.Cast( m_Body[index] );
  53. }
  54. return null;
  55. }
  56. void SetFocusedContainer( Container cont )
  57. {
  58. m_FocusedContainer = cont;
  59. }
  60. SlotsIcon GetFocusedSlotsIcon()
  61. {
  62. Container c = GetFocusedContainer();
  63. if (c)
  64. {
  65. return c.GetFocusedSlotsIcon();
  66. }
  67. return null;
  68. }
  69. int GetActiveIndex()
  70. {
  71. return m_ActiveIndex;
  72. }
  73. void SetActiveIndex( int index )
  74. {
  75. m_ActiveIndex = index;
  76. }
  77. ScrollWidget GetSlotsScrollWidget()
  78. {
  79. return null;
  80. }
  81. ScrollWidget GetScrollWidget()
  82. {
  83. return null;
  84. }
  85. void UpdateRadialIcon()
  86. {
  87. if ( m_SlotIcon )
  88. {
  89. m_SlotIcon.GetRadialIconPanel().Show( false );
  90. }
  91. }
  92. void SetSlotIcon( SlotsIcon icon )
  93. {
  94. m_SlotIcon = icon;
  95. }
  96. void SetDefaultFocus(bool while_micromanagment_mode = false)
  97. {
  98. m_ActiveIndex = 0;
  99. }
  100. void SetLastFocus()
  101. {
  102. m_ActiveIndex = 0;
  103. m_FocusedColumn = 0;
  104. if ( m_OpenedContainers.Count() > 0 )
  105. {
  106. m_ActiveIndex = m_OpenedContainers.Count() - 1;
  107. }
  108. }
  109. void Unfocus()
  110. {
  111. }
  112. void MoveGridCursor(int direction)
  113. {
  114. if ( direction == Direction.UP )
  115. {
  116. SetPreviousActive();
  117. }
  118. else if ( direction == Direction.DOWN )
  119. {
  120. SetNextActive();
  121. }
  122. else if ( direction == Direction.RIGHT )
  123. {
  124. SetNextRightActive();
  125. }
  126. else if ( direction == Direction.LEFT )
  127. {
  128. SetNextLeftActive();
  129. }
  130. UpdateSelectionIcons();
  131. Inventory.GetInstance().UpdateConsoleToolbar();
  132. }
  133. void ScrollToActiveContainer()
  134. {
  135. ScrollWidget sw = GetScrollWidget();
  136. if (sw)
  137. {
  138. ScrollToActiveContainer(sw);
  139. }
  140. #ifndef PLATFORM_CONSOLE
  141. ScrollWidget ssw = GetSlotsScrollWidget();
  142. if (ssw)
  143. {
  144. ScrollToActiveContainer(ssw);
  145. }
  146. #endif
  147. }
  148. void ScrollToActiveContainer(ScrollWidget sw)
  149. {
  150. if (!sw)
  151. return;
  152. float x, y, y_s;
  153. float f_y,f_h;
  154. float amount;
  155. sw.GetScreenPos(x, y);
  156. sw.GetScreenSize(x, y_s);
  157. f_y = GetFocusedContainerYScreenPos(true);
  158. f_h = GetFocusedContainerHeight(true);
  159. float next_pos = f_y + f_h;
  160. if (next_pos > (y + y_s))
  161. {
  162. amount = sw.GetVScrollPos() + next_pos - (y + y_s) + 2;
  163. sw.VScrollToPos(amount);
  164. }
  165. else if (f_y < y)
  166. {
  167. amount = sw.GetVScrollPos() + f_y - y - 2;
  168. sw.VScrollToPos(amount);
  169. }
  170. //CheckScrollbarVisibility();
  171. }
  172. void CheckScrollbarVisibility()
  173. {
  174. ScrollWidget sw = GetScrollWidget();
  175. if (sw)
  176. {
  177. CheckScrollbarVisibility(sw);
  178. }
  179. #ifndef PLATFORM_CONSOLE
  180. ScrollWidget ssw = GetSlotsScrollWidget();
  181. if (ssw)
  182. {
  183. CheckScrollbarVisibility(ssw);
  184. }
  185. #endif
  186. }
  187. void CheckScrollbarVisibility(ScrollWidget sw)
  188. {
  189. if (!sw)
  190. return;
  191. if (!sw.IsScrollbarVisible())
  192. {
  193. sw.VScrollToPos01(0.0);
  194. }
  195. else if (sw.GetVScrollPos01() > 1.0)
  196. {
  197. sw.VScrollToPos01(1.0);
  198. }
  199. }
  200. void Open()
  201. {
  202. m_Closed = false;
  203. UpdateSelectionIcons();
  204. }
  205. void Close()
  206. {
  207. m_Closed = true;
  208. UpdateSelectionIcons();
  209. }
  210. bool IsOpened()
  211. {
  212. return !m_Closed;
  213. }
  214. void SetOpenForSlotIcon(bool open, SlotsIcon icon = null/*m_SlotIcon*/)
  215. {
  216. if (!icon)
  217. {
  218. icon = m_SlotIcon;
  219. }
  220. if (icon)
  221. {
  222. icon.GetRadialIcon().Show(open);
  223. icon.GetRadialIconClosed().Show(!open);
  224. }
  225. /*else
  226. {
  227. ErrorEx("Dbg No Icon");
  228. }*/
  229. }
  230. void Toggle()
  231. {
  232. if (IsOpened())
  233. {
  234. Close();
  235. }
  236. else
  237. {
  238. Open();
  239. }
  240. SetOpenForSlotIcon(IsOpened());
  241. }
  242. float GetFocusedContainerHeight( bool contents = false )
  243. {
  244. float x, y, result;
  245. if( GetFocusedContainer() )
  246. y = GetFocusedContainer().GetFocusedContainerHeight( contents );
  247. else if( GetRootWidget() )
  248. GetRootWidget().GetScreenSize( x, y );
  249. result = y;
  250. if ( m_ActiveIndex == 0 )
  251. {
  252. if ( GetHeader() )
  253. {
  254. GetHeader().GetRootWidget().GetScreenSize( x, y );
  255. result += y;
  256. }
  257. }
  258. return result;
  259. }
  260. float GetFocusedContainerYPos( bool contents = false )
  261. {
  262. float x, y;
  263. if( GetFocusedContainer() )
  264. y = GetFocusedContainer().GetFocusedContainerYPos( contents );
  265. else if( GetRootWidget() )
  266. GetRootWidget().GetPos( x, y );
  267. return y;
  268. }
  269. float GetFocusedContainerYScreenPos( bool contents = false )
  270. {
  271. float x, y, result;
  272. if( GetFocusedContainer() )
  273. y = GetFocusedContainer().GetFocusedContainerYScreenPos( contents );
  274. else if( GetRootWidget() )
  275. GetRootWidget().GetScreenPos( x, y );
  276. result = y;
  277. if ( m_ActiveIndex == 0 )
  278. {
  279. if ( GetHeader() )
  280. {
  281. GetHeader().GetRootWidget().GetScreenPos( x, y );
  282. result = y;
  283. }
  284. }
  285. return result;
  286. }
  287. int Count()
  288. {
  289. return m_Body.Count();
  290. }
  291. bool SelectItem()
  292. {
  293. if( GetFocusedContainer() )
  294. return GetFocusedContainer().SelectItem();
  295. return false;
  296. }
  297. bool Select()
  298. {
  299. if( GetFocusedContainer() )
  300. return GetFocusedContainer().Select();
  301. return false;
  302. }
  303. bool OnSelectButton()
  304. {
  305. if(GetFocusedContainer())
  306. {
  307. return GetFocusedContainer().OnSelectButton();
  308. }
  309. return false;
  310. }
  311. bool Combine()
  312. {
  313. if( GetFocusedContainer() )
  314. return GetFocusedContainer().Combine();
  315. return true;
  316. }
  317. bool TransferItemToVicinity()
  318. {
  319. if( GetFocusedContainer() )
  320. return GetFocusedContainer().TransferItemToVicinity();
  321. return false;
  322. }
  323. bool TransferItem()
  324. {
  325. if( GetFocusedContainer() )
  326. return GetFocusedContainer().TransferItem();
  327. return false;
  328. }
  329. bool InspectItem()
  330. {
  331. if( GetFocusedContainer() )
  332. return GetFocusedContainer().InspectItem();
  333. return false;
  334. }
  335. bool SplitItem()
  336. {
  337. if (GetFocusedContainer())
  338. {
  339. return GetFocusedContainer().SplitItem();
  340. }
  341. else
  342. {
  343. if (CanSplit())
  344. {
  345. ItemBase.Cast(GetFocusedItem()).OnRightClick();
  346. }
  347. }
  348. return false;
  349. }
  350. bool EquipItem()
  351. {
  352. if (GetFocusedContainer())
  353. return GetFocusedContainer().EquipItem();
  354. if (CanEquip())
  355. {
  356. EntityAI ent = GetFocusedItem();
  357. bool res = false;
  358. if (ent)
  359. {
  360. res = GetGame().GetPlayer().PredictiveTakeOrSwapAttachment(ent);
  361. if(!res)
  362. {
  363. res = GetGame().GetPlayer().PredictiveTakeEntityToInventory(FindInventoryLocationType.ATTACHMENT, ent);
  364. }
  365. }
  366. return res;
  367. }
  368. return false;
  369. }
  370. bool CanOpenCloseContainer()
  371. {
  372. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  373. return false;
  374. EntityAI focusedEntity = GetFocusedItem();
  375. if (focusedEntity)
  376. {
  377. if (GetFocusedContainer())
  378. return GetFocusedContainer().CanOpenCloseContainerEx(focusedEntity);
  379. return CanOpenCloseContainerEx(focusedEntity);
  380. }
  381. return false;
  382. }
  383. bool CanOpenCloseContainerEx(EntityAI focusedEntity)
  384. {
  385. return false;
  386. }
  387. bool CanSplit()
  388. {
  389. EntityAI focusedEntity = GetFocusedItem();
  390. if (focusedEntity)
  391. {
  392. if (GetFocusedContainer())
  393. return GetFocusedContainer().CanSplitEx(focusedEntity);
  394. return CanSplitEx(focusedEntity);
  395. }
  396. return false;
  397. }
  398. bool CanSplitEx(EntityAI focusedEntity)
  399. {
  400. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  401. return false;
  402. if (focusedEntity)
  403. {
  404. if (GetFocusedContainer())
  405. return GetFocusedContainer().CanSplitEx(focusedEntity);
  406. return focusedEntity.CanBeSplit();
  407. }
  408. return false;
  409. }
  410. bool CanDrop()
  411. {
  412. EntityAI focusedEntity = GetFocusedItem();
  413. if (focusedEntity)
  414. {
  415. if (GetFocusedContainer())
  416. return GetFocusedContainer().CanDropEx(focusedEntity);
  417. return CanDropEx(focusedEntity);
  418. }
  419. return false;
  420. }
  421. bool CanDropEx(EntityAI focusedEntity)
  422. {
  423. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  424. return false;
  425. if (focusedEntity)
  426. {
  427. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  428. if (player)
  429. {
  430. return player.CanDropEntity(focusedEntity);
  431. }
  432. }
  433. return false;
  434. }
  435. bool CanSwapOrTakeToHands()
  436. {
  437. EntityAI focusedEntity = GetFocusedItem();
  438. if (focusedEntity)
  439. {
  440. if (GetFocusedContainer())
  441. return GetFocusedContainer().CanSwapOrTakeToHandsEx(focusedEntity);
  442. return CanSwapOrTakeToHandsEx(focusedEntity);
  443. }
  444. return false;
  445. }
  446. bool CanSwapOrTakeToHandsEx(EntityAI focusedEntity)
  447. {
  448. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  449. return false;
  450. if (focusedEntity)
  451. {
  452. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  453. EntityAI entityInHands = player.GetItemInHands();
  454. if (entityInHands)
  455. {
  456. InventoryLocation il = new InventoryLocation();
  457. if (!GameInventory.CanSwapEntitiesEx(focusedEntity, entityInHands))
  458. {
  459. return GameInventory.CanForceSwapEntitiesEx( focusedEntity, null, entityInHands, il );
  460. }
  461. else
  462. {
  463. return true;
  464. }
  465. }
  466. else
  467. {
  468. return player.GetInventory().CanAddEntityIntoHands(focusedEntity);
  469. }
  470. }
  471. return false;
  472. }
  473. bool CanEquip()
  474. {
  475. EntityAI focusedEntity = GetFocusedItem();
  476. if (focusedEntity)
  477. {
  478. if (GetFocusedContainer())
  479. return GetFocusedContainer().CanEquipEx(focusedEntity);
  480. return CanEquipEx(focusedEntity);
  481. }
  482. return false;
  483. }
  484. bool CanEquipEx(EntityAI focusedEntity)
  485. {
  486. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  487. return false;
  488. bool found = false;
  489. if (focusedEntity)
  490. {
  491. InventoryLocation il = new InventoryLocation;
  492. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  493. found = player.GetInventory().FindFreeLocationFor(focusedEntity,FindInventoryLocationType.ATTACHMENT, il);
  494. if (found && il.GetParent().GetInventory().FindAttachment(il.GetSlot()))
  495. {
  496. found = false;
  497. }
  498. else if (!found)
  499. {
  500. for (int i = 0; i < focusedEntity.GetInventory().GetSlotIdCount(); i++)
  501. {
  502. int slot_id = focusedEntity.GetInventory().GetSlotId(i);
  503. EntityAI slot_item = player.GetInventory().FindAttachment( slot_id );
  504. if (slot_item && player.GetInventory().CanSwapEntitiesEx( focusedEntity, slot_item ))
  505. {
  506. found = true;
  507. break;
  508. }
  509. }
  510. }
  511. }
  512. return found;
  513. }
  514. bool CanTakeToInventory()
  515. {
  516. EntityAI focusedEntity = GetFocusedItem();
  517. if (focusedEntity)
  518. {
  519. if (GetFocusedContainer())
  520. return GetFocusedContainer().CanTakeToInventoryEx(focusedEntity);
  521. return CanTakeToInventoryEx(focusedEntity);
  522. }
  523. return false;
  524. }
  525. bool CanTakeToInventoryEx(EntityAI focusedEntity)
  526. {
  527. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  528. return false;
  529. if (focusedEntity)
  530. {
  531. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  532. return player.GetInventory().CanAddEntityToInventory(focusedEntity,FindInventoryLocationType.CARGO);
  533. }
  534. return false;
  535. }
  536. bool CanCombine()
  537. {
  538. EntityAI focusedEntity = GetFocusedItem();
  539. if (focusedEntity)
  540. {
  541. if (GetFocusedContainer())
  542. return GetFocusedContainer().CanCombineEx(focusedEntity);
  543. return CanCombineEx(focusedEntity);
  544. }
  545. return false;
  546. }
  547. bool CanCombineEx(EntityAI focusedEntity)
  548. {
  549. if (ItemManager.GetInstance().IsMicromanagmentMode())
  550. return false;
  551. if (focusedEntity)
  552. {
  553. EntityAI entityInHands = PlayerBase.Cast(GetGame().GetPlayer()).GetItemInHands();
  554. if (focusedEntity != entityInHands)
  555. {
  556. return (ItemManager.GetCombinationFlags(entityInHands, focusedEntity) != 0);
  557. }
  558. }
  559. return false;
  560. }
  561. bool CanCombineAmmo()
  562. {
  563. if( GetFocusedContainer() )
  564. return GetFocusedContainer().CanCombineAmmo();
  565. return false;
  566. }
  567. bool CanAddToQuickbarEx(EntityAI focusedEntity)
  568. {
  569. if ( ItemManager.GetInstance().IsMicromanagmentMode() )
  570. return false;
  571. if (focusedEntity)
  572. {
  573. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  574. if (focusedEntity.GetHierarchyRootPlayer() == player)
  575. {
  576. return true;
  577. }
  578. }
  579. return false;
  580. }
  581. bool AddItemToQuickbarRadial(EntityAI itemToAssign)
  582. {
  583. if ( CanAddToQuickbarEx(itemToAssign) )
  584. {
  585. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  586. DayZPlayerInventory dpi;
  587. dpi = player.GetDayZPlayerInventory();
  588. if (itemToAssign && dpi && !dpi.IsProcessing())
  589. {
  590. RadialQuickbarMenu.SetItemToAssign(itemToAssign);
  591. //open radial quickbar menu
  592. if (!GetGame().GetUIManager().IsMenuOpen(MENU_RADIAL_QUICKBAR))
  593. {
  594. RadialQuickbarMenu.OpenMenu(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
  595. }
  596. }
  597. return true;
  598. }
  599. return false;
  600. }
  601. bool IsEmpty()
  602. {
  603. return m_OpenedContainers.Count() == 0;
  604. }
  605. bool IsItemActive()
  606. {
  607. if( GetFocusedContainer() )
  608. return GetFocusedContainer().IsItemActive();
  609. return false;
  610. }
  611. bool IsItemWithQuantityActive()
  612. {
  613. if( GetFocusedContainer() )
  614. return GetFocusedContainer().IsItemWithQuantityActive();
  615. return false;
  616. }
  617. EntityAI GetFocusedItem()
  618. {
  619. EntityAI item;
  620. if( GetFocusedContainer() )
  621. item = GetFocusedContainer().GetFocusedItem();
  622. return item;
  623. }
  624. EntityAI GetFocusedContainerEntity()
  625. {
  626. EntityAI item;
  627. if( GetFocusedContainer() )
  628. item = GetFocusedContainer().GetFocusedContainerEntity();
  629. return item;
  630. }
  631. int GetColumnCount()
  632. {
  633. return m_ColumnCount;
  634. }
  635. void SetColumnCount( int count )
  636. {
  637. m_ColumnCount = count;
  638. }
  639. int GetFocusedColumn()
  640. {
  641. return m_FocusedColumn;
  642. }
  643. void SetFocusedColumn( int column )
  644. {
  645. m_FocusedColumn = column;
  646. }
  647. override void UpdateInterval()
  648. {
  649. for ( int i = 0; i < m_Body.Count(); i++ )
  650. {
  651. if ( m_Body.Get( i ) )
  652. m_Body.Get( i ).UpdateInterval();
  653. }
  654. CheckHeaderDragability();
  655. }
  656. override void SetLastActive()
  657. {
  658. if (m_IsActive)
  659. {
  660. m_IsActive = true;
  661. if (m_OpenedContainers.Count())
  662. {
  663. SetLastFocus();
  664. if (!m_OpenedContainers[m_ActiveIndex].IsActive())
  665. {
  666. for (int i = 0; i < m_OpenedContainers.Count() - 1; i++)
  667. {
  668. if (m_OpenedContainers[i].IsActive())
  669. {
  670. m_OpenedContainers[i].SetActive(false);
  671. }
  672. }
  673. m_OpenedContainers[m_ActiveIndex].SetLastActive();
  674. }
  675. else
  676. {
  677. m_OpenedContainers[m_ActiveIndex].SetLastActive();
  678. }
  679. }
  680. }
  681. else
  682. {
  683. m_IsActive = true;
  684. if (GetHeader())
  685. {
  686. GetHeader().SetActive(m_IsActive);
  687. }
  688. SetLastFocus();
  689. if (m_OpenedContainers.Count())
  690. {
  691. Container c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
  692. if (c)
  693. {
  694. c.SetLastActive( );
  695. }
  696. }
  697. }
  698. }
  699. override void SetFirstActive()
  700. {
  701. if (!m_IsActive)
  702. {
  703. SetActive(true);
  704. }
  705. else
  706. {
  707. if (m_OpenedContainers.Count())
  708. {
  709. SetDefaultFocus();
  710. if (!m_OpenedContainers[m_ActiveIndex].IsActive())
  711. {
  712. for (int i = 1; i < m_OpenedContainers.Count(); i++)
  713. {
  714. if (m_OpenedContainers[i].IsActive())
  715. {
  716. m_OpenedContainers[i].SetActive(false);
  717. }
  718. }
  719. m_OpenedContainers[m_ActiveIndex].SetActive(true);
  720. }
  721. else
  722. {
  723. m_OpenedContainers[m_ActiveIndex].SetFirstActive();
  724. }
  725. }
  726. }
  727. }
  728. override void SetActive(bool active)
  729. {
  730. if (!active)
  731. {
  732. HideOwnedTooltip();
  733. }
  734. if (!active && !m_IsActive)
  735. return;
  736. super.SetActive( active );
  737. if ( GetHeader() )
  738. {
  739. GetHeader().SetActive(active);
  740. }
  741. if (m_MainWidget.FindAnyWidget("SelectedContainer"))
  742. {
  743. m_MainWidget.FindAnyWidget("SelectedContainer").Show(active);
  744. }
  745. Container c;
  746. if( active )
  747. {
  748. SetDefaultFocus();
  749. if( m_OpenedContainers.Count() )
  750. {
  751. c = Container.Cast(m_OpenedContainers.Get( m_ActiveIndex ));
  752. if (c)
  753. {
  754. c.SetActive(active);
  755. }
  756. }
  757. }
  758. else
  759. {
  760. c = GetFocusedContainer();
  761. if (c)
  762. {
  763. GetFocusedContainer().SetActive(false);
  764. }
  765. Unfocus();
  766. m_ActiveIndex = 0;
  767. m_FocusedColumn = 0;
  768. }
  769. }
  770. void UnfocusAll()
  771. {
  772. for ( int i = 0; i < Count(); i++ )
  773. {
  774. for ( int j = 0; j < ITEMS_IN_ROW; j++ )
  775. {
  776. SlotsIcon icon;
  777. if (Get(i) && Get(i).GetMainWidget())
  778. Get( i ).GetMainWidget().GetUserData(icon);
  779. if (icon)
  780. icon.GetCursorWidget().Show( false );
  781. }
  782. }
  783. }
  784. void UnfocusGrid()
  785. {
  786. if( GetFocusedContainer() )
  787. {
  788. m_FocusedColumn = 0;
  789. GetFocusedContainer().UnfocusAll();
  790. }
  791. }
  792. bool IsLastIndex()
  793. {
  794. return m_ActiveIndex == ( m_OpenedContainers.Count() - 1 );
  795. }
  796. bool IsFirstIndex()
  797. {
  798. return m_ActiveIndex == 0;
  799. }
  800. bool IsFirstContainerFocused()
  801. {
  802. return m_ActiveIndex == 0;
  803. }
  804. bool IsLastContainerFocused()
  805. {
  806. return m_ActiveIndex >= ( m_OpenedContainers.Count() - 1 );
  807. }
  808. void ResetFocusedContainer()
  809. {
  810. if ( GetFocusedContainer() )
  811. {
  812. GetFocusedContainer().ResetFocusedContainer();
  813. }
  814. m_ActiveIndex == 0;
  815. }
  816. void SetNextActive()
  817. {
  818. HideOwnedTooltip();
  819. Container active;
  820. if (m_OpenedContainers.Count())
  821. {
  822. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  823. }
  824. if (active && active.IsActive())
  825. {
  826. active.SetNextActive();
  827. }
  828. if (!active || !active.IsActive())
  829. {
  830. Container next;
  831. if (!IsLastContainerFocused())
  832. {
  833. m_ActiveIndex++;
  834. next = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  835. next.SetActive(true);
  836. }
  837. else if (Container.Cast( GetParent() ))
  838. {
  839. SetActive(false);
  840. }
  841. else
  842. {
  843. SetActive(false);
  844. SetFirstActive();
  845. }
  846. }
  847. }
  848. void SetPreviousActive(bool force = false)
  849. {
  850. HideOwnedTooltip();
  851. Container active;
  852. if (m_OpenedContainers.Count())
  853. {
  854. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  855. }
  856. if (active && active.IsActive())
  857. {
  858. active.SetPreviousActive();
  859. }
  860. if (!active || !active.IsActive())
  861. {
  862. Container prev;
  863. if (!IsFirstContainerFocused())
  864. {
  865. m_ActiveIndex--;
  866. prev = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  867. prev.SetLastActive();
  868. }
  869. else if (Container.Cast( GetParent() ))
  870. {
  871. SetActive(false);
  872. }
  873. else
  874. {
  875. SetActive(false);
  876. SetLastActive();
  877. }
  878. }
  879. }
  880. void SetNextRightActive()
  881. {
  882. Container active;
  883. if (m_OpenedContainers.Count())
  884. {
  885. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  886. }
  887. if (active)
  888. {
  889. active.SetNextRightActive();
  890. }
  891. }
  892. void SetNextLeftActive()
  893. {
  894. Container active;
  895. if (m_OpenedContainers.Count())
  896. {
  897. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  898. }
  899. if (active)
  900. {
  901. active.SetNextLeftActive();
  902. }
  903. }
  904. void SetSameLevelNextActive()
  905. {
  906. HideOwnedTooltip();
  907. Container active, next;
  908. if (m_OpenedContainers.Count())
  909. {
  910. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  911. }
  912. if (active && active.IsActive())
  913. {
  914. SlotsIcon icon = GetFocusedSlotsIcon();
  915. if (icon && icon.GetParent() && SlotsContainer.Cast(icon.GetParent()))
  916. {
  917. SlotsContainer sc = SlotsContainer.Cast(icon.GetParent());
  918. AttachmentsGroupContainer agc = AttachmentsGroupContainer.Cast(sc.GetParent());
  919. if (agc)
  920. {
  921. agc.SetActive(false);
  922. }
  923. }
  924. active.SetSameLevelNextActive();
  925. }
  926. if (!active || !active.IsActive())
  927. {
  928. if (!IsLastContainerFocused())
  929. {
  930. m_ActiveIndex++;
  931. next = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  932. next.SetActive(true);
  933. }
  934. else if (Container.Cast(GetParent()))
  935. {
  936. SetActive(false);
  937. }
  938. else
  939. {
  940. SetActive(false);
  941. SetFirstActive();
  942. }
  943. }
  944. }
  945. void SetSameLevelPreviousActive()
  946. {
  947. HideOwnedTooltip();
  948. Container active;
  949. if (m_OpenedContainers.Count())
  950. {
  951. active = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  952. }
  953. if (active && active.IsActive())
  954. {
  955. SlotsIcon icon = GetFocusedSlotsIcon();
  956. if (icon && icon.GetParent() && SlotsContainer.Cast(icon.GetParent()))
  957. {
  958. SlotsContainer sc = SlotsContainer.Cast(icon.GetParent());
  959. AttachmentsGroupContainer agc = AttachmentsGroupContainer.Cast(sc.GetParent());
  960. if (agc)
  961. {
  962. agc.SetActive(false);
  963. }
  964. }
  965. active.SetSameLevelPreviousActive();
  966. }
  967. if (!active || !active.IsActive())
  968. {
  969. Container prev;
  970. if (!IsFirstContainerFocused())
  971. {
  972. m_ActiveIndex--;
  973. prev = Container.Cast(m_OpenedContainers[m_ActiveIndex]);
  974. prev.SetLastActive();
  975. }
  976. else if (Container.Cast( GetParent() ))
  977. {
  978. SetActive(false);
  979. }
  980. else
  981. {
  982. SetActive(false);
  983. SetLastActive();
  984. }
  985. }
  986. }
  987. void RecomputeOpenedContainers()
  988. {
  989. m_OpenedContainers.Clear();
  990. int i;
  991. bool need_reset_focus = false;
  992. Container c;
  993. for (i = 0; i < m_Body.Count(); i++)
  994. {
  995. c = Container.Cast(m_Body.Get( i ));
  996. if ( c )
  997. {
  998. c.RecomputeOpenedContainers();
  999. if (c.IsDisplayable() && c.IsVisible())
  1000. {
  1001. m_OpenedContainers.Insert(c);
  1002. }
  1003. else if (c.IsActive())
  1004. {
  1005. c.SetActive(false);
  1006. need_reset_focus = true;
  1007. }
  1008. }
  1009. }
  1010. //In case of removing focused container or change order of containers
  1011. if (IsActive())
  1012. {
  1013. if (!need_reset_focus && ( m_ActiveIndex >= m_OpenedContainers.Count() || !m_OpenedContainers[m_ActiveIndex].IsActive() ))
  1014. {
  1015. need_reset_focus = true;
  1016. for (i = 0; i < m_OpenedContainers.Count(); i++)
  1017. {
  1018. if (m_OpenedContainers[i].IsActive())
  1019. {
  1020. need_reset_focus = false;
  1021. m_ActiveIndex = i;
  1022. }
  1023. }
  1024. }
  1025. if (need_reset_focus)
  1026. {
  1027. SetFirstActive();
  1028. }
  1029. }
  1030. }
  1031. override void SetLayoutName()
  1032. {
  1033. m_LayoutName = WidgetLayoutName.Container;
  1034. }
  1035. void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
  1036. {
  1037. if ( pos > -1 && pos < m_Body.Count() )
  1038. {
  1039. if ( pos <= m_ActiveIndex )
  1040. m_ActiveIndex++;
  1041. m_Body.InsertAt( container, pos );
  1042. }
  1043. else
  1044. m_Body.Insert( container );
  1045. if ( immedUpdate )
  1046. Refresh();
  1047. }
  1048. void Remove( LayoutHolder container )
  1049. {
  1050. if( m_Body )
  1051. {
  1052. int index = m_Body.Find( container );
  1053. if( index > -1 )
  1054. {
  1055. index = m_OpenedContainers.Find( container );
  1056. if (index > -1)
  1057. {
  1058. if (index <= m_ActiveIndex)
  1059. {
  1060. if (GetFocusedContainer() == container)
  1061. {
  1062. SetPreviousActive( true );
  1063. }
  1064. else
  1065. {
  1066. m_ActiveIndex--;
  1067. }
  1068. }
  1069. m_OpenedContainers.RemoveItem( container );
  1070. }
  1071. m_Body.RemoveItem( container );
  1072. }
  1073. }
  1074. Refresh();
  1075. }
  1076. LayoutHolder Get( int x )
  1077. {
  1078. return m_Body.Get( x );
  1079. }
  1080. override void Refresh()
  1081. {
  1082. for ( int i = 0; i < m_Body.Count(); i++ )
  1083. {
  1084. if( m_Body.Get( i ) )
  1085. m_Body.Get( i ).Refresh();
  1086. }
  1087. }
  1088. void UpdateBodySpacers()
  1089. {
  1090. for ( int i = 0; i < m_Body.Count(); i++ )
  1091. {
  1092. Container c = Container.Cast( m_Body.Get( i ) );
  1093. if( c && c.IsInherited( Container ) )
  1094. {
  1095. c.UpdateSpacer();
  1096. }
  1097. }
  1098. UpdateSpacer();
  1099. }
  1100. void HideContent( bool force_hide = false )
  1101. {
  1102. if( !m_ForcedHide )
  1103. {
  1104. m_ForcedHide = force_hide;
  1105. }
  1106. for(int i = 0; i < m_Body.Count(); i++)
  1107. {
  1108. if( m_Body.Get( i ) )
  1109. m_Body.Get( i ).OnHide();
  1110. }
  1111. }
  1112. void ShowContent( bool force_show = false )
  1113. {
  1114. if( force_show )
  1115. m_ForcedHide = false;
  1116. if( !m_ForcedHide )
  1117. {
  1118. for(int i = 0; i < m_Body.Count(); i++)
  1119. {
  1120. if( m_Body.Get( i ) )
  1121. m_Body.Get( i ).OnShow();
  1122. }
  1123. }
  1124. }
  1125. void SetForceShow(bool value)
  1126. {
  1127. m_ForcedShow = value;
  1128. }
  1129. override void UpdateSelectionIcons()
  1130. {
  1131. m_Parent.UpdateSelectionIcons();
  1132. }
  1133. void ExpandCollapseContainer(){}
  1134. }