Exemple #1
0
        /** <summary> Called every step to update the mouse button states. </summary> */
        public static void Update(GameTime gameTime, Vector2F mouseOffset)
        {
            // Update each of the buttons
            UpdateButton(1, MouseButtons.None, ButtonState.Released);
            UpdateButton(1, MouseButtons.Left, XnaMouse.GetState().LeftButton);
            UpdateButton(1, MouseButtons.Middle, XnaMouse.GetState().MiddleButton);
            UpdateButton(1, MouseButtons.Right, XnaMouse.GetState().RightButton);
            UpdateButton(1, MouseButtons.XButton1, XnaMouse.GetState().XButton1);
            UpdateButton(1, MouseButtons.XButton2, XnaMouse.GetState().XButton2);

            for (int i = 0; i < NumButtons; i++)
            {
                rawButtonDoubleClick[i] = false;
                rawButtonClick[i]       = false;
            }

            int rawWheelDeltaLast = rawWheelDelta;

            rawWheelDelta = XnaMouse.GetState().ScrollWheelValue;
            if (!disabled)
            {
                // Update the mouse wheel
                wheelDelta = rawWheelDeltaLast - rawWheelDelta;

                // Update the mouse position
                mousePosLast = mousePos;
                mousePos     = (new Vector2F(XnaMouse.GetState().X, XnaMouse.GetState().Y) - mouseOffset) / (float)gameScale;
            }
        }
Exemple #2
0
        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            var mState = XnaMouse.GetState();

            // Save the mouse position...
            this.Position = mState.Position.ToVector2();

            // Update the mouse button states...
            this[MouseButton.Left].TrySetState(mState.LeftButton);
            this[MouseButton.Middle].TrySetState(mState.MiddleButton);
            this[MouseButton.Right].TrySetState(mState.RightButton);

            if (this.ScrollWheelValue != mState.ScrollWheelValue)
            { // If the scroll value has been updated...
                _oldScrollWheelValue  = this.ScrollWheelValue;
                this.ScrollWheelValue = mState.ScrollWheelValue;

                this.OnScrollWheelValueChanged?.Invoke(
                    sender: this,
                    args: new ScrollWheelArgs(
                        value: this.ScrollWheelValue,
                        delta: this.ScrollWheelValue - _oldScrollWheelValue));
            }
        }
Exemple #3
0
        public override void Update(IEnumerable <Entity> entities)
        {
            MouseState newState = NativeMouse.GetState();

            UpdateValuesFromState(ref newState);
            base.Update(entities);
        }
Exemple #4
0
 private void RefreshInputState()
 {
     _keyboard = _keyboard.Next(KB.GetState());
     _mouse    = _mouse.Next(MS.GetState());
     UpdateGamePadState(PlayerIndex.One);
     UpdateGamePadState(PlayerIndex.Two);
     UpdateGamePadState(PlayerIndex.Three);
     UpdateGamePadState(PlayerIndex.Four);
 }
    public void Update(GameTime gameTime)
    {
        previousMouseState    = currentMouseState;
        previousKeyboardState = currentKeyboardState;
        previousGamePadState  = (GamePadState[])currentGamePadState.Clone();
        //previousJoyState = currentJoyState;

        currentMouseState    = Mouse.GetState();
        currentKeyboardState = Keyboard.GetState();

        foreach (PlayerIndex index in Enum.GetValues(typeof(PlayerIndex)))
        {
            currentGamePadState[(int)index] = GamePad.GetState(index);
        }

        if (RumbleDuration > 0)
        {
            GamePadVibration(PlayerIndex.One, leftMotor, rightMotor);
            rumbleDuration -= (float)gameTime.ElapsedGameTime.TotalSeconds;
        }

        if (!currentGamePadState[0].IsConnected && enableControllers && joystick == null)
        {
            JoystickPing -= (float)gameTime.ElapsedGameTime.TotalSeconds;
            if (JoystickPing < 0)
            {
                JoystickPing = JoystickPingDuration;
                var th = new Thread(GenericControllerConnection);
                th.Start();
#if DEBUG
                Console.WriteLine("A new thread has been created!");
#endif
            }
        }
        else if (joystick != null && enableControllers)
        {
            joystick.Poll();
#if DEBUG
            Console.WriteLine("Polling Joystick...");
#endif
            try
            {
                JoystickState state = joystick.GetCurrentState();
                currentJoyState = joystick.GetCurrentState();
                bool[] button = state.Buttons;
                int[]  hats   = state.PointOfViewControllers;
                Console.WriteLine("[{0}]", string.Join(", ", hats));
            }
            catch (Exception)
            {
#if DEBUG
                Console.WriteLine("Oops, the controller disconnected!");
#endif
                joystick = null;
            }
        }
    }
