./col_main.lua

  1.  
  2. -- Offset of list and header from other store layouts 
  3. local REWARDS_OFFSET = 80  
  4.  
  5. local REWARDS_LIST_WIDTH = 0 
  6.  
  7. -- Hint bar and store header vdo's. 
  8. local Hint_bar 
  9. local Hint_bar_rotate 
  10. local Store_logo 
  11. local Store_popup 
  12. local Not_popup_grp 
  13. Cur_text_adv = 0 
  14.  
  15. local Color_grid 
  16. local Color_grid_grp 
  17.  
  18. local Col_title 
  19.  
  20. local Reward_image 
  21.  
  22. local Input_tracker 
  23. local Mouse_input_tracker 
  24. local Hint_bar_mouse_input_tracker 
  25.  
  26. local Col_main_loading_img = nil 
  27. local Col_main_unload_img  = nil 
  28.  
  29. local Col_main_category_id = 0 
  30. local CATEGORY_AUDIO = 0 
  31. local CATEGORY_TEXT = 1 
  32. local CATEGORY_TOD = 2 
  33. local CATEGORY_XMAS_TEXT = 3 
  34. local CATEGORY_XMAS_LETTER = 4 
  35. local Col_main_category_name = nil 
  36. local Col_main_doc_handle = -1 
  37.  
  38. local Col_main_building_menu = {} 
  39.  
  40. local Col_main_img_update_thread = -1 
  41.  
  42. local COLOR_COL_POPUP = {R = 255/255, G =255/255, B =255/255} 
  43.  
  44. local Audio_images = { 
  45. 	[0] = "ui_reward_homie_asha",		--// COLLECTIBLE_TYPE_AUDIO_LOG_ASHA, 
  46. 	[1] = "ui_reward_homie_ben_king",      --// COLLECTIBLE_TYPE_AUDIO_LOG_BEN_KING, 
  47. 	[2] = "ui_reward_homie_cyrus",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_CYRUS, 
  48.    [3] = "ui_reward_homie_gat",      --// COLLECTIBLE_TYPE_AUDIO_LOG_DJ_VETERAN_CHILD, 
  49.    [4] = "ui_reward_homie_julius",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_JULIUS, 
  50.    [5] = "ui_reward_homie_kinzie",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_KINZIE, 
  51.    [6] = "ui_reward_homie_maero",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_MAERO, 
  52.    [7] = "ui_reward_homie_matt_miller",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_MATT_MILLER, 
  53.    [8] = "ui_reward_homie_pierce",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_PIERCE, 
  54.    [9] = "ui_reward_homie_shaundi_sr2",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_SHAUNDI_SR2, 
  55.    [10] = "ui_reward_homie_shaundi",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_SHAUNDI_SR3, 
  56.    [11] = "ui_reward_homie_tanya",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_TANYA, 
  57.    [12] = "ui_reward_homie_keith_david",     -- // COLLECTIBLE_TYPE_AUDIO_LOG_VICE_PRESIDENT,	 
  58. } 
  59. local Text_images = { 
  60. 	[0] = "ui_col_txt_adv_title", 
  61. 	[1] = "ui_col_xmas_txt_adv_title", --xmas text 
  62. 	[2] = "ui_col_xmas_letter_title", --letters to santa 
  63. } 
  64.  
  65. ---------------------------------------------------------------------------  
  66. -- Initialize Rewards Store 
  67. --------------------------------------------------------------------------- 
  68. function col_main_init() 
  69. 	 
  70. 	pause_map_dump() 
  71. 	Col_main_doc_handle = vint_document_find("col_main") 
  72.  
  73. 	-- Set up some callbacks for the common store script 
  74. 	Store_common_populate_list_cb = col_main_populate_list 
  75. 	Store_common_exit_cb				= col_main_exit 
  76.  
  77. 	-- Subscribe to the button presses we need 
  78. 	Input_tracker = Vdo_input_tracker:new() 
  79. 	Input_tracker:add_input("nav_up", "col_main_nav_up", 50) 
  80. 	Input_tracker:add_input("nav_down", "col_main_nav_down", 50)	 
  81. 	Input_tracker:add_input("back", "col_main_button_b", 50) 
  82. 	Input_tracker:add_input("select", "col_main_button_a", 50) 
  83.  
  84. 	vint_set_glitch_percent( 0 ) 
  85. 	 
  86. 	--Set Title 
  87. 	Col_title = Vdo_cell_title:new("col_title", 0, Col_main_doc_handle) 
  88. 	Col_title:set_text("COL_MAIN_TITLE") 
  89. 	Col_title:set_icon("ui_cell_icon_tomes") 
  90. 	Col_title:play_dots_anim() 
  91. 	 
  92. 	--Setup Button Hints 
  93. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Col_main_doc_handle) 
  94. 	local hint_data = { 
  95. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  96. 		{CTRL_MENU_BUTTON_A, "MENU_TITLE_CONFIRM"}	 
  97. 	} 
  98. 	Hint_bar:set_hints(hint_data) 	 
  99. 	Hint_bar:set_visible(true) 
  100.  
  101. 	Active_list = Vdo_mega_list:new("tomes_list", 0, Col_main_doc_handle, "col_main.lua", "Active_list") 
  102. 	Active_list:set_highlight_color(COLOR_CHEATS_PRIMARY, COLOR_CHEATS_SECONDARY) 
  103. 	-- HVS_JPM hack this list into the correct position 
  104. 	--Active_list:set_property("anchor", 186, 275) 
  105.  
  106. 	Store_logo = Vdo_base_object:new("store_logo_img", 0, Store_common_doc_handle) 
  107. 	Store_logo:set_visible(false) 
  108. 	 
  109. 	--Popup 
  110. 	Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle) 
  111. 	Store_popup:set_visible(false) 
  112. 	Store_popup:set_color(COLOR_COL_POPUP, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY) 
  113. 	Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  114. 	 
  115. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  116. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  117. 	 
  118. 	Color_grid_grp = Vdo_base_object:new("color_grid_grp", 0, Store_common_doc_handle) 
  119. 	Color_grid_grp:set_visible(false)	 
  120. 	 
  121. 	-- Needs to be done after the list is drawn/populated 
  122. 	--Active_list:set_highlight_color(1, 1)	 
  123. 	 
  124. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_COLLECTIBLES, CELL_SCREEN_MAIN, col_main_unlock_controls) 
  125. 	 
  126. 	local screen_grp = Vdo_base_object:new("screen_grp", 0, Col_main_doc_handle)	 
  127. 	screen_grp:set_visible(true) 
  128. 		 
  129. 	-- Pass the table data to the megalist vdo. 
  130. 	--vint_dataresponder_request("col_main_category_dr", "col_main_add_category", 0) 
  131. 	 
  132. 	--col_main_add_category("COL_CAT_AUDIO", nil, nil, false)	 
  133.  
  134. 	-- HVS_JPM we only have the Audio Tomes 
  135. 	--[[ 
  136. 	col_main_add_category("COL_CAT_TEXT", nil, nil, false) 
  137. 	 
  138. 	if game_unlockable_is_unlocked( "ship_tod" ) and game_get_is_coop_client() == false then 
  139. 		col_main_add_category("COL_CAT_TOD", nil, nil, false) 
  140. 	end 
  141. 	 
  142. 	if game_is_dlc_available("DLC2") then 
  143. 		col_main_add_category("COL_CAT_XMAS_TEXT", nil, nil, false) 
  144. 		col_main_add_category("COL_CAT_XMAS_LETTER", nil, nil, false) 
  145. 	end 
  146. 	--]] 
  147.  
  148. 	col_main_populate_audio_tomes() 
  149. 	col_main_populate_list(Menu_data, 1)	 
  150. 	 
  151. 	-- Add this on_enter callback so the category menu gets refreshed when returning from a submenu 
  152. 	--Menu_data.on_enter = col_main_category_menu_update 
  153. 	 
  154. 	-- For the rewards store, we don't want the bg to render behind the player, so change this property. 
  155. 	-- Perhaps these can be organized so it's easier to do this. 
  156. 	--local grp1_h = vint_object_find("lets_pretend_bg_grp", 0, Store_common_doc_handle) 
  157. 	--vint_set_property(grp1_h, "background", false) 
  158. 	--vint_set_property(grp1_h, "visible", false) 
  159. 	 
  160. 	-- Animate phone in 
  161. 	--local col_main_anim_in_h = vint_object_find("col_main_anim_in", 0, Store_common_doc_handle) 
  162. 	--lua_play_anim(col_main_anim_in_h, 0, Store_common_doc_handle) 
  163.  
  164. 	-- Tint store green 
  165. 	--local store_common_grp_h = vint_object_find("cell_rotate_grp", 0, Store_common_doc_handle) 
  166. 	--vint_set_property(store_common_grp_h, "saturation", 0) 
  167. 	--vint_set_property(store_common_grp_h, "tint", COLOR_COL_CELL_ROTATE.R, COLOR_COL_CELL_ROTATE.G, COLOR_COL_CELL_ROTATE.B) 
  168. 	 
  169. 	-- Initialize reward image... 
  170. 	Reward_image = Vdo_bitmap_viewer:new("reward_image", 0, Col_main_doc_handle)	 
  171. 	 
  172. 	-- Hide description 
  173. 	Reward_image:set_description(" ", nil) 
  174. 	Reward_image:set_visible(false) 
  175.  
  176. 	 
  177. 	-- Mouse input 
  178. 	if game_get_platform() == "PC" then 
  179. 		 
  180. 		Hint_bar:set_highlight(0) 
  181. 	 
  182. 		Mouse_input_tracker = Vdo_input_tracker:new() 
  183. 		Active_list:add_mouse_inputs("col_main", Mouse_input_tracker) 
  184. 		Mouse_input_tracker:subscribe(false) 
  185.  
  186. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  187. 		Hint_bar:add_mouse_inputs("col_main", Hint_bar_mouse_input_tracker) 
  188. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  189. 	end 
  190. 	 
  191. 	--TODO: Transition the screen in... 
  192. 	--local pulse_anim_h = vint_object_find("pulse_anim", 0, Col_main_doc_handle) 
  193. 	--lua_play_anim(pulse_anim_h) 
  194. 	col_main_unlock_controls() 
  195.  
  196. 	col_main_on_enter_draw_tome_img() 
  197. 	 
  198. end 
  199.  
  200. -- Cleanup 
  201. function col_main_cleanup() 
  202. 	-- Nuke all button subscriptions 
  203. 	Input_tracker:subscribe(false) 
  204. 	col_main_enable_mouse(false) 
  205.  
  206. 	local current_image = Reward_image:get_image()	 
  207. 	if current_image ~= nil then 
  208. 		game_peg_unload(current_image) 
  209. 	end		 
  210. 	if Col_main_unload_img ~= nil then 
  211. 		game_peg_unload(Col_main_unload_img) 
  212. 	end 
  213. 	if Col_main_loading_img ~= nil then 
  214. 		game_peg_unload(Col_main_loading_img) 
  215. 	end 
  216. 	vint_scriptevent_post("audio_log_play", -1, -1) 
  217. 	pause_map_restore() 
  218. 	 
  219. end 
  220.  
  221. ------------------------------------------------------------------------------- 
  222. -- Controls Unlock  
  223. -- 
  224. function col_main_unlock_controls() 
  225. 	Input_tracker:subscribe(true) 
  226. 	col_main_enable_mouse(true) 
  227. end 
  228.  
  229. ------------------------------------------------------------------------------- 
  230. -- Controls Lock 
  231. -- 
  232. function col_main_lock_controls() 
  233. 	Input_tracker:subscribe(false) 
  234. 	col_main_enable_mouse(false) 
  235. end 
  236.  
  237. -- Populate the active megalist menu, and hide the previous menu 
  238. -- 
  239. -- list_data: 		this table contains the data to populate the megalist 
  240. -- current_index: 	the current index in the menu that's selected 
  241. -- 
  242. function col_main_populate_list(list_data, current_index) 
  243.  
  244. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 9, .8, false, false)	 
  245. 	Active_list:set_visible(true) 
  246. 	 
  247. 	col_main_mouse_update() 
  248. 	--[[	 
  249. 	if game_get_platform() == "PC" then 
  250. 		Mouse_input_tracker:remove_all() 
  251. 		Active_list:set_store("col_main") 
  252. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  253. 		Mouse_input_tracker:subscribe(true) 
  254. 	end 
  255. 	--]] 
  256. end 
  257.  
  258. -- Called in a thread to delay the image updating. 
  259. -- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly, 
  260. -- and because the streaming system didn't always co-operate with the images being released 
  261. -- from the callback context that was executed when another stream load completed. 
  262. -- 
  263. function col_main_image_update() 
  264. 	delay(0.2) 
  265. 	game_peg_unload(Col_main_unload_img)	 
  266. 	game_peg_load_with_cb("col_main_show_image", 1, Col_main_loading_img) 
  267. 	Col_main_img_update_thread = -1 
  268. end 
  269.  
  270. function col_main_tome_image_update() 
  271. 	delay(0.2) 
  272. 	game_peg_unload(Col_main_unload_img)	 
  273. 	game_peg_load_with_cb("col_main_show_tome_image", 1, Col_main_loading_img) 
  274. 	Col_main_img_update_thread = -1 
  275. end 
  276.  
  277. -- Callback for when an image is done loading. 
  278. -- SEH: It might make sense to roll this into vdo_bitmap_viewer... 
  279. -- 
  280. function col_main_show_image() 
  281. 	local index = Active_list:get_selection() 
  282. 	local new_image 
  283. 	if Col_main_category_id == CATEGORY_AUDIO then 
  284. 		local homie = Menu_data[index].homie 
  285. 		new_image = Audio_images[homie] 
  286. 	elseif Col_main_category_id == CATEGORY_TEXT then 
  287. 		local id = Menu_data[index].id 
  288. 		new_image = Text_images[0] 
  289. 	elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  290. 		local id = Menu_data[index].id 
  291. 		new_image = Text_images[1] 
  292. 	elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  293. 		local id = Menu_data[index].id 
  294. 		new_image = Text_images[2] 
  295. 	end 
  296. 	 
  297. 	local img_scale_x = 1 
  298. 	local img_scale_y = 1 
  299. 	 
  300. 	if Col_main_loading_img == new_image then 
  301. 		Reward_image:set_image(new_image, Menu_data[index].is_locked, Menu_data[index].is_purchased, Menu_data[index].level, Menu_data[index].level_required, img_scale_x, img_scale_y) 
  302. 		Reward_image:set_description(nil, Menu_data[index].description) 
  303. 		Reward_image:set_visible(true) 
  304. 		Col_main_loading_img = nil 
  305. 		 
  306. 	else 
  307. 		-- a new image was picked while we were loading - load this now, and unload the one we just loaded 
  308. 		if new_image ~= nil then 
  309. 			Col_main_unload_img = Col_main_loading_img 
  310. 			Col_main_loading_img = new_image 
  311. 			Col_main_img_update_thread = thread_new("col_main_image_update")	 
  312. 		else 
  313. 			game_peg_unload(Col_main_loading_img) 
  314. 			Col_main_loading_img = nil 
  315. 		end 
  316. 	end 
  317. end 
  318.  
  319. function col_main_show_tome_image() 
  320. 	local index = Active_list:get_selection() 
  321. 	local new_image 
  322. 	new_image = "ui_col_tome" 
  323. 	 
  324. 	local img_scale_x = 1 
  325. 	local img_scale_y = 1 
  326. 	 
  327. 	if Col_main_loading_img == new_image then 
  328. 		Reward_image:set_image(new_image, Menu_data[index].is_locked, Menu_data[index].is_purchased, Menu_data[index].level, Menu_data[index].level_required, img_scale_x, img_scale_y) 
  329. 		Reward_image:set_description(nil, Menu_data[index].description) 
  330. 		Reward_image:set_visible(not Menu_data[index].is_locked) 
  331. 		Col_main_loading_img = nil 
  332. 		 
  333. 	else 
  334. 		-- a new image was picked while we were loading - load this now, and unload the one we just loaded 
  335. 		if new_image ~= nil then 
  336. 			Col_main_unload_img = Col_main_loading_img 
  337. 			Col_main_loading_img = new_image 
  338. 			Col_main_img_update_thread = thread_new("col_main_tome_image_update")	 
  339. 		else 
  340. 			game_peg_unload(Col_main_loading_img) 
  341. 			Col_main_loading_img = nil 
  342. 		end 
  343. 	end 
  344. end 
  345.  
  346. -- Update reward image based on which reward is highlighted 
  347. -- 
  348. -- index of the reward in the table 
  349. -- 
  350. function col_main_item_nav(menu_data) 
  351. 	Reward_image:set_visible(false) 
  352. 	if Col_main_loading_img == nil then 
  353. 		local new_image 
  354. 		if Col_main_category_id == CATEGORY_AUDIO then 
  355. 			local homie = menu_data.homie 
  356. 			new_image = Audio_images[homie] 
  357. 		elseif Col_main_category_id == CATEGORY_TEXT then 
  358. 			local id = menu_data.id 
  359. 			new_image = Text_images[0] 
  360. 		elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  361. 			local id = menu_data.id 
  362. 			new_image = Text_images[1] 
  363. 		elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  364. 			local id = menu_data.id 
  365. 			new_image = Text_images[2] 
  366. 		end	 
  367. 		local current_image = Reward_image:get_image()	 
  368. 		if current_image ~= nil then 
  369. 			game_peg_unload(current_image) 
  370. 		end 
  371. 		if new_image ~= nil then 
  372. 			-- must set Col_main_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  373. 			Col_main_loading_img = new_image		 
  374. 			game_peg_load_with_cb("col_main_show_image", 1, new_image) 
  375. 		end 
  376. 	end 
  377. 	 
  378. 	-- if this unlockable was marked as "new", then clear the flag since the player highlighted it 
  379. 	if menu_data.is_new then 
  380. 		vint_dataresponder_post("col_main_reward_dr", "Clear_new", menu_data.id) 
  381. 		 
  382. 		--Get index from the list and then remove the flag... 
  383. 		local index = Active_list:get_index_from_id(menu_data.id) 
  384. 		if index ~= -1 then 
  385. 			Active_list:remove_new_flag(index) 
  386. 		end 
  387. 		 
  388. 		--Update cursor, 
  389. 		Active_list:move_cursor(0) 
  390. 		--Re add mouse inputs... 
  391. 		if Mouse_input_tracker ~= 0 then 
  392. 			Mouse_input_tracker:remove_all() 
  393. 			Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  394. 			Mouse_input_tracker:subscribe(true) 
  395. 		end 
  396. 	end 
  397. end 
  398.  
  399. function col_main_tome_item_nav(menu_data) 
  400. 	Reward_image:set_visible(false) 
  401.  
  402. 	if Col_main_loading_img == nil then 
  403. 		local new_image 
  404. 		new_image = "ui_col_tome" 
  405.  
  406. 		local current_image = Reward_image:get_image()	 
  407. 		if current_image ~= nil then 
  408. 			game_peg_unload(current_image) 
  409. 		end 
  410. 		if new_image ~= nil then 
  411. 			-- must set Col_main_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  412. 			Col_main_loading_img = new_image		 
  413. 			game_peg_load_with_cb("col_main_show_tome_image", 1, new_image) 
  414. 		end 
  415. 	end 
  416.  
  417. 	if menu_data.is_locked then 
  418. 		local hint_data = { 
  419. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  420. 		} 
  421. 		Hint_bar:set_hints(hint_data) 	 
  422. 	else 
  423. 		local hint_data = { 
  424. 			{CTRL_MENU_BUTTON_B, "MENU_BACK"}, 
  425. 			{CTRL_MENU_BUTTON_A, "MENU_AUDIO_PLAY_TOME"}	 
  426. 		} 
  427. 		Hint_bar:set_hints(hint_data) 	 
  428. 	end 
  429.  
  430. 	if game_get_platform() == "PC" then 
  431. 		Hint_bar:set_highlight(0) 
  432. 		Hint_bar_mouse_input_tracker:remove_all() 
  433. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  434. 		Hint_bar:add_mouse_inputs("col_main", Hint_bar_mouse_input_tracker) 
  435. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  436. 	end 
  437.  
  438. 		-- if this unlockable was marked as "new", then clear the flag since the player highlighted it 
  439. 	if menu_data.is_new then 
  440. 		vint_dataresponder_post("col_main_reward_dr", "Clear_new", menu_data.id) 
  441. 		 
  442. 		--Get index from the list and then remove the flag... 
  443. 		local index = Active_list:get_index_from_id(menu_data.id) 
  444. 		if index ~= -1 then 
  445. 			Active_list:remove_new_flag(index) 
  446. 		end 
  447. 		 
  448. 		--Update cursor, 
  449. 		Active_list:move_cursor(0) 
  450. 		--Re add mouse inputs... 
  451. 		if Mouse_input_tracker ~= 0 then 
  452. 			Mouse_input_tracker:remove_all() 
  453. 			Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  454. 			Mouse_input_tracker:subscribe(true) 
  455. 		end 
  456. 	end 
  457. end 
  458.  
  459. -- Update category image based on which category is highlighted 
  460. -- 
  461. -- index of the category in the table 
  462. -- 
  463. function col_main_category_nav(menu_data) 
  464. 	--Col_main_category_id = menu_data.id 
  465. 	Col_main_category_id = menu_data.cat_id 
  466. 	Col_main_category_name = menu_data.label 
  467. 	Reward_image:set_visible(false) 
  468. end 
  469.  
  470. function col_main_purchase_select(menu_data) 
  471. 	if menu_data.is_locked == true or menu_data.is_purchased == true then	 
  472. 		return 
  473. 	end 
  474.  
  475. 	-- give reward and take money here 
  476. 	local current_index = Active_list:get_selection() 
  477. 	if Col_main_category_id == CATEGORY_AUDIO then 
  478. 		local homie = menu_data.homie 
  479. 		local index = menu_data.id 
  480. 		vint_scriptevent_post("audio_log_play", -1, -1) 
  481. 		vint_scriptevent_post("audio_log_play", homie, index) 
  482. 	elseif Col_main_category_id == CATEGORY_TEXT then 
  483. 		Cur_text_adv = current_index 
  484. 		push_screen("col_text_adventure") 
  485. 		Input_tracker:subscribe(false) 
  486. 		col_main_enable_mouse(false) 
  487. 	elseif Col_main_category_id == CATEGORY_TOD then 
  488. 		vint_scriptevent_post("player_set_tod", menu_data.id) 
  489. 		ui_audio_post_event("ui_tod_toggle")  
  490. 		store_common_button_b() 
  491. 	elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  492. 		Cur_text_adv = current_index + 10 --Text Adv 11-18 
  493. 		push_screen("col_text_adventure") 
  494. 		Input_tracker:subscribe(false)	 
  495. 	elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  496. 		if menu_data.id == 9 then 
  497. 			Cur_text_adv = menu_data.id + 1 + 20 --Special case for the last letter 
  498. 		else  
  499. 			Cur_text_adv = current_index + 20 --Letters 21-29 
  500. 		end 
  501. 		push_screen("col_text_adventure") 
  502. 		Input_tracker:subscribe(false)	 
  503. 	end	 
  504. 	 
  505. 	-- Save off index before we refresh the list 
  506. 	Menu_data.start_index = current_index 
  507. 	 
  508. end 
  509.  
  510. function col_main_tome_select(menu_data) 
  511. 	if menu_data.is_locked == true then	 
  512. 		return 
  513. 	end 
  514.  
  515. 	local current_index = Active_list:get_selection() 
  516.  
  517. 	local homie = menu_data.homie 
  518. 	local index = menu_data.id 
  519. 	vint_scriptevent_post("audio_log_play", -1, -1) 
  520. 	vint_scriptevent_post("audio_log_play", homie, index) 
  521.  
  522. 	-- Save off index before we refresh the list 
  523. 	Menu_data.start_index = current_index 
  524. end 
  525.  
  526. function col_main_popup_nav(event, value) 
  527. 	if event == "nav_up" then	 
  528. 		Store_popup.list:move_cursor(-1)	 
  529. 	elseif event == "nav_down" then 
  530. 		Store_popup.list:move_cursor(1) 
  531. 	elseif event == "mouse_move" then 
  532. 		-- value contains the target_handle in this case 
  533. 		local new_index = Store_popup.list:get_button_index(value) 
  534. 		if new_index ~= 0 then 
  535. 			Store_popup.list:set_selection(new_index) 
  536. 			Store_popup.list:move_cursor(0, true) 
  537. 		end 
  538. 	else 
  539. 		--do nothing 
  540. 	end	 
  541. end 
  542.  
  543. function col_main_fail_msg(event) 
  544. 	Store_popup:nav_enable(false, nil, nil) 
  545. 	Not_popup_grp:set_alpha(1) 
  546. 	Active_list:set_visible(true) 
  547. 	col_main_enable_mouse(true) 
  548. end 
  549.  
  550. function col_main_add_category(name, image_name, is_new, disabled) 
  551. 	local menu_idx = #Menu_data + 1 
  552. 	 
  553. 	local cat_id 
  554. 	if name == "COL_CAT_AUDIO" then 
  555. 		cat_id = CATEGORY_AUDIO 
  556. 	elseif name == "COL_CAT_TEXT" then 
  557. 		cat_id = CATEGORY_TEXT 
  558. 	elseif name == "COL_CAT_TOD" then 
  559. 		cat_id = CATEGORY_TOD 
  560. 	elseif name == "COL_CAT_XMAS_TEXT" then 
  561. 		cat_id = CATEGORY_XMAS_TEXT 
  562. 	elseif name == "COL_CAT_XMAS_LETTER" then 
  563. 		cat_id = CATEGORY_XMAS_LETTER 
  564. 	end 
  565. 	 
  566. 	local new_item = { 
  567. 		type = TYPE_BUTTON, 
  568. 		id = menu_idx - 1, 
  569. 		cat_id = cat_id, 
  570. 		label = name, 
  571. 		label_crc = nil, 
  572. 		image = image_name, 
  573. 		on_nav = col_main_category_nav, 
  574. 		on_sub_menu_fill = col_main_populate_rewards, 
  575. 		is_new = is_new, 
  576. 		disabled = disabled, 
  577. 	}		 
  578.  
  579. 	Menu_data[menu_idx] = new_item 
  580. end 
  581.  
  582. -- This is called after the sub menu is generated for a selected category, and we now need to update 
  583. -- the image and description for the first award available.  Must be called in on_enter(), because  
  584. -- the script asssumes Menu_data has already been set to the new sub menu we entered. 
  585. -- 
  586. function col_main_on_enter_draw_image() 
  587. 	col_main_item_nav(Menu_data[1]) 
  588. end 
  589.  
  590. function col_main_on_enter_draw_tome_img() 
  591. 	col_main_tome_item_nav(Menu_data[1]) 
  592. end 
  593.  
  594. function col_main_populate_rewards(menu_data) 
  595. 	Col_main_building_menu = menu_data.sub_menu 
  596. 	local category 
  597. 	 
  598. 	if Col_main_category_id == CATEGORY_AUDIO then 
  599. 		category = "audio_logs" 
  600. 	elseif Col_main_category_id == CATEGORY_TEXT then 
  601. 		category = "text_adventures" 
  602. 	elseif Col_main_category_id == CATEGORY_TOD then 
  603. 		category = "tod" 
  604. 	elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  605. 		category = "xmas_text_adventures" 
  606. 	elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  607. 		category = "xmas_letters" 
  608. 	end 
  609. 	 
  610. 	vint_dataresponder_request("collections_main_dr", "col_main_add_reward", 0, category) 
  611. 	 
  612. 	if #Col_main_building_menu > 0 then 
  613. 		if Col_main_category_id == CATEGORY_AUDIO then 
  614. 			Col_title:set_text("COL_CAT_AUDIO") 
  615. 		elseif Col_main_category_id == CATEGORY_TEXT then 
  616. 			Col_title:set_text("COL_CAT_TEXT") 
  617. 		elseif Col_main_category_id == CATEGORY_TOD then 
  618. 			Col_title:set_text("COL_CAT_TOD") 
  619. 		elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  620. 			Col_title:set_text("COL_CAT_XMAS_TEXT") 
  621. 		elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  622. 			Col_title:set_text("COL_CAT_XMAS_LETTER") 
  623. 		end 
  624. 	else 
  625. 		Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  626. 		Store_popup:set_title("MENU_TITLE_NOTICE") 
  627. 		Store_popup:set_text("COL_MAIN_NONE")		 
  628. 		Store_popup:nav_enable(true, "col_main_fail_msg", "col_main_popup_nav") 
  629. 		Not_popup_grp:set_alpha(.5)		 
  630. 		Active_list:set_visible(false) 
  631. 	end 
  632. 	 
  633. 	Col_main_building_menu.on_enter = col_main_on_enter_draw_image 
  634. end 
  635.  
  636. -- HVS_JPM new function used to only populate this menu with audio tomes 
  637. function col_main_populate_audio_tomes() 
  638. 	local category = "audio_logs" 
  639.  
  640. 	vint_dataresponder_request("collections_main_dr", "col_main_add_audio_tome", 0, category) 
  641. 	 
  642. 	Menu_data.on_enter = col_main_on_enter_draw_tome_img 
  643. end 
  644.  
  645. function col_main_add_audio_tome(collected, id, name, desc_crc) 
  646. 	local menu_idx = #Menu_data + 1 
  647.  
  648. 	local new_item = { 
  649. 		type = TYPE_BUTTON, 
  650. 		homie = 0, 
  651. 		id = id, 
  652. 		label = name, 
  653. 		label_crc = nil, 
  654. 		image = nil, 
  655. 		description = desc_crc, 
  656. 		is_locked =  not collected, 
  657. 		is_purchased = collected, 
  658. 		level_required = 1, 
  659. 		-- Display of level and max_level disabled for now 
  660. 		level = nil, 
  661. 		max_level = nil, 
  662. 		on_nav = nil,--col_main_tome_item_nav, 
  663. 		on_select = nil, --col_main_tome_select, 
  664. 		on_back = nil, 
  665. 		--trumps = trumps, -- CRC for the name of the prerequisite 
  666. 		--is_new = is_new, 
  667. 	}	 
  668. 	 
  669. 	Menu_data[menu_idx] = new_item 
  670. end 
  671.  
  672. function col_main_add_reward(homie, id, name, desc_crc) 
  673. 	local menu_idx = #Col_main_building_menu + 1 
  674. 	 
  675. 	 
  676. 	local new_item = { 
  677. 		type = TYPE_BUTTON, 
  678. 		homie = homie, 
  679. 		id = id, 
  680. 		label = name, 
  681. 		label_crc = nil, 
  682. 		image = nil, 
  683. 		description = desc_crc, 
  684. 		is_locked = false, 
  685. 		is_purchased = false, 
  686. 		level_required = 1, 
  687. 		-- Display of level and max_level disabled for now 
  688. 		level = nil, 
  689. 		max_level = nil, 
  690. 		on_nav = col_main_item_nav, 
  691. 		on_select = col_main_purchase_select, 
  692. 		on_back = col_main_revert_header, 
  693. 		--trumps = trumps, -- CRC for the name of the prerequisite 
  694. 		--is_new = is_new, 
  695. 	}		 
  696. 	 
  697. 	Col_main_building_menu[menu_idx] = new_item 
  698. end 
  699.  
  700. function col_main_revert_header(menu_data) 
  701.  
  702. 	-- kill update thread 
  703. 	if Col_main_img_update_thread ~= -1 then 
  704. 		thread_kill(Col_main_img_update_thread) 
  705. 		Col_main_img_update_thread = -1 
  706. 	end 
  707. 	 
  708. 	Col_title:set_text("COL_MAIN_TITLE") 
  709. 	 
  710. 	-- Hide description 
  711. 	Reward_image:set_description(" ", nil) 
  712. 	Reward_image:set_visible(false) 
  713. 	local current_image = Reward_image:get_image()	 
  714. 	if current_image ~= nil then 
  715. 		game_peg_unload(current_image) 
  716. 	end	 
  717. 	if Col_main_unload_img ~= nil then 
  718. 		game_peg_unload(Col_main_unload_img) 
  719. 	end 
  720. 	if Col_main_loading_img ~= nil then 
  721. 		game_peg_unload(Col_main_loading_img) 
  722. 		Col_main_loading_img = nil		 
  723. 	end	 
  724. end 
  725.  
  726. function col_main_exit(event) 
  727. 	-- exit the interface 
  728. 	col_main_lock_controls() 
  729. 	 
  730. 	-- Animate reward screen out 
  731. 	local anim_out_h = vint_object_find("col_main_anim_out", 0, Store_common_doc_handle) 
  732. 	lua_play_anim(anim_out_h) 
  733. 	pop_screen() 
  734.  
  735. end 
  736.  
  737. --HVS_TBT 6/27/2014 added missing *_unload() func 
  738. function col_main_unload() 
  739. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_COLLECTIBLES, nil) 
  740. end 
  741.  
  742. -- After the completion screen from a purchase, refresh the list of rewards. 
  743.  
  744. function col_main_gained_focus() 
  745. 	local index = Active_list:get_selection() 
  746. 	Menu_data = {} 
  747. 	Col_main_building_menu = Menu_data 
  748. 	 
  749. 	local category 
  750. 	if Col_main_category_id == CATEGORY_AUDIO then 
  751. 		Col_title:set_text("COL_CAT_AUDIO") 
  752. 		category = "audio_logs" 
  753. 	elseif Col_main_category_id == CATEGORY_TEXT then 
  754. 		Col_title:set_text("COL_CAT_TEXT") 
  755. 		category = "text_adventures" 
  756. 	elseif Col_main_category_id == CATEGORY_TOD then 
  757. 		Col_title:set_text("COL_CAT_TOD") 
  758. 		category = "tod" 
  759. 	elseif Col_main_category_id == CATEGORY_XMAS_TEXT then 
  760. 		Col_title:set_text("COL_CAT_XMAS_TEXT") 
  761. 		category = "xmas_text_adventures" 
  762. 	elseif Col_main_category_id == CATEGORY_XMAS_LETTER then 
  763. 		Col_title:set_text("COL_CAT_XMAS_LETTER") 
  764. 		category = "xmas_letters" 
  765. 	end 
  766. 	 
  767. 	vint_dataresponder_request("collections_main_dr", "col_main_add_reward", 0, category) 
  768. 	 
  769. 	-- May need to update image and description if list was shifted 
  770. 	col_main_item_nav(Col_main_building_menu[index])	 
  771. 	 
  772. 	col_main_populate_list(Menu_data, index) 
  773. 	 
  774. 	if game_get_platform() == "PC" then 
  775. 		Hint_bar:set_highlight(0) 
  776. 		Hint_bar_mouse_input_tracker:remove_all() 
  777. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  778. 		Hint_bar:add_mouse_inputs("col_main", Hint_bar_mouse_input_tracker) 
  779. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  780. 	end 
  781. 	 
  782. 	Input_tracker:subscribe(true)	 
  783. end 
  784.  
  785. -- When returning to the category menu from submenu, this gets called to repopulate the data, 
  786. -- since we need to determine which categories still have new rewards. 
  787. -- 
  788. function col_main_category_menu_update(menu_data) 
  789. 	local index = Active_list:get_selection() 
  790. 	Menu_data = {} 
  791. 	Col_main_building_menu = Menu_data 
  792. 	--vint_dataresponder_request("col_main_category_dr", "col_main_add_category", 0)	 
  793. 	col_main_add_category("COL_CAT_AUDIO", nil, nil, false) 
  794. 	-- HVS_JPM, we only want the first category 
  795. 	--[[ 
  796. 	col_main_add_category("COL_CAT_TEXT", nil, nil, false) 
  797. 	 
  798. 	if game_unlockable_is_unlocked( "ship_tod" ) and game_get_is_coop_client() == false then 
  799. 		col_main_add_category("COL_CAT_TOD", nil, nil, false) 
  800. 	end 
  801. 	 
  802. 	if game_is_dlc_available("DLC2") then 
  803. 		col_main_add_category("COL_CAT_XMAS_TEXT", nil, nil, false) 
  804. 		col_main_add_category("COL_CAT_XMAS_LETTER", nil, nil, false) 
  805. 	end 
  806. 	--]] 
  807. 	 
  808. 	Menu_data = Col_main_building_menu 
  809. 	Menu_data.on_enter = col_main_category_menu_update 
  810. 	col_main_populate_list(Menu_data, index) 
  811. end 
  812.  
  813.  
  814. function col_main_nav_up(event, acceleration) 
  815. 	Active_list:move_cursor(-1) 
  816.  
  817. 	local data_item = Active_list:return_selected_data() 
  818. 	col_main_tome_item_nav(data_item) 
  819.  
  820. end 
  821.  
  822. function col_main_nav_down(event, acceleration) 
  823. 	Active_list:move_cursor(1) 
  824.  
  825. 	local data_item = Active_list:return_selected_data() 
  826. 	col_main_tome_item_nav(data_item) 
  827.  
  828. end 
  829.  
  830. function col_main_button_a() 
  831. 	local current_index = Active_list:get_selection() 
  832.  
  833. 	local data_item = Active_list:return_selected_data() 
  834.  
  835. 	if data_item.is_locked == true then	 
  836. 		return 
  837. 	end 
  838.  
  839. 	local homie = data_item.homie 
  840. 	local index = data_item.id 
  841. 	vint_scriptevent_post("audio_log_play", -1, -1) 
  842. 	vint_scriptevent_post("audio_log_play", homie, index) 
  843. end 
  844.  
  845. function col_main_button_b() 
  846. 	col_main_lock_controls() 
  847. 	cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_COLLECTIBLES, col_main_exit_to_extras) 
  848. end 
  849.  
  850. function col_main_exit_to_extras() 
  851. 	pop_screen() 
  852. end 
  853.  
  854. -- ===================================== 
  855. --       Mouse Specific Functions 
  856. -- ===================================== 
  857.  
  858. function col_main_mouse_update() 
  859. 	if Mouse_input_tracker ~= nil then 
  860. 		Mouse_input_tracker:remove_all() 
  861. 		Active_list:add_mouse_inputs("col_main", Mouse_input_tracker) 
  862. 		Hint_bar:add_mouse_inputs("col_main", Mouse_input_tracker) 
  863. 		Mouse_input_tracker:subscribe(true) 
  864. 	end 
  865. end 
  866.  
  867. function col_main_enable_mouse(enable) 
  868. 	if game_get_platform() == "PC" and enable ~= nil then 
  869. 		if Mouse_input_tracker ~= 0 then 
  870. 			Mouse_input_tracker:subscribe(enable) 
  871. 		end 
  872. 		 
  873. 		if Hint_bar_mouse_input_tracker ~= nil then 
  874. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  875. 		end 
  876. 	end 
  877. end 
  878.  
  879. -- Mouse inputs 
  880. function col_main_mouse_click(event, target_handle, mouse_x, mouse_y) 
  881. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  882. 	if hint_index == 1 then 
  883. 		col_main_button_b() 
  884. 	elseif hint_index == 2 then 
  885. 		col_main_button_a() 
  886. 	end 
  887.  
  888. 	local new_index = Active_list:get_button_index(target_handle) 
  889. 	if new_index ~= 0 then 
  890. 		Active_list:set_selection(new_index) 
  891. 		col_main_button_a() 
  892. 	end 
  893. end 
  894.  
  895. function col_main_mouse_move(event, target_handle) 
  896. 	Hint_bar:set_highlight(0) 
  897. 	 
  898. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  899. 	if hint_index ~= 0 then 
  900. 		Hint_bar:set_highlight(hint_index) 
  901. 	end 
  902. 	 
  903. 	local old_index = Active_list:get_selection() 
  904. 	local new_index = Active_list:get_button_index(target_handle) 
  905. 	if new_index ~= 0 and new_index ~= old_index then 
  906. 		Active_list:set_selection(new_index) 
  907. 		Active_list:move_cursor(0, true) 
  908. 		 
  909. 		-- If the item has a callback for navigation, do it 
  910. 		local data_item = Active_list:return_selected_data() 
  911. 		 
  912. 		col_main_tome_item_nav(data_item) 
  913. 	end 
  914. end 
  915.  
  916. function col_main_mouse_scroll(event, target_handle, mouse_x, mouse_y, scroll_lines) 
  917.  
  918. 	if Active_list:list_is_playing() == false then			 
  919. 		if scroll_lines ~= 0 then 
  920. 			if Active_list:get_scroll_region_handle() == target_handle then 
  921. 				Active_list:scroll_list(scroll_lines * -1) 
  922. 				Active_list:update_mouse_inputs("col_main", Mouse_input_tracker) 
  923. 			end 
  924. 		end 
  925. 	end 
  926. end 
  927.  
  928. function col_main_mouse_drag(event, target_handle, mouse_x, mouse_y) 
  929. 	if Active_list:list_is_playing() == false then 
  930. 		if Active_list.scrollbar.tab_grp.handle == target_handle then 
  931. 			local new_start_index = Active_list.scrollbar:drag_scrolltab(mouse_y, Active_list.num_buttons - (Active_list.max_buttons - 1)) 
  932. 			Active_list:scroll_list(0, new_start_index) 
  933. 		end 
  934. 	end 
  935. end 
  936.  
  937. function  col_main_mouse_drag_release(event, target_handle, mouse_x, mouse_y) 
  938. 	if Active_list:list_is_playing() == false then 
  939. 		if Active_list.scrollbar.tab_grp.handle == target_handle then 
  940. 			local start_index = Active_list:get_visible_indices() 
  941. 			Active_list.scrollbar:release_scrolltab(start_index, Active_list.num_buttons - (Active_list.max_buttons - 1)) 
  942. 			col_main_mouse_update() 
  943. 		end 
  944. 	end 
  945. end