Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SupplyInventorySlotUI.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
4 const string SLOT_LAYOUT_SUPPLY = "{AF25F325D2730142}UI/layouts/Menus/Inventory/SupplyInventoryItemSlot.layout";
5 const float SLOT_UNAVAILABLE_OPACITY = 0.35;
6
7 protected const string RESOURCES_TEXT_WIDGET_NAME = "SuppliesText";
8 protected const string STORED_RESOURCES_WIDGET_NAME = "SuppliesStored";
9 protected const string AVAILABLE_RESOURCES_WIDGET_NAME = "SuppliesAvailable";
10 protected const string COST_RESOURCES_WIDGET_NAME = "SuppliesCost";
11
14
17
18 //~ What supplies type are displayed
20
21 //~ ArsenalInventorySlotUI is the cost one
22
23 protected LocalizedString m_sCurrentAndMaxResourceFormat = "#AR-Campaign_BaseSuppliesAmount";
24
25 protected SCR_ResourceComponent m_ResourceComponent;
26 protected SCR_ResourceConsumer m_ResourceConsumer;
28 protected ref array<RplId> m_aStackedItems = {};
29
30 //------------------------------------------------------------------------------------------------
31 SCR_ResourceComponent GetResourceComponent()
32 {
34 }
35
36 //------------------------------------------------------------------------------------------------
37 override protected string SetSlotSize()
38 {
39 string slotLayout = SLOT_LAYOUT_SUPPLY;
40 switch ( m_Attributes.GetItemSize() )
41 {
42 case ESlotSize.SLOT_1x1:
43 m_iSizeX = 1;
44 m_iSizeY = 1;
45
46 break;
47 case ESlotSize.SLOT_2x1:
48 m_iSizeX = 2;
49 m_iSizeY = 1;
50
51 break;
52 case ESlotSize.SLOT_2x2:
53 m_iSizeX = 2;
54 m_iSizeY = 2;
55
56 break;
57 case ESlotSize.SLOT_3x3:
58 m_iSizeX = 3;
59 m_iSizeY = 3;
60
61 break;
62 }
63
64 return slotLayout;
65 }
66
67 //------------------------------------------------------------------------------------------------
68 override void SetItemFunctionality()
69 {
70 if (m_pItem.GetOwner().FindComponent(BaseInventoryStorageComponent))
71 m_eSlotFunction = ESlotFunction.TYPE_STORAGE;
72 }
73
74 //------------------------------------------------------------------------------------------------
75 override void UseItem(IEntity player, SCR_EUseContext context)
76 {
77 if (!m_pItem)
78 return;
79
80 IEntity item = m_pItem.GetOwner();
81 if (!item)
82 return;
83
85 if (!storage)
86 return;
87
88 ESlotFunction overrideSlotFunction = m_eSlotFunction;
89 if (item.FindComponent(SCR_GadgetComponent))
90 overrideSlotFunction = ESlotFunction.TYPE_GADGET;
91
92 if (storage.UseItem(item, overrideSlotFunction, context))
93 Refresh();
94 }
95
96 //------------------------------------------------------------------------------------------------
97 override bool CanUseItem(IEntity player)
98 {
99 if (!m_pItem)
100 return false;
101
102 IEntity item = m_pItem.GetOwner();
103 if (!item)
104 return false;
105
107 if (!storage)
108 return false;
109
110 ESlotFunction overrideSlotFunction = m_eSlotFunction;
111 if (item.FindComponent(SCR_GadgetComponent))
112 overrideSlotFunction = ESlotFunction.TYPE_GADGET;
113
114 return storage.CanUseItem(item, overrideSlotFunction);
115 }
116
117 //------------------------------------------------------------------------------------------------
118 override bool IsDraggable()
119 {
120 if (!super.IsDraggable())
121 return false;
122
123 SCR_ChimeraCharacter char = SCR_ChimeraCharacter.Cast(SCR_PlayerController.GetLocalControlledEntity());
124 return !m_ResourceComponent || char && m_ResourceComponent.CanBeUsedByCharacter(char);
125 }
126
127 //------------------------------------------------------------------------------------------------
128 override void SetSlotVisible(bool bVisible)
129 {
130 super.SetSlotVisible(bVisible);
131
132 if (!m_wDimmerEffect)
133 m_wDimmerEffect = m_widget.FindAnyWidget("Dimmer");
134
138
142
143 //~ Never show cost
144 Widget resourceCost = m_widget.FindAnyWidget(COST_RESOURCES_WIDGET_NAME);
145 if (resourceCost)
146 resourceCost.SetVisible(false);
147
148 Refresh();
149 }
150
151 //------------------------------------------------------------------------------------------------
152 override void Refresh()
153 {
154 super.Refresh();
155 }
156
157 //------------------------------------------------------------------------------------------------
159 {
161 return;
162
163 float totalResources, maxResources;
164
165 //~ Stored supplies
166 bool showUI = SCR_ResourceSystemHelper.GetStoredAndMaxResources(m_ResourceComponent, totalResources, maxResources, m_eResourceType);
167 UpdateStoredResources(showUI, totalResources, maxResources);
168
169 //~ Available Supplies
170 showUI = m_ResourceComponent.IsResourceTypeEnabled() && SCR_ResourceSystemHelper.GetAvailableResources(m_ResourceComponent, totalResources, m_eResourceType);
171 UpdateAvailableResources(showUI, totalResources);
172 }
173
174 //------------------------------------------------------------------------------------------------
175 override void OnOwnedSlotsUpdated()
176 {
178 }
179
180 //------------------------------------------------------------------------------------------------
181 void UpdateStoredResources(bool showUI, float totalResources, float maxResources)
182 {
184 return;
185
186 if (!showUI)
187 {
188 m_StoredResourcesHolder.SetVisible(false);
189 return;
190 }
191
192 //~ Update supplies
193 float additionalTotalResources, additionalMaxResources;
194
195 GetAdditionalResourceValuesFromStack(additionalTotalResources, additionalMaxResources);
196
197 m_StoredResourcesText.SetTextFormat(
199 SCR_ResourceSystemHelper.SuppliesToString(totalResources + additionalTotalResources),
200 SCR_ResourceSystemHelper.SuppliesToString(maxResources + additionalMaxResources));
201 m_StoredResourcesHolder.SetVisible(true);
202 }
203
204 //------------------------------------------------------------------------------------------------
205 void GetAdditionalResourceValuesFromStack(out float addTotalResources, out float addMaxResources)
206 {
207 foreach (RplId id : m_aStackedItems)
208 {
209 if (!id.IsValid())
210 continue;
211
212 RplComponent rpl = RplComponent.Cast(Replication.FindItem(id));
213 if (!rpl)
214 continue;
215
216 IEntity ent = rpl.GetEntity();
217 if (!ent)
218 continue;
219
220 SCR_ResourceComponent resComp = SCR_ResourceComponent.Cast(ent.FindComponent(SCR_ResourceComponent));
221 if (!resComp)
222 continue;
223
224 float addTotal, addMax;
225 if (SCR_ResourceSystemHelper.GetStoredAndMaxResources(resComp, addTotal, addMax))
226 {
227 addTotalResources += addTotal;
228 addMaxResources += addMax;
229 }
230 }
231 }
232
233 //------------------------------------------------------------------------------------------------
235 {
237 m_aStackedItems.Insert(id);
238 }
239
240 //------------------------------------------------------------------------------------------------
241 void UpdateAvailableResources(bool showUI, float totalResources)
242 {
244 return;
245
246 if (!showUI)
247 {
248 m_AvailableResourcesHolder.SetVisible(false);
249 return;
250 }
251
252 //~ Update supplies
253 m_AvailableResourcesText.SetText(SCR_ResourceSystemHelper.SuppliesToString(totalResources));
254 m_AvailableResourcesHolder.SetVisible(true);
255 }
256
257 //------------------------------------------------------------------------------------------------
258 override void HandlerAttached(Widget w)
259 {
260 super.HandlerAttached(w);
261
262 Refresh();
263 }
264
265 //------------------------------------------------------------------------------------------------
266 override void HandlerDeattached(Widget w)
267 {
268 super.HandlerDeattached(w);
269
271
273 m_ResourceComponent.TEMP_GetOnInteractorReplicated().Remove(UpdateConsumer);
274 }
275
276 void SCR_SupplyInventorySlotUI(InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null)
277 {
278 if (!m_pItem)
279 return;
280
281 m_ResourceComponent = SCR_ResourceComponent.FindResourceComponent(m_pItem.GetOwner());
283 return;
284
285 m_ResourceComponent.TEMP_GetOnInteractorReplicated().Insert(UpdateConsumer);
287
290 return;
291
293
294 if (!resourceInventoryPlayerComponent)
295 return;
296
297 RplId resourceInventoryPlayerComponentRplId = Replication.FindItemId(resourceInventoryPlayerComponent);
298
299 if (!resourceInventoryPlayerComponentRplId.IsValid())
300 return;
301
302 m_ResourceSubscriptionHandle = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandle(m_ResourceConsumer, resourceInventoryPlayerComponentRplId);
303
304 }
305};
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_EUseContext
proto external Managed FindComponent(typename typeName)
Main replication API.
Definition Replication.c:14
Replication item identifier.
Definition RplId.c:14
bool UseItem(notnull IEntity item, ESlotFunction slotFunction=ESlotFunction.TYPE_GENERIC, SCR_EUseContext context=SCR_EUseContext.FROM_QUICKSLOT)
bool CanUseItem(notnull IEntity item, ESlotFunction slotFunction=ESlotFunction.TYPE_GENERIC)
void SCR_InventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
SCR_CharacterInventoryStorageComponent GetCharacterStorage(IEntity entity)
ESlotFunction m_eSlotFunction
ref SCR_ItemAttributeCollection m_Attributes
InventoryItemComponent m_pItem
static IEntity GetLocalControlledEntity()
SCR_ResourceConsumer m_ResourceConsumer
override void HandlerAttached(Widget w)
override void SetSlotVisible(bool bVisible)
ref SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandle
void GetAdditionalResourceValuesFromStack(out float addTotalResources, out float addMaxResources)
void UpdateStoredResources(bool showUI, float totalResources, float maxResources)
override bool CanUseItem(IEntity player)
override void UseItem(IEntity player, SCR_EUseContext context)
SCR_ResourceComponent m_ResourceComponent
override void HandlerDeattached(Widget w)
void SCR_SupplyInventorySlotUI(InventoryItemComponent pComponent=null, SCR_InventoryStorageBaseUI pStorageUI=null, bool bVisible=true, int iSlotIndex=-1, SCR_ItemAttributeCollection pAttributes=null)
SCR_ResourceComponent GetResourceComponent()
void UpdateAvailableResources(bool showUI, float totalResources)
override void IncreaseStackNumberWithRplId(RplId id)
proto external PlayerController GetPlayerController()