5 protected const float TRACE_DIS_SINGLE = 10000;
6 protected const float TRACE_DIS_REPEATED = 250;
12 private ref array<ref SCR_CursorEditor> m_Cursors;
14 private ref map<EEditorCursor, ref SCR_CursorEditor> m_CursorsMap =
new map<EEditorCursor, ref SCR_CursorEditor>();
15 private SCR_CursorEditor m_CurrentCursor;
16 private vector m_vGamepadCursorSize;
17 private float m_fGamepadCursorRadius;
18 private float m_fGamepadCursorRadiusSq;
19 private InputManager m_InputManager;
20 private WorkspaceWidget m_wWorkspace;
28 private IEntity m_TraceEntity;
30 private vector m_vCursorPos;
31 private vector m_vCursorPosWorld;
32 private vector m_vCursorPosWorldNormalized;
33 private int m_iCursorPosX;
34 private int m_iCursorPosY;
35 private bool m_bCanFocus =
true;
36 private int m_iFrameIndex;
37 private int m_iFrameUpdate;
38 private int m_iFrameUpdateWorld;
39 private float m_fTargetAlpha = 1;
40 private float m_fTargetAlphaStrength;
42 protected TraceFlags m_DefaultWorldTraceFlags = TraceFlags.WORLD | TraceFlags.OCEAN | TraceFlags.ENTS;
48 void SetCursorPos(vector pos,
bool DPIScale =
false)
53 ArmaReforgerScripted game =
GetGame();
57 WorkspaceWidget workspace = game.GetWorkspace();
61 float mouseX = pos[0];
62 float mouseY = pos[1];
65 mouseX = workspace.DPIScale(mouseX);
66 mouseY = workspace.DPIScale(mouseY);
96 float cursorX, cursorY;
113 void GetCursorPos(out
int posX, out
int posY)
125 bool GetCursorWorldPos(out vector worldPos,
bool isNormalized =
false, TraceFlags flags = -1)
128 if (m_iFrameUpdateWorld == m_iFrameIndex && flags == m_DefaultWorldTraceFlags)
139 ArmaReforgerScripted game =
GetGame();
143 WorkspaceWidget workspace = game.GetWorkspace();
147 BaseWorld world = game.GetWorld();
153 if (mapEntity && mapEntity.IsOpen())
155 float worldX, worldY;
156 mapEntity.GetMapCursorWorldPosition(worldX, worldY);
157 worldPos[0] = worldX;
158 worldPos[2] = worldY;
159 worldPos[1] = world.GetSurfaceY(worldPos[0], worldPos[2]);
166 vector cursorPos = GetCursorPos();
168 vector startPos = workspace.ProjScreenToWorld(cursorPos[0], cursorPos[1], outDir, world, -1);
176 if (startPos[1] < world.GetOceanBaseHeight())
177 flags = flags & ~TraceFlags.OCEAN;
179 TraceParam trace =
new TraceParam();
180 trace.Start = startPos;
181 trace.End = startPos + outDir;
184 float traceDis = world.TraceMove(trace,
null);
196 worldPos = startPos + outDir * traceDis;
197 if (flags == m_DefaultWorldTraceFlags)
208 IEntity GetTraceEntity()
216 SCR_CursorEditor cursor;
219 Print(
string.Format(
"Configuration for cursor %1 not found!",
typename.EnumToString(
EEditorCursor,
type)), LogLevel.WARNING);
224 WidgetManager.SetCursor(cursor.GetID());
234 if (cursor.GetWidget())
235 cursor.GetWidget().SetOpacity(opacity);
241 protected void ResetCursor()
248 float GetCursorRadius()
255 float GetCursorRadiusSq()
263 void SetCursorAlpha(
float alpha,
float strength = 1)
270 protected void UpdateCursorDebug()
277 protected void UpdateCursor()
375 void OnFilterChange(
EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
381 protected bool TraceFilter(Class target)
391 vector camPos =
m_wWorkspace.ProjScreenToWorld(cursorPos[0], cursorPos[1], outDir,
GetGame().GetWorld(), -1);
394 TraceParam trace =
new TraceParam();
395 trace.Start = camPos;
397 trace.Flags = TraceFlags.ENTS | TraceFlags.WORLD | TraceFlags.OCEAN;
398 float coefTrace =
GetGame().GetWorld().TraceMove(trace,
null);
403 if (!trace.TraceEnt || trace.TraceEnt.Type() == GenericTerrainEntity || !
m_MouseArea.IsMouseOn())
408 while (genericEntity)
414 genericEntity =
GenericEntity.Cast(genericEntity.GetParent());
421 protected void OnInputDeviceIsGamepad(
bool isGamepad)
428 protected void OnMenuUpdate(
float tDelta)
442 if (!m_CurrentCursor)
446 if (!currentCursorWidget)
449 float currentAlpha = currentCursorWidget.GetOpacity();
450 if (currentAlpha != m_fTargetAlpha)
451 currentCursorWidget.SetOpacity(Math.Lerp(currentAlpha, m_fTargetAlpha, m_fTargetAlphaStrength * tDelta));
456 void OnMapToggled(MapConfiguration config)
462 override void HandlerAttachedScripted(Widget w)
464 super.HandlerAttachedScripted(w);
483 GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
500 if (m_PreviewManager)
519 if (m_CommandManager)
525 foreach (SCR_CursorEditor cursor: m_Cursors)
527 cursor.InitWidget(w);
532 SCR_CursorEditor defaultCursor;
536 if (defaultCursor.GetWidget())
538 vector alignment = FrameSlot.GetAlignment(defaultCursor.GetWidget());
548 Print(
"Default cursor settings not found!", LogLevel.ERROR);
552 menu.GetOnMenuFocusLost().Insert(UpdateCursor);
553 menu.GetOnMenuHide().Insert(UpdateCursor);
554 menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
558 override void HandlerDeattached(Widget w)
560 super.HandlerDeattached(w);
573 GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
599 if (transformingManager)
600 transformingManager.GetOnTransformationStart().Remove(UpdateCursor);
602 if (m_CommandManager)
608 menu.GetOnMenuFocusLost().Remove(UpdateCursor);
609 menu.GetOnMenuHide().Remove(UpdateCursor);
610 menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
616 class SCR_CursorEditor
624 private Widget m_wWidget;
657 void InitWidget(Widget root)
662 m_wWidget = root.FindAnyWidget(
m_sName);
664 m_wWidget.SetOpacity(0);
666 Print(
string.Format(
"Gamepad cursor '%1' for type %2 not found!",
m_sName,
m_Type), LogLevel.ERROR);