DayZ Scripts
v1.21.156300 ยท Jun 20, 2023
 
Loading...
Searching...
No Matches
VONManager.c
Go to the documentation of this file.
2{
3 protected bool m_VoNToggled;
6
8 {
9 m_VoNToggled = false;
10 }
11
13 void ShowVoiceNotification(int level, bool fading);
14 void HandleInput(Input inp);
16 void OnEvent(EventType eventTypeId, Param params);
17
19 {
20 return m_VoNToggled;
21 }
22}
23
25{
27 {
30 }
33 {
36 }
37
41 override void HideVoiceNotification()
42 {
43 if (GetGame().IsMissionMainMenu())
44 {
45 return;
46 }
47
49 mission.GetMicrophoneIcon().Show(false);
51 }
52
58 override void ShowVoiceNotification(int level, bool fading)
59 {
60 if (GetGame().IsMissionMainMenu())
61 {
62 return;
63 }
64
66 ImageWidget micIcon = mission.GetMicrophoneIcon();
67 WidgetFadeTimer micTimer = mission.GetMicWidgetFadeTimer();
70
71 // microphone icon
72 micTimer.Stop();
73 micIcon.SetAlpha(1.0);
74 micIcon.Show(true);
75
76 if (fading)
77 {
78 micTimer.FadeOut(micIcon, 3.0);
79 }
80
81 // range icons
82 for( int n = 0; n < voiceLeveWidgets.Count(); n++ )
83 {
84 int voiceKey = voiceLeveWidgets.GetKey(n);
85 ImageWidget voiceWidget = voiceLeveWidgets.Get(n);
86
87 // stop fade timer since it will be refreshed
88 WidgetFadeTimer timer = voiceLevelTimers.Get(n);
89 timer.Stop();
90
91 // show widgets according to the level
92 if ( voiceKey <= level )
93 {
94 voiceWidget.SetAlpha(1.0); // reset from possible previous fade out
95 voiceWidget.Show(true);
96
97 if (fading)
98 {
99 timer.FadeOut(voiceWidget, 3.0);
100 }
101 }
102 else
103 {
104 voiceWidget.Show(false);
105 }
106 }
107 }
108
113 override void HandleInput(Input inp)
114 {
115#ifdef PLATFORM_XBOX
116 // ignore VON-related input if user is in an xbox party
117 if (GetGame().IsInPartyChat())
118 {
119 return;
120 }
121#endif
122 int oldLevel = GetGame().GetVoiceLevel();
123 int newLevel = -1;
124
125 if (inp.LocalPress_ID(UAVoiceDistanceUp,false))
126 {
127 newLevel = ( oldLevel + 1 ) % ( VoiceLevelShout + 1 );
128 }
129
130 if (inp.LocalPress_ID(UAVoiceDistanceDown,false))
131 {
132 newLevel = oldLevel - 1;
133 if (newLevel < VoiceLevelWhisper) //nah...
134 {
135 newLevel = VoiceLevelShout;
136 }
137 }
138
139 if (newLevel != -1)
140 {
141 if (m_VoNToggled)
142 {
144 {
145 ShowVoiceNotification(newLevel, false);
146 }
147 else
148 {
149 ShowVoiceNotification(newLevel, true);
150 }
151 }
152 else
153 {
154 ShowVoiceNotification(newLevel, !GetGame().GetMission().IsVoNActive());
155 }
156
157 // update general voice icon
158 GetGame().SetVoiceLevel(newLevel);
159 }
160 }
161
166 {
168
169 // voice activation mode
170 if (m_VoNToggled)
171 {
173 {
174 ShowVoiceNotification(GetGame().GetVoiceLevel(), false);
175 }
176 else
177 {
179 }
180 }
181 }
182
188 override void OnEvent(EventType eventTypeId, Param params)
189 {
191 switch (eventTypeId)
192 {
194 {
195 // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
196 if (m_VoNToggled)
197 {
199 {
200 ShowVoiceNotification(GetGame().GetVoiceLevel(), false);
201 }
202 }
203 break;
204 }
205
207 {
208 // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
209 if (m_VoNToggled)
210 {
212 {
214 }
215 }
216 break;
217 }
218
220 {
221 if (!mission)
222 {
223 break;
224 }
225
226 VONStateEventParams vonStateParams = VONStateEventParams.Cast( params );
227 mission.SetVoNActive(vonStateParams.param1);
228 m_VoNToggled = vonStateParams.param2;
229 int rangeLevel = GetGame().GetVoiceLevel();
230
231 if (mission.IsVoNActive())
232 {
233 if (m_VoNToggled)
234 {
236 {
237 ShowVoiceNotification(rangeLevel, false);
238 }
239 else
240 {
241 ShowVoiceNotification(rangeLevel, true);
242 }
243 }
244 else
245 {
246 ShowVoiceNotification(rangeLevel, false);
247 }
248 }
249 else
250 {
252 }
253
255 break;
256 }
257
259 {
261 break;
262 }
263
265 {
266 VONStartSpeakingEventParams vonStartParams;
267 if (Class.CastTo(vonStartParams, params))
268 {
269 GetDayZGame().AddVoiceNotification(vonStartParams);
270 }
271 break;
272 }
273
275 {
276 VONStopSpeakingEventParams vonStopParams;
277 if (Class.CastTo(vonStopParams, params))
278 {
279 GetDayZGame().RemoveVoiceNotification(vonStopParams);
280 }
281 break;
282 }
283
285 {
286 if (m_VoNToggled)
287 {
289 {
290 ShowVoiceNotification(GetGame().GetVoiceLevel(), false);
291 }
292 }
293 break;
294 }
295 }
296 }
297}
298
301{
302 private static ref VONManagerBase m_VONManager = new VONManagerBase();
303
309 {
310 return m_VONManager;
311 }
312
316 static void Init()
317 {
318 delete m_VONManager;
320 }
321
325 static void CleanupInstance()
326 {
327 delete m_VONManager;
329 }
330
335 static bool IsVONToggled()
336 {
337 return m_VONManager.IsVonToggled();
338 }
339
345 {
346 GameOptions gameOptions = new GameOptions();
347 NumericOptionsAccess noa;
348 Class.CastTo(noa, gameOptions.GetOptionByType( OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER ));
349
350 return noa.ReadValue() <= GetGame().GetSoundScene().GetSilenceThreshold();
351 }
352}
DayZGame GetDayZGame()
Definition DayZGame.c:3656
Mission mission
ref ScriptInvoker m_OnPartyChatChangedEvent
Definition VONManager.c:29
VONManagerBase Managed VONManagerImplementation()
Definition VONManager.c:26
void ~VONManagerImplementation()
Definition VONManager.c:32
ref ScriptInvoker m_OnVonStateEvent
Definition VONManager.c:28
protected bool m_VoNToggled
Definition VONManager.c:27
proto native void SetVoiceLevel(int level)
Set voice level of VoN (only on client) (VoiceLevelWhisper = 0, VoiceLevelNormal = 1,...
proto native Mission GetMission()
proto native AbstractSoundScene GetSoundScene()
proto native int GetVoiceLevel(Object player=null)
Get voice level of VoN (on both client and server) (VoiceLevelWhisper = 0, VoiceLevelNormal = 1,...
Super root of all classes in Enforce script.
Definition EnScript.c:11
proto native OptionsAccess GetOptionByType(int accessType)
Get option by AccessType.
Definition input.c:11
proto native bool LocalPress_ID(int action, bool check_focus=true)
Returns true just in frame, when action was invoked (button was pressed)
TODO doc.
Definition EnScript.c:118
Mission class.
Definition gameplay.c:670
void SetVoNActive(bool active)
Definition gameplay.c:787
map< int, ref WidgetFadeTimer > GetVoiceLevelTimers()
Definition gameplay.c:821
ImageWidget GetMicrophoneIcon()
Definition gameplay.c:810
void HideVoiceLevelWidgets()
Definition gameplay.c:785
bool IsVoNActive()
Definition gameplay.c:786
map< int, ImageWidget > GetVoiceLevelWidgets()
Definition gameplay.c:819
WidgetFadeTimer GetMicWidgetFadeTimer()
Definition gameplay.c:815
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition param.c:12
ScriptInvoker Class provide list of callbacks usage:
Definition tools.c:116
proto void Invoke(void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
invoke call on all inserted methods with given arguments
proto native void Clear()
remove all calls from list
void VONManagerBase()
Definition VONManager.c:7
ref ScriptInvoker m_OnPartyChatChangedEvent
Definition VONManager.c:5
void HandleInput(Input inp)
void HideVoiceNotification()
bool IsVonToggled()
Definition VONManager.c:18
ref ScriptInvoker m_OnVonStateEvent
Definition VONManager.c:4
void OnEvent(EventType eventTypeId, Param params)
void OnVOIPThresholdChanged()
protected bool m_VoNToggled
Definition VONManager.c:3
void ShowVoiceNotification(int level, bool fading)
Manager class which handles Voice-over-network functionality while player is connected to a server.
Definition VONManager.c:301
static void Init()
Initializes VONManager, runs when user first connects to a server.
Definition VONManager.c:316
static void CleanupInstance()
Uninitializes VONManager, runs when user disconnects from server.
Definition VONManager.c:325
static private ref VONManagerBase m_VONManager
Definition VONManager.c:302
static bool IsVONToggled()
Specifies whether VON mode is toggled or not.
Definition VONManager.c:335
static VONManagerBase GetInstance()
Main way to access VONManager functionality from script.
Definition VONManager.c:308
static bool IsVoiceThresholdMinimum()
Specifies whether user's voice activation threshold value is equal to the minimum voice activation th...
Definition VONManager.c:344
const EventType PartyChatStatusChangedEventTypeID
no params
Definition gameplay.c:548
const EventType VONStartSpeakingEventTypeID
params: VONStartSpeakingEventParams
Definition gameplay.c:538
const EventType VONStateEventTypeID
params: VONStateEventParams
Definition gameplay.c:536
const EventType VONUserStoppedTransmittingAudioEventTypeID
no params
Definition gameplay.c:544
const EventType VONUserStartedTransmittingAudioEventTypeID
no params
Definition gameplay.c:542
const EventType VONStopSpeakingEventTypeID
params: VONStopSpeakingEventParams
Definition gameplay.c:540
const EventType MPSessionPlayerReadyEventTypeID
no params
Definition gameplay.c:468
proto native CGame GetGame()
OptionAccessType
C++ OptionAccessType.
Definition gameplay.c:1178
static proto bool CastTo(out Class to, Class from)
Try to safely down-cast base class to child class.
TypeID EventType
Definition EnWidgets.c:54