//--------------------------------------------------------------------------------------------------------------------------------------------------- // // 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; using DarkWynter.Engine.Globals; using DarkWynter.Engine.ObjectLib; using DarkWynter.Engine.Menus; using DarkWynter.Engine.Controllers; using DarkWynter.Stream; #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 Enums_Engine.ControllerType playerControllerType = Enums_Engine.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 = Enums_Engine.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 = Enums_Engine.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 = Enums_Engine.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 /// /// Object Library /// Menu System public void Update(ObjectLibrary objectLibrary, MenuSystem menuSystem) { gamePadState = GamePad.GetState(playerIndex); keyboardState = Keyboard.GetState(); mouseState = Mouse.GetState(); // Update Controls if not paused if (Statics_Engine.SystemSettings.gameState != Enums_Engine.EngineState.GAME_PAUSE) { // PC for (int i = 0; i < keyboardControls.Count; i++) { keyboardControls[i].Update(keyboardState, ref objectLibrary, ref menuSystem); } for (int i = 0; i < mouseControls.Count; i++) { mouseControls[i].Update(mouseState, ref objectLibrary, ref menuSystem); } // XBOX for (int i = 0; i < xboxAnalogControls.Count; i++) { xboxAnalogControls[i].Update(gamePadState, ref objectLibrary, ref menuSystem); } for (int i = 0; i < xboxDigitalControls.Count; i++) { xboxDigitalControls[i].Update(gamePadState, ref objectLibrary, ref menuSystem); } } else { // ======= Check for unpause button ========= } } /// /// Kills the rumble on all controllers /// /// ObjectLibrary public static void StopRumble(ObjectLibrary objectLibrary) { if (objectLibrary != null && objectLibrary.humans != null && objectLibrary.bots != null) { for (int i = 0; i < objectLibrary.humans.Count; i++) { if (objectLibrary.humans[i] != null) { objectLibrary.humans[i].stopRumble = true; } } } } } }