Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
handscontainer.c
Go to the documentation of this file.
2 {
3  protected bool m_Hidden;
4  protected ref HandsHeader m_CollapsibleHeader;
5  protected ref HandsPreview m_HandsPreview;
6 
7  protected ref Attachments m_Atts;
8  protected ref CargoContainer m_CargoGrid;
9 
10  protected ref map<EntityAI, ref CargoContainer> m_AttachmentCargos;
11  protected ref map<EntityAI, AttachmentsWrapper> m_AttachmentAttachmentsContainers;
12  protected ref map<EntityAI, ref Attachments> m_AttachmentAttachments;
13  protected ref array<int> m_AttachmentSlotsSorted;
14 
15  protected int m_StaticAttCount = 0;
16  protected int m_StaticCargoCount = 0;
17 
18  protected ScrollWidget m_ScrollWidget;
19 
20  void HandsContainer( LayoutHolder parent )
21  {
22  m_AttachmentCargos = new map<EntityAI, ref CargoContainer>;
23  m_AttachmentAttachmentsContainers = new map<EntityAI, AttachmentsWrapper>;
24  m_AttachmentAttachments = new map<EntityAI, ref Attachments>;
25 
26  m_CollapsibleHeader = new HandsHeader( this, "CollapseButtonOnMouseButtonDown" );
27  GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
28  m_MainWidget = m_MainWidget.FindWidget( "body" );
29  GetMainWidget().SetFlags( WidgetFlags.IGNOREPOINTER );
30  m_Body = new array<ref LayoutHolder>;
31  m_HandsPreview = new HandsPreview( this );
32  ItemManager.GetInstance().SetHandsPreview( m_HandsPreview );
33  m_Body.Insert( m_HandsPreview );
34 
35  ItemBase hands_item = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
36  if ( hands_item )
37  m_HandsPreview.CreateNewIcon( hands_item );
38 
39  m_ScrollWidget = ScrollWidget.Cast( m_RootWidget.GetParent().GetParent() );
40  RecomputeOpenedContainers();
41  }
42 
43  void ~HandsContainer()
44  {
45  if ( m_Entity )
46  {
47  m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
48  m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
49  }
50 
51  m_AttachmentCargos.Clear();
52  m_AttachmentAttachmentsContainers.Clear();
53  m_AttachmentAttachments.Clear();
54  }
55 
56  void ResetContainer()
57  {
58  m_Body.Clear();
59  m_Body.Insert( m_HandsPreview );
60  }
61 
62  override Header GetHeader()
63  {
64  return m_CollapsibleHeader;
65  }
66 
67  override bool IsLastIndex()
68  {
69  return m_ActiveIndex == m_OpenedContainers.Count() - 1;
70  }
71 
72  void SetFocusToIndex()
73  {
74  int index = m_ActiveIndex - 1;
75  int attachment_start_index = -1;
76  int cargo_start_index = -1;
77  int attachment_end_index = -1;
78  int cargo_end_index = -1;
79 
80  if ( m_Atts || m_AttachmentAttachments.Count() > 0 )
81  {
82  attachment_start_index = 0;
83  if ( m_Atts )
84  attachment_end_index++;
85  attachment_end_index += m_AttachmentAttachments.Count();
86  }
87 
88  if ( m_CargoGrid || m_AttachmentCargos.Count() > 0 )
89  {
90  cargo_start_index = attachment_end_index + 1;
91  if ( m_CargoGrid )
92  cargo_end_index++;
93  cargo_end_index += cargo_start_index + m_AttachmentCargos.Count();
94  }
95 
96  if ( m_ActiveIndex > m_OpenedContainers.Count() )
97  {
98  m_ActiveIndex = m_OpenedContainers.Count();
99  }
100 
101  if ( index == -1 )
102  {
103  #ifdef PLATFORM_CONSOLE
104  if ( m_MainWidget.FindAnyWidget("Cursor") )
105  m_MainWidget.FindAnyWidget("Cursor").Show( true );
106  #endif
107  m_ScrollWidget.VScrollToPos01( 0 );
108  }
109  else
110  {
111  if( index.InRange( 0, attachment_end_index ) )
112  {
113  if( m_Atts )
114  {
115  if( index == 0 )
116  {
117  m_Atts.SetDefaultFocus();
118  SetFocusedContainer( m_Atts.GetWrapper() );
119  }
120  else
121  {
122  m_AttachmentAttachments.GetElement( index - 1 ).SetDefaultFocus();
123  SetFocusedContainer( m_AttachmentAttachments.GetElement( index - 1 ).GetWrapper() );
124  }
125  }
126  else
127  {
128  m_AttachmentAttachments.GetElement( index ).SetDefaultFocus();
129  SetFocusedContainer( m_AttachmentAttachments.GetElement( index ).GetWrapper() );
130  }
131  }
132  else if( index.InRange( cargo_start_index, cargo_end_index ) )
133  {
134  if( m_CargoGrid )
135  {
136  if( index == cargo_start_index )
137  {
138  m_CargoGrid.SetDefaultFocus();
139  SetFocusedContainer( m_CargoGrid );
140  }
141  else
142  {
143  m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ).SetDefaultFocus();
144  SetFocusedContainer( m_AttachmentCargos.GetElement( index - 1 - cargo_start_index ) );
145  }
146  }
147  else
148  {
149  m_AttachmentCargos.GetElement( index - cargo_start_index ).SetDefaultFocus();
150  SetFocusedContainer( m_AttachmentCargos.GetElement( index - cargo_start_index ) );
151  }
152  }
153 
154  if( m_MainWidget.FindAnyWidget("Cursor") )
155  m_MainWidget.FindAnyWidget("Cursor").Show( false );
156  ScrollToActiveContainer( GetFocusedContainer() );
157  }
158  }
159 
160  void ScrollToActiveContainer( Container active_container )
161  {
162  if( !active_container )
163  return;
164  float x, y, y_s;
165  m_ScrollWidget.GetScreenPos( x, y );
166  m_ScrollWidget.GetScreenSize( x, y_s );
167  float amount;
168  float next_pos = active_container.GetFocusedContainerYScreenPos( true ) + active_container.GetFocusedContainerHeight( true );
169 
170  if( next_pos > ( y + y_s ) )
171  {
172  amount = y + active_container.GetFocusedContainerYScreenPos( true );
173  m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + active_container.GetFocusedContainerHeight( true ) + 2 );
174  }
175  else if( active_container.GetFocusedContainerYScreenPos( true ) < y )
176  {
177  amount = active_container.GetFocusedContainerYScreenPos( true ) - y;
178  m_ScrollWidget.VScrollToPos( m_ScrollWidget.GetVScrollPos() + amount - 2 );
179  }
180  }
181 
182  override void Insert( LayoutHolder container, int pos = -1, bool immedUpdate = true )
183  {
184  super.Insert( container, pos, immedUpdate );
185  }
186 
187  override bool TransferItem()
188  {
189  if (m_ActiveIndex == 0)
190  {
191  if (CanTakeToInventory())
192  {
193  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
194  if (item_in_hands && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null))
195  {
196  if (GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, item_in_hands ))
197  {
198  m_MainWidget.FindAnyWidget("Cursor").Show( false );
199  m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
200  return true;
201  }
202  }
203  }
204  }
205  else if (GetFocusedContainer())
206  {
207  return GetFocusedContainer().TransferItem();
208  }
209  return false;
210  }
211 
212  override bool SplitItem()
213  {
214  if (CanSplit())
215  {
216  if (m_ActiveIndex == 0)
217  {
218  ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
219  if ( item_in_hands )
220  {
221  if ( item_in_hands.CanBeSplit() )
222  {
223  item_in_hands.OnRightClick();
224  }
225  }
226  }
227  else if( GetFocusedContainer() )
228  {
229  return GetFocusedContainer().SplitItem();
230  }
231  }
232  return false;
233  }
234 
235  override bool EquipItem()
236  {
237  if (CanEquip())
238  {
239  if (m_ActiveIndex == 0)
240  {
241  ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
242  if ( item_in_hands )
243  {
244  if ( GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !GetGame().GetPlayer().GetInventory().HasInventoryReservation(item_in_hands, null) )
245  {
246  if ( GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, item_in_hands ) )
247  {
248  m_MainWidget.FindAnyWidget("Cursor").Show( false );
249  m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
250  return true;
251  }
252  }
253  }
254  }
255  else if (GetFocusedContainer())
256  {
257  return GetFocusedContainer().EquipItem();
258  }
259  }
260  return false;
261  }
262 
263  override void SetActive( bool active )
264  {
265  super.SetActive(active);
266  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
267  EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
268 
269  if( item_in_hands )
270  {
271  if( m_MainWidget.FindAnyWidget( "Cursor" ) )
272  {
273  m_MainWidget.FindAnyWidget( "Cursor" ).Show( active );
274  }
275 
276  if( active )
277  {
278  float x, y;
279  GetMainWidget().GetScreenPos( x, y );
280  PrepareOwnedTooltip( item_in_hands, -1, y );
281  }
282  }
283  else
284  {
285  if (active)
286  m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
287  else
288  m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.7 );
289  }
290  }
291 
292  override void SetLastActive()
293  {
294  super.SetLastActive();
295  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
296  EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
297 
298  if( item_in_hands )
299  {
300  if ( m_ActiveIndex == 0)
301  {
302  if( m_MainWidget.FindAnyWidget( "Cursor" ) )
303  {
304  m_MainWidget.FindAnyWidget( "Cursor" ).Show( true );
305  }
306 
307  float x, y;
308  GetMainWidget().GetScreenPos( x, y );
309  PrepareOwnedTooltip( item_in_hands, x, y );
310  }
311  }
312  else
313  {
314  m_MainWidget.FindAnyWidget( "hands_preview_root" ).SetAlpha( 0.85 );
315  }
316  }
317 
318  override void Refresh()
319  {
320  super.Refresh();
321  SetActive( m_IsActive );
322  }
323 
324  override bool IsItemActive()
325  {
326  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
327  ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
328  if( item == null )
329  {
330  return false;
331  }
332  return !IsEmpty() && ( !QuantityConversions.HasItemQuantity( item ) || ( QuantityConversions.HasItemQuantity( item ) && !item.CanBeSplit() ) );
333  }
334 
335  override bool IsItemWithQuantityActive()
336  {
337  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
338  ItemBase item = ItemBase.Cast( player.GetHumanInventory().GetEntityInHands() );
339  if( item == null )
340  {
341  return false;
342  }
343  return !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit();
344  }
345 
346  override bool IsEmpty()
347  {
348  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
349  return player.GetHumanInventory().GetEntityInHands() == null;
350  }
351 
352  override bool TransferItemToVicinity()
353  {
354  if (CanDrop())
355  {
356  if (m_ActiveIndex == 0)
357  {
358  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
359  ItemBase item_in_hands = ItemBase.Cast(player.GetHumanInventory().GetEntityInHands());
360  if ( item_in_hands && player.CanDropEntity( item_in_hands ) && GetGame().GetPlayer().GetHumanInventory().CanRemoveEntityInHands() && !player.GetInventory().HasInventoryReservation(item_in_hands, null) )
361  {
362  if ( item_in_hands.GetTargetQuantityMax() < item_in_hands.GetQuantity() )
363  item_in_hands.SplitIntoStackMaxClient( null, -1 );
364  else
365  player.PhysicalPredictiveDropItem( item_in_hands );
366  m_MainWidget.FindAnyWidget("Cursor").Show( false );
367  m_MainWidget.FindAnyWidget("hands_preview_root").SetAlpha( 0.7 );
368  return true;
369  }
370  }
371  else if ( GetFocusedContainer() )
372  {
373  return GetFocusedContainer().TransferItemToVicinity();
374  }
375  }
376  return false;
377  }
378 
379  override bool InspectItem()
380  {
381  if(m_ActiveIndex == 0)
382  {
383  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
384  EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
385  if( item_in_hands )
386  {
387  InspectItem( item_in_hands );
388  return true;
389  }
390  }
391  else if( GetFocusedContainer() )
392  {
393  return GetFocusedContainer().InspectItem();
394  }
395  return false;
396  }
397 
398  override bool OnSelectButton()
399  {
400  if(m_ActiveIndex == 0)
401  {
402  if (ItemManager.GetInstance().IsMicromanagmentMode())
403  {
404  EntityAI selectedItem = ItemManager.GetInstance().GetSelectedItem();
405  if( selectedItem == GetFocusedItem() )
406  {
407  Inventory.GetInstance().DisableMicromanagement();
408  return true;
409  }
410  else
411  {
412  return Select();
413  }
414  }
415  else
416  {
417  Inventory.GetInstance().EnableMicromanagement();
418  return true;
419  }
420  }
421  else
422  {
423  if( GetFocusedContainer() )
424  {
425  return GetFocusedContainer().OnSelectButton();
426  }
427  }
428  return false;
429  }
430 
431  EntityAI GetItemPreviewItem( Widget w )
432  {
433  ItemPreviewWidget ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
434  if( !ipw )
435  {
436  string name = w.GetName();
437  name.Replace( "PanelWidget", "Render" );
438  ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
439  }
440 
441  if( !ipw )
442  {
443  ipw = ItemPreviewWidget.Cast( w );
444  }
445 
446  if( !ipw )
447  {
448  return null;
449  }
450 
451  return ipw.GetItem();
452  }
453 
454  override void DraggingOverHeader( Widget w, int x, int y, Widget receiver )
455  {
456  if( w == null )
457  {
458  return;
459  }
460  EntityAI receiver_item;
461  EntityAI slot_owner;
462  int slot_id = -1;
463 
464  string name = w.GetName();
465  name.Replace( "PanelWidget", "Render" );
466 
467  ItemPreviewWidget w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( name ) );
468  if( w_ipw == null )
469  {
470  w_ipw = ItemPreviewWidget.Cast( w.FindAnyWidget( "Render" ) );
471  }
472  if( w_ipw == null )
473  {
474  return;
475  }
476 
477  SlotsIcon slots_icon;
478  receiver.GetUserData(slots_icon);
479 
480  if(slots_icon)
481  {
482  receiver_item = slots_icon.GetEntity();
483  slot_id = slots_icon.GetSlotID();
484  slot_owner = slots_icon.GetSlotParent();
485  }
486 
487 
488  PlayerBase p = PlayerBase.Cast( GetGame().GetPlayer() );
489  InventoryItem receiver_entity = InventoryItem.Cast( p.GetHumanInventory().GetEntityInHands() );
490  InventoryItem w_entity = InventoryItem.Cast( w_ipw.GetItem() );
491  if( !w_entity )
492  {
493  return;
494  }
495 
496  if( receiver_entity )
497  {
498  if( receiver_item )
499  {
500  ItemBase receiver_itemIB = ItemBase.Cast( receiver_item );
501  ItemBase itemIB = ItemBase.Cast( receiver_item );
502  if( receiver_itemIB && itemIB && receiver_itemIB.CanBeCombined( itemIB ) )
503  {
504  ItemManager.GetInstance().HideDropzones();
505  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
506  {
507  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
508  }
509  else
510  {
511  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
512  }
513  ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
514  }
515  else
516  {
517  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
518  Magazine mag = Magazine.Cast(receiver_item);
519  Weapon_Base wpn = Weapon_Base.Cast(receiver_item.GetHierarchyParent());
520 
521  if( wpn && mag )
522  {
523  if( player.GetWeaponManager().CanSwapMagazine( wpn, Magazine.Cast(w_entity) ) )
524  {
525  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
526  if( w_entity.GetHierarchyRootPlayer() == player )
527  {
528  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
529  }
530  else
531  {
532  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
533  }
534  }
535  else
536  {
537  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
538  ItemManager.GetInstance().ShowSourceDropzone( w_entity );
539  }
540  }
541  else
542  {
543  if( GameInventory.CanSwapEntitiesEx( receiver_item, w_entity ) )
544  {
545  ItemManager.GetInstance().HideDropzones();
546  if( m_Entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
547  {
548  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
549  }
550  else
551  {
552  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
553  }
554  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
555  }
556  else if( receiver_itemIB.GetInventory().CanAddAttachment( w_entity ) )
557  {
558  ItemManager.GetInstance().HideDropzones();
559  if( receiver_itemIB.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
560  {
561  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
562  }
563  else
564  {
565  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
566  }
567  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
568  }
569  }
570  }
571  }
572  else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( w_entity ) )
573  {
574  ItemManager.GetInstance().HideDropzones();
575  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
576  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
577  }
578  else if( receiver_entity.GetInventory().CanAddAttachment( w_entity ) )
579  {
580  ItemManager.GetInstance().HideDropzones();
581  if( receiver_entity.GetHierarchyRootPlayer() == GetGame().GetPlayer() )
582  {
583  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
584  }
585  else
586  {
587  ItemManager.GetInstance().GetLeftDropzone().SetAlpha( 1 );
588  }
589  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
590  }
591  else
592  {
593  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
594  ItemManager.GetInstance().ShowSourceDropzone( w_entity );
595  }
596  }
597  else
598  {
599  /*if( m_HandsIcon )
600  {
601  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
602  ItemManager.GetInstance().HideDropzones();
603  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
604  }
605 
606  else
607  {*/
608  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
609  ItemManager.GetInstance().ShowSourceDropzone( w_entity );
610  //}
611  }
612  }
613 
614  void OnDropReceivedFromHeader2( Widget w, int x, int y, Widget receiver )
615  {
616  TakeAsAttachment( w, receiver );
617  }
618 
619  void OnPerformCombination(int combinationFlags)
620  {
622  if ( m_am_entity1 == null || m_am_entity2 == null ) return;
623 
624  if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
625 
626  if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
627  {
628  Magazine mag;
629  if ( Class.CastTo(mag, m_am_entity2 ) )
630  {
631  m_player.GetWeaponManager().LoadBullet( mag );
632  return;
633  }
634  }
635 
636  if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
637  {
638  if( m_Atts )
639  {
640  m_Body.RemoveItem( m_Atts.GetWrapper() );
641  delete m_Atts;
642  }
643  if( m_am_entity2.GetSlotsCountCorrect() > 0 )
644  {
645  m_Atts = new Attachments( this, m_am_entity2 );
646  m_Atts.InitAttachmentGrid( 1 );
647 
648  }
649 
650  Refresh();
651  m_Parent.Refresh();
652 
653  Weapon_Base wpn1;
654  Magazine mag1;
655  if ( Class.CastTo(wpn1, m_am_entity1 ) && Class.CastTo(mag1, m_am_entity2 ) )
656  {
657  if( m_player.GetWeaponManager().CanAttachMagazine(wpn1, mag1) )
658  {
659  m_player.GetWeaponManager().AttachMagazine(mag1);
660  return;
661  }
662  }
663 
664  SplitItemUtils.TakeOrSplitToInventory(m_player, m_am_entity1, m_am_entity2);
665  //m_player.PredictiveTakeEntityToTargetAttachment( m_am_entity1, m_am_entity2 );
666  }
667 
668  if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
669  {
670  m_player.PredictiveTakeEntityToTargetCargo( m_am_entity1, m_am_entity2 );
671  }
672 
673  if ( combinationFlags & InventoryCombinationFlags.SWAP )
674  {
675  Magazine swapmag1;
676  Magazine swapmag2;
677  if (Class.CastTo(swapmag1, m_am_entity1) && Class.CastTo(swapmag2, m_am_entity2 ) )
678  {
679  if( m_player.GetWeaponManager().CanSwapMagazine( Weapon_Base.Cast( swapmag1.GetParent() ), Magazine.Cast( swapmag2 ) ) )
680  {
681  m_player.GetWeaponManager().SwapMagazine(swapmag2);
682  return;
683  }
684 
685  if( m_player.GetWeaponManager().CanSwapMagazine(Weapon_Base.Cast( swapmag2.GetParent() ), Magazine.Cast( swapmag1 )) )
686  {
687  m_player.GetWeaponManager().SwapMagazine(swapmag1);
688  return;
689  }
690  }
691  if ( !m_player.PredictiveSwapEntities( m_am_entity1, m_am_entity2 ) && m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity1 ) )
692  {
693  m_player.PredictiveTakeEntityToHands( m_am_entity1 );
694  }
695  }
696 
697  if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
698  {
699  if ( m_Atts )
700  {
701  m_Body.RemoveItem( m_Atts.GetWrapper() );
702  delete m_Atts;
703  }
704 
705  if ( m_am_entity2.GetSlotsCountCorrect() > 0 )
706  {
707  m_Atts = new Attachments( this, m_am_entity2 );
708  m_Atts.InitAttachmentGrid( 1 );
709 
710  }
711  Refresh();
712  m_Parent.Refresh();
713 
714  if ( m_player.GetHumanInventory().CanAddEntityInHands( m_am_entity2 ) )
715  {
716  m_player.PredictiveTakeEntityToHands( m_am_entity2 );
717  }
718  }
719  }
720 
721  void ShowActionMenuCombine( EntityAI entity1, EntityAI entity2, int combinationFlags )
722  {
723  if ( entity1 && entity2 ) PrintString( "Showing action menu for " + entity1.GetDisplayName() + " and " + entity2.GetDisplayName() );
724 
725  ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
726  m_am_entity1 = entity1;
727  m_am_entity2 = entity2;
728  cmenu.Hide();
729  cmenu.Clear();
730 
731  if( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
732  {
733  ItemBase entity = ItemBase.Cast( entity1 );
734  entity.CombineItemsClient( ItemBase.Cast( entity2 ) );
735  return;
736  }
737 
738  if ( entity1 == null || entity2 == null ) return;
739 
740  if ( combinationFlags == InventoryCombinationFlags.NONE ) return;
741 
742  if ( combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
743  {
744  cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_ATTACHMENT ) );
745  }
746  if ( combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
747  {
748  cmenu.Add( "#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.LOAD_CHAMBER ) );
749  }
750 
751  if ( combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
752  {
753  cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.ADD_AS_CARGO ) );
754  }
755 
756  if ( combinationFlags & InventoryCombinationFlags.SWAP )
757  {
758  cmenu.Add( "#inv_context_swap", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.SWAP ) );
759  }
760 
761  if ( combinationFlags & InventoryCombinationFlags.TAKE_TO_HANDS )
762  {
763  cmenu.Add( "#inv_context_take_to_hands", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.TAKE_TO_HANDS ) );
764  }
765 
766  if ( combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
767  {
768  cmenu.Add( "#inv_context_combine", this, "OnPerformCombination", new Param1<int>( InventoryCombinationFlags.COMBINE_QUANTITY2 ) );
769  }
770 
771  int m_am_pos_x, m_am_pos_y;
772  GetMousePos( m_am_pos_x, m_am_pos_y );
773  m_am_pos_x -= 5;
774  m_am_pos_y -= 5;
775 
776  cmenu.Show( m_am_pos_x, m_am_pos_y );
777  }
778 
779 
780  override void OnDropReceivedFromHeader( Widget w, int x, int y, Widget receiver )
781  {
782  TakeAsAttachment( w, receiver );
783  }
784 
785  int GetCombinationFlags( EntityAI entity1, EntityAI entity2 )
786  {
787  int flags = 0;
789  EntityAI entity_in_hands = m_player.GetHumanInventory().GetEntityInHands();
790 
791  if (!entity1 || !entity2) return flags;
792 
793  Magazine swapmag1;
794  Magazine swapmag2;
795  bool skipSwap = false;
796 
797  if (Class.CastTo(swapmag1, entity1) && Class.CastTo(swapmag2, entity2))
798  {
799  Weapon_Base parentWpn;
800 
801  if (Class.CastTo(parentWpn, swapmag1.GetHierarchyParent()))
802  {
803  skipSwap = true;
804  if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag2))
805  flags = flags | InventoryCombinationFlags.SWAP;
806  }
807 
808  if (Class.CastTo(parentWpn, swapmag2.GetHierarchyParent()))
809  {
810  skipSwap = true;
811  if (m_player.GetWeaponManager().CanSwapMagazine(parentWpn,swapmag1))
812  flags = flags | InventoryCombinationFlags.SWAP;
813 
814  }
815  }
816 
817  if ( !skipSwap )
818  {
819  if (entity1 == m_player.GetHumanInventory().GetEntityInHands() ) flags = flags | InventoryCombinationFlags.TAKE_TO_HANDS;
820  else if (GameInventory.CanSwapEntitiesEx( entity1, entity2 ))
821  {
822  if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ))
823  {
824  flags = flags | InventoryCombinationFlags.SWAP;
825  }
826  }
827  }
828 
829  if (entity1.IsInherited( ItemBase) && entity2.IsInherited( ItemBase ))
830  {
831  ItemBase ent1 = ItemBase.Cast( entity1 );
832  if (ent1.CanBeCombined( ItemBase.Cast( entity2 ) )) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
833  }
834 
835  else if (entity1.GetInventory().CanAddAttachment( entity2 ))
836  {
837  if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited( ZombieBase ) && !entity2.IsInherited( Car ))
838  {
839  flags = flags | InventoryCombinationFlags.ADD_AS_ATTACHMENT;
840  }
841  }
842  if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() )) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
843 
844  if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
845  {
847  Class.CastTo(amc, m_player.GetActionManager());
848  if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
849  {
850  if (amc.CanSetActionFromInventory( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ) ))
851  {
852  flags = flags | InventoryCombinationFlags.SET_ACTION;
853  }
854  }
855  else
856  {
857  if (amc.CanSetActionFromInventory( ItemBase.Cast( entity2 ), ItemBase.Cast( entity1 ) ))
858  {
859  flags = flags | InventoryCombinationFlags.SET_ACTION;
860  }
861  }
862  }
863 
864  if (GetRecipeCount( true, entity1, entity2 ) > 0)
865  {
866  flags = flags | InventoryCombinationFlags.RECIPE_ANYWHERE;
867  }
868  return flags;
869  }
870 
871  int GetRecipeCount( bool recipe_anywhere, EntityAI entity1, EntityAI entity2 )
872  {
873  PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
874  return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), null, PlayerBase.Cast( GetGame().GetPlayer() ) );
875  }
876 
877  void RemoveItem()
878  {
879  m_Entity = null;
880  m_CollapsibleHeader.ShowCollapseButtons( false, true );
881  }
882 
883  void DestroyAtt()
884  {
885  if( m_Atts )
886  {
887  m_Body.RemoveItem( m_Atts.GetWrapper() );
888  delete m_Atts;
889 
890  if( m_Entity )
891  {
892  m_Entity.GetOnItemAttached().Remove( AttachmentAdded );
893  m_Entity.GetOnItemDetached().Remove( AttachmentRemoved );
894  }
895  }
896 
897  if( m_AttachmentAttachmentsContainers )
898  {
899  foreach( EntityAI ent, AttachmentsWrapper att : m_AttachmentAttachmentsContainers )
900  {
901  m_Body.RemoveItem( att );
902  m_AttachmentAttachments.Remove( ent );
903  delete att;
904  }
905  }
906 
907  m_AttachmentAttachmentsContainers.Clear();
908  Refresh();
909  m_Parent.Refresh();
910  RecomputeOpenedContainers();
911  }
912 
913  override void UnfocusGrid()
914  {
915  if( m_Atts )
916  {
917  m_Atts.UnfocusAll();
918  }
919 
920  if( m_CargoGrid )
921  {
922  m_CargoGrid.UnfocusAll();
923  }
924 
925  if( m_AttachmentCargos )
926  {
927  foreach( EntityAI e1, CargoContainer cargo : m_AttachmentCargos )
928  {
929  cargo.UnfocusAll();
930 
931  }
932  }
933 
934  if( m_AttachmentCargos )
935  {
936  foreach( EntityAI e2, Attachments att : m_AttachmentAttachments )
937  {
938  att.UnfocusAll();
939  }
940  }
941  }
942 
943  override void UnfocusAll()
944  {
945  UnfocusGrid();
946  }
947 
948  void DestroyCargo()
949  {
950  if( m_CargoGrid )
951  {
952  m_Body.RemoveItem( m_CargoGrid );
953  delete m_CargoGrid;
954  }
955 
956  if( m_AttachmentCargos )
957  {
958  foreach( CargoContainer cargo : m_AttachmentCargos )
959  {
960  m_Body.RemoveItem( cargo );
961  delete cargo;
962  }
963  }
964 
965  m_AttachmentCargos.Clear();
966  Refresh();
967  m_Parent.Refresh();
968  RecomputeOpenedContainers();
969  }
970 
971  void DropReceived( Widget w, int x, int y, CargoContainer cargo )
972  {
973  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
974  EntityAI item_in_hands = player.GetHumanInventory().GetEntityInHands();
975 
976  EntityAI item = GetItemPreviewItem( w );
977  if( !item )
978  {
979  return;
980  }
981 
982  int idx = 0;
983  int c_x, c_y;
984 
985  EntityAI target_entity;
986  CargoBase target_cargo;
987 
988  if( cargo == m_CargoGrid )
989  {
990  target_entity = m_Entity;
991  target_cargo = m_Entity.GetInventory().GetCargo();
992  #ifdef PLATFORM_CONSOLE
993  if( m_CargoGrid.HasItem( item ) )
994  {
995  return;
996  }
997  #endif
998  }
999  else
1000  {
1001  target_entity = m_AttachmentCargos.GetKeyByValue( cargo );
1002  if( target_entity )
1003  {
1004  target_cargo = target_entity.GetInventory().GetCargo();
1005  #ifdef PLATFORM_CONSOLE
1006  if( cargo.HasItem( item ) )
1007  {
1008  return;
1009  }
1010  #endif
1011  }
1012  else
1013  return;
1014  }
1015 
1016  if( target_cargo && target_entity )
1017  {
1018  c_x = target_cargo.GetHeight();
1019  c_y = target_cargo.GetWidth();
1020  }
1021  else
1022  return;
1023 
1025  #ifdef PLATFORM_CONSOLE
1026  x = 0;
1027  y = target_cargo.GetItemCount();
1028  target_entity.GetInventory().FindFreeLocationFor( item, FindInventoryLocationType.CARGO, dst );
1029  #else
1030  dst.SetCargoAuto(target_cargo, item, x, y, item.GetInventory().GetFlipCargo());
1031  #endif
1032 
1034  item.GetInventory().GetCurrentInventoryLocation(src);
1035  if(src.CompareLocationOnly(dst) && src.GetFlip() == dst.GetFlip())
1036  return;
1037 
1038  #ifdef PLATFORM_CONSOLE
1039  if(dst.IsValid() && target_entity.GetInventory().LocationCanAddEntity(dst))
1040  #else
1041  if( c_x > x && c_y > y && target_entity.GetInventory().LocationCanAddEntity(dst))
1042  #endif
1043  {
1044  SplitItemUtils.TakeOrSplitToInventoryLocation( player, dst );
1045 
1046  Icon icon = cargo.GetIcon( item );
1047 
1048  if( icon )
1049  {
1050  if( w && w.FindAnyWidget("Cursor") )
1051  w.FindAnyWidget("Cursor").SetColor( ColorManager.BASE_COLOR );
1052  icon.Refresh();
1053  Refresh();
1054  }
1055  }
1056  ItemManager.GetInstance().HideDropzones();
1057  ItemManager.GetInstance().SetIsDragging( false );
1058  }
1059 
1060  bool DraggingOverGrid( Widget w, int x, int y, Widget reciever, CargoContainer cargo )
1061  {
1062  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1063  if( w == null )
1064  {
1065  return false;
1066  }
1067  EntityAI item = GetItemPreviewItem( w );
1068  if( !item || !item_in_hands )
1069  {
1070  return false;
1071  }
1072 
1073  int color;
1074  int idx = 0;
1075  int c_x, c_y;
1076 
1077  if( item_in_hands.GetInventory().GetCargo() )
1078  {
1079  c_x = item_in_hands.GetInventory().GetCargo().GetHeight();
1080  c_y = item_in_hands.GetInventory().GetCargo().GetWidth();
1081  }
1082 
1083  if( c_x > x && c_y > y && item_in_hands.GetInventory().CanAddEntityInCargoEx( item, 0, x, y, item.GetInventory().GetFlipCargo() ) )
1084  {
1085  ItemManager.GetInstance().HideDropzones();
1086  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
1087  color = ColorManager.GREEN_COLOR;
1088  }
1089  else
1090  {
1091  color = ColorManager.RED_COLOR;
1092  ItemManager.GetInstance().ShowSourceDropzone( item );
1093  }
1094 
1095  if( w.FindAnyWidget("Cursor") )
1096  {
1097  w.FindAnyWidget("Cursor").SetColor( color );
1098  }
1099  else
1100  {
1101  string name = w.GetName();
1102  name.Replace( "PanelWidget", "Cursor" );
1103  w.FindAnyWidget( name ).SetColor( color );
1104  }
1105 
1106  return true;
1107  }
1108 
1109  void TakeAsAttachment( Widget w, Widget receiver )
1110  {
1111  EntityAI receiver_item;
1112  EntityAI slot_owner;
1113  int slot_id = -1;
1114 
1115  SlotsIcon slots_icon;
1116  receiver.GetUserData(slots_icon);
1117  if( slots_icon )
1118  {
1119  receiver_item = slots_icon.GetEntity();
1120  slot_id = slots_icon.GetSlotID();
1121  slot_owner = slots_icon.GetSlotParent();
1122  }
1123 
1124  EntityAI item = GetItemPreviewItem( w );
1125  if( !item )
1126  {
1127  return;
1128  }
1129 
1130  ItemBase item_base = ItemBase.Cast( item );
1131  float stack_max = item_base.GetTargetQuantityMax(slot_id);
1132 
1133  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
1134  if( !item.GetInventory().CanRemoveEntity() || !player.CanManipulateInventory() )
1135  return;
1136 
1137  EntityAI target_att_entity = m_Entity;
1138  Weapon_Base wpn;
1139  Magazine mag;
1140  if( Class.CastTo(wpn, m_Entity ) && Class.CastTo(mag, item ) )
1141  {
1142  if( player.GetWeaponManager().CanAttachMagazine( wpn, mag ) )
1143  {
1144  player.GetWeaponManager().AttachMagazine( mag );
1145  }
1146  else if(player.GetWeaponManager().CanSwapMagazine( wpn, mag ))
1147  {
1148  player.GetWeaponManager().SwapMagazine( mag );
1149  }
1150  }
1151  else if( receiver_item )
1152  {
1153  if( receiver_item != item )
1154  {
1155  if( ( ItemBase.Cast( receiver_item ) ).CanBeCombined( ItemBase.Cast( item ) ) )
1156  {
1157  ( ItemBase.Cast( receiver_item ) ).CombineItemsClient( ItemBase.Cast( item ) );
1158  }
1159  else if( GameInventory.CanSwapEntitiesEx( receiver_item, item ) )
1160  {
1161  if( !receiver_item.GetInventory().CanRemoveEntity() )
1162  return;
1163  GetGame().GetPlayer().PredictiveSwapEntities( item, receiver_item );
1164  }
1165  }
1166  }
1167  else if( slot_owner && slot_owner.GetInventory().CanAddAttachmentEx( item, slot_id ) )
1168  {
1169  if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1170  {
1171  player.PredictiveTakeEntityToTargetAttachmentEx(slot_owner, item, slot_id);
1172  }
1173  else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1174  {
1175  item_base.SplitIntoStackMaxClient( m_Entity, slot_id );
1176  }
1177  }
1178  else if( slot_owner && slot_owner.GetInventory().CanAddAttachment( item ) )
1179  {
1180  if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1181  {
1182  player.PredictiveTakeEntityToTargetAttachment(slot_owner, item);
1183  }
1184  else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1185  {
1186  item_base.SplitIntoStackMaxClient( m_Entity, -1 );
1187  }
1188  }
1189  else if( m_Entity.GetInventory().CanAddAttachment( item ) )
1190  {
1191  if( stack_max == 0 || stack_max >= item_base.GetQuantity() )
1192  {
1193  player.PredictiveTakeEntityToTargetAttachment(m_Entity, item);
1194  }
1195  else if( stack_max != 0 && stack_max < item_base.GetQuantity() )
1196  {
1197  item_base.SplitIntoStackMaxClient( m_Entity, -1 );
1198  }
1199  }
1200  else if( ( m_Entity.GetInventory().CanAddEntityInCargo( item, item.GetInventory().GetFlipCargo() ) && ( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item )) ) || player.GetHumanInventory().HasEntityInHands( item ) )
1201  {
1202  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
1203  }
1204  /*else if( !player.GetInventory().HasEntityInInventory( item ) || !m_Entity.GetInventory().HasEntityInCargo( item ) )
1205  {
1206  SplitItemUtils.TakeOrSplitToInventory( PlayerBase.Cast( GetGame().GetPlayer() ), m_Entity, item );
1207  }*/
1208 
1209  ItemManager.GetInstance().HideDropzones();
1210  ItemManager.GetInstance().SetIsDragging( false );
1211  }
1212 
1213  void ShowAtt( EntityAI entity )
1214  {
1215  ResetContainer();
1216  m_StaticCargoCount = 0;
1217  m_Entity = entity;
1218  m_ActiveIndex = 0;
1219  if( entity.GetSlotsCountCorrect() > 0 )
1220  {
1221  m_Atts = new Attachments( this, entity );
1222  m_Atts.InitAttachmentGrid( 1 );
1223  m_AttachmentSlotsSorted = m_Atts.GetSlotsSorted();
1224  m_StaticAttCount = m_Atts.GetAttachmentHeight();
1225  m_Entity.GetOnItemAttached().Insert( AttachmentAdded );
1226  m_Entity.GetOnItemDetached().Insert( AttachmentRemoved );
1227  }
1228  else
1229  {
1230  m_StaticAttCount = 0;
1231  }
1232 
1233  if( entity.GetInventory().GetCargo() )
1234  {
1235  m_CargoGrid = new CargoContainer( this, false );
1236  m_CargoGrid.SetEntity( entity );
1237  m_CargoGrid.GetRootWidget().SetSort( 1 );
1238  Insert( m_CargoGrid );
1239  m_StaticCargoCount++;
1240  }
1241 
1242  if (m_AttachmentSlotsSorted)
1243  {
1244  foreach( int slot_id : m_AttachmentSlotsSorted )
1245  {
1246  EntityAI item = m_Entity.GetInventory().FindAttachment( slot_id );
1247  if( item )
1248  AttachmentAdded( item, InventorySlots.GetSlotName( slot_id ), m_Entity );
1249  }
1250  }
1251 
1252  if (m_CargoGrid)
1253  {
1254  bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1255  if (m_CargoGrid.IsVisible() && hideCargo)
1256  {
1257  HideCargo();
1258  }
1259  else if (!m_CargoGrid.IsVisible() && !hideCargo)
1260  {
1261  ShowCargo();
1262  }
1263  }
1264 
1265  m_CollapsibleHeader.ShowCollapseButtons(false);
1266  //m_CollapsibleHeader.ShowCollapseButtons( m_Atts || m_CargoGrid, m_Atts || m_CargoGrid );
1267  RecomputeOpenedContainers();
1268  Refresh();
1269  m_Parent.Refresh();
1270  }
1271 
1272  void RefreshHands()
1273  {
1274  for (int i = 0; i < m_Body.Count(); i++)
1275  {
1276  m_Body.Get( i ).OnShow();
1277  }
1278  Refresh();
1279  m_Parent.Refresh();
1280  }
1281 
1282  void AttachmentAdded(EntityAI item, string slot, EntityAI parent)
1283  {
1284  int slot_id = InventorySlots.GetSlotIdFromString( slot );
1285  int sort = -1;
1286  Attachments att_cont = null;
1287  CargoContainer cont = null;
1288 
1289  if( item.GetInventory().GetAttachmentSlotsCount() > 0 )
1290  {
1291  att_cont = new Attachments( this, item );
1292  sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_ATTACHMENTS_NEXT_OFFSET;
1293  att_cont.InitAttachmentGrid( sort );
1294 
1295  m_AttachmentAttachments.Insert( item, att_cont );
1296  m_AttachmentAttachmentsContainers.Insert( item, att_cont.GetWrapper() );
1297 
1298  att_cont.UpdateInterval();
1299  if( m_Parent )
1300  m_Parent.Refresh();
1301  Inventory.GetInstance().UpdateConsoleToolbar();
1302  }
1303 
1304  if( item.GetInventory().GetCargo() )
1305  {
1306  cont = new CargoContainer( this, true );
1307  sort = (m_AttachmentSlotsSorted.Find( slot_id ) * 2) + SORT_CARGO_NEXT_OFFSET; //m_AttachmentSlotsSorted.Find( slot_id ) + 50
1308  cont.GetRootWidget().SetSort( sort );
1309  cont.SetEntity( item );
1310 
1311  Insert(cont, -1);
1312 
1313  m_AttachmentCargos.Insert( item, cont );
1314  if( m_Parent )
1315  m_Parent.Refresh();
1316  Inventory.GetInstance().UpdateConsoleToolbar();
1317  }
1318 
1319  if (att_cont)
1320  {
1321  att_cont.ShowFalseAttachmentsHeader(true);
1322  if (cont)
1323  {
1324  cont.ShowFalseCargoHeader(false);
1325  cont.UpdateSize();
1326  cont.SetAlternateFalseTextHeaderWidget(att_cont.GetFalseHeaderTextWidget());
1327  }
1328  }
1329  else if (cont)
1330  {
1331  cont.SetAlternateFalseTextHeaderWidget(null); //just to be safe..
1332  }
1333 
1334  RecomputeOpenedContainers();
1335  }
1336 
1337  void AttachmentRemoved(EntityAI item, string slot, EntityAI parent)
1338  {
1339  int slot_id = InventorySlots.GetSlotIdFromString( slot );
1340 
1341  CargoContainer old_cont = m_AttachmentCargos.Get( item );
1342  if( old_cont )
1343  {
1344  m_Body.RemoveItem( old_cont );
1345  m_AttachmentCargos.Remove( item );
1346  delete old_cont;
1347  if( m_Parent )
1348  m_Parent.Refresh();
1349  Inventory.GetInstance().UpdateConsoleToolbar();
1350  }
1351 
1352  AttachmentsWrapper old_att_cont = m_AttachmentAttachmentsContainers.Get( item );
1353  if( old_att_cont )
1354  {
1355  m_AttachmentAttachmentsContainers.Remove( item );
1356  m_AttachmentAttachments.Remove( item );
1357  m_Body.RemoveItem( old_att_cont );
1358  delete old_att_cont;
1359  if( m_Parent )
1360  m_Parent.Refresh();
1361  Inventory.GetInstance().UpdateConsoleToolbar();
1362  }
1363  RecomputeOpenedContainers();
1364  }
1365 
1366  override void UpdateInterval()
1367  {
1368  super.UpdateInterval();
1369 
1370  if ( m_Entity )
1371  {
1372  if (m_CargoGrid)
1373  {
1374  bool hideCargo = m_Entity.GetInventory().IsInventoryLockedForLockType( HIDE_INV_FROM_SCRIPT ) || !m_Entity.CanDisplayCargo() || m_ForcedHide;
1375  if (m_CargoGrid.IsVisible() && hideCargo)
1376  {
1377  HideCargo();
1378  }
1379  else if (!m_CargoGrid.IsVisible() && !hideCargo)
1380  {
1381  ShowCargo();
1382  }
1383 
1384  m_CargoGrid.UpdateInterval();
1385  }
1386 
1387  if ( m_Atts )
1388  {
1389  m_Atts.UpdateInterval();
1390  }
1391 
1392  for ( int i = 0; i < m_AttachmentCargos.Count(); i++ )
1393  {
1394  m_AttachmentCargos.GetElement( i ).UpdateInterval();
1395  }
1396  }
1397 
1398  ElectricityIcon();
1399  m_CollapsibleHeader.UpdateInterval();
1400  }
1401 
1402  override void SetLayoutName()
1403  {
1404  m_LayoutName = WidgetLayoutName.ClosableContainer;
1405  }
1406 
1407  override void OnShow()
1408  {
1409  super.OnShow();
1410 
1411  for ( int i = 0; i < m_Body.Count(); i++ )
1412  {
1413  m_Body.Get( i ).OnShow();
1414  }
1415  }
1416 
1417  void MouseClick2(Widget w, int x, int y, int button)
1418  {
1419  string name = w.GetName();
1420  name.Replace("PanelWidget", "Render");
1421  ItemPreviewWidget itemPreview = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1422 
1423  if (itemPreview)
1424  {
1425  ItemBase selectedItem = ItemBase.Cast(itemPreview.GetItem());
1426 
1427  if (selectedItem)
1428  {
1429  switch (button)
1430  {
1431  case MouseState.RIGHT:
1432  #ifdef DIAG_DEVELOPER
1433  if (g_Game.IsLeftCtrlDown())
1434  ShowActionMenu(selectedItem);
1435  #endif
1436 
1437  break;
1438 
1439  case MouseState.MIDDLE:
1440  InspectItem(selectedItem);
1441  break;
1442 
1443  case MouseState.LEFT:
1444  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
1445  if (g_Game.IsLeftCtrlDown())
1446  {
1447  if (controlledPlayer.CanDropEntity(selectedItem))
1448  {
1449  if (selectedItem.GetTargetQuantityMax() < selectedItem.GetQuantity())
1450  selectedItem.SplitIntoStackMaxClient(null, -1);
1451  else
1452  controlledPlayer.PhysicalPredictiveDropItem(selectedItem);
1453  }
1454  else
1455  {
1456  bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(selectedItem, null ) && !controlledPlayer.GetInventory().IsInventoryLocked() && selectedItem.GetInventory().CanRemoveEntity() && !controlledPlayer.IsItemsToDelete();
1457  ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
1458  }
1459  }
1460 
1461  break;
1462  }
1463  }
1464  }
1465  }
1466 
1467  void DoubleClick(Widget w, int x, int y, int button)
1468  {
1469  if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
1470  {
1471  ItemPreviewWidget iw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
1472  if (!iw)
1473  {
1474  string name = w.GetName();
1475  name.Replace("PanelWidget", "Render");
1476  iw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
1477  }
1478 
1479  if (!iw)
1480  iw = ItemPreviewWidget.Cast(w);
1481 
1482  ItemBase item = ItemBase.Cast(iw.GetItem());
1483  if (item)
1484  {
1485  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
1486  EntityAI itemInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
1487 
1488  if (!item.GetInventory().CanRemoveEntity())
1489  return;
1490 
1491  if (controlledPlayer.GetInventory().HasEntityInInventory(item) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1492  {
1493  controlledPlayer.PredictiveTakeEntityToHands(item);
1494  }
1495  else
1496  {
1497  if (controlledPlayer.GetInventory().CanAddEntityToInventory(item) && controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
1498  {
1499  controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, item);
1500  }
1501  else
1502  {
1503  if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(item))
1504  controlledPlayer.PredictiveTakeEntityToHands(item);
1505  }
1506  }
1507 
1508  HideOwnedTooltip();
1509 
1510  name = w.GetName();
1511  name.Replace("PanelWidget", "Temperature");
1512  w.FindAnyWidget(name).Show(false);
1513  }
1514  }
1515  }
1516 
1517  void DraggingOverHeader2(Widget w, int x, int y, Widget receiver )
1518  {
1519  DraggingOverHeader(w, x, y, receiver );
1520  }
1521 
1522  void ElectricityIcon()
1523  {
1524  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
1525  if( item_in_hands && item_in_hands.GetCompEM() )
1526  {
1527  if( GetRootWidget().FindAnyWidget( "electricity" ) )
1528  {
1529  bool show_electricity_icon = item_in_hands.GetCompEM().HasElectricityIcon();
1530  GetRootWidget().FindAnyWidget( "electricity" ).Show( show_electricity_icon );
1531  }
1532 
1533  if( GetRootWidget().FindAnyWidget( "electricity_can_work" ) )
1534  {
1535  bool show_electricity_can_work_icon = item_in_hands.GetCompEM().CanWork() && !item_in_hands.IsRuined();
1536  GetRootWidget().FindAnyWidget( "electricity_can_work" ).Show( show_electricity_can_work_icon );
1537  }
1538  }
1539  else
1540  {
1541  GetRootWidget().FindAnyWidget( "electricity" ).Show( false );
1542  }
1543  }
1544 
1545  void CollapseButtonOnMouseButtonDown( Widget w )
1546  {
1547  int i;
1548  if( !m_Hidden )
1549  {
1550  for (i = 0; i < m_Body.Count(); i++)
1551  {
1552  m_Body.Get( i ).OnHide();
1553  }
1554  m_Hidden = true;
1555  }
1556  else
1557  {
1558  for (i = 0; i < m_Body.Count(); i++)
1559  {
1560  m_Body.Get( i ).OnShow();
1561  }
1562  m_Hidden = false;
1563  }
1564 
1565  w.FindAnyWidget("opened").Show(m_Hidden);
1566  w.FindAnyWidget("closed").Show(!m_Hidden);
1567 
1568  m_Parent.Refresh();
1569  }
1570 
1571  void HideCargo()
1572  {
1573  if( m_CargoGrid )
1574  {
1575  m_CargoGrid.OnHide();
1576  RecomputeOpenedContainers();
1577  }
1578  }
1579 
1580  void ShowCargo()
1581  {
1582  if( m_CargoGrid )
1583  {
1584  m_CargoGrid.OnShow();
1585  RecomputeOpenedContainers();
1586  }
1587  }
1588 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
m_player
DayZPlayer m_player
Definition: randomgeneratorsyncmanager.c:15
HandsHeader
Definition: handsheader.c:1
QuantityConversions
Definition: quantityconversions.c:1
InventorySlots
provides access to slot configuration
Definition: inventoryslots.c:5
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
GetMousePos
proto void GetMousePos(out int x, out int y)
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
WidgetLayoutName
Definition: widgetlayoutname.c:1
HandsPreview
Definition: handspreview.c:1
m_Parent
protected Widget m_Parent
Definition: sizetochild.c:92
SplitItemUtils
Definition: splititemutils.c:1
InventoryItem
Definition: itembase.c:13
FindAnyWidget
proto native Widget FindAnyWidget(string pathname)
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
GetContextMenu
override ContextMenu GetContextMenu()
Definition: inventorymenu.c:80
Attachments
Definition: attachments.c:3
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
m_IsActive
bool m_IsActive
Definition: modifierbase.c:20
Header
Definition: header.c:1
ColorManager
Definition: colormanager.c:1
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
Container
Definition: cargocontainer.c:2
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
PrintString
void PrintString(string s)
Helper for printing out string expression. Example: PrintString("Hello " + var);.
Definition: enscript.c:345
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
ActionManagerClient
Definition: actionmanagerclient.c:4
MouseState
MouseState
Definition: ensystem.c:310
array
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
Definition: isboxcollidinggeometryproxyclasses.c:27
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
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
InventoryCombinationFlags
Definition: inventorycombinationflags.c:1
Widget
Definition: enwidgets.c:189
AttachmentsWrapper
Definition: attachmentswrapper.c:1
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
ZombieBase
Definition: zombiefemalebase.c:1
EntityAI
Definition: building.c:5
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11
HandsContainer
Definition: handscontainer.c:1
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78