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; }