//	Challenge.h - The main Challenge game mode.
//  ----------------------------------------------------------------------------
//	This file is part of 'GameTemplate', template code for a game.
//	Copyright (C) 2011  Niall Moody
//	
//	This program is free software: you can redistribute it and/or modify
//	it under the terms of the GNU General Public License as published by
//	the Free Software Foundation, either version 3 of the License, or
//	(at your option) any later version.
//
//	This program is distributed in the hope that it will be useful,
//	but WITHOUT ANY WARRANTY; without even the implied warranty of
//	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//	GNU General Public License for more details.
//
//	You should have received a copy of the GNU General Public License
//	along with this program.  If not, see <http://www.gnu.org/licenses/>.
//	----------------------------------------------------------------------------

#ifndef CHALLENGE_H_
#define CHALLENGE_H_

#include "generators/MetaGenerator.h"
#include "drawing/TextLayout.h"
#include "TonesGlobalData.h"
#include "GameCounter.h"
#include "GameState.h"
#include "GameCore.h"
#include "Player.h"
#include "Crash.h"

///	The main Challenge game mode.
class Challenge : public GameState,
				  public CounterNotification,
				  public GameCore::Callback
{
  public:
	///	Constructor.
	Challenge(Application& app, SounderPtr& sound);
	///	Destructor.
	~Challenge();

	///	Updates the state.
	void update();
	///	Draws the state.
	void draw(DrawerPtr& d, float timestepInterp);

	///	Called when Tones collide.
	void toneCollision();

	///	So we're notified when the player gets enough Near Misses to regain a lost life.
	void countReached(const std::wstring& counter, int value);

	///	Called when a key down event is received.
	void keyDown(const std::wstring& action,
				 const std::wstring& keyPressed,
				 int keyModifier);

	///	Called when a mouse down event is received.
	void mouseDown(int button, const TwoFloats& pos);
	///	Called when a mouse up event is received.
	void mouseUp(int button, const TwoFloats& pos);
	///	Called when a mouse move event is received.
	void mouseMove(const TwoFloats& pos);

	///	Returns the name of this state.
	const std::wstring getName() const {return L"Challenge";};
	///	Used to construct instances of this state.
	static GameStateCreator<Challenge> creator;
  private:
	///	Whether we should be in pure mode or not.
	bool pure;
	///	Whether we should be in zen mode or not.
	bool zen;

	///	Handles all the game logic.
	GameCore gameCore;

	///	The player's remaining lives.
	int numLives;
	///	Used to ensure the player doesn't quit to the title screen too early.
	int gameOverCount;

	///	Whether or not we're currently paused.
	bool paused;

	///	Used to make some of the text rendering more efficient.
	TextLayout textLayouts[3];

	///	Our copy of the game's global data.
	/*!
		(this is less hassle than writing
		 dynamic_pointer_cast<TonesGlobalData>(getGlobalData()) every time)
	 */
	TonesGlobalDataPtr globalData;
	///	Our copy of the game's Sounder.
	TonesSounderPtr sounder;
};

#endif
