./pause_options_controls.lua

  1. local PM_MENU_CONTROL_OPTIONS			= 1 
  2.  
  3. local CONTROL_SCHEME_BUTTON_ID = -1 
  4.  
  5. local Data = { } 
  6.  
  7. local Anims = {} 
  8.  
  9. local Input_tracker 
  10. local Mouse_input_tracker 
  11.  
  12. local Max_list_items = 11 
  13.  
  14. local Screen_width = 840 
  15.  
  16. local Tween_done = true 
  17.  
  18. function pause_options_controls_init() 
  19. 	-- Subscribe to the button presses we need 
  20. 	 
  21. 	Input_tracker = Vdo_input_tracker:new() 
  22. 	Input_tracker:add_input("select", "options_controls_button_a", 50) 
  23. 	Input_tracker:add_input("back", "options_controls_button_b", 50) 
  24. 	if In_pause_menu then 
  25. 		Input_tracker:add_input("pause", "options_controls_button_start", 50) 
  26. 	end 
  27. 	Input_tracker:add_input("alt_select", "options_controls_button_x", 50) 
  28. 	Input_tracker:add_input("nav_up", "options_controls_nav_up", 50) 
  29. 	Input_tracker:add_input("nav_down", "options_controls_nav_down", 50) 
  30. 	Input_tracker:add_input("nav_left", "options_controls_nav_left", 50) 
  31. 	Input_tracker:add_input("nav_right", "options_controls_nav_right", 50) 
  32. 	Input_tracker:subscribe(false) 
  33.  
  34. 	if vint_is_std_res() then 
  35. 		Screen_width = 750 
  36. 	else 
  37. 		Screen_width = 840 
  38. 	end 
  39. 	 
  40. 	--Initialize Header 
  41. 	if game_get_platform() == "PC" then 
  42. 		Header_obj:set_text("MENU_CONTROLLER_OPTIONS_TITLE", Screen_width)		 
  43. 	else 
  44. 		Header_obj:set_text("CONTROLS_TITLE", Screen_width) 
  45. 	end 
  46. 	 
  47.  
  48. 	--Shift screen up we don't have to scroll for one additional option. 
  49. 	--Newsticker gets in the way in the main menu. 
  50. 	 
  51. 	--set up the list in twns 
  52. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  53. 	local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle) 
  54. 	 
  55. 	list_back_in:set_property("start_value", 100, 140) 
  56. 	header_back_in:set_property("start_value", 130, 83) 
  57. 	 
  58. 	list_back_in:set_property("end_value", 100, 140) 
  59. 	header_back_in:set_property("end_value", 130, 83) 
  60. 	 
  61. 	--set up the list out twns 
  62. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  63. 	local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle) 
  64. 	 
  65. 	list_slide_out:set_property("start_value", 100, 140) 
  66. 	header_slide_out:set_property("start_value", 130, 83) 
  67. 		 
  68. 	list_slide_out:set_property("end_value", 100, 140) 
  69. 	header_slide_out:set_property("end_value", 130, 83) 
  70. 	 
  71. 	local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle) 
  72. 	local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle) 
  73. 	 
  74. 	list_slide_in:set_property("start_value", 100, 140) 
  75. 	header_slide_in:set_property("start_value", 130, 83) 
  76. 	 
  77. 	list_slide_in:set_property("end_value", 100, 140) 
  78. 	header_slide_in:set_property("end_value", 130, 83) 
  79. 	 
  80.  
  81. 	--Get the selection option from when the menu was last loaded 
  82. 	local last_option_selected = menu_common_stack_get_index() 
  83.  
  84. 	--Setup button hints 
  85. 	local hint_data = { 
  86. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  87. 		{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"}, 
  88. 	} 
  89. 	Menu_hint_bar:set_hints(hint_data)   
  90.  
  91. 	-- Initialize and draw list object 
  92. 	vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)	 
  93. 	 
  94. 	List:set_input_tracker(Input_tracker) 
  95. 	List:draw_items(Data, last_option_selected, Screen_width, Max_list_items) 
  96. 	 
  97. 	--Store some locals to the pause menu common for screen processing. 
  98. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  99. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  100. 	 
  101. 	-- Add mouse inputs for the PC 
  102. 	if game_get_platform() == "PC" then 
  103. 		Menu_hint_bar:set_highlight(0) 
  104. 		 
  105. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  106. 		List:add_mouse_inputs("pause_options_controls", Mouse_input_tracker) 
  107. 		Menu_hint_bar:add_mouse_inputs("pause_options_controls", Mouse_input_tracker) 
  108. 		Mouse_input_tracker:subscribe(true) 
  109. 		 
  110. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  111. 	end 
  112. end 
  113.  
  114. function pause_options_controls_cleanup() 
  115. 	-- Nuke all button subscriptions 
  116. 	Input_tracker:subscribe(false) 
  117. 	if Mouse_input_tracker ~= nil then 
  118. 		Mouse_input_tracker:subscribe(false) 
  119. 	end 
  120. 	List:enable_toggle_input(false) 
  121. 	 
  122. 	--set up the list out twns 
  123. 	local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle) 
  124. 	local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle) 
  125. 	 
  126. 	local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle) 
  127. 	local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle) 
  128. 	 
  129. 	local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle) 
  130. 	local header_back_out = Vdo_tween_object:new("back_out_twn2", Screen_back_out_anim.handle) 
  131. 	 
  132. 	local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle) 
  133. 	local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle) 
  134. 	 
  135. 	list_back_in:set_property("start_value", 100, 267) 
  136. 	header_back_in:set_property("start_value", 130, 210) 
  137. 	 
  138. 	list_back_in:set_property("end_value", 100, 267) 
  139. 	header_back_in:set_property("end_value", 130, 210) 
  140. 	 
  141. 	 
  142.  
  143. 	list_slide_out:set_property("start_value", 100, 267) 
  144. 	header_slide_out:set_property("start_value", 130, 210) 
  145. 	 
  146. 	list_slide_out:set_property("end_value", 100, 267) 
  147. 	header_slide_out:set_property("end_value", 130, 210) 
  148. 		 
  149. 	list_slide_in:set_property("start_value", 100, 267) 
  150. 	header_slide_in:set_property("start_value", 130, 210) 
  151. 	 
  152. 	list_slide_in:set_property("end_value", 100, 267) 
  153. 	header_slide_in:set_property("end_value", 130, 210) 
  154. 	 
  155. end 
  156.  
  157. function options_controls_populate(invert_y, invert_rotation, veh_camera_snap, airplane_controls, vertical_sens, horz_sens, vibration, toggle_crouch, fine_auto_aim, invert_aircraft_pitch, qte_touch_pad) 
  158.  
  159. 	Data = { } 
  160. 	if game_get_platform() == "PC" then 
  161. 		Data[#Data + 1] = { 
  162. 			type = TYPE_BUTTON, 
  163. 			label = "MENU_CONTROL_SCHEMES", 
  164. 			id = CONTROL_SCHEME_BUTTON_ID, 
  165. 			current_value = 0 
  166. 		} 
  167. 	end 
  168. 	Data[#Data + 1] = { 
  169. 		type = TYPE_TOGGLE, 
  170. 		label = "MENU_CONTROLS_INVERT_Y", 
  171. 		options = {"OPTION_NO", "OPTION_YES"}, 
  172. 		id = 1, 
  173. 		current_value = 1 
  174. 	} 
  175. 	if invert_y == 1 then 
  176. 		Data[#Data].current_value = 2 
  177. 	else  
  178. 		Data[#Data].current_value = 1 
  179. 	end 
  180. 	 
  181. 	Data[#Data + 1] = { 
  182. 		type = TYPE_TOGGLE, 
  183. 		label = "MENU_CONTROLS_INVERT_ROTATION", 
  184. 		options = {"OPTION_NO", "OPTION_YES"}, 
  185. 		id = 2, 
  186. 		current_value = 1 
  187. 	} 
  188. 	if invert_rotation == 1 then 
  189. 		Data[#Data].current_value = 2 
  190. 	else  
  191. 		Data[#Data].current_value = 1 
  192. 	end 
  193. 	 
  194. 	if game_get_platform() ~= "PC" then 
  195. 		Data[#Data + 1] = { 
  196. 			type = TYPE_TOGGLE, 
  197. 			label = "CONTROLS_INVERT_AIRCRAFT_PITCH", 
  198. 			options = {"OPTION_NO", "OPTION_YES"}, 
  199. 			id = 10, 
  200. 			current_value = 1 
  201. 		} 
  202. 		if invert_aircraft_pitch == 1 then 
  203. 			Data[#Data].current_value = 2 
  204. 		else 
  205. 			Data[#Data].current_value = 1 
  206. 		end 
  207. 	end 
  208.  
  209. 	local vehicle_snap_option = { 
  210. 		type = TYPE_TOGGLE, 
  211. 		label = "MENU_VEHICLE_CAMERA_SNAP", 
  212. 		options = {"MENU_INSTANT", "MENU_DELAYED"}, 
  213. 		id = 3, 
  214. 		current_value = 1 
  215. 	} 
  216. 	if veh_camera_snap == 1 then 
  217. 		vehicle_snap_option.current_value = 2 
  218. 	else 
  219. 		vehicle_snap_option.current_value = 1 
  220. 	end 
  221.  
  222. --[[	 
  223. 	if game_get_platform() ~= "PC" then 
  224. 		Data[#Data + 1] = vehicle_snap_option 
  225. 	 
  226. 		Data[#Data + 1] = { 
  227. 			type = TYPE_TOGGLE, 
  228. 			label = "MENU_AIRPLANE_CONTROLS", 
  229. 			options = {"MENU_ADVANCED", "MENU_NORMAL"}, 
  230. 			id = 4, 
  231. 			current_value = 1 
  232. 		} 
  233. 		 
  234. 		if airplane_controls == 1 then 
  235. 			Data[#Data].current_value = 2 
  236. 		else 
  237. 			Data[#Data].current_value = 1 
  238. 		end 
  239. 	end 
  240. --]] 
  241. 	Data[#Data + 1] = { 
  242. 		type = TYPE_SLIDER, 
  243. 		label = "CONTROLS_SENSE_V", 
  244. 		min = 0, 
  245. 		max = 100, 
  246. 		step = 1, 
  247. 		id = 5, 
  248. 		current_value = floor(vertical_sens * 100) 
  249. 	} 
  250.  
  251. 	Data[#Data + 1] = { 
  252. 		type = TYPE_SLIDER, 
  253. 		label = "CONTROLS_SENSE_H", 
  254. 		min = 0, 
  255. 		max = 100, 
  256. 		step = 1, 
  257. 		id = 6, 
  258. 		current_value = floor(horz_sens * 100) 
  259. 	} 
  260. 	Data[#Data + 1] = { 
  261. 		type = TYPE_TOGGLE, 
  262. 		label = "CONTROLS_FORCE_FEED", 
  263. 		options = {"OPTION_NO", "OPTION_YES"}, 
  264. 		id = 7, 
  265. 		current_value = 1 
  266. 	} 
  267. 	if vibration == 1 or vibration == true then 
  268. 		Data[#Data].current_value = 2 
  269. 	else 
  270. 		Data[#Data].current_value = 1 
  271. 	end 
  272. 	 
  273. 	Data[#Data + 1] = { 
  274. 		type = TYPE_TOGGLE, 
  275. 		label = "CONTROLS_CROUCH_TOGGLE", 
  276. 		options = {"OPTION_NO", "OPTION_YES"}, 
  277. 		id = 8, 
  278. 		current_value = 1 
  279. 	} 
  280. 	if toggle_crouch == 1 then 
  281. 		Data[#Data].current_value = 2 
  282. 	else 
  283. 		Data[#Data].current_value = 1 
  284. 	end 
  285. 	 
  286. 	Data[#Data + 1] = { 
  287. 		type = TYPE_TOGGLE, 
  288. 		label = "CONTROLS_FINE_AUTO_AIM", 
  289. 		options = {"OPTION_NO", "OPTION_YES"}, 
  290. 		id = 9, 
  291. 		current_value = 1 
  292. 	} 
  293. 	if fine_auto_aim == 1 then 
  294. 		Data[#Data].current_value = 2 
  295. 	else 
  296. 		Data[#Data].current_value = 1 
  297. 	end 
  298.  
  299. 	if game_get_platform() == "PC" then 
  300. 		Data[#Data + 1] = vehicle_snap_option 
  301. 	end 
  302. 	-- HVS_JPM [KING ONLY] 10/21/2014 - HS 11166 - there are no QTEs in King so we removed the touchpad option 
  303. 	--[[ 
  304. 	if game_get_platform() == "PS4" then	--HVS_JRP[PRINCE] 4/1/2014 PS4 touch pad for quick time events. 
  305. 		Data[#Data + 1] = { 
  306. 			type = TYPE_TOGGLE, 
  307. 			label = "CONTROLS_QTE_TOUCH_PAD", 
  308. 			options = {"OPTION_NO", "OPTION_YES"}, 
  309. 			id = 11, 
  310. 			current_value = 1 
  311. 		} 
  312.  
  313. 		if qte_touch_pad == 1 then 
  314. 			Data[#Data].current_value = 2 
  315. 		else 
  316. 			Data[#Data].current_value = 1 
  317. 		end 
  318. 	end 
  319. 	--]] 
  320. end 
  321.  
  322. function options_controls_nav_up(event, acceleration) 
  323. 	-- Move highlight up 
  324. 	List:move_cursor(-1) 
  325. end 
  326.  
  327. function options_controls_nav_down(event, acceleration) 
  328. 	-- Move highlight down 
  329. 	List:move_cursor(1) 
  330. end 
  331.  
  332. function options_controls_nav_left(event, acceleration) 
  333. 	-- Move highlight left 
  334. 	List:move_slider(-1) 
  335. 	options_controls_update_option_value() 
  336. end 
  337.  
  338. function options_controls_nav_right(event, acceleration) 
  339. 	-- Move highlight right 
  340. 	List:move_slider(1) 
  341. 	options_controls_update_option_value() 
  342. end 
  343.  
  344. function options_controls_update_option_value() 
  345. 	local current_idx = List:get_selection() 
  346. 	local menu_item = Data[current_idx] 
  347. 	 
  348. 	local bool_val = true 
  349. 	if menu_item.current_value == 1 then 
  350. 		bool_val = false 
  351. 	end 
  352. 	 
  353. 	-- Convert the value to [0.0 - 1.0] 
  354. 	local converted_float = menu_item.current_value 
  355. 	if converted_float ~= 0 then 
  356. 		converted_float = menu_item.current_value / 100 
  357. 	end 
  358. 	 
  359. 	pause_menu_update_option(PM_MENU_CONTROL_OPTIONS, menu_item.id, bool_val, converted_float) 
  360. end 
  361.  
  362. function options_controls_button_a(event, acceleration) 
  363. 	options_controls_nav_right() 
  364. 	 
  365. 	if Tween_done == true then 
  366. 		--set the screen data to the list data 
  367. 		Data = List:return_data() 
  368. 		 
  369. 		--Add current selection to the stack to store the selected position on the menu 
  370. 		local current_id = List:get_id() 
  371. 			 
  372. 		--pass off the input to the list 
  373. 		List:button_a() 
  374. 			 
  375. 		if current_id == CONTROL_SCHEME_BUTTON_ID then 
  376. 			menu_common_stack_add(List:get_selection()) 
  377. 			 
  378. 			local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle) 
  379. 			local header_back_out = Vdo_tween_object:new("back_out_twn2", Screen_back_out_anim.handle) 
  380. 	 
  381. 			list_back_out:set_property("start_value", 100, 140) 
  382. 			header_back_out:set_property("start_value", 130, 83) 
  383. 	 
  384. 			list_back_out:set_property("end_value", 100, 140) 
  385. 			header_back_out:set_property("end_value", 130, 83) 
  386. 			 
  387. 			menu_common_transition_push("pause_ctrl_scheme") 
  388. 			pause_options_controls_cleanup() 
  389. 			 
  390. 			return 
  391. 		end 
  392. 	end 
  393. end 
  394.  
  395. function options_controls_button_b(event, acceleration) 
  396. 	if Tween_done == true then 
  397. 		List:button_b() 
  398. 		-- save options to the profile 
  399. 		pause_menu_accept_options() 
  400.  
  401. 		Input_tracker:subscribe(false) 
  402. 		if Mouse_input_tracker ~= nil then 
  403. 			Mouse_input_tracker:subscribe(false) 
  404. 		end 
  405. 		List:enable_toggle_input(false) 
  406. 		 
  407. 		--Remove current menu from the stack 
  408. 		menu_common_stack_remove() 
  409. 		menu_common_transition_pop(1) 
  410. 	end 
  411. end 
  412.  
  413. function options_controls_button_x(event, acceleration) 
  414. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_controls_revert", true, true,1) 
  415. end 
  416.  
  417. function options_controls_revert(result, action) 
  418. 	if result == 0 then 
  419. 		pause_menu_restore_defaults(PM_MENU_CONTROL_OPTIONS) 
  420. 		vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)	 
  421. 		List:draw_items(Data, List:get_selection(), Screen_width, Max_list_items) 
  422. 		if Mouse_input_tracker ~= nil then 
  423. 			Mouse_input_tracker:remove_all() 
  424. 			List:add_mouse_inputs("pause_options_controls", Mouse_input_tracker) 
  425. 			Menu_hint_bar:add_mouse_inputs("pause_options_controls", Mouse_input_tracker) 
  426. 			Mouse_input_tracker:subscribe(true) 
  427. 		end 
  428. 	end 
  429. end 
  430.  
  431. function options_controls_button_start(event, acceleration) 
  432. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  433. 	Input_tracker:subscribe(false) 
  434. 	if game_get_platform() == "PC" then 
  435. 		menu_common_transition_pop(5) --controls, mouse_controls, options, pause menu top, pause menu common 
  436. 	else 
  437. 		menu_common_transition_pop(4) --controls, options, pause menu top, pause menu common 
  438. 	end 
  439. 	bg_saints_slide_out() 
  440. end 
  441.  
  442. -- Mouse inputs 
  443. function pause_options_controls_mouse_click(event, target_handle, mouse_x, mouse_y) 
  444. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  445. 	if hint_index == 1 then 
  446. 		options_controls_button_b() 
  447. 	elseif hint_index == 2 then 
  448. 		options_controls_button_x() 
  449. 	end 
  450.  
  451. 	local new_index = List:get_button_index(target_handle) 
  452. 	if new_index ~= 0 then 
  453. 		List:set_selection(new_index) 
  454. 		options_controls_button_a() 
  455. 	end 
  456. 	 
  457. 	if List:is_left_arrow(target_handle) then 
  458. 		List:move_slider(-1) 
  459. 		options_controls_update_option_value() 
  460. 	elseif List:is_right_arrow(target_handle) then 
  461. 		List:move_slider(1) 
  462. 		options_controls_update_option_value() 
  463. 	end 
  464. 	if List:is_slider(target_handle) then 
  465. 		List:move_slider(0, mouse_x) 
  466. 		options_controls_update_option_value() 
  467. 	end 
  468. end 
  469.  
  470. function pause_options_controls_mouse_move(event, target_handle) 
  471. 	Menu_hint_bar:set_highlight(0) 
  472. 	 
  473. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  474. 	if hint_index ~= 0 then 
  475. 		Menu_hint_bar:set_highlight(hint_index) 
  476. 	end 
  477. 	 
  478. 	local new_index = List:get_button_index(target_handle) 
  479. 	if new_index ~= 0 then 
  480. 		List:set_selection(new_index) 
  481. 		List:move_cursor(0, true) 
  482. 	end 
  483. end 
  484.  
  485.  
  486. function pause_options_controls_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  487. 	if List:is_slider(target_handle) then 
  488. 		List:move_slider(0, mouse_x) 
  489. 	end 
  490.  
  491. 	 
  492. 	local scrollbar = List.scrollbar 
  493. 	 
  494. 	--Max items is number of buttons in the list minus the max buttons that can be displayed. 
  495. 	local max_items = List.num_buttons - (List.max_buttons - 1) 
  496. 	 
  497. 	if List:list_is_playing() == false then	 
  498. 		if scrollbar.tab_grp.handle == target_handle then 
  499. 		 
  500. 			--Get new start index from scroll tab 
  501. 			local new_start_index = scrollbar:drag_scrolltab(mouse_y, max_items) 
  502. 		 
  503. 			--Scroll Mission list 
  504. 			List:scroll_list(0, new_start_index)			 
  505. 		end		 
  506. 	end	 
  507. end 
  508.  
  509.  
  510. function pause_options_controls_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  511. 	if List:is_slider(target_handle) then 
  512. 		List:move_slider(0, mouse_x) 
  513. 		options_controls_button_a() 
  514. 	end 
  515. 	 
  516. 	local scrollbar = List.scrollbar 
  517. 	 
  518. 	if List:list_is_playing() == false then	 
  519. 		if scrollbar.tab_grp.handle == target_handle then 
  520. 			local start_index, end_index = List:get_visible_indices() 
  521. 			 
  522. 			--Max items is number of buttons in the list minus the max buttons that can be displayed. 
  523. 			local max_items = List.num_buttons - (List.max_buttons - 1) 
  524. 			 
  525. 			--Set scrolltab position... 
  526. 			scrollbar:release_scrolltab(start_index, max_items)				 
  527. 		end 
  528. 	end	 
  529. end 
  530.  
  531.  
  532. function pause_options_controls_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  533. 	 
  534. 	--scroll lines are inverted for some reason 
  535. 	scroll_lines = scroll_lines * -1 
  536. 	 
  537. 	if scroll_lines ~= 0 then 
  538. 		List:scroll_list(scroll_lines) 
  539. 	end 
  540. end 
  541.