Ejemplo n.º 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);
     }
 }
Ejemplo n.º 2
0
        public bool TryNavigate(NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping)
        {
            Rectangle?HoveredSlot = GetHoveredSlot(false);

            if (IsGamepadFocused && HoveredSlot == null)
            {
                HoveredBundleItem       = ItemSlotPositions.First().Key;
                IsNavigatingWithGamepad = HoveredBundleItem != null;
                return(HoveredBundleItem != null);
            }
            else if (TryGetSlotNeighbor(HoveredSlot, Direction, HorizontalWrapping, VerticalWrapping, out Rectangle? Neighbor))
            {
                foreach (KeyValuePair <BundleItem, Rectangle> KVP in ItemSlotPositions)
                {
                    if (KVP.Value == Neighbor.Value)
                    {
                        HoveredBundleItem       = KVP.Key;
                        HoveredBundleTask       = null;
                        IsNavigatingWithGamepad = true;
                        return(true);
                    }
                }

                foreach (KeyValuePair <BundleTask, Rectangle> KVP in TaskHeaderPositions)
                {
                    if (KVP.Value == Neighbor.Value)
                    {
                        HoveredBundleTask       = KVP.Key;
                        HoveredBundleItem       = null;
                        IsNavigatingWithGamepad = true;
                        return(true);
                    }
                }

                HoveredBundleItem = null;
                HoveredBundleTask = null;

                return(false);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 3
0
 public bool TryNavigate(NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping)
 {
     if (IsGamepadFocused && HoveredSlot == null)
     {
         HoveredSlot             = InventorySlotBounds.FirstOrDefault();
         IsNavigatingWithGamepad = HoveredSlot != null;
         return(HoveredSlot != null);
     }
     else if (TryGetSlotNeighbor(HoveredSlot, Direction, HorizontalWrapping, VerticalWrapping, out Rectangle? Neighbor))
     {
         HoveredSlot             = Neighbor.Value;
         IsNavigatingWithGamepad = true;
         return(true);
     }
     else
     {
         return(false);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
        public bool TryGetSlotNeighbor(Rectangle?ItemSlot, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
        {
            List <Rectangle> AllSlots = TaskHeaderPositions.Select(x => x.Value).Union(ItemSlotPositions.Select(x => x.Value)).Union(LockedSlotPositions)
                                        .OrderBy(x => x.Top).ThenBy(x => x.Left).ToList();

            return(GamepadControls.TryGetSlotNeighbor(AllSlots, ItemSlot, ColumnCount, Direction, HorizontalWrapping, VerticalWrapping, out Neighbor));
        }
Ejemplo n.º 6
0
 public bool TryGetSlotNeighbor(Rectangle?ItemSlot, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
 {
     return(GamepadControls.TryGetSlotNeighbor(InventorySlotBounds, ItemSlot, InventoryColumns, Direction, HorizontalWrapping, VerticalWrapping, out Neighbor));
 }
Ejemplo n.º 7
0
        internal static bool TryGetSlotNeighbor(IList <Rectangle> AllSlots, Rectangle?CurrentSlot, int ColumnsPerRow, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
        {
            Neighbor = null;
            if (!CurrentSlot.HasValue || !AllSlots.Contains(CurrentSlot.Value))
            {
                return(false);
            }
            else
            {
                int Index = AllSlots.IndexOf(CurrentSlot.Value);

                int CurrentRow    = Index / ColumnsPerRow;
                int CurrentColumn = Index % ColumnsPerRow;

                int MaxRow    = Math.Max(0, (AllSlots.Count - 1) / ColumnsPerRow);
                int MaxColumn = Math.Min(AllSlots.Count, ColumnsPerRow) - 1;

                int NeighborRow;
                int NeighborColumn;

                if (Direction == NavigationDirection.Up)
                {
                    NeighborRow    = CurrentRow - 1;
                    NeighborColumn = CurrentColumn;

                    if (NeighborRow < 0)
                    {
                        if (VerticalWrapping == NavigationWrappingMode.NoWrap)
                        {
                            return(false);
                        }
                        else if (VerticalWrapping == NavigationWrappingMode.AllowWrapToSame)
                        {
                            NeighborRow = MaxRow;
                        }
                        else if (VerticalWrapping == NavigationWrappingMode.AllowWrapToPreviousOrNext)
                        {
                            NeighborRow    = MaxRow;
                            NeighborColumn = CurrentColumn - 1;

                            if (NeighborColumn < 0)
                            {
                                NeighborColumn = MaxColumn;
                            }
                        }
                    }
                }
                else if (Direction == NavigationDirection.Down)
                {
                    NeighborRow    = CurrentRow + 1;
                    NeighborColumn = CurrentColumn;

                    if (NeighborRow > MaxRow)
                    {
                        if (VerticalWrapping == NavigationWrappingMode.NoWrap)
                        {
                            return(false);
                        }
                        else if (VerticalWrapping == NavigationWrappingMode.AllowWrapToSame)
                        {
                            NeighborRow = 0;
                        }
                        else if (VerticalWrapping == NavigationWrappingMode.AllowWrapToPreviousOrNext)
                        {
                            NeighborRow    = 0;
                            NeighborColumn = CurrentColumn + 1;

                            if (NeighborColumn > MaxColumn)
                            {
                                NeighborColumn = 0;
                            }
                        }
                    }
                }
                else if (Direction == NavigationDirection.Left)
                {
                    NeighborRow    = CurrentRow;
                    NeighborColumn = CurrentColumn - 1;

                    if (NeighborColumn < 0)
                    {
                        if (HorizontalWrapping == NavigationWrappingMode.NoWrap)
                        {
                            return(false);
                        }
                        else if (HorizontalWrapping == NavigationWrappingMode.AllowWrapToSame)
                        {
                            NeighborColumn = MaxColumn;
                        }
                        else if (HorizontalWrapping == NavigationWrappingMode.AllowWrapToPreviousOrNext)
                        {
                            NeighborColumn = MaxColumn;
                            NeighborRow    = CurrentRow - 1;

                            if (NeighborRow < 0)
                            {
                                NeighborRow = MaxRow;
                            }
                        }
                    }
                }
                else if (Direction == NavigationDirection.Right)
                {
                    NeighborRow    = CurrentRow;
                    NeighborColumn = CurrentColumn + 1;

                    if (NeighborColumn > MaxColumn)
                    {
                        if (HorizontalWrapping == NavigationWrappingMode.NoWrap)
                        {
                            return(false);
                        }
                        else if (HorizontalWrapping == NavigationWrappingMode.AllowWrapToSame)
                        {
                            NeighborColumn = 0;
                        }
                        else if (HorizontalWrapping == NavigationWrappingMode.AllowWrapToPreviousOrNext)
                        {
                            NeighborColumn = 0;
                            NeighborRow    = CurrentRow + 1;

                            if (NeighborRow > MaxRow)
                            {
                                NeighborRow = 0;
                            }
                        }
                    }
                }
                else
                {
                    throw new NotImplementedException(string.Format("Unrecognized Navigation direction: {0}", Direction.ToString()));
                }

                if (NeighborRow < 0 || NeighborRow > MaxRow || NeighborColumn < 0 || NeighborColumn > MaxColumn)
                {
                    return(false);
                }
                else
                {
                    int NeighborIndex = NeighborRow * ColumnsPerRow + NeighborColumn;
                    if (NeighborIndex >= AllSlots.Count)
                    {
                        return(false);
                    }
                    else
                    {
                        Neighbor = AllSlots[NeighborIndex];
                        return(true);
                    }
                }
            }
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
0
        public bool TryGetSlotNeighbor(Rectangle?ItemSlot, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
        {
            List <Rectangle> AllSlots = SlotBounds.Select(x => x.Value).SelectMany(x => x.OrderBy(y => y.Key).Select(z => z.Value)).ToList();

            return(GamepadControls.TryGetSlotNeighbor(AllSlots, ItemSlot, GroupsPerRow * ColumnsPerGroup, Direction, HorizontalWrapping, VerticalWrapping, out Neighbor));
        }
Ejemplo n.º 10
0
 public bool TryNavigate(NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping)
 {
     return(false);
 }
Ejemplo n.º 11
0
 public bool TryGetSlotNeighbor(Rectangle?ItemSlot, NavigationDirection Direction, NavigationWrappingMode HorizontalWrapping, NavigationWrappingMode VerticalWrapping, out Rectangle?Neighbor)
 {
     Neighbor = null;
     return(false);
 }