./pause_co_op_menu.lua

  1. -- Global 
  2. local FFO_NONE						= 2	-- From code 
  3.  
  4. local ID_INVITE					= 1 
  5. local ID_KICK						= 2 
  6. local ID_PRIV						= 3 
  7. local ID_FF							= 4 
  8. local ID_VIEW_GAMERCARD			= 5 
  9. local ID_CHECK_MESSAGES 		= 6 
  10.  
  11. local Anims = {} 
  12. local Check_messages_button = { 
  13. 	type = TYPE_BUTTON, 
  14. 	label = "MAINMENU_CHECK_MESSAGES", 
  15. 	id = ID_CHECK_MESSAGES, 
  16. } 
  17. local Invite_button = {  
  18. 	type = TYPE_BUTTON,  
  19. 	label = "COOP_MENU_INVITE", 
  20. 	id = ID_INVITE, 
  21. } 
  22. local Kick_button = { 
  23. 	type = TYPE_BUTTON,  
  24. 	label = "COOP_MENU_KICK",  
  25. 	id = ID_KICK, 
  26. } 
  27. local Privacy_button = {  
  28. 	type = TYPE_TOGGLE,  
  29. 	label = "COOP_MENU_PRIVACY",  
  30. 	options = {"COOP_MENU_OPEN",  
  31. 					"COOP_MENU_FRIENDS_ONLY",  
  32. 					"COOP_MENU_PRIVATE", 
  33. 	}, 
  34. 	current_value = game_get_coop_join_type() + 1, id = ID_PRIV  
  35. } 
  36. local FF_button = {  
  37. 	type = TYPE_TOGGLE,  
  38. 	label = "COOP_MENU_FRIENDLY_FIRE", 
  39. 	options = {"COOP_MENU_FULL_DAMAGE",  
  40. 					"COOP_MENU_LIGHT_DAMAGE",  
  41. 					"MENU_NONE", 
  42. 	}, 
  43. 	current_value = game_get_coop_friendly_fire() + 1,	id = ID_FF,	 
  44. } 
  45. local Show_gamercard_button = {  
  46. 	type = TYPE_BUTTON,  
  47. 	label = "PLT_MENU_VIEW_PARTNER_GAMERCARD", 
  48. 	id = ID_VIEW_GAMERCARD, 
  49. } 
  50. local Data = {} 
  51. local Input_tracker 
  52. local Mouse_input_tracker 
  53.  
  54. local Screen_width = 840 
  55.  
  56. local Tween_done = true 
  57.  
  58. local Co_op_monitor_thread_h = -1 
  59.  
  60. function pause_co_op_build_data() 
  61.  
  62. 	Data = {} 
  63. 	 
  64. 	if game_get_platform() == "PS3" then 
  65. 		Data[#Data + 1] = Check_messages_button 
  66. 		-- HVS_BDF: added the "not game_get_is_host() and In_pause_menu == true" to disable the Check Messages button 
  67. 		-- for the client (since they deliberately ignore the input of that button under the same conditions) 
  68. 		if (not game_get_is_host() and In_pause_menu == true) or not game_is_connected_to_service() then 
  69. 			Data[#Data].disabled = true 
  70. 			Data[#Data].toggle_disabled = true 
  71. 		end 
  72. 	end 
  73.  
  74. 	if In_pause_menu == false then 
  75. 	-- Main Menu coop menu 
  76. 		Data[#Data + 1] = Privacy_button 
  77. 		Data[#Data + 1] = FF_button 
  78. 	elseif coop_is_active() then 
  79. 	-- During Coop Game menu 
  80. 		if game_get_is_host() then 
  81. 		-- The host's version 
  82. 			Data[#Data + 1] = Kick_button 
  83. 			Data[#Data + 1] = Privacy_button 
  84. 			Data[#Data + 1] = FF_button 
  85. 		else  
  86. 		-- The client's version 
  87. 			Data[#Data + 1] = FF_button 
  88. 			Data[#Data].disabled = true	-- can't change as client 
  89. 		end 
  90.  
  91. 		if not game_is_syslink() then 
  92. 			Data[#Data + 1] = Show_gamercard_button 
  93. 		end 
  94.  
  95. 	else 
  96. 		-- In Game, coop not started 
  97. 		if not game_is_syslink() then 
  98. 			Data[#Data + 1] = Invite_button 
  99. 			if game_is_joinable() == false then 
  100. 				Data[#Data].disabled = true 
  101. 				Data[#Data].toggle_disabled = true 
  102. 			else 
  103. 				Data[#Data].disabled = false 
  104. 				Data[#Data].toggle_disabled = false 
  105. 			end 
  106. 		end 
  107. 		Data[#Data + 1] = Privacy_button 
  108. 		Data[#Data + 1] = FF_button 
  109. 	end 
  110. end 
  111.  
  112. function pause_co_op_menu_init() 
  113. 	-- Subscribe to the button presses we need 
  114. 	 
  115. 	Input_tracker = Vdo_input_tracker:new() 
  116. 	Input_tracker:add_input("select", "pause_co_op_menu_button_a", 50) 
  117. 	-- Input_tracker:add_input("pause", "pause_co_op_menu_button_start", 50) -- HVS_TJW, disabling for now 
  118. 	Input_tracker:add_input("back", "pause_co_op_menu_button_b", 50) 
  119. 	Input_tracker:add_input("nav_up", "pause_co_op_menu_nav_up", 50) 
  120. 	Input_tracker:add_input("nav_down", "pause_co_op_menu_nav_down", 50) 
  121. 	Input_tracker:add_input("nav_left", "pause_co_op_menu_nav_left", 50) 
  122. 	Input_tracker:add_input("nav_right", "pause_co_op_menu_nav_right", 50) 
  123. 	Input_tracker:subscribe(false) 
  124.  
  125. 	if vint_is_std_res() then 
  126. 		Screen_width = 750 
  127. 	else 
  128. 		Screen_width = 840 
  129. 	end 
  130. 	 
  131. 	--Initialize Header 
  132. 	Header_obj:set_text("MAINMENU_COOP", Screen_width) 
  133.  
  134. 	--Setup Button Hints 
  135. 	local hint_data = { 
  136. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  137. 	} 
  138. 	Menu_hint_bar:set_hints(hint_data)   
  139. 	 
  140. 	--Get the selection option from when the menu was last loaded 
  141. 	local last_option_selected = menu_common_stack_get_index() 
  142. 	 
  143. 	pause_co_op_build_data() 
  144. 	 
  145. 	-- draw it up 
  146. 	List:draw_items(Data, last_option_selected, Screen_width) 
  147. 	 
  148. 	--Store some locals to the pause menu common for screen processing. 
  149. 	menu_common_set_list_style(List, Header_obj, Screen_width) 
  150. 	menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim) 
  151. 	 
  152. 	-- Add mouse input subscriptions for the PC 
  153. 	if game_get_platform() == "PC" then 
  154. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  155. 		Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  156. 		List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  157. 		 
  158. 		Mouse_input_tracker:subscribe(true) 
  159. 	end 
  160. 	 
  161. 	if In_pause_menu then 
  162. 		Co_op_monitor_thread_h = thread_new("pause_co_op_monitor_co_op_active") 
  163. 	end 
  164. end 
  165.  
  166. function pause_co_op_menu_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. 	 
  174. 	if Co_op_monitor_thread_h ~= -1 then 
  175. 		thread_kill(Co_op_monitor_thread_h) 
  176. 		Co_op_monitor_thread_h = -1 
  177. 	end 
  178. end 
  179.  
  180. function pause_co_op_menu_nav_up(event, acceleration) 
  181. 	-- Move highlight up 
  182. 	List:move_cursor(-1) 
  183. end 
  184.  
  185. function pause_co_op_menu_nav_down(event, acceleration) 
  186. 	-- Move highlight down 
  187. 	List:move_cursor(1) 
  188. end 
  189.  
  190. function pause_co_op_menu_nav_left(event, acceleration) 
  191. 	-- only host can change this guy 
  192. 	if not game_get_is_host() and In_pause_menu == true then 
  193. 		return 
  194. 	end 
  195.  
  196. 	-- Move highlight left	 
  197. 	List:move_slider(-1) 
  198. 	 
  199. 	update_option(List:get_id()) 
  200. end 
  201.  
  202. function pause_co_op_menu_nav_right(event, acceleration) 
  203. 	-- only host can change this guy 
  204. 	if not game_get_is_host() and In_pause_menu == true then 
  205. 		return 
  206. 	end 
  207.  
  208. 	-- Move highlight right 
  209. 	List:move_slider(1) 
  210. 	 
  211. 	update_option(List:get_id()) 
  212. end 
  213.  
  214. function pause_co_op_menu_button_a(event, acceleration) 
  215. 	if Tween_done == true then 
  216. 	 
  217. 		local current_id = List:get_id() 
  218. 		if current_id == ID_VIEW_GAMERCARD then 
  219. 			game_show_coop_partner_gamercard() 
  220. 			return 
  221. 		end 
  222. 	 
  223. 		if not game_get_is_host() and In_pause_menu == true then 
  224. 			return 
  225. 		end 
  226. 		 
  227. 		--set the screen data to the list data 
  228. 		Data = List:return_data() 
  229. 		 
  230. 		local current_id = List:get_id() 
  231. 		menu_common_stack_add(current_id) 
  232. 		if current_id == ID_INVITE then 
  233. 			-- See if we're connected to the network even... 
  234. 			if game_is_connected_to_network() == false then 
  235. 				dialog_box_message("MENU_TITLE_WARNING", "NO_NETWORK_CONNECTION") 
  236. 				return 
  237. 			end 
  238. 			-- See if we're connected to PSN or XBL 
  239. 			if game_is_connected_to_service() == false then 
  240. 				if game_get_platform() == "PC" then 
  241. 					dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN") 
  242. 				elseif game_get_platform() == "XBOX360" then 
  243. 					dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN_XBOX") 
  244. 				elseif game_get_platform() == "XBOX3" then 
  245. 					dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN_X3") 
  246. 				else 
  247. 					dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN_PS3") 
  248. 				end 
  249. 				return 
  250. 			end 
  251. 			--see if we're on a profile 
  252. 			if game_is_signed_in() == false then 
  253. 				if game_get_platform() == "PC" then 
  254. 					dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN") 
  255. 				elseif (game_get_platform() == "XBOX360") then 
  256. 					dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN") 
  257. 				elseif (game_get_platform() == "XBOX3") then 
  258. 					dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN_X3") 
  259. 				else 
  260. 					dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN_PS3") 
  261. 				end 
  262. 				return 
  263. 			end 
  264. 			menu_common_transition_push("pause_invite_friends") 
  265. 			return 
  266. 		elseif current_id == ID_KICK then 
  267. 			game_coop_kick_player("pause_co_op_kick_complete") 
  268. 		elseif current_id == ID_CHECK_MESSAGES then 
  269. 			main_menu_check_messages() 
  270. 		else  
  271. 			--update_option(current_id) 
  272. 			pause_co_op_menu_nav_right(event, acceleration) 
  273. 		end 
  274. 	end 
  275. end 
  276.  
  277. function pause_co_op_kick_complete(kicked) 
  278. 	if kicked then 
  279. 		pause_co_op_build_data() 
  280. 		-- draw it up 
  281. 		local last_option_selected = menu_common_stack_get_index() 
  282. 		List:draw_items(Data, last_option_selected, Screen_width) 
  283. 		 
  284. 		if Mouse_input_tracker ~= nil then 
  285. 			Mouse_input_tracker:remove_all() 
  286. 			Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  287. 			List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  288. 			Mouse_input_tracker:subscribe(true) 
  289. 		end 
  290. 	end 
  291. end 
  292.  
  293. function update_option(option_id) 
  294. 	if option_id == ID_PRIV then 
  295. 		game_set_coop_join_type(List:get_data_from_id(ID_PRIV).current_value - 1) 
  296. 	else 
  297. 		local value = List:get_data_from_id(ID_FF).current_value - 1 
  298. 		game_set_coop_friendly_fire(List:get_data_from_id(ID_FF).current_value - 1) 
  299. 	end 
  300. end 
  301.  
  302. function pause_co_op_menu_button_b(event, acceleration) 
  303. 	if Tween_done == true then 
  304. 		--pass off the input to the list 
  305. 		List:button_b() 
  306. 		--Remove current menu from the stack 
  307. 		menu_common_stack_remove() 
  308. 		menu_common_transition_pop(1) 
  309. 	end 
  310. end 
  311.  
  312. -- HVS_TJW, removing this for now as it causes us to pop off too many screens and hang 
  313. -- function pause_co_op_menu_button_start(event, acceleration) 
  314. 	-- if Tween_done == true then 
  315. 		-- menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)	 
  316. 		-- Input_tracker:subscribe(false) 
  317. 		-- menu_common_transition_pop(3)	-- save_load, pause_menu_top, menu_common 
  318. 		-- bg_saints_slide_out() 
  319. 	-- end 
  320. -- end 
  321.  
  322. function pause_co_op_menu_mouse_click(event, target_handle) 
  323. 	-- First check if the target_handle refers to the hint bar 
  324. 	local hint_index = Menu_hint_bar:get_hint_index(target_handle) 
  325. 	if hint_index == 1 then 
  326. 		pause_co_op_menu_button_b() 
  327. 	end 
  328.  
  329. 	local new_index = List:get_button_index(target_handle) 
  330. 	if new_index ~= 0 then 
  331. 		-- Enter an option if the target_handle is in the Mega_list 
  332. 		List:set_selection(new_index) 
  333. 		local data = List:return_selected_data() 
  334. 		if data.type == TYPE_TOGGLE then 
  335. 			pause_co_op_menu_nav_right() 
  336. 		else 
  337. 			pause_co_op_menu_button_a() 
  338. 		end 
  339. 	end 
  340. 	if List:is_left_arrow(target_handle) then 
  341. 		pause_co_op_menu_nav_left() 
  342. 	end 
  343. end 
  344.  
  345. function pause_co_op_menu_mouse_move(event, target_handle) 
  346. 	-- Reset highlights 
  347. 	Menu_hint_bar:set_highlight(0) 
  348. 	 
  349. 	-- Check if the target_handle is the hint bar 
  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. 		-- Get the button's index and set it as the selected button 
  358. 		List:set_selection(new_index) 
  359. 		List:move_cursor(0, true) 
  360. 	end 
  361.  
  362. end 
  363.  
  364. function pause_co_op_monitor_co_op_active() 
  365.  
  366. 	local prev_game_is_joinable = false 
  367. 	local prev_coop_is_active = false 
  368. 	 
  369. 	while true do 
  370. 		local cur_game_is_joinable = game_is_joinable() 
  371. 		local cur_coop_is_active = coop_is_active() 
  372. 		 
  373. 		if prev_coop_is_active ~= cur_coop_is_active or prev_game_is_joinable ~= cur_game_is_joinable then 
  374. 			pause_co_op_build_data() 
  375. 			-- draw it up 
  376. 			local last_option_selected = menu_common_stack_get_index() 
  377. 			List:draw_items(Data, last_option_selected, Screen_width) 
  378. 			 
  379. 			if Mouse_input_tracker ~= nil then 
  380. 				Mouse_input_tracker:remove_all() 
  381. 				Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  382. 				List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker) 
  383. 				Mouse_input_tracker:subscribe(true) 
  384. 			end 
  385. 		end 
  386. 		 
  387. 		prev_game_is_joinable = cur_game_is_joinable 
  388. 		prev_coop_is_active = cur_coop_is_active 
  389. 		delay(1.0) 
  390. 	end 
  391.  
  392. end 
  393.