./cell_rewards.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 Color_grid 
  13. local Color_grid_grp 
  14. local Not_popup_grp 
  15. local Reward_image 
  16.  
  17. local Hint_bar_mouse_input_tracker 
  18.  
  19. local Cell_rewards_loading_img = nil 
  20. local Cell_rewards_unload_img  = nil 
  21.  
  22. local Cell_rewards_category_id = 0 
  23. local Cell_rewards_category_name = nil 
  24. local Cell_rewards_doc_handle = -1 
  25.  
  26. local Cell_rewards_building_menu = {} 
  27.  
  28. local Cell_rewards_img_update_thread = -1 
  29.  
  30. ---------------------------------------------------------------------------  
  31. -- Initialize Rewards Store 
  32. --------------------------------------------------------------------------- 
  33. function cell_rewards_init() 
  34. 	 
  35. 	Cell_rewards_doc_handle = vint_document_find("cell_rewards") 
  36.  
  37. 	-- Set up some callbacks for the common store script 
  38. 	Store_common_populate_list_cb = cell_rewards_populate_list 
  39. 	Store_common_exit_cb				= cell_rewards_exit 
  40.  
  41. 	-- Subscribe to the button presses we need 
  42. 	Input_tracker:remove_input("map") 
  43. 	Input_tracker:add_input("map", "cell_rewards_input_map", 50) 
  44. 	Input_tracker:subscribe(false) 
  45.  
  46. 	--Set Mask in the store... 
  47. 	local cell_mask = Vdo_base_object:new("cell_mask", 0, Store_common_doc_handle) 
  48. 	cell_mask:set_visible(true) 
  49. 	cell_mask:set_property("mask", true) 
  50. 	 
  51. 	--Set Title 
  52. 	local rewards_title = Vdo_base_object:new("rewards_title", 0,Cell_rewards_doc_handle) 
  53. 	rewards_title:set_text("STORE_UPGRADES_TITLE") 
  54. 	 
  55. 	--Setup Button Hints 
  56. 	Hint_bar = Vdo_hint_bar:new("hint_bar", 0, Store_common_doc_handle) 
  57. 	local hint_data = { 
  58. 		{CTRL_MENU_BUTTON_B, "MENU_BACK"},	 
  59. 	} 
  60. 	Hint_bar:set_hints(hint_data) 	 
  61. 	Hint_bar:set_visible(true) 
  62.  
  63. 	Store_header:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY)	 
  64. 	Store_header:set_visible(true) 
  65. 	 
  66. 	Active_list = Vdo_mega_list:new("list_1", 0, Store_common_doc_handle, "store_common.lua", "Active_list") 
  67.  
  68. 	Store_logo = Vdo_base_object:new("store_logo_img", 0, Store_common_doc_handle) 
  69. 	 
  70. 	-- Everything that is not in the popup so we can fade it when the popup is active 
  71. 	Not_popup_grp = Vdo_base_object:new("not_popup_grp", 0, Store_common_doc_handle) 
  72. 	 
  73. 	-- Setup purchase popup 
  74. 	Store_popup = Vdo_store_popup:new("store_popup", 0, Store_common_doc_handle) 
  75. 	Store_popup:set_visible(false) 
  76. 	Store_popup:set_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY, COLOR_STORE_REWARDS_TERTIARY) 
  77. 	Store_popup:set_size(STORE_COMMON_LIST_SIZE, (LIST_BUTTON_HEIGHT * 5) + (LIST_BUTTON_SPACE * 5)) 
  78. 	 
  79. 	Color_grid_grp = Vdo_base_object:new("color_grid_grp", 0, Store_common_doc_handle) 
  80. 	Color_grid_grp:set_visible(false)	 
  81. 	 
  82. 	-- Needs to be done after the list is drawn/populated 
  83. 	Active_list:set_highlight_color(COLOR_STORE_REWARDS_PRIMARY, COLOR_STORE_REWARDS_SECONDARY)	 
  84. 	 
  85. 	local rewards_grp = Vdo_base_object:new("rewards_grp", 0, Cell_rewards_doc_handle)	 
  86. 	rewards_grp:set_visible(true) 
  87. 		 
  88. 	-- Pass the table data to the megalist vdo. 
  89. 	vint_dataresponder_request("cell_rewards_category_dr", "cell_rewards_add_category", 0)	 
  90.  
  91. 	cell_rewards_populate_list(Menu_data, 1)	 
  92. 	 
  93. 	-- Add this on_enter callback so the category menu gets refreshed when returning from a submenu 
  94. 	Menu_data.on_enter = cell_rewards_category_menu_update 
  95. 	 
  96. 	-- For the rewards store, we don't want the bg to render behind the player, so change this property. 
  97. 	-- Perhaps these can be organized so it's easier to do this. 
  98. 	local grp1_h = vint_object_find("lets_pretend_bg_grp", 0, Store_common_doc_handle) 
  99. 	vint_set_property(grp1_h, "background", false) 
  100. 	vint_set_property(grp1_h, "visible", false) 
  101. 	 
  102. 	-- Animate phone in 
  103. 	local from_phone_anim_h = vint_object_find("rewards_anim_in", 0, Store_common_doc_handle) 
  104. 	lua_play_anim(from_phone_anim_h, 0, Store_common_doc_handle) 
  105.  
  106. 	-- Iniitialize reward image... 
  107. 	Reward_image = Vdo_bitmap_viewer:new("reward_image", 0, Cell_rewards_doc_handle)	 
  108. 	 
  109. 	-- Hide description 
  110. 	Reward_image:set_description(" ", nil) 
  111. 	Reward_image:set_visible(false) 
  112.  
  113. 	-- Make sure our cellphone frame is in view, sometimes we could come straight into this menu... 
  114. 	cell_show_frame() 
  115. 	 
  116. 	-- Mouse input 
  117. 	if game_get_platform() == "PC" then 
  118. 		Hint_bar:set_highlight(0) 
  119. 		 
  120. 		Hint_bar_mouse_input_tracker = Vdo_input_tracker:new() 
  121. 		Hint_bar:add_mouse_inputs("cell_rewards", Hint_bar_mouse_input_tracker) 
  122. 		Hint_bar_mouse_input_tracker:subscribe(true) 
  123. 	end 
  124. 	 
  125. 	--Transition the screen in... 
  126. 	if Rewards_from_menu then 
  127. 		cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_REWARDS, CELL_SCREEN_MAIN, cell_rewards_unlock_controls) 
  128. 	else 
  129. 		--fade out header from the foreground... 
  130. 		cell_foreground_fade_out_header() 
  131. 		cell_transition_screen(CELL_STATE_LANDSCAPE, CELL_SCREEN_REWARDS, CELL_SCREEN_NONE, cell_rewards_unlock_controls) 
  132. 		 
  133. 		--Reset our rewards from menu flag, this is a quick fix so back button functions as normal, 
  134. 		-- even if we went into the screen via (press back to upgrade). JMH 7/3/201) 
  135. 		Rewards_from_menu = true 
  136. 	end 
  137. end 
  138.  
  139. -- Cleanup 
  140. function cell_rewards_cleanup() 
  141. 	-- Nuke all button subscriptions 
  142. 	Input_tracker:subscribe(false) 
  143. 	cell_rewards_enable_mouse(false) 
  144.  
  145. 	local current_image = Reward_image:get_image()	 
  146. 	if current_image ~= nil then 
  147. 		game_peg_unload(current_image) 
  148. 	end		 
  149. 	if Cell_rewards_unload_img ~= nil then 
  150. 		game_peg_unload(Cell_rewards_unload_img) 
  151. 	end 
  152. 	if Cell_rewards_loading_img ~= nil then 
  153. 		game_peg_unload(Cell_rewards_loading_img) 
  154. 	end 
  155. end 
  156.  
  157. ------------------------------------------------------------------------------- 
  158. -- Controls Unlock  
  159. -- 
  160. function cell_rewards_unlock_controls() 
  161. 	Input_tracker:subscribe(true) 
  162. 	cell_rewards_enable_mouse(true) 
  163. end 
  164.  
  165. ------------------------------------------------------------------------------- 
  166. -- Controls Lock 
  167. -- 
  168. function cell_rewards_lock_controls() 
  169. 	Input_tracker:subscribe(false) 
  170. 	cell_rewards_enable_mouse(false) 
  171. end 
  172.  
  173. -- Populate the active megalist menu, and hide the previous menu 
  174. -- 
  175. -- list_data: 		this table contains the data to populate the megalist 
  176. -- current_index: 	the current index in the menu that's selected 
  177. -- 
  178. function cell_rewards_populate_list(list_data, current_index) 
  179.  
  180. 	Active_list:draw_items(list_data, current_index, STORE_COMMON_LIST_SIZE, 12, .8) 
  181. 	Active_list:set_visible(true) 
  182. 	 
  183. 	if game_get_platform() == "PC" then 
  184. 		Mouse_input_tracker:remove_all() 
  185. 		Active_list:set_store("cell_rewards") 
  186. 		Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  187. 		Mouse_input_tracker:subscribe(true) 
  188. 	end 
  189. end 
  190.  
  191. -- Called in a thread to delay the image updating. 
  192. -- This is done for 2 reasons: to slow down rapid scrolling updates done too quickly, 
  193. -- and because the streaming system didn't always co-operate with the images being released 
  194. -- from the callback context that was executed when another stream load completed. 
  195. -- 
  196. function cell_rewards_image_update() 
  197. 	delay(0.2) 
  198. 	game_peg_unload(Cell_rewards_unload_img)	 
  199. 	game_peg_load_with_cb("cell_rewards_show_image", 1, Cell_rewards_loading_img) 
  200. 	Cell_rewards_img_update_thread = -1 
  201. end 
  202.  
  203. -- Callback for when an image is done loading. 
  204. -- SEH: It might make sense to roll this into vdo_bitmap_viewer... 
  205. -- 
  206. function cell_rewards_show_image() 
  207. 	local index = Active_list:get_selection() 
  208. 	local new_image = Menu_data[index].image 
  209. 	local img_scale_x = .68 
  210. 	local img_scale_y = .68 
  211. 	 
  212. 	if Cell_rewards_loading_img == new_image then 
  213. 		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) 
  214. 		Reward_image:set_description(nil, Menu_data[index].description) 
  215. 		Reward_image:set_visible(true) 
  216. 		Cell_rewards_loading_img = nil 
  217. 	else 
  218. 		-- a new image was picked while we were loading - load this now, and unload the one we just loaded 
  219. 		if new_image ~= nil then 
  220. 			Cell_rewards_unload_img = Cell_rewards_loading_img 
  221. 			Cell_rewards_loading_img = new_image 
  222. 			Cell_rewards_img_update_thread = thread_new("cell_rewards_image_update")	 
  223. 		else 
  224. 			game_peg_unload(Cell_rewards_loading_img) 
  225. 			Cell_rewards_loading_img = nil 
  226. 		end 
  227. 	end 
  228. end 
  229.  
  230. -- Update reward image based on which reward is highlighted 
  231. -- 
  232. -- index of the reward in the table 
  233. -- 
  234. function cell_rewards_item_nav(menu_data) 
  235. 	Reward_image:set_visible(false) 
  236. 	if Cell_rewards_loading_img == nil then 
  237. 		local new_image = menu_data.image	 
  238. 		local current_image = Reward_image:get_image()	 
  239. 		if current_image ~= nil then 
  240. 			game_peg_unload(current_image) 
  241. 		end 
  242. 		if new_image ~= nil then 
  243. 			-- must set Cell_rewards_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  244. 			Cell_rewards_loading_img = new_image		 
  245. 			game_peg_load_with_cb("cell_rewards_show_image", 1, new_image) 
  246. 		end 
  247. 	end 
  248. 	 
  249. 	-- if this unlockable was marked as "new", then clear the flag since the player highlighted it 
  250. 	if menu_data.is_new then 
  251. 		vint_dataresponder_post("cell_rewards_reward_dr", "Clear_new", menu_data.id) 
  252. 		 
  253. 		--Remove our mouse inputs first... 
  254. 		if Mouse_input_tracker ~= 0 then 
  255. 			Mouse_input_tracker:remove_all() 
  256. 		end 
  257. 		 
  258. 		--Get index from the list and then remove the flag... 
  259. 		local index = Active_list:get_index_from_id(menu_data.id) 
  260. 		if index ~= -1 then 
  261. 			Active_list:remove_new_flag(index) 
  262. 		end 
  263. 		 
  264. 		--Update cursor, 
  265. 		Active_list:move_cursor(0) 
  266. 		--Re add mouse inputs... 
  267. 		if Mouse_input_tracker ~= 0 then 
  268. 			Mouse_input_tracker:remove_all() 
  269. 			Active_list:add_mouse_inputs("store_common", Mouse_input_tracker) 
  270. 			Mouse_input_tracker:subscribe(true) 
  271. 		end 
  272. 	end 
  273. 	 
  274. 	Store_header:set_price(menu_data.price) 
  275. 	Store_header:set_level(menu_data.level_required) 
  276. 	--Reward_image:set_level_required(Menu_data[index].level_required) 
  277. end 
  278.  
  279. -- Update category image based on which category is highlighted 
  280. -- 
  281. -- index of the category in the table 
  282. -- 
  283. function cell_rewards_category_nav(menu_data) 
  284. 	Cell_rewards_category_id = menu_data.id 
  285. 	Cell_rewards_category_name = menu_data.label 
  286. 	Reward_image:set_visible(false) 
  287. 	 
  288. 	-- SEH - for now, we're not going to show any category images since they aren't ready.  Uncomment following code when we are. 
  289. 	-- if Cell_rewards_loading_img == nil then 
  290. 		-- local new_image = Menu_data[index].image 
  291. 		-- local current_image = Reward_image:get_image() 
  292. 		-- if current_image ~= nil then 
  293. 			-- game_peg_unload(current_image) 
  294. 		-- end 
  295. 		-- if new_image ~= nil then 
  296. 			-- -- must set Cell_rewards_loading_img before calling game_peg_load_with_cb(), which could fire the callback right away 
  297. 			-- Cell_rewards_loading_img = new_image		 
  298. 			-- game_peg_load_with_cb("cell_rewards_show_image", 1, new_image) 
  299. 		-- end 
  300. 	-- end 
  301. end 
  302.  
  303. function cell_rewards_purchase_select(menu_data) 
  304. 	if menu_data.is_locked == true or menu_data.is_purchased == true then	 
  305. 		return 
  306. 	end 
  307. 	cell_rewards_enable_mouse(false) 
  308.  
  309. 	-- Are we short on cash? 
  310. 	if menu_data.price > Store_common_player_cash then 
  311. 		Store_popup:populate_list(Ok_choice, 1, STORE_COMMON_LIST_SIZE, 1) 
  312. 		Store_popup:set_title("MENU_TITLE_NOTICE") 
  313. 		Store_popup:set_text("HUD_SHOP_INSUFFICIENT_FUNDS")		 
  314. 		Store_popup:nav_enable(true, "cell_rewards_fail_msg", "cell_rewards_popup_nav") 
  315. 		Not_popup_grp:set_alpha(.5)		 
  316. 		Active_list:set_visible(false) 
  317. 		return 
  318. 	end 
  319. 	 
  320. 	-- Make sure they want to buy this 
  321. 	Store_popup:populate_list(Yes_no_choices, 1, STORE_COMMON_LIST_SIZE, 2)	 
  322. 	Store_popup:set_title("STORE_TITLE_PURCHASING") 
  323. 	Store_popup:set_text("STORE_TEXT_CONFIRM_PURCHASE_BLANK")				 
  324. 	Store_popup:nav_enable(true, "cell_rewards_purchase_final", "cell_rewards_popup_nav") 
  325. 	Not_popup_grp:set_alpha(.5) 
  326. 	Active_list:set_visible(false) 
  327. end 
  328.  
  329. function cell_rewards_popup_nav(event, value) 
  330. 	if event == "nav_up" then	 
  331. 		Store_popup.list:move_cursor(-1)	 
  332. 	elseif event == "nav_down" then 
  333. 		Store_popup.list:move_cursor(1) 
  334. 	elseif event == "mouse_move" then 
  335. 		-- value contains the target_handle in this case 
  336. 		local new_index = Store_popup.list:get_button_index(value) 
  337. 		if new_index ~= 0 then 
  338. 			Store_popup.list:set_selection(new_index) 
  339. 			Store_popup.list:move_cursor(0, true) 
  340. 		end 
  341. 	else 
  342. 		--do nothing 
  343. 	end	 
  344. end 
  345.  
  346. function cell_rewards_fail_msg(event) 
  347. 	Store_popup:nav_enable(false, nil, nil) 
  348. 	Not_popup_grp:set_alpha(1) 
  349. 	Active_list:set_visible(true) 
  350. 	cell_rewards_enable_mouse(true) 
  351. end 
  352.  
  353. -- Finalize or cancel a purchase based on the result of the confirmation question. 
  354. -- 
  355. -- response: 	how did the user respond? 
  356. -- action: 		indicates if the dialog box was closed or some other action. 
  357. -- 
  358. function cell_rewards_purchase_final(event) 
  359. 	Store_popup:nav_enable(false, nil, nil) 
  360. 	Not_popup_grp:set_alpha(1) 
  361. 	Active_list:set_visible(true) 
  362.  
  363. 	cell_rewards_enable_mouse(true) 
  364. 	 
  365. 	-- The user hit the B button and are cancelling the purchase 
  366. 	-- This is redundant to selecting "No" in the list 
  367. 	if event == "back" then 
  368. 		game_UI_audio_play("UI_Main_Menu_Nav_Back")	 
  369. 		return 
  370. 	end 
  371. 	 
  372. 	game_UI_audio_play("UI_Main_Menu_Select")	 
  373. 	 
  374. 	-- Did we select yes?  This assumes yes is the first item 
  375. 	if Store_popup:get_selected_data() ~= 1 then 
  376. 		return 
  377. 	end 
  378.  
  379. 	-- give reward and take money here 
  380. 	local current_index = Active_list:get_selection() 
  381. 	vint_dataresponder_post("cell_rewards_reward_dr", "Purchase", Menu_data[current_index].id) 
  382.  
  383. 	-- do this so holding down the button doesn't cause repeated actions 
  384. 	Input_tracker:subscribe(false)	 
  385. 	 
  386. 	-- Save off index before we refresh the list 
  387. 	Menu_data.start_index = current_index 
  388. end 
  389.  
  390. function cell_rewards_add_category(name, image_name, is_new, disabled) 
  391. 	local menu_idx = #Menu_data + 1 
  392.  
  393. 	local new_item = { 
  394. 		type = TYPE_BUTTON, 
  395. 		id = menu_idx - 1, 
  396. 		label = name, 
  397. 		label_crc = nil, 
  398. 		image = image_name, 
  399. 		on_nav = cell_rewards_category_nav, 
  400. 		on_sub_menu_fill = cell_rewards_populate_rewards, 
  401. 		is_new = is_new, 
  402. 		disabled = disabled 
  403. 	}		 
  404.  
  405. 	Menu_data[menu_idx] = new_item 
  406. end 
  407.  
  408. -- This is called after the sub menu is generated for a selected category, and we now need to update 
  409. -- the image and description for the first award available.  Must be called in on_enter(), because  
  410. -- the script asssumes Menu_data has already been set to the new sub menu we entered. 
  411. -- 
  412. function cell_rewards_on_enter_draw_image() 
  413. 	cell_rewards_item_nav(Menu_data[1]) 
  414. end 
  415.  
  416. function cell_rewards_populate_rewards(menu_data) 
  417. 	Cell_rewards_building_menu = menu_data.sub_menu 
  418. 	vint_dataresponder_request("cell_rewards_reward_dr", "cell_rewards_add_reward", 0, Cell_rewards_category_id) 
  419. 	Cell_rewards_building_menu.on_enter = cell_rewards_on_enter_draw_image 
  420. end 
  421.  
  422. function cell_rewards_add_reward(name_crc, desc_crc, image_name, is_locked, is_purchased, price, id, level_required, trumps, is_new) 
  423. 	local menu_idx = #Cell_rewards_building_menu + 1 
  424.  
  425. 	--Levels always displayed to the user as +1... (JMH 6/9/2011) 
  426. 	level_required = level_required +1 
  427. 	 
  428. 	local new_item = { 
  429. 		type = TYPE_BUTTON, 
  430. 		id = id, 
  431. 		label = nil, 
  432. 		label_crc = name_crc, 
  433. 		image = image_name, 
  434. 		description = desc_crc, 
  435. 		is_locked = is_locked, 
  436. 		is_purchased = is_purchased, 
  437. 		price = price, 
  438. 		-- Display of level and max_level disabled for now 
  439. 		level = nil, 
  440. 		max_level = nil, 
  441. 		level_required = level_required, 
  442. 		on_nav = cell_rewards_item_nav, 
  443. 		on_select = cell_rewards_purchase_select, 
  444. 		on_back = cell_rewards_revert_header, 
  445. 		trumps = trumps, -- CRC for the name of the prerequisite 
  446. 		is_new = is_new, 
  447. 	}		 
  448. 	 
  449. 	Cell_rewards_building_menu[menu_idx] = new_item 
  450. end 
  451.  
  452. function cell_rewards_revert_header(menu_data) 
  453.  
  454. 	-- kill update thread 
  455. 	if Cell_rewards_img_update_thread ~= -1 then 
  456. 		thread_kill(Cell_rewards_img_update_thread) 
  457. 		Cell_rewards_img_update_thread = -1 
  458. 	end 
  459. 	 
  460. 	Store_header:set_price(nil) 
  461. 	Store_header:set_level(nil) 
  462. 	-- Hide description 
  463. 	Reward_image:set_description(" ", nil) 
  464. 	Reward_image:set_visible(false) 
  465. 	local current_image = Reward_image:get_image()	 
  466. 	if current_image ~= nil then 
  467. 		game_peg_unload(current_image) 
  468. 	end	 
  469. 	if Cell_rewards_unload_img ~= nil then 
  470. 		game_peg_unload(Cell_rewards_unload_img) 
  471. 	end 
  472. 	if Cell_rewards_loading_img ~= nil then 
  473. 		game_peg_unload(Cell_rewards_loading_img) 
  474. 		Cell_rewards_loading_img = nil		 
  475. 	end	 
  476. end 
  477.  
  478.  
  479. function cell_rewards_input_map() 
  480. 	Rewards_from_menu = false 
  481. 	cell_rewards_exit() 
  482. end 
  483.  
  484.  
  485. function cell_rewards_exit(event) 
  486. 	-- exit the interface 
  487. 	cell_rewards_lock_controls() 
  488. 	 
  489. 	-- Animate reward screen out 
  490. 	local anim_out_h = vint_object_find("rewards_anim_out", 0, Store_common_doc_handle) 
  491. 	lua_play_anim(anim_out_h) 
  492. 	 
  493. 	if Rewards_from_menu then 
  494. 		--Transition to cell main 
  495. 		cell_transition_screen(CELL_STATE_PORTRAIT, CELL_SCREEN_MAIN, CELL_SCREEN_REWARDS, cell_rewards_exit_to_main) 
  496. 		game_UI_audio_play("UI_Cell_Nav_Back") 
  497. 	else	 
  498. 		--Transition to game 
  499. 		cell_transition_screen(CELL_STATE_OUT, CELL_SCREEN_REWARDS, CELL_SCREEN_NONE, cell_rewards_exit_to_game) 
  500. 		game_UI_audio_play("UI_Cell_Close") 
  501. 	end 
  502. end 
  503.  
  504. function cell_rewards_exit_to_main() 
  505. 	pop_screen() 
  506. end 
  507.  
  508. function cell_rewards_exit_to_game(event)	 
  509. 	pop_screen()	--Rewards 
  510. 	pop_screen()	--Main 
  511. 	pop_screen()	--Cell Frame 
  512. end 
  513.  
  514. -- After the completion screen from a purchase, refresh the list of rewards. 
  515. -- 
  516. function cell_rewards_gained_focus() 
  517. 	local index = Active_list:get_selection() 
  518. 	Menu_data = {} 
  519. 	Cell_rewards_building_menu = Menu_data 
  520. 	vint_dataresponder_request("cell_rewards_reward_dr", "cell_rewards_add_reward", 0, Cell_rewards_category_id) 
  521. 	 
  522. 	-- May need to update image and description if list was shifted 
  523. 	cell_rewards_item_nav(Cell_rewards_building_menu[index])	 
  524. 	 
  525. 	cell_rewards_populate_list(Menu_data, index) 
  526. 	Input_tracker:subscribe(true)	 
  527. end 
  528.  
  529. -- ===================================== 
  530. --       Mouse Specific Functions 
  531. -- ===================================== 
  532. function cell_rewards_enable_mouse(enable) 
  533. 	if game_get_platform() == "PC" and enable ~= nil then 
  534. 		if Mouse_input_tracker ~= 0 then 
  535. 			Mouse_input_tracker:subscribe(enable) 
  536. 		end 
  537. 		 
  538. 		if Hint_bar_mouse_input_tracker ~= nil then 
  539. 			Hint_bar_mouse_input_tracker:subscribe(enable) 
  540. 		end 
  541. 	end 
  542. end 
  543.  
  544. -- Mouse inputs 
  545. function cell_rewards_mouse_click(event, target_handle, mouse_x, mouse_y) 
  546. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  547. 	if hint_index == 1 then 
  548. 		store_common_button_b() 
  549. 	end 
  550.  
  551. 	local new_index = Active_list:get_button_index(target_handle) 
  552. 	if new_index ~= 0 then 
  553. 		Active_list:set_selection(new_index) 
  554. 		cell_rewards_button_a() 
  555. 	end 
  556. end 
  557.  
  558. function cell_rewards_mouse_move(event, target_handle) 
  559. 	Hint_bar:set_highlight(0) 
  560. 	 
  561. 	local hint_index = Hint_bar:get_hint_index(target_handle) 
  562. 	if hint_index ~= 0 then 
  563. 		Hint_bar:set_highlight(hint_index) 
  564. 	end 
  565. 	 
  566. 	local old_index = Active_list:get_selection() 
  567. 	local new_index = Active_list:get_button_index(target_handle) 
  568. 	if new_index ~= 0 and new_index ~= old_index then 
  569. 		Active_list:set_selection(new_index) 
  570. 		Active_list:move_cursor(0, true) 
  571. 		 
  572. 		-- If the item has a callback for navigation, do it 
  573. 		local data_item = Active_list:return_selected_data() 
  574. 		if data_item.on_nav ~= nil then 
  575. 			data_item.on_nav(data_item) 
  576. 		end 
  577. 	end 
  578. end 
  579.  
  580. -- When returning to the category menu from submenu, this gets called to repopulate the data, 
  581. -- since we need to determine which categories still have new rewards. 
  582. -- 
  583. function cell_rewards_category_menu_update(menu_data) 
  584. 	local index = Active_list:get_selection() 
  585. 	Menu_data = {} 
  586. 	Cell_rewards_building_menu = Menu_data 
  587. 	vint_dataresponder_request("cell_rewards_category_dr", "cell_rewards_add_category", 0)	 
  588. 	Menu_data = Cell_rewards_building_menu 
  589. 	Menu_data.on_enter = cell_rewards_category_menu_update 
  590. 	cell_rewards_populate_list(Menu_data, index) 
  591. end