26 protected ref array<ref SCR_HUDManagerHandler> m_aHandlers;
27 protected ref array<SCR_HUDManagerHandler> m_aUpdatableHandlers = {};
30 string m_sDefaultBackgroundLayer;
32 string m_sDefaultForegroundLayer;
34 [
Attribute(
"0 0 1 1", UIWidgets.GraphDialog,
params:
"0.1 0.6 0 0.4",
desc:
"Adaptive opacity (y) based on screen brightness (x).",
category:
"AdaptiveOpacity")]
35 private ref Curve m_AdaptiveOpacityCurve;
37 private ref map<EHudLayers, Widget> m_aLayerWidgets =
new map<EHudLayers, Widget>;
38 private Widget m_wRoot;
39 private Widget m_wRootTop;
41 protected BaseWorld m_World;
43 private bool m_MenuOpen;
45 protected ref ScriptInvokerBase<OnScreenBrightnessChanged> m_OnSceneBrightnessChanged =
new ScriptInvokerBase<OnScreenBrightnessChanged>();
47 protected float m_fUpdateTime = -1;
48 const float UPDATE_DELAY = 500;
50 const float ADAPTIVE_OPACITY_BRIGHTNESS_THROTTLE = 0.001;
51 const float ADAPTIVE_OPACITY_THROTTLE = 0.01;
53 protected float m_fSceneBrightness = -1;
54 protected float m_fOpacity = -1;
56 protected IEntity m_Owner;
58 protected ref array<SCR_HUDManagerHandler> m_aHandlersToRemoveFromUpdate = {};
60 #ifndef DISABLE_HUD_MANAGER
63 int GetInfoDisplayCount()
65 return m_aHUDElements.Count();
79 if (handler.Type() == handlerType)
89 m_aHandlersToRemoveFromUpdate.Insert(handler);
93 Widget GetHUDRootWidget()
99 protected override void OnInit(IEntity owner)
101 if (!
GetGame().GetWorldEntity())
107 handler.OnInit(
this);
109 if (handler.CanUpdate())
115 handler.OnStart(
this);
118 ArmaReforgerScripted game =
GetGame();
119 if (game && !game.GetHUDManager())
121 game.SetHUDManager(
this);
129 protected override void OnUpdate(IEntity owner)
134 if (!m_aHandlersToRemoveFromUpdate.IsEmpty())
139 handler.SetCanUpdate(
false);
142 m_aHandlersToRemoveFromUpdate.Clear();
147 handler.OnUpdate(
this);
150 float time =
m_World.GetWorldTime();
152 if (time < m_fUpdateTime)
155 m_fUpdateTime = time + UPDATE_DELAY;
162 float sceneBrightness = Math.Clamp(
m_World.GetCameraSceneMiddleBrightness(0), 0, 0.1);
165 if (Math.AbsFloat(m_fSceneBrightness - sceneBrightness) < ADAPTIVE_OPACITY_BRIGHTNESS_THROTTLE)
169 float opacity = Math3D.Curve(ECurveType.CurveProperty2D, sceneBrightness, m_AdaptiveOpacityCurve)[1];
170 opacity = Math.Clamp(Math.Round(opacity * 100) / 100, 0, 1);
173 if (Math.AbsFloat(m_fOpacity - opacity) >= ADAPTIVE_OPACITY_THROTTLE)
177 m_fSceneBrightness = sceneBrightness;
178 m_fOpacity = opacity;
180 if (m_OnSceneBrightnessChanged)
181 m_OnSceneBrightnessChanged.Invoke(opacity, sceneBrightness);
186 float GetAdaptiveOpacity()
192 float GetSceneBrightness()
194 return m_fSceneBrightness;
198 ScriptInvokerBase<OnScreenBrightnessChanged> GetSceneBrightnessChangedInvoker()
200 return m_OnSceneBrightnessChanged;
213 protected void CreateHUDLayers()
215 m_wRoot =
GetGame().GetWorkspace().CreateWidget(WidgetType.FrameWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0);
216 m_wRootTop =
GetGame().GetWorkspace().CreateWidget(WidgetType.FrameWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0);
217 m_wRootTop.SetZOrder(100);
221 InitRootWidget(
m_wRoot,
"SCR_HUDManagerComponent.m_wRoot");
222 InitRootWidget(m_wRootTop,
"SCR_HUDManagerComponent.m_wRootTop");
224 array<int> bitValues =
new array<int>;
227 for (
int i = 0; i < bitCount; i++)
234 frame =
GetGame().GetWorkspace().CreateWidget(WidgetType.FrameWidgetTypeID, WidgetFlags.VISIBLE, Color.FromInt(Color.WHITE), 0, parent);
235 FrameSlot.SetAnchorMin(frame, 0, 0);
236 FrameSlot.SetAnchorMax(frame, 1, 1);
237 FrameSlot.SetOffsets(frame, 0, 0, 0, 0);
238 frame.SetFlags(WidgetFlags.IGNORE_CURSOR);
239 frame.SetName(
string.Format(
"SCR_HudManagerComponent: %1",
typename.EnumToString(
EHudLayers, bitValues[i])));
241 m_aLayerWidgets.Insert(bitValues[i], frame);
248 SCR_InfoDisplay FindInfoDisplay(
typename type)
250 foreach (SCR_InfoDisplay display : m_aHUDElements)
252 if (display.Type() ==
type)
261 SCR_InfoDisplay FindInfoDisplayByResourceName(ResourceName path)
263 foreach (SCR_InfoDisplay display : m_aHUDElements)
265 if (display.m_LayoutPath == path)
274 Widget FindLayoutByResourceName(ResourceName path)
276 foreach (SCR_InfoDisplay display : m_aHUDElements)
278 if (display.m_LayoutPath == path)
279 return display.GetRootWidget();
286 protected void InitRootWidget(Widget root,
string name)
288 FrameSlot.SetAnchorMin(root, 0, 0);
289 FrameSlot.SetAnchorMax(root, 1, 1);
290 FrameSlot.SetOffsets(root, 0, 0, 0, 0);
291 root.SetFlags(WidgetFlags.IGNORE_CURSOR);
296 Widget CreateLayout(ResourceName path,
EHudLayers layer,
int zOrder = 0)
298 #ifndef DISABLE_HUD_MANAGER
300 if (path ==
string.Empty)
304 if (m_aLayerWidgets.Find(layer, parent) && parent)
306 Widget w =
GetGame().GetWorkspace().CreateWidgets(path, parent);
309 FrameSlot.SetAnchorMin(w, 0, 0);
310 FrameSlot.SetAnchorMax(w, 1, 1);
311 FrameSlot.SetOffsets(w, 0, 0, 0, 0);
312 w.SetFlags(WidgetFlags.IGNORE_CURSOR);
325 SCR_HUDElement CreateFreeElement(ResourceName path,
string parentName)
332 Widget parentWidget = layoutHandler.FindWidgetByNameFromAnyLayout(parentName, owningLayout);
338 Print(parentName +
" is a HUD Slot! Use InfoDisplay instead!", LogLevel.ERROR);
342 Widget elementWidget =
GetGame().GetWorkspace().CreateWidgets(path, parentWidget);
345 hudElement.SetWidget(elementWidget);
346 hudElement.SetParentWidgetName(parentName);
347 hudElement.SetParentLayout(owningLayout);
348 owningLayout.AddHudElement(hudElement);
357 void SetVisible(
bool isVisible)
360 m_wRootTop.SetVisible(isVisible);
380 foreach (
EHudLayers layer, Widget w : m_aLayerWidgets)
388 foreach (
EHudLayers layer, Widget w : m_aLayerWidgets)
390 w.SetVisible(layers & layer);
402 foreach (
EHudLayers layer, Widget w : m_aLayerWidgets)
404 if (w.IsVisible()) layers = layers | layer;
412 #ifndef DISABLE_HUD_MANAGER
414 ArmaReforgerScripted game =
GetGame();
417 return game.GetHUDManager();
433 const int CONTEXT_GENERATE_AVAILABLE_INPUT_ACTION = 0;
435 override array<ref WB_UIMenuItem> _WB_GetContextMenuItems(IEntity owner)
438 array<ref WB_UIMenuItem> items =
new array<ref WB_UIMenuItem>();
441 array<BaseInfoDisplay> elements =
new array<BaseInfoDisplay>();
443 foreach (
auto element : elements)
448 ref WB_UIMenuItem actionsContextItem =
new WB_UIMenuItem(
"Add actions to AvailableActionsDisplay info", CONTEXT_GENERATE_AVAILABLE_INPUT_ACTION);
449 items.Insert(actionsContextItem);
458 override void _WB_OnContextMenu(IEntity owner,
int id)
460 if (
id == CONTEXT_GENERATE_AVAILABLE_INPUT_ACTION)
465 array<BaseInfoDisplay> elements =
new array<BaseInfoDisplay>();
467 foreach (
auto element : elements)
484 InputManager mgr =
GetGame().GetInputManager();
485 array<string> actions =
new array<string>();
488 int cnt = mgr.GetActionCount();
489 for (
int i = 0; i < cnt; i++)
491 auto act = mgr.GetActionName(i);
497 WorldEditorAPI api = genericOwner._WB_GetEditorAPI();
503 array<int> selection =
new array<int>();
504 api.ShowItemListDialog(
"Actions Selection",
"Select actions from the actions manager to create entry for.", 340, 480, actions, selection, 0);
507 IEntitySource entitySource = api.EntityToSource(owner);
512 BaseContainer componentContainer;
513 int cmpCount = entitySource.GetComponentCount();
514 for (
int i = 0; i < cmpCount; i++)
516 IEntityComponentSource componentSource = entitySource.GetComponent(i);
517 if (componentSource.GetClassName() ==
"SCR_HUDManagerComponent")
519 componentContainer = componentSource.ToBaseContainer();
524 if (!componentContainer)
528 BaseContainerList infoDisplays = componentContainer.GetObjectArray(
"InfoDisplays");
533 BaseContainer displaySource;
534 for (
int i = 0; i < infoDisplays.Count(); i++)
536 BaseContainer container = infoDisplays.Get(i);
537 if (container.GetClassName() ==
"SCR_AvailableActionsDisplay")
539 displaySource = container;
547 api.BeginEntityAction(
"Create action container");
549 const string list =
"m_aActions";
551 foreach (
auto sel : selection)
553 string selectedActionName = actions[sel];
554 if (selectedActionName ==
string.Empty)
557 const int objIndex = 0;
559 api.CreateObjectArrayVariableMember(displaySource,
null, list,
"SCR_AvailableActionContext", objIndex);
561 BaseContainerList itemsList = displaySource.GetObjectArray(list);
562 BaseContainer thisContainer = itemsList.Get(objIndex);
563 thisContainer.Set(
"m_sAction", selectedActionName);
564 thisContainer.Set(
"m_sName", selectedActionName);
567 api.EndEntityAction();