-- Global
local FFO_NONE = 2 -- From code
local ID_INVITE = 1
local ID_KICK = 2
local ID_PRIV = 3
local ID_FF = 4
local ID_VIEW_GAMERCARD = 5
local Anims = {}
local Invite_button = { type = TYPE_BUTTON, label = "COOP_MENU_INVITE", id = ID_INVITE }
local Kick_button = { type = TYPE_BUTTON, label = "COOP_MENU_KICK", id = ID_KICK }
local Privacy_button = { type = TYPE_TOGGLE, label = "COOP_MENU_PRIVACY",
options = {"COOP_MENU_OPEN", "COOP_MENU_FRIENDS_ONLY", "COOP_MENU_PRIVATE"},
current_value = game_get_coop_join_type() + 1, id = ID_PRIV }
local FF_button = { type = TYPE_TOGGLE, label = "COOP_MENU_FRIENDLY_FIRE",
options = {"COOP_MENU_FULL_DAMAGE", "COOP_MENU_LIGHT_DAMAGE", "MENU_NONE"},
current_value = game_get_coop_friendly_fire() + 1, id = ID_FF, }
local Show_gamercard_button = { type = TYPE_BUTTON, label = "PLT_MENU_VIEW_PARTNER_GAMERCARD", id = ID_VIEW_GAMERCARD }
local Data = {}
local Input_tracker
local Mouse_input_tracker
local Screen_width = 700
local Tween_done = true
local Co_op_monitor_thread_h = -1
function pause_co_op_build_data()
Data = {}
if In_pause_menu == false then
-- Main Menu coop menu
Data[#Data + 1] = Privacy_button
Data[#Data + 1] = FF_button
elseif coop_is_active() then
-- During Coop Game menu
if game_get_is_host() then
-- The host's version
Data[#Data + 1] = Kick_button
Data[#Data + 1] = Privacy_button
Data[#Data + 1] = FF_button
else
-- The client's version
Data[#Data + 1] = FF_button
Data[#Data].disabled = true -- can't change as client
end
if not game_is_syslink() then
Data[#Data + 1] = Show_gamercard_button
end
else
-- In Game, coop not started
if not game_is_syslink() then
Data[#Data + 1] = Invite_button
if game_is_joinable() == false then
Data[#Data].disabled = true
Data[#Data].toggle_disabled = true
else
Data[#Data].disabled = false
Data[#Data].toggle_disabled = false
end
end
Data[#Data + 1] = Privacy_button
Data[#Data + 1] = FF_button
end
end
function pause_co_op_menu_init()
-- Subscribe to the button presses we need
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("select", "pause_co_op_menu_button_a", 50)
Input_tracker:add_input("pause", "pause_co_op_menu_button_start", 50)
Input_tracker:add_input("back", "pause_co_op_menu_button_b", 50)
Input_tracker:add_input("nav_up", "pause_co_op_menu_nav_up", 50)
Input_tracker:add_input("nav_down", "pause_co_op_menu_nav_down", 50)
Input_tracker:add_input("nav_left", "pause_co_op_menu_nav_left", 50)
Input_tracker:add_input("nav_right", "pause_co_op_menu_nav_right", 50)
Input_tracker:subscribe(false)
--Initialize Header
Header_obj:set_text("MAINMENU_COOP", Screen_width)
--Setup Button Hints
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
}
Menu_hint_bar:set_hints(hint_data)
--Get the selection option from when the menu was last loaded
local last_option_selected = menu_common_stack_get_index()
pause_co_op_build_data()
-- draw it up
List:draw_items(Data, last_option_selected, Screen_width)
--Store some locals to the pause menu common for screen processing.
menu_common_set_list_style(List, Header_obj, Screen_width)
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_slide_out_anim)
-- Add mouse input subscriptions for the PC
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
if In_pause_menu then
Co_op_monitor_thread_h = thread_new("pause_co_op_monitor_co_op_active")
end
end
function pause_co_op_menu_cleanup()
-- Nuke all button subscriptions
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
List:enable_toggle_input(false)
if Co_op_monitor_thread_h ~= -1 then
thread_kill(Co_op_monitor_thread_h)
Co_op_monitor_thread_h = -1
end
end
function pause_co_op_menu_nav_up(event, acceleration)
-- Move highlight up
List:move_cursor(-1)
end
function pause_co_op_menu_nav_down(event, acceleration)
-- Move highlight down
List:move_cursor(1)
end
function pause_co_op_menu_nav_left(event, acceleration)
-- only host can change this guy
if not game_get_is_host() and In_pause_menu == true then
return
end
-- Move highlight left
List:move_slider(-1)
update_option(List:get_id())
end
function pause_co_op_menu_nav_right(event, acceleration)
-- only host can change this guy
if not game_get_is_host() and In_pause_menu == true then
return
end
-- Move highlight right
List:move_slider(1)
update_option(List:get_id())
end
function pause_co_op_menu_button_a(event, acceleration)
if Tween_done == true then
local current_id = List:get_id()
if current_id == ID_VIEW_GAMERCARD then
game_show_coop_partner_gamercard()
return
end
if not game_get_is_host() and In_pause_menu == true then
return
end
--set the screen data to the list data
Data = List:return_data()
local current_id = List:get_id()
menu_common_stack_add(current_id)
if current_id == ID_INVITE then
-- See if we're connected to the network even...
if game_is_connected_to_network() == false then
dialog_box_message("MENU_TITLE_WARNING", "NO_NETWORK_CONNECTION")
return
end
-- See if we're connected to PSN or XBL
if game_is_connected_to_service() == false then
if game_get_platform() == "PC" then
dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN")
elseif game_get_platform() == "XBOX360" then
dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN_XBOX")
else
dialog_box_message("MENU_TITLE_WARNING", "NOT_LOGGED_IN_PS3")
end
return
end
--see if we're on a profile
if game_is_signed_in() == false then
if game_get_platform() == "PC" then
dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN")
elseif game_get_platform() == "XBOX360" then
dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN")
else
dialog_box_message("MENU_TITLE_WARNING", "MULTI_NOT_SIGNED_IN_PS3")
end
return
end
menu_common_transition_push("pause_invite_friends")
return
elseif current_id == ID_KICK then
game_coop_kick_player("pause_co_op_kick_complete")
else
--update_option(current_id)
pause_co_op_menu_nav_right(event, acceleration)
end
end
end
function pause_co_op_kick_complete(kicked)
if kicked then
pause_co_op_build_data()
-- draw it up
local last_option_selected = menu_common_stack_get_index()
List:draw_items(Data, last_option_selected, 700)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
end
function update_option(option_id)
if option_id == ID_PRIV then
game_set_coop_join_type(List:get_data_from_id(ID_PRIV).current_value - 1)
else
local value = List:get_data_from_id(ID_FF).current_value - 1
if value == FFO_NONE and pause_menu_cat_mouse_active() then
dialog_box_confirmation("MENU_TITLE_WARNING", "CAT_MOUSE_FRIENDLY_FIRE_WARNING", "pause_co_op_ff_conf")
else
game_set_coop_friendly_fire(List:get_data_from_id(ID_FF).current_value - 1)
end
end
end
function pause_co_op_ff_conf(result, action)
if result == 0 then
game_set_coop_friendly_fire(List:get_data_from_id(ID_FF).current_value - 1)
else
-- Reset the selection
List:get_data_from_id(ID_FF).current_value = game_get_coop_friendly_fire() + 1
List:move_slider(0)
end
end
function pause_co_op_menu_button_b(event, acceleration)
if Tween_done == true then
--pass off the input to the list
List:button_b()
--Remove current menu from the stack
menu_common_stack_remove()
menu_common_transition_pop(1)
end
end
function pause_co_op_menu_button_start(event, acceleration)
if Tween_done == true then
menu_common_set_screen_data(List, Header_obj, Input_tracker, Screen_back_out_anim, Screen_out_anim)
Input_tracker:subscribe(false)
menu_common_transition_pop(3) -- save_load, pause_menu_top, menu_common
bg_saints_slide_out()
end
end
function pause_co_op_menu_mouse_click(event, target_handle)
-- First check if the target_handle refers to the hint bar
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
pause_co_op_menu_button_b()
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
-- Enter an option if the target_handle is in the Mega_list
List:set_selection(new_index)
local data = List:return_selected_data()
if data.type == TYPE_TOGGLE then
pause_co_op_menu_nav_right()
else
pause_co_op_menu_button_a()
end
end
if List:is_left_arrow(target_handle) then
pause_co_op_menu_nav_left()
end
end
function pause_co_op_menu_mouse_move(event, target_handle)
-- Reset highlights
Menu_hint_bar:set_highlight(0)
-- Check if the target_handle is the hint bar
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Menu_hint_bar:set_highlight(hint_index)
end
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
-- Get the button's index and set it as the selected button
List:set_selection(new_index)
List:move_cursor(0, true)
end
end
function pause_co_op_monitor_co_op_active()
local prev_game_is_joinable = false
local prev_coop_is_active = false
while true do
local cur_game_is_joinable = game_is_joinable()
local cur_coop_is_active = coop_is_active()
if prev_coop_is_active ~= cur_coop_is_active or prev_game_is_joinable ~= cur_game_is_joinable then
pause_co_op_build_data()
-- draw it up
local last_option_selected = menu_common_stack_get_index()
List:draw_items(Data, last_option_selected, 700)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
Menu_hint_bar:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
List:add_mouse_inputs("pause_co_op_menu", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
end
prev_game_is_joinable = cur_game_is_joinable
prev_coop_is_active = cur_coop_is_active
delay(1.0)
end
end