./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 = 495 
  80.  
  81. local Tween_done = true 
  82.  
  83.  
  84. ---------------------------------------------------------------------------  
  85. -- Initialize Pause Options Menu. 
  86. --------------------------------------------------------------------------- 
  87. function pause_options_menu_init() 
  88. 	-- Subscribe to the button presses we need 
  89. 	 
  90. 	Input_tracker = Vdo_input_tracker:new() 
  91. 	Input_tracker:add_input("select", "options_menu_button_a", 50) 
  92. 	Input_tracker:add_input("back", "options_menu_button_b", 50) 
  93. 	Input_tracker:add_input("nav_up", "options_menu_nav_up", 50) 
  94. 	Input_tracker:add_input("nav_down", "options_menu_nav_down", 50) 
  95. 	Input_tracker:add_input("nav_left", "options_menu_nav_left", 50) 
  96. 	Input_tracker:add_input("nav_right", "options_menu_nav_right", 50) 
  97. 	if In_pause_menu then 
  98. 		Input_tracker:add_input("pause", "options_menu_button_start", 50) 
  99. 	end 
  100. 	 
  101. 	Input_tracker:subscribe(false) 
  102.  
  103. 	--Initialize Header 
  104. 	Header_obj:set_text("MENU_OPTIONS_TITLE") 
  105.  
  106. 	--Setup Button Hints 
  107. 	local hint_data = { 
  108. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  109. 	} 
  110. 	Menu_hint_bar:set_hints(hint_data)   
  111. 	 
  112. 	-- Initialize the list object and draw	 
  113. 	option_menu_init_data() 
  114. 	 
  115. 	--Get the selection option from when the menu was last loaded 
  116. 	local last_option_selected = menu_common_stack_get_index(Data) 
  117. 	 
  118. 	--Draw items... 
  119. 	List:draw_items(Data, last_option_selected, Screen_width) 
  120. 	 
  121. 	--Store some locals to the pause menu common for screen processing. 
  122. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  123. 	 
  124. 	bg_saints_show(true) 
  125. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)	 
  126. 	 
  127. 	if not In_pause_menu then 
  128. 		main_menu_logo_hide() 
  129. 		if First_time then 
  130. 			Screen_in_anim:play(0) 
  131. 			bg_saints_slide_in(Screen_width) 
  132. 			First_time = false 
  133. 		end 
  134. 	end 
  135. 	 
  136. 	-- Add mouse inputs for the PC 
  137. 	if game_get_platform() == "PC" then 
  138. 		Menu_hint_bar:set_highlight(0) 
  139. 		 
  140. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  141. 		List:add_mouse_inputs("options_menu", Mouse_input_tracker) 
  142. 		Menu_hint_bar:add_mouse_inputs("options_menu", Mouse_input_tracker) 
  143. 		Mouse_input_tracker:subscribe(true) 
  144. 		 
  145. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  146. 	end 
  147. 	 
  148. end 
  149.  
  150. function pause_options_menu_cleanup() 
  151. 	-- Nuke all button subscriptions 
  152. 	Input_tracker:subscribe(false) 
  153. 	if Mouse_input_tracker ~= nil then 
  154. 		Mouse_input_tracker:subscribe(false) 
  155. 	end 
  156. 	List:enable_toggle_input(false) 
  157. end 
  158.  
  159. function options_menu_nav_up(event, acceleration) 
  160. 	-- Move highlight up 
  161. 	List:move_cursor(-1) 
  162. end 
  163.  
  164. function options_menu_nav_down(event, acceleration) 
  165. 	-- Move highlight down 
  166. 	List:move_cursor(1) 
  167. end 
  168.  
  169. function options_menu_nav_left(event, acceleration) 
  170. 	-- Move highlight left 
  171. 	List:move_slider(-1) 
  172. end 
  173.  
  174. function options_menu_nav_right(event, acceleration) 
  175. 	-- Move highlight right 
  176. 	List:move_slider(1) 
  177. end 
  178.  
  179. function options_menu_button_a(event, acceleration) 
  180. 	if Tween_done == true then 
  181. 		--Set the screen data to the list data 
  182. 		Data = List:return_data() 
  183. 		local current_id = List:get_id() 
  184. 				 
  185. 		--Add current selection to the stack to store the selected position on the menu 
  186. 		menu_common_stack_add(current_id) 
  187. 		 
  188. 		--pass off the input to the list 
  189. 		List:button_a() 
  190. 		 
  191. 		if current_id == ID_CONTROLS then 
  192. 			menu_common_transition_push("pause_options_controls") 
  193. 			return 
  194. 		elseif current_id == ID_CONTROL_CONFIG then 
  195. 			menu_common_transition_push("pause_ctrl_scheme")			 
  196. 			return	 
  197. 		elseif current_id == ID_DIFFICULTY then 
  198. 			menu_common_transition_push("pause_options_difficulty")			 
  199. 			return	 
  200. 		elseif current_id == ID_DISPLAY then 
  201. 		 
  202. 			if game_get_platform() == "PC" then 
  203. 				menu_common_transition_push("pause_options_display_pc") 
  204. 			else 
  205. 				menu_common_transition_push("pause_options_display") 
  206. 			end 
  207. 			return	 
  208. 		elseif current_id == ID_AUDIO then 
  209. 			menu_common_transition_push("pause_options_audio") 
  210. 			return 
  211. 		elseif current_id == ID_REMAP then 
  212. 			menu_common_transition_push("pause_options_remap")	 
  213. 			return 
  214. 		elseif current_id == ID_MOUSE then 
  215. 			menu_common_transition_push("pause_options_mouse")	 
  216. 			return	 
  217. 		end 
  218. 	end 
  219. end 
  220.  
  221.  
  222. function options_menu_button_b(event, acceleration) 
  223. 	if Tween_done == true then 
  224. 		List:button_b() 
  225.  
  226. 		Input_tracker:subscribe(false) 
  227. 		if Mouse_input_tracker ~= nil then 
  228. 			Mouse_input_tracker:subscribe(false) 
  229. 		end 
  230. 		 
  231. 		--Remove current menu from the stack 
  232. 		menu_common_stack_remove() 
  233. 		 
  234. 		--Pop Screen off the list 
  235. 		menu_common_transition_pop(1) 
  236. 	end 
  237. end 
  238.  
  239. function options_menu_button_start(event, acceleration) 
  240. 	if Tween_done == true then 
  241. 		menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  242. 		Input_tracker:subscribe(false) 
  243. 		menu_common_transition_pop(3) -- options, pause_menu_top, pause_menu_top 
  244. 		bg_saints_slide_out() 
  245. 	end 
  246. end 
  247.  
  248. function options_menu_mouse_click(event, target_handle) 
  249. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  250. 	if hint_index == 1 then 
  251. 		options_menu_button_b() 
  252. 	end 
  253.  
  254. 	local new_index = List:get_button_index(target_handle) 
  255. 	if new_index ~= 0 then 
  256. 		List:set_selection(new_index) 
  257. 		options_menu_button_a() 
  258. 	end 
  259. end 
  260.  
  261. function options_menu_mouse_move(event, target_handle) 
  262. 	Menu_hint_bar:set_highlight(0) 
  263. 	 
  264. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  265. 	if hint_index ~= 0 then 
  266. 		Menu_hint_bar:set_highlight(hint_index) 
  267. 	end 
  268. 	 
  269. 	local new_index = List:get_button_index(target_handle) 
  270. 	if new_index ~= 0 then 
  271. 		List:set_selection(new_index) 
  272. 		List:move_cursor(0, true) 
  273. 	end 
  274. end