16 [
Attribute(
"Content", UIWidgets.EditBox,
"Name of widget which will be animated")]
17 string m_sAnimationContentWidget;
19 [
Attribute(
"10", UIWidgets.EditBox,
"Animation speed")]
20 protected float m_fAnimationSpeedPxPerSec;
22 [
Attribute(
"0.5", UIWidgets.EditBox,
"Wait time while animating when content is on the left")]
23 protected float m_fWaitTimeLeftSec;
25 [
Attribute(
"0.5", UIWidgets.EditBox,
"Wait time while animating when content is on the right")]
26 protected float m_fWaitTimeRightSec;
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;
31 [
Attribute(
"0", UIWidgets.CheckBox,
"Inwards offset from right edge of root widget to be used in calculations")]
32 protected float m_fOffsetRight;
34 [
Attribute(
"0", UIWidgets.CheckBox,
"Inwards offset from left edge of root widget to be used in calculations")]
35 protected float m_fOffsetLeft;
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;
44 protected static const int STATE_NONE = 0;
45 protected static const int STATE_MOVING_LEFT = 1;
46 protected static const int STATE_MOVING_LEFT_DONE_WAITING = 2;
47 protected static const int STATE_MOVING_RIGHT = 3;
48 protected static const int STATE_MOVING_RIGHT_DONE_WAITING = 4;
88 m_wRoot.GetScreenSize(rootw, rooth);
90 float contentw, contenth;
93 WorkspaceWidget workspace =
GetGame().GetWorkspace();
95 return rootw > contentw + workspace.DPIScale(m_fOffsetLeft +
m_fOffsetRight);
105 protected override void HandlerAttached(Widget w)
111 m_wContent = w.FindAnyWidget(m_sAnimationContentWidget);
116 Print(
string.Format(
"[SCR_HorizontalScrollAnimationComponent] Widget %1 was not found", m_sAnimationContentWidget), LogLevel.ERROR);
125 auto callQueue =
GetGame().GetCallqueue();
126 callQueue.CallLater(OnEachFrame, 0,
true);
130 override void HandlerDeattached(Widget w)
132 ArmaReforgerScripted game =
GetGame();
133 if (game && game.GetCallqueue())
134 game.GetCallqueue().Remove(OnEachFrame);
138 protected void OnEachFrame()
140 float tDelta = ftime / 1000.0;
148 case STATE_MOVING_LEFT:
151 AnimatePosition(tDelta, -m_fAnimationSpeedPxPerSec);
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);
161 if (contentx + contentw < rootx + rootw - workspace.DPIScale(
m_fOffsetRight))
163 m_State = STATE_MOVING_LEFT_DONE_WAITING;
170 case STATE_MOVING_LEFT_DONE_WAITING:
183 m_State = STATE_MOVING_RIGHT_DONE_WAITING;
189 case STATE_MOVING_RIGHT:
192 AnimatePosition(tDelta, m_fAnimationSpeedPxPerSec);
194 WorkspaceWidget workspace =
GetGame().GetWorkspace();
196 float contentx, contenty;
197 m_wRoot.GetScreenPos(rootx, rooty);
200 if (contentx > rootx + workspace.DPIScale(m_fOffsetLeft))
202 m_State = STATE_MOVING_RIGHT_DONE_WAITING;
209 case STATE_MOVING_RIGHT_DONE_WAITING:
222 protected void AnimatePosition(
float tDelta,
float speed)
224 float currentPos = FrameSlot.GetPosX(
m_wContent);
225 float newPos = currentPos + tDelta * speed;