// KJL - 29-Mar-01 15:33:38
// 
// Asura_PlatformInput.h

#ifdef ASURA_USE_PRAGMA_ONCE
    #pragma once
#endif

#ifndef __ASURA_PLATFORMINPUT_H__
#define __ASURA_PLATFORMINPUT_H__

#include "Input/Asura_Mouse.h"
#include "Core/Asura_UserInput.h"

// (AAM - 14.01.2004)
#include "Input/Asura_PC_Input_Joystick.h"

#ifdef ASURA_PC_SUPPORT_XINPUT
#include "Input/Asura_PC_Input_XInput.h"
#endif

// (AAM - 10.05.2004) Only support 1 pad for now. These values actually come from the POV hat, at least on
// the PS2 USB converter
// (MH - 28.06.2004) added a bunch more values for the PS2 pad on PC
// (AAM - 30.09.2004) and for Xbox
// (AAM - 11.04.2005) and for Game's PS2-clone USB pad
// NY - 16 August 2005 - added mappings for HAT; controls below that map to buttons 13-16 may no longer work,
// as the hat used to map to 13-16. Any mappings that should point to the HAT rather than 13-16 (which are used as real buttons anyway)
// will need fixing.
enum ASURA_PC_KEYID
{
	ASURA_PC_KEYID_HAT_UP		= ASURA_KEYID_JOYSTICK_BUTTON_1,
	ASURA_PC_KEYID_HAT_DOWN		= ASURA_KEYID_JOYSTICK_BUTTON_2,
	ASURA_PC_KEYID_HAT_LEFT		= ASURA_KEYID_JOYSTICK_BUTTON_3,
	ASURA_PC_KEYID_HAT_RIGHT	= ASURA_KEYID_JOYSTICK_BUTTON_4,

	ASURA_PC_KEYID_PS2PAD1_CROSS    = ASURA_KEYID_PAD1_BUTTON3, 
	ASURA_PC_KEYID_PS2PAD1_CIRCLE	= ASURA_KEYID_PAD1_BUTTON2, 
	ASURA_PC_KEYID_PS2PAD1_SQUARE	= ASURA_KEYID_PAD1_BUTTON4, 
	ASURA_PC_KEYID_PS2PAD1_TRIANGLE	= ASURA_KEYID_PAD1_BUTTON1, 
	ASURA_PC_KEYID_PS2PAD1_R2		= ASURA_KEYID_PAD1_BUTTON6, 
	ASURA_PC_KEYID_PS2PAD1_L2		= ASURA_KEYID_PAD1_BUTTON5, 
	ASURA_PC_KEYID_PS2PAD1_START	= ASURA_KEYID_PAD1_BUTTON12, 
	ASURA_PC_KEYID_PS2PAD1_SELECT	= ASURA_KEYID_PAD1_BUTTON9, 
	ASURA_PC_KEYID_PS2PAD1_L1	    = ASURA_KEYID_PAD1_BUTTON7, 
	ASURA_PC_KEYID_PS2PAD1_R1	    = ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_PS2PAD1_L3	    = ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_PS2PAD1_R3	    = ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_PS2PAD1_UP		= ASURA_PC_KEYID_HAT_UP,
	ASURA_PC_KEYID_PS2PAD1_DOWN		= ASURA_PC_KEYID_HAT_DOWN,
	ASURA_PC_KEYID_PS2PAD1_LEFT		= ASURA_PC_KEYID_HAT_LEFT,
	ASURA_PC_KEYID_PS2PAD1_RIGHT	= ASURA_PC_KEYID_HAT_RIGHT,

	ASURA_PC_KEYID_PS3PAD1_SELECT	= ASURA_KEYID_PAD1_BUTTON1, 
	ASURA_PC_KEYID_PS3PAD1_L3	    = ASURA_KEYID_PAD1_BUTTON2,
	ASURA_PC_KEYID_PS3PAD1_R3	    = ASURA_KEYID_PAD1_BUTTON3,
	ASURA_PC_KEYID_PS3PAD1_START	= ASURA_KEYID_PAD1_BUTTON4, 
	ASURA_PC_KEYID_PS3PAD1_UP		= ASURA_KEYID_PAD1_BUTTON5,
	ASURA_PC_KEYID_PS3PAD1_RIGHT	= ASURA_KEYID_PAD1_BUTTON6,
	ASURA_PC_KEYID_PS3PAD1_DOWN		= ASURA_KEYID_PAD1_BUTTON7,
	ASURA_PC_KEYID_PS3PAD1_LEFT		= ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_PS3PAD1_L2		= ASURA_KEYID_PAD1_BUTTON9, 
	ASURA_PC_KEYID_PS3PAD1_R2		= ASURA_KEYID_PAD1_BUTTON10, 
	ASURA_PC_KEYID_PS3PAD1_L1	    = ASURA_KEYID_PAD1_BUTTON11, 
	ASURA_PC_KEYID_PS3PAD1_R1	    = ASURA_KEYID_PAD1_BUTTON12,
	ASURA_PC_KEYID_PS3PAD1_TRIANGLE	= ASURA_KEYID_PAD1_BUTTON13, 
	ASURA_PC_KEYID_PS3PAD1_CIRCLE	= ASURA_KEYID_PAD1_BUTTON14, 
	ASURA_PC_KEYID_PS3PAD1_CROSS    = ASURA_KEYID_PAD1_BUTTON15, 
	ASURA_PC_KEYID_PS3PAD1_SQUARE	= ASURA_KEYID_PAD1_BUTTON16, 

