./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 Bg_mouse_input_tracker 
  16. local Bg_image 
  17.  
  18. --Initialize 
  19. function reward_granted_init() 
  20. 	Reward_granted_doc = vint_document_find("reward_granted") 
  21. 	--Setup fleur Outline Anims 
  22. 	--Clone fleur outline animation and object. Then Retarget and store handles for later... 
  23. 	local fleur_outline = Vdo_anim_object:new("fleur_outline", 0, Reward_granted_doc) 
  24. 	local fleur_outline_anim = Vdo_anim_object:new("fleur_outline_zoom_anim", 0, Reward_granted_doc) 
  25. 	fleur_outline:set_alpha(0) 
  26. 	for index = 1, 7 do 
  27. 		local fleur_outline_clone = Vdo_base_object:clone(fleur_outline.handle) 
  28. 		local anim = Vdo_anim_object:clone(fleur_outline_anim.handle) 
  29. 		anim:set_target_handle(fleur_outline_clone.handle) 
  30. 		fleur_outline_clone:set_alpha(0) 
  31. 		anim:stop() 
  32. 		Fluer_outline_objects[index] = fleur_outline_clone 
  33. 		Fluer_outline_anims[index] = anim  
  34. 	end 
  35. 	 
  36. 	--Show Button Tips 
  37. 	local hint_data = { 
  38. 		{CTRL_MENU_BUTTON_A, "COMPLETION_CONTINUE"}, 
  39. 	} 
  40. 	local button_tips = Vdo_hint_bar:new("button_tips") 
  41. 	button_tips:set_hints(hint_data) 
  42. 	button_tips:pulse(1) 
  43. 	 
  44. 	--Hide the stuff until we are ready... 
  45. 	local h = vint_object_find("big_container", 0, Reward_granted_doc) 
  46. 	vint_set_property(h, "alpha", 0) 
  47. 	local background_grp_h = vint_object_find("respect_background_grp") 
  48. 	vint_set_property(background_grp_h, "alpha", 0) 
  49.  
  50. 	--setup callbacks for screen_fade_out anims 
  51. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  52. 	local fade_out_twn_h = vint_object_find("screen_fade_out_twn", 0, Reward_granted_doc) 
  53. 	vint_set_property(fade_out_twn_h, "end_event", "reward_screen_fade_cb") 
  54. 	 
  55. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  56. 	local button_tip_twn_h = vint_object_find("button_tip_twn", 0, Reward_granted_doc) 
  57. 	vint_set_property(button_tip_twn_h, "end_event", "screen_in_complete") 
  58. end 
  59.  
  60. --Close 
  61. function reward_granted_cleanup() 
  62. 	--unload old peg if loaded... 
  63. 	local peg_name = Peg_image_name 
  64. 	if Peg_image_name ~= -1 then 
  65. 		game_peg_unload("bms_pause_menu") 
  66. 		game_peg_unload(Peg_image_name) 
  67. 		Peg_image_name = -1 
  68. 	end 
  69. 	 
  70. 	reward_granted_inputs_unsubscribe() 
  71. end 
  72.  
  73. function noop() 
  74. 	-- Does nothing 
  75. end 
  76.  
  77. -------------------------------------------------------------------------------------------------------------- 
  78. -- Unsubscribe from inputs... 
  79. -- 
  80. function reward_granted_inputs_unsubscribe() 
  81. 	--Unsubscribe... 
  82. 	if Reward_granted_input_tracker ~= nil then 
  83. 		Reward_granted_input_tracker:subscribe(false) 
  84. 	end 
  85. 	 
  86. 	if Bg_mouse_input_tracker ~= nil then 
  87. 		Bg_mouse_input_tracker:subscribe(false) 
  88. 	end 
  89. end 
  90.  
  91. --Starts the reward sequence... This is designed to be called by its parent completion document or directly from c++... 
  92. function reward_granted_start() 
  93. 	local h = vint_object_find("safe_frame",0, Reward_granted_doc) 
  94. 	vint_set_property(h, "visible", true) 
  95.  
  96. 	Reward_granted_input_tracker = Vdo_input_tracker:new() 
  97. 	Reward_granted_input_tracker:add_input("nav_left", "noop", 100) 
  98. 	Reward_granted_input_tracker:add_input("nav_right", "noop", 100) 
  99. 	Reward_granted_input_tracker:add_input("nav_up", "noop", 100) 
  100. 	Reward_granted_input_tracker:add_input("nav_down", "noop", 100) 
  101. 	Reward_granted_input_tracker:add_input("back", "noop", 100) 
  102. 	Reward_granted_input_tracker:add_input("map", "noop", 100) 
  103. 	Reward_granted_input_tracker:add_input("select", "reward_granted_button_press", 100) 
  104. 	Reward_granted_input_tracker:add_input("pause", "reward_granted_button_press", 100) 
  105. 	Reward_granted_input_tracker:subscribe(true) 
  106. 	 
  107. 	Bg_image = Vdo_base_object:new("respect_background_bmp", 0, Reward_granted_doc) 
  108. 	 
  109. 	-- Mouse input 
  110. 	if game_get_platform() == "PC" then		 
  111. 		Bg_mouse_input_tracker = Vdo_input_tracker:new() 
  112. 		Bg_mouse_input_tracker:add_mouse_input("mouse_move", "reward_granted_mouse_move", 0, Bg_image.handle) 
  113. 		Bg_mouse_input_tracker:add_mouse_input("mouse_click", "reward_granted_mouse_click", 0, Bg_image.handle) 
  114. 		Bg_mouse_input_tracker:subscribe(true) 
  115. 	end 
  116. 	 
  117. 	--Show Screen 
  118. 	reward_screen_fade_cb() 
  119. 	 
  120. 	--Block controls until we are complete... 
  121. 	control_block(true) 
  122. end 
  123.  
  124. -- Callback when the a button is pressed. 
  125. function reward_granted_button_press() 
  126. 	if is_control_blocked() == false then 
  127. 		game_UI_audio_play("UI_Main_Menu_Select") 
  128. 		reward_granted_next_screen() 
  129. 	end 
  130. end 
  131.  
  132. --Starts the next screen... 
  133. function reward_granted_next_screen() 
  134. 	--fade out current screen, a callback will attempt to bring in the next... reward_screen_fade_cb() 
  135. 	local fade_out_anim_h = vint_object_find("fade_out_anim", 0, Reward_granted_doc) 
  136. 	lua_play_anim(fade_out_anim_h) 
  137. 	 
  138. 	--Block controls until we are complete... 
  139. 	control_block(true) 
  140. end 
  141.  
  142. --This is the callback after the VBM has loaded. 
  143. function reward_granted_next_cb() 
  144. 	--Plays back the screen... 
  145. 	local item_image = Reward.item_image 
  146. 	local item_name = Reward.item_name 
  147. 	local item_desc = Reward.item_desc 
  148.  
  149. 	--replace image with queued up image... 
  150. 	local unlockable_bmp = vint_object_find("unlockable_bmp", 0, Reward_granted_doc) 
  151. 	vint_set_property(unlockable_bmp, "image", item_image) 
  152. 	 
  153. 	--Set title 
  154. 	local title_h = vint_object_find("reward_name", 0, Reward_granted_doc) 
  155. 	vint_set_property(title_h, "text_tag", item_name) 
  156. 	 
  157. 	--Set Name 
  158. 	local description_h = vint_object_find("reward_description", 0, Reward_granted_doc) 
  159. 	vint_set_property(description_h, "text_tag", item_desc) 
  160.  
  161. 	local desc_text_h = vint_object_find("reward_description", 0, Reward_granted_doc) 
  162. 	local x, y = vint_get_property(desc_text_h, "anchor") 
  163. 	local w, h = element_get_actual_size(desc_text_h) 
  164. 	 
  165. 	local button_tips_h = vint_object_find("button_tips", 0, Reward_granted_doc) 
  166. 	vint_set_property(button_tips_h, "anchor", x + 13, y + h + 30) 
  167. 	 
  168. 	--Background anim in only on first playback... 
  169. 	if Rewards_current_display == 0 then 
  170. 		local anim_h = vint_object_find("background_anim_in", 0, Reward_granted_doc) 
  171. 		lua_play_anim(anim_h) 
  172. 	end 
  173. 	 
  174. 	--Play animation 
  175. 	local anim_h = vint_object_find("animate_in", 0, Reward_granted_doc) 
  176. 	lua_play_anim(anim_h) 
  177. 	 
  178. 	anim_h = vint_object_find("circles", 0, Reward_granted_doc) 
  179. 	lua_play_anim(anim_h) 
  180.  
  181. 	--Play Fleur outline animation... 
  182. 	for index = 1, 7 do 
  183. 		Fluer_outline_objects[index]:set_alpha(0) 
  184. 		Fluer_outline_anims[index]:play(index * .125) 
  185. 	end 
  186. 	 
  187. 	--Play Audio 
  188. 	game_UI_audio_play("UI_Unlock_Reward") 
  189. 	 
  190. 	Rewards_current_display = Rewards_current_display + 1	 
  191. end 
  192.  
  193. -- Gets called when the screen starts  
  194. -- or when the callback from when the previous screen fades out 
  195. function reward_screen_fade_cb() 
  196. 	--Determine if there are rewards left to display... 
  197. 	if Rewards_current_display == Rewards_count then 
  198. 		--No more rewards... 
  199. 		 
  200. 		--Hide this doc... 
  201. 		local safe_frame_h = vint_object_find("safe_frame", 0, Reward_granted_doc) 
  202. 		vint_set_property(safe_frame_h, "visible", false) 
  203. 		 
  204. 		--unload old peg if loaded... 
  205. 		if Peg_image_name ~= -1 then 
  206. 			game_peg_unload(Peg_image_name) 
  207. 			Peg_image_name = -1 
  208. 		end 
  209. 		 
  210.  
  211. 		 
  212. 		--lets call the callback function set by the parent document. 
  213. 		Reward_granted_end_cb() 
  214. 		 
  215. 		--Nothing else to do with inputs on this screen. unsubscribe them. 
  216. 		reward_granted_inputs_unsubscribe() 
  217. 		return 
  218. 	else 
  219. 		--Still more rewards.. 
  220. 		 
  221. 		--Query game for next reward... 
  222. 		vint_dataresponder_request("cmp_fetch_unlockable", "reward_granted_add", 0, Rewards_current_display) 
  223. 		 
  224. 		--Load next set of pegs... 
  225. 		local item_image = Reward.item_image 
  226.  
  227. 		--unload old peg if loaded... 
  228. 		if Peg_image_name ~= -1 then 
  229. 			game_peg_unload(Peg_image_name) 
  230. 			Peg_image_name = -1 
  231. 		end 
  232. 		 
  233. 		--Load peg.. and then wait for it to load... 
  234. 		game_peg_load_with_cb("reward_granted_next_cb", 1, item_image) 
  235. 		Peg_image_name = item_image 
  236. 	end 
  237. end 
  238.  
  239. --Gets called when a current screen is done displaying... 
  240. function screen_in_complete() 
  241. 	--Unlock controls 
  242. 	control_block(false) 
  243. end 
  244.  
  245. --Provides functionality to stack blocking of the control input... 
  246. -- 
  247. --@param	is_blocked		bool determines whether we want to block or unblock controls. 
  248. function control_block(is_blocked) 
  249. 	if is_blocked == true then 
  250. 		Control_blocked = Control_blocked + 1 
  251. 	else 
  252. 		Control_blocked = Control_blocked - 1 
  253. 	end 
  254. end 
  255.  
  256. --Function to check if the controls are blocked 
  257. -- 
  258. --@return	bool	True if the controls are blocked. 
  259. function is_control_blocked() 
  260. 	local ctrl_block = Control_blocked 
  261. 	if Control_blocked > 0 then 
  262. 		return true 
  263. 	else  
  264. 		return false 
  265. 	end 
  266. end 
  267.  
  268. --This is set by the parent document to be called later... 
  269. function set_reward_granted_end_cb(func) 
  270. 	Reward_granted_end_cb = func 
  271. end 
  272.  
  273. --Sets the amount of rewards that we should cycle through... 
  274. function reward_granted_set_reward_count(count) 
  275. 	Rewards_count = count 
  276. end 
  277.  
  278. ------------------------------------------------------------- 
  279. --	Populates the script from the dataresponder... 
  280. -- 
  281. -- @param	ignore_first_param 		Unused Parameter 
  282. -- @param	ignore_second_param		Unused Parameter 
  283. -- @param	item_name					Name of the item. 
  284. -- @param	item_image					This is the name of the image... also same name of VBM to stream from disc. 
  285. -- @param	item_desc					Description of the item... 
  286. -- 
  287. function reward_granted_add(ignore_first_param, ignore_second_param, item_name, item_image, item_desc) 
  288. 	Reward = { 
  289. 		item_name = item_name, 
  290. 		item_image = item_image, 
  291. 		item_desc = item_desc, 
  292. 	} 
  293. end 
  294.  
  295. -- Mouse inputs 
  296. function reward_granted_mouse_click(event, target_handle) 
  297. 	if target_handle == Bg_image.handle then 
  298. 		reward_granted_button_press() 
  299. 	end 
  300. end 
  301.  
  302. function reward_granted_mouse_move(event, target_handle) 
  303. end