Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
icon.c
Go to the documentation of this file.
2 {
3  protected int m_SizeX;
4  protected int m_SizeY;
5  protected int m_PosX;
6  protected int m_PosY;
7 
8  protected EntityAI m_Lock;
9  protected bool m_IsWeapon = false;
10  protected bool m_IsMagazine = false;
11  protected bool m_HasTemperature = false;
12  protected bool m_HasQuantity = false;
13  protected float m_CurrQuantity = -1;
14 
15  protected EntityAI m_Obj;
16  protected ItemBase m_Item;
17  protected bool m_HandsIcon;
18  protected int m_CargoPos;
19  protected bool m_IsDragged;
20  protected bool m_PreviousFlipOrientation;
21 
22  const int NUMBER_OF_TIMERS = 2;
23 
24  protected ItemPreviewWidget m_ItemPreview;
25 
26  protected Widget m_ColorWidget;
27  protected Widget m_SelectedPanel;
28  protected Widget m_MicromanagedPanel;
29  protected Widget m_CursorWidget;
30 
31  protected Widget m_QuantityPanel;
32  protected TextWidget m_QuantityItem;
33  protected ProgressBarWidget m_QuantityProgress;
34  protected Widget m_QuantityStack;
35 
36  protected Widget m_ItemSizePanel;
37  protected TextWidget m_ItemSizeWidget;
38 
39  protected ref array<ImageWidget>m_AmmoIcons;
40  protected ImageWidget m_AmmoTypeIcon;
41 
42  void Icon( LayoutHolder parent, bool hands_icon = false )
43  {
44  m_HandsIcon = hands_icon;
45  ItemManager.GetInstance().SetSelectedItemEx(null, null, null);
46 
47  m_ItemPreview = ItemPreviewWidget.Cast( GetMainWidget().FindAnyWidget( "Render" ));
48 
49  m_ColorWidget = GetMainWidget().FindAnyWidget( "Color" );
50  m_SelectedPanel = GetMainWidget().FindAnyWidget( "Selected" );
51  m_MicromanagedPanel = GetMainWidget().FindAnyWidget( "Micromanaged" );
52  m_CursorWidget = GetMainWidget().FindAnyWidget( "Cursor" );
53 
54  m_QuantityPanel = GetMainWidget().FindAnyWidget( "QuantityPanel" );
55  m_QuantityItem = TextWidget.Cast( GetMainWidget().FindAnyWidget( "Quantity" ) );
56  m_QuantityProgress = ProgressBarWidget.Cast( GetMainWidget().FindAnyWidget( "QuantityBar" ) );
57  m_QuantityStack = GetMainWidget().FindAnyWidget( "QuantityStackPanel" );
58 
59  m_ItemSizePanel = GetMainWidget().FindAnyWidget( "ItemSizePanel" );
60  m_ItemSizeWidget = TextWidget.Cast( GetMainWidget().FindAnyWidget( "ItemSize" ) );
61 
62  m_AmmoTypeIcon = ImageWidget.Cast( GetMainWidget().FindAnyWidget( "AmmoTypeIcon" ) );
63  SetActive( false );
64  }
65 
66  void ~Icon()
67  {
68  if (m_Obj)
69  {
70  m_Obj.GetOnItemFlipped().Remove(UpdateFlip);
71  m_Obj.GetOnViewIndexChanged().Remove(SetItemPreview);
72  }
73 
74  if (m_IsDragged)
75  {
76  RevertToOriginalFlip();
77  ItemManager.GetInstance().HideDropzones();
78  ItemManager.GetInstance().SetIsDragging(false);
79  m_IsDragged = false;
80  }
81  }
82 
83  Widget GetSelectedWidget()
84  {
85  return m_SelectedPanel;
86  }
87 
88  Widget GetCursorWidget()
89  {
90  return m_CursorWidget;
91  }
92 
93  Widget GetMicromanagedPanel()
94  {
95  return m_MicromanagedPanel;
96  }
97 
98  bool IsDragged()
99  {
100  return m_IsDragged;
101  }
102 
103  override void SetActive( bool active )
104  {
105  super.SetActive(active);
106  if (active && GetObject())
107  {
108  float x, y;
109  GetMainWidget().GetScreenPos(x, y);
110  PrepareOwnedTooltip(EntityAI.Cast( GetObject() ), -1, y);
111  }
112 
113  m_SelectedPanel.Show(active);
114  }
115 
116  override void SetParentWidget()
117  {
118  #ifndef PLATFORM_CONSOLE
119  if (m_Parent.IsInherited(HandsPreview))
120  {
121  super.SetParentWidget();
122  }
123  else
124  {
125  if (m_Parent != null)
126  {
127  CargoContainer gridContainer = CargoContainer.Cast(m_Parent);
128  if (gridContainer)
129  {
130  m_ParentWidget = gridContainer.GetMainWidget();
131  }
132  }
133  }
134  #else
135  super.SetParentWidget();
136  #endif
137  }
138 
139  int GetRelevantInventoryAction(int relevantActions)
140  {
141  return 0;
142 
143  }
144 
145  void RefreshQuickbar()
146  {
147  InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu(MENU_INVENTORY));
148  HideOwnedTooltip();
149  if (menu)
150  {
151  menu.RefreshQuickbar();
152  }
153  }
154 
155  void DoubleClick(Widget w, int x, int y, int button)
156  {
157  if (button == MouseState.LEFT && !g_Game.IsLeftCtrlDown())
158  {
159  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
160  if (controlledPlayer.GetInventory().HasInventoryReservation(m_Obj, null) || controlledPlayer.GetInventory().IsInventoryLocked() || controlledPlayer.IsItemsToDelete())
161  return;
162 
163  ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
164  if (!targetIpw)
165  {
166  string name = w.GetName();
167  name.Replace("PanelWidget", "Render");
168  targetIpw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
169  }
170 
171  if (!targetIpw)
172  targetIpw = ItemPreviewWidget.Cast(w);
173 
174  EntityAI targetEntity = targetIpw.GetItem();
175  if (targetIpw)
176  {
177  if (!targetEntity.GetInventory().CanRemoveEntity())
178  return;
179 
180  if (m_HandsIcon)
181  {
182  if (controlledPlayer.GetHumanInventory().CanRemoveEntityInHands())
183  controlledPlayer.PredictiveMoveItemFromHandsToInventory();
184 
185  RefreshQuickbar();
186 
187  return;
188  }
189 
190  EntityAI entityInHands = controlledPlayer.GetHumanInventory().GetEntityInHands();
191  EntityAI entityRootParent = targetEntity.GetHierarchyRoot();
192 
193  if (controlledPlayer.GetInventory().HasEntityInInventory(targetEntity) && controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
194  {
195  controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
196  }
197  else if (entityInHands && entityRootParent == controlledPlayer)
198  {
199  InventoryLocation inventoryLocation = new InventoryLocation();
200  int index = controlledPlayer.GetHumanInventory().FindUserReservedLocationIndex(entityInHands);
201  if (index >= 0)
202  controlledPlayer.GetHumanInventory().GetUserReservedLocation(index, inventoryLocation);
203 
204  if (controlledPlayer.GetInventory().CanForceSwapEntitiesEx(targetEntity, null, entityInHands, inventoryLocation))
205  {
206  controlledPlayer.PredictiveForceSwapEntities(targetEntity, entityInHands, inventoryLocation);
207  }
208  else if (controlledPlayer.GetInventory().CanSwapEntitiesEx(targetEntity, entityInHands ))
209  {
210  controlledPlayer.PredictiveSwapEntities(targetEntity, entityInHands);
211  }
212  else
213  {
214  controlledPlayer.GetInventory().FindFreeLocationFor(targetEntity, FindInventoryLocationType.ANY, inventoryLocation);
215  if (inventoryLocation.IsValid() && controlledPlayer.GetInventory().LocationCanAddEntity(inventoryLocation))
216  SplitItemUtils.TakeOrSplitToInventoryLocation(controlledPlayer, inventoryLocation);
217  }
218  }
219  else
220  {
221  bool found = false;
222  if (targetEntity.GetInventory().CanRemoveEntity())
223  {
225  found = controlledPlayer.GetInventory().FindFreeLocationFor(targetEntity, FindInventoryLocationType.ANY, i2);
226  if (found)
227  {
228  if (i2.GetType() == FindInventoryLocationType.ATTACHMENT)
229  {
230  if (i2.GetParent() != controlledPlayer)
231  found = false;
232  }
233  }
234  }
235 
236  if (found)
237  {
238  if (controlledPlayer.GetHumanInventory().CanAddEntityToInventory(targetEntity))
239  controlledPlayer.PredictiveTakeEntityToInventory(FindInventoryLocationType.ANY, targetEntity);
240  }
241  else
242  {
243  if (controlledPlayer.GetHumanInventory().CanAddEntityInHands(targetEntity))
244  controlledPlayer.PredictiveTakeEntityToHands(targetEntity);
245  }
246  }
247 
248  RefreshQuickbar();
249  }
250  }
251  }
252 
253  void DraggingOverSwap( Widget w, int x, int y, Widget receiver )
254  {
255  if (w == null)
256  {
257  return;
258  }
259 
260  string name = w.GetName();
261  name.Replace("PanelWidget", "Render");
262 
263  ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(receiver.FindAnyWidget( "Render" ));
264  if (m_HandsIcon)
265  {
266  targetIpw = ItemPreviewWidget.Cast(receiver.GetParent().FindAnyWidget( "Render" ));
267  }
268 
269  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
270  if (selectedIpw == null)
271  {
272  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
273  }
274 
275  if (selectedIpw == null)
276  {
277  return;
278  }
279 
280  InventoryItem targetEntity = InventoryItem.Cast(targetIpw.GetItem());
281  InventoryItem selectedEntity = InventoryItem.Cast(selectedIpw.GetItem());
282  if (!selectedEntity || !targetEntity)
283  {
284  return;
285  }
286 
288  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
289  int index = player.GetHumanInventory().FindUserReservedLocationIndex(m_Item);
290 
291  if (index >= 0)
292  {
293  player.GetHumanInventory().GetUserReservedLocation(index, il);
294 
295  if (GameInventory.CanForceSwapEntitiesEx(selectedEntity, null, targetEntity, il))
296  {
297  ColorManager.GetInstance().SetColor(w, ColorManager.FSWAP_COLOR);
298  ItemManager.GetInstance().HideDropzones();
299  ItemManager.GetInstance().ShowSourceDropzone(il.GetParent());
300  return;
301  }
302  }
303  static int testedFlags = InventoryCombinationFlags.SWAP | InventoryCombinationFlags.FSWAP;
304 
305  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags, il);
306  UpdateFrameColor(selectedEntity, targetEntity, chosenInventoryAction, w, il);
307  }
308 
309  void DraggingOverCombine(Widget w, int x, int y, Widget receiver)
310  {
311  if (w == null)
312  {
313  return;
314  }
315 
316  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
317  if (!selectedIpw)
318  {
319  string name = w.GetName();
320  name.Replace("PanelWidget", "Render");
321  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget(name));
322  }
323 
324  if (!selectedIpw)
325  {
326  selectedIpw = ItemPreviewWidget.Cast(w);
327  }
328 
329  if (!selectedIpw.GetItem())
330  {
331  return;
332  }
333  EntityAI selectedEntity = selectedIpw.GetItem();
334  EntityAI targetEntity = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
335 
336  static int testedFlags = InventoryCombinationFlags.SET_ACTION | InventoryCombinationFlags.PERFORM_ACTION | InventoryCombinationFlags.COMBINE_QUANTITY2 | InventoryCombinationFlags.ADD_AS_CARGO | InventoryCombinationFlags.ADD_AS_ATTACHMENT;
337 
338  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags);
339  UpdateFrameColor(selectedEntity, targetEntity, chosenInventoryAction, w);
340  }
341 
342  bool MouseEnter(Widget w, int x, int y)
343  {
344  if (!m_IsDragged)
345  {
346  PrepareOwnedTooltip(m_Obj, x, y);
347  m_CursorWidget.Show(true);
348  }
349 
350  return true;
351  }
352 
353  bool MouseLeave( Widget w, Widget s, int x, int y)
354  {
355  HideOwnedTooltip();
356  if (!m_IsDragged)
357  {
358  m_CursorWidget.Show(false);
359  }
360  return true;
361  }
362 
363  void DraggingOver( Widget w, int x, int y, Widget receiver )
364  {
365  ItemManager.GetInstance().HideDropzones();
366 
367  if (w == null)
368  {
369  return;
370  }
371  string name = w.GetName();
372  name.Replace("PanelWidget", "Render");
373 
374  ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(receiver.FindAnyWidget( "Render" ));
375  if (m_HandsIcon)
376  {
377  targetIpw = ItemPreviewWidget.Cast(receiver.GetParent().FindAnyWidget( "Render" ));
378  }
379 
380  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( name ));
381  if (selectedIpw == null)
382  {
383  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( "Render" ));
384  }
385  if (selectedIpw == null)
386  {
387  return;
388  }
389 
390  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
391  InventoryItem targetEntity = InventoryItem.Cast(targetIpw.GetItem());
392  InventoryItem selectedEntity = InventoryItem.Cast(selectedIpw.GetItem());
393  InventoryLocation ilDst;
394  if (!targetEntity || !selectedEntity)
395  {
396  return;
397  }
398 
399  if (m_Lock)
400  {
401  if (targetEntity == selectedEntity)
402  {
403  ColorManager.GetInstance().SetColor( w, ColorManager.SWAP_COLOR );
404  ItemManager.GetInstance().GetRightDropzone().SetAlpha( 1 );
405  }
406  else
407  {
408  CargoContainer parentContainer = CargoContainer.Cast(m_Parent);
409 
410  float parentX;
411  float parentY;
412 
413  parentContainer.GetRootWidget().GetScreenPos(parentX, parentY);
414 
415  float iconSize = parentContainer.GetIconSize();
416  float spaceSize = parentContainer.GetSpaceSize();
417 
418  int PosX = (x - parentX) / (iconSize + spaceSize);
419  int PosY = (y - parentY) / (iconSize + spaceSize);
420 
421  EntityAI parent = m_Lock;
422  CargoBase targetCargo = parent.GetInventory().GetCargo();
423 
424  ilDst = new InventoryLocation();
425  ilDst.SetCargoAuto(targetCargo, selectedEntity, PosY, PosX, selectedEntity.GetInventory().GetFlipCargo());
426 
427  if (parent.GetInventory().LocationCanAddEntity(ilDst))
428  {
429  ColorManager.GetInstance().SetColor(w, ColorManager.GREEN_COLOR);
430  ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
431  }
432  else
433  {
434  ColorManager.GetInstance().SetColor(w, ColorManager.RED_COLOR);
435  ItemManager.GetInstance().ShowSourceDropzone(selectedEntity);
436  }
437  }
438  }
439  else
440  {
441  static int testedFlags = InventoryCombinationFlags.COMBINE_QUANTITY2 | InventoryCombinationFlags.ADD_AS_CARGO | InventoryCombinationFlags.ADD_AS_ATTACHMENT | InventoryCombinationFlags.SWAP | InventoryCombinationFlags.FSWAP | InventoryCombinationFlags.SWAP_MAGAZINE;
442 
443  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags, ilDst);
444  UpdateFrameColor(selectedEntity, targetEntity, chosenInventoryAction, w, ilDst);
445  }
446  }
447 
448  void OnPerformCombination( int combinationFlags )
449  {
450  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
451  if (m_am_entity1 == null || m_am_entity2 == null) return;
452 
453  if (combinationFlags == InventoryCombinationFlags.NONE) return;
454 
455  Weapon_Base wpn;
456  Magazine mag;
457 
458  if (combinationFlags & InventoryCombinationFlags.PERFORM_ACTION)
459  {
461  Class.CastTo(amc, player.GetActionManager());
462 
463  if (m_am_entity1 == player.GetHumanInventory().GetEntityInHands())
464  {
465  amc.PerformActionFromInventory(ItemBase.Cast( m_am_entity1 ),ItemBase.Cast( m_am_entity2 ));
466  }
467  else
468  {
469  amc.PerformActionFromInventory(ItemBase.Cast( m_am_entity2 ),ItemBase.Cast( m_am_entity1 ));
470  }
471  }
472  else if (combinationFlags & InventoryCombinationFlags.SET_ACTION)
473  {
474  ActionManagerClient amc2;
475  Class.CastTo(amc2, player.GetActionManager());
476 
477  if (m_am_entity1 == player.GetHumanInventory().GetEntityInHands())
478  {
479  amc2.SetActionFromInventory(ItemBase.Cast( m_am_entity1 ), ItemBase.Cast( m_am_entity2 ));
480  }
481  else
482  {
483  amc2.SetActionFromInventory(ItemBase.Cast( m_am_entity2 ), ItemBase.Cast( m_am_entity1 ));
484  }
485  }
486  else if (combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2)
487  {
488  ItemBase entity = ItemBase.Cast(m_am_entity1);
489  entity.CombineItemsClient(ItemBase.Cast( m_am_entity2 ));
490  }
491  else if (combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT)
492  {
493  float stackable = m_am_entity2.GetTargetQuantityMax(-1);
494 
495  if (stackable == 0 || stackable >= m_am_entity2.GetQuantity())
496  {
497  player.PredictiveTakeEntityToTargetAttachment(m_am_entity1, m_am_entity2);
498  }
499  else
500  {
502  m_am_entity1.GetInventory().FindFreeLocationFor(m_am_entity2, FindInventoryLocationType.ATTACHMENT, il);
503  ItemBase.Cast(m_am_entity2).SplitIntoStackMaxToInventoryLocationClient(il);
504  }
505  }
506  else if (combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO)
507  {
508  SplitItemUtils.TakeOrSplitToInventory(player, m_am_entity1, m_am_entity2);
509  }
510  }
511 
512  bool PerformCombination(EntityAI selectedEntity, EntityAI targetEntity, int combinationFlag, InventoryLocation ilSwapDst = null)
513  {
514  PlayerBase player = PlayerBase.Cast(GetGame().GetPlayer());
516 
517  switch (combinationFlag)
518  {
519  case InventoryCombinationFlags.ADD_AS_ATTACHMENT:
520  float stackable = targetEntity.GetTargetQuantityMax(-1);
521 
522  if (stackable == 0 || stackable >= targetEntity.GetQuantity())
523  {
524  return player.PredictiveTakeEntityToTargetAttachment(targetEntity, selectedEntity);
525  }
526  else
527  {
529  targetEntity.GetInventory().FindFreeLocationFor(selectedEntity, FindInventoryLocationType.ATTACHMENT, il);
530  ItemBase.Cast(selectedEntity).SplitIntoStackMaxToInventoryLocationClient(il);
531  return true;
532  }
533  break;
534  case InventoryCombinationFlags.ADD_AS_CARGO:
535  SplitItemUtils.TakeOrSplitToInventory(player, targetEntity, selectedEntity);
536  return true;
537  case InventoryCombinationFlags.COMBINE_QUANTITY2:
538  targetEntity.CombineItemsClient(selectedEntity);
539  return true;
540  case InventoryCombinationFlags.SET_ACTION:
541  Class.CastTo(amc, player.GetActionManager());
542  if (targetEntity == player.GetHumanInventory().GetEntityInHands())
543  {
544  amc.SetActionFromInventory(ItemBase.Cast(targetEntity), ItemBase.Cast(selectedEntity));
545  }
546  else
547  {
548  amc.SetActionFromInventory(ItemBase.Cast(selectedEntity), ItemBase.Cast(targetEntity));
549  }
550  return true;
551  case InventoryCombinationFlags.PERFORM_ACTION:
552  Class.CastTo(amc, player.GetActionManager());
553  if (targetEntity == player.GetHumanInventory().GetEntityInHands())
554  {
555  amc.PerformActionFromInventory(ItemBase.Cast(targetEntity), ItemBase.Cast(selectedEntity));
556  }
557  else
558  {
559  amc.PerformActionFromInventory(ItemBase.Cast(selectedEntity), ItemBase.Cast(targetEntity));
560  }
561  return true;
562  case InventoryCombinationFlags.SWAP_MAGAZINE:
563  return player.GetWeaponManager().SwapMagazine(Magazine.Cast(selectedEntity));
564  case InventoryCombinationFlags.SWAP:
565  return player.PredictiveSwapEntities(targetEntity, selectedEntity);
566  case InventoryCombinationFlags.FSWAP:
567  return player.PredictiveForceSwapEntities(selectedEntity, targetEntity, ilSwapDst);
568  default:
569  return false;
570  }
571 
572  return false;
573  }
574 
575  void UpdateFrameColor(EntityAI selectedEntity, EntityAI targetEntity, int combinationFlag, Widget w, InventoryLocation il = null)
576  {
577  int color;
578  Widget targetDropzone;
579 
580  ItemManager.GetInstance().HideDropzones();
581  switch (combinationFlag)
582  {
583  case InventoryCombinationFlags.ADD_AS_ATTACHMENT:
584  case InventoryCombinationFlags.ADD_AS_CARGO:
585  color = ColorManager.GREEN_COLOR;
586  ItemManager.GetInstance().ShowSourceDropzone(targetEntity);
587  break;
588  case InventoryCombinationFlags.COMBINE_QUANTITY2:
589  case InventoryCombinationFlags.SET_ACTION:
590  case InventoryCombinationFlags.PERFORM_ACTION:
591  color = ColorManager.COMBINE_COLOR;
592  ItemManager.GetInstance().ShowSourceDropzone(targetEntity);
593  break;
594  case InventoryCombinationFlags.SWAP_MAGAZINE:
595  color = ColorManager.SWAP_COLOR;
596  ItemManager.GetInstance().ShowSourceDropzone(selectedEntity);
597  break;
598  case InventoryCombinationFlags.SWAP:
599  color = ColorManager.SWAP_COLOR;
600  ItemManager.GetInstance().ShowSourceDropzone(selectedEntity);
601  break;
602  case InventoryCombinationFlags.FSWAP:
603  color = ColorManager.FSWAP_COLOR;
604  if (il)
605  {
606  ItemManager.GetInstance().ShowSourceDropzone(il.GetParent());
607  }
608  else
609  {
610  ItemManager.GetInstance().ShowSourceDropzone(selectedEntity);
611  }
612  break;
613  default:
614  color = ColorManager.RED_COLOR;
615  ItemManager.GetInstance().ShowSourceDropzone(selectedEntity);
616  }
617 
618  ColorManager.GetInstance().SetColor( w, color );
619  }
620 
621 
622 
623  void ShowActionMenuCombine( EntityAI entity1, EntityAI entity2, int combinationFlags, Widget w , bool color_test )
624  {
625  int lastFlag = 0;
626  ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
627  m_am_entity1 = entity1;
628  m_am_entity2 = entity2;
629  cmenu.Hide();
630  cmenu.Clear();
631  int id = -1;
632 
633  if ( entity1 == null || entity2 == null ) return;
634 
635  if ( combinationFlags == InventoryCombinationFlags.NONE )
636  {
637  if ( color_test )
638  {
639  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
640  ItemManager.GetInstance().ShowSourceDropzone( entity2 );
641  }
642  return;
643  }
644 
645  if (combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO)
646  {
647  lastFlag = InventoryCombinationFlags.ADD_AS_CARGO;
648  cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( lastFlag ) );
649  }
650  if (combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT)
651  {
652  lastFlag = InventoryCombinationFlags.ADD_AS_ATTACHMENT;
653  cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( lastFlag ));
654  }
655 
656  if (combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2)
657  {
658  lastFlag = InventoryCombinationFlags.COMBINE_QUANTITY2;
659  cmenu.Add("#inv_context_combine_quantity", this, "OnPerformCombination", new Param1<int>( lastFlag ));
660  }
661 
662  if (combinationFlags & InventoryCombinationFlags.SET_ACTION)
663  {
664  lastFlag = InventoryCombinationFlags.SET_ACTION;
665  cmenu.Add("#inv_context_attach_magazine", this, "OnPerformCombination", new Param1<int>( lastFlag ));
666  }
667 
668  if (combinationFlags & InventoryCombinationFlags.PERFORM_ACTION)
669  {
670  lastFlag = InventoryCombinationFlags.PERFORM_ACTION;
671  cmenu.Add("Perform action", this, "OnPerformCombination", new Param1<int>( lastFlag ));
672  }
673 
674  if (color_test)
675  {
676  if (lastFlag == 0)
677  {
678  ItemManager.GetInstance().HideDropzones();
679  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
680  ColorManager.GetInstance().SetColor( w, ColorManager.RED_COLOR );
681  }
682  else if (lastFlag == InventoryCombinationFlags.ADD_AS_ATTACHMENT || lastFlag == InventoryCombinationFlags.ADD_AS_CARGO )
683  {
684  ItemManager.GetInstance().HideDropzones();
685  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
686  ColorManager.GetInstance().SetColor( w, ColorManager.GREEN_COLOR );
687  }
688  else
689  {
690  ItemManager.GetInstance().HideDropzones();
691  ItemManager.GetInstance().GetCenterDropzone().SetAlpha( 1 );
692  ColorManager.GetInstance().SetColor( w, ColorManager.COMBINE_COLOR );
693  }
694  }
695  else if (cmenu.Count() >= 1)
696  {
697  OnPerformCombination(combinationFlags);
698  return;
699  }
700  }
701 
702  void OnPerformRecipe(int id)
703  {
704  if ( m_am_entity1 == null || m_am_entity2 == null ) return;
705 
706  Debug.Log("OnPerformRecipe called for id:"+id.ToString(),"recipes");
707  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
708  player.GetCraftingManager().SetInventoryCraft( id, ItemBase.Cast(m_am_entity1), ItemBase.Cast(m_am_entity2));
709  }
710 
711  void Combine( Widget w, int x, int y, Widget receiver )
712  {
713  ItemManager.GetInstance().HideDropzones();
714  ItemManager.GetInstance().SetIsDragging(false);
715  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget("Render"));
716  if (!selectedIpw)
717  {
718  string name = w.GetName();
719  name.Replace("PanelWidget", "Render");
720  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( name ));
721  }
722  if (!selectedIpw)
723  {
724  selectedIpw = ItemPreviewWidget.Cast(w);
725  }
726  if (!selectedIpw.GetItem())
727  {
728  return;
729  }
730  EntityAI selectedEntity = selectedIpw.GetItem();
731  EntityAI targetEntity = GetGame().GetPlayer().GetHumanInventory().GetEntityInHands();
732  static int testedFlags = InventoryCombinationFlags.SET_ACTION | InventoryCombinationFlags.PERFORM_ACTION | InventoryCombinationFlags.COMBINE_QUANTITY2 | InventoryCombinationFlags.ADD_AS_CARGO | InventoryCombinationFlags.ADD_AS_ATTACHMENT;
733 
734  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags);
735  PerformCombination(selectedEntity, targetEntity, chosenInventoryAction);
736  }
737 
738  bool CombineItems( EntityAI entity1, EntityAI entity2 )
739  {
740  int flags = ItemManager.GetCombinationFlags( entity1, entity2 );
741  return FlagAction( entity1, entity2, flags );
742  }
743 
744  bool FlagAction( EntityAI entity1, EntityAI entity2, int combinationFlags )
745  {
746  int current_flag;
747  ContextMenu cmenu = ContextMenu.Cast(GetGame().GetUIManager().GetMenu().GetContextMenu());
748  m_am_entity1 = entity1;
749  m_am_entity2 = entity2;
750  cmenu.Hide();
751  cmenu.Clear();
752  int id = -1;
753 
754  if (combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
755  {
756  ItemBase entity = ItemBase.Cast( entity1 );
757  entity.CombineItemsClient( ItemBase.Cast( entity2 ) );
758  return false;
759  }
760 
761  if (entity1 == null || entity2 == null || combinationFlags == InventoryCombinationFlags.NONE )
762  return true;
763 
764  if (combinationFlags & InventoryCombinationFlags.ADD_AS_ATTACHMENT )
765  {
766  current_flag = InventoryCombinationFlags.ADD_AS_ATTACHMENT;
767  cmenu.Add( "#inv_context_add_as_attachment", this, "OnPerformCombination", new Param1<int>( current_flag ) );
768  }
769  /*if (combinationFlags & InventoryCombinationFlags.LOAD_CHAMBER )
770  {
771  current_flag = InventoryCombinationFlags.LOAD_CHAMBER;
772  cmenu.Add( "#inv_context_load_chamber", this, "OnPerformCombination", new Param1<int>( current_flag ) );
773  }*/
774  if(combinationFlags & InventoryCombinationFlags.ATTACH_MAGAZINE)
775  {
776  current_flag = InventoryCombinationFlags.ATTACH_MAGAZINE;
777  cmenu.Add("#inv_context_attach_magazine", this, "OnPerformCombination", new Param1<int>( current_flag ) );
778  }
779 
780  if (combinationFlags & InventoryCombinationFlags.ADD_AS_CARGO )
781  {
782  current_flag = InventoryCombinationFlags.ADD_AS_CARGO;
783  cmenu.Add( "#inv_context_add_as_cargo", this, "OnPerformCombination", new Param1<int>( current_flag ) );
784  }
785 
786  if (combinationFlags & InventoryCombinationFlags.SWAP )
787  {
788  current_flag = InventoryCombinationFlags.SWAP;
789  cmenu.Add( "#inv_context_swap", this, "OnPerformCombination", new Param1<int>( current_flag ) );
790  }
791 
792  if (combinationFlags & InventoryCombinationFlags.COMBINE_QUANTITY2 )
793  {
794  current_flag = InventoryCombinationFlags.COMBINE_QUANTITY2;
795  cmenu.Add( "#inv_context_combine", this, "OnPerformCombination", new Param1<int>( current_flag ) );
796  }
797 
798  if(combinationFlags & InventoryCombinationFlags.SET_ACTION)
799  {
800  current_flag = InventoryCombinationFlags.SET_ACTION;
801  cmenu.Add("#inv_context_attach_magazine", this, "OnPerformCombination", new Param1<int>( current_flag ) );
802  }
803 
804  if(combinationFlags & InventoryCombinationFlags.PERFORM_ACTION)
805  {
806  current_flag = InventoryCombinationFlags.PERFORM_ACTION;
807  cmenu.Add("Perform Action2", this, "OnPerformCombination", new Param1<int>( current_flag ) );
808  }
809 
810  int m_am_Pos_x, m_am_Pos_y;
811  GetMousePos( m_am_Pos_x, m_am_Pos_y );
812  m_am_Pos_x -= 5;
813  m_am_Pos_y -= 5;
814 
815  MissionGameplay mission = MissionGameplay.Cast( GetGame().GetMission() );
816  /*if (combinationFlags & InventoryCombinationFlags.RECIPE_HANDS || combinationFlags & InventoryCombinationFlags.RECIPE_ANYWHERE )
817  {
818  OnPerformRecipe( id );
819  return true;
820  }
821  else /*if (cmenu.Count() == 1 )*/
822  //{
823  OnPerformCombination( current_flag );
824  return true;
825  //}
826  /*else
827  {
828  cmenu.Show( m_am_Pos_x, m_am_Pos_y );
829  return true;
830  }*/
831  }
832 
833  void MouseClick(Widget w, int x, int y, int button)
834  {
835  if (button == MouseState.RIGHT)
836  {
837  if (m_Lock)
838  {
839  GetGame().GetPlayer().GetHumanInventory().ClearUserReservedLocationSynced(m_Item);
840  }
841  else
842  {
843  if (m_Item && m_Item.IsItemBase())
844  {
845  m_Item.OnRightClick();
846 
847  if (m_HasQuantity)
848  SetQuantity();
849  #ifdef DIAG_DEVELOPER
850  if (GetDayZGame().IsLeftCtrlDown())
851  ShowActionMenu(m_Item);
852  #endif
853  }
854  }
855 
856  }
857  else if (!m_Lock)
858  {
859  switch (button)
860  {
861  case MouseState.MIDDLE:
862  InspectItem(m_Item);
863  break;
864 
865  case MouseState.LEFT:
866  PlayerBase controlledPlayer = PlayerBase.Cast(GetGame().GetPlayer());
867  if (g_Game.IsLeftCtrlDown())
868  {
869  if (controlledPlayer.CanDropEntity(m_Item))
870  {
871  if (m_Item.GetTargetQuantityMax() < m_Item.GetQuantity())
872  m_Item.SplitIntoStackMaxClient(null, -1);
873  else
874  controlledPlayer.PhysicalPredictiveDropItem(m_Item);
875 
876  ItemManager.GetInstance().SetWidgetDraggable(w, false);
877  }
878  }
879  else
880  {
882  m_Obj.GetInventory().GetCurrentInventoryLocation(il);
883 
884  bool draggable = !controlledPlayer.GetInventory().HasInventoryReservation(m_Obj, null) && !controlledPlayer.GetInventory().IsInventoryLocked() && !controlledPlayer.IsItemsToDelete();
885  draggable = draggable && (m_Obj.GetHierarchyRoot() && m_Obj.GetInventory().CanRemoveEntity() || !m_Obj.GetHierarchyRoot() && AttachmentsOutOfReach.IsAttachmentReachable(m_Obj, "", il.GetSlot()));
886 
887  ItemManager.GetInstance().SetWidgetDraggable(w, draggable);
888  }
889  break;
890  }
891  }
892  }
893 
894  void DropReceivedFromMain( Widget w, int x, int y, Widget receiver )
895  {
896  ItemManager.GetInstance().HideDropzones();
897  ItemManager.GetInstance().SetIsDragging(false);
898  string name = w.GetName();
899  name.Replace("PanelWidget", "Render");
900  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
901 
902  ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(receiver.FindAnyWidget( "Render" ));
903  if (m_HandsIcon)
904  {
905  targetIpw = ItemPreviewWidget.Cast(receiver.GetParent().FindAnyWidget( "Render" ));
906  }
907 
908  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( name ));
909  if (selectedIpw == null)
910  {
911  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( "Render" ));
912  }
913  if (selectedIpw == null)
914  {
915  return;
916  }
917 
918  InventoryItem targetEntity = InventoryItem.Cast(targetIpw.GetItem());
919  InventoryItem selectedEntity = InventoryItem.Cast(selectedIpw.GetItem());
920  if (!selectedEntity)
921  {
922  return;
923  }
924  int index;
925  InventoryLocation ilSrc;
926  InventoryLocation ilDst;
927  if (m_Lock && targetEntity == selectedEntity)
928  {
929  index = player.GetHumanInventory().FindUserReservedLocationIndex(m_Item);
930  ilSrc = new InventoryLocation();
931  ilDst = new InventoryLocation();
932 
933  m_Item.GetInventory().GetCurrentInventoryLocation(ilSrc);
934  player.GetHumanInventory().GetUserReservedLocation(index, ilDst);
935 
936  if (ilDst.GetParent().GetInventory().LocationCanAddEntity(ilDst))
937  {
938 
939  player.GetHumanInventory().ClearUserReservedLocation(m_Item);
940  player.PredictiveTakeToDst(ilSrc, ilDst);
941  m_Item.GetOnReleaseLock().Invoke(m_Item);
942  }
943  }
944  else if (m_Lock)
945  {
946  CargoContainer parentCargo = CargoContainer.Cast(m_Parent);
947 
948  float parentX;
949  float parentY;
950 
951  parentCargo.GetRootWidget().GetScreenPos(parentX, parentY);
952 
953  float iconSize = parentCargo.GetIconSize();
954  float spaceSize = parentCargo.GetSpaceSize();
955 
956  int PosX = (x-parentX) / (iconSize + spaceSize);
957  int PosY = (y-parentY) / (iconSize + spaceSize);
958 
959  EntityAI parent = m_Lock;
960  CargoBase targetCargo = parent.GetInventory().GetCargo();
961 
962  ilDst = new InventoryLocation();
963  ilDst.SetCargoAuto(targetCargo, selectedEntity, PosY, PosX, selectedEntity.GetInventory().GetFlipCargo());
964 
965  if (parent.GetInventory().LocationCanAddEntity(ilDst))
966  {
967  player.GetHumanInventory().ClearUserReservedLocation(m_Item);
968  m_Item.GetOnReleaseLock().Invoke(m_Item);
969 
970  SplitItemUtils.TakeOrSplitToInventoryLocation(player, ilDst);
971  }
972  }
973  else
974  {
975  ilDst = new InventoryLocation();
976  static int testedFlags = InventoryCombinationFlags.COMBINE_QUANTITY2 | InventoryCombinationFlags.ADD_AS_CARGO | InventoryCombinationFlags.ADD_AS_ATTACHMENT | InventoryCombinationFlags.SWAP | InventoryCombinationFlags.FSWAP | InventoryCombinationFlags.SWAP_MAGAZINE;
977 
978  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags, ilDst);
979  PerformCombination(selectedEntity, targetEntity, chosenInventoryAction, ilDst);
980  }
981  }
982 
983  void Swap( Widget w, int x, int y, Widget receiver )
984  {
985  ItemManager.GetInstance().HideDropzones();
986  ItemManager.GetInstance().SetIsDragging(false);
987  string name = w.GetName();
988  name.Replace("PanelWidget", "Render");
989 
990  ItemPreviewWidget targetIpw = ItemPreviewWidget.Cast(receiver.FindAnyWidget( "Render" ));
991  if (m_HandsIcon)
992  {
993  targetIpw = ItemPreviewWidget.Cast(receiver.GetParent().FindAnyWidget( "Render" ));
994  }
995 
996  ItemPreviewWidget selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( name ));
997  if (selectedIpw == null)
998  {
999  selectedIpw = ItemPreviewWidget.Cast(w.FindAnyWidget( "Render" ));
1000  }
1001  if (selectedIpw == null)
1002  {
1003  return;
1004  }
1005 
1006  InventoryItem targetEntity = InventoryItem.Cast(targetIpw.GetItem());
1007  InventoryItem selectedEntity = InventoryItem.Cast(selectedIpw.GetItem());
1008  if (!selectedEntity || !targetEntity)
1009  {
1010  return;
1011  }
1012 
1013  PlayerBase player = PlayerBase.Cast( GetGame().GetPlayer() );
1014  EntityAI itemInHands = player.GetHumanInventory().GetEntityInHands();
1015 
1016  InventoryLocation ilDst = new InventoryLocation();
1017  InventoryLocation ilSrc = new InventoryLocation();
1018  targetEntity.GetInventory().GetCurrentInventoryLocation(ilSrc);
1019  Icon icon = ItemManager.GetInstance().GetDraggedIcon();
1020 
1021  int index = player.GetHumanInventory().FindUserReservedLocationIndex(targetEntity);
1022  if (index>=0)
1023  {
1024  player.GetHumanInventory().GetUserReservedLocation(index, ilDst);
1025 
1026  if (GameInventory.CanForceSwapEntitiesEx( selectedEntity, ilSrc, targetEntity, ilDst ))
1027  {
1028  if (m_HandsIcon && !player.GetInventory().HasInventoryReservation(itemInHands, null) && !player.IsItemsToDelete())
1029  {
1030  GetGame().GetPlayer().PredictiveForceSwapEntities(selectedEntity, targetEntity, ilDst);
1031  return;
1032  }
1033  }
1034  }
1035  static int testedFlags = InventoryCombinationFlags.SWAP | InventoryCombinationFlags.FSWAP;
1036 
1037  int chosenInventoryAction = ItemManager.GetChosenCombinationFlag(selectedEntity, targetEntity, testedFlags, ilDst);
1038  PerformCombination(selectedEntity, targetEntity, chosenInventoryAction, ilDst);
1039  }
1040 
1041  void ToRefresh( Icon icon, Icon icon2 )
1042  {
1043  ( IconsContainer.Cast( m_Parent ) ).RemoveItem( icon );
1044  ( IconsContainer.Cast( m_Parent ) ).RemoveItem( icon2 );
1045  }
1046 
1047  override void SetLayoutName()
1048  {
1049  #ifdef PLATFORM_CONSOLE
1050  m_LayoutName = WidgetLayoutName.IconXbox;
1051  #else
1052  switch (InventoryMenu.GetWidthType())
1053  {
1054  case ScreenWidthType.NARROW:
1055  {
1056  m_LayoutName = WidgetLayoutName.IconNarrow;
1057  break;
1058  }
1059  case ScreenWidthType.MEDIUM:
1060  {
1061  m_LayoutName = WidgetLayoutName.IconMedium;
1062  break;
1063  }
1064  case ScreenWidthType.WIDE:
1065  {
1066  m_LayoutName = WidgetLayoutName.IconWide;
1067  break;
1068  }
1069  }
1070  #endif
1071 
1072  }
1073 
1074  void SetSize( int x, int y )
1075  {
1076  m_SizeX = x;
1077  m_SizeY = y;
1078  }
1079 
1080  void SetPos( int x, int y )
1081  {
1082  m_PosX = x;
1083  m_PosY = y;
1084  }
1085 
1086  int GetCargoPos()
1087  {
1088  return m_CargoPos;
1089  }
1090 
1091  void SetCargoPos(int x)
1092  {
1093  GetMainWidget().SetSort( x );
1094  m_CargoPos = x;
1095  }
1096 
1097  void DestroyWhiteBackground()
1098  {
1099  ItemManager.GetInstance().HideDropzones();
1100  ItemManager.GetInstance().SetIsDragging( false );
1101  m_IsDragged = false;
1102 
1103  RevertToOriginalFlip();
1104 
1105  if (m_HandsIcon)
1106  {
1107  m_ItemPreview.SetForceFlipEnable(true);
1108  m_ItemPreview.SetForceFlip(false);
1109  Refresh();
1110  FullScreen();
1111  }
1112 
1113  m_CursorWidget.SetColor( ARGBF( 1, 1, 1, 1 ) );
1114  m_CursorWidget.Show( false );
1115 
1116  InventoryMenu menu = InventoryMenu.Cast(GetGame().GetUIManager().FindMenu( MENU_INVENTORY ));
1117 
1118  if (menu)
1119  menu.RefreshQuickbar();
1120  }
1121 
1122  void CreateWhiteBackground()
1123  {
1124  m_PreviousFlipOrientation = m_Item.GetInventory().GetFlipCargo();
1125  ItemManager.GetInstance().SetDraggedIcon(this);
1126  ItemManager.GetInstance().SetDraggedItem(m_Item);
1127  m_IsDragged = true;
1128  ItemManager.GetInstance().SetIsDragging(true);
1129  int ww, hh;
1130  GetGame().GetInventoryItemSize(m_Item, ww, hh);
1131  if (m_Item.GetInventory().GetFlipCargo())
1132  SetSize(hh, ww);
1133  else
1134  SetSize(ww, hh);
1135 
1136  SetSize();
1137 
1138  if (!m_HandsIcon)
1139  {
1140  Refresh();
1141  }
1142  else
1143  {
1144  m_ItemPreview.SetForceFlipEnable(false);
1145  m_ColorWidget.SetColor(ColorManager.BASE_COLOR);
1146  m_ColorWidget.SetAlpha(0.1);
1147  }
1148 
1149  m_CursorWidget.Show(true);
1150  }
1151 
1152  void OnDraggingOverBackground( Widget w, int x, int y, Widget reciever )
1153  {
1154  ItemManager.GetInstance().HideDropzones();
1155  EntityAI entity = EntityAI.Cast( m_Obj );
1156  EntityAI parent = entity.GetHierarchyParent();
1157  if (parent && parent.GetHierarchyRootPlayer() == GetGame().GetPlayer())
1158  {
1159  ItemManager.GetInstance().GetRightDropzone().SetAlpha(1);
1160  }
1161  else if (!m_HandsIcon)
1162  {
1163  ItemManager.GetInstance().GetLeftDropzone().SetAlpha(1);
1164  }
1165 
1166  if (w == null || reciever == null)
1167  {
1168  return;
1169  }
1170  Pos pa;
1171  reciever.GetUserData(pa);
1172  if (m_Parent)
1173  {
1174  ContainerWithCargo item = ContainerWithCargo.Cast(m_Parent.m_Parent);
1175  if (item)
1176  {
1177  item.DraggingOverGrid(w, m_PosY + pa.y, m_PosX + pa.x, reciever);
1178  }
1179  HandsContainer hands_item = HandsContainer.Cast(m_Parent.m_Parent);
1180  if (hands_item)
1181  {
1182  hands_item.DraggingOverGrid(w, m_PosY + pa.y, m_PosX + pa.x, reciever, null);
1183  }
1184  }
1185  }
1186 
1187  void DropReceivedFromBackground( Widget w, int x, int y, Widget reciever )
1188  {
1189  Pos pa;
1190  if (reciever)
1191  {
1192  reciever.GetUserData(pa);
1193  if (m_Parent)
1194  {
1195  ContainerWithCargo item = ContainerWithCargo.Cast(m_Parent.m_Parent);
1196  if (item)
1197  {
1198  item.DropReceived(w, m_PosY + pa.y, m_PosX + pa.x);
1199  }
1200  }
1201  }
1202  }
1203 
1204  void RevertToOriginalFlip()
1205  {
1206  if (m_Item)
1207  {
1208  m_Item.GetInventory().SetFlipCargo(m_PreviousFlipOrientation);
1209  int ww, hh;
1210  GetGame().GetInventoryItemSize(m_Item, ww, hh);
1211 
1212  if (m_PreviousFlipOrientation)
1213  SetSize(hh, ww);
1214  else
1215  SetSize(ww, hh);
1216 
1217  SetSize();
1218  }
1219  }
1220 
1221  override void Refresh()
1222  {
1223  super.Refresh();
1224 
1225  if (!m_HandsIcon)
1226  SetPos();
1227 
1228  if (m_HasTemperature)
1229  SetTemperature();
1230 
1231  if (m_IsWeapon)
1232  RefreshMuzzleIcon();
1233 
1234  if (m_HasQuantity)
1235  SetQuantity();
1236  }
1237 
1238  void SetTemperature()
1239  {
1240  ItemManager.GetInstance().SetIconTemperature(EntityAI.Cast( m_Obj ), m_RootWidget);
1241  }
1242 
1243  void RefreshIconPos()
1244  {
1245  Refresh();
1246  GetMainWidget().Update();
1247  }
1248 
1249  void FullScreen()
1250  {
1251  if (m_IsDragged)
1252  {
1253  return;
1254  }
1255  GetRootWidget().ClearFlags(WidgetFlags.HEXACTSIZE + WidgetFlags.VEXACTSIZE);
1256  GetRootWidget().SetSize(1, 1);
1257  m_ColorWidget.SetColor(ARGB( 0, 0, 0, 0 ));
1258  }
1259 
1260  void RefreshPos( int row, int column )
1261  {
1262  if (row != m_PosY || column != m_PosX)
1263  {
1264  m_PosX = column;
1265  m_PosY = row;
1266  SetPos();
1267  RefreshIconPos();
1268  }
1269  }
1270 
1271  Object GetObject()
1272  {
1273  return m_Obj;
1274  }
1275 
1276  void RefreshMuzzleIcon()
1277  {
1278  Weapon_Base wpn = Weapon_Base.Cast(GetObject());
1279  if (wpn)
1280  {
1281  int i;
1282  ImageWidget ammoIcon;
1283  if (!wpn.IsShowingChamberedBullet())
1284  {
1285  for (i = 0; i < m_AmmoIcons.Count(); i++)
1286  {
1287  ammoIcon = m_AmmoIcons.Get(i);
1288  ammoIcon.Show(false);
1289  }
1290  /* int bullet_count = 0;
1291  int fireout_count = 0;
1292 
1293  for ( i = 0; i < wpn.GetMuzzleCount(); i++ )
1294  {
1295  if (wpn.IsChamberFull(i))
1296  {
1297  if (wpn.IsChamberFiredOut(i))
1298  {
1299  fireout_count++;
1300  }
1301  else
1302  {
1303  bullet_count++;
1304  }
1305  }
1306  }
1307 
1308  int j;
1309  i = 0;
1310  for ( j= 0; j < bullet_count; j++ )
1311  {
1312  if ( i > m_AmmoIcons.Count() )
1313  {
1314  //add plus ammo
1315  break;
1316  }
1317 
1318  ammoIcon = m_AmmoIcons.Get(i);
1319  ammoIcon.Show( true );
1320  ammoIcon.SetImage( 0 );
1321  i++;
1322  }
1323 
1324  for ( j= 0; j < fireout_count; j++ )
1325  {
1326  if ( i > m_AmmoIcons.Count() )
1327  {
1328  //add plus ammo
1329  break;
1330  }
1331 
1332  ammoIcon = m_AmmoIcons.Get(i);
1333  ammoIcon.Show( true );
1334  ammoIcon.SetImage( 1 );
1335  i++;
1336  }
1337 
1338  for (j = i; j < m_AmmoIcons.Count(); j++)
1339  {
1340  ammoIcon = m_AmmoIcons.Get(j);
1341  ammoIcon.Show(false);
1342  }*/
1343  }
1344  else
1345  {
1346  //TODO MW - add more conplex logic
1347  for (i = 0; i < wpn.GetMuzzleCount(); i++)
1348  {
1349  if ( i > m_AmmoIcons.Count() )
1350  {
1351  //add plus ammo
1352  break;
1353  }
1354 
1355  ammoIcon = m_AmmoIcons.Get(i);
1356 
1357  if (wpn.IsChamberFull(i))
1358  {
1359  if (wpn.IsJammed())
1360  {
1361  ammoIcon.Show(true);
1362  ammoIcon.SetImage(2);
1363  }
1364  else if (wpn.IsChamberFiredOut(i))
1365  {
1366  ammoIcon.Show(true);
1367  ammoIcon.SetImage(1);
1368  }
1369  else
1370  {
1371  ammoIcon.Show( true );
1372  ammoIcon.SetImage( 0 );
1373  }
1374  }
1375  else
1376  {
1377  ammoIcon.Show(false);
1378  }
1379  }
1380  }
1381  }
1382  }
1383 
1384  void SetQuantity()
1385  {
1386  if (m_Item)
1387  {
1388  int quantityType = QuantityConversions.HasItemQuantity(m_Item);
1389  if (quantityType != QUANTITY_HIDDEN && m_CurrQuantity != QuantityConversions.GetItemQuantity(m_Item))
1390  {
1391  m_CurrQuantity = QuantityConversions.GetItemQuantity(m_Item);
1392 
1393  if (quantityType == QUANTITY_COUNT)
1394  {
1395  string quantityText = QuantityConversions.GetItemQuantityText(m_Item);
1396 
1397  if (QuantityConversions.GetItemQuantityMax(m_Item) == 1 || quantityText == "")
1398  {
1399  m_QuantityStack.Show(false);
1400  }
1401  else
1402  {
1403  m_QuantityItem.SetText(quantityText);
1404  m_QuantityStack.Show(true);
1405  }
1406 
1407  m_QuantityProgress.Show(false);
1408  }
1409  else if (quantityType == QUANTITY_PROGRESS)
1410  {
1411  int max = m_Item.GetQuantityMax();
1412  int count = m_Item.ConfigGetInt("count");
1413  float quantity = m_CurrQuantity;
1414 
1415  if (count > 0)
1416  {
1417  max = count;
1418  }
1419 
1420  if (max > 0)
1421  {
1422  float value = Math.Round((quantity / max) * 100);
1423  m_QuantityProgress.SetCurrent(value);
1424  }
1425 
1426  m_QuantityStack.Show(false);
1427  m_QuantityProgress.Show(true);
1428  }
1429  }
1430  }
1431  }
1432 
1433  void SetSort(int index)
1434  {
1435  GetMainWidget().SetSort(index);
1436  GetMainWidget().Update();
1437  }
1438 
1439  int GetSort()
1440  {
1441  return GetMainWidget().GetSort();
1442  }
1443 
1444  void SetItemPreviewEx(bool refresh = true)
1445  {
1446  m_ItemPreview.Show(true, refresh);
1447  m_ItemPreview.SetItem(EntityAI.Cast(m_Obj));
1448  m_ItemPreview.SetModelOrientation("0 0 0");
1449  m_ItemPreview.SetView(m_Obj.GetViewIndex());
1450  }
1451 
1452  void SetItemPreview()
1453  {
1454  SetItemPreviewEx();
1455  }
1456 
1457  void SetItemSizeEx(bool refresh = true)
1458  {
1459  #ifdef PLATFORM_CONSOLE
1460  m_ItemSizePanel.Show(true, refresh);
1461  m_ItemSizeWidget.Show(true, refresh);
1462 
1463  int sizeX, sizeY;
1464  GetGame().GetInventoryItemSize(m_Item, sizeX, sizeY);
1465  int capacity = sizeX * sizeY;
1466  m_ItemSizeWidget.SetText(capacity.ToString());
1467  #endif
1468  }
1469 
1470  void SetItemSize()
1471  {
1472  SetItemSizeEx();
1473  }
1474 
1475  void UpdateFlip(bool flipped)
1476  {
1477  int sizeX, sizeY;
1478  GetGame().GetInventoryItemSize(m_Item, sizeX, sizeY);
1479 
1480  if (flipped)
1481  SetSize(sizeY, sizeX);
1482  else
1483  SetSize(sizeX, sizeY);
1484 
1485  SetSize();
1486  }
1487 
1488  void InitLock( EntityAI parent, EntityAI obj, int x_pos, int y_pos, bool flip)
1489  {
1490  m_Lock = parent;
1491  m_Obj = obj;
1492  m_Item = ItemBase.Cast(m_Obj);
1493 
1494  SetPos(x_pos, y_pos);
1495  UpdateFlip( flip );
1496 
1497  ItemManager.GetInstance().SetWidgetDraggable( GetMainWidget(), false );
1498  WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( GetMainWidget(), this, "MouseClick" );
1499  WidgetEventHandler.GetInstance().RegisterOnDropReceived( GetMainWidget(), this, "DropReceivedFromMain" );
1500  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( GetMainWidget(), this, "DraggingOver" );
1501 
1502  m_RootWidget.FindAnyWidget( "Reserved" ).Show( true );
1503  m_ItemPreview.SetForceFlipEnable(true);
1504  m_ItemPreview.SetForceFlip(flip);
1505  SetItemPreview();
1506  Refresh();
1507  }
1508 
1509  void InitEx( EntityAI obj, bool refresh = true )
1510  {
1511  if (obj != m_Obj)
1512  {
1513  if (m_Obj)
1514  {
1515  m_Obj.GetOnItemFlipped().Remove(UpdateFlip );
1516  m_Obj.GetOnViewIndexChanged().Remove(SetItemPreview);
1517  }
1518  if (obj)
1519  {
1520  obj.GetOnItemFlipped().Insert(UpdateFlip);
1521  obj.GetOnViewIndexChanged().Insert(SetItemPreview);
1522  }
1523  }
1524 
1525  if (m_HandsIcon)
1526  {
1527  m_ItemPreview.SetForceFlipEnable(true);
1528  m_ItemPreview.SetForceFlip(false);
1529  }
1530 
1531  m_Obj = obj;
1532  m_Item = ItemBase.Cast(m_Obj);
1533  m_Lock = null;
1534 
1535  SetItemPreviewEx(refresh);
1536 
1537  WidgetEventHandler.GetInstance().RegisterOnDrag( GetMainWidget(), this, "CreateWhiteBackground" );
1538  WidgetEventHandler.GetInstance().RegisterOnDrop( GetMainWidget(), this, "DestroyWhiteBackground" );
1539  WidgetEventHandler.GetInstance().RegisterOnDropReceived( GetMainWidget(), this, "DropReceivedFromMain" );
1540  WidgetEventHandler.GetInstance().RegisterOnMouseButtonDown( GetMainWidget(), this, "MouseClick" );
1541  WidgetEventHandler.GetInstance().RegisterOnDropReceived( GetMainWidget().FindAnyWidget( "Swap" ), this, "Swap" );
1542  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( GetMainWidget().FindAnyWidget( "Swap" ), this, "DraggingOverSwap" );
1543  WidgetEventHandler.GetInstance().RegisterOnDropReceived( GetMainWidget().FindAnyWidget( "Combine" ), this, "Combine" );
1544  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( GetMainWidget().FindAnyWidget( "Combine" ), this, "DraggingOverCombine" );
1545  WidgetEventHandler.GetInstance().RegisterOnDraggingOver( GetMainWidget(), this, "DraggingOver" );
1546  WidgetEventHandler.GetInstance().RegisterOnMouseEnter( GetMainWidget(), this, "MouseEnter" );
1547  WidgetEventHandler.GetInstance().RegisterOnMouseLeave( GetMainWidget(), this, "MouseLeave" );
1548  WidgetEventHandler.GetInstance().RegisterOnDoubleClick( GetMainWidget(), this, "DoubleClick" );
1549 
1550  SetItemSizeEx(refresh);
1551  CheckIsWeapon();
1552  CheckIsMagazineEx(refresh);
1553  CheckHasTemperature();
1554  CheckHasQuantityEx(refresh);
1555  m_RootWidget.FindAnyWidget("Reserved").Show(false, refresh);
1556 
1557  if (refresh)
1558  Refresh();
1559  }
1560 
1561  void Init(EntityAI obj)
1562  {
1563  InitEx(obj);
1564  }
1565 
1566  void CheckIsWeapon()
1567  {
1568  Weapon_Base wpn = Weapon_Base.Cast(m_Obj);
1569  if (wpn)
1570  {
1571  m_AmmoIcons = new array<ImageWidget>;
1572  m_IsWeapon = true;
1573  float posX = 0.0;
1574  float widht = 0.0, height = 0.0;
1575  for (int i = 0; i < wpn.GetMuzzleCount(); i++)
1576  {
1577  if (i == 1)
1578  {
1579  m_AmmoIcons[0].GetSize(widht,height);
1580  }
1581  posX += widht;
1582 
1583  Widget ammoIcon = Widget.Cast(GetGame().GetWorkspace().CreateWidgets( "gui/layouts/inventory_new/ammo_icon.layout", GetMainWidget() ));
1584  ammoIcon.SetPos(posX, 0.0, false);
1585 
1586  ImageWidget ammoIconImg = ImageWidget.Cast(ammoIcon.GetChildren());
1587 
1588  AmmoData data = Magazine.GetAmmoData(wpn.GetChamberAmmoTypeName(i));
1589  if (data)
1590  {
1591  CartridgeType c_type = data.m_CartridgeType;
1592  switch (c_type)
1593  {
1594  case CartridgeType.Pistol:
1595  {
1596  ammoIconImg.LoadImageFile(0, "set:dayz_gui image:cartridge_pistol");
1597  ammoIconImg.LoadImageFile(1, "set:dayz_gui image:shell_pistol");
1598  ammoIconImg.LoadImageFile(2, "set:dayz_gui image:jam_pistol");
1599  break;
1600  }
1601  case CartridgeType.Intermediate:
1602  {
1603  ammoIconImg.LoadImageFile(0, "set:dayz_gui image:cartridge_int");
1604  ammoIconImg.LoadImageFile(1, "set:dayz_gui image:shell_int");
1605  ammoIconImg.LoadImageFile(2, "set:dayz_gui image:jam_int");
1606  break;
1607  }
1608  case CartridgeType.FullPower:
1609  {
1610  ammoIconImg.LoadImageFile(0, "set:dayz_gui image:cartridge_fp");
1611  ammoIconImg.LoadImageFile(1, "set:dayz_gui image:shell_fp");
1612  ammoIconImg.LoadImageFile(2, "set:dayz_gui image:jam_fp");
1613  break;
1614  }
1615  case CartridgeType.Shell:
1616  {
1617  ammoIconImg.LoadImageFile(0, "set:dayz_gui image:cartridge_shell");
1618  ammoIconImg.LoadImageFile(1, "set:dayz_gui image:shell_shell");
1619  ammoIconImg.LoadImageFile(2, "set:dayz_gui image:jam_shell");
1620  break;
1621  }
1622  }
1623  }
1624  m_AmmoIcons.Insert(ammoIconImg);
1625  }
1626  }
1627  else
1628  {
1629  m_IsWeapon = false;
1630  }
1631  }
1632 
1633  void CheckIsMagazineEx( bool refresh = true )
1634  {
1635  Magazine mag = Magazine.Cast(m_Obj);
1636  if (mag)
1637  {
1638  m_IsMagazine = true;
1639  AmmoData data = Magazine.GetAmmoData(mag.ClassName());
1640  if (data)
1641  {
1642  ProjectileType p_type = data.m_ProjectileType;
1643  switch (p_type)
1644  {
1645  case ProjectileType.None:
1646  {
1647  m_AmmoTypeIcon.Show(false, refresh);
1648  break;
1649  }
1650  case ProjectileType.Tracer:
1651  {
1652  m_AmmoTypeIcon.LoadImageFile(0, "set:dayz_gui image:tracer");
1653  m_AmmoTypeIcon.Show(true, refresh);
1654  break;
1655  }
1656  case ProjectileType.AP:
1657  {
1658  m_AmmoTypeIcon.LoadImageFile(0, "set:dayz_gui image:armor_piercing");
1659  m_AmmoTypeIcon.Show(true, refresh);
1660  break;
1661  }
1662  }
1663  }
1664  }
1665  else
1666  {
1667  m_IsMagazine = false;
1668  }
1669  }
1670 
1671  void CheckIsMagazine()
1672  {
1673  CheckIsMagazineEx();
1674  }
1675 
1676  void CheckHasTemperature()
1677  {
1678  if (m_Item)
1679  {
1680  m_HasTemperature = (m_Item.GetTemperatureMax() != 0 && m_Item.GetTemperatureMin() != 0);
1681  }
1682  }
1683 
1684  void CheckHasQuantityEx(bool refresh = true)
1685  {
1686  if (m_Item)
1687  {
1688  m_HasQuantity = (QuantityConversions.HasItemQuantity( m_Item ) != QUANTITY_HIDDEN);
1689 
1690  if (m_HasQuantity)
1691  m_QuantityPanel.Show(true, refresh);
1692  }
1693  }
1694 
1695  void CheckHasQuantity()
1696  {
1697  CheckHasQuantityEx();
1698  }
1699 
1700  void SetPosX(int x)
1701  {
1702  m_PosX = x;
1703  }
1704 
1705  void SetPosY(int y)
1706  {
1707  m_PosY = y;
1708  }
1709 
1710  void SetSizeX(int x)
1711  {
1712  m_SizeX = x;
1713  }
1714 
1715  void SetSizeY(int y)
1716  {
1717  m_SizeY = y;
1718  }
1719 
1720  int GetPosX()
1721  {
1722  return m_PosX;
1723  }
1724 
1725  int GetPosY()
1726  {
1727  return m_PosY;
1728  }
1729 
1730  int GetSizeX()
1731  {
1732  return m_SizeX;
1733  }
1734 
1735  int GetSizeY()
1736  {
1737  return m_SizeY;
1738  }
1739 
1740  void SetPosEx(bool refresh = true)
1741  {
1742  CargoContainer parentContainer = CargoContainer.Cast(m_Parent);
1743  HandsPreview parentHPrevContainer = HandsPreview.Cast(m_Parent);
1744  Widget rootWidget = GetRootWidget();
1745  float iconSize, spaceSize;
1746  if (parentContainer)
1747  {
1748  iconSize = parentContainer.GetIconSize();
1749  spaceSize = parentContainer.GetSpaceSize();
1750  }
1751  else if (parentHPrevContainer)
1752  {
1753  iconSize = parentHPrevContainer.GetIconSize();
1754  if (rootWidget)
1755  {
1756  rootWidget.SetFlags(WidgetFlags.EXACTSIZE, refresh);
1757  }
1758  }
1759 
1760  if (rootWidget)
1761  {
1762  #ifndef PLATFORM_CONSOLE
1763  rootWidget.SetPos(iconSize * GetPosX() + ( GetPosX() + 1 ) * spaceSize, iconSize * GetPosY() + ( GetPosY() + 1 ) * spaceSize, refresh);
1764  rootWidget.SetSize(iconSize * m_SizeX + ( m_SizeX ) * spaceSize, iconSize * m_SizeY + ( m_SizeY ) * spaceSize, refresh);
1765  #else
1766  int row = m_CargoPos / 5;
1767  int column = m_CargoPos % 5;
1768  rootWidget.SetPos(iconSize * column, iconSize * row, refresh);
1769  rootWidget.SetSize(iconSize, iconSize, refresh);
1770  #endif
1771  }
1772  }
1773 
1774  void SetPos()
1775  {
1776  SetPosEx();
1777  }
1778 
1779  void SetSize()
1780  {
1781  CargoContainer parentContainer = CargoContainer.Cast(m_Parent);
1782  HandsPreview parentHPrevContainer = HandsPreview.Cast(m_Parent);
1783  float iconSize, spaceSize;
1784  Widget rootWidget = GetRootWidget();
1785  if (parentContainer)
1786  {
1787  iconSize = parentContainer.GetIconSize();
1788  spaceSize = parentContainer.GetSpaceSize();
1789  }
1790  else if (parentHPrevContainer)
1791  {
1792  iconSize = parentHPrevContainer.GetIconSize();
1793  if (rootWidget)
1794  {
1795  GetRootWidget().SetFlags(WidgetFlags.EXACTSIZE);
1796  }
1797  }
1798 
1799  if (rootWidget)
1800  {
1801  #ifndef PLATFORM_CONSOLE
1802  GetRootWidget().SetSize(iconSize * m_SizeX + ( m_SizeX ) * spaceSize, iconSize * m_SizeY + ( m_SizeY ) * spaceSize);
1803  #else
1804  GetRootWidget().SetSize(iconSize, iconSize);
1805  #endif
1806  }
1807  }
1808 
1809  override void UpdateInterval()
1810  {
1811  if (m_Item)
1812  {
1813  if (m_HasTemperature)
1814  SetTemperature();
1815 
1816  if (m_IsWeapon)
1817  RefreshMuzzleIcon();
1818 
1819  if (m_HasQuantity)
1820  SetQuantity();
1821  }
1822  }
1823 }
1824 
1825 class Pos
1826 {
1827  int x, y;
1828 
1829  void Pos(int _x, int _y)
1830  {
1831  x = _x;
1832  y = _y;
1833  }
1834 }
ItemBase
Definition: inventoryitem.c:730
GetGame
proto native CGame GetGame()
LayoutHolder
Definition: container.c:1
QUANTITY_PROGRESS
const int QUANTITY_PROGRESS
Definition: constants.c:484
QUANTITY_COUNT
const int QUANTITY_COUNT
Definition: constants.c:483
mission
Mission mission
Definition: displaystatus.c:28
QuantityConversions
Definition: quantityconversions.c:1
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
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
AttachmentsOutOfReach
Definition: attachmentsoutofreach.c:1
QUANTITY_HIDDEN
const int QUANTITY_HIDDEN
Definition: constants.c:482
InventoryLocation
InventoryLocation.
Definition: inventorylocation.c:27
WidgetLayoutName
Definition: widgetlayoutname.c:1
m_Item
protected EntityAI m_Item
Definition: radialquickbarmenu.c:14
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)
ToString
proto string ToString()
MENU_INVENTORY
const int MENU_INVENTORY
Definition: constants.c:170
GetContextMenu
override ContextMenu GetContextMenu()
Definition: inventorymenu.c:80
PlayerBase
Definition: playerbaseclient.c:1
CartridgeType
CartridgeType
Definition: magazine.c:3
TextWidget
Definition: enwidgets.c:219
ColorManager
Definition: colormanager.c:1
CargoBase
represents base for cargo storage for entities
Definition: cargo.c:6
g_Game
DayZGame g_Game
Definition: dayzgame.c:3727
Object
Definition: objecttyped.c:1
IconsContainer
Definition: iconscontainer.c:1
ItemManager
Definition: itemmanager.c:1
FindInventoryLocationType
FindInventoryLocationType
flags for searching locations in inventory
Definition: inventorylocation.c:15
ActionManagerClient
Definition: actionmanagerclient.c:4
ARGBF
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition: proto.c:332
MouseState
MouseState
Definition: ensystem.c:310
ScreenWidthType
ScreenWidthType
Definition: inventorymenu.c:1
array< ImageWidget >
name
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
x
Icon x
GetPlayer
protected void GetPlayer()
Definition: crosshairselector.c:127
Icon
Definition: icon.c:1
Debug
Definition: debug.c:13
ItemPreviewWidget
Definition: gameplay.c:275
WidgetFlags
WidgetFlags
Definition: enwidgets.c:57
InventoryMenu
void InventoryMenu()
Definition: inventorymenu.c:20
Weapon_Base
shorthand
Definition: boltactionrifle_base.c:5
InventoryCombinationFlags
Definition: inventorycombinationflags.c:1
m_ParentWidget
protected Widget m_ParentWidget
Definition: uihintpanel.c:24
m_SelectedPanel
protected SelectedPanel m_SelectedPanel
Definition: serverbrowsertab.c:37
Widget
Definition: enwidgets.c:189
Math
Definition: enmath.c:6
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
EntityAI
Definition: building.c:5
Pos
void Pos(int _x, int _y)
Definition: icon.c:1829
ARGB
int ARGB(int a, int r, int g, int b)
Definition: proto.c:322
HandsContainer
Definition: handscontainer.c:1
GameInventory
script counterpart to engine's class Inventory
Definition: inventory.c:78
WidgetEventHandler
Definition: widgeteventhandler.c:1