local GAMEPLAY_TYPE_MISSION = 3
local GAMEPLAY_TYPE_STRONGHOLD = 4
local GAMEPLAY_TYPE_ACTIVITY = 5
Cmp_fail_data = {}
Cmp_fail_doc = -1
local COMPLETION_RESTART = 0
local COMPLETION_RESTART_FROM_CHECKPOINT = 1
local COMPLETION_EXIT = 2
local COMPLETION_CONTINUE = 3
local Input_tracker
local Mouse_input_tracker
local Menu_hint_bar
local List
local First_screen_started = false
local Cmp_screen_is_finished = false -- Used to determine state of completion screen...
local Cmp_screen_can_skip = false -- Determines if we can skip the completion screen...
local Checkpoint_retry_disabled = false -- Coop player has disconnected or player isn't yet to ckpt
local Cmp_fail_coop_dialog_handle = 0
Cmp_screen_base_x = 0 -- Base position x
Cmp_screen_base_y = 0 -- Base position Y
local Camera_shake_multiplier = 0
local Coop_hint_data = {
{CTRL_MENU_BUTTON_BACK, "COMPLETION_COOP_DISCONNECT"},
}
--Populate options list depending on gameplay type...
-- This is what we will use to populate the menus
--Mission fail menu...
local Cmp_fail_list_mission_data = {
[1] = {
type = TYPE_BUTTON,
label = "COMPLETION_RESTART_CHECKPOINT",
id = COMPLETION_RESTART_FROM_CHECKPOINT,
},
[2] = {
type = TYPE_BUTTON,
label = "COMPLETION_RESTART_BEGINNING",
id = COMPLETION_RESTART,
},
[3] = {
type = TYPE_BUTTON,
label = "COMPLETION_EXIT_MISSION",
id = COMPLETION_EXIT,
}
}
-- Stronghold fail menu...
local Cmp_fail_list_stronghold_data = {
[1] = {
type = TYPE_BUTTON,
label = "COMPLETION_RESTART_CHECKPOINT",
id = COMPLETION_RESTART_FROM_CHECKPOINT,
},
[2] = {
type = TYPE_BUTTON,
label = "COMPLETION_RETRY_STRONGHOLD",
id = COMPLETION_RESTART,
},
[3] = {
type = TYPE_BUTTON,
label = "COMPLETION_EXIT_STRONGHOLD",
id = COMPLETION_EXIT,
}
}
-- Activity fail menu...
local Cmp_fail_list_activity_data = {
[1] = {
type = TYPE_BUTTON,
label = "COMPLETION_RETRY_ACTIVITY",
id = COMPLETION_RESTART,
},
[2] = {
type = TYPE_BUTTON,
label = "COMPLETION_EXIT_ACTIVITY",
id = COMPLETION_EXIT,
}
}
--Grouped fail menus to be retreived via data later...
local Cmp_fail_list = {
[GAMEPLAY_TYPE_MISSION] = Cmp_fail_list_mission_data,
[GAMEPLAY_TYPE_ACTIVITY] = Cmp_fail_list_activity_data,
[GAMEPLAY_TYPE_STRONGHOLD] = Cmp_fail_list_stronghold_data,
}
function cmp_fail_init()
bg_saints_set_type(BG_TYPE_CENTER,false,1280)
Cmp_fail_doc = vint_document_find("cmp_fail")
-- Init shake and audio callbacks...
cmp_fail_callack_enable(true)
-- Setup screen complete...
local h = vint_object_find("screen_complete_twn")
vint_set_property(h, "end_event", "cmp_fail_anim_complete_cb")
h = vint_object_find("screen_can_skip_twn")
vint_set_property(h, "end_event", "cmp_fail_anim_can_skip_cb")
--Screen group...
h = vint_object_find("screen_grp")
Cmp_screen_base_x, Cmp_screen_base_y = vint_get_property(h, "anchor")
--Populate data...
vint_dataresponder_request("cmp_fail_populate", "cmp_fail_populate", 0)
--Force screen to start...
cmp_common_screen_start(0)
end
function cmp_fail_cleanup()
if Input_tracker ~= nil then
Input_tracker:subscribe(false)
end
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
end
-- This is called when the screen needs to start.
-- Porting over function from cmp_common, because we don't use any of the common elements
-- On the fail screen...
function cmp_common_screen_start()
if First_screen_started == true then
return
end
First_screen_started = true
local gameplay_name_txt_h = vint_object_find("gameplay_name_txt")
local condition_detail_txt_h = vint_object_find("condition_detail_txt")
--Set text for screen...
vint_set_property(gameplay_name_txt_h, "text_tag", Cmp_fail_data.mission_name)
vint_set_property(condition_detail_txt_h, "text_tag", Cmp_fail_data.failure_text)
if Cmp_fail_data.is_coop_screen then
local coop_screen_base_h = vint_object_find("coop_base")
--set waiting text...
local coop_gamer_tag = Completion_get_other_player_name()
local values = {[0] = coop_gamer_tag}
local waiting_string = vint_insert_values_in_string("COMPLETION_COOP_WAITING", values)
local coop_wait_h = vint_object_find("coop_wait", coop_screen_base_h)
vint_set_property(coop_wait_h,"text_tag", waiting_string)
--Show coop info..
vint_set_property(coop_screen_base_h, "visible", true)
vint_set_property(coop_screen_base_h, "alpha", 1)
--Hide list...
local list_h = vint_object_find("options_list")
vint_set_property(list_h, "visible", false)
--Setup hints...
Menu_hint_bar = Vdo_hint_bar:new("coop_hint_bar")
Menu_hint_bar:set_hints(Coop_hint_data)
Menu_hint_bar:enable_text_shadow(true)
--Subscribe to input...
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("map", "cmp_fail_coop_input", 50)
Input_tracker:add_input("all_unassigned", "cmp_fail_coop_input", 50)
-- Add mouse inputs for the PC
if game_get_platform() == "PC" then
Menu_hint_bar:set_highlight(0)
Mouse_input_tracker = Vdo_input_tracker:new()
Menu_hint_bar:add_mouse_inputs("cmp_fail", Mouse_input_tracker)
end
else
-- Draw mega list...
--Get list data from gameplay type...
local list_data = Cmp_fail_list[Cmp_fail_data.gameplay_type]
--Initalize list and draw it...
List = Vdo_pause_mega_list:new("options_list", nil, Cmp_fail_doc)
List:draw_items(list_data, 1)
List:set_highlight_color(COLOR_CMP_FAIL)
--Subscribe to input...
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("nav_up", "cmp_fail_nav_up", 50)
Input_tracker:add_input("nav_down", "cmp_fail_nav_down", 50)
Input_tracker:add_input("select", "cmp_fail_input", 50)
Input_tracker:add_input("all_unassigned", "cmp_fail_input", 50)
-- Add mouse inputs for the PC
if game_get_platform() == "PC" then
Mouse_input_tracker = Vdo_input_tracker:new()
List:add_mouse_inputs("cmp_fail", Mouse_input_tracker)
end
end
--Animate screen in...
local anim_in_h = vint_object_find("fail_in_anim")
lua_play_anim(anim_in_h)
ui_audio_post_event("Mission_Fail")
end
-------------------------------------------------------------
--Populates the script from the dataresponder...
-------------------------------------------------------------
-- @param mission_name This is the mission/activity name... "DEATH AT SMILING JACKS", "INSURANCE FRAUD"
-- @param failure_text Text description the reason the player failed the mission.
-- @param gameplay_type Enum
function cmp_fail_populate(gameplay_type, mission_name, failure_text, restart_ckp_remove_option, exit_remove_option)
-- This should be set to true only if we are in coop mode, and this user is the client
local is_coop_screen = Completion_is_client()
if exit_remove_option == true then
cmp_fail_exit_remove()
end
if restart_ckp_remove_option == true then
cmp_fail_restart_remove()
Checkpoint_retry_disabled = true
end
Cmp_fail_data = {
mission_name = mission_name,
failure_text = failure_text,
gameplay_type = gameplay_type,
is_coop_screen = is_coop_screen
}
-- SR2 Legacy FAIL DATA... (Reference use only)
-- MISSION FAIL...
-- completion_init_mission_failure(mission_number, team, mission_name, failure_text, image_base)
--
-- ACTIVITY FAIL...
-- completion_init_activity_failure(district, activity_name, level, failure_text, activity_type)
--
-- --STRONGHOLD FAIL...
-- completion_init_stronghold_failure(team, stronghold_name, )
end
--Selection input...
function cmp_fail_input(event, acceleration)
if event == "select" then
if Cmp_screen_is_finished == false then
return
end
local current_id = List:get_id()
--send ID off to game as to what to do...
completion_call_callback(current_id)
--pass off the input to the list
List:button_a()
--prevent us from hitting A again
Input_tracker:subscribe(false)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(false)
end
--Fade out screen...
local anim_h = vint_object_find("fail_out_anim")
lua_play_anim(anim_h)
completion_screen_finished()
end
end
-- Nav Up
function cmp_fail_nav_up(event, acceleration)
if Cmp_screen_is_finished == false then
return
end
-- Move highlight up
List:move_cursor(-1)
end
-- Nav Down
function cmp_fail_nav_down(event, acceleration)
if Cmp_screen_is_finished == false then
return
end
-- Move highlight down
List:move_cursor(1)
end
--Input for coop waiting screen...
function cmp_fail_coop_input(event, acceleration)
if event == "map" then
if Cmp_screen_is_finished == false then
if Cmp_screen_can_skip == true then
cmp_fail_anim_force_end()
return
end
return
end
--Do coop escape...
cmp_fail_coop_quit_dialog()
end
end
--Coop quit dialog brings up the quit dialog for the coop player(Client) if they want to quit or not...
function cmp_fail_coop_quit_dialog()
local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" }
Cmp_fail_coop_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "cmp_fail_coop_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false)
end
function cmp_fail_coop_disconnect(result, action)
if result == 0 then
dialog_box_disconnect()
end
Cmp_fail_coop_dialog_handle = 0
end
--Removes the exit option from the menu structures. May only be called before cmp_fail_restart_remove...
function cmp_fail_exit_remove()
Cmp_fail_list_mission_data[3] = nil
Cmp_fail_list_stronghold_data[3] = nil
end
--Removes the restart option from the menu structures...
function cmp_fail_restart_remove()
Cmp_fail_list_mission_data[1] = table_clone(Cmp_fail_list_mission_data[2])
Cmp_fail_list_mission_data[2] = table_clone(Cmp_fail_list_mission_data[3])
Cmp_fail_list_mission_data[3] = nil
Cmp_fail_list_stronghold_data[1] = table_clone(Cmp_fail_list_stronghold_data[2])
Cmp_fail_list_stronghold_data[2] = table_clone(Cmp_fail_list_stronghold_data[3])
Cmp_fail_list_stronghold_data[3] = nil
end
--Callback for audio events for slamming...
function cmp_fail_audio_slam()
end
--Wrapper for c++ camera shake function...
function cmp_fail_camera_shake()
local anim_h = vint_object_find("shake_anim")
local shake_twn_h = vint_object_find("shake_twn")
vint_set_property(shake_twn_h, "per_frame_event", "cmp_fail_camera_shake_anim_cb")
lua_play_anim(anim_h)
Camera_shake_multiplier = Camera_shake_multiplier + 15
end
function cmp_fail_camera_shake_anim_cb()
Camera_shake_multiplier = (Camera_shake_multiplier * .84)
local screen_h = vint_object_find("screen_grp")
local x = Cmp_screen_base_x + (rand_float(-Camera_shake_multiplier,Camera_shake_multiplier))
local y = Cmp_screen_base_y + (rand_float(-Camera_shake_multiplier,Camera_shake_multiplier))
vint_set_property(screen_h, "anchor", x, y)
end
-- Forces main Animation to the end and
function cmp_fail_anim_force_end()
--Stop all audio callbacks and slams
cmp_fail_callack_enable(false)
--Fast Forward Anim...
local fail_in_anim_h = vint_object_find("fail_in_anim", 0, Cmp_fail_doc)
lua_play_anim(fail_in_anim_h, -10, Cmp_fail_doc)
--Repair two callbacks..
local h = vint_object_find("slam_4_twn")
vint_set_property(h, "end_event", "cmp_fail_camera_shake")
h = vint_object_find("slam_audio_4_twn")
vint_set_property(h, "end_event", "cmp_fail_audio_slam")
end
-- Callback from main animation when playback is complete...
function cmp_fail_anim_complete_cb()
Cmp_screen_is_finished = true
end
--Callback from main animation tween determining if the player can skip through the screen...
function cmp_fail_anim_can_skip_cb()
Cmp_screen_can_skip = true
end
-- Easy way to initialize or clear out the callbacks for sound and camera shakes.
function cmp_fail_callack_enable(is_enabled)
local camera_shake_cb = "cmp_fail_camera_shake"
local cmp_fail_audio_slam_cb = "cmp_fail_audio_slam"
if is_enabled == false then
camera_shake_cb = nil
cmp_fail_audio_slam_cb = nil
end
--Init shake callbacks...
local h = vint_object_find("slam_1_twn")
vint_set_property(h, "end_event", camera_shake_cb)
h = vint_object_find("slam_2_twn")
vint_set_property(h, "end_event", camera_shake_cb)
h = vint_object_find("slam_3_twn")
vint_set_property(h, "end_event", camera_shake_cb)
h = vint_object_find("slam_4_twn")
vint_set_property(h, "end_event", camera_shake_cb)
--Init sound callbacks...
local h = vint_object_find("slam_audio_1_twn")
vint_set_property(h, "end_event", cmp_fail_audio_slam_cb)
h = vint_object_find("slam_audio_2_twn")
vint_set_property(h, "end_event", cmp_fail_audio_slam_cb)
h = vint_object_find("slam_audio_3_twn")
vint_set_property(h, "end_event", cmp_fail_audio_slam_cb)
h = vint_object_find("slam_audio_4_twn")
vint_set_property(h, "end_event", cmp_fail_audio_slam_cb)
end
function completion_coop_disconnected()
if Checkpoint_retry_disabled == false then
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:remove_all()
end
cmp_fail_restart_remove()
local list_data = Cmp_fail_list[Cmp_fail_data.gameplay_type]
--Initalize list and draw it...
List:draw_items(list_data, 1, nil, nil, nil, true)
if Mouse_input_tracker ~= nil then
List:add_mouse_inputs("cmp_fail", Mouse_input_tracker)
Mouse_input_tracker:subscribe(true)
end
--Redraw the items...
Checkpoint_retry_disabled = true
end
end
--function Vdo_pause_mega_list:draw_items(data, current_option, width, max_buttons, alignment, refresh)
function cmp_fail_input_ready()
Input_tracker:subscribe(true)
if Mouse_input_tracker ~= nil then
Mouse_input_tracker:subscribe(true)
end
end
function cmp_fail_mouse_click(event, target_handle)
if Menu_hint_bar ~= nil then
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
cmp_fail_coop_input("map")
end
end
if List ~= nil then
local new_index = List:get_button_index(target_handle)
if new_index ~= 0 then
List:set_selection(new_index)
cmp_fail_input("select")
end
end
end
function cmp_fail_mouse_move(event, target_handle)
if Menu_hint_bar ~= nil then
Menu_hint_bar:set_highlight(0)
local hint_index = Menu_hint_bar:get_hint_index(target_handle)
if hint_index ~= 0 then
Menu_hint_bar:set_highlight(hint_index)
end
end
if List ~= nil then
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
end