Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InventorySlotUI.c
Go to the documentation of this file.
1 const string SLOT_LAYOUT_1x1 = "{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
2 const string SLOT_LAYOUT_2x1 = "{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
3 const string SLOT_LAYOUT_2x2 = "{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
4 const string SLOT_LAYOUT_3x3 = "{F437ACE2BD5F11E1}UI/layouts/Menus/Inventory/InventoryItemSlot.layout";
5 
6 const int CURRENT_AMMO_MAGAZINE = ARGB( 255, 255, 255, 255 );
7 const int CURRENT_AMMO_TEXT = ARGB( 255, 142, 142, 142 );
8 const int CURRENT_AMMO_EMPTY = ARGB( 255, 255, 75, 75 );
9 
10 const float CURRENT_AMMO_OPACITY = 0.432;
11 
13 {
22 };
23 
24 //------------------------------------------------------------------------------------------------
27 class SCR_InventorySlotUI : ScriptedWidgetComponent
28 {
29  [Attribute("1", UIWidgets.ComboBox, "Slot size", "", ParamEnumArray.FromEnum(ESlotSize) )]
30  private ESlotSize m_ESlotSize;
31  protected int m_iSizeX;
32  protected int m_iSizeY;
33  protected int m_iPage; //helper variable telling us what page the slot should be stored on
34 
35  private WorkspaceWidget m_workspaceWidget = null;
36  Widget m_widget = null;
37  private ButtonWidget m_wButton;
38  private ImageWidget m_wIcon = null;
39  private RenderTargetWidget m_wPreviewImage = null;
40 
41 // protected SCR_InventoryStorageManagerComponent m_InventoryManager = null; //TODO: not needed can be taken from storageBaseUI
42  protected SCR_InventoryStorageBaseUI m_pStorageUI;
43 
44  protected InventoryItemComponent m_pItem;
45  protected ref SCR_ItemAttributeCollection m_Attributes;
46  const string ITEM_LAYOUT = "{0921F9EB5F3843BA}UI/layouts/Menus/Inventory/Inventory20Item.layout";
47  const int LMB_CLICK = 0;
48  const int RMB_CLICK = 1;
49  const int MID_CLICK = 2;
50  protected bool m_bEnabled = true;
51  protected bool m_bSelected = false;
52  protected bool m_bBlocked = false;
53  protected Widget m_wSelectedEffect, m_wSelectedIcon , m_wMoveEffect, m_wDimmerEffect, m_wBlockedEffect;
54  protected TextWidget m_wTextQuickSlot = null;
55  protected TextWidget m_wTextQuickSlotLarge = null;
56  protected int m_iQuickSlotIndex;
57 
58  protected ProgressBarWidget m_wVolumeBar, m_wAmmoCount, m_wCurrentMagazineAmmoCount;
59  protected int m_iStackNumber = 1;
60  protected TextWidget m_wStackNumber, m_wMagazineNumber;
61  protected OverlayWidget m_wItemLockThrobber;
62  protected string m_sItemName = "";
63  protected int m_aAmmoCountActual = -1;
64  protected int m_aAmmoCountMax = -1;
65 
66 
67  protected bool m_bVisible;
68  protected ESlotFunction m_eSlotFunction = ESlotFunction.TYPE_GENERIC;
69 
70  //~ FUEL
71  protected const string FUEL_WIDGET_HOLDER_NAME = "FuelCountHolder";
72  protected const string FUEL_WIDGET_FILL_NAME = "FuelFill";
73  protected ImageWidget m_wFuelCount;
74  protected SCR_FuelManagerComponent m_FuelManager;
75 
76  #ifdef DEBUG_INVENTORY20
77  protected TextWidget m_wDbgClassText1;
78  protected TextWidget m_wDbgClassText2;
79  protected TextWidget m_wDbgClassText3;
80  #endif
81 
82  //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
83  //------------------------------------------------------------------------------------------------
84  void UpdateReferencedComponent( InventoryItemComponent pComponent, SCR_ItemAttributeCollection attributes = null )
85  {
86  if ( m_widget )
87  Destroy();
88  m_pItem = pComponent;
89 
90  if (attributes)
91  m_Attributes = attributes;
92 
93  if (m_pItem && m_pItem.GetAttributes())
94  m_Attributes = SCR_ItemAttributeCollection.Cast( m_pItem.GetAttributes() ); //set the slot attributes (size) based on the information stored in the item
95  if (!m_Attributes)
96  return;
97  if (m_pItem && !m_Attributes.IsVisible())
98  return;
99 
101  if (vehicleAttributes && !ShouldVehicleSlotBeVisible(vehicleAttributes))
102  return;
103 
104  m_workspaceWidget = GetGame().GetWorkspace();
105  Widget wGrid = m_pStorageUI.GetStorageGrid();
106 
107  if (!wGrid)
108  return;
109 
110  m_widget = m_workspaceWidget.CreateWidgets( SetSlotSize(), wGrid );
111  m_widget.AddHandler( this ); //calls the HandlerAttached()
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  void UpdateInventorySlot(InventoryItemComponent comp, int stackNumber)
116  {
117  m_pItem = comp;
118  m_iStackNumber = stackNumber;
119  Refresh();
120  }
121 
122  //------------------------------------------------------------------------------------------------
123  bool IsDraggable()
124  {
125  if (!m_Attributes)
126  return true;
127 
128  return m_Attributes.IsDraggable();
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  protected string SetSlotSize()
133  {
134  string slotLayout = SLOT_LAYOUT_1x1;
135  switch ( m_Attributes.GetItemSize() )
136  {
137  case ESlotSize.SLOT_1x1: { slotLayout = SLOT_LAYOUT_1x1; m_iSizeX = 1; m_iSizeY = 1; } break;
138  case ESlotSize.SLOT_2x1: { slotLayout = SLOT_LAYOUT_2x1; m_iSizeX = 2; m_iSizeY = 1; } break;
139  case ESlotSize.SLOT_2x2: { slotLayout = SLOT_LAYOUT_2x2; m_iSizeX = 2; m_iSizeY = 2; } break;
140  case ESlotSize.SLOT_3x3: { slotLayout = SLOT_LAYOUT_3x3; m_iSizeX = 3; m_iSizeY = 3; } break;
141  }
142  return slotLayout;
143  }
144  //------------------------------------------------------------------------------------------------
145  protected void Init()
146  {
147  m_iPage = -1; //no page placement by default
148  //and create the visual slot
149 
150  m_wTextQuickSlot = TextWidget.Cast( m_widget.FindAnyWidget( "TextQuickSlot" ) );
151  m_sItemName = GetItemName(); //debug purposes
152 
153  if (m_pItem)
154  m_pItem.m_OnLockedStateChangedInvoker.Insert(OnChangeLockState);
155 
156  //m_widget = w;
157  SetSlotVisible( m_bVisible );
158  SetItemFunctionality();
159  // If is it storage or attachment, register it to the array for the future use
160  if (!BaseInventoryStorageComponent.Cast(m_pItem) && !WeaponAttachmentsStorageComponent.Cast(m_pItem))
161  return;
162 
163  if (m_pStorageUI && m_pStorageUI.GetInventoryMenuHandler())
164  m_pStorageUI.GetInventoryMenuHandler().RegisterUIStorage(this);
165  }
166 
167  //------------------------------------------------------------------------------------------------
169  BaseInventoryStorageComponent GetStorageComponent() { return BaseInventoryStorageComponent.Cast(m_pItem); }
170 
171  //------------------------------------------------------------------------------------------------
172  LoadoutAreaType GetLoadoutArea()
173  {
174  if ( !m_pItem )
175  return null;
176  auto pClothComponent = BaseLoadoutClothComponent.Cast( m_pItem.GetOwner().FindComponent( BaseLoadoutClothComponent ) );
177  if ( !pClothComponent )
178  return null;
179 
180  return pClothComponent.GetAreaType();
181  }
182 
183 
184  //------------------------------------------------------------------------------------------------
185  void SetStackNumber( int i ) { m_iStackNumber = i; }
186  void IncreaseStackNumber() { m_iStackNumber++; }
187  void IncreaseStackNumber( int i ) { m_iStackNumber = m_iStackNumber + i; }
188 
189  //------------------------------------------------------------------------------------------------
191  protected void SetAmmoCount()
192  {
193  Widget ammoSizeCountHolder = GetWidget().FindAnyWidget("SizeAmmoCount");
194 
195  if (!m_pItem)
196  return;
197 
198  MagazineComponent pMagazineComponent = MagazineComponent.Cast( m_pItem.GetOwner().FindComponent( MagazineComponent ) );
199  if (!pMagazineComponent)
200  return;
201 
202  m_aAmmoCountActual = pMagazineComponent.GetAmmoCount();
203  m_aAmmoCountMax = pMagazineComponent.GetMaxAmmoCount();
204 
205  if (ammoSizeCountHolder)
206  ammoSizeCountHolder.SetVisible(true);
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected void OnFuelAmountChanged(float newFuelValue)
211  {
212  if (!m_wFuelCount || !m_FuelManager)
213  return;
214 
215  m_wFuelCount.SetMaskProgress(1 - (newFuelValue / m_FuelManager.GetTotalMaxFuel()));
216  }
217 
218  //------------------------------------------------------------------------------------------------
219  protected void InitFuelAmount()
220  {
221  m_wFuelCount = ImageWidget.Cast(m_widget.FindAnyWidget(FUEL_WIDGET_FILL_NAME));
222  if (!m_wFuelCount)
223  return;
224 
225  m_FuelManager.GetOnFuelChanged().Insert(OnFuelAmountChanged);
226  OnFuelAmountChanged(m_FuelManager.GetTotalFuel());
227 
228  Widget fuelCountHolder = m_widget.FindAnyWidget(FUEL_WIDGET_HOLDER_NAME);
229  if (fuelCountHolder)
230  fuelCountHolder.SetVisible(true);
231  }
232 
233  //------------------------------------------------------------------------------------------------
234  Widget GetButtonWidget() { return m_wButton; }
235  //------------------------------------------------------------------------------------------------
236  bool IsSlotEnabled() { return m_bEnabled; }
237  //------------------------------------------------------------------------------------------------
238  bool IsSlotBlocked() { return m_bBlocked; }
239  //------------------------------------------------------------------------------------------------
240  bool IsSlotSelected() { return m_bSelected; }
241  //------------------------------------------------------------------------------------------------
243  void SetSlotVisible( bool bVisible )
244  {
245  m_bVisible = bVisible;
246  m_widget.SetEnabled(bVisible);
247  m_widget.SetVisible(bVisible);
248 
249  if(bVisible)
250  {
251  m_wPreviewImage = RenderTargetWidget.Cast( m_widget.FindAnyWidget( "item" ) );
252 
253  ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
254  if (world)
255  {
256  ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
257  if (manager)
258  {
259  ItemPreviewWidget renderPreview = ItemPreviewWidget.Cast( m_wPreviewImage );
260  IEntity previewEntity = null;
261  if (m_pItem)
262  previewEntity = m_pItem.GetOwner();
263  if (renderPreview)
264  manager.SetPreviewItem(renderPreview, previewEntity, null, true);
265  }
266  }
267 
268  //if the slot has storage, then show its volume bar
269  BaseInventoryStorageComponent pStorageTo = GetStorageComponent();
270  if ( pStorageTo )
271  {
272  m_wVolumeBar = ProgressBarWidget.Cast( m_widget.FindAnyWidget( "VolumeBar" ) );
273  m_wVolumeBar.SetVisible( true );
274  }
275  m_wSelectedEffect = m_widget.FindAnyWidget("SelectedOverlay");
276  m_wSelectedIcon = m_widget.FindAnyWidget("SelectedIcon");
277  m_wMoveEffect = m_widget.FindAnyWidget( "IconMove" );
278  m_wDimmerEffect = m_widget.FindAnyWidget( "Dimmer" );
279  m_wBlockedEffect = m_widget.FindAnyWidget("Blocker");
280  m_wButton = ButtonWidget.Cast( m_widget.FindAnyWidget( "ItemButton" ) );
281  m_wStackNumber = TextWidget.Cast( m_widget.FindAnyWidget( "stackNumber" ) );
282  m_wItemLockThrobber = OverlayWidget.Cast(m_widget.FindAnyWidget("itemLockThrobber"));
283 
284  if ( m_iStackNumber > 1 )
285  {
286  m_wStackNumber.SetText( m_iStackNumber.ToString() );
287  m_wStackNumber.SetVisible( true );
288  }
289  else
290  {
291  m_wStackNumber.SetVisible( false );
292  }
293 
294  m_wAmmoCount = ProgressBarWidget.Cast( m_widget.FindAnyWidget( "ammoCount" ) );
295  if ( m_wAmmoCount )
296  {
297  SetAmmoCount();
298  UpdateAmmoCount();
299  }
300 
301  if (m_FuelManager)
302  OnFuelAmountChanged(m_FuelManager.GetTotalFuel());
303 
304  m_wMagazineNumber = TextWidget.Cast( m_widget.FindAnyWidget( "magazineCount" ) );
305  m_wCurrentMagazineAmmoCount = ProgressBarWidget.Cast( m_widget.FindAnyWidget( "currentMagazineAmmoCount" ) );
306  if ( m_wMagazineNumber && m_wCurrentMagazineAmmoCount )
307  {
308  UpdateWeaponAmmoCount();
309  }
310 
311  #ifdef DEBUG_INVENTORY20
312  if ( !m_pItem )
313  {
314  array<string> dbgText = new array<string>();
315  this.ToString().Split( "<", dbgText, false );
316  m_wDbgClassText1 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass1" ) );
317  m_wDbgClassText2 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass2" ) );
318  m_wDbgClassText3 = TextWidget.Cast( m_widget.FindAnyWidget( "dbgTextClass3" ) );
319  m_wDbgClassText1.SetText( dbgText[0] );
320  m_wDbgClassText1.SetEnabled( true );
321  m_wDbgClassText1.SetVisible( true );
322  m_wDbgClassText2.SetText( dbgText[1] );
323  m_wDbgClassText2.SetEnabled( true );
324  m_wDbgClassText2.SetVisible( true );
325  m_pItem.ToString().Split( "<", dbgText, false );
326  if ( dbgText.Count() > 1 )
327  {
328  m_wDbgClassText3.SetText( dbgText[1] );
329  m_wDbgClassText3.SetEnabled( true );
330  m_wDbgClassText3.SetVisible( true );
331  }
332  }
333  #endif
334  UpdateVolumeBarValue();
335 
336  }
337  else
338  {
339  m_wPreviewImage = null;
340  m_wSelectedEffect = null;
341  m_wSelectedIcon = null;
342  m_wMoveEffect = null;
343  m_wDimmerEffect = null;
344  m_wButton = null;
345  m_wVolumeBar = null;
346  m_wTextQuickSlot = null;
347  m_wTextQuickSlotLarge = null;
348  m_wStackNumber = null;
349  #ifdef DEBUG_INVENTORY20
350  m_wDbgClassText1 = null;
351  m_wDbgClassText2 = null;
352  m_wDbgClassText3 = null;
353  #endif
354  }
355  }
356 
357  //------------------------------------------------------------------------------------------------
359  void SetSlotBlocked(bool bBlocked)
360  {
361  m_bBlocked = bBlocked;
362 
363  if (!m_wBlockedEffect || !m_wDimmerEffect)
364  return;
365 
366  if (m_wBlockedEffect.IsVisible() == bBlocked)
367  return;
368 
369  m_wDimmerEffect.SetVisible(bBlocked);
370  m_wBlockedEffect.SetVisible(bBlocked);
371  }
372 
373  //------------------------------------------------------------------------------------------------
374  // !
375  int GetSlotIndex() { return m_iQuickSlotIndex; }
376 
377  //------------------------------------------------------------------------------------------------
378  // !
379  void SetQuickSlotIndexVisible( TextWidget textQuickSlot, bool bVisible )
380  {
381  if ( textQuickSlot && GetGame().GetInputManager().IsUsingMouseAndKeyboard() )
382  {
383  textQuickSlot.SetText( ( (m_iQuickSlotIndex + 1) % 10 ).ToString() );
384  textQuickSlot.SetVisible( bVisible );
385  }
386  }
387 
388 
389  //------------------------------------------------------------------------------------------------
390  void OnSlotFocused()
391  {
392  if ( !m_pStorageUI )
393  return;
394  m_pStorageUI.SetSlotFocused( this, true );
395  SCR_InventoryMenuUI pMenuManager = m_pStorageUI.GetInventoryMenuHandler();
396  if ( pMenuManager )
397  {
398  #ifdef DEBUG_INVENTORY20
399 
400  BaseInventoryStorageComponent dbgStorage;
401  InventoryStorageSlot dbgStorageParentSlot;
402 
403  if ( m_pStorageUI.GetStorage() )
404  {
405  dbgStorage = m_pStorageUI.GetStorage();
406  if ( m_pStorageUI.GetStorage().GetParentSlot() )
407  dbgStorageParentSlot = m_pStorageUI.GetStorage().GetParentSlot();
408  }
409 
410  PrintFormat( "INV:OnSlotFocused | m_pStorageUI: %1 | Focused slotUI: %2 | Parent storage: %3 | from parent slot: %4", m_pStorageUI, this, dbgStorage, dbgStorageParentSlot );
411  #endif
412  pMenuManager.SetSlotFocused( this, GetStorageUI(), true );
413  }
414  }
415 
416  //------------------------------------------------------------------------------------------------
417  override bool OnMouseEnter( Widget w, int x, int y )
418  {
419  OnSlotFocused();
420  if ( m_wButton )
421  if ( m_wButton.FindHandler( SCR_ButtonComponent ) )
422  m_wButton.FindHandler( SCR_ButtonComponent ).OnFocus( w, x, y );
423  return false;
424  }
425 
426  //------------------------------------------------------------------------------------------------
427  override bool OnMouseLeave( Widget w, Widget enterW, int x, int y )
428  {
429  OnSlotFocusLost();
430  if ( m_wButton )
431  if ( m_wButton.FindHandler( SCR_ButtonComponent ) )
432  m_wButton.FindHandler( SCR_ButtonComponent ).OnFocusLost( w, x, y );
433  return false;
434  }
435 
436  //------------------------------------------------------------------------------------------------
437  void OnSlotFocusLost()
438  {
439  if (!m_pStorageUI)
440  return;
441  m_pStorageUI.SetSlotFocused( this, false );
442  SCR_InventoryMenuUI pMenuManager = m_pStorageUI.GetInventoryMenuHandler();
443  if ( pMenuManager )
444  pMenuManager.SetSlotFocused( this, m_pStorageUI, false );
445  }
446 
447  //------------------------------------------------------------------------------------------------
448  void ToggleSelected()
449  {
451  if (!m_wSelectedEffect || !m_wSelectedIcon)
452  return;
453 
454  m_wSelectedEffect.SetVisible( m_bSelected );
455  m_wSelectedIcon.SetVisible(false);
456  m_pStorageUI.SetSlotSelected( this, m_bSelected );
457  }
458  //------------------------------------------------------------------------------------------------
459  void SetSelected( bool select )
460  {
461  //TODO: show the selected effect should be done as a component
462  if (!m_pItem)
463  return;
464 
465  m_bSelected = select;
466  if (!m_wSelectedEffect || !m_wSelectedIcon)
467  return;
468 
469  m_wSelectedEffect.SetVisible(select);
470  }
471 
472  //------------------------------------------------------------------------------------------------
473  void SetEnabled( bool enable )
474  {
475  if( enable )
476  m_widget.SetOpacity( BUTTON_OPACITY_ENABLED );
477  else
478  m_widget.SetOpacity( BUTTON_OPACITY_DISABLED );
479 
480  m_widget.SetEnabled( enable );
481  }
482 
483  bool OnDrop(SCR_InventorySlotUI slot)
484  {
485  return false;
486  }
487 
488  //------------------------------------------------------------------------------------------------
489  // ! 0 - Disable for move
490  // ! 1 - Enable for move
491  // ! 2 - Reset
492  void SetEnabledForMove( int iSelect )
493  {
494  switch ( iSelect )
495  {
496  case 0:
497  {
498  m_widget.SetEnabled( false );
499  if ( m_wMoveEffect )
500  m_wMoveEffect.SetVisible( false );
501  } break;
502 
503  case 1:
504  {
505  m_widget.SetEnabled( true );
506  if ( m_wMoveEffect )
507  m_wMoveEffect.SetVisible( true );
508 
509  } break;
510 
511  case 2:
512  {
513  m_widget.SetEnabled( true );
514  if ( m_wMoveEffect )
515  m_wMoveEffect.SetVisible( false );
516  } break;
517 
518  }
519 
520  }
521 
522  //------------------------------------------------------------------------------------------------
523  InventoryItemComponent GetInventoryItemComponent() { return m_pItem; }
524  //------------------------------------------------------------------------------------------------
525  BaseInventoryStorageComponent GetAsStorage() { return BaseInventoryStorageComponent.Cast( m_pItem ); }
526 
527  //------------------------------------------------------------------------------------------------
528  // ! Returns the UI storage the slot is associated with
529  SCR_InventoryStorageBaseUI GetStorageUI() { return m_pStorageUI; }
530 
531  //------------------------------------------------------------------------------------------------
532  bool IsSelected() { return m_bSelected; }
533 
534  //------------------------------------------------------------------------------------------------
535  protected UIInfo GetItemDetails()
536  {
537  if( !m_Attributes )
538  return null;
539  return m_Attributes.GetUIInfo();
540  }
541 
542  //------------------------------------------------------------------------------------------------
543  string GetItemName()
544  {
545  UIInfo itemDetails = GetItemDetails();
546  if( !itemDetails )
547  return string.Empty;
548  return itemDetails.GetName();
549  }
550 
551  //------------------------------------------------------------------------------------------------
552  protected void SetItemDetails()
553  {
554  UIInfo itemDetails = GetItemDetails();
555  if(!itemDetails)
556  return;
557 
558  if(m_pStorageUI)
559  {
560  SCR_InventoryUIInfo inventoryItemDetails = SCR_InventoryUIInfo.Cast(itemDetails);
561 
562  if (inventoryItemDetails)
563  m_pStorageUI.ShowItemDetails(inventoryItemDetails.GetInventoryItemName(m_pItem), inventoryItemDetails.GetInventoryItemDescription(m_pItem), m_Attributes.GetWeight().ToString());
564  else
565  m_pStorageUI.ShowItemDetails(itemDetails.GetName(), itemDetails.GetDescription(), m_Attributes.GetWeight().ToString());
566  }
567  }
568 
569  //------------------------------------------------------------------------------------------------
570  void ClearItemDetails()
571  {
572  if( m_pStorageUI )
573  m_pStorageUI.ShowItemDetails( "", "", "" );
574  }
575 
576 
577  //------------------------------------------------------------------------------------------------
578  protected void SetImage( string resource, string imageName )
579  {
580  if ( resource == string.Empty || imageName == string.Empty || m_wIcon == null )
581  return;
582 
583  m_wIcon.LoadImageFromSet( 0, resource, imageName );
584  int width, height;
585  m_wIcon.GetImageSize( 0, width, height );
586  m_wIcon.SetSize( 32, 32 ); //TODO force this
587  }
588 
589  //------------------------------------------------------------------------------------------------
590  protected SCR_InventoryStorageManagerComponent GetInventoryManager() { return m_pStorageUI.GetInventoryManager(); }
591 
592  //------------------------------------------------------------------------------------------------
593  bool RemoveItem()
594  {
595  SCR_InventoryStorageManagerComponent invMan = GetInventoryManager();
596  if (!invMan || !invMan.CanMoveItem(m_pItem.GetOwner()))
597  return false;
598  InventoryStorageSlot pSlot = m_pItem.GetParentSlot();
599  if( !pSlot )
600  return false;
601  auto pStorage = pSlot.GetStorage();
602  if( !pStorage )
603  return false;
604  if(!invMan.CanRemoveItemFromStorage(m_pItem.GetOwner(), pStorage))
605  return false;
606 
607  //TODO: return the check back once the true/false issue is solved
608  //if(!invMan().TryRemoveItemFromInventory(m_pItem.GetOwner(), pStorage))
609  //return false; //can't be removed, exit
610 
611  invMan.TryRemoveItemFromInventory(m_pItem.GetOwner(), pStorage);
612 
613  if( !m_pStorageUI )
614  return false;
615  if ( m_widget )
616  {
617  m_widget.RemoveHandler( this );
618  m_widget.RemoveFromHierarchy();
619  }
620  m_pStorageUI.RemoveSlotUI( this );
621  //delete this;
622 
623  return true;
624  }
625 
626  //------------------------------------------------------------------------------------------------
628  void SetItemFunctionality()
629  {
630  if(!m_pItem)
631  return;
632  IEntity item = m_pItem.GetOwner();
633  if (!item)
634  return;
635 
636  m_FuelManager = SCR_FuelManagerComponent.Cast(item.FindComponent(FuelManagerComponent));
637  if (m_FuelManager && m_FuelManager.GetTotalMaxFuel() > 0)
638  {
639  InitFuelAmount();
640  return;
641  }
642 
643  if (MagazineComponent.Cast(item.FindComponent(MagazineComponent)))
644  {
645  m_eSlotFunction = ESlotFunction.TYPE_MAGAZINE;
646  SetAmmoCount();
647  return;
648  }
649 
650  if (WeaponComponent.Cast(item.FindComponent(WeaponComponent)))
651  {
652  m_eSlotFunction = ESlotFunction.TYPE_WEAPON;
653  return;
654  }
655 
656  if (SCR_GadgetComponent.Cast(item.FindComponent(SCR_GadgetComponent)))
657  {
658  m_eSlotFunction = ESlotFunction.TYPE_GADGET;
659  return;
660  }
661  }
662 
663  //------------------------------------------------------------------------------------------------
664  SCR_CharacterInventoryStorageComponent GetCharacterStorage(IEntity entity)
665  {
666  ChimeraCharacter character = ChimeraCharacter.Cast(entity);
667  if (!character)
668  return null;
669 
670  CharacterControllerComponent controller = character.GetCharacterController();
671  if (!controller)
672  return null;
673 
674  SCR_InventoryStorageManagerComponent storageManager = GetInventoryManager();
675  if (!storageManager)
676  return null;
677 
678  return storageManager.GetCharacterStorage();
679  }
680 
681  //------------------------------------------------------------------------------------------------
682  void UseItem(IEntity player)
683  {
684  if (!m_pItem)
685  return;
686 
687  IEntity item = m_pItem.GetOwner();
688  if (!item)
689  return;
690 
691  SCR_CharacterInventoryStorageComponent storage = GetCharacterStorage(player);
692  if (!storage)
693  return;
694 
695  if (storage.UseItem(item, m_eSlotFunction))
696  Refresh();
697  }
698 
699  //------------------------------------------------------------------------------------------------
700  bool CanUseItem(IEntity player)
701  {
702  if (!m_pItem)
703  return false;
704 
705  IEntity item = m_pItem.GetOwner();
706  if (!item)
707  return false;
708 
709  SCR_CharacterInventoryStorageComponent storage = GetCharacterStorage(player);
710  if (!storage)
711  return false;
712 
713  return storage.CanUseItem(item, m_eSlotFunction);
714  }
715 
716  //------------------------------------------------------------------------------------------------
717  protected bool ShouldVehicleSlotBeVisible(SCR_InventoryVehicleVisibilityAttribute attr)
718  {
719  IEntity vehicle = m_pItem.GetOwner();
721  if (dm && dm.IsDestroyed())
722  return false;
723 
724  ChimeraCharacter player = ChimeraCharacter.Cast(GetGame().GetPlayerController().GetControlledEntity());
725 
726  if (attr.GetVisibleInVehicleOnly() && !player.IsInVehicle())
727  return false;
728 
729  if (!attr.GetVisibleForVehicleFactionOnly())
730  return false;
731 
732  if (!Vehicle.Cast(vehicle))
733  vehicle = vehicle.GetParent();
734 
735  FactionAffiliationComponent vehicleFaction = FactionAffiliationComponent.Cast(vehicle.FindComponent(FactionAffiliationComponent));
736  if (!vehicleFaction || !vehicleFaction.GetAffiliatedFaction())
737  return true;
738 
739  FactionAffiliationComponent playerFaction = FactionAffiliationComponent.Cast(player.FindComponent(FactionAffiliationComponent));
740  if (!playerFaction || !playerFaction.GetAffiliatedFaction())
741  return false;
742 
743  return (playerFaction.GetAffiliatedFaction() == vehicleFaction.GetAffiliatedFaction());
744  }
745 
746  //------------------------------------------------------------------------------------------------
747  // !
748  protected void UpdateVolumeBarValue()
749  {
750  if ( m_wVolumeBar && m_pItem )
751  {
752  BaseInventoryStorageComponent pStorage = GetAsStorage();
753  if ( !pStorage )
754  return;
755 
756  string name = "";
757  if ( pStorage.GetAttributes() && pStorage.GetAttributes().GetUIInfo() )
758  {
759  name = pStorage.GetAttributes().GetUIInfo().GetName();
760  }
761 
762  float fOccupied = 0.0;
763  //TODO: The folowing part needs refactor! This enumeration of attached storages is used on more places.
764  if ( pStorage.Type() == ClothNodeStorageComponent )
765  {
766  array<BaseInventoryStorageComponent> pOwnedStorages = new array<BaseInventoryStorageComponent>();
767  pStorage.GetOwnedStorages( pOwnedStorages, 1, false );
768  foreach ( BaseInventoryStorageComponent pSubStorage : pOwnedStorages )
769  fOccupied += pSubStorage.GetOccupiedSpace();
770  }
771  else
772  {
773  fOccupied = pStorage.GetOccupiedSpace();
774  }
775  float fCapacity = pStorage.GetMaxVolumeCapacity();
776  m_wVolumeBar.SetMax( fCapacity );
777  m_wVolumeBar.SetCurrent( fOccupied );
778 
779  }
780  }
781 
782  //------------------------------------------------------------------------------------------------
783  protected void UpdateAmmoCount()
784  {
785  if ( m_eSlotFunction != ESlotFunction.TYPE_MAGAZINE )
786  return;
787  if( !m_pItem )
788  return;
789 
790  if ( m_aAmmoCountActual > -1 && m_aAmmoCountMax != 1 )
791  {
792  m_wAmmoCount.SetMax( m_aAmmoCountMax );
793  m_wAmmoCount.SetCurrent( m_aAmmoCountActual );
794  m_wAmmoCount.SetVisible( true );
795  }
796  else
797  {
798  m_wAmmoCount.SetVisible( false );
799  }
800  }
801 
802  //------------------------------------------------------------------------------------------------
804  int GetAmmoCount() { return m_aAmmoCountActual; }
805 
806  //------------------------------------------------------------------------------------------------
807  protected void UpdateStackNumber()
808  {
809  if ( !m_wStackNumber )
810  return;
811 
812  m_wStackNumber.SetVisible(m_iStackNumber > 1);
813  m_wStackNumber.SetText( m_iStackNumber.ToString() );
814  }
815 
816  //------------------------------------------------------------------------------------------------
817  protected void UpdateWeaponAmmoCount()
818  {
819  if (!m_pItem)
820  return;
821  if (!m_wMagazineNumber)
822  return;
823  // Check if the storage is vicinity. We don't want to display ammo counts for weapons that are on the ground.
824  if (SCR_InventoryStorageLootUI.Cast(GetStorageUI()))
825  return;
826  BaseWeaponComponent weaponComp = BaseWeaponComponent.Cast( m_pItem.GetOwner().FindComponent( BaseWeaponComponent ) );
827  if (!weaponComp)
828  return;
829  BaseMuzzleComponent weaponMuzzleComp = weaponComp.GetCurrentMuzzle();
830  if (!weaponMuzzleComp)
831  return;
832 
833  int currentAmmoCount = weaponMuzzleComp.GetAmmoCount();
834  int maxAmmoCount = weaponMuzzleComp.GetMaxAmmoCount();
835  int magazineCount = GetInventoryManager().GetMagazineCountByWeapon(weaponComp);
836 
837  m_wMagazineNumber.SetText("+" + magazineCount);
838 
839  m_wCurrentMagazineAmmoCount.SetMax(maxAmmoCount);
840  m_wCurrentMagazineAmmoCount.SetCurrent(currentAmmoCount);
841 
842  m_wMagazineNumber.SetVisible(true);
843  m_wCurrentMagazineAmmoCount.SetVisible(true);
844 
845  if (currentAmmoCount > 0 && magazineCount == 0)
846  {
847  m_wCurrentMagazineAmmoCount.SetColorInt( CURRENT_AMMO_MAGAZINE );
848  m_wMagazineNumber.SetOpacity( 0 );
849  }
850  else if (currentAmmoCount == 0 && magazineCount == 0)
851  {
852  m_wMagazineNumber.SetColorInt( CURRENT_AMMO_EMPTY );
853  m_wMagazineNumber.SetOpacity( 1 );
854 
855  m_wCurrentMagazineAmmoCount.SetColorInt( CURRENT_AMMO_EMPTY );
856  m_wCurrentMagazineAmmoCount.SetCurrent( maxAmmoCount );
857  m_wCurrentMagazineAmmoCount.SetOpacity( CURRENT_AMMO_OPACITY );
858  }
859  else
860  {
861  m_wMagazineNumber.SetColorInt( CURRENT_AMMO_TEXT );
862  m_wMagazineNumber.SetOpacity( 1 );
863 
864  m_wCurrentMagazineAmmoCount.SetColorInt( CURRENT_AMMO_MAGAZINE );
865  m_wCurrentMagazineAmmoCount.SetOpacity( CURRENT_AMMO_OPACITY );
866  }
867  }
868 
869  //------------------------------------------------------------------------------------------------
870  void Refresh()
871  {
872  UpdateVolumeBarValue();
873  UpdateStackNumber();
874  UpdateAmmoCount();
875  UpdateWeaponAmmoCount();
876  }
877 
878 
879  //------------------------------------------------------------------------------------------------
881  void Destroy()
882  {
883  if (m_pStorageUI.GetInventoryMenuHandler())
884  m_pStorageUI.GetInventoryMenuHandler().UnregisterUIStorage( this );
885 
886  m_widget.RemoveHandler( this );
887  m_widget.RemoveFromHierarchy();
888  if (m_wPreviewImage)
889  {
890  ItemPreviewManagerEntity manager = m_pStorageUI.GetInventoryMenuHandler().GetItemPreviewManager();
891  if (manager)
892  {
893  ItemPreviewWidget renderPreview = ItemPreviewWidget.Cast( m_wPreviewImage );
894  if (renderPreview)
895  manager.SetPreviewItem(renderPreview, null);
896  }
897  }
898  }
899 
900  //------------------------------------------------------------------------------------------------
901  void OnChangeLockState()
902  {
903  if (!m_pItem)
904  return;
905 
906  if (m_wItemLockThrobber)
907  m_wItemLockThrobber.SetVisible(m_pItem.IsLocked());
908  }
909 
910  //------------------------------------------------------------------------------------------------
911  void SetSelectedQuickSlot( bool select )
912  {
913  m_bSelected = select;
914  if (!m_wSelectedEffect || !m_wSelectedIcon)
915  return;
916  m_wSelectedEffect.SetVisible( select );
917  m_wSelectedIcon.SetVisible(false);
918  }
919 
920  //------------------------------------------------------------------------------------------------
921  ECommonItemType GetCommonItemType()
922  {
923  if ( !m_Attributes )
924  return ECommonItemType.NONE;
925  return m_Attributes.GetCommonType();
926  }
927 
928  //------------------------------------------------------------------------------------------------
929 
930 
931  //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
932 
933  //------------------------------------------------------------------------------------------------
934  override bool OnSelect(Widget w, int x, int y)
935  {
936  //GetGame().GetWorkspace().SetFocusedWidget(w);
937  //w.SetOpacity( );
938  return false;
939  }
940 
941  //------------------------------------------------------------------------------------------------
942  override bool OnFocus(Widget w, int x, int y)
943  {
944  OnSlotFocused();
945  return false;
946  }
947 
948  //------------------------------------------------------------------------------------------------
949  override bool OnFocusLost(Widget w, int x, int y)
950  {
951  OnSlotFocusLost();
952  return false;
953  }
954 
955  //------------------------------------------------------------------------------------------------
956  override bool OnChange(Widget w, int x, int y, bool finished)
957  {
958  ClearItemDetails();
959  return false;
960  }
961  /*
962  //------------------------------------------------------------------------------------------------
963  override bool OnMouseButtonDown( Widget w, int x, int y, int button )
964  {
965  m_mouseButtonDown = true;
966  PrintFormat( "INV: widget: %1, ( %2, %3 ), button: %4 DOWN", w, x, y, button );
967  return false;
968  }
969 
970  //------------------------------------------------------------------------------------------------
971  override bool OnMouseButtonUp( Widget w, int x, int y, int button )
972  {
973  m_mouseButtonDown = false;
974  PrintFormat( "INV: widget: %1, ( %2, %3 ), button: %4 UP", w, x, y, button );
975  return false;
976  }
977  */
978 
979  //------------------------------------------------------------------------------------------------
980  Widget GetWidget() { return m_widget; }
981 
982  //------------------------------------------------------------------------------------------------
983  int GetColumnSize() { return m_iSizeX; }
984 
985  //------------------------------------------------------------------------------------------------
986  int GetRowSize() { return m_iSizeY; }
987 
988  //------------------------------------------------------------------------------------------------
989  void SetSlotSize( ESlotSize slotSize) { m_ESlotSize = slotSize; }
990 
991  //------------------------------------------------------------------------------------------------
992  ESlotSize GetSlotSize() { return m_ESlotSize; }
993 
994  //------------------------------------------------------------------------------------------------
995  void SetPage( int iPage ) { m_iPage = iPage; }
996 
997  //------------------------------------------------------------------------------------------------
998  int GetPage() { return m_iPage; }
999 
1000  //------------------------------------------------------------------------------------------------
1002  ESlotFunction GetSlotedItemFunction() { return m_eSlotFunction; }
1003 
1004  //------------------------------------------------------------------------------------------------
1005  void SetIcon( ResourceName texture )
1006  {
1007  m_wIcon = ImageWidget.Cast( m_widget.FindAnyWidget( "icon" ) );
1008  if ( !m_wIcon )
1009  return;
1010  m_wIcon.LoadImageTexture( 0, texture );
1011  m_wIcon.SetVisible( true );
1012  }
1013 
1014  //------------------------------------------------------------------------------------------------
1015  override void HandlerAttached( Widget w )
1016  {
1017  Init();
1018  }
1019 
1020  //------------------------------------------------------------------------------------------------
1021  ResourceName GetItemResource()
1022  {
1023  if (!m_pItem)
1024  return ResourceName.Empty;
1025  return m_pItem.GetOwner().GetPrefabData().GetPrefabName();
1026  }
1027 
1028  //------------------------------------------------------------------------------------------------
1029  bool IsStacked()
1030  {
1031  return (m_iStackNumber > 1);
1032  }
1033 
1034  //------------------------------------------------------------------------------------------------
1035  void SCR_InventorySlotUI( InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null )
1036  {
1037  m_pStorageUI = pStorageUI;
1038  m_bVisible = bVisible;
1039  m_iQuickSlotIndex = iSlotIndex;
1040  m_Attributes = pAttributes;
1041  UpdateReferencedComponent( pComponent );
1042  }
1043 
1044  //------------------------------------------------------------------------------------------------
1045  void ~SCR_InventorySlotUI()
1046  {
1047  }
1048 
1049  //------------------------------------------------------------------------------------------------
1050  override void HandlerDeattached(Widget w)
1051  {
1052  super.HandlerDeattached(w);
1053 
1054  if (m_FuelManager && m_wFuelCount)
1055  m_FuelManager.GetOnFuelChanged().Remove(OnFuelAmountChanged);
1056  }
1057 };
ChimeraWorld
Definition: ChimeraWorld.c:12
TYPE_STORAGE
@ TYPE_STORAGE
Definition: SCR_InventorySlotUI.c:20
m_wIcon
protected ImageWidget m_wIcon
Definition: SCR_InventoryHitZonePointUI.c:374
m_Attributes
private SCR_ItemAttributeCollection m_Attributes
Definition: SCR_UniversalInventoryStorageComponent.c:23
SCR_InventoryStorageLootUI
Definition: SCR_InventoryStorageLootUI.c:4
CURRENT_AMMO_TEXT
const int CURRENT_AMMO_TEXT
Definition: SCR_InventorySlotUI.c:7
InventoryStorageSlot
Definition: InventoryStorageSlot.c:12
BUTTON_OPACITY_ENABLED
const float BUTTON_OPACITY_ENABLED
Definition: InventoryConstants.c:49
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
UIInfo
UIInfo - declare object, allows to define UI elements.
Definition: UIInfo.c:13
ECommonItemType
ECommonItemType
Definition: InventoryConstants.c:30
CURRENT_AMMO_EMPTY
const int CURRENT_AMMO_EMPTY
Definition: SCR_InventorySlotUI.c:8
TYPE_CLOTHES
@ TYPE_CLOTHES
Definition: SCR_InventorySlotUI.c:21
SCR_VehicleDamageManagerComponent
void SCR_VehicleDamageManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_VehicleDamageManagerComponent.c:1720
SLOT_LAYOUT_2x2
const string SLOT_LAYOUT_2x2
Definition: SCR_InventorySlotUI.c:3
SLOT_LAYOUT_3x3
const string SLOT_LAYOUT_3x3
Definition: SCR_InventorySlotUI.c:4
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
CURRENT_AMMO_OPACITY
const float CURRENT_AMMO_OPACITY
Definition: SCR_InventorySlotUI.c:10
SCR_InventoryVehicleVisibilityAttribute
Definition: SCR_InventoryVehicleVisibilityAttribute.c:2
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
m_iSizeY
int m_iSizeY
Definition: SCR_MapRTWBaseUI.c:6
SCR_InventoryUIInfo
Definition: SCR_InventoryUIInfo.c:2
m_FuelManager
protected FuelManagerComponent m_FuelManager
Definition: SCR_VehicleDamageManagerComponent.c:215
BUTTON_OPACITY_DISABLED
const float BUTTON_OPACITY_DISABLED
Definition: InventoryConstants.c:48
SCR_ButtonComponent
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
Definition: SCR_ButtonComponent.c:4
Attribute
typedef Attribute
Post-process effect of scripted camera.
BaseWeaponComponent
Definition: BaseWeaponComponent.c:12
ESlotSize
ESlotSize
Definition: InventoryConstants.c:1
m_iPage
protected int m_iPage
Definition: BanCommands.c:54
SCR_InventoryMenuUI
Definition: SCR_InventoryMenuUI.c:247
GetControlledEntity
SCR_EditableEntityComponent GetControlledEntity()
Returns the controlled entity or null if none.
Definition: SCR_EditablePlayerDelegateComponent.c:86
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
SCR_FuelManagerComponent
void SCR_FuelManagerComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_FuelManagerComponent.c:475
TYPE_CONSUMABLE
@ TYPE_CONSUMABLE
Definition: SCR_InventorySlotUI.c:19
m_iSizeX
int m_iSizeX
Definition: SCR_MapRTWBaseUI.c:3
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
TYPE_GADGET
@ TYPE_GADGET
Definition: SCR_InventorySlotUI.c:17
m_bSelected
protected bool m_bSelected
Definition: SCR_InventoryHitZonePointUI.c:396
ItemPreviewWidget
Definition: ItemPreviewWidget.c:12
SLOT_LAYOUT_1x1
const string SLOT_LAYOUT_1x1
Definition: SCR_InventorySlotUI.c:1
m_bEnabled
private bool m_bEnabled
Definition: SCR_BaseManualCameraComponent.c:3
BaseLoadoutClothComponent
Definition: BaseLoadoutClothComponent.c:12
ESlotFunction
ESlotFunction
Definition: SCR_InventorySlotUI.c:12
LoadoutAreaType
Definition: LoadoutAreaType.c:12
m_bVisible
protected bool m_bVisible
Definition: SCR_UITaskManagerComponent.c:28
BaseMuzzleComponent
Definition: BaseMuzzleComponent.c:12
TYPE_GENERIC
@ TYPE_GENERIC
Definition: SCR_InventorySlotUI.c:14
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27
TYPE_WEAPON
@ TYPE_WEAPON
Definition: SCR_InventorySlotUI.c:16
SLOT_LAYOUT_2x1
const string SLOT_LAYOUT_2x1
Definition: SCR_InventorySlotUI.c:2
CURRENT_AMMO_MAGAZINE
const int CURRENT_AMMO_MAGAZINE
Definition: SCR_InventorySlotUI.c:6
TYPE_MAGAZINE
@ TYPE_MAGAZINE
Definition: SCR_InventorySlotUI.c:15
m_wButton
protected ButtonWidget m_wButton
Definition: SCR_InventoryHitZonePointUI.c:393
TYPE_HEALTH
@ TYPE_HEALTH
Definition: SCR_InventorySlotUI.c:18