Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
vonmanager.c
Go to the documentation of this file.
37
41 override void HideVoiceNotification()
42 {
43 if (GetGame().IsMissionMainMenu())
44 {
45 return;
46 }
47
48 Mission mission = GetGame().GetMission();
49 mission.GetMicrophoneIcon().Show(false);
50 mission.HideVoiceLevelWidgets();
51 }
52
58 override void ShowVoiceNotification(int level, bool fading)
59 {
60 if (GetGame().IsMissionMainMenu())
61 {
62 return;
63 }
64
65 Mission mission = GetGame().GetMission();
66 ImageWidget micIcon = mission.GetMicrophoneIcon();
67 WidgetFadeTimer micTimer = mission.GetMicWidgetFadeTimer();
68 map<int,ImageWidget> voiceLeveWidgets = mission.GetVoiceLevelWidgets();
69 map<int,ref WidgetFadeTimer> voiceLevelTimers = mission.GetVoiceLevelTimers();
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 if (oldLevel == -1) //VoN system not initialized!
124 return;
125
126 int newLevel = -1;
127
128 if (inp.LocalPress_ID(UAVoiceDistanceUp,false))
129 {
130 newLevel = ( oldLevel + 1 ) % ( VoiceLevelShout + 1 );
131 }
132
133 if (inp.LocalPress_ID(UAVoiceDistanceDown,false))
134 {
135 newLevel = oldLevel - 1;
136 if (newLevel < VoiceLevelWhisper) //nah...
137 {
138 newLevel = VoiceLevelShout;
139 }
140 }
141
142 if (newLevel > -1)
143 {
144 CGame game = GetGame();
145 game.SetVoiceLevel(newLevel);
146 if (game.GetMission().IsVoNActive()) // icon is already visible, just update the range
147 {
148 UpdateVoiceIcon();
149 }
150 else // Show the icon and let it fade out
151 {
152 int level = GetGame().GetVoiceLevel();
153 ShowVoiceNotification(level, true);
154 }
155 }
156 }
157
158 private void UpdateVoiceIcon()
159 {
160 Mission mission = GetGame().GetMission();
161 int rangeLevel = GetGame().GetVoiceLevel();
162
163 if (mission.IsVoNActive())
164 {
165 if (m_VoNToggled)
166 {
167 if (VONManager.IsVoiceThresholdMinimum())
168 {
169 ShowVoiceNotification(rangeLevel, false);
170 }
171 else
172 {
173 ShowVoiceNotification(rangeLevel, true);
174 }
175 }
176 else
177 {
178 ShowVoiceNotification(rangeLevel, false);
179 }
180 }
181 else
182 {
184 }
185 }
186
191 {
192 UpdateVoiceIcon();
193 }
194
200 override void OnEvent(EventType eventTypeId, Param params)
201 {
202 Mission mission = GetGame().GetMission();
203 switch (eventTypeId)
204 {
206 {
207 // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
208 if (m_VoNToggled)
209 {
210 if (!VONManager.IsVoiceThresholdMinimum())
211 {
212 ShowVoiceNotification(GetGame().GetVoiceLevel(), false);
213 }
214 }
215 break;
216 }
217
219 {
220 // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
221 if (m_VoNToggled)
222 {
223 if (!VONManager.IsVoiceThresholdMinimum())
224 {
226 }
227 }
228 break;
229 }
230
232 {
233 if (!mission)
234 {
235 break;
236 }
237
238 VONStateEventParams vonStateParams = VONStateEventParams.Cast( params );
239 mission.SetVoNActive(vonStateParams.param1);
240 m_VoNToggled = vonStateParams.param2;
241
242 UpdateVoiceIcon();
243
244 m_OnVonStateEvent.Invoke();
245 break;
246 }
247
249 {
251 break;
252 }
253
255 {
256 VONStartSpeakingEventParams vonStartParams;
257 if (Class.CastTo(vonStartParams, params))
258 {
259 GetDayZGame().AddVoiceNotification(vonStartParams);
260 }
261 break;
262 }
263
265 {
266 VONStopSpeakingEventParams vonStopParams;
267 if (Class.CastTo(vonStopParams, params))
268 {
269 GetDayZGame().RemoveVoiceNotification(vonStopParams);
270 }
271 break;
272 }
273
275 {
276 UpdateVoiceIcon();
277 break;
278 }
279 }
280 }
281}
282
284class VONManager
285{
286 private static ref VONManagerBase m_VONManager = new VONManagerBase();
287
292 static VONManagerBase GetInstance()
293 {
294 return m_VONManager;
295 }
296
300 static void Init()
301 {
302 delete m_VONManager;
303 m_VONManager = new VONManagerImplementation();
304 }
305
309 static void CleanupInstance()
310 {
311 delete m_VONManager;
312 m_VONManager = new VONManagerBase();
313 }
314
319 static bool IsVONToggled()
320 {
321 return m_VONManager.IsVonToggled();
322 }
323
328 static bool IsVoiceThresholdMinimum()
329 {
330 GameOptions gameOptions = new GameOptions();
331 NumericOptionsAccess noa;
332 Class.CastTo(noa, gameOptions.GetOptionByType( OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER ));
333
334 return noa.ReadValue() <= GetGame().GetSoundScene().GetSilenceThreshold();
335 }
336}
Super root of all classes in Enforce script.
Definition enscript.c:11
Definition input.c:11
TODO doc.
Definition enscript.c:118
Mission class.
Definition gameplay.c:687
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
void OnEvent(EventType eventTypeId, Param params)
bool m_VoNToggled
Definition vonmanager.c:3
void HandleInput(Input inp)
void ShowVoiceNotification(int level, bool fading)
void VONManagerBase()
Definition vonmanager.c:7
void HideVoiceNotification()
void OnVOIPThresholdChanged()
bool IsVonToggled()
Definition vonmanager.c:18
ref ScriptInvoker m_OnVonStateEvent
Definition vonmanager.c:4
ref ScriptInvoker m_OnPartyChatChangedEvent
Definition vonmanager.c:5
DayZGame GetDayZGame()
Definition dayzgame.c:3870
Mission mission
const EventType PartyChatStatusChangedEventTypeID
no params
Definition gameplay.c:561
const EventType VONStartSpeakingEventTypeID
params: VONStartSpeakingEventParams
Definition gameplay.c:551
const EventType VONStateEventTypeID
params: VONStateEventParams
Definition gameplay.c:549
const EventType VONUserStoppedTransmittingAudioEventTypeID
no params
Definition gameplay.c:557
const EventType VONUserStartedTransmittingAudioEventTypeID
no params
Definition gameplay.c:555
const EventType VONStopSpeakingEventTypeID
params: VONStopSpeakingEventParams
Definition gameplay.c:553
const EventType MPSessionPlayerReadyEventTypeID
no params
Definition gameplay.c:481
proto native CGame GetGame()
OptionAccessType
C++ OptionAccessType.
Definition gameplay.c:1224
TypeID EventType
Definition enwidgets.c:55
bool m_VoNToggled
Definition vonmanager.c:27
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
void VONManagerBase()
Definition vonmanager.c:31