./store_dlc.lua

  1. ---------------------------------------------------------------------------  
  2. -- DLC Store  
  3. -- Gets loaded from the main menu 
  4. -- Includes store_common for most of its megalist operations. 
  5. ------------------------------------------------------------------------ 
  6. local Store_dlc_doc_handle = 0 
  7.  
  8. local STORE_DLC_LIST_SIZE = 745 
  9.  
  10. --Global/Local VDO objects 
  11. Store_dlc_scrollbox = {}--Scrollbox on this screen... 
  12.  
  13. Dlc_category_names = { 
  14. 	[1] = "DLC_FEATURE", 
  15. 	[2] = "DLC_GAMEPLAY", 
  16. 	[4] = "DLC_MISSION",  
  17. 	[8] = "DLC_PREVIEW", 
  18. } 
  19.  
  20. local Input_tracker 
  21. local Hint_bar 
  22. local List 
  23.  
  24. local DLC_store_browsing_ready = false 
  25.  
  26. local Hint_bar_rotate 
  27. local Store_logo 
  28. local Store_popup 
  29. local Color_grid 
  30. local Color_grid_grp 
  31. local Not_popup_grp 
  32. local Reward_image 
  33.  
  34. local DLC_CATEGORY_LIST = 1 
  35. local DLC_ITEM_LIST = 2 
  36.  
  37. ---------------------------------------------------------------------------  
  38. -- Initialize DLC Store 
  39. --------------------------------------------------------------------------- 
  40. function store_dlc_init() 
  41. 	Store_dlc_doc_handle = vint_document_find("store_dlc") 
  42. 	 
  43. 	--Initialize scrollbox 
  44. 	Store_dlc_scrollbox = Vdo_scrollbox:new("scrollbox", 0, Store_dlc_doc_handle, "store_dlc.lua", "Store_dlc_scrollbox") 
  45. 	Store_dlc_scrollbox:set_size(492, 181) 
  46. 	Store_dlc_scrollbox:set_color(COLOR_STORE_REWARDS_PRIMARY) 
  47. 	 
  48. 	--Start bg saints loop 
  49. 	local bg_saints_loop_h = vint_object_find("bg_saints_loop") 
  50. 	lua_play_anim(bg_saints_loop_h) 
  51. 	 
  52. 	--Start spinner animation 
  53. 	local spinner_anim_h = vint_object_find("spinner_anim", 0, Store_dlc_doc_handle) 
  54. 	lua_play_anim(spinner_anim_h) 
  55.  
  56. 	--Setup Button Hints 
  57.  
  58. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_dlc_doc_handle) 
  59. 	local hint_data = { 
  60. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  61. 		{CTRL_BUTTON_X, "REDEEM_CODE"},	 
  62. 	} 
  63. 	Hint_bar:set_hints(hint_data) 	 
  64. 	Hint_bar:set_visible(true) 
  65.  
  66. 	-- subscribe to common inputs 
  67. 	Input_tracker = Vdo_input_tracker:new() 
  68. 	Input_tracker:add_input("pause", 		"store_dlc_nav_do_nothing", 	50) 
  69. 	Input_tracker:add_input("map", 			"store_dlc_nav_do_nothing", 	50) 
  70. 	Input_tracker:add_input("select", 		"store_dlc_nav_button_a", 		50) 
  71. 	Input_tracker:add_input("back", 			"store_dlc_nav_button_b", 		50)	 
  72. 	Input_tracker:add_input("alt_select", 	"store_dlc_nav_button_x", 		50)	 
  73. 	Input_tracker:add_input("nav_up", 		"store_dlc_nav_up", 				50) 
  74. 	Input_tracker:add_input("nav_down", 	"store_dlc_nav_down", 			50) 
  75. 	Input_tracker:add_input("nav_left", 	"store_dlc_nav_left", 			50) 
  76. 	Input_tracker:add_input("nav_right", 	"store_dlc_nav_right", 			50) 
  77. 	Input_tracker:add_input("right_joy_y", "store_dlc_input_joy",	 		50, true) 
  78. 		 
  79. 	--Setup list for the store... 
  80. 	List = Vdo_mega_list:new("list_1", 0, Store_dlc_doc_handle) 
  81. 	List:set_properties(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, 6, .9, STORE_DLC_LIST_SIZE, false, false) 
  82. 	List:set_visible(false) 
  83. 	 
  84. 	store_dlc_item_show(false) 
  85. 	 
  86. 	--set text on the logo... 
  87. 	store_dlc_set_logo() 
  88. end 
  89.  
  90. function store_dlc_cleanup() 
  91.  
  92. 	--cleanup scrollbar... 
  93. 	--Store_dlc_scrollbox:destroy() 
  94. 	Input_tracker:subscribe(false) 
  95. end 
  96.  
  97. ------------------------------------------------------------------------------- 
  98. -- Navigation 
  99. ------------------------------------------------------------------------------- 
  100. function store_dlc_nav_do_nothing() 
  101. end 
  102.  
  103. function store_dlc_nav_button_a() 
  104. 	--Set the screen data to the list data 
  105. 	local data = List:return_data() 
  106. 	local current_index = List:get_selection() 
  107. 	 
  108. 	--get select function from the dataset... 
  109. 	if data.on_select ~= nil then 
  110. 		--Execute select function 
  111. 		data.on_select(current_index) 
  112. 	end 
  113. end 
  114.  
  115. function store_dlc_nav_button_b() 
  116. 	--Set the screen data to the list data 
  117. 	local data = List:return_data() 
  118. 	 
  119. 	--get back function from the dataset... 
  120. 	if data.on_back ~= nil then 
  121. 		--Execute back function 
  122. 		data.on_back() 
  123. 	end 
  124. end 
  125.  
  126. function store_dlc_nav_button_x() 
  127. 	main_menu_redeem_code() 
  128. end 
  129.  
  130. function store_dlc_nav_up() 
  131. 	List:move_cursor(-1)	 
  132. 	 
  133. 	--Set the screen data to the list data 
  134. 	local data = List:return_data() 
  135. 	local selected_index = List:get_selection() 
  136. 	 
  137. 	--Get on nav function from the dataset... 
  138. 	if data.on_nav ~= nil then 
  139. 		--Execute back function 
  140. 		data.on_nav(selected_index) 
  141. 	end 
  142. end 
  143.  
  144. function store_dlc_nav_down() 
  145. 	List:move_cursor(1) 
  146. 	 
  147. 	--Set the screen data to the list data 
  148. 	local data = List:return_data() 
  149. 	local selected_index = List:get_selection() 
  150. 	 
  151. 	--Get on nav function from the dataset... 
  152. 	if data.on_nav ~= nil then 
  153. 		--Execute on nav function 
  154. 		data.on_nav(selected_index) 
  155. 	end 
  156. end 
  157.  
  158. function store_dlc_nav_left() 
  159. end 
  160.  
  161. function store_dlc_nav_right() 
  162. end 
  163.  
  164. function store_dlc_input_enable() 
  165. 	if DLC_store_browsing_ready then 
  166. 		Input_tracker:subscribe(true) 
  167. 	end 
  168. end 
  169.  
  170. function store_dlc_input_disable() 
  171. 	Input_tracker:subscribe(false) 
  172. end 
  173.  
  174. -------------------------------------------------------------------------------- 
  175. -- Categories functions... 
  176. -------------------------------------------------------------------------------- 
  177. function store_dlc_retrieve_data_do() 
  178. 	-- reset the categories data 
  179. 	Store_dlc_categories_data = { 
  180. 		current_index = 1, 
  181. 		on_show = store_dlc_categories_on_show, 
  182. 		on_select = store_dlc_categories_select, 
  183. 		on_back = store_dlc_exit, 
  184. 		list_type = DLC_CATEGORY_LIST, 
  185. 	} 
  186.  
  187. 	store_dlc_categories_add("DLC_STORE_CAT_ALL", "AWESOME_IMAGE", -1)	-- No category id 
  188. 	vint_dataresponder_request("dlc_store_populate", "store_dlc_category_item_add", 0)		 
  189. 	Input_tracker:subscribe(true) 
  190. end 
  191.  
  192. function store_dlc_retrieve_data() 
  193. 	Input_tracker:subscribe(false) 
  194. 	thread_new("store_dlc_retrieve_data_do") 
  195. end 
  196. ------------------------------------------------------------------------------- 
  197. -- Populate function for the main category menu... 
  198. -- 
  199. -- list_data: 		this table contains the data to populate the megalist 
  200. -- current_index: 	the current index in the menu that's selected 
  201. -- 
  202. function store_dlc_categories_add(title, desc, cat_id) 
  203. 	local name = title 
  204. 	local image_name = desc 
  205. 	local menu_idx = #Store_dlc_categories_data + 1 
  206.  
  207. 	local new_item = { 
  208. 		type = TYPE_BUTTON, 
  209. 		id = cat_id, 
  210. 		image = image_name, 
  211. 	} 
  212. 	 
  213. 	if game_get_platform() == "PS3" and title ~= "DLC_STORE_CAT_ALL" then 
  214. 		new_item.label = vint_insert_values_in_string("{0:text_tag_crc}", { [0] = name }) 
  215. 	else 
  216. 		new_item.label = name 
  217. 	end 
  218.  
  219. 	Store_dlc_categories_data[menu_idx] = new_item 
  220. 	Store_dlc_categories_data[menu_idx].menu = table_clone(Store_dlc_category_base_data) 
  221. 	Store_dlc_categories_data[menu_idx].menu.category_menu_index = menu_idx 
  222. 	 
  223. 	return menu_idx 
  224. end 
  225.  
  226. function store_dlc_categories_on_show() 
  227. 	--Hide item on right side... 
  228. 	store_dlc_item_show(false) 
  229. end 
  230.  
  231. function store_dlc_categories_select(current_idx)	 
  232. 	store_dlc_list_show(Store_dlc_categories_data[current_idx].menu, 1)	 
  233.  
  234. 	--call nav function to update category highlight... 
  235. 	Store_dlc_categories_data[current_idx].menu.on_nav() 
  236. end 
  237.  
  238. ------------------------------------------------------------------------------- 
  239. -- Category menu functions 
  240. ------------------------------------------------------------------------------- 
  241.  
  242. function store_dlc_category_on_show() 
  243. 	--Show item on right side... 
  244. 	store_dlc_item_show(true) 
  245. end 
  246.  
  247. ------------------------------------------------------------------------------- 
  248. -- Callback function when user presses back on category screen. 
  249. --  
  250. function store_dlc_category_on_back() 
  251. 	store_dlc_list_show(Store_dlc_categories_data, 1)	 
  252. end 
  253.  
  254. function store_dlc_image_downloaded(img_id) 
  255. 	--Update image... 
  256. 	local store_item_h = vint_object_find("store_item", 0, Store_dlc_doc_handle)	 
  257. 	local image_h = vint_object_find("store_item_image", store_item_h, Store_dlc_doc_handle) 
  258. 	 
  259. 	vint_set_property(image_h, "image", img_id) 
  260. 	store_dlc_show_spinner(false) 
  261. end 
  262.  
  263. function store_dlc_category_on_nav(current_idx) 
  264. 	--Get data from our currently selected item... 
  265. 	local data = List:return_selected_data() 
  266. 	local title = data.label 
  267. 	local price = data.price 
  268. 	local image_name = data.image_name 
  269. 	local description = data.description 
  270. 	local is_owned = data.is_owned 
  271. 			 
  272. 	--Update Title 
  273. 	local store_item_h = vint_object_find("store_item", 0, Store_dlc_doc_handle)	 
  274. 	local title_h = vint_object_find("title", store_item_h, Store_dlc_doc_handle)	 
  275. 	vint_set_property(title_h, "text_tag", title) 
  276. 	 
  277. 	--Update Price 
  278. 	local price_h = vint_object_find("price", store_item_h, Store_dlc_doc_handle) 
  279. 	 
  280. 	if is_owned then 
  281. 		price = "DLC_STORE_ITEM_PURCHASED" 
  282. 	end	 
  283. 	 
  284. 	vint_set_property(price_h, "text_tag", price) 
  285.  
  286. 	--Update image... 
  287. 	store_dlc_show_spinner(true) 
  288. 	thread_new("store_dlc_queue_icon_delayed", data.id) 
  289. 	 
  290. 	--Update description 
  291. 	Store_dlc_scrollbox:set_text(data.description) 
  292. 	Store_dlc_scrollbox:reset() 
  293. 	 
  294. 		--Format our screen... 
  295. 	local data = { 
  296. 		{h = title_h, 					type = VINT_OBJECT_TEXT, space = 0}, 
  297. 		{h = price_h,					type = VINT_OBJECT_TEXT, space = 5}, 
  298. 		{h = Store_dlc_scrollbox.handle, 	type = VINT_OBJECT_INVALID, space = 0}, 
  299. 	} 
  300. 	vint_align_elements(data, true) 
  301. end 
  302.  
  303. ------------------------------------------------------------------------------- 
  304. -- Delay queuing up the icon by a single frame to prevent missing image. 
  305. -- 
  306. function store_dlc_queue_icon_delayed(id) 
  307. 	thread_yield() 
  308. 	store_dlc_queue_icon(id, "store_dlc_image_downloaded") 
  309. end 
  310.  
  311. ------------------------------------------------------------------------------- 
  312. -- Populate function for the sub category menu... 
  313. -- 
  314. -- list_data: 		this table contains the data to populate the megalist 
  315. -- current_index: 	the current index in the menu that's selected 
  316. -- 
  317. function store_dlc_category_item_add(name, description, price, category_id, item_id, is_owned) 
  318. 	debug_print("vint", "price: " .. var_to_string(price) .. "\n")  
  319. 	if is_owned then 
  320. 		price = "[image:ui_text_star]" 
  321. 	else 
  322. 		if game_get_platform() == "XBOX360" then 
  323. 			if price == 0 then 
  324. 				--Convert to show free... 
  325. 				price = "FREE" 
  326. 			else 
  327. 				--Convert to show microsoft points. 
  328. 				local values = {[0] = price} 
  329. 				price = vint_insert_values_in_string("{0}[image:ui_text_mpoints]", values) 
  330. 			end 
  331. 		end 
  332. 	end 
  333.  
  334. 	local new_item = { 
  335. 		type = TYPE_ROW, 
  336. 		id = item_id, 
  337. 		label_1 = name, 
  338. 		label = name, 
  339. 		price = price, 
  340. 		description = description, 
  341. 		label_crc = nil, 
  342. 		image_name = "", 
  343. 		label_2 = price, 
  344. 		label_3 = "",  
  345. 		label_4 = "", 
  346. 		current_value = 1, 
  347. 		is_owned = is_owned 
  348. 	}		 
  349. 	 
  350. 	local Category_adding_to = nil 
  351. 	for i = 1, #Store_dlc_categories_data do  
  352. 		if Store_dlc_categories_data[i].id == category_id then 
  353. 			Category_adding_to = Store_dlc_categories_data[i] 
  354. 		end 
  355. 	end 
  356. 	 
  357. 	if Category_adding_to == nil then 
  358. 		local idx = -1 
  359. 		if game_get_platform() == "XBOX360" then 
  360. 			local name = Dlc_category_names[category_id] 
  361. 			if Dlc_category_names[category_id] ~= nil then 
  362. 				 idx = store_dlc_categories_add(Dlc_category_names[category_id], "AWESOME_IMAGE", category_id) 
  363. 			end 
  364. 		else 
  365. 			idx = store_dlc_categories_add(category_id, "AWESOME_IMAGE", category_id) 
  366. 		end 
  367. 		 
  368. 		if idx ~= -1 then 
  369. 			Category_adding_to = Store_dlc_categories_data[idx] 
  370. 		end 
  371. 	end 
  372. 	 
  373. 	-- Add it to its own category 
  374. 	if Category_adding_to ~= nil then 
  375. 		local menu_idx = #Category_adding_to.menu + 1 
  376. 		Category_adding_to.menu[menu_idx] = new_item 
  377. 	end 
  378. 	 
  379. 	-- Add it to all 
  380. 	local all_idx = #Store_dlc_categories_data[1].menu + 1 
  381. 	Store_dlc_categories_data[1].menu[all_idx] = new_item 
  382. end 
  383.  
  384. function store_dlc_category_select(index) 
  385. 	local id = List:get_id() 
  386. 	 
  387. 	store_dlc_make_purchase(id) 
  388. end 
  389.  
  390. --Input 
  391.  
  392. function store_dlc_input_joy(event, accelleration) 
  393. 	--do scrolling in the box... 
  394. 	Store_dlc_scrollbox:nav_smooth(accelleration) 
  395. end 
  396.  
  397.  
  398. ------------------------------------------------------------------------------- 
  399. -- Misc store functionality 
  400. ------------------------------------------------------------------------------- 
  401.  
  402. ------------------------------------------------------------------------------- 
  403. -- Shows/Hides the store item on the right side... 
  404. -- 
  405. function store_dlc_item_show(show_item) 
  406. 	local store_item_h = vint_object_find("store_item") 
  407. 	vint_set_property(store_item_h, "visible", show_item) 
  408. end 
  409.  
  410.  
  411. ------------------------------------------------------------------------------- 
  412. -- List and populate functions 
  413. ------------------------------------------------------------------------------- 
  414.  
  415. ------------------------------------------------------------------------------- 
  416. -- Populate the megalist menu 
  417. -- list_data: 		this table contains the data to populate the megalist 
  418. -- current_index: 	the current index in the menu that's selected 
  419. -- 
  420. function store_dlc_list_show(list_data, current_index) 
  421. 	List:draw_items(list_data, current_index, STORE_DLC_LIST_SIZE) 
  422. 	local data = List:return_data() 
  423. 	 
  424. 	--Callback for showing specific list... 
  425. 	if data.on_show ~= nil then 
  426. 		data.on_show() 
  427. 	end 
  428. end 
  429.  
  430. function store_dlc_exit(event) 
  431. 	-- exit the interface 
  432. 	store_dlc_input_disable() 
  433. 	store_dlc_exit_screen() 
  434. end 
  435.  
  436. function store_dlc_refresh() 
  437. 	DLC_store_browsing_ready = true 
  438.  
  439. 	local data = List:return_data() 
  440. 	local cat_idx = -1 
  441. 	local selection = 1 
  442. 	 
  443. 	if data ~= nil and data.list_type == DLC_ITEM_LIST then 
  444. 		cat_idx = data.category_menu_index 
  445. 	end 
  446. 	 
  447. 	if data ~= nil then 
  448. 		selection = List:get_selection() 
  449. 	end 
  450. 			 
  451. 	store_dlc_retrieve_data() 
  452. 	 
  453. 	if cat_idx == -1 then 
  454. 		store_dlc_list_show(Store_dlc_categories_data, selection) 
  455. 	else 
  456. 		store_dlc_list_show(Store_dlc_categories_data[cat_idx].menu, selection) 
  457. 	end 
  458. 	 
  459. 	List:set_visible(true)		 
  460. 	 
  461. 	store_dlc_input_enable() 
  462. end 
  463.  
  464. ------------------------------------------------------------------------------- 
  465. -- Arrange text on logo 
  466. -- 
  467. function store_dlc_set_logo() 
  468. 	-- Set playstation store logo 
  469. 	local ps3_store_logo_grp_h = vint_object_find("ps3_store_logo_grp") 
  470. 	 
  471. 	-- Set platform... 
  472. 	local platform = game_get_platform() 
  473. 	if platform == "PS3" then 
  474. 		vint_set_property(ps3_store_logo_grp_h, "visible", true) 
  475. 		local ps3_store_logo_bmp_h = vint_object_find("ps3_store_logo_bmp") 
  476. 		if vint_is_std_res() then 
  477. 			vint_set_property(ps3_store_logo_bmp_h, "image", "ui_dlc_store_ps3_store_sd") 
  478. 			vint_set_property(ps3_store_logo_bmp_h, "scale", 1, 1)	--reset scale... 
  479. 			local x, y = vint_get_property(ps3_store_logo_bmp_h, "anchor") 
  480. 			vint_set_property(ps3_store_logo_bmp_h, "anchor", x, y + 15) 
  481. 		else 
  482. 			vint_set_property(ps3_store_logo_bmp_h, "image", "ui_dlc_store_ps3_store_hd") 
  483. 		end 
  484. 	else 
  485. 		vint_set_property(ps3_store_logo_grp_h, "visible", false) 
  486. 	end 
  487. end 
  488.  
  489. ------------------------------------------------------------------------------- 
  490. -- Shows the spinner if visible when hidden we show the image 
  491. -- 
  492. function store_dlc_show_spinner(is_visible) 
  493. 	 
  494. 	local spinner_grp_h 			= vint_object_find("spinner_grp", 0, Store_dlc_doc_handle) 
  495. 	local spinner_anim_h 		= vint_object_find("spinner_anim", 0, Store_dlc_doc_handle) 
  496. 	local store_item_image_h 	= vint_object_find("store_item_image", 0, Store_dlc_doc_handle) 
  497. 	 
  498. 	if is_visible then 
  499. 		vint_set_property(spinner_grp_h, "visible", true) 
  500. 		vint_set_property(spinner_anim_h, "is_paused", false) 
  501. 		vint_set_property(store_item_image_h, "visible", false) 
  502. 	else 
  503. 		vint_set_property(spinner_grp_h, "visible", false) 
  504. 		vint_set_property(spinner_anim_h, "is_paused", true) 
  505. 		vint_set_property(store_item_image_h, "visible", true) 
  506. 	end 
  507. end 
  508.  
  509. ------------------------------------------------------------------------------- 
  510. -- Final exit for the dlc store...  
  511. function store_dlc_exit_screen() 
  512. 	pop_screen() 
  513. end 
  514.  
  515. --Data used in the DLC Store for categories 
  516. Store_dlc_categories_data = { } 
  517.  
  518. -- Base Data used in the DLC Store 
  519. Store_dlc_category_base_data = { 
  520. 	current_index = 1, 
  521. 	row_alignment = {ALIGN_LEFT, ALIGN_RIGHT}, 
  522. 	row_column_count = 2, 
  523. 	on_show = store_dlc_category_on_show, 
  524. 	on_select = store_dlc_category_select, 
  525. 	on_nav = store_dlc_category_on_nav, 
  526. 	on_back = store_dlc_category_on_back, 
  527. 	list_type = DLC_ITEM_LIST, 
  528. 	category_menu_index = 0, 
  529. }