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