local COUNTDOWN_DISPLAY_1 = 3
local COUNTDOWN_DISPLAY_2 = 2
local COUNTDOWN_DISPLAY_3 = 1
local COUNTDOWN_DISPLAY_GO = 0
local COUNTDOWN_DISPLAY_DATA = {
[COUNTDOWN_DISPLAY_1] = { sfx = "UI_HUD_Countdown", txt = "3", header_anim = "header_in_anim"},
[COUNTDOWN_DISPLAY_2] = { sfx = "UI_HUD_Countdown", txt = "2"},
[COUNTDOWN_DISPLAY_3] = { sfx = "UI_HUD_Countdown", txt = "1"},
[COUNTDOWN_DISPLAY_GO] = { sfx = "UI_HUD_Countdown_End", txt = "COUNTDOWN_GO", header_anim = "header_out_anim"},
}
local Countdown_title = false --no countdown title by default...
local Countdown_anims_playing = {} --storage for all of our animations...
local Countdown_tier_times_grp_h
local Countdown_doc_h = -1
local Countdown_medal_listener = 0
--Init
function countdown_init()
Countdown_doc_h = vint_document_find("countdown")
--Hide Everything
local h = vint_object_find("header_txt")
vint_set_property(h, "alpha", 0)
local h = vint_object_find("number_txt")
vint_set_property(h, "alpha", 0)
--Hide tier times
Countdown_tier_times_grp_h = vint_object_find("tier_times_grp", 0, Countdown_doc_h)
vint_set_property(Countdown_tier_times_grp_h, "visible", false)
Countdown_medal_listener = vint_scriptevent_listen( "countdown_show_medals", "countdown_set_tier_times" )
Countdown_medal_listener = vint_scriptevent_listen( "countdown_show_medals_scores", "countdown_set_tier_scores" )
end
function countdown_cleanup()
vint_scriptevent_stop_listening( Countdown_medal_listener )
end
-------------------------------------------------------------------------------
-- Sets the countdown title
-- @param title_str String for title
--
function countdown_set_title(title_str)
local h = vint_object_find("header_txt")
vint_set_property(h, "text_tag", title_str)
Countdown_title = true
end
-------------------------------------------------------------------------------
-- Plays a number count...
-- @parem id COUNTDOWN_DISPLAY_1, COUNTDOWN_DISPLAY_2, COUNTDOWN_DISPLAY_3, COUNTDOWN_DISPLAY_GO
function countdown_display(id)
local data = COUNTDOWN_DISPLAY_DATA[id]
--Set text tag of countdown "#" or "GO!"
local number_txt_h = vint_object_find("number_txt")
vint_set_property(number_txt_h, "text_tag", data.txt)
--always play number in animation...
local anim_h = vint_object_find("number_anim")
lua_play_anim(anim_h)
Countdown_anims_playing[1] = anim_h
--play custom anim if needed... (fade in or out of title)
if Countdown_title == true then
if data.header_anim ~= nil then
local anim_h = vint_object_find(data.header_anim)
lua_play_anim(anim_h)
Countdown_anims_playing[2] = anim_h
end
end
--play sound...
if data.sfx ~= nil then
game_UI_audio_play(data.sfx)
end
end
-------------------------------------------------------------------------------
-- Pauses animations and hides the screen...
--
function countdown_pause()
local h = vint_object_find("countdown_grp")
vint_set_property(h, "visible", false)
countdown_pause_anims(true)
end
-------------------------------------------------------------------------------
-- Unpauses animations and shows the screen... (called from c++)
--
function countdown_unpause()
local h = vint_object_find("countdown_grp")
vint_set_property(h, "visible", true)
countdown_pause_anims(false)
end
-------------------------------------------------------------------------------
-- Pauses or unpaused all animations...
-- @param is_paused True if you want to pause, false if you do not...
--
function countdown_pause_anims(is_paused)
for i=1, #Countdown_anims_playing do
vint_set_property(Countdown_anims_playing[i], "is_paused", is_paused)
end
end
-------------------------------------------------------------------------------
-- Function countdown_set_tier_times()
--
-- Displays tier (gold, silver, bronze) times for time activity before the
-- 3,2,1 countdown
--
-- @param gold_time -- Par time for gold
-- @param silver_time -- Par time for silver
-- @param bronze_time -- Par time for bronze
--
-------------------------------------------------------------------------------
function countdown_set_tier_times(gold_time, silver_time, bronze_time)
countdown_set_tier(gold_time, silver_time, bronze_time, true)
end
-------------------------------------------------------------------------------
-- Function countdown_set_tier_scores()
--
-- Displays tier (gold, silver, bronze) scores for activity before the
-- 3,2,1 countdown
--
-- @param gold_score -- Min score for gold
-- @param silver_score -- Min score for silver
-- @param bronze_score -- Min score for bronze
--
-------------------------------------------------------------------------------
function countdown_set_tier_scores(gold_score, silver_score, bronze_score)
countdown_set_tier(gold_score, silver_score, bronze_score, false)
end
-------------------------------------------------------------------------------
-- Function countdown_set_tier_times()
--
-- Generic function for displaying tiers (gold, silver, bronze) times or scores for activity before the
-- 3,2,1 countdown
--
-------------------------------------------------------------------------------
function countdown_set_tier(gold_time, silver_time, bronze_time, shouldFormatTime)
-- Find time text
local gold_txt_h = vint_object_find("gold_txt", 0, Countdown_doc_h)
local silver_txt_h = vint_object_find("silver_txt", 0, Countdown_doc_h)
local bronze_txt_h = vint_object_find("bronze_txt", 0, Countdown_doc_h)
-- Set times
-- GOLD
local body
local insert_values
if shouldFormatTime == true then
insert_values = { [0] = "[format][color:#B08522]", [1] = format_time(gold_time, false, false, false, true)}
else
insert_values = { [0] = "[format][color:#B08522]", [1] = gold_time}
end
body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_GOLD", insert_values)
vint_set_property(gold_txt_h, "text_tag", body)
-- SILVER
if shouldFormatTime == true then
insert_values = { [0] = "[format][color:#909192]", [1] = format_time(silver_time, false, false, false, true)}
else
insert_values = { [0] = "[format][color:#909192]", [1] = "" .. silver_time}
end
body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_SILVER", insert_values)
vint_set_property(silver_txt_h, "text_tag", body)
-- BRONZE
if shouldFormatTime == true then
insert_values = { [0] = "[format][color:#9E6F54]", [1] = format_time(bronze_time, false, false, false, true)}
else
insert_values = { [0] = "[format][color:#9E6F54]", [1] = "" .. bronze_time}
end
body = vint_insert_values_in_string("ACTIVITY_TIER_TIME_BRONZE", insert_values)
vint_set_property(bronze_txt_h, "text_tag", body)
vint_set_property(Countdown_tier_times_grp_h, "visible", true)
-- Find animation
local tier_times_anim_h = vint_object_find("tier_times_anim", 0, Countdown_doc_h)
local end_event_twn_h = vint_object_find("end_event_twn", tier_times_anim_h)
vint_set_property(end_event_twn_h, "end_event", "countdown_hide_tier_times")
vint_apply_start_values(tier_times_anim_h)
-- Play animation
lua_play_anim(tier_times_anim_h, 0)
-- Start audio for this animation
ui_audio_post_event("UI_Activity_Medal_Tiers")
end
-------------------------------------------------------------------------------
-- Callback for tier times anim. Hides tier times group.
--
function countdown_hide_tier_times()
vint_set_property(Countdown_tier_times_grp_h, "visible", false)
end
function test_countdown_1()
countdown_display(COUNTDOWN_DISPLAY_1)
end
function test_countdown_2()
countdown_display(COUNTDOWN_DISPLAY_2)
end
function test_countdown_3()
countdown_display(COUNTDOWN_DISPLAY_3)
end
function test_countdown_4()
countdown_display(COUNTDOWN_DISPLAY_GO)
end
function test_countdown_title()
countdown_set_title("WAVE 15")
end