Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SpinningWidgetComponent.c
Go to the documentation of this file.
1 
6 class SCR_SpinningWidgetComponent : ScriptedWidgetComponent
7 {
8  [Attribute("1", UIWidgets.Auto, "Speed, revolutions per second. Positive values mean clockwise rotation.")]
9  float m_fSpeedRps;
10 
11  protected Widget m_wRoot;
12 
13  protected ref SCR_SpinningWidgetAnimationAbstract m_Anim;
14 
15 
16  //-----------------------------------------------------------------------------
17  override void HandlerAttached(Widget w)
18  {
19  if (!GetGame().InPlayMode())
20  return;
21 
22  m_wRoot = w;
23 
24  if (TextWidget.Cast(w))
25  m_Anim = new SCR_SpinningWidgetAnimation<TextWidget>(w);
26  else if (ImageWidget.Cast(w))
27  m_Anim = new SCR_SpinningWidgetAnimation<ImageWidget>(w);
28 
29  if (!m_Anim)
30  return;
31 
32  ScriptCallQueue queue = GetGame().GetCallqueue();
33  queue.CallLater(OnEachFrame, 0, true);
34  }
35 
36  //-----------------------------------------------------------------------------
37  override void HandlerDeattached(Widget w)
38  {
39  if (!GetGame() || !GetGame().InPlayMode())
40  return;
41 
42  ScriptCallQueue queue = GetGame().GetCallqueue();
43  queue.Remove(OnEachFrame);
44  }
45 
46  //-----------------------------------------------------------------------------
47  protected void OnEachFrame()
48  {
49  if (!m_wRoot.IsEnabled() || !m_wRoot.IsVisible() || !m_Anim)
50  return;
51 
52  float tDelta = ftime / 1000.0;
53  m_Anim.Animate(tDelta, m_fSpeedRps);
54  }
55 };
56 
57 //-----------------------------------------------------------------------------
60 {
61  void Animate(float tDelta, float speedRps);
62 };
63 
64 //-----------------------------------------------------------------------------
66 class SCR_SpinningWidgetAnimation<Widget TWidget> : SCR_SpinningWidgetAnimationAbstract
67 {
68  TWidget m_wTarget;
69 
70 
71  //-----------------------------------------------------------------------------
72  void SCR_SpinningWidgetAnimation(Widget w)
73  {
74  m_wTarget = TWidget.Cast(w);
75  }
76 
77  //-----------------------------------------------------------------------------
78  override void Animate(float tDelta, float speedRps)
79  {
80  float angle = m_wTarget.GetRotation();
81  angle += tDelta*speedRps*360.0;
82  if (angle > 360.0)
83  angle -= 360.0;
84  if (angle < 0)
85  angle += 360.0;
86  m_wTarget.SetRotation(angle);
87  }
88 };
SCR_SpinningWidgetAnimationAbstract
Abstract class of a spinning animation.
Definition: SCR_SpinningWidgetComponent.c:59
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SpinningWidgetComponent
Definition: SCR_SpinningWidgetComponent.c:6