dofile('Data/Scripts/Common/Utils/SubtitlesBase.lua')

class 'Subtitles' (SubtitlesBase)
-------------------------------------------------------------

function Subtitles:__init(parent, timer)
	SubtitlesBase.__init(self, parent, timer)
	self.text_y = 738
	self.text_height = 30
end
-------------------------------------------------------------

function Subtitles:_createTextField()
	local field = CreateSpriteEntity('')
	field:attachTo			( self.parent:getMainEntity() )
	field:setName			( 'bottom_bar' )
	field:setAnimationSize	( Vector2f(1366, 60) )
	field:setHotSpot		( 683, 30 )
	field:setColor			( Colorf(0, 0, 0, 0.8) )
	field:setXY				( self.text_x, self.text_y )
	field:setOrder			( self.text_order )
	field:setRespondable	(false)


	local text = CreateTextEntity()
	text:setName			( 'Subtitles' )
	text:setFont			( self.font_name )
	text:setTextAlignment	( self.text_alignment )
	text:setHotSpotType		( self.text_alignment )
	text:setBounds			( self.text_width, self.text_height )
	text:setHeight			( self.text_height )
	text:setXY				( 0, -self.text_height/2)
	-- text:setOrder			( self.text_order )
	text:attachTo			( field )
	text:setRespondable		(false)
		
	self.fields[field] = true
	
	return field, text
end
-------------------------------------------------------------

function Subtitles:play()
	local max_time = 0;
	
	for i, info in ipairs(self.stack) do
		local field, text = self:_createTextField()
		text:setText( StringManager:getString(info.text) )

		local fade_time = (self.fade_time > info.dt) and info.dt or self.fade_time		

		local af = CreateAnimationEffector()
		af:setDestroysOnEnd(true)
		af:attachTo(field)	
		af:setKey(_TRACK_O, 0,                		            0)
		af:setKey(_TRACK_O, info.time,                          0)
		af:setKey(_TRACK_O, info.time + fade_time,              1)
		af:setKey(_TRACK_O, info.time + info.dt,                1)
		af:setKey(_TRACK_O, info.time + fade_time + info.dt, 	0)
		af:play()

		if info.hide_bar then
			field:setColor(Colorf(0, 0, 0, 0))
		end
	end
end
-------------------------------------------------------------

function Subtitles:pushReplic(text, time, dt, hide_bar)
	local info = {}
	info.text  = text
	info.time  = time
	info.dt    = dt
	info.hide_bar	= hide_bar
	
	table.insert(self.stack, info)
end