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