./cell_phone.lua

  1. local Data = { } 
  2. Num_items = 0 
  3.  
  4. --Input Trackers... 
  5. local Input_tracker = -1 
  6. local Input_tracker_garage = -1 
  7. local Input_tracker_call = -1 
  8. local Mouse_input_tracker = -1 
  9. local Mouse_input_tracker_garage = -1 
  10. local Mouse_input_tracker_garage_hint = -1 
  11. local Mouse_input_tracker_call = -1 
  12.  
  13. local List = nil 
  14. local Call_grp 
  15. local Cell_phone_handle = -1 
  16.  
  17. local MOUSE_INVALID_HANDLE = -1 
  18.  
  19. local Homie_data = {} 
  20. local Homie_data_cur_idx = 1 
  21. local HOMIE_MAX_ITEMS = 5 
  22. local Book_screen_is_scrolling = false 
  23.  
  24. local Hint_bar = -1 
  25. local Garage_hint_bar = -1 
  26.  
  27. local Visible_start_idx = 1 
  28. local Visible_end_idx = HOMIE_MAX_ITEMS 
  29. local Prev_y = -1 
  30.  
  31. CELL_PHONE_BOOK_MAX_WIDTH_LABEL = 224	--Max label width for the phone 
  32. CELL_PHONE_CALL_MAX_WIDTH_LABEL = 259	--Max label width for the calling screen. 
  33.  
  34. -- Enum to define which type of data to retrieve 
  35. local CELL_HOMIE_LIST	= 0 
  36. local CELL_VEHICLE_LIST	= 1 
  37.  
  38. --Connection States 
  39. local CELL_CALL_INVALID 			= -1 
  40. local CELL_CALL_CONNECTED 			= 0 
  41. local CELL_CALL_GARAGE_SHOW 		= 1 
  42.  
  43. --Hangup states 
  44. local CELL_CALL_HANGUP 				= 0 
  45. local CELL_CALL_RETURN_TO_PHONE 	= 1 
  46.  
  47. --Transition enums... 
  48. local CELL_MENU_TRANS_NONE 	= 0 
  49. local CELL_MENU_TRANS_LEFT 	= 1 
  50. local CELL_MENU_TRANS_RIGHT 	= 2 
  51.  
  52. -- Enums for pages on the phone... 
  53. local CELL_PHONE_MENU_BOOK			= 1 
  54. local CELL_PHONE_MENU_GARAGE		= 2 
  55. local CELL_PHONE_MENU_CALL			= 3 
  56.  
  57. --Layout constansts 
  58. local LIST_COLOR_HIGHLIGHT 	= COLOR_SAINTS_PURPLE 
  59. local LIST_COLOR_UNHIGHLIGHT	= {R=80/255,G=80/255,B=80/255} --COLOR_PLAYER_CREATION_TERTIARY 
  60. local LIST_COLOR_DISABLED 		= {R=30/255,G=30/255,B=30/255} 
  61.  
  62. local HOMIE_LIST_SPACING = 74		--Spacing between items 
  63. local GARAGE_LIST_WIDTH = 420		--Spacing between items 
  64.  
  65. local Cell_menus = {} 
  66.  
  67. local Menu_active = -1		--Active menu ID... 
  68.  
  69. --Garage stuff 
  70. Garage_list = -1					--VDO reference to garage list 
  71. local Garage_list_data = {}	--Data for garage list... 
  72. local GARAGE_LIST_MAX_BUTTONS = 8 
  73.  
  74. local Cell_phone_cash = -1 
  75.  
  76. local Scrollbar = -1 
  77.  
  78. local Screen_start_x 
  79. local Screen_start_y  
  80.  
  81. local Game_platform 
  82.  
  83. local Current_menu = -1 
  84. local HOMIE_MENU = 0 
  85. local GARAGE_MENU = 1 
  86.  
  87. local Highlight_btn = -1 
  88.  
  89. local Cell_phone_gamepad_listener = -1 
  90.  
  91. function cell_phone_init() 
  92. 	Cell_phone_handle = vint_document_find("cell_phone") 
  93.  
  94. 	--Initialize list... 
  95. 	local contact_highlight_grp_h = vint_object_find("contact_highlight_grp") 
  96. 	local highlight_bg_h = vint_object_find("highlight_bg", contact_highlight_grp_h) 
  97. 	vint_set_property(highlight_bg_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B) 
  98. 	 
  99. 	--Set button on contact list... 
  100. 			 
  101. 	--if pc then hide ctrl button 
  102. 	Highlight_btn = Vdo_hint_button:new("highlight_btn", contact_highlight_grp_h) 
  103. 	 
  104. 	Highlight_btn:set_button(CTRL_MENU_BUTTON_A) 
  105. 	 
  106. 	--Set text for vehicle delivery 
  107. 	vint_set_property(vint_object_find("calling_info_txt_1"),"text_tag", "HOMIES_DRIVEUP") 
  108. 	 
  109. 	--Set up title 
  110. 	local cell_title_h = Vdo_cell_title:new("cell_title", 0, Cell_phone_handle) 
  111. 	cell_title_h:set_text("MENU_PHONE") 
  112. 	cell_title_h:set_icon("ui_cell_icon_phone") 
  113. 	cell_title_h:play_dots_anim() 
  114. 	 
  115. 	--Show screens... 
  116. 	local call_screen_grp_h = vint_object_find("call_screen_grp") 
  117. 	local book_screen_grp_h = vint_object_find("book_screen_grp") 
  118. 	local garage_screen_grp_h = vint_object_find("garage_screen_grp") 
  119. 	vint_set_property(call_screen_grp_h, "visible", false) 
  120. 	--vint_set_property(garage_screen_grp_h, "anchor", 0, -203) 
  121. 	vint_set_property(garage_screen_grp_h, "visible", false) 
  122. 	vint_set_property(book_screen_grp_h, "visible", true) 
  123.  
  124. 	Screen_start_x, Screen_start_y = vint_get_property(call_screen_grp_h, "anchor") 
  125.  
  126. 	--Garage list init... 
  127. 	Garage_list = Vdo_mega_list:new("mega_list", 0, Cell_phone_handle, "cell_phone.lua", "Garage_list") 
  128. 	Garage_list:set_properties(LIST_COLOR_HIGHLIGHT, LIST_COLOR_UNHIGHLIGHT, 10, .8, GARAGE_LIST_WIDTH, false, true) 
  129. 	Garage_list:set_highlight_color(LIST_COLOR_HIGHLIGHT, LIST_COLOR_UNHIGHLIGHT) 
  130. 	 
  131. 	-- Subscribe to the button presses we need... 
  132. 	Input_tracker = Vdo_input_tracker:new() 
  133. 	Input_tracker:add_input("nav_up", 	"cell_phone_book_nav_up", 	50) 
  134. 	Input_tracker:add_input("nav_down", "cell_phone_book_nav_down", 	50)	 
  135. 	Input_tracker:add_input("back", 		"cell_phone_book_button_b", 	50) 
  136. 	Input_tracker:add_input("select", 	"cell_phone_book_button_a", 		50) 
  137. 	Input_tracker:add_input("map", 		"cell_phone_book_button_map", 	50) 
  138. 	Input_tracker:subscribe(false) 
  139. 	 
  140. 	--Input tracker for garage menu 
  141. 	Input_tracker_garage = Vdo_input_tracker:new() 
  142. 	Input_tracker_garage:add_input("nav_up", 		"cell_phone_garage_nav_up", 		50) 
  143. 	Input_tracker_garage:add_input("nav_down", 	"cell_phone_garage_nav_down", 	50)	 
  144. 	Input_tracker_garage:add_input("back", 		"cell_phone_garage_button_b", 	50) 
  145. 	Input_tracker_garage:add_input("select", 		"cell_phone_garage_button_a", 	50) 
  146. 	Input_tracker_garage:add_input("map", 			"cell_phone_garage_map", 			50) 
  147. 	Input_tracker_garage:subscribe(false) 
  148. 	 
  149. 	--Input tracker for garage menu 
  150. 	Input_tracker_call = Vdo_input_tracker:new() 
  151. 	Input_tracker_call:add_input("nav_up", 		"cell_phone_call_input", 		50) 
  152. 	Input_tracker_call:add_input("nav_down", 		"cell_phone_call_input", 		50)	 
  153. 	Input_tracker_call:add_input("back", 			"cell_phone_call_input",		50) 
  154. 	Input_tracker_call:add_input("select", 		"cell_phone_call_input",		50) 
  155. 	Input_tracker_call:add_input("map", 			"cell_phone_call_input",		50) 
  156. 	Input_tracker_call:subscribe(false) 
  157. 	 
  158. 	--Init scrollbar... 
  159. 	Scrollbar = Vdo_scrollbar:new("book_scrollbar")	 
  160. 	Scrollbar:set_highlight_color(LIST_COLOR_HIGHLIGHT) 
  161. 	 
  162. 	--Hint bar 
  163. 	Hint_bar 			= Vdo_hint_bar:new("hint_bar") 
  164. 	Garage_hint_bar	= Vdo_hint_bar:new("garage_hint_bar") 
  165. 	 
  166. 	local hints = { 
  167. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  168. 	} 
  169. 	 
  170. 	Hint_bar:set_hints(hints) 
  171. 	Garage_hint_bar:set_hints(hints) 
  172. 	 
  173. 	--setup call hintbar... 
  174. 	hints = { 
  175. 		{CTRL_MENU_BUTTON_A, "MENU_CONTINUE"}, 
  176. 	}	 
  177.  
  178. 	Game_platform = game_get_platform() 
  179. 	 
  180. 	local mouse_area_img_h = vint_object_find("mouse_area_img") 
  181. 	--create mouse input tracker and send it to the scrollbar vdo 
  182. 	if Game_platform == "PC" then 
  183. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  184. 		Mouse_input_tracker_garage = Vdo_input_tracker:new() 
  185. 		Mouse_input_tracker_garage_hint = Vdo_input_tracker:new() 
  186. 		Mouse_input_tracker_call = Vdo_input_tracker:new() 
  187. 		 
  188. 		Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_phone_mouse_scroll", 50, mouse_area_img_h) 
  189. 		 
  190. 		Hint_bar:add_mouse_inputs("cell_phone", Mouse_input_tracker, 50) 
  191. 		Scrollbar:add_mouse_inputs("cell_phone",Mouse_input_tracker,50) 
  192. 		Garage_hint_bar:add_mouse_inputs("cell_phone",Mouse_input_tracker_garage_hint,50) 
  193. 		 
  194. 		Mouse_input_tracker:subscribe(true)	 
  195. 		Mouse_input_tracker_garage:subscribe(false) 
  196. 		Mouse_input_tracker_garage_hint:subscribe(false) 
  197. 		Mouse_input_tracker_call:subscribe(false) 
  198. 	end 
  199. 	 
  200. 	--Setup object for our menu functions and handling input... 
  201. 	Cell_menus = { 
  202. 		[CELL_PHONE_MENU_BOOK]		=	{h = book_screen_grp_h, input_tracker = Input_tracker, mouse_input_tracker = Mouse_input_tracker, hint_input_tracker = nil}, 
  203. 		[CELL_PHONE_MENU_GARAGE] 	= 	{h = garage_screen_grp_h, input_tracker = Input_tracker_garage, mouse_input_tracker = Mouse_input_tracker_garage, hint_input_tracker = Mouse_input_tracker_garage_hint}, 
  204. 		[CELL_PHONE_MENU_CALL]	 	= 	{h = 	call_screen_grp_h, input_tracker = Input_tracker_call, mouse_input_tracker = Mouse_input_tracker_call, hint_input_tracker = nil}, 
  205. 	} 
  206. 	 
  207. 	--Subscribe to player information for cash data 
  208. 	vint_dataitem_add_subscription("sr2_local_player_status_infrequent", "update", "cell_phone_cash_update") 
  209.  
  210. 	-- Populate homie call list 
  211. 	vint_dataresponder_request("cell_phone_pad_populate", "cell_phone_populate_list", 0, CELL_HOMIE_LIST)	 
  212. 	 
  213. 	if #Homie_data == 0 then 
  214. 		-- No homie data... we need to abort this screen 
  215. 		debug_print("vint", "no homie data... cannot enter cellphone\n") 
  216. 		cell_phone_exit(false) 
  217. 		local safe_h = vint_object_find("safe_frame") 
  218. 		vint_set_property(safe_h, "visible", false) 
  219. 		return 
  220. 	end 
  221. 	 
  222. 	-- Build Phonebook Screen 
  223. 	cell_phone_book_build() 
  224.  
  225. 	--Transition the screen in... 
  226. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_PHONE, CELL_SCREEN_MAIN, cell_phone_menu_trans_in_complete) 
  227. 	 
  228. 	if Game_platform == "PC" then 
  229. 		Cell_phone_gamepad_listener = vint_scriptevent_listen( "gamepad_active", "cell_phone_update_gamepad_state" ) 
  230. 	end 
  231. end 
  232.  
  233. function cell_phone_cleanup() 
  234. 	if Game_platform == "PC" then 
  235. 		vint_scriptevent_stop_listening( Cell_phone_gamepad_listener ) 
  236. 	end 
  237. 	 
  238. 	if Input_tracker ~= -1 then 
  239. 		Input_tracker:subscribe(false) 
  240. 		Input_tracker:remove_all() 
  241. 	end 
  242. 	 
  243. 	if Input_tracker_garage ~= -1 then 
  244. 		Input_tracker_garage:subscribe(false) 
  245. 		Input_tracker_garage:remove_all() 
  246. 	end 
  247. 	 
  248. 	if Input_tracker_call ~= -1 then 
  249. 		Input_tracker_call:subscribe(false) 
  250. 		Input_tracker_call:remove_all() 
  251. 	end 
  252. 	 
  253. 	if Mouse_input_tracker ~= -1 then 
  254. 		Mouse_input_tracker:subscribe(false) 
  255. 		Mouse_input_tracker:remove_all() 
  256. 	end 
  257. 	 
  258. 	if Mouse_input_tracker_garage ~= -1 then 
  259. 		Mouse_input_tracker_garage:subscribe(false) 
  260. 		Mouse_input_tracker_garage:remove_all() 
  261. 	end 
  262. 	 
  263. 	if Mouse_input_tracker_garage_hint ~= -1 then 
  264. 		Mouse_input_tracker_garage_hint:subscribe(false) 
  265. 		Mouse_input_tracker_garage_hint:remove_all() 
  266. 	end 
  267. 	 
  268. 	if Mouse_input_tracker_call ~= -1 then 
  269. 		Mouse_input_tracker_call:subscribe(false) 
  270. 		Mouse_input_tracker_call:remove_all() 
  271. 	end 
  272. end 
  273.  
  274. function cell_phone_menu_trans_in_complete() 
  275. 	--Show homies menu... 
  276. 	cell_phone_menu_show(CELL_PHONE_MENU_BOOK) 
  277. end 
  278.  
  279. --Transitions to a specific menu... 
  280.  
  281. function cell_phone_menu_show(menu_id, direction) 
  282.  
  283. 	--simply show the current menu id... 
  284. 	for i = 1, #Cell_menus do 
  285. 		local h = Cell_menus[i].h 
  286. 		vint_set_property(h, "visible", false) 
  287.  
  288. 		--Switch to the proper input tracker... 
  289. 		--unsubscribe all menus because we need to wait for transition... and then put subscribe in AFTER the transition callback... 
  290. 		local input_tracker = Cell_menus[i].input_tracker		 
  291. 		input_tracker:subscribe(false) 
  292.  
  293. 		if Game_platform == "PC" then 
  294. 			local mouse_input_tracker = Cell_menus[i].mouse_input_tracker 
  295. 			mouse_input_tracker:subscribe(false) 
  296. 			 
  297. 			local hint_input_tracker = Cell_menus[i].hint_input_tracker 
  298. 			if hint_input_tracker ~= nil then 
  299. 				hint_input_tracker:subscribe(false) 
  300. 			end 
  301. 		end 
  302. 	end 
  303.  
  304.  
  305. 	if Menu_active == -1 then 
  306. 		 
  307. 		--No transition allowed... 
  308. 		--Just do callback.. 
  309. 		local input_tracker = Cell_menus[menu_id].input_tracker 
  310. 		input_tracker:subscribe(true) 
  311. 			 
  312. 		if Game_platform == "PC" then 
  313. 			local mouse_input_tracker = Cell_menus[menu_id].mouse_input_tracker 
  314. 			mouse_input_tracker:subscribe(true) 
  315. 			 
  316. 			local hint_input_tracker = Cell_menus[menu_id].hint_input_tracker 
  317. 			if hint_input_tracker ~= nil then 
  318. 				hint_input_tracker:subscribe(true) 
  319. 			end 
  320. 		end 
  321. 		 
  322. 		local h = Cell_menus[menu_id].h 
  323. 		vint_set_property(h, "visible", true) 
  324. 	else 
  325. 		local h = Cell_menus[menu_id].h 
  326. 		local previous_menu_id = Menu_active 
  327. 		local prev_h = Cell_menus[previous_menu_id].h 
  328. 		 
  329. 		-- show the two menus we are gonna transition... 
  330. 		vint_set_property(prev_h, "visible", true) 
  331. 		vint_set_property(h, "visible", true) 
  332. 		 
  333. 		local menu_width = 365 + 10 
  334. 		--Always transition left for now... 
  335. 		--vint_set_property(prev_h, "anchor", Screen_start_x, Screen_start_y) 
  336. 		--vint_set_property(h, "anchor", menu_width, 0) 
  337. 		 
  338. 		local left_h 	= prev_h  
  339. 		local right_h 	= h  
  340. 		 
  341. 		if direction == CELL_MENU_TRANS_NONE or direction == nil then 
  342. 			vint_set_property(prev_h, "visible", false) 
  343. 			menu_width = 0 
  344. 		elseif direction == CELL_MENU_TRANS_LEFT then 
  345. 			menu_width = - menu_width 
  346. 		elseif direction == CELL_MENU_TRANS_RIGHT then 
  347. 			 
  348. 		end 
  349. 		 
  350. 		local cell_screen_trans_anim_h = vint_object_find("cell_screen_trans_anim") 
  351. 		local left_twn_h = vint_object_find("trans_left_twn", cell_screen_trans_anim_h) 
  352. 		local right_twn_h = vint_object_find("trans_right_twn", cell_screen_trans_anim_h) 
  353. 		 
  354. 		vint_set_property(left_twn_h, "start_value", 	1) 
  355. 		vint_set_property(left_twn_h, "end_value",	 	0) 
  356. 		vint_set_property(right_twn_h, "start_value", 	0) 
  357. 		vint_set_property(right_twn_h, "end_value", 		1) 
  358. 		 
  359. 		--[[ 
  360. 		vint_set_property(left_twn_h, "start_value", 	Screen_start_x , 					Screen_start_y) 
  361. 		vint_set_property(left_twn_h, "end_value",	 	Screen_start_x - menu_width, 	Screen_start_y) 
  362. 		vint_set_property(right_twn_h, "start_value", 	Screen_start_x + menu_width , Screen_start_y) 
  363. 		vint_set_property(right_twn_h, "end_value", 		Screen_start_x , 					Screen_start_y) 
  364. 		]] 
  365. 		vint_set_property(right_twn_h, "target_handle", right_h) 
  366. 		vint_set_property(left_twn_h, "target_handle", left_h) 
  367. 		  
  368. 		vint_set_property(left_twn_h, "end_event", "cell_phone_menu_trans_cb") 
  369. 		lua_play_anim(cell_screen_trans_anim_h) 
  370. 	end 
  371.  
  372. 	 
  373. 	Menu_active = menu_id 
  374. end 
  375.  
  376. ------------------------------------------------------------------------------- 
  377. -- Gets called after we transition a menu, via tween callback.. 
  378. ------------------------------------------------------------------------------- 
  379. function cell_phone_menu_trans_cb() 
  380. 	-- menu is displaying... now subscribe to its input... 
  381. 	local input_tracker = Cell_menus[Menu_active].input_tracker 
  382. 	input_tracker:subscribe(true) 
  383.  
  384. 	if Game_platform == "PC" then 
  385. 		local mouse_input_tracker = Cell_menus[Menu_active].mouse_input_tracker 
  386. 		mouse_input_tracker:subscribe(true)	 
  387. 	end 
  388. 	 
  389. 	if Game_platform == "PC" then 
  390. 		local hint_input_tracker = Cell_menus[Menu_active].hint_input_tracker 
  391. 		if hint_input_tracker ~= nil then 
  392. 			hint_input_tracker:subscribe(true) 
  393. 		end 
  394. 	end	 
  395. end 
  396.  
  397. ------------------------------------------------------------------------------- 
  398. -- Connection callback... 
  399. -- This gets called after we dial... 
  400. -- @param success	 
  401. ------------------------------------------------------------------------------- 
  402. function cell_phone_dial_connection_cb(success) 
  403. 	debug_print("vint", "cell_phone_dial_connection_cb()\n") 
  404. 	debug_print("vint", "success" .. var_to_string(success) .. "\n") 
  405. 	 
  406. 	if success == CELL_CALL_INVALID then 
  407. 		--wrong number 
  408. 		--use invalid number screen 
  409. 		--DON'T DO ANYTHING... 
  410. 		cell_phone_call_build(true) 
  411. 		cell_phone_menu_show(CELL_PHONE_MENU_CALL, CELL_MENU_TRANS_RIGHT) 
  412. 	elseif success == CELL_CALL_CONNECTED then 
  413. 		--Connection has been made, string of store name to display is stored in name 
  414. 		cell_phone_call_build(false) 
  415. 		cell_phone_menu_show(CELL_PHONE_MENU_CALL, CELL_MENU_TRANS_RIGHT) 
  416. 	elseif success  == CELL_CALL_GARAGE_SHOW then 
  417. 		--Show garage... 
  418. 		--build garage menu here... 
  419. 		local success = cell_phone_garage_build() 
  420. 		if success == false then 
  421. 			cell_phone_garage_no_vehicles_dialog() 
  422. 			debug_print("vint", "you need vehicles in your garage to access this feature\n") 
  423. 			return 
  424. 		end 
  425. 		 
  426. 		--Show it... 
  427. 		cell_phone_menu_show(CELL_PHONE_MENU_GARAGE, CELL_MENU_TRANS_RIGHT) 
  428. 	end 
  429. end 
  430.  
  431. ------------------------------------------------------------------------------- 
  432. -- Builds the phone book 
  433. ------------------------------------------------------------------------------- 
  434. function cell_phone_book_build() 
  435. 	local book_screen_grp_h = vint_object_find("book_screen_grp") 
  436. 	 
  437. 	--Base contact handle and hide... 
  438. 	local contact_grp_h = vint_object_find("contact_grp", book_screen_grp_h) 
  439. 	vint_set_property(contact_grp_h, "visible", false) 
  440.  
  441. 	local homie_count = #Homie_data  
  442. 	for i = 1, homie_count do 
  443. 		--get data out of table... 
  444. 		local homie_index = Homie_data[i].homie_index 
  445. 		local homie_name_crc = Homie_data[i].homie_name_crc 
  446. 		local description_crc = Homie_data[i].description_crc 
  447. 		local image_crc = Homie_data[i].image_crc 
  448. 		local is_available = Homie_data[i].is_available 
  449. 		 
  450. 		--clone base item... 
  451. 		local h = vint_object_clone(contact_grp_h) 
  452. 		 
  453. 		--Set Text 
  454. 		local name_txt_h = vint_object_find("name_txt", h) 
  455. 		vint_set_property(name_txt_h, "text_tag_crc", homie_name_crc) 
  456. 		 
  457. 		resize_text_element(name_txt_h, CELL_PHONE_BOOK_MAX_WIDTH_LABEL) 
  458. 		 
  459. 				 
  460. 		--Set icon 
  461. 		local homie_icon_h = vint_object_find("homie_icon", h) 
  462. 		vint_set_property(homie_icon_h, "image_crc", image_crc) 
  463. 		 
  464. 		--Position Homie in list... 
  465. 		local x, y = vint_get_property(h, "anchor") 
  466. 		y = ( (i - 1) * HOMIE_LIST_SPACING ) 
  467. 		vint_set_property(h, "anchor", x, y ) 
  468. 		 
  469. 		--Show homie in list... 
  470. 		vint_set_property(h, "visible", true) 
  471. 		 
  472. 		if is_available == true then 
  473. 			--Reset to normal... 
  474. 			vint_set_property(h, "alpha", 1) 
  475. 			vint_set_property(homie_icon_h, "saturation", 1) 
  476. 		else 
  477. 			--Grey out homie in list... 
  478. 			vint_set_property(h, "alpha", .333) 
  479. 			vint_set_property(homie_icon_h, "saturation", 0) 
  480. 		end 
  481.  
  482. 		if Game_platform == "PC" then 
  483. 			Mouse_input_tracker:add_mouse_input("mouse_move", "cell_phone_mouse_move", 50, h) 
  484. 			Mouse_input_tracker:add_mouse_input("mouse_click", "cell_phone_mouse_click", 50, h)			 
  485. 		end 
  486. 		 
  487. 		--Store handle of cloned object into homie table... 
  488. 		Homie_data[i].h = h 
  489. 	end 
  490. 	 
  491. 	if Game_platform == "PC" then 
  492. 		Mouse_input_tracker:subscribe(true) 
  493. 	end 
  494. 	 
  495. 	--do we need scrollbar? 
  496. 	 
  497. 	-- Handle scrolling 
  498. 	if(homie_count > HOMIE_MAX_ITEMS) then 
  499. 		--show the scroll bar 
  500. 		Scrollbar:set_property("visible", true) 
  501. 		 
  502. 		local clip_height = HOMIE_LIST_SPACING + ((HOMIE_MAX_ITEMS - 1) * HOMIE_LIST_SPACING) 
  503. 		local total_height = homie_count * HOMIE_LIST_SPACING 
  504. 		Scrollbar:set_size(SCROLLBAR_WIDTH, clip_height, total_height)		 
  505. 	else 
  506. 		--show the scroll bar 
  507. 		Scrollbar:set_property("visible", false) 
  508. 	end	 
  509. 	 
  510. 	--Find first available homie... 
  511. 	local homie_count = #Homie_data 
  512. 	local is_available = Homie_data[Homie_data_cur_idx].is_available 
  513. 	local is_available_count = 0 
  514. 	local is_available_idx = Homie_data_cur_idx 
  515. 	if is_available == false then 
  516. 		local new_index 
  517. 		while not is_available do 
  518. 			is_available = Homie_data[is_available_idx].is_available 
  519. 			if is_available_count > homie_count then 
  520. 				new_index = Homie_data_cur_idx 
  521. 				is_available = true 
  522. 			end 
  523. 			 
  524. 			new_index = is_available_idx 
  525. 			is_available_count = is_available_count + 1 
  526. 			is_available_idx = is_available_idx + 1 
  527. 			if is_available_idx > homie_count then 
  528. 				is_available_idx = 1 
  529. 			end 
  530. 		end 
  531. 		Homie_data_cur_idx = new_index 
  532. 	end 
  533. 	 
  534. 	--Select item in list... 
  535. 	cell_phone_book_highlight(Homie_data_cur_idx) 
  536. 	 
  537. 	Current_menu = HOMIE_MENU  
  538. end 
  539.  
  540. ------------------------------------------------------------------------------------ 
  541. -- Sets the current highlighted option on the phone book and resets everything else 
  542. -- @param idx					index of item to highlight  
  543. -- @param is_mouse_input	are we using the mouse? 
  544. -- @param is_scrollbar		are we using the scrollbar with the mouse? 
  545. ------------------------------------------------------------------------------------ 
  546. function cell_phone_book_highlight(idx, is_mouse_input, is_scrollbar) 
  547. 	 
  548. 	Homie_data_cur_idx = idx 
  549. 	 
  550. 	local homie_count = #Homie_data  
  551. 	 
  552. 	--if using scrollbar don't update the highlight, just scroll the list 
  553. 	if is_scrollbar ~= true then 
  554. 		local book_screen_grp_h = vint_object_find("book_screen_grp") 
  555. 		 
  556. 		--cant select this if its not available... 
  557. 		local is_available = Homie_data[idx].is_available 
  558. 		 
  559. 		for i = 1, homie_count do 
  560. 		 
  561. 			--Get base group out of homie data... 
  562. 			local h = Homie_data[i].h 
  563. 			local is_available = Homie_data[i].available 
  564. 			local border_grp_h = vint_object_find("border_grp", h) 
  565. 			if i == idx then 
  566. 				--Highlight this option 
  567. 				 
  568. 				--Color border purple 
  569. 				 
  570. 				--Move the highlight bar to indexed location... 
  571. 				local contact_highlight_grp_h = vint_object_find("contact_highlight_grp", book_screen_grp_h) 
  572. 				vint_set_property(contact_highlight_grp_h, "visible", true) 
  573. 				 
  574. 				local x, y = vint_get_property(h, "anchor") 
  575. 				vint_set_property(contact_highlight_grp_h, "anchor", x, y) 
  576. 				 
  577. 				--Change text field of item... 
  578. 				local name_txt_h = vint_object_find("name_txt", contact_highlight_grp_h) 
  579. 				local homie_name_crc = Homie_data[i].homie_name_crc 
  580. 				vint_set_property(name_txt_h, "text_tag_crc", homie_name_crc) 
  581. 				vint_set_property(border_grp_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B) 
  582. 				 
  583. 				--Make sure it fits in the phone... 
  584. 				resize_text_element(name_txt_h, CELL_PHONE_BOOK_MAX_WIDTH_LABEL) 
  585. 				 
  586. 				local highlight_btn_h = vint_object_find("highlight_btn", contact_highlight_grp_h) 
  587. 				 
  588. 				local name_x, name_y = vint_get_property(name_txt_h, "anchor") 
  589. 				if game_is_active_input_gamepad() and Homie_data[i].is_available == true then 
  590. 					vint_set_property(name_txt_h, "anchor", 118, name_y) 
  591. 					vint_set_property(highlight_btn_h, "visible", true) 
  592. 				else 
  593. 					vint_set_property(name_txt_h, "anchor", 85, name_y) 
  594. 					vint_set_property(highlight_btn_h, "visible", false) 
  595. 				end 
  596. 		 
  597. 				--Update description text 
  598. 				local description_crc = Homie_data[i].description_crc 
  599. 				local description_txt_h = vint_object_find("description_txt") 
  600. 				vint_set_property(description_txt_h, "text_tag_crc", description_crc) 
  601. 				vint_set_property(description_txt_h, "visible", true) 
  602. 				 
  603. 				local desc_header_h = vint_object_find("desc_header", 0, Cell_phone_handle) 
  604. 				vint_set_property(desc_header_h, "text_tag_crc", homie_name_crc) 
  605. 				resize_text_element(desc_header_h, 380) 
  606. 				 
  607. 				local highlight_bg_h = vint_object_find("highlight_bg", contact_highlight_grp_h) 
  608. 				if Homie_data[i].is_available == false then 
  609. 					vint_set_property(highlight_bg_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B) 
  610. 					vint_set_property(border_grp_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B) 
  611. 				else 
  612. 					vint_set_property(highlight_bg_h, "tint", LIST_COLOR_HIGHLIGHT.R, LIST_COLOR_HIGHLIGHT.G, LIST_COLOR_HIGHLIGHT.B)					 
  613. 				end 
  614. 				 
  615. 			else 
  616. 				--Color border grey 
  617. 				vint_set_property(border_grp_h, "tint", LIST_COLOR_UNHIGHLIGHT.R, LIST_COLOR_UNHIGHLIGHT.G, LIST_COLOR_UNHIGHLIGHT.B)				 
  618. 			end 
  619. 		end 
  620. 	end 
  621.  
  622. 	local visual_center = ( HOMIE_MAX_ITEMS) 
  623. 	local move_height = HOMIE_LIST_SPACING 
  624. 	local new_y = 0 	 
  625. 	local list_x, list_y = vint_get_property(vint_object_find("contact_list_grp"), "anchor") 
  626. 	 
  627. 	if idx > Visible_end_idx and idx <= homie_count then 
  628. 		Visible_start_idx = idx - (HOMIE_MAX_ITEMS - 1) 
  629. 	elseif idx < Visible_start_idx then 
  630. 		Visible_start_idx = idx 
  631. 		 
  632. 		if Visible_start_idx < 1 then 
  633. 			Visible_start_idx = 1 
  634. 		end 
  635. 	end 
  636. 	 
  637. 	Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1) 
  638. 	new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1) 
  639. 	 
  640. 	local book_scroll_anim_h = vint_object_find("book_scroll_anim") 
  641. 	local book_scroll_twn_h = vint_object_find("book_scroll_twn") 
  642. 	 
  643. 	local contact_list_grp_h = vint_object_find("contact_list_grp") 
  644. 	local start_x, start_y = vint_get_property(contact_list_grp_h, "anchor") 
  645. 	local end_x = start_x 
  646. 	local end_y = new_y 
  647.  
  648. 	vint_set_property(book_scroll_twn_h, "start_value", 	start_x, start_y) 
  649. 	vint_set_property(book_scroll_twn_h, "end_value", 		end_x, 	end_y) 
  650. 	vint_set_property(book_scroll_twn_h, "end_event", "cell_phone_book_scroll_cb") 
  651. 	lua_play_anim(book_scroll_anim_h) 
  652. 	Book_screen_is_scrolling = true 
  653. 	 
  654. 	Prev_y = new_y 
  655. 	 
  656. 	--Adjust scrollbar 
  657. 	Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false ) 
  658. end 
  659.  
  660. ------------------------------------------------------------------------------- 
  661. -- Select 
  662. ------------------------------------------------------------------------------- 
  663. function cell_phone_book_scroll_cb(event) 
  664. 	Book_screen_is_scrolling = false 
  665. end 
  666.  
  667. ------------------------------------------------------------------------- 
  668. -- Populate cellphone homie list 
  669. ------------------------------------------------------------------------------- 
  670. --	@param	index					index of homie_icon 
  671. -- @param	homie_name_crc			crc of homie name 
  672. -- @param	description_crc			crc of the description for homie... 
  673. -- @param	image_crc				image of the homie 
  674. -- @param	is_available			is the homie available? 
  675. function cell_phone_populate_list(homie_index, homie_name_crc, description_crc, image_crc, is_available) 
  676. 	 
  677. 	local idx = #Homie_data + 1 
  678. 	Homie_data[idx] = { 
  679. 		homie_index = homie_index, 
  680. 		homie_name_crc = homie_name_crc, 
  681. 		description_crc = description_crc,  
  682. 		image_crc = image_crc,  
  683. 		is_available = is_available, 
  684. 	} 
  685. end 
  686.  
  687. function cell_phone_book_nav_up(event, acceleration) 
  688.  
  689. 	if Book_screen_is_scrolling == true then 
  690. 		return 
  691. 	end 
  692. 	 
  693. 	--move up 
  694. 	local loop_count = 0 
  695. 	local num_items =  #Homie_data 
  696. 	local stop_loop = true 
  697. 	while stop_loop do 
  698. 		Homie_data_cur_idx = Homie_data_cur_idx - 1 
  699. 			 
  700. 		if Homie_data_cur_idx < 1 then 
  701. 			Homie_data_cur_idx = #Homie_data 
  702. 		end 
  703. 		 
  704. 		stop_loop = false 
  705. 		 
  706. 		if loop_count > num_items then 
  707. 			--Cannot nav... 
  708. 			return 
  709. 		else 
  710. 			loop_count = loop_count + 1 
  711. 		end 
  712. 	end 
  713. 	 
  714. 	--Play sound 
  715. 	game_UI_audio_play("UI_Cell_Nav") 
  716. 	 
  717. 	--Highlight current option... 
  718. 	cell_phone_book_highlight(Homie_data_cur_idx) 
  719. end 
  720.  
  721. function cell_phone_book_nav_down(event, acceleration) 
  722. 	 
  723. 	if Book_screen_is_scrolling == true then 
  724. 		return 
  725. 	end 
  726.  
  727. 	--move down 
  728. 	local loop_count = 0 
  729. 	local num_items =  #Homie_data 
  730. 	local stop_loop = true 
  731. 	while stop_loop do 
  732. 		Homie_data_cur_idx = Homie_data_cur_idx + 1 
  733. 		 
  734. 		if Homie_data_cur_idx > #Homie_data  then 
  735. 			Homie_data_cur_idx = 1 
  736. 		end 
  737. 		 
  738. 		stop_loop = false 
  739. 		 
  740. 		if loop_count > num_items then 
  741. 			--Cannot nav... 
  742. 			return 
  743. 		else 
  744. 			loop_count = loop_count + 1 
  745. 		end 
  746. 	end 
  747. 	 
  748. 	--Play sound 
  749. 	game_UI_audio_play("UI_Cell_Nav") 
  750. 	 
  751. 	--Highlight current option... 
  752. 	cell_phone_book_highlight(Homie_data_cur_idx) 
  753. end 
  754.  
  755.  
  756. function cell_phone_book_button_a(event, acceleration) 
  757. 	if Book_screen_is_scrolling == true then 
  758. 		return 
  759. 	end 
  760. 	--Call homie 
  761. 	local homie_index = Homie_data[Homie_data_cur_idx].homie_index 
  762. 	local is_available = Homie_data[Homie_data_cur_idx].is_available 
  763.  
  764. 	--Check if homie is available and then call if so... 
  765. 	if is_available == true then		 
  766. 		--Lock inputs 
  767. 		Input_tracker:subscribe(false) 
  768. 		if Game_platform == "PC" then 
  769. 			Mouse_input_tracker:subscribe(false)	 
  770. 		end 
  771. 		 
  772. 		--Call homie 
  773. 		cellphone_dial(homie_index, "cell_phone_dial_connection_cb", "cell_phone_call_hangup_cb") 
  774. 		ui_audio_post_event("ui_call_homie")  
  775. 	end 
  776. end 
  777.  
  778. function cell_phone_book_button_b(event, acceleration) 
  779. 	cell_phone_exit(false) 
  780. end 
  781.  
  782. function cell_phone_book_button_map(event, acceleration)	 
  783. 	cell_phone_exit(true) 
  784. end 
  785.  
  786.  
  787. ------------------------------------------------------------------------------- 
  788. -- GARAGE 
  789. ------------------------------------------------------------------------------- 
  790.  
  791. ------------------------------------------------------------------------------- 
  792. -- Builds the garage list 
  793. ------------------------------------------------------------------------------- 
  794. function cell_phone_garage_build() 
  795. 	Garage_list_data = {} 
  796.  
  797. 	if Game_platform == "PC" then 
  798. 		Mouse_input_tracker_garage:remove_all()	 
  799. 	end 
  800.  
  801. 	--Dataresponder to the garage... 
  802. 	vint_dataresponder_request("cell_phone_pad_populate", "cell_phone_garage_populate", 0, CELL_VEHICLE_LIST)	 
  803. 	if #Garage_list_data == 0 then 
  804. 		--no items in list... 
  805. 		return false 
  806. 	end 
  807. 	Garage_list:draw_items(Garage_list_data, 1, GARAGE_LIST_WIDTH, GARAGE_LIST_MAX_BUTTONS) 
  808. 	 
  809. 	if Game_platform == "PC" then 
  810. 		Garage_list:add_mouse_inputs("cell_phone", Mouse_input_tracker_garage, 50)	 
  811. 		Garage_hint_bar:add_mouse_inputs("cell_phone", Mouse_input_tracker_garage_hint, 50) 
  812. 		 
  813. 		Mouse_input_tracker_garage:subscribe(true) 
  814. 		Mouse_input_tracker_garage_hint:subscribe(true) 
  815. 	end 
  816. 	 
  817. 	Current_menu = GARAGE_MENU 
  818. end 
  819.  
  820. function cell_phone_garage_populate(vehicle_index, vehicle_name, repair_cost) 
  821. 	--Add item to list... 
  822. 	local idx = #Garage_list_data + 1 
  823. 	Garage_list_data[idx] = { 
  824. 		type = TYPE_BUTTON, 
  825. 		label 			= vehicle_name, 
  826. 		id 				= 	vehicle_index, 
  827. 		repair_cost 	= 	repair_cost, 
  828. 	} 
  829. end 
  830.  
  831. function cell_phone_garage_no_vehicle_cb() 
  832. 	Input_tracker:subscribe(true) 
  833. 	if Game_platform == "PC" then 
  834. 		Mouse_input_tracker:subscribe(true) 
  835. 	end 
  836. end 
  837.  
  838. function cell_phone_garage_no_vehicles_dialog() 
  839. 	-- TODO: localize 
  840. 	dialog_box_message("CELL_PHONE_NO_VEHICLES", 
  841. 							"CELL_PHONE_MUST_ADD_VEHICLES", 
  842. 							nil, 
  843. 							nil, 
  844. 							"cell_phone_garage_no_vehicle_cb" 
  845. 	) 
  846. end 
  847.  
  848. function cell_phone_garage_map() 
  849. 	-- do nothing 
  850. end 
  851.  
  852. function cell_phone_garage_nav_up() 
  853. 	Garage_list:move_cursor(-1) 
  854. end 
  855.  
  856. function cell_phone_garage_nav_down() 
  857. 	Garage_list:move_cursor(1) 
  858. end 
  859.  
  860. function cell_phone_garage_button_a()	 
  861. 	if Garage_list:list_is_playing() == false then 
  862. 		-- Attempt to retrive vehicle 
  863.  
  864. 		-- Get current selected vehicle data... 
  865. 		local data = Garage_list:return_selected_data() 
  866. 		local repair_cost = data.repair_cost  
  867. 		 
  868. 		--Check if player has enough cash 
  869. 		if Cell_phone_cash < repair_cost then 
  870. 			--Not enough cash dialog 
  871. 			dialog_box_message("CELL_VEHICLE_DIALOG_NO_CASH_HEADER","CELL_VEHICLE_DIALOG_NO_CASH_BODY") 
  872. 			return 
  873. 		end 
  874.  
  875. 		--Repair and Deliver if player has enough cash. 
  876. 		if repair_cost == 0 then 
  877. 			--Deliver if repair price = 0 
  878. 			cellphone_choose_vehicle(data.id) 
  879. 		 
  880. 			--Exit phone... 
  881. 			cell_phone_exit(true) 
  882. 			return 
  883. 		end 
  884. 		 
  885. 		--Car needs repairs, prepare localized dialog and display 
  886. 		 
  887. 		if repair_cost ~= 0 then 
  888. 			local values = {[0] = repair_cost} 
  889. 			local dialog_repairs_body = vint_insert_values_in_string("CELL_VEHICLE_DIALOG_REPAIRS_BODY", values) 
  890. 			dialog_box_confirmation("CELL_VEHICLE_DIALOG_REPAIRS_HEADER", dialog_repairs_body, "cellphone_garage_get_car_dialog_cb") 
  891. 		else  
  892. 			cellphone_choose_vehicle(data.id) 
  893. 			cell_phone_exit(true) 
  894. 		end 
  895. 	end 
  896. end 
  897.  
  898. function cell_phone_garage_button_b() 
  899. 	-- Nav back to homie list... 
  900. 	-- Nav back to homie list... 
  901. 	cell_phone_menu_show(CELL_PHONE_MENU_BOOK, CELL_MENU_TRANS_LEFT) 
  902. 	 
  903. 	Current_menu = HOMIE_MENU 
  904. end 
  905.  
  906. function cell_phone_garage_button_map() 
  907. end 
  908.  
  909. ------------------------------------------------------------------------------- 
  910. -- Dialog response after selecting an option on the repair menu... 
  911. ------------------------------------------------------------------------------- 
  912. function cellphone_garage_get_car_dialog_cb(result, action) 
  913. 	if result == 0 then 
  914. 		--Result is good, retreive the car... 
  915. 		local vehicle_id = Garage_list:get_id() 
  916. 		cellphone_choose_vehicle(vehicle_id) 
  917. 		--Exit back to game... 
  918. 		cell_phone_exit(true) 
  919. 	end 
  920. 	 
  921. 	if result == 1 then 
  922. 		-- go back to the menu 
  923. 		return 
  924. 	end 
  925.  
  926. end 
  927.  
  928. ------------------------------------------------------------------------------- 
  929. -- Called when the game wants to hang up the phone... 
  930. -- This gets called after we dial... 
  931. -- @param is_busy 
  932. ------------------------------------------------------------------------------ 
  933. function cell_phone_call_build(is_busy) 
  934.  
  935. 	--Get homie data we need... 
  936. 	local homie_name_crc = Homie_data[Homie_data_cur_idx].homie_name_crc	 
  937. 	local image_crc = Homie_data[Homie_data_cur_idx].image_crc 
  938. 	 
  939. 	local call_contact_grp_h = vint_object_find("call_contact_grp")  
  940. 	 
  941. 	--Set text... 
  942. 	local call_name_txt_h = vint_object_find("call_name_txt", call_contact_grp_h) 
  943. 	vint_set_property(call_name_txt_h, "text_tag_crc", homie_name_crc) 
  944. 	 
  945. 	--Make sure it fits in the phone... 
  946. 	resize_text_element(call_name_txt_h, CELL_PHONE_CALL_MAX_WIDTH_LABEL) 
  947. 	 
  948. 	--Set icon 
  949. 	local call_icon_bmp_h = vint_object_find("call_icon_bmp", call_contact_grp_h) 
  950. 	vint_set_property(call_icon_bmp_h, "image_crc", image_crc) 
  951.  
  952. 	local calling_info_txt_h = vint_object_find("calling_info_txt")  
  953. 	if is_busy then 
  954. 		vint_set_property(calling_info_txt_h, "text_tag", "CELL_PHONE_BUSY") 
  955. 	else 
  956. 		vint_set_property(calling_info_txt_h, "text_tag", "CELL_PHONE_IN_CALL") 
  957. 	end 
  958. end 
  959.  
  960. -------------------------------------------------------------------------- 
  961. -- Called when the game wants to hang up the phone... 
  962. -- This gets called after we dial... 
  963. -- @param success			(CELL_CALL_HANGUP, CELL_CALL_RETURN_TO_PHONE) 
  964. ------------------------------------------------------------------------------- 
  965. function cell_phone_call_hangup_cb(success) 
  966. 	debug_print("vint", "cell_phone_call_hangup_cb()\n") 
  967. 	 
  968. 	if success == CELL_CALL_HANGUP then 
  969. 		--exit back to game.... 
  970. 		cell_phone_exit(true) 
  971. 	elseif success == CELL_CALL_RETURN_TO_PHONE then 
  972. 		--Return to phone 
  973. 		cell_phone_menu_show(CELL_PHONE_MENU_BOOK, CELL_MENU_TRANS_LEFT) 
  974. 	else 
  975. 		-- handle any other case exit back to game... 
  976. 		cell_phone_exit(true) 
  977. 	end 
  978. end 
  979.  
  980. -------------------------------------------------------------------------------- 
  981. -- Call screen input.. 
  982. -------------------------------------------------------------------------------- 
  983. function cell_phone_call_input(event) 
  984. 	--do something here 
  985. 	if event == "select" or event == "back" or event == "map" then 
  986. 		--exit to game... 
  987. 		cell_phone_exit(true) 
  988. 	end 
  989. end 
  990.  
  991. ------------------------------------------------------------------------------- 
  992. -- Updates player cash for this screen...  
  993. -- uses a hud data item and gets the first element from it. 
  994. ------------------------------------------------------------------------------- 
  995. function cell_phone_cash_update(di_h) 
  996. 	local cash = vint_dataitem_get(di_h) 
  997. 	Cell_phone_cash = floor(cash) 
  998. end 
  999.  
  1000. ------------------------------------------------------------------------------- 
  1001. -- Exits to a menu or back to game... 
  1002. ------------------------------------------------------------------------------- 
  1003. function cell_phone_exit(exit_to_game) 
  1004. 	-- Next time come back to phone main... 
  1005. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)  
  1006. 	 
  1007. 	--Unsubscribe from all controls while we make our transition... 
  1008. 	Input_tracker:subscribe(false) 
  1009. 	Input_tracker_garage:subscribe(false) 
  1010. 	Input_tracker_call:subscribe(false) 
  1011. 	 
  1012. 	if exit_to_game then 
  1013. 		--Exit to game... 
  1014. 		cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_PHONE, cell_phone_exit_to_game) 
  1015. 		ui_audio_post_event("UI_Hub_Menu_Back") 
  1016. 	else 
  1017. 		--Exit to main... 
  1018. 		cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_PHONE, cell_phone_exit_to_main) 
  1019. 		ui_audio_post_event("UI_Hub_Menu_Back") 
  1020. 	end 
  1021. end 
  1022.  
  1023. function cell_phone_exit_to_main() 
  1024. 	pop_screen()	 
  1025. end 
  1026.  
  1027. function cell_phone_exit_to_game() 
  1028. 	pop_screen() -- cell phone 
  1029. 	pop_screen() -- cell main 
  1030. 	pop_screen() -- cell fore/background	 
  1031. end 
  1032.  
  1033. ------------------------------------------------------------------------------- 
  1034. -- resize a specific text element... 
  1035. ------------------------------------------------------------------------------- 
  1036. function cell_phone_resize_text_element(element_h, max_width) 
  1037. 	vint_set_property(element_h, "scale", 1, 1) 
  1038. 	local text_width, text_height = element_get_actual_size(element_h)	 
  1039.  
  1040. 	if text_width > max_width then 
  1041. 		local text_scale = max_width/text_width 
  1042. 		vint_set_property(element_h, "scale", text_scale, text_scale) 
  1043. 	end 
  1044. end 
  1045.  
  1046. ------------------------------------------------------------------------------- 
  1047. -- Mouse specific functions... 
  1048. ------------------------------------------------------------------------------- 
  1049.  
  1050. --Search through active buttons and determine if the mouse is over a valid target 
  1051. -- 
  1052. function cell_phone_get_valid_handle(target_handle) 
  1053. 	for idx, cur_selection in pairs(Homie_data) do 
  1054. 		if cur_selection.h ~= nil and cur_selection.h == target_handle then			 
  1055. 			--if selection is visible then return idx 
  1056. 			if idx >= Visible_start_idx and idx <= Visible_end_idx then 
  1057. 				return idx 
  1058. 			end			 
  1059. 		end 
  1060. 	end 
  1061. 	 
  1062. 	return MOUSE_INVALID_HANDLE	 
  1063. end 
  1064.  
  1065. function cell_phone_mouse_click(event, target_handle)	 
  1066. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  1067. 	if hint_index == 1 then 
  1068. 		cell_phone_book_button_b() 
  1069. 	end 
  1070.  
  1071. 	local phone_index =  cell_phone_get_valid_handle(target_handle) 
  1072. 	if phone_index ~= MOUSE_INVALID_HANDLE then 
  1073. 		cell_phone_book_button_a(event, nil) 
  1074. 	end 
  1075. 		 
  1076. 	local garage_hint_index = Garage_hint_bar:get_hint_index(target_handle) 
  1077. 	if garage_hint_index == 1 then 
  1078. 		cell_phone_garage_button_b() 
  1079. 	end 
  1080. 	 
  1081. 	local garage_idx = Garage_list:get_button_index(target_handle) 
  1082. 	if garage_idx ~= 0 then 
  1083. 		Garage_list:set_selection(garage_idx) 
  1084. 		cell_phone_garage_button_a(event, nil) 
  1085. 	end		 
  1086. end 
  1087.  
  1088. function cell_phone_mouse_move(event, target_handle) 
  1089. 	 
  1090. 	if Current_menu == HOMIE_MENU then 
  1091. 		-- Phone book inputs 
  1092. 		Hint_bar:set_highlight(0) 
  1093. 			 
  1094. 		local hint_index = Hint_bar:get_hint_index(target_handle) 
  1095. 		if hint_index ~= 0 then 
  1096. 			Hint_bar:set_highlight(hint_index) 
  1097. 			game_UI_audio_play("UI_Cell_Nav") 
  1098. 		end 
  1099. 		 
  1100. 		local phone_index = cell_phone_get_valid_handle(target_handle) 
  1101. 		 
  1102. 		if phone_index ~= MOUSE_INVALID_HANDLE then 
  1103. 			cell_phone_book_highlight(phone_index, true) 
  1104. 			game_UI_audio_play("UI_Cell_Nav") 
  1105. 		end		 
  1106. 	elseif Current_menu == GARAGE_MENU then 
  1107. 		-- Garage inputs 
  1108. 		Garage_hint_bar:set_highlight(0) 
  1109. 		 
  1110. 		local garage_hint_index = Garage_hint_bar:get_hint_index(target_handle) 
  1111. 		if garage_hint_index ~= 0 then 
  1112. 			Garage_hint_bar:set_highlight(garage_hint_index) 
  1113. 			game_UI_audio_play("UI_Cell_Nav") 
  1114. 		end 
  1115. 		 
  1116. 		local old_index = Garage_list:get_selection() 
  1117. 		local new_index = Garage_list:get_button_index(target_handle) 
  1118. 		if new_index ~= 0 and new_index ~= old_index then 
  1119. 			Garage_list:set_selection(new_index) 
  1120. 			Garage_list:move_cursor(0, true) 
  1121. 			 
  1122. 			-- If the item has a callback for navigation, do it 
  1123. 			local data_item = Garage_list:return_selected_data() 
  1124. 			if data_item.on_nav ~= nil then 
  1125. 				data_item.on_nav(data_item) 
  1126. 			end 
  1127. 		end	 
  1128. 	end 
  1129. end 
  1130.  
  1131. function cell_phone_mouse_drag(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  1132. 	if Scrollbar.tab_grp.handle == target_handle then 
  1133. 		local homie_count = #Homie_data 
  1134. 		local contact_list_grp_h = vint_object_find("contact_list_grp") 
  1135. 		local list_x, list_y =  vint_get_property(contact_list_grp_h, "anchor") 
  1136. 		 
  1137. 		Visible_start_idx = Scrollbar:drag_scrolltab(mouse_y, #Homie_data) 
  1138. 		Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1) 
  1139. 		 
  1140. 		if Visible_start_idx < 1 then 
  1141. 			Visible_start_idx = 1 
  1142. 		elseif Visible_end_idx > homie_count then 
  1143. 			Visible_start_idx = homie_count - (HOMIE_MAX_ITEMS - 1) 
  1144. 		end 
  1145. 		 
  1146. 		Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1) 
  1147. 		 
  1148. 		local new_y = 0 
  1149. 		new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1) 
  1150. 		 
  1151. 		vint_set_property(contact_list_grp_h, "anchor", list_x, new_y) 
  1152. 		 
  1153. 		Prev_y = new_y 
  1154. 		 
  1155. 		Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false ) 
  1156. 	end 
  1157. 	 
  1158. 	if Garage_list.scrollbar.tab_grp.handle == target_handle then 
  1159. 		local new_start_index = Garage_list.scrollbar:drag_scrolltab(mouse_y, Garage_list.num_buttons - (Garage_list.max_buttons - 1)) 
  1160. 		 
  1161. 		--scroll Garage list 
  1162. 		Garage_list:scroll_list(0, new_start_index) 
  1163. 	end 
  1164. end 
  1165.  
  1166. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  1167. -- 
  1168. function cell_phone_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  1169. 	 
  1170. 	-- scroll garage list and update mouse inputs 
  1171. 	if Garage_list.scrollbar.tab_grp.handle == target_handle then 
  1172. 		local start_index = Garage_list:get_visible_indices() 
  1173. 		Garage_list.scrollbar:release_scrolltab(start_index, Garage_list.num_buttons - (Garage_list.max_buttons - 1)) 
  1174. 		Garage_list:update_mouse_inputs("cell_phone",Mouse_input_tracker_garage,50) 
  1175. 	end 
  1176. end 
  1177.  
  1178. function cell_phone_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  1179. 	--scroll lines are inverted for some reason 
  1180. 	scroll_lines = scroll_lines * -1 
  1181. 	 
  1182. 	-- scroll garage list if in garage 
  1183. 	if Menu_active == CELL_PHONE_MENU_GARAGE then 
  1184. 		if scroll_lines ~= 0 then 
  1185. 			Garage_list:scroll_list(scroll_lines) 
  1186. 			Garage_list:update_mouse_inputs("cell_phone",Mouse_input_tracker_garage,50)			 
  1187. 		end	 
  1188. 	else	 
  1189. 		local homie_count = #Homie_data	 
  1190. 		--if list has enough items to scroll then allow mouse wheel 
  1191. 		if homie_count > HOMIE_MAX_ITEMS then	 
  1192. 			 
  1193. 			local contact_list_grp_h = vint_object_find("contact_list_grp") 
  1194. 			local list_x, list_y =  vint_get_property(contact_list_grp_h, "anchor") 
  1195. 			 
  1196. 			Visible_start_idx = Visible_start_idx + scroll_lines 
  1197. 			Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1) 
  1198. 			 
  1199. 			if Visible_start_idx < 1 then 
  1200. 				Visible_start_idx = 1 
  1201. 			elseif Visible_end_idx > homie_count then 
  1202. 				Visible_start_idx = homie_count - (HOMIE_MAX_ITEMS - 1) 
  1203. 			end 
  1204. 			 
  1205. 			Visible_end_idx = Visible_start_idx + (HOMIE_MAX_ITEMS - 1) 
  1206. 			 
  1207. 			local new_y = 0 
  1208. 			new_y = -HOMIE_LIST_SPACING * (Visible_start_idx - 1) 
  1209. 			 
  1210. 			local book_scroll_anim_h = vint_object_find("book_scroll_anim") 
  1211. 			local book_scroll_twn_h = vint_object_find("book_scroll_twn") 
  1212.  
  1213. 			vint_set_property(book_scroll_twn_h, "start_value", 	list_x, list_y) 
  1214. 			vint_set_property(book_scroll_twn_h, "end_value", 		list_x, 	new_y) 
  1215. 			vint_set_property(book_scroll_twn_h, "end_event", "cell_phone_book_scroll_cb") 
  1216. 			lua_play_anim(book_scroll_anim_h) 
  1217. 			Book_screen_is_scrolling = true 
  1218. 			 
  1219. 			Prev_y = new_y 
  1220. 			 
  1221. 			Scrollbar:set_value( homie_count - (HOMIE_MAX_ITEMS - 1), Visible_start_idx, false ) 
  1222. 		end 
  1223. 	end 
  1224. end 
  1225.  
  1226. --[[ --------------------------------------------------------------------- 
  1227. -- Function - cell_phone_update_gamepad_state 
  1228. -- Description - Called by code anytime input switches between gamepad/mouse & keyboard 
  1229. -- Parameters - none 
  1230. -- Returns - nil 
  1231. ]]-- --------------------------------------------------------------------- 
  1232. function cell_phone_update_gamepad_state() 
  1233. 	 
  1234. 	Highlight_btn:set_button(CTRL_MENU_BUTTON_A) 
  1235. 	 
  1236. 	local book_screen_grp_h = vint_object_find("book_screen_grp") 
  1237. 	local contact_highlight_grp_h = vint_object_find("contact_highlight_grp", book_screen_grp_h)	 
  1238. 	local highlight_btn_h = vint_object_find("highlight_btn", contact_highlight_grp_h) 
  1239. 	local name_txt_h = vint_object_find("name_txt", contact_highlight_grp_h) 
  1240. 				 
  1241. 	local name_x, name_y = vint_get_property(name_txt_h, "anchor") 
  1242. 	if game_is_active_input_gamepad() then 
  1243. 		vint_set_property(name_txt_h, "anchor", 118, name_y) 
  1244. 		vint_set_property(highlight_btn_h, "visible", true) 
  1245. 	else 
  1246. 		vint_set_property(name_txt_h, "anchor", 85, name_y) 
  1247. 		vint_set_property(highlight_btn_h, "visible", false) 
  1248. 	end 
  1249. 	 
  1250. 	if Current_menu == HOMIE_MENU then 
  1251. 		if Input_tracker ~= -1 then 
  1252. 			Input_tracker:subscribe(false) 
  1253. 			Input_tracker:subscribe(true) 
  1254. 		end 
  1255. 		 
  1256. 		if Input_tracker_call ~= -1 then 
  1257. 			Input_tracker_call:subscribe(false) 
  1258. 			Input_tracker_call:subscribe(true) 
  1259. 		end 
  1260. 		 
  1261. 		if Mouse_input_tracker ~= -1 then 
  1262. 			Mouse_input_tracker:subscribe(false) 
  1263. 			Mouse_input_tracker:subscribe(true) 
  1264. 		end 
  1265. 		 
  1266. 		if Mouse_input_tracker_call ~= -1 then 
  1267. 			Mouse_input_tracker_call:subscribe(false) 
  1268. 			Mouse_input_tracker_call:subscribe(true) 
  1269. 		end 
  1270. 	 
  1271. 	elseif Current_menu == GARAGE_MENU then 
  1272. 		if Input_tracker_garage ~= -1 then 
  1273. 			Input_tracker_garage:subscribe(false) 
  1274. 			Input_tracker_garage:subscribe(true) 
  1275. 		end 
  1276. 		 
  1277. 		if Mouse_input_tracker_garage ~= -1 then 
  1278. 			Mouse_input_tracker_garage:subscribe(false) 
  1279. 			Mouse_input_tracker_garage:subscribe(true) 
  1280. 		end 
  1281. 		 
  1282. 		if Mouse_input_tracker_garage_hint ~= -1 then 
  1283. 			Mouse_input_tracker_garage_hint:subscribe(false) 
  1284. 			Mouse_input_tracker_garage_hint:subscribe(true) 
  1285. 		end 
  1286. 	end 
  1287. 	 
  1288. 	 
  1289. end