Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ArsenalInventorySlotUI.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 static const string SLOT_LAYOUT_SUPPLY = "{AF25F325D2730142}UI/layouts/Menus/Inventory/SupplyInventoryItemSlot.layout";
5
6 protected const string RESOURCES_TEXT_WIDGET_NAME = "SuppliesText";
7 protected const string STORED_RESOURCES_WIDGET_NAME = "SuppliesStored";
8 protected const string AVAILABLE_RESOURCES_WIDGET_NAME = "SuppliesAvailable";
9 protected const string COST_RESOURCES_WIDGET_NAME = "SuppliesCost";
10 protected const string RANK_ICON_WIDGET_NAME = "RankIcon";
11 protected const string MSAR_ICON_WIDGET_NAME = "MSARIcon";
12 protected const string AMMOTYPE_WIDGET_NAME = "AmmoTypeContainer";
13
16
17 protected bool m_bIsAvailable = true;
20
21 protected SCR_ResourceComponent m_ArsenalResourceComponent;
23
24 protected float m_fSupplyCost;
25 protected SCR_ECharacterRank m_eRequiredRank;
27
28 //------------------------------------------------------------------------------------------------
29 SCR_ResourceComponent GetArsenalResourceComponent()
30 {
32 }
33
34 void SetArsenalResourceComponent(SCR_ResourceComponent component)
35 {
37 }
38
39 //------------------------------------------------------------------------------------------------
41 {
42 m_pStorageUI = storageUI;
43 }
44
45 //------------------------------------------------------------------------------------------------
46 override protected string SetSlotSize()
47 {
48 string slotLayout = SLOT_LAYOUT_SUPPLY;
49
50 switch ( m_Attributes.GetItemSize() )
51 {
52 case ESlotSize.SLOT_1x1:
53 m_iSizeX = 1;
54 m_iSizeY = 1;
55
56 break;
57 case ESlotSize.SLOT_2x1:
58 m_iSizeX = 2;
59 m_iSizeY = 1;
60
61 break;
62 case ESlotSize.SLOT_2x2:
63 m_iSizeX = 2;
64 m_iSizeY = 2;
65
66 break;
67 case ESlotSize.SLOT_3x3:
68 m_iSizeX = 3;
69 m_iSizeY = 3;
70
71 break;
72 }
73
74 return slotLayout;
75 }
76
77 //------------------------------------------------------------------------------------------------
78 override void SetSlotVisible(bool bVisible)
79 {
80 super.SetSlotVisible(bVisible);
81
82 if (!m_wDimmerEffect)
83 m_wDimmerEffect = m_widget.FindAnyWidget("Dimmer");
84
85 if (!m_pItem || !m_pItem.GetOwner())
86 return;
87
88 //~ Never show Stored resources
89 Widget resourceStored = m_widget.FindAnyWidget(STORED_RESOURCES_WIDGET_NAME);
90 if (resourceStored)
91 resourceStored.SetVisible(false);
92
93 //~ Never show Available resources
94 Widget resourceAvailable = m_widget.FindAnyWidget(AVAILABLE_RESOURCES_WIDGET_NAME);
95 if (resourceAvailable)
96 resourceAvailable.SetVisible(false);
97
98 //~ Get cost widget
99 m_CostResourceHolder = m_widget.FindAnyWidget(COST_RESOURCES_WIDGET_NAME);
102
104 return;
105
106 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(m_pItem.GetOwner());
107 SCR_ResourceContainer resourceContainer;
108
109 if (resourceComponent)
110 resourceContainer = resourceComponent.GetContainer(EResourceType.SUPPLIES);
111
112 m_wMSARIcon = ImageWidget.Cast(m_widget.FindAnyWidget(MSAR_ICON_WIDGET_NAME));
113
115
116 // Check if player has enough Military Allocated Supplies
118
119 SetItemRank();
120
121 //Widget ammoTypeWidget = m_widget.FindAnyWidget(AMMOTYPE_WIDGET_NAME);
122 //if (ammoTypeWidget)
123 // ammoTypeWidget.SetVisible(true);
124
126 }
127
128 //------------------------------------------------------------------------------------------------
129 override void Refresh()
130 {
131 super.Refresh();
132
133 if (!m_pItem || !m_pItem.GetOwner())
134 return;
135
138 }
139
140 //------------------------------------------------------------------------------------------------
141 protected void CheckRequiredRank()
142 {
143 ImageWidget rankIcon = ImageWidget.Cast(m_widget.FindAnyWidget(RANK_ICON_WIDGET_NAME));
144 if (!rankIcon)
145 return;
146
147 rankIcon.SetVisible(false);
148
149 //~ No rank required
150 if (m_eRequiredRank < SCR_ECharacterRank.PRIVATE)
151 return;
152
154 if (rankIconImageSet.IsEmpty())
155 return;
156
157 //~ Get the rank icon and set it and disable the slot
158 SCR_ChimeraCharacter localCharacter = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
159 if (!localCharacter || m_eRequiredRank <= SCR_CharacterRankComponent.GetCharacterRank(localCharacter))
160 return;
161
162 SetItemAvailability(false);
163 rankIcon.SetVisible(true);
164
165 if (m_wMSARIcon)
166 m_wMSARIcon.SetVisible(false);
167
168 SCR_Faction playerFaction = SCR_Faction.Cast(localCharacter.GetFaction());
169 if (!playerFaction)
170 return;
171
172 SCR_RankInfo rank = playerFaction.GetRanks().GetRankByID(m_eRequiredRank, true);
173 if (!rank)
174 return;
175
176 //~ Set rank icon
177 rankIcon.LoadImageFromSet(0, rankIconImageSet, rank.GetRankInsignia());
178 }
179
180 //------------------------------------------------------------------------------------------------
181 protected void CheckPersonalResources(int cost)
182 {
183 if (m_wMSARIcon)
184 m_wMSARIcon.SetVisible(false);
185
186 if (cost == 0)
187 return;
188
189 PlayerController playerController = GetGame().GetPlayerController();
190 if (!playerController)
191 return;
192
193 SCR_PlayerSupplyAllocationComponent playerSupplyAllocationComponent = SCR_PlayerSupplyAllocationComponent.Cast(playerController.FindComponent(SCR_PlayerSupplyAllocationComponent));
194 if (!playerSupplyAllocationComponent)
195 return;
196
197 int msarBalance = playerSupplyAllocationComponent.GetPlayerAvailableAllocatedSupplies() - cost;
198 SetItemAvailability(msarBalance >= 0 && m_bIsAvailable);
199
200 if (!m_wMSARIcon)
201 return;
202
203 m_wMSARIcon.SetVisible(msarBalance < 0);
204 }
205
206 //------------------------------------------------------------------------------------------------
208 {
209 SCR_ArsenalManagerComponent arsenalManagerComponent;
210 SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManagerComponent);
211 if (!arsenalManagerComponent || !arsenalManagerComponent.IsMilitarySupplyAllocationEnabled())
212 return 0;
213
214 ResourceName resourceName = m_pItem.GetOwner().GetPrefabData().GetPrefabName();
215 if (resourceName.IsEmpty())
216 return 0;
217
218 IEntity storageEnt = GetStorageUI().GetCurrentNavigationStorage().GetOwner();
219 if (!storageEnt)
220 return 0;
221
223 if (!arsenalComponent)
224 return 0;
225
226 SCR_ChimeraCharacter character = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
227 if (!character)
228 return 0;
229
230 if (arsenalComponent.GetAssignedFaction() != character.GetFaction())
231 return 0;
232
233 return arsenalManagerComponent.GetItemMilitarySupplyAllocationCost(resourceName, arsenalComponent, true);
234 }
235
236 //------------------------------------------------------------------------------------------------
237 void UpdateTotalResources(float totalResources)
238 {
240 return;
241
242 if (totalResources < 0)
243 {
245 m_CostResourceHolder.SetVisible(false);
246 return;
247 }
248 else
249 {
250 m_CostResourceHolder.SetVisible(true);
251 }
252
253 m_CostResourceHolderText.SetText(totalResources.ToString());
254
256 {
258 return;
259 }
260
261 SCR_ResourceConsumer consumer = m_ArsenalResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
262 if (!consumer)
263 {
265 return;
266 }
267
268 SetItemAvailability(totalResources <= consumer.GetAggregatedResourceValue());
269 }
270
271 //------------------------------------------------------------------------------------------------
272 override bool IsDraggable()
273 {
274 return m_bIsAvailable && super.IsDraggable();
275 }
276
277 //------------------------------------------------------------------------------------------------
280 {
281 return m_bIsAvailable;
282 }
283
284 //------------------------------------------------------------------------------------------------
286 {
287 m_fSupplyCost = 0;
288
289 IEntity storageEnt = GetStorageUI().GetCurrentNavigationStorage().GetOwner();
290
292 if (arsenalComponent && !arsenalComponent.IsArsenalUsingSupplies())
293 {
294 m_fSupplyCost = -1;
295 return m_fSupplyCost;
296 }
297
298
299 if (!m_pItem || !m_pItem.GetOwner())
300 return 0;
301
302 SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
303 if (!entityCatalogManager)
304 return 0;
305
306 SCR_Faction faction;
307 if (arsenalComponent)
308 faction = arsenalComponent.GetAssignedFaction();
309
310 Resource resource = Resource.Load(m_pItem.GetOwner().GetPrefabData().GetPrefabName());
311
313 if (faction)
314 entry = entityCatalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName(), faction);
315 else
316 entry = entityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName());
317
318 if (!entry)
319 return 0;
320
322 if (!data)
323 return 0;
324
325 if (arsenalComponent)
326 m_fSupplyCost = data.GetSupplyCost(arsenalComponent.GetSupplyCostType());
327 else
328 m_fSupplyCost = data.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
329
331 return m_fSupplyCost;
332
333
334 SCR_ResourceConsumer consumer = m_ArsenalResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
335 if (!consumer)
336 return m_fSupplyCost;
337
338 m_fSupplyCost = m_fSupplyCost * consumer.GetBuyMultiplier();
339
340 return m_fSupplyCost;
341 }
342
343 //------------------------------------------------------------------------------------------------
344 void SetItemAvailability(bool isAvailable)
345 {
346 if (!m_wDimmerEffect)
347 return;
348
349 m_bIsAvailable = isAvailable;
350
351 if (!m_wDimmerEffect.IsVisible() == isAvailable)
352 return;
353
354 m_wDimmerEffect.SetVisible(!isAvailable);
355 }
356
357 //------------------------------------------------------------------------------------------------
359 {
360 return m_fSupplyCost;
361 }
362
363 //------------------------------------------------------------------------------------------------
364 protected void SetItemRank()
365 {
366 m_eRequiredRank = -1;
367
368 if (!m_pItem || !m_pItem.GetOwner())
369 return;
370
371 SCR_ArsenalManagerComponent arsenalManager;
372 if (!SCR_ArsenalManagerComponent.GetArsenalManager(arsenalManager) || !arsenalManager.AreItemsRankLocked())
373 return;
374
375 //~ TODO: This should be merged with total Resources to only update once!!!
376 SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
377 if (!entityCatalogManager)
378 return;
379
380 IEntity storageEnt = GetStorageUI().GetCurrentNavigationStorage().GetOwner();
382
383 SCR_Faction faction;
384 if (arsenalComponent)
385 faction = arsenalComponent.GetAssignedFaction();
386
387 Resource resource = Resource.Load(m_pItem.GetOwner().GetPrefabData().GetPrefabName());
388 if (!resource.IsValid())
389 return;
390
392 if (faction)
393 entry = entityCatalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName(), faction);
394 else
395 entry = entityCatalogManager.GetEntryWithPrefabFromAnyCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName());
396
397 if (!entry)
398 return;
399
401 if (!data)
402 return;
403
404 m_eRequiredRank = data.GetRequiredRank();
405 }
406
407 //------------------------------------------------------------------------------------------------
409 SCR_ECharacterRank GetRequiredRank()
410 {
411 return m_eRequiredRank;
412 }
413
414 //------------------------------------------------------------------------------------------------
421
422 //------------------------------------------------------------------------------------------------
423 void SCR_ArsenalInventorySlotUI(InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null)
424 {
425 PlayerController playerController = GetGame().GetPlayerController();
426 if (!playerController)
427 return;
428
429 SCR_PlayerSupplyAllocationComponent playerSupplyAllocationComponent = SCR_PlayerSupplyAllocationComponent.Cast(playerController.FindComponent(SCR_PlayerSupplyAllocationComponent));
430 if (!playerSupplyAllocationComponent)
431 return;
432
433 playerSupplyAllocationComponent.GetOnAvailableAllocatedSuppliesChanged().Insert(OnPlayerSupplyAllocationChanged);
434 }
435
436 //------------------------------------------------------------------------------------------------
438 {
439 SCR_InventoryStorageBaseUI.ARSENAL_SLOT_STORAGES.Remove(this);
440
441 PlayerController playerController = GetGame().GetPlayerController();
442 if (!playerController)
443 return;
444
445 SCR_PlayerSupplyAllocationComponent playerSupplyAllocationComponent = SCR_PlayerSupplyAllocationComponent.Cast(playerController.FindComponent(SCR_PlayerSupplyAllocationComponent));
446 if (!playerSupplyAllocationComponent)
447 return;
448
449 playerSupplyAllocationComponent.GetOnAvailableAllocatedSuppliesChanged().Remove(OnPlayerSupplyAllocationChanged);
450 }
451};
EEntityCatalogType
ArmaReforgerScripted GetGame()
Definition game.c:1398
ResourceName resourceName
Definition SCR_AIGroup.c:66
void SCR_CharacterRankComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Get all prefabs that have the spawner data
EResourceGeneratorID
proto external Managed FindComponent(typename typeName)
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
SCR_EArsenalSupplyCostType GetSupplyCostType()
override void SetSlotVisible(bool bVisible)
void UpdateTotalResources(float totalResources)
void SCR_ArsenalInventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
void SetStorageUI(SCR_InventoryStorageBaseUI storageUI)
SCR_ResourceComponent GetArsenalResourceComponent()
void SetItemAvailability(bool isAvailable)
void SetArsenalResourceComponent(SCR_ResourceComponent component)
SCR_ResourceContainer m_ResourceContainer
SCR_ResourceComponent m_ArsenalResourceComponent
Get prefab entity Data of type Ignores disabled Data s param dataType class of Data type you with to obtain return Entity Data of given type Null if not found *SCR_BaseEntityCatalogData GetEntityDataOfType(typename dataType)
SCR_RankContainer GetRanks()
void SCR_InventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
ref SCR_ItemAttributeCollection m_Attributes
SCR_InventoryStorageBaseUI GetStorageUI()
InventoryItemComponent m_pItem
SCR_InventoryStorageBaseUI m_pStorageUI
static IEntity GetLocalControlledEntity()
SCR_RankInfo GetRankByID(SCR_ECharacterRank rankIdentifier)
string GetRankInsignia()
static ResourceName GetRankIconImageSet()