-- "Defines" 
 
local COOP_INVITE_LIST 	= 0 
 
local ID_PRIV 				= 1 
 
local ID_FF					= 2 
 
 
 
-- "Globals" 
 
local Lobby_data = { }  
local Data = {}  
local LOBBY_LIST_WIDTH = 470 --440		-- 495 
 
local LOBBY_LIST_MAX_ITEMS = 4 
 
local LOBBY_LIST_FORCE_SCALE = false 
 
local Menu_has_shown = false 
 
 
 
local Local_ready = false 
 
local Remote_ready = false 
 
 
 
local	Host_char_bmp_h			 
 
local	Host_info_grp_h			 
 
local	Host_speak_bmp_h			 
 
local	Host_name_txt_h			 
 
local	Client_char_bmp_h			 
 
local	Client_info_grp_h			 
 
local	Client_speak_bmp_h		 
 
local	Client_name_txt_h			 
 
 
 
local In_invite = false 
 
 
 
local Game_lobby_doc_h = -1 
 
 
 
-- VDOs 
 
local Input_tracker 
 
local Mouse_input_tracker = 0 
 
local Hint_bar 
 
local Hint_bar_mouse_input_tracker = 0 
 
local Header_obj 
 
 
 
Game_lobby_list = {}  
 
 
local Char_client_grp_h 
 
local Char_host_grp_h 
 
 
 
-- Menu Data 
 
local Lobby_data 			= { }  
local Cooptions_data		= { }  
local Data 					= { }  
 
 
-- "Globals" 
 
local Back_callback 			= -1 
 
local Invite_show_thread 	= -1 
 
local Num_friends 			= 0 
 
local Connected 				= false 
 
local Join_completed 		= false 
 
 
 
-- Main menu indices 
 
local UNAVAILABLE_INDEX = -1 
 
local INVITE_INDEX		= UNAVAILABLE_INDEX 
 
local OPTIONS_INDEX		= UNAVAILABLE_INDEX 
 
local START_INDEX 		= UNAVAILABLE_INDEX 
 
local QUIT_INDEX			= UNAVAILABLE_INDEX 
 
 
 
local Party_invite = false 
 
 
 
local Show_partner_gamercard = false 
 
 
 
local Game_lobby_joined = -1 
 
 
 
 
 
local function build_hint_bar(show_invite_friends) 
 
	 
 
	if game_get_platform() == "PC" then 
 
		Hint_bar_mouse_input_tracker:subscribe(false) 
 
		Hint_bar_mouse_input_tracker:remove_all() 
 
	end 
 
	 
 
	Hint_bar:set_visible(false) 
 
 
 
	Show_partner_gamercard = false 
 
 
 
	if show_invite_friends then 
 
		-- Show the hint bar 
 
		local hint_data = {}  
		if Num_friends == 0 then 
 
			hint_data = {  
				{CTRL_MENU_BUTTON_B, "MENU_BACK"},  
			} 
 
		else 
 
			hint_data = {  
				{CTRL_MENU_BUTTON_B, "MENU_BACK"},  
				{CTRL_BUTTON_X, "PLT_MENU_VIEW_GAMERCARD"},  
			} 
 
		end 
 
 
 
		Party_invite = false 
 
		if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then 
 
			if game_get_party_member_count() > 1 then 
 
				hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_INVITE" }  
				Party_invite = true 
 
			end 
 
		end 
 
		 
 
		Hint_bar:set_hints(hint_data) 
 
		 
 
		Hint_bar:set_visible(true) 
 
	 
 
	else 
 
	 
 
		if (Connected or not game_get_is_host()) and game_is_syslink() == false then 
 
			local hint_data = {  
				{CTRL_BUTTON_X, "PLT_MENU_VIEW_PARTNER_GAMERCARD"},  
			} 
 
			Show_partner_gamercard = true 
 
			Hint_bar:set_hints(hint_data) 
 
			Hint_bar:set_visible(true) 
 
		end 
 
	 
 
	end 
 
	 
 
	if game_get_platform() == "PC" then 
 
		Hint_bar:set_highlight(0) 
 
		Hint_bar:add_mouse_inputs( "game_lobby", Hint_bar_mouse_input_tracker, 1000) 
 
		Hint_bar_mouse_input_tracker:subscribe(true) 
 
	end 
 
	 
 
end 
 
 
 
-- HVS_JRS 8/22/2014 go back after aborting invite 
 
function game_lobby_back() 
 
	game_lobby_button_b() 
 
end 
 
 
 
-------------------------------------------------------- 
 
-- Init/Clean up 
 
