// Handles Squad Information Gui.
// Worthless Bums 2012.


// *Sigh.* Sometimes the squad inventory does not refresh properly. Pop and push to "resolve" the issue.
function refreshSquadInventoryGui ()
{//echo("refreshSquadInventoryGui()");
	canvas.popDialog(squadInfoGui);
	canvas.pushDialog(squadInfoGui);
}

// Updates the data in the Squad Information Gui.
function updateSquadInfoGui ()
{//echo("updateSquadInfoGui()");
	// Hook to new GUI update function!
	updateInventoryTabInformation();
	
	// Don't update if the active character doesn't exist!
	if (!isObject($playerSquad[$activeCharacter]))
	{
		return;
	}
	// Don't update if weapons haven't sync'd!
	if (($leaderPersist 	&& ($playerSquad[0].weapon).imagemapname $= "")	||
		($scoutPersist 		&& ($playerSquad[1].weapon).imagemapname $= "")	||
		($grenadierPersist	&& ($playerSquad[2].weapon).imagemapname $= "")	||
		($supportPersist	&& ($playerSquad[3].weapon).imagemapname $= ""))
	{
		return;
	}
	
	// Actually update squad info gui since we're using it again!
	if ($leaderPersist	&&
		isObject($playerSquad[0]))
	{//echo("leader weapon imagemapname" SPC "\"" @ $playerSquad[0].weapon.imageMapName @ "\"");
		%character = $playerSquad[0];
		leaderInfoAvatar.bitmap = "../../../Sprites/1/assets/images/Squad Members/Armors/" @ getCharacterClassName(%character.characterClass) @ "_South";
		leaderAvatarWeapon.bitmap = "../../../Sprites/1/assets/images/Weapons/" @ strreplace(%character.weapon.imageMapName, "ImageMap", "") @ ".png";
		leaderNameText.text = getRankName(%character.rank) @ ". " @ %character.name;// SPC "(" @ %character.perks @ ")";
		leaderPerkText.text = "(" @ %character.perks @ ")";
		leaderExperience.text = "XP " @ %character.experience;
		leaderHealth.text = "HP " @ %character.currentHealth @ "/" @ %character.maxHealth;
		leaderActionPoints.text = "AP " @ %character.currentACtionPoints @ "/" @ %character.maxActionPoints;
		
		leaderKills.visible = false;
		leaderPower.visible = false;
		leaderSpeed.visible = false;
		leaderEndurance.visible = false;
		leaderBash.visible = false;
		leaderDemolitions.visible = false;
		leaderArms.visible = false;
		
		leaderInfoAvatar.visible = true;
		leaderAvatarWeapon.visible = true;
		leaderNameText.visible = true;
		leaderExperience.visible = true;
		leaderHealth.visible = true;
		leaderActionPoints.visible = true;
	}
	else
	{
		leaderKills.visible = false;
		leaderPower.visible = false;
		leaderSpeed.visible = false;
		leaderEndurance.visible = false;
		leaderBash.visible = false;
		leaderDemolitions.visible = false;
		leaderArms.visible = false;
		
		leaderInfoAvatar.visible = false;
		leaderAvatarWeapon.visible = false;
		leaderNameText.visible = false;
		leaderPerkText.visible = false;
		leaderExperience.visible = false;
		leaderHealth.visible = false;
		leaderActionPoints.visible = false;
	}
	
	if ($scoutPersist	&&
		isObject($playerSquad[1]))
	{//echo("scout weapon imagemapname" SPC "\"" @ $playerSquad[1].weapon.imageMapName @ "\"");
		%character = $playerSquad[1];
		scoutInfoAvatar.bitmap = "../../../Sprites/1/assets/images/Squad Members/Armors/" @ getCharacterClassName(%character.characterClass) @ "_South";
		scoutAvatarWeapon.bitmap = "../../../Sprites/1/assets/images/Weapons/" @ strreplace(%character.weapon.imageMapName, "ImageMap", "") @ ".png";
		scoutNameText.text = getRankName(%character.rank) @ ". " @ %character.name;// SPC "(" @ %character.perks @ ")";
		scoutPerkText.text = "(" @ %character.perks @ ")";
		scoutExperience.text = "XP " @ %character.experience;
		scoutHealth.text = "HP " @ %character.currentHealth @ "/" @ %character.maxHealth;
		scoutActionPoints.text = "AP " @ %character.currentACtionPoints @ "/" @ %character.maxActionPoints;
		
		scoutKills.visible = false;
		scoutPower.visible = false;
		scoutSpeed.visible = false;
		scoutEndurance.visible = false;
		scoutBash.visible = false;
		scoutDemolitions.visible = false;
		scoutArms.visible = false;
		
		scoutInfoAvatar.visible = true;
		scoutAvatarWeapon.visible = true;
		scoutNameText.visible = true;
		scoutExperience.visible = true;
		scoutHealth.visible = true;
		scoutActionPoints.visible = true;
	}
	else
	{
		scoutKills.visible = false;
		scoutPower.visible = false;
		scoutSpeed.visible = false;
		scoutEndurance.visible = false;
		scoutBash.visible = false;
		scoutDemolitions.visible = false;
		scoutArms.visible = false;
		
		scoutInfoAvatar.visible = false;
		scoutAvatarWeapon.visible = false;
		scoutNameText.visible = false;
		scoutPerkText.visible = false;
		scoutExperience.visible = false;
		scoutHealth.visible = false;
		scoutActionPoints.visible = false;
	}
	
	if ($grenadierPersist	&&
		isObject($playerSquad[2]))
	{//echo("grenadier weapon imagemapname" SPC "\"" @ $playerSquad[2].weapon.imageMapName @ "\"");
		%character = $playerSquad[2];
		grenadierInfoAvatar.bitmap = "../../../Sprites/1/assets/images/Squad Members/Armors/" @ getCharacterClassName(%character.characterClass) @ "_South";
		grenadierAvatarWeapon.bitmap = "../../../Sprites/1/assets/images/Weapons/" @ strreplace(%character.weapon.imageMapName, "ImageMap", "") @ ".png";
		grenadierNameText.text = getRankName(%character.rank) @ ". " @ %character.name;// SPC "(" @ %character.perks @ ")";
		grenadierPerkText.text = "(" @ %character.perks @ ")";
		grenadierExperience.text = "XP " @ %character.experience;
		grenadierHealth.text = "HP " @ %character.currentHealth @ "/" @ %character.maxHealth;
		grenadierActionPoints.text = "AP " @ %character.currentACtionPoints @ "/" @ %character.maxActionPoints;
		
		grenadierKills.visible = false;
		grenadierPower.visible = false;
		grenadierSpeed.visible = false;
		grenadierEndurance.visible = false;
		grenadierBash.visible = false;
		grenadierDemolitions.visible = false;
		grenadierArms.visible = false;
		
		grenadierInfoAvatar.visible = true;
		grenadierAvatarWeapon.visible = true;
		grenadierNameText.visible = true;
		grenadierExperience.visible = true;
		grenadierHealth.visible = true;
		grenadierActionPoints.visible = true;
	}
	else
	{
		grenadierKills.visible = false;
		grenadierPower.visible = false;
		grenadierSpeed.visible = false;
		grenadierEndurance.visible = false;
		grenadierBash.visible = false;
		grenadierDemolitions.visible = false;
		grenadierArms.visible = false;
		
		grenadierInfoAvatar.visible = false;
		grenadierAvatarWeapon.visible = false;
		grenadierNameText.visible = false;
		grenadierPerkText.visible = false;
		grenadierExperience.visible = false;
		grenadierHealth.visible = false;
		grenadierActionPoints.visible = false;
	}
	
	if ($supportPersist	&&
		isObject($playerSquad[3]))
	{//echo("support weapon imagemapname" SPC "\"" @ $playerSquad[3].weapon.imageMapName @ "\"");
		%character = $playerSquad[3];
		supportInfoAvatar.bitmap = "../../../Sprites/1/assets/images/Squad Members/Armors/" @ getCharacterClassName(%character.characterClass) @ "_South";
		supportAvatarWeapon.bitmap = "../../../Sprites/1/assets/images/Weapons/" @ strreplace(%character.weapon.imageMapName, "ImageMap", "") @ ".png";
		supportNameText.text = getRankName(%character.rank) @ ". " @ %character.name;// SPC "(" @ %character.perks @ ")";
		supportPerkText.text = "(" @ %character.perks @ ")";
		supportExperience.text = "XP " @ %character.experience;
		supportHealth.text = "HP " @ %character.currentHealth @ "/" @ %character.maxHealth;
		supportActionPoints.text = "AP " @ %character.currentACtionPoints @ "/" @ %character.maxActionPoints;
		
		supportKills.visible = false;
		supportPower.visible = false;
		supportSpeed.visible = false;
		supportEndurance.visible = false;
		supportBash.visible = false;
		supportDemolitions.visible = false;
		supportArms.visible = false;
		
		supportInfoAvatar.visible = true;
		supportAvatarWeapon.visible = true;
		supportNameText.visible = true;
		supportExperience.visible = true;
		supportHealth.visible = true;
		supportActionPoints.visible = true;
	}
	else
	{
		supportKills.visible = false;
		supportPower.visible = false;
		supportSpeed.visible = false;
		supportEndurance.visible = false;
		supportBash.visible = false;
		supportDemolitions.visible = false;
		supportArms.visible = false;
		
		supportInfoAvatar.visible = false;
		supportAvatarWeapon.visible = false;
		supportNameText.visible = false;
		supportPerkText.visible = false;
		supportExperience.visible = false;
		supportHealth.visible = false;
		supportActionPoints.visible = false;
	}
}