Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SelectionEditorUIComponent.c
Go to the documentation of this file.
1 
4 {
5  protected static const float FRAME_SIZE_MIN = 10;
6  protected static const float FRAME_DURATION_MIN = 0.15;
7 
9  [Attribute(desc: "State in which entities are unselected.", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditableEntityState))]
10  protected EEditableEntityState m_UnselectedState;
11 
12  [Attribute(desc: "Only entities of this state can be multi-selected, e.g., using selection frame or by pressing Ctrl+A.", uiwidget: UIWidgets.Flags, enums: ParamEnumArray.FromEnum(EEditableEntityState))]
13  protected EEditableEntityState m_MultiSelectStates;
14 
15  [Attribute(desc: "When true, multi-selection operations are disabled (e.g., selection frame or Ctrl+A).", defvalue: "1")]
16  protected bool m_bEnableMultiSelection;
17 
18  [Attribute(desc: "Name of a widget representing setting selection with mouse & keyboard.")]
19  protected string m_sSetSelectionWidgetName;
20 
21  [Attribute(desc: "Name of a widget representing toggling selection with mouse & keyboard.")]
22  protected string m_sToggleSelectionWidgetName;
23 
24  [Attribute(desc: "Name of a widget representing setting selection with gamepad.")]
25  protected string m_sGamepadSetSelectionWidgetName;
26 
27  [Attribute(desc: "Name of a widget representing toggling selection with gamepad.")]
28  protected string m_sGamepadToggleSelectionWidgetName;
29 
30  [Attribute("1", desc: "Initial size of multi-selection widget, measured as a coefficient of default cursor widget size (1 = same size).")]
31  protected float m_fGamepadSelectionWidgetStartSize;
32 
33  [Attribute(defvalue: "0.5")]
34  protected float m_fGamepadSelectionDuration;
35 
36  [Attribute(desc: "Curve defining how will gamepad selection widget expand.", defvalue: "0 0 1 1", uiwidget: UIWidgets.GraphDialog, params: "1 1 0 0")]
37  protected ref Curve m_GamepadSelectionCurve;
38 
39  [Attribute(SCR_SoundEvent.SOUND_E_MULTI_SELECT_START_KEYBOARD, UIWidgets.EditBox)]
40  protected string m_sSfxStartDrawingSelectionFrame_Keyboard;
41 
42  [Attribute(SCR_SoundEvent.SOUND_E_MULTI_SELECT_START_GAMEPAD, UIWidgets.EditBox)]
43  protected string m_sSfxStartDrawingSelectionFrame_Gamepad;
44 
45  [Attribute(SCR_SoundEvent.SOUND_E_TRAN_CANCEL, UIWidgets.EditBox)]
46  protected string m_sSfxSelectionFrameClose_NothingSelected;
47 
48  [Attribute(SCR_SoundEvent.SOUND_E_TRAN_CANCEL, UIWidgets.EditBox)]
49  protected string m_sSfxSelectionFrameClose_Cancel;
50 
51  [Attribute(SCR_SoundEvent.SOUND_FE_BUTTON_SELECT, UIWidgets.EditBox)]
52  protected string m_sSfxSelectEntities;
53 
54  [Attribute(SCR_SoundEvent.TAB_SWITCH, UIWidgets.EditBox)]
55  protected string m_sSfxToggleEntities;
56 
57  [Attribute(SCR_SoundEvent.SOUND_FE_BUTTON_SELECT, UIWidgets.EditBox)]
58  protected string m_sSfxToggleSingleEntity_On;
59 
60  [Attribute(SCR_SoundEvent.SOUND_E_TRAN_CANCEL, UIWidgets.EditBox)]
61  protected string m_sSfxToggleSingleEntity_Off;
62 
63  [Attribute(SCR_SoundEvent.SOUND_E_TRAN_CANCEL, UIWidgets.EditBox)]
64  protected string m_sSfxClearSelection;
65 
66  protected Widget m_SetSelectionWidget;
67  protected Widget m_ToggleSelectionWidget;
68  protected Widget m_GamepadSetSelectionWidget;
69  protected Widget m_GamepadToggleSelectionWidget;
70  protected InputManager m_InputManager;
71  protected WorkspaceWidget m_Workspace;
72 
73  protected SCR_MenuEditorComponent m_EditorMenuManager;
74  protected SCR_StatesEditorComponent m_StatesManager;
75  protected SCR_EntitiesManagerEditorComponent m_EntitiesManager;
76  protected SCR_LayersEditorComponent m_LayersManager;
77  protected SCR_BaseEditableEntityFilter m_UnselectedManager;
78  protected SCR_BaseEditableEntityFilter m_FocusedManager;
79  protected SCR_HoverEditableEntityFilter m_HoverManager;
80  protected SCR_SelectedEditableEntityFilter m_SelectedManager;
81 
82  protected SCR_CursorEditorUIComponent m_CursorComponent;
83  protected SCR_MouseAreaEditorUIComponent m_MouseArea;
84 
85  protected vector m_vCursorPosClick;
86  protected float m_fSelectionFrameDuration;
87  protected bool m_bEnableSelection = true;
88  protected bool m_bIsDrawingFrame;
89  protected bool m_bIsDrawingFrameIsToggle;
90  protected bool m_bIsDrawingFrameConfirmed;
91  protected bool m_bIsDrawingFrameCancelled;
92  protected bool m_bIsDrawingFrameDisabled;
93  protected bool m_bIsAnimatingFrame;
94  protected bool m_bHideCursor;
95  protected int m_iGamepadSelectionHeight;
96  protected BaseWorld m_World;
97 
98  //------------------------------------------------------------------------------------------------
102  void DisableMultiSelection()
103  {
104  if (!m_InputManager.IsUsingMouseAndKeyboard())
105  m_bIsDrawingFrameDisabled = true;
106  }
107 
109  //--- Input listeners
111 
112  //------------------------------------------------------------------------------------------------
113  protected void EditorToggleSelection(float value = 1, EActionTrigger reason = EActionTrigger.DOWN)
114  {
115  if (IsInputDisabled())
116  return;
117 
118  set<SCR_EditableEntityComponent> focused = new set<SCR_EditableEntityComponent>();
119  m_FocusedManager.GetEntities(focused);
120 
121  //~ Multiple entities selected so play general selection sfx
122  if (focused.Count() > 1)
123  {
124  SCR_UISoundEntity.SoundEvent(m_sSfxToggleEntities, true);
125  }
126  //~ Only one entity so check if toggle on or off sfx should be played
127  else if (!focused.IsEmpty())
128  {
129  set<SCR_EditableEntityComponent> selected = new set<SCR_EditableEntityComponent>();
130  m_SelectedManager.GetEntities(selected, true);
131 
132  if (selected.Contains(focused[0]))
133  SCR_UISoundEntity.SoundEvent(m_sSfxToggleSingleEntity_Off);
134  else
135  SCR_UISoundEntity.SoundEvent(m_sSfxToggleSingleEntity_On);
136  }
137 
138  m_SelectedManager.Toggle(focused);
139  ShowGUI();
140  }
141 
142  //------------------------------------------------------------------------------------------------
143  protected void EditorSetSelection(float value = 1, EActionTrigger reason = EActionTrigger.DOWN)
144  {
145  if (IsInputDisabled())
146  return;
147 
148  set<SCR_EditableEntityComponent> focused = new set<SCR_EditableEntityComponent>();
149  m_FocusedManager.GetEntities(focused);
150 
151  //~ Set selected
152  if (!focused.IsEmpty())
153  SCR_UISoundEntity.SoundEvent(m_sSfxSelectEntities, true);
154  //~ Check if deselecting any selected entities
155  else if (m_SelectedManager.GetEntitiesCount() > 0)
156  SCR_UISoundEntity.SoundEvent(m_sSfxClearSelection);
157 
158  m_SelectedManager.Replace(focused, true);
159 
160  ShowGUI();
161  }
162 
163  //------------------------------------------------------------------------------------------------
164  protected void EditorAddSelection(float value = 1, EActionTrigger reason = EActionTrigger.DOWN)
165  {
166  if (IsInputDisabled())
167  return;
168 
169  set<SCR_EditableEntityComponent> focused = new set<SCR_EditableEntityComponent>();
170  m_FocusedManager.GetEntities(focused);
171  m_SelectedManager.Add(focused, true);
172 
173  if (!focused.IsEmpty())
174  SCR_UISoundEntity.SoundEvent(m_sSfxSelectEntities);
175 
176  ShowGUI();
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  protected void EditorClearSelection(float value = 1, EActionTrigger reason = EActionTrigger.DOWN)
181  {
182  if (!m_SelectedManager)
183  return;
184 
185  if (m_SelectedManager.GetEntitiesCount() > 0)
186  SCR_UISoundEntity.SoundEvent(m_sSfxClearSelection);
187 
188  m_SelectedManager.Clear();
189  ShowGUI();
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  protected void EditorSelectAll(float value = 1, EActionTrigger reason = EActionTrigger.DOWN)
194  {
195  if (!m_UnselectedManager || !m_SelectedManager || IsMapOpened())
196  return;
197 
198  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
199  m_UnselectedManager.GetEntities(entities);
200  if (entities.IsEmpty())
201  return;
202 
203  int screenW = m_Workspace.GetWidth();
204  int screenH = m_Workspace.GetHeight();
205 
206  set<SCR_EditableEntityComponent> selectEntities = new set<SCR_EditableEntityComponent>();
207  foreach (SCR_EditableEntityComponent entity: entities)
208  {
209  if (!SCR_Enum.HasPartialFlag(entity.GetEntityStates(), m_MultiSelectStates))
210  continue;
211 
212  vector posWorld;
213  if (!entity.GetPos(posWorld))
214  continue;
215 
216  vector posScreen = m_Workspace.ProjWorldToScreenNative(posWorld, m_World); //--- ToDo: Also check for distance visibility
217  if (posScreen[2] > 0 && posScreen[0] > 0 && posScreen[0] < screenW && posScreen[1] > 0 && posScreen[1] < screenH)
218  selectEntities.Insert(entity);
219  }
220 
221  m_SelectedManager.Replace(selectEntities);
222 
223  if (!selectEntities.IsEmpty())
224  SCR_UISoundEntity.SoundEvent(m_sSfxSelectEntities);
225 
226  ShowGUI();
227  }
228 
229  //------------------------------------------------------------------------------------------------
230  protected void EditorDrawSetSelectionDown(float value, EActionTrigger reason)
231  {
232  DrawFrameDown(false);
233  }
234 
235  //------------------------------------------------------------------------------------------------
236  protected void EditorDrawSetSelectionPressed(float value, EActionTrigger reason)
237  {
238  DrawFramePressed(false);
239  }
240 
241  //------------------------------------------------------------------------------------------------
242  protected void EditorDrawSetSelectionUp(float value, EActionTrigger reason)
243  {
244  DrawFrameUp(false);
245  }
246 
247  //------------------------------------------------------------------------------------------------
248  protected void EditorDrawToggleSelectionDown(float value, EActionTrigger reason)
249  {
250  DrawFrameDown(true);
251  }
252 
253  //------------------------------------------------------------------------------------------------
254  protected void EditorDrawToggleSelectionPressed(float value, EActionTrigger reason)
255  {
256  DrawFramePressed(true);
257  }
258 
259  //------------------------------------------------------------------------------------------------
260  protected void EditorDrawToggleSelectionUp(float value, EActionTrigger reason)
261  {
262  DrawFrameUp(true);
263  }
264 
265  //------------------------------------------------------------------------------------------------
266  protected void EditorDrawSelectionCancel(float value, EActionTrigger reason)
267  {
268  CancelFrame();
269  }
270 
272  //--- Multi-selection
274 
275  //------------------------------------------------------------------------------------------------
276  protected void DrawFrameDown(bool isToggle)
277  {
278  //--- Exit when clicked not on mouse area (e.g., on a button)
279  if (m_MouseArea && !m_MouseArea.IsMouseOn() || m_bIsDrawingFrameDisabled || IsMapOpened())
280  {
281  m_bIsDrawingFrameCancelled = true;
282  return;
283  }
284 
285  m_bIsAnimatingFrame = true;
286  m_bIsDrawingFrameIsToggle = isToggle;
287  m_bIsDrawingFrameConfirmed = false;
288  m_bIsDrawingFrameCancelled = false;
289  m_fSelectionFrameDuration = 0;
290  if (m_vCursorPosClick == vector.Zero)
291  m_vCursorPosClick = m_CursorComponent.GetCursorPos();
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  protected void DrawFrameUp(bool isToggle)
296  {
297  if (!m_bIsDrawingFrame || IsMapOpened())
298  {
299  ResetFrame();
300  return;
301  }
302 
303  if (isToggle != m_bIsDrawingFrameIsToggle)
304  return;
305 
306  m_bIsDrawingFrameConfirmed = true;
307  GetGame().GetCallqueue().Call(ConfirmFrame, isToggle); //--- Needs a delay to faciliate switching between Set (LMB) and add (Ctrl+LMB) variants
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  protected void DrawFramePressed(bool isToggle)
312  {
313  if (!m_CursorComponent || !m_UnselectedManager)
314  return;
315 
316  //--- Some other state is preventing multi-selecting - instantly cancel, so it won't become activated after the other state is unset
317  if ((m_StatesManager && !m_StatesManager.CanSet(EEditorState.MULTI_SELECTING)) || IsMapOpened())
318  {
319  m_bIsDrawingFrameCancelled = true;
320  if (m_bIsDrawingFrame)
321  ResetFrame();
322 
323  return;
324  }
325 
326  if (m_bIsDrawingFrameCancelled)
327  return;
328 
329  //--- Get visible entities
330  set<SCR_EditableEntityComponent> entitiesInside = new set<SCR_EditableEntityComponent>();
331  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
332  m_UnselectedManager.GetEntities(entities);
333 
334  //--- Resize frame
335  if (m_InputManager.IsUsingMouseAndKeyboard())
336  {
337  if (!DrawFrameMouseAndKeyboard(entities, entitiesInside))
338  return;
339 
340  //~ Start drawing frame audio
341  if (!m_bIsDrawingFrame)
342  SCR_UISoundEntity.SoundEvent(m_sSfxStartDrawingSelectionFrame_Keyboard);
343  }
344  else
345  {
346  if (!DrawFrameController(entities, entitiesInside))
347  return;
348 
349  if (!m_bIsDrawingFrame)
350  SCR_UISoundEntity.SoundEvent(m_sSfxStartDrawingSelectionFrame_Gamepad);
351  }
352 
353  if (m_StatesManager && !m_StatesManager.SetState(EEditorState.MULTI_SELECTING))
354  {
355  DrawFrameUp(isToggle);
356  return;
357  }
358 
359  if (!m_bIsDrawingFrame && m_EditorMenuManager)
360  m_EditorMenuManager.SetVisible(true);
361 
362  m_bIsDrawingFrame = true;
363  m_HoverManager.SetEntityUnderCursorEnabled(false);
364 
365  if (entitiesInside.Count() == m_FocusedManager.GetEntitiesCount())
366  return; //--- Ignore when nothing changed
367 
368  m_FocusedManager.Replace(entitiesInside);
369  }
370 
371  //------------------------------------------------------------------------------------------------
372  protected bool DrawFrameMouseAndKeyboard(set<SCR_EditableEntityComponent> entities, out set<SCR_EditableEntityComponent> entitiesInside)
373  {
374  //--- Too small frame, ignore (e.g., when just clicking)
375  vector cursorPos = m_CursorComponent.GetCursorPos();
376  if (!m_bIsDrawingFrame && vector.Distance(m_vCursorPosClick, cursorPos) < FRAME_SIZE_MIN)
377  return false;
378 
379  //Print("DrawFrameMouseAndKeyboard");
380 
381  float xMin = m_vCursorPosClick[0];
382  float yMin = m_vCursorPosClick[1];
383  float xMax = cursorPos[0];
384  float yMax = cursorPos[1];
385  if (xMin > xMax)
386  {
387  xMin = xMax;
388  xMax = m_vCursorPosClick[0];
389  }
390 
391  if (yMin > yMax)
392  {
393  yMin = yMax;
394  yMax = m_vCursorPosClick[1];
395  }
396 
397  if (m_bIsDrawingFrameIsToggle)
398  {
399  FrameSlot.SetPos(m_ToggleSelectionWidget, xMin, yMin);
400  FrameSlot.SetSize(m_ToggleSelectionWidget, xMax - xMin, yMax - yMin);
401  if (m_SetSelectionWidget)
402  m_SetSelectionWidget.SetVisible(false);
403 
404  if (m_ToggleSelectionWidget)
405  m_ToggleSelectionWidget.SetVisible(true);
406  }
407  else
408  {
409  FrameSlot.SetPos(m_SetSelectionWidget, xMin, yMin);
410  FrameSlot.SetSize(m_SetSelectionWidget, xMax - xMin, yMax - yMin);
411  if (m_ToggleSelectionWidget)
412  m_ToggleSelectionWidget.SetVisible(false);
413 
414  if (m_SetSelectionWidget)
415  m_SetSelectionWidget.SetVisible(true);
416  }
417 
418  //--- Find entities in the frame
419  vector worldPos, screenPos;
420  foreach (SCR_EditableEntityComponent entity: entities)
421  {
422  if (!SCR_Enum.HasPartialFlag(entity.GetEntityStates(), m_MultiSelectStates))
423  continue;
424 
425  if (!entity.GetPos(worldPos))
426  continue;
427 
428  screenPos = m_Workspace.ProjWorldToScreen(worldPos, m_World);
429  if (screenPos[2] > 0 && screenPos[0] > xMin && screenPos[0] < xMax && screenPos[1] > yMin && screenPos[1] < yMax)
430  {
431  if (m_LayersManager)
432  entity = m_LayersManager.GetParentBelowCurrentLayer(entity);
433 
434  if (entity)
435  entitiesInside.Insert(entity);
436  }
437  }
438 
439  return true;
440  }
441 
442  //------------------------------------------------------------------------------------------------
443  protected bool DrawFrameController(set<SCR_EditableEntityComponent> entities, out set<SCR_EditableEntityComponent> entitiesInside)
444  {
445  //--- Too fast, ignore (e.g., when just clicking)
446  if (!m_bIsDrawingFrame && m_fSelectionFrameDuration < FRAME_DURATION_MIN)
447  return false;
448 
449  float size;
450  vector cursorPos = m_CursorComponent.GetCursorPos();
451  float curveCoef = Math3D.Curve(ECurveType.CurveProperty2D, (m_fSelectionFrameDuration - FRAME_DURATION_MIN) / m_fGamepadSelectionDuration, m_GamepadSelectionCurve)[1];
452 
453  Widget widgetShow = m_GamepadSetSelectionWidget;
454  Widget widgetHide = m_GamepadToggleSelectionWidget;
455  if (m_bIsDrawingFrameIsToggle)
456  {
457  widgetShow = m_GamepadToggleSelectionWidget;
458  widgetHide = m_GamepadSetSelectionWidget;
459  }
460 
461  if (widgetHide)
462  widgetHide.SetVisible(false);
463 
464  if (widgetShow)
465  {
466  float cursorRadius = 0;
467  if (m_CursorComponent)
468  cursorRadius = 2 * m_CursorComponent.GetCursorRadius() * m_fGamepadSelectionWidgetStartSize;
469 
470  size = cursorRadius + (m_iGamepadSelectionHeight - cursorRadius) * curveCoef;
471  FrameSlot.SetPos(widgetShow, cursorPos[0], cursorPos[1]);
472  FrameSlot.SetSize(widgetShow, size, size);
473  widgetShow.SetVisible(true);
474  widgetShow.SetOpacity(1);
475 
476  //--- Convert to squared radius
477  size *= 0.5;
478  size *= size;
479  }
480 
481  //--- Hide gamepad cursor
482  if (m_CursorComponent && !m_bHideCursor && curveCoef > 0.01)
483  {
484  m_bHideCursor = true;
485  m_CursorComponent.SetCursorAlpha(0, 32);
486  }
487 
488  //--- Find entities in the frame
489  foreach (SCR_EditableEntityComponent entity: entities)
490  {
491  if (!SCR_Enum.HasPartialFlag(entity.GetEntityStates(), m_MultiSelectStates))
492  continue;
493 
494  vector worldPos;
495  if (!entity.GetPos(worldPos))
496  continue;
497 
498  vector screenPos = m_Workspace.ProjWorldToScreen(worldPos, m_World);
499  if (screenPos[2] > 0 && vector.DistanceSq(cursorPos, screenPos) < size)
500  {
501  if (m_LayersManager)
502  entity = m_LayersManager.GetParentBelowCurrentLayer(entity);
503 
504  if (entity)
505  entitiesInside.Insert(entity);
506  }
507  }
508 
509  return true;
510  }
511 
512  //------------------------------------------------------------------------------------------------
513  protected void ConfirmFrame(bool isToggle)
514  {
515  if (!m_bIsDrawingFrameConfirmed)
516  return;
517 
518  m_bIsDrawingFrame = false;
519  if (m_bIsDrawingFrameIsToggle)
520  {
521  EditorToggleSelection();
522  }
523  else
524  {
525  EditorSetSelection();
526 
527  set<SCR_EditableEntityComponent> selected = new set<SCR_EditableEntityComponent>();
528  m_SelectedManager.GetEntities(selected, true);
529 
530  //Nothing selected so play SFX
531  if (m_SelectedManager.GetEntitiesCount() <= 0)
532  SCR_UISoundEntity.SoundEvent(m_sSfxSelectionFrameClose_NothingSelected, true);
533 
534 // if (m_InputManager.IsUsingMouseAndKeyboard())
535 // EditorSetSelection();
536 // else
537 // EditorAddSelection(); //--- With gamepad, add to selection, don't replace it
538  }
539 
540  ResetFrame();
541  m_bIsDrawingFrameCancelled = false;
542  }
543 
544  //------------------------------------------------------------------------------------------------
545  protected void CancelFrame()
546  {
547  if (m_bIsDrawingFrame)
548  {
549  //~ Cancel Sfx
550  SCR_UISoundEntity.SoundEvent(m_sSfxSelectionFrameClose_Cancel, true);
551 
552  m_bIsDrawingFrameCancelled = true;
553  ResetFrame();
554  }
555  }
556 
557  //------------------------------------------------------------------------------------------------
558  protected void ResetFrame()
559  {
560  m_bIsDrawingFrameDisabled = false;
561  m_fSelectionFrameDuration = 0;
562  m_vCursorPosClick = vector.Zero;
563  m_bIsDrawingFrame = false;
564  m_bHideCursor = false;
565 
566  if (m_StatesManager)
567  m_StatesManager.UnsetState(EEditorState.MULTI_SELECTING);
568 
569  //if (m_FocusedManager) m_FocusedManager.Clear(); //--- Disabled, handled in m_HoverManager.SetEntityUnderCursorEnabled
570  if (m_HoverManager)
571  m_HoverManager.SetEntityUnderCursorEnabled(true);
572 
573  if (m_SetSelectionWidget)
574  m_SetSelectionWidget.SetVisible(false);
575 
576  if (m_ToggleSelectionWidget)
577  m_ToggleSelectionWidget.SetVisible(false);
578  //if (m_GamepadSetSelectionWidget)
579  // m_GamepadSetSelectionWidget.SetVisible(false);
580  //if (m_GamepadToggleSelectionWidget)
581  // m_GamepadToggleSelectionWidget.SetVisible(false);
582  if (m_CursorComponent)
583  m_CursorComponent.SetCursorAlpha(1, 8);
584  }
585 
586  //------------------------------------------------------------------------------------------------
587  protected void OnCurrentLayerChange(SCR_EditableEntityComponent currentLayer, SCR_EditableEntityComponent prevLayer)
588  {
589  //--- Clear selection when layers change
590  EnableSelection(false);
591 
592  //--- Block input for a few frames (double-click also counts as selection click)
593  GetGame().GetCallqueue().CallLater(EnableSelection, 100, false, true);
594  m_SelectedManager.Clear();
595  }
596 
597  //------------------------------------------------------------------------------------------------
598  protected void EnableSelection(bool enable)
599  {
600  m_bEnableSelection = enable;
601  }
602 
603  //------------------------------------------------------------------------------------------------
604  protected bool IsMapOpened()
605  {
606  return SCR_MapEntity.GetMapInstance() && SCR_MapEntity.GetMapInstance().IsOpen();
607  }
608 
609  //------------------------------------------------------------------------------------------------
610  protected void OnMenuUpdate(float tDelta)
611  {
612  if (!m_Workspace || !m_InputManager/* || !GetWidget().IsEnabledInHierarchy()*/)
613  return;
614 
615  if (m_StatesManager && (m_StatesManager.GetState() != EEditorState.SELECTING && m_StatesManager.GetState() != EEditorState.MULTI_SELECTING))
616  return; //--- ToDo: Move to OnStateChange event?
617 
618  //--- Activate context for input listeners
619  m_InputManager.ActivateContext("EditorSelectingContext");
620 
621  if (m_bIsAnimatingFrame)
622  {
623  //--- Fade in gamepad selection frame
624  m_fSelectionFrameDuration += tDelta;
625 
626  //--- Fade out gamepad selection frame
627  if (!m_bIsDrawingFrame && (m_bIsDrawingFrameConfirmed || m_bIsDrawingFrameCancelled))
628  {
629  Widget frameWidget;
630  if (m_bIsDrawingFrameIsToggle)
631  frameWidget = m_GamepadToggleSelectionWidget;
632  else
633  frameWidget = m_GamepadSetSelectionWidget;
634 
635  if (frameWidget)
636  {
637  float opacity = Math.Lerp(frameWidget.GetOpacity(), 0, 32 * tDelta);
638  if (opacity < 0.001)
639  {
640  opacity = 0;
641  m_bIsAnimatingFrame = false;
642  }
643  frameWidget.SetOpacity(opacity);
644  }
645  }
646  }
647  }
648 
649  //------------------------------------------------------------------------------------------------
650  protected void OnMenuFocusLost()
651  {
652  CancelFrame();
653  }
654 
655  //------------------------------------------------------------------------------------------------
656  protected Widget GetFrameWidget(Widget root, string name)
657  {
658  Widget widget = root.FindWidget(name);
659  if (widget && !name.IsEmpty())
660  {
661  widget.SetVisible(false);
662  return widget;
663  }
664  else
665  {
666  Print(string.Format("Selection frame widget '%1' not found!", name), LogLevel.ERROR);
667  return null;
668  }
669  }
670 
672  //--- Saved selection (cannot be done dynamically, action listeners cannot pass index as param)
674 
675  //------------------------------------------------------------------------------------------------
676  protected void EditorSaveSelection(int index)
677  {
678  m_SelectedManager.SaveSelection(index);
679  }
680  protected void EditorSaveSelection1() { EditorSaveSelection(1); }
681  protected void EditorSaveSelection2() { EditorSaveSelection(2); }
682  protected void EditorSaveSelection3() { EditorSaveSelection(3); }
683  protected void EditorSaveSelection4() { EditorSaveSelection(4); }
684  protected void EditorSaveSelection5() { EditorSaveSelection(5); }
685  protected void EditorSaveSelection6() { EditorSaveSelection(6); }
686  protected void EditorSaveSelection7() { EditorSaveSelection(7); }
687  protected void EditorSaveSelection8() { EditorSaveSelection(8); }
688  protected void EditorSaveSelection9() { EditorSaveSelection(9); }
689  protected void EditorSaveSelection0() { EditorSaveSelection(0); }
690 
691  //------------------------------------------------------------------------------------------------
692  protected void EditorLoadSelection(int index)
693  {
694  m_SelectedManager.LoadSelection(index);
695  }
696  protected void EditorLoadSelection1() { EditorLoadSelection(1); }
697  protected void EditorLoadSelection2() { EditorLoadSelection(2); }
698  protected void EditorLoadSelection3() { EditorLoadSelection(3); }
699  protected void EditorLoadSelection4() { EditorLoadSelection(4); }
700  protected void EditorLoadSelection5() { EditorLoadSelection(5); }
701  protected void EditorLoadSelection6() { EditorLoadSelection(6); }
702  protected void EditorLoadSelection7() { EditorLoadSelection(7); }
703  protected void EditorLoadSelection8() { EditorLoadSelection(8); }
704  protected void EditorLoadSelection9() { EditorLoadSelection(9); }
705  protected void EditorLoadSelection0() { EditorLoadSelection(0); }
706 
707  //------------------------------------------------------------------------------------------------
708  protected void EditorTeleportSelection(int index)
709  {
710  m_SelectedManager.TeleportSelection(index);
711  }
712  protected void EditorTeleportSelection1() { EditorTeleportSelection(1); }
713  protected void EditorTeleportSelection2() { EditorTeleportSelection(2); }
714  protected void EditorTeleportSelection3() { EditorTeleportSelection(3); }
715  protected void EditorTeleportSelection4() { EditorTeleportSelection(4); }
716  protected void EditorTeleportSelection5() { EditorTeleportSelection(5); }
717  protected void EditorTeleportSelection6() { EditorTeleportSelection(6); }
718  protected void EditorTeleportSelection7() { EditorTeleportSelection(7); }
719  protected void EditorTeleportSelection8() { EditorTeleportSelection(8); }
720  protected void EditorTeleportSelection9() { EditorTeleportSelection(9); }
721  protected void EditorTeleportSelection0() { EditorTeleportSelection(0); }
722 
724  //--- Custom methods
726 
727  //------------------------------------------------------------------------------------------------
728  protected bool IsInputDisabled()
729  {
730  return m_bIsDrawingFrame //--- Multi-selection is active
731  //--- Required classes unavailable
732  || !m_FocusedManager || !m_SelectedManager || !m_MouseArea
733  //--- Disabled internally
734  || !m_bEnableSelection
735  //--- Clicked with mouse on unrelated widget with no entity under cursor
736  || (m_InputManager.IsUsingMouseAndKeyboard() && m_FocusedManager.GetEntitiesCount() == 0 && !m_MouseArea.IsMouseOn());
737  }
738 
739  //------------------------------------------------------------------------------------------------
740  protected void ShowGUI()
741  {
742  if (m_EditorMenuManager)
743  m_EditorMenuManager.SetVisible(true);
744  }
745 
747  //--- Default methods
749 
750  //------------------------------------------------------------------------------------------------
751  override void HandlerAttachedScripted(Widget w)
752  {
753  super.HandlerAttachedScripted(w);
754  if (SCR_Global.IsEditMode())
755  return; //--- Run-time only
756 
757  ArmaReforgerScripted game = GetGame();
758  if (!game)
759  return;
760 
761  m_InputManager = game.GetInputManager();
762  m_Workspace = game.GetWorkspace();
763  m_World = game.GetWorld();
764  if (!m_Workspace)
765  return;
766 
767  MenuRootBase menu = GetMenu();
768  if (!menu)
769  return;
770 
771  m_SetSelectionWidget = GetFrameWidget(w, m_sSetSelectionWidgetName);
772  m_ToggleSelectionWidget = GetFrameWidget(w, m_sToggleSelectionWidgetName);
773  m_GamepadSetSelectionWidget = GetFrameWidget(w, m_sGamepadSetSelectionWidgetName);
774  m_GamepadToggleSelectionWidget = GetFrameWidget(w, m_sGamepadToggleSelectionWidgetName);
775 
776  if (m_GamepadSetSelectionWidget)
777  m_iGamepadSelectionHeight = FrameSlot.GetSizeY(m_GamepadSetSelectionWidget);
778 
779  MenuRootComponent root = GetRootComponent();
780  if (root)
781  {
783  if (!m_CursorComponent)
784  return;
785 
787  }
788 
790  if (m_StatesManager)
791  m_StatesManager.SetState(EEditorState.SELECTING);
792 
794  if (m_LayersManager)
795  m_LayersManager.GetOnCurrentLayerChange().Insert(OnCurrentLayerChange);
796 
797  m_EditorMenuManager = SCR_MenuEditorComponent.Cast(SCR_MenuEditorComponent.GetInstance(SCR_MenuEditorComponent));
799  if (!m_EntitiesManager)
800  return;
801 
802  m_UnselectedManager = m_EntitiesManager.GetFilter(m_UnselectedState);
803  m_FocusedManager = m_EntitiesManager.GetFilter(EEditableEntityState.FOCUSED);
804  m_SelectedManager = SCR_SelectedEditableEntityFilter.Cast(m_EntitiesManager.GetFilter(EEditableEntityState.SELECTED));
805  m_HoverManager = SCR_HoverEditableEntityFilter.Cast(m_EntitiesManager.GetFilter(EEditableEntityState.HOVER));
806 
807  if (m_InputManager)
808  {
809  m_InputManager.AddActionListener("EditorSetSelection", EActionTrigger.DOWN, EditorSetSelection);
810  m_InputManager.AddActionListener("EditorToggleSelection", EActionTrigger.DOWN, EditorToggleSelection);
811  m_InputManager.AddActionListener("EditorClearSelection", EActionTrigger.DOWN, EditorClearSelection);
812  m_InputManager.AddActionListener("EditorSelectAll", EActionTrigger.DOWN, EditorSelectAll);
813  if (m_bEnableMultiSelection)
814  {
815  m_InputManager.AddActionListener("EditorDrawSetSelection", EActionTrigger.DOWN, EditorDrawSetSelectionDown);
816  m_InputManager.AddActionListener("EditorDrawSetSelection", EActionTrigger.PRESSED, EditorDrawSetSelectionPressed);
817  m_InputManager.AddActionListener("EditorDrawSetSelection", EActionTrigger.UP, EditorDrawSetSelectionUp);
818 
819  m_InputManager.AddActionListener("EditorDrawToggleSelection", EActionTrigger.DOWN, EditorDrawToggleSelectionDown);
820  m_InputManager.AddActionListener("EditorDrawToggleSelection", EActionTrigger.PRESSED, EditorDrawToggleSelectionPressed);
821  m_InputManager.AddActionListener("EditorDrawToggleSelection", EActionTrigger.UP, EditorDrawToggleSelectionUp);
822 
823  m_InputManager.AddActionListener("EditorDrawSelectionCancel", EActionTrigger.DOWN, EditorDrawSelectionCancel);
824  }
825 
826  m_InputManager.AddActionListener("EditorSaveSelection1", EActionTrigger.DOWN, EditorSaveSelection1);
827  m_InputManager.AddActionListener("EditorSaveSelection2", EActionTrigger.DOWN, EditorSaveSelection2);
828  m_InputManager.AddActionListener("EditorSaveSelection3", EActionTrigger.DOWN, EditorSaveSelection3);
829  m_InputManager.AddActionListener("EditorSaveSelection4", EActionTrigger.DOWN, EditorSaveSelection4);
830  m_InputManager.AddActionListener("EditorSaveSelection5", EActionTrigger.DOWN, EditorSaveSelection5);
831  m_InputManager.AddActionListener("EditorSaveSelection6", EActionTrigger.DOWN, EditorSaveSelection6);
832  m_InputManager.AddActionListener("EditorSaveSelection7", EActionTrigger.DOWN, EditorSaveSelection7);
833  m_InputManager.AddActionListener("EditorSaveSelection8", EActionTrigger.DOWN, EditorSaveSelection8);
834  m_InputManager.AddActionListener("EditorSaveSelection9", EActionTrigger.DOWN, EditorSaveSelection9);
835  m_InputManager.AddActionListener("EditorSaveSelection0", EActionTrigger.DOWN, EditorSaveSelection0);
836 
837  m_InputManager.AddActionListener("EditorLoadSelection1", EActionTrigger.DOWN, EditorLoadSelection1);
838  m_InputManager.AddActionListener("EditorLoadSelection2", EActionTrigger.DOWN, EditorLoadSelection2);
839  m_InputManager.AddActionListener("EditorLoadSelection3", EActionTrigger.DOWN, EditorLoadSelection3);
840  m_InputManager.AddActionListener("EditorLoadSelection4", EActionTrigger.DOWN, EditorLoadSelection4);
841  m_InputManager.AddActionListener("EditorLoadSelection5", EActionTrigger.DOWN, EditorLoadSelection5);
842  m_InputManager.AddActionListener("EditorLoadSelection6", EActionTrigger.DOWN, EditorLoadSelection6);
843  m_InputManager.AddActionListener("EditorLoadSelection7", EActionTrigger.DOWN, EditorLoadSelection7);
844  m_InputManager.AddActionListener("EditorLoadSelection8", EActionTrigger.DOWN, EditorLoadSelection8);
845  m_InputManager.AddActionListener("EditorLoadSelection9", EActionTrigger.DOWN, EditorLoadSelection9);
846  m_InputManager.AddActionListener("EditorLoadSelection0", EActionTrigger.DOWN, EditorLoadSelection0);
847 
848  m_InputManager.AddActionListener("EditorTeleportSelection1", EActionTrigger.DOWN, EditorTeleportSelection1);
849  m_InputManager.AddActionListener("EditorTeleportSelection2", EActionTrigger.DOWN, EditorTeleportSelection2);
850  m_InputManager.AddActionListener("EditorTeleportSelection3", EActionTrigger.DOWN, EditorTeleportSelection3);
851  m_InputManager.AddActionListener("EditorTeleportSelection4", EActionTrigger.DOWN, EditorTeleportSelection4);
852  m_InputManager.AddActionListener("EditorTeleportSelection5", EActionTrigger.DOWN, EditorTeleportSelection5);
853  m_InputManager.AddActionListener("EditorTeleportSelection6", EActionTrigger.DOWN, EditorTeleportSelection6);
854  m_InputManager.AddActionListener("EditorTeleportSelection7", EActionTrigger.DOWN, EditorTeleportSelection7);
855  m_InputManager.AddActionListener("EditorTeleportSelection8", EActionTrigger.DOWN, EditorTeleportSelection8);
856  m_InputManager.AddActionListener("EditorTeleportSelection9", EActionTrigger.DOWN, EditorTeleportSelection9);
857  m_InputManager.AddActionListener("EditorTeleportSelection0", EActionTrigger.DOWN, EditorTeleportSelection0);
858  }
859 
860  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
861  menu.GetOnMenuFocusLost().Insert(OnMenuFocusLost);
862  }
863 
864  //------------------------------------------------------------------------------------------------
865  override void HandlerDeattached(Widget w)
866  {
867  super.HandlerDeattached(w);
868 
869  MenuRootBase menu = GetMenu();
870  if (menu)
871  {
872  menu.GetOnMenuUpdate().Remove(OnMenuUpdate);
873  menu.GetOnMenuFocusLost().Remove(OnMenuFocusLost);
874  }
875 
876  if (m_LayersManager)
877  m_LayersManager.GetOnCurrentLayerChange().Remove(OnCurrentLayerChange);
878 
879  if (m_InputManager)
880  {
881  m_InputManager.RemoveActionListener("EditorSetSelection", EActionTrigger.DOWN, EditorSetSelection);
882  m_InputManager.RemoveActionListener("EditorToggleSelection", EActionTrigger.DOWN, EditorToggleSelection);
883  m_InputManager.RemoveActionListener("EditorClearSelection", EActionTrigger.DOWN, EditorClearSelection);
884  m_InputManager.RemoveActionListener("EditorSelectAll", EActionTrigger.DOWN, EditorSelectAll);
885  if (m_bEnableMultiSelection)
886  {
887  m_InputManager.RemoveActionListener("EditorDrawSetSelection", EActionTrigger.DOWN, EditorDrawSetSelectionDown);
888  m_InputManager.RemoveActionListener("EditorDrawSetSelection", EActionTrigger.PRESSED, EditorDrawSetSelectionPressed);
889  m_InputManager.RemoveActionListener("EditorDrawSetSelection", EActionTrigger.UP, EditorDrawSetSelectionUp);
890 
891  m_InputManager.RemoveActionListener("EditorDrawToggleSelection", EActionTrigger.DOWN, EditorDrawToggleSelectionDown);
892  m_InputManager.RemoveActionListener("EditorDrawToggleSelection", EActionTrigger.PRESSED, EditorDrawToggleSelectionPressed);
893  m_InputManager.RemoveActionListener("EditorDrawToggleSelection", EActionTrigger.UP, EditorDrawToggleSelectionUp);
894 
895  m_InputManager.RemoveActionListener("EditorDrawSelectionCancel", EActionTrigger.DOWN, EditorDrawSelectionCancel);
896  }
897  }
898  }
899 }
m_MouseArea
private SCR_MouseAreaEditorUIComponent m_MouseArea
Definition: SCR_CursorEditorUIComponent.c:38
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
SCR_CursorEditorUIComponent
Definition: SCR_CursorEditorUIComponent.c:3
SCR_Enum
Definition: SCR_Enum.c:1
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
m_StatesManager
private SCR_StatesEditorComponent m_StatesManager
Definition: SCR_AttributesManagerEditorComponent.c:65
SCR_UISoundEntity
Definition: SCR_UISoundEntity.c:7
EEditorState
EEditorState
Unique editor state.
Definition: EEditorState.c:5
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_SoundEvent
Definition: SCR_SoundEvent.c:1
SCR_EntitiesManagerEditorComponent
Definition: SCR_EntitiesManagerEditorComponent.c:13
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_SelectedEditableEntityFilter
Definition: SCR_SelectedEditableEntityFilter.c:6
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
m_HoverManager
SCR_BaseActionsEditorComponentClass m_HoverManager
Attribute
typedef Attribute
Post-process effect of scripted camera.
MenuRootBase
Definition: MenuRootBase.c:6
SCR_MouseAreaEditorUIComponent
Definition: SCR_MouseAreaEditorUIComponent.c:3
m_LayersManager
protected SCR_LayersEditorComponent m_LayersManager
Definition: SCR_EntitiesToolbarEditorUIComponent.c:38
m_SelectedManager
protected SCR_BaseEditableEntityFilter m_SelectedManager
Definition: SCR_BaseActionsEditorComponent.c:151
m_Workspace
protected WorkspaceWidget m_Workspace
Definition: SCR_EntitiesEditorUIComponent.c:13
SCR_MapEntity
Map entity.
Definition: SCR_MapEntity.c:20
SCR_HoverEditableEntityFilter
Definition: SCR_HoverEditableEntityFilter.c:6
m_World
protected BaseWorld m_World
Definition: SCR_PreviewEntityEditorUIComponent.c:46
SCR_SelectionEditorUIComponent
Definition: SCR_SelectionEditorUIComponent.c:3
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_LayersEditorComponent
Definition: SCR_LayersEditorManager.c:11
MenuRootComponent
Definition: MenuRootComponent.c:6
SCR_Global
Definition: Functions.c:6
m_CursorComponent
protected SCR_CursorEditorUIComponent m_CursorComponent
Definition: SCR_EntitiesEditorUIComponent.c:16
SCR_MenuEditorComponent
Definition: SCR_MenuEditorComponent.c:8
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
SCR_StatesEditorComponent
Definition: SCR_StatesEditorComponent.c:9