local Input_tracker = 0
Player_choice_tutorial_doc_handle = 0
Player_choice_tutorial_data = {}
Player_choice_tutorial_image = 0
Player_choice_disconnect_dialog_handle = 0
local PLAYER_CHOICE_TEXT_PADDING = 20
function player_choice_tutorial_init()
--store handles to important docs...
Player_choice_tutorial_doc_handle = vint_document_find("player_choice")
--Hide safe frame
local safe_frame_h = vint_object_find("safe_frame")
vint_set_property(safe_frame_h, "visible", false)
--Hide bg saints
bg_saints_show(false)
Input_tracker = Vdo_input_tracker:new()
-- Data responder request
vint_dataresponder_request("player_choice_populate", "player_choice_tutorial_populate", 0)
--Setup screen and insert data...
local title_h = vint_object_find("choice_title")
local body_h = vint_object_find("choice_body")
local title_clone_h = title_h
local body_clone_h = body_h
local format_data = {}
--Loop through data and populate our elements...
for idx, val in pairs(Player_choice_tutorial_data) do
--don't clone the first item...
if idx > 1 then
title_clone_h = vint_object_clone(title_h)
body_clone_h = vint_object_clone(body_h)
end
--set text tages of child elements...
vint_set_property(title_clone_h, "text_tag_crc", val.title)
vint_set_property(body_clone_h, "text_tag_crc", val.body)
format_data[#format_data + 1] = {h = title_clone_h, type = VINT_OBJECT_TEXT, space = 20 * max(idx - 1,1)}
format_data[#format_data + 1] = {h = body_clone_h, type = VINT_OBJECT_TEXT, space = 5}
end
--Format our screen...
local width, height = vint_align_elements(format_data, true)
--Position the SP/COOP options elements below all the choices...(continue / waiting for other player)
local ctrl_info_h = vint_object_find("ctrl_info_grp")
local coop_info_h = vint_object_find("coop_base_grp")
local h_x, h_y = vint_get_property(ctrl_info_h, "anchor")
local x, y = vint_get_property(title_h, "anchor")
local y = height + y + 20
vint_set_property(ctrl_info_h, "anchor", h_x, y)
vint_set_property(coop_info_h, "anchor", h_x, y)
--vertically centera all options... center of screen - half the group size - 50 offset.
local choice_options_grp_h = vint_object_find("choice_options_grp")
local x, y = vint_get_property(choice_options_grp_h, "anchor")
y = Screen_center_y - (height * .5) - 50
vint_set_property(choice_options_grp_h, "anchor", x, y)
--Control button...
local ctrl_btn = Vdo_hint_button:new("ctrl_btn")
ctrl_btn:set_button(CTRL_MENU_BUTTON_A)
--Load peg... callback will continue the screen...
game_peg_load_with_cb("player_choice_tutorial_image_loaded", 1, Player_choice_tutorial_image)
end
function player_choice_tutorial_cleanup()
--Game peg unload...
if Player_choice_tutorial_image ~= 0 then
game_peg_unload(Player_choice_tutorial_image)
end
--make sure we close any open dialog boxes...
if Dialog_pause_disconnect_dialog_handle ~= 0 then
dialog_box_force_close(Dialog_pause_disconnect_dialog_handle)
end
end
-------------------------------------------------------------------------------
-- Populates the player choice tutorial via data responder.
-- @param image image name, this is the same for every line item.
-- @param title title_crc for the title of the choice
-- @param body body_crc for the body of the choice
--
function player_choice_tutorial_populate(image, title, body)
local item_num = #Player_choice_tutorial_data + 1
Player_choice_tutorial_data[item_num] = {
title = title,
body = body,
}
Player_choice_tutorial_image = image
end
-------------------------------------------------------------------------------
-- Player choice image loaded...
-- this is when we set the image and display the screen, and apply for input...
--
function player_choice_tutorial_image_loaded()
local image_h = vint_object_find("image")
vint_set_property(image_h, "image", Player_choice_tutorial_image)
vint_set_property(image_h, "scale", 1.0, 1.0)
local safe_frame_h = vint_object_find("safe_frame")
vint_set_property(safe_frame_h, "visible", true)
bg_saints_show(true)
bg_saints_set_type(BG_TYPE_CENTER, false, 1290, false)
local control_grp_h = vint_object_find("ctrl_info_grp")
local coop_grp_h = vint_object_find("coop_base_grp")
if game_get_is_host() == false then
--Hide controls group...
vint_set_property(control_grp_h, "visible", false)
local hint_data = {
{CTRL_MENU_BUTTON_BACK, "COMPLETION_COOP_DISCONNECT"},
}
--Setup hints...
local coop_hintbar = Vdo_hint_bar:new("coop_hint_bar")
coop_hintbar:set_hints(hint_data)
coop_hintbar:enable_text_shadow(true)
Input_tracker:add_input("map", "pc_tutorial_coop_input", 50)
Input_tracker:add_input("all_unassigned", "pc_tutorial_coop_input", 50)
Input_tracker:subscribe(true)
else
--Hide coop group...
vint_set_property(coop_grp_h, "visible", false)
Input_tracker:add_input("select", "pc_tutorial_input", 50)
--only host gets controls to
Input_tracker:subscribe(true)
end
end
-------------------------------------------------------------------------------
-- Player choice input
--
function pc_tutorial_input(event)
if event == "select" then
--screen is over...
pop_screen()
end
end
-------------------------------------------------------------------------------
-- Player choice input for coop...
--
function pc_tutorial_coop_input(event)
if event == "map" then
--Coop quit dialog brings up the quit dialog for the coop player(Client) if they want to quit or not...
local options = { [0] = "CONTROL_YES", [1] = "CONTROL_NO" }
Player_choice_disconnect_dialog_handle = dialog_box_open("MENU_TITLE_WARNING", "DIALOG_PAUSE_DISCONNECT_PROMPT", options, "pc_tutorial_coop_disconnect", 1, DIALOG_PRIORITY_SYSTEM_CRITICAL, true, nil, false, false)
end
end
-------------------------------------------------------------------------------
-- When the coop disconnect dialog closes... this is called.
--
function pc_tutorial_coop_disconnect(result, action)
--They selected yes...
if result == 0 then
dialog_box_disconnect()
end
Player_choice_disconnect_dialog_handle = 0
end