./main_menu_coop.lua

  1. local JOIN_FRIEND_INDEX		= 1 
  2. local NEW_GAME_INDEX			= 2 
  3. local LOAD_GAME_INDEX		= 3 
  4. local MATCHMAKING_INDEX		= 4 
  5.  
  6. local ID_JOIN_FRIEND			= 1 
  7. local ID_NEW_GAME				= 2 
  8. local ID_LOAD_GAME			= 3 
  9. local ID_MATCHMAKING			= 4 
  10. local ID_CHECK_MESSAGES		= 5 
  11.  
  12. local Check_messages_button = { 
  13. 	type = TYPE_BUTTON, 
  14. 	label = "MAINMENU_CHECK_MESSAGES", 
  15. 	id = ID_CHECK_MESSAGES, 
  16. } 
  17.  
  18. local Syslink_join_button = { 
  19. 	type = TYPE_BUTTON, 
  20. 	label = "MULTI_FIND_GAMES", 
  21. 	id = ID_JOIN_FRIEND, 
  22. } 
  23.  
  24. local Live_join_button = { 
  25. 	type = TYPE_BUTTON, 
  26. 	label = "MULTI_JOIN_FRIEND", 
  27. 	id = ID_JOIN_FRIEND, 
  28. } 
  29.  
  30. local New_game_button = { 
  31. 	type = TYPE_BUTTON, 
  32. 	label = "MAINMENU_NEW", 
  33. 	id = ID_NEW_GAME, 
  34. } 
  35.  
  36. local Load_game_button = { 
  37. 	type = TYPE_BUTTON, 
  38. 	label = "SAVELOAD_LOAD_GAME", 
  39. 	id = ID_LOAD_GAME, 
  40. } 
  41.  
  42. local Matchmaking_button = { 
  43. 	type = TYPE_BUTTON, 
  44. 	label = "MULTI_MATCHMAKING", 
  45. 	id = ID_MATCHMAKING, 
  46. } 
  47.  
  48. local Data 
  49. local Anims = {} 
  50.  
  51. local Input_tracker 
  52. local Mouse_input_tracker 
  53. local Should_lock = false 
  54.  
  55. local Tween_done = true 
  56.  
  57. ---------------------------------------------------------------------------  
  58. -- Initialize Pause Options Menu. 
  59. --------------------------------------------------------------------------- 
  60. function main_menu_coop_init() 
  61. 	-- Subscribe to the button presses we need 
  62. 	  
  63. 	Input_tracker = Vdo_input_tracker:new() 
  64. 	Input_tracker:add_input("select", "main_menu_coop_button_a", 50) 
  65. 	Input_tracker:add_input("back", "main_menu_coop_button_b", 50) 
  66. 	Input_tracker:add_input("nav_up", "main_menu_coop_nav_up", 50) 
  67. 	Input_tracker:add_input("nav_down", "main_menu_coop_nav_down", 50) 
  68. 	Input_tracker:add_input("nav_left", "main_menu_coop_nav_left", 50) 
  69. 	Input_tracker:add_input("nav_right", "main_menu_coop_nav_right", 50) 
  70. 	 
  71. 	main_menu_coop_gained_focus() 
  72. end 
  73.  
  74. function main_menu_coop_gained_focus() 
  75. 	Input_tracker:subscribe(false) 
  76. 	 
  77. 	local screen_width = 600 
  78. 	 
  79. 	local header_str = "MAINMENU_ONLINE_GAME" 
  80. 	local header_crumb = "" 
  81. 	Data = { } 
  82.  
  83. 	-- DAD - 9/10/11 - reset the indices (PS3) (last minute hack) 
  84. 	JOIN_FRIEND_INDEX		= 1 
  85. 	NEW_GAME_INDEX			= 2 
  86. 	LOAD_GAME_INDEX		= 3 
  87. 	MATCHMAKING_INDEX		= 4 
  88. 	 
  89. 	if game_get_platform() == "PS3" and Main_menu_coop_is_xbox_live then 
  90. 		JOIN_FRIEND_INDEX = JOIN_FRIEND_INDEX + 1 
  91. 		NEW_GAME_INDEX		= JOIN_FRIEND_INDEX + 1 
  92. 		LOAD_GAME_INDEX	= JOIN_FRIEND_INDEX + 2 
  93. 		MATCHMAKING_INDEX	= JOIN_FRIEND_INDEX + 3 
  94. 		Data[1] = Check_messages_button 
  95. 	end 
  96. 	 
  97. 	--Get menu specific data...  
  98. 	if Main_menu_coop_is_xbox_live then 
  99. 		-- Xbox live 
  100. 		Data[JOIN_FRIEND_INDEX] = Live_join_button 
  101. 	else 
  102. 		-- System link 
  103. 		Data[JOIN_FRIEND_INDEX] = Syslink_join_button 
  104. 		header_str = "MAINMENU_SYSLINK_TITLE" 
  105. 	end 
  106. 	Data[NEW_GAME_INDEX] = New_game_button 
  107. 	 
  108. 	if Whored_mode_active == true then 
  109. 		if Main_menu_coop_is_xbox_live then 
  110. 			Data[NEW_GAME_INDEX].label = "MAINMENU_WHORED_COOP_OPTION" 
  111. 		else 
  112. 			Data[NEW_GAME_INDEX].label = "MAINMENU_WHORED_OPTION" 
  113. 		end 
  114. 		MATCHMAKING_INDEX = LOAD_GAME_INDEX 
  115. 		header_crumb = "MAINMENU_WHORED" 
  116. 	else 
  117. 		Data[LOAD_GAME_INDEX] = Load_game_button	 
  118. 	end 
  119. 	 
  120. 	if Main_menu_coop_is_xbox_live == true then 
  121. 		-- Xbox live 
  122. 		Data[MATCHMAKING_INDEX] = Matchmaking_button 
  123. 	end 
  124. 	 
  125. 	--Initialize Header 
  126. 	Header_obj:set_text(header_str, screen_width) 
  127. 	Header_obj:set_crumb(header_crumb) 
  128.  
  129. 	--Setup Button Hints  
  130. 	local hint_data = { 
  131. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  132. 	} 
  133. 	Menu_hint_bar:set_hints(hint_data)   
  134. 	 
  135. 	--Get the selection option from when the menu was last loaded 
  136. 	local last_option_selected = menu_common_stack_get_index(Data) 
  137.  
  138. 	List:draw_items(Data, last_option_selected, screen_width) 
  139. 	 
  140. 	--Store some locals to the pause menu common for screen processing. 
  141. 	menu_common_set_list_style(List, Header_obj, screen_width) 
  142. 	menu_common_set_screen_data(List, Header_obj, nil, Screen_back_out_anim, Screen_slide_out_anim, anim_finished) 
  143.  
  144. 	-- Add mouse inputs for the PC 
  145. 	if game_get_platform() == "PC" then 
  146. 		if Mouse_input_tracker == nil then 
  147. 			Mouse_input_tracker = Vdo_input_tracker:new() 
  148. 		end 
  149. 		List:add_mouse_inputs("main_menu_coop", Mouse_input_tracker) 
  150. 		Menu_hint_bar:add_mouse_inputs("main_menu_coop", Mouse_input_tracker) 
  151. 		Menu_hint_bar:set_highlight(0) 
  152. 		Mouse_input_tracker:subscribe(true) 
  153. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  154. 	end 
  155. end 
  156.  
  157. function main_menu_coop_lost_focus() 
  158. 	-- Nuke all button subscriptions 
  159. 	Input_tracker:subscribe(false) 
  160. 	if Mouse_input_tracker ~= nil then 
  161. 		Mouse_input_tracker:subscribe(false) 
  162. 	end 
  163. 	List:enable_toggle_input(false) 
  164. end 
  165.  
  166. function anim_finished() 
  167. 	if Should_lock == false then 
  168. 		main_menu_coop_lock_controls(false) 
  169. 	end 
  170. end 
  171.  
  172. function main_menu_coop_cleanup() 
  173. 	-- Nuke all button subscriptions 
  174. 	Input_tracker:subscribe(false) 
  175. 	if Mouse_input_tracker ~= nil then 
  176. 		Mouse_input_tracker:subscribe(false) 
  177. 	end 
  178. 	List:enable_toggle_input(false) 
  179. end 
  180.  
  181. function main_menu_coop_nav_up(event, acceleration) 
  182. 	-- Move highlight up 
  183. 	List:move_cursor(-1) 
  184. end 
  185.  
  186. function main_menu_coop_nav_down(event, acceleration) 
  187. 	-- Move highlight down 
  188. 	List:move_cursor(1) 
  189. end 
  190.  
  191. function main_menu_coop_nav_left(event, acceleration) 
  192. 	-- Move highlight left 
  193. 	List:move_slider(-1) 
  194. end 
  195.  
  196. function main_menu_coop_nav_right(event, acceleration) 
  197. 	-- Move highlight right 
  198. 	List:move_slider(1) 
  199. end 
  200.  
  201. function main_menu_coop_button_a(event, acceleration) 
  202. 	if Tween_done == true then 
  203. 		--Set the screen data to the list data 
  204. 		Data = List:return_data() 
  205. 		local current_id = List:get_id() 
  206. 		 
  207. 		--pass off the input to the list 
  208. 		--List:button_a() 
  209. 		 
  210. 		--Add current selection to the stack to store the selected position on the menu 
  211. 		menu_common_stack_add(current_id) 
  212. 		 
  213. 		if current_id == ID_JOIN_FRIEND then 
  214. 			if Main_menu_coop_is_xbox_live == true then 
  215. 				Coop_connect_operation = COOP_ONLINE_JOIN_LIST 
  216. 			else  
  217. 				Coop_connect_operation = COOP_SYSLINK_JOIN_LIST 
  218. 			end 
  219. 			menu_common_transition_push("pause_invite_friends") 
  220. 			return 
  221. 		elseif current_id == ID_NEW_GAME then 
  222. 			if Main_menu_coop_is_xbox_live then 
  223. 				game_coop_start_new_live() 
  224. 			else  
  225. 				game_coop_start_new_syslink() 
  226. 			end 
  227. 			 
  228. 			if Whored_mode_active then 
  229. 				main_menu_horde_start() 
  230. 			else 
  231. 				menu_common_transition_push("main_menu_new_game") 
  232. 			end 
  233. 			return	 
  234. 		elseif current_id == ID_LOAD_GAME then 
  235. 			Load_for_coop = true 
  236. 			menu_common_transition_push("pause_save_game")			 
  237. 			return	 
  238. 		elseif current_id == ID_MATCHMAKING then 
  239. 			main_menu_matchmaking(Whored_mode_active) 
  240. 			main_menu_coop_lock_controls(true) 
  241. 		elseif current_id == ID_CHECK_MESSAGES then 
  242. 			main_menu_check_messages() 
  243. 		end 
  244. 	end 
  245. end 
  246.  
  247. function main_menu_coop_button_b(event, acceleration) 
  248. 	if Tween_done == true then 
  249. 			--pass off the input to the list 
  250. 			List:button_b() 
  251. 			 
  252. 			main_menu_coop_lost_focus() 
  253. 			 
  254. 			--Remove current menu from the stack 
  255. 			menu_common_stack_remove() 
  256. 			 
  257. 			--Pop Screen off the list 
  258. 			menu_common_transition_pop(1) 
  259. 		--else 
  260. 			--back up a screen 
  261. 			--Anims.list_in:stop() 
  262. 			--Anims.list_out:play() 
  263. 			--Anims.list_out_tween = Vdo_tween_object:new("list_anchor_twn_2") 
  264. 			--Anims.list_out_tween:set_property("end_event", "ui_options_audio_anim_done") 
  265. 			--Tween_done = false 
  266. 		--end 
  267. 	end 
  268. end 
  269.  
  270. function main_menu_coop_mouse_click(event, target_handle) 
  271. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  272. 	if hint_index == 1 then 
  273. 		main_menu_coop_button_b() 
  274. 	end 
  275.  
  276. 	local new_index = List:get_button_index(target_handle) 
  277. 	if new_index ~= 0 then 
  278. 		List:set_selection(new_index) 
  279. 		main_menu_coop_button_a() 
  280. 	end 
  281. end 
  282.  
  283. function main_menu_coop_mouse_move(event, target_handle) 
  284. 	Menu_hint_bar:set_highlight(0) 
  285. 	 
  286. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  287. 	if hint_index ~= 0 then 
  288. 		Menu_hint_bar:set_highlight(hint_index) 
  289. 	end 
  290. 	 
  291. 	local new_index = List:get_button_index(target_handle) 
  292. 	if new_index ~= 0 then 
  293. 		List:set_selection(new_index) 
  294. 		List:move_cursor(0, true) 
  295. 	end 
  296. end 
  297.  
  298. function main_menu_coop_lock_controls(lock) 
  299. 	Should_lock = lock 
  300. 	 
  301. 	if Should_lock then 
  302. 		debug_print("vint", "Coop input locked!\n") 
  303. 	else 
  304. 		debug_print("vint", "Coop input unlocked!\n") 
  305. 	end 
  306. 	-- Nuke all button subscriptions 
  307. 	Input_tracker:subscribe(not lock) 
  308. 	if Mouse_input_tracker ~= nil then 
  309. 		Mouse_input_tracker:subscribe(not lock) 
  310. 	end 
  311. end 
  312.