-- "Defines"
local COOP_INVITE_LIST = 0
local ID_PRIV = 1
local ID_FF = 2
local ID_MAP = 3
local ID_CHARACTER = 4
local ID_CANCEL_READY = 5
local HMLD_MAPS = 0
local HMLD_CHARS = 1
local HOST_ID = true
local CLIENT_ID = false
-- "Globals"
local Lobby_data = { }
local Data = {}
local LOBBY_LIST_SCALE = .9
local LOBBY_LIST_WIDTH = 440 -- 495
local LOBBY_LIST_MAX_ITEMS = 9
local LOBBY_LIST_FORCE_SCALE = false
local Horde_button
local Horde_mode_continue = 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
--Internal name is on left, bitmap on right.
local Char_image_names = {
["Bobert"] = "ui_lobby_char_bobert",
["Cowgirl"] = "ui_lobby_char_cowgirl",
["Cyril"] = "ui_lobby_char_cyril",
["Gimpy"] = "ui_lobby_char_gimpy",
["Super"] = "ui_lobby_char_super",
}
--Internal name is on left, bitmap on right.
local Map_image_names = {
["angels_area"] = "ui_lobby_level_casino",
["daedelus_area"] = "ui_lobby_level_daetelus",
["zombie_area"] = "ui_lobby_level_zombie",
}
-- VDOs
local Input_tracker
local Mouse_input_tracker = 0
local List = {}
local Hint_bar
local Header_obj
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
-- Whored Mode indices
local MAP_INDEX = UNAVAILABLE_INDEX
local CHARACTER_INDEX = UNAVAILABLE_INDEX
local CONTINUE_INDEX = UNAVAILABLE_INDEX
-- Coop options menu indices
local PRIVACY_INDEX = 1
local FF_INDEX = 2
local Party_invite = false
local Can_refresh_friend_list = false
local Show_partner_gamercard = false
local function build_hint_bar(show_invite_friends, searching)
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" 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
Can_refresh_friend_list = false
if searching ~= true and game_get_platform() == "PC" then
hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_REFRESH_SYSLINK" }
Can_refresh_friend_list = true
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)
else
Hint_bar:set_hints(nil)
Hint_bar:set_visible(false)
end
end
end
--------------------------------------------------------
-- Init/Clean up
function game_lobby_init()
--Do we need to pause map dump?
pause_map_dump()
--Set background for "bg_saints"
bg_saints_set_type(BG_TYPE_FULLSCREEN, false)
--Setup Button Hints
Hint_bar = Vdo_hint_bar:new("hint_bar")
--Setup the list
List = Vdo_mega_list:new("list")
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()
Mouse_input_tracker:subscribe(false)
--menu_common_set_mouse_tracker(Mouse_input_tracker)
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
--Unload logos and characters...
game_peg_unload("ui_bms_lobby_whored")
game_peg_unload("ui_bms_lobby_coop")
game_peg_unload("ui_bms_lobby_levels")
pause_map_restore()
end
-------------------------------------------------------------------------------
-- Called from game after we've unloaded the pause map...
--
function game_lobby_init_done()
if horde_mode_is_active() then
game_peg_load_with_cb("game_lobby_peg_loaded", 2, "ui_bms_lobby_whored", "ui_bms_lobby_levels")
else
--load coop
game_peg_load_with_cb("game_lobby_peg_loaded", 2, "ui_bms_lobby_coop", "ui_bms_lobby_levels")
end
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)
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)
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)
if horde_mode_is_active() then
-- Update client name
vint_set_property(Client_name_txt_h, "text_tag", game_lobby_get_remote_player_name())
-- We are not ready!
game_lobby_update_local_ready(false)
end
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)
build_hint_bar()
if Data == Lobby_data then
local selection = List:get_selection()
List:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
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
if horde_mode_is_active() then
Lobby_data[START_INDEX].disabled = true
else
Lobby_data[START_INDEX].label = "COOP_LOBBY_START_GAME"
end
-- 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
-- Hide the client in horde mode
if horde_mode_is_active() then
-- hide the client
game_lobby_show_char(false, false)
end
-- We're always ready when we're the only bros
--game_lobby_update_local_ready(true)
build_hint_bar()
-- Redraw the list with the updated button
if Data == Lobby_data then
local selection = List:get_selection()
List:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
------------------------------------------------
-- Set the waiting text back to "waiting"
--
function game_lobby_reset_waiting()
delay(5)
game_lobby_show_spinner(true, "COOP_LOBBY_WAITING")
end
------------------------------------------------
-- Update the map from the server (client only)
--
function game_lobby_update_map(new_value)
local new_selection = 0
for i = 1, #Map_button.options_data do
if Map_button.options_data[i].id == new_value then
new_selection = i
end
end
Map_button.current_value = new_selection
game_UI_audio_play("UI_Reward_Store_Menu_Navigation")
game_lobby_update_map_display()
game_lobby_update_continue_button()
local last_option_selected = List:get_selection()
List:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
------------------------------------------------
-- Update the other player's character
--
function game_lobby_update_char(new_value)
local new_selection = 0
for i = 1, #Character_button.options_data do
if Character_button.options_data[i].id == new_value then
new_selection = i
end
end
-- If I'm the host, we're updating the client
if game_get_is_host() then
game_lobby_update_char_display(false, new_selection)
else
-- If I'm the client, we're updating the host
game_lobby_update_char_display(true, new_selection)
end
end
------------------------------------------------
-- Update the other player's ready state
--
function game_lobby_update_ready(new_value, redraw_list)
local char_grp_h = 0
if game_get_is_host() then
char_grp_h = Char_client_grp_h
else
char_grp_h = Char_host_grp_h
end
Remote_ready = new_value
if new_value == false then
vint_set_property(char_grp_h, "tint", 0.2, 0.2, 0.2)
game_lobby_show_spinner(false,"")
if game_get_is_host() then
Lobby_data[START_INDEX].disabled = true
Lobby_data[CONTINUE_INDEX].disabled = true
-- If the remote player is no longer ready and we are doing a countdown, then cancel it
if Local_ready == true then
game_lobby_cancel_ready()
end
if redraw_list == true then
local last_option_selected = List:get_selection()
List:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
else
vint_set_property(char_grp_h, "tint", 1.0, 1.0, 1.0)
local values = { [0] = game_lobby_get_remote_player_name() }
local tag = vint_insert_values_in_string("COOP_LOBBY_IS_READY", values)
game_lobby_show_spinner(false, tag)
if game_get_is_host() then
Lobby_data[START_INDEX].disabled = false
Lobby_data[CONTINUE_INDEX].disabled = false
game_lobby_update_continue_button()
if redraw_list == true then
local last_option_selected = List:get_selection()
List:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
end
end
function game_lobby_countdown_update(should_display, time_left)
if should_display then
game_UI_audio_play("UI_HUD_Countdown")
game_lobby_show_spinner(false, vint_insert_values_in_string("COOP_LOBBY_GAME_STARTING", { [0] = time_left }))
else
game_lobby_hide_spinner(true)
end
end
-------------------------------------------------------------------------------
--
-- MENU SETUP / INITIALIZATION
--
-------------------------------------------------------------------------------
-- Sets whether or not the map / character stuff is shown, and updates the
-- bitmaps whether we're in horde/not horde
--
function game_lobby_set_screen_layout()
local whored_char_info_grp_h = vint_object_find("whored_char_info_grp")
local coop_grp_h = vint_object_find("coop_grp")
if horde_mode_is_active() then
--Horde mode version...
--Hide what is not used...
vint_set_property(coop_grp_h, "visible", false) --coop lobby stuff...
--set game lobby logo, whored mode.
game_lobby_set_logo(true)
-- Check if we're playing singleplayer or not
if game_coop_get_starting_coop() == true then
-- Coop
-- Hide the client group
game_lobby_show_char(false, false)
-- Set the host's name
vint_set_property(Host_name_txt_h, "text_tag", game_lobby_get_local_player_name())
elseif game_get_is_host() then -- not client
-- Hide the client group
game_lobby_show_char(false, false)
-- Hide the host name and his speaker
vint_set_property(Host_name_txt_h, "visible", false)
vint_set_property(Host_speak_bmp_h, "visible", false)
else
-- Client, so everyone should be visible
-- Set the host's name
vint_set_property(Host_name_txt_h, "text_tag", game_lobby_get_remote_player_name())
game_lobby_update_ready(false)
-- Set the client's name
vint_set_property(Client_name_txt_h, "text_tag", game_lobby_get_local_player_name())
end
else
-- For non-whored mode coop lobby...
vint_set_property(whored_char_info_grp_h, "visible", false)
vint_set_property(coop_grp_h, "visible", true)
--set game lobby logo, non whored mode.
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_lobby_char_saints")
-- Map background...
local map_bmp_h = vint_object_find("level_map_bmp")
vint_set_property(map_bmp_h, "image", "ui_lobby_level_sr3city")
end
end
-- Create the main lobby list
--
function game_lobby_create_lobby()
local coop_client = false
if game_get_is_host() and game_coop_get_starting_coop() == false then
-- Whored mode single player
MAP_INDEX = 1
CHARACTER_INDEX = 2
CONTINUE_INDEX = 3
START_INDEX = 4
QUIT_INDEX = 5
elseif game_get_is_host() then
-- Host Lobby
if game_coop_get_starting_syslink() == true then
FF_INDEX = 1 -- No invite button in sys link
if horde_mode_is_active() then
-- Starting a Horde Mode game, so add those options
MAP_INDEX = 2
CHARACTER_INDEX = 3
CONTINUE_INDEX = 4
START_INDEX = 5
QUIT_INDEX = 6
Start_game_button.label = "COOP_LOBBY_COOP_START"
Start_game_button.disabled = true
else
-- Non Horde Mode syslink
START_INDEX = 2
QUIT_INDEX = 3
end
else
INVITE_INDEX = 1
if horde_mode_is_active() then
-- Starting a Horde Mode game, so add those options
MAP_INDEX = 2
CHARACTER_INDEX = 3
OPTIONS_INDEX = 4
CONTINUE_INDEX = 5
START_INDEX = 6
QUIT_INDEX = 7
Start_game_button.label = "COOP_LOBBY_COOP_START"
Start_game_button.disabled = true
else
-- Non Horde Mode Live/PSN
OPTIONS_INDEX = 2
START_INDEX = 3
QUIT_INDEX = 4
end
end
else
-- Client menu
local start_index = 1
coop_client = true
if horde_mode_is_active() then
CHARACTER_INDEX = 1
start_index = 2
end
MAP_INDEX = start_index
FF_INDEX = start_index + 1
START_INDEX = start_index + 2 -- Sets the player in the ready state
QUIT_INDEX = start_index + 3
Start_game_button.label = "COOP_LOBBY_CLIENT_READY"
Start_game_button.owned = true
Start_game_button.equipped = false
--Start_game_button.is_checked = false
-- Get FF Updates from host
FF_button.disabled = true
Map_button.disabled = true
vint_dataitem_add_subscription("friendly_fire_data", "update", "game_lobby_update_ff")
end
-- Set all the menu buttons based on the indexes
Lobby_data[INVITE_INDEX] = Invite_button
Lobby_data[MAP_INDEX] = Map_button
Lobby_data[CHARACTER_INDEX] = Character_button
Lobby_data[OPTIONS_INDEX] = Cooptions_button
Lobby_data[CONTINUE_INDEX] = Continue_button
Lobby_data[START_INDEX] = Start_game_button
Lobby_data[QUIT_INDEX] = Quit_game_button
if coop_client == true or game_coop_get_starting_syslink() then
Lobby_data[FF_INDEX] = FF_button
--Lobby_data[MAP_INDEX] = Map_button
else
Cooptions_data[PRIVACY_INDEX] = Privacy_button
Cooptions_data[FF_INDEX] = FF_button
end
-- 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
-- For horde mode, setup the additional displays
if horde_mode_is_active() then
-- Populate the map options with the map names
Map_button.options = { }
Map_button.options_data = { }
Horde_button = Map_button
vint_dataresponder_request("horde_mode_lobby_populate", "game_lobby_populate_horde_data", 0, HMLD_MAPS)
Horde_mode_continue = false
-- Populate the character options with character names
Character_button.options = { }
Character_button.options_data = { }
Horde_button = Character_button
vint_dataresponder_request("horde_mode_lobby_populate", "game_lobby_populate_horde_data", 0, HMLD_CHARS)
game_lobby_update_map_selection(Map_button.options_data[Map_button.current_value].id)
game_lobby_update_char_selection(Character_button.options_data[Character_button.current_value].id)
game_lobby_update_char_display(game_get_is_host(), Character_button.current_value)
game_lobby_update_map_display()
game_lobby_update_continue_button()
if (game_get_is_host() and game_coop_get_starting_coop() ) then
Lobby_data[START_INDEX].disabled = true
Lobby_data[CONTINUE_INDEX].disabled = true
end
-- SEH: 8/6/2011: changed following so server isn't ready, as we want to be able to wait until both the server and host say they are ready.
game_lobby_update_local_ready(false)
end
-- If coop is already active when the Whored Mode lobby opens, allow immediate access
-- to the start button
if (game_get_is_host() and coop_is_active() and horde_mode_is_active()) then
game_lobby_joined(true)
end
end
function game_lobby_populate_horde_data(display_name, internal_name, id)
local index = #Horde_button.options + 1
Horde_button.options[index] = display_name
Horde_button.options_data[index] = { display_name = display_name, internal_name = internal_name, id = id }
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
List:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar: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.
-- Single player whored mode shows nothing here.
--
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 = List:get_selection()
List:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar: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
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
-- @is_whored_mode bool true if in whored mode...
function game_lobby_set_logo(is_whored_mode)
local game_logo_grp_h = vint_object_find("game_logo_grp")
local whored_logo_grp_h = vint_object_find("whored_logo_grp")
vint_set_property(game_logo_grp_h, "visible", false)
vint_set_property(whored_logo_grp_h, "visible", false)
if is_whored_mode then
--whored mode style logo...
vint_set_property(whored_logo_grp_h, "visible", true)
--set logo
local logo_bmp_h = vint_object_find("whored_logo_bmp")
vint_set_property(logo_bmp_h, "image", "ui_whored_logo")
vint_set_property(logo_bmp_h, "visible", true)
else
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
end
-------------------------------------------------------------------------------
--
-- LOBBY FUNCTIONALITY
--
-------------------------------------------------------------------------------
-- Initiate a single player game
-- (Horde or Regular)
--
function game_lobby_start_single_player()
if horde_mode_is_active() then
-- Horde_mode_continue should only be true if the player has hit the continue button
game_lobby_set_horde_mode_data(Horde_mode_continue)
else
game_lobby_coop_finished()
end
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()
if horde_mode_is_active() and game_get_is_host() then
-- Horde_mode_continue should only be true if the player has hit the continue button
game_lobby_set_horde_mode_data(Horde_mode_continue)
else
game_lobby_coop_finished()
end
end
------------------------------------------------------
-- Respond to Start game button
-- Prompts to kick a joining coop player if necessary
--
function game_lobby_start_game()
if game_get_is_host() == false then
if horde_mode_is_active() then
if Local_ready then
game_lobby_update_local_ready(false)
else
game_lobby_update_local_ready(true)
end
end
return
end
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
if horde_mode_is_active() then
-- Set us ready!
game_lobby_update_local_ready(Local_ready ~= true)
return
end
game_lobby_coop_finished()
end
end
------------------------------------------------------------------
-- Set horde mode continuing to true, and go to normal start logic
--
function game_lobby_whored_continue_game()
-- Horde_mode_continue should only be true if the player has hit the continue button
Horde_mode_continue = true
game_lobby_start_game()
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
Mouse_input_tracker:remove_all()
Mouse_input_tracker:subscribe(false)
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 = 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)
elseif option_id == ID_MAP then
game_lobby_update_map_selection(Map_button.options_data[Map_button.current_value].id)
game_lobby_update_map_display()
game_lobby_update_continue_button()
elseif option_id == ID_CHARACTER then
game_lobby_update_char_selection(Character_button.options_data[Character_button.current_value].id)
game_lobby_update_char_display(game_get_is_host(), Character_button.current_value)
end
local selection = List:get_selection()
List:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar: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()
local map_bmp_h = vint_object_find("level_map_bmp")
local map_img_name = Map_image_names[Map_button.options_data[Map_button.current_value].internal_name]
vint_set_property(map_bmp_h, "image", map_img_name)
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
Horde_mode_continue = 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
else
Horde_mode_continue = false
Start_game_button.on_select = game_lobby_start_game
end
local selection = List:get_selection()
Data = Lobby_data
List:draw_items(Data, selection, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if game_get_is_host() and game_coop_get_starting_coop() == false then
game_lobby_hide_spinner(true)
end
end
-----------------------------------------------------
-- Update the continue button to show wave number
-- or be disabled
--
function game_lobby_update_continue_button()
if game_get_is_host() then
local continue_wave = game_lobby_horde_continue_from_wave()
if continue_wave == -1 then
Continue_button.label = "CONTROL_CONTINUE"
Continue_button.disabled = true
else
local tag = vint_insert_values_in_string("COOP_LOBBY_CONTINUE_WAVE", { [0] = continue_wave })
Continue_button.label = tag
-- Allow the Continue button name to be updated above, but only enable the button if the
-- remote player has said they are ready
if (Remote_ready == false) and (game_coop_get_starting_coop() == true) then
Continue_button.disabled = true
else
Continue_button.disabled = false
end
end
else
Continue_button.label = "CONTROL_CONTINUE"
Continue_button.disabled = 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
List:draw_items(Data)
game_UI_audio_play("UI_Main_Menu_Select")
Show_partner_gamercard = false
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
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar: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 = List:get_selection()
List:draw_items(Data, last_option_selected, LOBBY_LIST_WIDTH)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar: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 }, }
List:draw_items(Data, 1, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
--if Mouse_input_tracker ~= 0 then
-- List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
-- Mouse_input_tracker:subscribe(true)
--end
Num_friends = 0
build_hint_bar(true, true)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
--List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
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(List:get_selection(), Num_friends)
end
List:draw_items(Data, current_index, LOBBY_LIST_WIDTH, LOBBY_LIST_MAX_ITEMS, LOBBY_LIST_SCALE, LOBBY_LIST_FORCE_SCALE)
build_hint_bar(true)
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= 0 then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if game_get_platform() == "PC" then -- Only search once on PC
break
end
delay(2.0)
end
-- Clear thread
Invite_show_thread = -1
end
---------------------------------------------
-- Populate the invite list
-- @param name Name of the friend
--
function game_lobby_invite_populate(name)
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) }
end
---------------------------------------
-- Show the selected friend's gamercard
--
function game_lobby_view_gamercard()
game_show_coop_gamercard(List:get_selection() - 1)
end
-------------------------------
-- Invite the selected friend
--
function game_lobby_invite_friend()
local friend_index = List:get_id()
local insert_values = { [0] = Data[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
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 sfx_faded_out() then
return
end
local current_id = List:get_id()
local current_index = List:get_selection()
--Do something different on our toggle options...
if Data[current_index].type == TYPE_TOGGLE then
-- Move highlight right
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
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 sfx_faded_out() then
return
end
local current_index = 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
function game_lobby_button_y()
if sfx_faded_out() then
return
end
if Party_invite then
game_send_party_invites()
elseif Can_refresh_friend_list then
if Invite_show_thread == -1 then
Invite_show_thread = thread_new("game_lobby_retrieve_invite")
end
end
end
function game_lobby_button_start()
end
function game_lobby_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
end
function game_lobby_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
end
function game_lobby_nav_left(event, acceleration)
local current_index = List:get_selection()
if current_index < 0 then
return
end
-- Move highlight left
List:move_slider(-1)
if Data[current_index].on_change ~= nil then
Data[current_index].on_change()
end
end
function game_lobby_nav_right(event, acceleration)
local current_index = List:get_selection()
if current_index < 0 then
return
end
-- Move highlight right
List:move_slider(1)
if Data[current_index].on_change ~= nil then
Data[current_index].on_change()
end
end
-- Mouse inputs
function game_lobby_mouse_click(event, target_handle, mouse_x, mouse_y)
if sfx_faded_out() then
return
end
local hint_index = Hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
if Show_partner_gamercard then
game_lobby_button_x()
else
game_lobby_button_b()
end
elseif hint_index == 2 then
game_lobby_button_x()
elseif hint_index == 3 then
game_lobby_button_y()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
game_lobby_button_a()
end
local current_index = List:get_selection()
if List:is_left_arrow(target_handle) then
List:move_slider(-1)
if Data[current_index].on_change ~= nil then
Data[current_index].on_change()
end
elseif List:is_right_arrow(target_handle) then
List:move_slider(1)
if Data[current_index].on_change ~= nil then
Data[current_index].on_change()
end
end
if List:is_slider(target_handle) then
List:move_slider(0, mouse_x)
if Data[current_index].on_change ~= nil then
Data[current_index].on_change()
end
end
end
function game_lobby_mouse_move(event, target_handle)
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 = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
List:move_cursor(0, true)
end
end
function game_lobby_mouse_drag(event, target_handle, mouse_x, mouse_y)
if List.scrollbar.tab.handle == target_handle then
local new_start_index = List.scrollbar:drag_scrolltab(mouse_y, List.num_buttons - (List.max_buttons - 1))
List:scroll_list(0, new_start_index)
end
end
function game_lobby_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end
function game_lobby_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
if scroll_lines ~= 0 then
if List:get_scroll_region_handle() == target_handle then
List:scroll_list(scroll_lines * -1)
List:update_mouse_inputs("game_lobby", Mouse_input_tracker)
Hint_bar:add_mouse_inputs("game_lobby", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
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 }
-- Whored Mode buttons
Continue_button = { type = TYPE_BUTTON, label = "CONTROL_CONTINUE", on_select = game_lobby_whored_continue_game }
Map_button = { type = TYPE_TOGGLE, label = "COOP_LOBBY_MAP", on_change = game_lobby_change_option, id = ID_MAP,
options = { "Test", "Test 2" }, current_value = 1 }
Character_button = { type = TYPE_TOGGLE, label = "COOP_LOBBY_CHARACTER", on_change = game_lobby_change_option, id = ID_CHARACTER,
options = { "Test", "Test 2" }, current_value = 1 }