Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HideEditorUIComponent.c
Go to the documentation of this file.
1 
4 {
5  [Attribute("10", UIWidgets.Auto, "Speed of smooth transition between visible and hidden state.")]
6  protected float m_fTransitionSpeed;
7 
8  [Attribute(desc: "Show interface again when any of these actions is triggered")]
9  protected ref array<string> m_aShowActions;
10 
11  protected SCR_MenuEditorComponent m_EditorMenuManager;
12  protected float m_fTargetOpacity = 1;
13  protected bool m_bInTransition;
14  protected ref ScriptInvoker Event_OnOpacityChange;
15 
16  //------------------------------------------------------------------------------------------------
20  void SetVisible(bool visible, bool instant = false)
21  {
22  Widget widget = GetWidget();
23  if (!widget)
24  return;
25 
26  widget.SetEnabled(visible);
27 
28  if (visible)
29  m_fTargetOpacity = 1;
30  else
31  m_fTargetOpacity = 0;
32 
33  if (instant)
34  SetWidgetOpacity(widget, m_fTargetOpacity);
35  else
36  m_bInTransition = true;
37  }
38 
39  //------------------------------------------------------------------------------------------------
41  ScriptInvoker GetOnOpacityChange()
42  {
43  if (!Event_OnOpacityChange)
44  Event_OnOpacityChange = new ScriptInvoker();
45 
46  return Event_OnOpacityChange;
47  }
48 
49  //------------------------------------------------------------------------------------------------
50  protected void Show()
51  {
52  //--- Use delay, so clicking on hidden button won't activate it instantly
53  GetGame().GetCallqueue().CallLater(SetMenuVisible, 1, false, true);
54  }
55 
56  //------------------------------------------------------------------------------------------------
57  protected void SetMenuVisible(bool visible)
58  {
59  if (m_EditorMenuManager)
60  m_EditorMenuManager.SetVisible(visible);
61  }
62 
63  //------------------------------------------------------------------------------------------------
64  protected void SetWidgetOpacity(Widget widget, float opacity)
65  {
66  if (widget)
67  widget.SetOpacity(opacity);
68 
69  if (Event_OnOpacityChange)
70  Event_OnOpacityChange.Invoke(opacity);
71  }
72 
73  //------------------------------------------------------------------------------------------------
74  protected void OnMenuUpdate(float tDelta)
75  {
76  Widget widget = GetWidget();
77  if (!widget)
78  return;
79 
80  //--- Disabled, handled by SCR_ToggleInterfaceToolbarAction now
81 // if (m_InputManager.GetActionTriggered("EditorToggleUI"))
82 // {
83 // if (m_EditorMenuManager)
84 // m_EditorMenuManager.ToggleVisible();
85 // else
86 // SetVisible(!widget.IsEnabled());
87 // }
88 
89  if (m_bInTransition)
90  {
91  float opacity = widget.GetOpacity();
92  if (Math.AbsFloat(opacity - m_fTargetOpacity) < 0.01)
93  {
94  SetWidgetOpacity(widget, m_fTargetOpacity);
95  m_bInTransition = false;
96  return;
97  }
98  SetWidgetOpacity(widget, Math.Lerp(opacity, m_fTargetOpacity, m_fTransitionSpeed * tDelta));
99  }
100  }
101 
102  //------------------------------------------------------------------------------------------------
103  protected void OnMenuInit()
104  {
105  if (m_EditorMenuManager)
106  SetVisible(m_EditorMenuManager.IsVisible(), true);
107  }
108 
109  //------------------------------------------------------------------------------------------------
110  override void HandlerAttachedScripted(Widget w)
111  {
112  super.HandlerAttachedScripted(w);
113  if (SCR_Global.IsEditMode())
114  return; //--- Run-time only
115 
116  MenuRootBase menu = GetMenu();
117  if (!menu)
118  return;
119 
120  OnMenuInit();
121  menu.GetOnMenuInit().Insert(OnMenuInit);
122  menu.GetOnMenuUpdate().Insert(OnMenuUpdate);
123 
124  m_EditorMenuManager = SCR_MenuEditorComponent.Cast(SCR_MenuEditorComponent.GetInstance(SCR_MenuEditorComponent));
125 
126  InputManager inputManager = GetGame().GetInputManager();
127  if (inputManager)
128  {
129  foreach (string showAction : m_aShowActions)
130  {
131  inputManager.AddActionListener(showAction, EActionTrigger.DOWN, Show);
132  }
133  }
134  }
135 
136  //------------------------------------------------------------------------------------------------
137  override void HandlerDeattached(Widget w)
138  {
139  super.HandlerDeattached(w);
140 
141  InputManager inputManager = GetGame().GetInputManager();
142  if (inputManager)
143  {
144  foreach (string showAction : m_aShowActions)
145  {
146  inputManager.RemoveActionListener(showAction, EActionTrigger.DOWN, Show);
147  }
148  }
149  }
150 }
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_HideEditorUIComponent
Definition: SCR_HideEditorUIComponent.c:3
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
Attribute
typedef Attribute
Post-process effect of scripted camera.
MenuRootBase
Definition: MenuRootBase.c:6
SCR_BaseEditorUIComponent
Definition: SCR_BaseEditorUIComponent.c:3
SCR_Global
Definition: Functions.c:6
SCR_MenuEditorComponent
Definition: SCR_MenuEditorComponent.c:8
GetWidget
protected Widget GetWidget()
Definition: SCR_VonDisplay.c:155