require( "scripts/style.lua" );

--local gEnterNameValue = "";
function CheckUsers()
	if (GetNumUsers() == 0) then
		gEnterNameValue = "";
		name = DoModal("scripts/entername1.lua");
		if (not(name == nil)) then
			CreateNewUser(name);
			SetWelcomeName();
			return false;
		end
		return false ;
	elseif (not(SettingsInited())) then
		DoModal("scripts/chooseplayer.lua");		
		return true;
	else
		return true;
	end
end

local playerCreated = false;

menuBtnStartY = 150;
menuBtnDistY = 41;

MakeDialog
{
    Bitmap
    {
      x = 0, y = 0,
	    image="interface/black",
	    scale = 130,
    },
  
  MainMenu
  {
    x = 0, y = 0,
		w = ScreenWight, h = ScreenHeight,
	  name="mainmenu",
	  alphaStep = 2.5,
	  fit=true;

    Bitmap
    {
      x = 0, y = 0,
	    name="backgroundimage",
	    image="Menu/back",
    },
	
  		-- мужики
		AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="anim_man",
			image="assets/menu/anims/stealingstuff.xml",
			anim="assets/menu/anims/stealingstuff_move.xml",
		},
		
		-- со статуей
  		AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="anim_man2",
			image="assets/menu/anims/stealingstuff2.xml",
			anim="assets/menu/anims/stealingstuff2_move.xml",
		},

		-- с вазой
  		AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="anim_man3",
			image="assets/menu/anims/stealingstuff3.xml",
			anim="assets/menu/anims/stealingstuff3_move.xml",
		},

		 -- со слоном
  	AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="anim_man4",
			image="assets/menu/anims/stealingstuff4.xml",
			anim="assets/menu/anims/stealingstuff4_move.xml",
		},

  	AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="window1",
			image="assets/menu/anims/window1.xml",
			anim="assets/menu/anims/window1_move.xml",
		},

  	AnimObject
		{
			x = 0, y = 0,
			w = kMax, h = kMax,
			name="window2",
			image="assets/menu/anims/window2.xml",
			anim="assets/menu/anims/window2_move.xml",
		},

		  -- машина
		  Bitmap
		  {
			  x=0,
			  y=291,
			  name="car",
			  image="Menu/car",
		  },
  		
		  -- фон меню
		  Bitmap
		  {
			  x=22,
			  y=400,
			  name="menu_fon",
			  image="Menu/menu_fon",
			},
  			
		  SetStyle( MenuButtonStyle1 ),
		  -- кнопка начала игры
		  QEMenuButton
		  {
			  font = StandardButtonFont,
			  name = "start_game",
			  StartGameLabel("start_game"),
			  x=kCenter-12-326,
			  y=86+400,
				default=true,
			  command=	 
			   function()
			      Pause();
			      if (CheckUsers()) then 
						DoModal("scripts/loading.lua");
			      end
            Resume();
          end
		  },
		  SetStyle( MenuButtonStyle2 ),
		  -- кнопка выбора профиля
		  QEMenuButton
		  {
			  x=kCenter-22-340+26,
			  y=menuBtnStartY + menuBtnDistY+400,
			  name="select_profile",
			  MenuButtonLabel("select_profile"),
			  command=
				  function()
					  Pause();
					  PlaySfx(mainMenuOpenSound);
					  DoModal("scripts/chooseplayer.lua");
					  SetWelcomeName();
					  Resume();
				  end
		  },
		  -- кнопка опций
		  QEMenuButton
		  {
			  x=kCenter-22-340+26,
			  y=menuBtnStartY + menuBtnDistY*2+400,
			  name = "options",
--				label = "",
			  MenuButtonLabel("optionsbutton");
			  type = kPush,
				  command=
					  function()
						  Pause();
						  PlaySfx(mainMenuOpenSound);
						  DoModal("scripts/options.lua");							  
						  Resume();
					  end
		  },
		  -- кнопка выхода
		  QEMenuButton
		  {
			  x=kCenter-22-340+26,
			  y=menuBtnStartY + menuBtnDistY*3+400,
			  name="quit",
			   cancel=true,
--				label = "",
			  MenuButtonLabel("quit"),
			  type = kPush,
			  command=
				  function()
				  QuitGame();
				  end
		  },
		  -- лев
		  Bitmap
		  {
			  x=728,
			  y=298,
			  name="lion",
			  image="Menu/statueLeon",
		  },
  		AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  name="anim_rain",
			  image="assets/fx/rain.lua",
			  anim="assets/menu/anims/rain_move.xml",
		  },

		  Bitmap
		  {
			  x=0,
			  y=0,
			  image="Menu/back_md",
		  },
		  
    	AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  image="assets/menu/anims/drop1.xml",
			  anim="assets/menu/anims/drop1_move.xml",
		  },
    	AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  image="assets/menu/anims/drop2.xml",
			  anim="assets/menu/anims/drop2_move.xml",
		  },
    	AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  image="assets/menu/anims/drop3.xml",
			  anim="assets/menu/anims/drop3_move.xml",
		  },
    	AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  image="assets/menu/anims/drop4.xml",
			  anim="assets/menu/anims/drop4_move.xml",
		  },
    	AnimObject
		  {
			  x = 0, y = 0,
			  w = kMax, h = kMax,
			  image="assets/menu/anims/drop5.xml",
			  anim="assets/menu/anims/drop5_move.xml",
		  },
		  
		  Bitmap
		  {
			  x=712,
			  y=640,
			  image="assets/menu/welcome.png",
		  },

		  
		  Text
		  {
			  x=662,y=682,w=400,h=200,
			  flags = kHAlignCenter + kVAlignTop,
			  WelcomeTextLabel( "welcome" )
		  };
		  Text
		  {
			  name = "welcome",
			  x=662,y=712,w=400,h=200,
			  flags = kHAlignCenter + kVAlignTop,
			  PlayerNameLabel( "welcome" )
		  };
		  --Bitmap
		  --{
--			  x=556,
	--		  y=402,
		--	  image="Menu/back_md1",
		  --},

		 	},
}

--EnableWindow("start_game", false);
SetWelcomeName();
