예제 #1
0
        public void Update(TouchStateBase touchState, MouseStateBase mouseState, IGameTiming gameTime)
        {
            if (this.touchAction != null &&
                touchState.Touches.Any(t => this.Rectangle.Intercept(t.Position)))
            {
                this.touchAction.Invoke(gameTime);
            }

            if (this.hoverAction != null &&
                this.Rectangle.Intercept(mouseState.Position))
            {
                this.hoverAction.Invoke(gameTime);
            }

            if (this.clickAction != null)
            {
                if (this.mappingGestures.Any(g => (g & touchState.CurrentGesture.GestureType) == g)
                    && this.Rectangle.Intercept(touchState.CurrentGesture.Position))
                {
                    this.clickAction.Invoke(gameTime);
                }

                if (this.mappingMouseButtons.Any(mouseState.IsButtonDown)
                    && this.Rectangle.Intercept(mouseState.Position))
                {
                    this.clickAction.Invoke(gameTime);
                }
            }
        }
예제 #2
0
        public void Update(KeyboardStateBase keyboardState, MouseStateBase mouseState, IGameTiming gameTime)
        {
            var previousDown = this.isDown;

            this.isDown = this.mappingKeys.Any(keyboardState.IsKeyDown)
                || this.mappingButtons.Any(mouseState.IsButtonDown);

            if (this.isDown && this.buttonDownAction != null) this.buttonDownAction.Invoke(gameTime);
            if (!this.isDown && this.buttonUpAction != null) this.buttonUpAction.Invoke(gameTime);

            if (this.buttonClickAction != null && previousDown && !this.isDown) this.buttonClickAction.Invoke(gameTime);

            if (this.buttonStateAction != null) this.buttonStateAction.Invoke(this.isDown, gameTime);
        }
예제 #3
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            // Keyboard
            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                //.MapClickTo(gt => this.screenNavigation.Exit());
                .MapClickTo(gt => this.Exit());

            inputConfiguration.AddDigitalButton("GotoSandbox").Assign(KeyboardKeys.D1)
                .MapClickTo(gt => this.LaunchSandboxSample());

            inputConfiguration.AddDigitalButton("GotoShootEmUp").Assign(KeyboardKeys.D2)
                .MapClickTo(gt => this.LaunchShootEmUpSample());

            inputConfiguration.AddDigitalButton("GotoTiled").Assign(KeyboardKeys.D3)
                .MapClickTo(gt => this.LaunchTiledSample());

            inputConfiguration.AddDigitalButton("GotoTouch").Assign(KeyboardKeys.D4)
                .MapClickTo(gt => this.LaunchTouchSample());

            // Mouse
            Func<RectangleHit, Samples> hitToSampleFunc = hit =>
            {
                if (hit != null)
                {
                    if (hit.RectangleElement == this.sandboxRectangle) return Samples.Sandbox;
                    if (hit.RectangleElement == this.shootEmUpRectangle) return Samples.ShootEmUp;
                    if (hit.RectangleElement == this.tiledRectangle) return Samples.Tiled;
                    if (hit.RectangleElement == this.touchRectangle) return Samples.Touch;
                }

                return Samples.None;
            };

            inputConfiguration.CreateMouseTracking(this.Camera).OnUpdate((mt, e) =>
            {
                this.mouseState = mt;

                var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault();
                this.hoveringSample = hitToSampleFunc(hit);
            });

            inputConfiguration.AddDigitalButton("MouseSelection").Assign(MouseButtons.Left).MapClickTo(elapse =>
            {
                var hit = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).OfType<RectangleHit>().FirstOrDefault();
                var hitSample = hitToSampleFunc(hit);

                switch (hitSample)
                {
                    case Samples.Sandbox:
                        this.LaunchSandboxSample();
                        break;
                    case Samples.ShootEmUp:
                        this.LaunchShootEmUpSample();
                        break;
                    case Samples.Tiled:
                        this.LaunchTiledSample();
                        break;
                    case Samples.Touch:
                        this.LaunchTouchSample();
                        break;
                }
            });

            // Touch
            inputConfiguration.CreateTouchTracking(this.Camera).OnUpdate((ts, gt) =>
            {
                this.touchState = ts;

                if (this.touchState.Touches.Any())
                {
                    var hit = this.touchState.Touches
                        .SelectMany(t => this.Scene.GetHits(t.Position, this.Camera))
                        .OfType<RectangleHit>().FirstOrDefault();

                    this.hoveringSample = hitToSampleFunc(hit);
                }
            });

            inputConfiguration.AddEvent("TouchSelection").Assign(TouchGestureType.Tap).MapTo(gt =>
            {
                var hit = this.Scene.GetHits(this.touchState.CurrentGesture.Position, this.Camera)
                    .OfType<RectangleHit>().FirstOrDefault();

                var hitSample = hitToSampleFunc(hit);

                switch (hitSample)
                {
                    case Samples.Sandbox:
                        this.LaunchSandboxSample();
                        break;
                    case Samples.ShootEmUp:
                        this.LaunchShootEmUpSample();
                        break;
                    case Samples.Tiled:
                        this.LaunchTiledSample();
                        break;
                    case Samples.Touch:
                        this.LaunchTouchSample();
                        break;
                }
            });

            return inputConfiguration;
        }
