Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_MenuOverlaysEditorComponent.c
Go to the documentation of this file.
1 [ComponentEditorProps(category: "GameScripted/Editor", description: "Overlays for in-game editor. Works only with SCR_EditorBaseEntity!", icon: "WBData/ComponentEditorProps/componentEditor.png")]
3 {
4 };
5 
17 {
18  [Attribute()]
19  private ref array<ref SCR_EditorMenuOverlayLayer> m_aLayers;
20 
26  SCR_EditorMenuOverlayLayer GetOverlayLayer(EEditorMenuOverlayLayer layerType)
27  {
28  if (!m_aLayers) return null;
29  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
30  {
31  if (layer.GetLayer() == layerType) return layer;
32  }
33  return null;
34  }
35 
36  override void ResetEditorComponent()
37  {
38  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
39  {
40  layer.ResetOverlay();
41  }
42  }
43  override void EOnEditorDebug(array<string> debugTexts)
44  {
45  if (!m_aLayers || m_aLayers.IsEmpty()) return;
46  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
47  {
48  SCR_EditorMenuOverlay overlay = layer.GetCurrentOverlay();
49  if (overlay) debugTexts.Insert(string.Format("Overlay %1: %2", Type().EnumToString(EEditorMenuOverlayLayer, layer.GetLayer()), overlay.GetDisplayName()));
50  }
51  }
52  override void EOnEditorActivate()
53  {
54  if (!m_aLayers || m_aLayers.IsEmpty()) return;
55  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
56  {
57  layer.ActivateLayer();
58  }
59  }
60  override void EOnEditorPostActivate()
61  {
62  if (!m_aLayers || m_aLayers.IsEmpty()) return;
63 
64  WorkspaceWidget workspace = GetGame().GetWorkspace();
65  if (!workspace) return;
66 
68  if (!menuEditor) return;
69 
70  EditorMenuBase menu = menuEditor.GetMenu();
71  if (!menu) return;
72 
73  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
74  {
75  layer.PostActivateLayer(menuEditor, workspace);
76  }
77  }
78  override void EOnEditorDeactivate()
79  {
80  if (!m_aLayers || m_aLayers.IsEmpty()) return;
81 
83  if (!menuEditor) return;
84 
85  EditorMenuBase menu = menuEditor.GetMenu();
86  if (!menu) return;
87 
88  foreach (SCR_EditorMenuOverlayLayer layer: m_aLayers)
89  {
90  layer.ExitLayer(menuEditor);
91  }
92  }
93 };
96 {
97  //--- Name of the frame widget in the root in which the overlay is created
98  private const string DEFAULT_ROOT_FRAME = "Frame";
99 
100  [Attribute(defvalue: "0", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorMenuOverlayLayer))]
101  private EEditorMenuOverlayLayer m_Layer;
102 
103  //[Attribute(defvalue: "0", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorMenuOverlayRoot))]
104  //private EEditorMenuOverlayRoot m_Root;
105 
106  [Attribute()];
107  private bool m_bCanHide;
108 
109  [Attribute(defvalue: "", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorMenuOverlayLayer))]
110  private EEditorMenuOverlayLayer m_CustomRoot;
111 
112  [Attribute()];
113  private bool m_bAlignToRoot;
114 
115  [Attribute(desc: "Name of the frame widget in the root in which the overlay is created.\nWhen undefined, default will be used.")];
116  private string m_sRootFrameName;
117 
118  [Attribute(defvalue: "-1")];
119  private int m_iZOrder;
120 
121  //[Attribute()]
122  //private bool m_bCanHide;
123 
124  [Attribute(defvalue: "0")]
125  private int m_iCurrentOverlay;
126 
127  [Attribute()]
128  private ref array<ref SCR_EditorMenuOverlay> m_aOverlays;
129 
130  private int m_iDefaultOverlay;
131  private Widget m_RootWidget;
132  private Widget m_RootWidgetDefault;
133  private SCR_EditorMenuOverlayLayer m_RootLayer;
134  private ref ScriptInvoker Event_OnOverlayChanged = new ScriptInvoker;
135 
140  EEditorMenuOverlayLayer GetLayer()
141  {
142  return m_Layer;
143  }
149  int GetOverlays(out notnull array<SCR_EditorMenuOverlay> outOverlays)
150  {
151  outOverlays.Clear();
152  if (!m_aOverlays) return 0;
153  int countOverlays = m_aOverlays.Count();
154  for (int i = 0; i < countOverlays; i++)
155  {
156  outOverlays.Insert(m_aOverlays[i]);
157  }
158  return countOverlays;
159  }
165  void SetCurrentOverlay(int index, bool forced = false)
166  {
167  if (!m_aOverlays || (index == m_iCurrentOverlay && !forced)) return;
168 
169  if (index < 0 || index >= m_aOverlays.Count())
170  {
171  Print(string.Format("Canot set current overlay of %1, index out of bounds (is %2, must be 0-%3)", typename.EnumToString(EEditorMenuOverlayLayer, m_Layer), index, m_aOverlays.Count() - 1), LogLevel.ERROR);
172  return;
173  }
174 
175  if (m_CustomRoot != 0) UpdateCustomRoot();
176  if (!m_RootWidget) return;
177 
178  m_aOverlays[m_iCurrentOverlay].DeleteWidget();
179  m_iCurrentOverlay = index;
180  m_aOverlays[m_iCurrentOverlay].CreateWidget(m_RootWidget, m_iZOrder, m_bAlignToRoot);
181  Event_OnOverlayChanged.Invoke(m_aOverlays[m_iCurrentOverlay]);
182 
183  if (m_bCanHide && m_CustomRoot != 0)
184  {
186  if (menuEditor && !menuEditor.IsVisible()) m_aOverlays[m_iCurrentOverlay].SetWidgetOpacity(0);
187  }
188  }
192  void ResetOverlay()
193  {
194  SetCurrentOverlay(m_iDefaultOverlay);
195  }
200  SCR_EditorMenuOverlay GetCurrentOverlay()
201  {
202  if (!m_aOverlays || m_aOverlays.IsEmpty()) return null;
203  return m_aOverlays[m_iCurrentOverlay];
204  }
209  int GetCurrentOverlayIndex()
210  {
211  return m_iCurrentOverlay;
212  }
217  Widget GetOverlayWidget()
218  {
219  if (!m_aOverlays || m_aOverlays.IsEmpty()) return null;
220  return m_aOverlays[m_iCurrentOverlay].GetWidget();
221  }
222  void ActivateLayer()
223  {
224  if (m_CustomRoot == 0 || m_CustomRoot == m_Layer) return;
225 
227  if (!overlayManager) return;
228 
229  SCR_EditorMenuOverlayLayer rootLayer = overlayManager.GetOverlayLayer(m_CustomRoot);
230  if (!rootLayer) return;
231 
232  m_RootLayer = rootLayer;
233  m_RootLayer.GetOnOverlayChanged().Insert(RefreshOverlay);
234  }
241  void PostActivateLayer(SCR_MenuEditorComponent menu, WorkspaceWidget workspace)
242  {
243  if (!menu)
244  return;
245 
246  m_RootWidgetDefault = menu.GetMenu().GetRootWidget();
247  if (m_CustomRoot != 0)
248  {
249  if (m_bCanHide)
250  {
251  SCR_HideEditorUIComponent hideComponent = SCR_HideEditorUIComponent.Cast(menu.GetMenuComponent().GetHideableWidget().FindHandler(SCR_HideEditorUIComponent));
252  if (hideComponent) hideComponent.GetOnOpacityChange().Insert(OnHide);
253  }
254  }
255  else
256  {
257  if (m_bCanHide)
258  {
259  //--- Hidden on key press, create in 'Hide' layer
260  SCR_HideEditorUIComponent hideComponent = SCR_HideEditorUIComponent.Cast(menu.GetMenuComponent().GetHideableWidget().FindHandler(SCR_HideEditorUIComponent));
261  if (hideComponent) m_RootWidget = hideComponent.GetWidget();
262  }
263  if (!m_RootWidget) m_RootWidget = m_RootWidgetDefault;
264  SetCurrentOverlay(m_iCurrentOverlay, true);
265  }
266  //SetCurrentOverlay(m_iCurrentOverlay, true);
267  }
271  void ExitLayer(SCR_MenuEditorComponent menu)
272  {
273  if (!m_aOverlays || m_aOverlays.IsEmpty()) return;
274 
275  m_aOverlays[m_iCurrentOverlay].DeleteWidget();
276 
277  SCR_HideEditorUIComponent hideComponent = SCR_HideEditorUIComponent.Cast(menu.GetMenuComponent().GetHideableWidget().FindHandler(SCR_HideEditorUIComponent));
278  if (hideComponent) hideComponent.GetOnOpacityChange().Remove(OnHide);
279  }
284  ScriptInvoker GetOnOverlayChanged()
285  {
286  return Event_OnOverlayChanged;
287  }
288 
289  protected void OnHide(float opacity)
290  {
291  if (!m_aOverlays || m_aOverlays.IsEmpty()) return;
292  m_aOverlays[m_iCurrentOverlay].SetWidgetOpacity(opacity);
293  }
294  protected void RefreshOverlay()
295  {
296  SetCurrentOverlay(m_iCurrentOverlay, true);
297  }
298  protected void UpdateCustomRoot()
299  {
300  if (m_RootLayer)
301  {
302  Widget rootWidget = m_RootLayer.GetOverlayWidget();
303  if (rootWidget)
304  {
305  m_RootWidget = GetRootWidget(rootWidget, m_sRootFrameName);
306  if (!m_RootWidget) m_RootWidget = GetRootWidget(rootWidget, DEFAULT_ROOT_FRAME);
307 
308  /*
309  if (rootWidget.GetName() == "Frame")
310  m_RootWidget = rootWidget;
311  else
312  m_RootWidget = rootWidget.FindAnyWidget("Frame");
313  */
314 
315  if (m_RootWidget)
316  {
317  if (m_RootWidget.GetTypeID() == WidgetType.FrameWidgetTypeID)
318  return;
319  else
320  Print(string.Format("Custom overlay root of layer %1 is not a frame widget!", Type().EnumToString(EEditorMenuOverlayLayer, m_Layer)), LogLevel.ERROR);
321  }
322  else
323  {
324  Print(string.Format("Custom overlay root of layer %1 is missing 'Frame' widget!", Type().EnumToString(EEditorMenuOverlayLayer, m_Layer)), LogLevel.ERROR);
325  }
326  }
327  }
328  m_RootWidget = m_RootWidgetDefault;
329  }
330  protected Widget GetRootWidget(Widget rootWidget, string widgetName)
331  {
332  if (rootWidget.GetName() == widgetName)
333  return rootWidget;
334  else
335  return rootWidget.FindAnyWidget(widgetName);
336  }
338  {
339  m_iDefaultOverlay = m_iCurrentOverlay;
340  }
341 };
342 
345 {
346  [Attribute()]
347  private LocalizedString m_sDisplayName;
348 
349  [Attribute(params: "layout")]
350  private ResourceName m_Overlay;
351 
352  private Widget m_Widget;
353 
358  string GetDisplayName()
359  {
360  return m_sDisplayName;
361  }
362 
369  void CreateWidget(Widget rootWidget, int zOrder, bool align)//, WorkspaceWidget workspace)
370  {
371  if (m_Widget || m_Overlay.IsEmpty() || !rootWidget) return;
372 
373  ArmaReforgerScripted game = GetGame();
374  if (!game) return;
375 
376  WorkspaceWidget workspace = game.GetWorkspace();
377  if (!workspace) return;
378 
379  m_Widget = workspace.CreateWidgets(m_Overlay, rootWidget);
380  if (!m_Widget) return;
381 
382  m_Widget.SetZOrder(zOrder);
383  if (align)
384  {
385  float left, top, right, bottom;
386  FrameSlot.GetOffsets(rootWidget, left, top, right, bottom);
387  vector anchorsMin = FrameSlot.GetAnchorMin(rootWidget);
388  vector anchorsMax = FrameSlot.GetAnchorMin(rootWidget);
389  vector alignment = FrameSlot.GetAlignment(rootWidget);
390  vector size = FrameSlot.GetSize(m_Widget);
391 
392  FrameSlot.SetAlignment(m_Widget, alignment[0], alignment[1]);
393  FrameSlot.SetAnchorMin(m_Widget, anchorsMin[0], anchorsMin[1]);
394  FrameSlot.SetAnchorMax(m_Widget, anchorsMax[0], anchorsMax[1]);
395  FrameSlot.SetOffsets(m_Widget, left, top, right, bottom);
396  FrameSlot.SetSize(m_Widget, size[0], size[1]);
397  }
398  else
399  {
400  FrameSlot.SetAnchorMin(m_Widget, 0, 0);
401  FrameSlot.SetAnchorMax(m_Widget, 1, 1);
402  FrameSlot.SetOffsets(m_Widget, 0, 0, 0, 0);
403  }
404  }
408  void DeleteWidget()
409  {
410  if (!m_Widget) return;
411  m_Widget.RemoveFromHierarchy();
412  m_Widget = null;
413  }
418  void SetWidgetOpacity(float opacity)
419  {
420  if (m_Widget) m_Widget.SetOpacity(opacity)
421  }
426  Widget GetWidget()
427  {
428  return m_Widget;
429  }
430 };
ComponentEditorProps
SCR_FragmentEntityClass ComponentEditorProps
m_sDisplayName
protected string m_sDisplayName
Definition: SCR_KeybindDialogs.c:39
m_RootWidget
protected Widget m_RootWidget
Definition: SCR_BinocularsComponent.c:10
SCR_MenuOverlaysEditorComponentClass
Definition: SCR_MenuOverlaysEditorComponent.c:2
SCR_MenuOverlaysEditorComponent
Definition: SCR_MenuOverlaysEditorComponent.c:16
SCR_BaseContainerCustomTitleEnum
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
Definition: SCR_CampaignHintStorage.c:22
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
EEditorMenuOverlayLayer
EEditorMenuOverlayLayer
Overlay layer.
Definition: EEditorMenuOverlayLayer.c:5
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
BaseContainerCustomTitleField
class SCR_KeyBindingFilter BaseContainerCustomTitleField("m_sBindString")
Definition: SCR_KeyBindingMenuConfig.c:113
SCR_HideEditorUIComponent
Definition: SCR_HideEditorUIComponent.c:3
SCR_BaseEditorComponent
Definition: SCR_BaseEditorComponent.c:119
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EditorMenuOverlay
Definition: SCR_MenuOverlaysEditorComponent.c:344
EditorMenuBase
Definition: EditorMenuBase.c:7
SCR_EditorMenuOverlayLayer
Definition: SCR_MenuOverlaysEditorComponent.c:95
SCR_BaseEditorComponentClass
Definition: SCR_BaseEditorComponent.c:2
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
SCR_MenuEditorComponent
Definition: SCR_MenuEditorComponent.c:8
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
LocalizedString
Definition: LocalizedString.c:21
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180