---------------------------------------------------------------------------
-- DLC Store
-- Gets loaded from the main menu
-- Includes store_common for most of its megalist operations.
------------------------------------------------------------------------
local Store_dlc_doc_handle = 0
local Screen_width = 840
local STORE_DLC_LIST_SIZE = 745
--Global/Local VDO objects
Store_dlc_scrollbox = {}--Scrollbox on this screen...
Dlc_category_names = {
[1] = "DLC_FEATURE",
[2] = "DLC_GAMEPLAY",
[4] = "DLC_MISSION",
[8] = "DLC_PREVIEW",
}
local Header_obj = -1
local Input_tracker
local Hint_bar
Store_dlc_list = -1
local DLC_store_browsing_ready = false
local DLC_season_pass_installed = false
local DLC_season_pass_category_index = -1
local DLC_season_pass_category_added = false
local Hint_bar_rotate
local Store_logo
local Store_popup
local Color_grid
local Color_grid_grp
local Not_popup_grp
local Reward_image
local DLC_CATEGORY_LIST = 1
local DLC_ITEM_LIST = 2
---------------------------------------------------------------------------
-- Initialize DLC Store
---------------------------------------------------------------------------
function store_dlc_init()
Store_dlc_doc_handle = vint_document_find("store_dlc")
ui_audio_post_event("UI_Hub_Menu_Forward")
if vint_is_std_res() then
Screen_width = 750
else
Screen_width = 840
end
--set header
Header_obj = Vdo_pause_header:new("header",0,Store_dlc_doc_handle)
Header_obj:set_text("MAINMENU_DOWNLOADS", Screen_width)
--Initialize scrollbox
Store_dlc_scrollbox = Vdo_scrollbox:new("scrollbox", 0, Store_dlc_doc_handle, "store_dlc.lua", "Store_dlc_scrollbox")
--Store_dlc_scrollbox:set_size(580, 181)
Store_dlc_scrollbox:set_size(Screen_width - 260, 173)
Store_dlc_scrollbox:set_color(COLOR_STORE_REWARDS_PRIMARY)
--Start bg saints loop
local bg_saints_loop_h = vint_object_find("bg_saints_loop")
lua_play_anim(bg_saints_loop_h)
--Start spinner animation
local spinner_anim_h = vint_object_find("spinner_anim", 0, Store_dlc_doc_handle)
lua_play_anim(spinner_anim_h)
--Setup Button Hints
Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_dlc_doc_handle)
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "REDEEM_CODE"},
}
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
-- subscribe to common inputs
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("pause", "store_dlc_nav_do_nothing", 50)
Input_tracker:add_input("map", "store_dlc_nav_do_nothing", 50)
Input_tracker:add_input("select", "store_dlc_nav_button_a", 50)
Input_tracker:add_input("back", "store_dlc_nav_button_b", 50)
Input_tracker:add_input("alt_select", "store_dlc_nav_button_x", 50)
Input_tracker:add_input("nav_up", "store_dlc_nav_up", 50)
Input_tracker:add_input("nav_down", "store_dlc_nav_down", 50)
Input_tracker:add_input("nav_left", "store_dlc_nav_left", 50)
Input_tracker:add_input("nav_right", "store_dlc_nav_right", 50)
Input_tracker:add_input("right_joy_y", "store_dlc_input_joy", 50, true)
--Setup list for the store...
Store_dlc_list = Vdo_mega_list:new("list_1", 0, Store_dlc_doc_handle, "store_dlc.lua", "Store_dlc_list")
Store_dlc_list:set_properties(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, 5, .8, Screen_width, false, false)
Store_dlc_list:set_visible(false)
store_dlc_item_show(false)
--set text on the logo...
store_dlc_set_logo()
end
function store_dlc_cleanup()
--cleanup scrollbar...
--Store_dlc_scrollbox:destroy()
Input_tracker:subscribe(false)
end
-------------------------------------------------------------------------------
-- Navigation
-------------------------------------------------------------------------------
function store_dlc_nav_do_nothing()
end
function store_dlc_nav_button_a()
if Store_dlc_list:list_is_playing() == false then
--Set the screen data to the list data
local data = Store_dlc_list:return_data()
local current_index = Store_dlc_list:get_selection()
--get select function from the dataset...
if data.on_select ~= nil then
--Execute select function
data.on_select(current_index)
end
end
end
function store_dlc_nav_button_b()
if Store_dlc_list:list_is_playing() == false then
--Set the screen data to the list data
local data = Store_dlc_list:return_data()
--get back function from the dataset...
if data.on_back ~= nil then
--Execute back function
data.on_back()
end
end
end
function store_dlc_nav_button_x()
main_menu_redeem_code()
end
function store_dlc_nav_up()
Store_dlc_list:move_cursor(-1)
--Set the screen data to the list data
local data = Store_dlc_list:return_data()
local selected_index = Store_dlc_list:get_selection()
--Get on nav function from the dataset...
if data.on_nav ~= nil then
--Execute back function
data.on_nav(selected_index)
end
end
function store_dlc_nav_down()
Store_dlc_list:move_cursor(1)
--Set the screen data to the list data
local data = Store_dlc_list:return_data()
local selected_index = Store_dlc_list:get_selection()
--Get on nav function from the dataset...
if data.on_nav ~= nil then
--Execute on nav function
data.on_nav(selected_index)
end
end
function store_dlc_nav_left()
end
function store_dlc_nav_right()
end
function store_dlc_input_enable()
if DLC_store_browsing_ready then
Input_tracker:subscribe(true)
end
end
function store_dlc_input_disable()
Input_tracker:subscribe(false)
end
--------------------------------------------------------------------------------
-- Categories functions...
--------------------------------------------------------------------------------
function store_dlc_retrieve_data_do()
-- reset the categories data
Store_dlc_categories_data = {
current_index = 1,
on_show = store_dlc_categories_on_show,
on_select = store_dlc_categories_select,
on_back = store_dlc_exit,
list_type = DLC_CATEGORY_LIST,
}
store_dlc_categories_add("DLC_STORE_CAT_ALL", "AWESOME_IMAGE", -1) -- No category id
vint_dataresponder_request("dlc_store_populate", "store_dlc_category_item_add", 0)
Input_tracker:subscribe(true)
end
function store_dlc_retrieve_data()
Input_tracker:subscribe(false)
thread_new("store_dlc_retrieve_data_do")
end
-------------------------------------------------------------------------------
-- Populate function for the main category 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_dlc_categories_add(title, desc, cat_id)
local name = title
local image_name = desc
local menu_idx = #Store_dlc_categories_data + 1
local new_item = {
type = TYPE_BUTTON,
id = cat_id,
image = image_name,
}
if game_get_platform() == "PS3" and title ~= "DLC_STORE_CAT_ALL" then
new_item.label = vint_insert_values_in_string("{0:text_tag_crc}", { [0] = name })
else
new_item.label = name
end
Store_dlc_categories_data[menu_idx] = new_item
Store_dlc_categories_data[menu_idx].menu = table_clone(Store_dlc_category_base_data)
Store_dlc_categories_data[menu_idx].menu.category_menu_index = menu_idx
return menu_idx
end
function store_dlc_categories_on_show()
--Hide item on right side...
store_dlc_item_show(false)
end
function store_dlc_categories_select(current_idx)
store_dlc_list_show(Store_dlc_categories_data[current_idx].menu, 1)
--call nav function to update category highlight...
Store_dlc_categories_data[current_idx].menu.on_nav()
end
-------------------------------------------------------------------------------
-- Category menu functions
-------------------------------------------------------------------------------
function store_dlc_category_on_show()
--Show item on right side...
store_dlc_item_show(true)
end
-------------------------------------------------------------------------------
-- Callback function when user presses back on category screen.
--
function store_dlc_category_on_back()
store_dlc_list_show(Store_dlc_categories_data, 1)
end
function store_dlc_image_downloaded(img_id)
--Update image...
local store_item_h = vint_object_find("store_item", 0, Store_dlc_doc_handle)
local image_h = vint_object_find("store_item_image", store_item_h, Store_dlc_doc_handle)
vint_set_property(image_h, "image", img_id)
store_dlc_show_spinner(false)
end
function store_dlc_category_on_nav(current_idx)
--Get data from our currently selected item...
local data = Store_dlc_list:return_selected_data()
local title = data.title
local price = data.price
local image_name = data.image_name
local description = data.description
local is_owned = data.is_owned
-- At the category selection level, items do not correspond to actual offers.
if (data.id == -1) then
return
end
--Update Title
local store_item_h = vint_object_find("store_item", 0, Store_dlc_doc_handle)
local title_h = vint_object_find("title", store_item_h, Store_dlc_doc_handle)
vint_set_property(title_h, "text_tag", title)
--Update Price
local price_h = vint_object_find("price", store_item_h, Store_dlc_doc_handle)
if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then
-- Set the price
if data.is_installed then
-- The price of installed items is always denoted by the star symbol, even if
-- the user would need to purchase the content to install it.
price = "DLC_STORE_ITEM_INSTALLED"
elseif data.is_season_pass_owned then
price = "DLC_STORE_ITEM_SEASON_PASS"
elseif data.is_owned then
price = "DLC_STORE_ITEM_PURCHASED"
end
-- Set the A-button hint
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "REDEEM_CODE"},
}
if data.is_owned or store_dlc_is_offer_free(data.id) then
hint_data[3] = {CTRL_MENU_BUTTON_A, "DLC_STORE_HINT_DOWNLOAD"}
else
hint_data[3] = {CTRL_MENU_BUTTON_A, "DLC_STORE_HINT_PURCHASE"}
end
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
else
if is_owned then
price = "DLC_STORE_ITEM_PURCHASED"
end
end
vint_set_property(price_h, "text_tag", price)
--Update image...
store_dlc_show_spinner(true)
thread_new("store_dlc_queue_icon_delayed", data.id)
--Update description
Store_dlc_scrollbox:set_text(data.description)
Store_dlc_scrollbox:reset()
--Format our screen...
local data = {
{h = title_h, type = VINT_OBJECT_TEXT, space = 0},
{h = price_h, type = VINT_OBJECT_TEXT, space = 5},
{h = Store_dlc_scrollbox.handle, type = VINT_OBJECT_INVALID, space = 0},
}
vint_align_elements(data, true)
end
-------------------------------------------------------------------------------
-- Delay queuing up the icon by a single frame to prevent missing image.
--
function store_dlc_queue_icon_delayed(id)
thread_yield()
store_dlc_queue_icon(id, "store_dlc_image_downloaded")
end
-------------------------------------------------------------------------------
-- Populate function for the sub category 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_dlc_category_item_add(name, trunc_name, description, price, category_id, item_id, is_owned, is_installed, is_season_pass_category, is_season_pass)
debug_print("vint", "price: " .. var_to_string(price) .. "\n")
local is_season_pass_owned = is_season_pass_category and (not is_season_pass)
if is_owned then
price = "[image:ui_text_star]"
else
if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then
if (is_installed or is_season_pass_owned) then
price = "[image:ui_text_star]"
else
--Convert to show microsoft points.
local values = {[0] = price}
price = vint_insert_values_in_string("{0}[image:ui_text_mpoints]", values)
end
end
end
local new_item = {
type = TYPE_ROW,
id = item_id,
label_1 = trunc_name,
label = trunc_name,
title = name,
price = price,
description = description,
label_crc = nil,
image_name = "",
label_2 = price,
label_3 = "",
label_4 = "",
current_value = 1,
is_owned = is_owned,
}
if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then
new_item.is_installed = is_installed
new_item.is_season_pass_category = is_season_pass_category
new_item.is_season_pass = is_season_pass
new_item.is_season_pass_owned = is_season_pass_owned
if (new_item.is_season_pass and is_installed) then
DLC_season_pass_installed = true
end
end
local Category_adding_to = nil
for i = 1, #Store_dlc_categories_data do
if Store_dlc_categories_data[i].id == category_id then
Category_adding_to = Store_dlc_categories_data[i]
end
end
if Category_adding_to == nil then
local idx = -1
if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then
local name = Dlc_category_names[category_id]
if Dlc_category_names[category_id] ~= nil then
idx = store_dlc_categories_add(Dlc_category_names[category_id], "AWESOME_IMAGE", category_id)
end
else
idx = store_dlc_categories_add(category_id, "AWESOME_IMAGE", category_id)
end
if idx ~= -1 then
Category_adding_to = Store_dlc_categories_data[idx]
end
end
-- Add it to its own category
if Category_adding_to ~= nil then
local menu_idx = #Category_adding_to.menu + 1
Category_adding_to.menu[menu_idx] = new_item
end
-- Add it to all
local all_idx = #Store_dlc_categories_data[1].menu + 1
Store_dlc_categories_data[1].menu[all_idx] = new_item
-- Add to the season pass category
if ((game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3")) and is_season_pass_category) then
if (DLC_season_pass_category_added == false) then
DLC_season_pass_category_index = store_dlc_categories_add("DLC_STORE_SEASON_PASS_CATEGORY", "AWESOME_IMAGE", -2)
DLC_season_pass_category_added = true
end
local sp_idx = #Store_dlc_categories_data[DLC_season_pass_category_index].menu + 1
Store_dlc_categories_data[DLC_season_pass_category_index].menu[sp_idx] = new_item
end
end
function store_dlc_category_select_confirm(result, action)
if result == 0 then
local id = Store_dlc_list:get_id()
store_dlc_make_purchase(id)
end
end
function store_dlc_category_select(index)
local id = Store_dlc_list:get_id()
local data = Store_dlc_list:return_selected_data()
if (game_get_platform() == "XBOX360") or (game_get_platform() == "XBOX3") then
-- TODO: check for season-pass requirement.
-- Warn the user if they're about to purchase content that is installed and accessible.
local has_cost = ( (not data.is_owned) and (not store_dlc_is_offer_free(id)) )
if data.is_installed and has_cost then
dialog_box_confirmation("MENU_TITLE_WARNING", "DLC_STORE_PURCHASE_INSTALLED_CONFIRM", "store_dlc_category_select_confirm", nil, nil, 1)
elseif data.is_installed then
-- Warn users if they're about to download content that is already installed and accessible.
dialog_box_confirmation("MENU_TITLE_WARNING", "DLC_STORE_DOWNLOAD_INSTALLED_CONFIRM", "store_dlc_category_select_confirm", nil, nil, 1)
elseif (data.is_season_pass_owned and (not DLC_season_pass_installed)) then
-- Warn users that the season pass content will not function properly until the season pass is installed.
dialog_box_confirmation("MENU_TITLE_WARNING", "DLC_STORE_SEASON_PASS_PREREQ_CONFIRM", "store_dlc_category_select_confirm", nil, nil, 1)
else
store_dlc_make_purchase(id)
end
else
store_dlc_make_purchase(id)
end
end
--Input
function store_dlc_input_joy(event, accelleration)
--do scrolling in the box...
Store_dlc_scrollbox:nav_smooth(accelleration)
end
-------------------------------------------------------------------------------
-- Misc store functionality
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Shows/Hides the store item on the right side...
--
function store_dlc_item_show(show_item)
local store_item_h = vint_object_find("store_item")
vint_set_property(store_item_h, "visible", show_item)
end
-------------------------------------------------------------------------------
-- Store_dlc_list and populate functions
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
-- Populate the megalist 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_dlc_list_show(list_data, current_index)
if game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3") then
local hint_data = {
{CTRL_MENU_BUTTON_B, "MENU_BACK"},
{CTRL_BUTTON_X, "REDEEM_CODE"},
}
Hint_bar:set_hints(hint_data)
Hint_bar:set_visible(true)
end
Store_dlc_list:draw_items(list_data, current_index, Screen_width)
local data = Store_dlc_list:return_data()
--Callback for showing specific list...
if data.on_show ~= nil then
data.on_show()
end
end
function store_dlc_exit(event)
-- exit the interface
store_dlc_input_disable()
store_dlc_exit_screen()
end
function store_dlc_refresh()
DLC_store_browsing_ready = true
local data = Store_dlc_list:return_data()
local cat_idx = -1
local selection = 1
DLC_season_pass_installed = false
DLC_season_pass_category_index = -1
DLC_season_pass_category_added = false
if data ~= nil and data.list_type == DLC_ITEM_LIST then
cat_idx = data.category_menu_index
end
if data ~= nil then
selection = Store_dlc_list:get_selection()
end
store_dlc_retrieve_data()
if (cat_idx == -1 or Store_dlc_categories_data[cat_idx] == nil) then
store_dlc_list_show(Store_dlc_categories_data, selection)
else
store_dlc_list_show(Store_dlc_categories_data[cat_idx].menu, selection)
if (game_get_platform() == "XBOX360" or (game_get_platform() == "XBOX3")) and data.on_nav ~= nil then
-- Rerun the selection callback to update hints and the items price in the
-- detail portion of the screen.
data.on_nav(selection)
end
end
Store_dlc_list:set_visible(true)
store_dlc_input_enable()
end
-------------------------------------------------------------------------------
-- Arrange text on logo
--
function store_dlc_set_logo()
-- Set playstation store logo
local ps3_store_logo_grp_h = vint_object_find("ps3_store_logo_grp")
-- Set platform...
local platform = game_get_platform()
if platform == "PS3" then
vint_set_property(ps3_store_logo_grp_h, "visible", true)
local ps3_store_logo_bmp_h = vint_object_find("ps3_store_logo_bmp")
if vint_is_std_res() then
vint_set_property(ps3_store_logo_bmp_h, "image", "ui_dlc_store_ps3_store_sd")
vint_set_property(ps3_store_logo_bmp_h, "scale", 1, 1) --reset scale...
local x, y = vint_get_property(ps3_store_logo_bmp_h, "anchor")
vint_set_property(ps3_store_logo_bmp_h, "anchor", x, y + 15)
else
vint_set_property(ps3_store_logo_bmp_h, "image", "ui_dlc_store_ps3_store_hd")
end
else
vint_set_property(ps3_store_logo_grp_h, "visible", false)
end
end
-------------------------------------------------------------------------------
-- Shows the spinner if visible when hidden we show the image
--
function store_dlc_show_spinner(is_visible)
local spinner_grp_h = vint_object_find("spinner_grp", 0, Store_dlc_doc_handle)
local spinner_anim_h = vint_object_find("spinner_anim", 0, Store_dlc_doc_handle)
local store_item_image_h = vint_object_find("store_item_image", 0, Store_dlc_doc_handle)
if is_visible then
vint_set_property(spinner_grp_h, "visible", true)
vint_set_property(spinner_anim_h, "is_paused", false)
vint_set_property(store_item_image_h, "visible", false)
else
vint_set_property(spinner_grp_h, "visible", false)
vint_set_property(spinner_anim_h, "is_paused", true)
vint_set_property(store_item_image_h, "visible", true)
end
end
-------------------------------------------------------------------------------
-- Final exit for the dlc store...
function store_dlc_exit_screen()
pop_screen()
end
--Data used in the DLC Store for categories
Store_dlc_categories_data = { }
-- Base Data used in the DLC Store
Store_dlc_category_base_data = {
current_index = 1,
row_alignment = {ALIGN_LEFT, ALIGN_RIGHT},
row_column_count = 2,
on_show = store_dlc_category_on_show,
on_select = store_dlc_category_select,
on_nav = store_dlc_category_on_nav,
on_back = store_dlc_category_on_back,
list_type = DLC_ITEM_LIST,
category_menu_index = 0,
}