local TUTORIAL_HINT_PADDING = 5
local TUTORIAL_HINT_SPACING = -1
local TUTORIAL_HEADER_PADDING = 14
Tutorial = {}
Tutorial_content = {}
Outline_anims = {}
Max_outlines = 5
Tutorial_first_time = true
Tutorial_show_scanimate = true
Tutorial_frame_values = -1
Tutorial_current_window = 1 --id to control the current content frame...
local Input_tracker
function tutorial_init()
--Find Objects
Tutorial.window_h = vint_object_find("tutorial") --Main window
Tutorial.bg_body_h = vint_object_find("bg_body") --Body Element...
Tutorial.bg_top = vint_object_find("bg_top") --background for title bar
Tutorial.content_clip_h = vint_object_find("content_clip") --background for title bar
local hint_data = {
{CTRL_MENU_BUTTON_BACK, "TUT_DISMISS"},
}
--Content Elements
local h = vint_object_find("content_1")
Tutorial_content[1] = {
h = h,
hint_bar = Vdo_hint_bar:new("tutorial_hint", h),
header_text_h = vint_object_find("tutorial_header_text", h),
body_text_h = vint_object_find("tutorial_body_text", h),
illustration_h = vint_object_find("illustration", h),
}
Tutorial_content[1].hint_bar:set_hints(hint_data)
Tutorial_content[1].hint_bar:set_visible(false)
Tutorial_content[1].hint_bar:enable_text_shadow(true)
local h = vint_object_find("content_2")
Tutorial_content[2] = {
h = h,
hint_bar = Vdo_hint_bar:new("tutorial_hint", h),
header_text_h = vint_object_find("tutorial_header_text", h),
body_text_h = vint_object_find("tutorial_body_text", h),
illustration_h = vint_object_find("illustration", h),
}
Tutorial_content[2].hint_bar:set_hints(hint_data)
Tutorial_content[2].hint_bar:set_visible(false)
Tutorial_content[2].hint_bar:enable_text_shadow(true)
--Initialize Frame size
Tutorial.start_x, Tutorial.start_y = vint_get_property(Tutorial.window_h, "anchor")
Tutorial.scaler = vint_get_property(Tutorial.window_h, "scale")
Tutorial.scaler = 1 * Tutorial.scaler
Tutorial.body_text_x, Tutorial.body_text_y = vint_get_property(Tutorial_content[1].body_text_h, "anchor")
--Fade out tween callback...
local anim_h = vint_object_find("fade_out_anim")
local twn_h = vint_object_find("tutorial_alpha_twn", anim_h)
vint_set_property(twn_h, "end_event", "tutorial_wipe_old_values")
Input_tracker = Vdo_input_tracker:new()
Input_tracker:add_input("map", "tutorial_advance", 500)
Input_tracker:subscribe(false)
--Hide frame
vint_set_property(Tutorial.window_h, "alpha", 0)
end
--Standard Cleanup function...
function tutorial_cleanup()
Input_tracker:subscribe(false)
end
-- Opens the tutorisl
function tutorial_open()
--Populate and show the tutorial window
vint_dataresponder_request("tutorial_responder", "tutorial_update", 0, 1)
end
-- Advances the tutorial... This is called by c when we want to show the next tutorial in sequence...
function tutorial_advance() -- called from c when it is time to request more data
-- Find out if there are any more tutorials
vint_dataresponder_request("tutorial_responder", "tutorial_update", 0)
end
-- Closes the tutorial... This is called by c when the game wants the tutorial to die.
function tutorial_close(force)
Input_tracker:subscribe(false)
--Stop Fadein
local fade_in_anim_h = vint_object_find("fade_in_anim")
vint_set_property(fade_in_anim_h, "is_paused", true)
Tutorial_first_time = true
Tutorial_show_scanimate = true
if force == true then
tutorial_set_hud_help_closing(false)
-- Stop fade out in case its playing
local fade_out_anim_h = vint_object_find("fade_out_anim")
vint_set_property(fade_out_anim_h, "is_paused", true)
vint_set_property(Tutorial.window_h, "alpha", 0)
else
-- Reset the fade out's start value
local alpha = vint_get_property(Tutorial.window_h, "alpha")
-- If the window's already at 0, then we don't need to fade out
if alpha > 0 then
tutorial_set_hud_help_closing(true)
local fade_out_anim_h = vint_object_find("fade_out_anim")
local twn_h = vint_object_find("tutorial_alpha_twn", fade_out_anim_h)
vint_set_property(twn_h, "start_value", alpha)
--Fade out window
lua_play_anim(fade_out_anim_h)
else
tutorial_set_hud_help_closing(false)
end
end
end
--Update callback function for the tutorial responder...
--
-- @param tutorial_ready true, if there is another tutorial and false, if we close.;
-- @param header_txt Title of tutorial
-- @param body_txt Body of the tutorial
-- @param tutorial_type Enum of the tutorial
-- @param image_name Name of the image that should load with the tutorial...
function tutorial_update(tutorial_ready, header_txt, body_txt, tutorial_type, image_name, use_back_button)
-- We don't have any tutorials left to display so exit.
if tutorial_ready == false then
tutorial_close()
return
end
--Get next window content...
local tutorial_content_id = tutorial_advance_window()
local content = Tutorial_content[tutorial_content_id]
--Update the window Text Elements...
vint_set_property(content.body_text_h, "text_tag", body_txt)
--Some tutorials should not have headers
if header_txt == "" or header_txt == nil then
vint_set_property(Tutorial.bg_top, "visible", false)
vint_set_property(content.header_text_h, "visible", false)
Tutorial_show_scanimate = false
tutorial_enable_text_shadow(true, content.body_text_h)
else
vint_set_property(content.header_text_h, "text_tag", header_txt)
vint_set_property(Tutorial.bg_top, "visible", true)
vint_set_property(content.header_text_h, "visible", true)
tutorial_enable_text_shadow(false, content.body_text_h)
--Reset scale of header text...
vint_set_property(content.header_text_h, "scale", 1, 1)
--Test sizes and scale if needed.
local bg_top_w, bg_top_h = element_get_actual_size(Tutorial.bg_top)
local text_width, text_height = element_get_actual_size(content.header_text_h)
local max_width = bg_top_w - TUTORIAL_HEADER_PADDING
local scale_x, scale_y = 1, 1 --Scale defaults
if text_width > max_width then
--need to scale down header text to fit...
scale_x = max_width / text_width --only scale the x direction(text is squished but otherwise too small!)
end
--Set scale... (
vint_set_property(content.header_text_h, "scale", scale_x, scale_y)
end
--Set image if it exists...
local image_width = 0
local image_height = 0
if image_name == "" or image_name == nil then
--No Image...
vint_set_property(content.illustration_h, "visible", false)
--Reset text position to default...
vint_set_property(content.body_text_h, "anchor", Tutorial.body_text_x, Tutorial.body_text_y)
else
--Show image and set name...
vint_set_property(content.illustration_h, "visible", true)
vint_set_property(content.illustration_h, "image", image_name)
--Reposition text below the image...
image_width, image_height = element_get_actual_size(content.illustration_h)
vint_set_property(content.body_text_h, "anchor", Tutorial.body_text_x, Tutorial.body_text_y + image_height)
end
--Resize tutorial frame and prepare animations...
--Prepare some numbers to resize the window below...
local clip_offset_y = 25 --the distance from the groups origin to the body text box...
local width, height = element_get_actual_size(content.body_text_h)
height = (height) + (image_height) + 12 -- Height of tutorial window...
-- Show back button
if use_back_button == true then
content.hint_bar:set_visible(true)
Input_tracker:subscribe(true)
local hint_width, hint_height = content.hint_bar:get_size()
height = height + hint_height + TUTORIAL_HINT_PADDING
content.hint_bar:set_anchor(24,height + (hint_height / 2) + TUTORIAL_HINT_SPACING)
else
content.hint_bar:set_visible(false)
end
--Target box scale...
local body_bg_width, body_bg_height = element_get_actual_size(Tutorial.bg_body_h)
local scale_x, scale_y = element_get_scale_from_size(Tutorial.bg_body_h, body_bg_width, height)
--Target Clip Size
local clip_width = body_bg_width
local clip_height = height + clip_offset_y
--Target positions
local x = Tutorial.start_x
local y = Tutorial.start_y - (height * Tutorial.scaler) --The scaler is used for translation...
--Resize Clip Tween
--Do Alpha Transitions
local content_1_alpha_twn_h = vint_object_find("content_1_alpha_twn")
local content_2_alpha_twn_h = vint_object_find("content_2_alpha_twn")
local clip_size_twn_h = vint_object_find("clip_size_twn")
local body_scale_twn_h = vint_object_find("body_scale_twn")
local window_anchor_twn_h = vint_object_find("window_anchor_twn")
--Reset values if the tutorial box is new...
local previous_content_alpha = 1 --Value for fading the previous content out... gets set to zero if there was no previous content...
local next_frame_values = {
clip_size_x = clip_width,
clip_size_y = clip_height,
scale_x = scale_x,
scale_y = scale_y,
start_x = Tutorial.start_x,
start_y = y,
}
if Tutorial_frame_values == -1 then
--Start values same as next values...
Tutorial_frame_values = table_clone(next_frame_values)
--Have clip mask fade in from left...
Tutorial_frame_values.clip_size_x = 10
--Do not allow previous content in view...
previous_content_alpha = 0
end
if tutorial_content_id == 1 then
--Set alpha fades
vint_set_property(content_1_alpha_twn_h, "start_value", 0)
vint_set_property(content_1_alpha_twn_h, "end_value", 1)
vint_set_property(content_2_alpha_twn_h, "start_value", previous_content_alpha)
vint_set_property(content_2_alpha_twn_h, "end_value", 0)
elseif tutorial_content_id == 2 then
--Set alpha fades
vint_set_property(content_1_alpha_twn_h, "start_value", previous_content_alpha)
vint_set_property(content_1_alpha_twn_h, "end_value", 0)
vint_set_property(content_2_alpha_twn_h, "start_value", 0)
vint_set_property(content_2_alpha_twn_h, "end_value", 1)
end
--Animate Clip
vint_set_property(clip_size_twn_h, "start_value", Tutorial_frame_values.clip_size_x, Tutorial_frame_values.clip_size_y)
vint_set_property(clip_size_twn_h, "end_value", next_frame_values.clip_size_x, next_frame_values.clip_size_y)
--Animate Body Scale
vint_set_property(body_scale_twn_h, "start_value", Tutorial_frame_values.scale_x, Tutorial_frame_values.scale_y)
vint_set_property(body_scale_twn_h, "end_value", next_frame_values.scale_x, next_frame_values.scale_y)
--Animate window position
vint_set_property(window_anchor_twn_h, "start_value", Tutorial_frame_values.start_x, Tutorial_frame_values.start_y)
vint_set_property(window_anchor_twn_h, "end_value", Tutorial_frame_values.start_x, next_frame_values.start_y)
Tutorial_frame_values = next_frame_values
--play animation
local box_morph_anim_h = vint_object_find("box_morph_anim")
lua_play_anim(box_morph_anim_h)
--Stop Fadeout
local fade_out_anim_h = vint_object_find("fade_out_anim")
vint_set_property(fade_out_anim_h, "is_paused", true)
--if the tutorial is not already visible then do a seperate/different animation
--and if it's really a tutorial and not help text (DAD 3/21/11)
if Tutorial_first_time and Tutorial_show_scanimate then
local drop_in_anim_h = vint_object_find("drop_in")
--start the frame x far to the right so it animates in centered
--Tutorial_frame_values.start_x = 76
--set the outlines up, they are only used for the first tutorial
tutorial_set_outlines(height, next_frame_values.start_y)
--loop through, offset and play the scanimations
for i=1,Max_outlines do
lua_play_anim( Outline_anims[i].anim.handle, (i-1) * 0.06 )
end
--play audio for scanimate type
game_UI_audio_play("UI_HUD_Tutorial")
lua_play_anim(drop_in_anim_h)
--until tutorial_wipe_old_values() or tutorial_close(true) happen we have an open tutorial
Tutorial_first_time = false
elseif Tutorial_first_time then
--play audio for help type
game_UI_audio_play("UI_HUD_Help")
end
-- tutorial may already be up (or it's a hud help message) attempt to fade in
local fade_in_anim_h = vint_object_find("fade_in_anim")
local twn_h = vint_object_find("tutorial_alpha_twn")
local alpha = vint_get_property(Tutorial.window_h, "alpha")
vint_set_property(twn_h, "start_value", alpha)
lua_play_anim(fade_in_anim_h)
end
--Setup all the outlines for the scanimation spectacular...
--
-- @param height height of the black bg box calculated in tutorial_update()
-- @param window_end_y new tutorial window y value calculated in tutorial_update()
function tutorial_set_outlines( height, window_end_y )
--clear out the clones if we have any
if #Outline_anims > 1 then
for i = 1,Max_outlines do
Outline_anims[i].anim:object_destroy()
Outline_anims[i].outlines_clone:object_destroy()
end
end
Outline_anims = {}
local outlines = Vdo_base_object:new( "outlines" )
outlines:set_visible(false)
local bg_top_w, bg_top_h = element_get_actual_size( Tutorial.bg_top )
local total_h = height + bg_top_h
--how big the outlines start out at
local scale_amount = 4.0
--base size of the square image the outlines are made of
local base_square_root_scale = 16
--pixel thickness of the lines, if you change this you must change magic_x_offset and magic_y_offset
local line_thickness = 3
--creates a scale value out of a pixel size
local line_scale = line_thickness / base_square_root_scale
--center y value for the outline group
local outline_y_center = window_end_y - line_thickness + (total_h * 0.5)
--center x value for the outline group
local outline_x_center = Tutorial.start_x + (bg_top_w * 0.5)
--how many pixels we want the lines to stop at before/after they reach the tutorial box
local end_position_offset = 10
--these numbers adjust the line widths so that their tips do not overlap
local magic_x_offset = 13
local magic_y_offset = 7
--set up the anchor tweens
local outline_start_y = total_h * scale_amount
local outline_end_y = (total_h + end_position_offset) * 0.5
local outline_start_x = bg_top_w * scale_amount
local outline_end_x = (bg_top_w + end_position_offset) * 0.5
vint_set_property( outlines, "anchor", outline_x_center, outline_y_center )
local tween = Vdo_tween_object:new( "top_line_anchor")
vint_set_property(tween.handle, "start_value", 0, -1 * outline_start_y)
vint_set_property(tween.handle, "end_value", 0, -1 * outline_end_y)
tween = Vdo_tween_object:new( "bottom_line_anchor" )
vint_set_property(tween.handle, "start_value", 0, outline_start_y)
vint_set_property(tween.handle, "end_value", 0, outline_end_y)
tween = Vdo_tween_object:new( "left_line_anchor" )
vint_set_property(tween.handle, "start_value", -1 * outline_start_x, 0 )
vint_set_property(tween.handle, "end_value", -1 * outline_end_x, 0 )
tween = Vdo_tween_object:new( "right_line_anchor" )
vint_set_property(tween.handle, "start_value", outline_start_x, 0 )
vint_set_property(tween.handle, "end_value", outline_end_x, 0 )
--set up the scale tweens
local start_scale_x = line_scale
local start_scale_y = ((total_h) / base_square_root_scale) * ( scale_amount * 2 )
local end_scale_x = start_scale_x
local end_scale_y = ((total_h + magic_y_offset) / base_square_root_scale)
tween = Vdo_tween_object:new( "left_line_scale" )
vint_set_property(tween.handle, "start_value", start_scale_x, start_scale_y)
vint_set_property(tween.handle, "end_value", end_scale_x, end_scale_y)
tween = Vdo_tween_object:new( "right_line_scale" )
vint_set_property(tween.handle, "start_value", start_scale_x, start_scale_y)
vint_set_property(tween.handle, "end_value", end_scale_x, end_scale_y)
start_scale_x = ((bg_top_w) / base_square_root_scale) * ( scale_amount * 2 )
start_scale_y = line_scale
end_scale_x = ((bg_top_w + magic_x_offset) / base_square_root_scale)
end_scale_y = start_scale_y
tween = Vdo_tween_object:new( "top_line_scale" )
vint_set_property(tween.handle, "start_value", start_scale_x, start_scale_y)
vint_set_property(tween.handle, "end_value", end_scale_x, end_scale_y)
tween = Vdo_tween_object:new( "bottom_line_scale" )
vint_set_property(tween.handle, "start_value", start_scale_x, start_scale_y)
vint_set_property(tween.handle, "end_value", end_scale_x, end_scale_y)
-- Clone outline animation and group. Then Retarget and store handles for later...
local outline_anim = Vdo_anim_object:new("scanimation")
for index = 1, Max_outlines do
local outlines_clone = Vdo_base_object:clone(outlines.handle)
outlines_clone:set_visible(true)
outlines_clone:set_alpha(0)
local anim = Vdo_anim_object:clone(outline_anim.handle)
anim:set_target_handle(outlines_clone.handle)
anim:stop()
Outline_anims[index] = {
anim = anim,
outlines_clone = outlines_clone,
}
vint_set_property( outlines_clone.handle, "anchor", outline_x_center, outline_y_center )
end
end
-- Callback function for wiping any stagnant window position and size values.
-- This is used only when the window fully fades out so it is tied as a callback
-- to the window fadout animation.
function tutorial_wipe_old_values()
Tutorial_frame_values = -1
-- DAD - 2/22/11 - For the hud help region that uses the tutorial box, need to notify it the fade is done
tutorial_set_hud_help_closing(false)
--reset the flag for checking whether the popup is up or not
Tutorial_first_time = true
Tutorial_show_scanimate = true
end
-- Advances window id saftely.
--
--@return id of next window...
function tutorial_advance_window()
Tutorial_current_window = Tutorial_current_window + 1
if Tutorial_current_window == 3 then
Tutorial_current_window = 1
end
return Tutorial_current_window
end
-----------------------------------------------------------------------------
-- Enables super text shadow on
-----------------------------------------------------------------------------
function tutorial_enable_text_shadow(enabled, text_object_h)
if enabled then
vint_set_property(text_object_h, "line_frame_w", "ui_fnt_body_s_w")
vint_set_property(text_object_h, "line_frame_m", "ui_fnt_body_s_m")
vint_set_property(text_object_h, "line_frame_e", "ui_fnt_body_s_e")
vint_set_property(text_object_h, "line_frame_enable", true)
vint_set_property(Tutorial.bg_body_h, "visible", false)
vint_set_property(Tutorial.content_clip_h, "clip_enabled", false)
else
vint_set_property(text_object_h, "line_frame_enable", false)
vint_set_property(Tutorial.bg_body_h, "visible", true)
vint_set_property(Tutorial.content_clip_h, "clip_enabled", true)
end
end