./main_menu_coop_top.lua

  1. local XBOX_LIVE_INDEX		= 1 
  2. local SYSTEM_LINK_INDEX		= 2 
  3. local COOP_OPTIONS_INDEX	= 3 
  4.  
  5. local ID_XBOX_LIVE			= 1 
  6. local ID_SYSTEM_LINK			= 2 
  7. local	ID_COOP_OPTIONS		= 3 
  8.  
  9. local Xbox_live_button = { 
  10. 	type = TYPE_BUTTON, 
  11. 	label = "MAINMENU_ONLINE_GAME", 
  12. 	id = ID_XBOX_LIVE, 
  13. } 
  14.  
  15. local System_link_button = { 
  16. 	type = TYPE_BUTTON, 
  17. 	label = "MULTI_GAMETYPE_1", 
  18. 	id = ID_SYSTEM_LINK, 
  19. } 
  20.  
  21. local Coop_options_button = { 
  22. 	type = TYPE_BUTTON, 
  23. 	label = "COOP_OPTIONS", 
  24. 	id = ID_COOP_OPTIONS, 
  25. } 
  26.  
  27. local Data = { } 
  28. local Input_tracker 
  29. local Mouse_input_tracker 
  30.  
  31. local Screen_width 
  32. if vint_is_std_res() then 
  33. 	Screen_width = 750 
  34. else 
  35. 	Screen_width = 840 
  36. end 
  37.  
  38. local Tween_done = true 
  39. local Online_check_thread = -1 
  40. ---------------------------------------------------------------------------  
  41. -- Initialize Pause Options Menu. 
  42. --------------------------------------------------------------------------- 
  43. function main_menu_coop_top_init() 
  44. 	-- Subscribe to the button presses we need 
  45. 	 
  46. 	Input_tracker = Vdo_input_tracker:new() 
  47. 	Input_tracker:add_input("select", "main_menu_coop_top_button_a", 50) 
  48. 	Input_tracker:add_input("back", "main_menu_coop_top_button_b", 50) 
  49. 	Input_tracker:add_input("nav_up", "main_menu_coop_top_nav", 50) 
  50. 	Input_tracker:add_input("nav_down", "main_menu_coop_top_nav", 50) 
  51. 	Input_tracker:add_input("nav_left", "main_menu_coop_top_nav", 50) 
  52. 	Input_tracker:add_input("nav_right", "main_menu_coop_top_nav", 50) 
  53. 	Input_tracker:subscribe(false) 
  54.  
  55. 	main_menu_coop_top_set_menu() 
  56. 	 
  57. 	--Setup Button Hints 
  58. 	local hint_data = { 
  59. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  60. 	} 
  61. 	Menu_hint_bar:set_hints(hint_data)   
  62. 	 
  63. 	--Get the selection option from when the menu was last loaded 
  64. 	local last_option_selected = menu_common_stack_get_index() 
  65. 	 
  66. 	List:draw_items(Data, last_option_selected, Screen_width) 
  67. 	 
  68. 	--Store some locals to the pause menu common for screen processing. 
  69. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  70. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim) 
  71. 	 
  72. 	if First_time then 
  73. 		Screen_in_anim:play(0) 
  74. 		bg_saints_slide_in(Screen_width) 
  75. 	 
  76. 		First_time = false 
  77. 	end 
  78. 			 
  79. 	-- Add mouse inputs for the PC 
  80. 	if game_get_platform() == "PC" then 
  81. 		Menu_hint_bar:set_highlight(0) 
  82. 		 
  83. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  84. 		List:add_mouse_inputs("main_menu_coop_top", Mouse_input_tracker) 
  85. 		Menu_hint_bar:add_mouse_inputs("main_menu_coop_top", Mouse_input_tracker) 
  86. 		Mouse_input_tracker:subscribe(true) 
  87. 		 
  88. 		--menu_common_set_mouse_tracker(Mouse_input_tracker) 
  89. 	end 
  90. end 
  91.  
  92. function main_menu_coop_top_cleanup() 
  93. 	if Online_check_thread ~= -1 then 
  94. 		thread_kill(Online_check_thread) 
  95. 	end 
  96. 	-- Nuke all button subscriptions 
  97. 	Input_tracker:subscribe(false) 
  98. 	if Mouse_input_tracker ~= nil then 
  99. 		Mouse_input_tracker:subscribe(false) 
  100. 	end 
  101. 	List:enable_toggle_input(false) 
  102. end 
  103.  
  104. function main_menu_coop_top_set_menu() 
  105. 	local header_str 
  106. 	Data = { }  
  107. 	 
  108. 	--Get Platform specific data... 
  109. 	header_str = "MAINMENU_COOP" 
  110. 		 
  111. 	Data[#Data + 1] = Xbox_live_button			--HVS_JRP[PRINCE] 4/28/2014 Changed from XBOX_LIVE_INDEX to "#Data + 1". 
  112. 	if game_get_platform() ~= "XBOX3" then		--HVS_JRP[PRINCE] 4/28/2014 Remove System Link on XB1. 
  113. 		Data[#Data + 1] = System_link_button	--HVS_JRP[PRINCE] 4/28/2014 Changed from SYSTEM_LINK_INDEX to "#Data + 1". 
  114. 	end 
  115. 	Data[#Data + 1] = Coop_options_button		--HVS_JRP[PRINCE] 4/28/2014 Changed from COOP_OPTIONS_INDEX to "#Data + 1". 
  116. 	 
  117. 	--Initialize Header 
  118. 	Header_obj:set_text(header_str, Screen_width) 
  119. end 
  120.  
  121. function main_menu_coop_top_nav(event, acceleration) 
  122. 	if Tween_done == true then 
  123. 		if event == "nav_up" then 
  124. 			-- Move highlight up 
  125. 			List:move_cursor(-1) 
  126. 		elseif event == "nav_down" then 
  127. 			-- Move highlight down 
  128. 			List:move_cursor(1) 
  129. 		elseif event == "nav_left" then 
  130. 			-- Move highlight left 
  131. 			List:move_slider(-1) 
  132. 		elseif event == "nav_right" then 
  133. 			-- Move highlight right 
  134. 			List:move_slider(1) 
  135. 		end 
  136. 	end 
  137. end 
  138.  
  139. function mm_coop_top_check_live() 
  140. 	main_menu_supress_profile_change(true) 
  141. 	 
  142. 	Input_tracker:subscribe(false) 
  143. 	if game_get_platform() == "PC" then	 
  144. 		Mouse_input_tracker:subscribe(false) 
  145. 	end 
  146. 	 
  147. 	online_and_privilege_validator_begin(true, true, true, true, false) 
  148. 	while Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS do 
  149. 		thread_yield() 
  150. 	end 
  151. 	 
  152. 	Input_tracker:subscribe(true) 
  153. 	if game_get_platform() == "PC" then	 
  154. 		Mouse_input_tracker:subscribe(true) 
  155. 	end 
  156. 	 
  157. 	main_menu_supress_profile_change(false) 
  158. 			 
  159. 	List:highlight_show(true) 
  160. 		 
  161. 	if Online_validator_result ~= ONLINE_VALIDATOR_PASSED then 
  162. 		return 
  163. 	end 
  164. 			 
  165. 	main_menu_coop_top_dlc_check_live(true, false) 
  166. 	Online_check_thread = -1 
  167. end 
  168.  
  169. function mm_coop_top_check_lan() 
  170. 	main_menu_supress_profile_change(true) 
  171. 	 
  172. 	Input_tracker:subscribe(false) 
  173. 	if game_get_platform() == "PC" then	 
  174. 		Mouse_input_tracker:subscribe(false) 
  175. 	end 
  176. 	 
  177. 	online_and_privilege_validator_begin(true, false, false, false, false) 
  178. 	while Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS do 
  179. 		thread_yield() 
  180. 	end 
  181. 	 
  182. 	Input_tracker:subscribe(true) 
  183. 	if game_get_platform() == "PC" then	 
  184. 		Mouse_input_tracker:subscribe(true) 
  185. 	end 
  186. 	 
  187. 	main_menu_supress_profile_change(false) 
  188. 			 
  189. 	List:highlight_show(true) 
  190. 		 
  191. 	if Online_validator_result ~= ONLINE_VALIDATOR_PASSED then 
  192. 		Input_tracker:subscribe(true) 
  193. 		return 
  194. 	end 
  195. 	 
  196. 	main_menu_coop_top_dlc_check_lan(true, false) 
  197. 	Online_check_thread = -1 
  198. end 
  199.  
  200. function mm_coop_top_redeem_check() 
  201. 	main_menu_supress_profile_change(true) 
  202. 	 
  203. 	Input_tracker:subscribe(false) 
  204. 	if game_get_platform() == "PC" then	 
  205. 		Mouse_input_tracker:subscribe(false) 
  206. 	end 
  207. 	 
  208. 	online_and_privilege_validator_begin(true, true, true, false, false) 
  209. 	while Online_validator_result == ONLINE_VALIDATOR_IN_PROGRESS do 
  210. 		thread_yield() 
  211. 	end 
  212. 	 
  213. 	Input_tracker:subscribe(true) 
  214. 	if game_get_platform() == "PC" then	 
  215. 		Mouse_input_tracker:subscribe(true) 
  216. 	end 
  217. 	 
  218. 	main_menu_supress_profile_change(false) 
  219. 	 
  220. 	List:highlight_show(true)	 
  221. 	if Online_validator_result ~= ONLINE_VALIDATOR_PASSED then 
  222. 		return 
  223. 	end 
  224. 	main_menu_redeem_code() 
  225. 	Input_tracker:subscribe(true) 
  226. 	Online_check_thread = -1 
  227. end 
  228.  
  229. function mm_coop_top_dlc_cb(result, action) 
  230. 	if game_get_platform() == "PC" then 
  231. 		if result == 0 then 
  232. 			Enter_dlc_menu = true 
  233. 			main_menu_coop_top_button_b() 
  234. 		end 
  235. 	else 
  236. 		if result == 0 then 
  237. 			Input_tracker:subscribe(false) 
  238. 			Online_check_thread = thread_new("mm_coop_top_redeem_check")  
  239. 		elseif result == 1 then 
  240. 			Enter_dlc_menu = true 
  241. 			main_menu_coop_top_button_b() 
  242. 		end 
  243. 	end 
  244. end 
  245.  
  246. function main_menu_coop_top_dlc_dialog() 
  247. 	local options 
  248. 	if game_get_platform() == "PC" then 
  249. 		options = { [0] = "GO_DLC_STORE", [1] = "CONTROL_CANCEL" } 
  250. 	else 
  251. 		options = { [0] = "REDEEM_CODE", [1] = "GO_DLC_STORE", [2] = "CONTROL_CANCEL" } 
  252. 	end 
  253. 	dialog_box_open("DIALOG_COOP_DLC_TITLE", "DLC_COOP_DLC_MAIN_BODY", options, "mm_coop_top_dlc_cb",  
  254. 						0, DIALOG_PRIORITY_ACTION, false, nil, false, false) 
  255. end 
  256.  
  257. function main_menu_coop_top_dlc_check_live(has_dlc, cancelled) 
  258. 	--why do this? 
  259. 	--Input_tracker:subscribe(true) 
  260. 	if has_dlc then 
  261. 		main_menu_check_open_nat() 
  262. 		Main_menu_coop_is_xbox_live = true 
  263. 		main_menu_set_coop_menu_type(true) 
  264. 		menu_common_stack_add(List:get_selection()) 
  265. 		menu_common_transition_push("main_menu_coop") 
  266. 	elseif not cancelled then 
  267. 		main_menu_coop_top_dlc_dialog() 
  268. 	end 
  269. end 
  270.  
  271. function main_menu_coop_top_dlc_check_lan(has_dlc, cancelled) 
  272. 	if has_dlc then 
  273. 		Main_menu_coop_is_xbox_live = false 
  274. 		main_menu_set_coop_menu_type(false) 
  275. 		 
  276. 		menu_common_stack_add(List:get_selection()) 
  277. 		menu_common_transition_push("main_menu_coop") 
  278. 	elseif not cancelled then 
  279. 		main_menu_coop_top_dlc_dialog() 
  280. 	end 
  281. 	--why do this? 
  282. 	--Input_tracker:subscribe(true) 
  283. end 
  284.  
  285. function main_menu_coop_top_button_a(event, acceleration) 
  286. 	if Tween_done == true then 
  287. 		--Set the screen data to the list data 
  288. 		Data = List:return_data() 
  289. 		local current_id = List:get_id() 
  290. 		Input_tracker:subscribe(false) 
  291. 		if current_id == ID_XBOX_LIVE then 
  292. 			if game_get_platform() == "PS3" then 
  293. 				if not game_user_has_online_privilege() then 
  294. 					dialog_box_message( "MENU_TITLE_NOTICE", "PLATFORM_PS3_ONLINE_AGE_RESTRICTED" ) 
  295. 					Input_tracker:subscribe(true) 
  296. 					return 
  297. 				end 
  298. 			end	 
  299. 			 
  300. 			Online_check_thread = thread_new("mm_coop_top_check_live") 
  301. 			return 
  302. 		elseif current_id == ID_SYSTEM_LINK then 
  303. 			if game_is_connected_to_network() == false then 
  304. 				dialog_box_message("MENU_TITLE_WARNING", "NO_NETWORK_CONNECTION") 
  305. 				Input_tracker:subscribe(true) 
  306. 				return 
  307. 			end 
  308. 			Online_check_thread = thread_new("mm_coop_top_check_lan") 
  309. 			return 
  310. 		elseif current_id == ID_COOP_OPTIONS then 
  311. 			--Add current selection to the stack to store the selected position on the menu 
  312. 			menu_common_stack_add(List:get_selection()) 
  313. 			menu_common_transition_push("pause_co_op_menu") 
  314. 			return	-- Make sure we don't try to push the coop menu 
  315. 		end 
  316. 		--Add current selection to the stack to store the selected position on the menu 
  317. 		menu_common_stack_add(List:get_selection()) 
  318. 		menu_common_transition_push("main_menu_coop") 
  319. 	end 
  320. end 
  321.  
  322. function main_menu_coop_top_button_b(event, acceleration) 
  323. 	if Tween_done == true then 
  324. 	 
  325. 		--pass off the input to the list 
  326. 		List:button_b() 
  327. 		 
  328. 		--Remove current menu from the stack 
  329. 		menu_common_stack_remove() 
  330. 		 
  331. 		--Pop Screen off the list 
  332. 		menu_common_transition_pop(1) 
  333. 		 
  334. 		First_time = true 
  335. 		bg_saints_slide_out() 
  336. 	end 
  337. end 
  338.  
  339. function main_menu_coop_top_mouse_click(event, target_handle) 
  340. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  341. 	if hint_index == 1 then 
  342. 		main_menu_coop_top_button_b() 
  343. 	end 
  344.  
  345. 	local new_index = List:get_button_index(target_handle) 
  346. 	if new_index ~= 0 then 
  347. 		List:set_selection(new_index) 
  348. 		main_menu_coop_top_button_a() 
  349. 	end 
  350. end 
  351.  
  352. function main_menu_coop_top_mouse_move(event, target_handle) 
  353. 	Menu_hint_bar:set_highlight(0) 
  354. 	 
  355. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  356. 	if hint_index ~= 0 then 
  357. 		Menu_hint_bar:set_highlight(hint_index) 
  358. 	end 
  359. 	 
  360. 	local new_index = List:get_button_index(target_handle) 
  361. 	if new_index ~= 0 then 
  362. 		List:set_selection(new_index) 
  363. 		List:move_cursor(0, true) 
  364. 	end 
  365. end 
  366.