./pause_options_mouse.lua

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