./game_lobby.lua

  1. -- "Defines" 
  2. local COOP_INVITE_LIST 	= 0 
  3. local ID_PRIV 				= 1 
  4. local ID_FF					= 2 
  5.  
  6. -- "Globals" 
  7. local Lobby_data = { } 
  8. local Data = {} 
  9. local LOBBY_LIST_WIDTH = 470 --440		-- 495 
  10. local LOBBY_LIST_MAX_ITEMS = 4 
  11. local LOBBY_LIST_FORCE_SCALE = false 
  12. local Menu_has_shown = false 
  13.  
  14. local Local_ready = false 
  15. local Remote_ready = false 
  16.  
  17. local	Host_char_bmp_h			 
  18. local	Host_info_grp_h			 
  19. local	Host_speak_bmp_h			 
  20. local	Host_name_txt_h			 
  21. local	Client_char_bmp_h			 
  22. local	Client_info_grp_h			 
  23. local	Client_speak_bmp_h		 
  24. local	Client_name_txt_h			 
  25.  
  26. local In_invite = false 
  27.  
  28. local Game_lobby_doc_h = -1 
  29.  
  30. -- VDOs 
  31. local Input_tracker 
  32. local Mouse_input_tracker = 0 
  33. local Hint_bar 
  34. local Hint_bar_mouse_input_tracker = 0 
  35. local Header_obj 
  36.  
  37. Game_lobby_list = {} 
  38.  
  39. local Char_client_grp_h 
  40. local Char_host_grp_h 
  41.  
  42. -- Menu Data 
  43. local Lobby_data 			= { } 
  44. local Cooptions_data		= { } 
  45. local Data 					= { } 
  46.  
  47. -- "Globals" 
  48. local Back_callback 			= -1 
  49. local Invite_show_thread 	= -1 
  50. local Num_friends 			= 0 
  51. local Connected 				= false 
  52. local Join_completed 		= false 
  53.  
  54. -- Main menu indices 
  55. local UNAVAILABLE_INDEX = -1 
  56. local INVITE_INDEX		= UNAVAILABLE_INDEX 
  57. local OPTIONS_INDEX		= UNAVAILABLE_INDEX 
  58. local START_INDEX 		= UNAVAILABLE_INDEX 
  59. local QUIT_INDEX			= UNAVAILABLE_INDEX 
  60.  
  61. local Party_invite = false 
  62.  
  63. local Show_partner_gamercard = false 
  64.  
  65. local Game_lobby_joined = -1 
  66.  
  67.  
  68. local function build_hint_bar(show_invite_friends) 
  69. 	 
  70. 	if game_get_platform() == "PC" then 
  71. 		Hint_bar_mouse_input_tracker:subscribe(false) 
  72. 		Hint_bar_mouse_input_tracker:remove_all() 
  73. 	end 
  74. 	 
  75. 	Hint_bar:set_visible(false) 
  76.  
  77. 	Show_partner_gamercard = false 
  78.  
  79. 	if show_invite_friends then 
  80. 		-- Show the hint bar 
  81. 		local hint_data = {} 
  82. 		if Num_friends == 0 then 
  83. 			hint_data = { 
  84. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  85. 			} 
  86. 		else 
  87. 			hint_data = { 
  88. 				{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  89. 				{CTRL_BUTTON_X, "PLT_MENU_VIEW_GAMERCARD"}, 
  90. 			} 
  91. 		end 
  92.  
  93. 		Party_invite = false 
  94. 		if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then 
  95. 			if game_get_party_member_count() > 1 then 
  96. 				hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_INVITE" } 
  97. 				Party_invite = true 
  98. 			end 
  99. 		end 
  100. 		 
  101. 		Hint_bar:set_hints(hint_data) 
  102. 		 
  103. 		Hint_bar:set_visible(true) 
  104. 	 
  105. 	else 
  106. 	 
  107. 		if (Connected or not game_get_is_host()) and game_is_syslink() == false then 
  108. 			local hint_data = { 
  109. 				{CTRL_BUTTON_X, "PLT_MENU_VIEW_PARTNER_GAMERCARD"}, 
  110. 			} 
  111. 			Show_partner_gamercard = true 
  112. 			Hint_bar:set_hints(hint_data) 
  113. 			Hint_bar:set_visible(true) 
  114. 		end 
  115. 	 
  116. 	end 
  117. 	 
  118. 	if game_get_platform() == "PC" then 
  119. 		Hint_bar:set_highlight(0) 
  120. 		Hint_bar:add_mouse_inputs( "game_lobby", Hint_bar_mouse_input_tracker, 1000) 
  121. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  122. 	end 
  123. 	 
  124. end 
  125.  
  126. -- HVS_JRS 8/22/2014 go back after aborting invite 
  127. function game_lobby_back() 
  128. 	game_lobby_button_b() 
  129. end 
  130.  
  131. -------------------------------------------------------- 
  132. -- Init/Clean up 
  133. function game_lobby_init() 
  134. 	Game_lobby_doc_h = vint_document_find("game_lobby") 
  135. 	 
  136. 	--Do we need to pause map dump? 
  137. 	pause_map_dump() 
  138. 	 
  139. 	--Set background for "bg_saints" 
  140. 	bg_saints_set_type(BG_TYPE_PAUSE, false) 
  141. 	bg_saints_show(true) 
  142.  
  143. 	--Setup Button Hints 
  144. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  145. 	 
  146. 	--Setup the list 
  147. 	Game_lobby_list = Vdo_mega_list:new("list", 0, Game_lobby_doc_h, "game_lobby.lua", "Game_lobby_list") 
  148. 	Game_lobby_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY) 
  149. 	 
  150. 	Char_client_grp_h = vint_object_find("client_char_bmp") 
  151. 	Char_host_grp_h = vint_object_find("host_char_bmp") 
  152. 	 
  153. 	--Initialize Input Tracker 
  154. 	Input_tracker = Vdo_input_tracker:new() 
  155. 	Input_tracker:add_input("pause", 		"game_lobby_button_start", 	50) 
  156. 	Input_tracker:add_input("select", 		"game_lobby_button_a", 			50) 
  157. 	Input_tracker:add_input("alt_select", 	"game_lobby_button_x", 			50) 
  158. 	Input_tracker:add_input("exit",			"game_lobby_button_y",			50) 
  159. 	Input_tracker:add_input("back", 			"game_lobby_button_b", 			50) 
  160. 	Input_tracker:add_input("nav_up", 		"game_lobby_nav_up", 			50) 
  161. 	Input_tracker:add_input("nav_down", 	"game_lobby_nav_down", 			50) 
  162. 	Input_tracker:add_input("nav_left", 	"game_lobby_nav_left", 			50) 
  163. 	Input_tracker:add_input("nav_right", 	"game_lobby_nav_right", 		50) 
  164. 	 
  165. 	-- Add mouse inputs for the PC 
  166. 	if game_get_platform() == "PC" then 
  167. 		Hint_bar:set_highlight(0) 
  168. 		 
  169. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  170. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  171.  
  172. 		Mouse_input_tracker:subscribe(false) 
  173. 		Hint_bar_mouse_input_tracker:subscribe(false) 
  174. 	end 
  175. 	 
  176. 	if game_get_is_host() and game_coop_get_starting_coop() then 
  177. 		game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
  178. 	else 
  179. 		game_lobby_show_spinner(false, nil) 
  180. 	end 
  181. 	 
  182. 	local base_grp_h = vint_object_find("base_grp") 
  183. 	vint_set_property(base_grp_h, "visible", false) 
  184. 	 
  185. 	build_hint_bar() 
  186. 	 
  187. end 
  188.  
  189. function game_lobby_cleanup() 
  190. 	if Invite_show_thread ~= -1 then 
  191. 		thread_kill(Invite_show_thread) 
  192. 	end 
  193. 	game_peg_unload("ui_bms_lobby_coop") 
  194. 	 
  195. 	pause_map_restore() 
  196. end 
  197.  
  198. ------------------------------------------------------------------------------- 
  199. -- Called from game after we've unloaded the pause map... 
  200. -- 
  201. function game_lobby_init_done() 
  202. 	--load coop  
  203. 	game_peg_load_with_cb("game_lobby_peg_loaded", 1, "ui_bms_lobby_coop") 
  204. end 
  205.  
  206. function game_lobby_peg_loaded() 
  207. 	--base group.... 
  208. 	local base_grp_h = vint_object_find("base_grp") 
  209. 	vint_set_property(base_grp_h, "visible", true) 
  210.  
  211. 	-- Grab some common handles 
  212. 	Host_char_bmp_h			= vint_object_find("host_char_bmp") 
  213. 	Host_info_grp_h			= vint_object_find("host_info_grp") 
  214. 	Host_speak_bmp_h			= vint_object_find("host_speak_bmp") 
  215. 	Host_name_txt_h			= vint_object_find("host_name_txt") 
  216. 	Client_char_bmp_h			= vint_object_find("client_char_bmp") 
  217. 	Client_info_grp_h			= vint_object_find("client_info_grp") 
  218. 	Client_speak_bmp_h		= vint_object_find("client_speak_bmp") 
  219. 	Client_name_txt_h			= vint_object_find("client_name_txt") 
  220.  
  221. 	-- Set the waiting text, if necessary 
  222. 	game_lobby_set_waiting_prompt() 
  223. 	 
  224. 	-- Adjust the screen layout 
  225. 	game_lobby_set_screen_layout() 
  226. 	 
  227. 	-- Create the main lobby list 
  228. 	game_lobby_create_lobby() 
  229. 	 
  230. 	-- Show the main coop lobby menu 
  231. 	game_lobby_show_main() 
  232.  
  233. 	game_lobby_finished_loading() 
  234. 	 
  235. 	Input_tracker:subscribe(true) 
  236. 	 
  237. 	if Game_lobby_joined ~= -1 then 
  238. 		game_lobby_joined(Game_lobby_joined) 
  239. 	end 
  240. end 
  241.  
  242. ------------------------------------------------------------------------------- 
  243. -- 
  244. -- Updates from code 
  245. -- 
  246. ------------------------------------------------------------------------------- 
  247. -- Called from code when a client connects, and again when finished connecting 
  248. -- @param 	join_complete				true when the client is fully connected, false when still connecting 
  249. -- 
  250. function game_lobby_joined(join_complete) 
  251. 	 
  252. 	Game_lobby_joined = join_complete 
  253. 	 
  254. 	local values = { [0] = game_lobby_get_remote_player_name(), } 
  255. 	local tag = nil 
  256. 	 
  257. 	if In_invite == true then 
  258. 		game_lobby_button_b() 
  259. 	end 
  260. 	 
  261. 	if game_is_syslink() == false then  
  262. 		Lobby_data[1] = Kick_button 
  263. 	end 
  264. 		 
  265. 	if join_complete then  
  266. 		Lobby_data[START_INDEX].label = "COOP_LOBBY_COOP_START" 
  267. 		Lobby_data[START_INDEX].disabled = false 
  268. 				 
  269. 		Join_completed = true 
  270. 		tag = vint_insert_values_in_string("COOP_LOBBY_JOINED", values) 
  271. 	 
  272. 	else 
  273. 		Join_completed = false 
  274. 		tag = vint_insert_values_in_string("COOP_LOBBY_JOINING", values) 
  275. 	end 
  276. 	 
  277. 	Connected = true 
  278. 	game_lobby_show_spinner((join_complete ~= true), tag) 
  279.  
  280. 	if Data == Lobby_data then 
  281. 		if Mouse_input_tracker ~= 0 then 
  282. 			Mouse_input_tracker:remove_all() 
  283. 		end 
  284. 		 
  285. 		local selection = Game_lobby_list:get_selection() 
  286. 		Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  287. 		 
  288. 		if Mouse_input_tracker ~= 0 then 
  289. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  290. 			Mouse_input_tracker:subscribe(true) 
  291. 		end 
  292. 	end 
  293. 	 
  294. 	build_hint_bar() 
  295.  
  296. end 
  297.  
  298. ------------------------------------------------ 
  299. -- Called from code when the client disconnects 
  300. -- 
  301. function game_lobby_disconnect() 
  302. 	-- reset the globals, we're disconnected	 
  303. 	Join_completed = false 
  304. 	Connected = false 
  305. 	 
  306. 	-- Flag start button for not being enabled 
  307. 	Lobby_data[START_INDEX].label = "COOP_LOBBY_START_GAME" 
  308. 	 
  309. 	-- Update the imagery 
  310. 	game_lobby_set_screen_layout() 
  311. 	 
  312. 	-- Update the spinner to show "Left" text 
  313. 	local values = { [0] = game_lobby_get_remote_player_name(), } 
  314. 	local tag = vint_insert_values_in_string("COOP_LOBBY_LEFT", values) 
  315. 	game_lobby_show_spinner(false, tag) 
  316. 	 
  317. 	-- Spawn a thread to reset the text to "waiting for player" after 5 seconds 
  318. 	thread_new("game_lobby_reset_waiting") 
  319. 	 
  320. 	-- Update the invite button 
  321. 	if game_is_syslink() == false then  
  322. 		Lobby_data[1] = Invite_button 
  323. 	end 
  324. 	 
  325. 	-- We're always ready when we're the only bros 
  326. 	--game_lobby_update_local_ready(true) 
  327. 	 
  328. 	-- Redraw the list with the updated button 
  329. 	if Data == Lobby_data then 
  330. 		local selection = Game_lobby_list:get_selection() 
  331. 		Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  332. 		 
  333. 		if Mouse_input_tracker ~= 0 then 
  334. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  335. 			Mouse_input_tracker:subscribe(true) 
  336. 		end 
  337. 	end 
  338. 	 
  339. 	build_hint_bar() 
  340. end 
  341.  
  342. ------------------------------------------------ 
  343. -- Set the waiting text back to "waiting" 
  344. -- 
  345. function game_lobby_reset_waiting() 
  346. 	delay(5) 
  347. 	game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
  348. end 
  349.  
  350. ------------------------------------------------------------------------------- 
  351. -- 
  352. -- MENU SETUP / INITIALIZATION 
  353. -- 
  354. ------------------------------------------------------------------------------- 
  355. -- Sets whether or not the map / character stuff is shown, and updates the 
  356. -- 
  357. function game_lobby_set_screen_layout() 
  358. 	local coop_grp_h = vint_object_find("coop_grp") 
  359. 	local whored_char_info_grp_h = vint_object_find("whored_char_info_grp") 
  360. 	 
  361. 	vint_set_property(whored_char_info_grp_h, "visible", false) 
  362. 	vint_set_property(coop_grp_h, "visible", true) 
  363.  
  364. 	game_lobby_set_logo(false) 
  365. 		 
  366. 	-- Set bitmaps 
  367. 	-- Saints bitmap... 
  368. 	local saints_bmp_h = vint_object_find("saints_bmp") 
  369. 	vint_set_property(saints_bmp_h, "image", "ui_main_menu_coop_team") 
  370.  
  371. end 
  372.  
  373. -- Create the main lobby list 
  374. -- 
  375. function game_lobby_create_lobby() 
  376. 	local coop_client = false 
  377. 	if game_get_is_host() then 
  378. 		-- Host Lobby 
  379. 		if game_coop_get_starting_syslink() == true then  
  380. 			OPTIONS_INDEX 		= 1	-- No invite button in sys link 
  381. 			START_INDEX 		= 2 
  382. 			QUIT_INDEX 			= 3 
  383. 		else  
  384. 			INVITE_INDEX 		= 1 
  385. 			OPTIONS_INDEX		= 2 
  386. 			START_INDEX 		= 3 
  387. 			QUIT_INDEX			= 4 
  388. 		end 
  389. 	end 
  390.  
  391. 	-- Set all the menu buttons based on the indexes 
  392. 	Lobby_data[INVITE_INDEX]		= Invite_button 
  393. 	Lobby_data[OPTIONS_INDEX]		= Cooptions_button 
  394. 	Lobby_data[START_INDEX]			= Start_game_button 
  395. 	Lobby_data[QUIT_INDEX]			= Quit_game_button 
  396.  
  397. 	if game_is_syslink() == false then  
  398. 		Cooptions_data[#Cooptions_data + 1]	= Privacy_button 
  399. 	end 
  400. 	Cooptions_data[#Cooptions_data + 1] 		= FF_button 
  401.  
  402. 	-- Items that weren't available overwrote -1, so set it back to nil	 
  403. 	Lobby_data[UNAVAILABLE_INDEX]	= nil 
  404.  
  405. 	-- Get the defaults for these buttons 
  406. 	Privacy_button.current_value = game_get_coop_join_type() + 1 
  407. 	FF_button.current_value = game_get_coop_friendly_fire() + 1 -- the values reverse the options 
  408. end 
  409.  
  410. --------------------------- 
  411. -- Show the main lobby Menu 
  412. -- 
  413. function game_lobby_show_main() 
  414. 	if Invite_show_thread ~= -1 then 
  415. 		thread_kill(Invite_show_thread) 
  416. 		Invite_show_thread = -1 
  417. 	end 
  418. 	In_invite = false	 
  419. 	 
  420. 	Num_friends = 0 
  421. 	Party_invite = false 
  422.  
  423. 	build_hint_bar() 
  424. 	 
  425. 	Back_callback = -1	-- No back from here 
  426. 	Data = Lobby_data 
  427. 	Game_lobby_list:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  428. 	 
  429. 	if Mouse_input_tracker ~= 0 then 
  430. 		Mouse_input_tracker:subscribe(false) 
  431. 		Mouse_input_tracker:remove_all() 
  432. 		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  433. 		Mouse_input_tracker:subscribe(true) 
  434. 	end 
  435.  
  436. 	Menu_has_shown = true 
  437. end 
  438.  
  439. ------------------------------------------------------------------------------- 
  440. -- 
  441. -- SPINNER FUNCTIONALTIY 
  442. -- 
  443. ------------------------------------------------------------------------------- 
  444. -- Set "Waiting for player" text if we're in coop.  
  445. -- 
  446. function game_lobby_set_waiting_prompt() 
  447. 	if game_coop_get_starting_coop() then 
  448. 		if game_get_is_host() == true then 
  449. 			game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
  450. 		else 
  451. 			local values = { [0] = game_lobby_get_remote_player_name() } 
  452. 			local tag = vint_insert_values_in_string("COOP_LOBBY_WAITING_FOR_HOST", values) 
  453. 			game_lobby_show_spinner(false, tag) 
  454. 		end 
  455. 	else  
  456. 		game_lobby_hide_spinner() 
  457. 	end 
  458. end 
  459.  
  460. ------------------------------------------------------------ 
  461. -- Shows spinner 
  462. -- @param	show_spinner		spinner on or off 
  463. -- @param	text					text to appear next to spinner 
  464. -- 
  465. function game_lobby_show_spinner(show_spinner, text) 
  466. 	local spinner_h = vint_object_find("spinner_grp") 
  467. 	local player_waiting_txt_h = vint_object_find("player_waiting_txt") 
  468. 	local spinny_anim_h = vint_object_find("spinny_anim") 
  469. 	if show_spinner then 
  470. 		lua_play_anim(spinny_anim_h) 
  471. 		vint_set_property(spinner_h, "visible", true) 
  472. 	else 
  473. 		vint_set_property(spinner_h, "visible", false) 
  474. 	end 
  475. 	 
  476. 	if Data == Lobby_data then 
  477. 		local last_option_selected = Game_lobby_list:get_selection() 
  478. 		Game_lobby_list:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  479. 		 
  480. 		if Mouse_input_tracker ~= 0 then 
  481. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  482. 			Mouse_input_tracker:subscribe(true) 
  483. 		end 
  484. 	end 
  485.  
  486. 	if text ~= nil then 
  487. 		--Set Text 
  488. 		vint_set_property(player_waiting_txt_h, "visible", true) 
  489. 		vint_set_property(player_waiting_txt_h, "text_tag", text) 
  490. 	else 
  491. 		vint_set_property(player_waiting_txt_h, "visible", false)		 
  492. 	end 
  493. 	 
  494. 	--Align text to left if no spinner present 
  495. 	if text ~= nil and show_spinner == false then 
  496. 		vint_set_property(player_waiting_txt_h, "anchor", 0, -11) 
  497. 	else 
  498. 		vint_set_property(player_waiting_txt_h, "anchor", 50, -11) 
  499. 	end 
  500. 	 
  501. end 
  502.  
  503. ------------------------------------------------------------ 
  504. -- Hides the spinner and waiting text 
  505. function game_lobby_hide_spinner() 
  506. 	local spinner_h = vint_object_find("spinner") 
  507. 	local player_waiting_txt_h = vint_object_find("player_waiting_txt") 
  508. 	vint_set_property(spinner_h, "visible", false) 
  509. 	vint_set_property(player_waiting_txt_h, "visible", false) 
  510. end 
  511.  
  512. ------------------------------------------------------------------------------- 
  513. -- Sets the style logo depending on what mode we are in 
  514. function game_lobby_set_logo() 
  515. 	local whored_logo_grp_h = vint_object_find("whored_logo_grp") 
  516. 	vint_set_property(whored_logo_grp_h, "visible", false) 
  517.  
  518. 	local game_logo_grp_h = vint_object_find("game_logo_grp") 
  519. 	vint_set_property(game_logo_grp_h, "visible", true) 
  520. 	local logo_bmp_h = vint_object_find("game_logo_bmp") 
  521. 	vint_set_property(logo_bmp_h, "image", "ui_whored_logo_game") 
  522. end 
  523.  
  524. ------------------------------------------------------------------------------- 
  525. -- 
  526. -- LOBBY FUNCTIONALITY 
  527. -- 
  528. ------------------------------------------------------------------------------- 
  529. -- Initiate a single player game 
  530. -- 
  531. function game_lobby_start_single_player() 
  532. 	game_lobby_coop_finished() 
  533. 	game_UI_audio_play("UI_Main_Menu_Select") 
  534. end 
  535.  
  536. ------------------------------------------------------------------------ 
  537. -- Dialog Confirmation Callback for start with a joining client 
  538. -- @param 	result				Yes / No to kick the joining coop player 
  539. -- @param	action				Make sure this was closed (should always be in SR3) 
  540. -- 
  541. function game_lobby_sp_start_confim(result, action) 
  542. 	if result == 0 then 
  543. 		game_kick_coop_player(true) 
  544. 		game_lobby_start_single_player() 
  545. 	end 
  546. end 
  547.  
  548. -------------------------------------------------------- 
  549. -- Called from C when the countdown to start is complete 
  550. -- 
  551. function game_lobby_countdown_game_start() 
  552. 	game_lobby_coop_finished() 
  553. end 
  554.  
  555. ------------------------------------------------------ 
  556. -- Respond to Start game button 
  557. -- Prompts to kick a joining coop player if necessary 
  558. -- 
  559. function game_lobby_start_game() 
  560. 	if Join_completed == false then 
  561. 		if Connected == true then 
  562. 			-- If a join hasn't been completed, but someone is joining, prompt to kick them 
  563. 			dialog_box_confirmation("CONTROL_START_GAME", "COOP_SINGLE_PLAYER_KICK_MSG", "game_lobby_sp_start_confim", nil, nil, 1) 
  564. 		else  
  565. 			-- If the no one is connected, continue on with a start 
  566. 			game_lobby_start_single_player() 
  567. 		end 
  568. 	else  
  569. 		-- Join's complete 
  570. 		game_lobby_coop_finished() 
  571. 	end 
  572. end 
  573.  
  574. ------------------------------------------------------------------------ 
  575. -- Dialog Confirmation Callback for quitting to main menu 
  576. -- @param 	result				Yes / No  
  577. -- @param	action				Make sure this was closed (should always be in SR3) 
  578. -- 
  579. function game_lobby_confirm_quit(result, action) 
  580. 	if result == 0 then 
  581. 		Input_tracker:subscribe(false) 
  582. 		if Mouse_input_tracker ~= 0 then 
  583. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  584. 			Mouse_input_tracker:subscribe(true) 
  585. 		end 
  586. 		pause_menu_quit_game_internal() 
  587. 	end 
  588. end 
  589.  
  590. --------------------------------------------- 
  591. -- Confirm we want to return to the main menu 
  592. -- 
  593. function game_lobby_quit() 
  594. 	dialog_box_confirmation("PAUSE_MENU_QUIT_TITLE","QUIT_GAME_TEXT_FULL","game_lobby_confirm_quit", nil, nil, 1) 
  595. end 
  596.  
  597. ------------------------------------------ 
  598. -- Called when a toggle option is changed 
  599. -- 
  600. function game_lobby_change_option() 
  601. 	local option_id = Game_lobby_list:get_id() 
  602. 	 
  603. 	if option_id == ID_PRIV then 
  604. 		game_set_coop_join_type(Privacy_button.current_value - 1) 
  605. 	elseif option_id == ID_FF then 
  606. 		game_set_coop_friendly_fire(FF_button.current_value - 1) 
  607. 	end 
  608.  
  609. 	local selection = Game_lobby_list:get_selection() 
  610. 	Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  611. 	 
  612. 	if Mouse_input_tracker ~= 0 then 
  613. 		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  614. 		Mouse_input_tracker:subscribe(true) 
  615. 	end 
  616. end 
  617.  
  618. ------------------------------------------------------------------------------ 
  619. -- Update the map image from global data. 
  620. -- 
  621. function game_lobby_update_map_display() 
  622. 	 
  623. end 
  624.  
  625. ------------------------------------------------------------------------------- 
  626. -- Update the character image and name 
  627. -- 
  628. -- @host_update	true if we are the host, false for client 
  629. -- @value			internal name of the character. 
  630. -- 
  631. function game_lobby_update_char_display(host_update, value) 
  632. 	local char_name_h 
  633. 	local char_bmp_h 
  634. 	if host_update == true then 
  635. 		char_bmp_h = Host_char_bmp_h 
  636. 	else  
  637. 		game_lobby_show_char(false, true) 
  638. 		vint_set_property(Client_speak_bmp_h, "visible", false) 
  639. 		char_bmp_h = Client_char_bmp_h 
  640. 	end 
  641. 	local char_img_name = Char_image_names[Character_button.options_data[value].internal_name] 
  642. 	vint_set_property(char_bmp_h, "image", char_img_name) 
  643. end 
  644.  
  645. ------------------------------------------------------------------------------- 
  646. -- Shows or hides client or host images and text 
  647. -- 
  648. -- @host_update	true if we are the host, false for client 
  649. -- @value			internal name of the character. 
  650. -- 
  651. function game_lobby_show_char(host_update, is_visible) 
  652. 	local bmp_h 
  653. 	local info_grp_h  
  654. 	if host_update then 
  655. 		bmp_h			= Host_char_bmp_h 
  656. 		info_grp_h	= Host_info_grp_h 
  657. 	else 
  658. 		bmp_h			= Client_char_bmp_h 
  659. 		info_grp_h	= Client_info_grp_h 
  660. 	end 
  661. 	vint_set_property(bmp_h, "visible", is_visible) 
  662. 	vint_set_property(info_grp_h, "visible", is_visible) 
  663. end 
  664.  
  665.  
  666. function game_lobby_cancel_ready() 
  667. 	game_lobby_update_local_ready(false) 
  668. 	if game_get_is_host() then 
  669. 		game_lobby_show_main() 
  670. 	end 
  671. end 
  672.  
  673. function game_lobby_start_dialog_canceled() 
  674. 	Local_ready = false 
  675. 	Start_game_button.on_select = game_lobby_start_game 
  676. end 
  677.  
  678. ------------------------------------------------ 
  679. -- Update the ready display for the local player 
  680. -- and send the changed ready state to C 
  681. function game_lobby_update_local_ready(ready) 
  682. 	game_lobby_update_ready_state(ready) 
  683. 	Local_ready = ready 
  684. 	 
  685. 	if game_get_is_host() == false then 
  686. 		Start_game_button.equipped = ready 
  687. 		game_UI_audio_play("UI_Main_Menu_Select") 
  688. 	end 
  689. 	 
  690. 	-- Swap the list and add cancel 
  691. 	if Local_ready then 
  692. 		if Remote_ready ~= true then 
  693. 			-- Set spinner text to "Waiting for " 
  694. 		end 
  695.  
  696. 		Start_game_button.on_select = game_lobby_cancel_ready 
  697.  
  698. 		if Mouse_input_tracker ~= 0 then 
  699. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  700. 			Mouse_input_tracker:subscribe(true) 
  701. 		end 
  702. 	else 
  703. 		Start_game_button.on_select = game_lobby_start_game 
  704. 	end 
  705. 	 
  706. 	local selection = Game_lobby_list:get_selection() 
  707. 	Game_lobby_list:draw_items(Lobby_data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  708. 	 
  709. 	if game_get_is_host() and game_coop_get_starting_coop() == false then 
  710. 		game_lobby_hide_spinner(true) 
  711. 	end 
  712. end 
  713.  
  714. ----------------------------------------------------- 
  715. -- Kick the client. Prompts with a dialog internally 
  716. -- 
  717. function game_lobby_kick() 
  718. 	game_coop_kick_player() 
  719. end 
  720.  
  721. --------------------------------- 
  722. -- Show the coop options menu 
  723. -- 
  724. function game_lobby_coop_options() 
  725. 	Data = Cooptions_data 
  726. 	Game_lobby_list:draw_items(Data, nil, nil, nil, nil, nil, false) 
  727. 	 
  728. 	game_UI_audio_play("UI_Main_Menu_Select") 
  729. 	 
  730. 	local hint_data = { 
  731. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  732. 	} 
  733. 	Hint_bar:set_hints(hint_data) 
  734. 	Hint_bar:set_visible(true) 
  735. 	 
  736. 	if Mouse_input_tracker ~= 0 then 
  737. 		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  738. 		Mouse_input_tracker:subscribe(true) 
  739. 	end 
  740. end 
  741.  
  742. -------------------------------------------------- 
  743. -- When the Friendly Fire option changes, update it 
  744. -- (Client only) 
  745. -- 
  746. function game_lobby_update_ff(data_item_handle, event_name) 
  747. 	if game_get_is_host() or Menu_has_shown == false then 
  748. 		return 
  749. 	end 
  750. 	 
  751. 	local ff_option = vint_dataitem_get(data_item_handle) 
  752. 	FF_button.current_value = ff_option + 1 
  753.  
  754. 	-- Redraw the current menu 
  755. 	local last_option_selected = Game_lobby_list:get_selection() 
  756. 	Game_lobby_list:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, nil, nil, nil, false) 
  757. 	 
  758. 	if Mouse_input_tracker ~= 0 then 
  759. 		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  760. 		Mouse_input_tracker:subscribe(true) 
  761. 	end 
  762. end 
  763.  
  764. ------------------------------------------------------------------------------- 
  765. -- 
  766. -- INVITE FRIEND 
  767. -- 
  768. ------------------------------------------------------------------------------- 
  769. -- Spawn a thread to show the invite interface 
  770. -- (It may have to yield for the dataresponder, so use another thread 
  771. --  
  772. function game_lobby_show_invite() 
  773. 	In_invite = true 
  774. 	if Invite_show_thread == -1 then 
  775. 		Invite_show_thread = thread_new("game_lobby_retrieve_invite") 
  776. 	end 
  777. end 
  778.  
  779. ------------------------------------------ 
  780. -- Thread to get the friends list 
  781. -- 
  782. function game_lobby_retrieve_invite() 
  783.  
  784. 	-- Show "Searching" while the other data responder goes for it 
  785. 	Data = {	[1] = { type = TYPE_BUTTON, label = "MENU_SEARCHING", id = -1,	disabled = true }, 	} 
  786. 	Game_lobby_list:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  787.  
  788. 	Num_friends = 0 
  789. 	build_hint_bar(true) 
  790.  
  791. 	delay(.5) -- Make sure we show that "Searching" message for at least half a second. 
  792.  
  793. 	-- Populate the friends list 
  794. 	while true do	 
  795. 		Data = { } 
  796. 		Num_friends = 0 
  797. 		vint_dataresponder_request("coop_list_responder", "game_lobby_invite_populate", 0, COOP_INVITE_LIST) 
  798.  
  799. 		-- Check for no friends found 
  800. 		if Num_friends == 0 then 
  801. 			Data = {	[1] = {	type = TYPE_BUTTON, label = "MENU_NO_FRIENDS_FOUND", id = -1, disabled = true	}	} 
  802. 		end 
  803.  
  804. 		--Get the selection option from when the menu was last loaded 
  805. 		local current_index = 1 
  806. 		if Num_friends > 0 then 
  807. 			current_index = min(Game_lobby_list:get_selection(), Num_friends) 
  808. 		end 
  809. 		Game_lobby_list:draw_items(Data, current_index, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
  810. 		 
  811. 		build_hint_bar(true) 
  812. 		Input_tracker:subscribe(true) 
  813. 		if Mouse_input_tracker ~= 0 then 
  814. 			Mouse_input_tracker:subscribe(false) 
  815. 			Mouse_input_tracker:remove_all() 
  816. 			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker) 
  817. 			Mouse_input_tracker:subscribe(true) 
  818. 		end 
  819. 		 
  820. 		delay(2.0) 
  821. 	end 
  822. 	 
  823. 	-- Clear thread 
  824. 	Invite_show_thread = -1 
  825. end 
  826.  
  827. --------------------------------------------- 
  828. -- Populate the invite list 
  829. -- @param 	name				Name of the friend 
  830. -- 
  831. --HVS_JPM[KING] 12/12/2014: added invite_flags from XBOX3 version to differentiate between friends online playing the game and ones just online 
  832. function game_lobby_invite_populate(name, id, invite_tag, invite_flags) 
  833. 	if In_invite == true then	-- HVS_JRS 11/25/2014 only populate invite when In_invite == true 
  834. 		Num_friends = Num_friends + 1 
  835. 		Data[Num_friends] = { type = TYPE_BUTTON, label = name, on_select = game_lobby_invite_friend, on_alt_select = game_lobby_view_gamercard, id = (Num_friends - 1), invite_flags = invite_flags } 
  836. 	end 
  837. end 
  838.  
  839. --------------------------------------- 
  840. -- Show the selected friend's gamercard 
  841. -- 
  842. function game_lobby_view_gamercard() 
  843. 	game_show_coop_gamercard(Game_lobby_list:get_selection() - 1) 
  844. end 
  845.  
  846. ------------------------------- 
  847. -- Invite the selected friend 
  848. -- 
  849. function game_lobby_invite_friend() 
  850. 	local friend_index = Game_lobby_list:get_id() 
  851. 	local insert_values = { [0] = Data[Game_lobby_list:get_selection()].label } 
  852. 	local body = vint_insert_values_in_string("MP_INVITE_SENT_BODY", insert_values) 
  853.  
  854. 	if game_can_send_player_invite(friend_index) == false then 
  855. 		local body = vint_insert_values_in_string("INVITE_FAILED_BODY", insert_values) 
  856. 		dialog_box_message("INVITE_FAILED_TITLE", body) 
  857. 		return 
  858. 	end 
  859.  
  860. 	game_send_pause_menu_player_invite(friend_index) -- offset index by 1 
  861. 	dialog_box_message("MP_INVITE_SENT_TITLE", body) 
  862. end 
  863.  
  864. --------------------------------- 
  865. -- 
  866. -- Input handlers 
  867. -- 
  868. --------------------------------- 
  869. function game_lobby_button_a(event, acceleration) 
  870. 	if Game_lobby_list:list_is_playing() == false then 
  871. 		local current_id = Game_lobby_list:get_id() 
  872. 		local current_index = Game_lobby_list:get_selection() 
  873.  
  874. 		if Data[current_index] == nil then 
  875. 			return 
  876. 		end 
  877. 		 
  878. 		--Do something different on our toggle options... 
  879. 		if Data[current_index].type == TYPE_TOGGLE then 
  880. 			-- Move highlight right 
  881. 			Game_lobby_list:move_slider(1) 
  882. 			if Data[current_index].on_change ~= nil then 
  883. 				Data[current_index].on_change() 
  884. 			end 
  885. 			return 
  886. 		end 
  887. 		 
  888. 		if Data[current_index].on_select ~= nil then 
  889. 			if Data[current_index].set_back_callback ~= nil then 
  890. 				Back_callback = Data[current_index].set_back_callback 
  891. 			end 
  892. 			Data[current_index].on_select() 
  893. 		end 
  894. 	end 
  895. end 
  896.  
  897. function game_lobby_button_b(event, acceleration) 
  898. 	if Back_callback ~= nil and Back_callback ~= -1 then 
  899. 		game_UI_audio_play("UI_Main_Menu_Nav_Back") 
  900. 		Back_callback() 
  901. 	end 
  902. end 
  903.  
  904. function game_lobby_button_x(event, acceleration) 
  905. 	if Game_lobby_list:list_is_playing() == false then 
  906. 		local current_index = Game_lobby_list:get_selection() 
  907.  
  908. 		if Data[current_index].on_alt_select ~= nil then 
  909. 			Data[current_index].on_alt_select() 
  910. 		elseif Show_partner_gamercard then -- only show the gamercard while on the top menu 
  911. 			game_show_coop_partner_gamercard() 
  912. 		end 
  913. 	end 
  914. end 
  915.  
  916. function game_lobby_button_y() 
  917. 	if Party_invite then 
  918. 		game_send_party_invites() 
  919. 	end 
  920. end 
  921.  
  922. function game_lobby_button_start() 
  923. end 
  924.  
  925. function game_lobby_nav_up(event, acceleration) 
  926. 	-- Move highlight up 
  927. 	Game_lobby_list:move_cursor(-1) 
  928. end 
  929.  
  930. function game_lobby_nav_down(event, acceleration) 
  931. 	-- Move highlight down 
  932. 	Game_lobby_list:move_cursor(1) 
  933. end 
  934.  
  935. function game_lobby_nav_left(event, acceleration) 
  936. 	if Game_lobby_list:list_is_playing() == false then 
  937. 		local current_index = Game_lobby_list:get_selection() 
  938. 		if current_index < 0 then 
  939. 			return 
  940. 		end 
  941. 		 
  942. 		-- Move highlight left	 
  943. 		Game_lobby_list:move_slider(-1) 
  944. 		if Data[current_index].on_change ~= nil then 
  945. 			Data[current_index].on_change() 
  946. 		end 
  947. 	end 
  948. end 
  949.  
  950. function game_lobby_nav_right(event, acceleration) 
  951. 	if Game_lobby_list:list_is_playing() == false then 
  952. 		local current_index = Game_lobby_list:get_selection() 
  953. 		if current_index < 0 then 
  954. 			return 
  955. 		end 
  956.  
  957. 		-- Move highlight right 
  958. 		Game_lobby_list:move_slider(1) 
  959. 		if Data[current_index].on_change ~= nil then 
  960. 			Data[current_index].on_change() 
  961. 		end 
  962. 	end 
  963. end 
  964.  
  965. -- Mouse inputs 
  966. function game_lobby_mouse_click(event, target_handle, mouse_x, mouse_y) 
  967. 	if Game_lobby_list:list_is_playing() == false then 
  968. 		local hint_index = Hint_bar:get_hint_index(target_handle) 
  969. 		if hint_index == 1 then 
  970. 			game_lobby_button_b() 
  971. 			return 
  972. 		elseif hint_index == 2 then 
  973. 			game_lobby_button_x() 
  974. 		end 
  975. 		 
  976. 		local new_index = Game_lobby_list:get_button_index(target_handle) 
  977. 		if new_index ~= 0 then 
  978. 			Game_lobby_list:set_selection(new_index) 
  979. 			game_lobby_button_a() 
  980. 		end 
  981. 		 
  982. 		local current_index = Game_lobby_list:get_selection() 
  983. 		if Game_lobby_list:is_left_arrow(target_handle) then 
  984. 			Game_lobby_list:move_slider(-1) 
  985. 			if Data[current_index].on_change ~= nil then 
  986. 				Data[current_index].on_change() 
  987. 			end 
  988. 		elseif Game_lobby_list:is_right_arrow(target_handle) then 
  989. 			Game_lobby_list:move_slider(1) 
  990. 			if Data[current_index].on_change ~= nil then 
  991. 				Data[current_index].on_change() 
  992. 			end 
  993. 		end 
  994. 		if Game_lobby_list:is_slider(target_handle) then 
  995. 			Game_lobby_list:move_slider(0, mouse_x) 
  996. 			if Data[current_index].on_change ~= nil then 
  997. 				Data[current_index].on_change() 
  998. 			end 
  999. 		end 
  1000. 	end 
  1001. end 
  1002.  
  1003. function game_lobby_mouse_move(event, target_handle) 
  1004. 	if Game_lobby_list:list_is_playing() == false then 
  1005. 		Hint_bar:set_highlight(0) 
  1006. 		 
  1007. 		local hint_index = Hint_bar:get_hint_index(target_handle) 
  1008. 		if hint_index ~= 0 then 
  1009. 			Hint_bar:set_highlight(hint_index) 
  1010. 		end 
  1011. 		 
  1012. 		local new_index = Game_lobby_list:get_button_index(target_handle) 
  1013. 		if new_index ~= 0 then 
  1014. 			Game_lobby_list:set_selection(new_index) 
  1015. 			Game_lobby_list:move_cursor(0, true) 
  1016. 		end 
  1017. 	end 
  1018. end 
  1019.  
  1020. function game_lobby_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  1021. 	if scroll_lines ~= 0 then 
  1022. 		if Game_lobby_list:get_scroll_region_handle() == target_handle then 
  1023. 			Game_lobby_list:scroll_list(scroll_lines * -1) 
  1024. 			Game_lobby_list:update_mouse_inputs("game_lobby", Mouse_input_tracker) 
  1025. 		end 
  1026. 	end 
  1027. end 
  1028.  
  1029. function game_lobby_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  1030. 	local scrollbar = Game_lobby_list.scrollbar 
  1031. 	if Game_lobby_list.scrollbar.tab_grp.handle == target_handle then 
  1032. 		 
  1033. 		local max_items = Game_lobby_list.num_buttons - (Game_lobby_list.max_buttons - 1) 
  1034. 		 
  1035. 		local new_start_index = scrollbar:drag_scrolltab(mouse_y, max_items) 
  1036. 		 
  1037. 		Game_lobby_list:scroll_list(0, new_start_index) 
  1038. 	end 
  1039. end 
  1040.  
  1041. function game_lobby_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  1042. end 
  1043.  
  1044. -- List data 
  1045. ------------------------------------------------------------------------------- 
  1046. Invite_button 		= { 	type = TYPE_BUTTON, label = "COOP_MENU_INVITE", on_select = game_lobby_show_invite, set_back_callback = game_lobby_show_main 		} 
  1047. Kick_button 		= { 	type = TYPE_BUTTON, label = "CONTROL_KICK_PLAYER", on_select = game_lobby_kick 																	} 
  1048. Cooptions_button	= {	type = TYPE_BUTTON, label = "COOP_OPTIONS", on_select = game_lobby_coop_options, set_back_callback = game_lobby_show_main 			} 
  1049. Start_game_button	= { 	type = TYPE_BUTTON, label = "COOP_LOBBY_START_GAME", on_select = game_lobby_start_game 														} 
  1050. Quit_game_button	= {	type = TYPE_BUTTON, label = "COOP_LOBBY_QUIT", on_select = game_lobby_quit,																		} 
  1051. -- Coop options, Cooptions. 
  1052. Privacy_button		= { 	type = TYPE_TOGGLE,	label = "COOP_MENU_PRIVACY", on_change = game_lobby_change_option, id = ID_PRIV, 
  1053. 								options = {"COOP_MENU_OPEN", "COOP_MENU_FRIENDS_ONLY", "COOP_MENU_PRIVATE"}, current_value = 1 												} 
  1054. FF_button 			= { 	type = TYPE_TOGGLE, label = "COOP_MENU_FRIENDLY_FIRE", on_change = game_lobby_change_option, id = ID_FF, 
  1055. 								options = {"COOP_MENU_FULL_DAMAGE", "COOP_MENU_LIGHT_DAMAGE", "MENU_NONE"},	current_value = 1 											} 
  1056.