require( "scripts/style.lua" );

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

local playerCreated = false;

menuBtnStartY = 82-36;
menuBtnDistY = 36;

MakeDialog
{
	FadeWindow
	{
		x = 0, y = 0,
		w = ScreenWight, h = ScreenHeight,
		name="mainmenu",
		alphaStep = 2.5,
	
		fit=true;
		Bitmap
		{
			name="backgroundimage",
			image="menu/back",
		},

		MainMenu
		{
			name="script",
			w = 1024,
			h = 768,
			
			QEMenuButton
			{
				name = "switch_light_btn",
				x = 48,
				y = 388,
				graphics = { "menu/light_on", "menu/light_off", "menu/light_on", "menu/light_off", "menu/light_on" },
				type = kToggle,
				command =
					function()
						PlaySfx(mainLampSwitch);
						SwitchLight();
					end
			},
			-- кнопка начала игры
			QEMenuButton
			{
				name = "start_game_btn",
				x = 230,
				y = 370,
				graphics = { "Menu/start_game_free", "Menu/start_game_press", "Menu/start_game_over", "Menu/start_game_free" },
				default=true,
				type = kPush,
				command =
					function()
						if (CheckUsers())
						then
							SetWelcomeName();
							DoModal("scripts/loading.lua");
						end;
					end
			},
			-- кнопка выбора профиля
			QEMenuButton
			{
				name = "choose_profile_btn",
				x = 210,
				y = 416,
				graphics = { "Menu/choose_profile_free", "Menu/choose_profile_press", "Menu/choose_profile_over", "Menu/choose_profile_free" },
				type = kPush,
				command =
					function()
						PlaySfx(mainMenuOpenSound);
						DoModal("scripts/chooseplayer.lua");
						SetWelcomeName();
					end
			},

			QEMenuButton
			{
				name = "about_the_movie_btn",
				x = 170,
				y = 478,
				graphics = { "Menu/about_the_movie_free", "Menu/about_the_movie_press", "Menu/about_the_movie_over", "Menu/about_the_movie_free" },
				type = kPush,
				command =
					function()
						PlaySfx(mainMenuOpenSound);
						DoModal("scripts/about_the_movie.lua");
					end
			},
			-- кнопка опций
			QEMenuButton
			{
				name = "options_btn",
				x = 230,
				y = 535,
				graphics = { "menu/options_free", "menu/options_press", "menu/options_over", "menu/options_free" },
				type = kPush,
				command =
					function()
						PlaySfx(mainMenuOpenSound);
						DoModal("scripts/options.lua");
					end
			},
			-- кнопка выхода
			QEMenuButton
			{
				name = "quit_btn",
				x = 245,
				y = 595,
				graphics = { "menu/quit_free", "menu/quit_press", "menu/quit_over", "menu/quit_free" },
				cancel=true,
				type = kPush,
				command =
					function()
						PlaySfx(mainMenuOpenSound);
						result = DisplayDialog {
							"scripts/yesno_quit.lua",
							body ="quitconfirm",
							title = "quittitle"
						};

						if (result=='yes') then
							SaveSettings();
							CloseFade("mainmenu","PostMessage(CreateNamedMessage(kQuitNow,'Quit'))");
						end
					end
			},
			
			-- пустая бмп для вывода текста поверх всего
			Bitmap
			{
				name="empty",
				x = 40, y = 720, w = 1000, h = 200,
				Text
				{
					font = WelcomeFont,
					name = "welcome",
					x = 0, y = 0, w = 1000, h = 200,
					flags = kHAlignCenter + kVAlignTop,
					label = "welcome"
				};
			},
		},
	},
}

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