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