#include "BreakoutGameOverScene.h"

#include "GameConfig.h"
#include "Visualisation.h"
#include "EventManager.h"
#include "InputEvents.h"
#include "BreakoutEvents.h"

BreakoutGameOverScene::BreakoutGameOverScene()
: BreakoutMainMenuScene()
{

}

BreakoutGameOverScene::~BreakoutGameOverScene()
{

}

void BreakoutGameOverScene::Initialise()
{
	Visualisation* pVis = Visualisation::getSingleton();
	MenuEntry startEntry;
	startEntry.Name = MENU_PLAY_AGAIN_GAME_TEXT;
	startEntry.NormalSprite = pVis->CreateSpriteText(startEntry.Name, MENU_NORMAL_COLOUR);
	startEntry.SelectedSprite = pVis->CreateSpriteText(startEntry.Name, MENU_SELECTED_COLOUR);
	m_vMenuEntries.push_back(startEntry);

	MenuEntry quitEntry;
	quitEntry.Name = MENU_QUIT_GAME_TEXT;
	quitEntry.NormalSprite = pVis->CreateSpriteText(quitEntry.Name, MENU_NORMAL_COLOUR);
	quitEntry.SelectedSprite = pVis->CreateSpriteText(quitEntry.Name, MENU_SELECTED_COLOUR);
	m_vMenuEntries.push_back(quitEntry);

	m_gameTitleID = Visualisation::getSingleton()->CreateSpriteText(GAME_OVER_TEXT, GAME_TITLE_COLOUR);
	m_gameTitleShadowID = Visualisation::getSingleton()->CreateSpriteText(GAME_OVER_TEXT, GAME_TITLE_SHADOW_COLOUR);

	EventManager::getSingleton()->AddEventListener(ButtonInputEvent::cEventName, this);
}

bool BreakoutGameOverScene::HandleEvent(IEvent* pEvent)
{
	if(!m_bIsActive)
		return false;

	if(pEvent->GetEventType() == ButtonInputEvent::cEventName)
	{
		ButtonInputEvent* pButtonEvent = (ButtonInputEvent*)pEvent;
		if(pButtonEvent->GetKey() == eKeyButtonB)
		{
			std::string name = m_vMenuEntries[m_selectedEntry].Name;

			if(name == MENU_PLAY_AGAIN_GAME_TEXT)
			{
				BreakoutStartGameEvent* pStartEvent = new BreakoutStartGameEvent();
				EventManager::getSingleton()->QueueEvent(pStartEvent);

				return true;
			}
		}
	}

	return BreakoutMainMenuScene::HandleEvent(pEvent);
}
