Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_InventoryGearInspectionSlotUI.c
Go to the documentation of this file.
2{
3 protected ref array<InventoryStorageSlot> m_aStorageSlotsInStorage = {};
4
6 protected SCR_WeaponAttachmentsStorageComponent m_WeaponStorage;
7
8 //------------------------------------------------------------------------------------------------
9 override void HandlerAttached(Widget w)
10 {
11 super.HandlerAttached(w);
13
14 SCR_WeaponAttachmentsStorageComponent weaponStorage = SCR_WeaponAttachmentsStorageComponent.Cast(m_Storage);
15 if (!weaponStorage)
16 return;
17
18 m_WeaponStorage = weaponStorage;
19 m_WeaponStorage.m_OnItemAddedToSlotInvoker.Insert(RefreshInspectionSlots);
20 m_WeaponStorage.m_OnItemRemovedFromSlotInvoker.Insert(RefreshInspectionSlots);
21 }
22
23 //------------------------------------------------------------------------------------------------
24 override void HandlerDeattached(Widget w)
25 {
27 {
28 m_WeaponStorage.m_OnItemAddedToSlotInvoker.Remove(RefreshInspectionSlots);
29 m_WeaponStorage.m_OnItemRemovedFromSlotInvoker.Remove(RefreshInspectionSlots);
30 m_WeaponStorage = null;
31 }
32
33 super.HandlerDeattached(w);
34 ClearSlots();
35 }
36
37 //------------------------------------------------------------------------------------------------
38 protected void RefreshInspectionSlots()
39 {
40 ClearSlots();
42 m_MenuHandler.UpdateGearInspectionPreview();
43 }
44
45 //------------------------------------------------------------------------------------------------
47 {
48 return m_wFrameSlot;
49 }
50
51 //------------------------------------------------------------------------------------------------
52 override bool IsTraversalAllowed()
53 {
54 return false;
55 }
56
57 protected typename GetSlotType(InventoryStorageSlot slot, out string name)
58 {
59 typename type = slot.GetParentContainer().Type();
60 if (type.IsInherited(BaseMuzzleComponent))
61 {
62 name = "#AR-Magazine_Name";
63 BaseMagazineWell magwell = BaseMuzzleComponent.Cast(slot.GetParentContainer()).GetMagazineWell();
64
65 if (magwell)
66 return magwell.Type();
67 }
68 else if (type == AttachmentSlotComponent)
69 {
70 AttachmentSlotComponent attachment = AttachmentSlotComponent.Cast(slot.GetParentContainer());
71 if (!attachment || !attachment.GetAttachmentSlotType())
72 {
73 name = string.Empty;
74 return typename.Empty;
75 }
76
77 //TODO: FIX THIS, VERY BAD!
78
79 type = attachment.GetAttachmentSlotType().Type();
80 if (type.IsInherited(AttachmentOptics))
81 name = "#AR-KeybindSeparator_WeaponOptics";
82 if (type.IsInherited(AttachmentUnderBarrel))
83 name = "#AR-AttachmentType_Underbarrel";
84 if (type.IsInherited(AttachmentBayonet))
85 name = "#AR-AttachmentType_Bayonet";
86 if (type.IsInherited(AttachmentMuzzle))
87 name = "#AR-AttachmentType_Suppressor";
88 if (type.IsInherited(AttachmentHandGuard))
89 {
90 name = string.Empty;
91 return typename.Empty;
92 }
93 }
94
95 return type;
96 }
97
98 //------------------------------------------------------------------------------------------------
99 override protected int CreateSlots()
100 {
101 array<IEntity> pItemsInStorage = {};
102 int count = m_Storage.GetSlotsCount();
103
104 for (int i = 0; i < count; ++i)
105 {
106 IEntity item = m_Storage.Get(i);
107 InventoryStorageSlot storageSlot = m_Storage.GetSlot(i);
108
109 m_aStorageSlotsInStorage.Insert(storageSlot);
110 pItemsInStorage.Insert(item);
111 }
112
113 UpdateOwnedSlots(pItemsInStorage);
114
115 for (int i = 0; i < count; ++i)
116 {
117 InventoryStorageSlot storageSlot = m_Storage.GetSlot(i);
118 AttachmentSlotComponent attachment = AttachmentSlotComponent.Cast(storageSlot.GetParentContainer());
119 if (attachment && !attachment.ShouldShowInInspection())
120 m_aSlots[i].SetSlotVisible(false);
121 }
122
123 return count;
124 }
125
126 //------------------------------------------------------------------------------------------------
127 override protected void UpdateOwnedSlots(notnull array<IEntity> pItemsInStorage)
128 {
129 const int numberOfItems = pItemsInStorage.Count();
130 const int initialNumberOfSlots = m_aSlots.Count();
131 if (numberOfItems < initialNumberOfSlots)
132 {
133 SCR_InventorySlotUI slotUI;
134 for (int i = initialNumberOfSlots - numberOfItems - 1; i > 0; i--)
135 {
136 slotUI = m_aSlots[i + numberOfItems];
137 if (slotUI)
138 slotUI.Destroy();
139 }
140 }
141
142 m_aSlots.Resize(numberOfItems);
143 IEntity item;
146 foreach (int i, SCR_InventorySlotUI slot : m_aSlots)
147 {
148 item = pItemsInStorage[i];
149 if (item)
151 else
152 iic = null;
153
154 if (slot)
155 {
156 slot.UpdateReferencedComponent(iic);
157 }
158 else
159 {
160 slot = CreateSlotUI(iic);
161 m_aSlots[i] = slot;
162 }
163
164 string slotName;
165 const typename slotType = GetSlotType(m_Storage.GetSlot(i), slotName);
166 if (!slotType || slotName.IsEmpty())
167 continue;
168
169 inspectionSlot = SCR_InventorySlotGearInspectionUI.Cast(slot);
170 if (inspectionSlot)
171 inspectionSlot.m_tAttachmentType = slotType;
172
173 m_MenuHandler.AddItemToAttachmentSelection(slotName, inspectionSlot);
174 }
175 }
176
177 //------------------------------------------------------------------------------------------------
178 // ! creates the slot
180 {
181 return new SCR_InventorySlotGearInspectionUI(pComponent, this);
182 }
183
184 //------------------------------------------------------------------------------------------------
186 {
187 foreach (int i, SCR_InventorySlotUI slotUI: m_aSlots)
188 {
189 slotUI.UpdateReferencedComponent(slotUI.GetInventoryItemComponent());
190
191 Widget slotWidget = slotUI.GetWidget();
192 InventoryStorageSlot storageSlot = m_Storage.GetSlot(i);
193 m_Storage.GetOwner();
194
195 vector screenPos;
196 vector transform[4];
197
198 //InventoryStorageSlot.GetInspectionWidgetOffset();
199
200 transform[3] = m_aStorageSlotsInStorage.Get(i).GetInspectionWidgetOffset();
201
202 charPreview.TryGetItemNodePositionInWidgetSpace(-1, transform, screenPos);
203 FrameSlot.SetPos(slotWidget, screenPos[0], screenPos[1]);
204 }
205 }
206
207 //------------------------------------------------------------------------------------------------
208 override bool OnDrop(SCR_InventorySlotUI slot)
209 {
210 if (!slot)
211 return true;
212
213 // SLOT is the original slot where of the item to replace. Add InventoryOperationCallback to tryReplace
214
215 SCR_InvCallBack callBack = new SCR_InvCallBack();
217 IEntity item;
218
219 if (itemComp)
220 item = itemComp.GetOwner();
221
222 callBack.m_pItem = item;
223 callBack.m_pMenu = m_MenuHandler;
224
225 callBack.m_pStorageFrom = slot.GetStorageUI();
226 callBack.m_pStorageTo = this;
227 callBack.m_pStorageMan = m_InventoryManager;
228 callBack.m_eAttachAction = EAttachAction.ATTACH;
229 callBack.m_pStorageToFocus = callBack.m_pStorageFrom;
230
231 m_InventoryManager.EquipAny(m_Storage, item, -1, callBack);
232
233 return true;
234 }
235
236 //------------------------------------------------------------------------------------------------
238 {
239 foreach (SCR_InventorySlotUI slot: m_aSlots)
240 {
241 slot.Destroy();
242 }
243 m_aSlots.Clear();
244 }
245
246 //------------------------------------------------------------------------------------------------
247 // ! leave this empty because we don't want to initiate the matrix
248 override void SetRowsAndColumns() {}
249
250 //------------------------------------------------------------------------------------------------
251 // ! creates the the grid from array of UI items
252 override protected void SortSlots() {}
253
254 //------------------------------------------------------------------------------------------------
255 // ! We want to avoid creating the grid
256 void InitMatrix() {}
257
258 //------------------------------------------------------------------------------------------------
259 override void FillWithEmptySlots() {}
260
261 //------------------------------------------------------------------------------------------------
262 override void Refresh() {}
263
264 //------------------------------------------------------------------------------------------------
265 override void InitPaging() {}
266
267 //------------------------------------------------------------------------------------------------
269 BaseInventoryStorageComponent storage,
270 LoadoutAreaType slotID = null,
271 SCR_InventoryMenuUI menuManager = null,
272 int iPage = 0,
273 array<BaseInventoryStorageComponent> aTraverseStorage = null,
274 Widget frameSlot = null)
275 {
276 m_Storage = storage;
277 m_MenuHandler = menuManager;
278 m_eSlotAreaType = slotID;
279 m_iMaxRows = 1;
280 m_iMaxColumns = 1;
281 m_iMatrix = new SCR_Matrix(m_iMaxColumns, m_iMaxRows);
282 m_wFrameSlot = frameSlot;
283 }
284};
285
286//------------------------------------------------------------------------------------------------
288{
289 protected static const float SLOT_SIZE_DEFAULT = 32;
290 protected static const float SLOT_SIZE_HIGHLIGHTED = 64;
291
292 protected static const ResourceName ICON_VALID_SLOT = "{A1A2E6F6DB36CF61}UI/Textures/InventoryIcons/Inspection-gizmo-small_UI.edds";
293 protected static const ResourceName ICON_INVALID_SLOT = "{2EB962B6F404C01E}UI/Textures/InventoryIcons/Inspection-gizmo-invalid-small_UI.edds";
294 protected static const string SLOT_LAYOUT = "{EB835F21257F0C51}UI/layouts/Menus/Inventory/AttachmentItemSlot.layout";
295
296 protected Widget m_wItemWidget = null;
297 protected ImageWidget m_wIconWidget = null;
299
302
305
306 //------------------------------------------------------------------------------------------------
308 {
309 if (m_widget)
310 Destroy();
311
312 m_pItem = pComponent;
313 Widget m_wFrameSlot = m_pStorageUI.GetStorageGrid();
314 m_widget = GetGame().GetWorkspace().CreateWidgets(SLOT_LAYOUT, m_wFrameSlot);
315 m_widget.AddHandler(this); //calls the HandlerAttached()
316
317 m_wItemWidget = m_widget.FindAnyWidget("ButtonOverlay");
318 m_wIconWidget = ImageWidget.Cast(m_widget.FindAnyWidget("WidgetGizmo"));
319
320 if (m_wIconWidget)
321 {
322 m_wIconWidget.LoadImageTexture(0, ICON_VALID_SLOT);
323 m_wIconWidget.SetVisible(true);
324 }
325
326 if (m_wItemWidget)
327 m_wItemWidget.SetVisible(false);
328 }
329
330 //------------------------------------------------------------------------------------------------
331 override bool OnMouseEnter(Widget w, int x, int y)
332 {
333 Highlight(true);
334
335 return super.OnMouseEnter(w, x, y);
336 }
337
338 //------------------------------------------------------------------------------------------------
339 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
340 {
341 if (!m_bIsSelected)
342 Highlight(false);
343
344 return super.OnMouseLeave(w, enterW, x, y);
345 }
346
347 override bool OnClick(Widget w, int x, int y, int button)
348 {
349 if (button == 0)
350 {
353 else
355 }
356
357 return false;
358 }
359
361 {
363 Select(true);
364 if (m_tAttachmentType.IsInherited(BaseMagazineWell))
365 {
366 SCR_MagazinePredicate predicate = new SCR_MagazinePredicate();
367 predicate.magWellType = m_tAttachmentType;
368 if (m_pStorageUI)
369 m_pStorageUI.GetInventoryMenuHandler().ShowAttachmentStorage(predicate);
370 }
371 else
372 {
373 SCR_CompatibleAttachmentPredicate predicate = new SCR_CompatibleAttachmentPredicate();
374 predicate.attachmentType = m_tAttachmentType;
375 if (m_pStorageUI)
376 m_pStorageUI.GetInventoryMenuHandler().ShowAttachmentStorage(predicate);
377 }
378 }
379
381 {
383 Select(false);
384 m_pStorageUI.GetInventoryMenuHandler().CloseAttachmentStorage();
385 }
386
387 //------------------------------------------------------------------------------------------------
388 void Highlight(bool highlight)
389 {
390 if (m_widget)
391 {
392 if (highlight)
394 else
396 }
397
398 if (m_wItemWidget)
399 m_wItemWidget.SetVisible(highlight);
400
401 if (m_wIconWidget)
402 m_wIconWidget.SetVisible(!highlight);
403 }
404
405 void Select(bool select = true)
406 {
407 if (s_SelectedPoint)
408 {
409 s_SelectedPoint.m_bIsSelected = false;
410 s_SelectedPoint.Highlight(false);
411 }
412
413 m_bIsSelected = select;
414 Highlight(select);
415 if (select)
416 {
417 s_SelectedPoint = this;
418 }
419 else
420 {
421 s_SelectedPoint = null;
422 }
423 }
424
425 //------------------------------------------------------------------------------------------------
426 override BaseInventoryStorageComponent GetAsStorage()
427 {
428 return m_pStorageUI.GetStorage();
429 }
430
431 //------------------------------------------------------------------------------------------------
432 override bool OnDrop(SCR_InventorySlotUI slot)
433 {
434 return m_pStorageUI.OnDrop(slot);
435 }
436};
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref array< SCR_WeaponRackSlotEntity > m_aSlots
SCR_InventoryStorageManagerComponent m_InventoryManager
SCR_DeployMenuBase m_MenuHandler
Main deploy menu with the map present.
EDamageType type
SCR_EEntitySpawnerSlotType GetSlotType()
void SCR_InventoryAttachmentPointUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID=null, SCR_InventoryMenuUI menuManager=null, int iPage=0, array< BaseInventoryStorageComponent > aTraverseStorage=null)
BaseInventoryStorageComponent m_Storage
proto external Managed FindComponent(typename typeName)
override SCR_InventorySlotUI CreateSlotUI(InventoryItemComponent pComponent, SCR_ItemAttributeCollection pAttributes=null)
void SCR_InventoryGearInspectionPointUI(BaseInventoryStorageComponent storage, LoadoutAreaType slotID=null, SCR_InventoryMenuUI menuManager=null, int iPage=0, array< BaseInventoryStorageComponent > aTraverseStorage=null, Widget frameSlot=null)
override bool OnDrop(SCR_InventorySlotUI slot)
void UpdatePreviewSlotWidgets(notnull ItemPreviewWidget charPreview)
GetSlotType(InventoryStorageSlot slot, out string name)
SCR_WeaponAttachmentsStorageComponent m_WeaponStorage
ref array< InventoryStorageSlot > m_aStorageSlotsInStorage
void UpdateOwnedSlots(notnull array< IEntity > pItemsInStorage)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override BaseInventoryStorageComponent GetAsStorage()
override bool OnClick(Widget w, int x, int y, int button)
override void UpdateReferencedComponent(InventoryItemComponent pComponent, SCR_ItemAttributeCollection attributes=null)
override bool OnDrop(SCR_InventorySlotUI slot)
static SCR_InventorySlotGearInspectionUI s_SelectedPoint
override bool OnMouseEnter(Widget w, int x, int y)
void Destroy()
Removes just the UI slot.
void SCR_InventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
InventoryItemComponent GetInventoryItemComponent()
SCR_InventoryStorageBaseUI GetStorageUI()
InventoryItemComponent m_pItem
SCR_InventoryStorageBaseUI m_pStorageUI