Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
vonmanager.c
Go to the documentation of this file.
2 {
3  protected bool m_VoNToggled;
4  ref ScriptInvoker m_OnVonStateEvent;
5  ref ScriptInvoker m_OnPartyChatChangedEvent;
6 
7  void VONManagerBase()
8  {
9  m_VoNToggled = false;
10  }
11 
12  void HideVoiceNotification();
13  void ShowVoiceNotification(int level, bool fading);
14  void HandleInput(Input inp);
15  void OnVOIPThresholdChanged();
16  void OnEvent(EventType eventTypeId, Param params);
17 
18  bool IsVonToggled()
19  {
20  return m_VoNToggled;
21  }
22 }
23 
25 {
27  {
30  }
31 
33  {
34  m_OnVonStateEvent.Clear();
36  }
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  GetGame().SetVoiceLevel(newLevel);
145  UpdateVoiceIcon();
146  }
147  }
148 
149  private void UpdateVoiceIcon()
150  {
151  Mission mission = GetGame().GetMission();
152  int rangeLevel = GetGame().GetVoiceLevel();
153 
154  if (mission.IsVoNActive())
155  {
156  if (m_VoNToggled)
157  {
158  if (VONManager.IsVoiceThresholdMinimum())
159  {
160  ShowVoiceNotification(rangeLevel, false);
161  }
162  else
163  {
164  ShowVoiceNotification(rangeLevel, true);
165  }
166  }
167  else
168  {
169  ShowVoiceNotification(rangeLevel, false);
170  }
171  }
172  else
173  {
175  }
176  }
177 
181  override void OnVOIPThresholdChanged()
182  {
183  UpdateVoiceIcon();
184  }
185 
191  override void OnEvent(EventType eventTypeId, Param params)
192  {
193  Mission mission = GetGame().GetMission();
194  switch (eventTypeId)
195  {
197  {
198  // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
199  if (m_VoNToggled)
200  {
201  if (!VONManager.IsVoiceThresholdMinimum())
202  {
203  ShowVoiceNotification(GetGame().GetVoiceLevel(), false);
204  }
205  }
206  break;
207  }
208 
210  {
211  // only handle this if we are in Voice Activation mode, so ignore if in PTT mode
212  if (m_VoNToggled)
213  {
214  if (!VONManager.IsVoiceThresholdMinimum())
215  {
217  }
218  }
219  break;
220  }
221 
222  case VONStateEventTypeID:
223  {
224  if (!mission)
225  {
226  break;
227  }
228 
229  VONStateEventParams vonStateParams = VONStateEventParams.Cast( params );
230  mission.SetVoNActive(vonStateParams.param1);
231  m_VoNToggled = vonStateParams.param2;
232 
233  UpdateVoiceIcon();
234 
235  m_OnVonStateEvent.Invoke();
236  break;
237  }
238 
240  {
241  m_OnPartyChatChangedEvent.Invoke();
242  break;
243  }
244 
246  {
247  VONStartSpeakingEventParams vonStartParams;
248  if (Class.CastTo(vonStartParams, params))
249  {
250  GetDayZGame().AddVoiceNotification(vonStartParams);
251  }
252  break;
253  }
254 
256  {
257  VONStopSpeakingEventParams vonStopParams;
258  if (Class.CastTo(vonStopParams, params))
259  {
260  GetDayZGame().RemoveVoiceNotification(vonStopParams);
261  }
262  break;
263  }
264 
266  {
267  UpdateVoiceIcon();
268  break;
269  }
270  }
271  }
272 }
273 
276 {
277  private static ref VONManagerBase m_VONManager = new VONManagerBase();
278 
283  static VONManagerBase GetInstance()
284  {
285  return m_VONManager;
286  }
287 
291  static void Init()
292  {
293  delete m_VONManager;
294  m_VONManager = new VONManagerImplementation();
295  }
296 
300  static void CleanupInstance()
301  {
302  delete m_VONManager;
303  m_VONManager = new VONManagerBase();
304  }
305 
310  static bool IsVONToggled()
311  {
312  return m_VONManager.IsVonToggled();
313  }
314 
319  static bool IsVoiceThresholdMinimum()
320  {
321  GameOptions gameOptions = new GameOptions();
322  NumericOptionsAccess noa;
323  Class.CastTo(noa, gameOptions.GetOptionByType( OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER ));
324 
325  return noa.ReadValue() <= GetGame().GetSoundScene().GetSilenceThreshold();
326  }
327 }
Param2
Definition: ppeconstants.c:66
GetGame
proto native CGame GetGame()
HandleInput
void HandleInput(Input inp)
Handles some VON related input.
Definition: vonmanager.c:113
mission
Mission mission
Definition: displaystatus.c:28
VONManagerBase
Definition: vonmanager.c:1
HideVoiceNotification
void HideVoiceNotification()
Hides the VON notification completely and immediately.
Definition: vonmanager.c:41
VONUserStoppedTransmittingAudioEventTypeID
const EventType VONUserStoppedTransmittingAudioEventTypeID
no params
Definition: gameplay.c:544
Mission
Mission class.
Definition: gameplay.c:670
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
GetDayZGame
DayZGame GetDayZGame()
Definition: dayzgame.c:3729
VONUserStartedTransmittingAudioEventTypeID
const EventType VONUserStartedTransmittingAudioEventTypeID
no params
Definition: gameplay.c:542
PartyChatStatusChangedEventTypeID
const EventType PartyChatStatusChangedEventTypeID
no params
Definition: gameplay.c:548
m_OnPartyChatChangedEvent
ref ScriptInvoker m_OnPartyChatChangedEvent
Definition: vonmanager.c:4
UpdateVoiceIcon
private void UpdateVoiceIcon()
Definition: vonmanager.c:149
Managed
TODO doc.
Definition: enscript.c:117
GameOptions
Definition: gameplay.c:1420
MPSessionPlayerReadyEventTypeID
const EventType MPSessionPlayerReadyEventTypeID
no params
Definition: gameplay.c:468
VONStateEventTypeID
const EventType VONStateEventTypeID
params: VONStateEventParams
Definition: gameplay.c:536
EventType
TypeID EventType
Definition: enwidgets.c:55
map
map
Definition: controlsxboxnew.c:3
VONStopSpeakingEventTypeID
const EventType VONStopSpeakingEventTypeID
params: VONStopSpeakingEventParams
Definition: gameplay.c:540
OptionAccessType
OptionAccessType
C++ OptionAccessType.
Definition: gameplay.c:1200
Input
Definition: input.c:10
VONManagerBase
void VONManagerBase()
Definition: vonmanager.c:6
VONStartSpeakingEventTypeID
const EventType VONStartSpeakingEventTypeID
params: VONStartSpeakingEventParams
Definition: gameplay.c:538
VONManager
Manager class which handles Voice-over-network functionality while player is connected to a server.
Definition: vonmanager.c:275
m_VoNToggled
protected bool m_VoNToggled
Definition: vonmanager.c:2
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
OnVOIPThresholdChanged
void OnVOIPThresholdChanged()
Fires every time VOIP threshold value changes.
Definition: vonmanager.c:181
~VONManagerImplementation
void ~VONManagerImplementation()
Definition: vonmanager.c:32
VONManagerImplementation
VONManagerBase Managed VONManagerImplementation()
Definition: vonmanager.c:26
ShowVoiceNotification
void ShowVoiceNotification(int level, bool fading)
Shows the voice notification.
Definition: vonmanager.c:58
m_OnVonStateEvent
ref ScriptInvoker m_OnVonStateEvent
Definition: vonmanager.c:3
OnEvent
void OnEvent(EventType eventTypeId, Param params)
Handles VON-related events.
Definition: vonmanager.c:191
ScriptInvoker
ScriptInvoker Class provide list of callbacks usage:
Definition: tools.c:115