/*
	Lan Wars.
	Copyright (c) 2009, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GAME_GAME_MENUS_H
#define GAME_GAME_MENUS_H

//=====================================================================================================================
//=====================================================================================================================

#include "Graphics\Texture.h"
#include "Graphics\BitmapFont.h"

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{	
	//=================================================================================================================
	//=================================================================================================================
	
	class GameCore;	
	class Camera2D;

	//=================================================================================================================
	/// @brief		Class that represents the menus for the game. This class is responsible for both drawing the menus
	///				and for handling user input on the menus.
	//=================================================================================================================

	class GameMenus : public ObjectBase , public Keyboard::PolledEventListener
	{
		public:
		
			//=========================================================================================================
			// Enums
			//=========================================================================================================
			
				/// Current menu being shown
				
				enum Menu
				{
					/// No menu is currently being shown. This is used during gameplay.
					
					MENU_NONE ,
				
					/// The game start menu where the player choses to host the game or to join a game
					
					MENU_START ,
					
					/// Menu for the client. This is where the client is entering a host name or ip
					
					MENU_HOST_NAME ,

					/// Menu for a server. Server chooses which port to use 

					MENU_SERVER_PORT , 

					/// Menu for a client. Client chooses which port to use 

					MENU_CLIENT_PORT ,
					
					/// Menu for the client. This is where the client is trying to connect to the host
					
					MENU_CONNECTING ,			
					
					/// Menu for the client. This is where a connection has been refused 
					
					MENU_CONNECTION_REFUSED , 
					
					/// Menu for a client: connection to the server has been lost
					
					MENU_CONNECTION_LOST ,

					/// Menu for a client: invalid host name

					MENU_INVALID_HOST_NAME , 
					
					/// Menu for client/server: invalid port number entered
					
					MENU_INVALID_PORT , 
					
					/// Menu for server: unable to create socket (typically because port is already in use)
					
					MENU_INVALID_SERVER_SOCKET,

					/// Menu for a client: server disconnect

					MENU_SERVER_DISCONNECT
				};
			
			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Creates the menus
				
				GameMenus();
				
				/// Destroys the menus
				
				~GameMenus();
				
				/// Draws the current menu
				
				void Draw();
				
				/// Does input etc. for the current menu
				
				void DoInput();
				
				/// Sets the current menu to use
				
				inline void SetMenu( Menu new_menu ){ m_menu = new_menu; }
				
				/// Gets the current menu in use
				
				inline Menu GetMenu() const { return m_menu; }
				
				/// Tells the object to announce it's type name: this is the type name without the Game:: namespace

				virtual const char * GetTypeName() const;
				
				/// Called when a character is typed into the keyboard
				
				virtual void OnKeyboardTyped( char c );	

		private:
		
			//=========================================================================================================
			// Functions
			//=========================================================================================================
			
				/// Draws the background for all the menus
				
				void DrawBackground();
			
				/// Draws the game start menu
				
				void DrawStartMenu();

				/// Draws the host name screen
				
				void DrawHostNameMenu();

				/// Draws the server port screen

				void DrawServerPortMenu();

				/// Draws the client port screen

				void DrawClientPortMenu();
				
				/// Draws the connecting screen
				
				void DrawConnectingMenu();

				/// Draws the connection lost screen
				
				void DrawConnectionLost();

				/// Draws the connection refused screen
				
				void DrawConnectionRefused();

				/// Draws the invalid host name screen
				
				void DrawInvalidHostName();

				/// Draws the invalid port screen
				
				void DrawInvalidPort();
				
				/// Draws the invalid server socket screen
				
				void DrawInvalidServerSocket();

				/// Draws the server disconnected screen
				
				void DrawServerDisconnected();
				
				/// Draws the in game hud for the client:
				
				void DrawHud();
				
				/// Draws the prompt for instructions
				
				void DrawInstructionsPrompt();
				
				/// Draws the actual instructions themselves
				
				void DrawInstructions();

			//=========================================================================================================
			// Variables
			//=========================================================================================================
			
				/// This is the background texture for all the menus
				
				Texture m_background_tex;
				
				/// This is the hud bar texture
				
				Texture m_hud_bar_tex;
				
				/// The font to use for drawing the menus
				
				BitmapFont m_font;
				
				/// Current menu we are on
				
				Menu m_menu;
				
				/// Previous state of the keyboard
				
				Keyboard::State m_kbs_prev;
				
				/// True if we have valid resources
				
				bool m_valid_resources;
				
				/// This is a camera we use to get the view projection matrix for the screen
				
				Camera2D * m_camera;
				
				/// This is the name of the host to try and connect to
				
				std::string m_host_name;
				
				/// This is the number of the port to use for client/server connections. The user can enter this and change it.
				
				std::string m_server_port_string;
				
				/// Are we showing instructions ?
				
				bool m_show_instructions;
	};
};

#endif
