File size: 13,111 Bytes
24b81cb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
class OptionsMenuSounds extends ScriptedWidgetEventHandler
{
	protected Widget						m_Root;
	
	protected Widget						m_SettingsRoot;
	protected Widget						m_DetailsRoot;
	protected Widget						m_DetailsBodyDefault;
	protected Widget						m_DetailsBodyConnectivity;
	protected TextWidget					m_DetailsLabel;
	protected RichTextWidget				m_DetailsText;
	
	protected ref NumericOptionsAccess		m_MasterOption;
	protected ref NumericOptionsAccess		m_EffectsOption;
	protected ref NumericOptionsAccess		m_VOIPOption;
	protected ref NumericOptionsAccess  	m_VOIPThresholdOption;
	protected ref NumericOptionsAccess		m_MusicOption;
	protected ref ListOptionsAccess			m_InputModeOption;
	
	protected ref OptionSelectorSlider		m_MasterSelector;
	protected ref OptionSelectorSlider		m_EffectsSelector;
	protected ref OptionSelectorSlider		m_VOIPSelector;
	protected ref OptionSelectorLevelMarker	m_VOIPThresholdSelector;
	protected ref OptionSelectorSlider		m_MusicSelector;
	protected ref OptionSelectorMultistate	m_InputModeSelector;
	
	protected ref Timer 					m_AudioLevelTimer;
	protected GameOptions					m_Options;
	protected OptionsMenu					m_Menu;
	protected MissionGameplay				m_MissionGameplay;
	protected VONManagerBase				m_VonManager;
	
	protected ref map<int, ref Param2<string, string>> m_TextMap;
	
	private bool 							m_WasMicCapturing;
	
