./store_character_select.lua

  1. --Globals... 
  2. local TILE_WIDTH 	= 126 
  3. local TILE_HEIGHT = 126 
  4.  
  5. local Character_select_doc_h 
  6. local Character_select_screen_grp_h 
  7. local Grid_highlight_h 
  8. local Grid_glow_h 
  9. local Character_image_h 
  10. local Character_image_mask_h 
  11. local Character_select_out_anim_h 
  12. local Grid_button 
  13. local Character_select_input_tracker 
  14. local Character_select_mouse_Character_select_input_tracker 
  15. local Grid_data = {} 
  16. local Store_character_select_img_update_thread = -1 
  17. local Store_character_select_loading_img = nil 
  18. local Store_character_select_unload_img  = nil 
  19. local Store_character_select_current_img = nil 
  20. local Character_select_image_idx = 1 
  21.  
  22. Store_character_select_anim_done = false 
  23.  
  24. local Character_select_mouse_input_tracker = nil 
  25. local Character_cell_handles = {	"cell_1_1","cell_1_2","cell_1_3", 
  26. 											"cell_2_1","cell_2_2","cell_2_3", 
  27. 											"cell_3_1","cell_3_2","cell_3_3",} 
  28.  
  29. local Zinyak_image_string = "ui_store_lineup_mugshot_10" 
  30.  
  31. local Grid_col_idx 		= 1 
  32. local Grid_row_idx 		= 1 
  33. local Grid_width 			= 3 
  34. local Grid_height 		= 3 
  35. local Grid_max_width 	= ( TILE_WIDTH * Grid_width ) - TILE_WIDTH 
  36. local Grid_max_height 	= ( TILE_HEIGHT * Grid_height ) - TILE_HEIGHT 
  37.  
  38. function store_character_select_init() 
  39. 	-- Find our documents... 
  40. 	Character_select_doc_h = vint_document_find( "store_character_select" ) 
  41. 	 
  42. 	Character_select_screen_grp_h = vint_object_find( "screen_grp" ) 
  43. 	vint_set_property( Character_select_screen_grp_h, "alpha", 0.0 ) 
  44.  
  45. 	Character_select_input_tracker = Input_tracker:new() 
  46. 	Character_select_input_tracker:add_input( "select", "store_character_select_button_a", 50 ) 
  47. 	Character_select_input_tracker:add_input( "nav_up", "store_character_select_nav_up", 50 ) 
  48. 	Character_select_input_tracker:add_input( "nav_down", "store_character_select_nav_down", 50 ) 
  49. 	Character_select_input_tracker:add_input( "nav_left", "store_character_select_nav_left", 50 ) 
  50. 	Character_select_input_tracker:add_input( "nav_right", "store_character_select_nav_right", 50 ) 
  51. 	Character_select_input_tracker:subscribe( false ) 
  52. 	 
  53. 	Grid_highlight_h = vint_object_find( "grid_highlight_grp" ) 
  54. 	Grid_glow_h = vint_object_find( "grid_glow" ) 
  55. 	Grid_button = Vdo_hint_button:new( "highlight_button", 0, Character_select_doc_h ) 
  56. 	Grid_button:set_button( CTRL_MENU_BUTTON_A ) 
  57. 	 
  58. 	Character_image_h = vint_object_find( "player_image" ) 
  59. 	Character_image_mask_h = vint_object_find( "player_image_mask" ) 
  60. 	 
  61. 	-- build the grid data 
  62. 	local image_idx = 0 
  63. 	for x = 1, 3 do 
  64. 		Grid_data[ x ] = { } 
  65. 		for y = 1, 3 do 
  66. 			Grid_data[ x ][ y ] = { } 
  67. 			Grid_data[ x ][ y ].handle = vint_object_find( "cell_"..x.."_"..y ) 
  68. 			image_idx = ( x - 1 ) * Grid_width + y 
  69. 			Grid_data[ x ][ y ].image = "ui_store_lineup_mugshot_0"..image_idx 
  70. 		end 
  71. 	end 
  72. 	 
  73. 	local highlight_anim_h = vint_object_find( "highlight_anim" ) 
  74. 	lua_play_anim( highlight_anim_h, 0, Character_select_doc_h ) 
  75. 	 
  76. 	local player_glow_anim_h = vint_object_find( "player_glow_anim" ) 
  77. 	lua_play_anim( player_glow_anim_h, 0, Character_select_doc_h ) 
  78. 	 
  79. 	local zinyak_glow_anim_h = vint_object_find( "zinyak_glow_anim" ) 
  80. 	lua_play_anim( zinyak_glow_anim_h, 0, Character_select_doc_h  ) 
  81. 	 
  82. 	-- make fire 
  83. 	local fire_h = vint_object_find( "fire" ) 
  84. 	local fire_frames_table = {	"ui_hud_diversion_fire1", "ui_hud_diversion_fire2", "ui_hud_diversion_fire3", "ui_hud_diversion_fire4", "ui_hud_diversion_fire5","ui_hud_diversion_fire6", "ui_hud_diversion_fire7",  
  85. 								"ui_hud_diversion_fire8", "ui_hud_diversion_fire9", "ui_hud_diversion_fire10", "ui_hud_diversion_fire11", "ui_hud_diversion_fire12", "ui_hud_diversion_fire13", "ui_hud_diversion_fire14"} 
  86. 	vint_bitmap_animator_register_animation(--[[target handle]]fire_h, --[[loop type see game_ui_globals.lua]]ANIMATED_BITMAP_PLAYBACK_TYPE_LOOPING, --[[playback reverse]] false, 
  87. 											--[[frametime]]1/18, --[[duration (negative means forever)]]-1.0, --[[start paused]]false, --[[starting frame]] 1, --[[frames table]]fire_frames_table, --[[end event]] "") 
  88. 	 
  89. 	local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h ) 
  90. 	Character_select_out_anim_h = vint_object_clone( char_sel_in_anim_h ) 
  91. 	lua_reverse_anim( Character_select_out_anim_h ) 
  92. 	 
  93. 	if game_get_platform() == "PC" then 
  94. 		Character_select_mouse_input_tracker = Vdo_input_tracker:new()		 
  95. 		for x = 1, 3 do 
  96. 			for y = 1, 3 do 
  97. 				Character_select_mouse_input_tracker:add_mouse_input("mouse_click", "store_character_select_mouse_click", 25, Grid_data[ x ][ y ].handle ) 
  98. 				Character_select_mouse_input_tracker:add_mouse_input("mouse_move", "store_character_select_mouse_move", 100, Grid_data[ x ][ y ].handle ) 
  99. 			end 
  100. 		end 
  101. 		Character_select_mouse_input_tracker:subscribe(true) 
  102. 	end 
  103. 	 
  104. 	local player_name = game_lobby_get_local_player_name() 
  105. 	store_character_select_set_player_name( player_name ) 
  106. 	 
  107. 	if pcr_is_plastic_surgeon() == false then 
  108. 		--Load initial pegs... 
  109. 		thread_new( "store_character_select_load_initial_pegs" ) 
  110. 	end 
  111. end 
  112.  
  113. function store_character_select_load_initial_pegs() 
  114. 	--Dump the pause map. 
  115. 	game_peg_unload( "ui_map_world_city" ) 
  116. 	 
  117. 	thread_yield() 
  118. 	 
  119. 	-- Pre-load top level images 
  120. 	game_peg_load_with_cb( "store_character_select_zinyak_loaded", 2, "ui_store_lineup_mugshot_01", Zinyak_image_string ) 
  121. end 
  122.  
  123. function store_character_select_zinyak_loaded() 
  124. 	--show screen stuff 
  125. 	local zinyak_image = vint_object_find( "zinyak_image" ) 
  126. 	vint_set_property( zinyak_image, "image", Zinyak_image_string ) 
  127. 	 
  128. 	vint_set_property( Character_image_h, "image", "ui_store_lineup_mugshot_01" ) 
  129. 	 
  130. 	vint_set_property( Character_image_mask_h, "image", "ui_store_lineup_mugshot_01"  ) 
  131. 	vint_set_property( Character_image_mask_h, "visible", false ) 
  132. 		 
  133. 	store_character_line_up_is_loaded() 
  134. 	--store_character_select_set_grid_highlight( 0 ) 
  135. end 
  136.  
  137. function store_character_select_close() 
  138. 	-- Unscubscribe from inputs... 
  139. 	Character_select_input_tracker:subscribe(false) 
  140. 	 
  141. 	--play loading animation... 
  142. 	--local loading_anim_h = vint_object_find("loading_anim") 
  143. 	--lua_play_anim(loading_anim_h) 
  144. 	 
  145. 	--delay while we we transition out... 
  146. 	delay(.25) 
  147. 	 
  148. 	store_character_select_unload_pegs() 
  149. 	thread_yield() 
  150. 	 
  151. 	--Load pause map on callback we will do the final exit and transition out as planned. 
  152. 	game_peg_load_with_cb("store_character_select_close_final", 1, "ui_map_world_city")	 
  153. end 
  154.  
  155. function store_character_select_unload_pegs() 
  156. 	game_peg_unload( Zinyak_image_string ) 
  157. 	 
  158. 	for i = 1, 9 do 
  159. 		game_peg_unload( "ui_store_lineup_mugshot_0"..i ) 
  160. 	end 
  161. 	 
  162. 	if Store_character_select_unload_img ~= nil then 
  163. 		game_peg_unload( Store_character_select_unload_img ) 
  164. 	end 
  165. 	if Store_character_select_loading_img ~= nil then 
  166. 		game_peg_unload( Store_character_select_loading_img ) 
  167. 	end 
  168. 	 
  169. 	game_peg_unload( "ui_store_lineup_mugshot_01" ) 
  170. 	 
  171. end 
  172.  
  173. function store_character_select_close_final() 
  174. end 
  175.  
  176. function store_character_select_nothing() 
  177. end 
  178.  
  179.  
  180. function store_character_select_cleanup() 
  181. 	store_character_select_unload_pegs() 
  182. end 
  183.  
  184.  
  185. ------------------------------------------------------------------------------- 
  186. -- Called by C++ via data responder 
  187. -- 
  188. -- cash_from_bank		how much the bank is paying the player 
  189. -- player_cash			how much cash the player has before withdrawl 
  190. --	daily_cash			how much cash the player earns per day... 
  191. -- transfer_cap		How much cash the bank can max out on. 
  192. ------------------------------------------------------------------------------- 
  193. function store_character_select_populate(cash_from_bank, player_cash, daily_cash, transfer_cap, next_transfer_percent)	 
  194.  
  195. end 
  196.  
  197. ------------------------------------------------------------------------------- 
  198. -- Process input 
  199. ------------------------------------------------------------------------------- 
  200. function store_character_select_button_a() 
  201. 	store_character_lineup_select() 
  202. end 
  203.  
  204. function store_character_select_nav_up(event, acceleration) 
  205. 	 
  206. 	store_character_select_set_grid_highlight(-2) 
  207.  
  208. end 
  209.  
  210. function store_character_select_nav_down(event, acceleration) 
  211. 	 
  212. 	store_character_select_set_grid_highlight(2) 
  213. 	 
  214. end 
  215.  
  216. function store_character_select_nav_left(event, acceleration) 
  217. 	 
  218. 	store_character_select_set_grid_highlight(-1) 
  219. 	 
  220. end 
  221.  
  222. function store_character_select_nav_right(event, acceleration) 
  223. 	 
  224. 	store_character_select_set_grid_highlight(1) 
  225. 	 
  226. end 
  227.  
  228. function store_character_select_set_grid_highlight(direction) 
  229. 	local x ,y = vint_get_property(Grid_highlight_h, "anchor") 
  230. 	if direction == 1 then 
  231. 	-- RIGHT 
  232. 		x = x + TILE_WIDTH 
  233. 		Grid_col_idx = Grid_col_idx + 1 
  234. 	elseif direction == -1 then 
  235. 	-- LEFT 
  236. 		x = x - TILE_WIDTH 
  237. 		Grid_col_idx = Grid_col_idx - 1 
  238. 	elseif direction == 2 then 
  239. 	-- DOWN 
  240. 		y = y + TILE_HEIGHT 
  241. 		Grid_row_idx = Grid_row_idx + 1 
  242. 	elseif direction == -2 then 
  243. 	-- UP 
  244. 		y = y - TILE_HEIGHT 
  245. 		Grid_row_idx = Grid_row_idx - 1 
  246. 	else 
  247. 		x = 0 
  248. 		Grid_col_idx = 1 
  249. 		y = 0 
  250. 		Grid_row_idx = 1 
  251. 	end 
  252. 	 
  253. 	--check the limits 
  254. 	if x > Grid_max_width then 
  255. 		x = 0 
  256. 		Grid_col_idx = 1 
  257. 	end 
  258. 	if x < 0 then 
  259. 		x = Grid_max_width 
  260. 		Grid_col_idx = Grid_width 
  261. 	end 
  262. 	if y > Grid_max_height then 
  263. 		y = 0 
  264. 		Grid_row_idx = 1 
  265. 	end 
  266. 	if y < 0 then 
  267. 		y = Grid_max_height 
  268. 		Grid_row_idx = Grid_height 
  269. 	end 
  270.  
  271. 	vint_set_property( Grid_highlight_h, "anchor", x, y ) 
  272. 	vint_set_property( Grid_glow_h, "anchor", x, y ) 
  273. 	 
  274. 	 
  275. 	for x = 1, 3 do 
  276. 		for y = 1, 3 do 
  277. 			vint_set_property( Grid_data[ x ][ y ].handle, "scale", 0.9, 0.9 )  
  278. 			vint_set_property( Grid_data[ x ][ y ].handle, "tint", 80/255, 80/255, 80/255 )  
  279. 		end 
  280. 	end 
  281.  
  282. 	Character_select_image_idx = ( Grid_row_idx - 1 ) * Grid_width + Grid_col_idx 
  283. 	 
  284. 	vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "scale", 1.0, 1.0 )  
  285. 	vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "tint", 1.0, 1.0, 1.0 )  
  286. 	 
  287. 	vint_set_property( Character_image_h, "visible", false ) 
  288. 	 
  289. 	local player_flash_h = vint_object_find( "player_flash" ) 
  290. 	vint_set_property( player_flash_h, "visible", false ) 
  291. 	 
  292. 	if  Character_select_image_idx == 9 then 
  293. 		store_character_select_show_text( "LINEUP_DOWNLOAD_CHARACTER", "LINEUP_DOWNLOAD_CHARACTER_DESC", true ) 
  294. 	else 
  295. 		store_character_select_show_text( nil, nil, false ) 
  296. 	end 
  297. 	 
  298. 	if Store_character_select_loading_img == nil then 
  299. 		local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image 
  300. 		--local Store_character_select_current_img = vint_get_property( Character_image_h, "image_crc" )	 
  301. 	 
  302. 		if Store_character_select_current_img ~= nil then 
  303. 			game_peg_unload( Store_character_select_current_img ) 
  304. 		end 
  305. 		if new_image ~= nil then 
  306. 			-- must set Store_character_select_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  307. 			Store_character_select_loading_img = new_image		 
  308. 			game_peg_load_with_cb( "store_character_select_show_image", 1, new_image ) 
  309. 		end 
  310. 	end 
  311. 	 
  312. end 
  313.  
  314. -- Called in a thread to delay the image updating. 
  315. -- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly, 
  316. -- and because the streaming system didn't always co-operate with the images being released 
  317. -- from the callback context that was executed when another stream load completed. 
  318. -- 
  319. function store_character_select_image_update() 
  320. 	delay( 0.2 ) 
  321. 	game_peg_unload( Store_character_select_unload_img )	 
  322. 	game_peg_load_with_cb( "store_character_select_show_image", 1, Store_character_select_loading_img ) 
  323. 	Store_character_select_img_update_thread = -1 
  324. end 
  325.  
  326. -- Callback for when an image is done loading. 
  327. -- SEH: It might make sense to roll this into vdo_bitmap_viewer... 
  328. -- 
  329. function store_character_select_show_image() 
  330. 	local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image 
  331.  
  332. 	if Store_character_select_loading_img == new_image then 
  333. 		vint_set_property( Character_image_h, "image", new_image ) 
  334. 		vint_set_property( Character_image_h, "visible", true ) 
  335. 		vint_set_property( Character_image_mask_h, "image", new_image ) 
  336. 		vint_set_property( Character_image_mask_h, "visible", true ) 
  337. 		 
  338. 		if Store_character_select_current_img ~= new_image then 
  339. 			 
  340. 			local player_flash_h = vint_object_find( "player_flash", 0, Character_select_doc_h ) 
  341. 			vint_set_property( player_flash_h, "visible", true ) 
  342. 			 
  343. 			local player_anim_h = vint_object_find( "player_anim", 0, Character_select_doc_h ) 
  344. 			lua_play_anim( player_anim_h, 0, Character_select_doc_h ) 
  345. 		 
  346. 		end 
  347. 		 
  348. 		Store_character_select_current_img = new_image 
  349. 		Store_character_select_loading_img = nil 
  350. 		 
  351. 	else 
  352. 		-- a new image was picked while we were loading - load this now, and unload the one we just loaded 
  353. 		if new_image ~= nil then 
  354. 			Store_character_select_unload_img = Store_character_select_loading_img 
  355. 			Store_character_select_loading_img = new_image 
  356. 			Store_character_select_img_update_thread = thread_new( "store_character_select_image_update" )	 
  357. 		else 
  358. 			game_peg_unload( Store_character_select_loading_img ) 
  359. 			Store_character_select_loading_img = nil 
  360. 		end 
  361. 	end 
  362. end 
  363.  
  364. function store_character_select_show_screen() 
  365. 	vint_set_property( Character_select_screen_grp_h, "alpha", 1.0 ) 
  366. end 
  367.  
  368. function store_character_select_hide_screen() 
  369. 	vint_set_property( Character_select_screen_grp_h, "alpha", 0 ) 
  370. end 
  371.  
  372. function store_character_select_get_index() 
  373. 	return Character_select_image_idx 
  374. end 
  375.  
  376. function store_character_select_lock_input() 
  377. 	Character_select_input_tracker:subscribe( false ) 
  378. end 
  379.  
  380. function store_character_select_unlock_input() 
  381. 	Character_select_input_tracker:subscribe( true ) 
  382. end 
  383.  
  384. function store_character_select_play_intro() 
  385. 	local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h ) 
  386. 	local end_tween_h = vint_object_find( "char_in_last_tween", char_sel_in_anim_h ) 
  387. 	vint_set_property( end_tween_h, "end_event", "store_character_select_anim_in_done" ) 
  388. 	lua_play_anim( char_sel_in_anim_h, 0, Character_select_doc_h ) 
  389. 	if Character_select_mouse_input_tracker ~= nil then 
  390. 		Character_select_mouse_input_tracker:subscribe(true) 
  391. 	end 
  392. end 
  393.  
  394. function store_character_select_play_outro() 
  395. 	--local char_sel_in_anim_h = vint_object_find( "char_sel_in_anim", 0, Character_select_doc_h ) 
  396. 	lua_play_anim( Character_select_out_anim_h, 0, Character_select_doc_h ) 
  397. 	vint_apply_start_values( Character_select_out_anim_h ) 
  398. 	if Character_select_mouse_input_tracker ~= nil then 
  399. 		Character_select_mouse_input_tracker:subscribe(false) 
  400. 	end 
  401. end 
  402.  
  403. function store_character_select_anim_in_done() 
  404. 	Store_character_select_anim_done = true 
  405. 	store_character_select_unlock_input() 
  406. end 
  407.  
  408. function store_character_select_show_text( title, desc, is_visible ) 
  409. 	local title_txt_h = vint_object_find( "title_txt_1", 0, Character_select_doc_h ) 
  410. 	local desc_txt_h = vint_object_find( "desc_txt", 0, Character_select_doc_h ) 
  411. 	 
  412. 	if title ~= nil then 
  413. 		vint_set_property( title_txt_h, "text_tag", title ) 
  414. 	end 
  415. 	 
  416. 	if desc ~= nil then 
  417. 		vint_set_property( desc_txt_h, "text_tag", desc )		 
  418. 	end 
  419. 	 
  420. 	vint_set_property( title_txt_h, "visible", is_visible ) 
  421. 	vint_set_property( desc_txt_h, "visible", is_visible ) 
  422. 	 
  423. end 
  424.  
  425. function store_character_select_set_player_name( new_name ) 
  426. 	local player_name_h = vint_object_find( "label_name" ) 
  427. 	vint_set_property( player_name_h, "text_tag", new_name ) 
  428. 	 
  429. 	if vint_is_std_res() then 
  430. 		--resize player name to fit 
  431. 		vint_set_property( player_name_h, "scale", 1, 1 ) 
  432. 		local MAX_WIDTH_TITLE = 265 
  433. 		local text_width_label, text_height_label = element_get_actual_size( player_name_h ) 
  434.  
  435. 		if text_width_label > MAX_WIDTH_TITLE then 
  436. 			local text_scale_label = MAX_WIDTH_TITLE/text_width_label 
  437. 			vint_set_property( player_name_h, "scale", text_scale_label, 1 ) 
  438. 		end	 
  439. 	end 
  440. end 
  441.  
  442. -- ===================================== 
  443. --       Mouse Specific Functions 
  444. -- ===================================== 
  445.  
  446. function store_character_select_mouse_click( event, target_handle ) 
  447. 	store_character_lineup_select(event) 
  448. end 
  449.  
  450. function store_character_select_mouse_move(event, target_handle) 
  451. 	for x = 1, 3 do 
  452. 		for y = 1, 3 do 
  453. 			vint_set_property( Grid_data[ x ][ y ].handle, "scale", 0.9, 0.9 )  
  454. 			vint_set_property( Grid_data[ x ][ y ].handle, "tint", 80/255, 80/255, 80/255 )  
  455. 			if Grid_data[ x ][ y ].handle == target_handle then  
  456. 				Grid_row_idx = x 
  457. 				Grid_col_idx = y 
  458. 			end 
  459. 		end 
  460. 	end 
  461. 	 
  462. 	Character_select_image_idx = ( Grid_row_idx - 1 ) * Grid_width + Grid_col_idx 
  463.  
  464. 	vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "scale", 1.0, 1.0 )  
  465. 	vint_set_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "tint", 1.0, 1.0, 1.0 )  
  466. 	 
  467. 	local cell_x, cell_y = vint_get_property( Grid_data[ Grid_row_idx ][ Grid_col_idx ].handle, "anchor" ) 
  468. 	cell_x = cell_x - 64 
  469. 	cell_y = cell_y - 64 
  470. 	vint_set_property( Grid_highlight_h, "anchor", cell_x, cell_y ) 
  471. 	vint_set_property( Grid_glow_h, "anchor", cell_x, cell_y ) 
  472. 	 
  473. 	vint_set_property( Character_image_h, "visible", false ) 
  474. 	 
  475. 	local player_flash_h = vint_object_find( "player_flash", 0, Character_select_doc_h ) 
  476. 	vint_set_property( player_flash_h, "visible", false ) 
  477. 	 
  478. 	if  Character_select_image_idx == 9 then 
  479. 		store_character_select_show_text( "LINEUP_DOWNLOAD_CHARACTER", "LINEUP_DOWNLOAD_CHARACTER_DESC", true ) 
  480. 	else 
  481. 		store_character_select_show_text( nil, nil, false ) 
  482. 	end 
  483. 	 
  484. 	if Store_character_select_loading_img == nil then 
  485. 		local new_image = Grid_data[ Grid_row_idx ][ Grid_col_idx ].image 
  486.  
  487. 		if Store_character_select_current_img ~= nil then 
  488. 			game_peg_unload( Store_character_select_current_img ) 
  489. 		end 
  490. 		if new_image ~= nil then 
  491. 			-- must set Store_character_select_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  492. 			Store_character_select_loading_img = new_image		 
  493. 			game_peg_load_with_cb( "store_character_select_show_image", 1, new_image ) 
  494. 		end 
  495. 	end 
  496. end