///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_CoreState_MultiplayerLobby.cpp
// Author : Anthony Gregson
// Date   : 21/11/07
//
// Copyright (C) 2007 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Include files...
////////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

#if defined(ASURA_SUPPORT_LOBBY)

// This file's header...
#include "Core/States/Core/AVP_CoreState_MultiplayerLobby.h"

// Asura independent header-files...
#include "Core/Asura_Multithread.h"
#include "Debugging/Asura_Assert.h"
#include "Network/Asura_NetLinkManager.h"

// Game independent header-files...
#include "Core/AVP_Core.h"
#include "Core/AVP_StateMachine_Core.h"
#include "Core/States/Core/AVP_StateMachine_GameFrontend.h"
#include "FrontEnd/AVP_DevLobby.h"
#include "FrontEnd/AVP_GameLobby.h"
#include "GUIMenu/AVP_GUIMenu_System.h"


////////////////////////////////////////////////////////////////////////////////
// Function	: AVP_CoreState_MultiplayerLobby::Enter
// Author	: Anthony Gregson
// Date		: 21/11/07
////////////////////////////////////////////////////////////////////////////////

void AVP_CoreState_MultiplayerLobby::Enter(const u_int uPreviousState)
{
	const AVP_GUIMenu_System::LOBBY_TYPE	eLobbyType	= AVP_GUIMenu_System::GetLobbyType();

	switch(eLobbyType)
	{
#if defined(AVP_USE_DEV_LOBBY)
		case AVP_GUIMenu_System::LT_DEVELOPMENT:
		{
			AVP_DevLobby::Initialise();
			break;
		}
#endif	//defined(AVP_USE_DEV_LOBBY)

#if defined(AVP_USE_GAME_LOBBY)
		case AVP_GUIMenu_System::LT_GAME:
		{
			AVP_GameLobby::Initialise();
			break;
		}
#endif	//defined(AVP_USE_GAME_LOBBY)

		default:
		{
			Asura_Assert(false, "Unexpected lobby-type found.");
			break;
		}
	}	// End of switch.
}

/// End of function 'AVP_CoreState_MultiplayerLobby::Enter'. ///

void AVP_CoreState_MultiplayerLobby::Update()
{
	bool									bUpdate			= false;
	bool									bQuitRequested	= false;
	const AVP_GUIMenu_System::LOBBY_TYPE	eLobbyType		= AVP_GUIMenu_System::GetLobbyType();

	switch(eLobbyType)
	{
#if defined(AVP_USE_DEV_LOBBY)
		case AVP_GUIMenu_System::LT_DEVELOPMENT:
		{
			bUpdate			= AVP_DevLobby::Update();
			bQuitRequested	= AVP_DevLobby::IsQuitRequested();
			break;
		}
#endif	//defined(AVP_USE_DEV_LOBBY)

#if defined(AVP_USE_GAME_LOBBY)
		case AVP_GUIMenu_System::LT_GAME:
		{
			bUpdate			= AVP_GameLobby::Update();
			bQuitRequested	= AVP_GameLobby::IsQuitRequested();
			break;
		}
#endif	//defined(AVP_USE_GAME_LOBBY)

		default:
		{
			Asura_Assert(false, "Unexpected lobby-type found.");
			break;
		}
	}	// End of switch.

	if ( bUpdate )
	{
		if( bQuitRequested )
		{
#if defined(AVP_USE_DEVELOPMENT_FRONT_END)
			m_xParentMachine.ChangeState(AVP_StateMachine_GameFrontend::STATE_DEVELOPMENTFRONTEND);
#elif defined(AVP_USE_GAME_FRONTEND)
			m_xParentMachine.ChangeState(AVP_StateMachine_GameFrontend::STATE_LOADINGFRONTEND);
#else
			m_xParentMachine.ChangeState(AVP_StateMachine_GameFrontend::STATE_SHUTTINGDOWN); 
#endif	//defined(AVP_USE_DEVELOPMENT_FRONT_END)
		}
		else
		{
			m_xParentMachine.ChangeState(AVP_StateMachine_GameFrontend::STATE_GAME);
		}
	}
}

void AVP_CoreState_MultiplayerLobby::Render() const
{
	AVP_Core::BeginRender( false );
	{
		const AVP_GUIMenu_System::LOBBY_TYPE	eLobbyType	= AVP_GUIMenu_System::GetLobbyType();

		switch(eLobbyType)
		{
#if defined(AVP_USE_DEV_LOBBY)
			case AVP_GUIMenu_System::LT_DEVELOPMENT:
			{
				AVP_DevLobby::Render();
				break;
			}
#endif	//defined(AVP_USE_DEV_LOBBY)

#if defined(AVP_USE_GAME_LOBBY)
			case AVP_GUIMenu_System::LT_GAME:
			{
				AVP_GameLobby::Render();
				break;
			}
#endif	//defined(AVP_USE_GAME_LOBBY)

			default:
			{
				Asura_Assert(false, "Unexpected lobby-type found.");
				break;
			}
		}	// End of switch.

		AVP_GUIMenu_System::Render(true);
	}
	AVP_Core::EndRender();
}

void AVP_CoreState_MultiplayerLobby::Exit(const u_int uNextState)
{
	const AVP_GUIMenu_System::LOBBY_TYPE	eLobbyType	= AVP_GUIMenu_System::GetLobbyType();

	switch(eLobbyType)
	{
#if defined(AVP_USE_DEV_LOBBY)
		case AVP_GUIMenu_System::LT_DEVELOPMENT:
		{
			AVP_DevLobby::Shutdown();
			break;
		}
#endif	//defined(AVP_USE_DEV_LOBBY)

#if defined(AVP_USE_GAME_LOBBY)
		case AVP_GUIMenu_System::LT_GAME:
		{
			AVP_GameLobby::Shutdown();
			break;
		}
#endif	//defined(AVP_USE_GAME_LOBBY)

		default:
		{
			Asura_Assert(false, "Unexpected lobby-type found.");
			break;
		}
	}	// End of switch.
}

#endif	//defined(ASURA_SUPPORT_LOBBY)


/// End of file. ///
