Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SightsZoomFOVInfo.c
Go to the documentation of this file.
1 /*
2 Scripted fov info class basing fovs on given zoom info.
3 Variable zoom.
4 */
5 
7 {
8  [Attribute("1", UIWidgets.Auto, desc: "Initial zoom that can be static or scaled up", params: "0.1 100 0.1")]
9  protected float m_fBaseZoom;
10 
11  [Attribute("0", UIWidgets.Auto, desc: "Max zoom, smaller zoomMax than baseZoom will result in static zoom", params: "0.1 100 0.1")]
12  protected float m_fZoomMax;
13 
14  [Attribute("0.5", UIWidgets.Slider, desc: "Zoom step size, will automatically set step count", params: "0.1 5 0.1")]
15  protected float m_fStepZoomSize;
16 
17  [Attribute("6.0", UIWidgets.Slider, desc: "Interpolation speed.", params: "0 100 0.1")]
18  protected float m_fInterpolationSpeed;
19 
20  protected ref array<float> m_aFOVs = new array<float>;
21  protected int m_iStepsCount = 1;
22 
24  protected float m_fCurrentFOV;
25 
27  protected int m_iCurrentIndex = 0;
28 
29  protected ref ScriptInvoker<float, float> event_OnZoomChanged;
30 
31  //------------------------------------------------------------------------------------------------
33  override int GetCount() { return m_aFOVs.Count(); }
34 
35  //------------------------------------------------------------------------------------------------
37  override int GetCurrentIndex() { return m_iCurrentIndex; }
38 
39  //------------------------------------------------------------------------------------------------
44  override void SetIndex(int index)
45  {
46  m_iCurrentIndex = index;
47  InvokeOnZoomChanged(GetCurrentZoom(), m_aFOVs[m_iCurrentIndex]);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  protected override void OnInit(IEntity owner, BaseSightsComponent sights)
52  {
53  // Initialize to default (first available) value
54  if (GetCount() > 0)
55  {
56  SetIndex(0);
57  m_fCurrentFOV = m_aFOVs[0];
58  }
59  else
60  {
61  m_fCurrentFOV = SCR_2DOpticsComponent.CalculateZoomFOV(m_fBaseZoom);
62  }
63  }
64 
65  //------------------------------------------------------------------------------------------------
72  protected override void OnUpdate(IEntity owner, BaseSightsComponent sights, float timeSlice)
73  {
74  if (!m_aFOVs.IsIndexValid(m_iCurrentIndex))
75  return;
76 
77  float target = m_aFOVs[m_iCurrentIndex];
78 
79  float t = timeSlice * m_fInterpolationSpeed;
80  if (t > 1.0)
81  t = 1.0;
82  if (t < 0.0)
83  t = 0.0;
84 
85  m_fCurrentFOV = Math.Lerp(m_fCurrentFOV, target, t);
86  }
87 
88  //------------------------------------------------------------------------------------------------
93  protected override float GetCurrentFOV()
94  {
95  return m_fCurrentFOV;
96  }
97 
98  //------------------------------------------------------------------------------------------------
100  array<float> ZoomsToArray()
101  {
102  array<float> zooms = new array<float>;
103 
104  // Single zoom
105  if (m_fBaseZoom == m_fZoomMax || m_fBaseZoom > m_fZoomMax)
106  {
107  zooms.Insert(m_fBaseZoom);
108  return zooms;
109  }
110 
111  // Count steps
112  int count = (m_fZoomMax - m_fBaseZoom) / m_fStepZoomSize;
113 
114  // Create variable zooms
115  for (int i = 0; i <= count; i++)
116  {
117  float zoom = GetZoom(i, count);
118  zooms.Insert(zoom);
119  }
120 
121  m_iStepsCount = zooms.Count();
122  return zooms;
123  }
124 
125  //------------------------------------------------------------------------------------------------
127  void InsertFov(float fov)
128  {
129  m_aFOVs.Insert(fov);
130  }
131 
132  //------------------------------------------------------------------------------------------------
133  int GetStepsCount()
134  {
135  return m_iStepsCount;
136  }
137 
138  //------------------------------------------------------------------------------------------------
139  void SetCurrentFov(float fov)
140  {
141  m_fCurrentFOV = fov;
142  }
143 
144  //------------------------------------------------------------------------------------------------
145  protected float GetZoom(int i, int count)
146  {
147  if (i < 0)
148  i = 0;
149 
150  return m_fBaseZoom + i * m_fStepZoomSize;
151  }
152 
153  //------------------------------------------------------------------------------------------------
154  float GetCurrentZoom()
155  {
156  // TODO just check this with Jakub Werner as whether its good or nicht,
157  // ich have to say that das ist nicht gut, das ist nicht gut Hans!
158 
159  int count = m_aFOVs.Count();
160 
161  if (count == 0)
162  return m_fBaseZoom;
163 
164  return GetZoom(m_iCurrentIndex, count);
165  }
166 
167  //------------------------------------------------------------------------------------------------
168  float GetBaseZoom()
169  {
170  int count = m_aFOVs.Count();
171  if (count > 0)
172  return GetZoom(0, count);
173 
174  return 1.0;
175  }
176 
177  //------------------------------------------------------------------------------------------------
184  override float GetBaseFOV()
185  {
186  if (!m_aFOVs.IsEmpty())
187  return m_aFOVs[0];
188 
189  return m_fCurrentFOV;
190  }
191 
192  //------------------------------------------------------------------------------------------------
194  override bool IsAdjusting()
195  {
196  if (!m_aFOVs.IsIndexValid(m_iCurrentIndex))
197  return false;
198 
199  return !float.AlmostEqual(m_fCurrentFOV, m_aFOVs[m_iCurrentIndex]);
200  }
201 
202  void ForceUpdate(IEntity owner, BaseSightsComponent sights, float timeSlice)
203  {
204  OnUpdate(owner, sights, timeSlice);
205  }
206 
207  //------------------------------------------------------------------------------------------------
208  // Invoker API
209  //------------------------------------------------------------------------------------------------
210 
211  //------------------------------------------------------------------------------------------------\
212  ScriptInvoker GetEventOnZoomChanged()
213  {
214  if (!event_OnZoomChanged)
215  event_OnZoomChanged = new ScriptInvoker();
216 
217  return event_OnZoomChanged;
218  }
219 
220  //------------------------------------------------------------------------------------------------\
221  protected void InvokeOnZoomChanged(float zoom, float fov)
222  {
223  if (event_OnZoomChanged)
224  event_OnZoomChanged.Invoke(zoom, fov);
225  }
226 };
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_2DOpticsComponent
Definition: SCR_2DOpticsComponent.c:12
SCR_SightsZoomFOVInfo
Definition: SCR_SightsZoomFOVInfo.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_BaseVariableSightsFOVInfo
Definition: SCR_BaseVariableSightsFOVInfo.c:1
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24