class "TutorialScreen"

TutorialScreen = {}

--------------------------------------------------------------------------------
function TutorialScreen:New(screen, text)
    local result = CreateObjectOfClass(self)
    result.bg = nil
    result.screen = screen
    result.arrow = {}
    
    local maxZ = 1000
    
    local anim = CreateAnimation('data/Texture/Screen/TutorialScreen/TutorialScreen.png',0,0,488,375,1,0)
	anim:SetHotSpot(244,187)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	result.bg = screen:CreateObject('TutorialScreen',anim,512,384,100,0,1,1)
	result.bg:SetZ(maxZ + 1)

    -- create text help	
	local text_title = CreateTextEntity("WindowText28", GetString(text))
    text_title:AttachTo( result.bg )
	text_title:SetScale(1)
	text_title:SetZ(10)
	text_title:SetXY(-205, -100)
	text_title:SetBorderSize(420, 170)
	text_title:SetTextAlignment(HGETEXT_TOP + HGETEXT_LEFT)
	result.text_title = text_title
	
	-- create back for button
	local pos_skip = Vector(10, 120)
	local z_skip = 50
	local anim = CreateAnimation('data/Texture/Screen/TutorialScreen/bttn_background.png',0,0,239,55,1,0)
	anim:SetHotSpot(119,27)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	local bttn_skip_back = screen:CreateObject('bttn_background',anim,pos_skip.x - 3,pos_skip.y + 2,z_skip - 1,0,1,1)
	bttn_skip_back:AttachTo(result.bg)
	result.bttn_skip_back = bttn_skip_back
	
	-- Create button
	local bttn_skip = create_button_ex(screen, 'data/Texture/Screen/TutorialScreen/bttn_skip_tutorial.png', 'skip_tutorial', pos_skip.x, pos_skip.y, z_skip)
	bttn_skip:AttachTo(result.bg)
	result.bttn_skip = bttn_skip
	
	return result
end

--------------------------------------------------------------------------------
function TutorialScreen:SetPos(x, y)
    self.bg:SetXY(x, y)
end
--------------------------------------------------------------------------------
function TutorialScreen:SetOffsetPosText(offset_x, offset_y)
    if self.text_title then
        local x_new = self.text_title:GetX() + offset_x
        local y_new = self.text_title:GetY() + offset_y
        self.text_title:SetXY(x_new, y_new)
    end
end
--------------------------------------------------------------------------------
function TutorialScreen:SetArrow(x, y, angle)
    local name_arrow = 'TutorialArrow'..table.getn(self.arrow)

    local anim = CreateAnimation('data/Texture/Comics/TutorialArrow.png',0,0,64,32,1,0)
	anim:SetHotSpot(32,16)
	anim:SetBlendMode(2)
	anim:SetColor('0xFFFFFFFF')
	local obj_arrow = self.screen:CreateObject(name_arrow,anim,608,410,1001,90,1.5,1.5)
	
	obj_arrow:SetXY(x, y)
	obj_arrow:SetAngle(angle)
	table.insert(self.arrow, obj_arrow)
	
	return obj_arrow
end
--------------------------------------------------------------------------------
function TutorialScreen:Hide()
    self.bg:ChangeOpacity(1, 0, 0.3)
end
--------------------------------------------------------------------------------
function TutorialScreen:HideBttnSkip()
    self.bttn_skip:SetVisible(false)
    self.bttn_skip_back:SetVisible(false)
end
--------------------------------------------------------------------------------
function IsSkipTutorial()
    if not GameStateExists('TutorialEnabled') then
        return true
    end
    
    if HasGameState('TutorialEnabled', 'true') then
        return true
    end
    return false
end
--------------------------------------------------------------------------------
function SetTutorialEnabled(state)
    if not GameStateExists('TutorialEnabled') then
        AddGameState('TutorialEnabled', state)
    end
        
    SetGameState('TutorialEnabled', state)
end
--------------------------------------------------------------------------------

