// Tooltip Handler.
// Worthless Bums 2013.


function deleteUnitTooltip ()
{//echo("deleteUnitTooltip()");
	UnitTooltip.visible = false;
	return;
	/*
	if (isObject($UnitBackpanel))
	{
		$UnitBackpanel.safeDelete();
	}
	if (isObject($UnitNameText))
	{
		$UnitNameText.safeDelete();
	}
	if (isObject($UnitInfoText))
	{
		$UnitInfoText.safeDelete();
	}
	*/
}
function createUnitTooltip (%unit)
{//echo("createUnitTooltip()");
	deleteUnitTooltip();
	// Marine.
	if (isSquadMember(%unit))
	{
		setMarineTooltipInfo(%unit);
	}
	// Enemy.
	else
	{
		setEnemyTooltipInfo(%unit);
	}
	return;
	
/*
return;	// Disabled for now!
	// Delete any existing tooltip!
	deleteUnitTooltip();
	// Backpanel.
	%backPanelImage = "Sprites:UnitTooltipBackpanel";
	if (!isSquadMember(%unit))
	{
		%backPanelImage = "Sprites:EnemyTooltipBackpanel";
	}
	$UnitBackpanel = new Sprite()
	{
		SceneLayer = 0;
		scenegraph = levelSceneGraph;
		image = %backPanelImage;
		canSaveDynamicFields = "1";
		position = getWord(%unit.position, 0) + 10.0 SPC getWord(%unit.position, 1) - 10.0;
		size = "16.000 16.000";
	};
	addObjectToScene($UnitBackpanel);
	if (isSquadMember(%unit))
	{
		// Name.
		%nameColor = "255 255 255";
		switch (%unit.characterClass)
		{
			case 0:	%nameColor = "0 255 0";
			case 1:	%nameColor = "255 0 255";
			case 2:	%nameColor = "0 0 255";
			case 3:	%nameColor = "255 0 0";
			case 4:	%nameColor = "255 255 0";
		}
		$UnitNameText = new ImageFont();
		$UnitNameText.SceneLayer = $RenderedFontSceneLayer;
		$UnitNameText.Image = $RenderedFontImage;
		$UnitNameText.FontSize = $RenderedFontSize;
		$UnitNameText.BlendColor = %nameColor;
		$UnitNameText.Text = getRankName(%unit.rank) @ ". " @ %unit.name SPC "(" @ %unit.perks @ ")";
		$UnitNameText.Position = getWord(%unit.position, 0) + 10.0 SPC getWord(%unit.position, 1);
		addObjectToScene($UnitNameText);
	}
	// Info.
	// Marine.
	if (isSquadMember(%unit))
	{
		setMarineTooltipInfo(%unit);
	}
	// Enemy.
	else
	{
		setEnemyTooltipInfo(%unit);
	}
*/
}
function setMarineTooltipInfo (%unit)
{//echo("setMarineTooltipInfo()");
	/*
	// Calculate unit sight range!
	%radius = %unit.sight;
	// Hard cap of (max) 6 sight range!
	if (%radius > 6)
	{
		%radius = 6;
	}
	// Hard cap of (min) 1 sight range!
	else if (%radius < 1)
	{
		%radius = 1;
	}
	// Check for weapon attachment.
	if ((%unit.laserSprite).image !$= "Sprites:Flashlight")
	{
		%radius--;
	}
	*/
	// Increase radius if unit is on a lifted tile.
	if (isObject($mazeLiftedTiles[%unit.xIndex, %unit.yIndex]))
	{
		%radius++;
	}
	%text = "Damage.."			@ %unit.weapon.damage + %unit.arms				NL
			"Range....."		@ %unit.weapon.range		NL
			"Hit............" 	@ %unit.weapon.accuracy + %unit.arms * $armsAccuracyModifier @ "%"	NL
			"Armor......"		@ %unit.armor.armorRating	NL
			"Guard......"		@ 1 + %unit.power			NL
			"Repair....."		@ %unit.armor.repair;
	UnitTooltipReadout.bitmap = "../../../Sprites/1/assets/images/UI/Unit-Tooltip-Backpanel";
	UnitTooltipReadout.setText(%text);
	UnitTooltip.visible = true;
	/*
	%text = "???";
	%text = "[" @ getProjectileTypeName(%unit.weapon.projectileType) @ " Weapon]"	NL
			"Damage........."		@ %unit.weapon.damage + %unit.arms				NL
			"Range............"		@ %unit.weapon.range		NL
			"Hit Chance..." 		@ %unit.weapon.accuracy + %unit.arms * $armsAccuracyModifier @ "%"	NL
			""													NL
			"[Regulation Armor]"								NL
			"Protection..."			@ %unit.armor.armorRating	NL
			"Speed............"		@ %unit.armor.speed			NL
			""													NL
			"[Guard Mode]"										NL
			"Max Shots..."			@ 1 + %unit.power;
	$UnitInfoText = new ImageFont();
	$UnitInfoText.SceneLayer = $RenderedFontSceneLayer;
	$UnitInfoText.Image = $RenderedFontImage;
	$UnitInfoText.FontSize = $RenderedFontSize;
	$UnitInfoText.BlendColor = "255 255 255";
	$UnitInfoText.Text = %text;
	$UnitInfoText.Position = getWord(%unit.position, 0) + 9.0 SPC getWord(%unit.position, 1);
	addObjectToScene($UnitInfoText);
	*/
}
function setEnemyTooltipInfo (%unit)
{//echo("setEnemyTooltipInfo()");
	%text = "???";
	//%unit.name = "Bruton";	// For testing purposes only!
	switch$ (%unit.name)
	{
		case "Brute":
			%text = "BRUTES are melee units, relentless but slow.";
		case "Flamejack":
			%text = "FLAMEJACKS spit fire and are a general nuisance.";
		case "Revenant":
			%text = "REVENANT: ???";
		case "Hulk":
			%text = "HULK: ???";
		case "Bucket":
			%text = "BUCKETS are small and serve to distract.";
		case "Thopter":
			%text = "THOPTERS are fast but weak. Hit to slow.";
		case "Ripsaw":
			%text = "RIPSAWS are tough and mean. Do not ignore.";
		case "Tick":
			%text = "TICKS are evasive with high accuracy.";
		case "Amputator":
			%text = "AMPUTATORS are heavily armored and blitz.";
		case "Torgon":
			%text = "TORGONS are aliens with energy weapons.";
		case "TorSniper":
			%text = "TORSNIPERS are long range specialists.";
		case "TorScout":
			%text = "TORSCOUTS weak but can call for backup.";
		case "TorChaser":
			%text = "TORCHASERS are tough and nasty..";
		case "Sapper":
			%text = "SAPPERS throw boom and go boom.";
		case "Brainien":
			%text = "BRAINIEN: ???";
		case "Bruton":
			%text = "BRUTONS use shields to cover the front.";
		case "Gunship":
			%text = "GUNSHIP: ???";
		case "Matrix":
			%text = "MATRIX: ???";
		case "Patriarch":
			%text = "PATRIARCH: ???";
	}
	// Is this unit revealed (e.g. Engineer class talent "Target Scan")? If so, reveal more information!
	if (%unit.scanned)
	{
		%unitDamage = %unit.baseMeleeDamage;
		%unitRange = 1;
		%unitCanRange = "No";
		if (%unit.canRange)
		{
			%unitDamage = %unit.baseRangeDamage;
			%unitRange = mRound(%unit.range / 4);
			%unitCanRange = "Yes";
		}
		%unitAccuracy = %unit.attackModifier;
		%unitEvasion = %unit.evasion;
		%unitArmor = %unit.armorRating;
		%unitType = "Robot";
		if (%unit.isAlien)
		{
			%unitType = "Alien";
		}
		if (%unitCanRange $= "Yes")
		{
			%text = "Damage.."			@ %unitDamage			NL
					"Range....." 		@ %unitRange			NL
					"Hit............" 	@ %unitAccuracy @ "%"	NL
					"Armor......" 		@ %unitArmor			NL
					"Type....." 		@ %unitType;
		}
		else
		{
			%text = "Damage.."			@ %unitDamage			NL
					"Range....." 		@ %unitRange			NL
					"Hit............" 	@ "100%"				NL
					"Armor......" 		@ %unitArmor			NL
					"Type..." 			@ %unitType;
		}
	}
	else
	{
		%text = %text @ "\n" @ "[NO SCAN]";
	}
	UnitTooltipReadout.bitmap = "../../../Sprites/1/assets/images/UI/Enemy-Tooltip-Backpanel";
	UnitTooltipReadout.setText(%text);
	UnitTooltip.visible = true;
	/*
	$UnitInfoText = new ImageFont();
	$UnitInfoText.SceneLayer = $RenderedFontSceneLayer;
	$UnitInfoText.Image = $RenderedFontImage;
	$UnitInfoText.FontSize = $RenderedFontSize;
	$UnitInfoText.BlendColor = "255 255 255";
	$UnitInfoText.Text = %text;
	$UnitInfoText.Position = getWord(%unit.position, 0) + 9.0 SPC getWord(%unit.position, 1);
	*/
}