コード例 #1
0
ファイル: MenuSystem.cs プロジェクト: ARLM-Attic/neat
            public void HandleInput(GameTime gameTime)
            {
                if (game.IsTapped(Keys.Enter) || game.IsTapped(Buttons.A) || game.IsTapped(Buttons.Start))
                {
                    select(SelectedItem);
                }
                if (game.IsTapped(Keys.Down) || game.IsTapped(Buttons.DPadDown) || game.IsTapped(Buttons.LeftThumbstickDown))
                {
                    Bleep(); NextItem();
                }
                else
                if (game.IsTapped(Keys.Up) || game.IsTapped(Buttons.DPadUp) || game.IsTapped(Buttons.LeftThumbstickUp))
                {
                    Bleep(); PrevItem();
                }
#if WINDOWS || WINDOWS_PHONE
                if (EnableShortcuts)
                {
                    HandleShortcuts();
                }
#endif
#if WINDOWS_PHONE
                if (game.IsTouched())
                {
                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].enabled)
                        {
                            bool      isSelected = (selectedItem == i);
                            Rectangle r          = Geometry2D.Vectors2Rectangle(
                                (position - centerOffset) + i * itemsOffset + (isSelected ? selectedItemOffset : Vector2.Zero),
                                font.MeasureString(items[i].caption));
                            if (game.IsTouched(r))
                            {
                                if (!isSelected)
                                {
                                    selectedItem = i;
                                }
                                else
                                {
                                    items[i].Selected();
                                }
                                break;
                            }
                        }
                    }
                }
#endif
#if WINDOWS
                if (game.IsMouseClicked())
                {
                    for (int i = 0; i < Items.Count; i++)
                    {
                        if (!Items[i].Enabled)
                        {
                            continue;
                        }
                        bool isSelected = (SelectedItem == i);
                        var  ipos       = (Position - centerOffset) + i * ItemsOffset + (isSelected ? SelectedItemOffset : Vector2.Zero) - new Vector2(10, 0);
                        var  size       = font.MeasureString(Items[i].Caption) + new Vector2(20, 0);

                        if (GeometryHelper.Vectors2Rectangle(ipos, size).Contains(
                                GeometryHelper.Vector2Point(game.MousePosition)))
                        {
                            select(i);
                            break;
                        }
                    }
                }
#endif

#if KINECT
                if (game.Touch.Enabled)
                {
                    for (int i = 0; i < Items.Count; i++)
                    {
                        bool breakAll = false;
                        if (!Items[i].Enabled)
                        {
                            continue;
                        }
                        bool isSelected = (SelectedItem == i);
                        var  ipos       = (Position - centerOffset) + i * ItemsOffset + (isSelected ? SelectedItemOffset : Vector2.Zero) - new Vector2(10, 0);
                        var  size       = font.MeasureString(Items[i].Caption) + new Vector2(20, 0);

                        foreach (var item in game.Touch.TrackPoints)
                        {
                            if (GeometryHelper.Vectors2Rectangle(ipos, size).Intersects(
                                    new Rectangle((int)(item.Position.X), (int)(item.Position.Y), 32, 32)) &&
                                item.Hold && !item.LastHold)
                            {
                                select(i);
                                game.Touch.Reset(new TimeSpan(0, 0, 0, 1));
                                //item.Hold = item.LastHold;
                                breakAll = true;
                                break;
                            }
                        }

                        if (breakAll)
                        {
                            break;
                        }
                    }
                }
#endif
            }
コード例 #2
0
        public virtual void Update(GameTime gameTime)
        {
            if (MainForm)
            {
                ClickHandled = false;
            }
            var n = controlChain.First;

            while (n != null)
            {
                n.Value.Update(gameTime);
                if (!ClickHandled)
                {
                    if (n.Value.Visible)
                    {
                        n.Value.HandleInput(gameTime);

                        if (GeometryHelper.Vectors2Rectangle(n.Value.Position, n.Value.Size).Intersects(
                                new Rectangle((int)(MousePosition.X), (int)(MousePosition.Y), 1, 1)))
                        {
                            n.Value.IsMouseHovered = true;
                            n.Value.Hovered(MousePosition);

                            if (game.IsPressed(Keys.Space, Buttons.A) || game.IsMousePressed())
                            {
                                n.Value.Held(MousePosition);
                            }
                            else
                            {
                                n.Value.IsMouseHold = false;
                            }

                            if (game.IsReleased(Keys.Space, Buttons.A) || game.IsMouseClicked())
                            {
                                n.Value.Released(MousePosition);
                            }
                            if (game.IsTapped(Keys.Space, Buttons.A) || game.IsMouseClicked(false))
                            {
                                n.Value.Pressed(MousePosition);
                            }
                            ClickHandled = true;
                        }
                        else
                        {
                            n.Value.IsMouseHovered = false;
                        }
#if KINECT
                        if (Touch.Enabled)
                        {
                            foreach (var item in Touch.TrackPoints)
                            {
                                var pos = item.Position + MouseOffset;

                                if (GeometryHelper.Vectors2Rectangle(n.Value.Position, n.Value.Size).Intersects(
                                        new Rectangle((int)(pos.X), (int)(pos.Y), 32, 32)))
                                {
                                    n.Value.IsMouseHovered = true;
                                    n.Value.Hovered(pos);

                                    if (item.Pushed)
                                    {
                                        n.Value.IsMouseHold = true;
                                        n.Value.Held(pos);
                                    }

                                    if (item.LastHold && !item.Hold)
                                    {
                                        n.Value.Released(pos);
                                        //Touch.Reset();
                                    }
                                    else if (!item.LastHold && item.Hold)
                                    {
                                        n.Value.Pressed(pos);
                                        //Touch.Reset();
                                    }
                                    ClickHandled = true;
                                }
                            }
                        }
#endif
                    }
                }
                n = n.Next;
            }

#if WINDOWS
            if (HasMouse)
            {
                if (game.IsPressed(Keys.Right) || game.IsPressed(Buttons.LeftThumbstickRight))
                {
                    Mouse.SetPosition(Mouse.GetState().X + MouseSpeed, Mouse.GetState().Y);
                }

                else if (game.IsPressed(Keys.Left) || game.IsPressed(Buttons.LeftThumbstickLeft))
                {
                    Mouse.SetPosition(Mouse.GetState().X - MouseSpeed, Mouse.GetState().Y);
                }

                if (game.IsPressed(Keys.Up) || game.IsPressed(Buttons.LeftThumbstickUp))
                {
                    Mouse.SetPosition(Mouse.GetState().X, Mouse.GetState().Y - MouseSpeed);
                }

                else if (game.IsPressed(Keys.Down) || game.IsPressed(Buttons.LeftThumbstickDown))
                {
                    Mouse.SetPosition(Mouse.GetState().X, Mouse.GetState().Y + MouseSpeed);
                }
            }
#elif WINDOWS_PHONE
            if (game.IsTouched())
            {
                Vector2 p = game.GetHardestTouchPosition();
                foreach (var item in objects)
                {
                    if (game.IsTouched(
                            Geometry2D.Vectors2Rectangle(item.Value.position, item.Value.size)))
                    {
                        item.Value.Pressed();
                    }
                }
            }
#endif
        }