	void OptionsMenuSounds(Widget parent, Widget details_root, GameOptions options, OptionsMenu menu)
	{
		m_Root					= GetGame().GetWorkspace().CreateWidgets(GetLayoutName(), parent);
		m_DetailsRoot			= details_root;
		m_DetailsBodyDefault 		= m_DetailsRoot.FindAnyWidget("settings_details_body");
		m_DetailsBodyConnectivity 	= m_DetailsRoot.FindAnyWidget("settings_details_body_connectivity");
		m_DetailsLabel			= TextWidget.Cast( m_DetailsRoot.FindAnyWidget("details_label"));
		m_DetailsText			= RichTextWidget.Cast( m_DetailsRoot.FindAnyWidget("details_content"));	
		m_Options				= options;
		m_Menu					= menu;
		
		m_MasterOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MASTER_VOLUME));
		m_EffectsOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER));
		m_MusicOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER));
		m_VOIPOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_SLIDER));
		m_VOIPThresholdOption	= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER));
		m_InputModeOption		= ListOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE));
		
		m_MissionGameplay		= MissionGameplay.Cast(GetGame().GetMission());
		m_VonManager 			= VONManager.GetInstance();
		m_AudioLevelTimer = new Timer();
		m_AudioLevelTimer.Run(0.1, this, "UpdateAudioLevel", NULL, true); 
		
		m_Root.FindAnyWidget( "master_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_MASTER_VOLUME);
		m_Root.FindAnyWidget( "effects_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER);
		m_Root.FindAnyWidget( "music_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER);
		m_Root.FindAnyWidget( "voip_output_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_SLIDER);
		m_Root.FindAnyWidget( "voip_threshold_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER);
		m_Root.FindAnyWidget( "voip_selection_setting_option" ).SetUserID(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE);
		
		FillTextMap();
		
		array<string> inputModeValues = { "#STR_Controls_PushToTalk", "#STR_USRACT_UAVOICEOVERNETTOGGLE" };
		
		m_MasterSelector			= new OptionSelectorSlider(m_Root.FindAnyWidget("master_setting_option" ), m_MasterOption.ReadValue(), this, false, m_MasterOption.GetMin(), m_MasterOption.GetMax());
		m_EffectsSelector			= new OptionSelectorSlider(m_Root.FindAnyWidget("effects_setting_option" ), m_EffectsOption.ReadValue(), this, false, m_EffectsOption.GetMin(), m_EffectsOption.GetMax());
		m_VOIPSelector				= new OptionSelectorSlider(m_Root.FindAnyWidget("voip_output_setting_option" ), m_VOIPOption.ReadValue(), this, false, m_VOIPOption.GetMin(), m_VOIPOption.GetMax());
		m_VOIPThresholdSelector  	= new OptionSelectorLevelMarker(m_Root.FindAnyWidget("voip_threshold_setting_option" ), m_VOIPThresholdOption.ReadValue(), this, false, m_VOIPThresholdOption.GetMin(), m_VOIPThresholdOption.GetMax());
		m_MusicSelector				= new OptionSelectorSlider(m_Root.FindAnyWidget("music_setting_option" ), m_MusicOption.ReadValue(), this, false, m_MusicOption.GetMin(), m_MusicOption.GetMax());
		m_InputModeSelector			= new OptionSelectorMultistate(m_Root.FindAnyWidget("voip_selection_setting_option" ), m_InputModeOption.GetIndex(), this, false, inputModeValues);
		
		m_MasterSelector.m_OptionChanged.Insert(UpdateMaster);
		m_EffectsSelector.m_OptionChanged.Insert(UpdateEffects);
		m_VOIPSelector.m_OptionChanged.Insert(UpdateVOIP);
		m_VOIPThresholdSelector.m_OptionChanged.Insert(UpdateVOIPThreshold);
		m_MusicSelector.m_OptionChanged.Insert(UpdateMusic);
		m_InputModeSelector.m_OptionChanged.Insert(UpdateInputMode);
		
		if (m_MissionGameplay)
		{
			// event to monitor when options get reverted directly from C++
			m_VOIPThresholdOption.GetEvents().Event_OnRevert.Insert(m_VonManager.OnVOIPThresholdChanged);
			m_VonManager.m_OnVonStateEvent.Insert(OnVonStateEvent);
			m_VonManager.m_OnPartyChatChangedEvent.Insert(OnPartyChatChangedEvent);
			m_VOIPThresholdSelector.m_OptionChanged.Insert(m_VonManager.OnVOIPThresholdChanged);
		}
		
		float x, y, y2;
		m_Root.FindAnyWidget("sound_settings_scroll").GetScreenSize(x, y);
		m_Root.FindAnyWidget("sound_settings_root").GetScreenSize(x, y2);
		int f = (y2 > y);
		m_Root.FindAnyWidget("sound_settings_scroll").SetAlpha(f);
		
		m_Root.SetHandler(this);
		
		CGame game = GetGame();
		m_WasMicCapturing = game.IsMicCapturing();

		// do not enable mic capture if user in party chat
		if (!game.IsInPartyChat())
		{
			game.EnableMicCapture(true);
		}
	}
	
	void ~OptionsMenuSounds()
	{
		m_VonManager.m_OnVonStateEvent.Remove(OnVonStateEvent);	
		m_VonManager.m_OnPartyChatChangedEvent.Remove(OnPartyChatChangedEvent);
		
		if (m_MissionGameplay)
		{
			// reset mic to previous capturing state
			GetGame().EnableMicCapture(m_WasMicCapturing);		
		}

		m_AudioLevelTimer.Stop();
	}
	
	string GetLayoutName()
	{
		#ifdef PLATFORM_CONSOLE
			return "gui/layouts/new_ui/options/xbox/sound_tab.layout";
		#else
		#ifdef PLATFORM_WINDOWS
			return "gui/layouts/new_ui/options/pc/sound_tab.layout";
		#endif
		#endif
	}
	
	void Focus()
	{
		#ifdef PLATFORM_CONSOLE
			SetFocus(m_MasterSelector.GetParent());
		#endif
	}
	
	override bool OnMouseEnter(Widget w, int x, int y)
	{
		if ( w && w.IsInherited(ScrollWidget))
		{
			return false;
		}
		
		m_Menu.ColorHighlight(w);
		
		return true;
	}
	
	override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
	{
		if ( w && w.IsInherited(ScrollWidget))
		{
			return false;
		}
		
		m_Menu.ColorNormal(w);
		return true;
	}
	
	override bool OnFocus(Widget w, int x, int y)
	{
		OptionsMenu menu = OptionsMenu.Cast(GetGame().GetUIManager().GetMenu());
		if (menu)
		{
			menu.OnFocus(w, x, y);
		}
		if (w)
		{
			if (TextMapUpdateWidget(w.GetUserID())) 
			{
				return true;
			}
			
			if (w.IsInherited(SliderWidget))
			{
				return true;
			}
		}
		m_DetailsRoot.Show(false);
		return (w != null);
	}
	
	bool TextMapUpdateWidget(int key)
	{
		bool connectivityInfoShown = key == OptionIDsScript.OPTION_CONNECTIVITY_INFO;
		Param2<string, string> p;
		Param tmp = m_TextMap.Get(key);
		
		m_DetailsBodyDefault.Show(!connectivityInfoShown);
		m_DetailsBodyConnectivity.Show(connectivityInfoShown);
		
		if (Class.CastTo(p,tmp))
		{
			m_DetailsRoot.Show(true);
			m_DetailsText.Show(true);
			m_DetailsLabel.SetText(p.param1);
			m_DetailsText.SetText(p.param2);
			
			m_DetailsText.Update();
			m_DetailsLabel.Update();
			m_DetailsRoot.Update();
			m_DetailsBodyConnectivity.Update(); //...
			return true;
		}
		return false;
	}

	void OnVonStateEvent()
	{		
		// changing VON mode may disable mic capture,
		// but mic should capture the entire time this menu is open (unless user in party chat)
		if (!GetGame().IsInPartyChat())
		{
			// force enable mic capture
			GetGame().EnableMicCapture(true);
		}
		
		UpdateWasMicCapturing();
	}
	
	void OnPartyChatChangedEvent()
	{
		auto game = GetGame();
		if (!game.IsInPartyChat())
		{
			game.EnableMicCapture(true);
		}
		
		UpdateWasMicCapturing();
	}
	
	// updates the mic capture state to reset to, when this menu closes
	void UpdateWasMicCapturing()
	{
		// if user is in party chat, then mic should not capture
		if (GetGame().IsInPartyChat())
		{
			m_WasMicCapturing = false;
		}
		
		// otherwise, mic should capture ONLY if Voice Activation is enabled
		else
		{
			m_WasMicCapturing = m_MissionGameplay.IsVoNActive();
		}
	}
	
	bool IsChanged()
	{
		return false;
	}
	
	void Apply()
	{
		
	}
	
	void Revert()
	{
		if (m_MasterOption)
		{
			m_MasterSelector.SetValue(m_MasterOption.ReadValue(), true);
		}
		if (m_EffectsOption)
		{
			m_EffectsSelector.SetValue(m_EffectsOption.ReadValue(),true);
		}
		if (m_VOIPOption)
		{
			m_VOIPSelector.SetValue(m_VOIPOption.ReadValue(), true);
		}
		if (m_VOIPThresholdOption)
		{
			m_VOIPThresholdSelector.SetValue(m_VOIPThresholdOption.ReadValue(), true);
		}
		if (m_MusicOption)
		{
			m_MusicSelector.SetValue(m_MusicOption.ReadValue(), true);
		}
		if (m_InputModeOption)
		{
			m_InputModeSelector.SetValue(m_InputModeOption.GetIndex(), false);
		}
	}
	
	void SetToDefaults()
	{
		if (m_MasterOption)
		{
			m_MasterSelector.SetValue(m_MasterOption.GetDefault(), true);
		}
		if (m_EffectsOption)
		{
			m_EffectsSelector.SetValue(m_EffectsOption.GetDefault(), true);
		}
		if (m_VOIPOption)
		{
			m_VOIPSelector.SetValue(m_VOIPOption.GetDefault(), true);
		}
		if (m_VOIPThresholdOption)
		{
			m_VOIPThresholdSelector.SetValue(m_VOIPThresholdOption.GetDefault(), true);
		}
		if (m_MusicOption)
		{
			m_MusicSelector.SetValue(m_MusicOption.GetDefault(), true);
		}
		if (m_InputModeOption)
		{
			m_InputModeOption.SetIndex(m_InputModeOption.GetDefaultIndex());
			m_InputModeSelector.SetValue( m_InputModeOption.GetIndex(), false );
		}
	}
	
	void ReloadOptions()
	{
		m_Menu.ReloadOptions();
	}
	
	void SetOptions(GameOptions options)
	{
		m_Options = options;
		
		m_MasterOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MASTER_VOLUME));
		m_EffectsOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER));
		m_MusicOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER));
		m_VOIPOption			= NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_SLIDER));
		m_InputModeOption		= ListOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_INPUT_MODE));
		m_VOIPThresholdOption   = NumericOptionsAccess.Cast(m_Options.GetOptionByType(OptionAccessType.AT_OPTIONS_VON_THRESHOLD_SLIDER));
		
		Revert();
	}
	
	void ToggleDependentOptions(int mode, bool state)
	{
	}
	
	void InitDependentOptionsVisibility()
	{
	}
	
	void UpdateMaster(float value)
	{
		m_MasterOption.WriteValue(value);
		m_Menu.OnChanged();
	}
	
	void UpdateEffects(float value)
	{
		m_EffectsOption.WriteValue(value);
		m_Menu.OnChanged();
	}
	
	void UpdateVOIP(float value)
	{
		m_VOIPOption.WriteValue(value);
		m_Menu.OnChanged();
	}
	
	void UpdateVOIPThreshold(float value)
	{
		m_VOIPThresholdOption.WriteValue(value);
		m_Menu.OnChanged();
	}
	
	void UpdateMusic(float value)
	{
		m_MusicOption.WriteValue(value);
		m_Menu.OnChanged();
	}
	
	void UpdateInputMode(int newIndex)
	{
		m_InputModeOption.SetIndex(newIndex);
		m_Menu.OnChanged();
	}
	
	void UpdateAudioLevel()
	{	
		m_VOIPThresholdSelector.SetSlider2Value(GetGame().GetSoundScene().GetAudioLevel());
	}
	
	
	void FillTextMap()
	{
		m_TextMap = new map<int, ref Param2<string, string>>;
	
		m_TextMap.Insert(OptionAccessType.AT_OPTIONS_MASTER_VOLUME, new Param2<string, string>("#STR_sound_tab_master_tip_header", "#STR_sound_tab_master_tip"));
		m_TextMap.Insert(OptionAccessType.AT_OPTIONS_EFFECTS_SLIDER, new Param2<string, string>("#STR_sound_tab_effects_tip_header", "#STR_sound_tab_effects_tip"));
		m_TextMap.Insert(OptionAccessType.AT_OPTIONS_MUSIC_SLIDER, new Param2<string, string>("#STR_sound_tab_music_tip_header", "#STR_sound_tab_music_tip"));

		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"));
		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"));
		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")); 
	}
}