./pause_options_menu.lua

  1. local CONTROLS_INDEX				= 1 
  2. local CONTROL_CONFIG_INDEX		= 2 
  3. local DIFFICULTY_INDEX			= 3 
  4. local DISPLAY_INDEX				= 4 
  5. local AUDIO_INDEX					= 5 
  6. local REMAP_INDEX					= 6 
  7. local MOUSE_INDEX					= 7 
  8.  
  9. local ID_CONTROLS				= 1 
  10. local ID_CONTROL_CONFIG		= 2 
  11. local ID_DIFFICULTY			= 3 
  12. local ID_DISPLAY				= 4 
  13. local ID_AUDIO					= 5 
  14. local ID_REMAP					= 6 
  15. local ID_MOUSE					= 7 
  16.  
  17. local Data = { } 
  18.  
  19. function option_menu_init_data () 
  20. 	Data = { } 
  21. 	 
  22. 	if game_get_platform() == "PC" then 
  23. 		CONTROLS_INDEX = -1 
  24. 		CONTROL_CONFIG_INDEX = -1 
  25. 		Data[#Data + 1] = { 
  26. 			type = TYPE_BUTTON, 
  27. 			label = "MENU_OPTIONS_MOUSE",  
  28. 			id = ID_MOUSE 
  29. 		} 
  30. 		MOUSE_INDEX = #Data 
  31. 		REMAP_INDEX = -1 
  32. 	else 
  33. 		Data[#Data + 1] = { 
  34. 			type = TYPE_BUTTON, 
  35. 			label = "MENU_CONTROL_OPTIONS", 
  36. 			id = ID_CONTROLS, 
  37. 		} 
  38. 		CONTROLS_INDEX = #Data 
  39. 		 
  40. 		Data[#Data + 1] = { 
  41. 			type = TYPE_BUTTON, 
  42. 			label = "MENU_CONTROL_SCHEMES",	 
  43. 			id = ID_CONTROL_CONFIG, 
  44. 		} 
  45. 		CONTROL_CONFIG_INDEX = #Data 
  46. 	end 
  47. 	 
  48. 	local diff_label = "MENU_DIFFICULTY" 
  49. 	if game_get_platform() == "PC" then 
  50. 		diff_label = "MENU_GAMEPLAY" 
  51. 	end 
  52. 	Data[#Data + 1] = { 
  53. 		type = TYPE_BUTTON, 
  54. 		label = diff_label, 
  55. 		id = ID_DIFFICULTY, 
  56. 	} 
  57. 	DIFFICULTY_INDEX = #Data 
  58. 	 
  59. 	Data[#Data + 1] = { 
  60. 		type = TYPE_BUTTON, 
  61. 		label = "MENU_OPTIONS_DISPLAY", 
  62. 		id = ID_DISPLAY, 
  63. 	} 
  64. 	DISPLAY_INDEX = #Data 
  65. 	 
  66. 	Data[#Data + 1] = { 
  67. 		type = TYPE_BUTTON, 
  68. 		label = "MENU_OPTIONS_AUDIO", 
  69. 		id = ID_AUDIO, 
  70. 	} 
  71. 	AUDIO_INDEX = #Data	 
  72. end 
  73.  
  74. local Anims = {} 
  75.  
  76. local Input_tracker 
  77. local Mouse_input_tracker 
  78.  
  79. local Screen_width 
  80. if vint_is_std_res() then 
  81. 	Screen_width = 750 
  82. else 
  83. 	Screen_width = 840 
  84. end 
  85.  
  86. local Tween_done = true 
  87.  
  88.  
  89. ---------------------------------------------------------------------------  
  90. -- Initialize Pause Options Menu. 
  91. --------------------------------------------------------------------------- 
  92. function pause_options_menu_init() 
  93. 	-- Subscribe to the button presses we need 
  94. 	 
  95. 	Input_tracker = Vdo_input_tracker:new() 
  96. 	Input_tracker:add_input("select", "options_menu_button_a", 50) 
  97. 	Input_tracker:add_input("back", "options_menu_button_b", 50) 
  98. 	Input_tracker:add_input("nav_up", "options_menu_nav_up", 50) 
  99. 	Input_tracker:add_input("nav_down", "options_menu_nav_down", 50) 
  100. 	Input_tracker:add_input("nav_left", "options_menu_nav_left", 50) 
  101. 	Input_tracker:add_input("nav_right", "options_menu_nav_right", 50) 
  102. 	if In_pause_menu then 
  103. 		Input_tracker:add_input("pause", "options_menu_button_start", 50) 
  104. 	end 
  105. 	 
  106. 	Input_tracker:subscribe(false) 
  107.  
  108. 	--Initialize Header 
  109. 	Header_obj:set_text("MENU_OPTIONS_TITLE", Screen_width) 
  110.  
  111. 	--Setup Button Hints 
  112. 	local hint_data = { 
  113. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  114. 	} 
  115. 	Menu_hint_bar:set_hints(hint_data)   
  116. 	 
  117. 	-- Initialize the list object and draw	 
  118. 	option_menu_init_data() 
  119. 	 
  120. 	--Get the selection option from when the menu was last loaded 
  121. 	local last_option_selected = menu_common_stack_get_index(Data) 
  122. 	 
  123. 	--Draw items... 
  124. 	List:draw_items(Data, last_option_selected, Screen_width) 
  125. 	 
  126. 	--Store some locals to the pause menu common for screen processing. 
  127. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  128. 	 
  129. 	bg_saints_show(true) 
  130. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)	 
  131. 	 
  132. 	if not In_pause_menu then 
  133. 		--main_menu_logo_hide() 
  134. 		if First_time then 
  135. 			Screen_in_anim:play(0) 
  136. 			bg_saints_slide_in(Screen_width) 
  137. 			First_time = false 
  138. 		end 
  139. 	end 
  140. 	 
  141. 	-- Add mouse inputs for the PC 
  142. 	if game_get_platform() == "PC" then 
  143. 		Menu_hint_bar:set_highlight(0) 
  144. 		 
  145. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  146. 		List:add_mouse_inputs("pause_options_menu", Mouse_input_tracker) 
  147. 		Menu_hint_bar:add_mouse_inputs("pause_options_menu", Mouse_input_tracker) 
  148. 		Mouse_input_tracker:subscribe(true) 
  149. 		 
  150. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  151. 	end 
  152. 	 
  153. end 
  154.  
  155. function pause_options_menu_cleanup() 
  156. 	-- Nuke all button subscriptions 
  157. 	Input_tracker:subscribe(false) 
  158. 	if Mouse_input_tracker ~= nil then 
  159. 		Mouse_input_tracker:subscribe(false) 
  160. 	end 
  161. 	List:enable_toggle_input(false) 
  162. end 
  163.  
  164. function options_menu_nav_up(event, acceleration) 
  165. 	-- Move highlight up 
  166. 	List:move_cursor(-1) 
  167. end 
  168.  
  169. function options_menu_nav_down(event, acceleration) 
  170. 	-- Move highlight down 
  171. 	List:move_cursor(1) 
  172. end 
  173.  
  174. function options_menu_nav_left(event, acceleration) 
  175. 	-- Move highlight left 
  176. 	List:move_slider(-1) 
  177. end 
  178.  
  179. function options_menu_nav_right(event, acceleration) 
  180. 	-- Move highlight right 
  181. 	List:move_slider(1) 
  182. end 
  183.  
  184. function options_menu_button_a(event, acceleration) 
  185. 	if Tween_done == true then 
  186. 		--Set the screen data to the list data 
  187. 		Data = List:return_data() 
  188. 		local current_id = List:get_id() 
  189. 				 
  190. 		--Add current selection to the stack to store the selected position on the menu 
  191. 		menu_common_stack_add(current_id) 
  192. 		 
  193. 		--pass off the input to the list 
  194. 		List:button_a() 
  195. 		 
  196. 		if current_id == ID_CONTROLS then 
  197. 			menu_common_transition_push("pause_options_controls") 
  198. 			return 
  199. 		elseif current_id == ID_CONTROL_CONFIG then 
  200. 			menu_common_transition_push("pause_ctrl_scheme")			 
  201. 			return	 
  202. 		elseif current_id == ID_DIFFICULTY then 
  203. 			menu_common_transition_push("pause_options_difficulty")			 
  204. 			return	 
  205. 		elseif current_id == ID_DISPLAY then 
  206. 		 
  207. 			if game_get_platform() == "PC" then 
  208. 				menu_common_transition_push("pause_options_display_pc") 
  209. 			else 
  210. 				menu_common_transition_push("pause_options_display") 
  211. 			end 
  212. 			return	 
  213. 		elseif current_id == ID_AUDIO then 
  214. 			menu_common_transition_push("pause_options_audio") 
  215. 			return 
  216. 		elseif current_id == ID_REMAP then 
  217. 			menu_common_transition_push("pause_options_remap")	 
  218. 			return 
  219. 		elseif current_id == ID_MOUSE then 
  220. 			menu_common_transition_push("pause_options_mouse")	 
  221. 			return	 
  222. 		end 
  223. 	end 
  224. end 
  225.  
  226.  
  227. function options_menu_button_b(event, acceleration) 
  228. 	if Tween_done == true then 
  229. 		List:button_b() 
  230.  
  231. 		Input_tracker:subscribe(false) 
  232. 		if Mouse_input_tracker ~= nil then 
  233. 			Mouse_input_tracker:subscribe(false) 
  234. 		end 
  235. 		 
  236. 		--Remove current menu from the stack 
  237. 		menu_common_stack_remove() 
  238. 		 
  239. 		--Pop Screen off the list 
  240. 		menu_common_transition_pop(1) 
  241. 	end 
  242. end 
  243.  
  244. function options_menu_button_start(event, acceleration) 
  245. 	if Tween_done == true then 
  246. 		menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  247. 		Input_tracker:subscribe(false) 
  248. 		menu_common_transition_pop(3) -- options, pause_menu_top, pause_menu_top 
  249. 		bg_saints_slide_out() 
  250. 	end 
  251. end 
  252.  
  253. function pause_options_menu_mouse_click(event, target_handle) 
  254. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  255. 	if hint_index == 1 then 
  256. 		options_menu_button_b() 
  257. 	end 
  258.  
  259. 	local new_index = List:get_button_index(target_handle) 
  260. 	if new_index ~= 0 then 
  261. 		List:set_selection(new_index) 
  262. 		options_menu_button_a() 
  263. 	end 
  264. end 
  265.  
  266. function pause_options_menu_mouse_move(event, target_handle) 
  267. 	Menu_hint_bar:set_highlight(0) 
  268. 	 
  269. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  270. 	if hint_index ~= 0 then 
  271. 		Menu_hint_bar:set_highlight(hint_index) 
  272. 	end 
  273. 	 
  274. 	local new_index = List:get_button_index(target_handle) 
  275. 	if new_index ~= 0 then 
  276. 		List:set_selection(new_index) 
  277. 		List:move_cursor(0, true) 
  278. 	end 
  279. end