container.c 25 KB

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