Ejemplo n.º 1
0
 public void OnInputDeviceAdded(int deviceId)
 {
     //Log.Debug(TAG, "OnInputDeviceAdded: " + deviceId);
     if (!connected_devices.Contains(deviceId))
     {
         connected_devices.Add(deviceId);
     }
     if (current_device_id == -1)
     {
         current_device_id = deviceId;
         InputDevice dev = InputDevice.GetDevice(current_device_id);
         if (dev != null)
         {
             //controller_view.SetCurrentControllerNumber(dev.ControllerNumber);
             //controller_view.Invalidate();
         }
     }
     updateOnScreenJoyVisibility();
 }
Ejemplo n.º 2
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone deadZoneMode)
        {
            var          gamePad = GamePads[index];
            GamePadState state   = GamePadState.Default;

            if (gamePad != null && gamePad._isConnected)
            {
                // Check if the device was disconnected
                var dvc = InputDevice.GetDevice(gamePad._deviceId);
                if (dvc == null)
                {
                    Android.Util.Log.Debug("MonoGame", "Detected controller disconnect [" + index + "] ");
                    gamePad._isConnected = false;
                    return(state);
                }

                GamePadThumbSticks thumbSticks = new GamePadThumbSticks(gamePad._leftStick, gamePad._rightStick, deadZoneMode);

                state = new GamePadState(
                    thumbSticks,
                    new GamePadTriggers(gamePad._leftTrigger, gamePad._rightTrigger),
                    new GamePadButtons(gamePad._buttons),
                    new GamePadDPad(gamePad._buttons));
            }
            // we need to add the default "no gamepad connected but the user hit back"
            // behaviour here
            else
            {
                if (index == 0 && Back)
                {
                    // Consume state
                    Back  = false;
                    state = new GamePadState(new GamePadThumbSticks(), new GamePadTriggers(), new GamePadButtons(Buttons.Back), new GamePadDPad());
                }
                else
                {
                    state = new GamePadState();
                }
            }

            return(state);
        }
        /*
         * Gamepad input
         */

        public int EnumerateGamepads()
        {
            int[] deviceIds = _inputManager.GetInputDeviceIds();
            foreach (int deviceId in deviceIds)
            {
                InputDevice dev = InputDevice.GetDevice(deviceId);
                if (IsGamepad(dev))
                {
                    if (!_connected_devices.Contains(deviceId))
                    {
                        _connected_devices.Add(deviceId);
                        if (_current_device_id == INVALID_GAMEPAD_INDEX)
                        {
                            _current_device_id = deviceId;
                        }
                    }
                }
            }
            return(_connected_devices.Count);
        }
Ejemplo n.º 4
0
        //Check for any connected game controllers
        private void CheckGameControllers()
        {
            int[] deviceIds = input_manager.GetInputDeviceIds();
            foreach (int deviceId in deviceIds)
            {
                Android.Views.InputDevice dev = InputDevice.GetDevice(deviceId);
                int sources = (int)dev.Sources;

                if (((sources & (int)InputSourceType.Gamepad) == (int)InputSourceType.Gamepad) ||
                    ((sources & (int)InputSourceType.Joystick) == (int)InputSourceType.Joystick))
                {
                    if (!connected_devices.Contains(deviceId))
                    {
                        connected_devices.Add(deviceId);
                        if (current_device_id == -1)
                        {
                            current_device_id = deviceId;
                        }
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public static GamePadState GetState(PlayerIndex playerIndex, GamePadDeadZone deadZone)
        {
            var          gamePad = GamePads[(int)playerIndex];
            GamePadState state   = GamePadState.InitializedState;

            if (gamePad != null && gamePad._isConnected)
            {
                // Check if the device was disconnected
                var dvc = InputDevice.GetDevice(gamePad._deviceId);
                if (dvc == null)
                {
                    Debug.WriteLine("Detected controller disconnect [" + (int)playerIndex + "] ");
                    gamePad._isConnected = false;
                    return(state);
                }

                GamePadThumbSticks thumbSticks = new GamePadThumbSticks(gamePad._leftStick, gamePad._rightStick);
                thumbSticks.ApplyDeadZone(deadZone, 0.3f);

                if (gamePad._startButtonPressed)
                {
                    gamePad._buttons           |= Buttons.Start;
                    gamePad._startButtonPressed = false;
                }
                else
                {
                    gamePad._buttons &= ~Buttons.Start;
                }

                state = new GamePadState(
                    thumbSticks,
                    new GamePadTriggers(gamePad._leftTrigger, gamePad._rightTrigger),
                    new GamePadButtons(gamePad._buttons),
                    new GamePadDPad(gamePad._buttons));
            }

            return(state);
        }
Ejemplo n.º 6
0
        private static GamePadState PlatformGetState(int index, GamePadDeadZone deadZoneMode)
        {
            var          gamePad = GamePads[index];
            GamePadState state   = GamePadState.Default;

            if (gamePad != null && gamePad._isConnected)
            {
                // Check if the device was disconnected
                var dvc = InputDevice.GetDevice(gamePad._deviceId);
                if (dvc == null)
                {
                    Debug.WriteLine("Detected controller disconnect [" + index + "] ");
                    gamePad._isConnected = false;
                    return(state);
                }

                GamePadThumbSticks thumbSticks = new GamePadThumbSticks(gamePad._leftStick, gamePad._rightStick, deadZoneMode);

                if (gamePad._startButtonPressed)
                {
                    gamePad._buttons           |= Buttons.Start;
                    gamePad._startButtonPressed = false;
                }
                else
                {
                    gamePad._buttons &= ~Buttons.Start;
                }

                state = new GamePadState(
                    thumbSticks,
                    new GamePadTriggers(gamePad._leftTrigger, gamePad._rightTrigger),
                    new GamePadButtons(gamePad._buttons),
                    new GamePadDPad(gamePad._buttons));
            }

            return(state);
        }