./reward_granted.lua

  1. --Globals 
  2. Reward_granted_doc = -1 --Global Reference to doc... 
  3.  
  4. --Locals! 
  5. local Reward = {} 
  6. local Rewards_count = 0 
  7. local Rewards_current_display = 0  
  8. local Fluer_outline_anims = {} 
  9. local Fluer_outline_objects = {} 
  10. local Peg_image_name = -1 
  11. local Reward_granted_input_tracker 
  12. local Control_blocked = 0 
  13. local Reward_granted_end_cb 
  14.  
  15. local Upgrades_descriptions = {} 
  16.  
  17. local Bg_mouse_input_tracker 
  18. local Bg_image 
  19.  
  20. local DESC_GRP_SPACING = 20 
  21. local Desc_cloned_grps = {} 
  22.  
  23. --Initialize 
  24. function reward_granted_init() 
  25. 	Reward_granted_doc = vint_document_find("reward_granted") 
  26. 	--Setup fleur Outline Anims 
  27. 	--Clone fleur outline animation and object. Then Retarget and store handles for later... 
  28. 	local fleur_outline = Vdo_anim_object:new("fleur_outline", 0, Reward_granted_doc) 
  29. 	local fleur_outline_anim = Vdo_anim_object:new("fleur_outline_zoom_anim", 0, Reward_granted_doc) 
  30. 	fleur_outline:set_alpha(0) 
  31. 	for index = 1, 7 do 
  32. 		local fleur_outline_clone = Vdo_base_object:clone(fleur_outline.handle) 
  33. 		local anim = Vdo_anim_object:clone(fleur_outline_anim.handle) 
  34. 		anim:set_target_handle(fleur_outline_clone.handle) 
  35. 		fleur_outline_clone:set_alpha(0) 
  36. 		anim:stop() 
  37. 		Fluer_outline_objects[index] = fleur_outline_clone 
  38. 		Fluer_outline_anims[index] = anim  
  39. 	end 
  40. 	 
  41. 	--Show Button Tips 
  42. 	local hint_data = { 
  43. 		{CTRL_MENU_BUTTON_A, "COMPLETION_CONTINUE"}, 
  44. 	} 
  45. 	local button_tips = Vdo_hint_bar:new("button_tips") 
  46. 	button_tips:set_hints(hint_data) 
  47. 	if( game_get_platform() ~= "PC" ) then	 
  48. 		button_tips:pulse(1) 
  49. 	end 
  50. 	--Hide the stuff until we are ready... 
  51. 	local h = vint_object_find("big_container", 0, Reward_granted_doc) 
  52. 	vint_set_property(h, "alpha", 0) 
  53. 	local background_grp_h = vint_object_find("respect_background_grp") 
  54. 	vint_set_property(background_grp_h, "alpha", 0) 
  55.  
  56. 	--setup callbacks for screen_fade_out anims 
  57. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  58. 	local fade_out_twn_h = vint_object_find("screen_fade_out_twn", 0, Reward_granted_doc) 
  59. 	vint_set_property(fade_out_twn_h, "end_event", "reward_screen_fade_cb") 
  60. 	 
  61. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  62. 	local button_tip_twn_h = vint_object_find("button_tip_twn", 0, Reward_granted_doc) 
  63. 	vint_set_property(button_tip_twn_h, "end_event", "screen_in_complete") 
  64. end 
  65.  
  66. --Close 
  67. function reward_granted_cleanup() 
  68. 	--unload old peg if loaded... 
  69. 	local peg_name = Peg_image_name 
  70. 	if Peg_image_name ~= -1 then 
  71. 		game_peg_unload("bms_pause_menu") 
  72. 		game_peg_unload(Peg_image_name) 
  73. 		Peg_image_name = -1 
  74. 	end 
  75. 	 
  76. 	reward_granted_inputs_unsubscribe() 
  77. end 
  78.  
  79. function noop() 
  80. 	-- Does nothing 
  81. end 
  82.  
  83. -------------------------------------------------------------------------------------------------------------- 
  84. -- Unsubscribe from inputs... 
  85. -- 
  86. function reward_granted_inputs_unsubscribe() 
  87. 	--Unsubscribe... 
  88. 	if Reward_granted_input_tracker ~= nil then 
  89. 		Reward_granted_input_tracker:subscribe(false) 
  90. 	end 
  91. 	 
  92. 	if Bg_mouse_input_tracker ~= nil then 
  93. 		Bg_mouse_input_tracker:subscribe(false) 
  94. 	end 
  95. end 
  96.  
  97. --Starts the reward sequence... This is designed to be called by its parent completion document or directly from c++... 
  98. function reward_granted_start() 
  99. 	local h = vint_object_find("safe_frame",0, Reward_granted_doc) 
  100. 	vint_set_property(h, "visible", true) 
  101.  
  102. 	Reward_granted_input_tracker = Vdo_input_tracker:new() 
  103. 	Reward_granted_input_tracker:add_input("nav_left", "noop", 100) 
  104. 	Reward_granted_input_tracker:add_input("nav_right", "noop", 100) 
  105. 	Reward_granted_input_tracker:add_input("nav_up", "noop", 100) 
  106. 	Reward_granted_input_tracker:add_input("nav_down", "noop", 100) 
  107. 	Reward_granted_input_tracker:add_input("back", "noop", 100) 
  108. 	Reward_granted_input_tracker:add_input("map", "noop", 100) 
  109. 	Reward_granted_input_tracker:add_input("select", "reward_granted_button_press", 100) 
  110. 	Reward_granted_input_tracker:add_input("pause", "reward_granted_button_press", 100) 
  111. 	Reward_granted_input_tracker:subscribe(true) 
  112. 	 
  113. 	Bg_image = Vdo_base_object:new("respect_background_bmp", 0, Reward_granted_doc) 
  114. 	 
  115. 	-- Mouse input 
  116. 	if game_get_platform() == "PC" then		 
  117. 		Bg_mouse_input_tracker = Vdo_input_tracker:new() 
  118. 		Bg_mouse_input_tracker:add_mouse_input("mouse_move", "reward_granted_mouse_move", 0, Bg_image.handle) 
  119. 		Bg_mouse_input_tracker:add_mouse_input("mouse_click", "reward_granted_mouse_click", 0, Bg_image.handle) 
  120. 		Bg_mouse_input_tracker:subscribe(true) 
  121. 	end 
  122. 	 
  123. 	--Show Screen 
  124. 	reward_screen_fade_cb() 
  125. 	 
  126. 	--Block controls until we are complete... 
  127. 	control_block(true) 
  128. end 
  129.  
  130. -- Callback when the a button is pressed. 
  131. function reward_granted_button_press() 
  132. 	if is_control_blocked() == false then 
  133. 		game_UI_audio_play("UI_Main_Menu_Select") 
  134. 		reward_granted_next_screen() 
  135. 	end 
  136. end 
  137.  
  138. --Starts the next screen... 
  139. function reward_granted_next_screen() 
  140. 	--fade out current screen, a callback will attempt to bring in the next... reward_screen_fade_cb() 
  141. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  142. 	lua_play_anim(fade_out_anim_h) 
  143. 	 
  144. 	--Block controls until we are complete... 
  145. 	control_block(true) 
  146. end 
  147.  
  148. --This is the callback after the VBM has loaded. 
  149. function reward_granted_next_cb() 
  150. 	--Plays back the screen... 
  151. 	local item_image = Reward.item_image 
  152. 	local item_name = Reward.item_name 
  153. 	local item_desc = Reward.item_desc 
  154. 	local unlockable_id = Reward.unlockable_id 
  155. 	local is_silverlink = Reward.is_silverlink 
  156. 	 
  157. 	--replace image with queued up image... 
  158. 	local unlockable_bmp = vint_object_find("unlockable_bmp", 0, Reward_granted_doc) 
  159. 	vint_set_property(unlockable_bmp, "image", item_image) 
  160. 	 
  161. 	--Set title 
  162. 	local title_h = vint_object_find("reward_name", 0, Reward_granted_doc) 
  163. 	vint_set_property(title_h, "text_tag", item_name) 
  164. 	resize_text_element(title_h, 435) 
  165. 	 
  166. 	--If Silverlink unlockable show the silverlink logo... 
  167. 	local silverlink_bmp_h = vint_object_find("silverlink_bmp", 0 , Reward_granted_doc) 
  168. 	vint_set_property(silverlink_bmp_h, "visible", is_silverlink) 
  169. 	 
  170. 	------------------ 
  171. 	--Set descritpions 
  172. 	------------------ 
  173. 	 
  174. 	--Destroy any cloned grps 
  175. 	for i = 1, #Desc_cloned_grps do 
  176. 		vint_object_destroy(Desc_cloned_grps[i]) 
  177. 	end 
  178. 	 
  179. 	Upgrades_descriptions = {} 
  180. 	 
  181. 	--Sean we need an identifier here in place of menu_data.id 
  182. 	vint_dataresponder_request("powers_upgrades_dr", "reward_granted_add_upgrades_descriptions", 0, "get_upgrade_desc", unlockable_id) 
  183. 	 
  184. 	--[[reward_granted_add_upgrades_descriptions("Test ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 1) 
  185. 	reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2) 
  186. 	reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt.", 3)  
  187. 	reward_granted_add_upgrades_descriptions("Lorem ipsum dolor sit amet, consectetur adipisicing elit.", 2)]] 
  188. 	 
  189. 	 
  190. 	 
  191. 	 
  192. 	 
  193. 	local description_h = vint_object_find("reward_description", 0, Reward_granted_doc) 
  194. 	local final_y, final_x 
  195. 	local align_grp_h = vint_object_find("align_grp", 0, Reward_granted_doc) 
  196. 	 
  197. 	local desc_grp_h = vint_object_find("desc_grp", 0, Reward_granted_doc) 
  198. 	vint_set_property(desc_grp_h, "visible", false) 
  199.  
  200. 	if #Upgrades_descriptions ~= 0 and Upgrades_descriptions[1].element ~= -1 then 
  201. 		--hide simple description 
  202. 		vint_set_property(description_h, "visible", false) 
  203. 		 
  204. 		 
  205. 		 
  206. 		--base group that holds cloned groups 
  207. 		local desc_move_grp_h = vint_object_find("desc_move_grp", 0, Reward_granted_doc) 
  208. 		local desc_move_grp_x, desc_move_grp_y = vint_get_property(desc_move_grp_h, "anchor") 
  209. 		 
  210. 		local prev_height = 0 
  211. 		Desc_cloned_grps = {} 
  212. 		 
  213. 		for i = 1, #Upgrades_descriptions do 
  214. 			--get data out of table 
  215. 			local description = Upgrades_descriptions[i].description 
  216. 			local element = Upgrades_descriptions[i].element 
  217. 			 
  218. 			--clone base item... 
  219. 			local h = vint_object_clone(desc_grp_h) 
  220. 			 
  221. 			--Set Text 
  222. 			local desc_type_txt_h = vint_object_find("desc_type_txt", h) 
  223. 			local desc_txt_h = vint_object_find("desc_txt", h) 
  224. 			vint_set_property(desc_type_txt_h, "text_tag", POWERS_ELEMENTS_ENUMS[element].short_label) 
  225. 			vint_set_property(desc_txt_h, "text_tag", description) 
  226. 			 
  227. 			--Set icon 
  228. 			local desc_icon_h = vint_object_find("desc_icon", h) 
  229. 			vint_set_property(desc_icon_h, "image", POWERS_ELEMENTS_ENUMS[element].bitmap) 
  230. 			 
  231. 			--Position grp... 
  232. 			local x, y = vint_get_property(h, "anchor") 
  233. 			local width1, height1 = element_get_actual_size(desc_type_txt_h) 
  234. 			local width2, height2 = element_get_actual_size(desc_txt_h) 
  235. 			y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height 
  236. 			vint_set_property(h, "anchor", x, y ) 
  237. 			prev_height = prev_height + height1 + height2 
  238. 			 
  239. 			--store cloned grps in table to be destroyed 
  240. 			Desc_cloned_grps[i] = h 
  241. 	 
  242. 			--Show grp 
  243. 			vint_set_property(h, "visible", true) 
  244. 			 
  245. 			--Store off height and y of last group to align button hints 
  246. 			final_x = x + desc_move_grp_x - 11 
  247. 			final_y = ( (i - 1) * DESC_GRP_SPACING ) + prev_height + desc_move_grp_y + DESC_GRP_SPACING + 3 
  248. 			 
  249. 		end 
  250. 		 
  251. 		--scale if nessesary 
  252. 		local max_desc_height = 400 
  253. 		local scale_grp_h = vint_object_find("scale_grp", 0, Reward_granted_doc) 
  254. 		local scale_amount = 1 
  255. 		if prev_height > max_desc_height then 
  256. 			scale_amount = max_desc_height/prev_height 
  257. 			vint_set_property(scale_grp_h, "scale", scale_amount, scale_amount) 
  258. 		else 
  259. 			vint_set_property(scale_grp_h, "scale", 1,1) 
  260. 		end 
  261. 		 
  262. 		vint_set_property(align_grp_h, "anchor", 0, -(((prev_height * scale_amount)/2) - 37)) 
  263. 		 
  264. 		 
  265. 		 
  266. 	--use simple upgrade text box if element is -1 
  267. 	else 
  268. 		vint_set_property(desc_grp_h, "visible", false) 
  269. 		vint_set_property(description_h, "text_tag", item_desc) 
  270. 		vint_set_property(description_h, "visible", true) 
  271. 		local x, y = vint_get_property(description_h, "anchor") 
  272. 		local w, h = element_get_actual_size(description_h) 
  273. 		final_x = x 
  274. 		final_y = y + h + 41 
  275. 		 
  276. 		local scale_grp_h = vint_object_find("scale_grp", 0, Reward_granted_doc) 
  277. 		vint_set_property(scale_grp_h, "scale", 1,1) 
  278. 		 
  279. 		vint_set_property(align_grp_h, "anchor", 0, 0) 
  280.  
  281. 	end 
  282.  
  283. 	 
  284. 	 
  285. 	--align button hints 
  286. 	local button_tips_h = vint_object_find("button_tips", 0, Reward_granted_doc) 
  287. 	vint_set_property(button_tips_h, "anchor", final_x + 13, final_y) 
  288. 	 
  289. 	--Background anim in only on first playback... 
  290. 	if Rewards_current_display == 0 then 
  291. 		local anim_h = vint_object_find("background_anim_in", 0, Reward_granted_doc) 
  292. 		lua_play_anim(anim_h) 
  293. 	end 
  294. 	 
  295. 	--Play animation 
  296. 	local anim_h = vint_object_find("animate_in", 0, Reward_granted_doc) 
  297. 	vint_apply_start_values(anim_h) 
  298. 	lua_play_anim(anim_h) 
  299. 	 
  300. 	anim_h = vint_object_find("circles", 0, Reward_granted_doc) 
  301. 	vint_apply_start_values(anim_h) 
  302. 	lua_play_anim(anim_h) 
  303.  
  304. 	--Play Fleur outline animation... 
  305. 	for index = 1, 7 do 
  306. 		Fluer_outline_objects[index]:set_alpha(0) 
  307. 		Fluer_outline_anims[index]:play(index * .125) 
  308. 	end 
  309. 	 
  310. 	--Play Audio 
  311. 	ui_audio_post_event("UI_Reward_Bonus") 
  312. 	ui_audio_post_event("UI_Reward_Loop") 
  313. 	 
  314. 	Rewards_current_display = Rewards_current_display + 1	 
  315. end 
  316.  
  317. -- Gets called when the screen starts  
  318. -- or when the callback from when the previous screen fades out 
  319. function reward_screen_fade_cb() 
  320. 	--Determine if there are rewards left to display... 
  321. 	if Rewards_current_display == Rewards_count then 
  322. 		--No more rewards... 
  323. 		ui_audio_post_event("UI_Reward_Loop_Stop") 
  324. 		 
  325. 		--Hide this doc... 
  326. 		local safe_frame_h = vint_object_find("safe_frame", 0, Reward_granted_doc) 
  327. 		vint_set_property(safe_frame_h, "visible", false) 
  328. 		 
  329. 		--unload old peg if loaded... 
  330. 		if Peg_image_name ~= -1 then 
  331. 			game_peg_unload(Peg_image_name) 
  332. 			Peg_image_name = -1 
  333. 		end 
  334. 		 
  335.  
  336. 		 
  337. 		--lets call the callback function set by the parent document. 
  338. 		Reward_granted_end_cb() 
  339. 		 
  340. 		--Nothing else to do with inputs on this screen. unsubscribe them. 
  341. 		reward_granted_inputs_unsubscribe() 
  342. 		return 
  343. 	else 
  344. 		--Still more rewards.. 
  345. 		 
  346. 		--Query game for next reward... 
  347. 		vint_dataresponder_request("cmp_fetch_unlockable", "reward_granted_add", 0, Rewards_current_display) 
  348. 		 
  349. 		--Load next set of pegs... 
  350. 		local item_image = Reward.item_image 
  351.  
  352. 		--unload old peg if loaded... 
  353. 		if Peg_image_name ~= -1 then 
  354. 			game_peg_unload(Peg_image_name) 
  355. 			Peg_image_name = -1 
  356. 		end 
  357. 		 
  358. 		--Load peg.. and then wait for it to load... 
  359. 		game_peg_load_with_cb("reward_granted_next_cb", 1, item_image) 
  360. 		Peg_image_name = item_image 
  361. 	end 
  362. end 
  363.  
  364. --Gets called when a current screen is done displaying... 
  365. function screen_in_complete() 
  366. 	--Unlock controls 
  367. 	control_block(false) 
  368. end 
  369.  
  370. --Provides functionality to stack blocking of the control input... 
  371. -- 
  372. --@param	is_blocked		bool determines whether we want to block or unblock controls. 
  373. function control_block(is_blocked) 
  374. 	if is_blocked == true then 
  375. 		Control_blocked = Control_blocked + 1 
  376. 	else 
  377. 		Control_blocked = Control_blocked - 1 
  378. 	end 
  379. end 
  380.  
  381. --Function to check if the controls are blocked 
  382. -- 
  383. --@return	bool	True if the controls are blocked. 
  384. function is_control_blocked() 
  385. 	local ctrl_block = Control_blocked 
  386. 	if Control_blocked > 0 then 
  387. 		return true 
  388. 	else  
  389. 		return false 
  390. 	end 
  391. end 
  392.  
  393. --This is set by the parent document to be called later... 
  394. function set_reward_granted_end_cb(func) 
  395. 	Reward_granted_end_cb = func 
  396. end 
  397.  
  398. --Sets the amount of rewards that we should cycle through... 
  399. function reward_granted_set_reward_count(count) 
  400. 	Rewards_count = count 
  401. end 
  402.  
  403. ------------------------------------------------------------- 
  404. --	Populates the script from the dataresponder... 
  405. -- 
  406. -- @param	ignore_first_param 		Unused Parameter 
  407. -- @param	ignore_second_param		Unused Parameter 
  408. -- @param	item_name					Name of the item. 
  409. -- @param	item_image					This is the name of the image... also same name of VBM to stream from disc. 
  410. -- @param	item_desc					Description of the item... 
  411. -- 
  412. function reward_granted_add(ignore_first_param, ignore_second_param, item_name, item_image, item_desc, unlockable_id, is_silverlink) 
  413. 	 
  414. 	Reward = { 
  415. 		item_name = item_name, 
  416. 		item_image = item_image, 
  417. 		item_desc = item_desc, 
  418. 		unlockable_id = unlockable_id, 
  419. 		is_silverlink = is_silverlink, 
  420. 	} 
  421. end 
  422.  
  423. --call this once for each list item, and it will fill in the appropriate number of descriptions 
  424. function reward_granted_add_upgrades_descriptions(description, element) 
  425. 	local i = #Upgrades_descriptions + 1 
  426. 	Upgrades_descriptions[i] = {} 
  427. 	local t = Upgrades_descriptions[i] 
  428. 	t.description = description 
  429. 	t.element = element 
  430. end 
  431.  
  432. -- Mouse inputs 
  433. function reward_granted_mouse_click(event, target_handle) 
  434. 	if target_handle == Bg_image.handle then 
  435. 		reward_granted_button_press() 
  436. 	end 
  437. end 
  438.  
  439. function reward_granted_mouse_move(event, target_handle) 
  440. end