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