Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventoryStorageBaseUI.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
2
5
7{
9
10 const float STORAGE_NON_HIGHLIGHTED_OPACITY = 0.35;
11 const string ARSENAL_TITLE_LAYOUT = "{E668FD2152D06CF9}UI/layouts/Menus/Inventory/ArsenalInventoryTraverseTitlePanel.layout";
12 const string SUPPLY_TITLE_LAYOUT = "{4CAAD8087F93ABE6}UI/layouts/Menus/Inventory/SupplyInventoryTraverseTitlePanel.layout";
13 const string GENERIC_CONTAINER_PREFAB = "{9F0C54A3740F7FC9}Prefabs/Props/Military/SupplyBox/SupplyPortableContainers/SupplyPortableContainer_01/SupplyContainerGeneric.et";
14 const string STORAGE_TITLE_LAYOUT = "{1E788C30AF7F76E9}UI/layouts/Menus/Inventory/InventoryTraverseTitlePanel.layout";
15 const string SLOT_LAYOUT_1x1_EMPTY = "{B11F8BE49DFB62A2}UI/layouts/Menus/Inventory/Inventory20Slot_1x1_empty.layout";
16 protected const int SLOT_LAYOUT_WIDTH = 66;
18 protected SCR_InventoryStorageManagerComponent m_InventoryManager; //manager - handles all the adding / removing operations
19 protected SCR_CharacterInventoryStorageComponent m_InventoryStorage; //top-most character's inventory component
21 protected BaseInventoryStorageComponent m_Storage; //linked storage
22 protected SCR_ResourceComponent m_ResourceComponent;
23 protected SCR_ResourceConsumer m_ResourceConsumer;
25 protected ref array<SCR_InventorySlotUI> m_aSlots = {};
26 protected ref array<Widget> m_aEmptySlotWidget;
30 protected SCR_InventorySlotUI m_pLastFocusedSlot = null; //memorize the last focused slot before leaving the actual UI storage
31
33 protected Widget m_widget = null;
34 protected GridLayoutWidget m_wGrid; //non-uniform grid
35 protected string m_sGridPath = "GridLayout0";
38 protected bool m_bEnabled = false; //if it is enabled for manipulation ( can be removed or an item can be moved into )
39 protected bool m_bSelected = false;
40 protected bool m_bShown = true;
41 protected bool m_bIsArsenal;
44
45 protected ref SCR_Matrix m_iMatrix;
47 //protected int m_iPage = 0;
48 protected int m_iNrOfPages = 0;
52 protected int m_iLastShownPage = 0;
54 protected ref array<BaseInventoryStorageComponent> m_aTraverseStorage = {};
55 protected ref array<Widget> m_aTraverseTitle = {};
56 protected ref array<SCR_ResourceComponent> m_aResourceCompsInStorage = {};
59
60 protected LocalizedString m_sSuppliesStoredFormat = "#AR-Campaign_BaseSuppliesAmount";
61 protected LocalizedString m_sSuppliesAvailableFormat = "#AR-Supplies_Arsenal_Availability";
65 protected static const ref Color m_WeightDefault = new Color(0.73, 0.73, 0.73, 1);
66
67 protected static ref ScriptInvokerVoid s_OnArsenalEnter;
68 //------------------------------------------------------------------------ USER METHODS ------------------------------------------------------------------------
69
70 //------------------------------------------------------------------------------------------------
78
79 //------------------------------------------------------------------------------------------------
84
85 //------------------------------------------------------------------------------------------------
86 void Init()
87 {
88 m_pInputManager = GetGame().GetInputManager();
89 //get the workspace
90 if ( m_workspaceWidget == null )
91 m_workspaceWidget = GetGame().GetWorkspace();
92
93 //Get player
94 // TODO: make it independent on player ( might be used for example in editor to change the loadout of a character )
95 PlayerController pPlayerController = GetGame().GetPlayerController();
96 if( !pPlayerController )
97 return;
98 m_Player = ChimeraCharacter.Cast(pPlayerController.GetControlledEntity());
99 if( !m_Player )
100 return;
101
102 //Get inventory manager and the actual character's topmost storage
103 m_InventoryManager = SCR_InventoryStorageManagerComponent.Cast( m_Player.FindComponent( SCR_InventoryStorageManagerComponent ) );
105 m_wGrid = GridLayoutWidget.Cast( m_widget.FindAnyWidget( m_sGridPath ) );
106 m_wStorageName = TextWidget.Cast( m_widget.FindAnyWidget( "StorageName" ) );
107 m_wItemStorage = ItemPreviewWidget.Cast( m_widget.FindAnyWidget( "itemStorage" ) );
108 m_wCapacityPercentageText = TextWidget.Cast(m_widget.FindAnyWidget("CapacityPercentageText"));
109 m_wWeightText = TextWidget.Cast(m_widget.FindAnyWidget("WeightText"));
110 m_wWeightDisplay = m_widget.FindAnyWidget("Weight");
111 m_wWidthOverride = SizeLayoutWidget.Cast(m_widget.FindWidget("TitleWidthOverride"));
112 m_wWarningOverlay = m_widget.FindAnyWidget("WarningOverlay");;
113
115 m_wWeightDisplay.SetVisible(true);
116
117 m_wProgressBar = m_widget.FindAnyWidget("ProgressBar");
118 if (m_wProgressBar)
119 {
121 m_wProgressBar.SetVisible(true);
122 }
123
124 InitPaging();
126
127 //Set the proper ratio according to the number of columns and rows
128 SizeLayoutWidget wSizeContainer = SizeLayoutWidget.Cast( m_widget.FindAnyWidget( "SizeLayout0" ) );
129 if ( wSizeContainer )
130 wSizeContainer.SetAspectRatio( m_iMaxColumns / m_iMaxRows );
131
134
135 //Get the storage the UI container will be showing the content from
137 m_Storage = m_InventoryStorage.GetStorageFromLoadoutSlot( m_eSlotAreaType );
138 if (!m_Storage)
139 m_Storage = m_InventoryStorage.GetWeaponStorage();
140 if (!m_Storage)
141 return;
142
144 {
146 {
147
148 m_wCapacityDisplay.SetVisible(true);
150 }
151
152 m_wWeightDisplay.SetVisible(true);
154 }
155
157 if (!m_wStorageName)
158 return;
159 ItemAttributeCollection attributes = m_Storage.GetAttributes();
160 if (!attributes)
161 return;
162 UIInfo uiInfo = attributes.GetUIInfo();
163 if (!uiInfo)
164 return;
165 m_wStorageName.SetText(uiInfo.GetName());
166
167 m_wResourceStoredDisplay = m_widget.FindAnyWidget("ResourceDisplayStored");
169 m_wResourceStoredText = TextWidget.Cast(m_wResourceStoredDisplay.FindAnyWidget("ResourceText"));
170
171 m_wResourceAvailableDisplay = m_widget.FindAnyWidget("ResourceDisplayAvailable");
173 m_wResourceAvailableText = TextWidget.Cast(m_wResourceAvailableDisplay.FindAnyWidget("ResourceText"));
174
176 return;
177
178 //~ Will ignore storage components of vehicle slots if they already have a storage assigned
179 if (m_Storage && m_Storage.GetOwner())
180 m_ResourceComponent = SCR_ResourceComponent.FindResourceComponent(m_Storage.GetOwner(), true);
181
184
186 return;
187
189
190 if (!resourceInventoryPlayerComponent)
191 return;
192
193 m_ResourceComponent.TEMP_GetOnInteractorReplicated().Insert(RefreshConsumer);
194
195 RplId resourceInventoryPlayerComponentRplId = Replication.FindItemId(resourceInventoryPlayerComponent);
196
197 if (!resourceInventoryPlayerComponentRplId.IsValid())
198 return;
199
200 m_ResourceSubscriptionHandleConsumer = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandle(m_ResourceConsumer, resourceInventoryPlayerComponentRplId);
201 }
202
203 //------------------------------------------------------------------------------------------------
205 {
207 {
210 {
211 m_wPagingSpinboxComponent.SetPageCount( 0 );
212 m_wPagingSpinboxComponent.SetCurrentItem( 0, false );
213 m_wPagingSpinboxComponent.SetButtonsActive(false);
214 SetPagingActive(false);
215 }
216
217 }
218 }
219
220 //------------------------------------------------------------------------------------------------
222 {
223 return m_bIsArsenal;
224 }
225
226 //------------------------------------------------------------------------------------------------
227 void SetPagingActive(bool active)
228 {
230 return;
231
232 m_wPagingSpinboxComponent.m_OnChanged.Remove(Action_ChangePage);
233 if (active)
234 m_wPagingSpinboxComponent.m_OnChanged.Insert(Action_ChangePage);
235
236 m_wPagingSpinboxComponent.SetButtonsActive(active);
237 m_wPagingSpinboxComponent.SetButtonsVisible(active);
238 }
239
240 //------------------------------------------------------------------------------------------------
241 override bool OnFocus( Widget w, int x, int y )
242 {
243 if ( m_MenuHandler )
244 m_MenuHandler.OnContainerHovered( this );
245 return false;
246 }
247
248 //------------------------------------------------------------------------------------------------
249 override bool OnFocusLost( Widget w, int x, int y )
250 {
251 if ( m_MenuHandler )
252 m_MenuHandler.OnContainerLeft( this );
253 return false;
254 }
255
256 //------------------------------------------------------------------------------------------------
257 override bool OnMouseEnter(Widget w, int x, int y)
258 {
259 if ( m_MenuHandler )
260 m_MenuHandler.OnContainerHovered( this );
261
262 return false;
263 }
264
265 //------------------------------------------------------------------------------------------------
266 override bool OnMouseLeave( Widget w, Widget enterW, int x, int y)
267 {
268 if (enterW && w && w.FindAnyWidget(enterW.GetName()))
269 return false;
270
271 if ( m_MenuHandler )
272 m_MenuHandler.OnContainerLeft( this );
273
274 return false;
275 }
276
278 {
279 return false;
280 }
281/*
282 override bool OnUpdate(Widget w)
283 {
284 Widget w2 = w;
285 PrintFormat( "INV: widget: %1", WidgetManager.GetWidgetUnderCursor() );
286 return false;
287 }
288*/
289
290 //------------------------------------------------------------------------------------------------
292 {
293 for ( int m = 0; m < m_iMaxRows; m++ )
294 {
295 m_wGrid.SetRowFillWeight( m, 0 );
296 for ( int n = 0; n < m_iMaxColumns; n++ )
297 {
298 m_wGrid.SetColumnFillWeight( n, 0 );
299 }
300 }
301 }
302
303 //------------------------------------------------------------------------------------------------
304 private BaseInventoryStorageComponent PushState(BaseInventoryStorageComponent storage)
305 {
306 m_aTraverseStorage.Insert(storage);
307 return storage;
308 }
309
310 //------------------------------------------------------------------------------------------------
311 private BaseInventoryStorageComponent PopState(int traverseStorageIndex)
312 {
313 if ( m_aTraverseStorage.IsEmpty() )
314 return null;
315
316 if ( traverseStorageIndex == -1 )
317 return null;
318
319 for ( int i = m_aTraverseStorage.Count() - 1; i >= traverseStorageIndex; --i)
320 {
321 m_aTraverseStorage.Remove(i);
322 if (m_aTraverseStorage.IsEmpty())
323 return null;
324 }
325 return m_aTraverseStorage[ m_aTraverseStorage.Count() - 1 ];
326 }
327
328 //------------------------------------------------------------------------------------------------
329 BaseInventoryStorageComponent GetCurrentNavigationStorage()
330 {
331 if (m_aTraverseStorage.Count() > 0)
332 {
333 return m_aTraverseStorage[m_aTraverseStorage.Count() - 1];
334 }
335 return m_Storage;
336 }
337
338 //------------------------------------------------------------------------------------------------
339 bool IsTraversalAllowed()
340 {
341 return true;
342 }
343
344 //------------------------------------------------------------------------------------------------
345 void Traverse(BaseInventoryStorageComponent storage)
346 {
347 DeleteSlots();
348 PushState( storage );
349 FillItemsFromStorage( storage );
350 SortSlots();
351 ShowPage( 0 );
352
353 //play open sound
354 if (!m_aTraverseStorage.Find(storage))
355 {
356 IEntity entity = storage.GetOwner();
357 m_InventoryManager.PlayItemSound(entity, SCR_SoundEvent.SOUND_CONTAINER_OPEN);
358 }
359
360 SCR_InventoryMenuUI inventoryMenu = GetInventoryMenuHandler();
361 if (inventoryMenu)
362 inventoryMenu.OpenLinkedStorages(storage, false);
363 }
364
365 //------------------------------------------------------------------------------------------------
366 void Back(int traverseStorageIndex)
367 {
368 DeleteSlots();
369
370 BaseInventoryStorageComponent lastStorage = m_aTraverseStorage.Get(traverseStorageIndex);
371 if (lastStorage)
372 {
373 //play CLOSE sound
374 IEntity entity = lastStorage.GetOwner();
375 m_InventoryManager.PlayItemSound(entity, SCR_SoundEvent.SOUND_CONTAINER_CLOSE);
376
377 //~ Close any linked storages
378 SCR_InventoryMenuUI inventoryMenu = GetInventoryMenuHandler();
379 if (inventoryMenu)
380 inventoryMenu.CloseLinkedStorages(lastStorage);
381 }
382
383 auto storage = PopState( traverseStorageIndex );
384
385 if (!storage)
386 {
387 Home();
388 return;
389 }
390
391 FillItemsFromStorage( storage );
392 SortSlots();
393 ShowPage( 0 );
394 }
395
396 //------------------------------------------------------------------------------------------------
397 void Home()
398 {
399 DeleteSlots();
400 m_aTraverseStorage.Clear();
402 CreateSlots();
403 SortSlots();
404 ShowPage(0);
405 }
406
407 //------------------------------------------------------------------------------------------------
408 float GetTotalResources(notnull SCR_ResourceConsumer resourceContainer)
409 {
410 return resourceContainer.GetAggregatedResourceValue();
411 }
412
413 //------------------------------------------------------------------------------------------------
414 float GetMaxResources(notnull SCR_ResourceConsumer resourceContainer)
415 {
416 return resourceContainer.GetAggregatedMaxResourceValue();
417 }
418
419 //------------------------------------------------------------------------------------------------
420 void GetTraverseStorage( out notnull array<BaseInventoryStorageComponent> aTraverseStorage )
421 {
422 aTraverseStorage.Copy( m_aTraverseStorage );
423 }
424
425 //---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
426 //------------------------------------------------------------------------------------------------
427 void Action_ChangePage( SCR_SpinBoxPagingComponent pSpinBox, int page )
428 {
429 int slotToFocus = -1;
430
431 SortSlots();
432 ShowPage(m_wPagingSpinboxComponent.GetCurrentIndex(), slotToFocus);
433
434 GetGame().GetCallqueue().CallLater(m_MenuHandler.FocusOnSlotInStorage, 0, false, this, slotToFocus); // call later, otherwise ShowPage() would get triggered again right away
435 }
436
437 //------------------------------------------------------------------------------------------------
438 void Action_PrevPage()
439 {
440 int slotToFocus = -1;
441
442 SortSlots();
443 ShowPage(m_iLastShownPage - 1, slotToFocus);
444
445 GetGame().GetCallqueue().CallLater(m_MenuHandler.FocusOnSlotInStorage, 0, false, this, slotToFocus); // call later, otherwise ShowPage() would get triggered again right away
446 }
447 //------------------------------------------------------------------------------------------------
448 void Action_NextPage()
449 {
450 int slotToFocus = -1;
451
452 SortSlots();
453 ShowPage(m_iLastShownPage + 1, slotToFocus);
454
455 GetGame().GetCallqueue().CallLater(m_MenuHandler.FocusOnSlotInStorage, 0, false, this, slotToFocus); // call later, otherwise ShowPage() would get triggered again right away
456 }
457 //---- REFACTOR NOTE END ----
458
459 //------------------------------------------------------------------------------------------------
460 bool IsStorageEnabled() { return m_bEnabled; }
461 //------------------------------------------------------------------------------------------------
462 bool IsStorageSelected() { return m_bSelected; }
463 //------------------------------------------------------------------------------------------------
464 bool GetLastShownPage() { return m_iLastShownPage; }
465 //------------------------------------------------------------------------------------------------
466 int GetPageCount() { return m_iNrOfPages; }
467
468 //------------------------------------------------------------------------------------------------
469 BaseInventoryStorageComponent GetStorage() { return m_Storage; }
470
471 //------------------------------------------------------------------------------------------------
472 EquipedWeaponStorageComponent GetWeaponStorage() { return EquipedWeaponStorageComponent.Cast( m_Storage ); }
473
474 //------------------------------------------------------------------------------------------------
475 string GetStorageName()
476 {
477 ItemAttributeCollection attributes = m_Storage.GetAttributes();
478 if( !attributes )
479 return "none";
480 UIInfo uiInfo = attributes.GetUIInfo();
481 if( !uiInfo )
482 return "none";
483 return uiInfo.GetName();
484 }
485
486 //------------------------------------------------------------------------------------------------
487 // !
488 SCR_InventorySlotUI GetSelectedSlot() { return m_pSelectedSlot; }
489 SCR_InventorySlotUI GetPrevSelectedSlot() { return m_pPrevSelectedSlot; }
490
491 //------------------------------------------------------------------------------------------------
492 // ! Hides / unhides the storage container
493 void Show( bool bShow )
494 {
495 /* Enable to have the expand / collapse feature
496 m_bShown = bShow;
497 m_wGrid.SetVisible( m_bShown );
498 if ( m_bShown )
499 {
500 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_CONTAINER_OPEN, true);
501 m_InventoryStorage.SetStorageAsShown( m_Storage );
502 if ( m_iNrOfPages > 1 && m_wPagingSpinboxComponent )
503 {
504 ShowPagesCounter( true, 0, m_iNrOfPages );
505 }
506 }
507 else
508 {
509 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_INV_CONTAINER_CLOSE, true);
510 m_InventoryStorage.SetStorageAsHidden( m_Storage );
511 ShowPagesCounter( false );
512 }
513 */
514 }
515
516 //------------------------------------------------------------------------------------------------
517 // ! Hides / unhides the storage container
518 void ToggleShow()
519 {
520 Show( !m_bShown );
521 }
522
523
524 //------------------------------------------------------------------------------------------------
525 // !
526 SCR_InventorySlotUI GetFocusedSlot() { return m_pFocusedSlot; }
527
528 //------------------------------------------------------------------------------------------------
529 // !
530 SCR_InventorySlotUI GetLastFocusedSlot() { return m_pLastFocusedSlot; }
531
532 //------------------------------------------------------------------------------------------------
533 // ! returns the grid widget of the storage
534 Widget GetStorageGrid() { return m_wGrid; }
535 //------------------------------------------------------------------------------------------------
536 // ! returns the root widget
537 Widget GetRootWidget() { return m_widget; }
538
539 //------------------------------------------------------------------------------------------------
540 // ! returns the inventory menu handler
541 SCR_InventoryMenuUI GetInventoryMenuHandler() { return m_MenuHandler; }
542
543 //------------------------------------------------------------------------------------------------
544 SCR_InventoryStorageManagerComponent GetInventoryManager() { return m_InventoryManager; }
545
546 //------------------------------------------------------------------------------------------------
547 // ! set the slot id of the storage the content will be shown from
548 protected void SetSlotAreaType( LoadoutAreaType eSlotType ) { m_eSlotAreaType = eSlotType; }
549
550 //------------------------------------------------------------------------------------------------
551 // !
553
554 //------------------------------------------------------------------------------------------------
555 // !
556 void GetUISlots( out array<SCR_InventorySlotUI> outArray)
557 {
558 outArray.Copy( m_aSlots );
559 }
560
561 //------------------------------------------------------------------------------------------------
562 // !
563 array<SCR_InventorySlotUI> GetUISlots()
564 {
565 return m_aSlots;
566 }
567
568 //------------------------------------------------------------------------------------------------
569 // !
571 {
572 m_aSlots.RemoveItem( pSlot );
573 SortSlots();
574 }
575
576 //------------------------------------------------------------------------------------------------
578
579 //------------------------------------------------------------------------------------------------
580 // ! creates empty slot - just visual of the matrix layout
581 protected Widget CreateEmptySlotUI( int iRow, int iCol )
582 {
583 Widget pWidget = m_workspaceWidget.CreateWidgets( SLOT_LAYOUT_1x1_EMPTY, m_wGrid );
584 GridSlot.SetColumn( pWidget, iCol );
585 GridSlot.SetRow( pWidget, iRow );
586 //SizeLayoutSlot.SetHorizontalAlign( pWidget, LayoutHorizontalAlign.Center );
587
588 return pWidget;
589 }
590
591 //------------------------------------------------------------------------------------------------
592 // ! creates the slot
594 {
595 if (!pComponent)
596 return new SCR_InventorySlotUI(null, this, false, -1, pAttributes);
597
598 if (WeaponAttachmentsStorageComponent.Cast(pComponent))
599 return new SCR_InventorySlotWeaponUI(pComponent, this, false); //creates the slot
600
601 if (SCR_ResourceComponent.FindResourceComponent(pComponent.GetOwner()))
602 return new SCR_SupplyInventorySlotUI(pComponent, this, false); //creates the slot
603
604 if (BaseInventoryStorageComponent.Cast(pComponent))
605 return new SCR_InventorySlotStorageEmbeddedUI(pComponent, this, false); //creates the slot
606
607 if (pComponent.GetOwner().FindComponent(SCR_ArsenalInventoryStorageManagerComponent))
608 {
609 SCR_ArsenalInventorySlotUI slotUI = new SCR_ArsenalInventorySlotUI(pComponent, this, false, -1, null);
610 BaseInventoryStorageComponent inventoryStorageComponent = GetCurrentNavigationStorage();
611
612 if (inventoryStorageComponent)
613 {
614 slotUI.SetArsenalResourceComponent(SCR_ResourceComponent.FindResourceComponent(inventoryStorageComponent.GetOwner()));
615 SCR_InventoryStorageBaseUI.ARSENAL_SLOT_STORAGES.Insert(slotUI, inventoryStorageComponent.GetOwner());
616 }
617
618 return slotUI;
619 }
620
621 return new SCR_InventorySlotUI(pComponent, this, false); //creates the slot
622 }
623
624 //------------------------------------------------------------------------------------------------
625 // !
626 protected void DeleteSlots()
627 {
628 foreach ( SCR_InventorySlotUI pSlot: m_aSlots )
629 {
630 if( pSlot )
631 {
632 pSlot.Destroy();
633 }
634
635 }
636 m_aSlots.Clear();
637 }
638
639 //------------------------------------------------------------------------------------------------
640 // !
641 private bool ValidateNavigationQueue()
642 {
643 int traverseSize = m_aTraverseStorage.Count();
644
645 if (traverseSize > 0)
646 {
647 BaseInventoryStorageComponent lastStorage = null;
648 ref array<IEntity> rootItems = new array<IEntity>();
649 GetAllItems(rootItems);
650
651 for (int i = 0; i < traverseSize; i++)
652 {
653 BaseInventoryStorageComponent current = m_aTraverseStorage[i];
654
655 if (!current)
656 break;
657 bool found = false;
658 for (int j = 0; j < rootItems.Count(); j++)
659 {
660 if (!rootItems[j])
661 continue;
662
663 auto storage = BaseInventoryStorageComponent.Cast(
664 rootItems[j].FindComponent(BaseInventoryStorageComponent)
665 );
666 if (!storage)
667 continue;
668 BaseInventoryStorageComponent parentStorage;
669 if ( current.GetParentSlot() )
670 parentStorage = current.GetParentSlot().GetStorage();
671
672 found = storage == current || parentStorage == storage;
673 if (found)
674 break;
675 }
676
677 if (!found)
678 break;
679
680
681 // Last storage in queue
682 if (i == traverseSize - 1)
683 {
684 lastStorage = current;
685 return true;
686 }
687
688 rootItems.Clear();
689 current.GetAll(rootItems);
690 }
691 return false;
692 }
693 return true;
694 }
695
696 //------------------------------------------------------------------------------------------------
697 protected void RefreshConsumer()
698 {
699 FindConsumer();
700 Refresh();
701 }
702
703 //------------------------------------------------------------------------------------------------
704 protected void FindConsumer()
705 {
706 m_ResourceConsumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, EResourceType.SUPPLIES);
707
709 m_ResourceConsumer = m_ResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, EResourceType.SUPPLIES);
710 }
711
712 //------------------------------------------------------------------------------------------------
714 {
716 {
717 float resources, maxResources;
718 bool hasStored = false;
719
720 //~ Display stored resources
721 if (SCR_ResourceSystemHelper.GetStoredAndMaxResources(m_ResourceComponent, resources, maxResources))
722 {
723 UpdateStoredResources(resources, maxResources);
724 hasStored = true;
725 m_wResourceStoredDisplay.SetVisible(true);
726 }
727 else
728 {
729 m_wResourceStoredDisplay.SetVisible(false);
730 }
731
732 //~ Display available resources
733 if (m_ResourceComponent.IsResourceTypeEnabled() && SCR_ResourceSystemHelper.GetAvailableResources(m_ResourceComponent, resources))
734 {
735 UpdateAvailableResources(resources, hasStored);
736 m_wResourceAvailableDisplay.SetVisible(true);
737 }
738 else
739 {
740 m_wResourceAvailableDisplay.SetVisible(false);
741 }
742
743 }
744 }
745
746 //------------------------------------------------------------------------------------------------
747 // !
748 void Refresh()
749 {
750 ResourceName focusedItemName;
751 if (m_pFocusedSlot)
752 {
753 focusedItemName = m_pFocusedSlot.GetItemResource(); // remember the slot which was in focus
754 }
755 else
756 {
757 SCR_InventorySlotUI focusedSlot = m_MenuHandler.GetCurrentlyFocusedSlot();
758 if (focusedSlot && m_aSlots.Contains(focusedSlot))
759 focusedItemName = focusedSlot.GetItemResource(); //if for some reason menu was focused on slot from this storage, and it didnt know, lets focus that slot
760 }
761
762 if ( ValidateNavigationQueue() )
763 {
764 int traverseSize = m_aTraverseStorage.Count();
765 if (traverseSize > 0)
766 {
768 FillItemsFromStorage(m_aTraverseStorage[traverseSize - 1]);
769 }
770 else
771 {
772 // Create root layout
773 CreateSlots();
774 }
775 }
776 else
777 {
779 m_aTraverseStorage.Clear();
781
782 // Create root layout
783 CreateSlots();
784 }
785 SortSlots();
787
788 if ( m_Storage )
789 {
792 }
793
794 array<IEntity> tmpAItemsInStorage = new array<IEntity>();
795 BaseInventoryStorageComponent tmpStorage = m_Storage;
796 GetAllItemsFromDepth( tmpAItemsInStorage );
797 m_Storage = tmpStorage;
798
800
801 if ( m_pSelectedSlot )
802 m_pSelectedSlot.Refresh();
803
804 array<IEntity> itemsInStorage = {};
805 GetAllItems(itemsInStorage); // Needs a better solution. Very wasteful.
808
809 if (focusedItemName.IsEmpty())
810 return;
811
812 foreach (int i, SCR_InventorySlotUI uiSlot : m_aSlots)
813 {
814 if (uiSlot && uiSlot.GetItemResource() == focusedItemName)
815 {
816 m_MenuHandler.FocusOnSlotInStorage(this, i);
817 return;
818 }
819 }
820
821 if (!m_aSlots.IsEmpty()) // if this container had a slot which was in focus, then despite the fact that specific prefab is not present, lets focus on something in here, in order to prevent focus being shifted onto a random spot in the inventory
822 m_MenuHandler.FocusOnSlotInStorage(this, 0);
823 }
824
825 //------------------------------------------------------------------------------------------------
826 protected void UpdateStoredResources(float totalResources, float maxResources)
827 {
829 return;
830
831 /*if (m_wWeightDisplay)
832 m_wWeightDisplay.SetVisible(false);
833 if (m_wCapacityDisplay)
834 m_wCapacityDisplay.SetVisible(false);*/
835
836 m_wResourceStoredText.SetTextFormat(m_sSuppliesStoredFormat, SCR_ResourceSystemHelper.SuppliesToString(totalResources), SCR_ResourceSystemHelper.SuppliesToString(maxResources));
837 }
838
839 //------------------------------------------------------------------------------------------------
840 protected void UpdateAvailableResources(float totalResources, bool hasStored)
841 {
843 return;
844
845 /*if (m_wWeightDisplay)
846 m_wWeightDisplay.SetVisible(false);
847 if (m_wCapacityDisplay)
848 m_wCapacityDisplay.SetVisible(false);*/
849
850 if (!hasStored)
851 m_wResourceAvailableText.SetTextFormat(m_sSuppliesAvailableFormat, SCR_ResourceSystemHelper.SuppliesToString(totalResources));
852 else
853 m_wResourceAvailableText.SetText(SCR_ResourceSystemHelper.SuppliesToString(totalResources));
854 }
855
856 //------------------------------------------------------------------------------------------------
857 protected void UpdateContainerResources(notnull Widget targetTitle, notnull BaseInventoryStorageComponent targetStorage)
858 {
859 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(targetStorage.GetOwner());
860 if(!resourceComponent)
861 return;
862
863 float totalResources, maxResources;
864
865 Widget resourceDisplay = targetTitle.FindAnyWidget("ResourceDisplayStored");
866 TextWidget resourceText;
867
868 if (resourceDisplay)
869 {
870 resourceText = TextWidget.Cast(resourceDisplay.FindAnyWidget("ResourceText"));
871
872 //~ Display stored resources
873 if (resourceText && SCR_ResourceSystemHelper.GetStoredAndMaxResources(resourceComponent, totalResources, maxResources))
874 {
875 resourceText.SetTextFormat(m_sSuppliesStoredFormat, SCR_ResourceSystemHelper.SuppliesToString(totalResources), SCR_ResourceSystemHelper.SuppliesToString(maxResources));
876 resourceDisplay.SetVisible(true);
877 }
878 else
879 {
880 resourceDisplay.SetVisible(false);
881 }
882 }
883
884 resourceDisplay = targetTitle.FindAnyWidget("ResourceDisplayAvailable");
885
886 if (resourceDisplay)
887 {
888 resourceText = TextWidget.Cast(resourceDisplay.FindAnyWidget("ResourceText"));
889
890 //~ Display available resources
891 if (resourceText && SCR_ResourceSystemHelper.GetAvailableResources(resourceComponent, totalResources) && resourceComponent.IsResourceTypeEnabled())
892 {
893 resourceText.SetTextFormat(m_sSuppliesAvailableFormat, SCR_ResourceSystemHelper.SuppliesToString(totalResources));
894 resourceDisplay.SetVisible(true);
895 return;
896 }
897 else
898 {
899 resourceDisplay.SetVisible(false);
900 }
901 }
902 }
903
904 protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
905 {
906 // TODO: optimize? ( the existing slots must be deleted. The previous algorithm doesn't work any more, since the number of slots is unknown due to the aggregation-stacking of the items of the same type )
907 DeleteSlots();
908
909 // number of items for which slots are not created, as they are part of the stack in a already exising slot
910 int iCompensationOffset = 0;
911 array<SCR_InventorySlotUI> slotsToUpdate = {};
912
915 RplComponent rplComp;
916 SCR_InventorySlotUI uiSlot;
917 foreach (int i, IEntity item : pItemsInStorage)
918 {
919 if (!item)
920 continue;
921
922 iic = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
923 if (!iic)
924 continue; // item in inventory without iic sounds like insanity but im not going to question safety
925
926 attributes = SCR_ItemAttributeCollection.Cast(iic.GetAttributes());
927 int slotId = -1;
928 if (attributes && attributes.IsStackable())
929 slotId = FindItem(iic);
930
931 if (slotId < 0)
932 {
933 uiSlot = CreateSlotUI(iic);
934 if (!uiSlot)
935 {
936 iCompensationOffset++;
937 continue;
938 }
939
940 if (i - iCompensationOffset > m_aSlots.Count() - 1) //if the item is not identical, create a new slow
941 m_aSlots.Insert(uiSlot);
942 else
943 m_aSlots[i - iCompensationOffset++] = uiSlot;
944
945 continue;
946 }
947
948 uiSlot = m_aSlots[slotId];
949 if (!uiSlot)
950 continue;
951
952 rplComp = RplComponent.Cast(item.FindComponent(RplComponent));
953 if (rplComp && uiSlot.IsInherited(SCR_SupplyInventorySlotUI))
954 {
955 uiSlot.IncreaseStackNumberWithRplId(rplComp.Id());
956 slotsToUpdate.Insert(uiSlot);
957 }
958 else
959 {
960 uiSlot.IncreaseStackNumber(); //if it exists, just increase the stacked number and don't create new slot
961 uiSlot.OverrideReferencedComponent(iic); // always point at the last item from the stack, to prevent tile from changing position when removing items
962 }
963
964 iCompensationOffset++;
965 }
966
967 foreach (SCR_InventorySlotUI slot : slotsToUpdate)
968 {
969 slot.OnOwnedSlotsUpdated();
970 }
971 }
972
973 //------------------------------------------------------------------------------------------------
974 void UpdateSlotUI(ResourceName itemPrefab)
975 {
976 array<IEntity> pItemsInStorage = {};
977
978 BaseInventoryStorageComponent storage = GetCurrentNavigationStorage();
979
980 GetAllItems(pItemsInStorage, storage);
981
990 foreach (int slotId, SCR_InventorySlotUI slot : m_aSlots)
991 {
992 if (slot.GetInventoryItemComponent().GetOwner().GetPrefabData().GetPrefabName() != itemPrefab)
993 continue;
994
995 changeMap.Set(slotId, new Tuple3<int, int, InventoryItemComponent>(slot.GetStackNumber(), 0, null));
996 }
997
1000 foreach (IEntity item : pItemsInStorage)
1001 {
1002 if (item.GetPrefabData().GetPrefabName() != itemPrefab)
1003 continue;
1004
1005 iic = InventoryItemComponent.Cast(item.FindComponent(InventoryItemComponent));
1006 int slotId = FindItem(iic);
1007 stackChange = changeMap.Get(slotId);
1008 if (!stackChange)
1009 continue;
1010
1011 stackChange.param2++;
1012 stackChange.param3 = iic; // keep the reference to the last item in the stack
1013 }
1014
1016 foreach (int slotId, Tuple3<int, int, InventoryItemComponent> finalChange : changeMap)
1017 {
1018 if (finalChange.param1 == finalChange.param2)
1019 continue;
1020
1021 m_aSlots[slotId].UpdateInventorySlot(finalChange.param3, finalChange.param2);
1022 }
1023 }
1024
1025 //------------------------------------------------------------------------------------------------
1026 // !
1027 protected void UpdateOwnedSlots(notnull array<BaseInventoryStorageComponent> pItemsInStorage)
1028 {
1029 int count = pItemsInStorage.Count();
1030 if (count < m_aSlots.Count())
1031 {
1032 for (int i = m_aSlots.Count() - count; i > 0; i--)
1033 {
1034 auto slotUI = m_aSlots[m_aSlots.Count() - 1];
1035 if (slotUI)
1036 slotUI.Destroy();
1037 }
1038
1039 }
1040 m_aSlots.Resize(count);
1041 for (int i = 0; i < count; i++)
1042 {
1043 if (m_aSlots[i])
1044 m_aSlots[i].UpdateReferencedComponent(pItemsInStorage[i]);
1045 else
1046 m_aSlots[i] = CreateSlotUI(pItemsInStorage[i]);
1047 }
1048 }
1049
1050 //------------------------------------------------------------------------------------------------
1051 /*protected void FindAndSetResourceCount(Widget targetTitle, BaseInventoryStorageComponent targetStorage)
1052 {
1053 TextWidget resourceText = TextWidget.Cast(targetTitle.FindAnyWidget("ResourceText"));
1054 if(!resourceText)
1055 return;
1056
1057 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(targetStorage.GetOwner());
1058 if(!resourceComponent)
1059 return;
1060
1061 SCR_ResourceConsumer resourceConsumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, EResourceType.SUPPLIES);
1062
1063 if (!resourceConsumer)
1064 resourceConsumer = resourceComponent.GetConsumer(EResourceGeneratorID.VEHICLE_UNLOAD, EResourceType.SUPPLIES);
1065
1066 if (!resourceConsumer)
1067 resourceConsumer = resourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
1068
1069 if (!resourceConsumer)
1070 return;
1071
1072 resourceText.SetText(resourceConsumer.GetAggregatedResourceValue().ToString());
1073 }*/
1074
1075 //------------------------------------------------------------------------------------------------
1076 // ! Looks for the very same item, including attachements and its content. Actually, it uses
1077 // ! the total weight to compare it. Not 100% reliable, but cheap ( instead of comparing the contents and attachements )
1078 // ! TODO: generate a key/hash for the items state
1079 protected int FindItem( notnull InventoryItemComponent pInvItem )
1080 {
1081 IEntity pEntity = pInvItem.GetOwner();
1082 if ( !pEntity )
1083 return -1;
1084 EntityPrefabData pEntPrefabData = pEntity.GetPrefabData();
1085 if ( !pEntPrefabData )
1086 return -1;
1087 float fWeight = pInvItem.GetTotalWeight();
1088
1090
1091 for ( int i = m_aSlots.Count() - 1; i >= 0; i-- )
1092 {
1093 if ( !m_aSlots[ i ] )
1094 continue;
1095 InventoryItemComponent pInvItemActual = m_aSlots[ i ].GetInventoryItemComponent();
1096
1097 if ( fWeight != pInvItemActual.GetTotalWeight() )
1098 continue;
1099
1100 IEntity pEnt = pInvItemActual.GetOwner();
1101 if ( pEnt && ( pEntPrefabData == pEnt.GetPrefabData() ) ) //is it the same prefab?
1102 {
1103 MagazineComponent pMagazineActual = MagazineComponent.Cast( pEnt.FindComponent( MagazineComponent ) );
1104 if ( pMagazineActual ) //TODO: we actually don't have the ammo in magazines physically. So comparing weight won't help here. We need to count the bullets. Later to remove and use the weight.
1105 {
1106 if (pMagazineActual.GetAmmoCount() != pMagazine.GetAmmoCount())
1107 continue;
1108 }
1109 return i;
1110 }
1111 }
1112 return -1;
1113 }
1114
1115 //------------------------------------------------------------------------------------------------
1116 // !
1117 protected int FindItemByName( string sItemName, int iActualIndex )
1118 {
1119 int iCount = m_aSlots.Count();
1120 for ( int i = 0; i < iCount; i++ )
1121 {
1122 if ( !m_aSlots[ i ] )
1123 continue;
1124 string sName = m_aSlots[ i ].GetItemName();
1125 if ( sName.Compare( sItemName, false ) == 0 )
1126 return i;
1127 }
1128 return -1;
1129 }
1130
1131 //------------------------------------------------------------------------------------------------
1132 // !
1133 protected string GetNameFromComponent( notnull InventoryItemComponent pComponent )
1134 {
1135 ItemAttributeCollection pAttributes = pComponent.GetAttributes();
1136 if ( !pAttributes )
1137 return string.Empty;
1138 if ( !pAttributes.GetUIInfo() )
1139 return string.Empty;
1140 return pAttributes.GetUIInfo().GetName();
1141 }
1142
1143 //------------------------------------------------------------------------------------------------
1144 // !
1145 protected int CreateSlots( )
1146 {
1147 ref array<IEntity> pItemsInStorage = new array<IEntity>();
1148 GetAllItems( pItemsInStorage );
1149 UpdateOwnedSlots(pItemsInStorage);
1150 return 0;
1151 }
1152
1153 protected int GetIndexFromCoords(int x, int y)
1154 {
1155 return m_iMaxColumns * y + x;
1156 }
1157
1158 //------------------------------------------------------------------------------------------------
1159 // ! creates the the grid from array of UI items
1160 protected void SortSlots()
1161 {
1162 array<int> aCoordinates;
1163 int iWidgetColumnSize, iWidgetRowSize;
1164 int iPageCounter = 0;
1165
1166 //reset all elements to 0 - free it
1167 m_iMatrix.Reset();
1168
1169 foreach ( SCR_InventorySlotUI pSlot: m_aSlots )
1170 {
1171
1172 if( !pSlot )
1173 continue;
1174 Widget w = pSlot.GetWidget();
1175 if( !w )
1176 continue;
1177
1178 iWidgetColumnSize = pSlot.GetColumnSize();
1179 iWidgetRowSize = pSlot.GetRowSize();
1180
1181 //find the 1st suitable position
1182 aCoordinates = m_iMatrix.Reserve1stFreePlace( iWidgetColumnSize, iWidgetRowSize );
1183
1184
1185 if( ( aCoordinates[0] != -1 ) && ( aCoordinates[1] != -1 ) )
1186 {
1187 GridSlot.SetColumn( w, aCoordinates[0] );
1188 GridSlot.SetRow( w, aCoordinates[1] );
1189 pSlot.SetPage( iPageCounter );
1190 }
1191 else
1192 {
1193 iPageCounter++;
1194 m_iMatrix.Reset();
1195 //find the 1st suitable position
1196 aCoordinates = m_iMatrix.Reserve1stFreePlace( iWidgetColumnSize, iWidgetRowSize );
1197 if( ( aCoordinates[0] == -1 ) || ( aCoordinates[1] == -1 ) )
1198 return;
1199 GridSlot.SetColumn( w, aCoordinates[0] );
1200 GridSlot.SetRow( w, aCoordinates[1] );
1201 pSlot.SetPage( iPageCounter );
1202 }
1203 GridSlot.SetColumnSpan( w, iWidgetColumnSize );
1204 GridSlot.SetRowSpan( w, iWidgetRowSize );
1205 }
1206 m_iNrOfPages = iPageCounter + 1;
1207 }
1208
1209 //------------------------------------------------------------------------------------------------
1210 protected void FillWithEmptySlots()
1211 {
1212 array<int> aCoordinates = {};
1213
1214 foreach ( int iIndex, SCR_InventorySlotUI pSlot: m_aSlots )
1215 {
1216 if ( pSlot )
1217 continue;
1218 ReserveAndSetSlot( iIndex );
1219 }
1220 }
1221
1222 //------------------------------------------------------------------------------------------------
1223 // !
1224 void ReserveAndSetSlot( int iIndex, )
1225 {
1226 array<int> aCoordinates = m_iMatrix.Reserve1stFreePlace( 1, 1 );
1228 pAttrib.SetSlotType( ESlotID.SLOT_ANY );
1229 pAttrib.SetSlotSize( ESlotSize.SLOT_1x1 );
1230 SCR_InventorySlotUI pSlotNew = CreateSlotUI( null, pAttrib );
1231 m_aSlots.Set( iIndex, pSlotNew );
1232 GridSlot.SetColumn( pSlotNew.GetWidget(), aCoordinates[0] );
1233 GridSlot.SetRow( pSlotNew.GetWidget(), aCoordinates[1] );
1234 }
1235
1236
1237 //------------------------------------------------------------------------------------------------
1238 // !
1239 protected void ShowPage( int iPage, out int slotToFocus = -1 )
1240 {
1241 if( iPage >= m_iNrOfPages )
1242 iPage = m_iNrOfPages - 1;
1243 if( iPage < 0 )
1244 iPage = 0;
1245
1246 // get all empty slots for the storage and reset their visibility
1247 array<Widget> emptySlots = {};
1248 Widget child;
1249 if (m_wGrid)
1250 child = m_wGrid.GetChildren();
1252 for (int i = 0; i < size; ++i)
1253 {
1254 if (!child)
1255 break;
1256 emptySlots.Insert(child);
1257 child.SetOpacity(1);
1258 child = child.GetSibling();
1259 }
1260
1261 SCR_InventorySlotUI firstVisibleSlot;
1262 foreach ( int i, SCR_InventorySlotUI pSlot: m_aSlots )
1263 {
1264 if ( pSlot )
1265 {
1266 bool visible = (pSlot.GetPage() == iPage);
1267 pSlot.SetSlotVisible(visible);
1268
1269 if (!visible && pSlot == m_pLastFocusedSlot) // when slot is made invisible then it looses track of its button, as it is disabled
1270 m_pLastFocusedSlot = null; // thus we should never try to refocus on such slot as its not possible
1271
1272 if (visible && !firstVisibleSlot) // because previously focused slot might be disabled now
1273 firstVisibleSlot = pSlot; // we need to find first visible slot, in case that we will want to focus on it
1274
1275 if (!visible)
1276 continue;
1277
1278 if (slotToFocus == -1)
1279 slotToFocus = i;
1280
1282 continue;
1283
1284 int startIndex = GridSlot.GetColumn(pSlot.m_widget) + GridSlot.GetRow(pSlot.m_widget) * m_iMaxColumns;
1285 for (int y = 0, maxY = pSlot.GetRowSize(); y < maxY; ++y)
1286 {
1287 for (int x = 0, maxX = pSlot.GetColumnSize(); x < maxX; ++x)
1288 {
1289 int index = startIndex + x + y * m_iMaxColumns;
1290 if (!emptySlots.IsIndexValid(index))
1291 break;
1292 // hide the empty slot if it's underneath an item slot
1293 emptySlots[index].SetOpacity(0);
1294 }
1295 }
1296 }
1297 }
1298
1299 if (!m_pLastFocusedSlot) // if we didnt have, or slot that was focused last time, got disabled
1300 m_pLastFocusedSlot = firstVisibleSlot; // then we need to point to something that has a button, meaning that it can be focused
1301
1302 if( m_iNrOfPages > 1 )
1303 ShowPagesCounter( true, iPage+1, m_iNrOfPages );
1304 else
1305 ShowPagesCounter( false );
1306
1308 m_wPagingSpinboxComponent.SetCurrentItem( iPage, false );
1309
1310 m_iLastShownPage = iPage;
1311 }
1312
1313 //------------------------------------------------------------------------------------------------
1314 // ! Removes all of the existing titles and clears the array.
1315 protected void ClearTraverseTitles()
1316 {
1317 if (m_aTraverseTitle.IsEmpty())
1318 return;
1319
1320 Widget titleLayout = m_widget.FindAnyWidget("titleLayout");
1321 if (!titleLayout)
1322 return;
1323
1324 foreach (Widget title: m_aTraverseTitle)
1325 {
1326 titleLayout.RemoveChild(title);
1327 }
1328
1329 m_aTraverseTitle.Clear();
1330 }
1331
1332 //------------------------------------------------------------------------------------------------
1333 // ! Fills out the storage with items from the storage param. Also creates traverse titles if traversing.
1334 protected void FillItemsFromStorage(BaseInventoryStorageComponent storage)
1335 {
1337
1338 int count = m_aTraverseStorage.Count();
1339
1340 array<IEntity> pItemsInStorage = new array<IEntity>();
1341 GetAllItems(pItemsInStorage, GetCurrentNavigationStorage());
1342 UpdateOwnedSlots(pItemsInStorage);
1343
1344 BaseInventoryStorageComponent currentStorage;
1345 Widget titleLayout = m_widget.FindAnyWidget("titleLayout");
1346 Widget title;
1347 RenderTargetWidget previewImage;
1348 ItemPreviewManagerEntity manager;
1349 ItemPreviewWidget renderPreview;
1350 IEntity previewEntity;
1351 SCR_InventoryNavigationButtonBack closeContainerButton;
1352 ButtonWidget navigationHelperWidget;
1353 SCR_EventHandlerComponent navigationHandler;
1354
1355 for (int i = 0; i < count; ++i)
1356 {
1357 currentStorage = m_aTraverseStorage[i];
1358
1359 if (currentStorage.GetOwner().FindComponent(SCR_ArsenalInventoryStorageManagerComponent))
1360 title = GetGame().GetWorkspace().CreateWidgets(SUPPLY_TITLE_LAYOUT/*ARSENAL_TITLE_LAYOUT*/, titleLayout);
1361 else if (SCR_ResourceComponent.FindResourceComponent(currentStorage.GetOwner(), true))
1362 title = GetGame().GetWorkspace().CreateWidgets(SUPPLY_TITLE_LAYOUT, titleLayout);
1363 else
1364 title = GetGame().GetWorkspace().CreateWidgets(STORAGE_TITLE_LAYOUT, titleLayout);
1365
1366 if (!title)
1367 return;
1368
1369 m_aTraverseTitle.Insert( title );
1370
1371 previewImage = RenderTargetWidget.Cast(title.FindAnyWidget("itemStorage"));
1372 manager = GetInventoryMenuHandler().GetItemPreviewManager();
1373 if (manager)
1374 {
1375 renderPreview = ItemPreviewWidget.Cast(previewImage);
1376 previewEntity = null;
1377 if (renderPreview && currentStorage)
1378 manager.SetPreviewItem(renderPreview, currentStorage.GetOwner(), null, true);
1379 }
1380
1381 FindAndSetTitleName(title, currentStorage);
1382 UpdateContainerResources(title, currentStorage);
1383
1384 closeContainerButton = SCR_InventoryNavigationButtonBack.Cast(SCR_InventoryNavigationButtonBack.GetInputButtonComponent("ButtonTraverseBack", title));
1385 if (!closeContainerButton)
1386 return;
1387
1388 closeContainerButton.m_OnActivated.Insert(m_MenuHandler.OnAction);
1389 closeContainerButton.SetParentStorage(this);
1390 closeContainerButton.SetStorageIndex(i);
1391 closeContainerButton.SetVisible(true);
1392
1393 navigationHelperWidget = ButtonWidget.Cast(title.FindAnyWidget("navigationHelper"));
1394
1395 if (!navigationHelperWidget)
1396 return;
1397
1398 if (i == count - 1)
1399 m_wLastCloseTraverseButton = navigationHelperWidget;
1400
1401 navigationHelperWidget.AddHandler(new SCR_EventHandlerComponent);
1402 navigationHandler = SCR_EventHandlerComponent.Cast(navigationHelperWidget.FindHandler(SCR_EventHandlerComponent));
1403
1404 if(!navigationHandler)
1405 return;
1406
1407 navigationHandler.GetOnClick().Insert(closeContainerButton.OnActivate);
1408 }
1409 }
1410
1411 //------------------------------------------------------------------------------------------------
1412 protected void FindAndSetTitleName(Widget targetTitle, BaseInventoryStorageComponent targetStorage)
1413 {
1414 TextWidget titleNameWidget = TextWidget.Cast(targetTitle.FindAnyWidget("TextC"));
1415 if(!titleNameWidget)
1416 return;
1417 ItemAttributeCollection attributes = targetStorage.GetAttributes();
1418 if(!attributes)
1419 return;
1420 UIInfo uiInfo = attributes.GetUIInfo();
1421 if(!uiInfo)
1422 return;
1423 titleNameWidget.SetText(uiInfo.GetName());
1424 }
1425
1426 //------------------------------------------------------------------------------------------------
1427 // !
1428 protected void GetAllItems( out notnull array<IEntity> pItemsInStorage, BaseInventoryStorageComponent pStorage = null )
1429 {
1430 if (pStorage)
1431 {
1432 IEntity ownerEntity = pStorage.GetOwner();
1433 if (!ownerEntity)
1434 return;
1435 SCR_ArsenalInventoryStorageManagerComponent arsenalManagerComponent = SCR_ArsenalInventoryStorageManagerComponent.Cast(ownerEntity.FindComponent(SCR_ArsenalInventoryStorageManagerComponent));
1436
1437 if (arsenalManagerComponent)
1438 {
1439 m_bIsArsenal = true;
1440 if (!pStorage)
1441 return;
1442
1443 ChimeraWorld chimeraWorld = GetGame().GetWorld();
1444 ItemPreviewManagerEntity itemPreviewManagerEntity = chimeraWorld.GetItemPreviewManager();
1445
1447 array<ResourceName> prefabsToSpawn = new array<ResourceName>();
1448
1449 if (!arsenalComponent)
1450 return;
1451
1452 arsenalComponent.GetAvailablePrefabs(prefabsToSpawn);
1453
1454 foreach (ResourceName resourceName: prefabsToSpawn)
1455 {
1456 pItemsInStorage.Insert(itemPreviewManagerEntity.ResolvePreviewEntityForPrefab(resourceName));
1457 }
1458
1459 if (s_OnArsenalEnter)
1460 s_OnArsenalEnter.Invoke();
1461
1462 return;
1463 }
1464
1465 if (ClothNodeStorageComponent.Cast(pStorage))
1466 {
1467 array<BaseInventoryStorageComponent> pStorages = {};
1468 array<IEntity> pItems = {};
1469 pStorage.GetOwnedStorages(pStorages, 1, false);
1470
1471 foreach (BaseInventoryStorageComponent pStor : pStorages)
1472 {
1473 if (!pStor)
1474 continue;
1475 pStor.GetAll(pItems);
1476 pItemsInStorage.Copy(pItems);
1477 }
1478 return;
1479 }
1480
1481 pStorage.GetAll(pItemsInStorage);
1482 return;
1483 }
1484
1485 if (m_Storage)
1486 m_Storage.GetAll(pItemsInStorage);
1487 }
1488
1489
1490 //------------------------------------------------------------------------------------------------
1491 // ! gets all the items only from the given depth. I.e. all items inserted in LBS pouches
1492 // ! changes the m_Storage, back it up !!!
1493 protected void GetAllItemsFromDepth( out notnull array<IEntity> pItemsInStorages, int iDepth = 3, int iDepthDefault = 0 )
1494 {
1495
1496 if ( !m_Storage )
1497 return;
1498
1499 if ( iDepthDefault == 0 )
1500 iDepthDefault = iDepth;
1501
1502 #ifdef DEBUG_INVENTORY20
1503 if ( iDepthDefault == iDepth )
1504 {
1505 LocalizedString sStorageName = "";
1506 ItemAttributeCollection pAttribs = m_Storage.GetAttributes();
1507 if ( pAttribs )
1508 {
1509 UIInfo pInfo = pAttribs.GetUIInfo();
1510 if ( pInfo )
1511 sStorageName = pInfo.GetName();
1512 Print( "-----------------------------------------------" );
1513 PrintFormat( "%1 ( %2 )", sStorageName, BaseInventoryStorageComponent.Cast( m_Storage ) );
1514 }
1515 }
1516 #endif
1517
1518 array<IEntity> aTraverseStorageTmp = new array<IEntity>();
1519 m_Storage.GetAll( aTraverseStorageTmp );
1520
1521 IEntity pEntity;
1522
1523 for ( int m = 0; m < aTraverseStorageTmp.Count(); m++ )
1524 {
1525 pEntity = aTraverseStorageTmp[ m ];
1526 //BaseInventoryStorageComponent tmpStorage
1527 m_Storage = BaseInventoryStorageComponent.Cast( pEntity.FindComponent( BaseInventoryStorageComponent ) );
1529 if ( iDepth == 1 )
1530 pItemsInStorages.Insert( pEntity );
1531 if ( m_Storage )
1532 {
1533 #ifdef DEBUG_INVENTORY20
1534 ItemAttributeCollection pAttrs = m_Storage.GetAttributes();
1535 if ( !pAttrs )
1536 return;
1537 LocalizedString sName = pAttrs.GetUIInfo().GetName();
1538 string sTextIn = "";
1539 ConstructSlashes( sTextIn, iDepthDefault-iDepth );
1540 PrintFormat( "|%1 %2 ( %3 )", sTextIn, sName, m_Storage );
1541 #endif
1542 GetAllItemsFromDepth( pItemsInStorages, iDepth - 1, iDepthDefault );
1543 }
1544 #ifdef DEBUG_INVENTORY20
1545 else
1546 {
1547 if ( pInventoryComponent )
1548 {
1549 LocalizedString sName = "";
1550 if ( pInventoryComponent.GetAttributes() )
1551 if ( pInventoryComponent.GetAttributes().GetUIInfo() )
1552 sName = pInventoryComponent.GetAttributes().GetUIInfo().GetName();
1553 string sTextIn = "";
1554 ConstructSlashes( sTextIn, iDepthDefault-iDepth );
1555 PrintFormat( "|%1 %2 ( %3 )", sTextIn, sName, pInventoryComponent );
1556 }
1557 }
1558 #endif
1559 }
1560 }
1561
1562 //------------------------------------------------------------------------------------------------
1563 void UpdateTotalWeight(float totalWeight, Color fontColor = Color.Gray25)
1564 {
1565 if (!m_wWeightText)
1566 return;
1567
1568 m_wWeightText.SetTextFormat("#AR-ValueUnit_Short_Kilograms", totalWeight);
1569 }
1570
1571 //------------------------------------------------------------------------------------------------
1572 float GetTotalRoundedUpWeight(BaseInventoryStorageComponent storage)
1573 {
1574 if (!storage)
1575 return -1;
1576
1577 float totalWeight = storage.GetTotalWeight();
1578
1579 totalWeight = Math.Round(totalWeight * 100); // totalWeight * 100 here to not lose the weight precision
1580
1581 return totalWeight / 100;
1582 }
1583
1584 //------------------------------------------------------------------------------------------------
1585 void UpdateVolumePercentage(float percentage, bool previewOnly = false)// Color fontColor = Color.Gray25)
1586 {
1587 if (m_ProgressBar)
1588 {
1589 m_ProgressBar.SetProgressRange(0, 100);
1590 if (previewOnly)
1591 m_ProgressBar.SetCurrentProgressPreview(percentage);
1592 else
1593 {
1594 m_ProgressBar.SetCurrentProgress(percentage);
1595 m_ProgressBar.SetCurrentProgressPreview(percentage);
1596 }
1597
1598 RichTextWidget percentageText = RichTextWidget.Cast(m_widget.FindAnyWidget("VolumeOver"));
1599 if (percentageText)
1600 {
1601 percentageText.SetTextFormat("#AR-ValueUnit_Percentage_Add", percentage - 100);
1602 percentageText.SetVisible(percentage > 100);
1603 Widget progressVolumeOver = m_widget.FindAnyWidget("ProgressVolumeOver");
1604 progressVolumeOver.SetVisible(percentage > 100);
1605 }
1606 }
1607 }
1608
1609 //------------------------------------------------------------------------------------------------
1610 protected bool CheckIfAnyItemInStorageHasResources(array<IEntity> items)
1611 {
1612 SCR_ResourceComponent resComp;
1613
1614 foreach(SCR_ResourceComponent oldResComp: m_aResourceCompsInStorage)
1615 {
1616 if (!oldResComp)
1617 continue;
1618
1619 SCR_ResourceConsumer oldResCont = oldResComp.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, EResourceType.SUPPLIES);
1620
1621 if (!oldResCont)
1622 continue;
1623
1624 oldResComp.TEMP_GetOnInteractorReplicated().Remove(RefreshResources);
1625 }
1626
1628
1629 foreach (IEntity item: items)
1630 {
1631 if (!item)
1632 continue;
1633
1634 resComp = SCR_ResourceComponent.FindResourceComponent(item);
1635
1636 if (!resComp)
1637 continue;
1638
1639 m_aResourceCompsInStorage.Insert(resComp);
1640
1641 SCR_ResourceConsumer resCont = resComp.GetConsumer(EResourceGeneratorID.DEFAULT_STORAGE, EResourceType.SUPPLIES);
1642
1643 if (!resCont)
1644 continue;
1645
1646 resComp.TEMP_GetOnInteractorReplicated().Insert(RefreshResources);
1647 }
1648
1649 if (m_aResourceCompsInStorage.IsEmpty())
1650 return false;
1651
1652 return true;
1653 }
1654
1655 //------------------------------------------------------------------------------------------------
1656 float GetOccupiedVolumePercentage(BaseInventoryStorageComponent storage, float occupiedSpace = 0)
1657 {
1658 if (!storage)
1659 return -1;
1660
1661 float occupiedVolumePercantage;
1662 float capacity = GetMaxVolumeCapacity(storage);
1663
1664 if (capacity == 0)
1665 return 0;
1666
1667 if (occupiedSpace != 0)
1668 occupiedVolumePercantage = Math.Round(occupiedSpace / (capacity / 100));
1669 else
1670 occupiedVolumePercantage = Math.Round(GetOccupiedVolume(storage) / (capacity / 100));
1671
1672 return occupiedVolumePercantage;
1673 }
1674
1675 //------------------------------------------------------------------------------------------------
1676 float GetOccupiedVolume(BaseInventoryStorageComponent storage)
1677 {
1678 if (!storage)
1679 return -1;
1680
1681 float fOccupied = 0.0;
1682 if (ClothNodeStorageComponent.Cast(storage))
1683 {
1684 array<BaseInventoryStorageComponent> pOwnedStorages = {};
1685 storage.GetOwnedStorages(pOwnedStorages, 1, false);
1686 foreach (BaseInventoryStorageComponent pSubStorage : pOwnedStorages)
1687 if (SCR_UniversalInventoryStorageComponent.Cast(pSubStorage))
1688 fOccupied += pSubStorage.GetOccupiedSpace();
1689 }
1690 else
1691 {
1692 fOccupied = storage.GetOccupiedSpace();
1693 }
1694
1695 return fOccupied;
1696 }
1697
1698 //------------------------------------------------------------------------------------------------
1699 float GetMaxVolumeCapacity(BaseInventoryStorageComponent storage)
1700 {
1701 if (!storage)
1702 return -1;
1703
1704 float fMaxCapacity = 0.0;
1705 if (ClothNodeStorageComponent.Cast(storage))
1706 {
1707 array<BaseInventoryStorageComponent> pOwnedStorages = {};
1708 storage.GetOwnedStorages(pOwnedStorages, 1, false);
1709 foreach (BaseInventoryStorageComponent pSubStorage : pOwnedStorages)
1710 {
1711 if (SCR_UniversalInventoryStorageComponent.Cast(pSubStorage))
1712 fMaxCapacity += pSubStorage.GetMaxVolumeCapacity();
1713 }
1714 }
1715 else
1716 {
1717 fMaxCapacity = storage.GetMaxVolumeCapacity();
1718 }
1719
1720 return fMaxCapacity;
1721 }
1722
1723 //------------------------------------------------------------------------------------------------
1725 {
1726 if (!m_widget)
1727 return;
1728
1729 if (!m_wWarningOverlay)
1730 return;
1731
1732 m_wWarningOverlay.SetVisible(!isVisible);
1733 if (m_ProgressBar)
1734 m_ProgressBar.SetPreviewColor(isVisible);
1735
1736 if (m_wWeightDisplay)
1738
1739 if (reason == EInvInsertFailReason.OK)
1740 return;
1741
1742 Widget size = m_wWarningOverlay.FindAnyWidget("Oversized");
1743 Widget weight = m_wWarningOverlay.FindAnyWidget("Overweight");
1744 Widget volume = m_wWarningOverlay.FindAnyWidget("Overvolume");
1745
1746 if (size)
1747 size.SetVisible(reason & EInvInsertFailReason.SIZE);
1748
1749 if (weight)
1750 {
1752 m_wWeightDisplay.SetColor(Color.Red);
1753 weight.SetVisible(reason & EInvInsertFailReason.WEIGHT);
1754 }
1755
1756 if (volume)
1757 volume.SetVisible(reason & EInvInsertFailReason.CAPACITY);
1758 }
1759
1760 //------------------------------------------------------------------------------------------------
1762 {
1763 if (!m_widget)
1764 return false;
1765
1766 return !IsWarningOverlayVisible();
1767 }
1768
1769 //------------------------------------------------------------------------------------------------
1770 // ! formating helper
1771 private void ConstructSlashes( out string sText, int iSlashes )
1772 {
1773 for ( int m = 0; m <= ( iSlashes * 2 ); m++ )
1774 {
1775 sText += "-";
1776 }
1777 }
1778
1779 //------------------------------------------------------------------------------------------------
1780 // ! creates the simple matrix of dimension [ m_iMaxRows, m_iMaxColumns ]
1782 protected void CreateEmptyLayout(bool recreate = false)
1783 {
1784 if (!m_aEmptySlotWidget)
1785 m_aEmptySlotWidget = {};
1786 else if (recreate)
1788 else if (m_aEmptySlotWidget.Count() == m_iMaxRows * m_iMaxColumns)
1789 return; // if number of slots has not changed then dont make new ones
1790
1791 for( int iLoop = 0; iLoop < m_iMaxRows; iLoop++ )
1792 {
1793 for( int jLoop = 0; jLoop < m_iMaxColumns; jLoop++ )
1794 {
1795 m_aEmptySlotWidget.Insert(CreateEmptySlotUI( iLoop, jLoop ));
1796 }
1797 }
1798 }
1799
1800 //------------------------------------------------------------------------------------------------
1802 protected void DestroyEmptySlots()
1803 {
1804 if (!m_aEmptySlotWidget)
1805 return;
1806
1807 foreach (Widget emptySlot : m_aEmptySlotWidget)
1808 {
1809 if (!emptySlot)
1810 continue;
1811
1812 emptySlot.RemoveFromHierarchy();
1813 }
1814
1815 m_aEmptySlotWidget.Clear();
1816 }
1817
1818 //------------------------------------------------------------------------------------------------
1819 // ! get the item inventory component
1821 {
1822 if ( pEntity == null )
1823 return null;
1825 }
1826
1827 //------------------------------------------------------------------------------------------------
1828 // !
1829 void GetSlots( out notnull array<SCR_InventorySlotUI> outSlots )
1830 {
1831 outSlots.InsertAll( m_aSlots );
1832 }
1833
1834 //------------------------------------------------------------------------------------------------
1835 // ! displays the info in details
1836 void ShowItemDetails( string sName, string sDescription, string sWeight );
1837
1838 //------------------------------------------------------------------------------------------------
1839 // ! helper for showing the number of pages
1840 private void ShowPagesCounter( bool bShow = false, int iPage = 0, int iNumberOfPages = 0 )
1841 {
1843 return;
1844
1845 m_wPagingSpinboxComponent.SetVisible( bShow, false );
1846
1847 if ( bShow )
1848 {
1849 m_wPagingSpinboxComponent.SetCanNavigate( true );
1850 m_wPagingSpinboxComponent.SetPageCount( iNumberOfPages );
1851 m_wPagingSpinboxComponent.SetCurrentItem( iPage, false );
1852 }
1853 else
1854 {
1856 }
1857 }
1858
1859 //-------------------------------------- MOVE MANAGEMENT -----------------------------------------
1860
1861 //------------------------------------------------------------------------------------------------
1863 void SetLastFocusedSlot( SCR_InventorySlotUI pSlot )
1864 {
1865 m_pLastFocusedSlot = pSlot;
1866 }
1867
1868 //------------------------------------------------------------------------------------------------
1870 void SetSlotFocused( SCR_InventorySlotUI pSlotUI = null, bool bSelected = true )
1871 {
1872 if(bSelected)
1873 {
1874 m_pFocusedSlot = pSlotUI;
1875 if (m_pFocusedSlot)
1876 SetLastFocusedSlot(m_pFocusedSlot);
1877 }
1878 else
1879 {
1880 m_pFocusedSlot = null;
1881 }
1882 }
1883
1884 //------------------------------------------------------------------------------------------------
1885 // ! selects the actual slot
1886 void SetSlotSelected( SCR_InventorySlotUI pSlot = null, bool bSelected = true )
1887 {
1889
1890 if( bSelected )
1891 {
1892 m_pSelectedSlot = pSlot;
1893 }
1894 else
1895 m_pSelectedSlot = null;
1896 }
1897
1898 //------------------------------------------------------------------------------------------------
1899 void ShowContainerBorder( bool bShow )
1900 {
1901 if (bShow && IsWarningOverlayVisible())
1902 return;
1903
1904 if ( m_wDropContainer )
1905 {
1906 m_wDropContainer.SetVisible( bShow );
1907 SCR_UISoundEntity.SoundEvent(SCR_SoundEvent.SOUND_FE_BUTTON_HOVER);
1908 }
1909 }
1910
1911 //------------------------------------------------------------------------------------------------
1912 void ActivateStorageButton(bool active)
1913 {
1914 if (m_wButton)
1915 {
1916 m_wButton.SetEnabled(active);
1917 m_wButton.SetVisible(active);
1918 foreach (SCR_InventorySlotUI slot : m_aSlots)
1919 {
1920 if (slot && slot.GetButtonWidget())
1921 slot.GetButtonWidget().SetEnabled(!active);
1922 }
1923 }
1924
1926 m_wLastCloseTraverseButton.SetEnabled(!active);
1927 }
1928
1929 //------------------------------------------------------------------------------------------------
1930 int GetFocusedSlotId()
1931 {
1932 if (!m_pFocusedSlot)
1933 return -1;
1934 return m_aSlots.Find(m_pFocusedSlot);
1935 }
1936
1937 //------------------------------------------------------------------------------------------------
1938 int GetSlotId(SCR_InventorySlotUI slot)
1939 {
1940 return m_aSlots.Find(slot);
1941 }
1942
1943 //------------------------------------------------------------------------------------------------
1944 int GetSlotIdForItem(ResourceName itemName)
1945 {
1946 int slotCount = m_aSlots.Count();
1947 SCR_InventorySlotUI slot;
1948
1949 for (int slotId = 0; slotId < slotCount; ++slotId)
1950 {
1951 slot = m_aSlots[slotId];
1952 if (slot && slot.GetItemResource() == itemName)
1953 {
1954 return slotId;
1955 }
1956 }
1957
1958 return 0;
1959 }
1960
1961 //------------------------------------------------------------------------------------------------
1962 protected void SetPreviewItem()
1963 {
1964 m_wPreviewImage = RenderTargetWidget.Cast( m_widget.FindAnyWidget( "itemStorage" ) );
1965
1966 ChimeraWorld world = ChimeraWorld.CastFrom(GetGame().GetWorld());
1967 if (!world)
1968 return;
1969
1970 ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
1971 if (!manager)
1972 return;
1973
1974 ItemPreviewWidget renderPreview = ItemPreviewWidget.Cast( m_wPreviewImage );
1975 if (!renderPreview)
1976 return;
1977
1978 IEntity previewEntity = null;
1979 if (m_Storage)
1980 previewEntity = m_Storage.GetOwner();
1981
1982 manager.SetPreviewItem(renderPreview, previewEntity, null, true);
1983 }
1984
1985 //------------------------------------------------------------------------ COMMON METHODS ----------------------------------------------------------------------
1986
1987 //------------------------------------------------------------------------------------------------
1988 void DimSlots( bool bDim )
1989 {
1990 foreach ( SCR_InventorySlotUI pSlot : m_aSlots )
1991 {
1992 if ( pSlot )
1993 {
1994 if ( !pSlot.IsSelected() )
1995 {
1996 pSlot.SetEnabledForMove( !bDim );
1997 }
1998 }
1999 }
2000 }
2001 //------------------------------------------------------------------------------------------------
2002 override void HandlerAttached( Widget w )
2003 {
2004 if( !w )
2005 return;
2006
2007 m_wDropContainer = w.FindAnyWidget( "DropContainer" );
2008 m_wButton = ButtonWidget.Cast(w.FindAnyWidget("Button"));
2009 if (m_wButton)
2010 {
2012 if (btn)
2013 {
2014 btn.SetParent(this);
2015 }
2016 else
2017 {
2019 newBtn.SetParent(this);
2020 m_wButton.AddHandler(newBtn);
2021 }
2022
2023 m_wButton.SetOpacity(0.1);
2024 }
2025
2026 m_widget = w;
2027 Init();
2028 }
2029
2030 //------------------------------------------------------------------------------------------------
2031 override event void HandlerDeattached(Widget w)
2032 {
2034 m_ResourceComponent.TEMP_GetOnInteractorReplicated().Remove(RefreshConsumer);
2035
2037 DeleteSlots();
2038 }
2039
2040 //------------------------------------------------------------------------------------------------
2042 {
2043 return m_wButton;
2044 }
2045
2046 //------------------------------------------------------------------------------------------------
2051
2053 {
2054 return m_wWarningOverlay && m_wWarningOverlay.IsVisible();
2055 }
2056
2057 //------------------------------------------------------------------------------------------------
2059 BaseInventoryStorageComponent storage,
2060 LoadoutAreaType slotID = null,
2061 SCR_InventoryMenuUI menuManager = null,
2062 int iPage = 0,
2063 array<BaseInventoryStorageComponent> aTraverseStorage = null)
2064 {
2065 m_Storage = storage;
2066 m_MenuHandler = menuManager;
2067 m_eSlotAreaType = slotID;
2068 m_iMaxRows = 3;
2069 m_iMaxColumns = 4;
2072 m_iLastShownPage = iPage;
2073 if ( aTraverseStorage )
2074 m_aTraverseStorage.Copy( aTraverseStorage );
2075 }
2076
2077 //------------------------------------------------------------------------------------------------
2079 {
2080 if( m_aSlots )
2081 delete m_aSlots;
2082 if( m_iMatrix )
2083 delete m_iMatrix;
2084 }
2085};
2086
2087//------------------------------------------------------------------------------------------------
2089{
2091
2092 //------------------------------------------------------------------------------------------------
2093 override bool OnFocus(Widget w, int x, int y)
2094 {
2095 m_Parent.GetInventoryMenuHandler().OnContainerFocused(m_Parent);
2096 return false;
2097 }
2098
2099 //------------------------------------------------------------------------------------------------
2100 override bool OnFocusLost(Widget w, int x, int y)
2101 {
2102 m_Parent.GetInventoryMenuHandler().OnContainerFocusLeft(m_Parent);
2103 return false;
2104 }
2105
2106 //------------------------------------------------------------------------------------------------
2108 {
2109 m_Parent = parent;
2110 }
2111};
ArmaReforgerScripted GetGame()
Definition game.c:1398
int size
ResourceName resourceName
Definition SCR_AIGroup.c:66
SCR_EAnalyticalItemSlotType
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
override bool IsTraversalAllowed()
EInvInsertFailReason
Widget GetRootWidget()
EResourceGeneratorID
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
void SCR_UniversalInventoryStorageComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
int Type
proto native external bool IsInherited(typename type)
enum EVehicleType IEntity
Definition Color.c:13
proto external Managed FindComponent(typename typeName)
proto external EntityPrefabData GetPrefabData()
Input management system for user interactions.
Definition Math.c:13
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
bool GetAvailablePrefabs(out notnull array< ResourceName > availablePrefabs)
void SetArsenalResourceComponent(SCR_ResourceComponent component)
void OpenLinkedStorages(BaseInventoryStorageComponent parentStorage, bool showVicinity=true, bool hideCloseButton=true)
void CloseLinkedStorages(BaseInventoryStorageComponent parentStorage)
Interactive non-focus button showing hint, and triggering actions.
void SetParentStorage(SCR_InventoryStorageBaseUI pParentStorage)
void IncreaseStackNumberWithRplId(RplId id)
void OverrideReferencedComponent(notnull InventoryItemComponent iic)
void ShowPage(int iPage, out int slotToFocus=-1)
void RemoveSlotUI(SCR_InventorySlotUI pSlot)
bool CheckIfAnyItemInStorageHasResources(array< IEntity > items)
SCR_SpinBoxPagingComponent m_wPagingSpinboxComponent
ref array< BaseInventoryStorageComponent > m_aTraverseStorage
void UpdateTotalWeight(float totalWeight, Color fontColor=Color.Gray25)
float GetTotalRoundedUpWeight(BaseInventoryStorageComponent storage)
override bool OnFocus(Widget w, int x, int y)
void RefreshSlot(int index)
Widget CreateEmptySlotUI(int iRow, int iCol)
ref SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandleConsumer
void UpdateStoredResources(float totalResources, float maxResources)
override event void HandlerDeattached(Widget w)
SCR_CharacterInventoryStorageComponent m_InventoryStorage
void FindAndSetTitleName(Widget targetTitle, BaseInventoryStorageComponent targetStorage)
void GetAllItems(out notnull array< IEntity > pItemsInStorage, BaseInventoryStorageComponent pStorage=null)
float GetOccupiedVolumePercentage(BaseInventoryStorageComponent storage, float occupiedSpace=0)
float GetMaxVolumeCapacity(BaseInventoryStorageComponent storage)
ref array< SCR_InventorySlotUI > m_aSlots
void CreateEmptyLayout(bool recreate=false)
void UpdateAvailableResources(float totalResources, bool hasStored)
int FindItemByName(string sItemName, int iActualIndex)
SCR_ResourceComponent m_ResourceComponent
float GetOccupiedVolume(BaseInventoryStorageComponent storage)
void UpdateOwnedSlots(notnull array< BaseInventoryStorageComponent > pItemsInStorage)
static ref ScriptInvokerVoid s_OnArsenalEnter
void UpdateVolumePercentage(float percentage, bool previewOnly=false)
void GetUISlots(out array< SCR_InventorySlotUI > outArray)
void UpdateSlotUI(ResourceName itemPrefab)
void GetAllItemsFromDepth(out notnull array< IEntity > pItemsInStorages, int iDepth=3, int iDepthDefault=0)
void SetStorageAsHighlighted(bool isVisible, EInvInsertFailReason reason=EInvInsertFailReason.OK)
void SCR_InventoryStorageBaseUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID=null, SCR_InventoryMenuUI menuManager=null, int iPage=0, array< BaseInventoryStorageComponent > aTraverseStorage=null)
InventoryItemComponent GetItemComponentFromEntity(IEntity pEntity)
override bool OnMouseEnter(Widget w, int x, int y)
array< SCR_InventorySlotUI > GetUISlots()
SCR_InventorySlotUI CreateSlotUI(InventoryItemComponent pComponent, SCR_ItemAttributeCollection pAttributes=null)
ref array< SCR_ResourceComponent > m_aResourceCompsInStorage
int FindItem(notnull InventoryItemComponent pInvItem)
string GetNameFromComponent(notnull InventoryItemComponent pComponent)
void UpdateOwnedSlots(notnull array< IEntity > pItemsInStorage)
BaseInventoryStorageComponent m_Storage
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
static ScriptInvokerVoid GetOnArsenalEnter()
SCR_InventoryProgressBar m_ProgressBar
void UpdateContainerResources(notnull Widget targetTitle, notnull BaseInventoryStorageComponent targetStorage)
void FillItemsFromStorage(BaseInventoryStorageComponent storage)
void ShowItemDetails(string sName, string sDescription, string sWeight)
SCR_InventoryStorageManagerComponent m_InventoryManager
void DestroyEmptySlots()
Destroys all empty slots which were created by this handler.
override bool OnFocusLost(Widget w, int x, int y)
SCR_EAnalyticalItemSlotType GetAnalyticalItemSlotType()
void GetSlots(out notnull array< SCR_InventorySlotUI > outSlots)
void SetSlotAreaType(LoadoutAreaType eSlotType)
bool OnDrop(SCR_InventorySlotUI slot)
override bool OnFocus(Widget w, int x, int y)
void SetParent(SCR_InventoryStorageBaseUI parent)
override bool OnFocusLost(Widget w, int x, int y)
SCR_InventoryStorageBaseUI m_Parent
static SCR_SpinBoxPagingComponent GetSpinBoxPagingComponent(string name, Widget parent, bool searchAllChildren=true)
UIInfo - allows to define UI elements.
Definition UIInfo.c:14
Definition Types.c:486
override void Show()
Definition gameLib.c:262
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
proto external PlayerController GetPlayerController()
proto external float GetMaxVolumeCapacity()
void Tuple3(T1 p1, T2 p2, T3 p3)
Definition tuple.c:95