public void OnMouseMoved(CursorMovedEventArgs e) { if (Bounds.Contains(e.OldPosition.ScreenPixels.AsPoint()) || Bounds.Contains(e.NewPosition.ScreenPixels.AsPoint())) { Rectangle?PreviouslyHovered = HoveredSlot; this.HoveredSlot = null; if (SlotBounds != null) { foreach (Rectangle Rect in SlotBounds) { if (Rect.Contains(e.NewPosition.ScreenPixels.AsPoint())) { if (PreviouslyHovered.HasValue && Rect != PreviouslyHovered.Value) { SecondaryActionButtonPressedLocation = null; } this.HoveredSlot = Rect; this.IsNavigatingWithGamepad = false; break; } } } } if (IsRightSidebarVisible) { Point OldPos = e.OldPosition.ScreenPixels.AsPoint(); Point NewPos = e.NewPosition.ScreenPixels.AsPoint(); if (ContentsRightSidebarButtonBounds.Any(x => x.Contains(OldPos) || x.Contains(NewPos))) { if (SortingPropertyBounds.Contains(NewPos)) { this.HoveredContentsButton = ContentsSidebarButton.SortingProperty; this.IsNavigatingWithGamepad = false; } else if (SortingOrderBounds.Contains(NewPos)) { this.HoveredContentsButton = ContentsSidebarButton.SortingOrder; this.IsNavigatingWithGamepad = false; } else { this.HoveredContentsButton = null; } } else { this.HoveredContentsButton = null; } } UpdateHoveredItem(e); }
public void InitializeLayout(int ResizeIteration) { if (Rucksack == null) { return; } HoveredSlot = null; HoveredContentsButton = null; SecondaryActionButtonPressedTime = null; SecondaryActionButtonPressedLocation = null; if (ResizeIteration > 1) { this.SlotSize = Math.Min(OriginalSlotSize, Math.Max(24, OriginalSlotSize - (ResizeIteration - 1) * 8)); } int SidebarWidth = 0; int SidebarHeight = 0; if (IsRightSidebarVisible) { SidebarWidth = ItemBagMenu.ButtonSize + ItemBagMenu.ButtonLeftTopMargin * 2; int RightButtons = ContentsRightSidebarButtonBounds.Count(); int RightHeight = ItemBagMenu.ContentsMargin + ItemBagMenu.ButtonLeftTopMargin + RightButtons * ItemBagMenu.ButtonSize + (RightButtons - 1) * ItemBagMenu.ButtonBottomMargin + ItemBagMenu.ButtonLeftTopMargin + ItemBagMenu.ContentsMargin; SidebarHeight = RightHeight; } List <Rectangle> SlotBounds = new List <Rectangle>(); int CurrentRow = 0; int CurrentColumn = 0; int TotalSlots = (((Rucksack.NumSlots - 1) / ColumnCount) + 1) * ColumnCount; // make it a perfect square. EX: if 12 columns, and 18 total slots, increase to next multiple of 12... 24 for (int i = 0; i < TotalSlots; i++) { if (CurrentColumn == ColumnCount) { CurrentRow++; CurrentColumn = 0; } int X = CurrentColumn * SlotSize; int Y = CurrentRow * SlotSize; SlotBounds.Add(new Rectangle(Padding + SidebarWidth + X, Padding + Y, SlotSize, SlotSize)); CurrentColumn++; } RelativeSlotBounds = new ReadOnlyCollection <Rectangle>(SlotBounds); int TotalWidth = ColumnCount * SlotSize + Padding * 2 + SidebarWidth * 2; int TotalHeight = Math.Max((CurrentRow + 1) * SlotSize + Padding * 2, SidebarHeight); // Set bounds of sidebar buttons if (IsRightSidebarVisible) { SortingPropertyBounds = new Rectangle(TotalWidth - ItemBagMenu.ContentsMargin - ItemBagMenu.ButtonLeftTopMargin - ItemBagMenu.ButtonSize, ItemBagMenu.ButtonLeftTopMargin, ItemBagMenu.ButtonSize, ItemBagMenu.ButtonSize); SortingOrderBounds = new Rectangle(TotalWidth - ItemBagMenu.ContentsMargin - ItemBagMenu.ButtonLeftTopMargin - ItemBagMenu.ButtonSize, ItemBagMenu.ButtonLeftTopMargin + ItemBagMenu.ButtonSize + ItemBagMenu.ButtonBottomMargin, ItemBagMenu.ButtonSize, ItemBagMenu.ButtonSize); } this.RelativeBounds = new Rectangle(0, 0, TotalWidth, TotalHeight); }