Exemple #6
0
 public override void Update(GameTime gameTime)
 {
     CenterScreen = Game.GraphicsDevice.Viewport.Bounds.Center.ToVector2();
     Keyboard     = Keyboard.Next(KB.GetState());
     Mouse        = Mouse.Next(MS.GetState());
     UpdateGamePadState(PlayerIndex.One);
     UpdateGamePadState(PlayerIndex.Two);
     UpdateGamePadState(PlayerIndex.Three);
     UpdateGamePadState(PlayerIndex.Four);
 }
Exemple #7
0
        public override void Update(GameTime gameTime)
        {
            bool checkForKeyPress;

#if NETCOREAPP
            MouseState mouseState = XnaMouse.GetState();

            checkForKeyPress = prevMouseState.LeftButton == XnaButtonState.Pressed &&
                               mouseState.LeftButton == XnaButtonState.Released;
#endif

#if ANDROID
            TouchCollection touchCollection = XnaTouchPanel.GetState();
            checkForKeyPress = touchCollection.Count > 0 && touchCollection[0].State == TouchLocationState.Released;
            // TODO multi-touch support?
            Vector2 touchPos = touchCollection.Count > 0 ? touchCollection[0].Position : Vector2.Zero;
#endif

            foreach (VirtualKey key in keys)
            {
                if (checkForKeyPress)
                {
#if WINDOWS
                    if (mouseState.Y > Y + key.Y && mouseState.Y < Y + key.Y + key.Height &&
                        mouseState.X > X + key.X && mouseState.X < X + key.X + key.Width)
                    {
                        HandleKeyPress(key);
                        checkForKeyPress = false;
                    }
#endif

#if ANDROID
                    if (touchPos.Y > Y + key.Y && touchPos.Y < Y + key.Y + key.Height &&
                        touchPos.X > X + key.X && touchPos.X < X + key.X + key.Width)
                    {
                        HandleKeyPress(key);
                        checkForKeyPress = false;
                    }
#endif
                }

                key.Update(gameTime);
            }

#if WINDOWS
            prevMouseState = mouseState;
#endif

            base.Update(gameTime);
        }
Exemple #8
0
        public override void Update(GameTime gameTime)
        {
            _lastState    = _currentState;
            _currentState = XnaMouse.GetState();

            CheckButtonUpdate(MouseButtons.Left);
            CheckButtonUpdate(MouseButtons.Right);
            CheckButtonUpdate(MouseButtons.Middle);

            if (Speed != Vector2.Zero)
            {
                Move?.Invoke(new MouseEventArgs(this, Position, MouseButtons.None));
            }
        }
        public void Update(Time time)
        {
#if XNA
            var state = XnaMouse.GetState();

            _currentPayload = new MousePayload
            {
                Position           = new Vector2(state.X, state.Y),
                LeftButtonPressed  = state.LeftButton == ButtonState.Pressed,
                RightButtonPressed = state.RightButton == ButtonState.Pressed,
                ScrollValue        = state.ScrollWheelValue
            };
#else
            throw new System.NotImplementedException("No implementation for this platform!");
#endif
        }
Exemple #10
0
        public static void Update(GameTime gameTime)
        {
            if (KeyboardEnabled)
            {
                _input.Update(gameTime);
            }

            _previousMousePosition = new Vector2(Mouse.X, Mouse.Y);
            MousePrevious          = Mouse;
            KeyboardPrevious       = Keyboard;

            Mouse    = XMouse.GetState();
            Keyboard = XKeyboard.GetState();

            _handledKeys.Clear();
            _handledMouseButtons.Clear();
        }
