
require "scripts/style"

kButtonSpacing = 35;
kButtonY = 30;
kButtonX = 20;



function MainMenuButtonLabel( label, color, colorHighlight )

	if not color then
		color =Color(0,0,0,255);	-- the default colors
		colorHighlight=Color(255,255,255,255)
	end

	return Group{
	
    AppendStyle{ font = { standardFont, kMenuButtonFontSize, color } },
    AppendStyle{ x=35, y=0, w=kMax, h=kMax, label=label },
		SelectLayer(0),
		Text{},
		AppendStyle{ font = { standardFont, kMenuButtonFontSize, colorHighlight } },
		SelectLayer(1),		
		Bitmap
		{
			image="backgrounds/hovergear",
			x=0,y=0,scale=1
		},
		Text{},
		AppendStyle{ font = { standardFont, kMenuButtonFontSize, colorHighlight } },
		SelectLayer(2),		
		Bitmap
		{
			image="backgrounds/hovergear",
			x=0,y=0,scale=1
		},
		Text{}
	}

end


function CheckUsers()
	if (GetNumUsers() == 0) then
		gEnterNameValue = "";
		name = DoModal("scripts/entername.lua");
		if (not(name == nil)) then
			CreateNewUser(name);
			DoModal("scripts/difficulty.lua");
			return true ;
		end
		return false ;
	elseif (IsGameOver()) then
    result = DisplayDialog {
			"scripts/yesno.lua",
			body ="resetconfirm",
			title = "resettitle"
			};		
		PlaySound("POPUP-OUT");				
		if (result=='yes') then
      ResetCurrentUser();
		end
    return false;
	else
		return true;
	end
end

function QuitGame()
	CloseWindow();
end

SetState( kGameMode, "mainmenu" );

