Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_InventoryWeaponSlotsUI.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/UI/Inventory", description: "Inventory 2.0 Weapon Slots UI class")]
2 
3 //------------------------------------------------------------------------------------------------
7 {
8  protected ref array<WeaponSlotComponent> m_aWeaponSlots = new array<WeaponSlotComponent>(); ;
9  protected EquipedWeaponStorageComponent m_weaponStorage;
10 
11 
12  //------------------------------------------------------------------------------------------------
13  override void HandlerAttached(Widget w)
14  {
15  m_weaponStorage = EquipedWeaponStorageComponent.Cast(m_Storage);
16 
17  super.HandlerAttached(w);
18  CreateEmptyLayout();
19  CreateSlots();
20  SortSlots();
21  InitMatrix();
22  }
23 
24  //------------------------------------------------------------------------------------------------
25  override void InitPaging()
26  {}
27 
28  //------------------------------------------------------------------------------------------------
29  override bool IsTraversalAllowed()
30  {
31  return false;
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  // !
36  override protected int CreateSlots()
37  {
38  array<IEntity> pItemsInStorage = {};
39  array<Managed> weaponSlots = {};
40 
41  m_Player.FindComponents(WeaponSlotComponent, weaponSlots);
42 
43  m_iMaxColumns = Math.Min(weaponSlots.Count(), SCR_InventoryMenuUI.WEAPON_SLOTS_COUNT);
44 
45  pItemsInStorage.Resize(m_iMaxColumns);
46  m_aWeaponSlots.Resize(m_iMaxColumns);
47 
48  WeaponSlotComponent weaponSlot;
49  int weaponSlotIndex;
50  foreach (Managed managed : weaponSlots)
51  {
52  weaponSlot = WeaponSlotComponent.Cast(managed);
53  if (!weaponSlot)
54  continue;
55 
56  weaponSlotIndex = weaponSlot.GetWeaponSlotIndex();
57  if (weaponSlotIndex < m_iMaxColumns)
58  {
59  pItemsInStorage.Set(weaponSlotIndex, weaponSlot.GetWeaponEntity());
60  m_aWeaponSlots.Set(weaponSlotIndex, weaponSlot);
61  }
62  }
63 
64  UpdateOwnedSlots(pItemsInStorage);
65  FillWithEmptySlots();
66  return 0;
67  }
68 
69  //------------------------------------------------------------------------------------------------
70  // !
71  override protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
72  {
73  int count = pItemsInStorage.Count();
74  if (count < m_aSlots.Count())
75  {
76  for (int i = m_aSlots.Count() - count; i > 0; i--)
77  {
78  SCR_InventorySlotUI slotUI = m_aSlots[m_aSlots.Count() - 1];
79  if (slotUI)
80  slotUI.Destroy();
81  }
82  }
83  m_aSlots.Resize(count);
84  for (int i = 0; i < count; i++)
85  {
86  InventoryItemComponent pComponent = GetItemComponentFromEntity( pItemsInStorage[i] );
87 
88  if (m_aSlots[i])
89  m_aSlots[i].UpdateReferencedComponent(pComponent);
90  else
91  m_aSlots[i] = CreateSlotUI(pComponent, i, null, i, m_aWeaponSlots[i].GetWeaponSlotType());
92  }
93  }
94 
95  //------------------------------------------------------------------------------------------------
96  override void FillWithEmptySlots()
97  {
98  array<int> aCoordinates;
99  int iWidgetColumnSize, iWidgetRowSize;
100  int iPageCounter = 0;
101  int iRelativeOffset = 0; //if there's an item taking more than one slot, offset the following items to the right
102 
103  foreach( int iIndex, SCR_InventorySlotUI pSlot: m_aSlots )
104  {
105  if( !pSlot ) //if pSlot doesn't exist it means no assigned item in this slot and we create the "empty" slot
106  {
107  ESlotSize eSlotSize;
108  if ( iIndex > 1 )
109  eSlotSize = ESlotSize.SLOT_1x1;
110  else
111  eSlotSize = ESlotSize.SLOT_2x1; //first 2 slots are dedicated to weapons ( thus 2x1 layout)
112 
114  pAttrib.SetSlotType( ESlotID.SLOT_ANY );
115  pAttrib.SetSlotSize( eSlotSize );
116  pSlot = SCR_InventorySlotWeaponSlotsUI.Cast( CreateSlotUI( null, iIndex, pAttrib, iIndex, m_aWeaponSlots[iIndex].GetWeaponSlotType() ) );
117  m_aSlots.Set( iIndex, pSlot );
118  }
119  Widget w = pSlot.GetWidget();
120  if( !w )
121  continue;
122 
123  iWidgetColumnSize = pSlot.GetColumnSize();
124  iWidgetRowSize = pSlot.GetRowSize();
125 
126  int iCol = pSlot.GetSlotIndex() + iRelativeOffset;
127  m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
128  GridSlot.SetColumn( w, iCol );
129  iRelativeOffset += ( iWidgetColumnSize - 1 );
130  GridSlot.SetRow( w, 0 );
131 
132  GridSlot.SetColumnSpan( w, iWidgetColumnSize );
133  GridSlot.SetRowSpan( w, iWidgetRowSize );
134  }
135 
136  SetRowsAndColumns();
137  }
138 
139  //------------------------------------------------------------------------------------------------
140  // ! creates the slot
141  protected SCR_InventorySlotWeaponSlotsUI CreateSlotUI(InventoryItemComponent pComponent, int iSlotIndex, SCR_ItemAttributeCollection pAttributes = null, int iWeaponSlotIndex = -1, string sWeaponSlotType = "")
142  {
143  return SCR_InventorySlotWeaponSlotsUI( pComponent, this, true, iSlotIndex, pAttributes, iWeaponSlotIndex, sWeaponSlotType ); //creates the slot
144  }
145 
146  //------------------------------------------------------------------------------------------------
147  override void SetRowsAndColumns()
148  {
149  // leave this empty because we need to initialize rows and columns in different place
150  }
151 
152  //------------------------------------------------------------------------------------------------
153  int GetActualSlotsUsedCount()
154  {
155  int result = 0;
156  int slotCount = m_aSlots.Count();
157  SCR_InventorySlotUI slot;
158  for (int id = 0; id < slotCount; ++id)
159  {
160  slot = m_aSlots[id];
161  if (slot)
162  result += slot.GetColumnSize();
163  }
164 
165  return result;
166  }
167 
168  //------------------------------------------------------------------------------------------------
169  // ! creates the the grid from array of UI items
170  override protected void SortSlots()
171  {
172  int iWidgetColumnSize, iWidgetRowSize;
173  int iPageCounter = 0;
174  int iRelativeOffset = 0; //if there's an item taking more than one slot, offset the following items to the right
175 
176  //reset all elements to 0 - free it
177  m_iMatrix.Reset();
178 
179  foreach( SCR_InventorySlotUI pSlot: m_aSlots )
180  {
181  if( !pSlot )
182  continue;
183 
184  Widget w = pSlot.GetWidget();
185  if( !w )
186  continue;
187 
188  iWidgetColumnSize = pSlot.GetColumnSize();
189  iWidgetRowSize = pSlot.GetRowSize();
190 
191  int iCol = pSlot.GetSlotIndex() + iRelativeOffset;
192  m_iMatrix.ReservePlace( iWidgetColumnSize, iWidgetRowSize, iCol, 0 );
193  GridSlot.SetColumn( w, iCol );
194  iRelativeOffset += ( iWidgetColumnSize - 1 );
195  GridSlot.SetRow( w, 0 );
196  pSlot.SetPage( iPageCounter );
197 
198  GridSlot.SetColumnSpan( w, iWidgetColumnSize );
199  GridSlot.SetRowSpan( w, iWidgetRowSize );
200  }
201 
202  m_iNrOfPages = iPageCounter + 1;
203  FillWithEmptySlots();
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  void InitMatrix()
208  {
209  if (!m_wGrid)
210  return;
211 
212  m_iMaxColumns = GetActualSlotsUsedCount();
213  m_iMatrix = new SCR_Matrix(m_iMaxColumns, m_iMaxRows);
214  m_iPageSize = m_iMaxRows * m_iMaxColumns;
215 
216  for (int y = 0; y < m_iMaxRows; ++y)
217  {
218  m_wGrid.SetRowFillWeight(y, 1);
219  for (int x = 0; x < m_iMaxColumns; ++x)
220  {
221  m_wGrid.SetColumnFillWeight(x, 1);
222  }
223  }
224 
225  SizeLayoutWidget wSizeContainer = SizeLayoutWidget.Cast(m_widget.FindAnyWidget("SizeLayout0"));
226  if (wSizeContainer)
227  wSizeContainer.SetAspectRatio(m_iMaxColumns / m_iMaxRows);
228  }
229 
230  //------------------------------------------------------------------------------------------------
231  void SCR_InventoryWeaponSlotsUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID = null, SCR_InventoryMenuUI menuManager = null, int iPage = 0, array<BaseInventoryStorageComponent> aTraverseStorage = null )
232  {
233  m_MenuHandler = menuManager;
234  m_iMaxRows = 1;
235  m_iMaxColumns = 0;
236  m_iMatrix = new SCR_Matrix( m_iMaxColumns, m_iMaxRows );
237  m_sGridPath = "WeaponsGrid";
238  m_Storage = storage;
239  }
240 };
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
ESlotID
ESlotID
Definition: InventoryConstants.c:14
SCR_InventorySlotWeaponSlotsUI
Definition: SCR_InventorySlotWeaponSlotsUI.c:4
WeaponSlotComponent
Definition: WeaponSlotComponent.c:12
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
m_Player
protected ChimeraCharacter m_Player
Definition: SCR_CampaignTutorialComponentArland.c:40
ESlotSize
ESlotSize
Definition: InventoryConstants.c:1
m_aSlots
protected ref array< SCR_WeaponRackSlotEntity > m_aSlots
Definition: SCR_ArsenalDisplayComponent.c:13
SCR_InventoryMenuUI
Definition: SCR_InventoryMenuUI.c:247
SCR_InventoryWeaponSlotsUI
Definition: SCR_InventoryWeaponSlotsUI.c:6
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
SCR_Matrix
Definition: SCR_Matrix.c:2
LoadoutAreaType
Definition: LoadoutAreaType.c:12
m_MenuHandler
SCR_DeployMenuBase m_MenuHandler
Main deploy menu with the map present.
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27
m_Storage
BaseInventoryStorageComponent m_Storage
Definition: SCR_TourniquetStorageComponent.c:10
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180