/// <summary>Unsubscribes the detector from all input devices</summary> private void unsubscribeAllEvents() { // Unsubscribe from all game pads for ( ExtendedPlayerIndex index = ExtendedPlayerIndex.Eight; index >= ExtendedPlayerIndex.One; --index ) { var method = this.subscribedGamePadReporters.Pop(); this.inputService.GetGamePad(index).ButtonPressed -= method; } // Unsubscribe from the main PC mouse { var method = this.subscribedMouseReporters.Pop(); this.inputService.GetMouse().MouseButtonPressed -= method; } // Unsubscribe from the main PC keyboard { var method = this.subscribedKeyReporters.Pop(); this.inputService.GetKeyboard().KeyPressed -= method; } // Unsubscribe from all chat pads for (PlayerIndex index = PlayerIndex.Four; index >= PlayerIndex.One; --index) { var method = this.subscribedKeyReporters.Pop(); this.inputService.GetKeyboard().KeyPressed -= method; } }
public void TestGetDirectInputGamePad(ExtendedPlayerIndex playerIndex) { using (var manager = new MockInputManager()) { Assert.IsNotNull(manager.GetGamePad(playerIndex)); Assert.IsNotNull(((IInputService)manager).GetGamePad(playerIndex)); } }
/// <summary>Subscribes the detector to all input devices</summary> private void subscribeAllEvents() { // Subscribe to all chat pads for (PlayerIndex index = PlayerIndex.One; index <= PlayerIndex.Four; ++index) { var reporter = new KeyReporter(this.detectedDelegate, (ExtendedPlayerIndex)index); var method = new KeyDelegate(reporter.KeyPressed); this.inputService.GetKeyboard(index).KeyPressed += method; this.subscribedKeyReporters.Push(method); } // Subscribe to the main PC keyboard { var reporter = new KeyReporter(this.detectedDelegate, null); var method = new KeyDelegate(reporter.KeyPressed); this.inputService.GetKeyboard().KeyPressed += method; this.subscribedKeyReporters.Push(method); } // Subscribe to the main PC mouse { var reporter = new MouseButtonReporter(this.detectedDelegate, null); var method = new MouseButtonDelegate(reporter.MouseButtonPressed); this.inputService.GetMouse().MouseButtonPressed += method; this.subscribedMouseReporters.Push(method); } // Subscribe to all game pads for ( ExtendedPlayerIndex index = ExtendedPlayerIndex.One; index <= ExtendedPlayerIndex.Eight; ++index ) { var reporter = new GamePadButtonReporter(this.detectedDelegate, index); var method = new GamePadButtonDelegate(reporter.ButtonPressed); this.inputService.GetGamePad(index).ButtonPressed += method; this.subscribedGamePadReporters.Push(method); } }
/// <summary>Initializes a new mouse reporter</summary> /// <param name="callback">Callback the reporter uses to report</param> /// <param name="playerIndex">Player index the reporter will report</param> public MouseButtonReporter( DetectionDelegate callback, ExtendedPlayerIndex? playerIndex ) : base(callback, playerIndex) { }
/// <summary>Initializes a new keyboard reporter</summary> /// <param name="callback">Callback the reporter uses to report</param> /// <param name="playerIndex">Player index the reporter will report</param> public KeyReporter( DetectionDelegate callback, ExtendedPlayerIndex? playerIndex ) : base(callback, playerIndex) { }
/// <summary>Initializes a new reporter</summary> /// <param name="callback">Callback the reporter uses to report</param> /// <param name="playerIndex">Player index the reporter will report</param> public Reporter(DetectionDelegate callback, ExtendedPlayerIndex? playerIndex) { this.Callback = callback; this.PlayerIndex = playerIndex; }
/// <summary>Called when a key/button press has been detected</summary> /// <param name="playerIndex">Index of the player who pressed a key/button</param> private void detected(ExtendedPlayerIndex? playerIndex) { OnControllerDetected(playerIndex); // Stop(); // Causes a StackEmptyException b/c unsubscribing inside event }
/// <summary>Fires the ControllerDetected event</summary> /// <param name="playerIndex">Event that will be fired</param> protected virtual void OnControllerDetected(ExtendedPlayerIndex? playerIndex) { if(ControllerDetected != null) { if(playerIndex.HasValue) { ControllerDetected(this, new ControllerEventArgs(playerIndex.Value)); } else { ControllerDetected(this, new ControllerEventArgs()); } } }
/// <summary>Returns the game pad for the specified player</summary> /// <param name="playerIndex">Player whose game pad will be returned</param> /// <returns>The game pad of the specified player</returns> IGamePad IInputService.GetGamePad(ExtendedPlayerIndex playerIndex) { return this.gamePads[(int)playerIndex]; }
/// <summary>Returns the game pad for the specified player</summary> /// <param name="playerIndex">Player whose game pad will be returned</param> /// <returns>The game pad of the specified player</returns> public IGamePad GetGamePad(ExtendedPlayerIndex playerIndex) { return(this.gamePads[(int)playerIndex]); }
/// <summary>Changes the controller which can interact with the GUI</summary> /// <param name="playerIndex"> /// Index of the player whose controller will be allowed to interact with the GUI /// </param> public void ChangePlayerIndex(ExtendedPlayerIndex playerIndex) { unsubscribePlayerSpecificInputDevices(); this.playerIndex = playerIndex; subscribePlayerSpecificDevices(); }
/// <summary>Returns the game pad for the specified player</summary> /// <param name="playerIndex">Player whose game pad will be returned</param> /// <returns>The game pad of the specified player</returns> IGamePad IInputService.GetGamePad(ExtendedPlayerIndex playerIndex) { return(this.gamePads[(int)playerIndex]); }
/// <summary>Initializes a new argument container with a controller index</summary> /// <param name="playerIndex">Player whose controller was detected</param> public ControllerEventArgs(ExtendedPlayerIndex playerIndex) { this.playerIndex = playerIndex; }
/// <summary>Returns the game pad for the specified player</summary> /// <param name="playerIndex">Player whose game pad will be returned</param> /// <returns>The game pad of the specified player</returns> public MockedGamePad GetGamePad(ExtendedPlayerIndex playerIndex) { return this.gamePads[(int)playerIndex]; }
/// <summary>Initializes a new matcher for controller event arguments</summary> /// <param name="playerIndex"> /// Index of the player to expect in the event arguments /// </param> public ControllerEventArgsMatcher(ExtendedPlayerIndex playerIndex) { this.playerIndex = playerIndex; }