require "scripts/style"

-- gRows and gColumns are set up in mainmenu.lua

kMiddle = 82
kButtonWidth = 30
kYPosition = 460

WinFont = {
  standardFont,
  70,
  WhiteColor
};

function SetLevel( level )
    currLevel = level
    SetWindowVisible("winbg", false)
    SetWindowVisible("win", false)
    SetWindowVisible("lose", false)

-- Show all the difficulty buttons
	SetWindowVisible("beginner", true);
	SetWindowVisible("intermediate", true);
	SetWindowVisible("advanced", true);
	
-- Hide the selected level button
	SetWindowVisible( level, false );

-- Show the right background
	if ( "advanced" == level ) then
		SetWindowVisible("usualbg", false);
		SetWindowVisible("advbg", true);
	else
		SetWindowVisible("usualbg", true);
		SetWindowVisible("advbg", false);
	end;
end

function WinWindow( didwin )
	SetWindowVisible("winbg", true)
    SetWindowVisible("win", didwin)
	if (didwin) then
		SetWindowVisible("lose", false)
	else
		SetWindowVisible("lose", true)
	end
end


MakeDialog
{
	-- Name the modal dialog
	name="window",
	
	Bitmap
    {
        name="usualbg",
        image="backgrounds/background_beginner",
        x=kCenter,
        y=kCenter,
    },
    
    Bitmap
    {
        name="advbg",
        image="backgrounds/background_advanced",
        x=kCenter,
        y=kCenter,
    },
    
    Bitmap
    {
        name="seaweed",
        image="backgrounds/seaweed_ui",
        x=kCenter,
        y=kCenter,
    },
	
	GameWindow
    {
        x=0,
        y=0,
        w=800,
        h=600,

		squareTextColor = Color( 236, 251, 255, 255 ),
		squareTextFont = "fonts/DomCasualStd.mvec",
		
		sideStripTextColor = Color( 236, 251, 255, 255 ),
		sideStripTextFont = "fonts/DomCasualStd.mvec",
		
		sideStripNumberColor = Color( 236, 251, 255, 255 ),
		sideStripNumberFont = "fonts/DomCasualStd-Bold.mvec",
	},
    
    Bitmap
    {
		name="winbg",
		image="backgrounds/win",
		x=375,
		y=230,
		
		Text
		{
			font = WinFont,
			name = "win",
			x=kCenter,y=kCenter,w=kMax,h=kMax,
			flags = kHAlignCenter + kVAlignCenter,
			label = "win"
		},
	
		Text
		{
			font = WinFont,
			name = "lose",
			x=kCenter,y=kCenter,w=kMax,h=kMax,
			flags = kHAlignCenter + kVAlignCenter,
			label = "lose"
		},    
	},
    
		
    SetStyle( LevelButtonStyle ),
    
    Text
    {
        font = StandardButtonFont,
        name = "textbeg",
        x=kMiddle-kButtonWidth+5,y=kYPosition,w=kButtonWidth,h=kButtonWidth,
        flags = kHAlignCenter,
        label = "beginner",
    },
    
    Button
    {
        x=kMiddle-kButtonWidth, y=kYPosition,
        name="beginner",
        label="beginner",
        command =
            function()
                SendGameMessage( "beginner" );
                SetLevel("beginner");
            end
    },
    
    Text
    {
        font = StandardButtonFont,
        name = "textint",
        x=kMiddle+15,y=kYPosition,w=kButtonWidth,h=kButtonWidth,
        flags = kHAlignCenter,
        label = "intermediate",
    },
    
    Button
    {
        x=kMiddle+10, y=kYPosition,
        name="intermediate",
        label="intermediate",
        command =
            function()
                SendGameMessage( "intermediate" );
                SetLevel("intermediate");
            end
    },
    
    Text
    {
        font = StandardButtonFont,
        name = "textadv",
        x=kMiddle+kButtonWidth+25,y=kYPosition,w=kButtonWidth,h=kButtonWidth,
        flags = kHAlignCenter,
        label = "advanced",
    },
    
    Button
    {
        x=kMiddle+kButtonWidth+20, y=kYPosition,
        name="advanced",
        label="advanced",
        command =
            function()
                SendGameMessage( "advanced" );
                SetLevel("advanced");
            end
    },
    
    SetStyle( ButtonStyle ),
    
    Button
    {
        x=45,
        y=160,
        name="newgame",
        label="newgame",
        cancel=true,
        command=
            function()
                SendGameMessage( currLevel );
                SetLevel( currLevel );
            end
    },
    
    Button
    {
        x=45,
        y=500,
        name="pause",
        label="pause",
        cancel=true,
        command=
            function()
                DoModal("scripts/pause.lua");
            end
    },
}

local currLevel = GetLevelName();
SetLevel(currLevel);