function game_lobby_init() 
 
	Game_lobby_doc_h = vint_document_find("game_lobby")  
	 
 
	--Do we need to pause map dump? 
 
	pause_map_dump() 
 
	 
 
	--Set background for "bg_saints" 
 
	bg_saints_set_type(BG_TYPE_PAUSE, false) 
 
	bg_saints_show(true) 
 
 
 
	--Setup Button Hints 
 
	Hint_bar = Vdo_hint_bar:new("hint_bar")  
	 
 
	--Setup the list 
 
	Game_lobby_list = Vdo_mega_list:new("list", 0, Game_lobby_doc_h, "game_lobby.lua", "Game_lobby_list")  
	Game_lobby_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY) 
 
	 
 
	Char_client_grp_h = vint_object_find("client_char_bmp")  
	Char_host_grp_h = vint_object_find("host_char_bmp")  
	 
 
	--Initialize Input Tracker 
 
	Input_tracker = Vdo_input_tracker:new() 
 
	Input_tracker:add_input("pause", 		"game_lobby_button_start", 	50)  
	Input_tracker:add_input("select", 		"game_lobby_button_a", 			50)  
	Input_tracker:add_input("alt_select", 	"game_lobby_button_x", 			50)  
	Input_tracker:add_input("exit",			"game_lobby_button_y",			50)  
	Input_tracker:add_input("back", 			"game_lobby_button_b", 			50)  
	Input_tracker:add_input("nav_up", 		"game_lobby_nav_up", 			50)  
	Input_tracker:add_input("nav_down", 	"game_lobby_nav_down", 			50)  
	Input_tracker:add_input("nav_left", 	"game_lobby_nav_left", 			50)  
	Input_tracker:add_input("nav_right", 	"game_lobby_nav_right", 		50)  
	 
 
	-- Add mouse inputs for the PC 
 
	if game_get_platform() == "PC" then 
 
		Hint_bar:set_highlight(0) 
 
		 
 
		Mouse_input_tracker = Vdo_input_tracker:new() 
 
		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
 
 
 
		Mouse_input_tracker:subscribe(false) 
 
		Hint_bar_mouse_input_tracker:subscribe(false) 
 
	end 
 
	 
 
	if game_get_is_host() and game_coop_get_starting_coop() then 
 
		game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
 
	else 
 
		game_lobby_show_spinner(false, nil) 
 
	end 
 
	 
 
	local base_grp_h = vint_object_find("base_grp")  
	vint_set_property(base_grp_h, "visible", false) 
 
	 
 
	build_hint_bar() 
 
	 
 
end 
 
 
 
function game_lobby_cleanup() 
 
	if Invite_show_thread ~= -1 then 
 
		thread_kill(Invite_show_thread) 
 
	end 
 
	game_peg_unload("ui_bms_lobby_coop")  
	 
 
	pause_map_restore() 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Called from game after we've unloaded the pause map... 
 
-- 
 
function game_lobby_init_done() 
 
	--load coop  
 
	game_peg_load_with_cb("game_lobby_peg_loaded", 1, "ui_bms_lobby_coop")  
end 
 
 
 
function game_lobby_peg_loaded() 
 
	--base group.... 
 
	local base_grp_h = vint_object_find("base_grp")  
	vint_set_property(base_grp_h, "visible", true) 
 
 
 
	-- Grab some common handles 
 
	Host_char_bmp_h			= vint_object_find("host_char_bmp")  
	Host_info_grp_h			= vint_object_find("host_info_grp")  
	Host_speak_bmp_h			= vint_object_find("host_speak_bmp")  
	Host_name_txt_h			= vint_object_find("host_name_txt")  
	Client_char_bmp_h			= vint_object_find("client_char_bmp")  
	Client_info_grp_h			= vint_object_find("client_info_grp")  
	Client_speak_bmp_h		= vint_object_find("client_speak_bmp")  
	Client_name_txt_h			= vint_object_find("client_name_txt")  
 
 
	-- Set the waiting text, if necessary 
 
	game_lobby_set_waiting_prompt() 
 
	 
 
	-- Adjust the screen layout 
 
	game_lobby_set_screen_layout() 
 
	 
 
	-- Create the main lobby list 
 
	game_lobby_create_lobby() 
 
	 
 
	-- Show the main coop lobby menu 
 
	game_lobby_show_main() 
 
 
 
	game_lobby_finished_loading() 
 
	 
 
	Input_tracker:subscribe(true) 
 
	 
 
	if Game_lobby_joined ~= -1 then 
 
		game_lobby_joined(Game_lobby_joined) 
 
	end 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- 
 
-- Updates from code 
 
-- 
 
------------------------------------------------------------------------------- 
 
-- Called from code when a client connects, and again when finished connecting 
 
-- @param 	join_complete				true when the client is fully connected, false when still connecting 
 
-- 
 
