optionsmenusounds.c 14 KB

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