//////////////////////////////////////////////////////////////////////////////
//
// Asura_Platform_CommandConsole.cpp
//
// Copyright (c) 2003 Rebellion. All rights reserved.
//
// Description:
//
//     PS2-specific implementations of command console functionality.
//
//////////////////////////////////////////////////////////////////////////////

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

#include "Core/Asura.h"

#ifdef ASURA_SUPPORT_COMMAND_CONSOLE

// This file's header.
#include "Interface/Asura_CommandConsole.h"

// Engine independent.
#include "Input/Asura_ControlMap.h"
#include "Input/Asura_PlatformInput.h"

// C L A S S   I M P L E M E N T A T I O N S /////////////////////////////////

void Asura_CommandConsole::Platform_Initialise( void )
{
    SetBorderX( 3.25f );
}

#ifdef ASURA_DEBUG_VARIABLE_SYSTEM

void Asura_DebugVariableSystem::Platform_InitialiseDefaultControlMapping( void )
{
	s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_KEYID_TAB,            Asura_ControlMapping::ON_DEBOUNCED_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_KEYID_RIGHT,          Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_KEYID_LEFT,           Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_KEYID_UP,             Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_KEYID_DOWN,           Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_KEYID_NUMPADADD,      Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_KEYID_NUMPADSUB,      Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          '=',                        Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          '-',                        Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_KEYID_NUMPADMULTIPLY, Asura_ControlMapping::ON_PRESS );
	s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_KEYID_NUMPADDIVIDE,   Asura_ControlMapping::ON_PRESS );

#ifdef ASURA_USE_CONTROLMAP_MANAGER
	if(Asura_PC_Input_Joystick::GetNumJoysticks() > 0)
	{
		const Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE	eJoystickType	= Asura_PC_Input_Joystick::GetJoystickType(0);

		switch(eJoystickType)
		{
			case Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE_PS2_JOYSTICK:
			{
				// PDC 17/05/07 added controls for a PS2JOY pad being used on a PC
				s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_PC_KEYID_PS2JOYPAD1_SELECT,	Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_PC_KEYID_PS2JOYPAD1_RIGHT,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_PC_KEYID_PS2JOYPAD1_LEFT,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_PC_KEYID_PS2JOYPAD1_UP,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_PC_KEYID_PS2JOYPAD1_DOWN,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS2JOYPAD1_R1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS2JOYPAD1_L1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_PC_KEYID_PS2JOYPAD1_R2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_PC_KEYID_PS2JOYPAD1_L2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS2JOYPAD1_CROSS,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS2JOYPAD1_CIRCLE,	Asura_ControlMapping::ON_PRESS );
				break;
			}

			case Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE_XBOX360_GAMEPAD:
			{
				// JAT 15/02/07 added controls for a 360 pad being used on a PC
				s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_PC_KEYID_XBOX360PAD1_BACK,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_PC_KEYID_XBOX360PAD1_RIGHT,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_PC_KEYID_XBOX360PAD1_LEFT,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_PC_KEYID_XBOX360PAD1_UP,			Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_PC_KEYID_XBOX360PAD1_DOWN,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_XBOX360PAD1_R_THUMB,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_XBOX360PAD1_L_THUMB,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_PC_KEYID_XBOX360PAD1_R_BUMPER,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_PC_KEYID_XBOX360PAD1_L_BUMPER,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_XBOX360PAD1_A,			Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_XBOX360PAD1_B,			Asura_ControlMapping::ON_PRESS );
				break;
			}

			#ifdef ASURA_PC_SUPPORT_XINPUT
			case Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE_XBOX360_XINPUT_GAMEPAD:
			{
				// added controls for a 360 pad being used on a PC through XInput
				s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_PC_KEYID_XINPUT360PAD1_BACK,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_PC_KEYID_XINPUT360PAD1_RIGHT,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_PC_KEYID_XINPUT360PAD1_LEFT,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_PC_KEYID_XINPUT360PAD1_UP,			Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_PC_KEYID_XINPUT360PAD1_DOWN,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_XINPUT360PAD1_R_THUMB,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_XINPUT360PAD1_L_THUMB,		Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_PC_KEYID_XINPUT360PAD1_R_BUMPER,	Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_PC_KEYID_XINPUT360PAD1_L_BUMPER,	Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_XINPUT360PAD1_A,			Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_XINPUT360PAD1_B,			Asura_ControlMapping::ON_DEBOUNCED_PRESS );
					break;
			}
			#endif

			case Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE_PS3_GAMEPAD:
			{
				s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_PC_KEYID_PS3PAD1_SELECT,	Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_PC_KEYID_PS3PAD1_RIGHT,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_PC_KEYID_PS3PAD1_LEFT,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_PC_KEYID_PS3PAD1_UP,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_PC_KEYID_PS3PAD1_DOWN,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS3PAD1_R1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS3PAD1_L1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_PC_KEYID_PS3PAD1_R2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_PC_KEYID_PS3PAD1_L2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS3PAD1_CROSS,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS3PAD1_CIRCLE,	Asura_ControlMapping::ON_PRESS );
				break;
			}

			case Asura_PC_Input_Joystick::ASURA_PC_JS_TYPE_PS2_GAMEPAD:
			default:
			{
				s_xControlMap.AddKeyMapping( KEYMAP_CLOSE,					ASURA_PC_KEYID_PS2PAD1_SELECT,	Asura_ControlMapping::ON_DEBOUNCED_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVERIGHT,              ASURA_PC_KEYID_PS2PAD1_RIGHT,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVELEFT,               ASURA_PC_KEYID_PS2PAD1_LEFT,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEUP,                 ASURA_PC_KEYID_PS2PAD1_UP,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_MOVEDOWN,               ASURA_PC_KEYID_PS2PAD1_DOWN,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS2PAD1_R1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS2PAD1_L1,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUEINCREMENT, ASURA_PC_KEYID_PS2PAD1_R2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUEINCREMENT, ASURA_PC_KEYID_PS2PAD1_L2,		Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_INCREASEVALUE,          ASURA_PC_KEYID_PS2PAD1_CROSS,	Asura_ControlMapping::ON_PRESS );
				s_xControlMap.AddKeyMapping( KEYMAP_DECREASEVALUE,          ASURA_PC_KEYID_PS2PAD1_CIRCLE,	Asura_ControlMapping::ON_PRESS );
				break;
			}
		}		// End of switch.
	}
#endif // #ifdef ASURA_USE_CONTROLMAP_MANAGER
}

#endif//#ifdef ASURA_DEBUG_VARIABLE_SYSTEM

#endif // #ifdef ASURA_SUPPORT_COMMAND_CONSOLE
