Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
 public bool TryGetMenuNeighbor(NavigationDirection Direction, out IGamepadControllable Neighbor)
 {
     if (MenuNeighbors.TryGetValue(Direction, out Neighbor))
     {
         return(true);
     }
     else if (Menu != null)
     {
         return(Menu.MenuNeighbors.TryGetValue(Direction, out Neighbor));
     }
     else
     {
         return(false);
     }
 }
Exemplo n.º 3
0
 public bool TryGetMenuNeighbor(NavigationDirection Direction, out IGamepadControllable Neighbor)
 {
     return(MenuNeighbors.TryGetValue(Direction, out Neighbor));
 }
Exemplo n.º 4
0
        internal static bool HandleNavigationButtons(IGamepadControllable Instance, Buttons?PressedButtons, Rectangle?CurrentSlotPosition)
        {
            bool IsFocused = true;

            foreach (NavigationDirection Direction in Enum.GetValues(typeof(NavigationDirection)).Cast <NavigationDirection>())
            {
                //  Handle navigating a single slot at a time
                bool HandleSingleSlotNavigation;
                if (PressedButtons.HasValue)
                {
                    HandleSingleSlotNavigation = IsMatch(PressedButtons.Value, NavigateSingleButtons[Direction]);
                }
                else
                {
                    HandleSingleSlotNavigation = InputHandler.IsNavigationButtonPressed(Direction) && DateTime.Now.Subtract(InputHandler.NavigationButtonsPressedTime[Direction]).TotalMilliseconds >= Current.NavigationRepeatInitialDelay;
                }
                if (HandleSingleSlotNavigation)
                {
                    NavigationWrappingMode HorizontalWrapping = NavigationWrappingMode.AllowWrapToSame;
                    NavigationWrappingMode VerticalWrapping   = NavigationWrappingMode.AllowWrapToSame;

                    bool HasNeighbor = Instance.TryGetMenuNeighbor(Direction, out IGamepadControllable Neighbor);
                    if (HasNeighbor)
                    {
                        if (Direction == NavigationDirection.Left || Direction == NavigationDirection.Right)
                        {
                            HorizontalWrapping = NavigationWrappingMode.NoWrap;
                        }
                        else
                        {
                            VerticalWrapping = NavigationWrappingMode.NoWrap;
                        }
                    }

                    if (!Instance.TryNavigate(Direction, HorizontalWrapping, VerticalWrapping))
                    {
                        //  If we're unable to continue moving the cursor in the desired direction,
                        //  then focus the gamepad controls on the appropriate neighboring UI element
                        if (HasNeighbor)
                        {
                            NavigationDirection StartingSide = GetOppositeDirection(Direction);
                            if (Neighbor.TryNavigateEnter(StartingSide, CurrentSlotPosition))
                            {
                                IsFocused = false;
                            }
                        }
                    }
                }

                //  Handle navigating across an entire UI element, or to the end of the current element's boundary
                if (PressedButtons.HasValue && IsMatch(PressedButtons.Value, NavigateMultipleButtons[Direction]))
                {
                    bool Handled = false;

                    //  Try to change focus to the neighboring UI element in this direction
                    bool HasNeighbor = Instance.TryGetMenuNeighbor(Direction, out IGamepadControllable Neighbor);
                    if (HasNeighbor)
                    {
                        NavigationDirection StartingSide = GetOppositeDirection(Direction);
                        if (Neighbor.TryNavigateEnter(StartingSide, CurrentSlotPosition))
                        {
                            Handled   = true;
                            IsFocused = false;
                        }
                    }

                    //  Navigate to the end of this element's boundary
                    if (!Handled)
                    {
                        while (Instance.TryNavigate(Direction, NavigationWrappingMode.NoWrap, NavigationWrappingMode.NoWrap))
                        {
                        }
                    }
                }
            }

            return(IsFocused);
        }