// Ship Overview Handler.
// Worthless Bums 2013.


function pushShipOverview ()
{//echo("pushShipOverview()");
	// Pre-Push GUI stuff.
	// Generate deck invasions, if any.
	//setRandomDeckInvasions();
	//invadeAllDecks();			// For testing purposes only (Invasion GUI icon).
	//printInvadedDecks();		// For testing purposes only! Debug printing!
	// Mark invasions on the deck gui.
	// Nothing here yet!
	
	shipUIMainBackground.bitmap = "../../../Sprites/1/assets/images/UI/Backgrounds/ShipOverview";
	
	$timescale = 0;
	// Hide non-demo decks!
	if ($gameIsDemo)
	{
		shipUIMedicalDeck.visible = false;
		shipUIArmoryDeck.visible = false;
		shipUIBridgeDeck.visible = false;
		shipUIAlienDeck.visible = false;
	}
	// Hide cleared decks.
	if ($commandDeckLevel >= 5)
	{
		shipUICommandDeck.visible = false;
	}
	if ($engineeringDeckLevel >= 5)
	{
		shipUIEngineeringDeck.visible = false;
	}
	if ($medicalDeckLevel >= 5)
	{
		shipUIMedicalDeck.visible = false;
	}
	if ($armoryDeckLevel >= 5)
	{
		shipUIArmoryDeck.visible = false;
	}
	if ($bridgeDeckLevel >= 5)
	{
		shipUIBridgeDeck.visible = false;
	}
	// Only reveal the Alien Deck when the rest of the ship is cleared!
	if ($commandDeckLevel < 5		||
		$engineeringDeckLevel < 5	||
		$medicalDeckLevel < 5		||
		$armoryDeckLevel < 5		||
		$bridgeDeckLevel < 5)
	{
		shipUIAlienDeck.visible = false;
	}
	else
	{
		shipUIAlienDeck.visible = true;
	}
	Canvas.pushDialog(shipUI);
	// Select the current deck.
	switch$ ($overworldLocation)
	{
		case "Command Deck":		commandDeckSelected();
		case "Engineering Deck":	engineeringDeckSelected();
		case "Medical Deck":		medicalDeckSelected();
		case "Armory Deck":			armoryDeckSelected();
		case "Bridge Deck":			bridgeDeckSelected();
		case "Alien Deck":			alienDeckSelected();
	}
}
function popShipOverview ()
{//echo("popShipOverview()");
	Canvas.popDialog(shipUI);
	$timescale = 0;
}
function setShipUIDeckInfo (%deck)
{//echo("setShipUIDeckInfo()");
	// Set deck text information.
	switch$ (%deck)
	{
		case "Command Deck":
			%descriptionText = "\c8";
			%deckIntegrity = $ship.commandDeckIntegrity;
			%deckMaxIntegrity = $ship.commandDeckMaxIntegrity;
			
		case "Engineering Deck":
			%descriptionText = "\c4";
			%deckIntegrity = $ship.engineeringDeckIntegrity;
			%deckMaxIntegrity = $ship.engineeringDeckMaxIntegrity;
			
		case "Medical Deck":
			%descriptionText = "\c1";
			%deckIntegrity = $ship.medicalDeckIntegrity;
			%deckMaxIntegrity = $ship.medicalDeckMaxIntegrity;
			
		case "Armory Deck":
			%descriptionText = "\c5";
			%deckIntegrity = $ship.armoryDeckIntegrity;
			%deckMaxIntegrity = $ship.armoryDeckMaxIntegrity;
			
		case "Bridge Deck":
			%descriptionText = "\c3";
			%deckIntegrity = $ship.bridgeDeckIntegrity;
			%deckMaxIntegrity = $ship.bridgeDeckMaxIntegrity;
			
		case "Alien Deck":
			%descriptionText = "\c3";
			%deckIntegrity = $ship.alienDeckIntegrity;
			%deckMaxIntegrity = $ship.alienDeckMaxIntegrity;
	}
	%descriptionText = /*%descriptionText @*/ %deck;
	shipUIDescription.setText(%descriptionText);
	// Set deck integrity bar.
	%integrityBarHeight = 13;
	%integrityBarWidth = %deckIntegrity / %deckMaxIntegrity;
	%integrityBarWidth = mFloor(%integrityBarWidth * 108);
	DeckIntegrityBar.extent = %integrityBarWidth SPC %integrityBarHeight;
}
function clearDeckSelection ()
{//echo("clearDeckSelection()");
	shipUICommandDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/CommandDeck");
	shipUIEngineeringDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/EngineeringDeck");
	shipUIMedicalDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/MedicalDeck");
	shipUIArmoryDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/ArmoryDeck");
	shipUIBridgeDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/BridgeDeck");
	shipUIAlienDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/AlienDeck");
}
// Deck Selection Button Functions.
function commandDeckSelected ()
{//echo("commandDeckSelected()");
	clearDeckSelection();
	shipUICommandDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/CommandDeck_s");
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/CommandDeckIcon");
	setShipUIDeckInfo("Command Deck");
	DeckIntegrityText.setText($ship.commandDeckIntegrity @ "/" @ $ship.commandDeckMaxIntegrity);
	$nextDeckSelection = "Command Deck";	// Set deck location the player wishes to go to.
	DeckDifficultyText.setText("Easy");
}
function engineeringDeckSelected ()
{//echo("engineeringDeckSelected()");
	clearDeckSelection();
	shipUIEngineeringDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/EngineeringDeck_s");
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/EngineeringDeckIcon");
	setShipUIDeckInfo("Engineering Deck");
	DeckIntegrityText.setText($ship.engineeringDeckIntegrity @ "/" @ $ship.engineeringDeckMaxIntegrity);
	$nextDeckSelection = "Engineering Deck";	// Set deck location the player wishes to go to.
	DeckDifficultyText.setText("Easy");
}
function medicalDeckSelected ()
{//echo("medicalDeckSelected()");
	// Reset all ship deck bitmaps.
	clearDeckSelection();
	// Set this deck bitmap.
	shipUIMedicalDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/MedicalDeck_s");
	// Set Deck Icon bitmap.
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/MedicalDeckIcon");
	// Set deck info.
	setShipUIDeckInfo("Medical Deck");
	DeckIntegrityText.setText($ship.medicalDeckIntegrity @ "/" @ $ship.medicalDeckMaxIntegrity);
	// Set deck location the player wishes to go to.
	$nextDeckSelection = "Medical Deck";	// Set deck location the player wishes to go to.
	// Set Deck Difficulty Text.
	DeckDifficultyText.setText("Normal");
}
function armoryDeckSelected ()
{//echo("armoryDeckSelected()");
	clearDeckSelection();
	shipUIArmoryDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/ArmoryDeck_s");
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/ArmoryDeckIcon");
	DeckIntegrityText.setText($ship.armoryDeckIntegrity @ "/" @ $ship.armoryDeckMaxIntegrity);
	setShipUIDeckInfo("Armory Deck");
	$nextDeckSelection = "Armory Deck";	// Set deck location the player wishes to go to.
	DeckDifficultyText.setText("Hard");
}
function bridgeDeckSelected ()
{//echo("bridgeDeckSelected()");
	clearDeckSelection();
	shipUIBridgeDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/BridgeDeck_s");
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/BridgeDeckIcon");
	DeckIntegrityText.setText($ship.bridgeDeckIntegrity @ "/" @ $ship.bridgeDeckMaxIntegrity);
	setShipUIDeckInfo("Bridge Deck");
	$nextDeckSelection = "Bridge Deck";	// Set deck location the player wishes to go to.
	DeckDifficultyText.setText("Hard");
}
function alienDeckSelected ()
{//echo("alienDeckSelected()");
	clearDeckSelection();
	shipUIAlienDeck.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/AlienDeck_s");
	DeckIcon.setBitmap("../../../Sprites/1/assets/images/UI/ShipUI/AlienDeckIcon");
	DeckIntegrityText.setText($ship.alienDeckIntegrity @ "/" @ $ship.alienDeckMaxIntegrity);
	setShipUIDeckInfo("Alien Deck");
	$nextDeckSelection = "Alien Deck";	// Set deck location the player wishes to go to.
	DeckDifficultyText.setText("???");
}
// Ship Overview onward button pressed.
function onwardShipUiButton ()
{//echo("onwardShipUiButton()");
	if ($nextDeckSelection !$= "Command Deck"		&&
		$nextDeckSelection !$= "Engineering Deck"	&&
		$nextDeckSelection !$= "Medical Deck"		&&
		$nextDeckSelection !$= "Armory Deck"		&&
		$nextDeckSelection !$= "Bridge Deck"		&&
		$nextDeckSelection !$= "Alien Deck")
	{//echo("1");
		playAudio("Audio:invalidAction", EffectsAudioVolume.value);
		return;
	}
	$overworldLocation = $nextDeckSelection;
	Canvas.hideCursor();
	Canvas.popDialog(endLevelScreenGui);
	popShipOverview();
	$deathScreenPushed = false;
	$timescale = 1;
	continueTestStairs();
}