zombiecontainer.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  1. class ZombieContainer: CollapsibleContainer
  2. {
  3. protected ref AttachmentsGroupContainer m_Container;
  4. protected ref ContainerWithCargo m_CargoGrid;
  5. protected ref map<int, SlotsIcon> m_InventorySlots;
  6. protected ref map<EntityAI, ref Container> m_ShowedItems = new ref map<EntityAI, ref Container>;
  7. protected EntityAI m_ZombieEntity;
  8. void ZombieContainer( LayoutHolder parent, int sort = -1 )
  9. {
  10. m_InventorySlots = new ref map<int, SlotsIcon>;
  11. m_Container = new AttachmentsGroupContainer(this);
  12. m_Container.SetHeader(GetHeader());
  13. SetHeaderName();
  14. SetHeader(null);
  15. m_Body.Insert( m_Container );
  16. m_MainWidget = m_RootWidget.FindAnyWidget( "body" );
  17. WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget, this, "OnChildAdd" );
  18. WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget, this, "OnChildRemove" );
  19. RecomputeOpenedContainers();
  20. }
  21. void ~ZombieContainer()
  22. {
  23. if( m_ZombieEntity )
  24. {
  25. m_ZombieEntity.GetOnItemAttached().Remove(ItemAttached);
  26. m_ZombieEntity.GetOnItemDetached().Remove(ItemDetached);
  27. }
  28. }
  29. void SetEntity( EntityAI zombie_entity )
  30. {
  31. m_ZombieEntity = zombie_entity;
  32. m_ZombieEntity.GetOnItemAttached().Insert(ItemAttached);
  33. m_ZombieEntity.GetOnItemDetached().Insert(ItemDetached);
  34. InitGhostSlots();
  35. m_Parent.Refresh();
  36. }
  37. override void UpdateRadialIcon()
  38. {
  39. if ( m_SlotIcon )
  40. {
  41. bool show_radial_icon;
  42. show_radial_icon = IsHidden();
  43. Widget rip = m_SlotIcon.GetRadialIconPanel();
  44. Widget icon_open = m_SlotIcon.GetRadialIcon();
  45. Widget icon_closed = m_SlotIcon.GetRadialIconClosed();
  46. rip.Show( !m_ZombieEntity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) && m_ZombieEntity.CanDisplayCargo());
  47. icon_open.Show( show_radial_icon );
  48. icon_closed.Show( !show_radial_icon );
  49. }
  50. }
  51. override bool IsItemWithQuantityActive()
  52. {
  53. EntityAI ent = GetFocusedItem();
  54. return ent && QuantityConversions.HasItemQuantity( ent ) && ent.CanBeSplit();
  55. }
  56. bool IsContainerWithCargoActive()
  57. {
  58. return GetFocusedContainer().IsInherited( ContainerWithCargo );
  59. }
  60. bool IsItemWithAttachmentsActive()
  61. {
  62. return GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments );
  63. }
  64. bool IsZombieEquipmentActive()
  65. {
  66. return GetFocusedContainer() == m_Container;
  67. }
  68. bool IsItemWithContainerActive()
  69. {
  70. EntityAI ent = GetFocusedItem();
  71. return ent && ( ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0 );
  72. }
  73. bool IsEmptyItemActive()
  74. {
  75. return !GetFocusedItem();
  76. }
  77. override void ExpandCollapseContainer()
  78. {
  79. if( IsZombieEquipmentActive() )
  80. {
  81. ItemPreviewWidget item_preview = GetFocusedSlotsIcon().GetRender();
  82. ToggleContainer( item_preview.GetParent() );
  83. }
  84. }
  85. override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
  86. {
  87. ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
  88. if( !ipw )
  89. {
  90. string name = w.GetName();
  91. name.Replace( "PanelWidget", "Render" );
  92. ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  93. }
  94. if( !ipw )
  95. {
  96. ipw = ItemPreviewWidget.Cast( w );
  97. }
  98. if( !ipw.IsInherited( ItemPreviewWidget ) )
  99. {
  100. return;
  101. }
  102. EntityAI item = ipw.GetItem();
  103. if( !item.GetInventory().CanRemoveEntity() )
  104. return;
  105. if (m_ZombieEntity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ))
  106. GetGame().GetPlayer().PredictiveTakeEntityToTargetCargo( m_ZombieEntity, item );
  107. else if( m_ZombieEntity.GetInventory().CanAddEntityToInventory( item ) )
  108. {
  109. GetGame().GetPlayer().PredictiveTakeEntityToTargetInventory( m_ZombieEntity, FindInventoryLocationType.CARGO, item );
  110. }
  111. }
  112. override void DraggingOverHeader(Widget w, int x, int y, Widget receiver)
  113. {
  114. ItemPreviewWidget ipw = ItemPreviewWidget.Cast(w.FindAnyWidget( "Render" ));
  115. string name = receiver.GetName();
  116. name.Replace("PanelWidget", "Render");
  117. ItemPreviewWidget receiver_iw = ItemPreviewWidget.Cast( receiver.FindAnyWidget( name ) );
  118. EntityAI receiver_item;
  119. if (receiver_iw)
  120. {
  121. receiver_item = receiver_iw.GetItem();
  122. }
  123. if(!ipw)
  124. {
  125. name = w.GetName();
  126. name.Replace("PanelWidget", "Render");
  127. ipw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
  128. }
  129. if(!ipw)
  130. {
  131. ipw = ItemPreviewWidget.Cast(w);
  132. }
  133. if( !ipw.IsInherited(ItemPreviewWidget))
  134. {
  135. return;
  136. }
  137. EntityAI item = ipw.GetItem();
  138. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  139. if(!item.GetInventory().CanRemoveEntity())
  140. return;
  141. }
  142. void OnDropReceivedFromGhostArea(Widget w, int x, int y, Widget receiver)
  143. {
  144. ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render"));
  145. string name = receiver.GetName();
  146. name.Replace("PanelWidget", "Render");
  147. ItemPreviewWidget receiver_iw = ItemPreviewWidget.Cast( receiver.FindAnyWidget(name));
  148. EntityAI receiver_item;
  149. if (receiver_iw)
  150. {
  151. receiver_item = receiver_iw.GetItem();
  152. }
  153. if( !ipw )
  154. {
  155. name = w.GetName();
  156. name.Replace( "PanelWidget", "Render" );
  157. ipw = ItemPreviewWidget.Cast( w.FindAnyWidget(name));
  158. }
  159. if(!ipw)
  160. {
  161. ipw = ItemPreviewWidget.Cast(w);
  162. }
  163. if(!ipw.IsInherited(ItemPreviewWidget))
  164. {
  165. return;
  166. }
  167. EntityAI item = ipw.GetItem();
  168. PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
  169. if(!item.GetInventory().CanRemoveEntity())
  170. {
  171. return;
  172. }
  173. if(receiver_item)
  174. {
  175. if(receiver_item.GetInventory().CanAddAttachment(item))
  176. {
  177. player.PredictiveTakeEntityToTargetAttachment(receiver_item, item);
  178. return;
  179. }
  180. else if(receiver_item.GetInventory().CanAddEntityInCargo(item, item.GetInventory().GetFlipCargo()) && !receiver_item.GetInventory().HasEntityInCargo(item))
  181. {
  182. player.PredictiveTakeEntityToTargetInventory(receiver_item, FindInventoryLocationType.ANY, item);
  183. return;
  184. }
  185. }
  186. if(item)
  187. {
  188. if(m_ZombieEntity.GetInventory().CanAddAttachment(item))
  189. {
  190. player.PredictiveTakeEntityToTargetAttachment(m_ZombieEntity, item);
  191. }
  192. else if(m_ZombieEntity.GetInventory().CanAddEntityToInventory(item))
  193. {
  194. player.PredictiveTakeEntityToTargetInventory(m_ZombieEntity, FindInventoryLocationType.ANY, item);
  195. }
  196. }
  197. if( item )
  198. {
  199. if( m_ZombieEntity.GetInventory().CanAddEntityInto(item, FindInventoryLocationType.CARGO ))
  200. {
  201. player.PredictiveTakeEntityToTargetInventory(m_ZombieEntity, FindInventoryLocationType.CARGO, item);
  202. }
  203. }
  204. }
  205. void SetHeaderName()
  206. {
  207. m_CollapsibleHeader.SetName( "#container_inventory" );
  208. }
  209. void ItemAttached(EntityAI item, string slot_name)
  210. {
  211. int slot = InventorySlots.GetSlotIdFromString( slot_name );
  212. SlotsIcon icon = m_InventorySlots.Get( slot );
  213. if( icon )
  214. {
  215. icon.Init( item );
  216. if( m_ShowedItems.Contains( item ) == false )
  217. {
  218. string name;
  219. if( item.GetSlotsCountCorrect() > 0 )
  220. {
  221. ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments( this, false );
  222. iwca.SetEntity( item );
  223. WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleContainer" );
  224. icon.GetRadialIconPanel().Show( true );
  225. m_ShowedItems.Insert( item, iwca );
  226. Refresh();
  227. }
  228. else if( item.GetInventory().GetCargo() )
  229. {
  230. ContainerWithCargo iwc = new ContainerWithCargo( this, false );
  231. iwc.SetEntity( item );
  232. iwc.UpdateInterval();
  233. WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleContainer" );
  234. m_ShowedItems.Insert( item, iwc );
  235. icon.GetRadialIconPanel().Show(true);
  236. Refresh();
  237. }
  238. }
  239. ClosableContainer conta = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
  240. string config = "CfgVehicles " + item.GetType() + " GUIInventoryAttachmentsProps";
  241. if( conta && conta.IsInherited( ClosableContainer ) )
  242. {
  243. bool show_radial_icon = ( item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0 ) && !GetGame().ConfigIsExisting( config );
  244. Widget rip = icon.GetRadialIconPanel();
  245. Widget icon_open = icon.GetRadialIcon();
  246. Widget icon_closed = icon.GetRadialIconClosed();
  247. rip.Show( show_radial_icon );
  248. icon_open.Show( conta.IsOpened() );
  249. icon_closed.Show( !conta.IsOpened() );
  250. }
  251. RecomputeOpenedContainers();
  252. }
  253. }
  254. void ItemDetached(EntityAI item, string slot_name)
  255. {
  256. int slot = InventorySlots.GetSlotIdFromString( slot_name );
  257. SlotsIcon icon = m_InventorySlots.Get( slot );
  258. if( icon )
  259. {
  260. Container con = m_ShowedItems.Get( item );
  261. if( con )
  262. {
  263. ( Container.Cast( con.m_Parent ) ).Remove( con );
  264. RecomputeOpenedContainers();
  265. GetMainWidget().Update();
  266. Refresh();
  267. m_ShowedItems.Remove( item );
  268. }
  269. icon.Clear();
  270. Inventory in = Inventory.Cast( GetRoot() );
  271. if( in )
  272. in.UpdateConsoleToolbar();
  273. }
  274. }
  275. override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
  276. {
  277. ClosableContainer c;
  278. if (focusedEntity)
  279. {
  280. c = ClosableContainer.Cast( m_ShowedItems.Get( focusedEntity ) );
  281. }
  282. else
  283. {
  284. SlotsIcon icon = GetFocusedSlotsIcon();
  285. if (icon)
  286. {
  287. c = ClosableContainer.Cast(icon.GetContainer());
  288. }
  289. }
  290. if (c && c.IsDisplayable())
  291. {
  292. return true;
  293. }
  294. return false;
  295. }
  296. // mouse button UP or call from ExpandCollapseContainer
  297. void ToggleContainer(Widget w)
  298. {
  299. EntityAI item;
  300. SlotsIcon icon;
  301. ClosableContainer c;
  302. w.GetUserData(icon);
  303. if (icon)
  304. item = icon.GetEntity();
  305. if (item)
  306. c = ClosableContainer.Cast(m_ShowedItems.Get(item));
  307. else
  308. c = ClosableContainer.Cast(icon.GetContainer());
  309. if (c)
  310. c.Toggle();
  311. RecomputeOpenedContainers();
  312. }
  313. void MouseClick(Widget w, int x, int y, int button)
  314. {
  315. ItemBase selectedItem;
  316. SlotsIcon icon;
  317. w.GetUserData(icon);
  318. if (icon)
  319. selectedItem = ItemBase.Cast(icon.GetEntity());
  320. if (selectedItem)
  321. {
  322. switch (button)
  323. {
  324. case MouseState.RIGHT:
  325. #ifdef DIAG_DEVELOPER
  326. if (GetDayZGame().IsLeftCtrlDown())
  327. ShowActionMenu(selectedItem);
  328. #endif
  329. break;
  330. case MouseState.MIDDLE:
  331. InspectItem(selectedItem);
  332. break;
  333. case MouseState.LEFT:
  334. if (g_Game.IsLeftCtrlDown())
  335. {
  336. PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
  337. if (controlledPlayer.CanDropEntity(selectedItem))
  338. {
  339. if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
  340. selectedItem.SplitIntoStackMaxClient(null, -1);
  341. else
  342. controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
  343. ItemManager.GetInstance().SetWidgetDraggable(w, false);
  344. }
  345. }
  346. break;
  347. }
  348. }
  349. }
  350. SlotsIcon GetSlotsIcon( int row, int column )
  351. {
  352. return SlotsContainer.Cast( m_Container.Get( row ) ).GetSlotIcon( column );
  353. }
  354. void InitGhostSlots()
  355. {
  356. int row, column;
  357. SlotsIcon icon;
  358. bool has_cargo = m_ZombieEntity.GetInventory().GetCargo() != null;
  359. string config_path_ghosts_slots = "CfgVehicles ZombieBase InventoryEquipment playerSlots";
  360. array<string> player_ghosts_slots = new array<string>();
  361. GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
  362. for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
  363. {
  364. string slot_name = player_ghosts_slots.Get ( i );
  365. string path = "CfgSlots" + " " + slot_name;
  366. if ( GetGame().ConfigIsExisting( path ) )
  367. {
  368. string icon_name; //icon_name must be in format "set:<setname> image:<imagename>"
  369. GetGame().ConfigGetText( path + " ghostIcon", icon_name );
  370. column = i % ITEMS_IN_ROW;
  371. //START - GetWidgetSlot
  372. row = i / ITEMS_IN_ROW;
  373. if( row >= m_Container.Count() )
  374. {
  375. if ( has_cargo )
  376. {
  377. if( row < ( (player_ghosts_slots.Count() + 1 )/ ITEMS_IN_ROW ) )
  378. AddSlotsContainer( ITEMS_IN_ROW );
  379. else
  380. AddSlotsContainer( ( player_ghosts_slots.Count() + 1 ) % ITEMS_IN_ROW );
  381. }
  382. else
  383. {
  384. if ( row < ( player_ghosts_slots.Count() / ITEMS_IN_ROW ) )
  385. AddSlotsContainer( ITEMS_IN_ROW );
  386. else
  387. AddSlotsContainer( player_ghosts_slots.Count() % ITEMS_IN_ROW );
  388. }
  389. }
  390. icon = GetSlotsIcon( row, column );
  391. icon.GetMainWidget().Show( true );
  392. icon.Clear();
  393. WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(), this, "DoubleClick" );
  394. //END - GetWidgetSlot
  395. WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), this, "OnDropReceivedFromGhostArea" );
  396. WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), this, "OnDropReceivedFromGhostArea" );
  397. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), this, "DraggingOver" );
  398. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), this, "DraggingOver" );
  399. WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), this, "DraggingOver" );
  400. WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(), this, "MouseClick" );
  401. icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,icon_name) );
  402. //END - LoadIconIntoWidgetSlot
  403. GetGame().ConfigGetText( path + " name", slot_name );
  404. int slot_id = InventorySlots.GetSlotIdFromString( slot_name );
  405. icon.SetSlotID( slot_id );
  406. icon.SetSlotDisplayName(InventorySlots.GetSlotDisplayName(slot_id));
  407. m_InventorySlots.Set( slot_id, icon );
  408. int slot = InventorySlots.GetSlotIdFromString( slot_name );
  409. ItemBase item = ItemBase.Cast( m_ZombieEntity.GetInventory().FindAttachment( slot ) );
  410. if( item )
  411. ItemAttached( item, slot_name );
  412. }
  413. }
  414. if( m_ZombieEntity.GetInventory().GetCargo() )
  415. {
  416. row = player_ghosts_slots.Count() / ITEMS_IN_ROW;
  417. column = player_ghosts_slots.Count() % ITEMS_IN_ROW;
  418. if( row >= m_Container.Count() )
  419. {
  420. if( row < ( player_ghosts_slots.Count() + 1 / ITEMS_IN_ROW ) )
  421. AddSlotsContainer( ITEMS_IN_ROW );
  422. else
  423. AddSlotsContainer( ( player_ghosts_slots.Count() + 1 ) % ITEMS_IN_ROW );
  424. }
  425. icon = GetSlotsIcon( row, column );
  426. icon.GetMainWidget().Show( true );
  427. icon.Clear();
  428. icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,m_ZombieEntity.ConfigGetString("GUIInventoryCargoIcon")) );
  429. icon.SetSlotDisplayName( m_ZombieEntity.ConfigGetString("GUIInventoryCargoName") );
  430. icon.GetRadialIconPanel().Show( true );
  431. icon.GetRadialIcon().Show( true );
  432. WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetGhostSlot(), this, "ToggleContainer" );
  433. m_CargoGrid = new ContainerWithCargo( this, false );
  434. m_CargoGrid.SetEntity( m_ZombieEntity );
  435. m_CargoGrid.GetHeader().GetMainWidget().ClearFlags( WidgetFlags.DRAGGABLE );
  436. m_ShowedItems.Insert( m_ZombieEntity, m_CargoGrid );
  437. icon.SetContainer(m_CargoGrid);
  438. }
  439. RecomputeOpenedContainers();
  440. }
  441. void AddSlotsContainer( int row_count )
  442. {
  443. ref SlotsContainer s_cont = new SlotsContainer( m_Container, m_ZombieEntity );
  444. s_cont.SetColumnCount( row_count );
  445. m_Container.Insert( s_cont );
  446. }
  447. Widget GetWidgetSlot( int slot_number )
  448. {
  449. int row = slot_number / ITEMS_IN_ROW;
  450. int column = slot_number % ITEMS_IN_ROW;
  451. return m_Container.Get( row ).GetMainWidget().FindAnyWidget( "Render" + column );
  452. }
  453. void DoubleClick(Widget w, int x, int y, int button)
  454. {
  455. if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
  456. {
  457. if( w == null )
  458. {
  459. return;
  460. }
  461. ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
  462. if( !iw )
  463. {
  464. string name = w.GetName();
  465. name.Replace( "PanelWidget", "Render" );
  466. iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
  467. }
  468. if( !iw )
  469. {
  470. iw = ItemPreviewWidget.Cast( w );
  471. }
  472. ItemBase item = ItemBase.Cast( iw.GetItem() );
  473. if( !item )
  474. {
  475. return;
  476. }
  477. PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
  478. if( player.GetInventory().HasInventoryReservation( item, null ) || player.IsItemsToDelete() )
  479. {
  480. return;
  481. }
  482. if( !item.GetInventory().CanRemoveEntity() )
  483. return;
  484. if ( player.GetInventory().HasEntityInInventory( item ) && GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( item ) )
  485. {
  486. player.PredictiveTakeEntityToHands( item );
  487. }
  488. else
  489. {
  490. InventoryLocation il = new InventoryLocation;
  491. if( player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ANY, il) )
  492. {
  493. if( item.GetTargetQuantityMax(il.GetSlot()) < item.GetQuantity() )
  494. item.SplitIntoStackMaxToInventoryLocationClient( il );
  495. else
  496. player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
  497. }
  498. else if( GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( item ) )
  499. {
  500. if( item.GetTargetQuantityMax() < item.GetQuantity() )
  501. item.SplitIntoStackMaxHandsClient( player );
  502. else
  503. player.PredictiveTakeEntityToHands( item );
  504. }
  505. }
  506. HideOwnedTooltip();
  507. InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
  508. if( menu )
  509. {
  510. menu.RefreshQuickbar();
  511. }
  512. }
  513. }
  514. override void CollapseButtonOnMouseButtonDown(Widget w)
  515. {
  516. super.CollapseButtonOnMouseButtonDown(w);
  517. }
  518. override bool EquipItem()
  519. {
  520. if (CanEquip())
  521. {
  522. if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
  523. {
  524. return GetFocusedContainer().EquipItem();
  525. }
  526. else
  527. {
  528. EntityAI item = GetFocusedItem();
  529. if( item )
  530. {
  531. GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item );
  532. return true;
  533. }
  534. }
  535. }
  536. return false;
  537. }
  538. override bool TransferItem()
  539. {
  540. LeftArea left_area = LeftArea.Cast( GetParent() );
  541. EntityAI item;
  542. if (CanTakeToInventory())
  543. {
  544. if (left_area)
  545. {
  546. if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
  547. {
  548. return GetFocusedContainer().TransferItem();
  549. }
  550. else
  551. {
  552. item = GetFocusedItem();
  553. if( item )
  554. {
  555. GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
  556. return true;
  557. }
  558. }
  559. }
  560. else
  561. {
  562. if (!GetFocusedContainer().IsInherited( ContainerWithCargo ) && !GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
  563. {
  564. item = GetFocusedItem();
  565. if (item)
  566. {
  567. GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
  568. return true;
  569. }
  570. }
  571. }
  572. }
  573. return false;
  574. }
  575. override bool Select()
  576. {
  577. if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
  578. {
  579. return GetFocusedContainer().Select();
  580. }
  581. else
  582. {
  583. SlotsIcon selected_slot = ItemManager.GetInstance().GetSelectedIcon();
  584. EntityAI focused_item = GetFocusedItem();
  585. EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
  586. if( !(selected_slot && selected_slot.IsOutOfReach() ) )
  587. {
  588. if( selected_item )
  589. {
  590. if( selected_item != focused_item)
  591. {
  592. if( selected_item.GetInventory().CanRemoveEntity() )
  593. {
  594. GetGame().GetPlayer().PredictiveTakeEntityToTargetInventory( m_ZombieEntity, FindInventoryLocationType.ANY, selected_item );
  595. ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
  596. return true;
  597. }
  598. }
  599. }
  600. else
  601. {
  602. if( focused_item && focused_item.GetInventory().CanRemoveEntity() )
  603. {
  604. EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
  605. if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
  606. {
  607. if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
  608. {
  609. GetGame().GetPlayer().PredictiveSwapEntities( item_in_hands, focused_item );
  610. return true;
  611. }
  612. else
  613. {
  614. InventoryLocation il_hands_dst = new InventoryLocation;
  615. if( GetGame().GetPlayer().GetHumanInventory().FindFreeLocationFor( item_in_hands, FindInventoryLocationType.ANY, il_hands_dst ) )
  616. {
  617. InventoryMode invMode = InventoryMode.PREDICTIVE;
  618. if ( GetGame().GetPlayer().NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) || GetGame().GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(), GetGame().GetPlayer()) )
  619. invMode = InventoryMode.JUNCTURE;
  620. GetGame().GetPlayer().GetHumanInventory().ForceSwapEntities( InventoryMode.JUNCTURE, focused_item, item_in_hands, il_hands_dst );
  621. return true;
  622. }
  623. }
  624. }
  625. else
  626. {
  627. if( GetGame().GetPlayer().GetHumanInventory().CanAddEntityInHands( focused_item ) )
  628. {
  629. GetGame().GetPlayer().PredictiveTakeEntityToHands( focused_item );
  630. return true;
  631. }
  632. }
  633. }
  634. }
  635. }
  636. }
  637. return false;
  638. }
  639. override bool TransferItemToVicinity()
  640. {
  641. if (CanDrop())
  642. {
  643. if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
  644. {
  645. return GetFocusedContainer().TransferItemToVicinity();
  646. }
  647. else
  648. {
  649. Man player = GetGame().GetPlayer();
  650. ItemBase item = ItemBase.Cast( GetFocusedItem() );
  651. if( item && player.CanDropEntity( item ) )
  652. {
  653. if( item.GetTargetQuantityMax() < item.GetQuantity() )
  654. item.SplitIntoStackMaxClient( null, -1 );
  655. else
  656. player.PhysicalPredictiveDropItem( item );
  657. return true;
  658. }
  659. }
  660. }
  661. return false;
  662. }
  663. }