Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CampaignBuildingServicesEditorUIComponent.c
Go to the documentation of this file.
2{
3 [Attribute("{09DFB36A6C8D45C0}UI/layouts/Editor/GameInfo/GameInfo_CampaignBuilding_ServiceIcon.layout")]
5
6 [Attribute(DEFAULT_VALUE.ToString(), params: "1 inf 1", desc: "Maximum number of icons in the row")]
7 protected int m_iMaxColumns;
8
9 protected ref array<ref Tuple2<EEditableEntityLabel, SCR_ServicePointComponent>> m_aServices = {};
10
12 protected SCR_MilitaryBaseComponent m_MilitaryBaseComponent;
13
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;
19
20 protected ref array<EEditableEntityLabel> m_aAvailableServicesLabel = {};
21
22 //------------------------------------------------------------------------------------------------
23 override void HandlerAttached(Widget w)
24 {
26
27 SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
28 if (!buildingEditorComponent)
29 return;
30
31 // if provider isn't a base, disable the UI.
32 IEntity provider = buildingEditorComponent.GetProviderEntity();
33 if (!provider)
34 return;
35
36 SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(provider.FindComponent(SCR_CampaignBuildingProviderComponent));
37 if (!providerComponent)
38 return;
39
40 SCR_MilitaryBaseComponent base = providerComponent.GetMilitaryBaseComponent();
41 if (!base)
42 {
43 w.SetOpacity(0);
44 return;
45 }
46
50
51 base.GetOnServiceRegistered().Insert(SetBaseServices);
52 base.GetOnServiceUnregistered().Insert(SetBaseServices);
53 base.GetOnServiceUnregistered().Insert(OnServiceUnregistered);
54 }
55
56 //------------------------------------------------------------------------------------------------
57 override void HandlerDeattached(Widget w)
58 {
59 super.HandlerDeattached(w);
61 return;
62
63 m_MilitaryBaseComponent.GetOnServiceUnregistered().Remove(OnServiceUnregistered);
64
66 }
67
68 //------------------------------------------------------------------------------------------------
69 // Go through all labels of service and filter out those belonging to a service type. One composition (EditableEntityUIInfo) can holds more then one service.
70 protected void FilterServiceLabels(notnull SCR_EditableEntityUIInfo editableUIInfo)
71 {
73 if (!entityCore)
74 return;
75
76 array<EEditableEntityLabel> entityLabels = {};
77 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
78
79 editableUIInfo.GetEntityLabels(entityLabels);
80
81 // This composition doesn't have a service trait, no need to evaluate it.
82 if (!entityLabels.Contains(EEditableEntityLabel.TRAIT_SERVICE))
83 return;
84
85 entityCore.GetCampaignBuildingModeLabelsData(entityLabels, buildingModeLabelData);
86
87 foreach (SCR_EditableEntityCampaignBuildingModeLabelData data : buildingModeLabelData)
88 {
89 if (!m_aAvailableServicesLabel.Contains(data.GetEntityLabel()))
90 m_aAvailableServicesLabel.Insert(data.GetEntityLabel());
91 }
92 }
93
94 //------------------------------------------------------------------------------------------------
95 protected void GetAllServicesUIInfo()
96 {
98 if (!placingPrefabData)
99 return;
100
101 array<ResourceName> AllPrefabs = {};
102 placingPrefabData.GetPrefabs(AllPrefabs);
103
104 foreach (ResourceName prefab : AllPrefabs)
105 {
106 Resource entityPrefab = Resource.Load(prefab);
107 if (!entityPrefab.IsValid())
108 continue;
109
110 IEntitySource entitySource = SCR_BaseContainerTools.FindEntitySource(entityPrefab);
111 if (!entitySource)
112 continue;
113
115 if (!editableEntitySource)
116 continue;
117
118 SCR_EditableEntityUIInfo editableUIInfo = SCR_EditableEntityComponentClass.GetInfo(editableEntitySource);
119 if (!editableUIInfo)
120 continue;
121
122 IEntity player = EntityUtils.GetPlayer();
123 if (!player)
124 continue;
125
126 if (editableUIInfo.GetFaction() != SCR_Faction.GetEntityFaction(player))
127 continue;
128
129 FilterServiceLabels(editableUIInfo);
130 }
131 }
132
133 //------------------------------------------------------------------------------------------------
134 protected void SetBaseServices(SCR_MilitaryBaseComponent militaryBaseComponent = null, SCR_ServicePointComponent serviceComponent = null)
135 {
137 if (!entityCore)
138 return;
139
141
142 m_MilitaryBaseComponent = militaryBaseComponent;
143
144 array<SCR_ServicePointComponent> services = {};
145 array<int> allEditorLabels = {};
146 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> serviceLabelData = {};
147
148 GetProviderServices(services);
149
150 SCR_Enum.GetEnumValues(EEditableEntityLabel, allEditorLabels);
151
152 entityCore.GetCampaignBuildingModeLabelsData(allEditorLabels, serviceLabelData);
153
154 m_aServices.Clear();
155
156 foreach (SCR_ServicePointComponent service : services)
157 {
158 if (service.GetLabel() == EEditableEntityLabel.NONE)
159 continue;
160
161 m_aServices.Insert(new Tuple2<EEditableEntityLabel, SCR_ServicePointComponent>(service.GetLabel(), service));
162 service.GetOnServiceStateChanged().Insert(RefreshServiceUI);
163 }
164 }
165
166 //------------------------------------------------------------------------------------------------
168 protected void GetProviderServices(out array<SCR_ServicePointComponent> services)
169 {
170 SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
171 if (!buildingEditorComponent)
172 return;
173
174 SCR_MilitaryBaseComponent militaryBaseComponent = buildingEditorComponent.GetProviderComponent().GetMilitaryBaseComponent();
175 if (!militaryBaseComponent)
176 return;
177
178 militaryBaseComponent.GetServices(services);
179 }
180
181 //------------------------------------------------------------------------------------------------
184 {
185 array<SCR_ServicePointComponent> services = {};
186 GetProviderServices(services);
187
188 foreach (SCR_ServicePointComponent service : services)
189 {
190 service.GetOnServiceStateChanged().Remove(RefreshServiceUI);
191 }
192 }
193
194 //------------------------------------------------------------------------------------------------
195 protected void OnServiceUnregistered(SCR_MilitaryBaseComponent militaryBaseComponent , SCR_ServicePointComponent service)
196 {
198 }
199
200 //------------------------------------------------------------------------------------------------
201 protected void OnServiceChanged(SCR_EServicePointStatus state)
202 {
204 }
205
206 //------------------------------------------------------------------------------------------------
208 protected void RefreshServiceUI()
209 {
212 }
213
214 //------------------------------------------------------------------------------------------------
215 protected void ClearServicesWidget()
216 {
217 Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget("Grid");
218 if (!gridWidget)
219 return;
220
221 SCR_WidgetHelper.RemoveAllChildren(gridWidget);
222 }
223
224 //------------------------------------------------------------------------------------------------
225 protected Widget CreateWidget(notnull Widget gridWidget, int serviceId)
226 {
227 Widget serviceBtn = GetGame().GetWorkspace().CreateWidgets(m_sServiceIconsGridPrefab, gridWidget);
228 if (!serviceBtn)
229 return null;
230
231 int row = Math.Floor(serviceId / m_iMaxColumns);
232 int column = serviceId % m_iMaxColumns;
233 GridSlot.SetPadding(serviceBtn, PADDING_LEFT, 0, PADDING_RIGHT, 0);
234 GridSlot.SetRow(serviceBtn, row);
235 GridSlot.SetColumn(serviceBtn, column);
236
237 return serviceBtn;
238 }
239
240 //------------------------------------------------------------------------------------------------
242 protected void SetServicesIcon()
243 {
244 if (m_iMaxColumns < 1)
246
247 Widget serviceBtn;
248 Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget("Grid");
249 if (!gridWidget)
250 return;
251
252 // Iterate all services, check if they are avialable and if so, set the icon properly.
253 for (int i = m_aAvailableServicesLabel.Count() -1; i >= 0; --i)
254 {
255 serviceBtn = CreateWidget(gridWidget, i);
256
258 serviceBtn.SetOpacity(1);
259 else
260 serviceBtn.SetOpacity(0.25);
261
262 ImageWidget imgWidget = ImageWidget.Cast(serviceBtn.FindAnyWidget("Image"));
263 if (!imgWidget)
264 continue;
265
266 SetIcon(imgWidget, m_aAvailableServicesLabel[i]);
267 }
268 }
269
270 //------------------------------------------------------------------------------------------------
275 {
276 foreach (Tuple2<EEditableEntityLabel, SCR_ServicePointComponent> service : m_aServices)
277 {
278 if (service.param1 != label)
279 continue;
280
281 if (service.param2 && service.param2.GetServiceState() == SCR_EServicePointStatus.ONLINE)
282 return true;
283 }
284
285 return false;
286 }
287
288 //------------------------------------------------------------------------------------------------
292 protected void SetIcon(ImageWidget widget, EEditableEntityLabel serviceLabel)
293 {
295 return;
296
298 if (!entityCore)
299 return;
300
301 array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
302 entityCore.GetCampaignBuildingModeLabelsData(m_aAvailableServicesLabel, buildingModeLabelData);
303
304 foreach (SCR_EditableEntityCampaignBuildingModeLabelData data : buildingModeLabelData)
305 {
306 if (data.GetEntityLabel() == serviceLabel)
307 data.GetUIInfo().SetIconTo(widget);
308 }
309 }
310}
EEditableEntityLabel
ArmaReforgerScripted GetGame()
Definition game.c:1398
void SCR_EditableEntityCampaignBuildingModeLabelData(EEditableEntityLabel label, SCR_UIInfo uiInfo, SCR_EServicePointType linkedServicePoint)
Get all prefabs that have the spawner data
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
proto external Managed FindComponent(typename typeName)
Definition Math.c:13
Object holding reference to resource. In destructor release the resource.
Definition Resource.c:25
void GetProviderServices(out array< SCR_ServicePointComponent > services)
Returns all services available with current provider.
void FilterServiceLabels(notnull SCR_EditableEntityUIInfo editableUIInfo)
void OnServiceUnregistered(SCR_MilitaryBaseComponent militaryBaseComponent, SCR_ServicePointComponent service)
void RemoveOnServiceStateChangedEvent()
Removes the update ui event from all currently available services.
ref array< ref Tuple2< EEditableEntityLabel, SCR_ServicePointComponent > > m_aServices
void SetServicesIcon()
Go through all available services and set an icon to it.
void SetIcon(ImageWidget widget, EEditableEntityLabel serviceLabel)
void RefreshServiceUI()
Refresh the service widgets to reflect current status of services in base.
void SetBaseServices(SCR_MilitaryBaseComponent militaryBaseComponent=null, SCR_ServicePointComponent serviceComponent=null)
static IEntityComponentSource GetEditableEntitySource(Resource entityResource)
static Faction GetEntityFaction(notnull IEntity entity)
int GetPrefabs(out notnull array< ResourceName > outPrefabs, bool onlyExposed=false)
SCR_FieldOfViewSettings Attribute