./cell_saintsbook.lua

  1. --Item Type Enum 
  2. SAINTSBOOK_ITEM_TYPE_ALL			 	= 0		--Note all is not used on v2 of the saints book screen. 
  3. SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS	= 1 
  4. SAINTSBOOK_ITEM_TYPE_CHOPSHOP			= 2 
  5. SAINTSBOOK_ITEM_TYPE_CHALLENGE	 	= 3 
  6.  
  7. --Screen types 
  8. local SCREEN_TYPE_TOP 	= 0 
  9. local SCREEN_TYPE_MAIN 	= 1 
  10. local SCREEN_TYPE_SUB 	= 2 
  11.  
  12. local Active_screen = {} 
  13. local Active_screen_type = -1 
  14.  
  15. --Local Globals 
  16. local SAINTSBOOK_COLOR_TOP_BG_SELECTED 		= {R = 148/255, 	G = 0/255, 		B = 197/255} 
  17. local SAINTSBOOK_COLOR_TOP_BG_UNSELECTED 		= {R = 51/255, 	G = 51/255,	 	B = 51/255} 
  18. local SAINTSBOOK_COLOR_TOP_TEXT_SELECTED 		= {R = 0/255, 		G = 0/255, 		B = 0/255} 
  19. local SAINTSBOOK_COLOR_TOP_TEXT_UNSELECTED 	= {R = 156/255, 	G = 156/255, 	B = 156/255} 
  20. local SAINTSBOOK_COLOR_ICON_SELECTED			= {R = 220/255, 	G = 220/255, 	B = 220/255} 
  21. local SAINTSBOOK_COLOR_ICON_UNSELECTED 		= {R = 120/255, 	G = 120/255, 	B = 120/255} 
  22.  
  23. local SAINTSBOOK_PAGE_WIDTH = 850	--size of entire page (used to space and transition the pages... 
  24.  
  25. --VDO 
  26. local Input_tracker_main 
  27. local Hint_bar 
  28. local Clip_region 
  29. local Mouse_input_tracker 
  30. local Scrollbar_mouse_input_tracker 
  31.  
  32. local Cell_saintsbook_main_scrollbar 
  33. local Cell_saintsbook_sub_scrollbar 
  34.  
  35. local Cell_saintsbook_contact_image = -1 --Reference to streamed in saintsbook image... 
  36. local Cell_saintsbook_target_image 	= -1 --Reference to streamed in saintsbook image... 
  37.  
  38. local Cell_saintsbook_exit_phone = false	--Determine if we go back to cellphone main or exit the phone all together. 
  39. local Cell_saintsbook_scroll_tween_done = true 
  40.  
  41. Cell_saintsbook_first_transition = false	--flag to determine if we finished the first transition	(determines when to unlock input) 
  42. Cell_saintsbook_top_is_ready = false				--flag to determine that we've loaded into saintsbook... (determines when to unlock input) 
  43. --Icons per item type.... 
  44. local Cell_saintsbook_icons = { 
  45. 	[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] 	= "ui_saintsbook_hitman", 
  46. 	[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] 			= "ui_saintsbook_vehicle", 
  47. 	[SAINTSBOOK_ITEM_TYPE_CHALLENGE] 		= "ui_saintsbook_challenge", 
  48. } 
  49.  
  50. --Icons per item type.... 
  51. local Cell_saintsbook_main_pegs = { 
  52. 	[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] 	= "ui_bms_sb_hitman", 
  53. 	[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] 			= "ui_bms_sb_chopshop", 
  54. 	[SAINTSBOOK_ITEM_TYPE_CHALLENGE] 		= "ui_bms_sb_challenges", 
  55. } 
  56.  
  57. --Icons per item type.... 
  58. local Cell_saintsbook_top_pegs = { 
  59. 	[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] 	= "ui_sb_main_hitman", 
  60. 	[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] 			= "ui_sb_main_chopshop", 
  61. 	[SAINTSBOOK_ITEM_TYPE_CHALLENGE] 		= "ui_sb_main_challenges", 
  62. } 
  63.  
  64. --Top level descriptions of items 
  65. local Cell_saintsbook_top_descriptions = { 
  66. 	[SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS] 	= "SB_ASSASSINATION_DESC", 
  67. 	[SAINTSBOOK_ITEM_TYPE_CHOPSHOP] 			= "SB_CHOP_SHOP_DESC", 
  68. 	[SAINTSBOOK_ITEM_TYPE_CHALLENGE] 		= "SB_CHALLENGES_DESC", 
  69. } 
  70.  
  71.  
  72. -- Table to translate contact images that are normally homie heads... 
  73. -- Use cell_saintsbook_contact_image_get(image_name) 
  74. -- This will attempt to pull the image from this table. 
  75. -- 
  76. local Cell_saintsbook_contact_images = { 
  77. 	["ui_homie_pierce"]			= "ui_sb_ct_pierce", 
  78. 	["ui_homie_shaundi"] 		= "ui_sb_ct_shaundi", 
  79. 	["ui_homie_zimos"] 			= "ui_sb_ct_zimos", 
  80. 	["ui_homie_kinzie"] 			= "ui_sb_ct_kinzie", 
  81. 	["ui_homie_angel_wmask"] 	= "ui_sb_ct_angel", 
  82. 	["ui_homie_angel_womask"] 	= "ui_sb_ct_angel", 
  83. 	["ui_homie_mayor"] 			= "ui_sb_ct_mayor", 
  84. 	["ui_homie_oleg"] 			= "ui_sb_ct_oleg", 
  85. 	["ui_homie_viola"] 			= "ui_sb_ct_viola", 
  86. } 
  87.  
  88. --Top level menu stuff 
  89. Cell_saintsbook_top_items = {} 
  90. Cell_saintsbook_top_selected_idx = 1 
  91.  
  92.  
  93. Cell_saintsbook_items 					= {}	-- Items in the list... 
  94. Cell_saintsbook_display_items 		= {}	-- Items that are currently displayed 
  95. Cell_saintsbook_item_count 			= 0 	-- # of items in the list... 
  96. Cell_saintsbook_main_selected_idx 	= 0	-- Currently selected inded... 
  97. Cell_saintsbook_main_max_items 		= 0	-- max items 
  98.  
  99. Cell_saintsbook_selected_target 		= -1 
  100.  
  101. local Cell_old_mouse_index = -1 
  102.  
  103. --Main menu stuff 
  104. SAINTSBOOK_MAIN_MAX_ITEMS = 4 
  105. SAINTSBOOK_MAIN_ITEM_SPACING = 115			--Spacing between items... 
  106.  
  107. ------------------------------------------------------------------------------- 
  108. -- Initialize saintsbook 
  109. -- 
  110. function cell_saintsbook_init() 
  111. 	local h = vint_object_find("safe_frame") 
  112. 	vint_set_property(h, "visible", false) 
  113. 	 
  114. 	--hide loading symbol (this is used on exit) 
  115. 	local loading_grp_h = vint_object_find("loading_grp") 
  116. 	vint_set_property(loading_grp_h, "alpha", 0) 
  117. 	 
  118. 	--Initailize Input tracker... 
  119. 	Input_tracker_main = Vdo_input_tracker:new() 
  120. 	Input_tracker_main:add_input("nav_up", 	"cell_saintsbook_input", 50) 
  121. 	Input_tracker_main:add_input("nav_down",	"cell_saintsbook_input", 50) 
  122. 	Input_tracker_main:add_input("map", 		"cell_saintsbook_input", 50) 
  123. 	Input_tracker_main:add_input("back", 		"cell_saintsbook_input", 50) 
  124. 	Input_tracker_main:add_input("pause", 		"cell_saintsbook_input", 50) 
  125. 	Input_tracker_main:add_input("select", 	"cell_saintsbook_input", 50) 
  126. 		 
  127. 	--hintbar... 
  128. 	local hint_data = { {CTRL_MENU_BUTTON_B, "BACK"}, } 
  129. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  130. 	Hint_bar:set_hints(hint_data) 
  131. 	 
  132. 	Clip_region = Vdo_base_object:new("content_clip") 
  133. 		 
  134. 	if game_get_platform() == "PC" then 
  135. 		Mouse_input_tracker = Vdo_input_tracker:new()		 
  136. 		Mouse_input_tracker:subscribe(false) 
  137. 		Scrollbar_mouse_input_tracker = Vdo_input_tracker:new()		 
  138. 		Scrollbar_mouse_input_tracker:subscribe(false) 
  139. 		Scrollbar_mouse_input_tracker.enabled = false 
  140. 	end 
  141. 		 
  142. 	Cell_saintsbook_main_selected_idx = 0 
  143.  
  144. 	Cell_saintsbook_main_scrollbar = Vdo_scrollbar:new("main_scroll_bar") 
  145. 	Cell_saintsbook_sub_scrollbar = Vdo_scrollbar:new("task_scroll_bar") 
  146.  
  147. 	Cell_saintsbook_main_scrollbar:set_property("visible", false) 
  148. 	Cell_saintsbook_sub_scrollbar:set_property("visible", false) 
  149. 	 
  150. 	Cell_saintsbook_main_scrollbar:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY) 
  151. 	Cell_saintsbook_sub_scrollbar:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY) 
  152.  
  153. 	--Position Pages in the slide. 
  154. 	local main_grp_h 		= vint_object_find("main_grp") 
  155. 	local subpage_grp_h 	= vint_object_find("subpage_grp") 
  156. 	local top_grp_h 		= vint_object_find("top_grp") 
  157. 	vint_set_property(top_grp_h, 		"anchor", 0, 0) 
  158. 	vint_set_property(main_grp_h, 	"anchor", SAINTSBOOK_PAGE_WIDTH, 		0) 
  159. 	vint_set_property(subpage_grp_h, "anchor", SAINTSBOOK_PAGE_WIDTH * 2, 	0) 
  160.  
  161. 	--Hint bar 
  162. 	local hint_data = { 
  163. 		{CTRL_MENU_BUTTON_B, "CONTROL_BACK"}, 
  164. 	} 
  165. 	Hint_bar = Vdo_hint_bar:new("hint_bar") 
  166. 	Hint_bar:set_hints(hint_data) 
  167. 	 
  168. 	--Specific screen setup... 
  169. 	 
  170. 	--Set button image for main screen. 
  171. 	local gps_btn = Vdo_hint_button:new("gps_btn") 
  172. 	gps_btn:set_button(CTRL_MENU_BUTTON_A) 
  173.  
  174. 	--Load initial pegs... 
  175. 	thread_new("cell_saintsbook_load_initial_pegs") 
  176. end 
  177.  
  178.  
  179. function cell_saintsbook_load_initial_pegs() 
  180. 	--Dump the pause map. 
  181. 	game_peg_unload("ui_map_world_city") 
  182. 	 
  183. 	thread_yield() 
  184. 	 
  185. 	-- Pre-load top level images 
  186. 	game_peg_load_with_cb("cell_saintsbook_top_img_loaded", 3, Cell_saintsbook_top_pegs[1], Cell_saintsbook_top_pegs[2], Cell_saintsbook_top_pegs[3]) 
  187. end 
  188.  
  189. ------------------------------------------------------------------------------- 
  190. -- Cleanup saintsbook.  
  191. -- 
  192. function cell_saintsbook_cleanup() 
  193. 	--unload the pegs again on cleanup to guaranteed cleanup... 
  194. 	cell_saintsbook_unload_pegs() 
  195. end 
  196.  
  197. -------------------------------------------------------------------------------- 
  198. -- Unloads pegs and queues up the pause map to load. 
  199. -- 
  200. function cell_saintsbook_close() 
  201.  
  202. 	-- Unscubscribe from inputs... 
  203. 	Input_tracker_main:subscribe(false) 
  204. 	 
  205. 	--play loading animation... 
  206. 	local loading_anim_h = vint_object_find("loading_anim") 
  207. 	lua_play_anim(loading_anim_h) 
  208. 	 
  209. 	--delay while we we transition out... 
  210. 	delay(.25) 
  211. 	 
  212. 	cell_saintsbook_unload_pegs() 
  213. 	thread_yield() 
  214. 	 
  215. 	--Load pause map on callback we will do the final exit and transition out as planned. 
  216. 	game_peg_load_with_cb("cell_phone_saintsbook_close_final", 1, "ui_map_world_city")	 
  217. end 
  218.  
  219. function cell_saintsbook_unload_pegs() 
  220. 	--Unload a peg if we have it loaded... 
  221. 	if Cell_saintsbook_contact_image ~= -1 then 
  222. 		game_peg_unload(Cell_saintsbook_contact_image) 
  223. 		Cell_saintsbook_contact_image = -1 
  224. 	end 
  225. 	if Cell_saintsbook_target_image ~= -1 then 
  226. 		game_peg_unload(Cell_saintsbook_target_image) 
  227. 		Cell_saintsbook_target_image = -1 
  228. 	end 
  229.  
  230. 	--unload all main image pegs... 
  231. 	for i = 1, #Cell_saintsbook_top_pegs do 
  232. 		game_peg_unload(Cell_saintsbook_top_pegs[i]) 
  233. 	end 
  234. 	 
  235. 	--Unload any main image pegs 
  236. 	for i = 1, #Cell_saintsbook_main_pegs do 
  237. 		game_peg_unload(Cell_saintsbook_main_pegs[i]) 
  238. 	end	 
  239. end 
  240.  
  241. ----------------------------------------------- 
  242. -- Closes Saintsbook and does the transition. 
  243. -- 
  244. function cell_phone_saintsbook_close_final() 
  245.  
  246. 	-- Next time come back to phone main... 
  247. 	vint_dataresponder_post("cell_menu_state_dr", "Set", ID_MAIN)  
  248. 	 
  249. 	if Cell_saintsbook_exit_phone then 
  250. 		--Exit to game... 
  251. 		 
  252. 		cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_NONE, CELL_SCREEN_SAINTSBOOK, cell_saintsbook_exit_final_to_game) 
  253. 		game_UI_audio_play("UI_Cell_Close") 
  254. 	else 
  255. 		--Exit to main... 
  256. 		cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_SAINTSBOOK, cell_saintsbook_exit_final_to_menu) 
  257. 		game_UI_audio_play("UI_Cell_Nav_Back") 
  258. 	end 
  259. end 
  260.  
  261. ---------------------------------------------------------------------------------------- 
  262. function cell_saintsbook_exit_to_game() 
  263. 	Cell_saintsbook_exit_phone = true 
  264. 	thread_new("cell_saintsbook_close") 
  265. end 
  266.  
  267. function cell_saintsbook_exit_to_menu() 
  268. 	Cell_saintsbook_exit_phone = false 
  269. 	thread_new("cell_saintsbook_close") 
  270. end 
  271.  
  272.  
  273. function cell_saintsbook_exit_final_to_menu() 
  274. 	pop_screen() 
  275. end 
  276.  
  277. function cell_saintsbook_exit_final_to_game() 
  278.  
  279. 	pop_screen()	--saintsbook 
  280. 	pop_screen()	--cellphone main 
  281. 	pop_screen()	--cellphone foreground/background 
  282. end 
  283.  
  284. ------------------------------------------------------------------------------- 
  285. -- Controls Unlock  
  286. -- 
  287. function cell_saintsbook_controls_unlock() 
  288. 	Input_tracker_main:subscribe(true) 
  289. 	if Mouse_input_tracker ~= nil then 
  290. 		Mouse_input_tracker:subscribe(true) 
  291. 		Scrollbar_mouse_input_tracker:subscribe(true) 
  292. 		Scrollbar_mouse_input_tracker.enabled = false -- Inentional: Will reset mouse inputs if necessary 
  293. 	end 
  294. end 
  295.  
  296. ------------------------------------------------------------------------------- 
  297. -- Controls lock  
  298. -- 
  299. function cell_saintsbook_controls_lock() 
  300. 	Input_tracker_main:subscribe(false) 
  301. 	if Mouse_input_tracker ~= nil then 
  302. 		Mouse_input_tracker:subscribe(false) 
  303. 		Scrollbar_mouse_input_tracker:subscribe(false) 
  304. 		Scrollbar_mouse_input_tracker.enabled = false 
  305. 	end 
  306. end 
  307.  
  308. ------------------------------------------------------------------------------- 
  309. -- Sets the active screen for nav callbacks. 
  310. -- 
  311. function cell_saintsbook_active_screen_set(screen_type) 
  312. 	if Saintsbook_screens[screen_type] ~= nil then 
  313. 		Active_screen = Saintsbook_screens[screen_type] 
  314. 		Active_screen_type = screen_type 
  315. 	end 
  316. 	 
  317. 	--transition to page 
  318. 	cell_saintsbook_transition(screen_type) 
  319. end 
  320.  
  321. ------------------------------------------------------------------------------- 
  322. -- Transitions to specific screen type, essentially first, second, third levels 
  323. -- 
  324. --	@screen_type		SCREEN_TYPE_TOP, SCREEN_TYPE_MAIN, SCREEN_TYPE_SUB 
  325. -- 
  326. function cell_saintsbook_transition(screen_type) 
  327. 	local transition_page_anim_h 	= vint_object_find("transition_page_anim") 
  328. 	local transition_twn_h 			= vint_object_find("transition_twn") 
  329. 	local content_h 					= vint_object_find("content") 
  330. 	 
  331. 	vint_set_property(transition_twn_h, "end_event", "cell_saintsbook_transition_complete") 
  332. 	 
  333. 	local new_x = -SAINTSBOOK_PAGE_WIDTH * screen_type 
  334. 	local old_x, old_y = vint_get_property(content_h, "anchor") 
  335. 	vint_set_property(transition_twn_h, "start_value", old_x, old_y) 
  336. 	vint_set_property(transition_twn_h, "end_value", 	new_x, old_y) 
  337. 	lua_play_anim(transition_page_anim_h) 
  338. end 
  339.  
  340. function cell_saintsbook_transition_complete() 
  341. 	--unlock controls 
  342. 	Cell_saintsbook_first_transition = true 
  343. 	if Cell_saintsbook_top_is_ready == true then 
  344. 		cell_saintsbook_controls_unlock() 
  345. 	end 
  346. 	 
  347. 	if Active_screen_type == SCREEN_TYPE_TOP then 
  348. 		--if we are at the top level we need to unload any pegs that are loaded for the main menu. 
  349. 		for i = 1, #Cell_saintsbook_main_pegs do 
  350. 			game_peg_unload(Cell_saintsbook_main_pegs[i]) 
  351. 		end	 
  352. 	end 
  353. 	 
  354. 	if game_get_platform() == "PC" then 
  355. 		if Active_screen_type == SCREEN_TYPE_TOP then 
  356. 			cell_saintsbook_top_activate_mouse() 
  357. 		elseif Active_screen_type == SCREEN_TYPE_MAIN then 
  358. 			cell_saintsbook_main_activate_mouse() 
  359. 		end 
  360. 	end 
  361. end 
  362.  
  363. ------------------------------------------------------------------------------- 
  364. -- Handles input callbacks for the Active_screen 
  365. -- 
  366. function cell_saintsbook_input(event, accelleration) 
  367. 	 
  368. 	if event == "nav_up" then --or event == "dpad_up" then 
  369. 		if Active_screen.nav ~= nil then 
  370. 			Active_screen.nav(-1) 
  371. 		end 
  372. 	elseif event == "nav_down" then -- or event == "dpad_down" then 
  373. 		if Active_screen.nav ~= nil then 
  374. 			Active_screen.nav(1) 
  375. 		end 
  376. 	elseif event == "select" then 
  377. 		if Active_screen.select ~= nil then 
  378. 			Active_screen.select(Active_screen.selected_idx) 
  379. 		end 
  380. 	elseif event == "back" then 
  381. 		if Active_screen.back ~= nil then 
  382. 			game_UI_audio_play("UI_Cell_Nav_Back") 
  383. 			Active_screen.back() 
  384. 		end 
  385. 	elseif event == "map" then 
  386. 		if Active_screen.exit ~= nil then 
  387. 			Active_screen.exit() 
  388. 		end 
  389. 	end 
  390. end 
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.  
  398. ------------------------------------------------------------------------------- 
  399. -- Top  
  400. ------------------------------------------------------------------------------- 
  401.  
  402. ------------------------------------------------------------------------------- 
  403. -- Callback for when our top level image is loaded. 
  404. -- Transitions from main screen to saintsbook and sets top level iamge. 
  405. -- 
  406. function cell_saintsbook_top_img_loaded()	 
  407. 	--Populate our top level menu. 
  408. 	vint_dataresponder_request("saintsbook_filters", "cell_saintsbook_top_populate", 0) 
  409. 	 
  410. 	--Now Build our top level menu... 
  411. 	cell_saintsbook_top_build() 
  412. 	 
  413. 	-- First streamed asset is loaded 
  414. 	 
  415. 	-- Show the safe and transition the screen 
  416. 	local h = vint_object_find("safe_frame") 
  417. 	vint_set_property(h, "visible", true) 
  418. 	local h = vint_object_find("saintsbook_grp") 
  419. 	vint_set_property(h, "alpha", 0) 
  420. 	 
  421. 	-- Set image 
  422. 	local h = vint_object_find("top_image_bmp") 
  423. 	local image = Cell_saintsbook_top_pegs[1] 
  424. 	vint_set_property(h, "image", image) 
  425. 	 
  426. 	--Transition the screen in... 
  427. 	cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_SAINTSBOOK, CELL_SCREEN_MAIN, cell_saintsbook_top_ready) 
  428. 	 
  429. 	--set active screen. 
  430. 	cell_saintsbook_active_screen_set(SCREEN_TYPE_TOP) 
  431. end 
  432.  
  433. function cell_saintsbook_top_ready() 
  434. 	--attemp to unlock controls 
  435. 	Cell_saintsbook_top_is_ready = true 
  436. 	if Cell_saintsbook_first_transition == true then 
  437. 		cell_saintsbook_controls_unlock() 
  438. 	end 
  439. end 
  440.  
  441. function cell_saintsbook_top_build() 
  442. 	local top_grp_h = vint_object_find("top_grp") 
  443. 	local top_item_grp_h = vint_object_find("top_item_grp", top_grp_h) 
  444. 	vint_set_property(top_item_grp_h, "visible", false) 
  445. 	 
  446. 	local x, y = 0, 0 --Use these outside of our loop...	 
  447. 	 
  448. 	local num_items = #Cell_saintsbook_top_items 
  449. 	for i = 1, num_items do 
  450. 		--get data out of table... 
  451. 		local index = Cell_saintsbook_top_items[i].filter_index 
  452. 		local filter_name = Cell_saintsbook_top_items[i].filter_name 
  453. 		local targets_completed = Cell_saintsbook_top_items[i].targets_completed 
  454. 		local targets_unlocked = Cell_saintsbook_top_items[i].targets_unlocked 
  455. 		 
  456. 		--clone our top level element. 
  457. 		local top_item_grp_clone_h = vint_object_clone(top_item_grp_h) 
  458. 		vint_set_property(top_item_grp_clone_h, "visible", true) 
  459. 	 
  460. 		--set text of our elements.... 
  461. 		local title_txt_h = vint_object_find("top_title_txt", top_item_grp_clone_h) 
  462. 		local completed_txt_h = vint_object_find("completed_items_txt", top_item_grp_clone_h) 
  463. 		 
  464. 		--set completed tag... 
  465. 		vint_set_property(title_txt_h, "text_tag", filter_name) 
  466. 		local values = { [0] = targets_completed, [1] = targets_unlocked} 
  467. 		local completed_string = vint_insert_values_in_string("SB_CAT_COMPLETED", values) 
  468. 		vint_set_property(completed_txt_h, "text_tag", completed_string) 
  469. 		 
  470. 		--Set icon... 
  471. 		local icon_bmp_h = vint_object_find("icon_bmp", top_item_grp_clone_h) 
  472. 		local icon = Cell_saintsbook_icons[index] 
  473. 		vint_set_property(icon_bmp_h, "image", icon) 
  474. 		 
  475. 		--shift top level group item. 
  476. 		x, y = vint_get_property(top_item_grp_h, "anchor") 
  477. 		y = (i - 1) * 86 
  478. 		vint_set_property(top_item_grp_clone_h, "anchor", x, y) 
  479. 		 
  480. 		--build button on highlight 
  481. 		local btn_obj = Vdo_hint_button:new("top_btn", top_item_grp_clone_h) 
  482. 		btn_obj:set_button(CTRL_MENU_BUTTON_A) 
  483. 		 
  484. 		Cell_saintsbook_top_items[i].h 					= top_item_grp_clone_h 
  485. 		Cell_saintsbook_top_items[i].title_txt_h 		= title_txt_h 
  486. 		Cell_saintsbook_top_items[i].completed_txt_h	= completed_txt_h 
  487. 		Cell_saintsbook_top_items[i].icon_bmp_h		= icon_bmp_h 
  488. 		Cell_saintsbook_top_items[i].bg_h				= vint_object_find("highlight_bmp", top_item_grp_clone_h) 
  489. 		Cell_saintsbook_top_items[i].btn_obj			= btn_obj 
  490. 	end 
  491. 	 
  492. 	--Adjust text so it lines up... 
  493. 	local item_desc_txt_h 	= vint_object_find("item_desc_txt", top_grp_h) 
  494. 	local item_desc_x, item_desc_y = vint_get_property(item_desc_txt_h, "anchor") 
  495. 	vint_set_property(item_desc_txt_h, "anchor", item_desc_x, y + 86) 
  496. 	 
  497. 	--select first item 
  498. 	cell_saintsbook_top_highlight_item(Cell_saintsbook_top_selected_idx) 
  499. 	 
  500. 	cell_saintsbook_top_activate_mouse() 
  501. end 
  502.  
  503. function cell_saintsbook_top_activate_mouse() 
  504. 	if Mouse_input_tracker ~= nil then 
  505. 		local num_items = #Cell_saintsbook_top_items 
  506. 		Mouse_input_tracker:remove_all() 
  507. 		for i = 1, num_items do 
  508. 			if Cell_saintsbook_top_items[i].bg_h ~= nil then 
  509. 				Mouse_input_tracker:add_mouse_input("mouse_move", "cell_saintsbook_top_mouse_move", 0, Cell_saintsbook_top_items[i].bg_h) 
  510. 				Mouse_input_tracker:add_mouse_input("mouse_click", "cell_saintsbook_top_mouse_click", 0, Cell_saintsbook_top_items[i].bg_h) 
  511. 			end 
  512. 		end 
  513. 		Hint_bar:add_mouse_inputs("cell_saintsbook", Mouse_input_tracker) 
  514. 		--Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_saintsbook_mouse_scroll", 0, Clip_region.handle) 
  515. 		Mouse_input_tracker:subscribe(true) 
  516. 		Scrollbar_mouse_input_tracker:subscribe(false) 
  517. 		Scrollbar_mouse_input_tracker.enabled = false 
  518. 	end 
  519. end 
  520.  
  521. function cell_saintsbook_top_mouse_click(event, target_handle) 
  522. 	local num_items = #Cell_saintsbook_top_items 
  523. 	 
  524. 	local new_index = -1 
  525. 	for i = 1, num_items do 
  526. 		if Cell_saintsbook_top_items[i] ~= nil and Cell_saintsbook_top_items[i].bg_h ~= nil then 
  527. 			if target_handle == Cell_saintsbook_top_items[i].bg_h then 
  528. 				new_index = i 
  529. 			end 
  530. 		end 
  531. 	end 
  532. 	 
  533. 	if new_index > -1 then 
  534. 		Cell_saintsbook_top_selected_idx = new_index 
  535. 		cell_saintsbook_top_select() 
  536. 		game_UI_audio_play("UI_Cell_Nav") 
  537. 	end 
  538. end 
  539.  
  540. function cell_saintsbook_top_mouse_move(event, target_handle) 
  541. 	local num_items = #Cell_saintsbook_top_items 
  542. 	 
  543. 	local new_index = -1 
  544. 	for i = 1, num_items do 
  545. 		if Cell_saintsbook_top_items[i] ~= nil and Cell_saintsbook_top_items[i].bg_h ~= nil then 
  546. 			if target_handle == Cell_saintsbook_top_items[i].bg_h then 
  547. 				new_index = i 
  548. 			end 
  549. 		end 
  550. 	end 
  551. 	 
  552. 	if new_index > -1 then 
  553. 		cell_saintsbook_top_highlight_item(new_index) 
  554. 		game_UI_audio_play("UI_Cell_Nav") 
  555. 	end 
  556. end 
  557.  
  558. function cell_saintsbook_mouse_click(event, target_handle) 
  559. 	-- Check if the user is over the hint bar 
  560. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  561. 	if hint_index ~= 0 then 
  562. 		cell_saintsbook_input("back") 
  563. 	end 
  564. 	 
  565. 	if Active_screen_type == SCREEN_TYPE_SUB then 
  566. 		cell_saintsbook_sub_mouse_click(event, target_handle) 
  567. 	end 
  568. end 
  569.  
  570. function cell_saintsbook_mouse_move(event, target_handle) 
  571. 	-- Reset highlights 
  572. 	Hint_bar:set_highlight(0) 
  573. 	 
  574. 	-- Check if the user is over the hint bar 
  575. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  576. 	if hint_index ~= 0 then 
  577. 		Hint_bar:set_highlight(hint_index) --COLOR_PLAYER_CREATION_PRIMARY) 
  578. 	end 
  579. 	 
  580. 	if Active_screen_type == SCREEN_TYPE_SUB then 
  581. 		cell_saintsbook_sub_mouse_move(event, target_handle) 
  582. 	end 
  583. end 
  584.  
  585. function cell_saintsbook_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  586. 	if scroll_lines ~= 0 then 
  587. 		if Active_screen_type == SCREEN_TYPE_MAIN then 
  588. 			if scroll_lines < 0 and Cell_saintsbook_main_first_item < Cell_saintsbook_item_count - 4 then 
  589. 				cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item + 1, Cell_saintsbook_main_first_item) 
  590. 			elseif scroll_lines > 0 and Cell_saintsbook_main_first_item > 0 then 
  591. 				cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item - 1, Cell_saintsbook_main_first_item) 
  592. 			end 
  593. 		end 
  594. 	end 
  595. end 
  596.  
  597.  
  598.  
  599. ------------------------------------------------------------------------------- 
  600. -- Highlights top level menu item 
  601. -- @item_index		index of top level item to highlight. 
  602. -- 
  603. function cell_saintsbook_top_highlight_item(item_index) 
  604. 	local num_items = #Cell_saintsbook_top_items 
  605. 	for i = 1, num_items do 
  606. 		local item = Cell_saintsbook_top_items[i] 
  607. 	 
  608. 		if i == item_index then 
  609. 			--Select this item... 
  610. 			 
  611. 			--tinting elements 
  612. 			vint_set_property(item.title_txt_h, 		"tint", SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.B) 
  613. 			vint_set_property(item.bg_h, 					"tint", SAINTSBOOK_COLOR_TOP_BG_SELECTED.R, SAINTSBOOK_COLOR_TOP_BG_SELECTED.G, SAINTSBOOK_COLOR_TOP_BG_SELECTED.B) 
  614. 			vint_set_property(item.icon_bmp_h, 			"tint", SAINTSBOOK_COLOR_ICON_SELECTED.R, SAINTSBOOK_COLOR_ICON_SELECTED.G, SAINTSBOOK_COLOR_ICON_SELECTED.B) 
  615. 			vint_set_property(item.completed_txt_h, 	"tint", SAINTSBOOK_COLOR_ICON_SELECTED.R, SAINTSBOOK_COLOR_ICON_SELECTED.G, SAINTSBOOK_COLOR_ICON_SELECTED.B) 
  616. 			 
  617. 			--Move text for button if gamepad is active 
  618. 			if game_is_active_input_gamepad() then 
  619. 				--Show button 
  620. 				vint_set_property(item.btn_obj.handle, "visible", true) 
  621. 				vint_set_property(item.title_txt_h, "anchor", 38, 19) 
  622. 			else 
  623. 				--Hide button 
  624. 				vint_set_property(item.btn_obj.handle, "visible", false) 
  625. 				vint_set_property(item.title_txt_h, "anchor", 8, 19) 
  626. 			end 
  627. 			 
  628. 			--Set description of text.. 
  629. 			local top_grp_h = vint_object_find("top_grp") 
  630. 			local item_desc_txt_h = vint_object_find("item_desc_txt", top_grp_h) 
  631. 			local description_txt = Cell_saintsbook_top_descriptions[item.filter_index] 
  632. 			vint_set_property(item_desc_txt_h, "text_tag", description_txt) 
  633. 			 
  634. 			--Stream in image... 
  635. 			local image = Cell_saintsbook_top_pegs[item.filter_index] 
  636. 			local image_bmp_h = vint_object_find("top_image_bmp", top_grp_h) 
  637. 			vint_set_property(image_bmp_h, "image", image) 
  638. 			 
  639. 		else 
  640. 			--Un-select this item... 
  641. 			vint_set_property(item.title_txt_h, 		"tint", SAINTSBOOK_COLOR_TOP_TEXT_UNSELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_UNSELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_UNSELECTED.B) 
  642. 			vint_set_property(item.bg_h, 					"tint", SAINTSBOOK_COLOR_TOP_BG_UNSELECTED.R, SAINTSBOOK_COLOR_TOP_BG_UNSELECTED.G, SAINTSBOOK_COLOR_TOP_BG_UNSELECTED.B) 
  643. 			vint_set_property(item.icon_bmp_h, 			"tint", SAINTSBOOK_COLOR_ICON_UNSELECTED.R, SAINTSBOOK_COLOR_ICON_UNSELECTED.G, SAINTSBOOK_COLOR_ICON_UNSELECTED.B) 
  644. 			vint_set_property(item.completed_txt_h, 	"tint", SAINTSBOOK_COLOR_ICON_UNSELECTED.R, SAINTSBOOK_COLOR_ICON_UNSELECTED.G, SAINTSBOOK_COLOR_ICON_UNSELECTED.B) 
  645. 		 
  646. 			--Hide button 
  647. 			vint_set_property(item.btn_obj.handle, "visible", false) 
  648. 			 
  649. 			--Move text 
  650. 			vint_set_property(item.title_txt_h, "anchor", 8, 19) 
  651. 		end	 
  652. 	end 
  653. 	 
  654. 	--store index... 
  655. 	Cell_saintsbook_top_selected_idx = item_index 
  656. end 
  657.  
  658. ------------------------------------------------------------------------------- 
  659. -- Top menu Nav callback 
  660. -- @direction	1 or -1 
  661. -- 
  662. function cell_saintsbook_top_nav(direction) 
  663. 	local item_to_select = Cell_saintsbook_top_selected_idx + direction 
  664. 	local num_items = #Cell_saintsbook_top_items 
  665. 	 
  666. 	if item_to_select > num_items then 
  667. 		item_to_select = 1 
  668. 	elseif item_to_select < 1 then 
  669. 		item_to_select = num_items  
  670. 	end 
  671. 	 
  672. 	cell_saintsbook_top_highlight_item(item_to_select) 
  673. 	game_UI_audio_play("UI_Cell_Nav") 
  674. end 
  675.  
  676. ------------------------------------------------------------------------------- 
  677. -- Opens selected top level item. 
  678. -- 
  679. function cell_saintsbook_top_select() 
  680. 	--lock controls 
  681. 	cell_saintsbook_controls_lock() 
  682.  
  683. 	--get selected item. 
  684. 	local selected_item = Cell_saintsbook_top_items[Cell_saintsbook_top_selected_idx]  
  685. 	local filter_index = selected_item.filter_index 
  686. 		 
  687. 	--Build main screen from our filter index. 
  688. 	cell_saintsbook_main_open_stage_1(filter_index) 
  689. 	 
  690. 	game_UI_audio_play("UI_Cell_Select") 
  691. end 
  692.  
  693.  
  694. ------------------------------------------------------------------------------- 
  695. -- Builds the section main menu. 
  696. -- @item_type	SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS, SAINTSBOOK_ITEM_TYPE_CHOPSHOP, SAINTSBOOK_ITEM_TYPE_CHALLENGE 
  697. -- 
  698. function cell_saintsbook_main_open_stage_1(item_type) 
  699. 	 
  700. 	--Remove items from list... 
  701. 	for idx, val in pairs(Cell_saintsbook_items) do 
  702. 		if val.item_h ~= nil then 
  703. 			vint_object_destroy(val.item_h) 
  704. 		end 
  705. 	end 
  706. 	 
  707. 	--Reset list... 
  708. 	Cell_saintsbook_item_count = 0  
  709. 	Cell_saintsbook_items = {} 
  710. 	 
  711. 	--Populate list... 
  712. 	vint_dataresponder_request("saintsbook_categories", "cell_saintsbook_populate", 0, item_type) 
  713. 	 
  714. 	--Sort List, puts completed items at the back of the list... 
  715. 	cell_saintsbook_sort() 
  716. 	 
  717. 	local thumbnail_peg = Cell_saintsbook_main_pegs[item_type] 
  718. 	game_peg_load_with_cb("cell_saintsbook_main_open_stage_2", 1, thumbnail_peg) 
  719. 	 
  720. end 
  721.  
  722. --This is called via callback after we load our stuff... 
  723. function cell_saintsbook_main_open_stage_2() 
  724. 	 
  725. 	--reset list position... 
  726. 	local h = vint_object_find("main_sub_grp") 
  727. 	vint_set_property(h, "anchor", 0,0) 
  728. 	local scroll_anim_h = vint_object_find("main_scroll_anim") 
  729. 	local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h) 
  730. 	vint_set_property(twn_h, "start_value", 0, 0) 
  731. 	 
  732. 	-- Show items in list... 
  733. 	cell_saintsbook_main_show_items(0) 
  734. 	cell_saintsbook_main_highlight_item(0) 
  735. 	 
  736. 	if Cell_saintsbook_item_count > 4 then 
  737. 		local h = vint_object_find("content_clip") 
  738. 		local width, height = vint_get_property(h, "clip_size") 
  739.  
  740. 		--show the scroll bar 
  741. 		Cell_saintsbook_main_scrollbar:set_property("visible", true) 
  742. 		Cell_saintsbook_main_scrollbar:set_size(SCROLLBAR_WIDTH, height) 
  743. 	else  
  744. 		-- hide the scroll bar 
  745. 		Cell_saintsbook_main_scrollbar:set_property("visible", false) 
  746. 	end 
  747. 	 
  748. 	--Show the main screen.... 
  749. 	cell_saintsbook_active_screen_set(SCREEN_TYPE_MAIN) 
  750. 	 
  751. end 
  752.  
  753.  
  754. --TODO: organize these... 
  755. Cell_saintsbook_main_first_item 	= 0 
  756. Cell_saintsbook_main_last_item 	= 0 
  757.  
  758. local main_first_mouse_item 	= 0 
  759. local main_last_mouse_item 	= 0 
  760.  
  761. ------------------------------------------------------------------------------- 
  762. -- Clears our current items in list and rebuilds them from the first to last... 
  763. -- 
  764. -- @param	first_item		# of the first item you want to draw... 
  765. -- 
  766. function cell_saintsbook_main_show_items(first_item, old_item) 
  767. 	if game_get_platform() == "PC" and Cell_saintsbook_scroll_tween_done == false then 
  768. 		return 
  769. 	end 
  770. 		 
  771. 	--Remove any existing items... 
  772. 	for i, item in pairs(Cell_saintsbook_items) do 
  773. 		if item.item_h ~= nil then 
  774. 			vint_object_destroy(item.item_h) 
  775. 			item.item_h = nil 
  776. 		end		 
  777. 	end 
  778. 	 
  779. 	--Loop through items and build list 
  780. 	local main_item_h = vint_object_find("main_item") 
  781. 	vint_set_property(main_item_h, "visible", false) 
  782. 		 
  783. 	if first_item < 0 then 
  784. 		first_item = 0  
  785. 	end 
  786. 	 
  787. 	Cell_saintsbook_main_first_item 	= first_item 
  788. 	Cell_saintsbook_main_last_item 	= first_item + SAINTSBOOK_MAIN_MAX_ITEMS + 1 
  789. 	 
  790. 	-- Set the range of the mouse inputs 
  791. 	main_first_mouse_item = first_item 
  792. 	main_last_mouse_item = main_first_mouse_item + 3 
  793. 	 
  794. 	-- If scrolling down, offset by 1 item 
  795. 	if old_item ~= nil then 
  796. 		if first_item > old_item then 
  797. 			first_item = first_item - 1  
  798. 		end 
  799. 	end 
  800. 	 
  801. 	for i = first_item, Cell_saintsbook_main_last_item do 
  802. 		if i >= Cell_saintsbook_item_count then 
  803. 			if game_get_platform() == "PC" then 
  804. 				cell_saintsbook_main_pc_scroll(Cell_saintsbook_main_first_item, false, old_item) 
  805. 				cell_saintsbook_main_activate_mouse() 
  806. 			end 
  807. 			return 
  808. 		end 
  809.  
  810. 		--Do common stuff... 
  811. 		local item = Cell_saintsbook_items[i] 
  812. 		local item_clone_h = vint_object_clone(main_item_h) 
  813. 		vint_set_property(item_clone_h, "name", "main_item_clone") 
  814. 		vint_set_property(item_clone_h, "visible", true) 
  815.  
  816. 		--Set button image... 
  817. 		local hint_btn = Vdo_hint_button:new("main_btn", item_clone_h) 
  818. 		hint_btn:set_button(CTRL_MENU_BUTTON_A) 
  819. 	 
  820. 		--Set target name 
  821. 		local target_name_txt_h = vint_object_find("target_name_txt", item_clone_h) 
  822. 		if type(item.target_name) == "number" then 
  823. 			vint_set_property(target_name_txt_h, "text_tag_crc", item.target_name) 
  824. 		else 
  825. 			vint_set_property(target_name_txt_h, "text_tag", item.target_name) 
  826. 		end 
  827. 		 
  828. 		--Set target image... 
  829. 		local target_img_h = vint_object_find("target_img", item_clone_h) 
  830. 		vint_set_property(target_img_h, "image", item.target_image .. "_t") 
  831.  
  832. 		--Details... 
  833. 		local challenge_grp_h = vint_object_find("challenge_grp", item_clone_h) 
  834. 		local task_grp_h = vint_object_find("task_grp", item_clone_h) 
  835. 		 
  836. 		--is the item selected... we set this to hide at first and then show it later if needed. 
  837. 		local contact_target_bmp_h = vint_object_find("contact_target_bmp", item_clone_h) 
  838. 		vint_set_property(contact_target_bmp_h, "visible", false) 
  839. 		 
  840. 		--Fill out details... 
  841. 		if item.item_type == SAINTSBOOK_ITEM_TYPE_CHALLENGE then 
  842. 			--Challenge type... fill out data... 
  843.  
  844. 			-- Contact Name 
  845. 			local challenge_contact_txt_h = vint_object_find("challenge_contact_txt", item_clone_h) 
  846. 			vint_set_property(challenge_contact_txt_h, "text_tag", item.contact_name) 
  847. 			 
  848. 			--challenge_x_y 
  849. 			local x_y_h = vint_object_find("challenge_x_y", item_clone_h) 
  850. 			if item.units_crc ~= 0 then 
  851. 				local insert = { [0] = floor(item.units_completed),[1] = floor(item.units_total), [2] = item.units_crc } 
  852. 				local x_y_str = vint_insert_values_in_string("DIVERSION_CHALLENGES_UNITS", insert) 
  853. 				vint_set_property(x_y_h, "text_tag", x_y_str) 
  854. 			else 
  855. 				vint_set_property(x_y_h, "text_tag", floor(item.units_completed).. "/" ..floor(item.units_total)) 
  856. 			end 
  857. 			 
  858. 			--meter 
  859. 			local meter_bg_h = vint_object_find("meter_bg", item_clone_h) 
  860. 			local meter_fill_h = vint_object_find("meter_fill", item_clone_h) 
  861. 			local meter_max_width, meter_max_height = element_get_actual_size(meter_bg_h) 
  862. 			 
  863. 			local pct = 0 
  864. 			if item.units_total ~= 0 then 
  865. 				pct = item.units_completed/item.units_total 
  866. 			end 
  867. 			 
  868. 			local meter_target_width = meter_max_width * pct 
  869. 			element_set_actual_size(meter_fill_h, meter_target_width, meter_max_height) 
  870.  
  871. 			--Remove unneeded item... 
  872. 			vint_object_destroy(task_grp_h) 
  873. 		else 
  874. 			--Hitman/chopshop type... 
  875.  
  876. 			local contact_name_txt_h = vint_object_find("contact_name_txt", item_clone_h) 
  877. 			vint_set_property(contact_name_txt_h, "text_tag", item.contact_name) 
  878. 			 
  879. 			--task_description 
  880. 			local task_description_h = vint_object_find("task_description", item_clone_h) 
  881. 			vint_set_property(task_description_h, "text_tag_crc", item.blurb_condensed) 
  882. 			 
  883. 			--If selected item we need to show the icon  
  884. 			if item.is_selected == true then 
  885. 				--Show icon 
  886. 				vint_set_property(contact_target_bmp_h, "visible", true) 
  887. 				 
  888. 				--Get icon name from type... 
  889. 				local icon_image = Cell_saintsbook_icons[item.item_type] 
  890. 				vint_set_property(contact_target_bmp_h, "image", icon_image) 
  891. 			end 
  892. 			 
  893. 			--Remove unneeded item... 
  894. 			vint_object_destroy(challenge_grp_h) 
  895. 		end 
  896. 		 
  897. 		--Reposition elements according to their index... 
  898. 		local x, y = vint_get_property(main_item_h, "anchor") 
  899. 		local target_x = x 
  900. 		local target_y = y + (SAINTSBOOK_MAIN_ITEM_SPACING * i) 
  901. 		vint_set_property(item_clone_h, "anchor", target_x, target_y) 
  902. 	 
  903. 		local highlight_bg_h = vint_object_find("highlight_bg", item_clone_h) 
  904. 		local highlight_mouse_bg_h = vint_object_find("background", item_clone_h) 
  905. 		if game_get_platform() == "PC" then 
  906. 			item.highlight_h = highlight_mouse_bg_h 
  907. 		end 
  908. 		 
  909. 		if Cell_saintsbook_main_selected_idx == i then 
  910. 			--Item is selected... 
  911. 			vint_set_property(highlight_bg_h, "visible", true) 
  912. 			vint_set_property(target_name_txt_h, "tint", SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.B) 
  913. 			-- Hide the button if not using the gamepad 
  914. 			if game_is_active_input_gamepad() == false then 
  915. 				local x, y = vint_get_property(target_name_txt_h, "anchor") 
  916. 				x = x - 38 
  917. 				vint_set_property(target_name_txt_h, "anchor", x,y) 
  918. 				hint_btn:set_visible(false) 
  919. 			end 
  920. 		else 
  921. 			--item is not selected... 
  922. 			hint_btn:set_visible(false) 
  923. 			--Item is selected... 
  924. 			vint_set_property(highlight_bg_h, "visible", false) 
  925. 			local x, y = vint_get_property(target_name_txt_h, "anchor") 
  926. 			x = x - 38 
  927. 			vint_set_property(target_name_txt_h, "anchor", x,y) 
  928. 		 
  929. 			--delete border frame... 
  930. 			local contact_highlight_h = vint_object_find("contact_highlight", item_clone_h) 
  931. 			vint_object_destroy(contact_highlight_h) 
  932. 		end 
  933. 		 
  934. 		--set disabled or not... 
  935. 		if item.is_completed == true then 
  936. 			vint_set_property(item_clone_h, "alpha", .3) 
  937. 		end 
  938. 	 
  939. 		--store clone to item table... 
  940. 		item.item_h = item_clone_h 
  941. 		item.hint_btn = hint_btn 
  942. 	end 
  943. 	 
  944. 	if game_get_platform() == "PC" then 
  945. 		cell_saintsbook_main_pc_scroll(Cell_saintsbook_main_first_item, false, old_item) 
  946. 		cell_saintsbook_main_activate_mouse() 
  947. 	end 
  948. end 
  949.  
  950. function cell_saintsbook_main_activate_mouse() 
  951. 	if Mouse_input_tracker ~= nil then 
  952. 		Mouse_input_tracker:remove_all() 
  953. 		for i = main_first_mouse_item, main_last_mouse_item do 
  954. 			if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then 
  955. 				Mouse_input_tracker:add_mouse_input("mouse_move", "cell_saintsbook_main_mouse_move", 0, Cell_saintsbook_items[i].highlight_h) 
  956. 				Mouse_input_tracker:add_mouse_input("mouse_click", "cell_saintsbook_main_mouse_click", 0, Cell_saintsbook_items[i].highlight_h) 
  957. 			end 
  958. 		end 
  959. 		Hint_bar:add_mouse_inputs("cell_saintsbook", Mouse_input_tracker) 
  960. 		Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_saintsbook_mouse_scroll", 0, Clip_region.handle) 
  961. 		Mouse_input_tracker:subscribe(true) 
  962. 		if Scrollbar_mouse_input_tracker.enabled == false then 
  963. 			Scrollbar_mouse_input_tracker:remove_all() 
  964. 			Cell_saintsbook_main_scrollbar:add_mouse_inputs("cell_saintsbook_main", Scrollbar_mouse_input_tracker, 0) 
  965. 		end 
  966. 		-- Only want to call :subscribe when switching to this screen, not when updating the mouse 
  967. 		if Scrollbar_mouse_input_tracker.enabled == false then 
  968. 			Scrollbar_mouse_input_tracker:subscribe(true) 
  969. 			Scrollbar_mouse_input_tracker.enabled = true 
  970. 		end 
  971. 	end 
  972. end 
  973.  
  974. function cell_saintsbook_main_mouse_click(event, target_handle) 
  975. 	local new_index = -1 
  976. 	for i = 0, Cell_saintsbook_item_count do 
  977. 		if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then 
  978. 			if target_handle == Cell_saintsbook_items[i].highlight_h then 
  979. 				new_index = i 
  980. 			end 
  981. 		end 
  982. 	end 
  983. 	 
  984. 	if new_index > -1 then 
  985. 		Cell_saintsbook_main_selected_idx = new_index 
  986. 		cell_saintsbook_main_select() 
  987. 		game_UI_audio_play("UI_Cell_Nav") 
  988. 	end 
  989. end 
  990.  
  991. function cell_saintsbook_main_mouse_move(event, target_handle) 
  992. 	local new_index = -1 
  993. 	for i = 0, Cell_saintsbook_item_count do 
  994. 		if Cell_saintsbook_items[i] ~= nil and Cell_saintsbook_items[i].highlight_h ~= nil then 
  995. 			if target_handle == Cell_saintsbook_items[i].highlight_h then 
  996. 				new_index = i 
  997. 			end 
  998. 		end 
  999. 	end 
  1000. 	 
  1001. 	if new_index > -1 then 
  1002. 		if new_index ~= Cell_saintsbook_main_selected_idx then 
  1003. 			Cell_saintsbook_main_selected_idx = new_index 
  1004. 			cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item) 
  1005. 			game_UI_audio_play("UI_Cell_Nav") 
  1006. 		end 
  1007. 	end 
  1008. end 
  1009.  
  1010. function cell_saintsbook_main_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  1011. 	if Active_screen_type == SCREEN_TYPE_MAIN then 
  1012. 		if Cell_saintsbook_main_scrollbar.tab.handle == target_handle then 
  1013. 			local new_start_index = Cell_saintsbook_main_scrollbar:drag_scrolltab(mouse_y, Cell_saintsbook_item_count - 3) 
  1014. 			new_start_index = new_start_index - 1 
  1015. 			cell_saintsbook_main_show_items(new_start_index, Cell_saintsbook_main_first_item) 
  1016. 		end 
  1017. 	end 
  1018. end 
  1019.  
  1020. -- Updates the mouse inputs for the list and snaps the scrolltab to the closest notch based on the visible index 
  1021. -- 
  1022. function cell_saintsbook_main_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  1023. 	if Active_screen_type == SCREEN_TYPE_MAIN then 
  1024. 		if Cell_saintsbook_main_scrollbar.tab.handle == target_handle then 
  1025. 			Cell_saintsbook_main_scrollbar:release_scrolltab(Cell_saintsbook_main_first_item + 1, Cell_saintsbook_item_count - 3) 
  1026. 		end 
  1027. 	end 
  1028. end 
  1029.  
  1030. function cell_saintsbook_main_nav(direction, index_to_set) 
  1031. 	if Cell_saintsbook_scroll_tween_done == false then 
  1032. 		return 
  1033. 	end 
  1034.  
  1035. 	local instant_set = false 
  1036. 	 
  1037. 	local item_to_select = Cell_saintsbook_main_selected_idx + direction 
  1038. 	if direction == 0 then 
  1039. 		item_to_select = index_to_set 
  1040. 	end 
  1041. 	 
  1042. 	if item_to_select >= Cell_saintsbook_item_count then 
  1043. 		item_to_select = 0 
  1044. 		instant_set = true 
  1045. 	elseif item_to_select < 0 then 
  1046. 		item_to_select = Cell_saintsbook_item_count - 1 
  1047. 		instant_set = true 
  1048. 	end 
  1049. 	 
  1050. 	--This is where we should probably send the index and rebuild the list... 
  1051. 	if game_get_platform() == "PC" then 
  1052. 		-- Select the item 
  1053. 		Cell_saintsbook_main_selected_idx = item_to_select 
  1054. 		 
  1055. 		-- Maybe scroll 
  1056. 		local scroll_item = Cell_saintsbook_main_first_item 
  1057. 		if Cell_saintsbook_main_selected_idx < main_first_mouse_item then 
  1058. 			scroll_item = Cell_saintsbook_main_selected_idx 
  1059. 		elseif Cell_saintsbook_main_selected_idx > main_last_mouse_item then 
  1060. 			scroll_item = Cell_saintsbook_main_selected_idx - 3 
  1061. 		end 
  1062. 		 
  1063. 		cell_saintsbook_main_show_items(scroll_item, Cell_saintsbook_main_first_item) 
  1064. 	else 
  1065. 		cell_saintsbook_main_highlight_item(item_to_select, instant_set) 
  1066. 	end 
  1067. 	game_UI_audio_play("UI_Cell_Nav") 
  1068. end 
  1069.  
  1070. ------------------------------------------------------------------------------- 
  1071. -- Navigates back to the top menu 
  1072. -- 
  1073. function cell_saintsbook_main_back() 
  1074. 	--lock controls 
  1075. 	cell_saintsbook_controls_lock() 
  1076.  
  1077. 	--Set active screen to top. 
  1078. 	cell_saintsbook_active_screen_set(SCREEN_TYPE_TOP) 
  1079. end 
  1080.  
  1081. function cell_saintsbook_main_select() 
  1082. 	--lock controls 
  1083. 	cell_saintsbook_controls_lock() 
  1084.  
  1085. 	cell_saintsbook_sub_open_stage_1() 
  1086. 	 
  1087. 	game_UI_audio_play("UI_Cell_Select") 
  1088. 	 
  1089. end 
  1090.  
  1091. function cell_saintsbook_main_pc_scroll(first_item, instant_set, old_item) 
  1092. 	if instant_set == true then 
  1093. 		local new_y = 0 
  1094. 		if first_item + 2 >= Cell_saintsbook_item_count then 
  1095. 			new_y = -(Cell_saintsbook_item_count - 3) * SAINTSBOOK_MAIN_ITEM_SPACING 
  1096. 		else 
  1097. 			new_y = -first_item * SAINTSBOOK_MAIN_ITEM_SPACING 
  1098. 		end 
  1099. 		 
  1100. 		local h = vint_object_find("main_sub_grp") 
  1101. 		vint_set_property(h, "anchor", 0, new_y) 
  1102. 		 
  1103. 		h = vint_object_find("root_animation") 
  1104. 		local scroll_anim_h = vint_object_find("main_scroll_anim", h) 
  1105. 		local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h) 
  1106. 		vint_set_property(twn_h, "start_value", 0, new_y) 
  1107. 	else  
  1108. 		if first_item + 1 == old_item then 
  1109. 			cell_saintsbook_main_animate_scroll(false) 
  1110. 		elseif first_item - 1 == old_item then 
  1111. 			cell_saintsbook_main_animate_scroll(true) 
  1112. 		else 
  1113. 			cell_saintsbook_main_pc_scroll(first_item, true) 
  1114. 		end 
  1115. 	end 
  1116. 	Cell_saintsbook_main_scrollbar:set_value(Cell_saintsbook_item_count - 3, first_item + 1, false) 
  1117. end 
  1118.  
  1119. ------------------------------------------------------------------------------- 
  1120. -- Highlights a specific item and scrolls to it. 
  1121. -- 
  1122. function cell_saintsbook_main_highlight_item(item_index, instant_set) 
  1123. 	local nav_down = Cell_saintsbook_main_selected_idx < item_index 
  1124. 	local old_index = Cell_saintsbook_main_selected_idx 
  1125.  
  1126. 	Cell_saintsbook_main_selected_idx = item_index 
  1127. 	if game_get_platform() ~= "PC" then 
  1128. 		Cell_saintsbook_main_scrollbar:set_value(Cell_saintsbook_item_count , Cell_saintsbook_main_selected_idx + 1, false) 
  1129. 		 
  1130. 		if instant_set == true then 
  1131. 			local new_y = 0 
  1132. 			if (nav_down == true and item_index + 2 >= Cell_saintsbook_item_count) or 
  1133. 				(nav_down == false and item_index + 3 >= Cell_saintsbook_item_count) then 
  1134. 				cell_saintsbook_main_show_items(Cell_saintsbook_item_count - 4 - 1) 
  1135. 				new_y = -(Cell_saintsbook_item_count - 4) * SAINTSBOOK_MAIN_ITEM_SPACING 
  1136. 			else 
  1137. 				new_y = -item_index * SAINTSBOOK_MAIN_ITEM_SPACING 
  1138. 				cell_saintsbook_main_show_items(max(item_index - 2, 0)) 
  1139. 			end 
  1140. 			 
  1141. 			local h = vint_object_find("main_sub_grp") 
  1142. 			vint_set_property(h, "anchor", 0, new_y) 
  1143. 			 
  1144. 			h = vint_object_find("root_animation") 
  1145. 			local scroll_anim_h = vint_object_find("main_scroll_anim", h) 
  1146. 			local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h) 
  1147. 			vint_set_property(twn_h, "start_value", 0, new_y) 
  1148.  
  1149. 			return 
  1150. 		end 
  1151. 		 
  1152. 		local animate = true 
  1153. 		-- step 1 - rebuild new list 
  1154. 		if nav_down == true and item_index - 2 < 0 then 
  1155. 			cell_saintsbook_main_show_items(0) 
  1156. 			animate = false 
  1157. 		end 
  1158. 		 
  1159. 		if nav_down == false and item_index == 0 then 
  1160. 			cell_saintsbook_main_show_items(0) 
  1161. 			animate = false 
  1162. 		end 
  1163.  
  1164. 		if (nav_down == true and item_index + 2 >= Cell_saintsbook_item_count) or 
  1165. 			(nav_down == false and item_index + 3 >= Cell_saintsbook_item_count) then 
  1166. 			cell_saintsbook_main_show_items(Cell_saintsbook_item_count - 4 - 1) 
  1167. 			animate = false 
  1168. 		end 
  1169. 			 
  1170. 		-- step 3 - animate 
  1171. 		if animate then  
  1172. 			cell_saintsbook_main_show_items(Cell_saintsbook_main_selected_idx - 2) 
  1173. 			cell_saintsbook_main_animate_scroll(nav_down) 
  1174. 		end 
  1175. 	end 
  1176. end 
  1177.  
  1178. function cell_saintsbook_main_animate_scroll(nav_down) 
  1179. 	local h = vint_object_find("root_animation") 
  1180. 	local scroll_anim_h = vint_object_find("main_scroll_anim", h) 
  1181. 	local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h) 
  1182. 	local x, y = vint_get_property(twn_h, "start_value") 
  1183. 	vint_set_property(twn_h, "duration", 0.2) 
  1184. 	if nav_down == true then 
  1185. 		vint_set_property(twn_h, "end_value", x, y - SAINTSBOOK_MAIN_ITEM_SPACING) 
  1186. 	else		 
  1187. 		vint_set_property(twn_h, "end_value", x, y + SAINTSBOOK_MAIN_ITEM_SPACING) 
  1188. 	end 
  1189. 	vint_set_property(twn_h, "end_event", "cell_saintsbook_finish_scroll") 
  1190. 	lua_play_anim(scroll_anim_h, 0)	 
  1191. 	Cell_saintsbook_scroll_tween_done = false 
  1192. end 
  1193.  
  1194. function cell_saintsbook_finish_scroll() 
  1195. 	local h = vint_object_find("root_animation") 
  1196. 	local scroll_anim_h = vint_object_find("main_scroll_anim", h) 
  1197. 	local twn_h = vint_object_find("main_scroll_twn", scroll_anim_h) 
  1198. 	local new_x, new_y = vint_get_property(twn_h, "end_value") 
  1199. 	vint_set_property(twn_h, "start_value", new_x, new_y) 
  1200.  
  1201. 	Cell_saintsbook_scroll_tween_done = true 
  1202. end 
  1203.  
  1204.  
  1205.  
  1206. ------------------------------------------------------------------------------- 
  1207. ------------------------------------------------------------------------------- 
  1208. -- Sub page display. 
  1209. ------------------------------------------------------------------------------- 
  1210. ------------------------------------------------------------------------------- 
  1211.  
  1212. Cell_saintsbook_sub_task_mask_height = 0 
  1213. Cell_saintsbook_sub_task_height = 0 
  1214. Cell_saintsbook_scroll_direction = 0 
  1215. Cell_saintsbook_scroll_enabled = false 
  1216. Cell_saintsbook_sub_scrollbar_thread = 0 
  1217.  
  1218. CELL_SAINTSBOOK_SUB_PIXEL_RATE = 20 
  1219. CELL_SAINTSBOOK_SUB_DURATION = 0.05 
  1220.  
  1221.  
  1222. ------------------------------------------------------------------------------- 
  1223. -- Opens sub page from currently selected main index... 
  1224. -- 
  1225. function cell_saintsbook_sub_open_stage_1() 
  1226. 	if Cell_saintsbook_item_count == 0 then 
  1227. 		return 
  1228. 	end 
  1229.  
  1230. 	-- Populate sub page with selected data from main page... 
  1231. 	local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx] 
  1232. 		 
  1233. 	-- Unload old image if exists... 
  1234. 	if Cell_saintsbook_contact_image ~= -1 then 
  1235. 		game_peg_unload(Cell_saintsbook_contact_image) 
  1236. 	end 
  1237. 	if Cell_saintsbook_target_image ~= -1 then 
  1238. 		game_peg_unload(Cell_saintsbook_target_image) 
  1239. 	end 
  1240. 	 
  1241. 	-- Stream the image and wait... 
  1242. 	Cell_saintsbook_contact_image = cell_saintsbook_contact_image_get(item.contact_image) 
  1243. 	Cell_saintsbook_target_image = item.target_image 
  1244. 	 
  1245. 	game_peg_load_with_cb("cell_saintsbook_sub_open_stage_2", 2, Cell_saintsbook_contact_image, Cell_saintsbook_target_image) 
  1246. end 
  1247.  
  1248. function cell_saintsbook_sub_open_stage_2() 
  1249.  
  1250. 	-- Populate sub page with selected data from main page... 
  1251. 	local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx] 
  1252. 	local subpage_grp_h 	= vint_object_find("subpage_grp") 
  1253. 	local mask_h 			= vint_object_find("mask", 					subpage_grp_h) 
  1254. 	local mask_width, mask_height = element_get_actual_size(mask_h) 
  1255. 	Cell_saintsbook_sub_task_mask_height = mask_height 
  1256. 	 
  1257. 	--Find challenge and location groups 
  1258. 	local challenge_grp_h 	= vint_object_find("challenge_grp", subpage_grp_h) 
  1259. 	local location_grp_h 	= vint_object_find("location_grp", 	subpage_grp_h) 
  1260. 	local gps_grp_h 			= vint_object_find("gps_grp", 		subpage_grp_h) 
  1261. 	local selected_grp_h 	= vint_object_find("selected_grp", 	subpage_grp_h) 
  1262. 	local task_icon_grp_h 	= vint_object_find("task_icon_grp", subpage_grp_h) 
  1263. 	local completed_txt_h 	= vint_object_find("completed_txt", subpage_grp_h) 
  1264. 	 
  1265. 	--Hide challenge and location groups, will show these depending on which mode we are in. 
  1266. 	vint_set_property(challenge_grp_h, 	"visible", false) 
  1267. 	vint_set_property(location_grp_h, 	"visible", false) 
  1268. 	vint_set_property(gps_grp_h, 			"visible", false) 
  1269. 	vint_set_property(task_icon_grp_h, 	"visible", false) 
  1270. 	vint_set_property(selected_grp_h, 	"visible", false) 
  1271. 	vint_set_property(completed_txt_h, 	"visible", false) 
  1272.  
  1273. 	--Set Completed or not... 
  1274. 	if item.is_completed == true then 
  1275. 		vint_set_property(subpage_grp_h, "alpha", .3) 
  1276. 		vint_set_property(completed_txt_h, "visible", true) 
  1277. 	else 
  1278. 		vint_set_property(subpage_grp_h, "alpha", 1) 
  1279. 	end 
  1280. 	 
  1281. 	--Common elements.... 
  1282. 	local target_name_txt_h 		= vint_object_find("target_name_txt", 		subpage_grp_h) 
  1283. 	local target_img_h 				= vint_object_find("target_img", 			subpage_grp_h) 
  1284. 	local location_desc_txt_h 		= vint_object_find("location_desc_txt", 	subpage_grp_h) 
  1285. 	local cash_desc_txt_h 			= vint_object_find("cash_desc_txt", 		subpage_grp_h) 
  1286. 	local respect_desc_txt_h 		= vint_object_find("respect_desc_txt", 	subpage_grp_h) 
  1287.  
  1288. 	local contact_name_h				= vint_object_find("contact_name", 			subpage_grp_h) 
  1289. 	local contact_image_h			= vint_object_find("contact_img", 			subpage_grp_h) 
  1290. 	local task_condensed_h  		= vint_object_find("task_condensed", 		subpage_grp_h) 
  1291. 	local task_icon_desc_h  		= vint_object_find("task_icon_desc", 		subpage_grp_h) 
  1292. 	local task_long_h  				= vint_object_find("task_long", 				subpage_grp_h) 
  1293. 	 
  1294. 	--Set our target name... 
  1295. 	if type(item.target_name) == "number" then 
  1296. 		vint_set_property(target_name_txt_h, "text_tag_crc", item.target_name) 
  1297. 	else 
  1298. 		vint_set_property(target_name_txt_h, "text_tag", item.target_name) 
  1299. 	end 
  1300. 	 
  1301. 	--Make sure russian fits here...  
  1302. 	--Check widths against max size... 
  1303. 	local max_width = 510 
  1304. 	vint_set_property(target_name_txt_h, "scale", 1, 1) 
  1305. 	local width, height = element_get_actual_size(target_name_txt_h) 
  1306. 	 
  1307. 	if width > max_width then 
  1308. 		local scale = max_width / width 
  1309. 		width = width * scale 
  1310. 		element_set_actual_size(target_name_txt_h, width, height) 
  1311. 	end 
  1312. 	 
  1313. 	 
  1314. 	--Target image 
  1315. 	vint_set_property(target_img_h, "image", item.target_image) 
  1316.  
  1317. 	--Cash and Respect 
  1318. 	vint_set_property(cash_desc_txt_h, "text_tag", "$" .. format_cash(item.cash)) 
  1319. 	vint_set_property(respect_desc_txt_h, "text_tag", item.respect) 
  1320. 	 
  1321. 	--Contact Name 
  1322. 	vint_set_property(contact_name_h, "text_tag", item.contact_name) 
  1323. 	 
  1324. 	--Contact Image 
  1325. 	local contact_image = cell_saintsbook_contact_image_get(item.contact_image) 
  1326. 	vint_set_property(contact_image_h, "image", contact_image) 
  1327. 	 
  1328. 	 
  1329. 	--Setup scrollbox 
  1330. 	 
  1331. 	--Condensed Blurb 
  1332. 	if type(item.blurb_condensed) == "number" then 
  1333. 		vint_set_property(task_condensed_h, "text_tag_crc", item.blurb_condensed) 
  1334. 	else 
  1335. 		vint_set_property(task_condensed_h, "text_tag", item.blurb_condensed)	 
  1336. 	end 
  1337. 	 
  1338. 	--Long Blurb 
  1339. 	if type(item.blurb_long) == "number" then 
  1340. 		vint_set_property(task_long_h, "text_tag_crc", item.blurb_long) 
  1341. 	else 
  1342. 		vint_set_property(task_long_h, "text_tag", item.blurb_long) 
  1343. 	end 
  1344. 	 
  1345. 	--Arrange task descriptions 
  1346. 	local task_condensed_x, task_condensed_y = vint_get_property(task_condensed_h, "anchor") 
  1347. 	local task_long_x, task_long_y = vint_get_property(task_long_h, "anchor") 
  1348. 	 
  1349. 	local task_condensed_width, task_condensed_height = element_get_actual_size(task_condensed_h) 
  1350. 	local task_long_width, task_long_height = element_get_actual_size(task_long_h) 
  1351. 	 
  1352. 	if item.blurb_condensed == 0 then 
  1353. 		-- Hide condensed blurb 
  1354. 		vint_set_property(task_condensed_h, "visible", false) 
  1355. 		 
  1356. 		-- Reposition because we don't have a condensed blurb 
  1357. 		task_long_y = task_condensed_y 
  1358. 		vint_set_property(task_long_h, "anchor", task_long_x, task_long_y) 
  1359. 	else 
  1360. 		--Show condensed blurb 
  1361. 		vint_set_property(task_condensed_h, "visible", true) 
  1362. 		 
  1363. 		task_long_y = task_condensed_y + task_condensed_height 
  1364. 		vint_set_property(task_long_h, "anchor", task_long_x, task_condensed_y + task_condensed_height + 20) 
  1365. 	end 
  1366. 	 
  1367. 	Cell_saintsbook_sub_task_height = task_long_y + task_long_height 
  1368. 	 
  1369. 	if Cell_saintsbook_sub_task_mask_height < Cell_saintsbook_sub_task_height then 
  1370. 		Cell_saintsbook_sub_scrollbar:set_property("visible", true) 
  1371. 		Cell_saintsbook_sub_scrollbar:set_size(SCROLLBAR_WIDTH, Cell_saintsbook_sub_task_mask_height)	 
  1372. 		cell_saintsbook_sub_scrollbar_set() 
  1373. 		Cell_saintsbook_scroll_enabled = true 
  1374. 	else 
  1375. 		Cell_saintsbook_sub_scrollbar:set_property("visible", false)	 
  1376. 		Cell_saintsbook_scroll_enabled = false 
  1377. 	end 
  1378. 	 
  1379. 	 
  1380. 	 
  1381. 	local gps_txt_h = vint_object_find("gps_to_target_txt", gps_grp_h) 
  1382.  
  1383. 	-- Specific stuff pertaining to each type... 
  1384. 	if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS or item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then 
  1385. 	 
  1386. 		-- Show location info... 
  1387. 		vint_set_property(location_grp_h, "visible", true) 
  1388. 		 
  1389. 		--show GPS info 
  1390. 		vint_set_property(gps_grp_h, "visible", true) 
  1391.  
  1392. 		-- Set target location... 
  1393. 		if item.target_location == 0 then 
  1394. 			-- no target location so hide the field... 
  1395. 			vint_set_property(location_desc_txt_h, "visible", false) 
  1396. 		else 
  1397. 			vint_set_property(location_desc_txt_h, "visible", true) 
  1398. 			vint_set_property(location_desc_txt_h, "text_tag_crc", item.target_location) 
  1399. 		end 
  1400. 		 
  1401. 		-- Determine what icon to show for map finding... 
  1402. 		local task_icon_h = vint_object_find("task_icon", subpage_grp_h) 
  1403. 		if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then 
  1404. 			--Show assassination Icons... 
  1405. 			vint_set_property(task_icon_h, "image", "ui_saintsbook_hitman") 
  1406. 		elseif item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then 
  1407. 			--Show chopshop icons... 
  1408. 			vint_set_property(task_icon_h, "image", "ui_saintsbook_vehicle") 
  1409. 		end 
  1410. 		 
  1411. 		--Check if item is selected, then set it to selected target... 
  1412. 		if item.is_selected == true then 
  1413. 			Cell_saintsbook_selected_target = Cell_saintsbook_main_selected_idx 
  1414. 		else 
  1415. 			--not selected so we reset the selected target index. 
  1416. 			Cell_saintsbook_selected_target = -1 
  1417. 		end 
  1418. 		 
  1419. 		--Set selected target, this determines if the target is selected. 
  1420. 		cell_saintsbook_sub_set_selected() 
  1421. 		 
  1422. 	else 
  1423. 	 
  1424. 		-- Show challenge page... 
  1425. 		vint_set_property(challenge_grp_h, "visible", true) 
  1426.  
  1427. 		-- Find all objects first... 
  1428. 		local x_y_h 						= vint_object_find("challenge_x_y", 			challenge_grp_h) 
  1429. 		local meter_bg_h 					= vint_object_find("meter_bg", 					challenge_grp_h) 
  1430. 		local meter_fill_h 				= vint_object_find("meter_fill", 				challenge_grp_h) 
  1431.  
  1432. 		--challenge_x_y 
  1433. 		if item.units_crc ~= 0 then 
  1434. 			local insert = { [0] = floor(item.units_completed),[1] = floor(item.units_total), [2] = item.units_crc } 
  1435. 			local x_y_str = vint_insert_values_in_string("DIVERSION_CHALLENGES_UNITS", insert) 
  1436. 			vint_set_property(x_y_h, "text_tag", x_y_str) 
  1437. 		else 
  1438. 			vint_set_property(x_y_h, "text_tag", floor(item.units_completed).."/"..floor(item.units_total)) 
  1439. 		end 
  1440. 		 
  1441. 		-- Set Meter 
  1442. 		local meter_max_width, meter_max_height = element_get_actual_size(meter_bg_h) 
  1443. 		local pct = 0 
  1444. 		if item.units_total ~= 0 then 
  1445. 			pct = item.units_completed/item.units_total 
  1446. 		end 
  1447. 		 
  1448. 		local meter_target_width = meter_max_width * pct 
  1449. 		element_set_actual_size(meter_fill_h, meter_target_width, meter_max_height)	 
  1450. 	end 
  1451. 	 
  1452. 	--Reset Scrollbar... 
  1453. 	cell_saintsbook_sub_scrollbar_reset() 
  1454. 	 
  1455. 	--Navigate to sub screen... 
  1456. 	cell_saintsbook_active_screen_set(SCREEN_TYPE_SUB) 
  1457. 	 
  1458. 	cell_saintsbook_sub_activate_mouse() 
  1459. end 
  1460.  
  1461. function cell_saintsbook_sub_activate_mouse() 
  1462. 	if Mouse_input_tracker ~= nil then 
  1463. 		Mouse_input_tracker:remove_all() 
  1464.  
  1465. 		-- Select/deselect button 
  1466. 		local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx] 
  1467. 		if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS or item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then 
  1468. 			local subpage_grp_h = vint_object_find("subpage_grp") 
  1469. 			local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h) 
  1470. 			 
  1471. 			Mouse_input_tracker:add_mouse_input("mouse_move", "cell_saintsbook_mouse_move", 0, gps_grp_h) 
  1472. 			Mouse_input_tracker:add_mouse_input("mouse_click", "cell_saintsbook_mouse_click", 0, gps_grp_h) 
  1473. 		end 
  1474. 		Hint_bar:add_mouse_inputs("cell_saintsbook", Mouse_input_tracker) 
  1475. 		Mouse_input_tracker:add_mouse_input("mouse_scroll", "cell_saintsbook_mouse_scroll", 0, Clip_region.handle) 
  1476. 		Mouse_input_tracker:subscribe(true) 
  1477. 		Scrollbar_mouse_input_tracker:subscribe(false) 
  1478. 		Scrollbar_mouse_input_tracker.enabled = false 
  1479. 	end 
  1480. end 
  1481.  
  1482. function cell_saintsbook_sub_mouse_click(event, target_handle) 
  1483. 	local subpage_grp_h = vint_object_find("subpage_grp") 
  1484. 	local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h) 
  1485. 	 
  1486. 	if target_handle == gps_grp_h then 
  1487. 		cell_saintsbook_sub_select() 
  1488. 	end 
  1489. end 
  1490.  
  1491. function cell_saintsbook_sub_mouse_move(event, target_handle) 
  1492. 	local subpage_grp_h = vint_object_find("subpage_grp") 
  1493. 	local gps_txt_h = vint_object_find("gps_to_target_txt", subpage_grp_h) 
  1494. 	 
  1495. 	vint_set_property(gps_txt_h, "tint", SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.R, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.G, SAINTSBOOK_COLOR_TOP_TEXT_SELECTED.B) 
  1496. 	local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h) 
  1497. 	if target_handle == gps_grp_h then 
  1498. 		vint_set_property(gps_txt_h, "tint", SAINTSBOOK_COLOR_ICON_SELECTED.R, SAINTSBOOK_COLOR_ICON_SELECTED.G, SAINTSBOOK_COLOR_ICON_SELECTED.B) 
  1499. 	end 
  1500. end 
  1501.  
  1502. function cell_saintsbook_sub_nav(event, value) 
  1503. 	if Cell_saintsbook_scroll_enabled == false then 
  1504. 		return 
  1505. 	end 
  1506. 	local h = vint_object_find("root_animation") 
  1507. 	local scroll_anim_h = vint_object_find("sub_scroll_anim", h) 
  1508.  
  1509. 	-- First check if the stick is pointed in any direction 
  1510. 	if abs(value) < 0.5 then 
  1511. 		-- Stop scrolling if it's not 
  1512. 		if Cell_saintsbook_scroll_direction ~= 0 then 
  1513. 			 
  1514. 			-- Kill the thread for scrolling 
  1515. 			if Cell_saintsbook_sub_scrollbar_thread ~= 0 then 
  1516. 				thread_kill(Cell_saintsbook_sub_scrollbar_thread) 
  1517. 				Cell_saintsbook_sub_scrollbar_thread = 0 
  1518. 			end 
  1519.  
  1520. 			-- Pause the animation 
  1521. 			vint_set_property(scroll_anim_h, "is_paused", true) 
  1522. 			Cell_saintsbook_scroll_direction = 0 
  1523. 			cell_saintsbook_sub_scrollbar_set() 
  1524. 		end 
  1525. 	else 
  1526. 		-- Just continue tweening if we're still going in the same direction 
  1527. 		if (Cell_saintsbook_scroll_direction > 0 and value > 0) or 
  1528. 			(Cell_saintsbook_scroll_direction < 0 and value < 0) then 
  1529. 			return 
  1530. 		elseif Cell_saintsbook_scroll_direction ~= 0 then 
  1531. 			-- Stop the animation if we're changing direction 
  1532. 			vint_set_property(scroll_anim_h, "is_paused", true) 
  1533. 		end 
  1534. 		 
  1535. 		-- Kill the thread if it exists, and reset the scrollbar 
  1536. 		if Cell_saintsbook_sub_scrollbar_thread ~= 0 then 
  1537. 			thread_kill(Cell_saintsbook_sub_scrollbar_thread) 
  1538. 			Cell_saintsbook_sub_scrollbar_thread = 0 
  1539. 			cell_saintsbook_sub_scrollbar_set() 
  1540. 		end 
  1541. 		 
  1542. 		-- If the value is negative, we're naving down 
  1543. 		local nav_down = (value < 0) 
  1544. 		local movement = 0 
  1545. 		local pixel_per_duration = 0 
  1546.  
  1547. 		local subpage_grp_h 	= vint_object_find("subpage_grp") 
  1548. 		local task_long_h 	= vint_object_find("task_desc_scroll", subpage_grp_h) 
  1549. 		local task_x, task_y = vint_get_property(task_long_h, "anchor") 
  1550. 		 
  1551. 		-- Find the bottom of the text 
  1552. 		local task_bottom = task_y + Cell_saintsbook_sub_task_height		 
  1553. 		 
  1554. 		-- Prepare for movement 
  1555. 		if nav_down == false then 
  1556. 			-- Move to the top 
  1557. 			if task_y < 0 then  
  1558. 				movement = -(task_y) 
  1559. 			end 
  1560. 		else  
  1561. 			-- Move to the bottom 
  1562. 			movement = -(task_bottom - Cell_saintsbook_sub_task_mask_height) 
  1563. 		end 
  1564. 		 
  1565. 		-- If we're going to be moving, then start the tween 
  1566. 		if movement ~= 0 then 
  1567. 			local twn_h 			= vint_object_find("sub_scroll_twn", scroll_anim_h) 
  1568. 			 
  1569. 			-- Calculate the duration of the tween, this is the amount of time it should take to scroll from the current position to bottom 
  1570. 			-- This speed should be consistent no matter how much movement is left 
  1571. 			local duration = CELL_SAINTSBOOK_SUB_DURATION * (abs(movement) / CELL_SAINTSBOOK_SUB_PIXEL_RATE) 
  1572. 			 
  1573. 			-- Create the tween, its told to scroll until it gets all the way to the top or the bottom, but will be killed when the  
  1574. 			-- stick is released 
  1575. 			vint_set_property(twn_h, "duration", duration) 
  1576. 			vint_set_property(twn_h, "start_value", task_x, task_y) 
  1577. 			vint_set_property(twn_h, "end_value", task_x, task_y + movement) 
  1578. 			vint_set_property(twn_h, "end_event", "cell_saintsbook_sub_finish_scroll") 
  1579. 			lua_play_anim(scroll_anim_h, 0)	 
  1580.  
  1581. 			-- Start the thread for scrolling 
  1582. 			Cell_saintsbook_sub_scrollbar_thread  = thread_new("cell_saintsbook_scroll_thread") 
  1583. 						 
  1584. 			-- Store our scroll direction 
  1585. 			if nav_down == true then  
  1586. 				Cell_saintsbook_scroll_direction = -1 
  1587. 			else  
  1588. 				Cell_saintsbook_scroll_direction = 1 
  1589. 			end				 
  1590. 		end 
  1591. 	end 
  1592. end 
  1593.  
  1594. function cell_saintsbook_scroll_thread() 
  1595. 	while true do 
  1596. 		-- Set the scrollbar position based on where the text currently is (should be tweening) 
  1597. 		cell_saintsbook_sub_scrollbar_set() 
  1598. 		thread_yield() 
  1599. 	end	 
  1600. end 
  1601.  
  1602. ------------------------------------------------------------------------------- 
  1603. -- Resets the scrollbar for the subscreens... 
  1604. ------------------------------------------------------------------------------- 
  1605. function cell_saintsbook_sub_scrollbar_reset() 
  1606. 	--Reset Tween 
  1607. 	local scroll_anim_h = vint_object_find("sub_scroll_anim") 
  1608. 	local twn_h = vint_object_find("sub_scroll_twn", scroll_anim_h) 
  1609. 	vint_set_property(twn_h, "start_value", 0, 0) 
  1610. 	 
  1611. 	--Reset Object we are scrolling... 
  1612. 	local subpage_grp_h 	= vint_object_find("subpage_grp") 
  1613. 	local task_desc_scroll_h 	= vint_object_find("task_desc_scroll", subpage_grp_h) 
  1614. 	vint_set_property(task_desc_scroll_h, "anchor", 0, 0) 
  1615. 	 
  1616. 	--Recalculate scrollbar... 
  1617. 	cell_saintsbook_sub_scrollbar_set() 
  1618. end 
  1619.  
  1620. function cell_saintsbook_sub_scrollbar_set() 
  1621. 	local subpage_grp_h 	= vint_object_find("subpage_grp") 
  1622. 	local task_long_h 	= vint_object_find("task_desc_scroll", subpage_grp_h) 
  1623. 	local task_x, task_y = vint_get_property(task_long_h, "anchor") 
  1624. 	local task_bottom = task_y + Cell_saintsbook_sub_task_height		 
  1625.  
  1626. 	-- Create the 'indices' to reference with the scroll bar.. we do this in pixel amoutns 
  1627. 	 
  1628. 	-- Our current index is how far the task_bottom is from the entire height of the text 
  1629. 	local index = floor(Cell_saintsbook_sub_task_height - task_bottom) + 1-- not sure about this +1 
  1630. 	 
  1631. 	-- The max index is the height of the task, minus the visible area of the text 
  1632. 	local max_index = floor(Cell_saintsbook_sub_task_height - Cell_saintsbook_sub_task_mask_height) + 1 
  1633. 	 
  1634. 	if index > max_index then 
  1635. 		index = max_index 
  1636. 	end 
  1637. 	 
  1638. 	Cell_saintsbook_sub_scrollbar:set_value(max_index, index, true) 
  1639. end 
  1640.  
  1641. function cell_saintsbook_sub_finish_scroll() 
  1642. 	-- Reset the start values for the tween when the scroll is no longer occuring 
  1643. 	local h = vint_object_find("root_animation") 
  1644. 	local scroll_anim_h = vint_object_find("sub_scroll_anim", h) 
  1645. 	local twn_h = vint_object_find("sub_scroll_twn", scroll_anim_h) 
  1646. 	local new_x, new_y = vint_get_property(twn_h, "end_value") 
  1647. 	vint_set_property(twn_h, "start_value", new_x, new_y) 
  1648.  
  1649. 	-- Kill the thread that runs while the button is held 
  1650. 	if Cell_saintsbook_sub_scrollbar_thread ~= 0 then 
  1651. 		thread_kill(Cell_saintsbook_sub_scrollbar_thread) 
  1652. 		Cell_saintsbook_sub_scrollbar_thread = 0 
  1653. 		cell_saintsbook_sub_scrollbar_set() 
  1654. 	end 
  1655. 	 
  1656. 	Cell_saintsbook_scroll_direction = 0 
  1657. end 
  1658.  
  1659.  
  1660. function cell_saintsbook_sub_select() 
  1661. 	local item = Cell_saintsbook_items[Cell_saintsbook_main_selected_idx] 
  1662. 	 
  1663. 	if item.is_completed == true then 
  1664. 		return 
  1665. 	end 
  1666. 	 
  1667. 	if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then 
  1668. 		 
  1669. 		--unselect all targets matching assassinations 
  1670. 		for i, item in pairs(Cell_saintsbook_items) do 
  1671. 			if item.item_type == SAINTSBOOK_ITEM_TYPE_ASSASSINATIONS then 
  1672. 				item.is_selected = false 
  1673. 			end 
  1674. 		end 
  1675. 		 
  1676. 		--select the current target. 
  1677. 		item.is_selected = sb_select_hitman_target(item.group_index, item.target_index) 
  1678. 		 
  1679. 		game_UI_audio_play("UI_Cell_Select") 
  1680. 		 
  1681. 	elseif item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then 
  1682. 	 
  1683. 		--unselect all targets matching assassinations 
  1684. 		for i, item in pairs(Cell_saintsbook_items) do 
  1685. 			if item.item_type == SAINTSBOOK_ITEM_TYPE_CHOPSHOP then 
  1686. 				item.is_selected = false 
  1687. 			end 
  1688. 		end 
  1689. 		 
  1690. 		--select the current target. 
  1691. 		item.is_selected = sb_select_chop_shop_vehicle(item.group_index, item.target_index) 
  1692. 		 
  1693. 		game_UI_audio_play("UI_Cell_Select") 
  1694. 		 
  1695. 	end 
  1696. 	 
  1697. 	Cell_saintsbook_items[Cell_saintsbook_main_selected_idx].is_selected = item.is_selected 
  1698.  
  1699. 	if item.is_selected == true then  
  1700. 		Cell_saintsbook_selected_target = Cell_saintsbook_main_selected_idx 
  1701. 	else  
  1702. 		Cell_saintsbook_selected_target = -1 
  1703. 	end 
  1704. 	 
  1705. 	cell_saintsbook_sub_set_selected() 
  1706. end 
  1707.  
  1708. ------------------------------------------------------------------------------- 
  1709. -- If our target is selected this sets it up in the proper state. 
  1710. -- 
  1711. function cell_saintsbook_sub_set_selected() 
  1712.  
  1713. 	local subpage_grp_h = vint_object_find("subpage_grp") 
  1714. 	 
  1715. 	local gps_grp_h = vint_object_find("gps_grp", subpage_grp_h) 
  1716. 	local gps_txt_h = vint_object_find("gps_to_target_txt", gps_grp_h) 
  1717.  
  1718. 	local selected_grp_h = vint_object_find("selected_grp", subpage_grp_h)	 
  1719. 	local task_icon_grp_h = vint_object_find("task_icon_grp", subpage_grp_h) 
  1720. 	 
  1721. 	if Cell_saintsbook_selected_target == Cell_saintsbook_main_selected_idx then 
  1722. 		vint_set_property(gps_txt_h, "text_tag", "SB_DESELECT_TARGET") 
  1723. 		vint_set_property(selected_grp_h, "visible", true) 
  1724. 		vint_set_property(task_icon_grp_h, "visible", true) 
  1725. 	else 
  1726. 		vint_set_property(gps_txt_h, "text_tag", "SB_SELECT_TARGET") 
  1727. 		vint_set_property(selected_grp_h, "visible", false) 
  1728. 		vint_set_property(task_icon_grp_h, "visible", false) 
  1729. 	end 
  1730. 	 
  1731. 	--align button 
  1732. 	local center_x = 263	--this is the center of the button	 
  1733. 	local gps_btn_grp_h = vint_object_find("gps_btn_grp", gps_grp_h) 
  1734. 	local text_x, text_y = vint_get_property(gps_txt_h, "anchor") 
  1735. 	local text_width, text_height = element_get_actual_size(gps_txt_h) 
  1736. 	local width = text_x + text_width 
  1737. 	local x, y = vint_get_property(gps_btn_grp_h, "anchor") 
  1738. 	x = center_x - (width * 0.5) 
  1739. 	vint_set_property(gps_btn_grp_h, "anchor", x, y) 
  1740. 		 
  1741. 	local gps_btn_h = vint_object_find("gps_btn", gps_btn_grp_h) 
  1742. 	if game_is_active_input_gamepad() == false then 
  1743. 		vint_set_property(gps_btn_h, "visible", false) 
  1744. 	else 
  1745. 		vint_set_property(gps_btn_h, "visible", true) 
  1746. 	end 
  1747. end 
  1748.  
  1749. function cell_saintsbook_sub_back() 
  1750. 	--lock controls 
  1751. 	cell_saintsbook_controls_lock() 
  1752. 	 
  1753. 	cell_saintsbook_main_show_items(Cell_saintsbook_main_first_item) 
  1754. 	 
  1755. 	--Navigate to main screen... 
  1756. 	cell_saintsbook_active_screen_set(SCREEN_TYPE_MAIN) 
  1757. end 
  1758.  
  1759.  
  1760.  
  1761. ------------------------------------------------------------------------------- 
  1762. -- Common functions for all screens. 
  1763. ------------------------------------------------------------------------------- 
  1764.  
  1765. ------------------------------------------------------------------------------- 
  1766. -- Populates the filter list. This is done via dataresponder during init. 
  1767. --	@index					index of the filter, enum defined up top... 
  1768. --	@filter_name			name of item (assassination, vehicle thefts, challenges) 
  1769. -- @targets_completed	# of targets completed 
  1770. -- @targets_unlocked		# of targets unlocked 
  1771. -- 
  1772. function cell_saintsbook_top_populate(index, filter_name, targets_completed, targets_unlocked) 
  1773.  
  1774. 	if index == SAINTSBOOK_ITEM_TYPE_ALL then 
  1775. 		--ignore the SAINTSBOOK_ITEM_TYPE_ALL index 
  1776. 		--we only want to show the next three... 
  1777. 		return 
  1778. 	end 
  1779. 	 
  1780. 	if targets_unlocked == 0 then 
  1781. 		--return if no targets have been unlocked. 
  1782. 		return 
  1783. 	end 
  1784. 	 
  1785. 	--if we somehow have more completed than unlocked we just make the numebers the same... 
  1786. 	if targets_completed > targets_unlocked then 
  1787. 		targets_unlocked = targets_completed 
  1788. 	end 
  1789. 	 
  1790. 	--pouplate our data 
  1791. 	local num_items = #Cell_saintsbook_top_items + 1 
  1792. 	Cell_saintsbook_top_items[num_items] = { 
  1793. 		filter_index = index, 
  1794. 		filter_name = filter_name, 
  1795. 		targets_completed = targets_completed, 
  1796. 		targets_unlocked = targets_unlocked, 
  1797. 	} 
  1798. end 
  1799.  
  1800. ------------------------------------------------------------------------------- 
  1801. -- Populate function via responder for saintsbook. 
  1802. -- This is a generic responder used for both challenges, hitman and diversion 
  1803. -- the additional parameters are determined by the item type. 
  1804. -- 
  1805. function cell_saintsbook_populate(item_type, param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11, param12, param13 ) 
  1806.  
  1807. 	if item_type == SAINTSBOOK_ITEM_TYPE_CHALLENGE then 
  1808. 		--Its a challenge... 
  1809. 		 
  1810. 		param9 = 0	--No use for acheivement 
  1811. 		if param11 == nil then 
  1812. 			param11 = "" 
  1813. 		end 
  1814. 		 
  1815. 		Cell_saintsbook_items[Cell_saintsbook_item_count] = { 
  1816. 			item_h 				= -1, 
  1817. 			item_type 			= item_type, 
  1818. 			contact_name 		= param1,  
  1819. 			contact_image 		= param2, 
  1820. 			target_image	 	= param11,								--get target image... 
  1821. 			target_name 		= param3,											-- Target name is also the challenge name. 
  1822. 			blurb_condensed	= 0,													--no blurb condensed for challenges. 
  1823. 			blurb_long 			= param12, 								--This is a CRC. 
  1824. 			units_completed 	= param4, 
  1825. 			units_total 		= param5, 
  1826. 			units_crc 			= param6, 
  1827. 			cash 					= param7, 
  1828. 			respect 				= param8, 
  1829. 			achievement_value = param9, 
  1830. 			is_completed 		= param10, 
  1831. 		} 
  1832. 	else 
  1833. 		--Its hitman or chopshop... 
  1834. 		Cell_saintsbook_items[Cell_saintsbook_item_count] = { 
  1835. 			item_h 				= -1, 
  1836. 			item_type 			= item_type, 
  1837. 			contact_name 		= param1,  
  1838. 			contact_image 		= param2, 
  1839. 			blurb_condensed 	= param3, 
  1840. 			blurb_long 			= param4, 
  1841. 			target_name			= param5, 
  1842. 			target_image	 	= param6, 
  1843. 			target_location 	= param7, 
  1844. 			cash 					= param8, 
  1845. 			respect 				= param9, 
  1846. 			is_completed 		= param10, 
  1847. 			group_index 		= param11, 
  1848. 			target_index 		= param12, 
  1849. 			is_selected 		= param13, 
  1850. 		} 
  1851. 	end 
  1852. 	 
  1853. 	if Cell_saintsbook_items[Cell_saintsbook_item_count].is_selected == true then  
  1854. 		Cell_saintsbook_selected_target = Cell_saintsbook_item_count 
  1855. 	end 
  1856. 	 
  1857. 	Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1 
  1858. end 
  1859.  
  1860. ------------------------------------------------------------------------------- 
  1861. -- Sorts saintsbook main menu... 
  1862. -- For now it just puts the completed items at the back of the list... 
  1863. -- 
  1864. function cell_saintsbook_sort() 
  1865. 	local front_list = {} 
  1866. 	local back_list = {} 
  1867. 	local front_list_count = 0 
  1868. 	local back_list_count = 0 
  1869. 	 
  1870. 	--split list... 
  1871. 	for key, val in pairs(Cell_saintsbook_items) do 
  1872. 		if val.is_completed == false then 
  1873. 			front_list[front_list_count] = val 
  1874. 			front_list_count = front_list_count + 1 
  1875. 		else 
  1876. 			back_list[back_list_count] = val 
  1877. 			back_list_count = back_list_count + 1 
  1878. 		end 
  1879. 	end 
  1880. 	 
  1881. 	--combine lists back into saintsbook items... first front then back.. 
  1882. 	Cell_saintsbook_items = {} 
  1883. 	Cell_saintsbook_item_count = 0 
  1884. 	for key, val in pairs(front_list) do 
  1885. 		Cell_saintsbook_items[Cell_saintsbook_item_count] = val 
  1886. 		Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1 
  1887. 	end 
  1888. 	for key, val in pairs(back_list) do 
  1889. 		Cell_saintsbook_items[Cell_saintsbook_item_count] = val 
  1890. 		Cell_saintsbook_item_count = Cell_saintsbook_item_count + 1 
  1891. 	end 
  1892. end 
  1893.  
  1894.  
  1895. function cell_saintsbook_map_restored() 
  1896. 	 
  1897. end 
  1898.  
  1899. ------------------------------------------------------------------------------- 
  1900. -- Handles dummy callbacks. 
  1901. -- 
  1902. function saints_book_empty_func() 
  1903. end 
  1904.  
  1905.  
  1906. ------------------------------------------------------------------------------- 
  1907. -- Returns an alternate contact image based on what we have in the contacts 
  1908. -- table. This is because saintsbook and missions use the same contact table 
  1909. -- but different images. So we translate them this way... 
  1910. -- 
  1911. function cell_saintsbook_contact_image_get(image) 
  1912. 	local image_test = Cell_saintsbook_contact_images[image] 
  1913. 	if image_test ~= nil then 
  1914. 		return image_test 
  1915. 	end 
  1916. 	return image 
  1917. end 
  1918.  
  1919. ------------------------------------------------------------------------------- 
  1920. -- Data saintsbook to maintain navigation callbacks  
  1921. -- and other data between screens. 
  1922. -- 
  1923. Saintsbook_screens = { 
  1924. 	[SCREEN_TYPE_TOP] = { 
  1925. 		nav = cell_saintsbook_top_nav, 
  1926. 		select = cell_saintsbook_top_select, 
  1927. 		back = cell_saintsbook_exit_to_menu, 
  1928. 		exit = cell_saintsbook_exit_to_game, 
  1929. 		selected_idx = 1, 
  1930. 	}, 
  1931. 	[SCREEN_TYPE_MAIN] = { 
  1932. 		nav = cell_saintsbook_main_nav, 
  1933. 		select = cell_saintsbook_main_select, 
  1934. 		back = cell_saintsbook_main_back, 
  1935. 		exit = cell_saintsbook_exit_to_game, 
  1936. 		selected_idx = 1, 
  1937. 	}, 
  1938. 	[SCREEN_TYPE_SUB] = { 
  1939. 		nav = saints_book_empty_func, 
  1940. 		select = cell_saintsbook_sub_select, 
  1941. 		back = cell_saintsbook_sub_back, 
  1942. 		exit = cell_saintsbook_exit_to_game, 
  1943. 		selected_idx = 1 
  1944. 	} 
  1945. } 
  1946.