./pause_options_difficulty.lua

  1. local PM_MENU_DIFFICULTY_OPTIONS			= 0 
  2.  
  3. local DIFFICULTY_INDEX = 1 
  4. --local AIRPLANE_INDEX = 2 
  5. local SUBTITLES_INDEX = 2 
  6. --local RADIO_INDEX = 4 
  7. local MINIMAP_INDEX = 3 
  8. --local PAUSE_FOCUS_INDEX = 4 
  9. --local FILM_GRAIN_INDEX = 7 
  10. local PAUSE_INV_SCREEN_INDEX = 4 
  11.  
  12. local Data = { 
  13. 	[DIFFICULTY_INDEX] = { 
  14. 		type = TYPE_TOGGLE, 
  15. 		label = "MENU_DIFFICULTY", 
  16. 		options = {"DLT_CASUAL", "DLT_NORMAL", "DLT_HARDCORE"}, 
  17. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_DIFFICULTY_TIP", 
  18. 		current_value = 1 
  19. 	} 
  20. } 
  21.  
  22. local Input_tracker 
  23. local Mouse_input_tracker 
  24.  
  25. local Screen_width = 840 
  26.  
  27. local Tween_done = true 
  28.  
  29. local Difficulty_doc_handle 
  30. local Tool_tip_h 
  31.  
  32. function pause_options_difficulty_set_tool_tip(new_tip_text) 
  33. 	vint_set_property(Tool_tip_h, "text_tag", new_tip_text) 
  34. end 
  35.  
  36. function pause_options_difficulty_init() 
  37.  
  38. 	Difficulty_doc_handle = vint_document_find("pause_options_difficulty") 
  39.  
  40. 	if vint_is_std_res() then 
  41. 		Screen_width = 750 
  42. 	else 
  43. 		Screen_width = 840 
  44. 	end 
  45. 	 
  46. 	Tool_tip_h = vint_object_find("tool_tip_text", 0, Difficulty_doc_handle) 
  47. 	 
  48. 	if game_get_platform() ~= "PC" then 
  49. 		vint_set_property(Tool_tip_h, "visible", false) 
  50. 	else 
  51. 		-- Align the tooltip to the list 
  52. 		--[[ 
  53. 		if In_pause_menu then 
  54. 			local anchor_in_h = vint_object_find("new_tween2") 
  55. 			local anchor_out_h = vint_object_find("new_tween4") 
  56. 			local anchor_in_x,anchor_in_y = vint_get_property(anchor_in_h, "start_value") 
  57. 			local anchor_out_x,anchor_out_y = vint_get_property(anchor_out_h, "start_value") 
  58. 			 
  59. 			if vint_is_std_res() then 
  60. 				vint_set_property(anchor_in_h, "start_value", 282, anchor_in_y) 
  61. 				vint_set_property(anchor_in_h, "end_value", 282, anchor_out_y) 
  62. 				 
  63. 				vint_set_property(anchor_out_h, "start_value", 282, anchor_out_y) 
  64. 				vint_set_property(anchor_out_h, "end_value", 282, anchor_in_y) 
  65. 			else 
  66. 				vint_set_property(anchor_in_h, "start_value", 448, anchor_in_y) 
  67. 				vint_set_property(anchor_in_h, "end_value", 448, anchor_out_y) 
  68. 				 
  69. 				vint_set_property(anchor_out_h, "start_value", 448, anchor_out_y) 
  70. 				vint_set_property(anchor_out_h, "end_value", 448, anchor_in_y) 
  71. 			end 
  72. 		end 
  73. 		]] 
  74. 	end 
  75. 	 
  76. 	pause_options_difficulty_set_tool_tip(Data[1].tool_tip_text) --("X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX X") -- Use this to figure out the correct anchor for In_pause_menu 
  77.  
  78. 	-- animate tooltip in 
  79. 	local anim_h = vint_object_find("animate_in", 0, Difficulty_doc_handle) 
  80. 	lua_play_anim(anim_h, 0, Difficulty_doc_handle) 
  81. 	 
  82. 	--game_peg_load_with_cb("pause_options_difficulty_finish_init", 1, "ui_cell_homies") 
  83. 	--game_peg_load_with_cb("options_difficulty_finish_init", 1, "ui_bms_cell_homies") 
  84. 	options_difficulty_finish_init() 
  85. end 
  86.  
  87. function options_difficulty_add_pc_options() 
  88. --[[ 
  89. 	Data[#Data + 1] = { 
  90. 		type = TYPE_TOGGLE, 
  91. 		label = "MENU_AIRPLANE_HANDLING", 
  92. 		options = {"MENU_ADVANCED", "MENU_NORMAL"}, 
  93. 		current_value = 1, 
  94. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_AIRPLANE_TIP", 
  95. 		id = #Data 
  96. 	} 
  97. --]] 
  98. 	 
  99. 	Data[#Data + 1] = { 
  100. 		type = TYPE_TOGGLE, 
  101. 		label = "MENU_CONTROLS_SUBTITLES", 
  102. 		options = {"OPTION_NO", "OPTION_YES"}, 
  103. 		current_value = 1, 
  104. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_SUBTITLES_TIP", 
  105. 		id = #Data 
  106. 	} 
  107. 	 
  108. --[[ 
  109. 	Data[#Data + 1] = { 
  110. 		type = TYPE_TOGGLE, 
  111. 		label = "MENU_AUDIO_RADIO", 
  112. 		options = {"RADIO_ALWAYS_ON", "RADIO_HIJACK_ON", "RADIO_LIFE_LIKE" }, 
  113. 		current_value = 1, 
  114. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_RADIO_TIP", 
  115. 		id = #Data 
  116. 	} 
  117. 	 
  118. --]]	 
  119. 	Data[#Data + 1] = { 
  120. 		type = TYPE_TOGGLE, 
  121. 		label = "CONTROLS_MINIMAP_VIEW", 
  122. 		options = {"MINIMAP_ROTATIONAL", "MINIMAP_STATIC"}, 
  123. 		current_value = 1, 
  124. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_MINIMAP_TIP", 
  125. 		id = #Data 
  126. 	} 
  127. 	--Data[#Data].current_value = Current_static_map and 2 or 1 
  128. 	--Data[#Data].old_value = Data[#Data].current_value 
  129. --[[ 
  130. 	Data[#Data + 1] = { 
  131. 		type = TYPE_TOGGLE, 
  132. 		label = "PLT_MENU_PAUSE_FOCUS", 
  133. 		options = {"OPTION_NO", "OPTION_YES"}, 
  134. 		current_value = 2, 
  135. 		tool_tip_text = "MENU_OPTIONS_GAMEPLAY_FOCUS_TIP", 
  136. 		id = #Data 
  137. 	} 
  138. --]] 
  139. --[[ 
  140. 	Data[#Data + 1] = { 
  141. 		type = TYPE_TOGGLE, 
  142. 		label = "MENU_OPTION_SHOW_FILM_GRAIN", 
  143. 		options = {"OPTION_NO", "OPTION_YES"}, 
  144. 		current_value = 2, 
  145. 		tool_tip_text = "MENU_OPTION_SHOW_FILM_GRAIN", 
  146. 		id = #Data 
  147. 	} 
  148. --]]	 
  149.  
  150. 	Data[#Data + 1] = { 
  151. 		type = TYPE_TOGGLE, 
  152. 		label = "MENU_OPTION_PAUSE_INV_SCREEN", 
  153. 		options = {"OPTION_NO", "OPTION_YES"}, 
  154. 		current_value = 2, 
  155. 		tool_tip_text = "MENU_OPTION_PAUSE_INV_SCREEN_HINT", 
  156. 		id = PAUSE_INV_SCREEN_INDEX 
  157. 	} 
  158.  
  159. end 
  160.  
  161. function options_difficulty_finish_init() 
  162.  
  163. 	--Initialize Header 
  164. 	if game_get_platform() == "PC" then 
  165. 		Header_obj:set_text("MENU_GAMEPLAY", Screen_width) 
  166. 		options_difficulty_add_pc_options() 
  167. 	else 
  168. 		Header_obj:set_text("MENU_DIFFICULTY", Screen_width) 
  169. 	end 
  170.  
  171. 	-- Subscribe to the button presses we need 
  172. 	 
  173. 	Input_tracker = Vdo_input_tracker:new() 
  174. 	Input_tracker:add_input("select", "options_difficulty_button_a", 50) 
  175. 	Input_tracker:add_input("back", "options_difficulty_button_b", 50) 
  176. 	if In_pause_menu then 
  177. 		Input_tracker:add_input("pause", "options_difficulty_button_start", 50) 
  178. 	end 
  179. 	Input_tracker:add_input("nav_up", "options_difficulty_nav_up", 50) 
  180. 	Input_tracker:add_input("nav_down", "options_difficulty_nav_down", 50) 
  181. 	Input_tracker:add_input("nav_left", "options_difficulty_nav_left", 50) 
  182. 	Input_tracker:add_input("nav_right", "options_difficulty_nav_right", 50) 
  183. 	Input_tracker:subscribe(false) 
  184. 	 
  185. 	--Set Button hints 
  186. 	local hint_data = { 
  187. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  188. 	} 
  189. 	if game_get_platform() == "PC" then 
  190. 		hint_data[2] = {CTRL_BUTTON_X, "MENU_RESTORE_DEFAULTS"} 
  191. 		Input_tracker:add_input("alt_select", "options_difficulty_button_x", 50) 
  192. 	end 
  193. 	Menu_hint_bar:set_hints(hint_data)   
  194. 	 
  195. 	Data[DIFFICULTY_INDEX].current_value = get_current_difficulty() + 1	-- Difficulties start at 0 
  196. 	vint_dataresponder_request("pause_menu_options", "options_difficulty_populate", 0, PM_MENU_DIFFICULTY_OPTIONS) 
  197. 	List:draw_items(Data, 1, Screen_width, 7) 
  198.  
  199. 	--Store some locals to the pause menu common for screen processing. 
  200. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  201. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  202. 	 
  203. 	-- Add mouse inputs for the PC 
  204. 	if game_get_platform() == "PC" then 
  205. 		Menu_hint_bar:set_highlight(0) 
  206. 		 
  207. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  208. 		List:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  209. 		Menu_hint_bar:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  210. 		Mouse_input_tracker:subscribe(true) 
  211. 		 
  212. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  213. 	end 
  214.  
  215. end 
  216.  
  217. function options_difficulty_populate(airplane, subtitles, radio, minimap, pause_focus, film_grain, pause_on_inv_screen) 
  218. 	--Data[AIRPLANE_INDEX].previous_value = Data[AIRPLANE_INDEX].current_value 
  219. 	--Data[AIRPLANE_INDEX].current_value = airplane + 1 
  220. 	Data[SUBTITLES_INDEX].previous_value = Data[SUBTITLES_INDEX].current_value 
  221. 	Data[SUBTITLES_INDEX].current_value = subtitles and 2 or 1 
  222. 	--Data[RADIO_INDEX].previous_value = Data[RADIO_INDEX].current_value 
  223. 	--Data[RADIO_INDEX].current_value = radio + 1 
  224. 	Data[MINIMAP_INDEX].previous_value = Data[MINIMAP_INDEX].current_value 
  225. 	Data[MINIMAP_INDEX].current_value = minimap and 2 or 1 
  226. 	--Data[PAUSE_FOCUS_INDEX].previous_value = Data[PAUSE_FOCUS_INDEX].current_value 
  227. 	--Data[PAUSE_FOCUS_INDEX].current_value = pause_focus and 2 or 1 
  228. 	--Data[FILM_GRAIN_INDEX].previous_value = Data[FILM_GRAIN_INDEX].current_value 
  229. 	--Data[FILM_GRAIN_INDEX].current_value = film_grain and 2 or 1 
  230. 	Data[PAUSE_INV_SCREEN_INDEX].previous_value = Data[PAUSE_INV_SCREEN_INDEX].current_value 
  231. 	Data[PAUSE_INV_SCREEN_INDEX].current_value = pause_on_inv_screen and 2 or 1 
  232. end 
  233.  
  234. function pause_options_difficulty_cleanup() 
  235. 	-- Nuke all button subscriptions 
  236. 	Input_tracker:subscribe(false) 
  237. 	if Mouse_input_tracker ~= nil then 
  238. 		Mouse_input_tracker:subscribe(false) 
  239. 	end 
  240. 	List:enable_toggle_input(false) 
  241. end 
  242.  
  243. function options_difficulty_nav_up(event, acceleration) 
  244. 	-- Move highlight up 
  245. 	List:move_cursor(-1) 
  246. 	 
  247. 	-- Set the tool_tip_text 
  248. 	local current_idx = List:get_selection() 
  249. 	local menu_item = Data[current_idx] 
  250. 	pause_options_difficulty_set_tool_tip(menu_item.tool_tip_text) 
  251. end 
  252.  
  253. function options_difficulty_nav_down(event, acceleration) 
  254. 	-- Move highlight down 
  255. 	List:move_cursor(1) 
  256. 	 
  257. 	-- Set the tool_tip_text 
  258. 	local current_idx = List:get_selection() 
  259. 	local menu_item = Data[current_idx] 
  260. 	pause_options_difficulty_set_tool_tip(menu_item.tool_tip_text) 
  261. end 
  262.  
  263. function options_difficulty_nav_left(event, acceleration) 
  264. 	List:move_slider(-1) 
  265. 	options_controls_update_option_value() 
  266. end 
  267.  
  268. function options_difficulty_nav_right(event, acceleration) 
  269. 	List:move_slider(1) 
  270. 	options_controls_update_option_value() 
  271. end 
  272.  
  273. function options_controls_update_option_value() 
  274. 	local current_idx = List:get_selection() 
  275. 	local menu_item = Data[current_idx] 
  276. 	 
  277. 	local bool_val = true 
  278. 	if menu_item.current_value == 1 then 
  279. 		bool_val = false 
  280. 	end 
  281. 	 
  282. 	local converted_float = menu_item.current_value 
  283. 	 
  284. 	pause_menu_update_option(PM_MENU_DIFFICULTY_OPTIONS, current_idx, bool_val, converted_float) 
  285. end 
  286.  
  287. function options_difficulty_button_b(event, acceleration) 
  288. 	--back up a screen 
  289. 	game_difficulty_select(Data[DIFFICULTY_INDEX].current_value - 1)	-- Difficulties indexed by 0 
  290. 	pause_menu_accept_options() 
  291. 	List:button_b() 
  292.  
  293. 	Input_tracker:subscribe(false) 
  294. 	if Mouse_input_tracker ~= nil then 
  295. 		Mouse_input_tracker:subscribe(false) 
  296. 	end 
  297. 	List:enable_toggle_input(false) 
  298. 	 
  299. 	-- animate tooltip out 
  300. 	local anim_h = vint_object_find("animate_out", 0, Difficulty_doc_handle) 
  301. 	lua_play_anim(anim_h, 0, Difficulty_doc_handle) 
  302. 	 
  303. 	--Remove current menu from the stack 
  304. 	menu_common_stack_remove() 
  305. 	menu_common_transition_pop(1) 
  306. end 
  307.  
  308. function options_difficulty_button_a(event, acceleration) 
  309. 	options_difficulty_nav_right(event, acceleration) 
  310. end 
  311.  
  312. function options_difficulty_button_x(event, acceleration) 
  313. 	dialog_box_confirmation("OPTIONS_MENU_DEFAULTS_TITLE", "OPTIONS_MENU_DEFAULTS_DESC", "options_difficulty_revert", true, true,1) 
  314. end 
  315.  
  316. function options_difficulty_revert(result, action) 
  317. 	if result == 0 then 
  318. 		pause_menu_restore_defaults(PM_MENU_DIFFICULTY_OPTIONS) 
  319. 		vint_dataresponder_request("pause_menu_options", "options_difficulty_populate", 0, PM_MENU_DIFFICULTY_OPTIONS)	 
  320. 		List:draw_items(Data, List:get_selection(), Screen_width, 7, nil, nil, false) 
  321. 		if Mouse_input_tracker ~= nil then 
  322. 			Mouse_input_tracker:remove_all() 
  323. 			List:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  324. 			Menu_hint_bar:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  325. 			Mouse_input_tracker:subscribe(true) 
  326. 		end 
  327. 	end 
  328. end 
  329.  
  330. function options_difficulty_button_start(event, acceleration) 
  331. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  332. 	Input_tracker:subscribe(false) 
  333. 	menu_common_transition_pop(4) -- options_difficulty, options, pause_menu_top, menu_common 
  334. 	bg_saints_slide_out() 
  335. end 
  336.  
  337. -- Mouse inputs 
  338. function pause_options_difficulty_mouse_click(event, target_handle, mouse_x, mouse_y) 
  339. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  340. 	if hint_index == 1 then 
  341. 		options_difficulty_button_b() 
  342. 	end 
  343. 	if hint_index == 2 then 
  344. 		options_difficulty_button_x() 
  345. 	end 
  346.  
  347. 	local new_index = List:get_button_index(target_handle) 
  348. 	if new_index ~= 0 then 
  349. 		List:set_selection(new_index) 
  350. 		-- Because only toggles are used in this menu, this acts as nav_right 
  351. 		options_difficulty_nav_right() 
  352. 	end 
  353. 	if List:is_left_arrow(target_handle) then 
  354. 		List:move_slider(-1) 
  355. 		options_controls_update_option_value() 
  356. 	end 
  357. end 
  358.  
  359. function pause_options_difficulty_mouse_move(event, target_handle) 
  360. 	Menu_hint_bar:set_highlight(0) 
  361. 	 
  362. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  363. 	if hint_index ~= 0 then 
  364. 		Menu_hint_bar:set_highlight(hint_index) 
  365. 	end 
  366. 	 
  367. 	local new_index = List:get_button_index(target_handle) 
  368. 	if new_index ~= 0 then 
  369. 		List:set_selection(new_index) 
  370. 		List:move_cursor(0, true) 
  371. 		-- Set the tool_tip_text 
  372. 		local current_idx = List:get_selection() 
  373. 		local menu_item = Data[current_idx] 
  374. 		pause_options_difficulty_set_tool_tip(menu_item.tool_tip_text) 
  375. 	end 
  376. end 
  377.  
  378. function pause_options_difficulty_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  379. 	if scroll_lines ~= 0 then 
  380. 		if List:get_scroll_region_handle() == target_handle then 
  381. 			List:scroll_list(scroll_lines * -1) 
  382. 			List:update_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  383. 			Menu_hint_bar:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  384. 			Mouse_input_tracker:subscribe(true) 
  385. 		end 
  386. 	end 
  387. end 
  388.  
  389. function pause_options_difficulty_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  390. 	if List.scrollbar.tab_grp.handle == target_handle then 
  391. 		local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, List.num_buttons - (List.max_buttons - 1)) 
  392. 		List:scroll_list(0, new_start_index) 
  393. 	end 
  394. end 
  395.  
  396. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  397. -- 
  398. function pause_options_difficulty_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  399. 	if List.scrollbar.tab_grp.handle == target_handle then 
  400. 		local start_index = List:get_visible_indices() 
  401. 		List.scrollbar:release_scrolltab(start_index, List.num_buttons - (List.max_buttons - 1)) 
  402. 		List:update_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  403. 		Menu_hint_bar:add_mouse_inputs("pause_options_difficulty", Mouse_input_tracker) 
  404. 		Mouse_input_tracker:subscribe(true) 
  405. 	end 
  406. end