#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@ 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"));
	@pBarney = cast<CGameSkin>(pTutorial.GetGameObject("Barney"));
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianGrinRight.ahsanimation");
	musicID = PlayMusic("Data/Musics/Stress.ogg", true);
}

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

//------------------------------------------------ Fade Chars ---------------------------------------------------
void FadeInBarneyLeftEnter()	
{	
	pBarney.SetPosition(vLeftPosition);
	FadeInSkinEnter(pBarney);
}	
void FadeInBarneyUpdate()	
{	
	FadeInSkinUpdate(pBarney);
}	

void FadeInMartianRightEnter()	
{	
	pMartian.SetPosition(vRightPosition);
	FadeInSkinEnter(pMartian);
}	
void FadeInMartianUpdate()	
{	
	FadeInSkinUpdate(pMartian);
}	

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

void EnterSaucer_1_100()
{
	pText.SetVisible(true);
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	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_1_100"));
}

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

void EnterSaucer_1_200()
{
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianGrinRight.ahsanimation");
	pMartian.SetVisible(true);
	pMartian.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_1_200"));
}

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

void EnterSaucer_1_300()
{
	pText.SetText(pLocalizer.LocalizeText("SAUCER_1_300"));
}


void EnterSaucer_1_400()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianSchemingRight.ahsanimation");
	pBarney.SetVisible(false);
	pMarvin.SetVisible(true);
	pMarvin.SetPosition(vLeftPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));

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

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

void EnterSaucer_1_500()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianNormalRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_1_500"));
}

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

void EnterSaucer_1_600()
{
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianGrinRight.ahsanimation");
	pMarvin.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_1_600"));
}


void EnterSaucer_1_700()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	pBarney.SetVisible(false);
	pMarvin.SetVisible(true);
	pMarvin.SetPosition(vLeftPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));

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

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

void EnterSaucer_1_800()
{
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianSchemingRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_1_800"));
}

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

void EnterSaucer_1_900()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinBlaseLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianGrinRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_1_900"));
}

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

void EnterSaucer_1_1000()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	ChangeSkinAnimation(pMartian, "Data/Levels/Chars/Martian/Poses/A_MartianSchemingRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("SAUCER_1_1000"));
}

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