	ASURA_PC_KEYID_XBOXPAD1_A			= ASURA_KEYID_PAD1_BUTTON1,
	ASURA_PC_KEYID_XBOXPAD1_B			= ASURA_KEYID_PAD1_BUTTON2,
	ASURA_PC_KEYID_XBOXPAD1_X			= ASURA_KEYID_PAD1_BUTTON3,
	ASURA_PC_KEYID_XBOXPAD1_Y			= ASURA_KEYID_PAD1_BUTTON4,
	ASURA_PC_KEYID_XBOXPAD1_BLACK		= ASURA_KEYID_PAD1_BUTTON5,
	ASURA_PC_KEYID_XBOXPAD1_WHITE		= ASURA_KEYID_PAD1_BUTTON6,
	ASURA_PC_KEYID_XBOXPAD1_START		= ASURA_KEYID_PAD1_BUTTON7,
	ASURA_PC_KEYID_XBOXPAD1_BACK		= ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_XBOXPAD1_LTHUMB		= ASURA_KEYID_PAD1_BUTTON9,
	ASURA_PC_KEYID_XBOXPAD1_RTHUMB		= ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_XBOXPAD1_LTRIGGER	= ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_XBOXPAD1_RTRIGGER	= ASURA_KEYID_PAD1_BUTTON12,
	ASURA_PC_KEYID_XBOXPAD1_UP			= ASURA_KEYID_PAD1_BUTTON13,
	ASURA_PC_KEYID_XBOXPAD1_DOWN		= ASURA_KEYID_PAD1_BUTTON14,
	ASURA_PC_KEYID_XBOXPAD1_LEFT		= ASURA_KEYID_PAD1_BUTTON15,
	ASURA_PC_KEYID_XBOXPAD1_RIGHT		= ASURA_KEYID_PAD1_BUTTON16,

	// 360 pad using Microsoft drivers
	ASURA_PC_KEYID_XBOX360PAD1_A			= ASURA_KEYID_PAD1_BUTTON1,
	ASURA_PC_KEYID_XBOX360PAD1_B			= ASURA_KEYID_PAD1_BUTTON2,
	ASURA_PC_KEYID_XBOX360PAD1_X			= ASURA_KEYID_PAD1_BUTTON3,
	ASURA_PC_KEYID_XBOX360PAD1_Y			= ASURA_KEYID_PAD1_BUTTON4,
	ASURA_PC_KEYID_XBOX360PAD1_L_BUMPER		= ASURA_KEYID_PAD1_BUTTON5,
	ASURA_PC_KEYID_XBOX360PAD1_R_BUMPER		= ASURA_KEYID_PAD1_BUTTON6,
	ASURA_PC_KEYID_XBOX360PAD1_START		= ASURA_KEYID_PAD1_BUTTON7,
	ASURA_PC_KEYID_XBOX360PAD1_BACK			= ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_XBOX360PAD1_L_THUMB		= ASURA_KEYID_PAD1_BUTTON9,
	ASURA_PC_KEYID_XBOX360PAD1_R_THUMB		= ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_XBOX360PAD1_L_TRIGGER	= ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_XBOX360PAD1_R_TRIGGER	= ASURA_KEYID_PAD1_BUTTON12,
	ASURA_PC_KEYID_XBOX360PAD1_UP			= ASURA_PC_KEYID_HAT_UP,
	ASURA_PC_KEYID_XBOX360PAD1_DOWN			= ASURA_PC_KEYID_HAT_DOWN,
	ASURA_PC_KEYID_XBOX360PAD1_LEFT			= ASURA_PC_KEYID_HAT_LEFT,
	ASURA_PC_KEYID_XBOX360PAD1_RIGHT		= ASURA_PC_KEYID_HAT_RIGHT,

