Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
playercontainer.c
Go to the documentation of this file.
2 {
3  protected ref AttachmentsGroupContainer m_PlayerAttachmentsContainer;
4  protected ref map<int, SlotsIcon> m_InventorySlots;
5  protected ref map<EntityAI, ref Container> m_ShowedItems = new ref map<EntityAI, ref Container>;
6  protected ref map<int, ref Container> m_ShowedItemsIDs = new ref map<int, ref Container>;
7  protected PlayerBase m_Player;
8 
9  protected const int HEADER_INDEX_OFFSET = 2;
10 
11  override void UpdateRadialIcon()
12  {
13  if ( m_SlotIcon )
14  {
15  bool show_radial_icon;
16  show_radial_icon = IsHidden();
17  Widget rip = m_SlotIcon.GetRadialIconPanel();
18  rip.Show( !m_Player.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) && m_Player.CanDisplayCargo());
19  SetOpenForSlotIcon(show_radial_icon);
20  }
21  }
22 
23  bool HasEntityContainerVisible( EntityAI entity )
24  {
25  ClosableContainer cont = ClosableContainer.Cast( m_ShowedItems.Get( entity ) );
26  return ( cont && cont.IsOpened() );
27  }
28 
29  SlotsIcon GetSlotsIcon( int row, int column )
30  {
31  return m_PlayerAttachmentsContainer.GetSlotsIcon(row, column);
32  }
33 
34  void PlayerContainer( LayoutHolder parent, int sort = -1 )
35  {
36  m_InventorySlots = new ref map<int, SlotsIcon>;
37  m_PlayerAttachmentsContainer = new AttachmentsGroupContainer(this);
38 
39  m_PlayerAttachmentsContainer.SetHeader(GetHeader());
40  m_CollapsibleHeader.SetName( "#container_inventory" );
41  SetHeader(null);
42  m_Body.Insert( m_PlayerAttachmentsContainer );
43  m_MainWidget = m_RootWidget.FindAnyWidget( "body" );
44  m_PlayerAttachmentsContainer.GetRootWidget().SetColor(166 << 24 | 80 << 16 | 80 << 8 | 80);
45  WidgetEventHandler.GetInstance().RegisterOnChildAdd( m_MainWidget, this, "OnChildAdd" );
46  WidgetEventHandler.GetInstance().RegisterOnChildRemove( m_MainWidget, this, "OnChildRemove" );
47 
48  //START - InitGhostSlots
49  string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
50  ref array<string> player_ghosts_slots = new array<string>;
51  GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
52 
53  for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
54  {
55  string slot_name = player_ghosts_slots.Get ( i );
56  string path = "CfgSlots" + " " + slot_name;
57 
58  if ( GetGame().ConfigIsExisting( path ) )
59  {
60  string icon_name; //icon_name must be in format "set:<setname> image:<imagename>"
61  GetGame().ConfigGetText( path + " ghostIcon", icon_name );
62  int slot_number = i;
63  int column = slot_number % ITEMS_IN_ROW;
64 
65  //START - GetWidgetSlot
66  int row = slot_number / ITEMS_IN_ROW;
67  if( row >= m_PlayerAttachmentsContainer.Count() )
68  {
69  if( row < ( player_ghosts_slots.Count() / ITEMS_IN_ROW ) )
70  AddSlotsContainer( ITEMS_IN_ROW );
71  else
72  AddSlotsContainer( player_ghosts_slots.Count() % ITEMS_IN_ROW );
73  }
74 
75  SlotsIcon icon = GetSlotsIcon( row, column );
76 
77  icon.GetMainWidget().Show( true );
78  icon.Clear();
79 
80  WidgetEventHandler.GetInstance().RegisterOnDoubleClick( icon.GetPanelWidget(), this, "DoubleClick" );
81 
82  //END - GetWidgetSlot
83  WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetPanelWidget(), this, "OnDropReceivedFromGhostArea" );
84  WidgetEventHandler.GetInstance().RegisterOnDropReceived( icon.GetGhostSlot(), this, "OnDropReceivedFromGhostArea" );
85  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetGhostSlot(), this, "DraggingOver" );
86  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( icon.GetPanelWidget(), this, "DraggingOver" );
87  WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( icon.GetPanelWidget(), this, "MouseClick" );
88 
89  icon.GetGhostSlot().LoadImageFile( 0, StaticGUIUtils.VerifyIconImageString(StaticGUIUtils.IMAGESETGROUP_INVENTORY,icon_name) );
90  //END - LoadIconIntoWidgetSlot
91 
92  GetGame().ConfigGetText( path + " name", slot_name );
93  int slot_id = InventorySlots.GetSlotIdFromString( slot_name );
94  icon.SetSlotID(slot_id);
95  icon.SetSlotDisplayName(InventorySlots.GetSlotDisplayName(slot_id));
96  m_InventorySlots.Set( slot_id, icon );
97  }
98  }
99  m_PlayerAttachmentsContainer.GetMainWidget().Update();
100  //END - InitGhostSlots
101  RecomputeOpenedContainers();
102  }
103 
104  void ~PlayerContainer()
105  {
106  if( m_Player )
107  {
108  m_Player.GetOnItemAttached().Remove(ItemAttached);
109  m_Player.GetOnItemDetached().Remove(ItemDetached);
110  m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
111  m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
112  }
113  }
114 
115  void ItemAttached(EntityAI item, string slot_name)
116  {
117  int slot = InventorySlots.GetSlotIdFromString( slot_name );
118  SlotsIcon icon = m_InventorySlots.Get( slot );
119 
120  if( icon )
121  {
122  if( icon.IsReserved())
123  m_Player.GetOnAttachmentReleaseLock().Invoke(item, slot);
124 
125  icon.Init( item );
126 
127  if( m_ShowedItems.Contains( item ) == false )
128  {
129  string name;
130  int sort_index = Inventory.GetPlayerAttachmentIndex( slot );
131  int current_sort = 9999;
132  if( GetFocusedContainer() )
133  current_sort = GetFocusedContainer().GetRootWidget().GetSort();
134 
135  if( item.GetSlotsCountCorrect() > 0 )
136  {
137  ContainerWithCargoAndAttachments iwca = new ContainerWithCargoAndAttachments( this, sort_index );
138  iwca.SetEntity( item );
139  iwca.SetSlotIcon( icon );
140  WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleWidget" );
141 
142  if( iwca.IsDisplayable() )
143  {
144  icon.GetRadialIconPanel().Show( true );
145  }
146  m_ShowedItems.Insert( item, iwca );
147  RecomputeOpenedContainers();
148  Refresh();
149  }
150  else if( item.GetInventory().GetCargo() )
151  {
152  ContainerWithCargo iwc = new ContainerWithCargo( this, sort_index );
153  iwc.SetEntity( item );
154  iwc.SetSlotIcon( icon );
155  iwc.UpdateInterval();
156  WidgetEventHandler.GetInstance().RegisterOnMouseButtonUp( icon.GetPanelWidget(), this, "ToggleWidget" );
157  m_ShowedItems.Insert( item, iwc );
158  RecomputeOpenedContainers();
159  if( iwc.IsDisplayable() )
160  icon.GetRadialIconPanel().Show(true);
161 
162  Refresh();
163  }
164  }
165 
166  ClosableContainer conta = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
167  string config = "CfgVehicles " + item.GetType() + " GUIInventoryAttachmentsProps";
168  if( conta && conta.IsInherited( ClosableContainer ) )
169  {
170  bool show_radial_icon = ( item.GetInventory().GetCargo() || item.GetSlotsCountCorrect() > 0 ) && !GetGame().ConfigIsExisting( config );
171  Widget rip = icon.GetRadialIconPanel();
172 
173  rip.Show( show_radial_icon );
174  SetOpenForSlotIcon(conta.IsOpened(),icon);
175  }
176  }
177  UpdateSelectionIcons();
178  }
179 
180  void ItemDetached(EntityAI item, string slot_name)
181  {
182  int slot = InventorySlots.GetSlotIdFromString( slot_name );
183  SlotsIcon icon = m_InventorySlots.Get( slot );
184 
185  if( icon )
186  {
187  Container con = m_ShowedItems.Get( item );
188  if( con )
189  {
190  ( Container.Cast( con.m_Parent ) ).Remove( con );
191  RecomputeOpenedContainers();
192  GetMainWidget().Update();
193  Refresh();
194  m_ShowedItems.Remove( item );
195  }
196 
197  icon.Clear();
198  Inventory in = Inventory.Cast( GetRoot() );
199  if( in )
200  in.UpdateConsoleToolbar();
201  }
202  UpdateSelectionIcons();
203  }
204 
205  void OnAttachmentReservationSet( EntityAI item, int slot_id )
206  {
207  SlotsIcon icon = m_InventorySlots.Get( slot_id );
208 
209  if( item )
210  {
211  icon.Init( item, true );
212  }
213  }
214 
215  void OnAttachmentReservationRelease( EntityAI item, int slot_id )
216  {
217  SlotsIcon icon = m_InventorySlots.Get( slot_id );
218  icon.Clear();
219  }
220 
221  void AddSlotsContainer( int row_count )
222  {
223  SlotsContainer container = new SlotsContainer(m_PlayerAttachmentsContainer, m_Player);
224  container.SetColumnCount(row_count);
225  m_PlayerAttachmentsContainer.Insert(container);
226  }
227 
228  void MouseClick( Widget w, int x, int y, int button )
229  {
230  SlotsIcon icon;
231  w.GetUserData(icon);
232 
233  ItemBase selectedItem;
234  bool isReserved;
235 
236  if (icon)
237  {
238  selectedItem = ItemBase.Cast(icon.GetEntity());
239  isReserved = icon.IsReserved();
240 
241  }
242 
243  if (selectedItem)
244  {
245  switch (button)
246  {
247  case MouseState.RIGHT:
248  #ifdef DIAG_DEVELOPER
249  if (GetDayZGame().IsLeftCtrlDown())
250  ShowActionMenu(selectedItem);
251  #endif
252 
253  if (isReserved)
254  {
255  GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(selectedItem);
256  m_Player.GetOnAttachmentReleaseLock().Invoke(selectedItem, icon.GetSlotID());
257  }
258  break;
259 
260  case MouseState.MIDDLE:
261  if (!isReserved)
262  InspectItem(selectedItem);
263 
264  break;
265 
266  case MouseState.LEFT:
267  if (!isReserved)
268  {
269  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
270  if (g_Game.IsLeftCtrlDown())
271  {
272  if (controlledPlayer.CanDropEntity(selectedItem))
273  {
274  if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
275  selectedItem.SplitIntoStackMaxClient(null, -1);
276  else
277  controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
278  }
279  }
280  else
281  {
282  bool draggable = !m_Player.GetInventory().HasInventoryReservation(selectedItem, null ) && !m_Player.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !m_Player.IsItemsToDelete();
283  ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
284  }
285  }
286  break;
287  }
288  }
289  }
290 
291  float GetMainContainerTopPos()
292  {
293  float x, y;
294  GetRootWidget().GetScreenPos( x, y );
295  return y;
296  }
297 
298  float GetMainContainerBottomPos()
299  {
300  float x, y;
301  float x2, y2;
302  GetRootWidget().GetScreenPos( x, y );
303  GetRootWidget().GetScreenSize( x2, y2 );
304  y += y2;
305  return y;
306  }
307 
308  override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
309  {
310  ClosableContainer c_cont = ClosableContainer.Cast( container );
311  if (c_cont && m_Body.Count() > 1)
312  {
313  ClosableContainer prev = ClosableContainer.Cast(m_Body.Get( 1 ));
314  int index = 1;
315  int curr_sort = c_cont.GetRootWidget().GetSort();
316  while ( prev )
317  {
318  int prev_sort = prev.GetRootWidget().GetSort();
319  if ( prev_sort > curr_sort )
320  break;
321 
322  if ( ++index < m_Body.Count() )
323  prev = ClosableContainer.Cast( m_Body.Get( index ) );
324  else
325  break;
326  }
327 
328  m_Body.InsertAt( container, index );
329  }
330  else
331  {
332  m_Body.Insert( container );
333  }
334 
335  if ( immedUpdate )
336  RecomputeOpenedContainers();
337  }
338 
339  bool IsItemWithContainerActive()
340  {
341  EntityAI ent = GetFocusedItem();
342  return ent && ( ent.GetInventory().GetCargo() || ent.GetSlotsCountCorrect() > 0 );
343  }
344 
345  override bool IsItemWithQuantityActive()
346  {
347  EntityAI ent = GetFocusedItem();
348  return ent && QuantityConversions.HasItemQuantity( ent ) && ent.CanBeSplit();
349  }
350 
351  override bool IsItemActive()
352  {
353  EntityAI ent = GetFocusedItem();
354  return ent && !IsItemWithQuantityActive() && !IsItemWithContainerActive();
355  }
356 
357  bool IsEmptyItemActive()
358  {
359  EntityAI ent = GetFocusedItem();
360  return ent == null;
361  }
362 
363  void UnfocusPlayerAttachmentsContainer()
364  {
365  m_PlayerAttachmentsContainer.UnfocusAll();
366  }
367 
368  void DoubleClick(Widget w, int x, int y, int button)
369  {
370  if( button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
371  {
372  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
373 
374  if( w == null || m_Player.GetInventory().IsInventoryLocked() )
375  {
376  return;
377  }
378  ItemPreviewWidget iw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
379  if( !iw )
380  {
381  string name = w.GetName();
382  name.Replace( "PanelWidget", "Render" );
383  iw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
384  }
385  if( !iw )
386  {
387  iw = ItemPreviewWidget.Cast( w );
388  }
389 
390  ItemBase item = ItemBase.Cast( iw.GetItem() );
391 
392  if( !item )
393  {
394  return;
395  }
396 
397  SlotsIcon icon;
398  iw.GetUserData(icon);
399 
400  if(icon && icon.IsReserved())
401  {
402  return;
403  }
404 
405  if( !item.GetInventory().CanRemoveEntity() )
406  return;
407 
408  if ( player.GetInventory().HasEntityInInventory( item ) && player.GetHumanInventory().CanAddEntityInHands( item ) )
409  {
410  player.PredictiveTakeEntityToHands( item );
411  }
412  else
413  {
414  if (player.GetInventory().CanAddEntityToInventory( item ) && item.GetInventory().CanRemoveEntity())
415  {
416  if( item.GetTargetQuantityMax() < item.GetQuantity() )
417  item.SplitIntoStackMaxClient( player, -1 );
418  else
419  player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ANY, item );
420  }
421  else
422  {
423  if( item.GetTargetQuantityMax() < item.GetQuantity() )
424  item.SplitIntoStackMaxHandsClient( player );
425  else
426  player.PredictiveTakeEntityToHands( item );
427  }
428  }
429  ToggleWidget( w );
430  HideOwnedTooltip();
431 
432  InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
433  if ( menu )
434  {
435  menu.RefreshQuickbar();
436  }
437  }
438  }
439 
440  override void ExpandCollapseContainer()
441  {
442  if( m_PlayerAttachmentsContainer.IsActive() )
443  {
444  ToggleWidget(m_PlayerAttachmentsContainer.GetFocusedSlotsIcon().GetPanelWidget());
445  }
446  }
447 
448  bool IsContainerWithCargoActive()
449  {
450  return GetFocusedContainer().IsInherited( ContainerWithCargo );
451  }
452 
453  bool IsItemWithAttachmentsActive()
454  {
455  return GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments );
456  }
457 
458  override bool TransferItemToVicinity()
459  {
460  if (CanDrop())
461  {
462  if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
463  {
464  return GetFocusedContainer().TransferItemToVicinity();
465  }
466  else
467  {
468  Man player = GetGame().GetPlayer();
469  ItemBase item = ItemBase.Cast(GetFocusedItem());
470  if ( item && player.CanDropEntity( item ) )
471  {
472  if ( item.GetTargetQuantityMax() < item.GetQuantity() )
473  item.SplitIntoStackMaxClient( null, -1 );
474  else
475  player.PhysicalPredictiveDropItem( item );
476  return true;
477  }
478  }
479  }
480  return false;
481  }
482 
483  override bool InspectItem()
484  {
485  if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
486  {
487  return GetFocusedContainer().InspectItem();
488  }
489  else
490  {
491  Man player = GetGame().GetPlayer();
492  EntityAI item = GetFocusedItem();
493  if( item )
494  {
495  InspectItem( item );
496  return true;
497  }
498  }
499  return false;
500  }
501 
502  int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
503  {
504  PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
505  return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
506  }
507 
508  override bool SplitItem()
509  {
510  if (CanSplit())
511  {
512  if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
513  {
514  return GetFocusedContainer().SplitItem();
515  }
516  }
517 
518  return false;
519  }
520 
521  override bool EquipItem()
522  {
523  if (CanEquip())
524  {
525  if ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
526  {
527  return GetFocusedContainer().EquipItem();
528  }
529  else
530  {
531  EntityAI item = GetFocusedItem();
532  if( item )
533  {
534  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item );
535  return true;
536  }
537  }
538  }
539  return false;
540  }
541 
542  override bool TransferItem()
543  {
544  if (CanTakeToInventory())
545  {
546  LeftArea left_area = LeftArea.Cast( GetParent() );
547  EntityAI item;
548  if (left_area)
549  {
550  if (GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
551  {
552  return GetFocusedContainer().TransferItem();
553  }
554  else
555  {
556  item = GetFocusedItem();
557  if( item )
558  {
559  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
560  return true;
561  }
562  }
563  }
564  else
565  {
566  if (!GetFocusedContainer().IsInherited( ContainerWithCargo ) && !GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ))
567  {
568  item = GetFocusedItem();
569  if( item )
570  {
571  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item );
572  return true;
573  }
574  }
575  }
576  }
577  return false;
578  }
579 
580  override EntityAI GetFocusedItem()
581  {
582  return GetFocusedContainer().GetFocusedItem();
583  }
584 
585  override bool Combine()
586  {
587  if (CanCombine())
588  {
589  if ( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
590  {
591  return GetFocusedContainer().Combine();
592  }
593  else
594  {
595  EntityAI item = GetFocusedItem();
596  ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
597 
598  Icon hands_icon = ItemManager.GetInstance().GetHandsPreview().GetIcon();
599 
600  if( item_in_hands && item )
601  {
602  return hands_icon.CombineItems( item_in_hands, item );
603  }
604  }
605  }
606  return true;
607  }
608 
609  override bool Select()
610  {
611  if( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) )
612  {
613  return GetFocusedContainer().Select();
614  }
615  else
616  {
617  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
618  EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
619  SlotsIcon focused_slot = GetFocusedSlotsIcon();
620  EntityAI focused_item = focused_slot.GetEntity();
621  if( focused_slot.IsReserved() || focused_item != selected_item )
622  {
623  if( selected_item )
624  {
625  if( selected_item.GetInventory().CanRemoveEntity() )
626  {
627  if (m_Player.GetInventory().CanAddAttachmentEx( selected_item, focused_slot.GetSlotID() ))
628  {
629  player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, selected_item, focused_slot.GetSlotID());
630  //m_Player.PredictiveTakeEntityAsAttachmentEx( selected_item, focused_slot.GetSlotID() );
631  ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
632  return true;
633 
634  }
635  else if (m_Player.GetInventory().CanAddAttachment( selected_item ))
636  {
637  player.PredictiveTakeEntityToTargetAttachment( m_Player, selected_item );
638  //m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, selected_item );
639  ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
640  return true;
641  }
642  }
643  }
644  else
645  {
646  if( focused_item && focused_item.GetInventory().CanRemoveEntity() )
647  {
648  EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
649  if( item_in_hands && item_in_hands.GetInventory().CanRemoveEntity() )
650  {
651  if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
652  {
653  player.PredictiveSwapEntities( item_in_hands, focused_item );
654  return true;
655  }
656  else
657  {
658  InventoryLocation il_hands_dst = new InventoryLocation;
659  if( player.GetHumanInventory().FindFreeLocationFor( item_in_hands, FindInventoryLocationType.ANY, il_hands_dst ) )
660  {
661  InventoryMode invMode = InventoryMode.PREDICTIVE;
662 
663  if ( player.NeedInventoryJunctureFromServer(item_in_hands, item_in_hands.GetHierarchyParent(), il_hands_dst.GetParent()) || GetGame().GetPlayer().NeedInventoryJunctureFromServer(focused_item, focused_item.GetHierarchyParent(), GetGame().GetPlayer()) )
664  invMode = InventoryMode.JUNCTURE;
665 
666  player.GetHumanInventory().ForceSwapEntities( invMode, focused_item, item_in_hands, il_hands_dst );
667  return true;
668  }
669  }
670  }
671  else
672  {
673  if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
674  {
675  player.PredictiveTakeEntityToHands( focused_item );
676  return true;
677  }
678  }
679  }
680  }
681  }
682  }
683  return false;
684  }
685 
686  void SetPlayer(PlayerBase player)
687  {
688  if (m_Player)
689  {
690  m_Player.GetOnItemAttached().Remove(ItemAttached);
691  m_Player.GetOnItemDetached().Remove(ItemDetached);
692  m_Player.GetOnAttachmentSetLock().Remove(OnAttachmentReservationSet);
693  m_Player.GetOnAttachmentReleaseLock().Remove(OnAttachmentReservationRelease);
694  }
695 
696  m_Player = player;
697  if (m_Player)
698  {
699  m_Player.GetOnItemAttached().Insert(ItemAttached);
700  m_Player.GetOnItemDetached().Insert(ItemDetached);
701  m_Player.GetOnAttachmentSetLock().Insert(OnAttachmentReservationSet);
702  m_Player.GetOnAttachmentReleaseLock().Insert(OnAttachmentReservationRelease);
703  }
704 
705  //START - InitGhostSlots
706  string config_path_ghosts_slots = "CfgVehicles SurvivorBase InventoryEquipment playerSlots";
707  ref array<string> player_ghosts_slots = new array<string>;
708  GetGame().ConfigGetTextArray( config_path_ghosts_slots, player_ghosts_slots );
709 
710  for ( int i = 0; i < player_ghosts_slots.Count(); i++ )
711  {
712  string slot_name = player_ghosts_slots.Get ( i );
713 
714  int column = i % ITEMS_IN_ROW;
715  int row = i / ITEMS_IN_ROW;
716 
717  SlotsIcon icon = GetSlotsIcon( row, column );
718 
719  icon.SetSlotParent(m_Player);
720  icon.GetMainWidget().Show( true );
721  icon.Clear();
722 
723  GetGame().ConfigGetText( "CfgSlots" + " " + slot_name + " name", slot_name );
724  EntityAI item = m_Player.GetInventory().FindAttachment( InventorySlots.GetSlotIdFromString( slot_name ) );
725  if( item )
726  {
727  ItemAttached( item, slot_name );
728  }
729  }
730  }
731 
732  override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
733  {
734  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
735 
736  if( !ipw.IsInherited( ItemPreviewWidget ) )
737  {
738  return;
739  }
740 
741  EntityAI item = ipw.GetItem();
742  if( !item )
743  {
744  return;
745  }
746 
747  if( !item.GetInventory().CanRemoveEntity() )
748  return;
749 
750  if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) )
751  {
752  m_Player.PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT, item );
753  }
754  }
755 
756  ItemPreviewWidget GetItemPreviewWidget( Widget w )
757  {
758  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget("Render") );
759  if( !ipw )
760  {
761  string name = w.GetName();
762  name.Replace( "PanelWidget", "Render" );
763  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
764  }
765  if( !ipw )
766  {
767  ipw = ItemPreviewWidget.Cast( w );
768  }
769 
770  return ipw;
771  }
772 
773  override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
774  {
775  if( w == null )
776  {
777  return;
778  }
779  ItemPreviewWidget ipw = GetItemPreviewWidget( w );
780 
781  if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
782  {
783  return;
784  }
785 
786  EntityAI item = ipw.GetItem();
787  if( !item )
788  {
789  return;
790  }
791 
792  if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && !m_Player.GetInventory().HasEntityInInventory( item ) )
793  {
794  ItemManager.GetInstance().HideDropzones();
795  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
796  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
797  }
798  else
799  {
800  ItemManager.GetInstance().HideDropzones();
801  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
802  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
803  //ItemManager.GetInstance().ShowSourceDropzone( item );
804  }
805  }
806 
807  override void DraggingOver( Widget w, int x, int y, Widget receiver )
808  {
809  if( w == null )
810  {
811  return;
812  }
813 
814  EntityAI receiver_item;
815  bool is_reserved = false;
816 
817  SlotsIcon slots_icon;
818  receiver.GetUserData(slots_icon);
819 
820  if(slots_icon)
821  {
822  receiver_item = slots_icon.GetEntity();
823  is_reserved = slots_icon.IsReserved();
824  }
825 
826  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
827 
828  if( !ipw || !ipw.IsInherited( ItemPreviewWidget ) )
829  {
830  return;
831  }
832 
833  EntityAI item = ipw.GetItem();
834  if( !item )
835  {
836  return;
837  }
838 
839  if( receiver_item && !is_reserved )
840  {
841  if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
842  {
843  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
844  ItemManager.GetInstance().HideDropzones();
845  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
846  return;
847  }
848  else if( receiver_item.GetInventory().CanAddAttachment(item) || receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ))
849  {
850  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
851  ItemManager.GetInstance().HideDropzones();
852  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
853  return;
854  }
855  else if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
856  {
857  ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
858  ItemManager.GetInstance().HideDropzones();
859  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
860  return;
861  }
862 
863  }
864 
865  if( item.GetInventory().CanRemoveEntity() )
866  {
867  if( m_Player.GetInventory().CanAddAttachment( item) )
868  {
869  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
870  ItemManager.GetInstance().HideDropzones();
871  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
872  }
873  else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
874  {
875  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
876  ItemManager.GetInstance().HideDropzones();
877  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
878  }
879  else if ( receiver_item && GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
880  {
881  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
882  ItemManager.GetInstance().HideDropzones();
883  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
884  }
885  else
886  {
887  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
888  ItemManager.GetInstance().HideDropzones();
889  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
890  }
891  }
892  else
893  {
894  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
895  ItemManager.GetInstance().HideDropzones();
896  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
897  //ItemManager.GetInstance().ShowSourceDropzone( item );
898  }
899  }
900 
901  void OnDropReceivedFromGhostArea( Widget w, int x, int y, Widget receiver )
902  {
903  ItemManager.GetInstance().HideDropzones();
904  ItemManager.GetInstance().SetIsDragging( false );
905 
906  EntityAI receiver_item;
907  bool is_reserved = false;
908  InventoryMenu menu = InventoryMenu.Cast( GetGame().GetUIManager().FindMenu( MENU_INVENTORY ) );
909  float stack_max;
910 
911  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( GetItemPreviewWidget( w ) );
912  SlotsIcon slots_icon;
913  receiver.GetUserData(slots_icon);
914  int slot_id = slots_icon.GetSlotID();
915 
916  receiver_item = slots_icon.GetEntity();
917  is_reserved = slots_icon.IsReserved();
919 
920  if ( !ipw )
921  {
922  return;
923  }
924 
925  ItemBase item = ItemBase.Cast(ipw.GetItem());
926  PlayerBase real_player = PlayerBase.Cast( GetGame().GetPlayer() );
927  if ( !item )
928  {
929  return;
930  }
931  if ( receiver_item && !is_reserved )
932  {
933  if ( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
934  {
935  GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
936 
937  if ( menu )
938  {
939  menu.RefreshQuickbar();
940  }
941  return;
942  }
943  else if ( receiver_item.GetInventory().CanAddAttachment( item ) )
944  {
945  GetGame().GetPlayer().PredictiveTakeEntityToTargetAttachment( receiver_item, item );
946 
947  if ( menu )
948  {
949  menu.RefreshQuickbar();
950  }
951  return;
952  }
953  else if ( receiver_item.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && !receiver_item.GetInventory().HasEntityInCargo( item ) )
954  {
955  SplitItemUtils.TakeOrSplitToInventory(real_player, receiver_item,item);
956 
957  if ( menu )
958  {
959  menu.RefreshQuickbar();
960  }
961  return;
962  }
963  else if ( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
964  {
965  ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
966  return;
967  }
968  }
969 
970  if ( m_Player.GetInventory().CanAddAttachmentEx( item, slot_id ) )
971  {
972  if (item.GetQuantity() > item.GetTargetQuantityMax(slot_id))
973  {
974  item.SplitIntoStackMaxClient( real_player, slot_id );
975  }
976  else
977  {
978  real_player.PredictiveTakeEntityToTargetAttachmentEx( m_Player, item, slots_icon.GetSlotID() );
979  }
980  }
981  else if ( m_Player.GetInventory().CanAddAttachment( item ) )
982  {
983  il = new InventoryLocation;
984  m_Player.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.ATTACHMENT, il );
985  float stackable = item.GetTargetQuantityMax(-1);
986 
987  if( il.IsValid() )
988  {
989  if ( stackable == 0 || stackable >= item.GetQuantity() )
990  {
991  real_player.PredictiveTakeEntityToTargetAttachment( il.GetParent(), item );
992  }
993  else
994  {
995 
996  ItemBase.Cast(item).SplitIntoStackMaxToInventoryLocationClient( il );
997  }
998  }
999  }
1000  else if( m_Player.GetInventory().CanAddEntityToInventory( item, FindInventoryLocationType.CARGO | FindInventoryLocationType.ATTACHMENT ) && ( !m_Player.GetInventory().HasEntityInInventory( item ) ) || m_Player.GetHumanInventory().HasEntityInHands( item ) )
1001  {
1002  SplitItemUtils.TakeOrSplitToInventory(m_Player, m_Player, item);
1003  }
1004 
1005  if ( menu )
1006  {
1007  menu.RefreshQuickbar();
1008  }
1009  }
1010 
1011  void SwapItemsInOrder( int slot1, int slot2 )
1012  {
1013  EntityAI item1 = m_Player.GetInventory().FindAttachment( slot1 );
1014  EntityAI item2 = m_Player.GetInventory().FindAttachment( slot2 );
1015 
1016  if( item1 && item2 )
1017  {
1018  Container cont1 = m_ShowedItems.Get( item1 );
1019  Container cont2 = m_ShowedItems.Get( item2 );
1020  if( cont1 && cont2 )
1021  {
1022  int sort1 = cont1.GetRootWidget().GetSort();
1023  int sort2 = cont2.GetRootWidget().GetSort();
1024 
1025  cont1.GetRootWidget().SetSort( sort2 );
1026  cont2.GetRootWidget().SetSort( sort1 );
1027 
1028  m_Body.SwapItems( m_Body.Find( cont1 ), m_Body.Find( cont2 ) );
1029  }
1030  }
1031  RecomputeOpenedContainers();
1032  }
1033 
1034  override void UpdateInterval()
1035  {
1036  int i;
1037  for ( i = 0; i < m_InventorySlots.Count(); i++ )
1038  {
1039  SlotsIcon icon = m_InventorySlots.GetElement( i );
1040  if ( icon )
1041  {
1042  icon.UpdateInterval();
1043  }
1044  }
1045  for ( i = 0; i < m_ShowedItems.Count(); i++ )
1046  {
1047  Container cont = m_ShowedItems.GetElement( i );
1048  if ( cont )
1049  {
1050  cont.UpdateInterval();
1051  }
1052  }
1053  }
1054 
1055  // Call from ToggleWidget
1056  void ToggleContainer( Widget w, EntityAI item )
1057  {
1059  item.GetInventory().GetCurrentInventoryLocation( il );
1060  SlotsIcon icon = m_InventorySlots.Get( il.GetSlot() );
1061  ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( item ) );
1062  if (c)
1063  {
1064  c.Toggle();
1065  Refresh();
1066  }
1067  }
1068 
1069  override bool CanOpenCloseContainerEx(EntityAI focusedEntity)
1070  {
1071  if (focusedEntity)
1072  {
1073  ClosableContainer c = ClosableContainer.Cast( m_ShowedItems.Get( focusedEntity ) );
1074  if (c && c.IsDisplayable())
1075  {
1076  return true;
1077  }
1078  }
1079  return false;
1080  }
1081 
1082  // Mouse button UP or Call other fn
1083  void ToggleWidget( Widget w )
1084  {
1085  if( ItemManager.GetInstance().IsDragging() )
1086  {
1087  return;
1088  }
1089  string name = w.GetName();
1090  name.Replace( "PanelWidget", "Render" );
1091  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
1092  if( ipw.GetItem() )
1093  {
1094  ToggleContainer( w, ipw.GetItem() );
1095  RecomputeOpenedContainers();
1096  }
1097 
1098  Refresh();
1099  }
1100 
1101  override void CollapseButtonOnMouseButtonDown(Widget w)
1102  {
1103  super.CollapseButtonOnMouseButtonDown(w);
1104  }
1105 
1106  bool IsPlayerEquipmentActive()
1107  {
1108  if( GetFocusedContainer() && ( GetFocusedContainer().IsInherited( ContainerWithCargo ) || GetFocusedContainer().IsInherited( ContainerWithCargoAndAttachments ) ) )
1109  {
1110  return false;
1111  }
1112 
1113  return true;
1114  }
1115 
1116  override void Refresh()
1117  {
1118  super.Refresh();
1119  m_MainWidget.Update();
1120  m_RootWidget.Update();
1121  UpdateSelectionIcons();
1122  }
1123 
1124  override bool OnChildRemove( Widget w, Widget child )
1125  {
1126  Refresh();
1127  return true;
1128  }
1129 
1130  override bool OnChildAdd( Widget w, Widget child )
1131  {
1132  Refresh();
1133  return true;
1134  }
1135 }
ItemBase
Definition: inventoryitem.c:730
SlotsContainer
Definition: slotscontainer.c:1
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
QuantityConversions
Definition: quantityconversions.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
Remove
void Remove(Object object)
Definition: actiontargets.c:95
StaticGUIUtils
Definition: staticguiutils.c:1
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
ITEMS_IN_ROW
const int ITEMS_IN_ROW
Definition: attachments.c:1
SplitItemUtils
Definition: splititemutils.c:1
MENU_INVENTORY
const int MENU_INVENTORY
Definition: constants.c:170
CombineItemsClient
override void CombineItemsClient(EntityAI entity2, bool use_stack_max=true)
Definition: itembase.c:849
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
InventoryMode
InventoryMode
NOTE: PREDICTIVE is not to be used at all in multiplayer.
Definition: inventory.c:21
GetHeader
string GetHeader()
Definition: errorproperties.c:76
ColorManager
Definition: colormanager.c:1
Container
Definition: cargocontainer.c:2
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
m_Player
DayZPlayer m_Player
Definition: hand_events.c:42
PlayerContainer
Definition: playercontainer.c:1
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
AttachmentsGroupContainer
Definition: attachmentsgroupcontainer.c:1
MouseState
MouseState
Definition: ensystem.c:310
array< string >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Icon
Definition: icon.c:1
ItemPreviewWidget
Definition: gameplay.c:275
InventoryMenu
void InventoryMenu()
Definition: inventorymenu.c:20
CollapsibleContainer
Definition: collapsiblecontainer.c:1
GetParent
proto native Widget GetParent()
Get parent of the Effect.
Definition: effect.c:405
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
Widget
Definition: enwidgets.c:189
LeftArea
Definition: leftarea.c:1
EntityAI
Definition: building.c:5
ClosableContainer
Definition: containerwithcargo.c:1
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
WidgetEventHandler
Definition: widgeteventhandler.c:1
path
string path
Definition: optionselectormultistate.c:135