Beispiel #1
0
        public void Move_FromPointToPointFor3Seconds_MovesTheMouseAccordingly()
        {
            var source      = Position.Point(new Point(100, 100));
            var destination = Position.Point(new Point(300, 400));

            MouseEx.Move(source, destination, 3000);
        }
Beispiel #2
0
 public void Execute(object parameter)
 {
     if (_showWaitCursor)
     {
         MouseEx.SetCursor(Cursors.Wait, () =>
         {
             Catch.ShowMessageBox(() =>
             {
                 if (parameter is T variable)
                 {
                     _method.Invoke(variable);
                 }
                 else
                 {
                     _method.Invoke(default(T));
                 }
             });
         });
     }
     else
     {
         Catch.ShowMessageBox(() =>
         {
             if (parameter is T variable)
             {
                 _method.Invoke(variable);
             }
             else
             {
                 _method.Invoke(default(T));
             }
         });
     }
 }
Beispiel #3
0
        protected Game2D(int screenWidth, int screenHeight, bool fullscreen, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None)
        {
            GraphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth    = screenWidth,
                PreferredBackBufferHeight   = screenHeight,
                PreferredDepthStencilFormat = depthFormat,
                IsFullScreen = fullscreen
            };
            Content.RootDirectory = "Content";

            Keyboard      = new KeyboardEx();
            Mouse         = new MouseEx();
            DepthRenderer = new DepthRenderer();
            ScriptRunner  = new ScriptRunner(this);
            if (useGamePad)
            {
                GamePad = new GamePadEx();
            }

            _clearOptions = ClearOptions.Target;
            if (depthFormat != DepthFormat.None)
            {
                _clearOptions |= ClearOptions.DepthBuffer;
            }

            _registeredGlobals = new Dictionary <string, GameObject>();
        }
Beispiel #4
0
        protected Game2D(int defaultScreenWidth = 800, int defaultScreenHeight = 600, bool fullscreen = false, bool useGamePad = false, DepthFormat depthFormat = DepthFormat.None, string configFileName = null)
        {
            _configFileName = string.IsNullOrEmpty(configFileName) ? DefaultConfigFileName : configFileName;
            LoadGameProperties();

            var width  = GetScreenSizeComponent(defaultScreenWidth, GameProperty.GameResolutionXProperty, 800);
            var height = GetScreenSizeComponent(defaultScreenHeight, GameProperty.GameResolutionYProperty, 600);

            GraphicsDeviceManager = new GraphicsDeviceManager(this)
            {
                PreferredBackBufferWidth    = width,
                PreferredBackBufferHeight   = height,
                PreferredDepthStencilFormat = depthFormat,
                IsFullScreen = fullscreen
            };
            Content.RootDirectory = "Content";

            Keyboard      = new KeyboardEx();
            Mouse         = new MouseEx();
            GuiSystem     = new GuiSystem(this);
            DepthRenderer = new DepthRenderer();
            Cursor        = new Cursor(this);
            if (useGamePad)
            {
                GamePad = new GamePadEx();
            }

            _clearOptions = ClearOptions.Target;
            if (depthFormat != DepthFormat.None)
            {
                _clearOptions |= ClearOptions.DepthBuffer;
            }

            _registeredGlobals = new Dictionary <string, GameObject>();
        }
Beispiel #5
0
 public void Click_WithShiftPressedInList_SelectsItems()
 {
     // Explorer open full screen on the left monitor
     MouseEx.Move(Position.Point(new Point(-1300, 210)));
     MouseEx.Click().And.Wait(500);
     MouseEx.Move(Position.Point(new Point(-1300, 310)));
     MouseEx.Click(ModifierKeys.Shift).And.Wait(500);
 }
Beispiel #6
0
        public void DoubleClick_InsideTheWindow_ExecutesTheDoubleClick()
        {
            var textBox = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(_testWindow));

            MouseEx.DoubleClick(textBox).And.Wait(1000);

            Assert.AreEqual("TextBox got doubleclicked", textBox.Text);
        }
