//	GamePlayState.h - The main gameplay state.
//  ----------------------------------------------------------------------------
//	This file is part of 'NiallsAVLib', base code for any kind of audiovisual
//	apps.
//	Copyright (C) 2012  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 GAMEPLAYSTATE_H_
#define GAMEPLAYSTATE_H_

#include "DwindlingSounder.h"
#include "GameState.h"

class World;
typedef StdSharedPtr<World>::type WorldPtr;

///	The main gameplay state.
class GamePlayState : public GameState,
					  public DwindlingSounder::Callback
{
  public:
	///	Constructor.
	GamePlayState(Application *app, Sounder *sound);
	///	Destructor.
	~GamePlayState();

	///	Draws the current state.
	void draw(DrawerPtr d);

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

	///	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"GamePlayState";};
	///	Used to construct instances of this state.
	static GameStateCreator<GamePlayState> creator;

	///	Called whenever the sounder hits a bar start.
	void barStart();
  private:
	///	The 8 worlds in the game.
	WorldPtr worlds[8];
	///	The 8 backing tracks in the game.
	std::wstring backingTracks[8];
	///	The 8 speech tracks in the game.
	std::wstring speechTracks[8];
	///	The final 8 world positions for the end screen.
	TwoFloats endPos[8];

	///	Used to interpolate to the end positions.
	float endInterp;
	///	 Used to jump the end worlds on bar starts.
	float endJump;
	///	Used to eventually quit the game.
	int endCount;

	///	Index of the current backing track.
	int backingIndex;

	///	Which world we're currently on.
	int worldIndex;
	///	Used to move between worlds.
	float worldInterp;

	///	The top left of our current viewport.
	TwoFloats viewPos;

	///	When the player solves a puzzle, flash the screen white.
	float flash;
	///	True if we're waiting on flash before continuing to the next puzzle.
	bool flashWait;

	///	Used to fade in at the start.
	float fadeIn;
	///	Used to fade out at the end.
	float fadeOut;

	///	True if we're now on the end screen.
	bool endScreen;

	///	Our sounder.
	DwindlingSounder *sounder;
};

#endif
