#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@ pBarney;
CGameSkin@ pHeather;
CGameSkin@ pStarling;
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"));
    @pBarney = cast<CGameSkin>(pTutorial.GetGameObject("Barney"));
    @pHeather = cast<CGameSkin>(pTutorial.GetGameObject("Heather"));
	@pStarling = cast<CGameSkin>(pTutorial.GetGameObject("Starling"));
    ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
    ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
    ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalLeft.ahsanimation");
	ChangeSkinAnimation(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingSadRight.ahsanimation");
	musicID = PlayMusic("Data/Musics/Upgrade.ogg", true);
}

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

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

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

void FadeOutMarvinUpdate(float _fDelta)
{
    pMarvin.SetPosition(vLeftPosition);
    FadeOutSkinUpdate(pMarvin);
}

void FadeInBarneyUpdate(float _fDelta)
{
    FadeInSkinUpdate(pBarney);
}

void FadeInMarvinLeftEnter()
{
    pMarvin.SetPosition(vLeftPosition);
    FadeInSkinEnter(pMarvin);
}

void FadeInMarvinUpdate()
{
    FadeInSkinUpdate(pMarvin);
}

void FadeInHeatherLeftEnter()
{
    pHeather.SetPosition(vLeftPosition);
    FadeInSkinEnter(pHeather);
}

void FadeInHeatherUpdate()
{
    FadeInSkinUpdate(pHeather);
}

void FadeInStarlingRightEnter()
{
    pStarling.SetPosition(vRightPosition);
    FadeInSkinEnter(pStarling);
}

void FadeInStarlingUpdate()
{
    FadeInSkinUpdate(pStarling);
}

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

void EnterMeadows_5_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"));
	PlaySound("Data/Levels/Common/Tutorial/SFX/StarlingLanding.ogg", false);
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_100"));
}


void EnterMeadows_5_200()
{
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_200"));
}

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

void EnterMeadows_5_300()
{
	ChangeSkinAnimation(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingSadRight.ahsanimation");
	pStarling.SetVisible(true);
	pStarling.SetPosition(vRightPosition);
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("STARLING_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("STARLING_NAMETAG"));

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

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

void EnterMeadows_5_400()
{
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_400"));
}


void EnterMeadows_5_500()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.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("MEADOWS_5_500"));
}


void EnterMeadows_5_600()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherCuteLeft.ahsanimation");
	pMarvin.SetVisible(false);
	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"));

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

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

void EnterMeadows_5_700()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedLeft.ahsanimation");
	ChangeSkinAnimation(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingShyRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_700"));
}

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

void EnterMeadows_5_800()
{
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_800"));
}


void EnterMeadows_5_900()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	pHeather.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("MEADOWS_5_900"));
}


void EnterMeadows_5_1000()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_1000"));
}


void EnterMeadows_5_1100()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedLeft.ahsanimation");
	pMarvin.SetVisible(false);
	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"));

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


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


void EnterMeadows_5_1300()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingHappyRight.ahsanimation");
	pHeather.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("MEADOWS_5_1300"));
}


void EnterMeadows_5_1400()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherCuteLeft.ahsanimation");
	pMarvin.SetVisible(false);
	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"));

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


void EnterMeadows_5_1500()
{
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedRight.ahsanimation");
	pStarling.SetVisible(false);
	pBarney.SetVisible(true);
	pBarney.SetPosition(vLeftPosition);
	pHeather.SetVisible(true);
	pHeather.SetPosition(vRightPosition);
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("BARNEY_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("BARNEY_NAMETAG"));
		pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));

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


void EnterMeadows_5_1600()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalRight.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("MEADOWS_5_1600"));
}


void EnterMeadows_5_1700()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinBlaseLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_1700"));
}


void EnterMeadows_5_1800()
{
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedRight.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("MEADOWS_5_1800"));
}


void EnterMeadows_5_1900()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinBlaseLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalRight.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("MEADOWS_5_1900"));
}


void EnterMeadows_5_2000()
{
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_2000"));
}

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

void EnterMeadows_5_2100()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherCuteRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_2100"));
}

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

void EnterMeadows_5_2200()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinBlaseLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MEADOWS_5_2200"));
}

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