./main_menu_campaign.lua

  1. local NEW_GAME_INDEX			= 1 
  2. local LOAD_GAME_INDEX		= 2 
  3.  
  4. local ID_NEW_GAME				= 1 
  5. local ID_LOAD_GAME			= 2 
  6.  
  7. local New_game_button = { 
  8. 	type = TYPE_BUTTON, 
  9. 	label = "MAINMENU_NEW", 
  10. 	id = ID_NEW_GAME, 
  11. } 
  12.  
  13. local Load_game_button = { 
  14. 	type = TYPE_BUTTON, 
  15. 	label = "SAVELOAD_LOAD_GAME", 
  16. 	id = ID_LOAD_GAME, 
  17. } 
  18.  
  19. local Data 
  20. local Anims = {} 
  21.  
  22. local Input_tracker 
  23. local Mouse_input_tracker 
  24.  
  25. local Tween_done = true 
  26.  
  27. local Screen_width 
  28. if vint_is_std_res() then 
  29. 	Screen_width = 750 
  30. else 
  31. 	Screen_width = 840 
  32. end 
  33.  
  34. ---------------------------------------------------------------------------  
  35. -- Initialize Pause Options Menu. 
  36. --------------------------------------------------------------------------- 
  37. function main_menu_campaign_init() 
  38. 	-- Subscribe to the button presses we need 
  39. 	  
  40. 	Input_tracker = Vdo_input_tracker:new() 
  41. 	Input_tracker:add_input("select", "main_menu_campaign_button_a", 50) 
  42. 	Input_tracker:add_input("back", "main_menu_campaign_button_b", 50) 
  43. 	Input_tracker:add_input("nav_up", "main_menu_campaign_nav_up", 50) 
  44. 	Input_tracker:add_input("nav_down", "main_menu_campaign_nav_down", 50) 
  45. 	Input_tracker:add_input("nav_left", "main_menu_campaign_nav_left", 50) 
  46. 	Input_tracker:add_input("nav_right", "main_menu_campaign_nav_right", 50) 
  47. 	Input_tracker:subscribe(false) 
  48. 	 
  49. 	local header_str = "MAINMENU_CAMPAIGN" 
  50. 	Data = { } 
  51. 		 
  52. 	Data[NEW_GAME_INDEX] = New_game_button 
  53. 	if game_is_demo() == false then 
  54. 		Data[LOAD_GAME_INDEX] = Load_game_button	 
  55. 	end 
  56.  
  57. 	--Initialize Header 
  58. 	Header_obj:set_text(header_str, Screen_width) 
  59.  
  60. 	--Setup Button Hints  
  61. 	local hint_data = { 
  62. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  63. 	} 
  64. 	Menu_hint_bar:set_hints(hint_data)   
  65. 	 
  66. 	--Get the selection option from when the menu was last loaded 
  67. 	local last_option_selected = menu_common_stack_get_index() 
  68.  
  69. 	List:draw_items(Data, last_option_selected, Screen_width) 
  70. 	 
  71. 	--Store some locals to the pause menu common for screen processing. 
  72. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  73. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim) 
  74. 	 
  75. 	if First_time then 
  76. 		Screen_in_anim:play(0) 
  77. 		bg_saints_slide_in(495) 
  78. 		First_time = false 
  79. 	end 
  80. 	 
  81. 	-- Add mouse inputs for the PC 
  82. 	if game_get_platform() == "PC" then 
  83. 		Menu_hint_bar:set_highlight(0) 
  84. 		 
  85. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  86. 		List:add_mouse_inputs("main_menu_campaign", Mouse_input_tracker) 
  87. 		Menu_hint_bar:add_mouse_inputs("main_menu_campaign", Mouse_input_tracker) 
  88. 		Mouse_input_tracker:subscribe(true) 
  89. 		 
  90. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  91. 	end 
  92. end 
  93.  
  94. function main_menu_campaign_cleanup() 
  95. 	-- Nuke all button subscriptions 
  96. 	Input_tracker:subscribe(false) 
  97. 	if Mouse_input_tracker ~= nil then 
  98. 		Mouse_input_tracker:subscribe(false) 
  99. 	end 
  100. 	List:enable_toggle_input(false) 
  101. end 
  102.  
  103. function main_menu_campaign_nav_up(event, acceleration) 
  104. 	-- Move highlight up 
  105. 	List:move_cursor(-1) 
  106. end 
  107.  
  108. function main_menu_campaign_nav_down(event, acceleration) 
  109. 	-- Move highlight down 
  110. 	List:move_cursor(1) 
  111. end 
  112.  
  113. function main_menu_campaign_nav_left(event, acceleration) 
  114. 	-- Move highlight left 
  115. 	List:move_slider(-1) 
  116. end 
  117.  
  118. function main_menu_campaign_nav_right(event, acceleration) 
  119. 	-- Move highlight right 
  120. 	List:move_slider(1) 
  121. end 
  122.  
  123. function main_menu_campaign_button_a(event, acceleration) 
  124. 	-- HVS_ARF - HS# 10810 See explanation in multi_core_platform.h 
  125. 	-- PS3 is in a different menu then the other platforms when this error can happen 
  126. 	local platform = game_get_platform() 
  127. 		 
  128. 	if platform == "PS3" then 
  129. 		if save_system_has_accepted_game_invite() then 
  130. 			return 
  131. 		end 
  132. 	end 
  133.  
  134. 	if Tween_done == true then 
  135. 		--Set the screen data to the list data 
  136. 		Data = List:return_data() 
  137. 		local current_id = List:get_id() 
  138.  
  139. 		--Add current selection to the stack to store the selected position on the menu 
  140. 		menu_common_stack_add(current_id) 
  141. 		 
  142. 		if current_id == ID_NEW_GAME then 
  143. 			menu_common_transition_push("main_menu_new_game") 
  144. 			return	 
  145. 		elseif current_id == ID_LOAD_GAME then 
  146. 			menu_common_transition_push("pause_save_game")			 
  147. 			return	 
  148. 		end	 
  149. 	end 
  150. end 
  151.  
  152. function main_menu_campaign_button_b(event, acceleration) 
  153. 	if Tween_done == true then 
  154. 		--pass off the input to the list 
  155. 		List:button_b() 
  156. 		--Remove current menu from the stack 
  157. 		menu_common_stack_remove() 
  158. 		 
  159. 		--Pop Screen off the list 
  160. 		menu_common_transition_pop(1) 
  161. 		 
  162. 		bg_saints_slide_out() 
  163. 	end 
  164. end 
  165.  
  166. function main_menu_campaign_mouse_click(event, target_handle) 
  167. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  168. 	if hint_index == 1 then 
  169. 		main_menu_campaign_button_b() 
  170. 	end 
  171.  
  172. 	local new_index = List:get_button_index(target_handle) 
  173. 	if new_index ~= 0 then 
  174. 		List:set_selection(new_index) 
  175. 		main_menu_campaign_button_a() 
  176. 	end 
  177. end 
  178.  
  179. function main_menu_campaign_mouse_move(event, target_handle) 
  180. 	Menu_hint_bar:set_highlight(0) 
  181. 	 
  182. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  183. 	if hint_index ~= 0 then 
  184. 		Menu_hint_bar:set_highlight(hint_index) 
  185. 	end 
  186. 	 
  187. 	local new_index = List:get_button_index(target_handle) 
  188. 	if new_index ~= 0 then 
  189. 		List:set_selection(new_index) 
  190. 		List:move_cursor(0, true) 
  191. 	end 
  192. end 
  193.