------------------------------------------------------------------------------
class 'l_IntroScreen' (BaseScreen)
------------------------------------------------------------------------------
function l_IntroScreen:__init(name, screen)
	BaseScreen.__init(self, name, screen)
	
	StopAmbientMusic(false)
	
	-- create button ----------------------------------------------------------
	do
	    local bttn_skip = self:CreateButton('bttn_skip')
	    bttn_skip:SetAction('OnSkipButtonClick', self)
	    bttn_skip:SetActionSound("Menu_button_click")
	    bttn_skip:Hide()
	    
	    if IsDebugMode() then
	        bttn_skip:Show()
	    else
            self.timer:Add( function()
                                bttn_skip:Show()
                            end,
                            10)
        end
    end
	-------------------------
	
	self.idle_movie_duration  = 34
	self.cycle_movie_duration = 3
	self.idle2_movie_duration = 13
	
	self.black_burs_move_time = 0.5
	self.current_movie_part   = nil
	-------------------------
	
	self.text = CreateTextEntity(MENU_FONT, 'CLICK_TO_CONTINUE')
	self.text:AttachTo(self.screen)
	self.text:SetXY(1014, 755)
    self.text:SetZ(300)
    self.text:SetScale(0.4)
	self.text:SetTextAlignment(HGETEXT_RIGHT + HGETEXT_MIDDLE)
	self.text:SetOpacity(0)
	-------------------------
	
	do
		self.letter_subtitles = Subtitles(screen, self.timer)
		self.letter_subtitles.mode = self.letter_subtitles.modes.CLICKABLE
		self.letter_subtitles.text_y = 680
		self.letter_subtitles.on_finish =   function()
												self:PlayMoviePart3()
											end    

		self.sub = Subtitles(screen, self.timer)
    	self.sub:pushReplic('INTRO_SUBTITLE', 26, 27) 
		
		do
		    local sound_dir  = 'data/Sound/Voices/Dupin/'
			local txt_prefix = 'INTRO_LETTER_TEXT_'
			local txt_id     = 1
			
			while HasString(txt_prefix..tostring(txt_id)) do
			    local sound = sound_dir..'INTRO_LETTER_'..tostring(txt_id)..'.ogg'
			    local text  = txt_prefix..tostring(txt_id)
			    
				self.letter_subtitles:pushVoicedReplic(sound, text)
				
				txt_id = txt_id + 1
			end
		end
	end
	-------------------------
	
	self:CreateMovies()
	self:PlayMoviePart1()
end
-------------------------------------------------------------------------------

function l_IntroScreen:CreateMovies()
    do
        self.movie_idle = CreateMovieEntity()
        self.movie_idle:AttachTo(self.screen)
        self.movie_idle:SetZ(102)
        self.movie_idle:SetXY(SCR_W/2, SCR_H/2 + 5)
        self.movie_idle:SetScale(SCR_W / 800)
        self.movie_idle:SetRepeat(false)
    end
    
    do
        self.movie_cycle = CreateMovieEntity()
        self.movie_cycle:AttachTo(self.screen)
        self.movie_cycle:SetZ(103)
        self.movie_cycle:SetXY(SCR_W/2, SCR_H/2 + 5)
        self.movie_cycle:SetScale(SCR_W / 800)
        self.movie_cycle:SetRepeat(true)
    end
    
    do
        self.movie_idle2 = CreateMovieEntity()
        self.movie_idle2:AttachTo(self.screen)
        self.movie_idle2:SetZ(104)
        self.movie_idle2:SetXY(SCR_W/2, SCR_H/2 + 5)
        self.movie_idle2:SetScale(SCR_W / 800)
        self.movie_idle2:SetRepeat(false)
    end
end
-------------------------------------------------------------------------------

