SCALE_FONT_STORE_GALLERY_LIST = 0.8
local Game_platform
local Store_gallery_building_menu = {}
--local Store_popup
--local Not_popup_grp
local Bg_saints_doc_h = -1
local Store_gallery_load_thread = -1
local Store_gallery_pending_load = -1
local Store_gallery_is_uploading = false
local Gallery_hint_bar_mouse_input_tracker = -1
-- work around so the active list doesn't render when popping out of the download only screen
local Store_gallery_popped = false
local Store_gallery_download_list_pending = false
local Gallery_mouse_input_tracker = nil
function store_gallery_init()
Game_platform = game_get_platform()
if Game_platform == "PC" then
Gallery_mouse_input_tracker = Vdo_input_tracker:new()
Gallery_mouse_input_tracker:subscribe(true)
Gallery_hint_bar_mouse_input_tracker = Vdo_input_tracker:new()
Store_common_hint_bar:add_mouse_inputs("store_gallery", Gallery_hint_bar_mouse_input_tracker)
Gallery_hint_bar_mouse_input_tracker:subscribe(true)
end
-- default to not changing the character
Store_common_gallery_cancel = true
-- Set up some callbacks for the common store script
Store_common_populate_list_cb = store_gallery_populate_list
Store_common_exit_cb = store_gallery_exit
Store_common_allow_input_cb = store_gallery_allow_input
local hint_data = { {CTRL_MENU_BUTTON_B, "MENU_BACK"} }
Store_common_hint_bar:set_hints(hint_data)
-- Setup purchase popup
-- Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle)
-- Store_popup:set_visible(false)
-- Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))
Store_common_popup:set_visible(false)
Bg_saints_doc_h = vint_document_find("bg_saints")
if Bg_saints_doc_h ~= nil and Bg_saints_doc_h ~= -1 then
vint_document_set_depth(Bg_saints_doc_h, -115)
bg_saints_set_type(BG_TYPE_FULLSCREEN)
bg_saints_set_background(not Store_common_gallery_download_only)
bg_saints_slide_in()
end
store_gallery_lock_controls()
end
function store_gallery_cleanup()
bg_saints_slide_out(-1300)
-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have
-- callbacks to the script that is unloading.
store_common_cleanup_current_store()
Store_common_popup:cleanup()
Store_common_popup:set_visible(false)
if Store_gallery_load_thread ~= -1 then
thread_kill(Store_gallery_load_thread)
end
--if something happened while uploading restore screen elements
if Store_gallery_is_uploading == true then
Store_gallery_is_uploading = false
if Game_platform ~= "PC" then
Store_common_rotate_hint:set_visible(true)
end
character_enable_mouse_drag(true)
Store_common_hint_bar:set_visible(true)
Active_list:set_visible(true)
Store_header:set_visible(true)
end
if Gallery_hint_bar_mouse_input_tracker ~= -1 then
Gallery_hint_bar_mouse_input_tracker:subscribe(false)
Gallery_hint_bar_mouse_input_tracker:remove_all(false)
end
if Gallery_mouse_input_tracker ~= nil then
Gallery_mouse_input_tracker:remove_all()
Gallery_mouse_input_tracker:subscribe(false)
Gallery_mouse_input_tracker = nil
end
end
-- Called from C after we have verified correct login to an Agora THQ account
--
function store_gallery_init_complete()
if Store_common_gallery_download_only then
vint_apply_start_values(Store_character_in_anim.handle)
local pcr_anim_in = Vdo_anim_object:new("player_creation_fade_in_anim")
Store_header:set_visible(true)
pcr_anim_in:play(0)
Store_character_in_anim:play(0)
store_gallery_download_retrieve()
else
Menu_data = {
{ label = "STORE_DOWNLOAD_CHARACTER", type = TYPE_BUTTON, on_select = store_gallery_download_retrieve,},
{ label = "STORE_UPLOAD_CHARACTER", type = TYPE_BUTTON, on_select = store_gallery_upload,},
{ label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_gallery_exit},
}
store_gallery_populate_list(Menu_data, 1)
store_gallery_unlock_controls()
end
--store_gallery_unlock_controls()
end
function store_gallery_exit()
if Store_gallery_download_list_pending == true then
return
end
if Store_common_gallery_download_only then
Active_list:set_visible(false)
Store_gallery_popped = true
end
-- no confirmation needed since we're just going back to the previous screen menu
pop_screen()
-- Fix button mashing issues
Store_gallery_popped = true
end
-- Populate the active megalist menu, and hide the previous menu
--
-- list_data: this table contains the data to populate the megalist
-- current_index: the current index in the menu that's selected
--
function store_gallery_populate_list(list_data, current_index)
Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, SCALE_FONT_STORE_GALLERY_LIST)
if Store_gallery_popped == false then
Active_list:set_visible(true)
end
if Game_platform == "PC" then
Mouse_input_tracker:remove_all()
Active_list:set_store("store_gallery")
if Gallery_mouse_input_tracker ~= nil then
Active_list:add_mouse_inputs("store_common", Gallery_mouse_input_tracker)
Gallery_mouse_input_tracker:subscribe(true)
end
end
if Store_common_gallery_download_only then
-- reset title
Store_header:clear_titles()
Store_header:push_title(nil, "LINEUP_DOWNLOAD_CHARACTER")
end
end
-- Handles navigation of any popups
function store_gallery_popup_nav(event, value)
if event == "nav_up" then
Store_common_popup.list:move_cursor(-1)
elseif event == "nav_down" then
Store_common_popup.list:move_cursor(1)
elseif event == "mouse_move" then
vint_set_mouse_cursor("")
-- value contains the target_handle in this case
local new_index = Store_common_popup.list:get_button_index(value)
if new_index ~= 0 then
Store_common_popup.list:set_selection(new_index)
Store_common_popup.list:move_cursor(0, true)
end
else
--do nothing
end
end
-- Begin retrieval of the list of stored characters
--
function store_gallery_download_retrieve()
if Store_gallery_popped == true then
return
end
local success = store_gallery_download_show_list()
if success then
Store_gallery_download_list_pending = true
end
end
-- Player navigated the list of characters to download
--
function store_gallery_download_list_nav(menu_data)
-- display the character
store_gallery_delayed_display_character(menu_data.id)
end
-- Player selected from the list of characters to download
--
function store_gallery_download_list_select(menu_data)
if pcu_is_streaming_done() == false then
return
end
Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2)
Store_common_popup:set_title("MENU_TITLE_WARNING")
Store_common_popup:set_text("MENU_CHARACTER_DOWNLOAD_CONFIRM")
if Gallery_mouse_input_tracker ~= nil then
Gallery_mouse_input_tracker:subscribe(false)
Gallery_hint_bar_mouse_input_tracker:subscribe(false)
Store_common_hint_bar:set_visible(false)
end
Store_common_popup:nav_enable(true, "store_gallery_download_list_select_final", "store_gallery_popup_nav")
--Not_popup_grp:set_alpha(.5)
game_UI_audio_play("UI_HUD_HELP")
end
-- Player selected from the list of characters to download, and then confirmed the action.
--
function store_gallery_download_list_select_final(event)
if Gallery_mouse_input_tracker ~= nil then
Gallery_mouse_input_tracker:subscribe(true)
Gallery_hint_bar_mouse_input_tracker:subscribe(true)
Store_common_hint_bar:set_visible(true)
character_enable_mouse_drag(true)
end
Store_common_popup:nav_enable(false, nil, nil)
--Not_popup_grp:set_alpha(1)
-- The user hit the B button and are cancelling the change
-- This is redundant to selecting "No" in the list
if event == "back" then
game_UI_audio_play("UI_Main_Menu_Nav_Back")
return
end
game_UI_audio_play("UI_Main_Menu_Select")
-- Did we select yes? This assumes yes is the first item
if Store_common_popup:get_selected_data() ~= 1 then
return
end
-- true indicates the character was changed
store_gallery_download_hide_list(true)
store_common_back_menu()
if Store_common_gallery_download_only then
Store_common_gallery_cancel = false
Store_gallery_popped = true
pop_screen()
end
end
-- Player cancelled from the list of characters to download
--
function store_gallery_download_list_cancel(menu_data)
if pcu_is_streaming_done() == false then
return
end
-- false indicates the character was not changed and needs to be restored
store_gallery_download_hide_list(false)
end
-- Called from a dataresponder to add a character available for download to the megalist
--
function store_gallery_add_download_character(display_name)
local item = {
label = display_name,
on_select = store_gallery_download_list_select,
on_nav = store_gallery_download_list_nav,
on_cancel = store_gallery_download_list_cancel,
id = #Store_gallery_building_menu,
}
-- leaving this should go back to the police lineup
if Store_common_gallery_download_only then
item.on_cancel = store_gallery_exit
end
local menu_idx = #Store_gallery_building_menu + 1
Store_gallery_building_menu[menu_idx] = item
end
function store_gallery_popup_close(event)
Store_common_popup:nav_enable(false, nil, nil)
game_UI_audio_play("UI_Main_Menu_Select")
--Not_popup_grp:set_alpha(1)
if Gallery_mouse_input_tracker ~= nil then
Gallery_mouse_input_tracker:subscribe(true)
Gallery_hint_bar_mouse_input_tracker:subscribe(true)
Store_common_hint_bar:set_visible(true)
character_enable_mouse_drag(true)
end
if Store_common_gallery_download_only then
Store_gallery_popped = true
pop_screen()
end
end
-- List of characters to download is retrieved - query data responder and populate menu
--
function store_gallery_download_list_complete()
Store_gallery_download_list_pending = false
Store_gallery_building_menu = {}
vint_dataresponder_request("store_gallery_populate_download_list", "store_gallery_add_download_character", 0)
if #Store_gallery_building_menu == 0 then
Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1)
Store_common_popup:set_title("MENU_TITLE_NOTICE")
Store_common_popup:set_text("MENU_CHARACTER_DOWNLOAD_NONE")
Store_common_popup:nav_enable(true, "store_gallery_popup_close", "store_gallery_popup_nav")
--Not_popup_grp:set_alpha(.5)
Store_common_rotate_hint:set_visible(false)
character_enable_mouse_drag(false)
if Gallery_mouse_input_tracker ~= nil then
Gallery_mouse_input_tracker:subscribe(false)
Gallery_hint_bar_mouse_input_tracker:subscribe(false)
Store_common_hint_bar:set_visible(false)
end
else
if Game_platform ~= "PC" then
Store_common_rotate_hint:set_visible(true)
end
character_enable_mouse_drag(true)
store_common_push_menu(Store_gallery_building_menu)
-- display the first character
store_gallery_delayed_display_character(0)
store_gallery_unlock_controls()
end
end
-- Begin the process of uploading a character
--
function store_gallery_upload()
-- Prep for screen capture
store_set_camera_pos("body")
Store_common_rotate_hint:set_visible(false)
character_enable_mouse_drag(false)
Store_common_hint_bar:set_visible(false)
Active_list:set_visible(false)
Store_header:set_visible(false)
Store_gallery_is_uploading = true
dialog_box_confirmation("MENU_TITLE_WARNING", "MENU_CHARACTER_UPLOAD_CONFIRM", "store_gallery_upload_cb")
store_gallery_lock_controls()
end
-- Results of the confirmation dialog when asking to upload a character
function store_gallery_upload_cb(result, action)
if result == 0 then
store_gallery_upload_character()
else
store_gallery_upload_complete()
end
end
function store_gallery_upload_complete()
Store_gallery_is_uploading = false
if Game_platform ~= "PC" then
Store_common_rotate_hint:set_visible(true)
end
character_enable_mouse_drag(true)
Store_common_hint_bar:set_visible(true)
Active_list:set_visible(true)
Store_header:set_visible(true)
store_gallery_unlock_controls()
end
function store_gallery_lock_controls()
Input_tracker:subscribe(false)
if Game_platform == "PC" then
Gallery_mouse_input_tracker:subscribe(false)
Gallery_hint_bar_mouse_input_tracker:subscribe(false)
--Store_common_hint_bar:set_visible(false)
end
end
function store_gallery_unlock_controls()
Input_tracker:subscribe(true)
if Game_platform == "PC" then
Gallery_mouse_input_tracker:subscribe(true)
Gallery_hint_bar_mouse_input_tracker:subscribe(true)
Store_common_hint_bar:set_visible(true)
character_enable_mouse_drag(true)
end
end
function store_gallery_load_thread()
while true do
delay(0.1)
if pcu_is_streaming_done() then
-- Must wait at least a frame for handshake after streaming is done
delay(0.1)
if Store_gallery_pending_load ~= -1 then
if Store_common_gallery_download_only then
vint_set_property(vint_object_find("player_creation_grp", 0, Store_character_doc_handle), "background", true)
bg_saints_set_background(true)
end
store_gallery_display_character(Store_gallery_pending_load)
Store_gallery_pending_load = -1
end
end
end
end
function store_gallery_delayed_display_character(id)
if Store_gallery_load_thread == -1 then
Store_gallery_load_thread = thread_new("store_gallery_load_thread")
end
Store_gallery_pending_load = id
end
function store_gallery_allow_input(event)
local allow = pcu_is_streaming_done() or (event ~= "back" and event ~= "select" and event ~= "mouse_click")
return allow
end
function store_gallery_mouse_move(event, target_handle)
store_common_mouse_move(event, target_handle)
end
function store_gallery_mouse_click(event, target_handle)
local hint_index = Store_common_hint_bar:get_hint_index(target_handle)
if hint_index == 1 then
-- return if input is not allowed at this time (ie. character is streaming in)
if store_gallery_allow_input(event) == false then
return
end
if Store_common_gallery_download_only then
store_common_back_menu()
Store_header:pop_title()
store_gallery_exit()
elseif Menu_data[1].on_cancel == store_gallery_download_list_cancel then
Store_header:pop_title()
store_common_button_b()
else
Store_header:pop_title()
store_gallery_exit()
end
end
end
function store_gallery_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines)
end
function store_gallery_mouse_drag(event, target_handle, mouse_x, mouse_y)
end
function store_gallery_mouse_drag_release(event, target_handle, mouse_x, mouse_y)
end