Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
cargocontainer.c
Go to the documentation of this file.
1 //cargo grid wrapper
2 class CargoContainer extends Container
3 {
4  protected const int ROWS_NUMBER_XBOX = 5;
5 
6  protected CargoBase m_Cargo;
7  protected int m_CargoIndex = -1;
8 
9  protected int m_FocusedItemPosition = -1;
10  protected ref array<ref CargoContainerRow> m_Rows;
11  protected ref array<ref Icon> m_Icons;
12  protected ref map<EntityAI, ref Param3<ref Icon, int, int>> m_ShowedItemPositions;
13  protected ref map<EntityAI, ref Param3<ref Icon, int, int>> m_ShowedLockPositions;
14 
15  protected float m_IconSize;
16  protected float m_SpaceSize;
17 
18  protected bool m_IsAttachment;
19  protected TextWidget m_FalseHeaderTextWidget;
20  protected TextWidget m_AlternateFalseHeaderTextWidget; //to be set and updated along with the main one
21  protected Widget m_CargoHeader;
22  protected Widget m_CargoContainer;
23  protected Widget m_ItemsContainer;
24 #ifndef PLATFORM_CONSOLE
25  protected ref SizeToChild m_Resizer1;
26 #endif
27  protected ref SizeToChild m_Resizer2;
28  protected ref Timer m_ResizeTimer;
29 
30  void CargoContainer( LayoutHolder parent, bool is_attachment = false )
31  {
32  m_IsAttachment = is_attachment;
33  m_Rows = new array<ref CargoContainerRow>;
34  m_Icons = new array<ref Icon>;
35  m_ShowedItemPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
36  m_ShowedLockPositions = new map<EntityAI, ref Param3<ref Icon, int, int>>;
37 
38  m_CargoContainer = m_RootWidget.FindAnyWidget( "grid_background" );
39  m_ItemsContainer = m_RootWidget.FindAnyWidget( "grid_overlay" );
40  m_CargoHeader = m_RootWidget.FindAnyWidget( "grid_container_header_spacer" );
41 #ifndef PLATFORM_CONSOLE
42  m_RootWidget.GetScript( m_Resizer1 );
43 #endif
44  m_RootWidget.FindAnyWidget( "grid_container" ).GetScript( m_Resizer2 );
45  m_CargoHeader.Show( is_attachment );
46  m_FalseHeaderTextWidget = TextWidget.Cast(m_CargoHeader.FindAnyWidget( "TextWidget0" ));
47 
48  m_MainWidget = m_CargoContainer;
49  m_FocusedItemPosition = -1;
50  }
51 
52  void ~CargoContainer()
53  {
54  if ( m_Entity )
55  {
56  m_Entity.GetOnItemAddedIntoCargo().Remove( AddedToCargo );
57  m_Entity.GetOnItemRemovedFromCargo().Remove( RemovedFromCargo );
58  m_Entity.GetOnItemMovedInCargo().Remove( MovedInCargo );
59  m_Entity.GetOnSetLock().Remove( SetLock );
60  m_Entity.GetOnReleaseLock().Remove( ReleaseLock );
61  }
62  }
63 
64  int GetCargoIndex() { return m_CargoIndex; }
65 
66  void AddedToCargoEx( EntityAI item, bool refresh = true )
67  {
69  item.GetInventory().GetCurrentInventoryLocation( il );
70  int x = il.GetCol();
71  int y = il.GetRow();
72 
73  if ( m_ShowedItemPositions.Contains( item ) )
74  {
75  Param3<ref Icon, int, int> item_pos = m_ShowedItemPositions.Get( item );
76  InitIconEx( item_pos.param1, item, x, y, refresh );
77  item_pos.param2 = x;
78  item_pos.param3 = y;
79  }
80  else
81  {
82  ref Icon icon = new Icon( this, false );
83  m_Icons.Insert( icon );
84  InitIconEx( icon, item, x, y, refresh );
85  m_ShowedItemPositions.Insert( item, new Param3<ref Icon, int, int>( icon, x, y ) );
86  }
87 
88  if (refresh)
89  UpdateHeaderText();
90 
91  #ifdef PLATFORM_CONSOLE
92  for ( int i = 0; i < m_Cargo.GetItemCount(); i++ )
93  {
94  EntityAI item2 = m_Cargo.GetItem( i );
95  Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item2 );
96  if ( data )
97  {
98  data.param1.SetCargoPos( i );
99  data.param1.SetPos();
100  }
101  }
102 
103  m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
104 
105  if (refresh)
106  Refresh();
107  #endif
108  }
109 
110  void AddedToCargo( EntityAI item )
111  {
112  AddedToCargoEx( item );
113  }
114 
115  void RemovedFromCargo( EntityAI item )
116  {
117  Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
118  if( data )
119  {
120  m_Icons.RemoveItem( data.param1 );
121  m_ShowedItemPositions.Remove( item );
122  }
123 
124  UpdateHeaderText();
125 
126  #ifdef PLATFORM_CONSOLE
127  for( int i = 0; i < m_Cargo.GetItemCount(); i++ )
128  {
129  EntityAI item2 = m_Cargo.GetItem( i );
130  data = m_ShowedItemPositions.Get( item2 );
131  if( data && data.param1 )
132  {
133  data.param1.SetCargoPos( i );
134  data.param1.SetPos();
135  }
136  }
137 
138  m_FocusedItemPosition = Math.Min( m_ShowedItemPositions.Count() - 1, m_FocusedItemPosition );
139 
140  Refresh();
141  #endif
142  }
143 
144  void MovedInCargo( EntityAI item )
145  {
147  item.GetInventory().GetCurrentInventoryLocation( il );
148 
149  int x = il.GetCol();
150  #ifdef PLATFORM_CONSOLE
151  int y = il.GetRow() - 1;
152  #else
153  int y = il.GetRow();
154  #endif
155  if( m_ShowedItemPositions.Contains( item ) )
156  {
157  ref Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
158  if( data.param1 )
159  {
160  if( data.param2 != x || data.param3 != y )
161  {
162  data.param2 = x;
163  data.param3 = y;
164  #ifdef PLATFORM_CONSOLE
165  data.param1.SetCargoPos( data.param3 );
166  #endif
167  #ifdef PLATFORM_WINDOWS
168  data.param1.SetPosX( data.param2 );
169  data.param1.SetPosY( data.param3 );
170  #endif
171  }
172  data.param1.UpdateInterval();
173  }
174  }
175  UpdateSelection();
176  }
177 
178  void SetLock( EntityAI item )
179  {
180  #ifndef PLATFORM_CONSOLE
181  if( GetGame().GetPlayer() )
182  {
184  int index = GetGame().GetPlayer().GetHumanInventory().FindUserReservedLocationIndex( item );
185  if( index >= 0 )
186  {
187  GetGame().GetPlayer().GetHumanInventory().GetUserReservedLocation( index, il );
188 
189  ref Icon icon = new Icon( this, false );
190  m_Icons.Insert( icon );
191  icon.InitLock( m_Entity, item, il.GetCol(), il.GetRow(), il.GetFlip() );
192  m_ShowedLockPositions.Insert( item, new Param3<ref Icon, int, int>( icon, 1, 1 ) );
193  item.GetOnReleaseLock().Insert( ReleaseLock );
194  }
195  }
196  #endif
197  }
198 
199  void ReleaseLock( EntityAI item )
200  {
201  #ifndef PLATFORM_CONSOLE
202  if( m_ShowedLockPositions.Contains( item ) )
203  {
204  Icon ic = m_ShowedLockPositions.Get( item ).param1;
205  m_Icons.RemoveItem( ic );
206  m_ShowedLockPositions.Remove( item );
207  item.GetOnReleaseLock().Remove( ReleaseLock );
208  }
209  #endif
210  }
211 
212  override void SetLayoutName()
213  {
214  #ifdef PLATFORM_CONSOLE
215  m_LayoutName = WidgetLayoutName.CargoContainerXbox;
216  #else
217  switch( InventoryMenu.GetWidthType() )
218  {
219  case ScreenWidthType.NARROW:
220  {
221  m_LayoutName = WidgetLayoutName.CargoContainerNarrow;
222  break;
223  }
224  case ScreenWidthType.MEDIUM:
225  {
226  m_LayoutName = WidgetLayoutName.CargoContainerMedium;
227  break;
228  }
229  case ScreenWidthType.WIDE:
230  {
231  m_LayoutName = WidgetLayoutName.CargoContainerWide;
232  break;
233  }
234  }
235  #endif
236 
237  }
238 
239  void SetEntity( EntityAI item, int cargo_index = 0, bool immedUpdate = true )
240  {
241  if ( item )
242  {
243  m_Entity = item;
244  m_Cargo = item.GetInventory().GetCargoFromIndex(cargo_index);
245  m_CargoIndex = cargo_index;
246 
247  m_Entity.GetOnItemAddedIntoCargo().Insert( AddedToCargo );
248  m_Entity.GetOnItemRemovedFromCargo().Insert( RemovedFromCargo );
249  m_Entity.GetOnItemMovedInCargo().Insert( MovedInCargo );
250  m_Entity.GetOnSetLock().Insert( SetLock );
251  m_Entity.GetOnReleaseLock().Insert( ReleaseLock );
252 
253  if (immedUpdate)
254  UpdateHeaderText();
255 
256  InitGridHeight();
257  m_MainWidget = m_ItemsContainer;
258 
259  if ( m_Cargo )
260  {
261  int i;
262  int prev_count = m_ShowedItemPositions.Count();
263 
264  //START - Add new item Icons
265  for ( i = 0; i < m_Cargo.GetItemCount(); i++ )
266  {
267  EntityAI cargo_item = m_Cargo.GetItem( i );
268  if ( cargo_item )
269  {
270  AddedToCargoEx( cargo_item, immedUpdate );
271  }
272  }
273 
274  #ifdef PLATFORM_CONSOLE
275  if (immedUpdate)
276  Refresh();
277  #endif
278  }
279  }
280  }
281 
283  {
284  return m_Entity;
285  }
286 
287  void UpdateHeaderText()
288  {
289  Widget header;
290  string name = m_Entity.GetDisplayName();
291  name.ToUpper();
292 
293  if ( m_Entity.CanDisplayCargo() && m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex) )
294  {
295  name = name + " (" + GetCargoCapacity().ToString() + "/" + GetMaxCargoCapacity() + ")";
296  if ( m_IsAttachment && m_CargoHeader )
297  {
298  m_FalseHeaderTextWidget.SetText(name);
299  float x, y;
300  m_FalseHeaderTextWidget.Update();
301  m_FalseHeaderTextWidget.GetScreenSize( x, y );
302  m_CargoHeader.FindAnyWidget( "grid_container_header" ).SetSize( 1, y + InventoryMenu.GetHeightMultiplied( 10 ) );
303  m_CargoHeader.Update();
304 
305  if (m_AlternateFalseHeaderTextWidget)
306  {
307  m_AlternateFalseHeaderTextWidget.SetText(name);
308  }
309  return;
310  }
311  }
312 
313  if ( Container.Cast( GetParent() ) && Container.Cast( GetParent() ).GetHeader() )
314  Container.Cast( GetParent() ).GetHeader().SetName(name);
315  }
316 
317  void InitGridHeight()
318  {
319  m_Rows.Clear();
320  m_ShowedItemPositions.Clear();
321 
322  ref CargoContainerRow row;
323 
324  #ifdef PLATFORM_CONSOLE
325  int cargo_height = 1;
326  #else
327  int cargo_height = m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetHeight();
328  #endif
329 
330  for ( int j = 0; j < cargo_height; j++ )
331  {
332  row = new CargoContainerRow( this );
333 
334  row.SetNumber( j );
335  row.SetEntity( m_Entity );
336 
337  #ifdef PLATFORM_WINDOWS
338  #ifndef PLATFORM_CONSOLE
339  row.SetWidth( m_Entity.GetInventory().GetCargoFromIndex(m_CargoIndex).GetWidth(), false );
340  #endif
341  #endif
342 
343  row.GetRootWidget().SetSort( j, false );
344  m_Rows.Insert( row );
345  }
346 
347  float y;
348  row.GetRootWidget().FindAnyWidget( "Icon0" ).GetScreenSize( y, m_IconSize );
349  #ifdef PLATFORM_WINDOWS
350  #ifndef PLATFORM_CONSOLE
351  row.GetRootWidget().FindAnyWidget( "Spacer0" ).GetScreenSize( m_SpaceSize, y );
352  #endif
353  #endif
354 
355  m_Resizer2.ResizeParentToChild();
356 #ifndef PLATFORM_CONSOLE
357  m_Resizer1.ResizeParentToChild();
358 #endif
359  }
360 
361  void UpdateSize()
362  {
363 #ifndef PLATFORM_CONSOLE
364  m_Resizer1.ResizeParentToChild();
365 #else
366  m_Resizer2.ResizeParentToChild();
367 #endif
368  }
369 
370  float GetIconSize()
371  {
372  return m_IconSize;
373  }
374 
375  float GetSpaceSize()
376  {
377  return m_SpaceSize;
378  }
379 
380  int GetCargoCapacity()
381  {
382  #ifdef PLATFORM_CONSOLE
383  #ifndef PLATFORM_WINDOWS
384  return CargoList.Cast( m_Cargo ).GetTotalWeight( null );
385  #endif
386  #endif
387  int total_size = 0;
388  for ( int i = 0; i < m_Cargo.GetItemCount(); ++i )
389  {
390  int x, y;
391  m_Cargo.GetItemSize( i, x, y );
392  total_size += x * y;
393  }
394  return total_size;
395  }
396 
397  int GetMaxCargoCapacity()
398  {
399  #ifdef PLATFORM_CONSOLE
400  #ifndef PLATFORM_WINDOWS
401  return CargoList.Cast( m_Cargo ).GetMaxWeight();
402  #endif
403  #endif
404  return m_Cargo.GetWidth() * m_Cargo.GetHeight();
405  }
406 
407  Icon GetIcon( EntityAI item )
408  {
409  if ( item && m_ShowedItemPositions.Contains( item ) )
410  {
411  Param3<ref Icon, int, int> data = m_ShowedItemPositions.Get( item );
412  return data.param1;
413  }
414  return null;
415  }
416 
417  Icon GetIcon( int index )
418  {
419  if ( m_Cargo == null )
420  {
421  return null;
422  }
423 
424  if ( index >= 0 && m_Cargo.GetItemCount() > index )
425  return GetIcon( m_Cargo.GetItem( index ) );
426  return null;
427  }
428 
429  Icon GetFocusedIcon()
430  {
431  return GetIcon( m_FocusedItemPosition );
432  }
433 
434  override float GetFocusedContainerHeight( bool contents = false )
435  {
436  float x, y;
437  if( contents && GetFocusedIcon() )
438  GetFocusedIcon().GetRootWidget().GetScreenSize( x, y );
439  else
440  GetRootWidget().GetScreenSize( x, y );
441  return y;
442  }
443 
444  override float GetFocusedContainerYPos( bool contents = false )
445  {
446  float x, y;
447  if( contents && GetFocusedIcon() )
448  GetFocusedIcon().GetRootWidget().GetPos( x, y );
449  else
450  GetRootWidget().GetPos( x, y );
451  return y;
452  }
453 
454  override float GetFocusedContainerYScreenPos( bool contents = false )
455  {
456  float x, y;
457  if( contents && GetFocusedIcon() )
458  GetFocusedIcon().GetRootWidget().GetScreenPos( x, y );
459  else
460  GetRootWidget().GetScreenPos( x, y );
461  return y;
462  }
463 
464  void UpdateSelection()
465  {
466  if( m_IsActive )
467  {
468  if( m_FocusedItemPosition >= m_Icons.Count() )
469  m_FocusedItemPosition = m_Icons.Count() - 1;
470  Icon icon = GetIcon( m_FocusedItemPosition );
471  if( icon && !icon.IsActive() )
472  {
473  icon.SetActive( true );
474  Inventory.GetInstance().UpdateConsoleToolbar();
475  }
476  }
477  }
478 
479  void UpdateRowVisibility( int count )
480  {
481  int i;
482  int rows = Math.Max( 1, Math.Ceil( (count + 1) / ROWS_NUMBER_XBOX ) );
483  int diff = rows - m_Rows.Count();
484 
485  if( diff < 0 )
486  {
487  for( i = m_Rows.Count() - 1; i >= rows; i-- )
488  {
489  m_Rows.Remove( i );
490  }
491  }
492  else if( diff > 0 )
493  {
494  m_MainWidget = m_CargoContainer;
495  for( i = m_Rows.Count(); i < rows; i++ )
496  {
497  ref CargoContainerRow row = new CargoContainerRow( this );
498 
499  row.SetNumber( i );
500  row.SetEntity( m_Entity );
501  row.GetRootWidget().SetSort( i );
502  m_Rows.Insert( row );
503  }
504  m_MainWidget = m_ItemsContainer;
505  }
506 
507  m_Resizer2.ResizeParentToChild();
508 #ifndef PLATFORM_CONSOLE
509  m_Resizer1.ResizeParentToChild();
510 #endif
511  }
512 
513  override void Refresh()
514  {
515  #ifdef PLATFORM_CONSOLE
516  if ( !m_ResizeTimer )
517  m_ResizeTimer = new Timer();
518  if ( m_ResizeTimer.IsRunning() )
519  m_ResizeTimer.Stop();
520  m_ResizeTimer.Run( 0.05, this, "RefreshImpl" );
521  #endif
522  }
523 
524  void RefreshImpl()
525  {
526  UpdateRowVisibility( m_ShowedItemPositions.Count() );
527  UpdateSelection();
528  }
529 
530  override void UpdateInterval()
531  {
532  foreach( Param3<ref Icon, int, int> data : m_ShowedItemPositions )
533  {
534  if( data.param1 )
535  {
536  data.param1.UpdateInterval();
537  }
538  }
539  }
540 
541  Icon InitIconEx( Icon icon, EntityAI item, int pos_x, int pos_y, bool refresh = true )
542  {
543  #ifdef PLATFORM_CONSOLE
544  icon.SetSize( 1, 1 );
545  #ifdef PLATFORM_WINDOWS
546  pos_y = pos_y * 5 + pos_x;
547  #endif
548  icon.SetCargoPos( pos_y );
549  icon.SetPosY( pos_y );
550  icon.SetPosEx( refresh );
551  #else
552  int size_x, size_y;
553  GetGame().GetInventoryItemSize( InventoryItem.Cast( item ), size_x, size_y );
554 
555  if ( item.GetInventory().GetFlipCargo() )
556  icon.SetSize( size_y, size_x );
557  else
558  icon.SetSize( size_x, size_y );
559 
560  icon.SetPosX( pos_x );
561  icon.SetPosY( pos_y );
562  icon.SetPosEx( refresh );
563  #endif
564  icon.InitEx( item, refresh );
565  return icon;
566  }
567 
568  Icon InitIcon( Icon icon, EntityAI item, int pos_x, int pos_y )
569  {
570  return InitIconEx( icon, item, pos_x, pos_y );
571  }
572 
573  bool HasItem( EntityAI item )
574  {
575  return m_ShowedItemPositions.Contains( item );
576  }
577 
578  override bool TransferItemToVicinity()
579  {
580  if (CanDrop())
581  {
582  Man player = GetGame().GetPlayer();
583  if( GetFocusedIcon() )
584  {
585  ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
586  if( item && player.CanDropEntity( item ) )
587  {
588  if( item.GetTargetQuantityMax() < item.GetQuantity() )
589  item.SplitIntoStackMaxClient( null, -1 );
590  else
591  player.PhysicalPredictiveDropItem( item );
592  return true;
593  }
594  }
595  }
596  return false;
597  }
598 
599  override void SetDefaultFocus( bool while_micromanagment_mode = false )
600  {
601  super.SetDefaultFocus(while_micromanagment_mode);
602 
603  Unfocus();
604  m_FocusedItemPosition = 0;
605  UpdateSelection();
606  }
607 
608  override void SetLastFocus()
609  {
610  SetDefaultFocus();
611  }
612 
613  override void Unfocus()
614  {
615  Icon icon = GetFocusedIcon();
616  if ( icon )
617  {
618  icon.SetActive( false );
619  }
620  }
621 
622  override void UnfocusAll()
623  {
624  if( m_Icons )
625  {
626  foreach( Icon icon : m_Icons )
627  {
628  icon.SetActive( false );
629  }
630  }
631  m_FocusedItemPosition = 0;
632  }
633 
634  override void SetNextActive()
635  {
636  Unfocus();
637  int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
638  int max_row = ( m_Icons.Count() - 1) / ROWS_NUMBER_XBOX;
639 
640  if ( max_row > focused_row )
641  {
642  m_FocusedItemPosition += ROWS_NUMBER_XBOX;
643  if ( m_FocusedItemPosition >= m_Icons.Count() )
644  {
645  m_FocusedItemPosition = m_Icons.Count() - 1;
646  }
647  UpdateSelection();
648  }
649  else
650  {
651  SetActive(false);
652  }
653  }
654 
655  override void SetPreviousActive( bool force = false )
656  {
657  Unfocus();
658  int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
659 
660  if ( focused_row > 0 )
661  {
662  m_FocusedItemPosition = m_FocusedItemPosition - ROWS_NUMBER_XBOX;
663  UpdateSelection();
664  }
665  else
666  {
667  SetActive(false);
668  }
669  }
670 
671 
672  override void SetNextRightActive()
673  {
674  if ( m_Icons.Count() > 0)
675  {
676  Unfocus();
677  int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
678  int row_min = focused_row * ROWS_NUMBER_XBOX;
679  int row_max = row_min + ROWS_NUMBER_XBOX - 1;
680 
681  if ( row_max >= m_Icons.Count() )
682  {
683  row_max = m_Icons.Count() - 1;
684  }
685 
686  m_FocusedItemPosition++;
687  if( m_FocusedItemPosition > row_max )
688  {
689  m_FocusedItemPosition = row_min;
690  }
691 
692  UpdateSelection();
693  }
694  }
695 
696  override void SetNextLeftActive()
697  {
698  if ( m_Icons.Count() > 0)
699  {
700  Unfocus();
701  int focused_row = m_FocusedItemPosition / ROWS_NUMBER_XBOX;
702  int row_min = focused_row * ROWS_NUMBER_XBOX;
703  int row_max = row_min + ROWS_NUMBER_XBOX - 1;
704 
705  if ( row_max >= m_Icons.Count() )
706  {
707  row_max = m_Icons.Count() - 1;
708  }
709 
710  m_FocusedItemPosition--;
711  if( m_FocusedItemPosition < row_min )
712  {
713  m_FocusedItemPosition = row_max;
714  }
715 
716  UpdateSelection();
717  }
718  }
719 
720  override EntityAI GetFocusedItem()
721  {
722  Icon icon = GetFocusedIcon();
723  if( icon )
724  {
725  return EntityAI.Cast( icon.GetObject() );
726  }
727 
728  return null;
729  }
730 
731  override void SetLastActive()
732  {
733  super.SetLastActive();
734  if( GetFocusedIcon() )
735  {
736  GetFocusedIcon().SetActive( false );
737  }
738  m_FocusedItemPosition = ( ( m_Rows.Count() - 1 ) * ROWS_NUMBER_XBOX );
739  UpdateSelection();
740  }
741 
742  override void SetActive( bool active )
743  {
744  super.SetActive( active );
745  UpdateSelection();
746  }
747 
748  override bool IsItemActive()
749  {
750  if( GetFocusedIcon() )
751  {
752  ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
753  return ( item != null );
754  }
755  return false;
756  }
757 
758  override bool IsItemWithQuantityActive()
759  {
760  if( GetFocusedIcon() )
761  {
762  ItemBase item = ItemBase.Cast( GetFocusedIcon().GetObject() );
763  return ( !IsEmpty() && QuantityConversions.HasItemQuantity( item ) && item.CanBeSplit() );
764  }
765  return false;
766  }
767 
768  override bool IsEmpty()
769  {
770  return m_Icons.Count() == 0;
771  }
772 
773  int GetRecipeCount( bool recipe_anywhere, ItemBase entity1, ItemBase entity2, PlayerBase player )
774  {
775  PluginRecipesManager recipes_manager = PluginRecipesManager.Cast( GetPlugin( PluginRecipesManager ) );
776  return recipes_manager.GetValidRecipes( entity1, entity2, null, player );
777  }
778 
779  override bool CanCombineAmmo()
780  {
781  if( GetFocusedIcon() )
782  {
784 
785  ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
786  ItemBase item_in_hands = ItemBase.Cast( GetGame().GetPlayer().GetHumanInventory().GetEntityInHands() );
787 
788  return ( amc.CanPerformActionFromInventory( item_in_hands, entity ) || amc.CanSetActionFromInventory( item_in_hands, entity ) );
789  }
790  return false;
791  }
792 
793  override bool TransferItem()
794  {
795  if (CanTakeToInventory())
796  {
797  if (GetFocusedIcon())
798  {
799  EntityAI entity = EntityAI.Cast( GetFocusedIcon().GetObject() );
800  if (entity)
801  {
802  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.CARGO, entity );
803  return true;
804  }
805  }
806  }
807  return false;
808  }
809 
810  override bool SplitItem()
811  {
812  if (CanSplit())
813  {
814  if ( GetFocusedIcon() )
815  {
816  ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
817  if ( entity )
818  {
819  if ( entity.HasQuantity() && entity.CanBeSplit() )
820  {
821  entity.OnRightClick();
822  Icon icon = m_ShowedItemPositions.Get( entity ).param1;
823 
824  if ( icon )
825  {
826  icon.SetQuantity();
827  }
828  }
829  }
830  }
831  }
832  return false;
833  }
834 
835  override bool EquipItem()
836  {
837  if (CanEquip())
838  {
839  if (GetFocusedIcon())
840  {
841  ItemBase entity = ItemBase.Cast( GetFocusedIcon().GetObject() );
842  if( entity )
843  {
844  GetGame().GetPlayer().PredictiveTakeEntityToInventory( FindInventoryLocationType.ATTACHMENT, entity );
845  return true;
846  }
847  }
848  }
849  return false;
850  }
851 
852  override bool SelectItem()
853  {
854  Icon focused_item = GetFocusedIcon();
855  if (focused_item)
856  {
857  ItemBase item = ItemBase.Cast(focused_item.GetObject());
858  if (item && item.IsTakeable() && item.CanPutIntoHands(null))
859  {
860  ItemManager.GetInstance().SetSelectedItemEx(item, this, focused_item);
861  return true;
862  }
863  }
864  return false;
865  }
866 
867  override bool Select()
868  {
869  EntityAI focused_item = GetFocusedItem();
870  EntityAI selected_item = ItemManager.GetInstance().GetSelectedItem();
871  DayZPlayer player = GetGame().GetPlayer();
872 
873 
874  if( focused_item != selected_item )
875  {
876  if( selected_item )
877  {
878  if( selected_item.GetInventory().CanRemoveEntity() && m_Entity )
879  {
880  bool can_add = m_Entity.GetInventory().CanAddEntityInCargo( selected_item, selected_item.GetInventory().GetFlipCargo());
881  bool in_cargo = !player.GetInventory().HasEntityInInventory( selected_item ) || !m_Entity.GetInventory().HasEntityInCargo( selected_item );
882  if( can_add && in_cargo )
883  {
884  player.PredictiveTakeEntityToTargetCargo( m_Entity, selected_item );
885  Container selected_cont2 = ItemManager.GetInstance().GetSelectedContainer();
886  if( selected_cont2 )
887  {
888  selected_cont2.SetActive( false );
889  }
890 
891  SetActive( true );
892  m_FocusedItemPosition = 0;
893  return true;
894  }
895  else
896  {
897  Container selected_cont = ItemManager.GetInstance().GetSelectedContainer();
898  if( selected_cont )
899  {
900  selected_cont.SetActive( false );
901  }
902 
903  SetActive( true );
904  SetDefaultFocus( true );
905  }
906  }
907  }
908  else if ( focused_item && focused_item.GetInventory().CanRemoveEntity() )
909  {
910  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
911  if( item_in_hands )
912  {
913  if( GameInventory.CanSwapEntitiesEx( item_in_hands, focused_item ) )
914  {
915  player.PredictiveSwapEntities( item_in_hands, focused_item );
916  return true;
917  }
918  }
919  else
920  {
921  if( player.GetHumanInventory().CanAddEntityInHands( focused_item ) )
922  {
923  player.PredictiveTakeEntityToHands( focused_item );
924  return true;
925  }
926  }
927  }
928  }
929  return false;
930  }
931 
932  override bool Combine()
933  {
934  if (CanCombine())
935  {
936  if (GetFocusedIcon())
937  {
938  Icon icon = GetFocusedIcon();
939  if( icon )
940  {
941  EntityAI item_in_hands = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
942  EntityAI prev_item = EntityAI.Cast( icon.GetObject() );
943  if( item_in_hands && prev_item )
944  {
945  return icon.CombineItems( item_in_hands, prev_item );
946  }
947  }
948  }
949  }
950  return false;
951  }
952 
953  void ShowFalseCargoHeader(bool show)
954  {
955  m_CargoHeader.Show(show);
956  }
957 
958  void SetAlternateFalseTextHeaderWidget(TextWidget w)
959  {
960  bool update = !m_AlternateFalseHeaderTextWidget;
961  m_AlternateFalseHeaderTextWidget = w;
962  if (update)
963  {
964  UpdateHeaderText();
965  }
966  }
967 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
QuantityConversions
Definition: quantityconversions.c:1
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
SetActive
void SetActive()
Definition: trapbase.c:437
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
IsEmpty
override bool IsEmpty()
Definition: fireplacebase.c:2454
WidgetLayoutName
Definition: widgetlayoutname.c:1
InventoryItem
Definition: itembase.c:13
Refresh
void Refresh()
Definition: sizetochild.c:108
Param3
Definition: entityai.c:95
DayZPlayer
Definition: dayzplayerimplement.c:72
CargoContainerRow
Definition: cargocontainerrow.c:1
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
SplitItem
void SplitItem(PlayerBase player)
Definition: itembase.c:1797
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
m_IsActive
bool m_IsActive
Definition: modifierbase.c:20
TextWidget
Definition: enwidgets.c:219
SetLayoutName
override void SetLayoutName()
Definition: inventory.c:1078
GetHeader
string GetHeader()
Definition: errorproperties.c:76
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
Container
Definition: cargocontainer.c:2
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
ActionManagerClient
Definition: actionmanagerclient.c:4
ScreenWidthType
ScreenWidthType
Definition: inventorymenu.c:1
array< ref CargoContainerRow >
GetIcon
string GetIcon()
Definition: notificationsystem.c:45
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
GetActionManager
protected void GetActionManager()
Definition: crosshairselector.c:132
x
Icon x
GetObject
proto native vobject GetObject(string name)
Loads object from data, or gets it from cache. Object must be released when not used.
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Icon
Definition: icon.c:1
InventoryMenu
void InventoryMenu()
Definition: inventorymenu.c:20
UpdateInterval
override void UpdateInterval()
Definition: inventory.c:672
SetLock
void SetLock(bool state)
Definition: modifierbase.c:135
GetParent
proto native Widget GetParent()
Get parent of the Effect.
Definition: effect.c:405
Inventory
void Inventory(LayoutHolder parent)
Definition: inventory.c:76
Timer
Definition: dayzplayerimplement.c:62
GetEntity
EntityAI GetEntity(int index)
Definition: quickbarbase.c:78
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
EntityAI
Definition: building.c:5
m_Entity
EntityAI m_Entity
Definition: actiondebug.c:11
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78