./pause_options_audio.lua

  1. local PM_MENU_AUDIO_OPTIONS			= 4 
  2.  
  3. -- These IDs correspond to values in the Pause_menu_audio_options enum in code. 
  4. local OVERALL_ID							= 1 
  5. local SOUND_EFFECTS_ID					= 2 
  6. local MUSIC_ID								= 3 
  7. local VOICE_ID								= 4 
  8. --local RADIO_CONTROLS_ID					= 5 
  9. local SUBTITLES_ID						= 6 
  10. local VOICE_CHAT_ENABLED_ID			= 7 
  11. local INTERACTIVE_MUSIC_ID					= 8 
  12. local LICENSED_MUSIC_ID						= 9 
  13.  
  14.  
  15. local OVERALL_INDEX						= -1 
  16. local SOUND_EFFECTS_INDEX				= 1 
  17. local MUSIC_INDEX							= 2 
  18. local VOICE_INDEX							= 3 
  19. --local RADIO_CONTROLS_INDEX				= 4 
  20. local SUBTITLES_INDEX					= 4 
  21. local INTERACTIVE_MUSIC_INDEX			= 5 
  22. local LICENSED_MUSIC_INDEX				= 6 
  23.  
  24. local VOICE_CHAT_ENABLED_INDEX		= -1 
  25. local SETUP_MIC_INDEX					= -1 
  26.  
  27. local Music_inst 							= -1 
  28.  
  29. local Screen_width						= 840 
  30.  
  31. local Data = {} 
  32.  
  33. function pause_options_audio_get_list_data() 
  34.  
  35. 	if game_get_platform() == "PC" then 
  36. 		OVERALL_INDEX					= 1 
  37. 		SOUND_EFFECTS_INDEX			= 2 
  38. 		MUSIC_INDEX						= 3 
  39. 		VOICE_INDEX						= 4 
  40. 		--RADIO_CONTROLS_INDEX			= -1 
  41. 		SUBTITLES_INDEX				= -1 
  42. 		VOICE_CHAT_ENABLED_INDEX	= 5 
  43. 		SETUP_MIC_INDEX				= 6 
  44. 	end 
  45.  
  46. 	Data = { 
  47. 		[SOUND_EFFECTS_INDEX] = { 
  48. 			type = TYPE_SLIDER, 
  49. 			label = "MENU_AUDIO_SFX", 
  50. 			min = 0, 
  51. 			max = 100, 
  52. 			step = 10, 
  53. 			current_value = 100, 
  54. 			id = SOUND_EFFECTS_ID 
  55. 		},	 
  56. 		[MUSIC_INDEX] = { 
  57. 			type = TYPE_SLIDER, 
  58. 			label = "MENU_AUDIO_MUSIC", 
  59. 			min = 0, 
  60. 			max = 100, 
  61. 			step = 10, 
  62. 			current_value = 100, 
  63. 			id = MUSIC_ID, 
  64. 		}, 
  65. 		[VOICE_INDEX] = { 
  66. 			type = TYPE_SLIDER, 
  67. 			label = "MENU_AUDIO_VOICE", 
  68. 			min = 0, 
  69. 			max = 100, 
  70. 			step = 10, 
  71. 			current_value = 100, 
  72. 			id = VOICE_ID 
  73. 		}, 
  74. 		--[[ 
  75. 		[RADIO_CONTROLS_INDEX] = { 
  76. 			type = TYPE_TOGGLE, 
  77. 			label = "MENU_AUDIO_RADIO", 
  78. 			options = {"RADIO_ALWAYS_ON", "RADIO_HIJACK_ON", "RADIO_LIFE_LIKE" }, 
  79. 			current_value = 1, 
  80. 			id = RADIO_CONTROLS_ID 
  81. 		}, 
  82. 		]] 
  83. 		[SUBTITLES_INDEX] = { 
  84. 			type = TYPE_TOGGLE, 
  85. 			label = "MENU_CONTROLS_SUBTITLES", 
  86. 			options = {"OPTION_NO", "OPTION_YES"}, 
  87. 			current_value = 1, 
  88. 			id = SUBTITLES_ID 
  89. 		}, 
  90. 		--[[ 
  91. 		[INTERACTIVE_MUSIC_INDEX] = { 
  92. 			type = TYPE_TOGGLE, 
  93. 			label = "MENU_AUDIO_INTERACTIVE_MUSIC", 
  94. 			options = {"OPTION_NO", "OPTION_YES"}, 
  95. 			current_value = 1, 
  96. 			id = INTERACTIVE_MUSIC_ID 
  97. 		}, 
  98. 		 
  99. 		[LICENSED_MUSIC_INDEX] = { 
  100. 			type = TYPE_TOGGLE, 
  101. 			label = "MENU_AUDIO_LICENSED_MUSIC", 
  102. 			options = {"OPTION_NO", "OPTION_YES"}, 
  103. 			current_value = 0, 
  104. 			id = LICENSED_MUSIC_ID 
  105. 		}, 
  106. 		--]] 
  107. 	} 
  108. 	 
  109. 	if game_get_platform() == "PC" then 
  110. 		Data[OVERALL_INDEX] = { 
  111. 			type = TYPE_SLIDER, 
  112. 			label = "MENU_AUDIO_OVERALL", 
  113. 			min = 0, 
  114. 			max = 100, 
  115. 			step = 10, 
  116. 			current_value = 100, 
  117. 			id = OVERALL_ID 
  118. 		} 
  119. 		Data[VOICE_CHAT_ENABLED_INDEX] = { 
  120. 			type = TYPE_TOGGLE, 
  121. 			label = "PLT_MENU_AUDIO_VOICE_ENABLE", 
  122. 			options = {"PLT_MENU_VOICE_DISABLED", "PLT_MENU_VOICE_ALWAYS_ON", "PLT_MENU_VOICE_PUSH_TO_TALK"}, 
  123. 			current_value = 2, 
  124. 			id = VOICE_CHAT_ENABLED_ID 
  125. 		} 
  126. 		Data[SETUP_MIC_INDEX] = { 
  127. 			type = TYPE_BUTTON, 
  128. 			label = "PLT_MENU_SETUP_MIC", 
  129. 		} 
  130. 	end 
  131. 	 
  132. end 
  133.  
  134. local Anims = {} 
  135.  
  136. local Input_tracker 
  137. local Mouse_input_tracker 
  138.  
  139. local Tween_done = true 
  140.  
  141. function pause_options_audio_init() 
  142.  
  143. 	if vint_is_std_res() then 
  144. 		Screen_width = 750 
  145. 	else 
  146. 		Screen_width = 840 
  147. 	end 
  148.  
  149. 	pause_options_audio_get_list_data() 
  150.  
  151. 	-- Subscribe to the button presses we need 
  152. 	 
  153. 	Input_tracker = Vdo_input_tracker:new() 
  154. 	Input_tracker:add_input("select", "options_audio_button_a", 50) 
  155. 	Input_tracker:add_input("back", "options_audio_button_b", 50) 
  156. 	Input_tracker:add_input("alt_select", "options_audio_button_x", 50) 
  157. 	if In_pause_menu then 
  158. 		Input_tracker:add_input("pause", "options_audio_button_start", 50) 
  159. 	end 
  160. 	Input_tracker:add_input("nav_up", "options_audio_nav_up", 50) 
  161. 	Input_tracker:add_input("nav_down", "options_audio_nav_down", 50) 
  162. 	Input_tracker:add_input("nav_left", "options_audio_nav_left", 50) 
  163. 	Input_tracker:add_input("nav_right", "options_audio_nav_right", 50) 
  164. 	Input_tracker:subscribe(false) 
  165.  
  166. 	--Set Button hints 
  167. 	local hint_data = { 
  168. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  169. 		{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"}, 
  170. 	} 
  171. 	Menu_hint_bar:set_hints(hint_data)   
  172. 	 
  173. 	Header_obj:set_text("MENU_OPTIONS_AUDIO", Screen_width) 
  174. 	 
  175. 	--Get the selection option from when the menu was last loaded 
  176. 	local last_option_selected = menu_common_stack_get_index() 
  177.  
  178. 	vint_dataresponder_request("pause_menu_options", "options_audio_populate", 0, PM_MENU_AUDIO_OPTIONS) 
  179.  
  180. 	List:draw_items(Data, last_option_selected, Screen_width) 
  181. 	 
  182. 	--Store some locals to the pause menu common for screen processing. 
  183. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  184. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  185. 	 
  186. 	ui_audio_post_event("Main_Menu_Music_Mute") 
  187. 	 
  188. 	-- Add mouse inputs for the PC 
  189. 	if game_get_platform() == "PC" then 
  190. 		Menu_hint_bar:set_highlight(0) 
  191. 		 
  192. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  193. 		List:add_mouse_inputs("pause_options_audio", Mouse_input_tracker) 
  194. 		Menu_hint_bar:add_mouse_inputs("pause_options_audio", Mouse_input_tracker) 
  195. 		Mouse_input_tracker:subscribe(true) 
  196. 		 
  197. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  198. 	end 
  199. end 
  200.  
  201. function pause_options_audio_cleanup() 
  202. 	if Music_inst ~= -1 then 
  203. 		game_audio_stop(Music_inst) 
  204. 		Music_inst = -1 
  205. 	end 
  206. 	 
  207. 	ui_audio_post_event("Main_Menu_Music_Unmute") 
  208. 	 
  209. 	-- Nuke all button subscriptions 
  210. 	Input_tracker:subscribe(false) 
  211. 	if Mouse_input_tracker ~= nil then 
  212. 		Mouse_input_tracker:subscribe(false) 
  213. 	end 
  214. 	List:enable_toggle_input(false) 
  215. end 
  216.  
  217. function options_audio_populate(overall, sfx, music, voice, radio_state, subtitles, voice_chat_state, interactive_audio, licensed_music) 
  218. 	if OVERALL_INDEX ~= -1 then 
  219. 		Data[OVERALL_INDEX].current_value = floor(overall * 100) 
  220. 		Data[OVERALL_INDEX].previous_value = Data[OVERALL_INDEX].current_value 
  221. 	end 
  222.  
  223. 	Data[SOUND_EFFECTS_INDEX].current_value = floor(sfx * 100) 
  224. 	Data[SOUND_EFFECTS_INDEX].previous_value = Data[SOUND_EFFECTS_INDEX].current_value 
  225.  
  226. 	Data[MUSIC_INDEX].current_value = floor(music * 100) 
  227. 	Data[MUSIC_INDEX].previous_value = Data[MUSIC_INDEX].current_value 
  228. 	 
  229. 	-- SEH: music is not allowed while recording 
  230. 	if game_record_mode_is_active() then 
  231. 		Data[MUSIC_INDEX].disabled = true 
  232. 	end 
  233. 	 
  234. 	Data[VOICE_INDEX].current_value = floor(voice * 100) 
  235. 	Data[VOICE_INDEX].previous_value = Data[VOICE_INDEX].current_value 
  236. 	 
  237. 	--Data[INTERACTIVE_MUSIC_INDEX].current_value = interactive_audio and 2 or 1 
  238. 	--Data[INTERACTIVE_MUSIC_INDEX].previous_value = interactive_audio and 2 or 1 
  239. 	 
  240. 	--Data[LICENSED_MUSIC_INDEX].current_value = licensed_music and 2 or 1 
  241. 	--Data[LICENSED_MUSIC_INDEX].previous_value = licensed_music and 2 or 1 
  242. 	--[[ 
  243. 	if RADIO_CONTROLS_INDEX ~= -1 then 
  244. 		Data[RADIO_CONTROLS_INDEX].current_value = radio_state + 1 
  245. 		Data[RADIO_CONTROLS_INDEX].previous_value = Data[RADIO_CONTROLS_INDEX].current_value 
  246. 	end 
  247. 	]] 
  248. 	if SUBTITLES_INDEX ~= -1 then 
  249. 		Data[SUBTITLES_INDEX].current_value = subtitles and 2 or 1 
  250. 		Data[SUBTITLES_INDEX].previous_value = Data[SUBTITLES_INDEX].current_value 
  251. 	end 
  252. 	 
  253. 	if VOICE_CHAT_ENABLED_INDEX ~= -1 then 
  254. 		Data[VOICE_CHAT_ENABLED_INDEX].current_value = voice_chat_state + 1 
  255. 		Data[VOICE_CHAT_ENABLED_INDEX].previous_value = Data[VOICE_CHAT_ENABLED_INDEX].current_value 
  256. 	end 
  257. end 
  258.  
  259. function options_audio_nav_up(event, acceleration) 
  260. 	-- Move highlight up 
  261. 	List:move_cursor(-1) 
  262. 	 
  263. 	if List:get_selection() == MUSIC_INDEX then 
  264. 		if Music_inst == -1 then 
  265. 			Music_inst = game_UI_audio_play("UI_Volume_Music") 
  266. 		end 
  267. 	elseif Music_inst ~= -1 then 
  268. 		game_audio_stop(Music_inst) 
  269. 		Music_inst = -1 
  270. 	end 
  271. end 
  272.  
  273. function options_audio_nav_down(event, acceleration) 
  274. 	-- Move highlight down 
  275. 	List:move_cursor(1) 
  276. 	 
  277. 	if List:get_selection() == MUSIC_INDEX then 
  278. 		if Music_inst == -1 then 
  279. 			Music_inst = game_UI_audio_play("UI_Volume_Music") 
  280. 		end 
  281. 	elseif Music_inst ~= -1 then 
  282. 		game_audio_stop(Music_inst) 
  283. 		Music_inst = -1 
  284. 	end 
  285. end 
  286.  
  287. function options_audio_nav_left(event, acceleration) 
  288. 	-- Move highlight left 
  289. 	List:move_slider(-1,nil,true) 
  290. 	options_audio_update_option_value() 
  291. end 
  292.  
  293. function options_audio_nav_right(event, acceleration) 
  294. 	-- Move highlight right 
  295. 	List:move_slider(1,nil,true) 
  296. 	options_audio_update_option_value() 
  297. end 
  298.  
  299. function options_audio_update_option_value() 
  300. 	local current_idx = List:get_selection() 
  301. 	local menu_item = Data[current_idx] 
  302. 	 
  303. 	local bool_val = true 
  304. 	if menu_item.current_value == 1 then 
  305. 		bool_val = false 
  306. 	end 
  307. 	 
  308. 	-- Keep us from updating the value more often than is needed. (Useful for PC). 
  309. 	if menu_item.current_value == menu_item.previous_value then 
  310. 		return 
  311. 	end 
  312. 	 
  313. 	menu_item.previous_value = menu_item.current_value 
  314. 	 
  315. 	-- Convert the value to [0.0 - 1.0] 
  316. 	local converted_float = menu_item.current_value 
  317. 	if converted_float ~= 0 then 
  318. 		converted_float = menu_item.current_value / 100 
  319. 	end 
  320. 	 
  321. 	if menu_item.type == TYPE_TOGGLE then 
  322. 		converted_float = menu_item.current_value - 1	-- 0-based in the radio system 
  323. 	end 
  324.  
  325. 	pause_menu_update_option(PM_MENU_AUDIO_OPTIONS, menu_item.id, bool_val, converted_float) 
  326. 	 
  327. 	if current_idx == SOUND_EFFECTS_INDEX or current_idx == OVERALL_INDEX then 
  328. 		game_UI_audio_play("UI_Volume_SFX") 
  329. 	elseif current_idx == VOICE_INDEX then 
  330. 		game_UI_audio_play("UI_Volume_Voice") 
  331. 	--elseif current_idx == RADIO_CONTROLS_INDEX then 
  332. 	 
  333. 	end 
  334. end 
  335.  
  336. function options_audio_button_a(event, acceleration) 
  337. 	local current_idx = List:get_selection() 
  338. 	if current_idx == SETUP_MIC_INDEX then 
  339. 		game_steam_open_overlay("voicesettings") 
  340. 	else 
  341. 		options_audio_nav_right() 
  342. 		 
  343. 		if Tween_done == true then 
  344. 			--set the screen data to the list data 
  345. 			Data = List:return_data() 
  346. 		end 
  347. 	end 
  348. end 
  349.  
  350. function options_audio_button_b(event, acceleration) 
  351. 	if Tween_done == true then 
  352. 		List:button_b() 
  353. 		-- Accept the options 
  354. 		pause_menu_accept_options() 
  355. 		 
  356. 		--Remove current menu from the stack 
  357. 		menu_common_stack_remove() 
  358. 		 
  359. 		--Pop Screen off the list 
  360. 		menu_common_transition_pop(1) 
  361. 		 
  362. 		if Mouse_input_tracker ~= nil then 
  363. 			Mouse_input_tracker:subscribe(false) 
  364. 		end 
  365. 	end 
  366. end 
  367.  
  368. function options_audio_button_x(event, acceleration) 
  369. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_audio_revert", true, true,1) 
  370. end 
  371.  
  372. function options_audio_revert(result, action) 
  373. 	if result == 0 then 
  374. 		pause_menu_restore_defaults(PM_MENU_AUDIO_OPTIONS) 
  375. 		vint_dataresponder_request("pause_menu_options", "options_audio_populate", 0, PM_MENU_AUDIO_OPTIONS)	 
  376. 		List:draw_items(Data, List:get_selection(), Screen_width, nil, nil, nil, true) 
  377. 		if Mouse_input_tracker ~= nil then 
  378. 			Mouse_input_tracker:remove_all() 
  379. 			List:add_mouse_inputs("pause_options_audio", Mouse_input_tracker) 
  380. 			Menu_hint_bar:add_mouse_inputs("pause_options_audio", Mouse_input_tracker) 
  381. 			Mouse_input_tracker:subscribe(true) 
  382. 		end 
  383. 	end 
  384. end 
  385.  
  386. function options_audio_button_start(event, acceleration) 
  387. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  388. 	Input_tracker:subscribe(false) 
  389. 	menu_common_transition_pop(4) -- options_audio, options, pause menu top, pause_menu common 
  390. 	bg_saints_slide_out() 
  391. end 
  392.  
  393. -- Mouse inputs 
  394. function pause_options_audio_mouse_click(event, target_handle, mouse_x, mouse_y) 
  395. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  396. 	if hint_index == 1 then 
  397. 		options_audio_button_b() 
  398. 	elseif hint_index == 2 then 
  399. 		options_audio_button_x() 
  400. 	end 
  401.  
  402. 	local new_index = List:get_button_index(target_handle) 
  403. 	if new_index ~= 0 then 
  404. 		List:set_selection(new_index) 
  405. 		options_audio_button_a() 
  406. 	end 
  407. 	 
  408. 	if List:is_left_arrow(target_handle) then 
  409. 		List:move_slider(-1) 
  410. 		options_audio_update_option_value() 
  411. 	elseif List:is_right_arrow(target_handle) then 
  412. 		List:move_slider(1) 
  413. 		options_audio_update_option_value() 
  414. 	end 
  415. 	if List:is_slider(target_handle) then 
  416. 		List:move_slider(0, mouse_x) 
  417. 		options_audio_update_option_value() 
  418. 	end 
  419. end 
  420.  
  421. function pause_options_audio_mouse_move(event, target_handle) 
  422. 	Menu_hint_bar:set_highlight(0) 
  423. 	 
  424. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  425. 	if hint_index ~= 0 then 
  426. 		Menu_hint_bar:set_highlight(hint_index) 
  427. 	end 
  428. 	 
  429. 	local new_index = List:get_button_index(target_handle) 
  430. 	if new_index ~= 0 then 
  431. 		List:set_selection(new_index) 
  432. 		List:move_cursor(0, true) 
  433. 	end 
  434. end 
  435.  
  436. function pause_options_audio_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  437. 	if List:is_slider(target_handle) then 
  438. 		List:move_slider(0, mouse_x) 
  439. 		options_audio_update_option_value() 
  440. 	end 
  441. end 
  442.  
  443. function pause_options_audio_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  444. end 
  445.