6 protected static const float MAX_PREVIEW_DIS = 50;
8 private InputManager m_InputManager;
15 private bool m_bClicked;
16 private bool m_bCanPlace;
17 private ref array<Widget> m_aClickWhitelist = {};
20 override void OnHoverChange(
EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
23 super.OnHoverChange(state, entitiesInsert, entitiesRemove);
27 override void OnEditorTransformRotationModifierUp(
float value, EActionTrigger reason)
30 super.OnEditorTransformRotationModifierUp(value, reason);
34 protected void OnEditorPlace(
float value, EActionTrigger reason)
40 protected void OnEditorPlaceAndCancel(
float value, EActionTrigger reason)
46 protected void OnEditorPlacePlayer(
float value, EActionTrigger reason)
52 protected void OnEditorPlacePlayerAndCancel(
float value, EActionTrigger reason)
57 if (m_SelectionComponent)
58 m_SelectionComponent.DisableMultiSelection();
62 protected void Place(
bool cancelAfterwards,
bool canBePlayer =
false)
73 if (mapEntity && mapEntity.IsOpen())
84 protected void OnEditorCancelPlacingUp(
float value, EActionTrigger reason)
91 protected void CancelPlacing()
98 protected void EnablePlacing()
104 protected bool CanClick()
111 Widget rootWidget = root.GetWidget();
117 array<Widget> widgets = {};
118 WidgetManager.TraceWidgets(mouseX, mouseY, rootWidget, widgets);
121 foreach (Widget widget: widgets)
123 bool canClick =
false;
124 foreach (Widget widgetWhitelisted: m_aClickWhitelist)
126 canClick |= IsChildOf(widget, widgetWhitelisted);
139 protected bool IsChildOf(Widget widget, Widget parent)
143 if (widget == parent)
146 widget = widget.GetParent();
152 protected void OnSelectedPrefabChange(ResourceName prefab, ResourceName prefabPrev)
154 ArmaReforgerScripted game =
GetGame();
158 ScriptCallQueue queue = game.GetCallqueue();
163 queue.CallLater(EnablePlacing, 50);
170 BaseWorld world = game.GetWorld();
174 WorkspaceWidget workspace = game.GetWorkspace();
179 float screenW, screenH;
180 workspace.GetScreenSize(screenW, screenH);
182 vector cameraPos = workspace.ProjScreenToWorldNative(screenW * 0.5, screenH * 0.5, cameraDir, world, -1);
185 float traceDis =
GetTraceDis(cameraPos, cameraDir * TRACE_DIS, cameraPos[1]);
187 traceDis = MAX_PREVIEW_DIS;
189 traceDis *= TRACE_DIS;
192 previewManager.SetPreviewHeight(cameraPos + cameraDir * traceDis);
197 protected void OnMenuUpdate(
float tDelta)
215 protected void OnMenuFocusGained()
217 GetMenu().GetOnMenuUpdate().Insert(OnMenuUpdate);
221 protected void OnMenuFocusLost()
223 GetMenu().GetOnMenuUpdate().Remove(OnMenuUpdate);
236 override void HandlerAttachedScripted(Widget w)
238 super.HandlerAttachedScripted(w);
251 if (m_EntitiesComponent)
252 m_aClickWhitelist.Insert(m_EntitiesComponent.GetWidget());
256 Print(
"SCR_PlacingEditorUIComponent requires SCR_CursorEditorUIComponent!", LogLevel.ERROR);
258 m_PlacingManager.GetOnSelectedPrefabChange().Insert(OnSelectedPrefabChange);
265 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
266 menu.GetOnMenuFocusGained().Insert(OnMenuFocusGained);
267 menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
270 ArmaReforgerScripted game =
GetGame();
276 m_InputManager.AddActionListener(
"EditorPlace", EActionTrigger.DOWN, OnEditorPlace);
277 m_InputManager.AddActionListener(
"EditorPlaceAndCancel", EActionTrigger.DOWN, OnEditorPlaceAndCancel);
278 m_InputManager.AddActionListener(
"EditorPlacePlayer", EActionTrigger.DOWN, OnEditorPlacePlayer);
279 m_InputManager.AddActionListener(
"EditorPlacePlayerAndCancel", EActionTrigger.DOWN, OnEditorPlacePlayerAndCancel);
280 m_InputManager.AddActionListener(
"EditorCancelPlacing", EActionTrigger.DOWN, OnCancelDown);
281 m_InputManager.AddActionListener(
"EditorCancelPlacing", EActionTrigger.UP, OnEditorCancelPlacingUp);
287 override void HandlerDeattached(Widget w)
289 super.HandlerDeattached(w);
292 m_PlacingManager.GetOnSelectedPrefabChange().Remove(OnSelectedPrefabChange);
297 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
298 menu.GetOnMenuFocusGained().Remove(OnMenuFocusGained);
299 menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
302 ArmaReforgerScripted game =
GetGame();
305 InputManager inputManager = game.GetInputManager();
308 inputManager.RemoveActionListener(
"EditorPlace", EActionTrigger.DOWN, OnEditorPlace);
309 inputManager.RemoveActionListener(
"EditorPlaceAndCancel", EActionTrigger.DOWN, OnEditorPlaceAndCancel);
310 inputManager.RemoveActionListener(
"EditorPlacePlayer", EActionTrigger.DOWN, OnEditorPlacePlayer);
311 inputManager.RemoveActionListener(
"EditorPlacePlayerAndCancel", EActionTrigger.DOWN, OnEditorPlacePlayerAndCancel);
312 m_InputManager.RemoveActionListener(
"EditorCancelPlacing", EActionTrigger.DOWN, OnCancelDown);
313 m_InputManager.RemoveActionListener(
"EditorCancelPlacing", EActionTrigger.UP, OnEditorCancelPlacingUp);