Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
itemmanager.c
Go to the documentation of this file.
2 {
3  private ref static ItemManager m_Instance;
4  protected bool m_IsDragging;
5  protected EntityAI m_HoveredItem;
6  protected bool m_SlotInfoShown;
7  protected EntityAI m_DraggedItem;
8  protected Icon m_DraggedIcon;
9  protected ref Widget m_TooltipWidget;
10  protected ref Widget m_TooltipSlotWidget;
11  protected ref Widget m_TooltipCategoryWidget;
12  protected ItemPreviewWidget m_ItemPreviewWidget;
13  protected Widget m_RootWidget;
14  protected ref map<string, bool> m_DefautOpenStates;
15  protected ref map<string, bool> m_DefautHeaderOpenStates;
16  protected int m_HandsDefaultOpenState;
17  protected ref Timer m_ToolTipTimer;
18  protected ref Timer m_TooltipSlotTimer;
19 
20  protected EntityAI m_SelectedItem;
21  protected Container m_SelectedContainer;
22  protected Widget m_SelectedWidget;
23  protected SlotsIcon m_SelectedIcon;
24  protected LayoutHolder m_SelectedBaseIcon;
25 
26  protected HandsPreview m_HandsPreview;
27 
28  protected bool m_ItemMicromanagmentMode;
29 
30  protected Widget m_LeftDropzone;
31  protected Widget m_CenterDropzone;
32  protected Widget m_RightDropzone;
33 
34  protected int m_TooltipPosX;
35  protected int m_TooltipPosY;
36  protected Widget m_TooltipSourceWidget; //stored here for tooltip position updates
37 
38  #ifndef PLATFORM_CONSOLE
39  protected const float TOOLTIP_DELAY = 0.25; // in seconds
40  #else
41  protected const float TOOLTIP_DELAY = 1.5; // in seconds
42  #endif
43 
44  void ItemManager( Widget root )
45  {
46  m_Instance = this;
47  m_RootWidget = root;
48  m_DefautOpenStates = new map<string, bool>;
49  m_DefautHeaderOpenStates = new map<string, bool>;
50  m_SlotInfoShown = false;
51 
52  #ifdef PLATFORM_CONSOLE
53  m_TooltipWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_xbox.layout", root );
54  m_TooltipSlotWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_slot_xbox.layout", root );
55  #else
56  m_TooltipWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip.layout", root );
57  m_TooltipSlotWidget = GetGame().GetWorkspace().CreateWidgets("gui/layouts/inventory_new/day_z_inventory_new_tooltip_slot.layout", root );
58  #endif
59  m_TooltipWidget.Show( false );
60  m_TooltipSlotWidget.Show( false );
61  }
62 
63  void SetItemMicromanagmentMode( bool item_micromanagment_mode )
64  {
65  m_ItemMicromanagmentMode = item_micromanagment_mode;
66  Inventory.GetInstance().UpdateConsoleToolbar();
67  }
68 
69  bool IsMicromanagmentMode()
70  {
71  return m_ItemMicromanagmentMode;
72  }
73 
74  HandsPreview GetHandsPreview()
75  {
76  return m_HandsPreview;
77  }
78 
79  void SetHandsPreview( HandsPreview hansd_preview )
80  {
81  m_HandsPreview = hansd_preview;
82  }
83 
84  EntityAI GetSelectedItem()
85  {
86  return m_SelectedItem;
87  }
88 
89  Container GetSelectedContainer()
90  {
91  return m_SelectedContainer;
92  }
93 
94  Widget GetSelectedWidget()
95  {
96  return m_SelectedWidget;
97  }
98 
99  SlotsIcon GetSelectedIcon()
100  {
101  return m_SelectedIcon;
102  }
103 
104  void SetSelectedItem( EntityAI selected_item, Container selected_container, Widget selected_widget, SlotsIcon selected_icon )
105  {
106  m_SelectedItem = selected_item;
107  m_SelectedContainer = selected_container;
108  m_SelectedWidget = selected_widget;
109  m_SelectedIcon = selected_icon;
110  }
111 
112  void SetSelectedItemEx( EntityAI selected_item, Container selected_container, LayoutHolder selected_icon )
113  {
114  SlotsIcon sIcon;
115  Icon icon;
116 
117  m_SelectedItem = selected_item;
118  m_SelectedContainer = selected_container;
119 
120  if (m_SelectedBaseIcon)
121  {
122  sIcon = SlotsIcon.Cast(m_SelectedBaseIcon);
123  icon = Icon.Cast(m_SelectedBaseIcon);
124  if (sIcon)
125  {
126  sIcon.GetMicromanagedPanel().Show(false);
127  }
128  else if (icon)
129  {
130  icon.GetMicromanagedPanel().Show(false);
131  }
132  }
133 
134  if (selected_icon)
135  {
136  sIcon = SlotsIcon.Cast(selected_icon);
137  icon = Icon.Cast(selected_icon);
138 
139  if (sIcon)
140  {
141  m_SelectedWidget = sIcon.GetCursorWidget();
142  sIcon.GetMicromanagedPanel().Show(true);
143  }
144  else if (icon)
145  {
146  m_SelectedWidget = icon.GetCursorWidget();
147  icon.GetMicromanagedPanel().Show(true);
148  }
149  }
150  else
151  {
152  m_SelectedWidget = null;
153  }
154  m_SelectedBaseIcon = selected_icon;
155  }
156 
157  void ClearDefaultOpenStates()
158  {
159  m_DefautOpenStates.Clear();
160  }
161 
162  void ClearDefaultHeaderOpenStates()
163  {
164  m_DefautHeaderOpenStates.Clear();
165  }
166 
167  void SetDefaultOpenState( string type, bool is_opened )
168  {
169  m_DefautOpenStates.Set( type, is_opened );
170  }
171 
172  void SetDefaultHeaderOpenState( string type, bool is_opened )
173  {
174  m_DefautHeaderOpenStates.Set( type, is_opened );
175  }
176 
177  void SetDefaultOpenStateHands( bool is_opened )
178  {
179  m_HandsDefaultOpenState = is_opened;
180  int hands_default_open_state = m_HandsDefaultOpenState; //from bool to int for easier parsing
181  GetGame().SetProfileString( "defaultOpenStateHands", hands_default_open_state.ToString() );
182  GetGame().SaveProfile();
183  }
184 
185  bool GetDefaultOpenStateHands( )
186  {
187  string value;
188  GetGame().GetProfileString( "defaultOpenStateHands", value );
189  m_HandsDefaultOpenState = value.ToInt();
190  return m_HandsDefaultOpenState;
191  }
192 
193  void SerializeDefaultHeaderOpenStates()
194  {
195  TStringArray serialized_types = new TStringArray;
196 
197  for ( int i = 0; i < m_DefautHeaderOpenStates.Count(); i++ )
198  {
199  int is_opened = m_DefautHeaderOpenStates.GetElement( i ); //from bool to int for easier parsing
200  serialized_types.Insert( m_DefautHeaderOpenStates.GetKey( i ) + "," + is_opened );
201  }
202 
203  if( serialized_types.Count() > 0 )
204  {
205  GetGame().SetProfileStringList( "defaultHeaderOpenStates", serialized_types );
206  }
207  GetGame().SaveProfile();
208  }
209 
210  void DeserializeDefaultHeaderOpenStates()
211  {
212  ClearDefaultHeaderOpenStates();
213 
214  TStringArray serialized_types = new TStringArray;
215  GetGame().GetProfileStringList( "defaultHeaderOpenStates", serialized_types );
216 
217  for( int i = 0; i < serialized_types.Count(); i++ )
218  {
219  TStringArray strs = new TStringArray;
220  serialized_types.Get( i ).Split( ",", strs );
221  bool is_opened = strs.Get( 1 ).ToInt();
222  SetDefaultHeaderOpenState( strs.Get( 0 ), is_opened );
223  }
224  }
225 
226  void SerializeDefaultOpenStates()
227  {
228  TStringArray serialized_types = new TStringArray;
229 
230  for ( int i = 0; i < m_DefautOpenStates.Count(); i++ )
231  {
232  int is_opened = m_DefautOpenStates.GetElement( i ); //from bool to int for easier parsing
233  serialized_types.Insert( m_DefautOpenStates.GetKey( i ) + "," + is_opened );
234  }
235 
236  if( serialized_types.Count() > 0 )
237  {
238  GetGame().SetProfileStringList( "defaultOpenStates", serialized_types );
239  }
240  GetGame().SaveProfile();
241  }
242 
243  void DeserializeDefaultOpenStates()
244  {
245  ClearDefaultOpenStates();
246 
247  TStringArray serialized_types = new TStringArray;
248  GetGame().GetProfileStringList( "defaultOpenStates", serialized_types );
249 
250  for( int i = 0; i < serialized_types.Count(); i++ )
251  {
252  TStringArray strs = new TStringArray;
253  serialized_types.Get( i ).Split( ",", strs );
254  bool is_opened = strs.Get( 1 ).ToInt();
255  SetDefaultOpenState( strs.Get( 0 ), is_opened );
256  }
257  }
258 
259  bool GetDefaultOpenState( string type )
260  {
261  if( m_DefautOpenStates.Contains( type ) )
262  {
263  return m_DefautOpenStates.Get( type );
264  }
265  else
266  {
267  return true;
268  }
269  }
270 
271  bool GetDefaultHeaderOpenState( string type )
272  {
273  if( m_DefautHeaderOpenStates.Contains( type ) )
274  {
275  return m_DefautHeaderOpenStates.Get( type );
276  }
277  else
278  {
279  return true;
280  }
281  }
282 
283  static ItemManager GetInstance()
284  {
285  return m_Instance;
286  }
287 
288  void HideDropzones()
289  {
290  GetRightDropzone().SetAlpha( 0 );
291  GetLeftDropzone().SetAlpha( 0 );
292  GetCenterDropzone().SetAlpha( 0 );
293  }
294 
295  void ShowSourceDropzone( EntityAI item )
296  {
297  EntityAI owner = item.GetHierarchyParent();
298  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
299 
300  if (item == player)
301  {
302  GetRightDropzone().SetAlpha(1);
303  }
304  else if (owner && owner != player)
305  {
306  ShowSourceDropzone(owner);
307  }
308  else
309  {
310  InventoryLocation inv_loc_src = new InventoryLocation;
311  item.GetInventory().GetCurrentInventoryLocation(inv_loc_src);
312  int loc_type = inv_loc_src.GetType();
313  HideDropzones();
314  if (loc_type == InventoryLocationType.GROUND)
315  {
316  GetLeftDropzone().SetAlpha(1);
317  }
318  else if (loc_type == InventoryLocationType.HANDS)
319  {
320  GetCenterDropzone().SetAlpha(1);
321  }
322  else
323  {
324  GetRightDropzone().SetAlpha(1);
325  }
326  }
327  }
328 
329  Widget GetLeftDropzone()
330  {
331  if (!m_LeftDropzone)
332  m_LeftDropzone = m_RootWidget.FindAnyWidget("LeftPanel").FindAnyWidget("DropzoneX");
333 
334  return m_LeftDropzone;
335  }
336 
337  Widget GetRightDropzone()
338  {
339  if( !m_RightDropzone )
340  m_RightDropzone = m_RootWidget.FindAnyWidget("RightPanel").FindAnyWidget("DropzoneX");
341  return m_RightDropzone;
342  }
343 
344  Widget GetCenterDropzone()
345  {
346  if( !m_CenterDropzone )
347  m_CenterDropzone = m_RootWidget.FindAnyWidget("HandsPanel").FindAnyWidget("DropzoneX");
348  return m_CenterDropzone;
349  }
350 
351  EntityAI GetHoveredItem()
352  {
353  return m_HoveredItem;
354  }
355 
356  void SetDraggedItem( EntityAI dragged_item )
357  {
358  m_DraggedItem = dragged_item;
359  }
360 
361  EntityAI GetDraggedItem()
362  {
363  return m_DraggedItem;
364  }
365 
366  void SetDraggedIcon( Icon dragged_icon )
367  {
368  m_DraggedIcon = dragged_icon;
369  }
370 
371  Icon GetDraggedIcon()
372  {
373  return m_DraggedIcon;
374  }
375 
376  void SetIsDragging( bool is_dragging )
377  {
378  m_IsDragging = is_dragging;
379  if( !is_dragging )
380  {
381  SetDraggedItem( null );
382  SetDraggedIcon( null );
383  }
384  }
385 
386  bool IsDragging()
387  {
388  return m_IsDragging;
389  }
390 
391  void HideTooltip()
392  {
393  m_TooltipWidget.Show( false );
394  m_HoveredItem = null;
395  delete m_ToolTipTimer;
396 
397  HideTooltipSlot();
398  }
399 
400  void HideTooltipSlot()
401  {
402  if ( m_SlotInfoShown )
403  {
404  m_TooltipSlotWidget.Show( false );
405  m_SlotInfoShown = false;
406  delete m_TooltipSlotTimer;
407  }
408  }
409 
410  static int GetItemHealthColor(int pHealthLevel)
411  {
412  switch (pHealthLevel)
413  {
414  case -1:
415  break;
416  case GameConstants.STATE_PRISTINE:
417  return Colors.COLOR_PRISTINE;
418  case GameConstants.STATE_WORN:
419  return Colors.COLOR_WORN;
420  case GameConstants.STATE_DAMAGED:
421  return Colors.COLOR_DAMAGED;
422  case GameConstants.STATE_BADLY_DAMAGED:
423  return Colors.COLOR_BADLY_DAMAGED;
424  case GameConstants.STATE_RUINED:
425  return Colors.COLOR_RUINED;
426  }
427 
428  return 0x00FFFFFF;
429  }
430 
431  static int GetItemHealthColor(EntityAI item, string zone = "")
432  {
433  if (item)
434  {
435  switch (item.GetHealthLevel(zone))
436  {
437  case -1:
438  break;
439  case GameConstants.STATE_PRISTINE:
440  return Colors.COLOR_PRISTINE;
441  case GameConstants.STATE_WORN:
442  return Colors.COLOR_WORN;
443  case GameConstants.STATE_DAMAGED:
444  return Colors.COLOR_DAMAGED;
445  case GameConstants.STATE_BADLY_DAMAGED:
446  return Colors.COLOR_BADLY_DAMAGED;
447  case GameConstants.STATE_RUINED:
448  return Colors.COLOR_RUINED;
449  }
450  }
451 
452  return 0x00FFFFFF;
453  }
454 
455  static int ColorFromFloat( float fraction )
456  {
457  if( fraction > 1 || fraction < 0 )
458  return 0x00FFFFFF;
459  else if( fraction > 0.80 )
460  return Colors.COLOR_PRISTINE;
461  else if( fraction > 0.6 )
462  return Colors.COLOR_WORN;
463  else if( fraction > 0.4 )
464  return Colors.COLOR_DAMAGED;
465  else if( fraction > 0.2 )
466  return Colors.COLOR_BADLY_DAMAGED;
467  else
468  return Colors.COLOR_RUINED;
469  }
470 
471  void SetTemperature(EntityAI item, Widget item_w)
472  {
473  if ( item_w )
474  {
475  if ( true/*show_temperature */ )
476  {
477  if ( item && item.IsInherited( ItemBase ) )
478  {
479  int color = ColorManager.GetInstance().GetItemColor( ItemBase.Cast( item ) ); // !!!!!
480  if ( color )
481  {
482  string name = item_w.GetName();
483  name.Replace("Render", "Temperature");
484  Widget temperature_widget = item_w.GetParent().FindAnyWidget( name );
485  if ( color != -1 )
486  {
487  temperature_widget.Show( true );
488  temperature_widget.SetColor( color );
489  }
490  else
491  {
492  temperature_widget.Show( false );
493  }
494 
495  temperature_widget.SetAlpha( 0.3 );
496  }
497  }
498  }
499  }
500  }
501 
502  void SetIconTemperature(EntityAI item, Widget item_w)
503  {
504  if ( item_w )
505  {
506  if ( item && item.IsInherited( ItemBase ) )
507  {
508  int color = ColorManager.GetInstance().GetItemColor( ItemBase.Cast( item ) );
509 
510  if ( color )
511  {
512  Widget color_widget = item_w.FindAnyWidget( "Color" );
513  if( color != -1 )
514  {
515  color_widget.SetColor( color );
516  }
517  else
518  {
519  color_widget.SetColor( ColorManager.BASE_COLOR );
520  }
521  }
522  }
523  }
524  }
525 
526  void PrepareTooltip(EntityAI item, int x = 0, int y = 0)
527  {
528  if( IsDragging() || !item )
529  {
530  return;
531  }
532 
533  if ( item.IsInherited( InventoryItem ) )
534  {
535  HideTooltip();
536 
537  m_HoveredItem = item;
538  InspectMenuNew.UpdateItemInfo( m_TooltipWidget, item );
539 
540  int screen_w, screen_h;
541  float w, h;
542  GetScreenSize(screen_w, screen_h);
543  m_TooltipWidget.GetScreenSize(w,h);
544 
545  if (x == -1)//set by icon focusing
546  {
547  x = screen_w/2 - w/2;
548  float x1,y1;
549  m_RootWidget.FindAnyWidget("InventoryFrameWidget").GetScreenPos(x1,y1); //allign to the same height
550  y = y1;
551  }
552  else if (x == 0 && y == 0 && GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
553  {
554  GetMousePos(x,y);
555  }
556 
557  //minimal edge distance adjustments..
558  screen_w -= 10;
559  screen_h -= 10;
560 
561  int rightEdge = x + w;
562  if (rightEdge > screen_w)
563  {
564  x = screen_w - w;
565  }
566 
567  int bottomEdge = y + h;
568  if (bottomEdge > screen_h)
569  {
570  y = screen_h - h;
571  }
572 
573  m_TooltipWidget.SetPos(x, y);
574 
575  m_ToolTipTimer = new Timer();
576  m_ToolTipTimer.Run( TOOLTIP_DELAY, this, "ShowTooltip" );
577 
578  Widget preview_frame = m_TooltipWidget.FindAnyWidget("ItemFrameWidget");
579  if (preview_frame)
580  {
581  m_ItemPreviewWidget = ItemPreviewWidget.Cast( preview_frame );
582  m_ItemPreviewWidget.SetItem(item);
583  m_ItemPreviewWidget.SetView( item.GetViewIndex() );
584  }
585  }
586  }
587 
589  void PrepareSlotsTooltip(string name, string desc, int x = 0, int y = 0)
590  {
591  InspectMenuNew.UpdateSlotInfo( m_TooltipSlotWidget, name, desc );
592 
593  HideTooltip();
594 
595  if (name != "")
596  {
597  m_SlotInfoShown = true;
598  //CalculateTooltipSlotPosition(x,y);
599  m_TooltipSlotTimer = new Timer();
600  m_TooltipSlotTimer.Run( TOOLTIP_DELAY, this, "ShowTooltipSlot" );
601  }
602  }
603 
604  void CalculateTooltipSlotPosition(int x = 0, int y = 0)
605  {
606  int screen_w, screen_h;
607  float w, h;
608  GetScreenSize(screen_w, screen_h);
609  //m_TooltipSlotWidget.GetScreenSize(w,h);
610  m_TooltipSlotWidget.GetSize(w,h);
611  int slot_normal_w = SlotsIcon.GetNormalWidth();
612  int slot_normal_h = SlotsIcon.GetNormalHeight();
613  //minimal edge distance adjustments..
614  screen_w -= 10;
615  screen_h -= 10;
616 
617 #ifndef PLATFORM_CONSOLE
618  x += 5;
619  y += slot_normal_h + 5;
620 #else
621  x += 5;
622  y += 15;
623 #endif
624  Widget scrollerWidget = m_TooltipSourceWidget.GetParent();
625  while (scrollerWidget)
626  {
627  if (ScrollWidget.Cast(scrollerWidget))
628  {
629  break;
630  }
631  else
632  {
633  scrollerWidget = scrollerWidget.GetParent();
634  }
635  }
636 
637  int rightEdge = x + w;
638  if (rightEdge > screen_w)
639  {
640  x = screen_w - w;
641  }
642 
643  int bottomEdge = y + h;
644  if (scrollerWidget)
645  {
646  float scrollerX, scrollerY, scrollerSizeX, scrollerSizeY;
647  scrollerWidget.GetScreenPos(scrollerX,scrollerY);
648  scrollerWidget.GetScreenSize(scrollerSizeX,scrollerSizeY);
649 
650  int scroller_bottom = scrollerY + scrollerSizeY;
651  if (bottomEdge > scroller_bottom)
652  {
653  y = scroller_bottom - slot_normal_h;
654  bottomEdge = y + h;
655  }
656  }
657  /*else
658  {
659  ErrorEx("No scroller widget! | m_TooltipSourceWidget: " + m_TooltipSourceWidget);
660  }*/
661 
662  if (bottomEdge > screen_h) //should mostly never proc now
663  {
664  y = screen_h - h;
665  }
666 
667  m_TooltipPosX = x;
668  m_TooltipPosY = y;
669  }
670 
671  void UpdateTooltipSlotPosition()
672  {
673  float x, y;
674  m_TooltipSourceWidget.GetScreenPos(x,y);
675  CalculateTooltipSlotPosition(x,y);
676  }
677 
678  void SetTooltipWidget(Widget w)
679  {
680  m_TooltipSourceWidget = w;
681  }
682 
683  bool EvaluateContainerDragabilityDefault(EntityAI entity)
684  {
685  if ( !ItemBase.Cast( entity ) )
686  return false;
687 
688  bool draggable;
689  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
690  draggable = !player.GetInventory().HasInventoryReservation( entity, null ) && !player.IsItemsToDelete();
691  draggable = draggable && entity.CanPutIntoHands( GetGame().GetPlayer() );
692  draggable = draggable && entity.GetInventory().CanRemoveEntity();
693 
694  return draggable;
695  }
696 
697  void SetWidgetDraggable( Widget w, bool draggable )
698  {
699  if (w)
700  {
701  if ( draggable )
702  w.SetFlags( WidgetFlags.DRAGGABLE );
703  else
704  w.ClearFlags( WidgetFlags.DRAGGABLE );
705  }
706  }
707 
708  void ShowTooltip()
709  {
710  if( m_ItemPreviewWidget )
711  {
712  m_TooltipWidget.Show( true );
713  }
714  }
715 
716  void ShowTooltipSlot()
717  {
718  UpdateTooltipSlotPosition();
719  m_TooltipSlotWidget.SetPos(m_TooltipPosX, m_TooltipPosY);
720  m_TooltipSlotWidget.Show( true );
721  }
722 
723  static int GetChosenCombinationFlag( EntityAI selectedEntity, EntityAI targetEntity, int relevantFlags, out InventoryLocation dst = null)
724  {
725  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
726 
727  if (!selectedEntity || !targetEntity)
728  return InventoryCombinationFlags.NONE;
729 
730  ItemBase selectedItem = ItemBase.Cast(selectedEntity);
731  ItemBase targetItem = ItemBase.Cast(targetEntity);
732 
733  //EntityAI itemInHands = m_player.GetHumanInventory().GetEntityInHands();
734  ActionManagerClient amc = ActionManagerClient.Cast(player.GetActionManager());
735 
736  if (relevantFlags & InventoryCombinationFlags.PERFORM_ACTION)
737  {
738  if (amc.CanPerformActionFromInventory(targetItem, selectedItem))
739  return InventoryCombinationFlags.PERFORM_ACTION;
740  }
741 
742  if (relevantFlags & InventoryCombinationFlags.SET_ACTION)
743  {
744  if (amc.CanSetActionFromInventory(targetItem, selectedItem))
745  return InventoryCombinationFlags.SET_ACTION;
746  }
747 
748  if (relevantFlags & InventoryCombinationFlags.COMBINE_QUANTITY2)
749  {
750  if (targetEntity.CanBeCombined(selectedEntity))
751  {
752  return InventoryCombinationFlags.COMBINE_QUANTITY2;
753  }
754  }
755 
756  if (relevantFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT)
757  {
758  if (targetEntity.GetInventory().CanAddAttachment(selectedEntity))
759  {
760  return InventoryCombinationFlags.ADD_AS_ATTACHMENT;
761  }
762  }
763 
764  if (relevantFlags & InventoryCombinationFlags.ADD_AS_CARGO)
765  {
766  if (!targetEntity.GetInventory().HasEntityInInventory(selectedEntity) && targetEntity.GetInventory().CanAddEntityInCargo( selectedEntity, selectedEntity.GetInventory().GetFlipCargo() ))
767  {
768  return InventoryCombinationFlags.ADD_AS_CARGO;
769  }
770  }
771 
772  if (relevantFlags & InventoryCombinationFlags.SWAP_MAGAZINE)
773  {
774  Magazine mag = Magazine.Cast(targetEntity);
775  Weapon_Base wpn = Weapon_Base.Cast(targetEntity.GetHierarchyParent());
776  if (wpn && mag)
777  {
778  if (player.GetWeaponManager().CanSwapMagazine(wpn, Magazine.Cast(selectedEntity)))
779  {
780  return InventoryCombinationFlags.SWAP_MAGAZINE;
781  }
782  }
783  }
784 
785  if (relevantFlags & InventoryCombinationFlags.SWAP)
786  {
787  if (GameInventory.CanSwapEntitiesEx(selectedEntity, targetEntity))
788  {
789  return InventoryCombinationFlags.SWAP;
790  }
791  }
792 
793  if (relevantFlags & InventoryCombinationFlags.FSWAP)
794  {
795  if (GameInventory.CanForceSwapEntitiesEx(selectedEntity, null, targetEntity, dst))
796  {
797  return InventoryCombinationFlags.FSWAP;
798  }
799  }
800 
801  return InventoryCombinationFlags.NONE;
802  }
803 
804  static int GetCombinationFlags( EntityAI entity1, EntityAI entity2 )
805  {
806  int flags = 0;
808 
809  if (!entity1 || !entity2)
810  return flags;
811 
812  if (entity1.IsInherited( ItemBase ) && entity2.IsInherited( ItemBase ))
813  {
814  ItemBase ent1 = ItemBase.Cast( entity1 );
815  if (ent1.CanBeCombined( ItemBase.Cast( entity2 ) )) flags = flags | InventoryCombinationFlags.COMBINE_QUANTITY2;
816  }
817 
818  if (entity1.GetInventory().CanAddAttachment( entity2 ))
819  {
820  if (!entity1.IsInherited( ZombieBase ) && !entity1.IsInherited( Car ) && !entity2.IsInherited( ZombieBase ) && !entity2.IsInherited( Car ))
821  {
822  flags = flags | InventoryCombinationFlags.ADD_AS_ATTACHMENT;
823  }
824  }
825  if (!entity1.GetInventory().HasEntityInInventory(entity2) && entity1.GetInventory().CanAddEntityInCargo( entity2, entity2.GetInventory().GetFlipCargo() )) flags = flags | InventoryCombinationFlags.ADD_AS_CARGO;
826 
827  if (entity1 == m_player.GetHumanInventory().GetEntityInHands() || entity2 == m_player.GetHumanInventory().GetEntityInHands())
828  {
830  Class.CastTo(amc, m_player.GetActionManager());
831  if (entity1 == m_player.GetHumanInventory().GetEntityInHands())
832  {
833  if (amc.CanPerformActionFromInventory( ItemBase.Cast(entity1), ItemBase.Cast(entity2) ))
834  {
835  flags = flags | InventoryCombinationFlags.PERFORM_ACTION;
836  }
837  else if (amc.CanSetActionFromInventory( ItemBase.Cast(entity1), ItemBase.Cast(entity2) ))
838  {
839  flags = flags | InventoryCombinationFlags.SET_ACTION;
840  }
841  }
842  else
843  {
844  if (amc.CanPerformActionFromInventory( ItemBase.Cast(entity2), ItemBase.Cast(entity1) ))
845  {
846  flags = flags | InventoryCombinationFlags.PERFORM_ACTION;
847  }
848  else if (amc.CanSetActionFromInventory( ItemBase.Cast(entity2), ItemBase.Cast(entity1) ))
849  {
850  flags = flags | InventoryCombinationFlags.SET_ACTION;
851  }
852  }
853  }
854  return flags;
855  }
856 
857  static int GetRecipeCount(bool recipe_anywhere, EntityAI entity1, EntityAI entity2)
858  {
859  PluginRecipesManager plugin_recipes_manager = PluginRecipesManager.Cast(GetPlugin( PluginRecipesManager ));
860  return plugin_recipes_manager.GetValidRecipes( ItemBase.Cast( entity1 ), ItemBase.Cast( entity2 ), NULL, PlayerBase.Cast( GetGame().GetPlayer() ) );
861  }
862 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
m_player
DayZPlayer m_player
Definition: randomgeneratorsyncmanager.c:15
m_RootWidget
ref Widget m_RootWidget[MAX_SIMULTANIOUS_PLAYERS]
Definition: pluginremoteplayerdebugclient.c:14
TStringArray
array< string > TStringArray
Definition: enscript.c:685
GetMousePos
proto void GetMousePos(out int x, out int y)
GetScreenSize
proto void GetScreenSize(out int x, out int y)
m_ItemPreviewWidget
ItemPreviewWidget m_ItemPreviewWidget
Definition: pluginitemdiagnostic.c:70
y
Icon y
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
HandsPreview
Definition: handspreview.c:1
InventoryItem
Definition: itembase.c:13
Colors
Definition: colors.c:3
GetPlugin
PluginBase GetPlugin(typename plugin_type)
Definition: pluginmanager.c:316
PlayerBase
Definition: playerbaseclient.c:1
map
map
Definition: controlsxboxnew.c:3
ColorManager
Definition: colormanager.c:1
InventoryLocationType
InventoryLocationType
types of Inventory Location
Definition: inventorylocation.c:3
Container
Definition: cargocontainer.c:2
SlotsIcon
Definition: slotsicon.c:1
ItemManager
Definition: itemmanager.c:1
ActionManagerClient
Definition: actionmanagerclient.c:4
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
GameConstants
Definition: constants.c:612
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
Timer
Definition: dayzplayerimplement.c:62
InventoryCombinationFlags
Definition: inventorycombinationflags.c:1
Widget
Definition: enwidgets.c:189
GetInput
ActionInput GetInput()
Definition: actionbase.c:1066
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
m_IsDragging
bool m_IsDragging
Definition: pluginitemdiagnostic.c:57
ZombieBase
Definition: zombiefemalebase.c:1
EntityAI
Definition: building.c:5
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78