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

#include "PauseMenu.h"
#include "Defines.h"
#include "DungeonGame.h"

PauseMenu::PauseMenu(Game& game) :
	Layer(game, kGameWidth/2, kGameHeight/2)
{
	setAnchorPoint(0, 0);
	setPosition(0, 0);
	
	_background = new SpriteNode("assets/uis/background.png");
	_background->setAnchorPoint(0, 0);
	_background->setPosition(0, 0);
	addChild(_background);
	
	_title = new LabelNode("Pause", "assets/uis/font");
	_title->setAnchorPoint(.5, 0);
	_title->setPosition(_frame.w/2, 20);
	_title->setFontSize(40);
	addChild(_title);
	
	_message = new LabelNode("press start to continue, B to quit", "assets/uis/font");
	_message->setAnchorPoint(.5, 1);
	_message->setPosition(_frame.w/2, _frame.h-20);
	_message->setFontSize(20);
	addChild(_message);
}

PauseMenu::~PauseMenu()
{
	delete _background;
	delete _title;
	delete _message;
}

void PauseMenu::didBecomeChild()
{
	Controls::setDelegate(this);
}

void PauseMenu::controllerButtonPressBegan(int controller, SDL_GameControllerButton button)
{
	if(button == SDL_CONTROLLER_BUTTON_START)
	{
		((DungeonGame*)_parent)->finishedIntro();
		removeFromParent();
	}
	else if(button == SDL_CONTROLLER_BUTTON_B)
	{
		_game.popScene();
	}
}

void PauseMenu::keyboardPressBegan(SDL_Scancode key)
{
	if(key == SDL_SCANCODE_RETURN)
	{
		((DungeonGame*)_parent)->finishedIntro();
		removeFromParent();
	}
	else if(key == SDL_SCANCODE_ESCAPE)
	{
		_game.popScene();
	}
}