local MAX_SUSANS = 9
local Highlight_index = 1
local Previous_index = 1
local Susan_is_done = true
local Susan_images = {}
local Susan_arrow_left_h
local Susan_arrow_right_h
local GRAY = 30
local Foward_values = {
alpha_start = {0,1,1,1,1,1,0},
alpha_end = {1,1,1,1,1,0,0},
anchor_start = {-638,-473,-252,0,225,473,0},
anchor_end = {-473,-252,0,225,473,638,0},
scale_start = {.4,.6,.8,1,.8,.6,0},
scale_end = {.6,.8,1,.8,.6,.4,0},
tint_start = {0,0,GRAY,255,GRAY,0,0},
tint_end = {0,GRAY,255,GRAY,0,0,0},
}
local Reverse_values = {
alpha_start = {0,1,1,1,1,1,0},
alpha_end = {0,0,1,1,1,1,1},
anchor_start = {0,-473,-252,0,225,473,638},
anchor_end = {0,-638,-473,-225,0,225,473},
scale_start = {0,.6,.8,1,.8,.6,.4},
scale_end = {0,.4,.6,.8,1,.8,.6},
tint_start = {0,0,GRAY,255,GRAY,0,0},
tint_end = {0,0,0,GRAY,255,GRAY,0},
}
function vdo_susan_init()
end
-- Inherited from Vdo_base_object
Vdo_susan = Vdo_base_object:new_base()
function Vdo_susan:init()
--make a handle to the animation
self.go_susan = Vdo_anim_object:new("go_susan", self.handle, self.doc_handle)
self.init_susan = Vdo_anim_object:new("init_susan", self.handle, self.doc_handle)
self.arrow_right_anim = Vdo_anim_object:new("arrow_right_move", self.handle, self.doc_handle)
self.arrow_left_anim = Vdo_anim_object:new("arrow_left_move", self.handle, self.doc_handle)
self.arrow_pulse_anim = Vdo_anim_object:new("arrow_pulse", self.handle, self.doc_handle)
self.txt_in_anim = Vdo_anim_object:new("txt_intro", self.handle, self.doc_handle)
self.arrow_right = Vdo_base_object:new("susan_arrow_right", self.handle, self.doc_handle)
self.arrow_left = Vdo_base_object:new("susan_arrow_left", self.handle, self.doc_handle)
self.title_txt = Vdo_base_object:new("title_txt", self.handle, self.doc_handle)
self.desc_txt = Vdo_base_object:new("desc_txt", self.handle, self.doc_handle)
self.desc_shadow = Vdo_base_object:new("desc_shadow", self.handle, self.doc_handle)
--init download character text to false
self.text_is_visible = false
vint_apply_start_values(self.txt_in_anim.handle)
Susan_arrow_right_h = Vdo_base_object:new("susan_arrow_right", self.handle, self.doc_handle)
Susan_arrow_left_h = Vdo_base_object:new("susan_arrow_left", self.handle, self.doc_handle)
--hide text until needed
self.title_txt:set_visible(false)
self.desc_txt:set_visible(false)
self.desc_shadow:set_visible(false)
--hide the left arrow, screen inits to index of 1
Susan_arrow_left_h:set_visible(false)
local end_event_twn = Vdo_tween_object:new("susan_1_alpha", self.go_susan.handle)
local callback_string = self:package_tween_callback("reset")
end_event_twn:set_end_event(callback_string)
end_event_twn = Vdo_tween_object:new("new_tween14", self.init_susan.handle)
callback_string = self:package_tween_callback("intro_done")
end_event_twn:set_end_event(callback_string)
self.arrow_pulse_anim:play()
end
function Vdo_susan:move_right()
if Highlight_index == 1 or not Susan_is_done then
return
end
Susan_arrow_left_h:set_visible(true)
Susan_arrow_right_h:set_visible(true)
--subtract from the index
Previous_index = Highlight_index
Highlight_index = Highlight_index - 1
if Highlight_index < 1 then
Highlight_index = 1
end
if Highlight_index <= 1 then
Susan_arrow_left_h:set_visible(false)
end
local tween_h
for i = 1,7 do
local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle)
if i == 3 then
current_susan_h:set_depth(-2)
elseif i == 4 then
current_susan_h:set_depth(-1)
elseif i == 5 then
current_susan_h:set_depth(0)
elseif i == 1 and Previous_index > 3 then
-- Doesn't matter which images we set this to, as long as it's loaded. The image will be
-- tinted black at this point. But if it's not loaded, we'll see ui_blank
current_susan_h:set_visible(true)
current_susan_h:set_image(Susan_images[Previous_index].image_name)
end
if i < 3 or i > 5 then
--set the alpha tweens
local tween_h = Vdo_base_object:new("susan_"..i.."_alpha", self.handle)
tween_h:set_property("start_value", Foward_values.alpha_start[i])
tween_h:set_property("end_value", Foward_values.alpha_end[i])
end
--set the anchor tweens
tween_h = Vdo_base_object:new("susan_"..i.."_anchor", self.handle)
tween_h:set_property("start_value", Foward_values.anchor_start[i], 0)
tween_h:set_property("end_value", Foward_values.anchor_end[i], 0)
--set the scale tweens
tween_h = Vdo_base_object:new("susan_"..i.."_scale", self.handle)
tween_h:set_property("start_value", Foward_values.scale_start[i], Foward_values.scale_start[i])
tween_h:set_property("end_value", Foward_values.scale_end[i], Foward_values.scale_end[i])
--set the tint tweens
tween_h = Vdo_base_object:new("susan_"..i.."_tint", self.handle)
local tint = Foward_values.tint_start[i]
tween_h:set_property("start_value", tint/255, tint/255, tint/255)
tint = Foward_values.tint_end[i]
tween_h:set_property("end_value", tint/255, tint/255, tint/255)
local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD
--set the rotation tweens
local old_rotation = current_susan_h:get_rotation()
--get a random rotation
local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD
tween_h = Vdo_base_object:new("susan_"..i.."_rotation", self.handle)
tween_h:set_property("start_value", old_rotation )
tween_h:set_property("end_value", random_rotation )
end
self.go_susan:play()
self.arrow_left_anim:play()
Susan_is_done = false
end
function Vdo_susan:move_left()
if Highlight_index == MAX_SUSANS or not Susan_is_done then
return
end
Susan_arrow_right_h:set_visible(true)
Susan_arrow_left_h:set_visible(true)
--add to the index
Previous_index = Highlight_index
Highlight_index = Highlight_index + 1
if Highlight_index > MAX_SUSANS then
Highlight_index = MAX_SUSANS
end
if Highlight_index >= MAX_SUSANS then
Susan_arrow_right_h:set_visible(false)
end
local tween_h
for i = 1,7 do
local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle)
if i == 3 then
current_susan_h:set_depth(0)
elseif i == 4 then
current_susan_h:set_depth(-1)
elseif i == 5 then
current_susan_h:set_depth(-2)
elseif i == 7 and Previous_index < MAX_SUSANS - 2 then
-- Doesn't matter which images we set this to, as long as it's loaded. The image will be
-- tinted black at this point. But if it's not loaded, we'll see ui_blank
current_susan_h:set_visible(true)
current_susan_h:set_image(Susan_images[Previous_index].image_name)
end
if i < 3 or i > 5 then
--set the alpha tweens
tween_h = Vdo_base_object:new("susan_"..i.."_alpha", self.handle)
tween_h:set_property("start_value", Reverse_values.alpha_start[i])
tween_h:set_property("end_value", Reverse_values.alpha_end[i])
end
--set the anchor tweens
tween_h = Vdo_base_object:new("susan_"..i.."_anchor", self.handle)
tween_h:set_property("start_value", Reverse_values.anchor_start[i], 0)
tween_h:set_property("end_value", Reverse_values.anchor_end[i], 0)
--set the scale tweens
tween_h = Vdo_base_object:new("susan_"..i.."_scale", self.handle)
tween_h:set_property("start_value", Reverse_values.scale_start[i], Reverse_values.scale_start[i])
tween_h:set_property("end_value", Reverse_values.scale_end[i], Reverse_values.scale_end[i])
--set the tint tweens
tween_h = Vdo_base_object:new("susan_"..i.."_tint", self.handle)
local tint = Reverse_values.tint_start[i]
tween_h:set_property("start_value", tint/255, tint/255, tint/255)
tint = Reverse_values.tint_end[i]
tween_h:set_property("end_value", tint/255, tint/255, tint/255)
--get a random rotation
local random_rotation = (rand_int(-10, 10)) * DEG_TO_RAD
local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle)
local old_rotation = current_susan_h:get_rotation()
--set the rotation tweens
tween_h = Vdo_base_object:new("susan_"..i.."_rotation", self.handle)
tween_h:set_property("start_value", old_rotation )
tween_h:set_property("end_value", random_rotation )
end
self.go_susan:play()
self.arrow_right_anim:play()
Susan_is_done = false
end
function Vdo_susan:reset()
local rotations = {}
local index_change = Highlight_index - Previous_index
-- save off rotations first
for i = 1,7 do
local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle)
rotations[i] = current_susan_h:get_rotation()
end
for i = 1,7 do
local current_susan_h = Vdo_base_object:new("susan_"..i, self.handle)
current_susan_h:set_anchor(Foward_values.anchor_start[i],0)
current_susan_h:set_alpha(Foward_values.alpha_start[i])
local tint = Reverse_values.tint_start[i]
current_susan_h:set_color(tint/255, tint/255, tint/255)
current_susan_h:set_rotation(rotations[i + index_change])
current_susan_h:set_scale(Foward_values.scale_start[i],Foward_values.scale_start[i])
-- streamer_index is the first loaded image. Find this based on the current Highlight_index.
local streamer_index = i + Highlight_index - 4
if streamer_index >= 1 and streamer_index <= MAX_SUSANS and Susan_images[streamer_index].image_name ~= nil then
current_susan_h:set_visible(true)
current_susan_h:set_image(Susan_images[streamer_index].image_name)
else
current_susan_h:set_visible(false)
end
if i == 3 then
current_susan_h:set_depth(-1)
elseif i == 4 then
current_susan_h:set_depth(-2)
elseif i == 5 then
current_susan_h:set_depth(-1)
end
end
Susan_is_done = true
end
function Vdo_susan:show_text(title, desc, is_visible)
if title ~= nil then
self.title_txt:set_text(title)
end
if desc ~= nil then
self.desc_txt:set_text(desc)
end
self.title_txt:set_visible(is_visible)
self.desc_txt:set_visible(is_visible)
self.desc_shadow:set_visible(is_visible)
self.txt_in_anim:play(0)
-- save off params so we can call again if needed when
-- susan animates in again. This assumes we're only
-- using this for one item.
self.title = title
self.desc = desc
self.text_is_visible = is_visible
end
function Vdo_susan:get_index()
return Highlight_index
end
function Vdo_susan:is_in_progress()
return not Susan_is_done
end
function Vdo_susan:set_images(image_table)
Susan_images = image_table
self:reset()
end
function Vdo_susan:play_intro()
local end_event_twn_h = vint_object_find("init_done_twn", self.init_susan.handle)
local callback_string = self:package_tween_callback("init_anim_complete")
vint_set_property(end_event_twn_h, "end_event", callback_string)
vint_apply_start_values(self.init_susan.handle)
vint_apply_start_values(self.txt_in_anim.handle)
self.init_susan:play()
Susan_is_done = false
end
function Vdo_susan:intro_done()
Susan_is_done = true
end
--------------------------------------------------------------------------------------------
-- Callback triggered when last tween of init_susan anim is done.
-- Determines if text should be shown or not.
function Vdo_susan:init_anim_complete()
if self.text_is_visible == true then
self:show_text(self.title, self.desc, self.text_is_visible)
end
end