Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_CollapseWidgetComponent.c
Go to the documentation of this file.
2 {
3  LEFT,
4  UP,
7 };
8 
9 class SCR_CollapseWidgetComponent : ScriptedWidgetComponent
10 {
11  [Attribute("false")]
12  protected bool m_bCollapsed;
13 
14  [Attribute("0", UIWidgets.ComboBox, "Direction of the collapse", "", ParamEnumArray.FromEnum(EDirection))]
15  protected EDirection m_eCollapseDirection;
16 
17  [Attribute("0.5")]
18  protected float m_fCollapseTime;
19 
20  [Attribute(desc: "Is widget slot a frame, or if it's inside a layout slot. FRAME SLOT NOT IMPLEMENTED!")]
21  protected bool m_bIsFrameSlot;
22 
23  protected float m_fDefaultValue = float.MAX;
24  protected Widget m_wRoot;
25  protected float m_fTimeout = 50;
26 
27  //ref ScriptInvoker<bool> m_OnToggled = new ScriptInvoker();
28 
29  //------------------------------------------------------------------------------------------------
30  override void HandlerAttached(Widget w)
31  {
32  m_wRoot = w;
33  SetCollapseTime(m_fCollapseTime);
34 
35  if (!m_bCollapsed)
36  return;
37 
38  // Hack - delayed start (if there should be animation)
39  if (m_fCollapseTime != float.MAX)
40  {
41  float opacity = w.GetOpacity();
42  w.SetOpacity(0);
43  GetGame().GetCallqueue().CallLater(ShowWidgetDelayed, m_fTimeout, false, opacity);
44  }
45  else
46  {
47  SetCollapsed(m_bCollapsed, false);
48  }
49  }
50 
51  //------------------------------------------------------------------------------------------------
52  void ShowWidgetDelayed(float opacity)
53  {
54  AnimateWidget.Opacity(m_wRoot, opacity, UIConstants.FADE_RATE_FAST);
55  SetCollapsed(true, false);
56  }
57 
58  //------------------------------------------------------------------------------------------------
59  Widget GetRootWidget()
60  {
61  return m_wRoot;
62  }
63 
64  //------------------------------------------------------------------------------------------------
65  void SetCollapsed(bool collapsed, bool animate = true)
66  {
67  if (m_bCollapsed == collapsed && animate)
68  return;
69 
70  m_bCollapsed = collapsed;
71 
72  if (m_bIsFrameSlot)
73  Print("CollapseWidgetComponent frameSlot not implemented", LogLevel.WARNING);
74  else
75  SetupLayoutAnimation(m_fCollapseTime, animate);
76  }
77 
78  //------------------------------------------------------------------------------------------------
79  bool IsCollapsed()
80  {
81  return m_bCollapsed;
82  }
83 
84  //------------------------------------------------------------------------------------------------
85  void SetCollapseTime(float time)
86  {
87  // Convert to collapse speed
88  if (time <= 0)
89  m_fCollapseTime = float.MAX;
90  else
91  m_fCollapseTime = 1 / time;
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  float GetCollapseTime()
96  {
97  // Collapse speed can never be 0
98  return 1 / m_fCollapseTime;
99  }
100 
101  //------------------------------------------------------------------------------------------------
102  void SetCollpseDirection(EDirection direction)
103  {
104  m_eCollapseDirection = direction;
105  }
106 
107  //------------------------------------------------------------------------------------------------
108  EDirection GetCollapseDirection()
109  {
110  return m_eCollapseDirection;
111  }
112 
113  //------------------------------------------------------------------------------------------------
114  protected void SetupLayoutAnimation(float speed, bool animate)
115  {
116  if (!m_wRoot)
117  return;
118 
119  // Do not try to animate the collapse if animation is too fast
120  if (m_fCollapseTime == float.MAX)
121  animate = false;
122 
123  float left, top, right, bottom, w, h;
124  AlignableSlot.GetPadding(m_wRoot, left, top, right, bottom);
125  m_wRoot.GetScreenSize(w, h);
126  if (w <= 0 || h <= 0)
127  {
128  //m_wRoot.Update();
129  m_wRoot.GetScreenSize(w, h);
130  }
131 
132  w = GetGame().GetWorkspace().DPIUnscale(w);
133  h = GetGame().GetWorkspace().DPIUnscale(h);
134 
135  float paddings[4];
136 
137  switch (m_eCollapseDirection)
138  {
139  case EDirection.LEFT:
140  if (m_bCollapsed)
141  {
142  if (m_fDefaultValue == float.MAX)
143  m_fDefaultValue = left;
144 
145  paddings = {-w - right, top, right, bottom};
146  }
147  else
148  {
149  paddings = {m_fDefaultValue, top, right, bottom};
150  }
151  break;
152  case EDirection.UP:
153  if (m_bCollapsed)
154  {
155  if (m_fDefaultValue == float.MAX)
156  m_fDefaultValue = top;
157 
158  paddings = {left, -h - bottom, right, bottom};
159  }
160  else
161  {
162  paddings = {left, m_fDefaultValue, right, bottom};
163  }
164  break;
165  case EDirection.RIGHT:
166  if (m_bCollapsed)
167  {
168  if (m_fDefaultValue == float.MAX)
169  m_fDefaultValue = right;
170 
171  paddings = {left, top, -w - left, bottom};
172  }
173  else
174  {
175  paddings = {left, top, m_fDefaultValue, bottom};
176  }
177  break;
178  case EDirection.DOWN:
179  if (m_bCollapsed)
180  {
181  if (m_fDefaultValue == float.MAX)
182  m_fDefaultValue = bottom;
183 
184  paddings = {left, top, right, -h - top};
185  }
186  else
187  {
188  paddings = {left, top, right, m_fDefaultValue};
189  }
190  break;
191  }
192 
193  if (animate)
194  AnimateWidget.Padding(m_wRoot, paddings, speed);
195  else
196  m_wRoot.SetVisible(!m_bCollapsed); // Do not attempt to set any padding, just hide the widget
197  //AlignableSlot.SetPadding(m_wRoot, paddings[0], paddings[1], paddings[2], paddings[3]);
198  }
199 };
direction
vector direction
Definition: SCR_DestructibleTreeV2.c:31
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
Attribute
typedef Attribute
Post-process effect of scripted camera.
DOWN
@ DOWN
Definition: SCR_CollapseWidgetComponent.c:6
UP
@ UP
Definition: SCR_CollapseWidgetComponent.c:4
SCR_CollapseWidgetComponent
Definition: SCR_CollapseWidgetComponent.c:9
LEFT
@ LEFT
Definition: SCR_CollapseWidgetComponent.c:3
EDirection
EDirection
Definition: SCR_CollapseWidgetComponent.c:1
RIGHT
@ RIGHT
Definition: SCR_CollapseWidgetComponent.c:5