MakeDialog
{
	-- Name the modal dialog
	name="mainmenu",
	MainMenu
	{	    
		fit=true;
		Bitmap
		{
			name="backgroundimage",
			image="titlescreen/background",	

      AnimButton
      {
        x=78,
				y=506,
				name="change_profile",
        animations={
          { key="normal", texture="titlescreen/change_profile/change_profile", animation="main", default=1},        
          { key="down", texture="titlescreen/change_profile/change_profile_down", animation="main"},
          { key="hover", texture="titlescreen/change_profile/change_profile_hover", animation="main"},
          { key="disabled", texture="titlescreen/change_profile/change_profile_disabled", animation="main"},
        },
        sound="audio/sfx/Monitor_Buttons_Click",
        rolloversound="audio/sfx/Monitor_Buttons_Hover",			
				command=
					function()
						DoModal("scripts/chooseplayer.lua");
					end
      },

      AnimButton
      {
        x=192,
				y=482,
				name="settings",
        animations={
          { key="normal", texture="titlescreen/settings/settings", animation="main", default=1},        
          { key="down", texture="titlescreen/settings/settings_down", animation="main"},
          { key="hover", texture="titlescreen/settings/settings_hover", animation="main"},
          { key="disabled", texture="titlescreen/settings/settings_disabled", animation="main"},
        },
        sound="audio/sfx/Monitor_Buttons_Click",
        rolloversound="audio/sfx/Monitor_Buttons_Hover",			
				command=
					function()
						DoModal("scripts/options.lua");
					end
      },
      
      AnimButton
      {
	  		x=520,
				y=475,
				name="help",
        animations={
          { key="normal", texture="titlescreen/help/help", animation="main", default=1},        
          { key="down", texture="titlescreen/help/help_down", animation="main"},
          { key="hover", texture="titlescreen/help/help_hover", animation="main"},
          { key="disabled", texture="titlescreen/help/help_disabled", animation="main"},
        },
        sound="audio/sfx/Monitor_Buttons_Click",
        rolloversound="audio/sfx/Monitor_Buttons_Hover",			
				command=
					function()
            ShowPopup("help01");						
					end
      },
      
      AnimButton
      {
	  		x=681,
				y=490,
				name="exit",
        animations={
          { key="normal", texture="titlescreen/exit/exit", animation="main", default=1},        
          { key="down", texture="titlescreen/exit/exit_down", animation="main"},
          { key="hover", texture="titlescreen/exit/exit_hover", animation="main"},
          { key="disabled", texture="titlescreen/exit/exit_disabled", animation="main"},
        },
        sound="audio/sfx/Monitor_Buttons_Click",
        rolloversound="audio/sfx/Monitor_Buttons_Hover",			
				command=
					function()
						PlaySound("POPUP-IN");
						result = DisplayDialog {
							"scripts/yesno.lua",
							body ="quitconfirm",
							title = "quittitle"
						};
						PlaySound("POPUP-OUT");
						if (result=='yes') then
							PostMessage( CreateNamedMessage( kQuitNow, "Quit" ) );
						end
					end
      },
			
			 Group 
      {
        AnimSprite
        {
          name='scanlines',
          x=474,y=485,-- from the center
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/scanlines/scanline", animation="main", default=1},
          },
        },        
        AnimSprite
        {
          name='proflines',
          x=80,y=508,-- from the center
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/scanlines/changeprofile", animation="main", default=1},
          },
        },        

      },



    AnimSprite
    {
      name='maggie',
      x=275,y=380,-- from the center
             
      xRef = 0, yRef = 0,
      animations={
        { key="idle", texture="characters/maggie/title_screen/maggie_title_blink", animation="main", default=1},        
        { key="idle2", texture="characters/maggie/title_screen/maggie_title_idle_01", animation="main"},
      },
    },      
    
    
     Window
      {
        x=405, y=510, w=kMax, h=kMax,
        name="namegroup",
        Bitmap
        {
          x=0, y=0,
          image="titlescreen/play/playernamebox",
        },
        Text
        {
          font = StandardButtonFont,
          name = "welcome",
          x=30,y=0,w=220,h=70,
          flags = kHAlignCenter + kVAlignCenter,
          label = "welcome"
        },
			},

    Button
			{
	  		x=302,
				y=455,
				name="gamemode1",
					type = kPush,
        sound="audio/sfx/Monitor_Buttons_Click",
        rolloversound="audio/sfx/Monitor_Buttons_Hover",					
				graphics = {
          "titlescreen/play/play",
          "titlescreen/play/play_click",
          "titlescreen/play/play_hover",
        },					
				command=

				function()
						if (CheckUsers()) then
							-- Tell TSettings what game mode we're entering
							SetCurrentGameMode(0);
							-- Switch to the appropriate screen				
							ProcessStart("scripts/mapmenu.lua");							
							SetState( kGameMode, "pregame" );
						end
				end				
			},
			
			

			
			--expiry text. may not show.
			Text
			{
				font = { standardFont,
        18,
        Color(255,0,0,255) },
				name = "betatext",
				x=10,y=10,w=kMax,h=80,
				flags = kHAlignLeft + kVAlignCenter,				
			};


      Group 
      {
        AnimSprite
        {
          name='bubbles2',
          x=770,y=163,-- from the center
          w=130, h=260,
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/bubbles/bubbles_top_half", animation="main", default=1},
          },
        },        

        AnimSprite
        {
          name='bubbles1',
          x=770,y=303,-- from the center
          w=130, h=260,
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/bubbles/bubbles_bottom_half", animation="main", default=1},
          },
        },        
      },

        AnimSprite
        {
          name='bubbles2',
          x=60,y=403,-- from the center
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/bubbles/small_bubbles", animation="main", default=1},
          },
        },        
      
      Group 
      {
        AnimSprite
        {
          name='lightning2',
          x=12,y=40,-- from the center
          
          xRef = 0, yRef = 0,
          animations={
            { key="idle", texture="titlescreen/lightning/lightning_top_half", animation="main", default=1},
          },
        },        

      },

		},
		
	}
}