3 [
Attribute(
"{09DFB36A6C8D45C0}UI/layouts/Editor/GameInfo/GameInfo_CampaignBuilding_ServiceIcon.layout")]
4 protected ResourceName m_sServiceIconsGridPrefab;
6 [
Attribute(DEFAULT_VALUE.ToString(),
params:
"1 inf 1",
desc:
"Maximum number of icons in the row")]
7 protected int m_iMaxColumns;
9 protected ref array<ref Tuple2<EEditableEntityLabel, SCR_ServicePointComponent>> m_aServices = {};
11 protected Widget m_wCampaignBuildingServicesRoot;
12 protected SCR_MilitaryBaseComponent m_MilitaryBaseComponent;
14 protected const int PADDING_LEFT = 5;
15 protected const int PADDING_RIGHT = 5;
16 protected const int PADDING_TOP = 5;
17 protected const int PADDING_BOTTOM = 5;
18 protected static const int DEFAULT_VALUE = 7;
20 protected ref array<EEditableEntityLabel> m_aAvailableServicesLabel = {};
23 override void HandlerAttached(Widget w)
25 m_wCampaignBuildingServicesRoot = w;
27 SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
28 if (!buildingEditorComponent)
32 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(buildingEditorComponent.GetProviderEntity().FindComponent(SCR_CampaignBuildingProviderComponent));
33 if (!providerComponent)
36 SCR_MilitaryBaseComponent base = providerComponent.GetMilitaryBaseComponent();
43 GetAllServicesUIInfo();
47 base.GetOnServiceRegistered().Insert(SetBaseServices);
48 base.GetOnServiceUnregistered().Insert(SetBaseServices);
49 base.GetOnServiceUnregistered().Insert(OnServiceUnregistered);
53 override void HandlerDeattached(Widget w)
55 super.HandlerDeattached(w);
61 RemoveOnServiceStateChangedEvent();
72 array<EEditableEntityLabel> entityLabels = {};
73 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
75 editableUIInfo.GetEntityLabels(entityLabels);
81 entityCore.GetCampaignBuildingModeLabelsData(entityLabels, buildingModeLabelData);
85 if (!m_aAvailableServicesLabel.Contains(
data.GetEntityLabel()))
86 m_aAvailableServicesLabel.Insert(
data.GetEntityLabel());
91 protected void GetAllServicesUIInfo()
94 if (!placingPrefabData)
97 array<ResourceName> AllPrefabs = {};
98 placingPrefabData.GetPrefabs(AllPrefabs);
100 foreach (ResourceName prefab : AllPrefabs)
102 Resource entityPrefab = Resource.Load(prefab);
103 if (!entityPrefab.IsValid())
111 if (!editableEntitySource)
122 if (editableUIInfo.GetFaction() !=
SCR_Faction.GetEntityFaction(player))
125 FilterServiceLabels(editableUIInfo);
130 protected void SetBaseServices(SCR_MilitaryBaseComponent militaryBaseComponent =
null, SCR_ServicePointComponent serviceComponent =
null)
136 RemoveOnServiceStateChangedEvent();
140 array<SCR_ServicePointComponent> services = {};
141 array<int> allEditorLabels = {};
142 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> serviceLabelData = {};
144 GetProviderServices(services);
148 entityCore.GetCampaignBuildingModeLabelsData(allEditorLabels, serviceLabelData);
152 foreach (SCR_ServicePointComponent service : services)
154 m_aServices.Insert(
new Tuple2<EEditableEntityLabel, SCR_ServicePointComponent>(service.GetLabel(), service));
155 service.GetOnServiceStateChanged().Insert(RefreshServiceUI);
161 protected void GetProviderServices(out array<SCR_ServicePointComponent> services)
163 SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
164 if (!buildingEditorComponent)
167 SCR_MilitaryBaseComponent militaryBaseComponent = SCR_MilitaryBaseComponent.Cast(buildingEditorComponent.GetProviderComponent().GetMilitaryBaseComponent());
168 if (!militaryBaseComponent)
171 militaryBaseComponent.GetServices(services);
176 protected void RemoveOnServiceStateChangedEvent()
178 array<SCR_ServicePointComponent> services = {};
179 GetProviderServices(services);
181 foreach (SCR_ServicePointComponent service : services)
183 service.GetOnServiceStateChanged().Remove(RefreshServiceUI);
188 protected void OnServiceUnregistered(SCR_MilitaryBaseComponent militaryBaseComponent , SCR_ServicePointComponent service)
194 protected void OnServiceChanged(SCR_EServicePointStatus state)
201 protected void RefreshServiceUI()
203 ClearServicesWidget();
208 protected void ClearServicesWidget()
210 Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget(
"Grid");
218 protected Widget CreateWidget(notnull Widget gridWidget,
int serviceId)
220 Widget serviceBtn =
GetGame().GetWorkspace().CreateWidgets(m_sServiceIconsGridPrefab, gridWidget);
224 int row = Math.Floor(serviceId / m_iMaxColumns);
225 int column = serviceId % m_iMaxColumns;
226 GridSlot.SetPadding(serviceBtn, PADDING_LEFT, 0, PADDING_RIGHT, 0);
227 GridSlot.SetRow(serviceBtn, row);
228 GridSlot.SetColumn(serviceBtn, column);
235 protected void SetServicesIcon()
237 if (m_iMaxColumns < 1)
238 m_iMaxColumns = DEFAULT_VALUE;
241 Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget(
"Grid");
246 for (
int i = m_aAvailableServicesLabel.Count() -1; i >= 0; --i)
248 serviceBtn = CreateWidget(gridWidget, i);
250 if (IsAnyServiceBuilt(m_aAvailableServicesLabel[i]))
251 serviceBtn.SetOpacity(1);
253 serviceBtn.SetOpacity(0.25);
255 ImageWidget imgWidget = ImageWidget.Cast(serviceBtn.FindAnyWidget(
"Image"));
259 SetIcon(imgWidget, m_aAvailableServicesLabel[i]);
269 foreach (Tuple2<EEditableEntityLabel, SCR_ServicePointComponent> service : m_aServices)
271 if (service.param1 != label)
274 if (service.param2 && service.param2.GetServiceState() == SCR_EServicePointStatus.ONLINE)
287 if (!m_aAvailableServicesLabel)
294 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
295 entityCore.GetCampaignBuildingModeLabelsData(m_aAvailableServicesLabel, buildingModeLabelData);
299 if (
data.GetEntityLabel() == serviceLabel)
300 data.GetUIInfo().SetIconTo(widget);