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