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