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