//
//  CreditsScreen.cpp
//  GlobalGameJam15
//
//  Created by Cesar Parent on 25/01/2015.
//  Copyright (c) 2015 Cesar Parent. All rights reserved.
//

#include "CreditsScreen.h"
#include "Defines.h"

CreditsScreen::CreditsScreen(Game& game) : Scene(game, kGameWidth/2, kGameHeight/2)
{
	setAnchorPoint(0, 0);
	setPosition(0, 0);
	setXScale(2);
	setYScale(2);
	
	_background = new SpriteNode("assets/uis/background.png");
	_background->setAnchorPoint(0, 0);
	_background->setPosition(0, 0);
	addChild(_background);
	
	_title = new LabelNode("Credits", "assets/uis/font");
	_title->setAnchorPoint(.5, 0);
	_title->setPosition(kGameWidth/4, 20);
	_title->setFontSize(40);
	addChild(_title);
	
	
	_names[0] = new LabelNode("Abbie Smeaton", "assets/uis/font");
	_names[1] = new LabelNode("Caitlin Smith", "assets/uis/font");
	_names[2] = new LabelNode("Chloe Smyth", "assets/uis/font");
	_names[3] = new LabelNode("Cesar Parent", "assets/uis/font");
	_names[4] = new LabelNode("", "assets/uis/font");
	_names[5] = new LabelNode("Music by Sycamore Drive", "assets/uis/font");
	
	for(int i = 0; i < 6; ++i)
	{
		_names[i]->setFontSize(20);
		_names[i]->setPosition(kGameWidth/4, 80+(25*i));
		addChild(_names[i]);
	}
	
	_message = new LabelNode("press start to continue", "assets/uis/font");
	_message->setAnchorPoint(.5, 1);
	_message->setPosition(kGameWidth/4, (kGameHeight/2)-20);
	_message->setFontSize(20);
	addChild(_message);
}

CreditsScreen::~CreditsScreen()
{
	delete _background;
	delete _title;
	delete _message;
	for(int i = 0; i < 6; ++i)
	{
		delete _names[i];
	}
}

void CreditsScreen::didEnterStack()
{
	Controls::setDelegate(this);
}

void CreditsScreen::didLeaveStack()
{
	Controls::setDelegate(nullptr);
}

void CreditsScreen::controllerButtonPressBegan(int controller, SDL_GameControllerButton button)
{
	if(button == SDL_CONTROLLER_BUTTON_START)
	{
		_game.popScene();
	}
}

void CreditsScreen::keyboardPressBegan(SDL_Scancode key)
{
	if(key == SDL_SCANCODE_ESCAPE)
	{
		_game.popScene();
	}
}