Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_TransformingEditorUIComponent.c
Go to the documentation of this file.
1 
3 class SCR_TransformingEditorUIComponent : SCR_PreviewEntityEditorUIComponent
4 {
5  protected InputManager m_InputManager;
6  protected SCR_TransformingEditorComponent m_TransformingManager;
7  protected SCR_StatesEditorComponent m_StatesManager;
8  protected SCR_CursorEditorUIComponent m_CursorComponent;
9  //protected SCR_HoverEditableEntityFilter m_HoverFilter;
10  protected SCR_BaseEditableEntityFilter m_SelectedFilter;
11  protected SCR_BaseEditableEntityFilter m_FocusedFilter;
12  protected SCR_EditableEntityComponent m_HoverEntity;
13  protected SCR_EditableEntityComponent m_ActiveHoverEntity;
14  protected SCR_LayersEditorComponent m_LayersManager;
15  protected SCR_EntitiesToolbarEditorUIComponent m_EntityToolbar;
16  protected vector m_vClickTransform[4];
17  protected bool m_bClicked;
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.TRANSFORMING)
23  super.OnHoverChange(state, entitiesInsert, entitiesRemove);
24  }
25 
26  //------------------------------------------------------------------------------------------------
27  override void OnEditorTransformRotationModifierUp(float value, EActionTrigger reason)
28  {
29  if (m_StatesManager && m_StatesManager.GetState() == EEditorState.TRANSFORMING)
30  super.OnEditorTransformRotationModifierUp(value, reason);
31  }
32 
33  //------------------------------------------------------------------------------------------------
34  protected void OnEditorTransformToggleDown(float value, EActionTrigger reason)
35  {
36  if (m_TransformingManager.IsEditing())
37  ConfirmEditing();
38  else
39  OnEditorTransformDown(value, reason);
40  }
41 
42  //------------------------------------------------------------------------------------------------
43  protected void OnEditorTransformDown(float value, EActionTrigger reason)
44  {
45  if (!m_InputManager || !m_SelectedFilter || !m_TransformingManager || !m_CursorComponent)
46  return;
47 
48  //--- Can't rotate from the entity toolbar
49  if (m_EntityToolbar && m_EntityToolbar.IsUnderCursor() && m_InputManager.GetActionTriggered("EditorTransformRotateYawModifier"))
50  return;
51 
52  //--- Ignore when not hovering over an entity
53  bool isDelegate;
54  SCR_EditableEntityComponent hoverEntity = m_HoverFilter.GetEntityUnderCursor(isDelegate);
55  if (!hoverEntity)
56  return;
57 
58  m_HoverEntity = hoverEntity;
59  m_HoverEntity.GetOwner().GetWorldTransform(m_vClickTransform);
60 
61  //--- Hovered entity not selected - replace the selection
62  if (m_LayersManager)
63  m_ActiveHoverEntity = m_LayersManager.GetParentBelowCurrentLayer(m_HoverEntity);
64  else
65  m_ActiveHoverEntity = m_HoverEntity;
66 
67  vector worldPos;
68  if (isDelegate)
69  {
70  //--- Clicked on icon - use entity's position as a pivot
71  if (!m_HoverEntity.GetPos(worldPos))
72  return;
73  }
74  else
75  {
76  //--- Use cursor world position as a pivot
77  if (!m_CursorComponent.GetCursorWorldPos(worldPos))
78  return;
79  }
80 
81  m_vClickTransform[3] = worldPos;
82  m_bClicked = true;
83 
84  if (m_InputManager.IsUsingMouseAndKeyboard())
85  SetClickPos(m_CursorComponent.GetCursorPos()); //--- Don't start editing just yet, do so only after cursor moves a bit
86  else
87  StartEditing();
88  }
89 
90  //------------------------------------------------------------------------------------------------
91  protected void OnEditorCancelTransformingUp(float value, EActionTrigger reason)
92  {
93  if (OnCancelUp())
94  CancelEditing();
95  }
96 
97  //------------------------------------------------------------------------------------------------
98  protected void StartEditing()
99  {
100  if (m_StatesManager && !m_StatesManager.CanSet(EEditorState.TRANSFORMING) || m_StatesManager.GetState() == EEditorState.TRANSFORMING)
101  return;
102 
103  //--- Transforming unselected entity - replace the selection upon click
104  if (!m_SelectedFilter.Contains(m_ActiveHoverEntity))
105  m_SelectedFilter.Replace(m_ActiveHoverEntity);
106 
107  //--- Get selected entities
108  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
109  m_SelectedFilter.GetEntities(entities);
110 
111  //--- Start editing process
112  m_TransformingManager.StartEditing(m_HoverEntity, entities, m_vClickTransform);
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  protected void ConfirmEditing()
117  {
118  if (!m_TransformingManager.IsEditing() && !m_bClicked)
119  return;
120 
121  //--- Cannot move attachable entity when target is not set
122  if (!m_PreviewEntityManager.CanMoveInRoot() && !m_PreviewEntityManager.GetTarget())
123  {
124  if (m_InputManager.IsUsingMouseAndKeyboard())
125  CancelEditing();
126 
127  return;
128  }
129 
130  Clean();
131 
132  if (!m_StatesManager || m_StatesManager.GetState() != EEditorState.TRANSFORMING)
133  return;
134 
135  if (!m_TransformingManager.ConfirmEditing())
136  {
137  if (m_InputManager.IsUsingMouseAndKeyboard()) //--- ToDo: Audio feedback
138  m_TransformingManager.CancelEditing();
139  }
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  protected void CancelEditing()
144  {
145  if (!m_bClicked && !m_TransformingManager.IsEditing())
146  return;
147 
148  if (m_TransformingManager)
149  m_TransformingManager.CancelEditing();
150 
151  Clean();
152  }
153 
154  //------------------------------------------------------------------------------------------------
155  protected void Clean()
156  {
157  m_bClicked = false;
158  m_InputManager.ResetAction("EditorTransform");
159  m_HoverEntity = null;
160  m_ActiveHoverEntity = null;
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  protected void OnTransformationEnd()
165  {
166  Clean();
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  protected void OnInputDeviceIsGamepad(bool isGamepad)
171  {
172  CancelEditing();
173  }
174 
176  //--- Update
178 
179  //------------------------------------------------------------------------------------------------
180  protected void OnMenuUpdate(float tDelta)
181  {
183 
185  return;
186 
187  if (SCR_MapEntity.GetMapInstance() && SCR_MapEntity.GetMapInstance().IsOpen()) // map shown
188  return;
189 
190  m_InputManager.ActivateContext("EditorTransformingContext");
191 
192  //--- Allow interaction only when cursor moves far enough from clicked position
193  if (m_InputManager.IsUsingMouseAndKeyboard())
194  {
195  if (m_bClicked && HasMouseMoved())
196  StartEditing();
197  else
198  return;
199  }
200 
201  //--- Exit when not transforming
202  if (m_StatesManager.GetState() != EEditorState.TRANSFORMING)
203  return;
204 
205  ProcessInput(tDelta);
206  }
207 
209  //--- Default methods
211 
212  //------------------------------------------------------------------------------------------------
213  override void HandlerAttachedScripted(Widget w)
214  {
215  super.HandlerAttachedScripted(w);
216 
217  MenuRootComponent root = GetRootComponent();
218  if (root)
220 
221  if (!m_CursorComponent)
222  return;
223 
225  if (!m_TransformingManager)
226  return;
227 
228  m_TransformingManager.GetOnTransformationConfirm().Insert(OnTransformationEnd);
229  m_TransformingManager.GetOnTransformationCancel().Insert(OnTransformationEnd);
230 
232  if (!m_StatesManager)
233  return;
234 
236  if (entitiesManager)
237  {
238  //m_HoverFilter = SCR_HoverEditableEntityFilter.Cast(entitiesManager.GetFilter(EEditableEntityState.HOVER));
239  m_SelectedFilter = entitiesManager.GetFilter(EEditableEntityState.SELECTED);
240  m_FocusedFilter = entitiesManager.GetFilter(EEditableEntityState.FOCUSED);
241  }
242 
243  m_EntityToolbar = SCR_EntitiesToolbarEditorUIComponent.Cast(root.FindComponent(SCR_EntitiesToolbarEditorUIComponent));
244 
246 
247  MenuRootBase menu = GetMenu();
248  if (menu)
249  {
250  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
251  menu.GetOnMenuFocusGained().Insert(Clean); //--- Reset dragging if a dialog was opened and closed during that
252  }
253 
254  ArmaReforgerScripted game = GetGame();
255  if (game)
256  {
257  m_InputManager = game.GetInputManager();
258  if (m_InputManager)
259  {
260  m_InputManager.ResetAction("EditorTransform");
261  m_InputManager.AddActionListener("EditorTransform", EActionTrigger.DOWN, OnEditorTransformDown);
262  m_InputManager.AddActionListener("EditorTransform", EActionTrigger.UP, ConfirmEditing);
263 
264  m_InputManager.AddActionListener("EditorTransformToggle", EActionTrigger.DOWN, OnEditorTransformToggleDown);
265 
266  //m_InputManager.AddActionListener("EditorTransformRotationModifier", EActionTrigger.DOWN, OnEditorTransformRotationModifierDown);
267 
268  m_InputManager.AddActionListener("EditorConfirmTransforming", EActionTrigger.DOWN, ConfirmEditing);
269  m_InputManager.AddActionListener("EditorCancelTransforming", EActionTrigger.DOWN, OnCancelDown);
270  m_InputManager.AddActionListener("EditorCancelTransforming", EActionTrigger.UP, OnEditorCancelTransformingUp);
271  }
272 
273  game.OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
274  }
275 
276  SCR_MapEntity.GetOnMapOpen().Insert(OnMapOpen);
277  }
278 
279  //------------------------------------------------------------------------------------------------
281  void OnMapOpen(MapConfiguration config)
282  {
283  CancelEditing();
284  }
285 
286  //------------------------------------------------------------------------------------------------
287  override void HandlerDeattached(Widget w)
288  {
289  super.HandlerDeattached(w);
290 
291  if (m_TransformingManager)
292  {
293  m_TransformingManager.GetOnTransformationConfirm().Remove(OnTransformationEnd);
294  m_TransformingManager.GetOnTransformationCancel().Remove(OnTransformationEnd);
295  }
296 
297  MenuRootBase menu = GetMenu();
298  if (menu)
299  {
300  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
301  menu.GetOnMenuFocusGained().Remove(Clean);
302  }
303 
304  ArmaReforgerScripted game = GetGame();
305  if (game)
306  {
307  if (m_InputManager)
308  {
309  m_InputManager.RemoveActionListener("EditorTransform", EActionTrigger.DOWN, OnEditorTransformDown);
310  m_InputManager.RemoveActionListener("EditorTransform", EActionTrigger.UP, ConfirmEditing);
311 
312  m_InputManager.RemoveActionListener("EditorTransformToggle", EActionTrigger.DOWN, OnEditorTransformToggleDown);
313 
314  //m_InputManager.RemoveActionListener("EditorTransformRotationModifier", EActionTrigger.DOWN, OnEditorTransformRotationModifierDown);
315 
316  m_InputManager.RemoveActionListener("EditorConfirmTransforming", EActionTrigger.DOWN, ConfirmEditing);
317  m_InputManager.RemoveActionListener("EditorCancelTransforming", EActionTrigger.DOWN, OnCancelDown);
318  m_InputManager.RemoveActionListener("EditorCancelTransforming", EActionTrigger.UP, OnEditorCancelTransformingUp);
319  }
320 
321  game.OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
322  }
323 
324  SCR_MapEntity.GetOnMapOpen().Remove(OnMapOpen);
325  }
326 
327  //------------------------------------------------------------------------------------------------
329  override protected SCR_EPreviewState GetPreviewStateToShow()
330  {
331  if (m_TransformingManager.CanBeTransformed())
332  return SCR_EPreviewState.PLACEABLE;
333  else
334  return SCR_EPreviewState.BLOCKED;
335  }
336 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_CursorEditorUIComponent
Definition: SCR_CursorEditorUIComponent.c:3
SetClickPos
protected void SetClickPos(vector clickPos)
Definition: SCR_PreviewEntityEditorUIComponent.c:207
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
m_StatesManager
private SCR_StatesEditorComponent m_StatesManager
Definition: SCR_AttributesManagerEditorComponent.c:65
EEditorState
EEditorState
Unique editor state.
Definition: EEditorState.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
ProcessInput
protected void ProcessInput(float tDelta)
Definition: SCR_PreviewEntityEditorUIComponent.c:677
SCR_EPreviewState
SCR_EPreviewState
Definition: SCR_PreviewEntityEditorComponent.c:1138
SCR_TransformingEditorComponent
Definition: SCR_TransformingEditorComponent.c:33
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
m_PreviewEntityManager
protected SCR_PreviewEntityEditorComponent m_PreviewEntityManager
Definition: SCR_PreviewEntityEditorUIComponent.c:41
MenuRootBase
Definition: MenuRootBase.c:6
m_LayersManager
protected SCR_LayersEditorComponent m_LayersManager
Definition: SCR_EntitiesToolbarEditorUIComponent.c:38
m_HoverFilter
protected SCR_HoverEditableEntityFilter m_HoverFilter
Definition: SCR_PreviewEntityEditorUIComponent.c:45
HasMouseMoved
protected bool HasMouseMoved()
Definition: SCR_PreviewEntityEditorUIComponent.c:226
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
m_HoverEntity
protected SCR_EditableEntityComponent m_HoverEntity
Definition: SCR_EntitiesToolbarEditorUIComponent.c:35
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
MenuRootComponent
Definition: MenuRootComponent.c:6
SCR_EntitiesToolbarEditorUIComponent
Definition: SCR_EntitiesToolbarEditorUIComponent.c:4
m_CursorComponent
protected SCR_CursorEditorUIComponent m_CursorComponent
Definition: SCR_EntitiesEditorUIComponent.c:16
ActivatePreviewContext
protected void ActivatePreviewContext()
Definition: SCR_PreviewEntityEditorUIComponent.c:756
SCR_StatesEditorComponent
Definition: SCR_StatesEditorComponent.c:9
SCR_TransformingEditorUIComponent
Definition: SCR_TransformingEditorUIComponent.c:3