Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditorPingInfoDisplay.c
Go to the documentation of this file.
1 
9 class SCR_EditorPingInfoDisplay : SCR_InfoDisplay
10 {
11  [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
12  protected ResourceName m_WidgetPrefab;
13 
14  [Attribute(uiwidget: UIWidgets.ResourceNamePicker, params: "layout")]
15  protected ResourceName m_SlotWidgetPrefab;
16 
17  protected bool m_bCanUpdate;
18  protected WorkspaceWidget m_Workspace;
19  protected SCR_PingEditorComponent m_PingManager;
20  protected ref map<SCR_EditableEntityComponent, SCR_EditableEntitySceneSlotUIComponent> m_EntitySlots = new map<SCR_EditableEntityComponent, SCR_EditableEntitySceneSlotUIComponent>;
21  protected ref map<SCR_EditableEntityComponent, Widget> m_EntityWidgets = new map<SCR_EditableEntityComponent, Widget>;
22 
23  protected void OnEditorPingAction(float value, EActionTrigger reason)
24  {
25  SendPing(false);
26  }
27  protected void OnEditorPingUnlimitedOnlyAction(float value, EActionTrigger reason)
28  {
29  SendPing(true);
30  }
31  protected void SendPing(bool unlimitedOnly)
32  {
33  if (SCR_EditorManagerEntity.IsOpenedInstance()) return;
34 
35  vector position;
37 
38  if (!target || !target.GetPos(position))
39  {
40  //--- Position under cursor
41  WorkspaceWidget workspace = GetGame().GetWorkspace();
42  if (!workspace) return;
43 
44  //--- Not reliable, cursor is not hidden in center of the screen on client
45  //int mouseX, mouseY;
46  //WidgetManager.GetMousePos(mouseX, mouseY);
47 
48  int screenW = workspace.GetWidth();
49  int screenH = workspace.GetHeight();
50 
51  BaseWorld world = GetGame().GetWorld();
52  vector outDir;
53  vector startPos = workspace.ProjScreenToWorld(workspace.DPIUnscale(screenW / 2), workspace.DPIUnscale(screenH / 2), outDir, world);
54  outDir *= 1000; //--- ToDo: Don't hardcode
55 
56  autoptr TraceParam trace = new TraceParam();
57  trace.Start = startPos;
58  trace.End = startPos + outDir;
59  trace.Flags = TraceFlags.WORLD | TraceFlags.OCEAN | TraceFlags.ENTS;
60  trace.LayerMask = TRACE_LAYER_CAMERA;
61  float traceDis = world.TraceMove(trace, null);
62 
63  target = SCR_EditableEntityComponent.GetEditableEntity(trace.TraceEnt);
64  if (!target && traceDis == 1) return; //--- No intersection
65 
66  position = startPos + outDir * traceDis;
67  }
68 
69  m_PingManager.SendPing(unlimitedOnly, position, target);
70  }
71  protected void OnPingEntityRegister(int reporterID, SCR_EditableEntityComponent pingEntity)
72  {
73  //--- When outside of the editor, don't create a ping on player
74  if (pingEntity.GetOwner() == SCR_PlayerController.GetLocalControlledEntity()) return;
75 
77  if (!m_EntitySlots.Find(pingEntity, slot))
78  {
79  Widget slotWidget = m_Workspace.CreateWidgets(m_SlotWidgetPrefab, m_wRoot);
80  if (!slotWidget) return;
81 
83  if (!slot) return;
84 
85  slot.InitSlot(pingEntity);
86  m_EntitySlots.Insert(pingEntity, slot);
87  }
88 
89  //--- Create ping widget in a slot
90  slot.DeleteWidget(null);
91  Widget entityWidget = slot.CreateWidget(pingEntity, m_WidgetPrefab);
92  m_EntityWidgets.Insert(pingEntity, entityWidget);
93  m_bCanUpdate = true;
94  }
95  protected void OnPingEntityUnregister(int reporterID, SCR_EditableEntityComponent pingEntity)
96  {
97  Widget entityWidget;
98  if (m_EntityWidgets.Find(pingEntity, entityWidget))
99  {
100  m_EntityWidgets.Remove(pingEntity);
101  }
102 
104  if (m_EntitySlots.Find(pingEntity, slot))
105  {
106  if (slot)
107  {
108  slot.DeleteWidget(null);
109  slot.DeleteSlot();
110  }
111 
112  if (!slot || slot.IsEmpty())
113  {
114  m_EntitySlots.Remove(pingEntity);
115  m_bCanUpdate = !m_EntitySlots.IsEmpty();
116  }
117  }
118  }
119 
120  override event void UpdateValues(IEntity owner, float timeSlice)
121  {
122  if (!m_bCanUpdate || !m_Workspace) return;
123 
124  int screenW = m_Workspace.GetWidth();
125  int screenH = m_Workspace.GetHeight();
126 
127  screenW = m_Workspace.DPIUnscale(screenW);
128  screenH = m_Workspace.DPIUnscale(screenH);
129  vector posCenter = Vector(screenW / 2, screenH / 2, 0);
130 
131  vector transformCam[4];
132  GetGame().GetWorld().GetCurrentCamera(transformCam);
133  vector posCam = transformCam[3];
134 
135  foreach (SCR_EditableEntitySceneSlotUIComponent entitySlot: m_EntitySlots)
136  {
137  entitySlot.UpdateSlot(screenW, screenH, posCenter, posCam);
138  }
139  }
140  override event void OnStartDraw(IEntity owner)
141  {
142  super.OnStartDraw(owner);
143 
144  if (!SCR_EditorManagerEntity.GetInstance())
145  {
146  //--- HUD initialized before the editor - wait
148  if (editorManagerCore) editorManagerCore.Event_OnEditorManagerInitOwner.Insert(OnStartDraw);
149  return;
150  }
151  else
152  {
154  if (editorManagerCore) editorManagerCore.Event_OnEditorManagerInitOwner.Remove(OnStartDraw);
155  }
156 
157  m_PingManager = SCR_PingEditorComponent.Cast(SCR_PingEditorComponent.GetInstance(SCR_PingEditorComponent, true));
158  if (!m_PingManager) return;
159 
160  m_PingManager.GetOnPingEntityRegister().Insert(OnPingEntityRegister);
161  m_PingManager.GetOnPingEntityUnregister().Insert(OnPingEntityUnregister);
162 
163  m_Workspace = m_wRoot.GetWorkspace();
164 
165  InputManager inputManager = GetGame().GetInputManager();
166  if (inputManager)
167  {
168  inputManager.AddActionListener("EditorPing", EActionTrigger.DOWN, OnEditorPingAction);
169  inputManager.AddActionListener("EditorPingUnlimitedOnly", EActionTrigger.DOWN, OnEditorPingUnlimitedOnlyAction);
170  }
171  }
172  override event void OnStopDraw(IEntity owner)
173  {
174  super.OnStopDraw(owner);
175 
176  //--- Clear existing ping widgets
177  for (int i = 0, count = m_EntitySlots.Count(); i < count; i++)
178  {
179  OnPingEntityUnregister(0, m_EntitySlots.GetKey(0));
180  }
181 
182  if (m_PingManager)
183  {
184  m_PingManager.GetOnPingEntityRegister().Remove(OnPingEntityRegister);
185  m_PingManager.GetOnPingEntityUnregister().Remove(OnPingEntityUnregister);
186  }
187 
188  InputManager inputManager = GetGame().GetInputManager();
189  if (inputManager)
190  {
191  inputManager.RemoveActionListener("EditorPing", EActionTrigger.DOWN, OnEditorPingAction);
192  inputManager.RemoveActionListener("EditorPingUnlimitedOnly", EActionTrigger.DOWN, OnEditorPingUnlimitedOnlyAction);
193  }
194  }
195 };
SCR_PlayerController
Definition: SCR_PlayerController.c:31
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EditorPingInfoDisplay
Definition: SCR_EditorPingInfoDisplay.c:9
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditorManagerCore
Core component to manage SCR_EditorManagerEntity.
Definition: SCR_EditorManagerCore.c:5
SCR_PingEditorComponent
Definition: SCR_PingEditorComponent.c:70
SCR_EditableEntitySceneSlotUIComponent
Definition: SCR_EditableEntitySceneSlotUIComponent.c:1
TRACE_LAYER_CAMERA
const int TRACE_LAYER_CAMERA
Definition: Constants.c:14
m_Workspace
protected WorkspaceWidget m_Workspace
Definition: SCR_EntitiesEditorUIComponent.c:13
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
position
vector position
Definition: SCR_DestructibleTreeV2.c:30
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26