Beispiel #7
0
        public void PressReleaseButtons_WithAnElementOnTheTopRight_DragsTheIconToAnotherPosition()
        {
            // Element on the right monitor on the very top right
            MouseEx.Move(Position.Point(new Point(3770, 45)));
            MouseEx.PressButtons(MouseButtons.Left);
            MouseEx.Move(Position.Point(new Point(3770, 45)), Position.Point(new Point(3770, 200)), 1000);
            MouseEx.ReleaseButtons(MouseButtons.Left);

            // Drag and drop working cannot be asserted, just place an element on the second monitor upper right and watch it
        }
Beispiel #8
0
 public void Click_WithControlPressedInListButThenAnymore_SelectsItems()
 {
     // Explorer open full screen on the left monitor
     MouseEx.Move(Position.Point(new Point(-1300, 210)));
     MouseEx.Click().And.Wait(500);
     MouseEx.Move(Position.Point(new Point(-1300, 250)));
     MouseEx.Click(ModifierKeys.Control).And.Wait(500);
     MouseEx.Move(Position.Point(new Point(-1300, 290)));
     MouseEx.Click(ModifierKeys.Control).And.Wait(500);
     MouseEx.Move(Position.Point(new Point(-1300, 310)));
     MouseEx.Click().And.Wait(500);
 }
Beispiel #9
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            MouseEx.Update();
            KeyboardEx.Update();

            // TODO: Add your update logic here
            _gameStateManager.Update(gameTime);

            base.Update(gameTime);
        }
Beispiel #10
0
        public void BringOnTop_TypesTextToDifferentWindows_TheWindowsGetsTheTextAccordingly()
        {
            var window1  = WindowFinder.Search(Use.AutomationId("CUI_WindowFocusTestsWindow_1"));
            var window2  = WindowFinder.Search(Use.AutomationId("CUI_WindowFocusTestsWindow_2"));
            var textBox1 = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(window1));
            var textBox2 = UI.GetChild <BasicEdit>(By.AutomationId("CUI_InputTextBox"), From.Element(window2));

            WindowFocus.BringOnTop(window1);
            MouseEx.Click(window1);
            KeyboardEx.TypeText("First Window Text").And.Wait(1000);

            WindowFocus.BringOnTop(window2);
            MouseEx.Click(window2);
            KeyboardEx.TypeText("Second Window Text").And.Wait(1000);

            Assert.AreEqual("First Window Text", textBox1.Text);
            Assert.AreEqual("Second Window Text", textBox2.Text);
        }
Beispiel #11
0
        public void Click_ChangeStatusBarVisibilityTwoTimes_DoesItAccordingly()
        {
            var statusBar = UI.GetChild(By.AutomationId("CUI_StatusBar"), From.Element(_testWindow));

            Assert.IsTrue(statusBar.IsVisible);

            var viewMenuItem = UI.GetChild(By.AutomationId("CUI_ViewMenuItem"), From.Element(_testWindow));

            MouseEx.Click(viewMenuItem).And.Wait(1000);
            var statusleisteMenuItem = UI.GetChild(By.AutomationId("CUI_ToggleStatusbarMenuItem"), From.Element(_testWindow));

            MouseEx.Click(statusleisteMenuItem).And.Wait(1000);
            Assert.IsFalse(statusBar.IsVisible);

            MouseEx.Click(viewMenuItem).And.Wait(1000);
            statusleisteMenuItem = UI.GetChild(By.AutomationId("CUI_ToggleStatusbarMenuItem"), From.Element(_testWindow));
            MouseEx.Click(statusleisteMenuItem).And.Wait(1000);
            Assert.IsTrue(statusBar.IsVisible);
        }
