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