//-------------------------------------------------------------- #region Properties & Events //-------------------------------------------------------------- #endregion //-------------------------------------------------------------- #region Methods //-------------------------------------------------------------- /// <inheritdoc/> public PlayerIndex?GetLogicalPlayer(LogicalPlayerIndex player) { // For efficiency: No boundary checks - array will throw exception anyways. int index = (int)player; return(_logicalPlayers[index]); }
/// <summary> /// Returns the Identified player with the given logical player index /// </summary> /// <param name="logicalPlayerIndex"></param> /// <returns>Returns the corresponding IdentifiedPlayer if found; null otherwise</returns> public static IdentifiedPlayer GetIdentifiedPlayer(LogicalPlayerIndex logicalPlayerIndex) { if (LogicalPlayers.ContainsKey(logicalPlayerIndex)) return LogicalPlayers[logicalPlayerIndex]; throw new CoreException("No players identified as " + logicalPlayerIndex.ToString()); }
/// <inheritdoc/> public void SetLogicalPlayer(LogicalPlayerIndex player, PlayerIndex?controller) { // For efficiency: No boundary checks - array will throw exception anyways. int index = (int)player; _logicalPlayers[index] = controller; }
public bool IsUp(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.All) { // Check game controllers of all players. bool isUp = true; foreach (PlayerIndex?controller in logicalPlayerMapping) { if (controller.HasValue) { if (!IsDown(ref currGamePadStates[(int)controller.Value], button)) { return(true); } isUp = false; } } return(isUp); } else { PlayerIndex?controller = logicalPlayerMapping[(int)player]; if (controller.HasValue) { return(!IsDown(ref currGamePadStates[(int)controller.Value], button)); } return(true); } }
public Player GetPlayer(LogicalPlayerIndex index) { if (players.ContainsKey(index)) return players[index]; else return null; }
/// <inheritdoc/> public GamePadState GetPreviousGamePadState(LogicalPlayerIndex player) { PlayerIndex? controller = _logicalPlayers[(int)player]; if (controller.HasValue) return _previousGamePadStates[(int)controller.Value]; return DefaultGamePadState; }
/// <summary> /// Returns the Identified player with the given logical player index /// </summary> /// <param name="logicalPlayerIndex"></param> /// <returns>Returns the corresponding IdentifiedPlayer if found; null otherwise</returns> public static IdentifiedPlayer GetIdentifiedPlayer(LogicalPlayerIndex logicalPlayerIndex) { if (LogicalPlayers.ContainsKey(logicalPlayerIndex)) { return(LogicalPlayers[logicalPlayerIndex]); } throw new CoreException("No players identified as " + logicalPlayerIndex.ToString()); }
/// <inheritdoc/> public GamePadState GetPreviousGamePadState(LogicalPlayerIndex player) { PlayerIndex?controller = _logicalPlayers[(int)player]; if (controller.HasValue) { return(_previousGamePadStates[(int)controller.Value]); } return(DefaultGamePadState); }
public GamePadState GetPreviousGamePadState(LogicalPlayerIndex player) { PlayerIndex?controller = logicalPlayerMapping[(int)player]; if (controller.HasValue) { return(prevGamePadStates[(int)controller.Value]); } return(BlankGamePadState); }
public Player GetPlayer(LogicalPlayerIndex index) { if (players.ContainsKey(index)) { return(players[index]); } else { return(null); } }
public T GetDevice <T>(LogicalPlayerIndex playerIndex) where T : Device { foreach (Device d in _registeredDevices) { if ((d.LogicalPlayerIndex == playerIndex) && (d is T)) { return((T)d); } } return(null); }
public void SetPlayer(LogicalPlayerIndex index, PlayerIndex controller) { if (!players.ContainsKey(index)) { Player player = new Player(index, controller); player.InputHandler = InputHandler; if (InputHandler != null) InputHandler.SetPlayerMapping(index, controller); players.Add(index, player); } }
/// <summary> /// Get devices registered for a player /// </summary> /// <param name="playerIndex"></param> /// <returns></returns> public List<Device> GetLinkedDevices(LogicalPlayerIndex playerIndex) { List<Device> devices = new List<Device>(); foreach (Device d in _registeredDevices) { if (d.LogicalPlayerIndex == playerIndex) { devices.Add(d); } } return devices; }
/// <summary> /// Get devices registered for a player /// </summary> /// <param name="playerIndex"></param> /// <returns></returns> public List <Device> GetLinkedDevices(LogicalPlayerIndex playerIndex) { List <Device> devices = new List <Device>(); foreach (Device d in _registeredDevices) { if (d.LogicalPlayerIndex == playerIndex) { devices.Add(d); } } return(devices); }
public void SetPlayer(LogicalPlayerIndex index, PlayerIndex controller) { if (!players.ContainsKey(index)) { Player player = new Player(index, controller); player.InputHandler = InputHandler; if (InputHandler != null) { InputHandler.SetPlayerMapping(index, controller); } players.Add(index, player); } }
protected Device(LogicalPlayerIndex logicalPlayerIndex, DeviceType type, int index) { Type = type; _index = index; mapping = new Dictionary<MappingButtons, ButtonState>(); ThumbStickRight = new ThumbstickState(); ThumbStickLeft = new ThumbstickState(); rumbles = new Rumble[4]; for (int i = 0; i < rumbles.Length; i++) { rumbles[i] = new Rumble(0); } RumbleAssignation(); }
/// <inheritdoc/> public void SetGamePadHandled(LogicalPlayerIndex player, bool value) { if (player == LogicalPlayerIndex.Any) { foreach (PlayerIndex? controller in _logicalPlayers) { if (controller.HasValue) _areGamePadsHandled[(int)controller.Value] = value; } } else { var controller = GetLogicalPlayer(player); if (controller.HasValue) _areGamePadsHandled[(int)controller.Value] = value; } }
protected Device(LogicalPlayerIndex logicalPlayerIndex, DeviceType type, int index) { Type = type; _index = index; mapping = new Dictionary <MappingButtons, ButtonState>(); ThumbStickRight = new ThumbstickState(); ThumbStickLeft = new ThumbstickState(); rumbles = new Rumble[4]; for (int i = 0; i < rumbles.Length; i++) { rumbles[i] = new Rumble(0); } RumbleAssignation(); }
/// <inheritdoc/> public bool IsGamePadHandled(LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { foreach (var controller in _logicalPlayers) { if (controller.HasValue && _areGamePadsHandled[(int)controller.Value]) return true; } } else { var controller = GetLogicalPlayer(player); if (controller.HasValue) return _areGamePadsHandled[(int)controller.Value]; } return false; }
public void SetGamePadHandled(LogicalPlayerIndex player, bool value) { if (player == LogicalPlayerIndex.All) { foreach (PlayerIndex?controller in logicalPlayerMapping) { if (controller.HasValue) { controllerHandled[(int)controller.Value] = value; } } } else { var controller = GetPlayerMapping(player); if (controller.HasValue) { controllerHandled[(int)controller.Value] = value; } } }
public bool IsNewlyPressed(Buttons button, bool useButtonRepetition, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.All) { // Check game controllers of all players. foreach (PlayerIndex?controller in logicalPlayerMapping) { if (controller.HasValue && IsNewlyPressed(button, useButtonRepetition, controller.Value)) { return(true); } } return(false); } else { PlayerIndex?controller = logicalPlayerMapping[(int)player]; return(controller.HasValue && IsNewlyPressed(button, useButtonRepetition, controller.Value)); } }
/// <inheritdoc/> public bool IsDoubleClick(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { // Check game controllers of all players. foreach (PlayerIndex?controller in _logicalPlayers) { if (controller.HasValue && IsDoubleClick(button, controller.Value)) { return(true); } } return(false); } else { PlayerIndex?controller = _logicalPlayers[(int)player]; return(controller.HasValue && IsDoubleClick(button, controller.Value)); } }
/// <inheritdoc/> public bool IsDown(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { // Check game controllers of all players. foreach (PlayerIndex?controller in _logicalPlayers) { if (controller.HasValue && IsDown(ref _newGamePadStates[(int)controller.Value], button)) { return(true); } } return(false); } else { PlayerIndex?controller = _logicalPlayers[(int)player]; return(controller.HasValue && IsDown(ref _newGamePadStates[(int)controller.Value], button)); } }
public bool IsReleased(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.All) { //Check if any player has released the provided button... foreach (PlayerIndex?controller in logicalPlayerMapping) { if (controller.HasValue && IsReleased(button, controller.Value)) { return(true); } } return(false); } else { //Check if the given player has released the provided button... PlayerIndex?controller = logicalPlayerMapping[(int)player]; return(controller.HasValue && IsReleased(button, controller.Value)); } }
public bool GamepadInputConsumed(LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.All) { foreach (PlayerIndex?controller in logicalPlayerMapping) { if (controller.HasValue && controllerHandled[(int)controller.Value]) { return(true); } } } else { PlayerIndex?controller = GetPlayerMapping(player); if (controller.HasValue) { return(controllerHandled[(int)controller.Value]); } } return(false); }
public Player(LogicalPlayerIndex index, PlayerIndex controller) { this.index = index; this.Controller = controller; }
public KeyboardDevice(LogicalPlayerIndex logicalPlayerIndex) : base(logicalPlayerIndex,DeviceType.KeyboardMouse, 0) { _keyboardMapping = new Dictionary<Keys, MappingButtons>(); }
public JoypadDevice(LogicalPlayerIndex logicalPlayerIndex, int index) : base(logicalPlayerIndex,DeviceType.Joystick, index) { }
public GamepadDevice(LogicalPlayerIndex logicalPlayerIndex, PlayerIndex index) : base(logicalPlayerIndex, DeviceType.Gamepad, (int)index) { }
/// <summary> /// Maps an internal logical player index to a controller index. /// </summary> /// <param name="player">The logical/internal index of the player to map.</param> /// <param name="controller">The index of the controller itself.</param> public void SetPlayerMapping(LogicalPlayerIndex player, PlayerIndex?controller) { logicalPlayerMapping[(int)player] = controller; }
public KeyboardDevice(LogicalPlayerIndex logicalPlayerIndex) : base(logicalPlayerIndex, DeviceType.Keyboard, 0) { _keyboardMapping = new Dictionary <Keys, MappingButtons>(); }
/// <summary> /// Gets the (controller) PlayerIndex for the player mapped to the (internal) logical player index. /// </summary> /// <param name="player">The logical player index to get a PlayerIndex mapping for.</param> /// <returns>The PlayerIndex corresponding to the provided logical player index, or null if no mapping exists.</returns> public PlayerIndex?GetPlayerMapping(LogicalPlayerIndex player) { return(logicalPlayerMapping[(int)player]); }
public static PlayerIndex GetPlayerIndex(LogicalPlayerIndex inIndex) { return mPlayerIndices[(int)inIndex]; }
public static void SetPlayerIndex(LogicalPlayerIndex inLogicalIndex, PlayerIndex inPlayerIndex) { mPlayerIndices[(int)inLogicalIndex] = inPlayerIndex; }
public MouseDevice(LogicalPlayerIndex logicalPlayerIndex) : base(logicalPlayerIndex, DeviceType.Mouse, 0) { }
public JoypadDevice(LogicalPlayerIndex logicalPlayerIndex, int index) : base(logicalPlayerIndex, DeviceType.Joystick, index) { }
/// <inheritdoc/> public bool IsDoubleClick(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { // Check game controllers of all players. foreach (PlayerIndex? controller in _logicalPlayers) if (controller.HasValue && IsDoubleClick(button, controller.Value)) return true; return false; } else { PlayerIndex? controller = _logicalPlayers[(int)player]; return controller.HasValue && IsDoubleClick(button, controller.Value); } }
internal void MoveFocus(UIControl control, LogicalPlayerIndex allowedPlayer) { // Called by the UIControl after UIControl.OnHandleInput. if (control == null) return; var inputService = InputService; // Handle AutoUnfocus. if (control.AutoUnfocus && FocusedControl != null) { if (inputService.IsPressed(MouseButtons.Left, false) || inputService.IsPressed(MouseButtons.Right, false)) { if (control == FocusScope && !FocusedControl.IsMouseOver // E.g. a window and not the focused control is clicked. || control.IsMouseDirectlyOver && !inputService.IsMouseOrTouchHandled) // E.g. a screen and no child UIControl is clicked. { ClearFocus(); } } } // Only focus scopes handle focus movement. // And only the current focus scope (which means the first focus scope in the hierarchy). if (!control.IsFocusScope || FocusScope != null && control != FocusScope) return; bool moveLeft = false; bool moveRight = false; bool moveUp = false; bool moveDown = false; // Check arrow keys. if (!inputService.IsKeyboardHandled) { // This focus scope "absorbs" arrow keys. if (inputService.IsDown(Keys.Left) || inputService.IsDown(Keys.Right) || inputService.IsDown(Keys.Up) || inputService.IsDown(Keys.Down)) { inputService.IsKeyboardHandled = true; if (inputService.IsPressed(Keys.Left, true)) moveLeft = true; else if (inputService.IsPressed(Keys.Right, true)) moveRight = true; else if (inputService.IsPressed(Keys.Up, true)) moveUp = true; else if (inputService.IsPressed(Keys.Down, true)) moveDown = true; } } #if !SILVERLIGHT // Check left thumb stick and d-pad. if (!moveLeft && !moveRight && !moveUp && !moveDown && !inputService.IsGamePadHandled(allowedPlayer)) { if (inputService.IsDown(Buttons.LeftThumbstickLeft, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickRight, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickUp, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickDown, allowedPlayer) || inputService.IsDown(Buttons.DPadLeft, allowedPlayer) || inputService.IsDown(Buttons.DPadRight, allowedPlayer) || inputService.IsDown(Buttons.DPadUp, allowedPlayer) || inputService.IsDown(Buttons.DPadDown, allowedPlayer)) { inputService.SetGamePadHandled(allowedPlayer, true); if (inputService.IsPressed(Buttons.LeftThumbstickLeft, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadLeft, true, allowedPlayer)) moveLeft = true; else if (inputService.IsPressed(Buttons.LeftThumbstickRight, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadRight, true, allowedPlayer)) moveRight = true; else if (inputService.IsPressed(Buttons.LeftThumbstickUp, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadUp, true, allowedPlayer)) moveUp = true; else if (inputService.IsPressed(Buttons.LeftThumbstickDown, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadDown, true, allowedPlayer)) moveDown = true; } } #endif // Now, we know in which direction the focus should move. if (!moveLeft && !moveRight && !moveUp && !moveDown) return; // Collect all focusable controls. _focusableControls.Clear(); GetFocusableControls(control); if (_focusableControls.Count == 0) return; // Call virtual method that does the job. var target = OnMoveFocus(moveLeft, moveRight, moveUp, moveDown, _focusableControls); Focus(target); _focusableControls.Clear(); }
//-------------------------------------------------------------- /// <inheritdoc/> public PlayerIndex? GetLogicalPlayer(LogicalPlayerIndex player) { // For efficiency: No boundary checks - array will throw exception anyways. int index = (int)player; return _logicalPlayers[index]; }
/// <inheritdoc/> public bool IsDown(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { // Check game controllers of all players. foreach (PlayerIndex? controller in _logicalPlayers) if (controller.HasValue && IsDown(ref _newGamePadStates[(int)controller.Value], button)) return true; return false; } else { PlayerIndex? controller = _logicalPlayers[(int)player]; return controller.HasValue && IsDown(ref _newGamePadStates[(int)controller.Value], button); } }
/// <inheritdoc/> public bool IsUp(Buttons button, LogicalPlayerIndex player) { if (player == LogicalPlayerIndex.Any) { // Check game controllers of all players. bool isUp = true; foreach (PlayerIndex? controller in _logicalPlayers) { if (controller.HasValue) { if (!IsDown(ref _newGamePadStates[(int)controller.Value], button)) return true; isUp = false; } } return isUp; } else { PlayerIndex? controller = _logicalPlayers[(int)player]; if (controller.HasValue) return !IsDown(ref _newGamePadStates[(int)controller.Value], button); return true; } }
internal void MoveFocus(UIControl control, LogicalPlayerIndex allowedPlayer) { // Called by the UIControl after UIControl.OnHandleInput. if (control == null) { return; } var inputService = InputService; // Handle AutoUnfocus. if (control.AutoUnfocus && FocusedControl != null) { if (inputService.IsPressed(MouseButtons.Left, false) || inputService.IsPressed(MouseButtons.Right, false)) { if (control == FocusScope && !FocusedControl.IsMouseOver || // E.g. a window and not the focused control is clicked. control.IsMouseDirectlyOver && !inputService.IsMouseOrTouchHandled) // E.g. a screen and no child UIControl is clicked. { ClearFocus(); } } } // Only focus scopes handle focus movement. // And only the current focus scope (which means the first focus scope in the hierarchy). if (!control.IsFocusScope || FocusScope != null && control != FocusScope) { return; } bool moveLeft = false; bool moveRight = false; bool moveUp = false; bool moveDown = false; // Check arrow keys. if (!inputService.IsKeyboardHandled) { // This focus scope "absorbs" arrow keys. if (inputService.IsDown(Keys.Left) || inputService.IsDown(Keys.Right) || inputService.IsDown(Keys.Up) || inputService.IsDown(Keys.Down)) { inputService.IsKeyboardHandled = true; if (inputService.IsPressed(Keys.Left, true)) { moveLeft = true; } else if (inputService.IsPressed(Keys.Right, true)) { moveRight = true; } else if (inputService.IsPressed(Keys.Up, true)) { moveUp = true; } else if (inputService.IsPressed(Keys.Down, true)) { moveDown = true; } } } #if !SILVERLIGHT // Check left thumb stick and d-pad. if (!moveLeft && !moveRight && !moveUp && !moveDown && !inputService.IsGamePadHandled(allowedPlayer)) { if (inputService.IsDown(Buttons.LeftThumbstickLeft, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickRight, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickUp, allowedPlayer) || inputService.IsDown(Buttons.LeftThumbstickDown, allowedPlayer) || inputService.IsDown(Buttons.DPadLeft, allowedPlayer) || inputService.IsDown(Buttons.DPadRight, allowedPlayer) || inputService.IsDown(Buttons.DPadUp, allowedPlayer) || inputService.IsDown(Buttons.DPadDown, allowedPlayer)) { inputService.SetGamePadHandled(allowedPlayer, true); if (inputService.IsPressed(Buttons.LeftThumbstickLeft, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadLeft, true, allowedPlayer)) { moveLeft = true; } else if (inputService.IsPressed(Buttons.LeftThumbstickRight, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadRight, true, allowedPlayer)) { moveRight = true; } else if (inputService.IsPressed(Buttons.LeftThumbstickUp, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadUp, true, allowedPlayer)) { moveUp = true; } else if (inputService.IsPressed(Buttons.LeftThumbstickDown, true, allowedPlayer) || inputService.IsPressed(Buttons.DPadDown, true, allowedPlayer)) { moveDown = true; } } } #endif // Now, we know in which direction the focus should move. if (!moveLeft && !moveRight && !moveUp && !moveDown) { return; } // Collect all focusable controls. _focusableControls.Clear(); GetFocusableControls(control); if (_focusableControls.Count == 0) { return; } // Call virtual method that does the job. var target = OnMoveFocus(moveLeft, moveRight, moveUp, moveDown, _focusableControls); Focus(target); _focusableControls.Clear(); }
/// <inheritdoc/> public void SetLogicalPlayer(LogicalPlayerIndex player, PlayerIndex? controller) { // For efficiency: No boundary checks - array will throw exception anyways. int index = (int)player; _logicalPlayers[index] = controller; }