private void HandlePrimaryAction() { if ((IsLeftSidebarVisible || IsRightSidebarVisible) && HoveredButton.HasValue) { if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.DepositAll) { List <Object> ToDeposit = InventorySource.Where(x => x != null && x is Object Obj && Bag.IsValidBagObject(Obj)).Cast <Object>().ToList(); Bag.MoveToBag(ToDeposit, ToDeposit.Select(x => x.Stack).ToList(), out int TotalMovedQty, true, InventorySource); } else if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.WithdrawAll) { List <Object> ToWithdraw = Bag.Contents.Where(x => x != null).ToList(); Bag.MoveFromBag(ToWithdraw, ToWithdraw.Select(x => x.Stack).ToList(), out int TotalMovedQty, true, InventorySource, ActualInventoryCapacity); } else if (IsLeftSidebarVisible && HoveredButton.Value == SidebarButton.Autoloot) { if (Bag is BoundedBag BB) { BB.Autofill = !BB.Autofill; } else if (Bag is Rucksack RS) { RS.CycleAutofill(); } } else if (IsRightSidebarVisible && HoveredButton.Value == SidebarButton.HelpInfo) { } else if (IsRightSidebarVisible && HoveredButton.Value == SidebarButton.CustomizeIcon && Bag.CanCustomizeIcon()) { ItemBag Copy; if (Bag is BoundedBag BB) { if (BB is BundleBag) { Copy = new BundleBag(Bag.Size, false); } else { Copy = new BoundedBag(BB.TypeInfo, Bag.Size, false); } } else if (Bag is Rucksack RS) { Copy = new Rucksack(Bag.Size, false); } else if (Bag is OmniBag OB) { Copy = new OmniBag(Bag.Size); } else { throw new NotImplementedException(string.Format("Unexpected Bag Type while creating CustomizeIconMenu: {0}", Bag.GetType().ToString())); } CustomizeIconMenu = new CustomizeIconMenu(this, this.Bag, Copy, 24); } } }
internal void OnWindowSizeChanged() { InitializeLayout(); if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.InitializeLayout(1); } }
public void CloseModalMenu() { if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.OnClose(); HoveredButton = null; CustomizeIconMenu = null; } }
public void OnMouseButtonReleased(ButtonReleasedEventArgs e) { if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.OnMouseButtonReleased(e); } else { InventoryMenu.OnMouseButtonReleased(e); Content.OnMouseButtonReleased(e); } }
public void OnMouseButtonPressed(ButtonPressedEventArgs e) { if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.OnMouseButtonPressed(e); } else { InventoryMenu.OnMouseButtonPressed(e); Content.OnMouseButtonPressed(e); if (e.Button == SButton.MouseLeft) { HandlePrimaryAction(); } if (e.Button == SButton.MouseRight) { HandleSecondaryAction(); } } }
public void Update(UpdateTickedEventArgs e) { RecentlyGainedFocus = false; if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.Update(e); } else { if (e.IsMultipleOf(GamepadControls.Current.NavigationRepeatFrequency) && IsGamepadFocused && IsNavigatingWithGamepad) { if (!GamepadControls.HandleNavigationButtons(this, null, HoveredButtonBounds)) { this.IsGamepadFocused = false; } } InventoryMenu.Update(e); Content.Update(e); } }
public sealed override void draw(SpriteBatch b) { try { DrawBox(b, xPositionOnScreen, yPositionOnScreen, width, height); int SeparatorHeight = 24; DrawHorizontalSeparator(b, xPositionOnScreen, InventoryMenu.TopLeftScreenPosition.Y - InventoryMargin - SeparatorHeight / 2, width, SeparatorHeight); InventoryMenu.Draw(b); if (IsLeftSidebarVisible || IsRightSidebarVisible) { if (IsLeftSidebarVisible) { // Draw the deposit/withdraw-all buttons Rectangle ArrowUpIconSourceRect = new Rectangle(421, 459, 12, 12); Rectangle ArrowDownIconSourceRect = new Rectangle(421, 472, 12, 12); int ArrowSize = (int)(ArrowUpIconSourceRect.Width * 1.5 / 32.0 * DepositAllBounds.Width); b.Draw(Game1.menuTexture, DepositAllBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(DepositAllBounds.X + (DepositAllBounds.Width - ArrowSize) / 2, DepositAllBounds.Y + (DepositAllBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowUpIconSourceRect, Color.White); b.Draw(Game1.menuTexture, WithdrawAllBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(WithdrawAllBounds.X + (WithdrawAllBounds.Width - ArrowSize) / 2, WithdrawAllBounds.Y + (WithdrawAllBounds.Height - ArrowSize) / 2, ArrowSize, ArrowSize), ArrowDownIconSourceRect, Color.White); // Draw the autofill togglebutton Rectangle HandIconSourceRect = new Rectangle(32, 0, 10, 10); int HandIconSize = (int)(HandIconSourceRect.Width * 2.0 / 32.0 * AutolootBounds.Width); b.Draw(Game1.menuTexture, AutolootBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(AutolootBounds.X + (AutolootBounds.Width - HandIconSize) / 2, AutolootBounds.Y + (AutolootBounds.Height - HandIconSize) / 2, HandIconSize, HandIconSize), HandIconSourceRect, Color.White); if (Bag is BoundedBag BB) { if (!BB.Autofill) { Rectangle DisabledIconSourceRect = new Rectangle(322, 498, 12, 12); int DisabledIconSize = (int)(DisabledIconSourceRect.Width * 1.5 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - DisabledIconSize - 2, AutolootBounds.Bottom - DisabledIconSize - 2, DisabledIconSize, DisabledIconSize); b.Draw(Game1.mouseCursors, Destination, DisabledIconSourceRect, Color.White); } } else if (Bag is Rucksack RS) { if (!RS.Autofill) { Rectangle DisabledIconSourceRect = new Rectangle(322, 498, 12, 12); int DisabledIconSize = (int)(DisabledIconSourceRect.Width * 1.5 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - DisabledIconSize - 2, AutolootBounds.Bottom - DisabledIconSize - 2, DisabledIconSize, DisabledIconSize); b.Draw(Game1.mouseCursors, Destination, DisabledIconSourceRect, Color.White); } else { if (RS.AutofillPriority == AutofillPriority.Low) { Rectangle LowPriorityIconSourceRect = new Rectangle(421, 472, 12, 12); int LowPriorityIconSize = (int)(LowPriorityIconSourceRect.Width * 1.0 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - LowPriorityIconSize - 2, AutolootBounds.Bottom - LowPriorityIconSize - 2, LowPriorityIconSize, LowPriorityIconSize); b.Draw(Game1.mouseCursors, Destination, LowPriorityIconSourceRect, Color.White); } else if (RS.AutofillPriority == AutofillPriority.High) { Rectangle HighPriorityIconSourceRect = new Rectangle(421, 459, 12, 12); int HighPriorityIconSize = (int)(HighPriorityIconSourceRect.Width * 1.0 / 32.0 * AutolootBounds.Width); Rectangle Destination = new Rectangle(AutolootBounds.Right - HighPriorityIconSize - 2, AutolootBounds.Bottom - HighPriorityIconSize - 2, HighPriorityIconSize, HighPriorityIconSize); b.Draw(Game1.mouseCursors, Destination, HighPriorityIconSourceRect, Color.White); } } } } if (IsRightSidebarVisible) { // Draw the help button Rectangle HelpIconSourceRect = new Rectangle(176, 425, 9, 12); int HelpIconWidth = (int)(HelpIconSourceRect.Width * 1.5 / 32.0 * HelpInfoBounds.Width); int HelpIconHeight = (int)(HelpIconSourceRect.Height * 1.5 / 32.0 * HelpInfoBounds.Height); b.Draw(Game1.menuTexture, HelpInfoBounds, new Rectangle(128, 128, 64, 64), Color.White); b.Draw(Game1.mouseCursors, new Rectangle(HelpInfoBounds.X + (HelpInfoBounds.Width - HelpIconWidth) / 2, HelpInfoBounds.Y + (HelpInfoBounds.Height - HelpIconHeight) / 2, HelpIconWidth, HelpIconHeight), HelpIconSourceRect, Color.White); if (Bag.CanCustomizeIcon()) { // Draw the customize icon button Rectangle CustomizeSourceRect = new Rectangle(121, 471, 12, 12); int CustomizeIconWidth = CustomizeIconBounds.Width; int CustomizeIconHeight = CustomizeIconBounds.Height; b.Draw(Game1.mouseCursors, new Rectangle(CustomizeIconBounds.X + (CustomizeIconBounds.Width - CustomizeIconWidth) / 2, CustomizeIconBounds.Y + (CustomizeIconBounds.Height - CustomizeIconHeight) / 2, CustomizeIconWidth, CustomizeIconHeight), CustomizeSourceRect, Color.White); b.Draw(Game1.menuTexture, CustomizeIconBounds, new Rectangle(128, 128, 64, 64), Color.White); } } // Draw a yellow border around the hovered sidebar button if (HoveredButton.HasValue) { Rectangle HoveredBounds = HoveredButtonBounds.Value; Color HighlightColor = Color.Yellow; Texture2D Highlight = TextureHelpers.GetSolidColorTexture(Game1.graphics.GraphicsDevice, HighlightColor); b.Draw(Highlight, HoveredBounds, Color.White * 0.25f); int BorderThickness = HoveredBounds.Width / 16; DrawBorder(b, HoveredBounds, BorderThickness, HighlightColor); } } Content.Draw(b); if (IsShowingModalMenu && CustomizeIconMenu != null) { CustomizeIconMenu.Draw(b); } else { InventoryMenu.DrawToolTips(b); Content.DrawToolTips(b); // Draw tooltips on the sidebar buttons if ((IsLeftSidebarVisible || IsRightSidebarVisible) && HoveredButton.HasValue) { if (IsLeftSidebarVisible) { string ButtonToolTip = ""; if (HoveredButton.Value == SidebarButton.DepositAll) { ButtonToolTip = ItemBagsMod.Translate("DepositAllToolTip"); } else if (HoveredButton.Value == SidebarButton.WithdrawAll) { ButtonToolTip = ItemBagsMod.Translate("WithdrawAllToolTip"); } else if (HoveredButton.Value == SidebarButton.Autoloot) { if (Bag is BoundedBag BB) { ButtonToolTip = ItemBagsMod.Translate(BB.Autofill ? "AutofillOnToolTip" : "AutofillOffToolTip"); } else if (Bag is Rucksack RS) { string TranslationKey; if (RS.Autofill) { if (RS.AutofillPriority == AutofillPriority.Low) { TranslationKey = "RucksackAutofillLowPriorityToolTip"; } else if (RS.AutofillPriority == AutofillPriority.High) { TranslationKey = "RucksackAutofillHighPriorityToolTip"; } else { throw new NotImplementedException(string.Format("Unrecognized Rucksack AutofillPriority: {0}", RS.AutofillPriority.ToString())); } } else { TranslationKey = "RucksackAutofillOffToolTip"; } ButtonToolTip = ItemBagsMod.Translate(TranslationKey); } } if (!string.IsNullOrEmpty(ButtonToolTip)) { int Margin = 16; Vector2 ToolTipSize = Game1.smallFont.MeasureString(ButtonToolTip); DrawBox(b, HoveredButtonBounds.Value.Right, HoveredButtonBounds.Value.Top, (int)(ToolTipSize.X + Margin * 2), (int)(ToolTipSize.Y + Margin * 2)); b.DrawString(Game1.smallFont, ButtonToolTip, new Vector2(HoveredButtonBounds.Value.Right + Margin, HoveredButtonBounds.Value.Top + Margin), Color.Black); } } if (IsRightSidebarVisible) { string ButtonToolTip = ""; if (HoveredButton.Value == SidebarButton.HelpInfo) { ButtonToolTip = ItemBagsMod.Translate("HelpInfoToolTip"); } else if (HoveredButton.Value == SidebarButton.CustomizeIcon) { ButtonToolTip = ItemBagsMod.Translate("CustomizeIconToolTip"); } if (!string.IsNullOrEmpty(ButtonToolTip)) { int Margin = 16; Vector2 ToolTipSize = Game1.smallFont.MeasureString(ButtonToolTip); DrawBox(b, HoveredButtonBounds.Value.Left - (int)(ToolTipSize.X + Margin * 2), HoveredButtonBounds.Value.Top, (int)(ToolTipSize.X + Margin * 2), (int)(ToolTipSize.Y + Margin * 2)); b.DrawString(Game1.smallFont, ButtonToolTip, new Vector2(HoveredButtonBounds.Value.Left - Margin - ToolTipSize.X, HoveredButtonBounds.Value.Top + Margin), Color.Black); } } } } upperRightCloseButton.draw(b); if (!Game1.options.hardwareCursor && !Game1.options.gamepadControls) { drawMouse(b); } } catch (Exception ex) { ItemBagsMod.ModInstance.Monitor.Log(string.Format("Unhandled error in ItemBagMenu.Draw: {0}", ex.Message), LogLevel.Error); } }
/*// 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); }