Exemple #11
0
        public void Update(GameTime gameTime)
        {
            _previousKeyboard = _currentKeyboard;
            _currentKeyboard  = Keyboard.GetState();

            _previousMouse = _currentMouse;
            _currentMouse  = Mouse.GetState();

            if (_previousKeyboard.IsKeyDown(ToggleDebugHotKey) && _currentKeyboard.IsKeyUp(ToggleDebugHotKey))
            {
                Enabled = !Enabled;
            }

            if (!Enabled)
            {
                return;
            }
            if (!BoundingBoxesEnabled)
            {
                return;
            }

            if ((_previousMouse.LeftButton == ButtonState.Pressed && _currentMouse.LeftButton != ButtonState.Pressed) ||
                (_previousMouse.RightButton == ButtonState.Pressed && _currentMouse.RightButton != ButtonState.Pressed))
            {
                TopMostFocused = TopMostFocused == null ? _topMostHighlighted : null;
            }

            if (_previousKeyboard.IsKeyDown(Keys.Escape) && _currentKeyboard.IsKeyUp(Keys.Escape))
            {
                TopMostFocused = null;
            }

            // add extra updates below here
            if (TopMostFocused == null)
            {
                CursorPosition = Renderer.Unproject(_currentMouse.Position.ToVector2());
            }

            if (GuiManager.FocusManager.TryGetElementAt(CursorPosition, e => e is GuiElement c,
                                                        out var controlMatchingPosition))
            {
                _topMostHighlighted = controlMatchingPosition as GuiElement;
            }
        public override void Update(GameTime gameTime)
        {
            if (!Visible || !EOGame.Instance.IsActive)
            {
                return;
            }

            MouseState mouseState = Mouse.GetState();

            //this is our own button press handler
            if (MouseOver && mouseState.LeftButton == ButtonState.Released && PreviousMouseState.LeftButton == ButtonState.Pressed)
            {
                if (!Selected)
                {
                    ((EOChatRenderer)parent).SetSelectedTab(WhichTab);
                }

                //logic for handling the close button (not actually a button, was I high when I made this...?)
                if ((WhichTab == ChatTabs.Private1 || WhichTab == ChatTabs.Private2) && closeRect != null)
                {
                    Rectangle withOffset = new Rectangle(DrawAreaWithOffset.X + closeRect.Value.X, DrawAreaWithOffset.Y + closeRect.Value.Y, closeRect.Value.Width, closeRect.Value.Height);
                    if (withOffset.ContainsPoint(Mouse.GetState().X, Mouse.GetState().Y))
                    {
                        ClosePrivateChat();
                    }
                }
            }
            else if (Selected && mouseState.RightButton == ButtonState.Released && PreviousMouseState.RightButton == ButtonState.Pressed && WhichTab != ChatTabs.None)
            {
                XNAControl tmpParent = parent.GetParent();                 //get the panel containing this tab, the parent is the chatRenderer
                if (tmpParent.DrawAreaWithOffset.Contains(mouseState.X, mouseState.Y))
                {
                    int adjustedY = mouseState.Y - tmpParent.DrawAreaWithOffset.Y;
                    int level     = (int)Math.Round(adjustedY / 13.0) - 1;
                    if (level >= 0 && scrollBar.ScrollOffset + level < chatStrings.Count)
                    {
                        EOGame.Instance.Hud.SetChatText("!" + chatStrings.Keys[scrollBar.ScrollOffset + level].Who + " ");
                    }
                }
            }

            base.Update(gameTime);
        }
Exemple #13
0
 public void Update()
 {
     if (Mouse.GetState().RightButton == ButtonState.Pressed)
     {
         myGame.Exit();
     }
     if (Mouse.GetState().LeftButton == ButtonState.Pressed && Mouse.GetState().X <= 400 && Mouse.GetState().Y <= 240)
     {
         myGame.sprite = new fixedStaticSprite(myGame.luigi, 6, 14);
     }
     if (Mouse.GetState().LeftButton == ButtonState.Pressed && Mouse.GetState().X > 400 && Mouse.GetState().Y <= 240)
     {
         myGame.sprite = new fixedAnimatedSprite(myGame.luigi, 6, 14);
     }
     if (Mouse.GetState().LeftButton == ButtonState.Pressed && Mouse.GetState().X <= 400 && Mouse.GetState().Y > 240)
     {
         myGame.sprite = new movingStaticSprite(myGame.luigi, 6, 14);
     }
     if (Mouse.GetState().LeftButton == ButtonState.Pressed && Mouse.GetState().X > 400 && Mouse.GetState().Y > 240)
     {
         myGame.sprite = new movingAnimatedSprite(myGame.luigi, 6, 14);
     }
 }
        // made public for unit tests
        public static void Initialize(IntPtr windowHandle)
        {
            mKeyboard = new Keyboard();
#if !XBOX360
            mMouse = new Mouse(windowHandle);
#endif

#if SUPPORTS_TOUCH_SCREEN
            InitializeTouchScreen();
#endif

#if SUPPORTS_XBOX_GAMEPADS
            InitializeXbox360GamePads();
#endif


        }
Exemple #15
0
 /** <summary> Sets the mouse position. </summary> */
 public static void SetPosition(Vector2F position)
 {
     XnaMouse.SetPosition((int)(position.X * gameScale), (int)(position.Y * (float)gameScale));
     mousePosLast = (position - (mousePos - mousePosLast)) * (float)gameScale;
     mousePos     = position * (float)gameScale;
 }
        /// <summary>
        ///
        /// </summary>
        protected virtual void HandleInput(GameTime gameTime)
        {
            Ms       = Mouse.GetState();
            MsRect.X = Ms.X;
            MsRect.Y = Ms.Y;

            // if deselected after the control had focus, remove the focus
            if (IsFocused && Ms.LeftButton == ButtonState.Pressed && !Panel.Contains(MsRect))
            {
                // focus removed.
                IsFocused = false;
                LostFocus(this, EventArgs.Empty);
            }

            if (Visibility == Visibility.Visible)
            {
                if (Panel.Contains(MsRect))
                {
                    if (!MouseEntered)
                    {
                        MouseEntered = true;
                        OnMouseEnter();
                    }
                }
                else
                {
                    if (MouseEntered)
                    {
                        MouseEntered = false;
                        OnMouseLeave();
                    }
                }

                if (IsTabStop && Keyboard.GetState().IsKeyDown(Keys.Tab) && !_tabRecorded)
                {
                    _tabRecorded = true;
                    //CurrentTabIndex++;
                }

                if (!IsEnabled)
                {
                    return;
                }

                if (!MousePressed && Ms.LeftButton == ButtonState.Pressed && MouseEntered)
                {
                    if (!MousePressPositionRecorded)
                    {
                        MousePressPositionRecorded = true;
                        MousePressPosition.X       = MsRect.X;
                        MousePressPosition.Y       = MsRect.Y;
                    }

                    MousePressed = true;
                    OnMouseDown();
                }

                if (Ms.LeftButton == ButtonState.Released)
                {
                    if (MousePressed)
                    {
                        MousePressed = false;
                        //_tabRecorded = false;

                        if (MouseEntered)
                        {
                            OnMouseUp();
                        }
                    }

                    if (MousePressPositionRecorded)
                    {
                        MousePressPositionRecorded = false;
                    }
                }
            }
        }
Exemple #17
0
        protected override void Update(GameTime gameTime)
        {
            _keyboardState = Keyboard.GetState();
            MouseState     = Mouse.GetState();
            Entity mainEntity = _manager.MainPlayer.Ball.Form;

            //Managing the different interactions following the current state of the game
            if (_launched)
            {
                //Updating the camera
                Camera.Update((float)gameTime.ElapsedGameTime.TotalSeconds);

                if (_keyboardState.IsKeyDown(Keys.Escape))
                {
                    //Quit using Escape
                    Exit();
                    return;
                }

                //Managing the loading of the shot
                if (!_manager.MainPlayer.Ball.IsMoving())
                {
                    if (MouseState.LeftButton == ButtonState.Pressed)
                    {
                        if (_chargeBar.Charge <= _chargeBar.ChargeMax)
                        {
                            _chargeBar.Charge += 0.1f * (float)gameTime.ElapsedGameTime.TotalMilliseconds;
                        }
                        if (_chargeBar.Charge >= _chargeBar.ChargeMax)
                        {
                            _chargeBar.Charge = _chargeBar.ChargeMax;
                        }
                    }
                    if (_lastMouseState.LeftButton == ButtonState.Pressed)
                    {
                        //Hitting the ball
                        if (MouseState.LeftButton == ButtonState.Released)
                        {
                            mainEntity.LinearVelocity += Camera.Camera.ViewDirection * _chargeBar.Charge;
                            _sound.Hit(_chargeBar);
                            _chargeBar.Charge = 0;
                            _manager.NbHits++;
                        }
                    }
                }
                else
                {
                    _chargeBar.Charge = 0;
                }
                _lastMouseState = MouseState;

                //Managing the hole and the finish of the course
                if (mainEntity.CollisionInformation.BoundingBox.Intersects(_manager.MainLevel.BoundingArrive) && !_manager.Loading)
                {
                    _sound.Success();
                    BoundingBox box = new BoundingBox(new Vector3(-1, -21, -1), new Vector3(1, -19, 1));
                    mainEntity.CollisionInformation.BoundingBox = box;
                    mainEntity.Position       = Vector3.Zero;
                    mainEntity.LinearVelocity = Vector3.Zero;
                    _manager.LoadNextLevel();
                }

                //Managing a fall and the reset of position in case of bug
                if (mainEntity.Position.Y < -50f || _keyboardState.IsKeyDown(Keys.R))
                {
                    _sound.Out();
                    mainEntity.LinearVelocity = Vector3.Zero;
                    mainEntity.Position       = Vector3.Zero;
                }

                _chargeBar.Update(gameTime);
                _manager.Space.Update();
                base.Update(gameTime);
            }
            //If the game is not launched or ended the start HUD is showed
            else if (!_launched && !_manager.Ended)
            {
                //Using Apos.GUI to show the HUD
                GuiHelper.UpdateSetup();
                _ui.UpdateAll(gameTime);

                // Creating the HUD
                Panel.Push().XY = new Vector2(Graphics.PreferredBackBufferWidth / 2, Graphics.PreferredBackBufferHeight / 2);
                Label.Put("MiniGolf");
                if (Button.Put("Launch Game").Clicked)
                {
                    IsMouseVisible = false;
                    _launched      = true;
                    _sound.PlayAmbiant();
                }
                if (Button.Put("Quit").Clicked)
                {
                    Exit();
                }

                Panel.Pop();


                GuiHelper.UpdateCleanup();
            }

            //Showing the score board at the end using Apos.GUI
            if (_manager.Ended)
            {
                int i = 1;
                GuiHelper.UpdateSetup();
                _ui.UpdateAll(gameTime);

                // Create your UI.
                Panel.Push().XY = new Vector2(Graphics.PreferredBackBufferWidth / 2, Graphics.PreferredBackBufferHeight / 2);
                Label.Put("Course finished");
                Label.Put("Player : " + _manager.MainPlayer.Name);
                foreach (var score in _manager.MainPlayer.Score)
                {
                    Label.Put($"Level {i} : " + score.ToString());
                    i++;
                }
                Label.Put("Press Echap to quit");
                if (Button.Put("Quit").Clicked)
                {
                    Exit();
                    return;
                }

                Panel.Pop();

                // Call UpdateCleanup at the end.
                GuiHelper.UpdateCleanup();

                if (_keyboardState.IsKeyDown(Keys.Escape))
                {
                    Exit();
                    return;
                }
            }
            base.Update(gameTime);
        }
Exemple #18
0
 public override void SetNativePosition(Vector2D position)
 {
     position = ScreenSpace.Current.ToPixelSpace(position);
     NativeMouse.SetPosition((int)position.X, (int)position.Y);
 }