1 [
ComponentEditorProps(
category:
"GameScripted/Editor", description:
"Overlays for in-game editor. Works only with SCR_EditorBaseEntity!", icon:
"WBData/ComponentEditorProps/componentEditor.png")]
19 private ref array<ref SCR_EditorMenuOverlayLayer> m_aLayers;
28 if (!m_aLayers)
return null;
31 if (layer.GetLayer() == layerType)
return layer;
36 override void ResetEditorComponent()
43 override void EOnEditorDebug(array<string> debugTexts)
45 if (!m_aLayers || m_aLayers.IsEmpty())
return;
49 if (overlay) debugTexts.Insert(
string.Format(
"Overlay %1: %2", Type().EnumToString(
EEditorMenuOverlayLayer, layer.GetLayer()), overlay.GetDisplayName()));
52 override void EOnEditorActivate()
54 if (!m_aLayers || m_aLayers.IsEmpty())
return;
57 layer.ActivateLayer();
60 override void EOnEditorPostActivate()
62 if (!m_aLayers || m_aLayers.IsEmpty())
return;
64 WorkspaceWidget workspace =
GetGame().GetWorkspace();
65 if (!workspace)
return;
68 if (!menuEditor)
return;
75 layer.PostActivateLayer(menuEditor, workspace);
78 override void EOnEditorDeactivate()
80 if (!m_aLayers || m_aLayers.IsEmpty())
return;
83 if (!menuEditor)
return;
90 layer.ExitLayer(menuEditor);
98 private const string DEFAULT_ROOT_FRAME =
"Frame";
107 private bool m_bCanHide;
113 private bool m_bAlignToRoot;
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;
119 private int m_iZOrder;
125 private int m_iCurrentOverlay;
128 private ref array<ref SCR_EditorMenuOverlay> m_aOverlays;
130 private int m_iDefaultOverlay;
131 private Widget m_RootWidget;
132 private Widget m_RootWidgetDefault;
134 private ref ScriptInvoker Event_OnOverlayChanged =
new ScriptInvoker;
149 int GetOverlays(out notnull array<SCR_EditorMenuOverlay> outOverlays)
152 if (!m_aOverlays)
return 0;
153 int countOverlays = m_aOverlays.Count();
154 for (
int i = 0; i < countOverlays; i++)
156 outOverlays.Insert(m_aOverlays[i]);
158 return countOverlays;
165 void SetCurrentOverlay(
int index,
bool forced =
false)
167 if (!m_aOverlays || (
index == m_iCurrentOverlay && !forced))
return;
169 if (index < 0 || index >= m_aOverlays.Count())
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);
175 if (m_CustomRoot != 0) UpdateCustomRoot();
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]);
183 if (m_bCanHide && m_CustomRoot != 0)
186 if (menuEditor && !menuEditor.IsVisible()) m_aOverlays[m_iCurrentOverlay].SetWidgetOpacity(0);
194 SetCurrentOverlay(m_iDefaultOverlay);
202 if (!m_aOverlays || m_aOverlays.IsEmpty())
return null;
203 return m_aOverlays[m_iCurrentOverlay];
209 int GetCurrentOverlayIndex()
211 return m_iCurrentOverlay;
217 Widget GetOverlayWidget()
219 if (!m_aOverlays || m_aOverlays.IsEmpty())
return null;
220 return m_aOverlays[m_iCurrentOverlay].GetWidget();
224 if (m_CustomRoot == 0 || m_CustomRoot == m_Layer)
return;
227 if (!overlayManager)
return;
230 if (!rootLayer)
return;
232 m_RootLayer = rootLayer;
233 m_RootLayer.GetOnOverlayChanged().Insert(RefreshOverlay);
246 m_RootWidgetDefault = menu.GetMenu().GetRootWidget();
247 if (m_CustomRoot != 0)
252 if (hideComponent) hideComponent.GetOnOpacityChange().Insert(OnHide);
261 if (hideComponent)
m_RootWidget = hideComponent.GetWidget();
264 SetCurrentOverlay(m_iCurrentOverlay,
true);
273 if (!m_aOverlays || m_aOverlays.IsEmpty())
return;
275 m_aOverlays[m_iCurrentOverlay].DeleteWidget();
278 if (hideComponent) hideComponent.GetOnOpacityChange().Remove(OnHide);
284 ScriptInvoker GetOnOverlayChanged()
286 return Event_OnOverlayChanged;
289 protected void OnHide(
float opacity)
291 if (!m_aOverlays || m_aOverlays.IsEmpty())
return;
292 m_aOverlays[m_iCurrentOverlay].SetWidgetOpacity(opacity);
294 protected void RefreshOverlay()
296 SetCurrentOverlay(m_iCurrentOverlay,
true);
298 protected void UpdateCustomRoot()
302 Widget rootWidget = m_RootLayer.GetOverlayWidget();
305 m_RootWidget = GetRootWidget(rootWidget, m_sRootFrameName);
317 if (
m_RootWidget.GetTypeID() == WidgetType.FrameWidgetTypeID)
320 Print(
string.Format(
"Custom overlay root of layer %1 is not a frame widget!", Type().EnumToString(
EEditorMenuOverlayLayer, m_Layer)), LogLevel.ERROR);
324 Print(
string.Format(
"Custom overlay root of layer %1 is missing 'Frame' widget!", Type().EnumToString(
EEditorMenuOverlayLayer, m_Layer)), LogLevel.ERROR);
330 protected Widget GetRootWidget(Widget rootWidget,
string widgetName)
332 if (rootWidget.GetName() == widgetName)
335 return rootWidget.FindAnyWidget(widgetName);
339 m_iDefaultOverlay = m_iCurrentOverlay;
350 private ResourceName m_Overlay;
352 private Widget m_Widget;
358 string GetDisplayName()
369 void CreateWidget(Widget rootWidget,
int zOrder,
bool align)
371 if (m_Widget || m_Overlay.IsEmpty() || !rootWidget)
return;
373 ArmaReforgerScripted game =
GetGame();
376 WorkspaceWidget workspace = game.GetWorkspace();
377 if (!workspace)
return;
379 m_Widget = workspace.CreateWidgets(m_Overlay, rootWidget);
380 if (!m_Widget)
return;
382 m_Widget.SetZOrder(zOrder);
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);
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]);
400 FrameSlot.SetAnchorMin(m_Widget, 0, 0);
401 FrameSlot.SetAnchorMax(m_Widget, 1, 1);
402 FrameSlot.SetOffsets(m_Widget, 0, 0, 0, 0);
410 if (!m_Widget)
return;
411 m_Widget.RemoveFromHierarchy();
418 void SetWidgetOpacity(
float opacity)
420 if (m_Widget) m_Widget.SetOpacity(opacity)