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

#include "FailMenu.h"
#include "Defines.h"
#include "DungeonGame.h"

FailMenu::FailMenu(Game& game) : Layer(game, kGameWidth/2, kGameHeight/2)
{
	setAnchorPoint(0, 0);
	setPosition(0, 0);
	
	_background = new SpriteNode("assets/uis/death.png");
	_background->setAnchorPoint(0, 0);
	_background->setPosition(0, 0);
	addChild(_background);
}

FailMenu::~FailMenu()
{
	delete _background;
}

#pragma mark delegates

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

void FailMenu::didExitParent()
{
	Controls::setDelegate((ControlDelegate*)_parent);
}

void FailMenu::controllerButtonPressBegan(int controller, SDL_GameControllerButton button)
{
	if(button == SDL_CONTROLLER_BUTTON_A || button == SDL_CONTROLLER_BUTTON_START)
	{
		_game.popScene();
	}
	else if(button == SDL_CONTROLLER_BUTTON_B)
	{
		_game.quit();
	}
}

void FailMenu::keyboardPressBegan(SDL_Scancode key)
{
	if(key == SDL_SCANCODE_RETURN)
	{
		_game.popScene();
	}
	else if(key == SDL_SCANCODE_ESCAPE)
	{
		_game.quit();
	}
}