class 'l_PromoScreen' (BaseScreen)

function l_PromoScreen:__init(name, screen)
	BaseScreen.__init(self, name, screen)
	
	-- init
	self.PICURES_NAME_PREFIX = 'layer_picture_'
    self.BUTTONS_NAME_PREFIX = 'bttn_picture_'
	self.PICURES_CHANGE_TIME = 0.5
	self.LIGHT_TIME          = 0.2
	self.PICURES_COUNT       = 8
	
	self.pictureButtons = {}
	self.currentInsex = 1
	self.underCursorButton = nil
	self.bChanging = false
    
	-- buttons
	for i=1, self.PICURES_COUNT do
	    local buttonName = self.BUTTONS_NAME_PREFIX .. i
	    local fadeName   = 'layer_dark_mask_'..i
	    local lightName  = 'layer_light_mask_'..i
	    
	    local info   = {}
	    info.index   = i
	    info.picture = nil
	    info.button  = nil
	    info.fade    = nil
	    info.light   = nil
	    info.pos     = Vector(screen:GetObject(buttonName):GetX(),
                              screen:GetObject(buttonName):GetY())
                             
	    self['OnClickPicture'..i] = function(self)
	        self:SetPicture(i)
	    end
	    
	    info.picture = screen:GetObject(self.PICURES_NAME_PREFIX..i)    
	    info.picture:SetOpacity(i==1 and 1 or 0)
	    
	    info.button = self:CreateButton(buttonName)
	    info.button:SetAction('OnClickPicture'..i, self)
	    info.button:SetActionSound("Menu_button_click")
	    
	    info.fade = screen:GetObject(fadeName)
	    info.fade:SetXY(info.pos.x, info.pos.y)
	    info.fade:SetOpacity(i==1 and 0 or 1)
	    screen:IgnoreOnTestPoint(fadeName)
	    
	    info.light = screen:GetObject(lightName)
	    info.light:SetXY(info.pos.x, info.pos.y)
	    info.light:SetOpacity(0)
	    screen:IgnoreOnTestPoint(lightName)
	    
	    self.pictureButtons[buttonName] = info
    end
	
	local button = self:CreateButton('bttn_continue')
	button:SetAction('ClosePromoScreen', self)
	button:SetActionSound("Menu_button_click")
end
-------------------------------------------------------------------------------

function l_PromoScreen:GetPicture(index)
    return self.screen:GetObject(self.PICURES_NAME_PREFIX .. index)    
end
-------------------------------------------------------------------------------

function l_PromoScreen:GetPictureInfo(index)
    for buttonName, info in pairs(self.pictureButtons) do
        if info.index == index then
            return info
        end
    end
    
    return nil
end
-------------------------------------------------------------------------------

function l_PromoScreen:SetPicture(index)
    if self.currentInsex ~= index and (not self.bChanging) then
        local prevInfo = self:GetPictureInfo(self.currentInsex)
        local nextInfo = self:GetPictureInfo(index)
        
        prevInfo.picture:ChangeOpacity(1, 0, self.PICURES_CHANGE_TIME)
        nextInfo.picture:ChangeOpacity(0, 1, self.PICURES_CHANGE_TIME)
        
        prevInfo.fade:SetVisible(true)
        nextInfo.fade:SetVisible(false)
        
        self.currentInsex = index
        
        self.bChanging = true
        self.timer:Add( function()
                            self.bChanging = false
                        end,
                        self.PICURES_CHANGE_TIME)
    end
end
-------------------------------------------------------------------------------

function l_PromoScreen:ClosePromoScreen()
    ClosePromoScreen()
end
-------------------------------------------------------------------------------

function l_PromoScreen:OnUpdate(dt)
end

function l_PromoScreen:OnObjectMouseEnter(object)
end

function l_PromoScreen:OnObjectMouseLeave(object)
end

function l_PromoScreen:OnScreenObjectMouseDown(object, key)
end

function l_PromoScreen:OnObjectMouseDownProcessed(is_wrong_click)
end

function l_PromoScreen:OnObjectMouseUp(object)
end

function l_PromoScreen:OnButtonPress(title)
end
-------------------------------------------------------------------------------

function l_PromoScreen:OnButtonMouseEnter(buttonName)
    local info = self.pictureButtons[buttonName]
    
    if info then
        info.fade:SetOpacity(0)
        
        if info.lightEffector then
            info.lightEffector:Destroy()
            info.lightEffector = nil
        end
        
        info.lightEffector = info.light:ChangeOpacity(info.light:GetOpacity(), 1, self.LIGHT_TIME)
        info.lightEffector:SetDestroysOnEnd(false)
    end
end
-------------------------------------------------------------------------------

function l_PromoScreen:OnButtonMouseLeave(buttonName)
    local info = self.pictureButtons[buttonName]
    
    if info then
        info.fade:SetOpacity(1)
        
        if info.lightEffector then
            info.lightEffector:Destroy()
            info.lightEffector = nil
        end
        
        info.lightEffector = info.light:ChangeOpacity(info.light:GetOpacity(), 0, self.LIGHT_TIME)
        info.lightEffector:SetDestroysOnEnd(false)
    end
end
-------------------------------------------------------------------------------

function CreatePromoScreen()
    local screen = CreateScriptedScreen('data/Scripts/screens/PromoScreen.lua', 'l_PromoScreen');
    PopUpScreensMgr:Push(screen, false, nil);
end
-------------------------------------------------------------------------------

function ClosePromoScreen()
    PopUpScreensMgr:Pop()
    AppExit()
end
-------------------------------------------------------------------------------


--------------------------------------------------------------------------------
-- CLEAR_ON_SAVE_BEGIN
-- Do not edit code listed below (generated by the editor on each save)
function l_PromoScreen:LoadData(screen)
	local anim
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/Background.png',0,0,1024,768,1,0)
	anim:SetHotSpot(512,384)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('Background',anim,512,384,10,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/InGameMenu/bttn_continue.png',0,0,302,100,3,0)
	anim:SetHotSpot(151,50)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_continue',anim,516,685,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_1',anim,112,115,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_2',anim,112,297,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_3',anim,112,479,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_4',anim,112,661,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_5',anim,919,115,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_6',anim,919,298,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_7',anim,919,478,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Buttons/bttn_picture.png',0,0,182,182,3,0)
	anim:SetHotSpot(91,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('bttn_picture_8',anim,919,661,100,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_1.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_1',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_2.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_2',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_3.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_3',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_4.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_4',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_5.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_5',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_6.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_6',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_7.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_7',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Pictures/layer_picture_8.jpg',0,0,600,426,1,0)
	anim:SetHotSpot(300,213)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_picture_8',anim,528,476,9,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_1',anim,601,486,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_2',anim,911,666,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_3',anim,927,473,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_4',anim,906,105,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_5',anim,114,121,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_6',anim,99,661,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_7',anim,110,465,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_dark_mask.png',0,0,180,182,1,0)
	anim:SetHotSpot(90,91)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_dark_mask_8',anim,129,295,90,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_1',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_2',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_3',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_4',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_5',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_6',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_7',anim,570,329,110,0,1,1)
	
	anim = CreateAnimation('data/Texture/GUI/Promo/Layers/layer_light_mask.png',0,0,200,200,1,0)
	anim:SetHotSpot(100,100)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	screen:CreateObject('layer_light_mask_8',anim,570,329,110,0,1,1)
	
end
-- CLEAR_ON_SAVE_END