function game_lobby_joined(join_complete) 
 
	 
 
	Game_lobby_joined = join_complete 
 
	 
 
	local values = { [0] = game_lobby_get_remote_player_name(), }  
	local tag = nil 
 
	 
 
	if In_invite == true then 
 
		game_lobby_button_b() 
 
	end 
 
	 
 
	if game_is_syslink() == false then  
 
		Lobby_data[1] = Kick_button 
 
	end 
 
		 
 
	if join_complete then  
 
		Lobby_data[START_INDEX].label = "COOP_LOBBY_COOP_START" 
 
		Lobby_data[START_INDEX].disabled = false 
 
				 
 
		Join_completed = true 
 
		tag = vint_insert_values_in_string("COOP_LOBBY_JOINED", values)  
	 
 
	else 
 
		Join_completed = false 
 
		tag = vint_insert_values_in_string("COOP_LOBBY_JOINING", values)  
	end 
 
	 
 
	Connected = true 
 
	game_lobby_show_spinner((join_complete ~= true), tag) 
 
 
 
	if Data == Lobby_data then 
 
		if Mouse_input_tracker ~= 0 then 
 
			Mouse_input_tracker:remove_all() 
 
		end 
 
		 
 
		local selection = Game_lobby_list:get_selection() 
 
		Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
		 
 
		if Mouse_input_tracker ~= 0 then 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
	end 
 
	 
 
	build_hint_bar() 
 
 
 
end 
 
 
 
------------------------------------------------ 
 
-- Called from code when the client disconnects 
 
-- 
 
function game_lobby_disconnect() 
 
	-- reset the globals, we're disconnected	 
 
	Join_completed = false 
 
	Connected = false 
 
	 
 
	-- Flag start button for not being enabled 
 
	Lobby_data[START_INDEX].label = "COOP_LOBBY_START_GAME" 
 
	 
 
	-- Update the imagery 
 
	game_lobby_set_screen_layout() 
 
	 
 
	-- Update the spinner to show "Left" text 
 
	local values = { [0] = game_lobby_get_remote_player_name(), }  
	local tag = vint_insert_values_in_string("COOP_LOBBY_LEFT", values)  
	game_lobby_show_spinner(false, tag) 
 
	 
 
	-- Spawn a thread to reset the text to "waiting for player" after 5 seconds 
 
	thread_new("game_lobby_reset_waiting")  
	 
 
	-- Update the invite button 
 
	if game_is_syslink() == false then  
 
		Lobby_data[1] = Invite_button 
 
	end 
 
	 
 
	-- We're always ready when we're the only bros 
 
	--game_lobby_update_local_ready(true) 
 
	 
 
	-- Redraw the list with the updated button 
 
	if Data == Lobby_data then 
 
		local selection = Game_lobby_list:get_selection() 
 
		Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
		 
 
		if Mouse_input_tracker ~= 0 then 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
	end 
 
	 
 
	build_hint_bar() 
 
end 
 
 
 
------------------------------------------------ 
 
-- Set the waiting text back to "waiting" 
 
-- 
 
function game_lobby_reset_waiting() 
 
	delay(5) 
 
	game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- 
 
-- MENU SETUP / INITIALIZATION 
 
-- 
 
------------------------------------------------------------------------------- 
 
-- Sets whether or not the map / character stuff is shown, and updates the 
 
-- 
 
function game_lobby_set_screen_layout() 
 
	local coop_grp_h = vint_object_find("coop_grp")  
	local whored_char_info_grp_h = vint_object_find("whored_char_info_grp")  
	 
 
	vint_set_property(whored_char_info_grp_h, "visible", false) 
 
	vint_set_property(coop_grp_h, "visible", true) 
 
 
 
	game_lobby_set_logo(false) 
 
		 
 
	-- Set bitmaps 
 
	-- Saints bitmap... 
 
	local saints_bmp_h = vint_object_find("saints_bmp")  
	vint_set_property(saints_bmp_h, "image", "ui_main_menu_coop_team") 
 
 
 
end 
 
 
 
-- Create the main lobby list 
 
-- 
 
