presentExtrasScreen = nil;
extrasEnterScreen   = nil;
finishExtrasScreen  = nil;
openExtrasScreen    = nil;

----------------------------------------------------------------------------------

function StartPresentExtrasScreen()
    local message = (EXTRAS_BUILD) and 'CE_PRESENT_EXTRAS_TEXT' or 'SE_PRESENT_EXTRAS_TEXT'
    
    local screen = CreateScreen();
    screen:SetLayer(POPUP_WINDOWS_LAYER);
    screen:SetXY(370, 400);
    
    local bg = screen:CreateAnimation("data/Texture/GUI/Help/InteractiveHelpBg.png"); -- 564, 279
    bg:SetHotSpot(282, 139);
    bg:SetPosZ(2);
   
    local textBox = CreateTextEntity(INGAME_MENU_FONT, message);
	textBox:SetZ(3);
	textBox:SetScale(0.8);
	textBox:AttachTo(screen);
	textBox:SetTextAlignment(HGETEXT_CENTER + HGETEXT_MIDDLE);
	textBox:SetBorderSize(530 / textBox:GetScale(), 0)
	
	local arrow = screen:CreateAnimation("data/Texture/GUI/Help/TutorialArrow.png"); -- 64 32
    arrow:SetColor('0xFFFF2222');
    arrow:SetHotSpot(64, 16);
    arrow:SetAngle(math.rad(30));
    arrow:SetXY(785 - screen:GetX(), 530 - screen:GetY());
    arrow:SetScale(2.5);
    arrow:SetZ(0);
    
    local OKButton = MakeButton(0, 120, 100, 40);
    OKButton:GetCaption():SetFont(BUTTONS_FONT);
	OKButton:GetCaption():SetScale(0.8);
	OKButton:SetZ(5);
	
	OKButton:AttachTo(screen);
	OKButton:SetAction("DestroyPresentExtrasScreen");
	OKButton:SetSpriteUp("OKButton");
	OKButton:SetSpriteOver("OKButtonOver");
	OKButton:SetSpriteDown("OKButtonDown");
	OKButton:SetActionSound("Menu_button_click");
	
	presentExtrasScreen = screen;
    PopUpScreensMgr:Push(presentExtrasScreen, false);
end

----------------------------------------------------------------------------------

function DestroyPresentExtrasScreen()
    
    if (presentExtrasScreen)
    then
        PopUpScreensMgr:Pop();
        presentExtrasScreen = nil;
        
        if not IsPresentExtrasScreenShown()
        then
            GM:GetCurrPlayer().m_gameState:AddState(EXTRAS_MODE_PREFIX.."PRESENT_EXTRAS_SHOWN", "true");
        end
    end
    
end

----------------------------------------------------------------------------------

function IsPresentExtrasScreenShown()
    return GM:GetCurrPlayer().m_gameState:HasState(EXTRAS_MODE_PREFIX.."PRESENT_EXTRAS_SHOWN")
end

----------------------------------------------------------------------------------

function ShowFinishExtras()
    local finishExtrasScreen = BuildOKScreen('FINISH_EXTRAS', "FinishExtrasScreen")
    
    finishExtrasScreen.textBox:SetY(340 + 15)
    finishExtrasScreen.textBox:SetBorderSize(530 / finishExtrasScreen.textBox:GetScale(), 0)
    finishExtrasScreen:SetZ(500)
    
	PopUpScreensMgr:Push(finishExtrasScreen);
    
    GM:GetCurrPlayer().m_gameState:AddState(EXTRAS_MODE_PREFIX.."EXTRAS_FINISHED", "true")
end

----------------------------------------------------------------------------------

function FinishExtrasScreen()
    if (finishExtrasScreen)
    then
        PopUpScreensMgr:Pop();
        finishExtrasScreen = nil;      
    end
    ExitToMainMenu(true)
end

----------------------------------------------------------------------------------

