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