dofile('Data/Scripts/Common/Screens/IntroScreenBase.lua')

class 'IntroScreen' (IntroScreenBase)

function IntroScreen:__init(name)
	IntroScreenBase.__init(self, name)
end

function IntroScreen:setupSkipButton()
	self:getEntityNamed('bttn_skip').onPress:add(bind(self.onSkipButtonClick, self))
	self:getEntityNamed('bttn_skip'):hide()

    self:getMainEntity():getEntityNamed('bttn_skip'):setSFXTrackOnPress( getCommonSoundEntity('ButtonClick') )
	
	if isDebugMode() then
		self:getEntityNamed('bttn_skip'):show()
	else
		self.timer:add( function()
							self:getEntityNamed('bttn_skip'):show()
							self:getEntityNamed('bttn_skip'):ChangeOpacity(0, 1, 0.4)
						end, 5)
	end
end

function IntroScreen:setupVideo()
	self.video = self:getEntityNamed('Intro')
	-- if not Application:getPlatform():getWindow():isFullscreen() or Application:getPlatform():getWindow():isWidescreen() then
	-- 	-- self.video:setScale(1366/912)
	-- 	-- self:getEntityNamed('bttn_skip'):setX(991 + 171)
	-- end

	-- local intro_sound = CreateSoundTrack('Data/Sounds/Intro/intro.ogg')
	-- intro_sound:setRepeated(false)
	-- intro_sound:setName('intro_sound')
	-- intro_sound:attachTo(self:getMainEntity())

	-- intro_sound:play()
	self.video:play()
	self.video.onFinish:add(	function()
									self:getEntityNamed('txt_after'):show()
									self.timer:add(	bind(self.onSkipButtonClick, self), 3.5)
								end)
	local subtitles = Subtitles(self)
	subtitles:pushReplic('SUB_1_INTRO', 10, 5)
    subtitles:pushReplic('SUB_2_INTRO', 15.5, 3.5)
	subtitles:pushReplic('SUB_3_INTRO', 19, 3)
	subtitles:pushReplic('SUB_4_INTRO', 26.5, 3)
	subtitles:pushReplic('SUB_5_INTRO', 31.5, 4.5)
	subtitles:play()
end

function IntroScreen:onSkipButtonClick()
	self:onScreenDestroy()
end

function IntroScreen:onScreenDestroy()
	self.video:stop()
	self:getEntityNamed('bttn_skip').onPress:removeAll()

	PopUpScreensMgr:pop()
	 
	createMainMenu()
end

--------------------------------------------------------------------------------
--                      GENERATED CONTENT. DO NOT EDIT.                       --
--------------------------------------------------------------------------------

function IntroScreen:CreateLoaderTable()
	local objects =
	{
		{ name = 'Intro',  entityType = 'VideoEntity',  x = 512,  y = 384,  order = 0,  scaleX = 1.5,  scaleY = 1.51,  editingLocked = false,  treeItemIsExpanded = true,  path = 'Data/Video/Intro/Intro.webm',  hasAlpha = false,  soundPath = 'Data/Sounds/Intro/intro.ogg',  isLooped = false,  fps = 24,  },
		{ name = 'txt_after',  entityType = 'TextEntity',  x = 512,  y = 384,  order = 0,  isVisible = false,  isRespondable = false,  editingLocked = false,  treeItemIsExpanded = false,  localizationKey = 'TXT_INTRO_AFTER',  height = 45,  },
		{ name = 'bttn_skip',  entityType = 'ButtonEntity',  x = 991,  y = 24,  order = 2,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/GUI/Buttons/bttn_skip.png',  text = '',  },
		{ name = 'CutSceneBar',  entityType = 'SpriteEntity',  x = 512,  y = 729,  order = 10,  isVisible = false,  scaleX = 1024,  scaleY = 1,  editingLocked = false,  treeItemIsExpanded = true,  texturePath = 'Data/Textures/Common/CutSceneBar.png',  width = 1,  height = 80,  },
	}
	return objects
end
