./cell_foreground.lua

  1. -- These are for the 9 buttons on the cellphone. 
  2. ID_INVALID			= -2 
  3. ID_MAIN				= -1 
  4. ID_MAP				= 0 
  5. ID_MISSIONS 		= 1 
  6. ID_SAINTSBOOK		= 2 
  7. ID_REWARDS			= 3 
  8. ID_MUSIC				= 4 
  9. ID_CAMERA			= 5 
  10. ID_PHONE				= 6 
  11. ID_CASH				= 7 
  12. ID_EXTRAS			= 8 
  13.  
  14. PING_RED = 300 
  15. PING_GREEN = 150 
  16.  
  17. Cell_foreground_doc	= -1 
  18. Cell_background_doc 	= -1 
  19. Cell_foreground_h 	= 0 
  20. Cell_background_h 	= 0 
  21.  
  22. Pause_map_from_menu	= false				--Are we coming from the cell_menu_main or directly from game? 
  23. Rewards_from_menu	 	= false					--Are we coming from the cell_menu_main or directly from game? 
  24. Missions_from_menu	= false					--Are we coming from the cell_menu_main or directly from game? 
  25.  
  26. --Transtition Enums... 
  27. CELL_TRANSITION_INVALID 		= 0 
  28. CELL_TRANSITION_IN_PORTRAIT 	= 1		--set to portrait 
  29. CELL_TRANSITION_IN_LANDSCAPE 	= 2		--set to landscape 
  30. CELL_TRANSITION_OUT_PORTRAIT 	= 3		--transition out to portrait 
  31. CELL_TRANSITION_OUT_LANDSCAPE = 4		--transition out to landscape 
  32.  
  33. CELL_STATE_INVALID 				= 0 
  34. CELL_STATE_START					= 1 
  35. CELL_STATE_OUT 					= 2 
  36. CELL_STATE_PORTRAIT				= 3 
  37. CELL_STATE_LANDSCAPE 			= 4  
  38. CELL_STATE_START_PORTRAIT		= 5 
  39. CELL_STATE_START_LANDSCAPE		= 6 
  40. CELL_STATE_OUT_PORTRAIT			= 7  
  41. CELL_STATE_OUT_LANDSCAPE		= 8   
  42.  
  43. CELL_TYPE_LANDSCAPE	= 1 
  44. CELL_TYPE_PORTRAIT	= 2 
  45.  
  46. local Ping_thread_h = 0 
  47.  
  48. local Cell_current_state = CELL_STATE_START 
  49. Cell_transition_cb_func = -1 
  50.  
  51. --This is a seperate enum because the ID_* enums does not have every screen in the phone... 
  52. CELL_SCREEN_NONE 			= 0 
  53. CELL_SCREEN_MAIN 			= 1 
  54. CELL_SCREEN_MAP 			= 2 
  55. CELL_SCREEN_MISSIONS		= 3 
  56. CELL_SCREEN_SAINTSBOOK	= 4 
  57. CELL_SCREEN_REWARDS		= 5 
  58. CELL_SCREEN_MUSIC			= 6 
  59. CELL_SCREEN_MUSIC_SUB	= 7 
  60. CELL_SCREEN_PLAYLIST		= 8 
  61. CELL_SCREEN_CAMERA		= 9 
  62. CELL_SCREEN_PHONE			= 10 
  63. CELL_SCREEN_EXTRAS		= 11 
  64. CELL_SCREEN_CHEATS		= 12 
  65. CELL_SCREEN_STATS			= 13 
  66. CELL_SCREEN_CASH			=14 
  67.  
  68.  
  69. -- Table is used to define screen types.  
  70. -- Allows us to store the type of screen it is, document name and target element. 
  71. -- This allows us to make any kind of transtion to a particular screen. 
  72. -- Screen type is either CELL_TYPE_LANDSCAPE (screens designed to be wide) or CELL_TYPE_PORTRAIT (screens in vertical orientation. 
  73. local Cell_menu_types = { 
  74. 	--Screen ID defined above		Screen Type				Document Name			First element of the group 
  75. 	[CELL_SCREEN_NONE] 			= {nil, 						nil,						nil},				--This is used so we can transition to nothing... 
  76. 	[CELL_SCREEN_MAIN] 			= {CELL_TYPE_PORTRAIT, 	"cell_menu_main",		"cell_menu_grp"}, 
  77. 	[CELL_SCREEN_MAP]				= {CELL_TYPE_LANDSCAPE, "pause_map",			"map_all_grp"}, 
  78. 	[CELL_SCREEN_MISSIONS] 		= {CELL_TYPE_PORTRAIT, 	"cell_missions",		"missions_grp"}, 
  79. 	[CELL_SCREEN_SAINTSBOOK]	= {CELL_TYPE_LANDSCAPE,	"cell_saintsbook",	"saintsbook_grp"}, 
  80. 	[CELL_SCREEN_REWARDS]		= {CELL_TYPE_LANDSCAPE, "cell_rewards", 		"rewards_base_grp"}, 
  81. 	[CELL_SCREEN_MUSIC_SUB]		= {CELL_TYPE_PORTRAIT, 	"cell_music_sub", 	"cell_menu_grp"}, 
  82. 	[CELL_SCREEN_MUSIC]			= {CELL_TYPE_LANDSCAPE, "cell_music_menu", 	"station_group"}, 
  83. 	[CELL_SCREEN_PLAYLIST]		= {CELL_TYPE_LANDSCAPE, "cell_playlist", 		"playlist_grp"}, 
  84. 	[CELL_SCREEN_CAMERA]			= {CELL_TYPE_PORTRAIT,	"cell_camera",			"camera_grp"}, 
  85. 	[CELL_SCREEN_PHONE]			= {CELL_TYPE_PORTRAIT,	"cell_phone",			"phone_grp"}, 
  86. 	[CELL_SCREEN_EXTRAS]			= {CELL_TYPE_PORTRAIT, 	"cell_extras", 		"cell_menu_grp"}, 
  87. 	[CELL_SCREEN_CHEATS]			= {CELL_TYPE_PORTRAIT, 	"cell_cheats", 		"cheats_grp"}, 
  88. 	[CELL_SCREEN_STATS]			= {CELL_TYPE_LANDSCAPE, "cell_stats", 			"stats_grp"}, 
  89. 	[CELL_SCREEN_CASH]			= {CELL_TYPE_PORTRAIT, 	"store_crib_cash", 	"cell_bonus_grp"}, 
  90. } 
  91.  
  92. -- Positions, rotation and scale values for screens in HD 
  93. local Cell_states = { 
  94. 	[CELL_TYPE_PORTRAIT] = { 
  95. 		[CELL_STATE_START_PORTRAIT] 	= {x = 1000, 	y = 1300, 	r = (45 * DEG_TO_RAD), 		s = 1.0}, 
  96. 		[CELL_STATE_START_LANDSCAPE] 	= {x = 1000, 	y = 1300, 	r = (-45 * DEG_TO_RAD), 	s = 1.5}, 
  97. 		[CELL_STATE_PORTRAIT] 			= {x = 640, 	y = 360, 	r = (0 * DEG_TO_RAD), 		s = 1.0}, 
  98. 		[CELL_STATE_LANDSCAPE] 			= {x = 640, 	y = 360, 	r = (-90 * DEG_TO_RAD), 	s = 1.5}, 
  99. 		[CELL_STATE_OUT_PORTRAIT] 		= {x = 1000, 	y = 1300, 	r = (45 * DEG_TO_RAD), 		s = 1.0}, 
  100. 		[CELL_STATE_OUT_LANDSCAPE] 	= {x = 1000, 	y = 1300, 	r = (-45 * DEG_TO_RAD), 	s = 1.5}, 
  101. 	}, 
  102. 	[CELL_TYPE_LANDSCAPE] = { 
  103. 		[CELL_STATE_START_PORTRAIT] 	= {x = 1000, 	y = 1300, 	r = (135 * DEG_TO_RAD), 	s = .65}, 
  104. 		[CELL_STATE_START_LANDSCAPE] 	= {x = 1000, 	y = 1300, 	r = (45 * DEG_TO_RAD), 		s = 1.0}, 
  105. 		[CELL_STATE_PORTRAIT] 			= {x = 640, 	y = 360, 	r = (90 * DEG_TO_RAD), 		s = .65}, 
  106. 		[CELL_STATE_LANDSCAPE] 			= {x = 640, 	y = 360, 	r = (0 * DEG_TO_RAD), 		s = 1.0}, 
  107. 		[CELL_STATE_OUT_PORTRAIT] 		= {x = 1000, 	y = 1300, 	r = (135 * DEG_TO_RAD), 	s = .65}, 
  108. 		[CELL_STATE_OUT_LANDSCAPE] 	= {x = 1000, 	y = 1300, 	r = (45 * DEG_TO_RAD), 		s = 1.0}, 
  109. 	}, 
  110. } 
  111.  
  112. --Initialize 
  113. function cell_foreground_init() 
  114. 	if vint_is_std_res() then 
  115. 		-- Positions, rotation and scale values for screens in SD 
  116. 		for idx, val in pairs(Cell_states) do  
  117. 			for idx2, val2 in pairs(val) do  
  118. 				if val2.x == 640 then 
  119. 					val2.x = 320 
  120. 				elseif val2.x == 1000 then 
  121. 					 val2.x = 700 
  122. 				end 
  123. 				if val2.y == 360 then 
  124. 					val2.y = 240 
  125. 				elseif val2.y == 1300 then 
  126. 					val2.y = 900  
  127. 				end 
  128. 				val2.s = val2.s *.667 *.9 
  129. 			end 
  130. 		end 
  131. 	end 
  132. 	 
  133. 	Cell_foreground_doc = vint_document_find("cell_foreground") 
  134. 	Cell_background_doc = vint_document_find("cell_background")	 
  135. 	Cell_foreground_h = 	vint_object_find("screen_grp",  0, Cell_foreground_doc) 
  136. 	Cell_background_h = 	vint_object_find("screen_grp",  0, Cell_background_doc) 
  137. 	 
  138. 	local ping_grp_h = vint_object_find("ping_grp", 0, Cell_foreground_doc) 
  139. 	local top_icons_h = vint_object_find("top_icons", 0, Cell_foreground_doc) 
  140. 		 
  141. 	vint_set_property(ping_grp_h, "visible", false) 
  142. 	 
  143. 	if game_get_platform() == "PC" then 
  144. 		if coop_is_active() == true then			 
  145. 			vint_set_property(top_icons_h, "visible", false) 
  146. 			vint_set_property(ping_grp_h, "visible", true) 
  147. 			 
  148. 			-- poll the ping every 2 seconds until the cell phone is closed 
  149. 			Ping_thread_h = thread_new("cell_foreground_ping_thread") 
  150. 		end 
  151. 	end	 
  152. 	 
  153. 	--Hide all elements to start out with... 
  154. 	vint_set_property(Cell_foreground_h, "visible", false) 
  155. 	vint_set_property(Cell_background_h, "visible", false) 
  156.  
  157. 	local bg_loop = Vdo_anim_object:new("bg_loop", 0, Cell_background_doc) 
  158. 	bg_loop:play(0) 
  159. 	 
  160. 	-- set up data items for player status 
  161. 	vint_dataitem_add_subscription("sr2_local_player_respect", "update", "cell_foreground_respect_update") 
  162. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "cell_foreground_cash_update")	 
  163. end 
  164.  
  165. --Cleanup 
  166. function cell_foreground_cleanup() 
  167. 	thread_kill(Ping_thread_h) 
  168. 	Ping_thread_h = 0 
  169. end 
  170.  
  171. --DELETE THIS.. 
  172. function cell_foreground_set_state() 
  173. end 
  174. ------------------------------------------------------------------------------- 
  175. -- Transitions the cellphone screen to next  
  176. -- 
  177. -- @transition_type		transition type... (CELL_TRANSITION_IN_LANDSCAPE) 
  178. -- @doc_name				"document name" 
  179. -- @doc_name				"base_name" 
  180. -- 
  181. --  transition_type, "pause_map", "map_all_grp", 
  182.  
  183. --cell_transition_screen(CELL_TYPE_LANDSCAPE, CELL_STATE_LANDSCAPE, "pause_map", "map_all_grp", pause_map_trans_in_complete) 
  184. function cell_transition_screen(target_state, screen1, screen2, callback_func) 
  185. 	local screen_1_data = Cell_menu_types[screen1] 
  186. 	local screen_2_data = Cell_menu_types[screen2] 
  187. 	 
  188. 	local transition_screens = { 
  189. 		[1] = {screen_type = screen_1_data[1],  		doc_name = screen_1_data[2], 		base_name = screen_1_data[3]}, 
  190. 		[2] = {screen_type = CELL_TYPE_LANDSCAPE,		doc_name = "cell_foreground", 	base_name = "cell_frame_grp"}, 
  191. 		[3] = {screen_type = CELL_TYPE_PORTRAIT, 		doc_name = "cell_background", 	base_name = "cell_bg_grp"}, 
  192. 		[4] = {screen_type = screen_2_data[1],  		doc_name = screen_2_data[2], 		base_name = screen_2_data[3]} 
  193. 	} 
  194. 	 
  195. 	if screen1 == nil or screen2 == nil then 
  196. 		--ABORT: attempt to do whack transition... 
  197. 		debug_print("vint", "No valid screen set for cell_transition_screen(). screen1 or screen2: " .. var_to_string(screen1) .. "\n") 
  198.  
  199. 		return 
  200. 	end 
  201. 	--Special case for cell rewards... needs to have an extra document transition... 
  202. 	if screen1 == CELL_SCREEN_REWARDS or screen2 == CELL_SCREEN_REWARDS then 
  203. 		transition_screens[5] = {screen_type = CELL_TYPE_LANDSCAPE, doc_name = "store_common", base_name = "cell_rotate_grp"} 
  204. 		 
  205. 		--Also needs to reset scale of store common because it gets overriden. 
  206. 		local store_common_doc_h = vint_document_find("store_common") 
  207. 		local h = vint_object_find("screen_grp", 0, store_common_doc_h) 
  208. 		vint_set_property(h, "scale", 1,1) 
  209. 	end 
  210. 	 
  211. 	local twn_h 
  212. 	 
  213. 	--This is used to ensure our callbacks context is called to the appropriate document. 
  214. 	local transition_callback_idx = 1 
  215. 	if screen1 == CELL_SCREEN_NONE then 
  216. 		-- If screen is none this means we are exiting the phone, 
  217. 		-- Our function callback should happen in the context of the screen we are exiting from... 
  218. 		transition_callback_idx = 2 
  219. 	end 
  220. 	 
  221. 	for idx, screen in pairs(transition_screens) do 
  222. 		if screen.screen_type ~= nil then 
  223. 			--Screen transitions... 
  224. 			local doc_h = vint_document_find(screen.doc_name) 
  225. 			local target_h = vint_object_find(screen.base_name, 0, doc_h) 
  226. 			 
  227. 			--Animation we use as the base(anchor, rotation, scale) 
  228. 			local anim_h = vint_object_find("transition_element_anim", 0, Cell_background_doc) 
  229. 			local anim_clone_h = vint_object_clone(anim_h) 
  230. 			 
  231. 			local root_anim_h = vint_object_find("root_animation", 0, doc_h) 
  232. 			vint_object_set_parent(anim_clone_h, root_anim_h) 
  233. 			 
  234. 			local anchor_twn_h 		= vint_object_find("anchor_twn", anim_clone_h) 
  235. 			local rotation_twn_h 	= vint_object_find("rotation_twn", anim_clone_h) 
  236. 			local scale_twn_h 		= vint_object_find("scale_twn", anim_clone_h) 
  237. 			 
  238. 			local start_state = Cell_current_state		--start state is the last state saved... 
  239. 			local end_state 	= target_state				--end state is the target state... 
  240. 			 
  241. 			 
  242. 			-- Do some translations for the start and end states... 
  243. 			-- If our state is starting then we need to figure out what type we should transition from. 
  244. 			-- This is to keep the size ratios the same all the way through... 
  245. 			if start_state == CELL_STATE_START then 
  246. 				if end_state == CELL_STATE_PORTRAIT then 
  247. 					start_state = CELL_STATE_START_PORTRAIT 
  248. 				else 
  249. 					start_state = CELL_STATE_START_LANDSCAPE 
  250. 				end 
  251. 			end 
  252. 			 
  253. 			--We do the same for when we are transitioning out... 
  254. 			if end_state == CELL_STATE_OUT then 
  255. 				if start_state == CELL_STATE_PORTRAIT then 
  256. 					end_state = CELL_STATE_OUT_PORTRAIT 
  257. 				else 
  258. 					end_state = CELL_STATE_OUT_LANDSCAPE 
  259. 				end 
  260. 			end 
  261. 				 
  262. 			local start_data 	= table_clone(Cell_states[screen.screen_type][start_state]) 
  263. 			local end_data 	= table_clone(Cell_states[screen.screen_type][end_state]) 
  264.  
  265. 			--Check to make sure we have valid states... 
  266. 			if start_data == nil or end_data == nil then 
  267. 				debug_print("vint", "invalid target_state: " .. var_to_string(target_state) .. "\n") 
  268. 				debug_print("vint", "invalid screen_type: " .. var_to_string(screen.screen_type) .. "\n") 
  269. 				return 
  270. 			end 
  271.  
  272. 			--Set target handle of our cloned tweens. 
  273. 			vint_set_property(anchor_twn_h, 	"target_handle", target_h) 
  274. 			vint_set_property(rotation_twn_h,"target_handle", target_h) 
  275. 			vint_set_property(scale_twn_h, 	"target_handle", target_h) 
  276. 			 
  277. 			--Set callback so we know we are completed and can cleanup the tweens. 
  278. 			--Additionally, the callback will call our sent in callback function. 
  279. 			if idx == transition_callback_idx then 
  280. 				-- only setup the action callback for the screen we are transitioning to... 
  281. 				-- this is to maintain vint context of the lua function call to that document. 
  282. 				vint_set_property(anchor_twn_h, "end_event", "cell_transition_action_cb") 
  283. 			else 
  284. 				--callback to make sure we cleanup the animation when we are finished. 
  285. 				vint_set_property(anchor_twn_h, "end_event", "cell_transition_delete_cb") 
  286. 			end 
  287. 			 
  288. 			--Get and set properties based on our start/end data. 
  289. 			vint_set_property(anchor_twn_h, 		"start_value", 	start_data.x, 	start_data.y) 
  290. 			vint_set_property(anchor_twn_h, 		"end_value", 		end_data.x, 	end_data.y) 
  291. 			vint_set_property(rotation_twn_h, 	"start_value", 	start_data.r) 
  292. 			vint_set_property(rotation_twn_h, 	"end_value", 		end_data.r) 
  293. 			vint_set_property(scale_twn_h, 		"start_value", 	start_data.s, 	start_data.s) 
  294. 			vint_set_property(scale_twn_h, 		"end_value", 		end_data.s, 	end_data.s) 
  295. 			 
  296. 			if end_state == CELL_STATE_OUT_PORTRAIT or end_state == CELL_STATE_OUT_LANDSCAPE then 
  297. 				vint_set_property(anchor_twn_h, 	"algorithm", "ease_out_quart") 
  298. 				vint_set_property(rotation_twn_h,"algorithm", "ease_out_quart") 
  299. 				vint_set_property(scale_twn_h, 	"algorithm", "ease_out_quart") 
  300. 			end 
  301. 			 
  302. 			-- Play animation... 
  303. 			vint_apply_start_values(anim_clone_h) 
  304. 			lua_play_anim(anim_clone_h, 0, doc_h) 
  305. 			 
  306. 			 
  307. 			--Play incomming screens transition animation 
  308. 			if idx == 1 then 
  309. 				--Pause out animation 
  310. 				local trans_out_anim_h = vint_object_find("trans_out_anim", 0, doc_h) 
  311. 				if trans_out_anim_h ~= 0 then 
  312. 					vint_set_property(trans_out_anim_h, "is_paused", true) 
  313. 				end 
  314. 				--Play in animation... 
  315. 				local trans_in_anim_h = vint_object_find("trans_in_anim", 0, doc_h) 
  316. 				if trans_in_anim_h ~= 0 then 
  317. 					lua_play_anim(trans_in_anim_h, 0, doc_h) 
  318. 				end 
  319. 	 
  320. 				 
  321. 				if screen1 == CELL_SCREEN_MAIN or screen1 == CELL_SCREEN_EXTRAS or screen1 == CELL_SCREEN_MUSIC_SUB then 
  322. 					--need to play hide top bar anim... 
  323. 					if start_state ~= end_state then 
  324. 						if end_state == CELL_STATE_PORTRAIT then 
  325. 							--fade in header 
  326. 							cell_foreground_fade_in_header() 
  327. 						else 
  328. 							--fade out header 
  329. 							cell_foreground_fade_out_header() 
  330. 						end 
  331. 					end 
  332. 				end 
  333. 			end 
  334. 			 
  335. 			if idx == 3 then 
  336. 				local bg_rotate_h = vint_object_find("bg_rotate",0,Cell_background_doc) 
  337. 				--bg rotation over ride 
  338. 				if start_state ~= end_state then 
  339. 					if (start_state == CELL_STATE_LANDSCAPE or start_state == CELL_STATE_START_PORTRAIT) and end_state == CELL_STATE_PORTRAIT then 
  340. 						vint_set_property(bg_rotate_h, 	"rotation", 	(-35 * DEG_TO_RAD)) 
  341. 					elseif (start_state == CELL_STATE_PORTRAIT or start_state == CELL_STATE_START_LANDSCAPE) and end_state == CELL_STATE_LANDSCAPE then 
  342. 						vint_set_property(bg_rotate_h, 	"rotation", 	(55 * DEG_TO_RAD)) 
  343. 					end 
  344. 				end 
  345. 			end 
  346. 			 
  347. 			--Play outgoing screens transition animation 
  348. 			if idx == 4 then 
  349. 				--Pause in animation 
  350. 				local trans_in_anim_h = vint_object_find("trans_in_anim", 0, doc_h) 
  351. 				if trans_in_anim_h ~= 0 then 
  352. 					vint_set_property(trans_in_anim_h, "is_paused", true) 
  353. 				end 
  354. 				--Play out animation 
  355. 				local trans_out_anim_h = vint_object_find("trans_out_anim", 0, doc_h) 
  356. 				if trans_out_anim_h ~= 0 then 
  357. 					lua_play_anim(trans_out_anim_h, 0, doc_h) 
  358. 				end 
  359. 				 
  360. 				if screen2 == CELL_SCREEN_MAIN or screen2 == CELL_SCREEN_EXTRAS or screen2 == CELL_SCREEN_MUSIC_SUB  then 
  361. 					--need to play hide top bar anim... 
  362. 					if start_state ~= end_state then 
  363. 						if screen.end_state == CELL_STATE_PORTRAIT then 
  364. 							--fade in header 
  365. 							cell_foreground_fade_in_header() 
  366. 						else 
  367. 							--fade out header 
  368. 							cell_foreground_fade_out_header() 
  369. 						end 
  370. 					end 
  371. 				end 
  372. 			end 
  373. 			 
  374. 			--PLAY AUDIO 
  375. 			if idx == 1 then 
  376. 				if start_state == CELL_STATE_LANDSCAPE and end_state == CELL_STATE_PORTRAIT then 
  377. 					game_UI_audio_play("UI_Cell_Switch_Horizontal") 
  378. 				elseif start_state == CELL_STATE_PORTRAIT and end_state == CELL_STATE_LANDSCAPE then 
  379. 					game_UI_audio_play("UI_Cell_Switch_Vertical") 
  380. 				end 
  381. 			end 
  382.  
  383. 		end 
  384. 	end 
  385. 	 
  386. 	--Store callback function to global 
  387. 	if callback_func ~= nil then 
  388. 		Cell_transition_cb_func = callback_func 
  389. 	else 
  390. 		Cell_transition_cb_func = -1 
  391. 	end 
  392.  
  393. 	--Store current state. 
  394. 	Cell_current_state = target_state 
  395. end 
  396.  
  397. function cell_foreground_cash_update(di_h) 
  398. 	local cash = vint_dataitem_get(di_h) 
  399. 	local cash_txt = Vdo_base_object:new("cash",0, Cell_foreground_doc) 
  400. 	cash_txt:set_text("$" .. format_cash(cash))	 
  401. end 
  402.  
  403. function cell_foreground_respect_update(di_h) 
  404. 	local respect_total, respect_needed, respect_level, show_upgrades = vint_dataitem_get(di_h) 
  405. 	local respect_txt = Vdo_base_object:new("respect",0, Cell_foreground_doc) 
  406. 	respect_txt:set_text(respect_level + 1)	 
  407. end 
  408.  
  409. ------------------------------------------------------------------------------- 
  410. -- Callback functions for tweens.  
  411. -- 1. Destroys its parent anim. 
  412. --  
  413. function cell_transition_delete_cb(tween_h) 
  414. 	vint_object_destroy(vint_object_parent(tween_h)) 
  415. end 
  416.  
  417. -- Callback functions for tweens.  
  418. -- 1. Destroys its parent anim. 
  419. -- 2. Does callback that was stored in the global from our last transition.  
  420. -- 3. Wipes the callback out so other tweens don't call it. 
  421. function cell_transition_action_cb(tween_h) 
  422. 	vint_object_destroy(vint_object_parent(tween_h)) 
  423. 	 
  424. 	--Do cell transition callback if it exists the reset it. 
  425. 	if Cell_transition_cb_func ~= -1 then 
  426. 		Cell_transition_cb_func() 
  427. 		Cell_transition_cb_func = -1 
  428. 	end 
  429. end 
  430.  
  431. ------------------------------------------------------------------------------- 
  432. -- Fades in the header(battery, power) 
  433. -- 
  434. function cell_foreground_fade_in_header() 
  435. 	lua_play_anim(vint_object_find("in_header_anim", 0, Cell_foreground_doc), 0, Cell_foreground_doc) 
  436. end 
  437.  
  438. ------------------------------------------------------------------------------- 
  439. -- Fades out the header(battery, power) 
  440. -- 
  441. function cell_foreground_fade_out_header() 
  442. 	lua_play_anim(vint_object_find("out_header_anim", 0, Cell_foreground_doc), 0, Cell_foreground_doc) 
  443. end 
  444.  
  445. function cell_show_frame() 
  446. 	vint_set_property(Cell_foreground_h, "visible", true) 
  447. 	vint_set_property(Cell_background_h, "visible", true) 
  448. end 
  449.  
  450. ------------------------------------------------------------------------------- 
  451. -- Get ping every 2 seconds until cell phone is closed 
  452. -- 
  453. function cell_foreground_ping_thread() 
  454. 	while true do 
  455. 		cell_forground_set_ping(game_get_coop_ping())		 
  456. 		delay(2) 
  457. 	end 
  458. end 
  459.  
  460. ------------------------------------------------------------------------------- 
  461. -- Sets connection strength for coop PC 
  462. -- 
  463. function cell_forground_set_ping(ping) 
  464. 	local ping_grp_h = vint_object_find("ping_grp", 0 , Cell_foreground_doc) 
  465. 	local ping_txt_h = vint_object_find("ping_txt", 0, Cell_foreground_doc) 
  466. 	local bars = {} 
  467. 	local num_bars = 0 
  468. 	local color = COLOR_PING_GREY 
  469.  
  470. 	vint_set_property(ping_txt_h, "text_tag", ping.." ms ") 
  471. 		 
  472. 	-- turn all bars "off" 
  473. 	for i = 1, 5 do 
  474. 		local h = vint_object_find("bar_img_"..i, ping_grp_h, Cell_foreground_doc) 
  475. 		vint_set_property(h, "alpha", .33)				 
  476. 		bars[i] = h 
  477. 	end 
  478. 	 
  479. 	-- determing how many bars and what color to show 
  480. 	if ping <= PING_GREEN then 
  481. 		if ping < 100 then 
  482. 			num_bars = 5 
  483. 		else 
  484. 			num_bars = 4 
  485. 		end		 
  486. 		 
  487. 		color = COLOR_PING_GREEN		 
  488. 	elseif ping > PING_GREEN and ping < PING_RED then 
  489. 		num_bars = 3		 
  490. 	 
  491. 		color = COLOR_PING_YELLOW		 
  492. 	else 
  493. 		if ping < 400 then 
  494. 			num_bars = 2 
  495. 		else 
  496. 			num_bars = 1 
  497. 		end 
  498. 		 
  499. 		color = COLOR_PING_RED 
  500. 		 
  501. 		if ping > 999 then 
  502. 			vint_set_property(ping_txt_h, "text_tag", "999 ms ") 
  503. 		end 
  504. 	end 
  505. 	 
  506. 	-- turn bars "on" 
  507. 	for i = 1, num_bars do 
  508. 		vint_set_property(bars[i], "alpha", 1)	 
  509. 	end 
  510. 	 
  511. 	--set color and show grp 
  512. 	vint_set_property(ping_grp_h,"tint", color.R, color.G, color.B) 
  513. 	vint_set_property(ping_grp_h,"visible", true) 
  514. end 
  515.