./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 Screen_width = 800 
  13.  
  14. local Tween_done = true 
  15.  
  16. function pause_options_controls_init() 
  17. 	-- Subscribe to the button presses we need 
  18. 	 
  19. 	Input_tracker = Vdo_input_tracker:new() 
  20. 	Input_tracker:add_input("select", "options_controls_button_a", 50) 
  21. 	Input_tracker:add_input("back", "options_controls_button_b", 50) 
  22. 	if In_pause_menu then 
  23. 		Input_tracker:add_input("pause", "options_controls_button_start", 50) 
  24. 	end 
  25. 	Input_tracker:add_input("alt_select", "options_controls_button_x", 50) 
  26. 	Input_tracker:add_input("nav_up", "options_controls_nav_up", 50) 
  27. 	Input_tracker:add_input("nav_down", "options_controls_nav_down", 50) 
  28. 	Input_tracker:add_input("nav_left", "options_controls_nav_left", 50) 
  29. 	Input_tracker:add_input("nav_right", "options_controls_nav_right", 50) 
  30. 	Input_tracker:subscribe(false) 
  31.  
  32. 	--Initialize Header 
  33. 	if game_get_platform() == "PC" then 
  34. 		Header_obj:set_text("MENU_CONTROLLER_OPTIONS_TITLE", Screen_width) 
  35. 	else 
  36. 		Header_obj:set_text("CONTROLS_TITLE", Screen_width) 
  37. 	end 
  38.  
  39. 	--Get the selection option from when the menu was last loaded 
  40. 	local last_option_selected = menu_common_stack_get_index() 
  41.  
  42. 	--Setup button hints 
  43. 	local hint_data = { 
  44. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  45. 		{CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"}, 
  46. 	} 
  47. 	Menu_hint_bar:set_hints(hint_data)   
  48.  
  49. 	-- Initialize and draw list object 
  50. 	vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)	 
  51. 	 
  52. 	List:set_input_tracker(Input_tracker) 
  53. 	List:draw_items(Data, last_option_selected, Screen_width) 
  54. 	 
  55. 	--Store some locals to the pause menu common for screen processing. 
  56. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  57. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  58. 	 
  59. 	-- Add mouse inputs for the PC 
  60. 	if game_get_platform() == "PC" then 
  61. 		Menu_hint_bar:set_highlight(0) 
  62. 		 
  63. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  64. 		List:add_mouse_inputs("options_controls", Mouse_input_tracker) 
  65. 		Menu_hint_bar:add_mouse_inputs("options_controls", Mouse_input_tracker) 
  66. 		Mouse_input_tracker:subscribe(true) 
  67. 		 
  68. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  69. 	end 
  70. end 
  71.  
  72. function pause_options_controls_cleanup() 
  73. 	-- Nuke all button subscriptions 
  74. 	Input_tracker:subscribe(false) 
  75. 	if Mouse_input_tracker ~= nil then 
  76. 		Mouse_input_tracker:subscribe(false) 
  77. 	end 
  78. 	List:enable_toggle_input(false) 
  79. end 
  80.  
  81. function options_controls_populate(invert_y, invert_rotation, veh_camera_snap, airplane_controls, vertical_sens, horz_sens, vibration, toggle_crouch) 
  82.  
  83. 	Data = { } 
  84. 	if game_get_platform() == "PC" then 
  85. 		Data[#Data + 1] = { 
  86. 			type = TYPE_BUTTON, 
  87. 			label = "MENU_CONTROL_SCHEMES", 
  88. 			id = CONTROL_SCHEME_BUTTON_ID, 
  89. 			current_value = 0 
  90. 		} 
  91. 	end 
  92. 	Data[#Data + 1] = { 
  93. 		type = TYPE_TOGGLE, 
  94. 		label = "MENU_CONTROLS_INVERT_Y", 
  95. 		options = {"OPTION_NO", "OPTION_YES"}, 
  96. 		id = 1, 
  97. 		current_value = 1 
  98. 	} 
  99. 	if invert_y == 1 then 
  100. 		Data[#Data].current_value = 2 
  101. 	else  
  102. 		Data[#Data].current_value = 1 
  103. 	end 
  104. 	 
  105. 	Data[#Data + 1] = { 
  106. 		type = TYPE_TOGGLE, 
  107. 		label = "MENU_CONTROLS_INVERT_ROTATION", 
  108. 		options = {"OPTION_NO", "OPTION_YES"}, 
  109. 		id = 2, 
  110. 		current_value = 1 
  111. 	} 
  112. 	if invert_rotation == 1 then 
  113. 		Data[#Data].current_value = 2 
  114. 	else  
  115. 		Data[#Data].current_value = 1 
  116. 	end 
  117.  
  118. 	local vehicle_snap_option = { 
  119. 		type = TYPE_TOGGLE, 
  120. 		label = "MENU_VEHICLE_CAMERA_SNAP", 
  121. 		options = {"MENU_INSTANT", "MENU_DELAYED"}, 
  122. 		id = 3, 
  123. 		current_value = 1 
  124. 	} 
  125. 	if veh_camera_snap == 1 then 
  126. 		vehicle_snap_option.current_value = 2 
  127. 	else 
  128. 		vehicle_snap_option.current_value = 1 
  129. 	end 
  130.  
  131. 	if game_get_platform() ~= "PC" then 
  132. 	 
  133. 		Data[#Data + 1] = vehicle_snap_option 
  134. 	 
  135. 		Data[#Data + 1] = { 
  136. 			type = TYPE_TOGGLE, 
  137. 			label = "MENU_AIRPLANE_CONTROLS", 
  138. 			options = {"MENU_ADVANCED", "MENU_NORMAL"}, 
  139. 			id = 4, 
  140. 			current_value = 1 
  141. 		} 
  142. 		 
  143. 		if airplane_controls == 1 then 
  144. 			Data[#Data].current_value = 2 
  145. 		else 
  146. 			Data[#Data].current_value = 1 
  147. 		end 
  148. 	end 
  149.  
  150. 	Data[#Data + 1] = { 
  151. 		type = TYPE_SLIDER, 
  152. 		label = "CONTROLS_SENSE_V", 
  153. 		min = 0, 
  154. 		max = 100, 
  155. 		step = 1, 
  156. 		id = 5, 
  157. 		current_value = floor(vertical_sens * 100) 
  158. 	} 
  159.  
  160. 	Data[#Data + 1] = { 
  161. 		type = TYPE_SLIDER, 
  162. 		label = "CONTROLS_SENSE_H", 
  163. 		min = 0, 
  164. 		max = 100, 
  165. 		step = 1, 
  166. 		id = 6, 
  167. 		current_value = floor(horz_sens * 100) 
  168. 	} 
  169. 	Data[#Data + 1] = { 
  170. 		type = TYPE_TOGGLE, 
  171. 		label = "CONTROLS_FORCE_FEED", 
  172. 		options = {"OPTION_NO", "OPTION_YES"}, 
  173. 		id = 7, 
  174. 		current_value = 1 
  175. 	} 
  176. 	if vibration == 1 or vibration == true then 
  177. 		Data[#Data].current_value = 2 
  178. 	else 
  179. 		Data[#Data].current_value = 1 
  180. 	end 
  181. 	 
  182. 	Data[#Data + 1] = { 
  183. 		type = TYPE_TOGGLE, 
  184. 		label = "CONTROLS_CROUCH_TOGGLE", 
  185. 		options = {"OPTION_NO", "OPTION_YES"}, 
  186. 		id = 8, 
  187. 		current_value = 1 
  188. 	} 
  189. 	if toggle_crouch == 1 then 
  190. 		Data[#Data].current_value = 2 
  191. 	else 
  192. 		Data[#Data].current_value = 1 
  193. 	end 
  194.  
  195. 	if game_get_platform() == "PC" then 
  196. 		Data[#Data + 1] = vehicle_snap_option 
  197. 	end		 
  198. end 
  199.  
  200. function options_controls_nav_up(event, acceleration) 
  201. 	-- Move highlight up 
  202. 	List:move_cursor(-1) 
  203. end 
  204.  
  205. function options_controls_nav_down(event, acceleration) 
  206. 	-- Move highlight down 
  207. 	List:move_cursor(1) 
  208. end 
  209.  
  210. function options_controls_nav_left(event, acceleration) 
  211. 	-- Move highlight left 
  212. 	List:move_slider(-1) 
  213. 	options_controls_update_option_value() 
  214. end 
  215.  
  216. function options_controls_nav_right(event, acceleration) 
  217. 	-- Move highlight right 
  218. 	List:move_slider(1) 
  219. 	options_controls_update_option_value() 
  220. end 
  221.  
  222. function options_controls_update_option_value() 
  223. 	local current_idx = List:get_selection() 
  224. 	local menu_item = Data[current_idx] 
  225. 	 
  226. 	local bool_val = true 
  227. 	if menu_item.current_value == 1 then 
  228. 		bool_val = false 
  229. 	end 
  230. 	 
  231. 	-- Convert the value to [0.0 - 1.0] 
  232. 	local converted_float = menu_item.current_value 
  233. 	if converted_float ~= 0 then 
  234. 		converted_float = menu_item.current_value / 100 
  235. 	end 
  236. 	 
  237. 	pause_menu_update_option(PM_MENU_CONTROL_OPTIONS, menu_item.id, bool_val, converted_float) 
  238. end 
  239.  
  240. function options_controls_button_a(event, acceleration) 
  241. 	options_controls_nav_right() 
  242. 	 
  243. 	if Tween_done == true then 
  244. 		--set the screen data to the list data 
  245. 		Data = List:return_data() 
  246. 		 
  247. 		--Add current selection to the stack to store the selected position on the menu 
  248. 		local current_id = List:get_id() 
  249. 		menu_common_stack_add(current_id) 
  250. 			 
  251. 		--pass off the input to the list 
  252. 		List:button_a() 
  253. 			 
  254. 		if current_id == CONTROL_SCHEME_BUTTON_ID then 
  255. 			menu_common_transition_push("pause_ctrl_scheme") 
  256. 			pause_options_controls_cleanup() 
  257. 			return 
  258. 		end 
  259. 	end 
  260. end 
  261.  
  262. function options_controls_button_b(event, acceleration) 
  263. 	if Tween_done == true then 
  264. 		List:button_b() 
  265. 		-- save options to the profile 
  266. 		pause_menu_accept_options() 
  267.  
  268. 		Input_tracker:subscribe(false) 
  269. 		if Mouse_input_tracker ~= nil then 
  270. 			Mouse_input_tracker:subscribe(false) 
  271. 		end 
  272. 		List:enable_toggle_input(false) 
  273. 		 
  274. 		--Remove current menu from the stack 
  275. 		menu_common_stack_remove() 
  276. 		menu_common_transition_pop(1) 
  277. 	end 
  278. end 
  279.  
  280. function options_controls_button_x(event, acceleration) 
  281. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_controls_revert", true, true,1) 
  282. end 
  283.  
  284. function options_controls_revert(result, action) 
  285. 	if result == 0 then 
  286. 		pause_menu_restore_defaults(PM_MENU_CONTROL_OPTIONS) 
  287. 		vint_dataresponder_request("pause_menu_options", "options_controls_populate", 0, PM_MENU_CONTROL_OPTIONS)	 
  288. 		List:draw_items(Data, List:get_selection(), Screen_width) 
  289. 		if Mouse_input_tracker ~= nil then 
  290. 			Mouse_input_tracker:remove_all() 
  291. 			List:add_mouse_inputs("options_controls", Mouse_input_tracker) 
  292. 			Menu_hint_bar:add_mouse_inputs("options_controls", Mouse_input_tracker) 
  293. 			Mouse_input_tracker:subscribe(true) 
  294. 		end 
  295. 	end 
  296. end 
  297.  
  298. function options_controls_button_start(event, acceleration) 
  299. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  300. 	Input_tracker:subscribe(false) 
  301. 	if game_get_platform() == "PC" then 
  302. 		menu_common_transition_pop(5) --controls, mouse_controls, options, pause menu top, pause menu common 
  303. 	else 
  304. 		menu_common_transition_pop(4) --controls, options, pause menu top, pause menu common 
  305. 	end 
  306. 	bg_saints_slide_out() 
  307. end 
  308.  
  309. -- Mouse inputs 
  310. function options_controls_mouse_click(event, target_handle, mouse_x, mouse_y) 
  311. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  312. 	if hint_index == 1 then 
  313. 		options_controls_button_b() 
  314. 	elseif hint_index == 2 then 
  315. 		options_controls_button_x() 
  316. 	end 
  317.  
  318. 	local new_index = List:get_button_index(target_handle) 
  319. 	if new_index ~= 0 then 
  320. 		List:set_selection(new_index) 
  321. 		options_controls_button_a() 
  322. 	end 
  323. 	 
  324. 	if List:is_left_arrow(target_handle) then 
  325. 		List:move_slider(-1) 
  326. 		options_controls_update_option_value() 
  327. 	elseif List:is_right_arrow(target_handle) then 
  328. 		List:move_slider(1) 
  329. 		options_controls_update_option_value() 
  330. 	end 
  331. 	if List:is_slider(target_handle) then 
  332. 		List:move_slider(0, mouse_x) 
  333. 		options_controls_update_option_value() 
  334. 	end 
  335. end 
  336.  
  337. function options_controls_mouse_move(event, target_handle) 
  338. 	Menu_hint_bar:set_highlight(0) 
  339. 	 
  340. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  341. 	if hint_index ~= 0 then 
  342. 		Menu_hint_bar:set_highlight(hint_index) 
  343. 	end 
  344. 	 
  345. 	local new_index = List:get_button_index(target_handle) 
  346. 	if new_index ~= 0 then 
  347. 		List:set_selection(new_index) 
  348. 		List:move_cursor(0, true) 
  349. 	end 
  350. end 
  351.  
  352. function options_controls_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  353. 	if List:is_slider(target_handle) then 
  354. 		List:move_slider(0, mouse_x) 
  355. 	end 
  356. end 
  357.  
  358. function options_controls_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  359. 	if List:is_slider(target_handle) then 
  360. 		List:move_slider(0, mouse_x) 
  361. 		options_controls_button_a() 
  362. 	end 
  363. end 
  364.