//---------------------------------------------------------------------------------------------------------------------------------------------------
//
// Copyright (C)2007 DarkWynter Studios. All rights reserved.
//
//---------------------------------------------------------------------------------------------------------------------------------------------------
// {Contact : darkwynter.com for licensing information
//---------------------------------------------------------------------------------------------------------------------------------------------------
namespace DarkWynter.Engine.Controllers
{
#region Using Statements
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using System.Diagnostics;
#endregion
#region Controller and Key Types
///
/// Supported Controller Types
///
public enum ControllerType : byte
{
///
/// PC only
///
PC_ONLY,
///
/// Xbox 360 only
///
XBOX_ONLY,
///
/// PC and Xbox
///
PC_AND_XBOX,
///
/// None
///
NONE
}
///
/// Different mouse control types
///
public enum ControlType : byte
{
///
/// Motion Type
///
Motion,
///
/// Right Button Type
///
RightButton,
///
/// Left Button Type
///
LeftButton,
///
/// Middle Button Type
///
MiddleButton,
///
/// Scroll Wheel Type
///
ScrollWheel
};
///
/// Different Xbox Analog control types
///
public enum XboxAnalogControlType
{
///
/// Right Stick
///
RIGHT_STICK,
///
/// Left Stick
///
LEFT_STICK,
///
/// Right Trigger
///
RIGHT_TRIGGER,
///
/// Left Trigger
///
LEFT_TRIGGER
};
#endregion
///
/// Event Publisher
/// Game level classes observer and subscribe to these events
///
public class Controller
{
private PlayerIndex _playerIndex = 0;
private int _playerNumber = 0;
///
/// PlayerIndex this controller checks for
///
public PlayerIndex playerIndex { get { return _playerIndex; } set { _playerIndex = value; } }
///
/// Integer player index associated with this controller
///
public int playerNumber { get { return _playerNumber; } set { _playerNumber = value; } }
///
/// Keyboard State
///
public static KeyboardState keyboardState;
///
/// Game Pad State
///
public static GamePadState gamePadState;
///
/// Mouse State
///
public static MouseState mouseState;
///
/// Controller Type
///
public ControllerType playerControllerType = ControllerType.NONE;
List keyboardControls = new List();
List xboxAnalogControls = new List();
List xboxDigitalControls = new List();
List mouseControls = new List();
///
/// Constructor for PC and mouse only
///
/// Player index in ObjectLibrary
public Controller(int player)
{
playerNumber = player;
playerIndex = (PlayerIndex) player;
mouseState = new MouseState();
keyboardState = new KeyboardState();
playerControllerType = ControllerType.PC_ONLY;
}
///
/// Constructor for Xbox
///
/// Controller index to associate with this controller
public Controller(PlayerIndex pIndex)
{
playerNumber = ((int)pIndex) - 1;
playerIndex = pIndex;
gamePadState = new GamePadState();
playerControllerType = ControllerType.XBOX_ONLY;
}
///
/// Constructor for Xbox and keyboard controls
///
/// Player index in ObjectLibrary
/// Controller index
public Controller(int player, PlayerIndex pIndex)
{
playerNumber = player;
playerIndex = pIndex;
keyboardState = new KeyboardState();
gamePadState = new GamePadState();
mouseState = new MouseState();
playerControllerType = ControllerType.PC_AND_XBOX;
}
///
/// Add a Keyboard control
///
/// Keyboard control
public void Add(KeyboardControl control)
{
keyboardControls.Add(control);
}
///
/// Add a Xbox Analog control
///
/// Xbox Analog control
public void Add(XboxAnalogControl control)
{
xboxAnalogControls.Add(control);
}
///
/// Add a Xbox Digital control
///
/// Xbox Digital control
public void Add(XboxDigitalControl control)
{
xboxDigitalControls.Add(control);
}
///
/// Add a Mouse control
///
/// Mouse control
public void Add(MouseControl control)
{
mouseControls.Add(control);
}
///
/// Update Method - Simple wrapper pipe to Update(list args);
///
/// Arguments passed to Control override classes on key events
public void Update(object arg)
{
List