Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ArsenalInventorySlotUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  static const string SLOT_LAYOUT_SUPPLY = "{EA29CC1952F8B019}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 
11  protected Widget m_CostResourceHolder;
12  protected TextWidget m_CostResourceHolderText;
13 
14  protected bool m_bIsAvailable = true;
15  protected TextWidget m_wResourceText;
16  protected Widget m_wResourceDisplay;
17 
18  protected SCR_ResourceComponent m_ArsenalResourceComponent;
19  protected SCR_ResourceContainer m_ResourceContainer;
20 
21  protected float m_fSupplyCost;
22 
23  //------------------------------------------------------------------------------------------------
24  SCR_ResourceComponent GetArsenalResourceComponent()
25  {
26  return m_ArsenalResourceComponent;
27  }
28 
29  void SetArsenalResourceComponent(SCR_ResourceComponent component)
30  {
31  m_ArsenalResourceComponent = component;
32  }
33 
34  //------------------------------------------------------------------------------------------------
35  void SetStorageUI(SCR_InventoryStorageBaseUI storageUI)
36  {
37  m_pStorageUI = storageUI;
38  }
39 
40  //------------------------------------------------------------------------------------------------
41  override protected string SetSlotSize()
42  {
43  string slotLayout = SLOT_LAYOUT_SUPPLY;
44 
45  switch ( m_Attributes.GetItemSize() )
46  {
47  case ESlotSize.SLOT_1x1:
48  m_iSizeX = 1;
49  m_iSizeY = 1;
50 
51  break;
52  case ESlotSize.SLOT_2x1:
53  m_iSizeX = 2;
54  m_iSizeY = 1;
55 
56  break;
57  case ESlotSize.SLOT_2x2:
58  m_iSizeX = 2;
59  m_iSizeY = 2;
60 
61  break;
62  case ESlotSize.SLOT_3x3:
63  m_iSizeX = 3;
64  m_iSizeY = 3;
65 
66  break;
67  }
68 
69  return slotLayout;
70  }
71 
72  //------------------------------------------------------------------------------------------------
73  override void SetSlotVisible(bool bVisible)
74  {
75  super.SetSlotVisible(bVisible);
76 
77  if (!m_wDimmerEffect)
78  m_wDimmerEffect = m_widget.FindAnyWidget("Dimmer");
79 
80  if (!m_pItem || !m_pItem.GetOwner())
81  return;
82 
83  //~ Never show Stored resources
84  Widget resourceStored = m_widget.FindAnyWidget(STORED_RESOURCES_WIDGET_NAME);
85  if (resourceStored)
86  resourceStored.SetVisible(false);
87 
88  //~ Never show Available resources
89  Widget resourceAvailable = m_widget.FindAnyWidget(AVAILABLE_RESOURCES_WIDGET_NAME);
90  if (resourceAvailable)
91  resourceAvailable.SetVisible(false);
92 
93  //~ Get cost widget
94  m_CostResourceHolder = m_widget.FindAnyWidget(COST_RESOURCES_WIDGET_NAME);
95  if (m_CostResourceHolder)
96  m_CostResourceHolderText = TextWidget.Cast(m_CostResourceHolder.FindAnyWidget(RESOURCES_TEXT_WIDGET_NAME));
97 
98  if (!m_CostResourceHolder || !m_CostResourceHolderText)
99  return;
100 
101  SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(m_pItem.GetOwner());
102  SCR_ResourceContainer resourceContainer;
103 
104  if (resourceComponent)
105  resourceContainer = resourceComponent.GetContainer(EResourceType.SUPPLIES);
106 
107  UpdateTotalResources(GetTotalResources());
108  }
109 
110  //------------------------------------------------------------------------------------------------
111  override void Refresh()
112  {
113  super.Refresh();
114 
115  if (!m_pItem || !m_pItem.GetOwner())
116  return;
117 
118  UpdateTotalResources(GetTotalResources());
119  }
120 
121  //------------------------------------------------------------------------------------------------
122  void UpdateTotalResources(float totalResources)
123  {
124  if (!m_CostResourceHolderText || !m_CostResourceHolder)
125  return;
126 
127  if (totalResources < 0)
128  {
129  SetItemAvailability(true);
130  m_CostResourceHolder.SetVisible(false);
131  return;
132  }
133  else
134  {
135  m_CostResourceHolder.SetVisible(true);
136  }
137 
138  m_CostResourceHolderText.SetText(totalResources.ToString());
139 
140  if (!m_ArsenalResourceComponent)
141  {
142  SetItemAvailability(true);
143  return;
144  }
145 
146  SCR_ResourceConsumer consumer = m_ArsenalResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
147  if (!consumer)
148  {
149  SetItemAvailability(true);
150  return;
151  }
152 
153  SetItemAvailability(totalResources <= consumer.GetAggregatedResourceValue());
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  override bool IsDraggable()
158  {
159  return m_bIsAvailable && super.IsDraggable();
160  }
161 
162  //------------------------------------------------------------------------------------------------
163  float GetTotalResources()
164  {
165  m_fSupplyCost = 0;
166 
167  IEntity storageEnt = GetStorageUI().GetCurrentNavigationStorage().GetOwner();
168 
169  SCR_ArsenalComponent arsenalComponent = SCR_ArsenalComponent.Cast(storageEnt.FindComponent(SCR_ArsenalComponent));
170  if (arsenalComponent && !arsenalComponent.IsArsenalUsingSupplies())
171  {
172  m_fSupplyCost = -1;
173  return m_fSupplyCost;
174  }
175 
176 
177  if (!m_pItem || !m_pItem.GetOwner())
178  return 0;
179 
180  SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
181  if (!entityCatalogManager)
182  return 0;
183 
184  SCR_Faction faction;
185  if (arsenalComponent)
186  faction = arsenalComponent.GetAssignedFaction();
187 
188  Resource resource = Resource.Load(m_pItem.GetOwner().GetPrefabData().GetPrefabName());
189 
191  if (faction)
192  entry = entityCatalogManager.GetEntryWithPrefabFromFactionCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName(), faction);
193  else
194  entry = entityCatalogManager.GetEntryWithPrefabFromCatalog(EEntityCatalogType.ITEM, resource.GetResource().GetResourceName());
195 
196  if (!entry)
197  return 0;
198 
199  SCR_ArsenalItem data = SCR_ArsenalItem.Cast(entry.GetEntityDataOfType(SCR_ArsenalItem));
200  if (!data)
201  return 0;
202 
203  if (arsenalComponent)
204  m_fSupplyCost = data.GetSupplyCost(arsenalComponent.GetSupplyCostType());
205  else
206  m_fSupplyCost = data.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
207 
208  if (!m_ArsenalResourceComponent)
209  return m_fSupplyCost;
210 
211 
212  SCR_ResourceConsumer consumer = m_ArsenalResourceComponent.GetConsumer(EResourceGeneratorID.DEFAULT, EResourceType.SUPPLIES);
213  if (!consumer)
214  return m_fSupplyCost;
215 
216  m_fSupplyCost = m_fSupplyCost * consumer.GetBuyMultiplier();
217 
218  return m_fSupplyCost;
219  }
220 
221  //------------------------------------------------------------------------------------------------
222  void SetItemAvailability(bool isAvailable)
223  {
224  if (!m_wDimmerEffect)
225  return;
226 
227  m_bIsAvailable = isAvailable;
228 
229  if (!m_wDimmerEffect.IsVisible() == isAvailable)
230  return;
231 
232  m_wDimmerEffect.SetVisible(!isAvailable);
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  float GetItemSupplyCost()
237  {
238  return m_fSupplyCost;
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  void SCR_ArsenalInventorySlotUI(InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null)
243  {
244  }
245 
246  //-------------------------------------S-----------------------------------------------------------
248  {
249  SCR_InventoryStorageBaseUI.ARSENAL_SLOT_STORAGES.Remove(this);
250  }
251 };
m_Attributes
private SCR_ItemAttributeCollection m_Attributes
Definition: SCR_UniversalInventoryStorageComponent.c:23
EEntityCatalogType
EEntityCatalogType
Definition: EEntityCatalogType.c:4
SCR_ArsenalInventorySlotUI
Definition: SCR_ArsenalInventorySlotUI.c:2
SCR_InventoryStorageBaseUI
Definition: SCR_InventoryStorageBaseUI.c:6
m_iSizeY
int m_iSizeY
Definition: SCR_MapRTWBaseUI.c:6
ESlotSize
ESlotSize
Definition: InventoryConstants.c:1
EResourceType
EResourceType
Definition: SCR_ResourceContainer.c:1
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
m_iSizeX
int m_iSizeX
Definition: SCR_MapRTWBaseUI.c:3
SCR_ResourceContainer
Definition: SCR_ResourceContainer.c:34
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
SCR_ArsenalComponent
Definition: SCR_ArsenalComponent.c:9
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27
SCR_ArsenalItem
Definition: SCR_ArsenalItem.c:2
SCR_Faction
Definition: SCR_Faction.c:6
SCR_EntityCatalogEntry
Definition: SCR_EntityCatalogEntry.c:5
EResourceGeneratorID
EResourceGeneratorID
Definition: SCR_ResourceGenerator.c:1