Beispiel #12
0
        public void Update(GameTime gameTime)
        {
            if (Mouse == null || Locked)
            {
                return;
            }

            var mouseState    = Mouse.GetState();
            var keyboardState = Keyboard.GetState();

            if (!GameView.IsActive)
            {
                return;
            }

            if (keyboardState.IsKeyDown(Keys.W))
            {
                Position += Dir * Speed;
            }
            if (keyboardState.IsKeyDown(Keys.S))
            {
                Position -= Dir * Speed;
            }
            if (keyboardState.IsKeyDown(Keys.A))
            {
                Position += Vector3.Cross(Up, Dir) * Speed;
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                Position -= Vector3.Cross(Up, Dir) * Speed;
            }
            if (keyboardState.IsKeyDown(Keys.Space))
            {
                Position += Up * Speed;
            }

            // camera speed control
            if (mouseState.ScrollWheelValue != PrevMouseState.ScrollWheelValue)
            {
                var diff = mouseState.ScrollWheelValue - PrevMouseState.ScrollWheelValue;

                if (diff >= 0)
                {
                    Speed *= SpeedMod;
                }
                else
                {
                    Speed /= SpeedMod;
                }
            }

            if (mouseState.LeftButton == ButtonState.Pressed && PrevMouseState.LeftButton != ButtonState.Pressed)
            {
                if (GameView.ViewMode == ViewMode.World)
                {
                    Picker.HandleLeftClick(mouseState.X, mouseState.Y);
                }
            }

            if (mouseState.RightButton == ButtonState.Pressed)
            {
                if (PrevMouseState.RightButton == ButtonState.Pressed)
                {
                    MouseEx.GetCursorPos(out var cursorPos);

                    var xDiff = cursorPos.X - (int)LastSetPoint.X;
                    var yDiff = cursorPos.Y - (int)LastSetPoint.Y;

                    if (ConfigManager.Config.Mouse.AltMethod)
                    {
                        xDiff = mouseState.X - PrevMouseState.X;
                        yDiff = mouseState.Y - PrevMouseState.Y;
                    }

                    // yaw / x-rotation
                    Dir = Vector3.Transform(Dir, Matrix.CreateFromAxisAngle(Up,
                                                                            -SpeedBase * ConfigManager.Config.Mouse.Speed * xDiff));

                    // pitch / y-rotation
                    Dir = Vector3.Transform(Dir, Matrix.CreateFromAxisAngle(Vector3.Cross(Up, Dir),
                                                                            SpeedBase * ConfigManager.Config.Mouse.Speed * yDiff));

                    if (MainWindow.DebugMode && (xDiff != 0 || yDiff != 0))
                    {
                        if (!ConfigManager.Config.Mouse.AltMethod)
                        {
                            Console.WriteLine($"mouseX: {mouseState.X}, mouseY: {mouseState.Y}, centerX: {centerX}, centerY: {centerY}");
                        }
                        else
                        {
                            Console.WriteLine($"xDiff: {xDiff}, yDiff: {yDiff}");
                        }
                    }
                }
                else
                {
                    System.Windows.Input.Mouse.OverrideCursor = Cursors.None;
                }
                // there is a delay here, so Mouse.GetState() won't be immediately affected
                if (!ConfigManager.Config.Mouse.AltMethod)
                {
                    LastSetPoint = MouseEx.SetCursor(GameView.Instance, centerX, centerY);
                }
            }
            else if (PrevMouseState.RightButton == ButtonState.Pressed)
            {
                if (ConfigManager.Config.Mouse.AltMethod)
                {
                    Mouse.SetCursor(centerX, centerY);
                }

                System.Windows.Input.Mouse.OverrideCursor = null;
            }

            Dir.Normalize();

            CreateLookAt();

            //Console.WriteLine("Camera pos: " + GameView.Instance.Render.Camera.Position);
            //Console.WriteLine("Camera dir: " + GameView.Instance.Render.Camera.Dir);
        }
Beispiel #13
0
        public void Move_To_PlacesTheMouse()
        {
            var destination = Position.Point(new Point(200, 300));

            MouseEx.Move(destination);
        }
