vicinityslotscontainer.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. class VicinitySlotsContainer: Container
  2. {
  3. protected ref AttachmentsGroupContainer m_Container;
  4. protected int m_ItemsCount;
  5. protected int m_SlotsCount;
  6. protected ref array<EntityAI> m_ShowedItems;
  7. void VicinitySlotsContainer( LayoutHolder parent )
  8. {
  9. m_Container = new AttachmentsGroupContainer(this);
  10. ref SlotsContainer con = new SlotsContainer( m_Container, null );
  11. m_Container.Insert( con );
  12. m_Body.Insert( m_Container );
  13. for( int j = 0; j < ITEMS_IN_ROW; j++ )
  14. {
  15. SlotsIcon icon = con.GetSlotIcon( j );
  16. WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), m_Parent, "OnDropReceivedFromIcon" );
  17. WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader" );
  18. WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader" );
  19. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), m_Parent, "DraggingOverIcon" );
  20. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), m_Parent, "DraggingOverHeader" );
  21. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetMainWidget(), m_Parent, "DraggingOverHeader" );
  22. WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(), this, "DoubleClick" );
  23. WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "MouseClick" );
  24. WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(), this, "MouseButtonDown" );
  25. }
  26. con.SetColumnCount(0);
  27. con.SetForceShow(true);
  28. WidgetEventHandler.GetInstance().RegisterOnDropReceived( m_Container.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader" );
  29. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( m_Container.GetMainWidget(), m_Parent, "DraggingOverHeader" );
  30. m_ShowedItems = new array<EntityAI>;
  31. }
  32. bool IsItemWithContainerActive()
  33. {
  34. EntityAI ent = GetFocusedItem();
  35. return ent && ( ent.GetInventory().GetCargo() || (ent.GetSlotsCountCorrect() > 0 && ent.CanDisplayAnyAttachmentSlot()) );
  36. //TODO: also check for cargo visibility maybe?
  37. }
  38. override bool IsItemWithQuantityActive()
  39. {
  40. EntityAI ent = GetFocusedItem();
  41. return ent && QuantityConversions.HasItemQuantity( ent ) && ent.CanBeSplit();
  42. }
  43. override bool IsItemActive()
  44. {
  45. EntityAI ent = GetFocusedItem();
  46. return ent && !IsItemWithQuantityActive() && !IsItemWithContainerActive();
  47. }
  48. bool IsEmptyItemActive()
  49. {
  50. EntityAI ent = GetFocusedItem();
  51. return ent == null;
  52. }
  53. //TODO MW Adjust this
  54. override bool IsDisplayable()
  55. {
  56. return true;
  57. }
  58. bool IsTakeable()
  59. {
  60. EntityAI ent = GetFocusedItem();
  61. return ent.IsTakeable();
  62. }
  63. override bool CanCombineAmmo()
  64. {
  65. PlayerBase m_player = PlayerBase.Cast( GetGame().GetPlayer() );
  66. ItemBase ent = ItemBase.Cast( GetFocusedItem() );
  67. ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
  68. ActionManagerClient amc;
  69. Class.CastTo(amc, m_player.GetActionManager());
  70. return ( amc.CanPerformActionFromInventory( item_in_hands, ent ) || amc.CanSetActionFromInventory( item_in_hands, ent ) );
  71. }
  72. override bool InspectItem()
  73. {
  74. EntityAI ent = GetFocusedItem();
  75. if( ent )
  76. {
  77. InspectItem( ent );
  78. return true;
  79. }
  80. return false;
  81. }
  82. override bool TransferItem()
  83. {
  84. if (CanTakeToInventory())
  85. {
  86. ItemBase ent = ItemBase.Cast(GetFocusedItem());
  87. if (ent)
  88. {
  89. if (ent.IsTakeable())
  90. {
  91. InventoryLocation il = new InventoryLocation;
  92. GetGame().GetPlayer().GetInventory().FindFreeLocationFor( ent, FindInventoryLocationType.CARGO, il );
  93. if (il.IsValid() && GetGame().GetPlayer().GetInventory().LocationCanAddEntity( il ))
  94. {
  95. SplitItemUtils.TakeOrSplitToInventoryLocation( PlayerBase.Cast( GetGame().GetPlayer() ), il );
  96. #ifdef PLATFORM_CONSOLE
  97. if (GetGame().GetInput().GetCurrentInputDevice() == EInputDeviceType.CONTROLLER)
  98. {
  99. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(PrepareOwnedTooltipAfterItemTransfer, 100); //update item tooltip after vicinity item has been transfered and the current selected row gets populated with a new item
  100. }
  101. #endif
  102. return true;
  103. }
  104. }
  105. }
  106. }
  107. return false;
  108. }
  109. override bool Combine()
  110. {
  111. ItemBase ent = ItemBase.Cast( GetFocusedItem() );
  112. ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
  113. Icon hands_icon = ItemManager.GetInstance().GetHandsPreview().GetIcon();
  114. if( item_in_hands && ent && hands_icon )
  115. {
  116. return hands_icon.CombineItems( item_in_hands, ent );
  117. }
  118. return false;
  119. }
  120. override bool Select()
  121. {
  122. SlotsIcon selected_slot = ItemManager.GetInstance().GetSelectedIcon();
  123. EntityAI ent = GetFocusedItem();
  124. ItemBase selected_item = ItemBase.Cast(ItemManager.GetInstance().GetSelectedItem());
  125. if( !(selected_slot && selected_slot.IsOutOfReach() ) )
  126. {
  127. if( selected_item )
  128. {
  129. if( ent != selected_item)
  130. {
  131. if( selected_item && GetGame().GetPlayer().CanDropEntity( selected_item ) )
  132. {
  133. bool draggable = false;
  134. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  135. draggable = !player.GetInventory().HasInventoryReservation( selected_item, null ) && !player.IsItemsToDelete();
  136. draggable = draggable && selected_item.GetInventory().CanRemoveEntity();
  137. if( draggable && m_ShowedItems.Find( selected_item ) == -1 )
  138. {
  139. if( selected_item.GetTargetQuantityMax() < selected_item.GetQuantity() )
  140. selected_item.SplitIntoStackMaxClient( null, -1 );
  141. else
  142. player.PhysicalPredictiveDropItem( selected_item );
  143. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  144. return true;
  145. }
  146. }
  147. }
  148. }
  149. else
  150. {
  151. if( ent && ent.GetInventory().CanRemoveEntity())
  152. {
  153. EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
  154. if( item_in_hands )
  155. {
  156. if( GameInventory.CanSwapEntitiesEx( item_in_hands, ent ) )
  157. {
  158. GetGame().GetPlayer().PredictiveSwapEntities( item_in_hands, ent );
  159. return true;
  160. }
  161. }
  162. else
  163. {
  164. if( GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( ent ) )
  165. {
  166. GetGame().GetPlayer().PredictiveTakeEntityToHands( ent );
  167. return true;
  168. }
  169. }
  170. }
  171. }
  172. }
  173. return false;
  174. }
  175. void ~VicinitySlotsContainer()
  176. {
  177. for ( int i = 0; i < m_Container.Count(); i++ )
  178. {
  179. Container c = ClosableContainer.Cast( m_Container.Get( i / ITEMS_IN_ROW ) );
  180. if( c && c.GetMainWidget() )
  181. {
  182. delete m_Container.Get( i / ITEMS_IN_ROW ).GetMainWidget();
  183. }
  184. }
  185. }
  186. override void SetLayoutName()
  187. {
  188. m_LayoutName = WidgetLayoutName.Container;
  189. }
  190. override void OnShow()
  191. {
  192. super.OnShow();
  193. }
  194. int GetRowSlotCount()
  195. {
  196. return GetFocusedContainer().GetColumnCount();
  197. }
  198. //! Decides on the icon visibility
  199. bool ExcludeFromContainer (EntityAI item)
  200. {
  201. int mask = item.GetHideIconMask();
  202. return mask & EInventoryIconVisibility.HIDE_VICINITY;
  203. }
  204. void ShowItemsInContainers( array<EntityAI> items )
  205. {
  206. EntityAI item;
  207. EntityAI selectedItem = ItemManager.GetInstance().GetSelectedItem();
  208. SlotsIcon icon;
  209. int x;
  210. int visible_items_count = 0;
  211. int visible_rows = 0;
  212. ref array<EntityAI> visible_items = new array<EntityAI>;
  213. for ( x = 0; x < items.Count(); ++x )
  214. {
  215. item = items.Get( x );
  216. if ( item == null || ExcludeFromContainer(item) )
  217. continue;
  218. visible_items.Insert( item );
  219. visible_items_count++;
  220. }
  221. RecomputeNumberOfContainers( visible_items );
  222. for ( x = 0; x < visible_items_count; ++x )
  223. {
  224. item = visible_items.Get( x );
  225. int row = (int)Math.Floor( x / ITEMS_IN_ROW );
  226. int column = x % ITEMS_IN_ROW;
  227. icon = SlotsContainer.Cast( m_Container.Get( row ) ).GetSlotIcon( column );
  228. icon.GetMainWidget().Show( true );
  229. icon.GetPanelWidget().SetUserID( item.GetID() );
  230. #ifdef PLATFORM_CONSOLE
  231. if (selectedItem == item)
  232. {
  233. icon.GetMicromanagedPanel().Show(true);
  234. }
  235. else
  236. {
  237. icon.GetMicromanagedPanel().Show(false);
  238. }
  239. #endif
  240. if ( m_ShowedItems.Find( item ) != x )
  241. icon.Init( item );
  242. icon.UpdateInterval();
  243. bool draggable = ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
  244. if ( !draggable && GetDragWidget() == icon.GetPanelWidget() )
  245. CancelWidgetDragging();
  246. ItemManager.GetInstance().SetWidgetDraggable( icon.GetPanelWidget(), draggable );
  247. ref map<int, ref Container> showed_items = ( VicinityContainer.Cast( m_Parent ) ).m_ShowedItemsIDs;
  248. Container conta = Container.Cast( showed_items.Get( item.GetID() ) );
  249. if ( conta )
  250. {
  251. conta.SetSlotIcon(icon);
  252. }
  253. if ( conta && conta.IsDisplayable() )
  254. {
  255. conta.UpdateRadialIcon();
  256. }
  257. else
  258. {
  259. icon.GetRadialIconPanel().Show( false );
  260. if ( conta )
  261. conta.OnHide();
  262. }
  263. }
  264. SlotsContainer slots_last = SlotsContainer.Cast( m_Container.Get( visible_items.Count() / ITEMS_IN_ROW ) );
  265. for ( int c = visible_items_count % ITEMS_IN_ROW; c < ITEMS_IN_ROW; ++c )
  266. {
  267. icon = slots_last.GetSlotIcon( c );
  268. icon.GetMainWidget().Show( false );
  269. icon.Clear();
  270. }
  271. //#ifndef PLATFORM_CONSOLE
  272. if ( visible_items_count % ITEMS_IN_ROW == 0 )
  273. {
  274. slots_last = SlotsContainer.Cast( m_Container.Get( m_Container.Count() - 1 ) );
  275. slots_last.GetSlotIcon( 0 ).GetMainWidget().Show( true );
  276. slots_last.GetSlotIcon( 0 ).GetGhostSlot().Show( false );
  277. slots_last.GetMainWidget().Update();
  278. }
  279. //#endif
  280. m_ShowedItems = visible_items;
  281. }
  282. void DoubleClick(Widget w, int x, int y, int button)
  283. {
  284. if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
  285. {
  286. if( w == null )
  287. {
  288. return;
  289. }
  290. ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
  291. if( !iw )
  292. {
  293. string name = w.GetName();
  294. name.Replace( "PanelWidget", "Render" );
  295. iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  296. }
  297. if( !iw )
  298. {
  299. iw = ItemPreviewWidget.Cast( w );
  300. }
  301. ItemBase item = ItemBase.Cast( iw.GetItem() );
  302. if( !item )
  303. {
  304. return;
  305. }
  306. if( !item.IsTakeable() )
  307. {
  308. return;
  309. }
  310. if( GetGame().GetPlayer().GetInventory().HasInventoryReservation( item, null ) )
  311. {
  312. return;
  313. }
  314. if( !item.GetInventory().CanRemoveEntity() )
  315. return;
  316. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  317. if ( player.GetInventory().HasEntityInInventory( item ) && GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( item ) )
  318. {
  319. player.PredictiveTakeEntityToHands( item );
  320. }
  321. else
  322. {
  323. InventoryLocation dst = new InventoryLocation;
  324. player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ANY, dst );
  325. if( dst.IsValid() && player.GetInventory().LocationCanAddEntity( dst ) )
  326. {
  327. SplitItemUtils.TakeOrSplitToInventoryLocation( player, dst );
  328. }
  329. }
  330. HideOwnedTooltip();
  331. GetGame().GetCallQueue(CALL_CATEGORY_GUI).CallLater(PrepareOwnedTooltipAfterItemTransferClick, 300); //update item tooltip after vicinity item has been transfered and the current selected row gets populated with a new item
  332. InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
  333. if( menu )
  334. {
  335. menu.RefreshQuickbar();
  336. }
  337. }
  338. }
  339. string GetItemQuantityText( EntityAI item )
  340. {
  341. string quantity_text = "";
  342. if ( item.IsInherited( InventoryItem ) )
  343. {
  344. ItemBase item_base = ItemBase.Cast( item );
  345. float quantity = item_base.GetQuantity();
  346. int ammo;
  347. if ( item.IsInherited( Magazine ) )
  348. {
  349. Magazine magazine_item = Magazine.Cast( item );
  350. ammo = magazine_item.GetAmmoCount();
  351. quantity_text = ammo.ToString();
  352. return quantity_text;
  353. }
  354. else if ( item.IsInherited( ItemBook ) )
  355. {
  356. return "";
  357. }
  358. int max = item.GetQuantityMax();
  359. //string unit = item.ConfigGetString( "stackedUnit" );
  360. if ( max > 0 )
  361. {
  362. if ( max == 1 )
  363. {
  364. float tmp = Math.Round( ( quantity / max ) * 100 );
  365. quantity_text = tmp.ToString() + "%";
  366. }
  367. else
  368. {
  369. quantity_text = quantity.ToString();
  370. }
  371. }
  372. }
  373. return quantity_text;
  374. }
  375. int HasItemQuantity( EntityAI item )
  376. {
  377. if ( item.IsInherited( InventoryItem ) )
  378. {
  379. ItemBase item_base = ItemBase.Cast( item );
  380. if ( item.IsInherited( Magazine ) )
  381. {
  382. return QUANTITY_COUNT;
  383. }
  384. else if ( item.IsInherited( ItemBook ) )
  385. {
  386. return QUANTITY_HIDDEN;
  387. }
  388. int max = item.GetQuantityMax();
  389. bool bar = item.ConfigGetBool( "quantityBar" );
  390. if ( max > 0 )
  391. {
  392. if ( max == 1 || bar )
  393. {
  394. return QUANTITY_PROGRESS;
  395. }
  396. else
  397. {
  398. return QUANTITY_COUNT;
  399. }
  400. }
  401. }
  402. return QUANTITY_HIDDEN;
  403. }
  404. float GetItemQuantity( InventoryItem item )
  405. {
  406. float quantity = 0;
  407. if ( item.IsInherited( InventoryItem ) )
  408. {
  409. ItemBase item_base = ItemBase.Cast( item );
  410. if ( item.IsInherited( Magazine ) )
  411. {
  412. Magazine magazine_item = Magazine.Cast( item );
  413. quantity = magazine_item.GetAmmoCount();
  414. }
  415. else
  416. {
  417. quantity = item_base.GetQuantity();
  418. }
  419. }
  420. return quantity;
  421. }
  422. // Mouse button DOWN
  423. void MouseButtonDown( Widget w, int x, int y, int button)
  424. {
  425. string name = w.GetName();
  426. name.Replace( "PanelWidget", "Render" );
  427. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  428. ItemBase item = ItemBase.Cast( item_preview.GetItem() );
  429. bool draggable = ItemManager.GetInstance().EvaluateContainerDragabilityDefault(item);
  430. ItemManager.GetInstance().SetWidgetDraggable( w, draggable );
  431. }
  432. // Mouse button UP <---- exist button down MouseButtonDown ^
  433. void MouseClick( Widget w, int x, int y, int button)
  434. {
  435. string name = w.GetName();
  436. name.Replace( "PanelWidget", "Render" );
  437. ItemPreviewWidget item_preview = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  438. EntityAI item = item_preview.GetItem();
  439. InventoryItem itemAtPos = InventoryItem.Cast( item );
  440. #ifdef DIAG_DEVELOPER
  441. if (itemAtPos && GetDayZGame().IsLeftCtrlDown() && button == MouseState.RIGHT)
  442. {
  443. ShowActionMenu(itemAtPos);
  444. }
  445. else if (m_Parent)
  446. #else
  447. if (m_Parent)
  448. #endif
  449. {
  450. ref map<int, ref Container> showed_items = ( VicinityContainer.Cast( m_Parent ) ).m_ShowedItemsIDs;
  451. if ( item && showed_items )
  452. {
  453. if (button == MouseState.LEFT)
  454. {
  455. VicinityContainer.Cast(m_Parent).ToggleContainer(w, item);
  456. }
  457. if (button == MouseState.RIGHT)
  458. {
  459. if (itemAtPos)
  460. {
  461. itemAtPos.OnRightClick();
  462. }
  463. }
  464. else if (button == MouseState.MIDDLE)
  465. {
  466. InspectItem(itemAtPos);
  467. return;
  468. }
  469. }
  470. }
  471. }
  472. override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
  473. {
  474. ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
  475. if( !ipw )
  476. {
  477. string name = w.GetName();
  478. name.Replace( "PanelWidget", "Render" );
  479. ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  480. }
  481. if( !ipw )
  482. {
  483. ipw = ItemPreviewWidget.Cast( w );
  484. }
  485. if( !ipw.IsInherited( ItemPreviewWidget ) )
  486. {
  487. return;
  488. }
  489. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  490. ItemBase item = ItemBase.Cast(ipw.GetItem());
  491. if( item )
  492. {
  493. if( !item.GetInventory().CanRemoveEntity() )
  494. return;
  495. if( player.CanDropEntity( item ) )
  496. {
  497. if( item.GetTargetQuantityMax() < item.GetQuantity() )
  498. item.SplitIntoStackMaxClient( null, -1 );
  499. else
  500. player.PhysicalPredictiveDropItem( item );
  501. }
  502. }
  503. }
  504. void RecomputeNumberOfContainers( array<EntityAI> items )
  505. {
  506. int number_of_containers = m_Container.m_Body.Count();
  507. int number_of_containers_needed = ( items.Count() / ITEMS_IN_ROW ) + 1;
  508. int difference = number_of_containers_needed - number_of_containers;
  509. int g;
  510. for (g = number_of_containers; g < number_of_containers_needed; g++)
  511. {
  512. SlotsContainer con = new SlotsContainer( m_Container, null );
  513. m_Container.Insert(con, -1, false);
  514. for (int j = 0; j < ITEMS_IN_ROW; j++)
  515. {
  516. SlotsIcon icon = con.GetSlotIcon(j);
  517. WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetPanelWidget(), m_Parent, "OnDropReceivedFromIcon");
  518. WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetGhostSlot(), m_Parent, "OnDropReceivedFromHeader");
  519. WidgetEventHandler.GetInstance().RegisterOnDropReceived(icon.GetMainWidget(), m_Parent, "OnDropReceivedFromHeader");
  520. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetPanelWidget(), m_Parent, "DraggingOverIcon");
  521. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetGhostSlot(), m_Parent, "DraggingOverHeader");
  522. WidgetEventHandler.GetInstance().RegisterOnDraggingOver(icon.GetMainWidget(), m_Parent, "DraggingOverHeader");
  523. WidgetEventHandler.GetInstance().RegisterOnDoubleClick(icon.GetPanelWidget(), this, "DoubleClick");
  524. WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp(icon.GetPanelWidget(), this, "MouseClick");
  525. WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown(icon.GetPanelWidget(), this, "MouseButtonDown");
  526. }
  527. con.SetColumnCount(items.Count() % ITEMS_IN_ROW);
  528. }
  529. for (g = number_of_containers - 1 ; g >= number_of_containers_needed ; g--)
  530. {
  531. Widget w = m_Container.m_Body.Get(g).GetMainWidget();
  532. delete w;
  533. m_Container.m_Body.Remove(g);
  534. }
  535. if ( (items.Count() % ITEMS_IN_ROW) == 0 )
  536. {
  537. SlotsContainer.Cast( m_Container.Get( number_of_containers_needed - 1 ) ).SetColumnCount( ITEMS_IN_ROW );
  538. }
  539. else
  540. {
  541. SlotsContainer.Cast( m_Container.Get( number_of_containers_needed - 1 ) ).SetColumnCount( items.Count() % ITEMS_IN_ROW );
  542. }
  543. for ( int i = 0; i < number_of_containers_needed - 1; i++ )
  544. {
  545. SlotsContainer.Cast( m_Container.Get( i ) ).SetColumnCount( ITEMS_IN_ROW );
  546. }
  547. RecomputeOpenedContainers();
  548. m_Container.RecomputeOpenedContainers();
  549. }
  550. void PrepareOwnedTooltipAfterItemTransfer()
  551. {
  552. if (m_IsActive)
  553. {
  554. float x, y;
  555. SlotsIcon icon = GetFocusedSlotsIcon();
  556. if (icon)
  557. {
  558. icon.GetSelectedPanel().GetScreenPos(x, y);
  559. EntityAI focusedItem = GetFocusedItem();
  560. if (focusedItem)
  561. {
  562. #ifdef PLATFORM_CONSOLE
  563. PrepareOwnedTooltip(focusedItem, -1, y); //custom positioning for the controller
  564. #else
  565. PrepareOwnedTooltip(focusedItem);
  566. #endif
  567. }
  568. }
  569. }
  570. }
  571. void PrepareOwnedTooltipAfterItemTransferClick()
  572. {
  573. Widget w = GetWidgetUnderCursor();
  574. if (!w)
  575. {
  576. return;
  577. }
  578. ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
  579. if (!iw)
  580. {
  581. string name = w.GetName();
  582. name.Replace("PanelWidget", "Render");
  583. iw = ItemPreviewWidget.Cast( w.FindAnyWidget(name));
  584. }
  585. if (!iw)
  586. {
  587. iw = ItemPreviewWidget.Cast(w);
  588. if (!iw)
  589. {
  590. return;
  591. }
  592. }
  593. ItemBase item = ItemBase.Cast(iw.GetItem());
  594. if (!item)
  595. {
  596. return;
  597. }
  598. PrepareOwnedTooltip(item);
  599. }
  600. }