Dayz Explorer  1.24.157551 (v105080)
Dayz Code Explorer by Zeroy
optionsmenusounds.c
Go to the documentation of this file.
1 class OptionsMenuSounds extends ScriptedWidgetEventHandler
2 {
3  protected Widget m_Root;
4 
5  protected Widget m_SettingsRoot;
6  protected Widget m_DetailsRoot;
7  protected Widget m_DetailsBodyDefault;
8  protected Widget m_DetailsBodyConnectivity;
9  protected TextWidget m_DetailsLabel;
10  protected RichTextWidget m_DetailsText;
11 
12  protected ref NumericOptionsAccess m_MasterOption;
13  protected ref NumericOptionsAccess m_EffectsOption;
14  protected ref NumericOptionsAccess m_VOIPOption;
15  protected ref NumericOptionsAccess m_VOIPThresholdOption;
16  protected ref NumericOptionsAccess m_MusicOption;
17  protected ref ListOptionsAccess m_InputModeOption;
18 
19  protected ref OptionSelectorSlider m_MasterSelector;
20  protected ref OptionSelectorSlider m_EffectsSelector;
21  protected ref OptionSelectorSlider m_VOIPSelector;
22  protected ref OptionSelectorLevelMarker m_VOIPThresholdSelector;
23  protected ref OptionSelectorSlider m_MusicSelector;
24  protected ref OptionSelectorMultistate m_InputModeSelector;
25 
26  protected ref Timer m_AudioLevelTimer;
27  protected GameOptions m_Options;
28  protected OptionsMenu m_Menu;
29  protected MissionGameplay m_MissionGameplay;
30  protected VONManagerBase m_VonManager;
31 
32  protected ref map<int, ref Param2<string, string>> m_TextMap;
33 
34  private bool m_WasMicCapturing;
35 
36  void OptionsMenuSounds(Widget parent, Widget details_root, GameOptions options, OptionsMenu menu)
37  {
38  m_Root = GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
39  m_DetailsRoot = details_root;
40  m_DetailsBodyDefault = m_DetailsRoot.FindAnyWidget("settings_details_body");
41  m_DetailsBodyConnectivity = m_DetailsRoot.FindAnyWidget("settings_details_body_connectivity");
42  m_DetailsLabel = TextWidget.Cast( m_DetailsRoot.FindAnyWidget("details_label"));
43  m_DetailsText = RichTextWidget.Cast( m_DetailsRoot.FindAnyWidget("details_content"));
44  m_Options = options;
45  m_Menu = menu;
46 
47  m_MasterOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MASTER_VOLUME));
48  m_EffectsOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER));
49  m_MusicOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER));
50  m_VOIPOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_SLIDER));
51  m_VOIPThresholdOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER));
52  m_InputModeOption = ListOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE));
53 
54  m_MissionGameplay = MissionGameplay.Cast(GetGame().GetMission());
55  m_VonManager = VONManager.GetInstance();
56  m_AudioLevelTimer = new Timer();
57  m_AudioLevelTimer.Run(0.1, this, "UpdateAudioLevel", NULL, true);
58 
59  m_Root.FindAnyWidget( "master_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_MASTER_VOLUME);
60  m_Root.FindAnyWidget( "effects_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER);
61  m_Root.FindAnyWidget( "music_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER);
62  m_Root.FindAnyWidget( "voip_output_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_SLIDER);
63  m_Root.FindAnyWidget( "voip_threshold_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER);
64  m_Root.FindAnyWidget( "voip_selection_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE);
65 
66  FillTextMap();
67 
68  array<string> inputModeValues = { "#STR_Controls_PushToTalk", "#STR_USRACT_UAVOICEOVERNETTOGGLE" };
69 
70  m_MasterSelector = new OptionSelectorSlider(m_Root.FindAnyWidget("master_setting_option" ), m_MasterOption.ReadValue(), this, false, m_MasterOption.GetMin(), m_MasterOption.GetMax());
71  m_EffectsSelector = new OptionSelectorSlider(m_Root.FindAnyWidget("effects_setting_option" ), m_EffectsOption.ReadValue(), this, false, m_EffectsOption.GetMin(), m_EffectsOption.GetMax());
72  m_VOIPSelector = new OptionSelectorSlider(m_Root.FindAnyWidget("voip_output_setting_option" ), m_VOIPOption.ReadValue(), this, false, m_VOIPOption.GetMin(), m_VOIPOption.GetMax());
73  m_VOIPThresholdSelector = new OptionSelectorLevelMarker(m_Root.FindAnyWidget("voip_threshold_setting_option" ), m_VOIPThresholdOption.ReadValue(), this, false, m_VOIPThresholdOption.GetMin(), m_VOIPThresholdOption.GetMax());
74  m_MusicSelector = new OptionSelectorSlider(m_Root.FindAnyWidget("music_setting_option" ), m_MusicOption.ReadValue(), this, false, m_MusicOption.GetMin(), m_MusicOption.GetMax());
75  m_InputModeSelector = new OptionSelectorMultistate(m_Root.FindAnyWidget("voip_selection_setting_option" ), m_InputModeOption.GetIndex(), this, false, inputModeValues);
76 
77  m_MasterSelector.m_OptionChanged.Insert(UpdateMaster);
78  m_EffectsSelector.m_OptionChanged.Insert(UpdateEffects);
79  m_VOIPSelector.m_OptionChanged.Insert(UpdateVOIP);
80  m_VOIPThresholdSelector.m_OptionChanged.Insert(UpdateVOIPThreshold);
81  m_MusicSelector.m_OptionChanged.Insert(UpdateMusic);
82  m_InputModeSelector.m_OptionChanged.Insert(UpdateInputMode);
83 
84  if (m_MissionGameplay)
85  {
86  // event to monitor when options get reverted directly from C++
87  m_VOIPThresholdOption.GetEvents().Event_OnRevert.Insert(m_VonManager.OnVOIPThresholdChanged);
88  m_VonManager.m_OnVonStateEvent.Insert(OnVonStateEvent);
89  m_VonManager.m_OnPartyChatChangedEvent.Insert(OnPartyChatChangedEvent);
90  m_VOIPThresholdSelector.m_OptionChanged.Insert(m_VonManager.OnVOIPThresholdChanged);
91  }
92 
93  float x, y, y2;
94  m_Root.FindAnyWidget("sound_settings_scroll").GetScreenSize(x, y);
95  m_Root.FindAnyWidget("sound_settings_root").GetScreenSize(x, y2);
96  int f = (y2 > y);
97  m_Root.FindAnyWidget("sound_settings_scroll").SetAlpha(f);
98 
99  m_Root.SetHandler(this);
100 
101  CGame game = GetGame();
102  m_WasMicCapturing = game.IsMicCapturing();
103 
104  // do not enable mic capture if user in party chat
105  if (!game.IsInPartyChat())
106  {
107  game.EnableMicCapture(true);
108  }
109  }
110 
111  void ~OptionsMenuSounds()
112  {
113  m_VonManager.m_OnVonStateEvent.Remove(OnVonStateEvent);
114  m_VonManager.m_OnPartyChatChangedEvent.Remove(OnPartyChatChangedEvent);
115 
116  if (m_MissionGameplay)
117  {
118  // reset mic to previous capturing state
119  GetGame().EnableMicCapture(m_WasMicCapturing);
120  }
121 
122  m_AudioLevelTimer.Stop();
123  }
124 
125  string GetLayoutName()
126  {
127  #ifdef PLATFORM_CONSOLE
128  return "gui/layouts/new_ui/options/xbox/sound_tab.layout";
129  #else
130  #ifdef PLATFORM_WINDOWS
131  return "gui/layouts/new_ui/options/pc/sound_tab.layout";
132  #endif
133  #endif
134  }
135 
136  void Focus()
137  {
138  #ifdef PLATFORM_CONSOLE
139  SetFocus(m_MasterSelector.GetParent());
140  #endif
141  }
142 
143  override bool OnMouseEnter(Widget w, int x, int y)
144  {
145  if ( w && w.IsInherited(ScrollWidget))
146  {
147  return false;
148  }
149 
150  m_Menu.ColorHighlight(w);
151 
152  return true;
153  }
154 
155  override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
156  {
157  if ( w && w.IsInherited(ScrollWidget))
158  {
159  return false;
160  }
161 
162  m_Menu.ColorNormal(w);
163  return true;
164  }
165 
166  override bool OnFocus(Widget w, int x, int y)
167  {
168  OptionsMenu menu = OptionsMenu.Cast(GetGame().GetUIManager().GetMenu());
169  if (menu)
170  {
171  menu.OnFocus(w, x, y);
172  }
173  if (w)
174  {
175  if (TextMapUpdateWidget(w.GetUserID()))
176  {
177  return true;
178  }
179 
180  if (w.IsInherited(SliderWidget))
181  {
182  return true;
183  }
184  }
185  m_DetailsRoot.Show(false);
186  return (w != null);
187  }
188 
189  bool TextMapUpdateWidget(int key)
190  {
191  bool connectivityInfoShown = key == OptionIDsScript.OPTION_CONNECTIVITY_INFO;
193  Param tmp = m_TextMap.Get(key);
194 
195  m_DetailsBodyDefault.Show(!connectivityInfoShown);
196  m_DetailsBodyConnectivity.Show(connectivityInfoShown);
197 
198  if (Class.CastTo(p,tmp))
199  {
200  m_DetailsRoot.Show(true);
201  m_DetailsText.Show(true);
202  m_DetailsLabel.SetText(p.param1);
203  m_DetailsText.SetText(p.param2);
204 
205  m_DetailsText.Update();
206  m_DetailsLabel.Update();
207  m_DetailsRoot.Update();
208  m_DetailsBodyConnectivity.Update(); //...
209  return true;
210  }
211  return false;
212  }
213 
214  void OnVonStateEvent()
215  {
216  // changing VON mode may disable mic capture,
217  // but mic should capture the entire time this menu is open (unless user in party chat)
218  if (!GetGame().IsInPartyChat())
219  {
220  // force enable mic capture
221  GetGame().EnableMicCapture(true);
222  }
223 
224  UpdateWasMicCapturing();
225  }
226 
227  void OnPartyChatChangedEvent()
228  {
229  auto game = GetGame();
230  if (!game.IsInPartyChat())
231  {
232  game.EnableMicCapture(true);
233  }
234 
235  UpdateWasMicCapturing();
236  }
237 
238  // updates the mic capture state to reset to, when this menu closes
239  void UpdateWasMicCapturing()
240  {
241  // if user is in party chat, then mic should not capture
242  if (GetGame().IsInPartyChat())
243  {
244  m_WasMicCapturing = false;
245  }
246 
247  // otherwise, mic should capture ONLY if Voice Activation is enabled
248  else
249  {
250  m_WasMicCapturing = m_MissionGameplay.IsVoNActive();
251  }
252  }
253 
254  bool IsChanged()
255  {
256  return false;
257  }
258 
259  void Apply()
260  {
261 
262  }
263 
264  void Revert()
265  {
266  if (m_MasterOption)
267  {
268  m_MasterSelector.SetValue(m_MasterOption.ReadValue(), true);
269  }
270  if (m_EffectsOption)
271  {
272  m_EffectsSelector.SetValue(m_EffectsOption.ReadValue(),true);
273  }
274  if (m_VOIPOption)
275  {
276  m_VOIPSelector.SetValue(m_VOIPOption.ReadValue(), true);
277  }
278  if (m_VOIPThresholdOption)
279  {
280  m_VOIPThresholdSelector.SetValue(m_VOIPThresholdOption.ReadValue(), true);
281  }
282  if (m_MusicOption)
283  {
284  m_MusicSelector.SetValue(m_MusicOption.ReadValue(), true);
285  }
286  if (m_InputModeOption)
287  {
288  m_InputModeSelector.SetValue(m_InputModeOption.GetIndex(), false);
289  }
290  }
291 
292  void SetToDefaults()
293  {
294  if (m_MasterOption)
295  {
296  m_MasterSelector.SetValue(m_MasterOption.GetDefault(), true);
297  }
298  if (m_EffectsOption)
299  {
300  m_EffectsSelector.SetValue(m_EffectsOption.GetDefault(), true);
301  }
302  if (m_VOIPOption)
303  {
304  m_VOIPSelector.SetValue(m_VOIPOption.GetDefault(), true);
305  }
306  if (m_VOIPThresholdOption)
307  {
308  m_VOIPThresholdSelector.SetValue(m_VOIPThresholdOption.GetDefault(), true);
309  }
310  if (m_MusicOption)
311  {
312  m_MusicSelector.SetValue(m_MusicOption.GetDefault(), true);
313  }
314  if (m_InputModeOption)
315  {
316  m_InputModeOption.SetIndex(m_InputModeOption.GetDefaultIndex());
317  m_InputModeSelector.SetValue( m_InputModeOption.GetIndex(), false );
318  }
319  }
320 
321  void ReloadOptions()
322  {
323  m_Menu.ReloadOptions();
324  }
325 
326  void SetOptions(GameOptions options)
327  {
328  m_Options = options;
329 
330  m_MasterOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MASTER_VOLUME));
331  m_EffectsOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER));
332  m_MusicOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER));
333  m_VOIPOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_SLIDER));
334  m_InputModeOption = ListOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE));
335  m_VOIPThresholdOption = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER));
336 
337  Revert();
338  }
339 
340  void ToggleDependentOptions(int mode, bool state)
341  {
342  }
343 
344  void InitDependentOptionsVisibility()
345  {
346  }
347 
348  void UpdateMaster(float value)
349  {
350  m_MasterOption.WriteValue(value);
351  m_Menu.OnChanged();
352  }
353 
354  void UpdateEffects(float value)
355  {
356  m_EffectsOption.WriteValue(value);
357  m_Menu.OnChanged();
358  }
359 
360  void UpdateVOIP(float value)
361  {
362  m_VOIPOption.WriteValue(value);
363  m_Menu.OnChanged();
364  }
365 
366  void UpdateVOIPThreshold(float value)
367  {
368  m_VOIPThresholdOption.WriteValue(value);
369  m_Menu.OnChanged();
370  }
371 
372  void UpdateMusic(float value)
373  {
374  m_MusicOption.WriteValue(value);
375  m_Menu.OnChanged();
376  }
377 
378  void UpdateInputMode(int newIndex)
379  {
380  m_InputModeOption.SetIndex(newIndex);
381  m_Menu.OnChanged();
382  }
383 
384  void UpdateAudioLevel()
385  {
386  m_VOIPThresholdSelector.SetSlider2Value(GetGame().GetSoundScene().GetAudioLevel());
387  }
388 
389 
390  void FillTextMap()
391  {
392  m_TextMap = new map<int, ref Param2<string, string>>;
393 
394  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_MASTER_VOLUME, new Param2<string, string>("#STR_sound_tab_master_tip_header", "#STR_sound_tab_master_tip"));
395  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER, new Param2<string, string>("#STR_sound_tab_effects_tip_header", "#STR_sound_tab_effects_tip"));
396  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER, new Param2<string, string>("#STR_sound_tab_music_tip_header", "#STR_sound_tab_music_tip"));
397 
398  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_VON_SLIDER, new Param2<string, string>("#STR_sound_tab_voice_output_tip_header", "#STR_sound_tab_voice_output_tip"));
399  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER, new Param2<string, string>("#STR_sound_tab_voice_threshold_tip_header", "#STR_sound_tab_voice_threshold_tip"));
400  m_TextMap.Insert(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE, new Param2<string, string>("#STR_sound_tab_voice_mode_tip_header", "#STR_sound_tab_voice_mode_tip"));
401  }
402 }
Param2< string, string >
GetGame
proto native CGame GetGame()
OptionIDsScript
OptionIDsScript
Used for script-based game options. For anything C++ based, you would most likely use "Option Access ...
Definition: gameplay.c:1264
VONManagerBase
Definition: vonmanager.c:1
Focus
void Focus()
Definition: serverbrowsertab.c:181
Param
Base Param Class with no parameters. Used as general purpose parameter overloaded with Param1 to Para...
Definition: param.c:11
y
Icon y
GameOptions
Definition: gameplay.c:1420
m_Menu
protected ServerBrowserMenuNew m_Menu
Definition: serverbrowsertab.c:30
UpdateMusic
void UpdateMusic()
Definition: anniversarymusicsource.c:55
OnMouseLeave
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
Definition: uihintpanel.c:276
RichTextWidget
Definition: gameplay.c:315
map
map
Definition: controlsxboxnew.c:3
TextWidget
Definition: enwidgets.c:219
OptionAccessType
OptionAccessType
C++ OptionAccessType.
Definition: gameplay.c:1200
CGame
Definition: dayzgame.c:874
array< string >
SetFocus
proto native void SetFocus(Widget w)
x
Icon x
GetAudioLevel
proto native float GetAudioLevel()
VONManager
Manager class which handles Voice-over-network functionality while player is connected to a server.
Definition: vonmanager.c:275
Timer
Definition: dayzplayerimplement.c:62
OnFocus
override bool OnFocus(Widget w, int x, int y)
Definition: serverbrowsertab.c:217
Widget
Definition: enwidgets.c:189
m_Root
protected Widget m_Root
Definition: sizetochild.c:91
Class
Super root of all classes in Enforce script.
Definition: enscript.c:10
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: uihintpanel.c:267
ScriptedWidgetEventHandler
map: item x vector(index, width, height)
Definition: enwidgets.c:650