function game_lobby_create_lobby() 
 
	local coop_client = false 
 
	if game_get_is_host() then 
 
		-- Host Lobby 
 
		if game_coop_get_starting_syslink() == true then  
 
			OPTIONS_INDEX 		= 1	-- No invite button in sys link 
 
			START_INDEX 		= 2 
 
			QUIT_INDEX 			= 3 
 
		else  
 
			INVITE_INDEX 		= 1 
 
			OPTIONS_INDEX		= 2 
 
			START_INDEX 		= 3 
 
			QUIT_INDEX			= 4 
 
		end 
 
	end 
 
 
 
	-- Set all the menu buttons based on the indexes 
 
	Lobby_data[INVITE_INDEX]		= Invite_button 
 
	Lobby_data[OPTIONS_INDEX]		= Cooptions_button 
 
	Lobby_data[START_INDEX]			= Start_game_button 
 
	Lobby_data[QUIT_INDEX]			= Quit_game_button 
 
 
 
	if game_is_syslink() == false then  
 
		Cooptions_data[#Cooptions_data + 1]	= Privacy_button 
 
	end 
 
	Cooptions_data[#Cooptions_data + 1] 		= FF_button 
 
 
 
	-- Items that weren't available overwrote -1, so set it back to nil	 
 
	Lobby_data[UNAVAILABLE_INDEX]	= nil 
 
 
 
	-- Get the defaults for these buttons 
 
	Privacy_button.current_value = game_get_coop_join_type() + 1 
 
	FF_button.current_value = game_get_coop_friendly_fire() + 1 -- the values reverse the options 
 
end 
 
 
 
--------------------------- 
 
-- Show the main lobby Menu 
 
-- 
 
function game_lobby_show_main() 
 
	if Invite_show_thread ~= -1 then 
 
		thread_kill(Invite_show_thread) 
 
		Invite_show_thread = -1 
 
	end 
 
	In_invite = false	 
 
	 
 
	Num_friends = 0 
 
	Party_invite = false 
 
 
 
	build_hint_bar() 
 
	 
 
	Back_callback = -1	-- No back from here 
 
	Data = Lobby_data 
 
	Game_lobby_list:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
	 
 
	if Mouse_input_tracker ~= 0 then 
 
		Mouse_input_tracker:subscribe(false) 
 
		Mouse_input_tracker:remove_all() 
 
		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
		Mouse_input_tracker:subscribe(true) 
 
	end 
 
 
 
	Menu_has_shown = true 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- 
 
-- SPINNER FUNCTIONALTIY 
 
-- 
 
------------------------------------------------------------------------------- 
 
-- Set "Waiting for player" text if we're in coop.  
 
-- 
 
function game_lobby_set_waiting_prompt() 
 
	if game_coop_get_starting_coop() then 
 
		if game_get_is_host() == true then 
 
			game_lobby_show_spinner(true, "COOP_LOBBY_WAITING") 
 
		else 
 
			local values = { [0] = game_lobby_get_remote_player_name() }  
			local tag = vint_insert_values_in_string("COOP_LOBBY_WAITING_FOR_HOST", values)  
			game_lobby_show_spinner(false, tag) 
 
		end 
 
	else  
 
		game_lobby_hide_spinner() 
 
	end 
 
end 
 
 
 
------------------------------------------------------------ 
 
-- Shows spinner 
 
-- @param	show_spinner		spinner on or off 
 
-- @param	text					text to appear next to spinner 
 
-- 
 
function game_lobby_show_spinner(show_spinner, text) 
 
	local spinner_h = vint_object_find("spinner_grp")  
	local player_waiting_txt_h = vint_object_find("player_waiting_txt")  
	local spinny_anim_h = vint_object_find("spinny_anim")  
	if show_spinner then 
 
		lua_play_anim(spinny_anim_h) 
 
		vint_set_property(spinner_h, "visible", true) 
 
	else 
 
		vint_set_property(spinner_h, "visible", false) 
 
	end 
 
	 
 
	if Data == Lobby_data then 
 
		local last_option_selected = Game_lobby_list:get_selection() 
 
		Game_lobby_list:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
		 
 
		if Mouse_input_tracker ~= 0 then 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
	end 
 
 
 
	if text ~= nil then 
 
		--Set Text 
 
		vint_set_property(player_waiting_txt_h, "visible", true) 
 
		vint_set_property(player_waiting_txt_h, "text_tag", text) 
 
	else 
 
		vint_set_property(player_waiting_txt_h, "visible", false)		 
 
	end 
 
	 
 
	--Align text to left if no spinner present 
 
	if text ~= nil and show_spinner == false then 
 
		vint_set_property(player_waiting_txt_h, "anchor", 0, -11) 
 
	else 
 
		vint_set_property(player_waiting_txt_h, "anchor", 50, -11) 
 
	end 
 
	 
 
end 
 
 
 
------------------------------------------------------------ 
 
-- Hides the spinner and waiting text 
 
function game_lobby_hide_spinner() 
 
	local spinner_h = vint_object_find("spinner")  
	local player_waiting_txt_h = vint_object_find("player_waiting_txt")  
	vint_set_property(spinner_h, "visible", false) 
 
	vint_set_property(player_waiting_txt_h, "visible", false) 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Sets the style logo depending on what mode we are in 
 
function game_lobby_set_logo() 
 
	local whored_logo_grp_h = vint_object_find("whored_logo_grp")  
	vint_set_property(whored_logo_grp_h, "visible", false) 
 
 
 
	local game_logo_grp_h = vint_object_find("game_logo_grp")  
	vint_set_property(game_logo_grp_h, "visible", true) 
 
	local logo_bmp_h = vint_object_find("game_logo_bmp")  
	vint_set_property(logo_bmp_h, "image", "ui_whored_logo_game") 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- 
 
-- LOBBY FUNCTIONALITY 
 
-- 
 
------------------------------------------------------------------------------- 
 
-- Initiate a single player game 
 
-- 
 
function game_lobby_start_single_player() 
 
	game_lobby_coop_finished() 
 
	game_UI_audio_play("UI_Main_Menu_Select")  
end 
 
 
 
------------------------------------------------------------------------ 
 
-- Dialog Confirmation Callback for start with a joining client 
 
-- @param 	result				Yes / No to kick the joining coop player 
 
-- @param	action				Make sure this was closed (should always be in SR3) 
 
-- 
 
function game_lobby_sp_start_confim(result, action) 
 
	if result == 0 then 
 
		game_kick_coop_player(true) 
 
		game_lobby_start_single_player() 
 
	end 
 
end 
 
 
 
-------------------------------------------------------- 
 
-- Called from C when the countdown to start is complete 
 
-- 
 
function game_lobby_countdown_game_start() 
 
	game_lobby_coop_finished() 
 
end 
 
 
 
------------------------------------------------------ 
 
-- Respond to Start game button 
 
-- Prompts to kick a joining coop player if necessary 
 
-- 
 
function game_lobby_start_game() 
 
	if Join_completed == false then 
 
		if Connected == true then 
 
			-- If a join hasn't been completed, but someone is joining, prompt to kick them 
 
			dialog_box_confirmation("CONTROL_START_GAME", "COOP_SINGLE_PLAYER_KICK_MSG", "game_lobby_sp_start_confim", nil, nil, 1)  
		else  
 
			-- If the no one is connected, continue on with a start 
 
			game_lobby_start_single_player() 
 
		end 
 
	else  
 
		-- Join's complete 
 
		game_lobby_coop_finished() 
 
	end 
 
end 
 
 
 
------------------------------------------------------------------------ 
 
-- Dialog Confirmation Callback for quitting to main menu 
 
-- @param 	result				Yes / No  
 
-- @param	action				Make sure this was closed (should always be in SR3) 
 
-- 
 
function game_lobby_confirm_quit(result, action) 
 
	if result == 0 then 
 
		Input_tracker:subscribe(false) 
 
		if Mouse_input_tracker ~= 0 then 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
		pause_menu_quit_game_internal() 
 
	end 
 
end 
 
 
 
--------------------------------------------- 
 
-- Confirm we want to return to the main menu 
 
-- 
 
function game_lobby_quit() 
 
	dialog_box_confirmation("PAUSE_MENU_QUIT_TITLE","QUIT_GAME_TEXT_FULL","game_lobby_confirm_quit", nil, nil, 1)  
end 
 
 
 
------------------------------------------ 
 
-- Called when a toggle option is changed 
 
-- 
 
function game_lobby_change_option() 
 
	local option_id = Game_lobby_list:get_id() 
 
	 
 
	if option_id == ID_PRIV then 
 
		game_set_coop_join_type(Privacy_button.current_value - 1) 
 
	elseif option_id == ID_FF then 
 
		game_set_coop_friendly_fire(FF_button.current_value - 1) 
 
	end 
 
 
 
	local selection = Game_lobby_list:get_selection() 
 
	Game_lobby_list:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
	 
 
	if Mouse_input_tracker ~= 0 then 
 
		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
		Mouse_input_tracker:subscribe(true) 
 
	end 
 
end 
 
 
 
------------------------------------------------------------------------------ 
 
-- Update the map image from global data. 
 
-- 
 
function game_lobby_update_map_display() 
 
	 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Update the character image and name 
 
-- 
 
-- @host_update	true if we are the host, false for client 
 
-- @value			internal name of the character. 
 
-- 
 
function game_lobby_update_char_display(host_update, value) 
 
	local char_name_h 
 
	local char_bmp_h 
 
	if host_update == true then 
 
		char_bmp_h = Host_char_bmp_h 
 
	else  
 
		game_lobby_show_char(false, true) 
 
		vint_set_property(Client_speak_bmp_h, "visible", false) 
 
		char_bmp_h = Client_char_bmp_h 
 
	end 
 
	local char_img_name = Char_image_names[Character_button.options_data[value].internal_name] 
 
	vint_set_property(char_bmp_h, "image", char_img_name) 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- Shows or hides client or host images and text 
 
-- 
 
-- @host_update	true if we are the host, false for client 
 
-- @value			internal name of the character. 
 
-- 
 
function game_lobby_show_char(host_update, is_visible) 
 
	local bmp_h 
 
	local info_grp_h  
 
	if host_update then 
 
		bmp_h			= Host_char_bmp_h 
 
		info_grp_h	= Host_info_grp_h 
 
	else 
 
		bmp_h			= Client_char_bmp_h 
 
		info_grp_h	= Client_info_grp_h 
 
	end 
 
	vint_set_property(bmp_h, "visible", is_visible) 
 
	vint_set_property(info_grp_h, "visible", is_visible) 
 
end 
 
 
 
 
 
function game_lobby_cancel_ready() 
 
	game_lobby_update_local_ready(false) 
 
	if game_get_is_host() then 
 
		game_lobby_show_main() 
 
	end 
 
end 
 
 
 
function game_lobby_start_dialog_canceled() 
 
	Local_ready = false 
 
	Start_game_button.on_select = game_lobby_start_game 
 
end 
 
 
 
------------------------------------------------ 
 
-- Update the ready display for the local player 
 
-- and send the changed ready state to C 
 
function game_lobby_update_local_ready(ready) 
 
	game_lobby_update_ready_state(ready) 
 
	Local_ready = ready 
 
	 
 
	if game_get_is_host() == false then 
 
		Start_game_button.equipped = ready 
 
		game_UI_audio_play("UI_Main_Menu_Select")  
	end 
 
	 
 
	-- Swap the list and add cancel 
 
	if Local_ready then 
 
		if Remote_ready ~= true then 
 
			-- Set spinner text to "Waiting for " 
 
		end 
 
 
 
		Start_game_button.on_select = game_lobby_cancel_ready 
 
 
 
		if Mouse_input_tracker ~= 0 then 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
	else 
 
		Start_game_button.on_select = game_lobby_start_game 
 
	end 
 
	 
 
	local selection = Game_lobby_list:get_selection() 
 
	Game_lobby_list:draw_items(Lobby_data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
	 
 
	if game_get_is_host() and game_coop_get_starting_coop() == false then 
 
		game_lobby_hide_spinner(true) 
 
	end 
 
end 
 
 
 
----------------------------------------------------- 
 
-- Kick the client. Prompts with a dialog internally 
 
-- 
 
function game_lobby_kick() 
 
	game_coop_kick_player() 
 
end 
 
 
 
--------------------------------- 
 
-- Show the coop options menu 
 
-- 
 
function game_lobby_coop_options() 
 
	Data = Cooptions_data 
 
	Game_lobby_list:draw_items(Data, nil, nil, nil, nil, nil, false) 
 
	 
 
	game_UI_audio_play("UI_Main_Menu_Select")  
	 
 
	local hint_data = {  
		{CTRL_MENU_BUTTON_B, "MENU_BACK"},  
	} 
 
	Hint_bar:set_hints(hint_data) 
 
	Hint_bar:set_visible(true) 
 
	 
 
	if Mouse_input_tracker ~= 0 then 
 
		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
		Mouse_input_tracker:subscribe(true) 
 
	end 
 
end 
 
 
 
-------------------------------------------------- 
 
-- When the Friendly Fire option changes, update it 
 
-- (Client only) 
 
-- 
 
function game_lobby_update_ff(data_item_handle, event_name) 
 
	if game_get_is_host() or Menu_has_shown == false then 
 
		return 
 
	end 
 
	 
 
	local ff_option = vint_dataitem_get(data_item_handle) 
 
	FF_button.current_value = ff_option + 1 
 
 
 
	-- Redraw the current menu 
 
	local last_option_selected = Game_lobby_list:get_selection() 
 
	Game_lobby_list:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, nil, nil, nil, false) 
 
	 
 
	if Mouse_input_tracker ~= 0 then 
 
		Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
		Mouse_input_tracker:subscribe(true) 
 
	end 
 
end 
 
 
 
------------------------------------------------------------------------------- 
 
-- 
 
-- INVITE FRIEND 
 
-- 
 
------------------------------------------------------------------------------- 
 
-- Spawn a thread to show the invite interface 
 
-- (It may have to yield for the dataresponder, so use another thread 
 
--  
 
function game_lobby_show_invite() 
 
	In_invite = true 
 
	if Invite_show_thread == -1 then 
 
		Invite_show_thread = thread_new("game_lobby_retrieve_invite")  
	end 
 
end 
 
 
 
------------------------------------------ 
 
-- Thread to get the friends list 
 
-- 
 
function game_lobby_retrieve_invite() 
 
 
 
	-- Show "Searching" while the other data responder goes for it 
 
	Data = {	[1] = { type = TYPE_BUTTON, label = "MENU_SEARCHING", id = -1,	disabled = true }, 	}  
	Game_lobby_list:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
 
 
	Num_friends = 0 
 
	build_hint_bar(true) 
 
 
 
	delay(.5) -- Make sure we show that "Searching" message for at least half a second. 
 
 
 
	-- Populate the friends list 
 
	while true do	 
 
		Data = { }  
		Num_friends = 0 
 
		vint_dataresponder_request("coop_list_responder", "game_lobby_invite_populate", 0, COOP_INVITE_LIST)  
 
 
		-- Check for no friends found 
 
		if Num_friends == 0 then 
 
			Data = {	[1] = {	type = TYPE_BUTTON, label = "MENU_NO_FRIENDS_FOUND", id = -1, disabled = true	}	}  
		end 
 
 
 
		--Get the selection option from when the menu was last loaded 
 
		local current_index = 1 
 
		if Num_friends > 0 then 
 
			current_index = min(Game_lobby_list:get_selection(), Num_friends) 
 
		end 
 
		Game_lobby_list:draw_items(Data, current_index, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LIST_FONT_SCALE, LOBBY_LIST_FORCE_SCALE, false) 
 
		 
 
		build_hint_bar(true) 
 
		Input_tracker:subscribe(true) 
 
		if Mouse_input_tracker ~= 0 then 
 
			Mouse_input_tracker:subscribe(false) 
 
			Mouse_input_tracker:remove_all() 
 
			Game_lobby_list:add_mouse_inputs("game_lobby", Mouse_input_tracker)  
			Mouse_input_tracker:subscribe(true) 
 
		end 
 
		 
 
		delay(2.0) 
 
	end 
 
	 
 
	-- Clear thread 
 
	Invite_show_thread = -1 
 
end 
 
 
 
--------------------------------------------- 
 
-- Populate the invite list 
 
-- @param 	name				Name of the friend 
 
-- 
 
--HVS_JPM[KING] 12/12/2014: added invite_flags from XBOX3 version to differentiate between friends online playing the game and ones just online 
 
function game_lobby_invite_populate(name, id, invite_tag, invite_flags) 
 
	if In_invite == true then	-- HVS_JRS 11/25/2014 only populate invite when In_invite == true 
 
		Num_friends = Num_friends + 1 
 
		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 }  
	end 
 
end 
 
 
 
--------------------------------------- 
 
-- Show the selected friend's gamercard 
 
-- 
 
function game_lobby_view_gamercard() 
 
	game_show_coop_gamercard(Game_lobby_list:get_selection() - 1) 
 
end 
 
 
 
------------------------------- 
 
-- Invite the selected friend 
 
-- 
 
function game_lobby_invite_friend() 
 
	local friend_index = Game_lobby_list:get_id() 
 
	local insert_values = { [0] = Data[Game_lobby_list:get_selection()].label }  
	local body = vint_insert_values_in_string("MP_INVITE_SENT_BODY", insert_values)  
 
 
	if game_can_send_player_invite(friend_index) == false then 
 
		local body = vint_insert_values_in_string("INVITE_FAILED_BODY", insert_values)  
		dialog_box_message("INVITE_FAILED_TITLE", body)  
		return 
 
	end 
 
 
 
	game_send_pause_menu_player_invite(friend_index) -- offset index by 1 
 
	dialog_box_message("MP_INVITE_SENT_TITLE", body)  
end 
 
 
 
--------------------------------- 
 
-- 
 
-- Input handlers 
 
-- 
 
--------------------------------- 
 
function game_lobby_button_a(event, acceleration) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		local current_id = Game_lobby_list:get_id() 
 
		local current_index = Game_lobby_list:get_selection() 
 
 
 
		if Data[current_index] == nil then 
 
			return 
 
		end 
 
		 
 
		--Do something different on our toggle options... 
 
		if Data[current_index].type == TYPE_TOGGLE then 
 
			-- Move highlight right 
 
			Game_lobby_list:move_slider(1) 
 
			if Data[current_index].on_change ~= nil then 
 
				Data[current_index].on_change() 
 
			end 
 
			return 
 
		end 
 
		 
 
		if Data[current_index].on_select ~= nil then 
 
			if Data[current_index].set_back_callback ~= nil then 
 
				Back_callback = Data[current_index].set_back_callback 
 
			end 
 
			Data[current_index].on_select() 
 
		end 
 
	end 
 
end 
 
 
 
function game_lobby_button_b(event, acceleration) 
 
	if Back_callback ~= nil and Back_callback ~= -1 then 
 
		game_UI_audio_play("UI_Main_Menu_Nav_Back")  
		Back_callback() 
 
	end 
 
end 
 
 
 
function game_lobby_button_x(event, acceleration) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		local current_index = Game_lobby_list:get_selection() 
 
 
 
		if Data[current_index].on_alt_select ~= nil then 
 
			Data[current_index].on_alt_select() 
 
		elseif Show_partner_gamercard then -- only show the gamercard while on the top menu 
 
			game_show_coop_partner_gamercard() 
 
		end 
 
	end 
 
end 
 
 
 
function game_lobby_button_y() 
 
	if Party_invite then 
 
		game_send_party_invites() 
 
	end 
 
end 
 
 
 
function game_lobby_button_start() 
 
end 
 
 
 
function game_lobby_nav_up(event, acceleration) 
 
	-- Move highlight up 
 
	Game_lobby_list:move_cursor(-1) 
 
end 
 
 
 
function game_lobby_nav_down(event, acceleration) 
 
	-- Move highlight down 
 
	Game_lobby_list:move_cursor(1) 
 
end 
 
 
 
function game_lobby_nav_left(event, acceleration) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		local current_index = Game_lobby_list:get_selection() 
 
		if current_index < 0 then 
 
			return 
 
		end 
 
		 
 
		-- Move highlight left	 
 
		Game_lobby_list:move_slider(-1) 
 
		if Data[current_index].on_change ~= nil then 
 
			Data[current_index].on_change() 
 
		end 
 
	end 
 
end 
 
 
 
function game_lobby_nav_right(event, acceleration) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		local current_index = Game_lobby_list:get_selection() 
 
		if current_index < 0 then 
 
			return 
 
		end 
 
 
 
		-- Move highlight right 
 
		Game_lobby_list:move_slider(1) 
 
		if Data[current_index].on_change ~= nil then 
 
			Data[current_index].on_change() 
 
		end 
 
	end 
 
end 
 
 
 
-- Mouse inputs 
 
function game_lobby_mouse_click(event, target_handle, mouse_x, mouse_y) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		local hint_index = Hint_bar:get_hint_index(target_handle) 
 
		if hint_index == 1 then 
 
			game_lobby_button_b() 
 
			return 
 
		elseif hint_index == 2 then 
 
			game_lobby_button_x() 
 
		end 
 
		 
 
		local new_index = Game_lobby_list:get_button_index(target_handle) 
 
		if new_index ~= 0 then 
 
			Game_lobby_list:set_selection(new_index) 
 
			game_lobby_button_a() 
 
		end 
 
		 
 
		local current_index = Game_lobby_list:get_selection() 
 
		if Game_lobby_list:is_left_arrow(target_handle) then 
 
			Game_lobby_list:move_slider(-1) 
 
			if Data[current_index].on_change ~= nil then 
 
				Data[current_index].on_change() 
 
			end 
 
		elseif Game_lobby_list:is_right_arrow(target_handle) then 
 
			Game_lobby_list:move_slider(1) 
 
			if Data[current_index].on_change ~= nil then 
 
				Data[current_index].on_change() 
 
			end 
 
		end 
 
		if Game_lobby_list:is_slider(target_handle) then 
 
			Game_lobby_list:move_slider(0, mouse_x) 
 
			if Data[current_index].on_change ~= nil then 
 
				Data[current_index].on_change() 
 
			end 
 
		end 
 
	end 
 
end 
 
 
 
function game_lobby_mouse_move(event, target_handle) 
 
	if Game_lobby_list:list_is_playing() == false then 
 
		Hint_bar:set_highlight(0) 
 
		 
 
		local hint_index = Hint_bar:get_hint_index(target_handle) 
 
		if hint_index ~= 0 then 
 
			Hint_bar:set_highlight(hint_index) 
 
		end 
 
		 
 
		local new_index = Game_lobby_list:get_button_index(target_handle) 
 
		if new_index ~= 0 then 
 
			Game_lobby_list:set_selection(new_index) 
 
			Game_lobby_list:move_cursor(0, true) 
 
		end 
 
	end 
 
end 
 
 
 
function game_lobby_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
 
	if scroll_lines ~= 0 then 
 
		if Game_lobby_list:get_scroll_region_handle() == target_handle then 
 
			Game_lobby_list:scroll_list(scroll_lines * -1) 
 
			Game_lobby_list:update_mouse_inputs("game_lobby", Mouse_input_tracker)  
		end 
 
	end 
 
end 
 
 
 
function game_lobby_mouse_drag(event, target_handle, mouse_x, mouse_y) 
 
	local scrollbar = Game_lobby_list.scrollbar 
 
	if Game_lobby_list.scrollbar.tab_grp.handle == target_handle then 
 
		 
 
		local max_items = Game_lobby_list.num_buttons - (Game_lobby_list.max_buttons - 1) 
 
		 
 
		local new_start_index = scrollbar:drag_scrolltab(mouse_y, max_items) 
 
		 
 
		Game_lobby_list:scroll_list(0, new_start_index) 
 
	end 
 
end 
 
 
 
function game_lobby_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
 
end 
 
 
 
-- List data 
 
------------------------------------------------------------------------------- 
 
Invite_button 		= { 	type = TYPE_BUTTON, label = "COOP_MENU_INVITE", on_select = game_lobby_show_invite, set_back_callback = game_lobby_show_main 		}  
Kick_button 		= { 	type = TYPE_BUTTON, label = "CONTROL_KICK_PLAYER", on_select = game_lobby_kick 																	}  
Cooptions_button	= {	type = TYPE_BUTTON, label = "COOP_OPTIONS", on_select = game_lobby_coop_options, set_back_callback = game_lobby_show_main 			}  
Start_game_button	= { 	type = TYPE_BUTTON, label = "COOP_LOBBY_START_GAME", on_select = game_lobby_start_game 														}  
Quit_game_button	= {	type = TYPE_BUTTON, label = "COOP_LOBBY_QUIT", on_select = game_lobby_quit,																		}  
-- Coop options, Cooptions. 
 
Privacy_button		= { 	type = TYPE_TOGGLE,	label = "COOP_MENU_PRIVACY", on_change = game_lobby_change_option, id = ID_PRIV,  
								options = {"COOP_MENU_OPEN", "COOP_MENU_FRIENDS_ONLY", "COOP_MENU_PRIVATE"}, current_value = 1 												}  
FF_button 			= { 	type = TYPE_TOGGLE, label = "COOP_MENU_FRIENDLY_FIRE", on_change = game_lobby_change_option, id = ID_FF,  
								options = {"COOP_MENU_FULL_DAMAGE", "COOP_MENU_LIGHT_DAMAGE", "MENU_NONE"},	current_value = 1 											}