./countdown.lua

  1. local COUNTDOWN_DISPLAY_1 = 3 
  2. local COUNTDOWN_DISPLAY_2 = 2 
  3. local COUNTDOWN_DISPLAY_3 = 1 
  4. local COUNTDOWN_DISPLAY_GO = 0 
  5.  
  6. local COUNTDOWN_DISPLAY_DATA = { 
  7. 	[COUNTDOWN_DISPLAY_1] = { sfx = "UI_HUD_Countdown", txt = "3", header_anim = "header_in_anim"}, 
  8. 	[COUNTDOWN_DISPLAY_2] = { sfx = "UI_HUD_Countdown", txt = "2"}, 
  9. 	[COUNTDOWN_DISPLAY_3] = { sfx = "UI_HUD_Countdown", txt = "1"}, 
  10. 	[COUNTDOWN_DISPLAY_GO] = { sfx = "UI_HUD_Countdown_End", txt = "COUNTDOWN_GO", header_anim = "header_out_anim"}, 
  11. } 
  12.  
  13. local Countdown_title = false		--no countdown title by default... 
  14. local Countdown_anims_playing = {}	--storage for all of our animations... 
  15.  
  16. local Countdown_tier_times_grp_h 
  17. local Countdown_doc_h = -1 
  18.  
  19. local Countdown_medal_listener = 0 
  20.  
  21. --Init 
  22. function countdown_init() 
  23.  
  24. 	Countdown_doc_h = vint_document_find("countdown") 
  25.  
  26. 	--Hide Everything 
  27. 	local h = vint_object_find("header_txt") 
  28. 	vint_set_property(h, "alpha", 0) 
  29. 	 
  30. 	local h = vint_object_find("number_txt") 
  31. 	vint_set_property(h, "alpha", 0) 
  32. 	 
  33. 	--Hide tier times 
  34. 	Countdown_tier_times_grp_h = vint_object_find("tier_times_grp", 0, Countdown_doc_h) 
  35. 	vint_set_property(Countdown_tier_times_grp_h, "visible", false) 
  36. 	 
  37. 	Countdown_medal_listener = vint_scriptevent_listen( "countdown_show_medals", "countdown_set_tier_times" ) 
  38. 	Countdown_medal_listener = vint_scriptevent_listen( "countdown_show_medals_scores", "countdown_set_tier_scores" ) 
  39. end 
  40.  
  41. function countdown_cleanup() 
  42. 	vint_scriptevent_stop_listening( Countdown_medal_listener ) 
  43. end 
  44.  
  45. ------------------------------------------------------------------------------- 
  46. -- Sets the countdown title 
  47. -- @param	title_str	String for title 
  48. -- 
  49. function countdown_set_title(title_str) 
  50. 	local h = vint_object_find("header_txt") 
  51. 	vint_set_property(h, "text_tag", title_str) 
  52. 	Countdown_title = true 
  53. end 
  54.  
  55. ------------------------------------------------------------------------------- 
  56. -- Plays a number count... 
  57. -- @parem id		COUNTDOWN_DISPLAY_1, COUNTDOWN_DISPLAY_2, COUNTDOWN_DISPLAY_3, COUNTDOWN_DISPLAY_GO 
  58. function countdown_display(id) 
  59.  
  60. 	local data = COUNTDOWN_DISPLAY_DATA[id] 
  61. 	 
  62. 	--Set text tag of countdown  "#" or "GO!" 
  63. 	local number_txt_h = vint_object_find("number_txt") 
  64. 	vint_set_property(number_txt_h, "text_tag", data.txt) 
  65. 	 
  66. 	--always play number in animation... 
  67. 	local anim_h = vint_object_find("number_anim") 
  68. 	lua_play_anim(anim_h) 
  69. 	 
  70. 	Countdown_anims_playing[1] = anim_h 
  71. 	 
  72. 	--play custom anim if needed... (fade in or out of title) 
  73. 	if Countdown_title == true then 
  74. 		if data.header_anim ~= nil then 
  75. 			local anim_h = vint_object_find(data.header_anim) 
  76. 			lua_play_anim(anim_h) 
  77. 			Countdown_anims_playing[2] = anim_h 
  78. 		end 
  79. 	end 
  80. 	 
  81. 	--play sound... 
  82. 	if data.sfx ~= nil then 
  83. 		game_UI_audio_play(data.sfx) 
  84. 	end 
  85. end 
  86.  
  87. ------------------------------------------------------------------------------- 
  88. -- Pauses animations and hides the screen... 
  89. -- 
  90. function countdown_pause() 
  91. 	local h = vint_object_find("countdown_grp") 
  92. 	vint_set_property(h, "visible", false) 
  93. 	countdown_pause_anims(true) 
  94. end 
  95.  
  96.  
  97. ------------------------------------------------------------------------------- 
  98. -- Unpauses animations and shows the screen... (called from c++) 
  99. -- 
  100. function countdown_unpause() 
  101. 	local h = vint_object_find("countdown_grp") 
  102. 	vint_set_property(h, "visible", true) 
  103. 	countdown_pause_anims(false) 
  104. end 
  105.  
  106. ------------------------------------------------------------------------------- 
  107. -- Pauses or unpaused all animations... 
  108. -- @param	is_paused 	True if you want to pause, false if you do not... 
  109. -- 
  110. function countdown_pause_anims(is_paused) 
  111. 	for i=1, #Countdown_anims_playing do 
  112. 		vint_set_property(Countdown_anims_playing[i], "is_paused", is_paused) 
  113. 	end 
  114. end 
  115.  
  116.  
  117. ------------------------------------------------------------------------------- 
  118. -- Function countdown_set_tier_times() 
  119. -- 
  120. -- Displays tier (gold, silver, bronze) times for time activity before the 
  121. -- 3,2,1 countdown 
  122. -- 
  123. -- @param gold_time			-- Par time for gold 
  124. -- @param silver_time		-- Par time for silver 
  125. -- @param bronze_time		-- Par time for bronze 
  126. -- 
  127. ------------------------------------------------------------------------------- 
  128. function countdown_set_tier_times(gold_time, silver_time, bronze_time) 
  129. 	countdown_set_tier(gold_time, silver_time, bronze_time, true) 
  130. end 
  131.  
  132. ------------------------------------------------------------------------------- 
  133. -- Function countdown_set_tier_scores() 
  134. -- 
  135. -- Displays tier (gold, silver, bronze) scores for activity before the 
  136. -- 3,2,1 countdown 
  137. -- 
  138. -- @param gold_score		-- Min score for gold 
  139. -- @param silver_score		-- Min score for silver 
  140. -- @param bronze_score		-- Min score for bronze 
  141. -- 
  142. ------------------------------------------------------------------------------- 
  143. function countdown_set_tier_scores(gold_score, silver_score, bronze_score) 
  144. 	countdown_set_tier(gold_score, silver_score, bronze_score, false) 
  145. end 
  146.  
  147. ------------------------------------------------------------------------------- 
  148. -- Function countdown_set_tier_times() 
  149. -- 
  150. -- Generic function for displaying tiers (gold, silver, bronze) times or scores for activity before the 
  151. -- 3,2,1 countdown 
  152. -- 
  153. ------------------------------------------------------------------------------- 
  154. function countdown_set_tier(gold_time, silver_time, bronze_time, shouldFormatTime) 
  155. 	 
  156. 	-- Find time text 
  157. 	local gold_txt_h = vint_object_find("gold_txt", 0, Countdown_doc_h) 
  158. 	local silver_txt_h = vint_object_find("silver_txt", 0, Countdown_doc_h) 
  159. 	local bronze_txt_h = vint_object_find("bronze_txt", 0, Countdown_doc_h) 
  160. 		 
  161. 	-- Set times 
  162. 	-- GOLD 
  163. 	local body 
  164. 	local insert_values 
  165. 	if shouldFormatTime == true then 
  166. 		insert_values = { [0] = "[format][color:#B08522]", [1] = format_time(gold_time, false, false, false, true)} 
  167. 	else 
  168. 		insert_values = { [0] = "[format][color:#B08522]", [1] = gold_time} 
  169. 	end 
  170. 	body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_GOLD", insert_values) 
  171. 	vint_set_property(gold_txt_h, "text_tag", body) 
  172. 	 
  173. 	-- SILVER 
  174. 	if shouldFormatTime == true then 
  175. 		insert_values = { [0] = "[format][color:#909192]",  [1] = format_time(silver_time, false, false, false, true)} 
  176. 	else 
  177. 		insert_values = { [0] = "[format][color:#909192]", [1] = "" .. silver_time} 
  178. 	end 
  179. 	body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_SILVER", insert_values) 
  180. 	vint_set_property(silver_txt_h, "text_tag", body) 
  181. 		 
  182. 	-- BRONZE 
  183. 	if shouldFormatTime == true then 
  184. 		insert_values = { [0] = "[format][color:#9E6F54]",  [1] = format_time(bronze_time, false, false, false, true)} 
  185. 	else 
  186. 		insert_values = { [0] = "[format][color:#9E6F54]", [1] = "" .. bronze_time} 
  187. 	end 
  188. 	body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_BRONZE", insert_values) 
  189. 	vint_set_property(bronze_txt_h, "text_tag", body) 
  190. 	 
  191. 	vint_set_property(Countdown_tier_times_grp_h, "visible", true) 
  192. 	 
  193. 	-- Find animation 
  194. 	local tier_times_anim_h = vint_object_find("tier_times_anim", 0, Countdown_doc_h) 
  195. 	local end_event_twn_h = vint_object_find("end_event_twn", tier_times_anim_h) 
  196. 	 
  197. 	vint_set_property(end_event_twn_h, "end_event", "countdown_hide_tier_times") 
  198. 	 
  199. 	vint_apply_start_values(tier_times_anim_h) 
  200. 	 
  201. 	-- Play animation 
  202. 	lua_play_anim(tier_times_anim_h, 0) 
  203. 	 
  204. 	-- Start audio for this animation 
  205. 	ui_audio_post_event("UI_Activity_Medal_Tiers") 
  206. end 
  207.  
  208.  
  209. ------------------------------------------------------------------------------- 
  210. -- Callback for tier times anim.  Hides tier times group. 
  211. -- 
  212. function countdown_hide_tier_times() 
  213. 	vint_set_property(Countdown_tier_times_grp_h, "visible", false) 
  214. end 
  215.  
  216.  
  217.  
  218. function test_countdown_1() 
  219. 	countdown_display(COUNTDOWN_DISPLAY_1) 
  220. end 
  221.  
  222. function test_countdown_2() 
  223. 	countdown_display(COUNTDOWN_DISPLAY_2) 
  224. end 
  225.  
  226. function test_countdown_3() 
  227. 	countdown_display(COUNTDOWN_DISPLAY_3) 
  228. end 
  229.  
  230. function test_countdown_4() 
  231. 	countdown_display(COUNTDOWN_DISPLAY_GO) 
  232. end 
  233.  
  234. function test_countdown_title() 
  235. 	countdown_set_title("WAVE 15") 
  236. end