function StartExtrasEnterScreen()
    local screen = CreateScreen();
    screen:SetLayer(POPUP_WINDOWS_LAYER);
    screen:SetXY(370, 400);
    
    local bg = screen:CreateAnimation("data/Texture/GUI/Help/InteractiveHelpBg.png"); -- 564, 279
    bg:SetHotSpot(282, 139);
    bg:SetPosZ(2);
   
    local textBox = CreateTextEntity(INGAME_MENU_FONT, "EXTRAS_ENTER_TEXT");
	textBox:SetZ(3);
	textBox:SetScale(0.8);
	textBox:AttachTo(screen);
	textBox:SetTextAlignment(HGETEXT_CENTER + HGETEXT_MIDDLE);
	textBox:SetBorderSize(530 / textBox:GetScale(), 0)
	
	local arrow = screen:CreateAnimation("data/Texture/GUI/Help/TutorialArrow.png"); -- 64 32
    arrow:SetColor('0xFFFF2222');
    arrow:SetHotSpot(64, 16);
    arrow:SetAngle(math.rad(30));
    arrow:SetXY(785 - screen:GetX(), 530 - screen:GetY());
    arrow:SetScale(2.5);
    arrow:SetZ(0);
    
    local OKButton = MakeButton(0, 120, 100, 40);
    OKButton:GetCaption():SetFont(BUTTONS_FONT);
	OKButton:GetCaption():SetScale(0.8);
	OKButton:SetZ(5);
	
	OKButton:AttachTo(screen);
	OKButton:SetAction("DestroyExtrasEnterScreen");
	OKButton:SetSpriteUp("OKButton");
	OKButton:SetSpriteOver("OKButtonOver");
	OKButton:SetSpriteDown("OKButtonDown");
	OKButton:SetActionSound("Menu_button_click");
	
	extrasEnterScreen = screen;
    PopUpScreensMgr:Push(extrasEnterScreen, false);
end

----------------------------------------------------------------------------------

function DestroyExtrasEnterScreen()
    
    if (extrasEnterScreen)
    then
        PopUpScreensMgr:Pop();
        extrasEnterScreen = nil;
        
        if not IsExtrasEnterShown()
        then
            GM:GetCurrPlayer().m_gameState:AddState(EXTRAS_MODE_PREFIX.."EXTRAS_ENTER_SHOWN", "true");
        end
        
        --StartMainMenuContentScreen();
    end
    
end

----------------------------------------------------------------------------------

function IsExtrasEnterShown()
    return GM:GetCurrPlayer().m_gameState:HasState(EXTRAS_MODE_PREFIX.."EXTRAS_ENTER_SHOWN");
end

----------------------------------------------------------------------------------

function StartOpenExtrasScreen()
    local screen = CreateScreen();
    screen:SetLayer(POPUP_WINDOWS_LAYER);
    screen:SetXY(512, 384);
    
    local bg = screen:CreateAnimation("data/texture/GUI/Square_dialog_back.png"); -- 618, 474
    bg:SetHotSpot(309, 237);
    bg:SetPosXY(0, 0);
    bg:SetPosZ(0);
    bg:AttachTo(screen);
	
	local textBox = CreateTextEntity(INGAME_MENU_FONT, "EXTRAS_OPEN_TEXT");
	textBox:SetXY(0, 15);
	textBox:SetZ(1);
	textBox:SetScale(1.0);
	textBox:SetRect(412, 264, 200, 200);
	textBox:AttachTo(screen);
	textBox:SetTextAlignment(HGETEXT_CENTER + HGETEXT_MIDDLE);
	textBox:SetBorderSize(530 / textBox:GetScale(), 0)
	
	local textBox = CreateTextEntity(INGAME_MENU_FONT, "CLICK_TO_CONTINUE");
	textBox:SetXY(0, 200);
	textBox:SetZ(1);
	textBox:SetScale(0.4);
	textBox:SetRect(0, 0, 1024, 768);
	textBox:AttachTo(screen);
	textBox:SetTextAlignment(HGETEXT_CENTER + HGETEXT_MIDDLE);
	textBox:SetAction("DestroyOpenExtrasScreen");
	
	openExtrasScreen = screen
	PopUpScreensMgr:Push(openExtrasScreen);
end

----------------------------------------------------------------------------------

function DestroyOpenExtrasScreen()
    
    if (openExtrasScreen)
    then
        PopUpScreensMgr:Pop();
        openExtrasScreen = nil;
        
        if not IsExtrasOpen()
        then
            GM:GetCurrPlayer().m_gameState:ClearByPrefix(EXTRAS_MODE_PREFIX, false);
            GM:GetCurrPlayer().m_gameState:AddState(EXTRAS_MODE_PREFIX.."EXTRAS_OPEN", "true");
    
            play_field:TimerDoString( "exitConfirmationScreen = 1;" ..
                                      "ExitToMainMenu();"..
                                      "exitConfirmationScreen = nil;",
                                      0.5);
        end
    end
    
end

----------------------------------------------------------------------------------

function IsExtrasOpen()
    return GM:GetCurrPlayer().m_gameState:HasState(EXTRAS_MODE_PREFIX.."EXTRAS_OPEN");
end

----------------------------------------------------------------------------------

function IsExtrasFinished()
	return GM:GetCurrPlayer().m_gameState:HasState(EXTRAS_MODE_PREFIX.."EXTRAS_FINISHED")
end

----------------------------------------------------------------------------------
