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