Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_HorizontalScrollAnimationComponent.c
Go to the documentation of this file.
1 
14 class SCR_HorizontalScrollAnimationComponent : ScriptedWidgetComponent
15 {
16  [Attribute("Content", UIWidgets.EditBox, "Name of widget which will be animated")]
17  string m_sAnimationContentWidget;
18 
19  [Attribute("10", UIWidgets.EditBox, "Animation speed")]
20  protected float m_fAnimationSpeedPxPerSec;
21 
22  [Attribute("0.5", UIWidgets.EditBox, "Wait time while animating when content is on the left")]
23  protected float m_fWaitTimeLeftSec;
24 
25  [Attribute("0.5", UIWidgets.EditBox, "Wait time while animating when content is on the right")]
26  protected float m_fWaitTimeRightSec;
27 
28  [Attribute("false", UIWidgets.CheckBox, "When true, content will animate to start after it has animated left. Otherwise it will jump to start instantly.")]
29  protected bool m_bAnimateBack;
30 
31  [Attribute("0", UIWidgets.CheckBox, "Inwards offset from right edge of root widget to be used in calculations")]
32  protected float m_fOffsetRight;
33 
34  [Attribute("0", UIWidgets.CheckBox, "Inwards offset from left edge of root widget to be used in calculations")]
35  protected float m_fOffsetLeft;
36 
37  protected int m_State;
38  protected Widget m_wContent;
39  protected Widget m_wRoot;
40  protected float m_fStartPosX;
41  protected float m_fTimer;
42 
43  // Internal state
44  protected static const int STATE_NONE = 0; // Nothing
45  protected static const int STATE_MOVING_LEFT = 1; // Moving left
46  protected static const int STATE_MOVING_LEFT_DONE_WAITING = 2; // Finished moving left, waiting
47  protected static const int STATE_MOVING_RIGHT = 3; // Moving right
48  protected static const int STATE_MOVING_RIGHT_DONE_WAITING = 4; // Finished moving right, waiting
49 
50 
51  //------------------------------------------------------------------------
52  // P U B L I C
53 
54  //------------------------------------------------------------------------
55  void AnimationStop()
56  {
57  m_State = STATE_NONE;
58  }
59 
60  //------------------------------------------------------------------------
61  void AnimationStart()
62  {
63  // If not animating, start animation
64  if (m_State == STATE_NONE)
65  m_State = STATE_MOVING_LEFT;
66 
67  // Otherwise it's already animating in some state, do nothing
68  }
69 
70  //------------------------------------------------------------------------
72  void ResetPosition()
73  {
74  if (!m_wContent)
75  return;
76 
77  FrameSlot.SetPosX(m_wContent, m_fStartPosX);
78  }
79 
80  //------------------------------------------------------------------------
82  bool GetContentFit()
83  {
84  if (!m_wContent)
85  return true;
86 
87  float rootw, rooth;
88  m_wRoot.GetScreenSize(rootw, rooth);
89 
90  float contentw, contenth;
91  m_wContent.GetScreenSize(contentw, contenth);
92 
93  WorkspaceWidget workspace = GetGame().GetWorkspace();
94 
95  return rootw > contentw + workspace.DPIScale(m_fOffsetLeft + m_fOffsetRight);
96  }
97 
98 
99 
100 
101  //------------------------------------------------------------------------
102  // P R O T E C T E D
103 
104  //------------------------------------------------------------------------
105  protected override void HandlerAttached(Widget w)
106  {
107  if (!GetGame().InPlayMode())
108  return;
109 
110  m_wRoot = w;
111  m_wContent = w.FindAnyWidget(m_sAnimationContentWidget);
112 
113  if (!m_wContent)
114  {
115  return;
116  Print(string.Format("[SCR_HorizontalScrollAnimationComponent] Widget %1 was not found", m_sAnimationContentWidget), LogLevel.ERROR);
117  }
118 
119  if (m_wContent)
120  {
121  m_fStartPosX = FrameSlot.GetPosX(m_wContent);
122  }
123 
124  m_State = STATE_MOVING_LEFT; // STATE_NONE;
125  auto callQueue = GetGame().GetCallqueue();
126  callQueue.CallLater(OnEachFrame, 0, true);
127  }
128 
129  //------------------------------------------------------------------------
130  override void HandlerDeattached(Widget w)
131  {
132  ArmaReforgerScripted game = GetGame();
133  if (game && game.GetCallqueue())
134  game.GetCallqueue().Remove(OnEachFrame);
135  }
136 
137  //------------------------------------------------------------------------
138  protected void OnEachFrame()
139  {
140  float tDelta = ftime / 1000.0;
141 
142  switch (m_State)
143  {
144  case STATE_NONE:
145  // Doing nothing
146  break;
147 
148  case STATE_MOVING_LEFT:
149  {
150  // Moving left
151  AnimatePosition(tDelta, -m_fAnimationSpeedPxPerSec);
152 
153  WorkspaceWidget workspace = GetGame().GetWorkspace();
154  float rootw, rooth, rootx, rooty;
155  float contentw, contenth, contentx, contenty;
156  m_wRoot.GetScreenSize(rootw, rooth);
157  m_wRoot.GetScreenPos(rootx, rooty);
158  m_wContent.GetScreenSize(contentw, contenth);
159  m_wContent.GetScreenPos(contentx, contenty);
160 
161  if (contentx + contentw < rootx + rootw - workspace.DPIScale(m_fOffsetRight))
162  {
163  m_State = STATE_MOVING_LEFT_DONE_WAITING;
164  m_fTimer = m_fWaitTimeLeftSec;
165  }
166 
167  break;
168  }
169 
170  case STATE_MOVING_LEFT_DONE_WAITING:
171  {
172  m_fTimer -= tDelta;
173  if (m_fTimer < 0)
174  {
175  if (m_bAnimateBack)
176  {
177  m_State = STATE_MOVING_RIGHT;
178  }
179  else
180  {
181  ResetPosition();
182  m_fTimer = m_fWaitTimeRightSec;
183  m_State = STATE_MOVING_RIGHT_DONE_WAITING;
184  }
185  }
186  break;
187  }
188 
189  case STATE_MOVING_RIGHT:
190  {
191  // Moving right
192  AnimatePosition(tDelta, m_fAnimationSpeedPxPerSec);
193 
194  WorkspaceWidget workspace = GetGame().GetWorkspace();
195  float rootx, rooty;
196  float contentx, contenty;
197  m_wRoot.GetScreenPos(rootx, rooty);
198  m_wContent.GetScreenPos(contentx, contenty);
199 
200  if (contentx > rootx + workspace.DPIScale(m_fOffsetLeft))
201  {
202  m_State = STATE_MOVING_RIGHT_DONE_WAITING;
203  m_fTimer = m_fWaitTimeRightSec;
204  }
205 
206  break;
207  }
208 
209  case STATE_MOVING_RIGHT_DONE_WAITING:
210  {
211  m_fTimer -= tDelta;
212  if (m_fTimer < 0)
213  {
214  m_State = STATE_MOVING_LEFT;
215  }
216  }
217  }
218  }
219 
220 
221  //------------------------------------------------------------------------
222  protected void AnimatePosition(float tDelta, float speed)
223  {
224  float currentPos = FrameSlot.GetPosX(m_wContent);
225  float newPos = currentPos + tDelta * speed;
226  FrameSlot.SetPosX(m_wContent, newPos);
227  }
228 
229 
230  //------------------------------------------------------------------------------------------------
231  static SCR_HorizontalScrollAnimationComponent FindComponent(Widget w)
232  {
234  }
235 };
SCR_HorizontalScrollAnimationComponent
Definition: SCR_HorizontalScrollAnimationComponent.c:14
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_fTimer
protected float m_fTimer
Definition: SCR_CampaignMilitaryBaseComponent.c:94
m_fOffsetRight
protected float m_fOffsetRight
Definition: PrefabGeneratorEntity.c:38
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_wContent
protected Widget m_wContent
Definition: SCR_InfoDisplay.c:64
m_State
private EEditableEntityState m_State
Definition: SCR_BaseEntitiesEditorUIEffect.c:3