Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlacingEditorUIComponent.c
Go to the documentation of this file.
1
2
3class 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 //------------------------------------------------------------------------------------------------
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
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())
95 }
96
97 //------------------------------------------------------------------------------------------------
98 protected void CancelPlacing()
99 {
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
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 {
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 //------------------------------------------------------------------------------------------------
235 {
236 if (m_PlacingManager && m_PlacingManager.CanCreateEntity())
237 return SCR_EPreviewState.PLACEABLE;
238 else
239 return SCR_EPreviewState.BLOCKED;
240 }
241
242 //------------------------------------------------------------------------------------------------
244 {
245 super.HandlerAttachedScripted(w);
246
247 MenuRootComponent root = GetRootComponent();
248 if (root)
249 {
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
268
269 MenuRootBase menu = GetMenu();
270 if (menu)
271 {
272 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
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
299 m_PlacingManager.GetOnSelectedPrefabChange().Remove(OnSelectedPrefabChange);
300
301 MenuRootBase menu = GetMenu();
302 if (menu)
303 {
304 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
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}
ref DSGameConfig game
Definition DSConfig.c:81
EEditorPlacingFlags
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_PreviewEntityEditorComponent m_PreviewEntityManager
SCR_PlacingEditorComponent m_PlacingManager
void OnHoverChange(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
float GetTraceDis(vector pos, vector dir, float cameraHeight)
void ProcessInput(float tDelta)
SCR_RadialMenu GetMenu()
Input management system for user interactions.
ScriptInvoker GetOnMenuFocusGained()
ScriptInvoker GetOnMenuUpdate()
ScriptInvoker GetOnMenuFocusLost()
MenuRootSubComponent FindComponent(typename type, bool showError=false)
bool IsOpen()
Check if the map is opened.
static SCR_MapEntity GetMapInstance()
Get map entity instance.
void OnEditorPlacePlayer(float value, EActionTrigger reason)
override void HandlerAttachedScripted(Widget w)
void Place(bool cancelAfterwards, bool canBePlayer=false)
void OnEditorCancelPlacingUp(float value, EActionTrigger reason)
void OnEditorPlaceAndCancel(float value, EActionTrigger reason)
void OnSelectedPrefabChange(ResourceName prefab, ResourceName prefabPrev)
void OnEditorPlace(float value, EActionTrigger reason)
void OnEditorPlacePlayerAndCancel(float value, EActionTrigger reason)
bool IsChildOf(Widget widget, Widget parent)
ScriptCallQueue Class provide "lazy" calls - when we don't want to execute function immediately but l...
Definition tools.c:53
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EEditableEntityState
EEditorTransformVertical
Vertical transformation mode.
EEditorState
Unique editor state.
Definition EEditorState.c:6
EActionTrigger