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