예제 #4
0
 public AdjustedMouseState(MouseStateBase inneMouseState, ICamera camera)
 {
     this.inneMouseState = inneMouseState;
     this.camera = camera;
 }
예제 #5
0
        protected override InputConfiguration CreateInputConfiguration()
        {
            var inputConfiguration = new InputConfiguration();

            inputConfiguration.AddDigitalButton("Back").Assign(KeyboardKeys.Escape)
                .MapClickTo(gt => this.screenNavigation.NavigateBack());

            inputConfiguration.AddDigitalButton("DiagToggle").Assign(KeyboardKeys.F1).MapClickTo(gt => this.diagnosticHud.ViewStateToggle());

            inputConfiguration.AddDigitalButton("Left").Assign(KeyboardKeys.Left).MapTo(gt => this.Camera.Move(-60 * gt.ElapsedSeconds, 0));
            inputConfiguration.AddDigitalButton("Right").Assign(KeyboardKeys.Right).MapTo(gt => this.Camera.Move(60 * gt.ElapsedSeconds, 0));
            inputConfiguration.AddDigitalButton("Up").Assign(KeyboardKeys.Up).MapTo(gt => this.Camera.Move(0, -60 * gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("Down").Assign(KeyboardKeys.Down).MapTo(gt => this.Camera.Move(0, 60 * gt.ElapsedSeconds));

            inputConfiguration.AddDigitalButton("ZoomIn").Assign(KeyboardKeys.A).MapTo(gt => this.Camera.ZoomFactor *= 1.2f * (1 + gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("ZoomOut").Assign(KeyboardKeys.Z).MapTo(gt => this.Camera.ZoomFactor *= 1 / (1.2f * (1 + gt.ElapsedSeconds)));

            inputConfiguration.AddDigitalButton("SwitchSampler").Assign(KeyboardKeys.Tab)
                .MapClickTo(gt => this.Scene.UseLinearSampler = !this.Scene.UseLinearSampler);

            inputConfiguration.AddDigitalButton("RangeUp").Assign(KeyboardKeys.W).MapTo(gt => this.range *= 1.2f * (1 + gt.ElapsedSeconds));
            inputConfiguration.AddDigitalButton("RangeDown").Assign(KeyboardKeys.Q).MapTo(gt => this.range *= 1 / (1.2f * (1 + gt.ElapsedSeconds)));

            inputConfiguration.AddDigitalButton("RotateLeft").Assign(KeyboardKeys.X).MapTo(gt => this.linkMouseFollow.Rotation -= 4 * gt.ElapsedSeconds);
            inputConfiguration.AddDigitalButton("RotateRight").Assign(KeyboardKeys.C).MapTo(gt => this.linkMouseFollow.Rotation += 4 * gt.ElapsedSeconds);

            inputConfiguration.AddDigitalButton("Selection").Assign(MouseButtons.Left).MapTo(elapse =>
            {
                this.hits = this.Scene.GetHits(this.mouseState.AbsolutePosition, this.Camera).ToList();
            });

            inputConfiguration.AddDigitalButton("Play sound").Assign(MouseButtons.Right).MapClickTo(e =>
            {
                this.coinSound.Pan = (this.mouseState.AbsolutePosition.X / this.Camera.SceneViewport.Width) - 0.5f;
                this.coinSound.Play();
            });

            inputConfiguration.AddDigitalButton("PlayPause music").Assign(KeyboardKeys.Space).MapClickTo(e =>
            {
                if (this.music.IsPlaying)
                    this.music.Pause();
                //else if (this.music.IsPaused)
                //    this.music.Resume();
                else if (this.music.IsPaused)
                    this.music.Play();
                else if (this.music.IsStopped)
                    this.music.Play();
            });

            inputConfiguration.CreateMouseTracking(this.Camera).OnUpdate((mt, e) =>
            {
                this.mouseState = mt;

                this.linkMouseFollow.Position = mt.AbsolutePosition;
            });

            return inputConfiguration;
        }
예제 #6
0
        public void Update(MouseStateBase mouseState, IGameTiming gameTime)
        {
            var cameraAdjutedMouseState = mouseState.AdjustToCamera(this.camera);

            this.mouseMoveAction.Invoke(cameraAdjutedMouseState, gameTime);
        }