Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CampaignBuildingServicesEditorUIComponent.c
Go to the documentation of this file.
2 {
3  [Attribute("{09DFB36A6C8D45C0}UI/layouts/Editor/GameInfo/GameInfo_CampaignBuilding_ServiceIcon.layout")]
4  protected ResourceName m_sServiceIconsGridPrefab;
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 
11  protected Widget m_wCampaignBuildingServicesRoot;
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  {
25  m_wCampaignBuildingServicesRoot = w;
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  SCR_CampaignBuildingProviderComponent providerComponent = SCR_CampaignBuildingProviderComponent.Cast(buildingEditorComponent.GetProviderEntity().FindComponent(SCR_CampaignBuildingProviderComponent));
33  if (!providerComponent)
34  return;
35 
36  SCR_MilitaryBaseComponent base = providerComponent.GetMilitaryBaseComponent();
37  if (!base)
38  {
39  w.SetOpacity(0);
40  return;
41  }
42 
43  GetAllServicesUIInfo();
44  SetBaseServices();
45  RefreshServiceUI();
46 
47  base.GetOnServiceRegistered().Insert(SetBaseServices);
48  base.GetOnServiceUnregistered().Insert(SetBaseServices);
49  base.GetOnServiceUnregistered().Insert(OnServiceUnregistered);
50  }
51 
52  //------------------------------------------------------------------------------------------------
53  override void HandlerDeattached(Widget w)
54  {
55  super.HandlerDeattached(w);
57  return;
58 
59  m_MilitaryBaseComponent.GetOnServiceUnregistered().Remove(OnServiceUnregistered);
60 
61  RemoveOnServiceStateChangedEvent();
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  // Go through all labels of service and filter out those belonging to a service type. One composition (EditableEntityUIInfo) can holds more then one service.
66  protected void FilterServiceLabels(notnull SCR_EditableEntityUIInfo editableUIInfo)
67  {
69  if (!entityCore)
70  return;
71 
72  array<EEditableEntityLabel> entityLabels = {};
73  array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
74 
75  editableUIInfo.GetEntityLabels(entityLabels);
76 
77  // This composition doesn't have a service trait, no need to evaluate it.
78  if (!entityLabels.Contains(EEditableEntityLabel.TRAIT_SERVICE))
79  return;
80 
81  entityCore.GetCampaignBuildingModeLabelsData(entityLabels, buildingModeLabelData);
82 
83  foreach (SCR_EditableEntityCampaignBuildingModeLabelData data : buildingModeLabelData)
84  {
85  if (!m_aAvailableServicesLabel.Contains(data.GetEntityLabel()))
86  m_aAvailableServicesLabel.Insert(data.GetEntityLabel());
87  }
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected void GetAllServicesUIInfo()
92  {
94  if (!placingPrefabData)
95  return;
96 
97  array<ResourceName> AllPrefabs = {};
98  placingPrefabData.GetPrefabs(AllPrefabs);
99 
100  foreach (ResourceName prefab : AllPrefabs)
101  {
102  Resource entityPrefab = Resource.Load(prefab);
103  if (!entityPrefab.IsValid())
104  continue;
105 
106  IEntitySource entitySource = SCR_BaseContainerTools.FindEntitySource(entityPrefab);
107  if (!entitySource)
108  continue;
109 
110  IEntityComponentSource editableEntitySource = SCR_EditableEntityComponentClass.GetEditableEntitySource(entitySource);
111  if (!editableEntitySource)
112  continue;
113 
114  SCR_EditableEntityUIInfo editableUIInfo = SCR_EditableEntityUIInfo.Cast(SCR_EditableEntityComponentClass.GetInfo(editableEntitySource));
115  if (!editableUIInfo)
116  continue;
117 
118  IEntity player = EntityUtils.GetPlayer();
119  if (!player)
120  continue;
121 
122  if (editableUIInfo.GetFaction() != SCR_Faction.GetEntityFaction(player))
123  continue;
124 
125  FilterServiceLabels(editableUIInfo);
126  }
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  protected void SetBaseServices(SCR_MilitaryBaseComponent militaryBaseComponent = null, SCR_ServicePointComponent serviceComponent = null)
131  {
133  if (!entityCore)
134  return;
135 
136  RemoveOnServiceStateChangedEvent();
137 
138  m_MilitaryBaseComponent = SCR_MilitaryBaseComponent.Cast(militaryBaseComponent);
139 
140  array<SCR_ServicePointComponent> services = {};
141  array<int> allEditorLabels = {};
142  array<ref SCR_EditableEntityCampaignBuildingModeLabelData> serviceLabelData = {};
143 
144  GetProviderServices(services);
145 
146  SCR_Enum.GetEnumValues(EEditableEntityLabel, allEditorLabels);
147 
148  entityCore.GetCampaignBuildingModeLabelsData(allEditorLabels, serviceLabelData);
149 
150  m_aServices.Clear();
151 
152  foreach (SCR_ServicePointComponent service : services)
153  {
154  m_aServices.Insert(new Tuple2<EEditableEntityLabel, SCR_ServicePointComponent>(service.GetLabel(), service));
155  service.GetOnServiceStateChanged().Insert(RefreshServiceUI);
156  }
157  }
158 
159  //------------------------------------------------------------------------------------------------
161  protected void GetProviderServices(out array<SCR_ServicePointComponent> services)
162  {
163  SCR_CampaignBuildingEditorComponent buildingEditorComponent = SCR_CampaignBuildingEditorComponent.Cast(SCR_CampaignBuildingEditorComponent.GetInstance(SCR_CampaignBuildingEditorComponent));
164  if (!buildingEditorComponent)
165  return;
166 
167  SCR_MilitaryBaseComponent militaryBaseComponent = SCR_MilitaryBaseComponent.Cast(buildingEditorComponent.GetProviderComponent().GetMilitaryBaseComponent());
168  if (!militaryBaseComponent)
169  return;
170 
171  militaryBaseComponent.GetServices(services);
172  }
173 
174  //------------------------------------------------------------------------------------------------
176  protected void RemoveOnServiceStateChangedEvent()
177  {
178  array<SCR_ServicePointComponent> services = {};
179  GetProviderServices(services);
180 
181  foreach (SCR_ServicePointComponent service : services)
182  {
183  service.GetOnServiceStateChanged().Remove(RefreshServiceUI);
184  }
185  }
186 
187  //------------------------------------------------------------------------------------------------
188  protected void OnServiceUnregistered(SCR_MilitaryBaseComponent militaryBaseComponent , SCR_ServicePointComponent service)
189  {
190  RefreshServiceUI();
191  }
192 
193  //------------------------------------------------------------------------------------------------
194  protected void OnServiceChanged(SCR_EServicePointStatus state)
195  {
196  RefreshServiceUI();
197  }
198 
199  //------------------------------------------------------------------------------------------------
201  protected void RefreshServiceUI()
202  {
203  ClearServicesWidget();
204  SetServicesIcon();
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  protected void ClearServicesWidget()
209  {
210  Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget("Grid");
211  if (!gridWidget)
212  return;
213 
214  SCR_WidgetHelper.RemoveAllChildren(gridWidget);
215  }
216 
217  //------------------------------------------------------------------------------------------------
218  protected Widget CreateWidget(notnull Widget gridWidget, int serviceId)
219  {
220  Widget serviceBtn = GetGame().GetWorkspace().CreateWidgets(m_sServiceIconsGridPrefab, gridWidget);
221  if (!serviceBtn)
222  return null;
223 
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);
229 
230  return serviceBtn;
231  }
232 
233  //------------------------------------------------------------------------------------------------
235  protected void SetServicesIcon()
236  {
237  if (m_iMaxColumns < 1)
238  m_iMaxColumns = DEFAULT_VALUE;
239 
240  Widget serviceBtn;
241  Widget gridWidget = m_wCampaignBuildingServicesRoot.FindAnyWidget("Grid");
242  if (!gridWidget)
243  return;
244 
245  // Iterate all services, check if they are avialable and if so, set the icon properly.
246  for (int i = m_aAvailableServicesLabel.Count() -1; i >= 0; --i)
247  {
248  serviceBtn = CreateWidget(gridWidget, i);
249 
250  if (IsAnyServiceBuilt(m_aAvailableServicesLabel[i]))
251  serviceBtn.SetOpacity(1);
252  else
253  serviceBtn.SetOpacity(0.25);
254 
255  ImageWidget imgWidget = ImageWidget.Cast(serviceBtn.FindAnyWidget("Image"));
256  if (!imgWidget)
257  continue;
258 
259  SetIcon(imgWidget, m_aAvailableServicesLabel[i]);
260  }
261  }
262 
263  //------------------------------------------------------------------------------------------------
267  bool IsAnyServiceBuilt(EEditableEntityLabel label)
268  {
269  foreach (Tuple2<EEditableEntityLabel, SCR_ServicePointComponent> service : m_aServices)
270  {
271  if (service.param1 != label)
272  continue;
273 
274  if (service.param2 && service.param2.GetServiceState() == SCR_EServicePointStatus.ONLINE)
275  return true;
276  }
277 
278  return false;
279  }
280 
281  //------------------------------------------------------------------------------------------------
285  protected void SetIcon(ImageWidget widget, EEditableEntityLabel serviceLabel)
286  {
287  if (!m_aAvailableServicesLabel)
288  return;
289 
291  if (!entityCore)
292  return;
293 
294  array<ref SCR_EditableEntityCampaignBuildingModeLabelData> buildingModeLabelData = {};
295  entityCore.GetCampaignBuildingModeLabelsData(m_aAvailableServicesLabel, buildingModeLabelData);
296 
297  foreach (SCR_EditableEntityCampaignBuildingModeLabelData data : buildingModeLabelData)
298  {
299  if (data.GetEntityLabel() == serviceLabel)
300  data.GetUIInfo().SetIconTo(widget);
301  }
302  }
303 }
EEditableEntityLabel
EEditableEntityLabel
Definition: EEditableEntityLabel.c:1
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_Enum
Definition: SCR_Enum.c:1
SCR_EditableEntityCampaignBuildingModeLabelData
void SCR_EditableEntityCampaignBuildingModeLabelData(EEditableEntityLabel label, SCR_UIInfo uiInfo, SCR_EServicePointType linkedServicePoint)
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:39
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditableEntityUIInfo
Definition: SCR_EditableEntityUIInfo.c:2
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
m_MilitaryBaseComponent
SCR_MilitaryBaseAreaMeshComponentClass m_MilitaryBaseComponent
SCR_WidgetHelper
Definition: SCR_WidgetHelper.c:1
SCR_CampaignBuildingServicesEditorUIComponent
Definition: SCR_CampaignBuildingServicesEditorUIComponent.c:1
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseContainerTools
Definition: SCR_BaseContainerTools.c:3
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
data
Get all prefabs that have the spawner data
Definition: SCR_EntityCatalogManagerComponent.c:305
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
EntityUtils
Definition: EntityUtils.c:12
SCR_EditableEntityComponentClass
Definition: SCR_EditableEntityComponentClass.c:2
SCR_PlacingEditorComponent
Definition: SCR_PlacingEditorComponent.c:118
SCR_Faction
Definition: SCR_Faction.c:6
SCR_PlacingEditorComponentClass
Definition: SCR_PlacingEditorComponent.c:2