// Handles Main Menu Functionality.
// Worthless Bums 2012.


function animateMainMenuLogo ()
{//echo("animateMainMenuLogo()");
mainMenuLogo.setBitmap("../../../Sprites/1/assets/images/UI/Logo/smLogo10");
return;	// Code below has errors with expandPath() not finding a relative path!
	mainMenuLogo.setBitmap("../../../Sprites/1/assets/images/UI/blank (1x1)");		// Starts blank!
	%frameStepDelay = 40;
	%toWhiteFrames = 20;
	for (%i = 1; %i <= %toWhiteFrames; %i++)
	{
		mainMenuLogo.schedule(%frameStepDelay * %i, "setBitmap", "../../../Sprites/1/assets/images/UI/Logo/smLogo" @ %i);
	}
	for (%i = %toWhiteFrames; %i >= (%toWhiteFrames / 2); %i--)
	{
		mainMenuLogo.schedule(%frameStepDelay * (%toWhiteFrames - %i + %toWhiteFrames), "setBitmap", "../../../Sprites/1/assets/images/UI/Logo/smLogo" @ %i);
	}
	mainMenuLogo.schedule(%frameStepDelay * 31, "setBitmap", "../../../Sprites/1/assets/images/UI/Logo/smLogo10");
}
function updateMainMenuFrameContainerPosition ()
{//echo("updateMainMenuFrameContainerPosition()");
	%y = getWord($Game::Resolution, 1) / 2 - getWord(mainMenuFrameContainer.extent, 1) / 2;
	%x = 0;
	mainMenuFrameContainer.setPosition(%x, %y);
	mainMenuSidePanel.setPosition(0, 0);
	updateMainMenuSaveStateDeckLevelPosition();
	updateMainMenuVersionTextPosition();
}
function updateMainMenuShipPanelPosition ()
{//echo("updateMainMenuShipPanelPosition()");
return;
	%xBuffer = 0;
	%x = getWord($Game::Resolution, 0) / 2 - getWord(mainMenuShipFrame.extent, 0) + %xBuffer;
	%yBuffer = 32;
	%y = getWord($Game::Resolution, 1) / 2 - getWord(mainMenuShipFrame.extent, 1) / 2 - %yBuffer;
	mainMenuShipPanel.setPosition(%x, %y);
}
function updateMainMenuSidePanelPosition ()
{//echo("updateMainMenuSidePanelPosition()");
	%xBuffer = 96;
	if (getWord($Game::Resolution, 0) == 800)
	{
		%xBuffer -= 200;
	}
	else if (getWord($Game::Resolution, 0) == 1024)
	{
		%xBuffer -= 120;
	}
	else if (getWord($Game::Resolution, 0) == 800)
	{
		%xBuffer -= 0;
	}
	%x = getWord($Game::Resolution, 0) / 2 + getWord(mainMenuLogo.extent, 0) / 2 + %xBuffer;
	%yPadding = 267;	// The vertical padding for all elements in the side panel.
	%yBuffer = 32;
	%y = getWord($Game::Resolution, 1) / 2 - %yPadding - %yBuffer;
	mainMenuSidePanel.setPosition(%x, %y);
	mainMenuSidePanel.position = %x SPC %y;
}
function updateMainMenuSaveStateDeckLevelPosition ()
{//echo("updateMainMenuSaveStateDeckLevelPosition()");
	if ($NewGamePlus > 0)
	{//echo("NGP DETECTED!");
		%xBuffer = -122;
		%x = getWord($Game::Resolution, 0) / 2 + %xBuffer;
		%yBuffer = 128;
		%y = getWord($Game::Resolution, 1) / 2 + %yBuffer;
		SaveStateDeckLevel.setPosition(%x, %y);
	}
	else
	{
		%xBuffer = -40;
		if (SaveStateDeckLevel.text !$= "I.S.S. Orion")
		{
			%xBuffer = -100;
		}
		%x = getWord($Game::Resolution, 0) / 2 + %xBuffer;
		%yBuffer = 128;
		%y = getWord($Game::Resolution, 1) / 2 + %yBuffer;
		SaveStateDeckLevel.setPosition(%x, %y);
	}
}
function updateMainMenuSaveStateDeckLevelText ()
{//echo("updateMainMenuSaveStateDeckLevelText()");//echo("$dungeonLevel =" SPC $dungeonLevel);//echo("$saveStateLevel =" SPC $saveStateLevel);
	if ($gameInProgress	||
		$validSaveState	||
		checkSaveState())
	{//echo("CHECKING SAVE STATE!");
		%ngpString = "";
		%xBuffer = -100;
		if ($NewGamePlus > 0)
		{
			%ngpString = " (NG+" @ $NewGamePlus @ ")";
			%xBuffer = -122;
		}
		//SaveStateDeckLevel.text = $overworldLocation @ ", Level " @ $dungeonLevel @ %ngpString;
		SaveStateDeckLevel.setText($saveStateDeck @ ", Level " @ $dungeonLevel @ %ngpString);
		%x = getWord($Game::Resolution, 0) / 2 + %xBuffer;
		%yBuffer = 128;
		%y = getWord($Game::Resolution, 1) / 2 + %yBuffer;
		SaveStateDeckLevel.setPosition(%x, %y);
	}
	else
	{//echo("GAME NOT IN PROGRESS! CHECKING SAVE STATE!");
		if ($validSaveState)
		{//echo("VALID SAVE STATE FOUND!");
			SaveStateDeckLevel.setText($saveStateDeck @ ", Level " @ $saveStateLevel);
		}
		else
		{
			SaveStateDeckLevel.text = "I.S.S. Orion";
		}
	}
}
function updateMainMenuVersionTextPosition ()
{//echo("updateMainMenuVersionTextPosition()");
	%x = 18;
	%y = getWord($Game::Resolution, 1) - 32;
	versionText.setPosition(%x, %y);
	creditsText.setPosition(32, %y - 8);
}
function pushMainMenu ()
{//echo("pushMainMenu()");
	//initializeSteamAchievements();
	hideHud();
	$guiInProgress = false;
	Canvas.pushDialog(mainMenuGui);
	$mainMenuPushed = true;
	updateMainMenuFrameContainerPosition();
	schedule(50, 0, "updateMainMenuFrameContainerPosition");
	// SERIOUSLY WHY DOES THIS NOT WORK SOMETIMES?
	schedule(100, 0, "updateMainMenuFrameContainerPosition");
	schedule(250, 0, "updateMainMenuFrameContainerPosition");
	schedule(500, 0, "updateMainMenuFrameContainerPosition");
	schedule(1000, 0, "updateMainMenuFrameContainerPosition");
	schedule(2000, 0, "updateMainMenuFrameContainerPosition");
	schedule(3000, 0, "updateMainMenuFrameContainerPosition");
	schedule(4000, 0, "updateMainMenuFrameContainerPosition");
	schedule(5000, 0, "updateMainMenuFrameContainerPosition");
	updateMainMenuSaveStateDeckLevelText();
	//if (mainMenuLogo.bitmap $= "../../../Sprites/1/assets/images/blank (1x1)")	// Prevents multiple firings during splash screen sequence.
																					// Has the side effect of also blocking main menu push from animating the logo!
	if (strstr(mainMenuLogo.bitmap, "blank (1x1)") >= 0)
	{
		animateMainMenuLogo();
	}
}
function popMainMenu ()
{//echo("popMainMenu()");
	Canvas.popDialog(mainMenuGui);
	$mainMenuPushed = false;
	showHud();
}