local Data = {}
local Anims = {}
local Input_tracker
local Mouse_input_tracker
local Hint_bar_input_tracker = nil
local Hint_y_index = -1
local Hint_x_index = -1
local List_width = 700
local MIN_SCROLL_ITEMS = 17
local HINT_BAR_OFFSET = 21
local Tween_done = true
local Started_syslink_search = false
local SYSLINK_UPDATE_DELAY = 3
local Search_thread = -1
local Num_friends = 0
local Party_invite = false
local Party_show = false
local Invite_friends_error = 0
local Network_check_thread = -1
local SEARCHING_OPTION = {
type = TYPE_BUTTON,
label = "MENU_SEARCHING",
id = -1,
disabled = true
}
local NO_GAMES_FOUND_OPTION = {
type = TYPE_BUTTON,
label = "MENU_NO_GAMES_FOUND",
id = -1,
disabled = true
}
local NO_FRIENDS_FOUND_OPTION = {
type = TYPE_BUTTON,
label = "MENU_NO_FRIENDS_FOUND",
id = -1,
disabled = true
}
local Data = {
[1] = SEARCHING_OPTION
}
local function build_hint_bar(searching)
--Setup Button Hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_x_index = -1
if game_get_platform() ~= "PC" and Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
hint_data[#hint_data + 1] = {CTRL_BUTTON_X, "MENU_REFRESH_SYSLINK"}
Hint_x_index = #hint_data
elseif Num_friends > 0 then
hint_data[#hint_data + 1] = {CTRL_BUTTON_X, "PLT_MENU_VIEW_GAMERCARD"}
Hint_x_index = #hint_data
end
Party_invite = false
Party_show = false
if game_get_platform() == "XBOX360" then
if Coop_connect_operation == COOP_ONLINE_JOIN_LIST and game_get_party_member_count() > 1 then
Party_show = true
elseif Coop_connect_operation == COOP_INVITE_LIST and game_get_party_member_count() > 1 then
Party_invite = true
end
end
Hint_y_index = -1
if Party_show == true then
hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_JOIN" }
Hint_y_index = #hint_data
elseif Party_invite == true then
Input_tracker:add_input("exit", "pause_invite_friends_button_y", 50)
hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_INVITE" }
Hint_y_index = #hint_data
elseif searching ~= true and game_get_platform() == "PC" then
hint_data[#hint_data + 1] = {CTRL_BUTTON_Y, "MENU_REFRESH_SYSLINK"}
Hint_y_index = #hint_data
end
Menu_hint_bar:set_width_max(List_width - HINT_BAR_OFFSET)
Menu_hint_bar:set_hints(hint_data)
if Hint_bar_input_tracker ~= nil then
Hint_bar_input_tracker:remove_all()
Menu_hint_bar:add_mouse_inputs("pause_invite_friends", Hint_bar_input_tracker)
Hint_bar_input_tracker:subscribe(true)
--vint_force_mouse_move_event()
end
Menu_hint_bar:set_visible(true)
end
function pause_invite_friends_init()
--Initialize Header
if Coop_connect_operation == COOP_INVITE_LIST then
Header_obj:set_text("COOP_MENU_INVITE", List_width)
elseif Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
Header_obj:set_text("MULTI_FIND_GAMES", List_width)
else
Header_obj:set_text("MULTI_JOIN_FRIEND", List_width)
end
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "pause_invite_friends_button_a", 60)
Input_tracker:add_input("back", "pause_invite_friends_button_b", 60)
Input_tracker:add_input("alt_select", "pause_invite_friends_button_x", 60)
Input_tracker:add_input("exit", "pause_invite_friends_button_y", 60)
Input_tracker:add_input("pause", "pause_invite_friends_button_start", 60)
Input_tracker:add_input("nav_up", "pause_invite_friends_nav_up", 60)
Input_tracker:add_input("nav_down", "pause_invite_friends_nav_down", 60)
Input_tracker:add_input("nav_left", "pause_invite_friends_nav_left", 60)
Input_tracker:add_input("nav_right", "pause_invite_friends_nav_right", 60)
build_hint_bar()
--set up the list in twns
local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle)
local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle)
list_back_in:set_property("start_value", 1000, 120)
header_back_in:set_property("start_value", 1000, 80)
list_back_in:set_property("end_value", 100, 120)
header_back_in:set_property("end_value", 130, 80)
--set up the list out twns
local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle)
local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle)
list_slide_out:set_property("start_value", 100, 120)
header_slide_out:set_property("start_value", 130, 80)
list_slide_out:set_property("end_value", 1000, 120)
header_slide_out:set_property("end_value", 1000, 80)
local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle)
local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle)
list_slide_in:set_property("start_value", -200, 120)
header_slide_in:set_property("start_value", -200, 80)
list_slide_in:set_property("end_value", 100, 120)
header_slide_in:set_property("end_value", 130, 80)
--Store some locals to the pause menu common for screen processing.
menu_common_set_list_style(List, Header_obj, List_width)
menu_common_set_screen_data(List, Header_obj, nil, Screen_back_out_anim, Screen_slide_out_anim)
List:set_visible(false)
Input_tracker:subscribe(false)
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
Mouse_input_tracker:subscribe(false)
Hint_bar_input_tracker = Vdo_input_tracker:new()
Hint_bar_input_tracker:subscribe(false)
end
Network_check_thread = thread_new("pause_invite_check_for_network")
end
function pause_invite_check_for_network()
while true do
if game_is_connected_to_internet() == false then
dialog_box_message("MENU_TITLE_WARNING", "MENU_PC_SIGN_IN_ERROR", false, false, "pause_invite_boot_to_main_menu")
return
end
thread_yield()
end
end
function pause_invite_friends_get_data()
if Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
Search_thread = thread_new("pause_invite_refresh_syslink")
else
Search_thread = thread_new("pause_invite_friends_get_list")
end
end
function pause_invite_friends_cleanup()
end
-- We want to perform this stuff when the screen is popped because the cleanup function can happen AFTER the "gained_focus" call back on the next screen. That messes with animations.
function pause_invite_friends_exited()
thread_kill(Network_check_thread)
Network_check_thread = -1
--cleanup hintbar...
Menu_hint_bar:set_width_max(nil)
if Search_thread ~= -1 then
thread_kill(Search_thread)
Search_thread = -1
end
if Started_syslink_search == true then
game_stop_find_syslink_servers();
end
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
--used by screen
--set up the list in twns
local list_back_in = Vdo_tween_object:new("back_in_twn2", Screen_back_in_anim.handle)
local header_back_in = Vdo_tween_object:new("back_in_twn3", Screen_back_in_anim.handle)
--used by screen
--set up the list out twns
local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle)
local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle)
local list_back_out = Vdo_tween_object:new("back_out_twn3", Screen_back_out_anim.handle)
local header_back_out = Vdo_tween_object:new("back_out_twn2", Screen_back_out_anim.handle)
local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle)
local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle)
list_slide_in:set_property("start_value", -200, 267)
header_slide_in:set_property("start_value", -200, 230)
list_slide_in:set_property("end_value", 100, 267)
header_slide_in:set_property("end_value", 130, 230)
list_back_in:set_property("start_value", 1000, 267)
header_back_in:set_property("start_value", 1000, 230)
list_back_in:set_property("end_value", 100, 267)
header_back_in:set_property("end_value", 130, 230)
list_slide_out:set_property("start_value", 100, 267)
header_slide_out:set_property("start_value", 130, 230)
list_slide_out:set_property("end_value", 1000, 267)
header_slide_out:set_property("end_value", 1000, 230)
list_back_out:set_property("start_value", 100, 267)
header_back_out:set_property("start_value", 130, 230)
list_back_out:set_property("end_value", -300, 267)
header_back_out:set_property("end_value", -300, 230)
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
end
function pause_invite_friends_get_list()
Input_tracker:subscribe(true)
Data = {
[1] = SEARCHING_OPTION
}
List:set_visible(true)
List:draw_items(Data, 1, List_width, MIN_SCROLL_ITEMS)
Num_friends = 0
build_hint_bar(true)
delay(.5) -- Make sure we show that "Searching" message for at least half a second.
while true do
Invite_friends_error = 0
Num_friends = 0
Data = {}
vint_dataresponder_request("coop_list_responder", "pause_invite_friends_populate", 0, Coop_connect_operation)
if Invite_friends_error ~= 0 then
dialog_box_message("MENU_TITLE_WARNING", "MENU_PC_SIGN_IN_ERROR", false, false, "pause_invite_boot_to_main_menu")
Search_thread = -1
return
end
if Num_friends == 0 then
if Coop_connect_operation == COOP_INVITE_LIST then
Data = { [1] = NO_FRIENDS_FOUND_OPTION }
else
Data = { [1] = NO_GAMES_FOUND_OPTION }
end
end
pause_invite_friends_update_list_width(#Data)
local selection = List:get_selection()
selection = min(selection, #Data)
--REMOVED true FROM LIST DRAW CALL TO FIX ASSERT JAM 5/3/11
List:draw_items(Data, selection, List_width, MIN_SCROLL_ITEMS, nil, false)--true)
build_hint_bar()
--do this after we have redrawn the list
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("pause_invite_friends", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if game_get_platform() == "PC" then -- Only search once on PC
Search_thread = -1
break
end
delay(2.0)
end
Search_thread = -1
end
function pause_invite_friends_set_error(error_number)
Invite_friends_error = error_number
end
function pause_invite_boot_to_main_menu()
menu_common_stack_remove()
if In_pause_menu then
menu_common_transition_pop(2)
else
menu_common_transition_pop(3)
end
end
function pause_invite_friends_populate(name, id, invite_tag)
Num_friends = Num_friends + 1
Data[Num_friends] = { type = TYPE_BUTTON, label = name, id = Num_friends, invite_tag = invite_tag }
end
function pause_invite_friends_do_responder()
Num_friends = 0
Data = { }
vint_dataresponder_request("coop_list_responder", "pause_invite_friends_populate", 0, Coop_connect_operation)
if Num_friends == 0 then
if Coop_connect_operation == COOP_INVITE_LIST then
Data = {
[1] = NO_FRIENDS_FOUND_OPTION
}
else
Data = {
[1] = NO_GAMES_FOUND_OPTION
}
end
end
--Get the selection option from when the menu was last loaded
pause_invite_friends_update_list_width(#Data)
local selection = List:get_selection()
selection = min(selection, #Data)
--REMOVED true FROM LIST DRAW CALL TO FIX ASSERT JAM 5/3/11
List:draw_items(Data, selection, List_width, MIN_SCROLL_ITEMS, nil, false)--true)
Hint_y_index = -1
local hint_data
if Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
if game_get_platform() ~= "PC" then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "MENU_REFRESH_SYSLINK"},
}
Hint_x_index = 2
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_Y, "MENU_REFRESH_SYSLINK"},
}
Hint_y_index = 2
end
elseif Num_friends == 0 then
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Hint_x_index = -1
else
hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "PLT_MENU_VIEW_GAMERCARD"},
}
Hint_x_index = 2
end
if Party_show == true then
hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_JOIN" }
Hint_y_index = #hint_data
elseif Party_invite == true then
hint_data[#hint_data + 1] = { CTRL_BUTTON_Y, "MENU_XBOX_PARTY_INVITE" }
Hint_y_index = #hint_data
end
Menu_hint_bar:set_width_max(List_width - HINT_BAR_OFFSET)
Menu_hint_bar:set_hints(hint_data)
--UNLOCK INPUT HERE JAM 5/3/11
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("pause_invite_friends", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if Hint_bar_input_tracker ~= nil then
Hint_bar_input_tracker:remove_all()
Menu_hint_bar:add_mouse_inputs("pause_invite_friends", Hint_bar_input_tracker)
Hint_bar_input_tracker:subscribe(true)
end
end
function pause_invite_refresh_syslink(quick_refresh)
game_start_find_syslink_servers()
Started_syslink_search = true
Data = {
[1] = SEARCHING_OPTION
}
pause_invite_friends_update_list_width(#Data)
List:draw_items(Data, 1, List_width, MIN_SCROLL_ITEMS)
List:set_visible(true)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Menu_hint_bar:set_width_max(List_width - HINT_BAR_OFFSET)
Menu_hint_bar:set_hints(hint_data)
Hint_y_index = -1
Hint_x_index = -1
--REMOVED quick_refresh FROM LIST DRAW CALL TO FIX ASSERT JAM 5/3/11
pause_invite_friends_update_list_width(#Data)
List:draw_items(Data, 1, List_width, MIN_SCROLL_ITEMS, nil, false)--quick_refresh)
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
List:add_mouse_inputs("pause_invite_friends", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if Hint_bar_input_tracker ~= nil then
Hint_bar_input_tracker:remove_all()
Menu_hint_bar:add_mouse_inputs("pause_invite_friends", Hint_bar_input_tracker)
Hint_bar_input_tracker:subscribe(true)
end
delay(SYSLINK_UPDATE_DELAY)
pause_invite_friends_do_responder()
-- Does not live update.
game_stop_find_syslink_servers()
Started_syslink_search = false
Search_thread = -1
end
function pause_invite_friends_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
end
function pause_invite_friends_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
end
function pause_invite_friends_nav_left(event, acceleration)
-- Move highlight left
List:move_slider(-1)
end
function pause_invite_friends_nav_right(event, acceleration)
-- Move highlight right
List:move_slider(1)
end
function pause_invite_friends_button_a(event, acceleration)
if Tween_done == true then
--set the screen data to the list data
Data = List:return_data()
local current_id = List:get_id()
if current_id == -1 then
return
end
if Coop_connect_operation == COOP_INVITE_LIST then
if game_can_send_player_invite(List:get_selection() - 1) == false then
return
end
local insert_values = { [0] = Data[List:get_selection()].invite_tag }
if game_send_pause_menu_player_invite(List:get_selection() - 1) == true then -- offset index by 1
local body = vint_insert_values_in_string("MP_INVITE_SENT_BODY", insert_values)
dialog_box_message("MP_INVITE_SENT_TITLE", body)
else
local body = vint_insert_values_in_string("INVITE_FAILED_BODY", insert_values)
dialog_box_message("INVITE_FAILED_TITLE", body)
end
if Exit_after_closing == true then
menu_common_transition_pop(3)
end
elseif Coop_connect_operation == COOP_ONLINE_JOIN_LIST then
local has_seen_cal_screen = pause_menu_has_seen_display_cal_screen()
if has_seen_cal_screen then
game_main_menu_join_friend_in_progress(List:get_selection() - 1);
pause_invite_friends_lock_input(true)
else
Join_friend_after_display = List:get_selection() - 1
push_screen("pause_options_display_cal")
end
elseif Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
game_join_syslink_game(current_id)
end
end
end
function pause_invite_friends_button_b(event, acceleration)
if Tween_done == true then
--pass off the input to the list
List:button_b()
--set up the list out twns
local list_slide_out = Vdo_tween_object:new("screen_slide_out_twn2", Screen_slide_out_anim.handle)
local header_slide_out = Vdo_tween_object:new("screen_slide_out_twn3", Screen_slide_out_anim.handle)
list_slide_out:set_property("start_value", 100, 120)
header_slide_out:set_property("start_value", 130, 80)
list_slide_out:set_property("end_value", 1000, 120)
header_slide_out:set_property("end_value", 1000, 80)
local list_slide_in = Vdo_tween_object:new("screen_slide_in_twn2", Screen_slide_in_anim.handle)
local header_slide_in = Vdo_tween_object:new("screen_slide_in_twn3", Screen_slide_in_anim.handle)
list_slide_in:set_property("start_value", -200, 267)
header_slide_in:set_property("start_value", -200, 230)
list_slide_in:set_property("end_value", 100, 267)
header_slide_in:set_property("end_value", 130, 230)
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
if Exit_after_closing == true then
menu_common_transition_pop(3)
else
--Remove current menu from the stack
menu_common_stack_remove()
menu_common_transition_pop(1)
end
end
end
function pause_invite_friends_button_x(event, acceleration)
if Tween_done == true and Hint_x_index ~= -1 then
if game_get_platform() ~= "PC" and Coop_connect_operation == COOP_SYSLINK_JOIN_LIST then
if Search_thread == -1 then
Search_thread = thread_new("pause_invite_refresh_syslink", true)
end
return
end
local current_id = List:get_id()
if current_id == -1 then
return
end
game_show_coop_gamercard(List:get_selection() - 1)
end
end
function pause_invite_friends_button_y(event, acceleration)
if Party_invite then
game_send_party_invites()
elseif Party_show then
if game_get_party_member_count() > 1 then
game_show_community_sessions_ui()
else
game_show_party_ui()
end
elseif game_get_platform() == "PC" then
if Search_thread == -1 then
pause_invite_friends_get_data()
end
end
end
function pause_invite_friends_button_start(event, acceleration)
if In_pause_menu == false then
return
end
if Tween_done == true then
menu_common_set_screen_data(List, Header_obj, nil, Screen_back_out_anim, Screen_out_anim)
Input_tracker:subscribe(false)
-- stack is part of common, which is getting popped, so we don't update it.
menu_common_transition_pop(4) -- invite_friends, pause_co_op_menu, pause_menu_top, menu_common
bg_saints_slide_out()
end
end
-- Update the list width (depending on if it will scroll or not)
function pause_invite_friends_update_list_width(list_items)
if list_items > MIN_SCROLL_ITEMS then
List_width = 685
else
List_width = 700
end
end
-- Mouse inputs
function pause_invite_friends_mouse_click(event, target_handle)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
pause_invite_friends_button_b()
elseif hint_index == Hint_y_index then
pause_invite_friends_button_y()
elseif hint_index == Hint_x_index then
pause_invite_friends_button_x()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
pause_invite_friends_button_a()
end
end
function pause_invite_friends_mouse_move(event, blah1, blah2, blah3, blah4, target_handle)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Menu_hint_bar:set_highlight(hint_index)
else
Menu_hint_bar:set_highlight(0)
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 pause_invite_friends_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("pause_invite_friends", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
function pause_invite_friends_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
-- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index
--
function pause_invite_friends_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
if List.scrollbar.tab.handle == target_handle then
local start_index = List:get_visible_indices()
List.scrollbar:release_scrolltab(start_index, List.num_buttons - (List.max_buttons - 1))
List:update_mouse_inputs("pause_invite_friends", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
function pause_invite_friends_lock_input(lock)
-- Nuke all button subscriptions
Input_tracker:subscribe(not lock)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(not lock)
end
end