---------------------------------------------------------------------------
-- DLC Store
-- Gets loaded from the main menu
-- Includes store_common for most of its megalist operations.
------------------------------------------------------------------------
local Store_dlc_doc_handle = 0
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 Input_tracker
local Hint_bar
local List
local DLC_store_browsing_ready = 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")
--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(492, 181)
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...
List = Vdo_mega_list:new("list_1", 0, Store_dlc_doc_handle)
List:set_properties(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, 6, .9, STORE_DLC_LIST_SIZE, false, false)
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()
--Set the screen data to the list data
local data = List:return_data()
local current_index = 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
function store_dlc_nav_button_b()
--Set the screen data to the list data
local data = List:return_data()
--get back function from the dataset...
if data.on_back ~= nil then
--Execute back function
data.on_back()
end
end
function store_dlc_nav_button_x()
main_menu_redeem_code()
end
function store_dlc_nav_up()
List:move_cursor(-1)
--Set the screen data to the list data
local data = List:return_data()
local selected_index = 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()
List:move_cursor(1)
--Set the screen data to the list data
local data = List:return_data()
local selected_index = 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 = List:return_selected_data()
local title = data.label
local price = data.price
local image_name = data.image_name
local description = data.description
local is_owned = data.is_owned
--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 is_owned then
price = "DLC_STORE_ITEM_PURCHASED"
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, description, price, category_id, item_id, is_owned)
debug_print("vint", "price: " .. var_to_string(price) .. "\n")
if is_owned then
price = "[image:ui_text_star]"
else
if game_get_platform() == "XBOX360" then
if price == 0 then
--Convert to show free...
price = "FREE"
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 = name,
label = name,
price = price,
description = description,
label_crc = nil,
image_name = "",
label_2 = price,
label_3 = "",
label_4 = "",
current_value = 1,
is_owned = is_owned
}
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" 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
end
function store_dlc_category_select(index)
local id = List:get_id()
store_dlc_make_purchase(id)
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
-------------------------------------------------------------------------------
-- 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)
List:draw_items(list_data, current_index, STORE_DLC_LIST_SIZE)
local data = 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 = List:return_data()
local cat_idx = -1
local selection = 1
if data ~= nil and data.list_type == DLC_ITEM_LIST then
cat_idx = data.category_menu_index
end
if data ~= nil then
selection = List:get_selection()
end
store_dlc_retrieve_data()
if cat_idx == -1 then
store_dlc_list_show(Store_dlc_categories_data, selection)
else
store_dlc_list_show(Store_dlc_categories_data[cat_idx].menu, selection)
end
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,
}