8 static ref map<SCR_ArsenalInventorySlotUI, IEntity> ARSENAL_SLOT_STORAGES =
new map<SCR_ArsenalInventorySlotUI, IEntity>();
10 const float STORAGE_NON_HIGHLIGHTED_OPACITY = 0.35;
11 const string ARSENAL_TITLE_LAYOUT =
"{E0C9EDCB8E63F10A}UI/layouts/Menus/Inventory/ArsenalInventoryTraverseTitlePanel.layout";
12 const string SUPPLY_TITLE_LAYOUT =
"{FCE2E160F8C0D4D4}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 =
"{EBBF9E10DB195DB0}UI/layouts/Menus/Inventory/InventoryTraverseTitlePanel.layout";
15 const string SLOT_LAYOUT_1x1_EMPTY =
"{B11F8BE49DFB62A1}UI/layouts/Menus/Inventory/Inventory20Slot_1x1_empty.layout";
16 protected const int SLOT_LAYOUT_WIDTH = 70;
17 protected ChimeraCharacter m_Player;
18 protected SCR_InventoryStorageManagerComponent m_InventoryManager;
19 protected SCR_CharacterInventoryStorageComponent m_InventoryStorage;
20 protected InputManager m_pInputManager;
21 protected BaseInventoryStorageComponent m_Storage;
22 protected SCR_ResourceComponent m_ResourceComponent;
23 protected SCR_ResourceConsumer m_ResourceConsumer;
25 protected ref array<SCR_InventorySlotUI> m_aSlots = {};
31 protected WorkspaceWidget m_workspaceWidget =
null;
32 protected Widget m_widget =
null;
33 protected GridLayoutWidget m_wGrid;
35 protected string m_sGridPath =
"GridLayout0";
36 protected PanelWidget m_wDropContainer;
38 protected bool m_bEnabled =
false;
39 protected bool m_bSelected =
false;
40 protected bool m_bShown =
true;
42 protected RenderTargetWidget m_wPreviewImage, m_wTraversePreviewImage;
45 protected int m_iMaxRows, m_iMaxColumns, m_iPageSize;
47 protected int m_iNrOfPages = 0;
48 protected TextWidget m_wStorageName, m_wCapacityPercentageText, m_wWeightText, m_wResourceAvailableText, m_wResourceStoredText;
49 protected Widget m_wCapacityDisplay, m_wWeightDisplay, m_wResourceAvailableDisplay, m_wResourceStoredDisplay;
50 protected SizeLayoutWidget m_wWidthOverride;
51 protected int m_iLastShownPage = 0;
53 protected ref array<BaseInventoryStorageComponent> m_aTraverseStorage = {};
54 protected ref array<Widget> m_aTraverseTitle = {};
55 protected ref array<SCR_ResourceComponent> m_aResourceCompsInStorage = {};
56 protected ButtonWidget m_wButton, m_wLastCloseTraverseButton, m_wCloseStorageButton;
59 protected LocalizedString m_sSuppliesStoredFormat =
"#AR-Campaign_BaseSuppliesAmount";
60 protected LocalizedString m_sSuppliesAvailableFormat =
"#AR-Supplies_Arsenal_Availability";
67 m_pInputManager =
GetGame().GetInputManager();
69 if ( m_workspaceWidget ==
null )
70 m_workspaceWidget =
GetGame().GetWorkspace();
74 PlayerController pPlayerController =
GetGame().GetPlayerController();
75 if( !pPlayerController )
77 m_Player = ChimeraCharacter.Cast(pPlayerController.GetControlledEntity());
82 m_InventoryManager = SCR_InventoryStorageManagerComponent.Cast(
m_Player.FindComponent( SCR_InventoryStorageManagerComponent ) );
83 m_InventoryStorage = SCR_CharacterInventoryStorageComponent.Cast(
m_Player.FindComponent( SCR_CharacterInventoryStorageComponent ) );
84 m_wGrid = GridLayoutWidget.Cast( m_widget.FindAnyWidget( m_sGridPath ) );
85 m_wStorageName = TextWidget.Cast( m_widget.FindAnyWidget(
"TextC" ) );
86 m_wItemStorage =
ItemPreviewWidget.Cast( m_widget.FindAnyWidget(
"itemStorage" ) );
87 m_wCapacityPercentageText = TextWidget.Cast(m_widget.FindAnyWidget(
"CapacityPercentageText"));
88 m_wWeightText = TextWidget.Cast(m_widget.FindAnyWidget(
"WeightText"));
89 m_wCapacityDisplay = Widget.Cast(m_widget.FindAnyWidget(
"CapacityDisplay"));
90 m_wWeightDisplay = Widget.Cast(m_widget.FindAnyWidget(
"WeightDisplay"));
91 m_wWidthOverride = SizeLayoutWidget.Cast(m_widget.FindWidget(
"TitleWidthOverride"));
97 SizeLayoutWidget wSizeContainer = SizeLayoutWidget.Cast( m_widget.FindAnyWidget(
"SizeLayout0" ) );
99 wSizeContainer.SetAspectRatio( m_iMaxColumns / m_iMaxRows );
101 if (m_wWidthOverride)
102 m_wWidthOverride.SetWidthOverride(m_iMaxColumns * SLOT_LAYOUT_WIDTH);
105 if (!m_InventoryStorage)
106 m_Storage = m_InventoryStorage.GetStorageFromLoadoutSlot( m_eSlotAreaType );
108 m_Storage = m_InventoryStorage.GetWeaponStorage();
116 m_wCapacityDisplay.SetVisible(
true);
117 UpdateVolumePercentage( GetOccupiedVolumePercentage(
m_Storage ) );
120 m_wWeightDisplay.SetVisible(
true);
121 UpdateTotalWeight( GetTotalRoundedUpWeight(
m_Storage ) );
130 UIInfo uiInfo = attributes.GetUIInfo();
133 m_wStorageName.SetText(uiInfo.GetName());
135 m_wResourceStoredDisplay = Widget.Cast(m_widget.FindAnyWidget(
"ResourceDisplayStored"));
136 if (m_wResourceStoredDisplay)
137 m_wResourceStoredText = TextWidget.Cast(m_wResourceStoredDisplay.FindAnyWidget(
"ResourceText"));
139 m_wResourceAvailableDisplay = Widget.Cast(m_widget.FindAnyWidget(
"ResourceDisplayAvailable"));
140 if (m_wResourceAvailableDisplay)
141 m_wResourceAvailableText = TextWidget.Cast(m_wResourceAvailableDisplay.FindAnyWidget(
"ResourceText"));
143 if (!m_wResourceStoredText || !m_wResourceAvailableText)
158 if (!resourceInventoryPlayerComponent)
163 RplId resourceInventoryPlayerComponentRplId = Replication.FindId(resourceInventoryPlayerComponent);
165 if (!resourceInventoryPlayerComponentRplId.IsValid())
174 if( m_InventoryStorage )
177 if ( m_wPagingSpinboxComponent )
179 m_wPagingSpinboxComponent.SetPageCount( 0 );
180 m_wPagingSpinboxComponent.SetCurrentItem( 0,
false );
181 m_wPagingSpinboxComponent.SetButtonsActive(
false);
182 SetPagingActive(
false);
189 void SetPagingActive(
bool active)
191 if (!m_wPagingSpinboxComponent)
194 m_wPagingSpinboxComponent.m_OnChanged.Remove(Action_ChangePage);
196 m_wPagingSpinboxComponent.m_OnChanged.Insert(Action_ChangePage);
198 m_wPagingSpinboxComponent.SetButtonsActive(active);
199 m_wPagingSpinboxComponent.SetButtonsVisible(active);
203 override bool OnFocus( Widget w,
int x,
int y )
211 override bool OnFocusLost( Widget w,
int x,
int y )
219 override bool OnMouseEnter(Widget w,
int x,
int y)
228 override bool OnMouseLeave( Widget w, Widget enterW,
int x,
int y)
230 if (enterW && w && w.FindAnyWidget(enterW.GetName()))
253 void SetRowsAndColumns()
255 for (
int m = 0; m < m_iMaxRows; m++ )
257 m_wGrid.SetRowFillWeight( m, 0 );
258 for (
int n = 0; n < m_iMaxColumns; n++ )
260 m_wGrid.SetColumnFillWeight( n, 0 );
266 private BaseInventoryStorageComponent PushState(BaseInventoryStorageComponent storage)
268 m_aTraverseStorage.Insert(storage);
273 private BaseInventoryStorageComponent PopState(
int traverseStorageIndex)
275 if ( m_aTraverseStorage.IsEmpty() )
278 if ( traverseStorageIndex == -1 )
281 for (
int i = m_aTraverseStorage.Count() - 1; i >= traverseStorageIndex; --i)
283 m_aTraverseStorage.Remove(i);
284 if (m_aTraverseStorage.IsEmpty())
287 return m_aTraverseStorage[ m_aTraverseStorage.Count() - 1 ];
291 BaseInventoryStorageComponent GetCurrentNavigationStorage()
293 if (m_aTraverseStorage.Count() > 0)
295 return m_aTraverseStorage[m_aTraverseStorage.Count() - 1];
301 bool IsTraversalAllowed()
307 void Traverse(BaseInventoryStorageComponent storage)
310 PushState( storage );
311 FillItemsFromStorage( storage );
316 if (!m_aTraverseStorage.Find(storage))
318 IEntity entity = storage.GetOwner();
324 inventoryMenu.OpenLinkedStorages(storage,
false);
328 void Back(
int traverseStorageIndex)
332 BaseInventoryStorageComponent lastStorage = m_aTraverseStorage.Get(traverseStorageIndex);
336 IEntity entity = lastStorage.GetOwner();
342 inventoryMenu.CloseLinkedStorages(lastStorage);
345 auto storage = PopState( traverseStorageIndex );
353 FillItemsFromStorage( storage );
362 m_aTraverseStorage.Clear();
363 ClearTraverseTitles();
370 float GetTotalResources(notnull SCR_ResourceConsumer resourceContainer)
372 return resourceContainer.GetAggregatedResourceValue();
376 float GetMaxResources(notnull SCR_ResourceConsumer resourceContainer)
378 return resourceContainer.GetAggregatedMaxResourceValue();
382 void GetTraverseStorage( out notnull array<BaseInventoryStorageComponent> aTraverseStorage )
384 aTraverseStorage.Copy( m_aTraverseStorage );
390 int slotToFocus = -1;
393 ShowPage(m_wPagingSpinboxComponent.GetCurrentIndex(), slotToFocus);
395 GetGame().GetCallqueue().CallLater(
m_MenuHandler.FocusOnSlotInStorage, 0,
false,
this, slotToFocus);
399 void Action_PrevPage()
401 int slotToFocus = -1;
404 ShowPage(m_iLastShownPage - 1, slotToFocus);
406 GetGame().GetCallqueue().CallLater(
m_MenuHandler.FocusOnSlotInStorage, 0,
false,
this, slotToFocus);
409 void Action_NextPage()
411 int slotToFocus = -1;
414 ShowPage(m_iLastShownPage + 1, slotToFocus);
416 GetGame().GetCallqueue().CallLater(
m_MenuHandler.FocusOnSlotInStorage, 0,
false,
this, slotToFocus);
420 bool IsStorageEnabled() {
return m_bEnabled; }
424 bool GetLastShownPage() {
return m_iLastShownPage; }
427 BaseInventoryStorageComponent GetStorage() {
return m_Storage; }
430 EquipedWeaponStorageComponent GetWeaponStorage() {
return EquipedWeaponStorageComponent.Cast(
m_Storage ); }
433 string GetStorageName()
438 UIInfo uiInfo = attributes.GetUIInfo();
441 return uiInfo.GetName();
451 void Show(
bool bShow )
492 Widget GetStorageGrid() {
return m_wGrid; }
495 Widget GetRootWidget() {
return m_widget; }
502 SCR_InventoryStorageManagerComponent GetInventoryManager() {
return m_InventoryManager; }
506 protected void SetSlotAreaType(
LoadoutAreaType eSlotType ) { m_eSlotAreaType = eSlotType; }
514 void GetUISlots( out array<SCR_InventorySlotUI> outArray)
521 array<SCR_InventorySlotUI> GetUISlots()
535 void RefreshSlot(
int index);
539 protected Widget CreateEmptySlotUI(
int iRow,
int iCol )
541 Widget pWidget = m_workspaceWidget.CreateWidgets( SLOT_LAYOUT_1x1_EMPTY, m_wGrid );
542 GridSlot.SetColumn( pWidget, iCol );
543 GridSlot.SetRow( pWidget, iRow );
557 else if ( WeaponAttachmentsStorageComponent.Cast( pComponent ) )
561 else if (SCR_ResourceComponent.FindResourceComponent(pComponent.GetOwner()))
565 else if ( BaseInventoryStorageComponent.Cast( pComponent ) )
569 else if (pComponent.GetOwner().FindComponent(SCR_ArsenalInventoryStorageManagerComponent))
572 BaseInventoryStorageComponent inventoryStorageComponent = GetCurrentNavigationStorage();
574 if (inventoryStorageComponent)
576 slotUI.SetArsenalResourceComponent(SCR_ResourceComponent.FindResourceComponent(inventoryStorageComponent.GetOwner()));
590 protected void DeleteSlots()
605 private bool ValidateNavigationQueue()
607 int traverseSize = m_aTraverseStorage.Count();
609 if (traverseSize > 0)
611 BaseInventoryStorageComponent lastStorage =
null;
612 ref array<IEntity> rootItems =
new array<IEntity>();
613 GetAllItems(rootItems);
615 for (
int i = 0; i < traverseSize; i++)
617 BaseInventoryStorageComponent current = m_aTraverseStorage[i];
622 for (
int j = 0; j < rootItems.Count(); j++)
627 auto storage = BaseInventoryStorageComponent.Cast(
628 rootItems[j].FindComponent(BaseInventoryStorageComponent)
632 BaseInventoryStorageComponent parentStorage;
633 if ( current.GetParentSlot() )
634 parentStorage = current.GetParentSlot().GetStorage();
636 found = storage == current || parentStorage == storage;
646 if (i == traverseSize - 1)
648 lastStorage = current;
653 current.GetAll(rootItems);
661 protected void RefreshConsumer()
672 void RefreshResources()
676 float resources, maxResources;
677 bool hasStored =
false;
682 UpdateStoredResources(resources, maxResources);
684 m_wResourceStoredDisplay.SetVisible(
true);
688 m_wResourceStoredDisplay.SetVisible(
false);
694 UpdateAvailableResources(resources, hasStored);
695 m_wResourceAvailableDisplay.SetVisible(
true);
699 m_wResourceAvailableDisplay.SetVisible(
false);
709 if ( ValidateNavigationQueue() )
711 int traverseSize = m_aTraverseStorage.Count();
712 if (traverseSize > 0)
714 ClearTraverseTitles();
715 FillItemsFromStorage(m_aTraverseStorage[traverseSize - 1]);
725 m_iLastShownPage = 0;
726 m_aTraverseStorage.Clear();
727 ClearTraverseTitles();
733 ShowPage(m_iLastShownPage);
737 UpdateVolumePercentage( GetOccupiedVolumePercentage(
m_Storage ) );
738 UpdateTotalWeight( GetTotalRoundedUpWeight(
m_Storage ) );
741 array<IEntity> tmpAItemsInStorage =
new array<IEntity>();
742 BaseInventoryStorageComponent tmpStorage =
m_Storage;
743 GetAllItemsFromDepth( tmpAItemsInStorage );
746 SetStorageAsHighlighted(
true);
748 if ( m_pSelectedSlot )
749 m_pSelectedSlot.Refresh();
751 array<IEntity> itemsInStorage = {};
752 GetAllItems(itemsInStorage);
753 CheckIfAnyItemInStorageHasResources(itemsInStorage);
758 protected void UpdateStoredResources(
float totalResources,
float maxResources)
760 if (!m_wResourceStoredText)
772 protected void UpdateAvailableResources(
float totalResources,
bool hasStored)
774 if (!m_wResourceAvailableText)
783 m_wResourceAvailableText.SetTextFormat(m_sSuppliesAvailableFormat,
SCR_ResourceSystemHelper.SuppliesToString(totalResources));
789 protected void UpdateContainerResources(notnull Widget targetTitle, notnull BaseInventoryStorageComponent targetStorage)
791 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(targetStorage.GetOwner());
792 if(!resourceComponent)
795 float totalResources, maxResources;
797 Widget resourceDisplay = targetTitle.FindAnyWidget(
"ResourceDisplayStored");
798 TextWidget resourceText;
802 resourceText = TextWidget.Cast(resourceDisplay.FindAnyWidget(
"ResourceText"));
805 if (resourceText &&
SCR_ResourceSystemHelper.GetStoredAndMaxResources(resourceComponent, totalResources, maxResources))
808 resourceDisplay.SetVisible(
true);
812 resourceDisplay.SetVisible(
false);
816 resourceDisplay = targetTitle.FindAnyWidget(
"ResourceDisplayAvailable");
820 resourceText = TextWidget.Cast(resourceDisplay.FindAnyWidget(
"ResourceText"));
823 if (resourceText &&
SCR_ResourceSystemHelper.GetAvailableResources(resourceComponent, totalResources) && resourceComponent.IsResourceTypeEnabled())
826 resourceDisplay.SetVisible(
true);
831 resourceDisplay.SetVisible(
false);
836 protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
841 int iCompensationOffset = 0;
843 for (
int i = 0; i < pItemsInStorage.Count(); i++)
851 bool stackable = (attributes && attributes.IsStackable());
853 int m = FindItem( pComponent );
855 if ( m != -1 && stackable )
857 m_aSlots[ m ].IncreaseStackNumber();
858 iCompensationOffset++;
862 if ( i - iCompensationOffset >
m_aSlots.Count()-1 )
863 m_aSlots.Insert( CreateSlotUI(pComponent) );
865 m_aSlots[ i - iCompensationOffset++ ] = CreateSlotUI(pComponent);
871 void UpdateSlotUI(ResourceName item)
873 int id = GetSlotIdForItem(item);
875 array<IEntity> pItemsInStorage = {};
877 BaseInventoryStorageComponent storage = GetCurrentNavigationStorage();
879 GetAllItems(pItemsInStorage, storage);
881 int count = pItemsInStorage.Count();
882 int newStackCount = 0;
885 for (
int i = 0; i < count; ++i)
887 if (pItemsInStorage[i].
GetPrefabData().GetPrefabName() == item)
889 comp = GetItemComponentFromEntity(pItemsInStorage[i]);
894 m_aSlots[id].UpdateInventorySlot(comp, newStackCount);
899 protected void UpdateOwnedSlots(notnull array<BaseInventoryStorageComponent> pItemsInStorage)
901 int count = pItemsInStorage.Count();
904 for (
int i =
m_aSlots.Count() - count; i > 0; i--)
913 for (
int i = 0; i < count; i++)
916 m_aSlots[i].UpdateReferencedComponent(pItemsInStorage[i]);
918 m_aSlots[i] = CreateSlotUI(pItemsInStorage[i]);
953 IEntity pEntity = pInvItem.GetOwner();
956 EntityPrefabData pEntPrefabData = pEntity.GetPrefabData();
957 if ( !pEntPrefabData )
959 float fWeight = pInvItem.GetTotalWeight();
961 MagazineComponent pMagazine = MagazineComponent.Cast( pEntity.FindComponent( MagazineComponent ) );
963 for (
int i =
m_aSlots.Count() - 1; i >= 0; i-- )
969 if ( fWeight != pInvItemActual.GetTotalWeight() )
972 IEntity pEnt = pInvItemActual.GetOwner();
973 if ( pEnt && ( pEntPrefabData == pEnt.GetPrefabData() ) )
975 MagazineComponent pMagazineActual = MagazineComponent.Cast( pEnt.FindComponent( MagazineComponent ) );
976 if ( pMagazineActual )
987 protected int FindItemByName(
string sItemName,
int iActualIndex )
990 for (
int i = 0; i < iCount; i++ )
994 string sName =
m_aSlots[ i ].GetItemName();
995 if ( sName.Compare( sItemName,
false ) == 0 )
1007 return string.Empty;
1008 if ( !pAttributes.GetUIInfo() )
1009 return string.Empty;
1010 return pAttributes.GetUIInfo().GetName();
1015 protected int CreateSlots( )
1017 ref array<IEntity> pItemsInStorage =
new array<IEntity>();
1018 GetAllItems( pItemsInStorage );
1019 UpdateOwnedSlots(pItemsInStorage);
1025 protected void SortSlots()
1027 array<int> aCoordinates;
1028 int iWidgetColumnSize, iWidgetRowSize;
1029 int iPageCounter = 0;
1039 Widget w = pSlot.GetWidget();
1043 iWidgetColumnSize = pSlot.GetColumnSize();
1044 iWidgetRowSize = pSlot.GetRowSize();
1047 aCoordinates = m_iMatrix.Reserve1stFreePlace( iWidgetColumnSize, iWidgetRowSize );
1049 if( ( aCoordinates[0] != -1 ) && ( aCoordinates[1] != -1 ) )
1051 GridSlot.SetColumn( w, aCoordinates[0] );
1052 GridSlot.SetRow( w, aCoordinates[1] );
1053 pSlot.SetPage( iPageCounter );
1060 aCoordinates = m_iMatrix.Reserve1stFreePlace( iWidgetColumnSize, iWidgetRowSize );
1061 if( ( aCoordinates[0] == -1 ) || ( aCoordinates[1] == -1 ) )
1063 GridSlot.SetColumn( w, aCoordinates[0] );
1064 GridSlot.SetRow( w, aCoordinates[1] );
1065 pSlot.SetPage( iPageCounter );
1067 GridSlot.SetColumnSpan( w, iWidgetColumnSize );
1068 GridSlot.SetRowSpan( w, iWidgetRowSize );
1070 m_iNrOfPages = iPageCounter + 1;
1074 protected void FillWithEmptySlots()
1076 array<int> aCoordinates = {};
1082 ReserveAndSetSlot( iIndex );
1088 void ReserveAndSetSlot(
int iIndex, )
1090 array<int> aCoordinates = m_iMatrix.Reserve1stFreePlace( 1, 1 );
1092 pAttrib.SetSlotType(
ESlotID.SLOT_ANY );
1093 pAttrib.SetSlotSize(
ESlotSize.SLOT_1x1 );
1096 GridSlot.SetColumn( pSlotNew.GetWidget(), aCoordinates[0] );
1097 GridSlot.SetRow( pSlotNew.GetWidget(), aCoordinates[1] );
1103 protected void ShowPage(
int iPage, out
int slotToFocus = -1 )
1105 if( iPage >= m_iNrOfPages )
1106 iPage = m_iNrOfPages - 1;
1114 bool visible = (pSlot.GetPage() == iPage);
1115 pSlot.SetSlotVisible(visible);
1116 if (visible && slotToFocus == -1)
1121 if( m_iNrOfPages > 1 )
1122 ShowPagesCounter(
true, iPage+1, m_iNrOfPages );
1124 ShowPagesCounter(
false );
1126 if ( m_wPagingSpinboxComponent )
1127 m_wPagingSpinboxComponent.SetCurrentItem( iPage,
false );
1129 m_iLastShownPage = iPage;
1134 protected void ClearTraverseTitles()
1136 if (m_aTraverseTitle.IsEmpty())
1139 Widget titleLayout = m_widget.FindAnyWidget(
"titleLayout");
1143 foreach (Widget title: m_aTraverseTitle)
1145 titleLayout.RemoveChild(title);
1148 m_aTraverseTitle.Clear();
1153 protected void FillItemsFromStorage(BaseInventoryStorageComponent storage)
1155 ClearTraverseTitles();
1157 int count = m_aTraverseStorage.Count();
1159 array<IEntity> pItemsInStorage =
new array<IEntity>();
1160 GetAllItems(pItemsInStorage, GetCurrentNavigationStorage());
1161 UpdateOwnedSlots(pItemsInStorage);
1163 BaseInventoryStorageComponent currentStorage;
1164 Widget titleLayout = m_widget.FindAnyWidget(
"titleLayout");;
1166 RenderTargetWidget previewImage;
1167 ItemPreviewManagerEntity manager;
1169 IEntity previewEntity;
1171 ButtonWidget navigationHelperWidget;
1174 for (
int i = 0; i < count; ++i)
1176 currentStorage = m_aTraverseStorage[i];
1178 if (currentStorage.GetOwner().FindComponent(SCR_ArsenalInventoryStorageManagerComponent))
1179 title =
GetGame().GetWorkspace().CreateWidgets(ARSENAL_TITLE_LAYOUT, titleLayout);
1180 else if (SCR_ResourceComponent.FindResourceComponent(currentStorage.GetOwner(),
true))
1181 title =
GetGame().GetWorkspace().CreateWidgets(SUPPLY_TITLE_LAYOUT, titleLayout);
1183 title =
GetGame().GetWorkspace().CreateWidgets(STORAGE_TITLE_LAYOUT, titleLayout);
1188 m_aTraverseTitle.Insert( title );
1190 previewImage = RenderTargetWidget.Cast(title.FindAnyWidget(
"itemStorage"));
1191 manager = GetInventoryMenuHandler().GetItemPreviewManager();
1195 previewEntity =
null;
1196 if (renderPreview && currentStorage)
1197 manager.SetPreviewItem(renderPreview, currentStorage.GetOwner(),
null,
true);
1200 FindAndSetTitleName(title, currentStorage);
1201 UpdateContainerResources(title, currentStorage);
1204 if (!closeContainerButton)
1207 closeContainerButton.m_OnActivated.Insert(
m_MenuHandler.OnAction);
1208 closeContainerButton.SetParentStorage(
this);
1209 closeContainerButton.SetStorageIndex(i);
1210 closeContainerButton.SetVisible(
true);
1212 navigationHelperWidget = ButtonWidget.Cast(title.FindAnyWidget(
"navigationHelper"));
1214 if (!navigationHelperWidget)
1218 m_wLastCloseTraverseButton = navigationHelperWidget;
1223 if(!navigationHandler)
1226 navigationHandler.GetOnClick().Insert(closeContainerButton.OnActivate);
1231 protected void FindAndSetTitleName(Widget targetTitle, BaseInventoryStorageComponent targetStorage)
1233 TextWidget titleNameWidget = TextWidget.Cast(targetTitle.FindAnyWidget(
"TextC"));
1234 if(!titleNameWidget)
1239 UIInfo uiInfo = attributes.GetUIInfo();
1242 titleNameWidget.SetText(uiInfo.GetName());
1247 protected void GetAllItems( out notnull array<IEntity> pItemsInStorage, BaseInventoryStorageComponent pStorage =
null )
1251 IEntity ownerEntity = pStorage.GetOwner();
1252 SCR_ArsenalInventoryStorageManagerComponent arsenalManagerComponent = SCR_ArsenalInventoryStorageManagerComponent.Cast(ownerEntity.FindComponent(SCR_ArsenalInventoryStorageManagerComponent));
1254 if (arsenalManagerComponent)
1260 ItemPreviewManagerEntity itemPreviewManagerEntity = chimeraWorld.GetItemPreviewManager();
1263 array<ResourceName> prefabsToSpawn =
new array<ResourceName>();
1265 if (!arsenalComponent)
1268 arsenalComponent.GetAvailablePrefabs(prefabsToSpawn);
1270 foreach (ResourceName resourceName: prefabsToSpawn)
1272 pItemsInStorage.Insert(itemPreviewManagerEntity.ResolvePreviewEntityForPrefab(resourceName));
1278 if (ClothNodeStorageComponent.Cast(pStorage))
1280 array<BaseInventoryStorageComponent> pStorages = {};
1281 array<IEntity> pItems = {};
1282 pStorage.GetOwnedStorages(pStorages, 1,
false);
1284 foreach (BaseInventoryStorageComponent pStor : pStorages)
1288 pStor.GetAll(pItems);
1289 pItemsInStorage.Copy(pItems);
1294 pStorage.GetAll(pItemsInStorage);
1306 protected void GetAllItemsFromDepth( out notnull array<IEntity> pItemsInStorages,
int iDepth = 3,
int iDepthDefault = 0 )
1312 if ( iDepthDefault == 0 )
1313 iDepthDefault = iDepth;
1315 #ifdef DEBUG_INVENTORY20
1316 if ( iDepthDefault == iDepth )
1322 UIInfo pInfo = pAttribs.GetUIInfo();
1324 sStorageName = pInfo.GetName();
1325 Print(
"-----------------------------------------------" );
1326 PrintFormat(
"%1 ( %2 )", sStorageName, BaseInventoryStorageComponent.Cast(
m_Storage ) );
1331 array<IEntity> aTraverseStorageTmp =
new array<IEntity>();
1332 m_Storage.GetAll( aTraverseStorageTmp );
1336 for (
int m = 0; m < aTraverseStorageTmp.Count(); m++ )
1338 pEntity = aTraverseStorageTmp[ m ];
1340 m_Storage = BaseInventoryStorageComponent.Cast( pEntity.FindComponent( BaseInventoryStorageComponent ) );
1343 pItemsInStorages.Insert( pEntity );
1346 #ifdef DEBUG_INVENTORY20
1351 string sTextIn =
"";
1352 ConstructSlashes( sTextIn, iDepthDefault-iDepth );
1353 PrintFormat(
"|%1 %2 ( %3 )", sTextIn, sName,
m_Storage );
1355 GetAllItemsFromDepth( pItemsInStorages, iDepth - 1, iDepthDefault );
1357 #ifdef DEBUG_INVENTORY20
1360 if ( pInventoryComponent )
1363 if ( pInventoryComponent.GetAttributes() )
1364 if ( pInventoryComponent.GetAttributes().GetUIInfo() )
1365 sName = pInventoryComponent.GetAttributes().GetUIInfo().GetName();
1366 string sTextIn =
"";
1367 ConstructSlashes( sTextIn, iDepthDefault-iDepth );
1368 PrintFormat(
"|%1 %2 ( %3 )", sTextIn, sName, pInventoryComponent );
1376 void UpdateTotalWeight(
float totalWeight, Color fontColor = Color.Gray25)
1381 m_wWeightText.SetTextFormat(
"#AR-ValueUnit_Short_Kilograms", totalWeight);
1383 if (fontColor != m_wWeightText.GetColor())
1384 m_wWeightText.SetColor(Color.FromInt(fontColor.PackToInt()));
1388 float GetTotalRoundedUpWeight(BaseInventoryStorageComponent storage)
1393 float totalWeight = storage.GetTotalWeight();
1395 totalWeight = Math.Round(totalWeight * 100);
1397 return totalWeight / 100;
1401 void UpdateVolumePercentage(
float percentage, Color fontColor = Color.Gray25)
1403 if (!m_wCapacityPercentageText)
1406 if (fontColor != m_wCapacityPercentageText.GetColor())
1407 m_wCapacityPercentageText.SetColor(Color.FromInt(fontColor.PackToInt()));
1409 m_wCapacityPercentageText.SetText(percentage.ToString() +
"%");
1413 protected bool CheckIfAnyItemInStorageHasResources(array<IEntity> items)
1415 SCR_ResourceComponent resComp;
1417 foreach(SCR_ResourceComponent oldResComp: m_aResourceCompsInStorage)
1427 oldResComp.TEMP_GetOnInteractorReplicated().Remove(RefreshResources);
1430 m_aResourceCompsInStorage.Clear();
1432 foreach (IEntity item: items)
1437 resComp = SCR_ResourceComponent.FindResourceComponent(item);
1442 m_aResourceCompsInStorage.Insert(resComp);
1449 resComp.TEMP_GetOnInteractorReplicated().Insert(RefreshResources);
1452 if (m_aResourceCompsInStorage.IsEmpty())
1459 float GetOccupiedVolumePercentage(BaseInventoryStorageComponent storage,
float occupiedSpace = 0)
1464 float occupiedVolumePercantage;
1465 float capacity = GetMaxVolumeCapacity(storage);
1470 if (occupiedSpace != 0)
1471 occupiedVolumePercantage = Math.Round(occupiedSpace / (capacity / 100));
1473 occupiedVolumePercantage = Math.Round(GetOccupiedVolume(storage) / (capacity / 100));
1475 return occupiedVolumePercantage;
1479 float GetOccupiedVolume(BaseInventoryStorageComponent storage)
1484 float fOccupied = 0.0;
1485 if (ClothNodeStorageComponent.Cast(storage))
1487 array<BaseInventoryStorageComponent> pOwnedStorages = {};
1488 storage.GetOwnedStorages(pOwnedStorages, 1,
false);
1489 foreach (BaseInventoryStorageComponent pSubStorage : pOwnedStorages)
1491 fOccupied += pSubStorage.GetOccupiedSpace();
1495 fOccupied = storage.GetOccupiedSpace();
1502 float GetMaxVolumeCapacity(BaseInventoryStorageComponent storage)
1507 float fMaxCapacity = 0.0;
1508 if (ClothNodeStorageComponent.Cast(storage))
1510 array<BaseInventoryStorageComponent> pOwnedStorages = {};
1511 storage.GetOwnedStorages(pOwnedStorages, 1,
false);
1512 foreach (BaseInventoryStorageComponent pSubStorage : pOwnedStorages)
1514 fMaxCapacity += pSubStorage.GetMaxVolumeCapacity();
1518 fMaxCapacity = storage.GetMaxVolumeCapacity();
1521 return fMaxCapacity;
1525 void SetStorageAsHighlighted(
bool isVisible)
1531 m_widget.SetOpacity(1);
1533 m_widget.SetOpacity(STORAGE_NON_HIGHLIGHTED_OPACITY);
1537 bool IsStorageHighlighted()
1539 return (m_widget.GetOpacity() == 1);
1544 private void ConstructSlashes( out
string sText,
int iSlashes )
1546 for (
int m = 0; m <= ( iSlashes * 2 ); m++ )
1554 protected void CreateEmptyLayout()
1556 for(
int iLoop = 0; iLoop < m_iMaxRows; iLoop++ )
1557 for(
int jLoop = 0; jLoop < m_iMaxColumns; jLoop++ )
1558 CreateEmptySlotUI( iLoop, jLoop );
1566 if ( pEntity ==
null )
1573 void GetSlots( out notnull array<SCR_InventorySlotUI> outSlots )
1580 void ShowItemDetails(
string sName,
string sDescription,
string sWeight );
1584 private void ShowPagesCounter(
bool bShow =
false,
int iPage = 0,
int iNumberOfPages = 0 )
1586 if ( !m_wPagingSpinboxComponent )
1589 m_wPagingSpinboxComponent.SetVisible( bShow,
false );
1593 m_wPagingSpinboxComponent.SetCanNavigate(
true );
1594 m_wPagingSpinboxComponent.SetPageCount( iNumberOfPages );
1595 m_wPagingSpinboxComponent.SetCurrentItem( iPage,
false );
1599 m_wPagingSpinboxComponent.SetCanNavigate(
true );
1609 m_pLastFocusedSlot = pSlot;
1620 m_pFocusedSlot = pSlotUI;
1628 m_pFocusedSlot =
null;
1640 m_pPrevSelectedSlot = m_pSelectedSlot;
1644 m_pSelectedSlot = pSlot;
1647 m_pSelectedSlot =
null;
1651 void ShowContainerBorder(
bool bShow )
1653 if ( m_wDropContainer )
1654 m_wDropContainer.SetVisible( bShow );
1658 void ActivateStorageButton(
bool active)
1666 if (slot && slot.GetButtonWidget())
1667 slot.GetButtonWidget().SetEnabled(!active);
1671 if (m_wLastCloseTraverseButton)
1672 m_wLastCloseTraverseButton.SetEnabled(!active);
1676 int GetFocusedSlotId()
1678 if (!m_pFocusedSlot)
1680 return m_aSlots.Find(m_pFocusedSlot);
1684 int GetSlotIdForItem(ResourceName itemName)
1689 for (
int slotId = 0; slotId < slotCount; ++slotId)
1692 if (slot && slot.GetItemResource() == itemName)
1702 protected void SetPreviewItem()
1704 m_wPreviewImage = RenderTargetWidget.Cast( m_widget.FindAnyWidget(
"itemStorage" ) );
1710 ItemPreviewManagerEntity manager = world.GetItemPreviewManager();
1718 IEntity previewEntity =
null;
1722 manager.SetPreviewItem(renderPreview, previewEntity,
null,
true);
1728 void DimSlots(
bool bDim )
1734 if ( !pSlot.IsSlotSelected() )
1736 pSlot.SetEnabledForMove( !bDim );
1742 override void HandlerAttached( Widget w )
1747 m_wDropContainer = PanelWidget.Cast( w.FindAnyWidget(
"DropContainer" ) );
1748 m_wButton = ButtonWidget.Cast(w.FindAnyWidget(
"Button"));
1754 btn.SetParent(
this);
1759 newBtn.SetParent(
this);
1771 override event void HandlerDeattached(Widget w)
1780 Widget GetButtonWidget()
1786 ButtonWidget GetLastCloseTraverseButton()
1788 return m_wLastCloseTraverseButton;
1793 BaseInventoryStorageComponent storage,
1797 array<BaseInventoryStorageComponent> aTraverseStorage =
null)
1801 m_eSlotAreaType = slotID;
1804 m_iMatrix =
new SCR_Matrix( m_iMaxColumns, m_iMaxRows );
1805 m_iPageSize = m_iMaxRows * m_iMaxColumns;
1806 m_iLastShownPage = iPage;
1807 if ( aTraverseStorage )
1808 m_aTraverseStorage.Copy( aTraverseStorage );
1827 override bool OnFocus(Widget w,
int x,
int y)
1829 m_Parent.GetInventoryMenuHandler().OnContainerFocused(m_Parent);
1834 override bool OnFocusLost(Widget w,
int x,
int y)
1836 m_Parent.GetInventoryMenuHandler().OnContainerFocusLeft(m_Parent);