Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventoryStorageQuickSlotsUI.c
Go to the documentation of this file.
1
2//------------------------------------------------------------------------------------------------
5
7{
9 protected static int s_iLastSelectedSlotIndex;
10 protected static int s_iInitSelectedSlotIndex;
11 protected static bool s_bQuickBarClosed;
12 protected static const float s_fEnabledOpacity = 1;
13 protected static const float s_fDisabledOpacity = 0.35;
14
15
16 protected ResourceName m_sGamepadIcons = "{F7FD1672FECA05E8}UI/Textures/Icons/icons_gamepad_64.imageset";
17 //------------------------------------------- USER METHODS -----------------------------------------------------
18
19 //------------------------------------------------------------------------------------------------
20 // !
21 override void InitPaging() { return; }
22
23 //------------------------------------------------------------------------------------------------
24 // !
25 void HighlightSlot(int iSlotIndex, bool bHighlight)
26 {
27 if ( m_aSlots.IsEmpty() || iSlotIndex == -1 )
28 return;
29
31 m_pLastSelectedSlot.SetSelected(false);
32
34 if ( iSlotIndex > m_aSlots.Count() - 1 )
35 return;
36
37 m_pSelectedSlot = m_aSlots.Get( iSlotIndex );
38 if ( !m_pSelectedSlot )
39 return;
40
41 m_pSelectedSlot.SetSelectedQuickSlot( bHighlight );
43 }
44
45 //------------------------------------------------------------------------------------------------
46 // !
47 void SelectSlot( float fWheelValue )
48 {
49 if ( fWheelValue == 0 )
50 return;
51
52 if ( m_aSlots.IsEmpty() )
53 return;
54
55 if ( fWheelValue == 1 )
56 fWheelValue = -1; //in case it's controler dpad uses
57
59 {
60 if (fWheelValue > 0)
62 else
64
65 }
66 else
67 {
68 if (m_pInputManager.IsUsingMouseAndKeyboard() && s_iLastSelectedSlotIndex < 0)
70 //PrintFormat( "INV: index to deselect: %1 | m_aSlotsCount: %2", s_iLastSelectedSlotIndex, m_aSlots.Count() );
72 if (fWheelValue > 0)
73 {
74 if (m_pInputManager.IsUsingMouseAndKeyboard())
76 else
77 s_iLastSelectedSlotIndex = ( s_iLastSelectedSlotIndex - 1 ) % ( m_aSlots.Count() ); //version for cyclic rotation through the items in slots
78 }
79 else
80 {
81 if (m_pInputManager.IsUsingMouseAndKeyboard())
83 else
84 s_iLastSelectedSlotIndex = ( s_iLastSelectedSlotIndex + 1 ) % ( m_aSlots.Count() ); //version for cyclic rotation through the items in slots
85 }
86
87
88 //if ( ) //version for cyclic rotation through the items in slots
89 //PrintFormat( "INV: index to select: %1 | m_aSlotsCount: %2", s_iLastSelectedSlotIndex, m_aSlots.Count() );
90
91 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_SCROLL);
92 }
94 }
95
96
97 //------------------------------------------------------------------------------------------------
98 // !
99 void SelectSlot( int iSlotIndex )
100 {
101 HighlightSlot( iSlotIndex, true );
102
103 if (s_iLastSelectedSlotIndex == iSlotIndex)
104 UseItemInSlot(false);
105
106 s_iLastSelectedSlotIndex = iSlotIndex;
107 }
108
109 //------------------------------------------------------------------------------------------------
110 // ! Hide all, but actual slot
112 {
113 foreach ( SCR_InventorySlotUI pSlot : m_aSlots )
114 {
115 if ( pSlot && pSlot != m_pSelectedSlot )
116 pSlot.SetSlotVisible( false );
117 }
118 }
119
120 //------------------------------------------------------------------------------------------------
121 // !
122 override protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
123 {
124 int count = pItemsInStorage.Count();
126 count = Math.Min(count, 3); // todo: get this from radial menu config
127
128 if (count < m_aSlots.Count())
129 {
130 for (int i = m_aSlots.Count() - count; i > 0; i--)
131 {
132 auto slotUI = m_aSlots[m_aSlots.Count() - 1];
133 if (slotUI)
134 slotUI.Destroy();
135 }
136
137 }
138
139 m_aSlots.Resize(count);
140 for (int i = 0; i < count; i++)
141 {
142 InventoryItemComponent pComponent = GetItemComponentFromEntity( pItemsInStorage[i] );
143 if (m_aSlots[i])
144 m_aSlots[i].UpdateReferencedComponent(pComponent);
145 else
146 m_aSlots[i] = CreateSlotUI(pComponent, i);
147 }
149 }
150
151 //------------------------------------------------------------------------------------------------
152 // !
153 override protected void GetAllItems( out notnull array<IEntity> pItemsInStorage, BaseInventoryStorageComponent pStorage = null )
154 {
155 if (!m_Player)
156 return;
157
158 array<ref SCR_QuickslotBaseContainer> quickslots = m_InventoryStorage.GetQuickSlotItems();
159
160 if (!m_InventoryStorage || !quickslots)
161 return;
162
163 pItemsInStorage.Clear();
164 SCR_QuickslotEntityContainer entityContainer;
165 foreach (SCR_QuickslotBaseContainer container : quickslots)
166 {
167 entityContainer = SCR_QuickslotEntityContainer.Cast(container);
168 if (!entityContainer)
169 {
170 pItemsInStorage.Insert(null); //we insert null here because previous implementation expected whole array even with nulls to be copied over
171 continue;
172 }
173
174 pItemsInStorage.Insert(entityContainer.GetEntity());
175
176 }
177 //pItemsInStorage.Copy( m_InventoryStorage.GetQuickSlotItems() );
178 }
179
180 //------------------------------------------------------------------------------------------------
181 // !
182 override protected int CreateSlots()
183 {
184 array<IEntity> itemsInStorage = {};
185 GetAllItems(itemsInStorage);
186 UpdateOwnedSlots(itemsInStorage);
188 return 0;
189 }
190
191 //------------------------------------------------------------------------------------------------
192 // ! creates the the grid from array of UI items
193 override protected void SortSlots()
194 {
195 array<int> aCoordinates;
196 int iWidgetColumnSize, iWidgetRowSize;
197 const int iPageCounter = 0; // TODO: check for good const usage
198 int iRelativeOffset = 0; // if there's an item taking more than one slot, offset the following items to the right
199
200 //reset all elements to 0 - free it
201 m_iMatrix.Reset();
202
203 foreach ( SCR_InventorySlotUI pSlot: m_aSlots )
204 {
205 if( !pSlot )
206 continue;
207 Widget w = pSlot.GetWidget();
208 if( !w )
209 continue;
210
211 iWidgetColumnSize = pSlot.GetColumnSize();
212 iWidgetRowSize = pSlot.GetRowSize();
213
214 int iCol = pSlot.GetSlotIndex() + iRelativeOffset;
215 m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
216 GridSlot.SetColumn( w, iCol );
217 iRelativeOffset += ( iWidgetColumnSize - 1 );
218 GridSlot.SetRow( w, 0 );
219 pSlot.SetPage( iPageCounter );
220
221 GridSlot.SetColumnSpan( w, iWidgetColumnSize );
222 GridSlot.SetRowSpan( w, iWidgetRowSize );
223 }
224 m_iNrOfPages = iPageCounter + 1;
227 }
228
229 //------------------------------------------------------------------------------------------------
231 {
232 if (!player)
233 return;
235 if (!storageComponent)
236 return;
237
238 SCR_QuickslotBaseContainer quickslotContainer;
239
240 foreach (int iIndex, SCR_InventorySlotUI pSlot: m_aSlots)
241 {
242 if(!pSlot)
243 continue;
244
245 Widget w = pSlot.GetWidget();
246 if(!w)
247 continue;
248
249 //yes this sadly has to be there as long as the first four quickslots are not the same as the rest of them
250 if (pSlot.GetSlotIndex() > 3)
251 {
252 quickslotContainer = storageComponent.GetContainerFromQuickslot(pSlot.GetSlotIndex());
253 if (!quickslotContainer)
254 {
255 continue;
256 }
257
258 if (!quickslotContainer.IsQuickslotActionAvailable())
259 w.SetOpacity(s_fDisabledOpacity);
260 else
261 w.SetOpacity(s_fEnabledOpacity);
262 }
263 else
264 {
265 if (!pSlot.GetInventoryItemComponent())
266 w.SetOpacity(s_fDisabledOpacity);
267
268 if (!pSlot.CanUseItem(m_Player))
269 w.SetOpacity(s_fDisabledOpacity);
270 else
271 w.SetOpacity(s_fEnabledOpacity);
272 }
273 }
274 }
275
276 //------------------------------------------------------------------------------------------------
277 override void FillWithEmptySlots()
278 {
279 int iWidgetColumnSize, iWidgetRowSize;
280 int iRelativeOffset = 0; //if there's an item taking more than one slot, offset the following items to the right
281 int i = 0;
282
283 foreach ( int iIndex, SCR_InventorySlotUI pSlot: m_aSlots )
284 {
285 if( !pSlot ) //if pSlot doesn't exist it means no assigned item in this slot and we create the "empty" slot
286 {
287 ESlotSize eSlotSize;
288 if ( iIndex > 1 )
289 eSlotSize = ESlotSize.SLOT_1x1;
290 else
291 eSlotSize = ESlotSize.SLOT_2x1; //first 2 slots are dedicated to weapons ( thus 2x1 layout)
292
294 pAttrib.SetSlotType( ESlotID.SLOT_ANY );
295 pAttrib.SetSlotSize( eSlotSize );
296 pSlot = CreateSlotUI( null, iIndex, pAttrib );
297 m_aSlots.Set( iIndex, pSlot );
298 }
299 Widget w = pSlot.GetWidget();
300 if( !w )
301 continue;
302
303 iWidgetColumnSize = pSlot.GetColumnSize();
304 iWidgetRowSize = pSlot.GetRowSize();
305
306 int iCol = i + iRelativeOffset;
307 m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
308 GridSlot.SetColumn( w, iCol );
309 GridSlot.SetRow( w, 0 );
310
311 if (GetInventoryMenuHandler() && iIndex < SCR_InventoryMenuUI.WEAPON_SLOTS_COUNT)
312 {
313 pSlot.SetSlotVisible(false);
314 i = 0;
315 }
316 else
317 {
318 iRelativeOffset += iWidgetColumnSize - 1;
319 i++;
320 }
321
322 GridSlot.SetColumnSpan( w, iWidgetColumnSize );
323 GridSlot.SetRowSpan( w, iWidgetRowSize );
324 }
325 }
326
327 //------------------------------------------------------------------------------------------------
328 void SetItem( InventoryItemComponent pInventoryComponent, int iSlotIndex )
329 {
330 m_aSlots.InsertAt( CreateSlotUI( pInventoryComponent ), iSlotIndex );
331 }
332
333 //------------------------------------------------------------------------------------------------
334 // ! creates the slot
335 protected SCR_InventorySlotQuickSlotUI CreateSlotUI( InventoryItemComponent pComponent, int iSlotIndex, SCR_ItemAttributeCollection pAttributes = null )
336 {
337 return SCR_InventorySlotQuickSlotUI( pComponent, this, true, iSlotIndex, pAttributes ); //creates the slot
338 }
339
340 //------------------------------------------------------------------------------------------------
341 override void SetRowsAndColumns()
342 {
343 // leave this empty because we need to initialize rows and columns in different place
344 }
345
346 //------------------------------------------------------------------------------------------------
347 // param[in] isClosingQuickSlots If true, it means that the unselected Quick Slots will be hidden
348 bool UseItemInSlot(bool isClosingQuickSlots)
349 {
350 if (!m_pSelectedSlot)
351 return false;
352
353 if (isClosingQuickSlots)
355
356 bool useItem = true;
358 {
360 s_bQuickBarClosed = false;
361 }
362
363 if (useItem)
364 {
366 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_CONFIRM);
367 }
368 else
369 {
370 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_HOTKEY_CLOSE);
371 }
372
373 return true;
374 }
375
376 //------------------------------------------------------------------------------------------------
378 {
379 if (!m_Player)
380 return;
381
382 SCR_CharacterControllerComponent characterController = SCR_CharacterControllerComponent.Cast(m_Player.GetCharacterController());
383 if (!characterController)
384 return;
385
386 SCR_InventoryStorageManagerComponent storageManager = SCR_InventoryStorageManagerComponent.Cast(characterController.GetInventoryStorageManager());
387 if (!storageManager)
388 return;
389
390 SCR_CharacterInventoryStorageComponent characterStorage = storageManager.GetCharacterStorage();
391 if (!characterStorage)
392 return;
393
394 array<ref SCR_QuickslotBaseContainer> quickslotItems = {};
395 quickslotItems = characterStorage.GetQuickSlotItems();
396 SCR_QuickslotBaseContainer container = quickslotItems.Get(s_iLastSelectedSlotIndex);
397 if (!container)
398 return;
399
400 //a bit hardcoded solution for now to perserve old functionality with items
401 SCR_QuickslotEntityContainer entityContainer = SCR_QuickslotEntityContainer.Cast(container);
402 if (entityContainer)
403 {
404 entityContainer.ActivateContainer(m_pSelectedSlot, m_Player);
405 return;
406 }
407
408 container.ActivateContainer();
409 }
410
411 //------------------------------------------------------------------------------------------------
413 {
414 IEntity currentItem = m_InventoryStorage.GetSelectedItem();
415 if (!currentItem)
416 {
419 return;
420 }
421
422 array<IEntity> items = m_InventoryStorage.GetQuickSlotEntitiesOnly();
423 foreach (int i, IEntity item : items)
424 {
425 if (item != currentItem)
426 continue;
427
431 return;
432 }
433 }
434
435 //------------------------------------------------------------------------------------------------
437 {
438 s_bQuickBarClosed = true;
439 }
440
441 //------------------------------------------------------------------------------------------------
442 override void Init()
443 {
444 super.Init();
445 // s_iLastSelectedSlotIndex = -1;
446 }
447
448 //------------------------------------------------------------------------------------------------
450 {
453 }
454
455 //------------------------------------------------------------------------------------------------
457 {
458 CreateSlots();
459 InitMatrix();
460 SortSlots();
461 }
462
463 //------------------------------------------------------------------------------------------------
464 override void RefreshSlot(int index)
465 {
466 if (!m_aSlots.IsIndexValid(index))
467 return;
468
469 IEntity item = m_InventoryStorage.GetItemFromQuickSlot(index);
470 if (!item)
471 return;
472
474 if (!itemComp)
475 return;
476
477 SCR_ItemAttributeCollection attributes = SCR_ItemAttributeCollection.Cast(itemComp.GetAttributes());
478 m_aSlots[index].UpdateReferencedComponent(itemComp, attributes);
479 SortSlots();
480 }
481
482 //------------------------------------------------------------------------------------------------
484 {
485 int result = 0;
486 int slotCount = m_aSlots.Count();
488 for (int id = 0; id < slotCount; ++id)
489 {
490 if (GetInventoryMenuHandler() && id < SCR_InventoryMenuUI.WEAPON_SLOTS_COUNT)
491 continue;
492
493 slot = m_aSlots[id];
494 if (slot)
495 {
496 result += slot.GetColumnSize();
497 }
498 else
499 {
500 if (id < 2) // first two doubleslots reserved for weapons
501 {
502 result += ESlotSize.SLOT_2x1;
503 }
504 else
505 {
506 result += ESlotSize.SLOT_1x1;
507 }
508 }
509 }
510
511 return result;
512 }
513
514 //------------------------------------------------------------------------------------------------
516 {
517 if (!m_wGrid)
518 return;
519
523
524 for (int y = 0; y < m_iMaxRows; ++y)
525 {
526 m_wGrid.SetRowFillWeight(y, 1);
527 for (int x = 0; x < m_iMaxColumns; ++x)
528 {
529 m_wGrid.SetColumnFillWeight(x, 1);
530 }
531 }
532
533 SizeLayoutWidget wSizeContainer = SizeLayoutWidget.Cast(m_widget.FindAnyWidget("SizeLayout0"));
534 if (wSizeContainer)
535 wSizeContainer.SetAspectRatio(m_iMaxColumns / m_iMaxRows);
536 }
537
538 //------------------------------------------------------------------------------------------------
543
552
553 //------------------------------------------------------------------------------------------------
558
559 //------------------------------------------------------------------------------------------------
564
565 //------------------------------------------- COMMON METHODS -----------------------------------------------------
566
567 //------------------------------------------------------------------------------------------------
568 override void HandlerAttached( Widget w )
569 {
570 super.HandlerAttached( w );
571 RefreshList();
572 }
573
574 //------------------------------------------------------------------------------------------------
575 void SCR_InventoryStorageQuickSlotsUI( BaseInventoryStorageComponent storage, LoadoutAreaType slotID = null, SCR_InventoryMenuUI menuManager = null, int iPage = 0, array<BaseInventoryStorageComponent> aTraverseStorage = null )
576 {
577 m_Storage = null; // quick slots don't use any storage. They will get m_aQuickSlotItems from CharacterInventoryStorageManager
578 //m_MenuHandler = menuManager;
579 m_eSlotAreaType = null;
580 m_iMaxRows = 1;
581 m_iMaxColumns = 0;
582 m_iLastShownPage = iPage;
583 }
584}
AddonBuildInfoTool id
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_QuickslotEntityContainer(IEntity entity)
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
array< ref SCR_QuickslotBaseContainer > GetQuickSlotItems()
SCR_QuickslotBaseContainer GetContainerFromQuickslot(int index)
InventoryItemComponent GetInventoryItemComponent()
SCR_CharacterInventoryStorageComponent m_InventoryStorage
ref array< SCR_InventorySlotUI > m_aSlots
void CreateEmptyLayout(bool recreate=false)
void SCR_InventoryStorageBaseUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID=null, SCR_InventoryMenuUI menuManager=null, int iPage=0, array< BaseInventoryStorageComponent > aTraverseStorage=null)
InventoryItemComponent GetItemComponentFromEntity(IEntity pEntity)
BaseInventoryStorageComponent m_Storage
SCR_InventorySlotQuickSlotUI CreateSlotUI(InventoryItemComponent pComponent, int iSlotIndex, SCR_ItemAttributeCollection pAttributes=null)
void UpdateOwnedSlots(notnull array< IEntity > pItemsInStorage)
void GetAllItems(out notnull array< IEntity > pItemsInStorage, BaseInventoryStorageComponent pStorage=null)
void SCR_InventoryStorageQuickSlotsUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID=null, SCR_InventoryMenuUI menuManager=null, int iPage=0, array< BaseInventoryStorageComponent > aTraverseStorage=null)
void SetItem(InventoryItemComponent pInventoryComponent, int iSlotIndex)
void HighlightSlot(int iSlotIndex, bool bHighlight)
SCR_QuickslotBaseContainer is intended to be used for quickslots, to allow quickslotting of non-item ...
void ActivateContainer()
Gets called when the quickslot with this container is activated.
bool IsQuickslotActionAvailable()
returns true if the containers action can be performed