4 static const string SLOT_LAYOUT_SUPPLY =
"{EA29CC1952F8B019}UI/layouts/Menus/Inventory/SupplyInventoryItemSlot.layout";
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";
11 protected Widget m_CostResourceHolder;
12 protected TextWidget m_CostResourceHolderText;
14 protected bool m_bIsAvailable =
true;
15 protected TextWidget m_wResourceText;
16 protected Widget m_wResourceDisplay;
18 protected SCR_ResourceComponent m_ArsenalResourceComponent;
21 protected float m_fSupplyCost;
24 SCR_ResourceComponent GetArsenalResourceComponent()
26 return m_ArsenalResourceComponent;
29 void SetArsenalResourceComponent(SCR_ResourceComponent component)
31 m_ArsenalResourceComponent = component;
37 m_pStorageUI = storageUI;
41 override protected string SetSlotSize()
43 string slotLayout = SLOT_LAYOUT_SUPPLY;
73 override void SetSlotVisible(
bool bVisible)
75 super.SetSlotVisible(bVisible);
78 m_wDimmerEffect = m_widget.FindAnyWidget(
"Dimmer");
80 if (!m_pItem || !m_pItem.GetOwner())
84 Widget resourceStored = m_widget.FindAnyWidget(STORED_RESOURCES_WIDGET_NAME);
86 resourceStored.SetVisible(
false);
89 Widget resourceAvailable = m_widget.FindAnyWidget(AVAILABLE_RESOURCES_WIDGET_NAME);
90 if (resourceAvailable)
91 resourceAvailable.SetVisible(
false);
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));
98 if (!m_CostResourceHolder || !m_CostResourceHolderText)
101 SCR_ResourceComponent resourceComponent = SCR_ResourceComponent.FindResourceComponent(m_pItem.GetOwner());
104 if (resourceComponent)
105 resourceContainer = resourceComponent.GetContainer(
EResourceType.SUPPLIES);
107 UpdateTotalResources(GetTotalResources());
111 override void Refresh()
115 if (!m_pItem || !m_pItem.GetOwner())
118 UpdateTotalResources(GetTotalResources());
122 void UpdateTotalResources(
float totalResources)
124 if (!m_CostResourceHolderText || !m_CostResourceHolder)
127 if (totalResources < 0)
129 SetItemAvailability(
true);
130 m_CostResourceHolder.SetVisible(
false);
135 m_CostResourceHolder.SetVisible(
true);
138 m_CostResourceHolderText.SetText(totalResources.ToString());
140 if (!m_ArsenalResourceComponent)
142 SetItemAvailability(
true);
149 SetItemAvailability(
true);
153 SetItemAvailability(totalResources <= consumer.GetAggregatedResourceValue());
157 override bool IsDraggable()
159 return m_bIsAvailable && super.IsDraggable();
163 float GetTotalResources()
167 IEntity storageEnt = GetStorageUI().GetCurrentNavigationStorage().GetOwner();
170 if (arsenalComponent && !arsenalComponent.IsArsenalUsingSupplies())
173 return m_fSupplyCost;
177 if (!m_pItem || !m_pItem.GetOwner())
180 SCR_EntityCatalogManagerComponent entityCatalogManager = SCR_EntityCatalogManagerComponent.GetInstance();
181 if (!entityCatalogManager)
185 if (arsenalComponent)
186 faction = arsenalComponent.GetAssignedFaction();
188 Resource resource = Resource.Load(m_pItem.GetOwner().GetPrefabData().GetPrefabName());
192 entry = entityCatalogManager.GetEntryWithPrefabFromFactionCatalog(
EEntityCatalogType.ITEM, resource.GetResource().GetResourceName(), faction);
194 entry = entityCatalogManager.GetEntryWithPrefabFromCatalog(
EEntityCatalogType.ITEM, resource.GetResource().GetResourceName());
203 if (arsenalComponent)
204 m_fSupplyCost =
data.GetSupplyCost(arsenalComponent.GetSupplyCostType());
206 m_fSupplyCost =
data.GetSupplyCost(SCR_EArsenalSupplyCostType.DEFAULT);
208 if (!m_ArsenalResourceComponent)
209 return m_fSupplyCost;
214 return m_fSupplyCost;
216 m_fSupplyCost = m_fSupplyCost * consumer.GetBuyMultiplier();
218 return m_fSupplyCost;
222 void SetItemAvailability(
bool isAvailable)
224 if (!m_wDimmerEffect)
227 m_bIsAvailable = isAvailable;
229 if (!m_wDimmerEffect.IsVisible() == isAvailable)
232 m_wDimmerEffect.SetVisible(!isAvailable);
236 float GetItemSupplyCost()
238 return m_fSupplyCost;