#include "Data/Levels/Common/Tutorial/Scripts/DialogsFades.bhass"
#include "Data/Levels/Common/Tutorial/Scripts/PatchFades.bhass"
#include "Data/Levels/Common/Tutorial/Scripts/SkinFades.bhass"
#include "Data/Levels/Common/Tutorial/Scripts/Utilities.bhass"

CTutorial@ pTutorial;
CLocalizer@ pLocalizer;
CGameText@ pText;
CFloat2 vLeftPosition;
CFloat2 vRightPosition;
CGameSkin@ pMarvin;
CGameSkin@ pMartian;
CGameSkin@ pHeather;
CGameSkin@ pBarney;
CGameText@ pLeftNameBlack;
CGameText@ pRightNameBlack;
CGameText@ pLeftNameWhite;
CGameText@ pRightNameWhite;
uint64 musicID;

//------------------------------------------------ Init/Release ---------------------------------------------------
void InitTutorial()
{
    @pTutorial = GetGame().GetCurrentLevel().GetTutorial();
    @pLocalizer = GetGame().GetLocalizer();
    @pText = pTutorial.GetGameText("Text");
    vLeftPosition.x = -350.0f;
    vLeftPosition.y = 250.0f;
    vRightPosition.x = 350.0f;
    vRightPosition.y = 250.0f;
	@pLeftNameBlack = pTutorial.GetGameText("LeftNameBlack");
    @pRightNameBlack = pTutorial.GetGameText("RightNameBlack");
	@pLeftNameWhite = pTutorial.GetGameText("LeftNameWhite");
    @pRightNameWhite = pTutorial.GetGameText("RightNameWhite");
    @pMarvin = cast<CGameSkin>(pTutorial.GetGameObject("Marvin"));
    @pMartian = cast<CGameSkin>(pTutorial.GetGameObject("Martian"));
	@pHeather = cast<CGameSkin>(pTutorial.GetGameObject("Heather"));
	@pBarney = cast<CGameSkin>(pTutorial.GetGameObject("Barney"));
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedLeft.ahsanimation");
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianNormalZRight.ahsanimation");
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	musicID = PlayMusic("Data/Musics/Stress.ogg", true);
}

void ReleaseTutorial()
{
	StopMusic(musicID, 0.5f);
}

//------------------------------------------------ Fade Chars ---------------------------------------------------
void FadeInHeatherLeftEnter()	
{	
	pHeather.SetPosition(vLeftPosition);
	FadeInSkinEnter(pHeather);
}	
void FadeInHeatherUpdate()	
{	
	FadeInSkinUpdate(pHeather);
}	

void FadeInMarvinRightEnter()	
{	
	pMarvin.SetPosition(vRightPosition);
	FadeInSkinEnter(pMarvin);
}	
void FadeInMarvinUpdate()	
{	
	FadeInSkinUpdate(pMarvin);
}	

void FadeOutMarvinLeftEnter()	
{	
	pMarvin.SetPosition(vLeftPosition);
	FadeOutSkinEnter(pMarvin);
}	
void FadeOutMarvinUpdate()	
{	
	FadeOutSkinUpdate(pMarvin);
}	

void FadeInMartianRightEnter()	
{	
	pMartian.SetPosition(vRightPosition);
	FadeInSkinEnter(pMartian);
}	
void FadeInMartianUpdate()	
{	
	FadeInSkinUpdate(pMartian);
}	
	
void FadeOutMartianRightEnter()	
{	
	pMartian.SetPosition(vRightPosition);
	FadeOutSkinEnter(pMartian);
}	
void FadeOutMartianUpdate()	
{	
	FadeOutSkinUpdate(pMartian);
}	


//------------------------------------------------ Script Functions ---------------------------------------------------
void HideText()
{
    pText.SetText("");
}

void EnterSaucer_8_100()
{
	pText.SetVisible(true);
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedLeft.ahsanimation");
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));

	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_100"));
}


void EnterSaucer_8_200()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_200"));
}


void EnterSaucer_8_300()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinRobotLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianNormalZRight.ahsanimation");
	pHeather.SetVisible(false);
	pMarvin.SetVisible(true);
	pMarvin.SetPosition(vLeftPosition);
	pMartian.SetVisible(true);
	pMartian.SetPosition(vRightPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MRV42-MK-I_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MRV42-MK-I_NAMETAG"));
		pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MARTIAN_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARTIAN_NAMETAG"));

	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_300"));
}

void ExitSaucer_8_300()
{
	pText.SetText("");
}

void EnterSaucer_8_400()
{
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianCommandZRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_400"));
	PlaySound("Data/Entities/Marvin/SFX/Zapper.ogg", false);
}


void EnterSaucer_8_500()
{
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianSchemingZRight.ahsanimation");
	pLeftNameBlack.SetText("");
	pLeftNameWhite.SetText("");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_500"));
}

void ExitSaucer_8_500()
{
	pText.SetText("");
}

void EnterSaucer_8_600()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedLeft.ahsanimation");
	pHeather.SetVisible(true);
	pHeather.SetPosition(vLeftPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));

	pRightNameBlack.SetText("");
	pRightNameWhite.SetText("");
pText.SetText(pLocalizer.LocalizeText("SAUCER_8_600"));
}

void ExitSaucer_8_600()
{
	pText.SetText("");
}

void EnterSaucer_8_700()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinRobotRight.ahsanimation");
	pMarvin.SetVisible(true);
	pMarvin.SetPosition(vRightPosition);
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("UNKNOWN_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("UNKNOWN_NAMETAG"));

	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_700"));
}


void EnterSaucer_8_800()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalRight.ahsanimation");
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));

	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_800"));
}

void ExitSaucer_8_800()
{
	pText.SetText("");
}

void EnterSaucer_8_900()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_900"));
}


void EnterSaucer_8_1000()
{
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalRight.ahsanimation");
	pHeather.SetVisible(false);
	pBarney.SetVisible(true);
	pBarney.SetPosition(vLeftPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("BARNEY_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("BARNEY_NAMETAG"));

	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_1000"));
}

void ExitSaucer_8_1000()
{
	pText.SetText("");
}

void EnterSaucer_8_1100()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_1100"));
}


void EnterSaucer_8_1200()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_1200"));
}


void EnterSaucer_8_1300()
{
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_1300"));
}

void ExitSaucer_8_1300()
{
	pText.SetText("");
}

void EnterSaucer_8_1400()
{
	pText.SetText(pLocalizer.LocalizeText("SAUCER_8_1400"));
}

void ExitSaucer_8_1400()
{
	pText.SetText("");
}
