/// <summary> /// Identifies a player /// </summary> /// <param name="playerInput">The PlayerInput instance used by the player to identify</param> public override void IdentifyPlayer(PlayerInput playerInput) { var identifiedPlayer = new LocalIdentifiedPlayer(playerInput); LocalPlayers.Add(playerInput.PlayerIndex, identifiedPlayer); OnPlayerLogin(identifiedPlayer); }
/// <summary> /// Creates a new instance /// </summary> /// <param name="renderToScreen">Set it to true to render directly to screen; false to use the Texture property and render the Screen content elsewhere</param> /// <param name="isMenu">If set to true, the inner Buttons will react as in a standard menu; false means that you'll control how inner controls react to input events within their Control.HandleInput() method</param> /// <param name="playerInput">The player input state instance. One Screen can only be controlled by One PlayerInput instance</param> /// <param name="width">The width of the screen, this will be also be used for the inner RenderTarget2D if renderToScreen is set to true</param> /// <param name="height">The height of the screen, this will be also be used for the inner RenderTarget2D if renderToScreen is set to true</param> public Screen(bool renderToScreen, bool isMenu, PlayerInput playerInput, int width, int height) { Alpha = 1.0f; // we create the render target where the screen will be rendered to RendersToScreen = renderToScreen; // we create an empty controls list controls will be added to. _controls = new List<Control>(); _focusableControls = new List<Control>(); // we set the initial visibility status to true IsVisible = true; CanFocus = true; IsMenu = isMenu; _playerInput = playerInput; Width = width; Height = height; InputSensibility = 0.2f; }
/// <summary> /// Creates a new instance /// </summary> /// <param name="playerInput"></param> internal LiveIdentifiedPlayer(PlayerInput playerInput, LocalNetworkGamer localNetworkGamer) : base(playerInput) { LiveGamer = localNetworkGamer; UniqueId = localNetworkGamer.Gamertag; DisplayName = localNetworkGamer.Gamertag; IsHost = localNetworkGamer.IsHost; }
/// <summary> /// Identifies a player /// </summary> /// <param name="playerInput">The PlayerInput instance used by the player to identify</param> public override void IdentifyPlayer(PlayerInput playerInput) { if (Guide.IsVisible) return; if (LocalPlayers.ContainsKey(playerInput.PlayerIndex) && (IsIdentifyingPlayers || (CurrentSession != null && CurrentSession.Status == SessionState.Playing && CurrentSession.AllowJoinInProgress))) { OnPlayerLogin(LocalPlayers[playerInput.PlayerIndex]); return; } Guide.ShowSignIn(1, false); }
/// <summary> /// Creates a new instance of the InputManager component and adds itself to the game's component collection as well as Service /// </summary> /// <param name = "application">The game instance</param> public InputManager(Application application) : base(application) { if (application == null) throw new ArgumentNullException("application", "InputManager requires a valid application instance"); if (Application.Input != null) throw new CoreException("There already is an InputManager instance."); application.Components.Add(this); application.Services.AddService(typeof (InputManager), this); Player1 = new PlayerInput(PlayerIndex.One); Player1.Connected += OnPlayerConnected; Player1.Disconnected += OnPlayerDisconnected; Player2 = new PlayerInput(PlayerIndex.Two); Player2.Connected += OnPlayerConnected; Player2.Disconnected += OnPlayerDisconnected; Player3 = new PlayerInput(PlayerIndex.Three); Player3.Connected += OnPlayerConnected; Player3.Disconnected += OnPlayerDisconnected; Player4 = new PlayerInput(PlayerIndex.Four); Player4.Connected += OnPlayerConnected; Player4.Disconnected += OnPlayerDisconnected; _noInputDeviceConnectedPlayer1 = new NoPlayerInput(PlayerIndex.One); _noInputDeviceConnectedPlayer2 = new NoPlayerInput(PlayerIndex.Two); _noInputDeviceConnectedPlayer3 = new NoPlayerInput(PlayerIndex.Three); _noInputDeviceConnectedPlayer4 = new NoPlayerInput(PlayerIndex.Four); _connectedPlayers = new Dictionary<PlayerIndex, PlayerInput>(); Player1.CheckConnectionStatus(); Player2.CheckConnectionStatus(); Player3.CheckConnectionStatus(); Player4.CheckConnectionStatus(); #if WINDOWS Game.Activated += delegate { _windowFocused = true; }; Game.Deactivated += delegate { _windowFocused = false; }; _windowFocused = true; #elif WINDOWS_PHONE VirtualGamePadSkin = new VirtualGamePadSkin(); #endif }
/// <summary> /// Creates a new instance /// </summary> /// <param name="renderToScreen">Set it to true to render directly to screen; false to use the Texture property and render the Screen content elsewhere</param> /// <param name="isMenu">If set to true, the inner Buttons will react as in a standard menu; false means that you'll control how inner controls react to input events within their Control.HandleInput() method</param> /// <param name="playerInput">The player input state instance. One Screen can only be controlled by One PlayerInput instance</param> /// <param name="width">The width of the screen, this will be also be used for the inner RenderTarget2D if renderToScreen is set to true</param> /// <param name="height">The height of the screen, this will be also be used for the inner RenderTarget2D if renderToScreen is set to true</param> public Screen(bool renderToScreen, bool isMenu, PlayerInput playerInput, int width, int height) { Alpha = 1.0f; // we create the render target where the screen will be rendered to RendersToScreen = renderToScreen; // we create an empty controls list controls will be added to. _controls = new List<Control>(); _focusableControls = new List<Control>(); // we set the initial visibility status to true IsVisible = true; CanFocus = true; IsMenu = isMenu; _playerInput = playerInput; Width = width; Height = height; InputSensibility = 0.2f; Application.Graphics.DeviceReset += (sender, args) => { if (IsVisible) foreach (Control control in _controls) { if (control.IsVisible) ((IGuiElement)control).Invalidate(); } }; }
/// <summary> /// Identifies a player /// </summary> /// <param name="playerInput">The PlayerInput instance used by the player to identify</param> public abstract void IdentifyPlayer(PlayerInput playerInput);
/// <summary> /// Creates a new local player instance /// </summary> /// <param name="playerInput">The PlayerInput instance used by the Player</param> internal LocalIdentifiedPlayer(PlayerInput playerInput) : base(playerInput) { UniqueId = playerInput.PlayerIndex.ToString(); IsHost = playerInput != null; DisplayName = Enum.GetName(typeof (PlayerIndex), playerInput.PlayerIndex); }
/// <summary> /// Creates a new local player instance /// </summary> /// <param name="playerInput">The PlayerInput instance used by the Player</param> protected IdentifiedPlayer(PlayerInput playerInput) { Input = playerInput; LogicalPlayerIndex = LogicalPlayerIndex.None; }
/// <summary> /// Creates a new local player instance /// </summary> /// <param name="playerInput">The PlayerInput instance used by the Player</param> public LidgrenIdentifiedPlayer(PlayerInput playerInput) : base(playerInput) { UniqueId = Guid.NewGuid().ToString(); }
/// <summary> /// Handles the input events from the player controlling the current control /// </summary> /// <param name="input">The current player input states</param> /// <param name="gameTime">The GameTime instance</param> public virtual void HandleInput(PlayerInput input, GameTime gameTime) { }
/// <summary> /// Creates a new instance which width and height are set to the current Viewport Width and Height /// </summary> /// <param name="renderToScreen">Set it to true to render directly to screen; false to use the Texture property and render the Screen content elsewhere</param> /// <param name="isMenu">If set to true, the inner Buttons will react as in a standard menu; false means that you'll control how inner controls react to input events within their Control.HandleInput() method</param> /// <param name="playerInput">The player input state instance. One Screen can only be controlled by One PlayerInput instance</param> public Screen(bool renderToScreen, bool isMenu, PlayerInput playerInput) : this(renderToScreen, isMenu, playerInput, Application.Graphics.PreferredBackBufferWidth, Application.Graphics.PreferredBackBufferHeight) { }
/// <summary> /// Handles the input events from the player controlling the current control /// </summary> /// <param name="input">The current player input states</param> /// <param name="gameTime">The GameTime instance</param> public virtual void HandleInput(PlayerInput input, GameTime gameTime) { if (input.Buttons.B.IsReleased || input.Buttons.Back.IsReleased) { if (BackButtonPressed != null) BackButtonPressed(this, EventArgs.Empty); } if (!IsMenu) { foreach (Control focusableControl in _focusableControls) { if (focusableControl.IsVisible) focusableControl.HandleInput(input, gameTime); } } else { #if WINDOWS if (input.UseKeyboardMouseInput && Application.Input.IsMouseVisible) { var mousePosition = new Point(input.KeyboardMouseState.MouseState.X, input.KeyboardMouseState.MouseState.Y); for (int i = 0; i < _focusableControls.Count; i++) { Control focusableControl = _focusableControls[i]; var bounds = new Rectangle(focusableControl.X, focusableControl.Y, focusableControl.Width, focusableControl.Height); if (bounds.Contains(mousePosition)) { focusableControl.SetFocus(); _focusedControlIndex = i; } else { if (focusableControl.HasFocus) focusableControl.LoseFocus(); } if (focusableControl.HasFocus) { if (_movementSleep <= 0.2f) _movementSleep += (float)gameTime.ElapsedGameTime.TotalSeconds; else if (input.Buttons.LeftStickClick.IsReleased) focusableControl.OnClicked(); else if (input.ThumbSticks.LeftStick.X < 0 && _movementSleep > InputSensibility) focusableControl.OnInputLeft(); else if (input.ThumbSticks.LeftStick.X > 0 && _movementSleep > InputSensibility) focusableControl.OnInputRight(); else if (input.ThumbSticks.LeftStick.Y < 0 && _movementSleep > InputSensibility) focusableControl.OnInputDown(); else if (input.ThumbSticks.LeftStick.Y > 0 && _movementSleep > InputSensibility) focusableControl.OnInputUp(); } } return; } #elif WINDOWS_PHONE if (input.UseWindowsPhoneTouch) { _previousMouseState = _currentMouseState; _currentMouseState = Mouse.GetState(); Point mousePosition; if(_currentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed) mousePosition = new Point(_currentMouseState.X, _currentMouseState.Y); else return; for (int i = 0; i < _focusableControls.Count; i++) { Control focusableControl = _focusableControls[i]; var bounds = new Rectangle(focusableControl.X, focusableControl.Y, focusableControl.Width, focusableControl.Height); if (bounds.Contains(mousePosition)) { if (focusableControl.HasFocus) { if (_currentMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed && _previousMouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Released) focusableControl.OnClicked(); } else { focusableControl.SetFocus(); _focusedControlIndex = i; } } else { if (focusableControl.HasFocus) { focusableControl.LoseFocus(); } } } return; } #endif if (_focusableControls.Count == 0) return; if (input.Buttons.A.IsReleased) _focusableControls[_focusedControlIndex].OnClicked(); int newFocusedControlIndex = _focusedControlIndex; if (input.ThumbSticks.LeftStick.Y > 0) { if (_movementSleep.Equals(0f) || _movementSleep >= InputSensibility) { newFocusedControlIndex--; if (newFocusedControlIndex < 0) newFocusedControlIndex = 0; _focusableControls[newFocusedControlIndex].OnInputUp(); _movementSleep = 0f; } _movementSleep += (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (input.ThumbSticks.LeftStick.Y < 0) { if (_movementSleep.Equals(0f) || _movementSleep >= InputSensibility) { newFocusedControlIndex++; if (newFocusedControlIndex > _focusableControls.Count - 1) newFocusedControlIndex = _focusableControls.Count - 1; _focusableControls[newFocusedControlIndex].OnInputDown(); _movementSleep = 0f; } _movementSleep += (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (input.ThumbSticks.LeftStick.X > 0) { if (_movementSleep.Equals(0f) || _movementSleep >= InputSensibility) { _focusableControls[_focusedControlIndex].OnInputRight(); _movementSleep = 0f; } _movementSleep += (float)gameTime.ElapsedGameTime.TotalSeconds; } else if (input.ThumbSticks.LeftStick.X < 0) { if (_movementSleep.Equals(0f) || _movementSleep >= InputSensibility) { _focusableControls[_focusedControlIndex].OnInputLeft(); _movementSleep = 0f; } _movementSleep += (float)gameTime.ElapsedGameTime.TotalSeconds; } else { _movementSleep = 0f; } if (newFocusedControlIndex != _focusedControlIndex) { _focusableControls[_focusedControlIndex].LoseFocus(); _focusedControlIndex = newFocusedControlIndex; _focusableControls[_focusedControlIndex].SetFocus(); } } }