./store_gallery.lua

  1.  
  2.  
  3. SCALE_FONT_STORE_GALLERY_LIST = 0.8 
  4.  
  5. local Game_platform 
  6.  
  7. local Store_gallery_building_menu = {} 
  8. --local Store_popup 
  9. --local Not_popup_grp 
  10. local Bg_saints_doc_h = -1 
  11.  
  12. local Store_gallery_load_thread = -1 
  13. local Store_gallery_pending_load = -1 
  14. local Store_gallery_is_uploading = false 
  15.  
  16. local Gallery_hint_bar_mouse_input_tracker = -1 
  17.  
  18. -- work around so the active list doesn't render when popping out of the download only screen 
  19. local Store_gallery_popped = false 
  20.  
  21. local Store_gallery_download_list_pending = false 
  22.  
  23. local Gallery_mouse_input_tracker = nil 
  24.  
  25. function store_gallery_init() 
  26.  
  27. 	Game_platform = game_get_platform()	 
  28. 	 
  29. 	if Game_platform == "PC" then 
  30. 		Gallery_mouse_input_tracker = Vdo_input_tracker:new() 
  31. 		Gallery_mouse_input_tracker:subscribe(true) 
  32. 		 
  33. 		Gallery_hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  34. 		Store_common_hint_bar:add_mouse_inputs("store_gallery", Gallery_hint_bar_mouse_input_tracker) 
  35. 		Gallery_hint_bar_mouse_input_tracker:subscribe(true) 
  36. 	end 
  37.  
  38. 	bg_saints_show(false) 
  39. 	 
  40. 	-- default to not changing the character 
  41. 	Store_common_gallery_cancel = true 
  42.  
  43. 	-- Set up some callbacks for the common store script 
  44. 	Store_common_populate_list_cb = store_gallery_populate_list 
  45. 	Store_common_exit_cb				= store_gallery_exit 
  46. 	Store_common_allow_input_cb	= store_gallery_allow_input 
  47.  
  48. 	local hint_data = { {CTRL_MENU_BUTTON_B, "MENU_BACK"} } 
  49. 	Store_common_hint_bar:set_hints(hint_data) 
  50. 	 
  51. 	-- Setup purchase popup 
  52. 	-- Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle) 
  53. 	-- Store_popup:set_visible(false) 
  54. 	-- Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5))		 
  55. 	Store_common_popup:set_visible(false) 
  56. 	 
  57. 	Bg_saints_doc_h = vint_document_find("bg_saints") 
  58. 	 
  59. 	if Bg_saints_doc_h ~= nil and Bg_saints_doc_h ~= -1 then 
  60. 		vint_document_set_depth(Bg_saints_doc_h, -115) 
  61. 		bg_saints_set_type(BG_TYPE_PAUSE) 
  62. 		bg_saints_set_background(not Store_common_gallery_download_only) 
  63. 		bg_saints_slide_in() 
  64. 	end 
  65. 	 
  66. 	store_gallery_lock_controls() 
  67. 	 
  68. end 
  69.  
  70. function store_gallery_cleanup() 
  71. 	bg_saints_slide_out(-1300) 
  72.  
  73. 	-- Some things need to be cleaned up right away when a store doc is unloading, particular disabled inputs which have 
  74. 	-- callbacks to the script that is unloading. 
  75. 	store_common_cleanup_current_store() 
  76. 	 
  77. 	Store_common_popup:cleanup() 
  78. 	Store_common_popup:set_visible(false) 
  79. 	 
  80. 	if Store_gallery_load_thread ~= -1 then 
  81. 		thread_kill(Store_gallery_load_thread) 
  82. 	end 
  83. 	 
  84. 	--if something happened while uploading restore screen elements 
  85. 	if Store_gallery_is_uploading == true then 
  86. 		Store_gallery_is_uploading = false 
  87. 		 
  88. 		if Game_platform ~= "PC" then 
  89. 			Store_common_rotate_hint:set_visible(true) 
  90. 		end 
  91. 		character_enable_mouse_drag(true) 
  92. 		Store_common_hint_bar:set_visible(true) 
  93. 		Active_list:set_visible(true) 
  94. 		Store_header:set_visible(true) 
  95. 	end 
  96.  
  97. 	if Gallery_hint_bar_mouse_input_tracker ~= -1 then 
  98. 		Gallery_hint_bar_mouse_input_tracker:subscribe(false) 
  99. 		Gallery_hint_bar_mouse_input_tracker:remove_all(false) 
  100. 	end 
  101. 	 
  102. 	if Gallery_mouse_input_tracker ~= nil then 
  103. 		Gallery_mouse_input_tracker:remove_all() 
  104. 		Gallery_mouse_input_tracker:subscribe(false) 
  105. 		Gallery_mouse_input_tracker = nil 
  106. 	end 
  107. end 
  108.  
  109. -- Called from C after we have verified correct login to an Agora THQ account 
  110. -- 
  111. function store_gallery_init_complete() 
  112.  
  113. 	if Store_common_gallery_download_only then 
  114. 	 
  115. 		vint_apply_start_values(Store_character_in_anim.handle) 
  116. 		local pcr_anim_in = Vdo_anim_object:new("player_creation_fade_in_anim")		 
  117. 		Store_header:set_visible(true) 
  118. 		pcr_anim_in:play(0)	 
  119. 		Store_character_in_anim:play(0) 
  120. 	 
  121. 		store_gallery_download_retrieve() 
  122. 	else 
  123. 		Menu_data = { 
  124. 			{ label = "STORE_DOWNLOAD_CHARACTER", type = TYPE_BUTTON, on_select = store_gallery_download_retrieve,}, 
  125. 			{ label = "STORE_UPLOAD_CHARACTER", type = TYPE_BUTTON, on_select = store_gallery_upload,}, 
  126. 			{ label = "STORE_EXIT", type = TYPE_BUTTON, on_select = store_gallery_exit},		 
  127. 		} 
  128. 		 
  129. 		store_gallery_populate_list(Menu_data, 1) 
  130. 		 
  131. 		store_gallery_unlock_controls() 
  132. 	end	 
  133. 		 
  134. 	--store_gallery_unlock_controls()	 
  135. end 
  136.  
  137. function store_gallery_exit() 
  138. 	 
  139. 	if Store_gallery_download_list_pending == true then 
  140. 		return 
  141. 	end 
  142. 	 
  143. 	if Store_common_gallery_download_only then 
  144. 		Active_list:set_visible(false) 
  145. 		Store_gallery_popped = true 
  146. 	end 
  147. 	 
  148. 	-- no confirmation needed since we're just going back to the previous screen menu	 
  149. 	pop_screen() 
  150. 	 
  151. 	-- Fix button mashing issues 
  152. 	Store_gallery_popped = true 
  153.  
  154. end 
  155.  
  156. -- Populate the active megalist menu, and hide the previous menu 
  157. -- 
  158. -- list_data: 		this table contains the data to populate the megalist 
  159. -- current_index: 	the current index in the menu that's selected 
  160. -- 
  161. function store_gallery_populate_list(list_data, current_index) 
  162. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 10, LIST_FONT_SCALE) 
  163. 	 
  164. 	if Store_gallery_popped == false then		 
  165. 		Active_list:set_visible(true) 
  166. 	end 
  167. 	 
  168. 	if Game_platform == "PC" then 
  169. 		Mouse_input_tracker:remove_all() 
  170. 		Active_list:set_store("store_gallery") 
  171. 		if Gallery_mouse_input_tracker ~= nil then 
  172. 			Active_list:add_mouse_inputs("store_common", Gallery_mouse_input_tracker) 
  173. 			Gallery_mouse_input_tracker:subscribe(true) 
  174. 		end 
  175. 	end 
  176. 	 
  177. 	if Store_common_gallery_download_only then 
  178. 		-- reset title 
  179. 		Store_header:clear_titles() 
  180. 		Store_header:push_title(nil, "LINEUP_DOWNLOAD_CHARACTER") 
  181. 	end 
  182. end 
  183.  
  184. -- Handles navigation of any popups 
  185. function store_gallery_popup_nav(event, value) 
  186. 	if event == "nav_up" then	 
  187. 		Store_common_popup.list:move_cursor(-1)	 
  188. 	elseif event == "nav_down" then 
  189. 		Store_common_popup.list:move_cursor(1) 
  190. 	elseif event == "mouse_move" then 
  191. 		vint_set_mouse_cursor("") 
  192. 		-- value contains the target_handle in this case 
  193. 		local new_index = Store_common_popup.list:get_button_index(value) 
  194. 		if new_index ~= 0 then 
  195. 			Store_common_popup.list:set_selection(new_index) 
  196. 			Store_common_popup.list:move_cursor(0, true) 
  197. 		end 
  198. 	else 
  199. 		--do nothing 
  200. 	end 
  201. end 
  202.  
  203. -- Begin retrieval of the list of stored characters 
  204. -- 
  205. function store_gallery_download_retrieve() 
  206.  
  207. 	if Store_gallery_popped == true then 
  208. 		return 
  209. 	end 
  210.  
  211. 	local success = store_gallery_download_show_list() 
  212. 	 
  213. 	if success then 
  214. 		Store_gallery_download_list_pending = true 
  215. 	end 
  216. end 
  217.  
  218. -- Player navigated the list of characters to download 
  219. -- 
  220. function store_gallery_download_list_nav(menu_data) 
  221. 	-- display the character 
  222. 	store_gallery_delayed_display_character(menu_data.id) 
  223. end 
  224.  
  225. -- Player selected from the list of characters to download 
  226. -- 
  227. function store_gallery_download_list_select(menu_data) 
  228.  
  229. 	if pcu_is_streaming_done() == false then 
  230. 		return 
  231. 	end 
  232.  
  233. 	Store_common_popup:populate_list(Yes_no_choices, 2, STORE_COMMON_LIST_SIZE, 2) 
  234. 	Store_common_popup:set_title("MENU_TITLE_WARNING") 
  235. 	 
  236. 	Store_common_popup:set_text("MENU_CHARACTER_DOWNLOAD_CONFIRM") 
  237. 	 
  238. 	if Gallery_mouse_input_tracker ~= nil then 
  239. 		Gallery_mouse_input_tracker:subscribe(false) 
  240. 		Gallery_hint_bar_mouse_input_tracker:subscribe(false) 
  241. 		Store_common_hint_bar:set_visible(false) 
  242. 	end 
  243. 	 
  244. 	Store_common_popup:nav_enable(true, "store_gallery_download_list_select_final", "store_gallery_popup_nav") 
  245. 	--Not_popup_grp:set_alpha(.5) 
  246.  
  247. 	game_UI_audio_play("UI_HUD_HELP") 
  248.  
  249. end 
  250.  
  251. -- Player selected from the list of characters to download, and then confirmed the action. 
  252. -- 
  253. function store_gallery_download_list_select_final(event) 
  254.  
  255. 	if Gallery_mouse_input_tracker ~= nil then 
  256. 		Gallery_mouse_input_tracker:subscribe(true) 
  257. 		Gallery_hint_bar_mouse_input_tracker:subscribe(true) 
  258. 		Store_common_hint_bar:set_visible(true) 
  259. 		character_enable_mouse_drag(true) 
  260. 	end 
  261. 	 
  262. 	Store_common_popup:nav_enable(false, nil, nil) 
  263. 	 
  264. 	--Not_popup_grp:set_alpha(1)	 
  265. 	 
  266. 	-- The user hit the B button and are cancelling the change 
  267. 	-- This is redundant to selecting "No" in the list 
  268. 	if event == "back" then 
  269. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")	 
  270. 		return 
  271. 	end 
  272. 	 
  273. 	game_UI_audio_play("UI_Main_Menu_Select") 
  274. 	 
  275. 	-- Did we select yes?  This assumes yes is the first item 
  276. 	if Store_common_popup:get_selected_data() ~= 1 then 
  277. 		return 
  278. 	end 
  279.  
  280. 	-- true indicates the character was changed 
  281. 	store_gallery_download_hide_list(true) 
  282. 	store_common_back_menu() 
  283. 	 
  284. 	if Store_common_gallery_download_only then 
  285. 		Store_common_gallery_cancel = false	 
  286. 		Store_gallery_popped = true 
  287. 		pop_screen() 
  288. 	end 
  289. end 
  290.  
  291. -- Player cancelled from the list of characters to download 
  292. -- 
  293. function store_gallery_download_list_cancel(menu_data) 
  294. 	if pcu_is_streaming_done() == false then 
  295. 		return 
  296. 	end 
  297.  
  298. 	-- false indicates the character was not changed and needs to be restored 
  299. 	store_gallery_download_hide_list(false) 
  300. end 
  301.  
  302. -- Called from a dataresponder to add a character available for download to the megalist 
  303. -- 
  304. function store_gallery_add_download_character(display_name) 
  305.  
  306. 	local item = {  
  307. 		label = display_name, 
  308. 		on_select = store_gallery_download_list_select, 
  309. 		on_nav = store_gallery_download_list_nav, 
  310. 		on_cancel = store_gallery_download_list_cancel, 
  311. 		id = #Store_gallery_building_menu, 
  312. 	} 
  313.  
  314. 	-- leaving this should go back to the police lineup 
  315. 	if Store_common_gallery_download_only then 
  316. 		item.on_cancel = store_gallery_exit 
  317. 	end 
  318. 	 
  319. 	local menu_idx = #Store_gallery_building_menu + 1 
  320. 	Store_gallery_building_menu[menu_idx] = item	 
  321. end 
  322.  
  323. function store_gallery_popup_close(event) 
  324. 	Store_common_popup:nav_enable(false, nil, nil) 
  325. 	game_UI_audio_play("UI_Main_Menu_Select") 
  326. 	--Not_popup_grp:set_alpha(1) 
  327. 	 
  328. 	if Gallery_mouse_input_tracker ~= nil then 
  329. 		Gallery_mouse_input_tracker:subscribe(true) 
  330. 		Gallery_hint_bar_mouse_input_tracker:subscribe(true) 
  331. 		Store_common_hint_bar:set_visible(true) 
  332. 		character_enable_mouse_drag(true) 
  333. 	end 
  334. 	 
  335. 	if Store_common_gallery_download_only then 
  336. 		Store_gallery_popped = true 
  337. 		pop_screen() 
  338. 	end 
  339. end 
  340.  
  341. -- List of characters to download is retrieved - query data responder and populate menu 
  342. -- 
  343. function store_gallery_download_list_complete() 
  344.  
  345. 	Store_gallery_download_list_pending = false 
  346.  
  347. 	Store_gallery_building_menu = {} 
  348.  
  349. 	vint_dataresponder_request("store_gallery_populate_download_list", "store_gallery_add_download_character", 0) 
  350. 	 
  351. 	if #Store_gallery_building_menu == 0 then 
  352. 	 
  353. 		Store_common_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  354. 		Store_common_popup:set_title("MENU_TITLE_NOTICE") 
  355. 		Store_common_popup:set_text("MENU_CHARACTER_DOWNLOAD_NONE") 
  356. 		Store_common_popup:nav_enable(true, "store_gallery_popup_close", "store_gallery_popup_nav") 
  357. 		--Not_popup_grp:set_alpha(.5)	 
  358.  
  359. 		Store_common_rotate_hint:set_visible(false) 
  360. 		character_enable_mouse_drag(false) 
  361. 		 
  362. 		if Gallery_mouse_input_tracker ~= nil then 
  363. 			Gallery_mouse_input_tracker:subscribe(false) 
  364. 			Gallery_hint_bar_mouse_input_tracker:subscribe(false) 
  365. 			Store_common_hint_bar:set_visible(false) 
  366. 		end 
  367. 	else 
  368. 		if Game_platform ~= "PC" then 
  369. 			Store_common_rotate_hint:set_visible(true) 
  370. 		end 
  371. 		character_enable_mouse_drag(true) 
  372. 		store_common_push_menu(Store_gallery_building_menu) 
  373. 	 
  374. 		-- display the first character 
  375. 		store_gallery_delayed_display_character(0) 
  376. 		 
  377. 		store_gallery_unlock_controls() 
  378. 		store_unlock_controls() 
  379. 	end 
  380. end 
  381.  
  382. -- Begin the process of uploading a character 
  383. -- 
  384. function store_gallery_upload() 
  385.  
  386. 	-- Prep for screen capture 
  387. 	store_set_camera_pos("body") 
  388. 	Store_common_rotate_hint:set_visible(false) 
  389. 	character_enable_mouse_drag(false) 
  390. 	Store_common_hint_bar:set_visible(false) 
  391. 	Active_list:set_visible(false) 
  392. 	Store_header:set_visible(false) 
  393. 	 
  394. 	Store_gallery_is_uploading = true 
  395. 	 
  396. 	dialog_box_confirmation("MENU_TITLE_WARNING", "MENU_CHARACTER_UPLOAD_CONFIRM", "store_gallery_upload_cb") 
  397. 	 
  398. 	store_gallery_lock_controls() 
  399. end 
  400.  
  401. -- Results of the confirmation dialog when asking to upload a character 
  402. function store_gallery_upload_cb(result, action) 
  403. 	if result == 0 then 
  404. 		store_gallery_upload_character()	 
  405. 	else 
  406. 		store_gallery_upload_complete() 
  407. 	end 
  408. end 
  409.  
  410. function store_gallery_upload_complete()	 
  411. 	Store_gallery_is_uploading = false 
  412. 	 
  413. 	if Game_platform ~= "PC" then 
  414. 		Store_common_rotate_hint:set_visible(true) 
  415. 	end 
  416. 	character_enable_mouse_drag(true) 
  417. 	Store_common_hint_bar:set_visible(true) 
  418. 	Active_list:set_visible(true) 
  419. 	Store_header:set_visible(true)	 
  420. 	store_gallery_unlock_controls()	 
  421. end 
  422.  
  423. function store_gallery_lock_controls() 
  424. 	Input_tracker:subscribe(false) 
  425.  
  426. 	if Game_platform == "PC" then 
  427. 		Gallery_mouse_input_tracker:subscribe(false) 
  428. 		Gallery_hint_bar_mouse_input_tracker:subscribe(false) 
  429. 		--Store_common_hint_bar:set_visible(false) 
  430. 	end 
  431. end 
  432.  
  433. function store_gallery_unlock_controls() 
  434. 	Input_tracker:subscribe(true) 
  435. 	 
  436. 	if Game_platform == "PC" then 
  437. 		Gallery_mouse_input_tracker:subscribe(true) 
  438. 		Gallery_hint_bar_mouse_input_tracker:subscribe(true) 
  439. 		Store_common_hint_bar:set_visible(true) 
  440. 		character_enable_mouse_drag(true) 
  441. 	end 
  442. end 
  443.  
  444. function store_gallery_load_thread() 
  445. 	while true do 
  446. 		delay(0.1) 
  447. 		if pcu_is_streaming_done() then 
  448. 			-- Must wait at least a frame for handshake after streaming is done 
  449. 			delay(0.1) 
  450. 			if Store_gallery_pending_load ~= -1 then 
  451. 			 
  452. 				if Store_common_gallery_download_only then 
  453. 					vint_set_property(vint_object_find("player_creation_grp", 0, Store_character_doc_handle), "background", true) 
  454. 					bg_saints_set_background(true) 
  455. 				end 
  456. 			 
  457. 				store_gallery_display_character(Store_gallery_pending_load) 
  458. 				Store_gallery_pending_load = -1 
  459. 			end 
  460. 		end 
  461. 	end 
  462. end 
  463.  
  464. function store_gallery_delayed_display_character(id) 
  465. 	if Store_gallery_load_thread == -1 then 
  466. 		Store_gallery_load_thread = thread_new("store_gallery_load_thread") 
  467. 	end 
  468. 	Store_gallery_pending_load = id 
  469. end 
  470.  
  471. function store_gallery_allow_input(event) 
  472. 	local allow = pcu_is_streaming_done() or (event ~= "back" and event ~= "select" and event ~= "mouse_click") 
  473. 	return allow 
  474. end 
  475.  
  476. function store_gallery_mouse_move(event, target_handle) 
  477. 	store_common_mouse_move(event, target_handle) 
  478. end 
  479.  
  480. function store_gallery_mouse_click(event, target_handle) 
  481. 	local hint_index = Store_common_hint_bar:get_hint_index(target_handle) 
  482. 	if hint_index == 1 then 
  483. 		-- return if input is not allowed at this time (ie. character is streaming in) 
  484. 		if store_gallery_allow_input(event) == false then 
  485. 			return 
  486. 		end 
  487. 		 
  488. 		if Store_common_gallery_download_only then 
  489. 			store_common_back_menu() 
  490. 			Store_header:pop_title() 
  491. 			store_gallery_exit() 
  492. 		elseif Menu_data[1].on_cancel == store_gallery_download_list_cancel then 
  493. 			Store_header:pop_title() 
  494. 			store_common_button_b() 
  495. 		else 
  496. 			Store_header:pop_title() 
  497. 			store_gallery_exit() 
  498. 		end 
  499. 	end 
  500. end 
  501.  
  502. function store_gallery_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  503. end 
  504.  
  505. function store_gallery_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  506. end 
  507.  
  508. function store_gallery_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  509. end 
  510.