Beispiel #14
0
        public void Update(GameTime time)
        {
            if (!FullSim)
            {
                UpdatePhysics(time);
                return;
            }

            var keyboardState = Keyboard.GetState();
            var mouseState    = Mouse.GetState();

            var isForward     = GetKeyState(keyboardState, ForwardKeys);
            var isBackward    = GetKeyState(keyboardState, BackwardKeys);
            var isTurnLeft    = GetKeyState(keyboardState, TurnLeftKeys);
            var isTurnRight   = GetKeyState(keyboardState, TurnRightKeys);
            var isStrafeLeft  = GetKeyState(keyboardState, StrafeLeftKeys);
            var isStrafeRight = GetKeyState(keyboardState, StrafeRightKeys);
            var isWalk        = GetKeyState(keyboardState, WalkKeys);
            var isJump        = GetKeyState(keyboardState, JumpKeys);

            var wasForward     = GetKeyState(PrevKeyboardState, ForwardKeys);
            var wasBackward    = GetKeyState(PrevKeyboardState, BackwardKeys);
            var wasTurnLeft    = GetKeyState(PrevKeyboardState, TurnLeftKeys);
            var wasTurnRight   = GetKeyState(PrevKeyboardState, TurnRightKeys);
            var wasStrafeLeft  = GetKeyState(PrevKeyboardState, StrafeLeftKeys);
            var wasStrafeRight = GetKeyState(PrevKeyboardState, StrafeRightKeys);
            var wasWalk        = GetKeyState(PrevKeyboardState, WalkKeys);
            var wasJump        = GetKeyState(PrevKeyboardState, JumpKeys);

            var isLeftClick  = mouseState.LeftButton == ButtonState.Pressed;
            var wasLeftClick = PrevMouseState.LeftButton == ButtonState.Pressed;

            var isRightClick  = mouseState.RightButton == ButtonState.Pressed;
            var wasRightClick = PrevMouseState.RightButton == ButtonState.Pressed;

            if (isForward && !wasForward)
            {
                RunForward(Speed, true);
            }

            if (!isForward && wasForward)
            {
                RunForward(Speed, false);
            }

            if (isBackward && !wasBackward)
            {
                WalkBackward(Speed);
            }

            if (!isBackward && wasBackward)
            {
                WalkBackward(Speed, false);
            }

            if (isTurnLeft && !wasTurnLeft /*|| isMouseLookLeft && !wasMouseLookLeft*/)
            {
                TurnLeft();
            }

            if (!isTurnLeft && wasTurnLeft /*|| !isMouseLookLeft && !isMouseLookRight && wasMouseLookLeft*/)
            {
                TurnLeft(false);
            }

            if (isTurnRight && !wasTurnRight /* || isMouseLookRight && !wasMouseLookRight*/)
            {
                TurnRight();
            }

            if (!isTurnRight && wasTurnRight /* || !isMouseLookRight && !isMouseLookLeft && wasMouseLookRight*/)
            {
                TurnRight(false);
            }

            if (isStrafeLeft && !wasStrafeLeft)
            {
                StrafeLeft();
            }

            if (!isStrafeLeft && wasStrafeLeft)
            {
                StrafeLeft(false);
            }

            if (isStrafeRight && !wasStrafeRight)
            {
                StrafeRight();
            }

            if (!isStrafeRight && wasStrafeRight)
            {
                StrafeRight(false);
            }

            /*if (keyboardState.IsKeyDown(Keys.OemOpenBrackets) && !PrevKeyboardState.IsKeyDown(Keys.OemOpenBrackets))
             * {
             *  CurrentHeightFactor -= 0.025f;
             *
             *  Console.WriteLine($"CurrentHeightFactor: {CurrentHeightFactor}");
             * }
             *
             * if (keyboardState.IsKeyDown(Keys.OemCloseBrackets) && !PrevKeyboardState.IsKeyDown(Keys.OemCloseBrackets))
             * {
             *  CurrentHeightFactor += 0.025f;
             *
             *  Console.WriteLine($"CurrentHeightFactor: {CurrentHeightFactor}");
             * }*/

            if (keyboardState.IsKeyDown(Keys.I) && !PrevKeyboardState.IsKeyDown(Keys.I))
            {
                var ethereal = PhysicsObj.State.HasFlag(PhysicsState.Ethereal);

                ethereal = !ethereal;

                PhysicsObj.set_ethereal(ethereal, true);

                MainWindow.Instance.AddStatusText($"Ethereal: {ethereal}");
            }

            if (isWalk && !wasWalk)
            {
                SetHoldKey(HoldKey.None);
                ApplyRawState();
            }

            if (!isWalk && wasWalk)
            {
                SetHoldKey(HoldKey.Run);
                ApplyRawState();
            }

            if (isRightClick)
            {
                if (wasRightClick)
                {
                    MouseEx.GetCursorPos(out var cursorPos);

                    var diffX = cursorPos.X - (int)LastSetPoint.X;
                    var diffY = cursorPos.Y - (int)LastSetPoint.Y;

                    if (ConfigManager.Config.Mouse.AltMethod)
                    {
                        diffX = mouseState.X - PrevMouseState.X;
                        diffY = mouseState.Y - PrevMouseState.Y;
                    }

                    if (diffX != 0)
                    {
                        var heading = PhysicsObj.get_heading();
                        heading += diffX * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;
                        PhysicsObj.set_heading(heading, false);
                    }

                    if (diffY > 0)
                    {
                        CurrentAngle -= diffY * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;

                        if (CurrentAngle < MaxAngleDown)
                        {
                            CurrentAngle = MaxAngleDown;
                        }

                        //Console.WriteLine($"CurrentAngle: {CurrentAngle}");
                    }
                    else if (diffY < 0)
                    {
                        CurrentAngle -= diffY * MouseSpeedBase * ConfigManager.Config.Mouse.Speed;

                        if (CurrentAngle > MaxAngleUp)
                        {
                            CurrentAngle = MaxAngleUp;
                        }

                        //Console.WriteLine($"CurrentAngle: {CurrentAngle}");
                    }
                }
                else
                {
                    System.Windows.Input.Mouse.OverrideCursor = System.Windows.Input.Cursors.None;
                }

                if (!ConfigManager.Config.Mouse.AltMethod)
                {
                    LastSetPoint = MouseEx.SetCursor(GameView.Instance, Camera.centerX, Camera.centerY);
                }
            }
            else if (wasRightClick)
            {
                if (ConfigManager.Config.Mouse.AltMethod)
                {
                    Mouse.SetCursor(Camera.centerX, Camera.centerY);
                }

                System.Windows.Input.Mouse.OverrideCursor = null;
            }

            if (mouseState.ScrollWheelValue != PrevMouseState.ScrollWheelValue)
            {
                var diff = mouseState.ScrollWheelValue - PrevMouseState.ScrollWheelValue;

                if (diff >= 0)
                {
                    CurrentDist -= 0.5f;
                }
                else
                {
                    CurrentDist += 0.5f;
                }

                //Console.WriteLine($"CurrentDist: {CurrentDist}");
            }

            UpdatePhysics(time);

            if (isLeftClick && !wasLeftClick)
            {
                Picker.HandleLeftClick(mouseState.X, mouseState.Y);
            }

            if (isJump && !wasJump)
            {
                // check if grounded?
                if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.OnWalkable))
                {
                    JumpMeter.Start();

                    var minterp = PhysicsObj.get_minterp();

                    if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.Contact | TransientStateFlags.OnWalkable) && minterp.InterpretedState.ForwardCommand == (uint)MotionCommand.Ready &&
                        minterp.InterpretedState.SideStepCommand == 0 && minterp.InterpretedState.TurnCommand == 0)
                    {
                        minterp.StandingLongJump = true;
                    }
                }
            }

            if (!isJump && wasJump)
            {
                JumpMeter.Stop();

                // check if grounded?
                if (PhysicsObj.TransientState.HasFlag(TransientStateFlags.OnWalkable))
                {
                    // calc velocity
                    PhysicsObj.WeenieObj.InqJumpVelocity(JumpMeter.Percent, out var jumpVelocityZ);

                    var minterp = PhysicsObj.get_minterp();

                    var jumpVelocity = minterp.get_leave_ground_velocity();
                    jumpVelocity.Z = jumpVelocityZ;

                    // perform physics jump
                    PhysicsObj.TransientState &= ~(TransientStateFlags.Contact | TransientStateFlags.WaterContact);
                    PhysicsObj.calc_acceleration();
                    PhysicsObj.set_on_walkable(false);
                    PhysicsObj.set_local_velocity(jumpVelocity, false);
                    minterp.StandingLongJump = false;
                }
            }

            if (JumpMeter.IsCharging)
            {
                JumpMeter.Update();
            }
        }