Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_CampaignBuildingServicesEditorUIComponent.c
Go to the documentation of this file.
1
class
SCR_CampaignBuildingServicesEditorUIComponent
:
SCR_BaseEditorUIComponent
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
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
47
GetAllServicesUIInfo
();
48
SetBaseServices
();
49
RefreshServiceUI
();
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);
60
if
(!
m_MilitaryBaseComponent
)
61
return
;
62
63
m_MilitaryBaseComponent
.GetOnServiceUnregistered().Remove(
OnServiceUnregistered
);
64
65
RemoveOnServiceStateChangedEvent
();
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
{
72
SCR_EditableEntityCore
entityCore =
SCR_EditableEntityCore
.Cast(
SCR_EditableEntityCore
.GetInstance(
SCR_EditableEntityCore
));
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
{
97
SCR_PlacingEditorComponentClass
placingPrefabData =
SCR_PlacingEditorComponentClass
.Cast(
SCR_PlacingEditorComponentClass
.GetInstance(
SCR_PlacingEditorComponent
,
true
));
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
114
IEntityComponentSource
editableEntitySource =
SCR_EditableEntityComponentClass
.
GetEditableEntitySource
(entitySource);
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
{
136
SCR_EditableEntityCore
entityCore =
SCR_EditableEntityCore
.Cast(
SCR_EditableEntityCore
.GetInstance(
SCR_EditableEntityCore
));
137
if
(!entityCore)
138
return
;
139
140
RemoveOnServiceStateChangedEvent
();
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
//------------------------------------------------------------------------------------------------
183
protected
void
RemoveOnServiceStateChangedEvent
()
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
{
197
RefreshServiceUI
();
198
}
199
200
//------------------------------------------------------------------------------------------------
201
protected
void
OnServiceChanged
(SCR_EServicePointStatus state)
202
{
203
RefreshServiceUI
();
204
}
205
206
//------------------------------------------------------------------------------------------------
208
protected
void
RefreshServiceUI
()
209
{
210
ClearServicesWidget
();
211
SetServicesIcon
();
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)
245
m_iMaxColumns
=
DEFAULT_VALUE
;
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
257
if
(
IsAnyServiceBuilt
(
m_aAvailableServicesLabel
[i]))
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
//------------------------------------------------------------------------------------------------
274
bool
IsAnyServiceBuilt
(
EEditableEntityLabel
label)
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
{
294
if
(!
m_aAvailableServicesLabel
)
295
return
;
296
297
SCR_EditableEntityCore
entityCore =
SCR_EditableEntityCore
.Cast(
SCR_EditableEntityCore
.GetInstance(
SCR_EditableEntityCore
));
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
EEditableEntityLabel
Definition
EEditableEntityLabel.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_EditableEntityCampaignBuildingModeLabelData
void SCR_EditableEntityCampaignBuildingModeLabelData(EEditableEntityLabel label, SCR_UIInfo uiInfo, SCR_EServicePointType linkedServicePoint)
Definition
SCR_EditableEntityCampaignBuildingModeLabelSetting.c:39
data
Get all prefabs that have the spawner data
Definition
SCR_EntityCatalogManagerComponent.c:320
base
around base
Definition
SCR_HoldCampaignMilitaryBaseTaskEntity.c:9
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
params
category params
Definition
SCR_SpherePointGeneratorPreviewComponent.c:21
EntityUtils
Definition
EntityUtils.c:13
GridSlot
Definition
GridSlot.c:13
IEntityComponentSource
Definition
IEntityComponentSource.c:13
IEntity
Definition
IEntity.c:13
IEntity::FindComponent
proto external Managed FindComponent(typename typeName)
IEntitySource
Definition
IEntitySource.c:13
ImageWidget
Definition
ImageWidget.c:13
Math
Definition
Math.c:13
Resource
Object holding reference to resource. In destructor release the resource.
Definition
Resource.c:25
ResourceName
Definition
ResourceName.c:13
SCR_BaseContainerTools
Definition
SCR_BaseContainerTools.c:4
SCR_BaseEditorUIComponent
Definition
SCR_BaseEditorUIComponent.c:4
SCR_CampaignBuildingServicesEditorUIComponent
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:2
SCR_CampaignBuildingServicesEditorUIComponent::GetProviderServices
void GetProviderServices(out array< SCR_ServicePointComponent > services)
Returns all services available with current provider.
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:168
SCR_CampaignBuildingServicesEditorUIComponent::PADDING_TOP
const int PADDING_TOP
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:16
SCR_CampaignBuildingServicesEditorUIComponent::PADDING_LEFT
const int PADDING_LEFT
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:14
SCR_CampaignBuildingServicesEditorUIComponent::FilterServiceLabels
void FilterServiceLabels(notnull SCR_EditableEntityUIInfo editableUIInfo)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:70
SCR_CampaignBuildingServicesEditorUIComponent::OnServiceUnregistered
void OnServiceUnregistered(SCR_MilitaryBaseComponent militaryBaseComponent, SCR_ServicePointComponent service)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:195
SCR_CampaignBuildingServicesEditorUIComponent::RemoveOnServiceStateChangedEvent
void RemoveOnServiceStateChangedEvent()
Removes the update ui event from all currently available services.
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:183
SCR_CampaignBuildingServicesEditorUIComponent::PADDING_RIGHT
const int PADDING_RIGHT
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:15
SCR_CampaignBuildingServicesEditorUIComponent::m_aServices
ref array< ref Tuple2< EEditableEntityLabel, SCR_ServicePointComponent > > m_aServices
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:9
SCR_CampaignBuildingServicesEditorUIComponent::ClearServicesWidget
void ClearServicesWidget()
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:215
SCR_CampaignBuildingServicesEditorUIComponent::SetServicesIcon
void SetServicesIcon()
Go through all available services and set an icon to it.
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:242
SCR_CampaignBuildingServicesEditorUIComponent::GetAllServicesUIInfo
void GetAllServicesUIInfo()
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:95
SCR_CampaignBuildingServicesEditorUIComponent::HandlerAttached
override void HandlerAttached(Widget w)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:23
SCR_CampaignBuildingServicesEditorUIComponent::m_MilitaryBaseComponent
SCR_MilitaryBaseComponent m_MilitaryBaseComponent
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:12
SCR_CampaignBuildingServicesEditorUIComponent::SetIcon
void SetIcon(ImageWidget widget, EEditableEntityLabel serviceLabel)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:292
SCR_CampaignBuildingServicesEditorUIComponent::RefreshServiceUI
void RefreshServiceUI()
Refresh the service widgets to reflect current status of services in base.
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:208
SCR_CampaignBuildingServicesEditorUIComponent::IsAnyServiceBuilt
bool IsAnyServiceBuilt(EEditableEntityLabel label)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:274
SCR_CampaignBuildingServicesEditorUIComponent::m_wCampaignBuildingServicesRoot
Widget m_wCampaignBuildingServicesRoot
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:11
SCR_CampaignBuildingServicesEditorUIComponent::DEFAULT_VALUE
static const int DEFAULT_VALUE
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:18
SCR_CampaignBuildingServicesEditorUIComponent::m_iMaxColumns
int m_iMaxColumns
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:7
SCR_CampaignBuildingServicesEditorUIComponent::OnServiceChanged
void OnServiceChanged(SCR_EServicePointStatus state)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:201
SCR_CampaignBuildingServicesEditorUIComponent::SetBaseServices
void SetBaseServices(SCR_MilitaryBaseComponent militaryBaseComponent=null, SCR_ServicePointComponent serviceComponent=null)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:134
SCR_CampaignBuildingServicesEditorUIComponent::HandlerDeattached
override void HandlerDeattached(Widget w)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:57
SCR_CampaignBuildingServicesEditorUIComponent::CreateWidget
Widget CreateWidget(notnull Widget gridWidget, int serviceId)
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:225
SCR_CampaignBuildingServicesEditorUIComponent::m_sServiceIconsGridPrefab
ResourceName m_sServiceIconsGridPrefab
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:4
SCR_CampaignBuildingServicesEditorUIComponent::PADDING_BOTTOM
const int PADDING_BOTTOM
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:17
SCR_CampaignBuildingServicesEditorUIComponent::m_aAvailableServicesLabel
ref array< EEditableEntityLabel > m_aAvailableServicesLabel
Definition
SCR_CampaignBuildingServicesEditorUIComponent.c:20
SCR_EditableEntityComponentClass
Definition
SCR_EditableEntityComponentClass.c:3
SCR_EditableEntityComponentClass::GetInfo
SCR_UIInfo GetInfo()
Definition
SCR_EditableEntityComponentClass.c:111
SCR_EditableEntityComponentClass::GetEditableEntitySource
static IEntityComponentSource GetEditableEntitySource(Resource entityResource)
Definition
SCR_EditableEntityComponentClass.c:143
SCR_EditableEntityCore
Definition
SCR_EditableEntityCore.c:20
SCR_EditableEntityUIInfo
Definition
SCR_EditableEntityUIInfo.c:3
SCR_EditableEntityUIInfo::GetFaction
Faction GetFaction()
Definition
SCR_EditableEntityUIInfo.c:88
SCR_Enum
Definition
SCR_Enum.c:2
SCR_Faction
Definition
SCR_Faction.c:6
SCR_Faction::GetEntityFaction
static Faction GetEntityFaction(notnull IEntity entity)
Definition
SCR_Faction.c:810
SCR_PlacingEditorComponentClass
Definition
SCR_PlacingEditorComponent.c:3
SCR_PlacingEditorComponentClass::GetPrefabs
int GetPrefabs(out notnull array< ResourceName > outPrefabs, bool onlyExposed=false)
Definition
SCR_PlacingEditorComponent.c:81
SCR_PlacingEditorComponent
Definition
SCR_PlacingEditorComponent.c:119
SCR_WidgetHelper
Definition
SCR_WidgetHelper.c:2
Widget
Definition
Widget.c:13
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
scripts
Game
Editor
UI
Components
Common
SCR_CampaignBuildingServicesEditorUIComponent.c
Generated by
1.17.0