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_PlacingEditorUIComponent.c
Go to the documentation of this file.
1
2
3
class
SCR_PlacingEditorUIComponent
: SCR_PreviewEntityEditorUIComponent
4
{
5
//--- When ASL vertical mode is on, how far from camera the entity appears when no ground intersection was found
6
protected
static
const
float
MAX_PREVIEW_DIS
= 50;
7
8
private
InputManager
m_InputManager;
9
private
SCR_StatesEditorComponent
m_StatesManager;
10
private
SCR_CursorEditorUIComponent
m_CursorComponent;
11
private
SCR_EntitiesEditorUIComponent
m_EntitiesComponent;
12
private
SCR_SelectionEditorUIComponent
m_SelectionComponent;
13
private
SCR_MouseAreaEditorUIComponent
m_MouseArea;
14
//private SCR_SiteSlotEntity m_Slot;
15
private
bool
m_bClicked;
16
private
bool
m_bCanPlace;
17
private
ref array<Widget> m_aClickWhitelist = {};
18
19
//------------------------------------------------------------------------------------------------
20
override
void
OnHoverChange
(
EEditableEntityState
state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
21
{
22
if
(m_StatesManager && m_StatesManager.GetState() ==
EEditorState
.PLACING)
23
super.OnHoverChange(state, entitiesInsert, entitiesRemove);
24
}
25
26
//------------------------------------------------------------------------------------------------
27
override
void
OnEditorTransformRotationModifierUp(
float
value,
EActionTrigger
reason
)
28
{
29
if
(!m_StatesManager)
30
return
;
31
32
EEditorState
currentState = m_StatesManager.GetState();
33
if
(currentState ==
EEditorState
.PLACING || currentState ==
EEditorState
.SELECTING)
34
super.OnEditorTransformRotationModifierUp(value,
reason
);
35
}
36
37
//------------------------------------------------------------------------------------------------
38
protected
void
OnEditorPlace
(
float
value,
EActionTrigger
reason
)
39
{
40
Place
(
false
);
41
}
42
43
//------------------------------------------------------------------------------------------------
44
protected
void
OnEditorPlaceAndCancel
(
float
value,
EActionTrigger
reason
)
45
{
46
Place
(
true
);
47
}
48
49
//------------------------------------------------------------------------------------------------
50
protected
void
OnEditorPlacePlayer
(
float
value,
EActionTrigger
reason
)
51
{
52
Place
(
false
,
true
);
53
}
54
55
//------------------------------------------------------------------------------------------------
56
protected
void
OnEditorPlacePlayerAndCancel
(
float
value,
EActionTrigger
reason
)
57
{
58
Place
(
true
,
true
);
59
60
//--- Prevent multi-selection from starting right afterwards (it's mapped to the same button by default; ToDo: More sandbox?)
61
if
(m_SelectionComponent)
62
m_SelectionComponent.DisableMultiSelection();
63
}
64
65
//------------------------------------------------------------------------------------------------
66
protected
void
Place
(
bool
cancelAfterwards,
bool
canBePlayer =
false
)
67
{
68
if
(m_StatesManager && m_StatesManager.IsWaiting())
69
return
;
70
71
//--- Placing not enabled
72
if
(!m_bCanPlace || (m_StatesManager && m_StatesManager.GetState() !=
EEditorState
.PLACING) || !
CanClick
())
73
return
;
74
75
if
(!
m_PreviewEntityManager
.CanMoveInRoot() && !
m_PreviewEntityManager
.GetTarget())
76
return
;
77
78
//--- Map is opened, placing not possible
79
SCR_MapEntity
mapEntity =
SCR_MapEntity
.
GetMapInstance
();
80
if
(mapEntity && mapEntity.
IsOpen
())
81
return
;
82
83
if
(!
m_PlacingManager
.CreateEntity(cancelAfterwards, canBePlayer))
84
return
;
85
86
//if (cancelAfterwards) CancelPlacing();
87
m_bClicked =
false
;
88
}
89
90
//------------------------------------------------------------------------------------------------
91
protected
void
OnEditorCancelPlacingUp
(
float
value,
EActionTrigger
reason
)
92
{
93
if
(OnCancelUp())
94
CancelPlacing
();
95
}
96
97
//------------------------------------------------------------------------------------------------
98
protected
void
CancelPlacing
()
99
{
100
if
(
m_PlacingManager
)
101
m_PlacingManager
.SetSelectedPrefab();
102
}
103
104
//------------------------------------------------------------------------------------------------
105
protected
void
EnablePlacing
()
106
{
107
m_bCanPlace =
true
;
108
}
109
110
//------------------------------------------------------------------------------------------------
111
protected
bool
CanClick
()
112
{
113
if
(m_CursorComponent && m_MouseArea && !m_MouseArea.IsMouseOn() && m_InputManager.IsUsingMouseAndKeyboard())
114
{
115
MenuRootComponent
root = GetRootComponent();
116
if
(root)
117
{
118
Widget
rootWidget = root.
GetWidget
();
119
if
(rootWidget)
120
{
121
//--- Get all widgets under cursor
122
int
mouseX, mouseY;
123
m_CursorComponent.GetCursorPos(mouseX, mouseY);
124
array<Widget> widgets = {};
125
WidgetManager
.TraceWidgets(mouseX, mouseY, rootWidget, widgets);
126
127
//--- Check if the widgets are whitelisted. If not, terminate
128
foreach
(
Widget
widget: widgets)
129
{
130
bool
canClick =
false
;
131
foreach
(
Widget
widgetWhitelisted: m_aClickWhitelist)
132
{
133
canClick |=
IsChildOf
(widget, widgetWhitelisted);
134
}
135
136
if
(!canClick)
137
return
false
;
138
}
139
}
140
}
141
}
142
return
true
;
143
}
144
145
//------------------------------------------------------------------------------------------------
146
protected
bool
IsChildOf
(
Widget
widget,
Widget
parent)
147
{
148
while
(widget)
149
{
150
if
(widget == parent)
151
return
true
;
152
153
widget = widget.GetParent();
154
}
155
return
false
;
156
}
157
158
//------------------------------------------------------------------------------------------------
159
protected
void
OnSelectedPrefabChange
(
ResourceName
prefab,
ResourceName
prefabPrev)
160
{
161
ArmaReforgerScripted
game
=
GetGame
();
162
if
(!
game
)
163
return
;
164
165
ScriptCallQueue
queue =
game
.GetCallqueue();
166
if
(!queue)
167
return
;
168
169
//--- Ignore input right after starting placing. Important for gamepads, because 'A' button is still held after selection.
170
queue.CallLater(
EnablePlacing
, 50);
171
m_bCanPlace =
false
;
172
173
//--- Set default entity height when in ASL vertical mode
174
SCR_PreviewEntityEditorComponent
previewManager =
SCR_PreviewEntityEditorComponent
.Cast(
SCR_PreviewEntityEditorComponent
.GetInstance(
SCR_PreviewEntityEditorComponent
));
175
if
(previewManager && previewManager.
GetVerticalMode
() ==
EEditorTransformVertical
.SEA)
176
{
177
BaseWorld
world =
game
.GetWorld();
178
if
(!world)
179
return
;
180
181
WorkspaceWidget
workspace =
game
.GetWorkspace();
182
if
(!workspace)
183
return
;
184
185
//--- Get intersection in the middle of the screen (don't use cursor, it just returned form a sub-menu ans is not relevant)
186
float
screenW, screenH;
187
workspace.GetScreenSize(screenW, screenH);
188
vector
cameraDir;
189
vector
cameraPos = workspace.ProjScreenToWorldNative(screenW * 0.5, screenH * 0.5, cameraDir, world, -1);
190
191
//--- Find ground intersection, or use maximum distance when none is found
192
float
traceDis =
GetTraceDis
(cameraPos, cameraDir * TRACE_DIS, cameraPos[1]);
193
if
(traceDis == 1)
194
traceDis =
MAX_PREVIEW_DIS
;
195
else
196
traceDis *= TRACE_DIS;
197
198
//--- Set default preview height
199
previewManager.
SetPreviewHeight
(cameraPos + cameraDir * traceDis);
200
}
201
}
202
203
//------------------------------------------------------------------------------------------------
204
protected
void
OnMenuUpdate
(
float
tDelta)
205
{
206
ActivatePreviewContext
();
207
208
if
(m_StatesManager && m_StatesManager.GetState() !=
EEditorState
.PLACING)
209
return
;
210
211
if
(m_InputManager &&
m_PlacingManager
)
212
{
213
m_InputManager.ActivateContext(
"EditorPlacingContext"
);
214
if
(
m_PlacingManager
.IsPlacingFlagCompatible(
EEditorPlacingFlags
.CHARACTER_PLAYER))
215
m_InputManager.ActivateContext(
"EditorPlacingPlayerContext"
);
216
}
217
218
ProcessInput
(tDelta);
219
}
220
221
//------------------------------------------------------------------------------------------------
222
protected
void
OnMenuFocusGained
()
223
{
224
GetMenu
().GetOnMenuUpdate().Insert(
OnMenuUpdate
);
225
}
226
227
//------------------------------------------------------------------------------------------------
228
protected
void
OnMenuFocusLost
()
229
{
230
GetMenu
().GetOnMenuUpdate().Remove(
OnMenuUpdate
);
231
}
232
233
//------------------------------------------------------------------------------------------------
234
override
protected
SCR_EPreviewState
GetPreviewStateToShow
()
235
{
236
if
(
m_PlacingManager
&&
m_PlacingManager
.CanCreateEntity())
237
return
SCR_EPreviewState
.PLACEABLE;
238
else
239
return
SCR_EPreviewState
.BLOCKED;
240
}
241
242
//------------------------------------------------------------------------------------------------
243
override
void
HandlerAttachedScripted
(
Widget
w)
244
{
245
super.HandlerAttachedScripted(w);
246
247
MenuRootComponent
root = GetRootComponent();
248
if
(root)
249
{
250
m_MouseArea =
SCR_MouseAreaEditorUIComponent
.Cast(root.
FindComponent
(
SCR_MouseAreaEditorUIComponent
));
251
m_EntitiesComponent =
SCR_EntitiesEditorUIComponent
.Cast(root.
FindComponent
(
SCR_EntitiesEditorUIComponent
));
252
m_CursorComponent =
SCR_CursorEditorUIComponent
.Cast(root.
FindComponent
(
SCR_CursorEditorUIComponent
));
253
m_SelectionComponent =
SCR_SelectionEditorUIComponent
.Cast(root.
FindComponent
(
SCR_SelectionEditorUIComponent
));
254
255
if
(m_MouseArea)
256
m_aClickWhitelist.Insert(m_MouseArea.GetWidget());
257
258
if
(m_EntitiesComponent)
259
m_aClickWhitelist.Insert(m_EntitiesComponent.GetWidget());
260
}
261
262
if
(!m_CursorComponent)
263
Print
(
"SCR_PlacingEditorUIComponent requires SCR_CursorEditorUIComponent!"
,
LogLevel
.ERROR);
264
265
m_PlacingManager
.GetOnSelectedPrefabChange().Insert(
OnSelectedPrefabChange
);
266
267
m_StatesManager =
SCR_StatesEditorComponent
.Cast(
SCR_StatesEditorComponent
.GetInstance(
SCR_StatesEditorComponent
));
268
269
MenuRootBase
menu =
GetMenu
();
270
if
(menu)
271
{
272
menu.
GetOnMenuUpdate
().Insert(
OnMenuUpdate
);
273
menu.
GetOnMenuFocusGained
().Insert(
OnMenuFocusGained
);
274
menu.
GetOnMenuFocusLost
().Insert(
OnMenuFocusLost
);
275
}
276
277
ArmaReforgerScripted
game
=
GetGame
();
278
if
(
game
)
279
{
280
m_InputManager =
game
.GetInputManager();
281
if
(m_InputManager)
282
{
283
m_InputManager.AddActionListener(
"EditorPlace"
,
EActionTrigger
.DOWN,
OnEditorPlace
);
284
m_InputManager.AddActionListener(
"EditorPlaceAndCancel"
,
EActionTrigger
.DOWN,
OnEditorPlaceAndCancel
);
285
m_InputManager.AddActionListener(
"EditorPlacePlayer"
,
EActionTrigger
.DOWN,
OnEditorPlacePlayer
);
286
m_InputManager.AddActionListener(
"EditorPlacePlayerAndCancel"
,
EActionTrigger
.DOWN,
OnEditorPlacePlayerAndCancel
);
287
m_InputManager.AddActionListener(
"EditorCancelPlacing"
,
EActionTrigger
.DOWN, OnCancelDown);
288
m_InputManager.AddActionListener(
"EditorCancelPlacing"
,
EActionTrigger
.UP,
OnEditorCancelPlacingUp
);
289
}
290
}
291
}
292
293
//------------------------------------------------------------------------------------------------
294
override
void
HandlerDeattached
(
Widget
w)
295
{
296
super.HandlerDeattached(w);
297
298
if
(
m_PlacingManager
)
299
m_PlacingManager
.GetOnSelectedPrefabChange().Remove(
OnSelectedPrefabChange
);
300
301
MenuRootBase
menu =
GetMenu
();
302
if
(menu)
303
{
304
menu.
GetOnMenuUpdate
().Remove(
OnMenuUpdate
);
305
menu.
GetOnMenuFocusGained
().Remove(
OnMenuFocusGained
);
306
menu.
GetOnMenuFocusLost
().Remove(
OnMenuFocusLost
);
307
}
308
309
ArmaReforgerScripted
game
=
GetGame
();
310
if
(
game
)
311
{
312
InputManager
inputManager =
game
.GetInputManager();
313
if
(m_InputManager)
314
{
315
inputManager.RemoveActionListener(
"EditorPlace"
,
EActionTrigger
.DOWN,
OnEditorPlace
);
316
inputManager.RemoveActionListener(
"EditorPlaceAndCancel"
,
EActionTrigger
.DOWN,
OnEditorPlaceAndCancel
);
317
inputManager.RemoveActionListener(
"EditorPlacePlayer"
,
EActionTrigger
.DOWN,
OnEditorPlacePlayer
);
318
inputManager.RemoveActionListener(
"EditorPlacePlayerAndCancel"
,
EActionTrigger
.DOWN,
OnEditorPlacePlayerAndCancel
);
319
m_InputManager.RemoveActionListener(
"EditorCancelPlacing"
,
EActionTrigger
.DOWN, OnCancelDown);
320
m_InputManager.RemoveActionListener(
"EditorCancelPlacing"
,
EActionTrigger
.UP,
OnEditorCancelPlacingUp
);
321
}
322
}
323
}
324
}
game
ref DSGameConfig game
Definition
DSConfig.c:81
EEditorPlacingFlags
EEditorPlacingFlags
Definition
EEditorPlacingFlags.c:3
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
SCR_EPreviewState
SCR_EPreviewState
Definition
SCR_PreviewEntityEditorComponent.c:1161
m_PreviewEntityManager
SCR_PreviewEntityEditorComponent m_PreviewEntityManager
Definition
SCR_PreviewEntityEditorUIComponent.c:41
ActivatePreviewContext
void ActivatePreviewContext()
Definition
SCR_PreviewEntityEditorUIComponent.c:761
m_PlacingManager
SCR_PlacingEditorComponent m_PlacingManager
Definition
SCR_PreviewEntityEditorUIComponent.c:43
OnHoverChange
void OnHoverChange(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
Definition
SCR_PreviewEntityEditorUIComponent.c:67
GetTraceDis
float GetTraceDis(vector pos, vector dir, float cameraHeight)
Definition
SCR_PreviewEntityEditorUIComponent.c:265
ProcessInput
void ProcessInput(float tDelta)
Definition
SCR_PreviewEntityEditorUIComponent.c:682
GetMenu
SCR_RadialMenu GetMenu()
Definition
SCR_RadialMenuGameModeComponent.c:38
reason
string reason
Definition
ServerBrowserMenuCallbacks.c:41
BaseWorld
Definition
BaseWorld.c:13
InputManager
Input management system for user interactions.
Definition
InputManager.c:20
MenuRootBase
Definition
MenuRootBase.c:11
MenuRootBase::GetOnMenuFocusGained
ScriptInvoker GetOnMenuFocusGained()
Definition
MenuRootBase.c:42
MenuRootBase::GetOnMenuUpdate
ScriptInvoker GetOnMenuUpdate()
Definition
MenuRootBase.c:72
MenuRootBase::GetOnMenuFocusLost
ScriptInvoker GetOnMenuFocusLost()
Definition
MenuRootBase.c:48
MenuRootComponent
Definition
MenuRootComponent.c:7
MenuRootComponent::GetWidget
Widget GetWidget()
Definition
MenuRootComponent.c:69
MenuRootComponent::FindComponent
MenuRootSubComponent FindComponent(typename type, bool showError=false)
Definition
MenuRootComponent.c:101
ResourceName
Definition
ResourceName.c:13
SCR_CursorEditorUIComponent
Definition
SCR_CursorEditorUIComponent.c:4
SCR_EntitiesEditorUIComponent
Definition
SCR_EntitiesEditorUIComponent.c:2
SCR_MapEntity
Definition
SCR_MapEntity.c:18
SCR_MapEntity::IsOpen
bool IsOpen()
Check if the map is opened.
Definition
SCR_MapEntity.c:123
SCR_MapEntity::GetMapInstance
static SCR_MapEntity GetMapInstance()
Get map entity instance.
Definition
SCR_MapEntity.c:112
SCR_MouseAreaEditorUIComponent
Definition
SCR_MouseAreaEditorUIComponent.c:4
SCR_PlacingEditorUIComponent
Definition
SCR_PlacingEditorUIComponent.c:4
SCR_PlacingEditorUIComponent::OnEditorPlacePlayer
void OnEditorPlacePlayer(float value, EActionTrigger reason)
Definition
SCR_PlacingEditorUIComponent.c:50
SCR_PlacingEditorUIComponent::MAX_PREVIEW_DIS
static const float MAX_PREVIEW_DIS
Definition
SCR_PlacingEditorUIComponent.c:6
SCR_PlacingEditorUIComponent::HandlerAttachedScripted
override void HandlerAttachedScripted(Widget w)
Definition
SCR_PlacingEditorUIComponent.c:243
SCR_PlacingEditorUIComponent::Place
void Place(bool cancelAfterwards, bool canBePlayer=false)
Definition
SCR_PlacingEditorUIComponent.c:66
SCR_PlacingEditorUIComponent::OnMenuUpdate
void OnMenuUpdate(float tDelta)
Definition
SCR_PlacingEditorUIComponent.c:204
SCR_PlacingEditorUIComponent::OnMenuFocusGained
void OnMenuFocusGained()
Definition
SCR_PlacingEditorUIComponent.c:222
SCR_PlacingEditorUIComponent::OnMenuFocusLost
void OnMenuFocusLost()
Definition
SCR_PlacingEditorUIComponent.c:228
SCR_PlacingEditorUIComponent::CanClick
bool CanClick()
Definition
SCR_PlacingEditorUIComponent.c:111
SCR_PlacingEditorUIComponent::HandlerDeattached
override void HandlerDeattached(Widget w)
Definition
SCR_PlacingEditorUIComponent.c:294
SCR_PlacingEditorUIComponent::OnEditorCancelPlacingUp
void OnEditorCancelPlacingUp(float value, EActionTrigger reason)
Definition
SCR_PlacingEditorUIComponent.c:91
SCR_PlacingEditorUIComponent::OnEditorPlaceAndCancel
void OnEditorPlaceAndCancel(float value, EActionTrigger reason)
Definition
SCR_PlacingEditorUIComponent.c:44
SCR_PlacingEditorUIComponent::OnSelectedPrefabChange
void OnSelectedPrefabChange(ResourceName prefab, ResourceName prefabPrev)
Definition
SCR_PlacingEditorUIComponent.c:159
SCR_PlacingEditorUIComponent::EnablePlacing
void EnablePlacing()
Definition
SCR_PlacingEditorUIComponent.c:105
SCR_PlacingEditorUIComponent::GetPreviewStateToShow
SCR_EPreviewState GetPreviewStateToShow()
Definition
SCR_PlacingEditorUIComponent.c:234
SCR_PlacingEditorUIComponent::CancelPlacing
void CancelPlacing()
Definition
SCR_PlacingEditorUIComponent.c:98
SCR_PlacingEditorUIComponent::OnEditorPlace
void OnEditorPlace(float value, EActionTrigger reason)
Definition
SCR_PlacingEditorUIComponent.c:38
SCR_PlacingEditorUIComponent::OnEditorPlacePlayerAndCancel
void OnEditorPlacePlayerAndCancel(float value, EActionTrigger reason)
Definition
SCR_PlacingEditorUIComponent.c:56
SCR_PlacingEditorUIComponent::IsChildOf
bool IsChildOf(Widget widget, Widget parent)
Definition
SCR_PlacingEditorUIComponent.c:146
SCR_PreviewEntityEditorComponent
Definition
SCR_PreviewEntityEditorComponent.c:13
SCR_PreviewEntityEditorComponent::SetPreviewHeight
void SetPreviewHeight(vector pos)
Definition
SCR_PreviewEntityEditorComponent.c:288
SCR_PreviewEntityEditorComponent::GetVerticalMode
EEditorTransformVertical GetVerticalMode()
Definition
SCR_PreviewEntityEditorComponent.c:358
SCR_SelectionEditorUIComponent
Definition
SCR_SelectionEditorUIComponent.c:4
SCR_StatesEditorComponent
Definition
SCR_StatesEditorComponent.c:10
ScriptCallQueue
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition
tools.c:53
Widget
Definition
Widget.c:13
WidgetManager
Definition
WidgetManager.c:16
WorkspaceWidget
Definition
WorkspaceWidget.c:16
vector
Definition
vector.c:13
Print
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
LogLevel
Enum with severity of the logging message.
Definition
LogLevel.c:14
EEditableEntityState
EEditableEntityState
Definition
EEditableEntityState.c:38
EEditorTransformVertical
EEditorTransformVertical
Vertical transformation mode.
Definition
EEditorTransformVertical.c:6
EEditorState
EEditorState
Unique editor state.
Definition
EEditorState.c:6
EActionTrigger
EActionTrigger
Definition
EActionTrigger.c:13
scripts
Game
Editor
UI
Components
Common
SCR_PlacingEditorUIComponent.c
Generated by
1.17.0