	#ifdef ASURA_PC_SUPPORT_XINPUT
	// 360 pad using XInput drivers
	ASURA_PC_KEYID_XINPUT360PAD1_A			= ASURA_KEYID_PAD1_BUTTON1,
	ASURA_PC_KEYID_XINPUT360PAD1_B			= ASURA_KEYID_PAD1_BUTTON2,
	ASURA_PC_KEYID_XINPUT360PAD1_X			= ASURA_KEYID_PAD1_BUTTON3,
	ASURA_PC_KEYID_XINPUT360PAD1_Y			= ASURA_KEYID_PAD1_BUTTON4,
	ASURA_PC_KEYID_XINPUT360PAD1_L_BUMPER	= ASURA_KEYID_PAD1_BUTTON5,
	ASURA_PC_KEYID_XINPUT360PAD1_R_BUMPER	= ASURA_KEYID_PAD1_BUTTON6,
	ASURA_PC_KEYID_XINPUT360PAD1_START		= ASURA_KEYID_PAD1_BUTTON7,
	ASURA_PC_KEYID_XINPUT360PAD1_BACK		= ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_XINPUT360PAD1_L_THUMB	= ASURA_KEYID_PAD1_BUTTON9,
	ASURA_PC_KEYID_XINPUT360PAD1_R_THUMB	= ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_XINPUT360PAD1_L_TRIGGER	= ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_XINPUT360PAD1_R_TRIGGER	= ASURA_KEYID_PAD1_BUTTON12,
	ASURA_PC_KEYID_XINPUT360PAD1_UP			= ASURA_PC_KEYID_HAT_UP,
	ASURA_PC_KEYID_XINPUT360PAD1_DOWN		= ASURA_PC_KEYID_HAT_DOWN,
	ASURA_PC_KEYID_XINPUT360PAD1_LEFT		= ASURA_PC_KEYID_HAT_LEFT,
	ASURA_PC_KEYID_XINPUT360PAD1_RIGHT		= ASURA_PC_KEYID_HAT_RIGHT,
	#endif

	// PDC 17/05/07 added controls for a PS2JOY pad being used on a PC
	ASURA_PC_KEYID_PS2JOYPAD1_CROSS		= ASURA_KEYID_PAD1_BUTTON3, 
	ASURA_PC_KEYID_PS2JOYPAD1_CIRCLE	= ASURA_KEYID_PAD1_BUTTON2, 
	ASURA_PC_KEYID_PS2JOYPAD1_SQUARE	= ASURA_KEYID_PAD1_BUTTON4, 
	ASURA_PC_KEYID_PS2JOYPAD1_TRIANGLE	= ASURA_KEYID_PAD1_BUTTON1, 
	ASURA_PC_KEYID_PS2JOYPAD1_R2		= ASURA_KEYID_PAD1_BUTTON6, 
	ASURA_PC_KEYID_PS2JOYPAD1_L2		= ASURA_KEYID_PAD1_BUTTON5, 
	ASURA_PC_KEYID_PS2JOYPAD1_START		= ASURA_KEYID_PAD1_BUTTON12, 
	ASURA_PC_KEYID_PS2JOYPAD1_SELECT	= ASURA_KEYID_PAD1_BUTTON9, 
	ASURA_PC_KEYID_PS2JOYPAD1_L1	    = ASURA_KEYID_PAD1_BUTTON7, 
	ASURA_PC_KEYID_PS2JOYPAD1_R1	    = ASURA_KEYID_PAD1_BUTTON8,
	ASURA_PC_KEYID_PS2JOYPAD1_L3	    = ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_PS2JOYPAD1_R3	    = ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_PS2JOYPAD1_UP		= ASURA_KEYID_PAD1_BUTTON13,
	ASURA_PC_KEYID_PS2JOYPAD1_DOWN		= ASURA_KEYID_PAD1_BUTTON15,
	ASURA_PC_KEYID_PS2JOYPAD1_LEFT		= ASURA_KEYID_PAD1_BUTTON16,
	ASURA_PC_KEYID_PS2JOYPAD1_RIGHT		= ASURA_KEYID_PAD1_BUTTON14,

	// Miscellaneous...
	ASURA_PC_KEYID_GAMEPAD1_SELECT		= ASURA_KEYID_PAD1_BUTTON9,
	ASURA_PC_KEYID_GAMEPAD1_START		= ASURA_KEYID_PAD1_BUTTON10,
	ASURA_PC_KEYID_GAMEPAD1_LTHUMB		= ASURA_KEYID_PAD1_BUTTON11,
	ASURA_PC_KEYID_GAMEPAD1_RTHUMB		= ASURA_KEYID_PAD1_BUTTON12,

