diff --git a/Intersect.Client.Core/Interface/Game/GameInterface.cs b/Intersect.Client.Core/Interface/Game/GameInterface.cs index 1d968ff795..9b6a6fd491 100644 --- a/Intersect.Client.Core/Interface/Game/GameInterface.cs +++ b/Intersect.Client.Core/Interface/Game/GameInterface.cs @@ -47,7 +47,7 @@ public partial class GameInterface : MutableInterface private QuestOfferWindow mQuestOfferWindow; - private ShopWindow mShopWindow; + private ShopWindow _shopWindow; private MapItemWindow mMapItemWindow; @@ -210,7 +210,7 @@ public void NotifyCloseShop() public void OpenShop() { - mShopWindow = new ShopWindow(GameCanvas) { DeleteOnClose = true }; + _shopWindow = new ShopWindow(GameCanvas) { DeleteOnClose = true }; mShouldOpenShop = false; } @@ -391,7 +391,7 @@ public void Update(TimeSpan elapsed, TimeSpan total) GameMenu.OpenInventory(); } - if (mShopWindow != null && (!mShopWindow.IsVisibleInTree || mShouldCloseShop)) + if (_shopWindow != null && (!_shopWindow.IsVisibleInTree || mShouldCloseShop)) { CloseShop(); } @@ -520,8 +520,8 @@ public void Draw(TimeSpan elapsed, TimeSpan total) private void CloseShop() { Globals.GameShop = null; - mShopWindow?.Hide(); - mShopWindow = null; + _shopWindow?.Hide(); + _shopWindow = null; PacketSender.SendCloseShop(); } @@ -584,7 +584,7 @@ public bool CloseAllWindows() closedWindows = true; } - if (mShopWindow is { IsVisibleInTree: true }) + if (_shopWindow is { IsVisibleInTree: true }) { CloseShop(); closedWindows = true; diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs index b3ed1ea9e3..c27a61ef3e 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryItem.cs @@ -1,5 +1,8 @@ using Intersect.Client.Core; +using Intersect.Client.Entities; +using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.GenericClasses; +using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.Framework.Gwen.Control.EventArguments; using Intersect.Client.Framework.Gwen.Input; @@ -13,101 +16,265 @@ using Intersect.Framework.Core.GameObjects.Items; using Intersect.GameObjects; using Intersect.Utilities; +using static Intersect.Client.Localization.Strings; namespace Intersect.Client.Interface.Game.Inventory; - -public partial class InventoryItem +public partial class InventoryItem : ImagePanel { + // Controls + private readonly ImagePanel _iconImage; + private readonly Label _quantityLabel; + private readonly Label _equipLabel; + private readonly Label _cooldownLabel; + private readonly ImagePanel _equipImageBackground; + private readonly InventoryWindow _inventoryWindow; + private Draggable? _dragIcon; + private ItemDescriptionWindow? _descWindow; + + // Drag Handling + public bool IsDragging; + private bool _canDrag; + private long _clickTime; + private bool _mouseOver; + private int _mouseX = -1; + private int _mouseY = -1; + + // Data control + private readonly int _mySlot = -1; + private string _textureLoaded = string.Empty; + + // Context Menu Handling + private readonly ContextMenu _contextMenu; + private readonly MenuItem _useItemMenuItem; + private readonly MenuItem _actionItemMenuItem; + private readonly MenuItem _dropItemMenuItem; + + public InventoryItem(InventoryWindow inventoryWindow, Base parent, int index) : base(parent, nameof(InventoryItem)) + { + _inventoryWindow = inventoryWindow; + _mySlot = index; - public ImagePanel Container; + MinimumSize = new Point(34, 34); + Margin = new Margin(4); + MouseInputEnabled = true; + TextureFilename = "inventoryitem.png"; - public Label EquipLabel; + _iconImage = new ImagePanel(this, "Icon") + { + MinimumSize = new Point(32, 32), + MouseInputEnabled = true, + Alignment = [Alignments.Center], + HoverSound = "octave-tap-resonant.wav", + }; + _iconImage.HoverEnter += _iconImage_HoverEnter; + _iconImage.HoverLeave += _iconImage_HoverLeave; + _iconImage.Clicked += _iconImage_Clicked; + _iconImage.DoubleClicked += _iconImage_DoubleClicked; - public ImagePanel EquipPanel; + _equipImageBackground = new ImagePanel(this, "EquippedIcon") + { + Texture = Graphics.Renderer.WhitePixel, + }; - public bool IsDragging; + _equipLabel = new Label(this, "EquippedLabel") + { + IsVisibleInParent = false, + Text = Strings.Inventory.EquippedSymbol, + FontName = "sourcesansproblack", + FontSize = 8, + TextColor = new Color(0, 255, 255, 255), + Alignment = [Alignments.Right, Alignments.Top], + BackgroundTemplateName = "equipped.png", + Padding = new Padding(2), + }; - //Dragging - private bool mCanDrag; + _cooldownLabel = new Label(this, "CooldownLabel") + { + IsVisibleInParent = false, + FontName = "sourcesansproblack", + FontSize = 8, + TextColor = new Color(0, 255, 255, 255), + Alignment = [Alignments.Center], + BackgroundTemplateName = "quantity.png", + Padding = new Padding(2), + }; - private long mClickTime; + _quantityLabel = new Label(this, "Quantity") + { + Alignment = [Alignments.Bottom, Alignments.Right], + BackgroundTemplateName = "quantity.png", + FontName = "sourcesansproblack", + FontSize = 8, + Padding = new Padding(2), + }; - private Label mCooldownLabel; + LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); - private int mCurrentAmt = 0; + // Generate our context menu with basic options. + _contextMenu = new ContextMenu(Interface.CurrentInterface.Root, "InventoryContextMenu") + { + IsVisibleInParent = false, + IconMarginDisabled = true, + ItemFont = GameContentManager.Current.GetFont(name: "sourcesansproblack"), + ItemFontSize = 10, + }; - private Guid mCurrentItemId; + _contextMenu.ClearChildren(); + _useItemMenuItem = _contextMenu.AddItem(Strings.ItemContextMenu.Use); + _useItemMenuItem.Clicked += _useItemContextItem_Clicked; + _dropItemMenuItem = _contextMenu.AddItem(Strings.ItemContextMenu.Drop); + _dropItemMenuItem.Clicked += _dropItemContextItem_Clicked; + _actionItemMenuItem = _contextMenu.AddItem(Strings.ItemContextMenu.Bank); + _actionItemMenuItem.Clicked += _actionItemContextItem_Clicked; + _contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString()); - private ItemDescriptionWindow mDescWindow; + if (Globals.Me is { } player) + { + player.InventoryUpdated += PlayerOnInventoryUpdated; + } + } - private Draggable mDragIcon; + #region Context Menu - private bool mIconCd; + public void OpenContextMenu() + { + // Clear out the old options since we might not show all of them + _contextMenu.ClearChildren(); - //Drag/Drop References - private InventoryWindow mInventoryWindow; + if (Globals.Me?.Inventory[_mySlot] is not { } inventorySlot) + { + return; + } - private bool mIsEquipped; + // No point showing a menu for blank space. + if (!ItemDescriptor.TryGet(inventorySlot.ItemId, out var descriptor)) + { + return; + } - //Mouse Event Variables - private bool mMouseOver; + // Add our use Item prompt, assuming we have a valid usecase. + switch (descriptor.ItemType) + { + case ItemType.Spell: + _contextMenu.AddChild(_useItemMenuItem); + var useItemLabel = descriptor.QuickCast ? Strings.ItemContextMenu.Cast : Strings.ItemContextMenu.Learn; + _useItemMenuItem.Text = useItemLabel.ToString(descriptor.Name); + break; - private int mMouseX = -1; + case ItemType.Event: + case ItemType.Consumable: + _contextMenu.AddChild(_useItemMenuItem); + _useItemMenuItem.Text = Strings.ItemContextMenu.Use.ToString(descriptor.Name); + break; - private int mMouseY = -1; + case ItemType.Bag: + _contextMenu.AddChild(_useItemMenuItem); + _useItemMenuItem.Text = Strings.ItemContextMenu.Open.ToString(descriptor.Name); + break; - //Slot info - private int mMySlot; + case ItemType.Equipment: + _contextMenu.AddChild(_useItemMenuItem); + var equipItemLabel = Globals.Me.MyEquipment.Contains(_mySlot) ? Strings.ItemContextMenu.Unequip : Strings.ItemContextMenu.Equip; + _useItemMenuItem.Text = equipItemLabel.ToString(descriptor.Name); + break; + } - private string mTexLoaded = string.Empty; + // Set up the correct contextual additional action. + if (Globals.InBag && descriptor.CanBag) + { + _contextMenu.AddChild(_actionItemMenuItem); + _actionItemMenuItem.SetText(Strings.ItemContextMenu.Bag.ToString(descriptor.Name)); + } + else if (Globals.InBank && (descriptor.CanBank || descriptor.CanGuildBank)) + { + _contextMenu.AddChild(_actionItemMenuItem); + _actionItemMenuItem.SetText(Strings.ItemContextMenu.Bank.ToString(descriptor.Name)); + } + else if (Globals.InTrade && descriptor.CanTrade) + { + _contextMenu.AddChild(_actionItemMenuItem); + _actionItemMenuItem.SetText(Strings.ItemContextMenu.Trade.ToString(descriptor.Name)); + } + else if (Globals.GameShop != null && descriptor.CanSell) + { + _contextMenu.AddChild(_actionItemMenuItem); + _actionItemMenuItem.SetText(Strings.ItemContextMenu.Sell.ToString(descriptor.Name)); + } + + // Can we drop this item? if so show the user! + if (descriptor.CanDrop) + { + _contextMenu.AddChild(_dropItemMenuItem); + _dropItemMenuItem.SetText(Strings.ItemContextMenu.Drop.ToString(descriptor.Name)); + } + + // Display our menu... If we have anything to display. + if (_contextMenu.Children.Count > 0) + { + _contextMenu.Open(Pos.None); + } + } - public ImagePanel Pnl; + private void _useItemContextItem_Clicked(Base sender, MouseButtonState arguments) + { + Globals.Me?.TryUseItem(_mySlot); + } - public InventoryItem(InventoryWindow inventoryWindow, int index) + private void _actionItemContextItem_Clicked(Base sender, MouseButtonState arguments) { - mInventoryWindow = inventoryWindow; - mMySlot = index; + if (Globals.GameShop != null) + { + Globals.Me?.TrySellItem(_mySlot); + } + else if (Globals.InBank) + { + Globals.Me?.TryStoreItemInBank(_mySlot); + } + else if (Globals.InBag) + { + Globals.Me?.TryStoreItemInBag(_mySlot, -1); + } + else if (Globals.InTrade) + { + Globals.Me?.TryOfferItemToTrade(_mySlot); + } } - public void Setup() + private void _dropItemContextItem_Clicked(Base sender, Framework.Gwen.Control.EventArguments.MouseButtonState arguments) { - Pnl = new ImagePanel(Container, "InventoryItemIcon"); - Pnl.HoverEnter += pnl_HoverEnter; - Pnl.HoverLeave += pnl_HoverLeave; - Pnl.Clicked += pnl_Clicked; - Pnl.DoubleClicked += Pnl_DoubleClicked; - EquipPanel = new ImagePanel(Pnl, "InventoryItemEquippedIcon"); - EquipPanel.Texture = Graphics.Renderer.WhitePixel; - EquipLabel = new Label(Pnl, "InventoryItemEquippedLabel"); - EquipLabel.IsHidden = true; - EquipLabel.Text = Strings.Inventory.EquippedSymbol; - EquipLabel.TextColor = new Color(0, 255, 255, 255); - mCooldownLabel = new Label(Pnl, "InventoryItemCooldownLabel"); - mCooldownLabel.IsHidden = true; - mCooldownLabel.TextColor = new Color(0, 255, 255, 255); + Globals.Me?.TryDropItem(_mySlot); } - private void Pnl_DoubleClicked(Base sender, MouseButtonState arguments) + #endregion + + #region Mouse Events + + private void _iconImage_DoubleClicked(Base sender, MouseButtonState arguments) { + if (Globals.Me == default) + { + return; + } + if (Globals.GameShop != null) { - Globals.Me.TrySellItem(mMySlot); + Globals.Me.TrySellItem(_mySlot); } else if (Globals.InBank) { - if (Globals.InputManager.IsKeyDown(Keys.Shift)) + if (Globals.InputManager.IsKeyDown(Framework.GenericClasses.Keys.Shift)) { Globals.Me.TryStoreItemInBank( - mMySlot, + _mySlot, skipPrompt: true ); } else { - var slot = Globals.Me.Inventory[mMySlot]; + var slot = Globals.Me.Inventory[_mySlot]; Globals.Me.TryStoreItemInBank( - mMySlot, + _mySlot, slot, quantityHint: slot.Quantity, skipPrompt: false @@ -116,126 +283,133 @@ private void Pnl_DoubleClicked(Base sender, MouseButtonState arguments) } else if (Globals.InBag) { - Globals.Me.TryStoreItemInBag(mMySlot, -1); + Globals.Me.TryStoreItemInBag(_mySlot, -1); } else if (Globals.InTrade) { - Globals.Me.TryOfferItemToTrade(mMySlot); + Globals.Me.TryOfferItemToTrade(_mySlot); } else { - Globals.Me.TryUseItem(mMySlot); + Globals.Me.TryUseItem(_mySlot); } } - void pnl_Clicked(Base sender, MouseButtonState arguments) + private void _iconImage_Clicked(Base sender, MouseButtonState arguments) { switch (arguments.MouseButton) { case MouseButton.Left: - mClickTime = Timing.Global.MillisecondsUtc + 500; + _clickTime = Timing.Global.MillisecondsUtc + 500; break; case MouseButton.Right: if (ClientConfiguration.Instance.EnableContextMenus) { - mInventoryWindow.OpenContextMenu(mMySlot); + OpenContextMenu(); } else { if (Globals.GameShop != null) { - Globals.Me?.TrySellItem(mMySlot); + Globals.Me?.TrySellItem(_mySlot); } else if (Globals.InBank) { - Globals.Me?.TryStoreItemInBank(mMySlot); + Globals.Me?.TryStoreItemInBank(_mySlot); } else if (Globals.InBag) { - Globals.Me?.TryStoreItemInBag(mMySlot, -1); + Globals.Me?.TryStoreItemInBag(_mySlot, -1); } else if (Globals.InTrade) { - Globals.Me?.TryOfferItemToTrade(mMySlot); + Globals.Me?.TryOfferItemToTrade(_mySlot); } else { - Globals.Me?.TryDropItem(mMySlot); + Globals.Me?.TryDropItem(_mySlot); } } break; } } - void pnl_HoverLeave(Base sender, EventArgs arguments) + private void _iconImage_HoverLeave(Base sender, EventArgs arguments) { - mMouseOver = false; - mMouseX = -1; - mMouseY = -1; - if (mDescWindow != null) + _mouseOver = false; + _mouseX = -1; + _mouseY = -1; + + if (_descWindow != null) { - mDescWindow.Dispose(); - mDescWindow = null; + _descWindow.Dispose(); + _descWindow = null; } } - void pnl_HoverEnter(Base sender, EventArgs arguments) + void _iconImage_HoverEnter(Base? sender, EventArgs? arguments) { if (InputHandler.MouseFocus != null) { return; } - mMouseOver = true; - mCanDrag = true; + _mouseOver = true; + _canDrag = true; + if (Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - mCanDrag = false; - + _canDrag = false; return; } - if (mDescWindow != null) + if (_descWindow != null) + { + _descWindow.Dispose(); + _descWindow = null; + } + + if (Globals.Me?.Inventory[_mySlot] is not { } inventorySlot) { - mDescWindow.Dispose(); - mDescWindow = null; + return; } if (Globals.GameShop == null) { - if (Globals.Me.Inventory[mMySlot]?.Descriptor != null) + if (inventorySlot.Descriptor != null) { - mDescWindow = new ItemDescriptionWindow( - Globals.Me.Inventory[mMySlot].Descriptor, Globals.Me.Inventory[mMySlot].Quantity, mInventoryWindow.X, - mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].ItemProperties + _descWindow = new ItemDescriptionWindow( + inventorySlot.Descriptor, inventorySlot.Quantity, _inventoryWindow.X, + _inventoryWindow.Y, inventorySlot.ItemProperties ); } } else { - var invItem = Globals.Me.Inventory[mMySlot]; - ShopItem shopItem = null; + ShopItem? shopItem = default; for (var i = 0; i < Globals.GameShop.BuyingItems.Count; i++) { var tmpShop = Globals.GameShop.BuyingItems[i]; - - if (invItem.ItemId == tmpShop.ItemId) + if (inventorySlot.ItemId == tmpShop.ItemId) { shopItem = tmpShop; - break; } } - if (Globals.GameShop.BuyingWhitelist && shopItem != null) + if (Globals.GameShop.BuyingWhitelist && shopItem != default) { - var hoveredItem = ItemDescriptor.Get(shopItem.CostItemId); - if (hoveredItem != null && Globals.Me.Inventory[mMySlot]?.Descriptor != null) + if (!ItemDescriptor.TryGet(shopItem.CostItemId, out var hoveredItem)) + { + return; + } + + if (inventorySlot.Descriptor != null) { - mDescWindow = new ItemDescriptionWindow( - Globals.Me.Inventory[mMySlot].Descriptor, Globals.Me.Inventory[mMySlot].Quantity, - mInventoryWindow.X, mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].ItemProperties, "", + _descWindow = new ItemDescriptionWindow( + inventorySlot.Descriptor, inventorySlot.Quantity, + _inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties, "", Strings.Shop.SellsFor.ToString(shopItem.CostItemQuantity, hoveredItem.Name) ); } @@ -243,21 +417,21 @@ void pnl_HoverEnter(Base sender, EventArgs arguments) else if (shopItem == null) { var costItem = Globals.GameShop.DefaultCurrency; - if (invItem.Descriptor != null && costItem != null && Globals.Me.Inventory[mMySlot]?.Descriptor != null) + if (inventorySlot.Descriptor != null && costItem != null) { - mDescWindow = new ItemDescriptionWindow( - Globals.Me.Inventory[mMySlot].Descriptor, Globals.Me.Inventory[mMySlot].Quantity, - mInventoryWindow.X, mInventoryWindow.Y, Globals.Me.Inventory[mMySlot].ItemProperties, "", - Strings.Shop.SellsFor.ToString(invItem.Descriptor.Price.ToString(), costItem.Name) + _descWindow = new ItemDescriptionWindow( + inventorySlot.Descriptor, inventorySlot.Quantity, + _inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties, "", + Strings.Shop.SellsFor.ToString(inventorySlot.Descriptor.Price.ToString(), costItem.Name) ); } } else { - if (invItem?.Descriptor != null) + if (inventorySlot.Descriptor != null) { - mDescWindow = new ItemDescriptionWindow( - invItem.Descriptor, invItem.Quantity, mInventoryWindow.X, mInventoryWindow.Y, invItem.ItemProperties, + _descWindow = new ItemDescriptionWindow( + inventorySlot.Descriptor, inventorySlot.Quantity, _inventoryWindow.X, _inventoryWindow.Y, inventorySlot.ItemProperties, "", Strings.Shop.WontBuy ); } @@ -265,14 +439,37 @@ void pnl_HoverEnter(Base sender, EventArgs arguments) } } + #endregion + + private void PlayerOnInventoryUpdated(Player player, int slotIndex) + { + if (player != Globals.Me) + { + return; + } + + if (slotIndex != _mySlot) + { + return; + } + + if (Globals.Me.Inventory[_mySlot] is not { } inventorySlot) + { + return; + } + + // empty texture to reload on update + _textureLoaded = string.Empty; + } + public FloatRect RenderBounds() { var rect = new FloatRect() { - X = Pnl.ToCanvas(new Point(0, 0)).X, - Y = Pnl.ToCanvas(new Point(0, 0)).Y, - Width = Pnl.Width, - Height = Pnl.Height + X = _iconImage.ToCanvas(new Point(0, 0)).X, + Y = _iconImage.ToCanvas(new Point(0, 0)).Y, + Width = _iconImage.Width, + Height = _iconImage.Height }; return rect; @@ -280,119 +477,114 @@ public FloatRect RenderBounds() public void Update() { - var equipped = false; - for (var i = 0; i < Options.Instance.Equipment.Slots.Count; i++) + if (Globals.Me == default) { - if (Globals.Me.MyEquipment[i] == mMySlot) - { - equipped = true; + return; + } - break; - } + if (Globals.Me.Inventory[_mySlot] is not { } inventorySlot) + { + return; } - var item = ItemDescriptor.Get(Globals.Me.Inventory[mMySlot].ItemId); - if (Globals.Me.Inventory[mMySlot].ItemId != mCurrentItemId || - Globals.Me.Inventory[mMySlot].Quantity != mCurrentAmt || - equipped != mIsEquipped || - item == null && mTexLoaded != "" || - item != null && mTexLoaded != item.Icon || - mIconCd != Globals.Me.IsItemOnCooldown(mMySlot) || - Globals.Me.IsItemOnCooldown(mMySlot)) - { - mCurrentItemId = Globals.Me.Inventory[mMySlot].ItemId; - mCurrentAmt = Globals.Me.Inventory[mMySlot].Quantity; - mIsEquipped = equipped; - EquipPanel.IsHidden = !mIsEquipped; - EquipLabel.IsHidden = !mIsEquipped; - mCooldownLabel.IsHidden = true; - if (item != null) - { - var itemTex = Globals.ContentManager.GetTexture(Framework.Content.TextureType.Item, item.Icon); - if (itemTex != null) - { - Pnl.Texture = itemTex; - if (Globals.Me.IsItemOnCooldown(mMySlot)) - { - Pnl.RenderColor = new Color(100, item.Color.R, item.Color.G, item.Color.B); - } - else - { - Pnl.RenderColor = item.Color; - } - } - else - { - if (Pnl.Texture != null) - { - Pnl.Texture = null; - } - } + if (!ItemDescriptor.TryGet(inventorySlot.ItemId, out var descriptor)) + { + _reset(); + return; + } - mTexLoaded = item.Icon; - mIconCd = Globals.Me.IsItemOnCooldown(mMySlot); - if (mIconCd) - { - var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(mMySlot); - mCooldownLabel.IsHidden = false; - mCooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); - } + var equipped = Globals.Me.MyEquipment.Any(s => s == _mySlot); + _equipImageBackground.IsVisibleInParent = !IsDragging && equipped; + _equipLabel.IsVisibleInParent = !IsDragging && equipped; + + _quantityLabel.IsVisibleInParent = !IsDragging && descriptor.IsStackable && inventorySlot.Quantity > 1; + if (_quantityLabel.IsVisibleInParent) + { + _quantityLabel.Text = FormatQuantityAbbreviated(inventorySlot.Quantity); + } + + _cooldownLabel.IsVisibleInParent = !IsDragging && Globals.Me.IsItemOnCooldown(_mySlot); + if (_cooldownLabel.IsVisibleInParent) + { + var itemCooldownRemaining = Globals.Me.GetItemRemainingCooldown(_mySlot); + _cooldownLabel.Text = TimeSpan.FromMilliseconds(itemCooldownRemaining).WithSuffix("0.0"); + _iconImage.RenderColor.A = 100; + } + else + { + _iconImage.RenderColor.A = descriptor.Color.A; + } + + if (_textureLoaded != descriptor.Icon) + { + var itemTex = Globals.ContentManager?.GetTexture(Framework.Content.TextureType.Item, descriptor.Icon); + if (itemTex != null) + { + _iconImage.Texture = itemTex; + _iconImage.RenderColor = Globals.Me.IsItemOnCooldown(_mySlot) + ? new Color(100, descriptor.Color.R, descriptor.Color.G, descriptor.Color.B) + : descriptor.Color; + _iconImage.IsVisibleInParent = true; } else { - if (Pnl.Texture != null) + if (_iconImage.Texture != null) { - Pnl.Texture = null; + _iconImage.Texture = null; + _iconImage.IsVisibleInParent = false; } - - mTexLoaded = string.Empty; } - if (mDescWindow != null) + _textureLoaded = descriptor.Icon; + + if (_descWindow != null) { - mDescWindow.Dispose(); - mDescWindow = null; - pnl_HoverEnter(null, null); + _descWindow.Dispose(); + _descWindow = null; + _iconImage_HoverEnter(null, null); } } if (!IsDragging) { - if (mMouseOver) + if (_mouseOver) { if (!Globals.InputManager.IsMouseButtonDown(MouseButton.Left)) { - mCanDrag = true; - mMouseX = -1; - mMouseY = -1; - if (Timing.Global.MillisecondsUtc < mClickTime) + _canDrag = true; + _mouseX = -1; + _mouseY = -1; + + if (Timing.Global.MillisecondsUtc < _clickTime) { - mClickTime = 0; + _clickTime = 0; } } else { - if (mCanDrag && Draggable.Active == null) + if (_canDrag && Draggable.Active == null) { - if (mMouseX == -1 || mMouseY == -1) + if (_mouseX == -1 || _mouseY == -1) { - mMouseX = InputHandler.MousePosition.X - Pnl.ToCanvas(new Point(0, 0)).X; - mMouseY = InputHandler.MousePosition.Y - Pnl.ToCanvas(new Point(0, 0)).Y; + _mouseX = InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X; + _mouseY = InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y; } else { - var xdiff = mMouseX - - (InputHandler.MousePosition.X - Pnl.ToCanvas(new Point(0, 0)).X); + var xdiff = _mouseX - + (InputHandler.MousePosition.X - _iconImage.ToCanvas(new Point(0, 0)).X); - var ydiff = mMouseY - - (InputHandler.MousePosition.Y - Pnl.ToCanvas(new Point(0, 0)).Y); + var ydiff = _mouseY - + (InputHandler.MousePosition.Y - _iconImage.ToCanvas(new Point(0, 0)).Y); if (Math.Sqrt(Math.Pow(xdiff, 2) + Math.Pow(ydiff, 2)) > 5) { IsDragging = true; - mDragIcon = new Draggable( - Pnl.ToCanvas(new Point(0, 0)).X + mMouseX, - Pnl.ToCanvas(new Point(0, 0)).X + mMouseY, Pnl.Texture, Pnl.RenderColor + _iconImage.IsVisibleInParent = false; + + _dragIcon = new Draggable( + _iconImage.ToCanvas(new Point(0, 0)).X + _mouseX, + _iconImage.ToCanvas(new Point(0, 0)).X + _mouseY, _iconImage.Texture, _iconImage.RenderColor ); } } @@ -400,16 +592,17 @@ public void Update() } } } - else if (mDragIcon.Update()) + else if (_dragIcon?.Update() == true) { //Drug the item and now we stopped IsDragging = false; + _iconImage.IsVisibleInParent = true; var dragRect = new FloatRect( - mDragIcon.X - (Container.Padding.Left + Container.Padding.Right) / 2f, - mDragIcon.Y - (Container.Padding.Top + Container.Padding.Bottom) / 2f, - (Container.Padding.Left + Container.Padding.Right) / 2f + Pnl.Width, - (Container.Padding.Top + Container.Padding.Bottom) / 2f + Pnl.Height + _dragIcon.X - (Padding.Left + Padding.Right) / 2f, + _dragIcon.Y - (Padding.Top + Padding.Bottom) / 2f, + (Padding.Left + Padding.Right) / 2f + _iconImage.Width, + (Padding.Top + Padding.Bottom) / 2f + _iconImage.Height ); float bestIntersect = 0; @@ -417,9 +610,9 @@ public void Update() //So we picked up an item and then dropped it. Lets see where we dropped it to. //Check inventory first. - if (mInventoryWindow.RenderBounds().IntersectsWith(dragRect)) + if (_inventoryWindow.RenderBounds().IntersectsWith(dragRect)) { - var inventorySlotComponents = mInventoryWindow.Items.ToArray(); + var inventorySlotComponents = _inventoryWindow.Items.ToArray(); var inventorySlotLimit = Math.Min(Options.Instance.Player.MaxInventory, inventorySlotComponents.Length); for (var inventoryIndex = 0; inventoryIndex < inventorySlotLimit; inventoryIndex++) { @@ -443,9 +636,9 @@ public void Update() if (bestIntersectIndex > -1) { - if (mMySlot != bestIntersectIndex) + if (_mySlot != bestIntersectIndex) { - Globals.Me.SwapItems(mMySlot, bestIntersectIndex); + Globals.Me.SwapItems(_mySlot, bestIntersectIndex); } } } @@ -477,7 +670,7 @@ public void Update() if (bestIntersectIndex > -1) { - Globals.Me.AddToHotbar((byte)bestIntersectIndex, 0, mMySlot); + Globals.Me.AddToHotbar((byte)bestIntersectIndex, 0, _mySlot); } } else if (Globals.InBag) @@ -508,7 +701,7 @@ public void Update() if (bestIntersectIndex > -1) { - Globals.Me.TryStoreItemInBag(mMySlot, bestIntersectIndex); + Globals.Me.TryStoreItemInBag(_mySlot, bestIntersectIndex); } } } @@ -544,9 +737,9 @@ public void Update() if (bestIntersectIndex > -1) { - var slot = Globals.Me.Inventory[mMySlot]; + var slot = Globals.Me.Inventory[_mySlot]; Globals.Me.TryStoreItemInBank( - mMySlot, + _mySlot, bankSlotIndex: bestIntersectIndex, quantityHint: slot.Quantity, skipPrompt: true @@ -556,11 +749,38 @@ public void Update() } else if (!Globals.Me.IsBusy) { - PacketSender.SendDropItem(mMySlot, Globals.Me.Inventory[mMySlot].Quantity); + PacketSender.SendDropItem(_mySlot, Globals.Me.Inventory[_mySlot].Quantity); } - mDragIcon.Dispose(); + _dragIcon.Dispose(); + } + } + + private void _reset() + { + _iconImage.IsVisibleInParent = false; + _equipImageBackground.IsVisibleInParent = false; + _quantityLabel.IsVisibleInParent = false; + _equipLabel.IsVisibleInParent = false; + _cooldownLabel.IsVisibleInParent = false; + _textureLoaded = string.Empty; + + if (_dragIcon != default) + { + _dragIcon.Dispose(); + _dragIcon = default; + } + + if (_descWindow != default) + { + _descWindow.Dispose(); + _descWindow = default; } } + protected override void Dispose(bool disposing) + { + _contextMenu?.Close(); + base.Dispose(disposing); + } } diff --git a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs index 585a4ed866..793e7329e4 100644 --- a/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs +++ b/Intersect.Client.Core/Interface/Game/Inventory/InventoryWindow.cs @@ -1,209 +1,62 @@ -using Intersect.Client.Core; +using Intersect.Client.Core; using Intersect.Client.Framework.File_Management; using Intersect.Client.Framework.GenericClasses; +using Intersect.Client.Framework.Gwen; using Intersect.Client.Framework.Gwen.Control; using Intersect.Client.General; using Intersect.Client.Localization; -using Intersect.Core; -using Intersect.Framework.Core.GameObjects.Items; -using Intersect.GameObjects; -using Microsoft.Extensions.Logging; namespace Intersect.Client.Interface.Game.Inventory; - -public partial class InventoryWindow +public partial class InventoryWindow : Window { + public List Items { get; set; } = []; - //Item List - public List Items = new List(); - - //Initialized Items? - private bool mInitializedItems = false; - - //Controls - private WindowControl mInventoryWindow; - - private ScrollControl mItemContainer; - - private List