Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SightsZoomFOVInfo.c
Go to the documentation of this file.
1/*
2Scripted fov info class basing fovs on given zoom info.
3Variable 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
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 {
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);
58 }
59 else
60 {
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
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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 //------------------------------------------------------------------------------------------------
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 {
216
218 }
219
220 //------------------------------------------------------------------------------------------------\
221 protected void InvokeOnZoomChanged(float zoom, float fov)
222 {
224 event_OnZoomChanged.Invoke(zoom, fov);
225 }
226};
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
override void OnUpdate()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Math.c:13
static float CalculateZoomFOV(float magnification)
Return camera FOV for given magnification. Focus FOV is used as reference 1x magnification.
override void OnUpdate(IEntity owner, BaseSightsComponent sights, float timeSlice)
override void OnInit(IEntity owner, BaseSightsComponent sights)
array< float > ZoomsToArray()
Get array of each zoom based on min-max and steps in between.
float GetZoom(int i, int count)
override bool IsAdjusting()
Returns true when current FOV of the optic does not match the target FOV.
void ForceUpdate(IEntity owner, BaseSightsComponent sights, float timeSlice)
float m_fCurrentFOV
Immediate field of view value.
override void SetIndex(int index)
ref ScriptInvoker< float, float > event_OnZoomChanged
void InsertFov(float fov)
Add new fov based on reticle range and zoom.
override int GetCurrentIndex()
Returns currently selected element or -1 if none.
override int GetCount()
Returns the number of available elements.
int m_iCurrentIndex
Currently selected FOV or 0 (as base fov) if none.
SCR_FieldOfViewSettings Attribute
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134