#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@ pHeather;
CGameSkin@ pStarling;
CGameSkin@ pStarking;
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"));
    @pHeather = cast<CGameSkin>(pTutorial.GetGameObject("Heather"));
    @pStarling = cast<CGameSkin>(pTutorial.GetGameObject("Starling"));
	@pStarking = cast<CGameSkin>(pTutorial.GetGameObject("Starking"));
	@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(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingSadRight.ahsanimation");
    ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedRight.ahsanimation");
	ChangeSkinAnimation(pStarking, "Data/Levels/Chars/Starking/Poses/A_StarkingNormalRight.ahsanimation");
	musicID = PlayMusic("Data/Musics/Upgrade.ogg", true);
}

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

//------------------------------------------------ Fade Chars ---------------------------------------------------
void FadeInMarvinLeftHeatherRightEnter()	
{	
	pMarvin.SetPosition(vLeftPosition);
	pHeather.SetPosition(vRightPosition);
	FadeInSkinEnter(pMarvin);
	FadeInSkinEnter(pHeather);
}	
void FadeInMarvinLeftHeatherRightUpdate(float _Delta)	
{	
	FadeInSkinUpdate(pMarvin);
	FadeInSkinUpdate(pHeather);
}	

void FadeOutHeatherRightEnter()	
{	
	pHeather.SetPosition(vRightPosition);
	FadeOutSkinEnter(pHeather);
}	
void FadeOutHeatherUpdate()	
{	
	FadeOutSkinUpdate(pHeather);
}	

void FadeInStarkingRightEnter()	
{	
	pStarking.SetPosition(vRightPosition);
	FadeInSkinEnter(pStarking);
}	
void FadeInStarkingUpdate()	
{	
	FadeInSkinUpdate(pStarking);
}	

void FadeInHeatherRightEnter()	
{	
	pHeather.SetPosition(vRightPosition);
	FadeInSkinEnter(pHeather);
}	
void FadeInHeatherUpdate()	
{	
	FadeInSkinUpdate(pHeather);
}	

void FadeOutStarkingRightEnter()	
{	
	pStarking.SetPosition(vRightPosition);
	FadeOutSkinEnter(pStarking);
}	
void FadeOutStarkingUpdate()	
{	
	FadeOutSkinUpdate(pStarking);
}	


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

void EnterMoon_8_100()
{
	pText.SetVisible(true);
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedRight.ahsanimation");
	pLeftNameBlack.SetVisible(true);
	pLeftNameWhite.SetVisible(true);
	pLeftNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));
	pLeftNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_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("MOON_8_100"));
}

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

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

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

void EnterMoon_8_300()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_300"));
}


void EnterMoon_8_400()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_400"));
}

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

void EnterMoon_8_500()
{
	pText.SetText(pLocalizer.LocalizeText("MOON_8_500"));
}

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

void EnterMoon_8_600()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherCuteRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_600"));
}

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

void EnterMoon_8_700()
{
	pRightNameBlack.SetText("");
	pRightNameWhite.SetText("");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_700"));
}

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

void EnterMoon_8_800()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	ChangeSkinAnimation(pStarking, "Data/Levels/Chars/Starking/Poses/A_StarkingHappyRight.ahsanimation");
	pStarking.SetVisible(true);
	pStarking.SetPosition(vRightPosition);
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("STARKING_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("STARKING_NAMETAG"));

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

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

void EnterMoon_8_900()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	ChangeSkinAnimation(pStarking, "Data/Levels/Chars/Starking/Poses/A_StarkingNormalRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_900"));
}

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

void EnterMoon_8_1000()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_1000"));
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherWorriedRight.ahsanimation");
}

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

void EnterMoon_8_1100()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_1100"));
}

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

void EnterMoon_8_1200()
{
	pStarking.SetVisible(false);
	pHeather.SetVisible(true);
	pHeather.SetPosition(vRightPosition);
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));

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

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

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

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

void EnterMoon_8_1400()
{
	pText.SetText(pLocalizer.LocalizeText("MOON_8_1400"));
}

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

void EnterMoon_8_1500()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinNormalLeft.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_1500"));
}

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

void EnterMoon_8_1600()
{
	ChangeSkinAnimation(pStarling, "Data/Levels/Chars/Starling/Poses/A_StarlingHappyRight.ahsanimation");
	pHeather.SetVisible(false);
	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("MOON_8_1600"));
}


void EnterMoon_8_1700()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherCuteRight.ahsanimation");
	pStarling.SetVisible(false);
	pHeather.SetVisible(true);
	pHeather.SetPosition(vRightPosition);
	pRightNameBlack.SetVisible(true);
	pRightNameWhite.SetVisible(true);
	pRightNameBlack.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("HEATHER_NAMETAG"));

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

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

void EnterMoon_8_1800()
{
	ChangeSkinAnimation(pHeather, "Data/Levels/Chars/Heather/Poses/A_HeatherNormalRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_1800"));
}


void EnterMoon_8_1900()
{
	ChangeSkinAnimation(pBarney, "Data/Levels/Chars/Barney/Poses/A_BarneyNormalLeft.ahsanimation");
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinPuzzledRight.ahsanimation");
	pHeather.SetVisible(false);
	pBarney.SetVisible(true);
	pBarney.SetPosition(vLeftPosition);
	pMarvin.SetVisible(true);
	pMarvin.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("MARVIN_NAMETAG"));
	pRightNameWhite.SetText(GetGame().GetLocalizer().LocalizeText("MARVIN_NAMETAG"));

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

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

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


void EnterMoon_8_2100()
{
	ChangeSkinAnimation(pMarvin, "Data/Levels/Chars/Marvin/Poses/A_MarvinBlaseRight.ahsanimation");
	pText.SetText(pLocalizer.LocalizeText("MOON_8_2100"));
}

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