Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InventoryStorageQuickSlotsUI.c
Go to the documentation of this file.
1 
2 //------------------------------------------------------------------------------------------------
5 
7 {
8  protected SCR_InventorySlotUI m_pLastSelectedSlot;
9  protected static int s_iLastSelectedSlotIndex;
10  protected static int s_iInitSelectedSlotIndex;
11  protected static bool s_bQuickBarClosed;
12 
13  protected ResourceName m_sGamepadIcons = "{F7FD1672FECA05E8}UI/Textures/Icons/icons_gamepad_64.imageset";
14  //------------------------------------------- USER METHODS -----------------------------------------------------
15 
16 
17  //------------------------------------------------------------------------------------------------
18  // !
19  override void InitPaging() { return; }
20 
21  //------------------------------------------------------------------------------------------------
22  // !
23  protected void HighlightSlot( int iSlotIndex, bool bHighlight )
24  {
25  if ( m_aSlots.IsEmpty() || iSlotIndex == -1 )
26  return;
27 
28  if (m_pLastSelectedSlot)
29  m_pLastSelectedSlot.SetSelected(false);
30 
31  m_pLastSelectedSlot = m_pSelectedSlot;
32  if ( iSlotIndex > m_aSlots.Count() - 1 )
33  return;
34  m_pSelectedSlot = m_aSlots.Get( iSlotIndex );
35  if ( !m_pSelectedSlot )
36  return;
37 
38  m_pSelectedSlot.SetSelectedQuickSlot( bHighlight );
39  CheckIfQuickSlotActionsAvailable(m_Player);
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  // !
44  void SelectSlot( float fWheelValue )
45  {
46  if ( fWheelValue == 0 )
47  return;
48 
49  if ( m_aSlots.IsEmpty() )
50  return;
51 
52  if ( fWheelValue == 1 )
53  fWheelValue = -1; //in case it's controler dpad uses
54 
55  if ( s_iLastSelectedSlotIndex < 0 )
56  {
57  if (fWheelValue > 0)
58  s_iLastSelectedSlotIndex = m_aSlots.Count() - 1;
59  else
60  s_iLastSelectedSlotIndex = 0;
61 
62  }
63  else
64  {
65  if (m_pInputManager.IsUsingMouseAndKeyboard() && s_iLastSelectedSlotIndex < 0)
66  s_iLastSelectedSlotIndex = m_aSlots.Count()-1;
67  //PrintFormat( "INV: index to deselect: %1 | m_aSlotsCount: %2", s_iLastSelectedSlotIndex, m_aSlots.Count() );
68  HighlightSlot( s_iLastSelectedSlotIndex, false );
69  if (fWheelValue > 0)
70  {
71  if (m_pInputManager.IsUsingMouseAndKeyboard())
72  s_iLastSelectedSlotIndex = Math.Max( ( s_iLastSelectedSlotIndex - 1 ), 0 );
73  else
74  s_iLastSelectedSlotIndex = ( s_iLastSelectedSlotIndex - 1 ) % ( m_aSlots.Count() ); //version for cyclic rotation through the items in slots
75  }
76  else
77  {
78  if (m_pInputManager.IsUsingMouseAndKeyboard())
79  s_iLastSelectedSlotIndex = Math.Min( ( s_iLastSelectedSlotIndex + 1 ), m_aSlots.Count()-1 );
80  else
81  s_iLastSelectedSlotIndex = ( s_iLastSelectedSlotIndex + 1 ) % ( m_aSlots.Count() ); //version for cyclic rotation through the items in slots
82  }
83 
84 
85  //if ( ) //version for cyclic rotation through the items in slots
86  //PrintFormat( "INV: index to select: %1 | m_aSlotsCount: %2", s_iLastSelectedSlotIndex, m_aSlots.Count() );
87 
88  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_SCROLL);
89  }
90  HighlightSlot( s_iLastSelectedSlotIndex, true );
91  }
92 
93 
94  //------------------------------------------------------------------------------------------------
95  // !
96  void SelectSlot( int iSlotIndex )
97  {
98  HighlightSlot( iSlotIndex, true );
99  s_iLastSelectedSlotIndex = iSlotIndex;
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  // ! Hide all, but actual slot
104  void FilterOutSlots()
105  {
106  foreach ( SCR_InventorySlotUI pSlot : m_aSlots )
107  {
108  if ( pSlot && pSlot != m_pSelectedSlot )
109  pSlot.SetSlotVisible( false );
110  }
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  // !
115  override protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
116  {
117  int count = pItemsInStorage.Count();
118  if (!GetGame().GetInputManager().IsUsingMouseAndKeyboard() && !m_MenuHandler)
119  count = Math.Min(count, 4); // todo: get this from radial menu config
120 
121  if (count < m_aSlots.Count())
122  {
123  for (int i = m_aSlots.Count() - count; i > 0; i--)
124  {
125  auto slotUI = m_aSlots[m_aSlots.Count() - 1];
126  if (slotUI)
127  slotUI.Destroy();
128  }
129 
130  }
131 
132  m_aSlots.Resize(count);
133  for (int i = 0; i < count; i++)
134  {
135  InventoryItemComponent pComponent = GetItemComponentFromEntity( pItemsInStorage[i] );
136  if (m_aSlots[i])
137  m_aSlots[i].UpdateReferencedComponent(pComponent);
138  else
139  m_aSlots[i] = CreateSlotUI(pComponent, i);
140  }
141  CheckIfQuickSlotActionsAvailable(m_Player);
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  // !
146  override protected void GetAllItems( out notnull array<IEntity> pItemsInStorage, BaseInventoryStorageComponent pStorage = null )
147  {
148  if (!m_Player)
149  return;
150 
151  if ( m_InventoryStorage && m_InventoryStorage.GetQuickSlotItems() )
152  pItemsInStorage.Copy( m_InventoryStorage.GetQuickSlotItems() );
153  }
154 
155  //------------------------------------------------------------------------------------------------
156  // !
157  override protected int CreateSlots()
158  {
159  array<IEntity> itemsInStorage = {};
160  GetAllItems(itemsInStorage);
161  UpdateOwnedSlots(itemsInStorage);
162  CheckIfQuickSlotActionsAvailable(m_Player);
163  return 0;
164  }
165 
166  //------------------------------------------------------------------------------------------------
167  // ! creates the the grid from array of UI items
168  override protected void SortSlots()
169  {
170  array<int> aCoordinates;
171  int iWidgetColumnSize, iWidgetRowSize;
172  int iPageCounter = 0;
173  int iRelativeOffset = 0; //if there's an item taking more than one slot, offset the following items to the right
174 
175  //reset all elements to 0 - free it
176  m_iMatrix.Reset();
177 
178  foreach ( SCR_InventorySlotUI pSlot: m_aSlots )
179  {
180  if( !pSlot )
181  continue;
182  Widget w = pSlot.GetWidget();
183  if( !w )
184  continue;
185 
186  iWidgetColumnSize = pSlot.GetColumnSize();
187  iWidgetRowSize = pSlot.GetRowSize();
188 
189  int iCol = pSlot.GetSlotIndex() + iRelativeOffset;
190  m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
191  GridSlot.SetColumn( w, iCol );
192  iRelativeOffset += ( iWidgetColumnSize - 1 );
193  GridSlot.SetRow( w, 0 );
194  pSlot.SetPage( iPageCounter );
195 
196  GridSlot.SetColumnSpan( w, iWidgetColumnSize );
197  GridSlot.SetRowSpan( w, iWidgetRowSize );
198  }
199  m_iNrOfPages = iPageCounter + 1;
200  FillWithEmptySlots();
201  CheckIfQuickSlotActionsAvailable(m_Player);
202  }
203 
204  //------------------------------------------------------------------------------------------------
205  protected void CheckIfQuickSlotActionsAvailable(IEntity player)
206  {
207  foreach (int iIndex, SCR_InventorySlotUI pSlot: m_aSlots)
208  {
209  if(!pSlot)
210  continue;
211 
212  Widget w = pSlot.GetWidget();
213  if(!w)
214  continue;
215 
216  if (!pSlot.GetInventoryItemComponent())
217  w.SetOpacity(0.35);
218 
219  if (!pSlot.CanUseItem(m_Player))
220  w.SetOpacity(0.35);
221  else
222  w.SetOpacity(1);
223  }
224  }
225 
226  //------------------------------------------------------------------------------------------------
227  override void FillWithEmptySlots()
228  {
229  array<int> aCoordinates;
230  int iWidgetColumnSize, iWidgetRowSize;
231  int iPageCounter = 0;
232  int iRelativeOffset = 0; //if there's an item taking more than one slot, offset the following items to the right
233  int i = 0;
234 
235  foreach ( int iIndex, SCR_InventorySlotUI pSlot: m_aSlots )
236  {
237  if( !pSlot ) //if pSlot doesn't exist it means no assigned item in this slot and we create the "empty" slot
238  {
239  ESlotSize eSlotSize;
240  if ( iIndex > 1 )
241  eSlotSize = ESlotSize.SLOT_1x1;
242  else
243  eSlotSize = ESlotSize.SLOT_2x1; //first 2 slots are dedicated to weapons ( thus 2x1 layout)
244 
246  pAttrib.SetSlotType( ESlotID.SLOT_ANY );
247  pAttrib.SetSlotSize( eSlotSize );
248  pSlot = SCR_InventorySlotQuickSlotUI.Cast( CreateSlotUI( null, iIndex, pAttrib ) );
249  m_aSlots.Set( iIndex, pSlot );
250  }
251  Widget w = pSlot.GetWidget();
252  if( !w )
253  continue;
254 
255  iWidgetColumnSize = pSlot.GetColumnSize();
256  iWidgetRowSize = pSlot.GetRowSize();
257 
258  int iCol = i + iRelativeOffset;
259  m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
260  GridSlot.SetColumn( w, iCol );
261  GridSlot.SetRow( w, 0 );
262 
263  if (GetInventoryMenuHandler() && iIndex < SCR_InventoryMenuUI.WEAPON_SLOTS_COUNT)
264  {
265  pSlot.SetSlotVisible(false);
266  i = 0;
267  }
268  else
269  {
270  iRelativeOffset += iWidgetColumnSize - 1;
271  i++;
272  }
273 
274  GridSlot.SetColumnSpan( w, iWidgetColumnSize );
275  GridSlot.SetRowSpan( w, iWidgetRowSize );
276  }
277  }
278 
279  //------------------------------------------------------------------------------------------------
280  void SetItem( InventoryItemComponent pInventoryComponent, int iSlotIndex )
281  {
282  m_aSlots.InsertAt( CreateSlotUI( pInventoryComponent ), iSlotIndex );
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  // ! creates the slot
287  protected SCR_InventorySlotQuickSlotUI CreateSlotUI( InventoryItemComponent pComponent, int iSlotIndex, SCR_ItemAttributeCollection pAttributes = null )
288  {
289  return SCR_InventorySlotQuickSlotUI( pComponent, this, true, iSlotIndex, pAttributes ); //creates the slot
290  }
291 
292  //------------------------------------------------------------------------------------------------
293  override void SetRowsAndColumns()
294  {
295  // leave this empty because we need to initialize rows and columns in different place
296  }
297 
298  //------------------------------------------------------------------------------------------------
299  bool UseItemInSlot()
300  {
301  if (!m_pSelectedSlot)
302  return false;
303  FilterOutSlots();
304 
305  bool useItem = true;
306  if (s_bQuickBarClosed)
307  {
308  useItem = (s_iInitSelectedSlotIndex != s_iLastSelectedSlotIndex);
309  s_bQuickBarClosed = false;
310  }
311 
312  if (useItem)
313  {
314  m_pSelectedSlot.UseItem(m_Player);
315  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_CONFIRM);
316  }
317  else
318  {
319  SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_CLOSE);
320  }
321 
322  return true;
323  }
324 
325  //------------------------------------------------------------------------------------------------
326  void SetInitialQuickSlot()
327  {
328  IEntity currentItem = m_InventoryStorage.GetSelectedItem();
329  if (!currentItem)
330  s_iInitSelectedSlotIndex = -1;
331 
332  array<IEntity> items = m_InventoryStorage.GetQuickSlotItems();
333  foreach (int i, IEntity item : items)
334  {
335  if (item != currentItem)
336  continue;
337 
338  s_iInitSelectedSlotIndex = i;
339  SelectSlot(s_iInitSelectedSlotIndex);
340  return;
341  }
342  }
343 
344  //------------------------------------------------------------------------------------------------
345  void SetQuickBarClosed()
346  {
347  s_bQuickBarClosed = true;
348  }
349 
350  //------------------------------------------------------------------------------------------------
351  override void Init()
352  {
353  super.Init();
354  // s_iLastSelectedSlotIndex = -1;
355  }
356 
357  //------------------------------------------------------------------------------------------------
358  void RefreshList()
359  {
360  CreateEmptyLayout();
361  RefreshQuickSlots();
362  }
363 
364  //------------------------------------------------------------------------------------------------
365  void RefreshQuickSlots()
366  {
367  CreateSlots();
368  InitMatrix();
369  SortSlots();
370  }
371 
372  //------------------------------------------------------------------------------------------------
373  override void RefreshSlot(int index)
374  {
375  if (!m_aSlots.IsIndexValid(index))
376  return;
377 
378  IEntity item = m_InventoryStorage.GetItemFromQuickSlot(index);
379  if (!item)
380  return;
381 
382  InventoryItemComponent itemComp = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
383  if (!itemComp)
384  return;
385 
386  SCR_ItemAttributeCollection attributes = SCR_ItemAttributeCollection.Cast(itemComp.GetAttributes());
387  m_aSlots[index].UpdateReferencedComponent(itemComp, attributes);
388  SortSlots();
389  }
390 
391  //------------------------------------------------------------------------------------------------
392  int GetActualSlotsUsedCount()
393  {
394  int result = 0;
395  int slotCount = m_aSlots.Count();
396  SCR_InventorySlotUI slot;
397  for (int id = 0; id < slotCount; ++id)
398  {
399  if (GetInventoryMenuHandler() && id < SCR_InventoryMenuUI.WEAPON_SLOTS_COUNT)
400  continue;
401 
402  slot = m_aSlots[id];
403  if (slot)
404  {
405  result += slot.GetColumnSize();
406  }
407  else
408  {
409  if (id < 2) // first two doubleslots reserved for weapons
410  {
411  result += ESlotSize.SLOT_2x1;
412  }
413  else
414  {
415  result += ESlotSize.SLOT_1x1;
416  }
417  }
418  }
419 
420  return result;
421  }
422 
423  //------------------------------------------------------------------------------------------------
424  void InitMatrix()
425  {
426  if (!m_wGrid)
427  return;
428 
429  m_iMaxColumns = GetActualSlotsUsedCount();
430  m_iMatrix = new SCR_Matrix(m_iMaxColumns, m_iMaxRows);
431  m_iPageSize = m_iMaxRows * m_iMaxColumns;
432 
433  for (int y = 0; y < m_iMaxRows; ++y)
434  {
435  m_wGrid.SetRowFillWeight(y, 1);
436  for (int x = 0; x < m_iMaxColumns; ++x)
437  {
438  m_wGrid.SetColumnFillWeight(x, 1);
439  }
440  }
441 
442  SizeLayoutWidget wSizeContainer = SizeLayoutWidget.Cast(m_widget.FindAnyWidget("SizeLayout0"));
443  if (wSizeContainer)
444  wSizeContainer.SetAspectRatio(m_iMaxColumns / m_iMaxRows);
445  }
446 
447  //------------------------------------------------------------------------------------------------
448  ResourceName GetGamepadIcons()
449  {
450  return m_sGamepadIcons;
451  }
452 
453  InventoryItemComponent GetCurrentSlotItem()
454  {
455  SCR_InventorySlotUI slot = m_aSlots.Get(s_iLastSelectedSlotIndex);
456  if (!slot.GetInventoryItemComponent())
457  return null;
458 
459  return slot.GetInventoryItemComponent();
460  }
461 
462  //------------------------------------------------------------------------------------------------
463  void HighlightLastSelectedSlot()
464  {
465  SelectSlot(s_iLastSelectedSlotIndex);
466  }
467 
468  //------------------------------------------- COMMON METHODS -----------------------------------------------------
469 
470  //------------------------------------------------------------------------------------------------
471  override void HandlerAttached( Widget w )
472  {
473  super.HandlerAttached( w );
474  RefreshList();
475  }
476 
477  //------------------------------------------------------------------------------------------------
478  void SCR_InventoryStorageQuickSlotsUI( BaseInventoryStorageComponent storage, LoadoutAreaType slotID = null, SCR_InventoryMenuUI menuManager = null, int iPage = 0, array<BaseInventoryStorageComponent> aTraverseStorage = null )
479  {
480  m_Storage = null; // quick slots don't use any storage. They will get m_aQuickSlotItems from CharacterInventoryStorageManager
481  //m_MenuHandler = menuManager;
482  m_eSlotAreaType = null;
483  m_iMaxRows = 1;
484  m_iMaxColumns = 0;
485  m_iLastShownPage = iPage;
486  }
487 };
ESlotID
ESlotID
Definition: InventoryConstants.c:14
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
m_Player
protected ChimeraCharacter m_Player
Definition: SCR_CampaignTutorialComponentArland.c:40
ESlotSize
ESlotSize
Definition: InventoryConstants.c:1
SCR_InventorySlotQuickSlotUI
Definition: SCR_InventorySlotQuickSlotUI.c:4
m_aSlots
protected ref array< SCR_WeaponRackSlotEntity > m_aSlots
Definition: SCR_ArsenalDisplayComponent.c:13
SCR_InventoryMenuUI
Definition: SCR_InventoryMenuUI.c:247
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
SCR_Matrix
Definition: SCR_Matrix.c:2
SCR_InventoryStorageQuickSlotsUI
Definition: SCR_InventoryStorageQuickSlotsUI.c:6
LoadoutAreaType
Definition: LoadoutAreaType.c:12
m_MenuHandler
SCR_DeployMenuBase m_MenuHandler
Main deploy menu with the map present.
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27
m_Storage
BaseInventoryStorageComponent m_Storage
Definition: SCR_TourniquetStorageComponent.c:10