Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SupplyInventorySlotUI.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4  const string SLOT_LAYOUT_SUPPLY = "{EA29CC1952F8B019}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 
12  protected Widget m_StoredResourcesHolder;
13  protected TextWidget m_StoredResourcesText;
14 
15  protected Widget m_AvailableResourcesHolder;
16  protected TextWidget m_AvailableResourcesText;
17 
18  //~ What supplies type are displayed
19  protected EResourceType m_eResourceType = EResourceType.SUPPLIES;
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;
27  protected ref SCR_ResourceSystemSubscriptionHandleBase m_ResourceSubscriptionHandle;
28 
29  //------------------------------------------------------------------------------------------------
30  override protected string SetSlotSize()
31  {
32  string slotLayout = SLOT_LAYOUT_SUPPLY;
33  switch ( m_Attributes.GetItemSize() )
34  {
35  case ESlotSize.SLOT_1x1:
36  m_iSizeX = 1;
37  m_iSizeY = 1;
38 
39  break;
40  case ESlotSize.SLOT_2x1:
41  m_iSizeX = 2;
42  m_iSizeY = 1;
43 
44  break;
45  case ESlotSize.SLOT_2x2:
46  m_iSizeX = 2;
47  m_iSizeY = 2;
48 
49  break;
50  case ESlotSize.SLOT_3x3:
51  m_iSizeX = 3;
52  m_iSizeY = 3;
53 
54  break;
55  }
56 
57  return slotLayout;
58  }
59 
60  //------------------------------------------------------------------------------------------------
61  override void SetItemFunctionality()
62  {
63  if (m_pItem.GetOwner().FindComponent(BaseInventoryStorageComponent))
64  m_eSlotFunction = ESlotFunction.TYPE_STORAGE;
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  override void SetSlotVisible(bool bVisible)
69  {
70  super.SetSlotVisible(bVisible);
71 
72  if (!m_wDimmerEffect)
73  m_wDimmerEffect = m_widget.FindAnyWidget("Dimmer");
74 
75  m_StoredResourcesHolder = m_widget.FindAnyWidget(STORED_RESOURCES_WIDGET_NAME);
76  if (m_StoredResourcesHolder)
77  m_StoredResourcesText = TextWidget.Cast(m_StoredResourcesHolder.FindAnyWidget(RESOURCES_TEXT_WIDGET_NAME));
78 
79  m_AvailableResourcesHolder = m_widget.FindAnyWidget(AVAILABLE_RESOURCES_WIDGET_NAME);
80  if (m_AvailableResourcesHolder)
81  m_AvailableResourcesText = TextWidget.Cast(m_AvailableResourcesHolder.FindAnyWidget(RESOURCES_TEXT_WIDGET_NAME));
82 
83  //~ Never show cost
84  Widget resourceCost = m_widget.FindAnyWidget(COST_RESOURCES_WIDGET_NAME);
85  if (resourceCost)
86  resourceCost.SetVisible(false);
87 
88  Refresh();
89  }
90 
91  //------------------------------------------------------------------------------------------------
92  override void Refresh()
93  {
94  super.Refresh();
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  void UpdateConsumer()
99  {
100  if (!m_ResourceComponent)
101  return;
102 
103  float totalResources, maxResources;
104 
105  //~ Stored supplies
106  bool showUI = SCR_ResourceSystemHelper.GetStoredAndMaxResources(m_ResourceComponent, totalResources, maxResources, m_eResourceType);
107  UpdateStoredResources(showUI, totalResources, maxResources);
108 
109  //~ Available Supplies
110  showUI = m_ResourceComponent.IsResourceTypeEnabled() && SCR_ResourceSystemHelper.GetAvailableResources(m_ResourceComponent, totalResources, m_eResourceType);
111  UpdateAvailableResources(showUI, totalResources);
112  }
113 
114  //------------------------------------------------------------------------------------------------
115  void UpdateStoredResources(bool showUI, float totalResources, float maxResources)
116  {
117  if (!m_StoredResourcesHolder || !m_StoredResourcesText)
118  return;
119 
120  if (!showUI)
121  {
122  m_StoredResourcesHolder.SetVisible(false);
123  return;
124  }
125 
126  //~ Update supplies
127  m_StoredResourcesText.SetTextFormat(m_sCurrentAndMaxResourceFormat, SCR_ResourceSystemHelper.SuppliesToString(totalResources), SCR_ResourceSystemHelper.SuppliesToString(maxResources));
128  m_StoredResourcesHolder.SetVisible(true);
129  }
130 
131  //------------------------------------------------------------------------------------------------
132  void UpdateAvailableResources(bool showUI, float totalResources)
133  {
134  if (!m_AvailableResourcesHolder || !m_AvailableResourcesText)
135  return;
136 
137  if (!showUI)
138  {
139  m_AvailableResourcesHolder.SetVisible(false);
140  return;
141  }
142 
143  //~ Update supplies
144  m_AvailableResourcesText.SetText(SCR_ResourceSystemHelper.SuppliesToString(totalResources));
145  m_AvailableResourcesHolder.SetVisible(true);
146  }
147 
148  //------------------------------------------------------------------------------------------------
149  override void HandlerAttached(Widget w)
150  {
151  super.HandlerAttached(w);
152 
153  Refresh();
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  override void HandlerDeattached(Widget w)
158  {
159  super.HandlerDeattached(w);
160 
161  m_ResourceSubscriptionHandle = null;
162 
164  m_ResourceComponent.TEMP_GetOnInteractorReplicated().Remove(UpdateConsumer);
165  }
166 
167  void SCR_SupplyInventorySlotUI(InventoryItemComponent pComponent = null, SCR_InventoryStorageBaseUI pStorageUI = null, bool bVisible = true, int iSlotIndex = -1, SCR_ItemAttributeCollection pAttributes = null)
168  {
169  if (!m_pItem)
170  return;
171 
172  m_ResourceComponent = SCR_ResourceComponent.FindResourceComponent(m_pItem.GetOwner());
173  if (!m_ResourceComponent)
174  return;
175 
176  m_ResourceComponent.TEMP_GetOnInteractorReplicated().Insert(UpdateConsumer);;
177  UpdateConsumer();
178 
180  if (!m_ResourceConsumer)
181  return;
182 
184 
185  if (!resourceInventoryPlayerComponent)
186  return;
187 
188  RplId resourceInventoryPlayerComponentRplId = Replication.FindId(resourceInventoryPlayerComponent);
189 
190  if (!resourceInventoryPlayerComponentRplId.IsValid())
191  return;
192 
193  m_ResourceSubscriptionHandle = GetGame().GetResourceSystemSubscriptionManager().RequestSubscriptionListenerHandle(m_ResourceConsumer, resourceInventoryPlayerComponentRplId);
194 
195  }
196 };
SCR_SupplyInventorySlotUI
Definition: SCR_SupplyInventorySlotUI.c:2
m_ResourceConsumer
protected SCR_ResourceConsumer m_ResourceConsumer
Definition: SCR_BaseSupportStationComponent.c:114
m_Attributes
private SCR_ItemAttributeCollection m_Attributes
Definition: SCR_UniversalInventoryStorageComponent.c:23
SCR_ResourceSystemHelper
Definition: SCR_ResourceSystemHelper.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GetPlayerController
proto external PlayerController GetPlayerController()
Definition: SCR_PlayerDeployMenuHandlerComponent.c:307
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
m_ResourceComponent
protected SCR_ResourceComponent m_ResourceComponent
Definition: SCR_CampaignBuildingProviderComponent.c:51
InventoryItemComponent
Definition: InventoryItemComponent.c:12
SCR_ItemAttributeCollection
Definition: SCR_ItemAttributeCollection.c:2
m_iSizeX
int m_iSizeX
Definition: SCR_MapRTWBaseUI.c:3
SCR_ResourcePlayerControllerInventoryComponent
Definition: SCR_ResourcePlayerControllerInventoryComponent.c:20
ESlotFunction
ESlotFunction
Definition: SCR_InventorySlotUI.c:12
SCR_ResourceSystemSubscriptionHandleBase
Definition: SCR_ResourceSystemSubscriptionHandleBase.c:1
LocalizedString
Definition: LocalizedString.c:21
SCR_InventorySlotUI
Definition: SCR_InventorySlotUI.c:27