function l_IntroScreen:PlayMoviePart1()
    self.screen:GetObject('border_bottom'):SetY(self.screen:GetObject('border_bottom'):GetY() + 64)
    self.screen:GetObject('border_top'   ):SetY(self.screen:GetObject('border_top'   ):GetY() - 64)
    self.screen:GetObject('border_bottom'):Move(0, -64, self.black_burs_move_time)
    self.screen:GetObject('border_top'   ):Move(0,  64, self.black_burs_move_time)
    -------------------------
    
    self.movie_idle:PlayMovie('data/Video/Intro/intro_video_part1.ogg', 'data/Video/Intro/intro_sound_part1.ogg')

    self.sub:play()

    self.current_movie_part = 1
    
	self.timer:Add( function()
	                    self:PlayMoviePart2()
	                end,
                    self.idle_movie_duration)
end
-----------------------------

function l_IntroScreen:PlayMoviePart2()
    self.screen:GetObject('border_bottom'):ChangeScaleY(7, 16, self.black_burs_move_time)
    self.text:ChangeOpacity(0, 1, self.black_burs_move_time)
    
    self.movie_cycle:PlayMovie('data/Video/Intro/intro_video_part2.ogg', '')
    self.current_movie_part = 2
    
    self.letter_subtitles:showNextReplic()
    
    do
        LoadSound('intro_sound_part2', 'data/Video/Intro/intro_sound_part2.ogg')
        self.intro_sound_part2 = MakeSoundEntity('intro_sound_part2')
        self.intro_sound_part2:PlaySound(true)
    end
    
    self.timer:Add( function()
                        self.click_to_continue = true
                    end,
                    self.black_burs_move_time)
end
-----------------------------

function l_IntroScreen:PlayMoviePart3()
    self.screen:GetObject('border_bottom'):ChangeScaleY(16, 7, self.black_burs_move_time)
    self.text:ChangeOpacity(1, 0, self.black_burs_move_time)
    
    self.timer:Add( function()
                        self.movie_idle2:PlayMovie('data/Video/Intro/intro_video_part3.ogg', 'data/Video/Intro/intro_sound_part3.ogg')
                        self.intro_sound_part2:StopSound()
                        
                        self.timer:Add( function()
                                            self.movie_cycle:StopMovie()
                                        end,
                                        0.05)
                        
                        self.current_movie_part = 3
                    end,
                    self.black_burs_move_time)
end
-----------------------------

function l_IntroScreen:OnUpdate(dt)
    if self.current_movie_part == 3 and not self.movie_idle2:IsPlaying() then
        self:OnSkipButtonClick()
    end
end
-------------------------------------------------------------------------------

function l_IntroScreen:OnSkipButtonClick()
    self.letter_subtitles:stop()
    
    OnSkipIntroScreen()
    self.current_movie_part = nil
end
-------------------------------------------------------------------------------

function l_IntroScreen:OnScreenObjectMouseDown(object)
    if self.current_movie_part == 2 then
        self.letter_subtitles:showNextReplic()
    end
end
-------------------------------------------------------------------------------

function CreateIntroScreen()
    local screen = CreateScriptedScreen('data/Scripts/screens/IntroScreen.lua', 'l_IntroScreen')
    GM:SetCurrentScreen(screen)
    PopUpScreensMgr:Push(screen, false, nil)
end
-------------------------------------------------------------------------------

function OnSkipIntroScreen()
    PopUpScreensMgr:Pop()
    CreateMainMenu()
end
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_IntroScreen:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/GUI/Buttons/bttn_skip.png',0,0,57,43,3,0)
	anim:SetHotSpot(28,21)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_skip',anim,989,30,120,0,1,1)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,8)
	anim:SetBlendMode(2)
	anim:SetColor('0xCC000000')
	screen:CreateObject('border_bottom',anim,508,768,110,0,130,7)
	
	anim = CreateAnimation('data/Texture/Common/area.png',0,0,8,8,1,0)
	anim:SetHotSpot(4,0)
	anim:SetBlendMode(2)
	anim:SetColor('0xCC000000')
	screen:CreateObject('border_top',anim,507,0,110,0,130,7)
	
end
-- CLEAR_ON_SAVE_END
