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