// AVP_Platform_GUIMenu_System.cpp
// Thomas Young - 13.10.08
// Copyright (C) 2008 Rebellion, All Rights Reserved.

#include "Core/Asura.h"

#ifdef ASURA_USE_GUI_MENU_SYSTEM

// I N C L U D E S ///////////////////////////////////////////////////////////

#include "Core/Asura_Xbox360_OS.h"
#include "GUIMenu/Asura_GUIMenu_System.h"
#include "GUIMenu/AVP_GUIMenu_System.h"
#include "Input/Asura_PlatformInput.h"

// G L O B A L   V A R I A B L E S ///////////////////////////////////////////

static const Asura_Hash_ID uAVP_START_SCREEN	= Asura_GetHashID( "Start_Menu");
static const Asura_Hash_ID uAVP_MAIN_MENU		= Asura_GetHashID( "E3_Connecter");

// F U N C T I O N   D E F I N I T I O N S ///////////////////////////////////

void AVP_GUIMenu_System::Platform_Initialise()
{

}


void AVP_GUIMenu_System::Platform_Update()
{
	// We need to check if we are on the start screen and if so, detect the start
	// button being pressed, we then use this as our active 360 controller
	
	Asura_Hash_ID uOpenMenu = Asura_GUIMenu_System::GetFocusedMenuHashID();
	if(uOpenMenu == uAVP_START_SCREEN)
	{
		// Check if a controller pressed start
		int iController = -1;
		if( Asura_UserInput::DebouncedKeyPressed(ASURA_XBOX360_KEYID_PAD1_START) )
		{
			iController = 0;
		}
		else if ( Asura_UserInput::DebouncedKeyPressed(ASURA_XBOX360_KEYID_PAD2_START) )
		{
			iController = 1;
		}
		else if ( Asura_UserInput::DebouncedKeyPressed(ASURA_XBOX360_KEYID_PAD3_START) )
		{
			iController = 2;
		}
		else if ( Asura_UserInput::DebouncedKeyPressed(ASURA_XBOX360_KEYID_PAD4_START) )
		{
			iController = 3;
		}

		if(iController >= 0)
		{
			// Update the active controller where necessary
			Asura_Xbox360_OS::SetActivePlayerIndex( iController );
			Asura_GUIMenu_System::SetControlMapIndexToUse( iController );
			
			// Show the main menu
			Asura_GUIMenu_System::CloseMenuPage( uOpenMenu );
			Asura_GUIMenu_System::OpenMenuPage( uAVP_MAIN_MENU );
		}
	}
}


void AVP_GUIMenu_System::Platform_Shutdown()
{

}

#endif	// ASURA_USE_GUI_MENU_SYSTEM

//eof