	ASURA_PC_KEYID_PAD1_UP		= ASURA_KEYID_PAD1_BUTTON13,
	ASURA_PC_KEYID_PAD1_DOWN	= ASURA_KEYID_PAD1_BUTTON14,
	ASURA_PC_KEYID_PAD1_LEFT	= ASURA_KEYID_PAD1_BUTTON15,
	ASURA_PC_KEYID_PAD1_RIGHT	= ASURA_KEYID_PAD1_BUTTON16,
};

enum ASURA_PC_AXISID
{
	ASURA_PC_AXISID_PS2PAD1_LSTICK_H	= ASURA_AXIS_PAD1_LSTICK_H,
	ASURA_PC_AXISID_PS2PAD1_LSTICK_V	= ASURA_AXIS_PAD1_LSTICK_V,
	ASURA_PC_AXISID_PS2PAD1_RSTICK_H	= ASURA_AXIS_PAD1_ROTATE_Z,
	ASURA_PC_AXISID_PS2PAD1_RSTICK_V	= ASURA_AXIS_PAD1_Z,

	ASURA_PC_AXISID_PS3PAD1_LSTICK_H	= ASURA_AXIS_PAD1_LSTICK_H,
	ASURA_PC_AXISID_PS3PAD1_LSTICK_V	= ASURA_AXIS_PAD1_LSTICK_V,
	ASURA_PC_AXISID_PS3PAD1_RSTICK_H	= ASURA_AXIS_PAD1_Z,
	ASURA_PC_AXISID_PS3PAD1_RSTICK_V	= ASURA_AXIS_PAD1_ROTATE_Z,

	ASURA_PC_AXISID_XBOX360PAD1_LSTICK_H	= ASURA_AXIS_PAD1_LSTICK_H,
	ASURA_PC_AXISID_XBOX360PAD1_LSTICK_V	= ASURA_AXIS_PAD1_LSTICK_V,
	ASURA_PC_AXISID_XBOX360PAD1_RSTICK_H	= ASURA_AXIS_PAD1_ROTATE_X,
	ASURA_PC_AXISID_XBOX360PAD1_RSTICK_V	= ASURA_AXIS_PAD1_ROTATE_Y,
	ASURA_PC_AXISID_XBOX360PAD1_TRIGGER		= ASURA_AXIS_PAD1_Z,
};

class Asura_PlatformInput
{
public:

	// Return the joystick's product name (NULL if none)
	static const char* GetJoystickName() { return s_xJoystick.GetProductName(); }

	// init the static joystick object with the supplied guid
	static bool InitJoystickFromGUID(GUID& xGuid);
	//shutdown the static joystick object
	static void ShutdownJoystick();

	//get the directX friendly name of a joystick object (Asura_PC_Input_Joystick::ASURA_PC_JS_OBJECT)
	static const char* GetObjectName(int iObject);

	//get the joystick object for an asura axis (-1 for none)
	static int GetAxisObject(ASURA_AXIS_ID eAxis);
	//get the joystick object for an asura key (-1 for none)
	static int GetKeyObject(ASURA_KEYID eKey);

	//Flags a key as having been pressed
	static void SetKeyPressedThisFrame(ASURA_KEYID eKey);

private:

	friend class Asura_UserInput;
	friend class Asura_Windows;
	friend class Asura_Mouse;

	#ifdef ASURA_PC_SUPPORT_XINPUT
	friend class Asura_PC_Input_XInputPad;
	#else
	friend class Asura_PC_Input_Joystick;
	#endif

	// (AAM - 19.01.2004)
	// for s_xJoystick
	friend class Asura_Rumble_System;
	friend class Asura_Rumble_DirectInput;

	#ifdef ASURA_PC_SUPPORT_XINPUT
	friend class Asura_Rumble_XInput;
	#endif

	static Asura_Mouse Mouse;		

	// (AAM - 14.01.2004)
	#ifdef ASURA_PC_SUPPORT_XINPUT
	static Asura_PC_Input_XInputPad s_xJoystick;
	#else
	static Asura_PC_Input_Joystick s_xJoystick;
	#endif

	static bool AsciiKeyBuffer[ASURA_KEYID_END_OF_KEYBOARD];
	static unsigned char KeyPressedThisFrameBuffer[MAX_NUMBER_OF_ASURA_KEYIDS];
	
	static void KeyboardInput_AsciiKeyDown(int key);
	static void KeyboardInput_AsciiKeyUp(int key);
	static void KeyboardInput_ClearAsciiKeyBuffer(void);
};


#endif//__ASURA_PLATFORMINPUT_H__
