Beispiel #1
0
 public bool TryNavigate(NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping)
 {
     if (IsGamepadFocused && HoveredButton == null)
     {
         if (IsLeftSidebarVisible)
         {
             HoveredButtonBounds = LeftSidebarButtonBounds.First();
         }
         else if (IsRightSidebarVisible)
         {
             HoveredButtonBounds = RightSidebarButtonBounds.First();
         }
         else
         {
             HoveredButtonBounds = null;
         }
         IsNavigatingWithGamepad = HoveredButton != null;
         return(HoveredButton != null);
     }
     else if (TryGetSlotNeighbor(HoveredButtonBounds, Direction, HorizontalWrapping, VerticalWrapping, out Rectangle? Neighbor))
     {
         HoveredButtonBounds     = Neighbor.Value;
         IsNavigatingWithGamepad = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #2
0
        public bool TryGetMenuNeighbor(NavigationDirection Direction, out IGamepadControllable Neighbor)
        {
            if (HoveredButton.HasValue)
            {
                if (IsLeftSidebarVisible && LeftSidebarButtonBounds.Contains(HoveredButtonBounds.Value) && Direction == NavigationDirection.Right)
                {
                    Neighbor = InventoryMenu;
                    return(true);
                }
                else if (IsRightSidebarVisible && RightSidebarButtonBounds.Contains(HoveredButtonBounds.Value) && Direction == NavigationDirection.Left)
                {
                    Neighbor = InventoryMenu;
                    return(true);
                }
            }

            if (Direction == NavigationDirection.Up)
            {
                Neighbor = Content;
                return(true);
            }

            Neighbor = null;
            return(false);
        }
Beispiel #3
0
 public bool TryNavigateEnter(NavigationDirection StartingSide, Rectangle?ClosestTo)
 {
     if (IsLeftSidebarVisible && StartingSide != NavigationDirection.Left)
     {
         IsGamepadFocused        = true;
         IsNavigatingWithGamepad = true;
         if (ClosestTo.HasValue)
         {
             HoveredButtonBounds = LeftSidebarButtonBounds.OrderBy(x => x.SquaredDistanceBetweenCenters(ClosestTo.Value)).First();
         }
         else
         {
             HoveredButtonBounds = LeftSidebarButtonBounds.First();
         }
         return(true);
     }
     else if (IsRightSidebarVisible)
     {
         IsGamepadFocused        = true;
         IsNavigatingWithGamepad = true;
         if (ClosestTo.HasValue)
         {
             HoveredButtonBounds = RightSidebarButtonBounds.OrderBy(x => x.SquaredDistanceBetweenCenters(ClosestTo.Value)).First();
         }
         else
         {
             HoveredButtonBounds = RightSidebarButtonBounds.First();
         }
         return(true);
     }
     else if (IsLeftSidebarVisible)
     {
         IsGamepadFocused        = true;
         IsNavigatingWithGamepad = true;
         if (ClosestTo.HasValue)
         {
             HoveredButtonBounds = LeftSidebarButtonBounds.OrderBy(x => x.SquaredDistanceBetweenCenters(ClosestTo.Value)).First();
         }
         else
         {
             HoveredButtonBounds = LeftSidebarButtonBounds.First();
         }
         return(true);
     }
     else
     {
         HoveredButtonBounds = null;
         return(false);
     }
 }
Beispiel #4
0
 public bool TryGetSlotNeighbor(Rectangle?ItemSlot, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
 {
     if (!ItemSlot.HasValue)
     {
         Neighbor = null;
         return(false);
     }
     else if (IsLeftSidebarVisible && LeftSidebarButtonBounds.Contains(ItemSlot.Value))
     {
         return(GamepadControls.TryGetSlotNeighbor(LeftSidebarButtonBounds, ItemSlot, 1, Direction, HorizontalWrapping, VerticalWrapping, out Neighbor));
     }
     else if (IsRightSidebarVisible && RightSidebarButtonBounds.Contains(ItemSlot.Value))
     {
         return(GamepadControls.TryGetSlotNeighbor(RightSidebarButtonBounds, ItemSlot, 1, Direction, HorizontalWrapping, VerticalWrapping, out Neighbor));
     }
     else
     {
         Neighbor = null;
         return(false);
     }
 }
Beispiel #5
0
        /*//  Doesn't work - this is a bug within the game, not my code. Pressing the 'B' button on my Xbox One controller is sending Keys.E to receiveKeyPress.
         * public override void receiveKeyPress(Keys key)
         * {
         *  if (Game1.options.gamepadControls || (key.ToSButton().TryGetController(out Buttons b) && GamepadControls.IsMatch(b, GamepadControls.CloseBag)))
         *      return; // Let this button press be handled by our custom OnGamepadButtonsPressed logic
         *  else
         *      base.receiveKeyPress(key);
         * }*/

        #region Input Handling

        #region Mouse Handling
        public void OnMouseMoved(CursorMovedEventArgs e)
        {
            if (IsShowingModalMenu && CustomizeIconMenu != null)
            {
                CustomizeIconMenu.OnMouseMoved(e);
            }
            else
            {
                if (InventoryMenu.Bounds.Contains(e.OldPosition.LegacyScreenPixels().AsPoint()) || InventoryMenu.Bounds.Contains(e.NewPosition.LegacyScreenPixels().AsPoint()))
                {
                    InventoryMenu.OnMouseMoved(e);
                }

                if (Content.Bounds.Contains(e.OldPosition.LegacyScreenPixels().AsPoint()) || Content.Bounds.Contains(e.NewPosition.LegacyScreenPixels().AsPoint()))
                {
                    Content.OnMouseMoved(e);
                }

                if (IsLeftSidebarVisible || IsRightSidebarVisible)
                {
                    Point OldPos = e.OldPosition.LegacyScreenPixels().AsPoint();
                    Point NewPos = e.NewPosition.LegacyScreenPixels().AsPoint();

                    if (LeftSidebarButtonBounds.Any(x => x.Contains(OldPos) || x.Contains(NewPos)) ||
                        RightSidebarButtonBounds.Any(x => x.Contains(OldPos) || x.Contains(NewPos)))
                    {
                        if (IsLeftSidebarVisible && DepositAllBounds.Contains(NewPos))
                        {
                            this.HoveredButton = SidebarButton.DepositAll;
                        }
                        else if (IsLeftSidebarVisible && WithdrawAllBounds.Contains(NewPos))
                        {
                            this.HoveredButton = SidebarButton.WithdrawAll;
                        }
                        else if (IsLeftSidebarVisible && AutolootBounds.Contains(NewPos))
                        {
                            this.HoveredButton = SidebarButton.Autoloot;
                        }
                        else if (IsRightSidebarVisible && HelpInfoBounds.Contains(NewPos))
                        {
                            this.HoveredButton = SidebarButton.HelpInfo;
                        }
                        else if (IsRightSidebarVisible && !(Bag is BundleBag) && CustomizeIconBounds.Contains(NewPos))
                        {
                            this.HoveredButton = SidebarButton.CustomizeIcon;
                        }
                        else
                        {
                            this.HoveredButton = null;
                        }

                        if (HoveredButton != null)
                        {
                            this.IsNavigatingWithGamepad = false;
                        }
                    }
                }
            }

            UpdateHoveredItem(e);
        }
Beispiel #6
0
        private void InitializeLayout()
        {
            ResizeIteration = 0;
            int PreviousWidth  = -1;
            int PreviousHeight = -1;

            bool AttemptResize;

            do
            {
                ResizeIteration++;

                int SidebarWidth  = 0;
                int SidebarHeight = 0;
                if (IsLeftSidebarVisible || IsRightSidebarVisible)
                {
                    SidebarWidth = ButtonSize + ButtonLeftTopMargin * 2;

                    int LeftButtons  = LeftSidebarButtonBounds.Count();
                    int LeftHeight   = InventoryMargin + ButtonLeftTopMargin + LeftButtons * ButtonSize + (LeftButtons - 1) * ButtonBottomMargin + ButtonLeftTopMargin + InventoryMargin;
                    int RightButtons = RightSidebarButtonBounds.Count();
                    int RightHeight  = InventoryMargin + ButtonLeftTopMargin + RightButtons * ButtonSize + (RightButtons - 1) * ButtonBottomMargin + ButtonLeftTopMargin + InventoryMargin;
                    SidebarHeight = Math.Max(IsLeftSidebarVisible ? LeftHeight : 0, IsRightSidebarVisible ? RightHeight : 0);
                }

                InventoryMenu.InitializeLayout(ResizeIteration);
                Content.InitializeLayout(ResizeIteration);

                //  Compute size of menu
                int InventoryWidth = InventoryMenu.RelativeBounds.Width + InventoryMargin * 2 + SidebarWidth * 2;
                int ContentsWidth  = Content.RelativeBounds.Width + ContentsMargin * 2;
                width = Math.Max(InventoryWidth, ContentsWidth);
                bool IsWidthBoundToContents = ContentsWidth > InventoryWidth;
                height            = Math.Max(InventoryMenu.RelativeBounds.Height + InventoryMargin * 2, SidebarHeight) + Math.Max(Content.RelativeBounds.Height + ContentsMargin * 2, 0);
                xPositionOnScreen = (int)((Game1.viewport.Size.Width * DrawingScaleFactor - width) / 2);
                yPositionOnScreen = (int)((Game1.viewport.Size.Height * DrawingScaleFactor - height) / 2);

                //  Check if menu fits on screen
                bool IsMenuTooWide = width > Game1.viewport.Size.Width * DrawingScaleFactor;
                bool IsMenuTooTall = height > Game1.viewport.Size.Height * DrawingScaleFactor;
                bool FitsOnScreen  = !IsMenuTooWide && !IsMenuTooTall;
                bool DidSizeChange = width != PreviousWidth || height != PreviousHeight;
                PreviousWidth  = width;
                PreviousHeight = height;

                AttemptResize = !FitsOnScreen && ResizeIteration < 5 && Content.CanResize && DidSizeChange && (IsWidthBoundToContents || IsMenuTooTall);
            } while (AttemptResize);

            //  Set position of inventory and contents
            InventoryMenu.SetTopLeft(new Point(
                                         xPositionOnScreen + (width - InventoryMenu.RelativeBounds.Width) / 2,
                                         yPositionOnScreen + Content.RelativeBounds.Height + ContentsMargin * 2 + InventoryMargin)
                                     );
            Content.SetTopLeft(new Point(
                                   xPositionOnScreen + (width - Content.RelativeBounds.Width) / 2,
                                   //BagInfo.Bounds.Right - ContentsMargin + (width - BagInfo.Bounds.Width - ContentsMargin - GetRelativeContentBounds().Width) / 2,
                                   yPositionOnScreen + ContentsMargin));

            //  Set bounds of sidebar buttons
            if (IsLeftSidebarVisible)
            {
                DepositAllBounds  = new Rectangle(xPositionOnScreen + ContentsMargin + ButtonLeftTopMargin, InventoryMenu.Bounds.Top + ButtonLeftTopMargin, ButtonSize, ButtonSize);
                WithdrawAllBounds = new Rectangle(xPositionOnScreen + ContentsMargin + ButtonLeftTopMargin, InventoryMenu.Bounds.Top + ButtonLeftTopMargin + ButtonSize + ButtonBottomMargin, ButtonSize, ButtonSize);
                AutolootBounds    = new Rectangle(xPositionOnScreen + ContentsMargin + ButtonLeftTopMargin, InventoryMenu.Bounds.Top + ButtonLeftTopMargin + ButtonSize * 2 + ButtonBottomMargin * 2, ButtonSize, ButtonSize);
            }
            if (IsRightSidebarVisible)
            {
                HelpInfoBounds      = new Rectangle(xPositionOnScreen + width - ContentsMargin - ButtonLeftTopMargin - ButtonSize, InventoryMenu.Bounds.Top + ButtonLeftTopMargin, ButtonSize, ButtonSize);
                CustomizeIconBounds = new Rectangle(xPositionOnScreen + width - ContentsMargin - ButtonLeftTopMargin - ButtonSize, InventoryMenu.Bounds.Top + ButtonLeftTopMargin + ButtonSize + ButtonBottomMargin, ButtonSize, ButtonSize);
            }

            //  Set bounds of close button
            Point CloseButtonOffset = Constants.TargetPlatform == GamePlatform.Android ? new Point(24, -24) : new Point(16, -16);

            upperRightCloseButton.bounds.X = xPositionOnScreen + width - upperRightCloseButton.bounds.Width + CloseButtonOffset.X;
            upperRightCloseButton.bounds.Y = yPositionOnScreen + CloseButtonOffset.Y;
        }