Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ArsenalDisplayComponent.c
Go to the documentation of this file.
2 {
3 }
4 
5 class SCR_ArsenalDisplayComponent : SCR_ArsenalComponent
6 {
7  [Attribute("0", desc: "Type of display data an arsenal item needs in in order to be displayed on this arsenal display", uiwidget: UIWidgets.SearchComboBox, enums: ParamEnumArray.FromEnum(EArsenalItemDisplayType), category: "Display settings")]
8  protected EArsenalItemDisplayType m_eArsenalItemDisplayType;
9 
10  [Attribute("4", desc: "Refresh time in seconds. Every x time the arsenal will try to refresh")]
11  protected float m_fRefreshDelay;
12 
13  protected ref array<SCR_WeaponRackSlotEntity> m_aSlots = {};
14 
15  //------------------------------------------------------------------------------------------------
17  {
18  ClearArsenal();
19  super.SetSupportedArsenalItemTypes(types);
20  }
21 
22  //------------------------------------------------------------------------------------------------
24  {
25  ClearArsenal();
26  super.SetSupportedArsenalItemModes(modes);
27  }
28 
29  //------------------------------------------------------------------------------------------------
31  {
32  if (!slot || m_aSlots.Find(slot) != -1)
33  {
34  return;
35  }
36 
37  m_aSlots.Insert(slot);
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override void OnFactionChanged(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
42  {
43  ClearArsenal();
45  }
46 
47  //------------------------------------------------------------------------------------------------
49  override void ClearArsenal()
50  {
51  for (int i = 0; i < m_aSlots.Count(); i++)
52  {
53  m_aSlots[i].RemoveItem();
54  }
55  }
56 
57  //------------------------------------------------------------------------------------------------
59  protected void RefreshUpdate()
60  {
61  RefreshArsenal(GetAssignedFaction());
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  override void RefreshArsenal(SCR_Faction faction = null)
66  {
67  array<SCR_ArsenalItem> filteredArsenalItems = {};
68 
69  //~ Could not get arsenal items
70  if (!GetFilteredArsenalItems(filteredArsenalItems, m_eArsenalItemDisplayType))
71  return;
72 
73  int availableItemCount = filteredArsenalItems.Count();
74  int availableSlotCount = m_aSlots.Count();
75 
76  SCR_ArsenalItem itemToSpawn;
77  SCR_WeaponRackSlotEntity currentSlot = null;
78  for (int i = 0; i < availableSlotCount; i++)
79  {
80  currentSlot = m_aSlots[i];
81  if (GetSlotValid(currentSlot))
82  {
83  continue;
84  }
85  else if(currentSlot && currentSlot.GetChildren())
86  {
87  currentSlot.RemoveItem();
88  }
89  else if (!currentSlot)
90  {
91  m_aSlots.RemoveOrdered(i--);
92  availableSlotCount--;
93  continue;
94  }
95 
96  if (!currentSlot.CanSpawnItem())
97  {
98  continue;
99  }
100 
101  int index = i % availableItemCount;
102  for (int j = 0; j < availableItemCount; j++)
103  {
104  itemToSpawn = filteredArsenalItems[index];
105  if (GetItemValidForSlot(itemToSpawn.GetItemType(), itemToSpawn.GetItemMode(), currentSlot.GetSlotSupportedItemTypes(), currentSlot.GetSlotSupportedItemModes()))
106  break;
107 
108  itemToSpawn = null;
109  index++;
110  if (index >= availableItemCount)
111  index = 0;
112  }
113 
114  if (!itemToSpawn)
115  continue;
116 
117  currentSlot.SpawnNewItem(itemToSpawn.GetItemResource(), itemToSpawn, itemToSpawn.GetDisplayDataOfType(m_eArsenalItemDisplayType));
118  }
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  protected bool GetSlotValid(SCR_WeaponRackSlotEntity slotEntity, out bool isEmpty = true)
123  {
124  if (!slotEntity)
125  return false;
126 
127  if (slotEntity.GetChildren() && slotEntity.GetChildren().GetPrefabData())
128  {
129  isEmpty = false;
130  return GetItemValidForSlot(slotEntity.GetCurrentOccupiedItemType(), slotEntity.GetCurrentOccupiedItemMode(), slotEntity.GetSlotSupportedItemTypes(), slotEntity.GetSlotSupportedItemModes());
131  }
132 
133  return false;
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  protected bool GetItemValidForSlot(SCR_EArsenalItemType itemType, SCR_EArsenalItemMode itemMode, SCR_EArsenalItemType supportedSlotTypes, SCR_EArsenalItemMode supportedSlotModes)
138  {
139  return GetItemValid(itemType, itemMode) && SCR_Enum.HasPartialFlag(supportedSlotTypes, itemType) && SCR_Enum.HasPartialFlag(supportedSlotModes, itemMode);
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  override void EOnInit(IEntity owner)
144  {
145  super.EOnInit(owner);
146 
147  IEntity child = owner.GetChildren();
148  while (child)
149  {
151  if (slot)
152  RegisterSlot(slot);
153 
154  child = child.GetSibling();
155  }
156 
157  RplComponent rpl = RplComponent.Cast(owner.FindComponent(RplComponent));
158  if (!rpl || (rpl && rpl.Role() == RplRole.Authority))
159  {
160  RefreshArsenal();
161 
162  if (!SCR_Global.IsEditMode())
163  GetGame().GetCallqueue().CallLater(RefreshUpdate, m_fRefreshDelay * 1000, true);
164  }
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  override void OnPostInit(IEntity owner)
169  {
170  if (SCR_Global.IsEditMode())
171  return;
172 
173  super.OnPostInit(owner);
174 
175  SetEventMask(owner, EntityEvent.INIT);
176  }
177 
178  //------------------------------------------------------------------------------------------------
179  override protected void OnDelete(IEntity owner)
180  {
181  super.OnDelete(owner);
182 
183  if (SCR_Global.IsEditMode())
184  return;
185 
186  GetGame().GetCallqueue().Remove(RefreshUpdate);
187  }
188 }
SCR_WeaponRackSlotEntity
Definition: SCR_WeaponRackSlotEntity.c:7
SCR_Enum
Definition: SCR_Enum.c:1
SetSupportedArsenalItemTypes
override void SetSupportedArsenalItemTypes(SCR_EArsenalItemType types)
Definition: SCR_ArsenalDisplayComponent.c:16
RegisterSlot
protected void RegisterSlot(SCR_WeaponRackSlotEntity slot)
Definition: SCR_ArsenalDisplayComponent.c:30
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EArsenalItemMode
SCR_EArsenalItemMode
Definition: SCR_EArsenalItemMode.c:1
SetSupportedArsenalItemModes
override void SetSupportedArsenalItemModes(SCR_EArsenalItemMode modes)
Definition: SCR_ArsenalDisplayComponent.c:23
OnDelete
override protected void OnDelete(IEntity owner)
Definition: SCR_ArsenalDisplayComponent.c:179
SCR_ArsenalComponentClass
Definition: SCR_ArsenalComponent.c:1
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_fRefreshDelay
protected float m_fRefreshDelay
Definition: SCR_ArsenalDisplayComponent.c:11
SCR_EArsenalItemType
SCR_EArsenalItemType
Definition: SCR_EArsenalItemType.c:2
Attribute
SCR_ArsenalDisplayComponentClass SCR_ArsenalComponentClass Attribute("0", desc:"Type of display data an arsenal item needs in in order to be displayed on this arsenal display", uiwidget:UIWidgets.SearchComboBox, enums:ParamEnumArray.FromEnum(EArsenalItemDisplayType), category:"Display settings")] protected EArsenalItemDisplayType m_eArsenalItemDisplayType
OnPostInit
override void OnPostInit(IEntity owner)
Called on PostInit when all components are added.
Definition: SCR_ArsenalDisplayComponent.c:168
m_aSlots
protected ref array< SCR_WeaponRackSlotEntity > m_aSlots
Definition: SCR_ArsenalDisplayComponent.c:13
GetSlotValid
protected bool GetSlotValid(SCR_WeaponRackSlotEntity slotEntity, out bool isEmpty=true)
Definition: SCR_ArsenalDisplayComponent.c:122
GetItemValidForSlot
protected bool GetItemValidForSlot(SCR_EArsenalItemType itemType, SCR_EArsenalItemMode itemMode, SCR_EArsenalItemType supportedSlotTypes, SCR_EArsenalItemMode supportedSlotModes)
Definition: SCR_ArsenalDisplayComponent.c:137
EOnInit
override void EOnInit(IEntity owner)
Definition: SCR_ArsenalDisplayComponent.c:143
Faction
Definition: Faction.c:12
RefreshArsenal
override void RefreshArsenal(SCR_Faction faction=null)
Definition: SCR_ArsenalDisplayComponent.c:65
SCR_ArsenalDisplayComponentClass
Definition: SCR_ArsenalDisplayComponent.c:1
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
GetFilteredArsenalItems
array< SCR_ArsenalItem > GetFilteredArsenalItems(SCR_EArsenalItemType typeFilter, SCR_EArsenalItemMode modeFilter, SCR_Faction faction=null, EArsenalItemDisplayType requiresDisplayType=-1)
Definition: SCR_EntityCatalogManagerComponent.c:541
SCR_Global
Definition: Functions.c:6
RefreshUpdate
protected void RefreshUpdate()
Refresh arsenal after m_fRefreshDelay delay.
Definition: SCR_ArsenalDisplayComponent.c:59
OnFactionChanged
override void OnFactionChanged(FactionAffiliationComponent owner, Faction previousFaction, Faction newFaction)
Definition: SCR_ArsenalDisplayComponent.c:41
ClearArsenal
override void ClearArsenal()
Remove every slot's item.
Definition: SCR_ArsenalDisplayComponent.c:49
SCR_ArsenalComponent
Definition: SCR_ArsenalComponent.c:9
SCR_ArsenalItem
Definition: SCR_ArsenalItem.c:2
SCR_Faction
Definition: SCR_Faction.c:6
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180