Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hotbar window/item inherances #2661

Merged
merged 4 commits into from
Mar 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Intersect.Client.Core/Interface/Game/Bag/BagItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ public partial class BagItem : SlotItem
// Context Menu Handling
private readonly MenuItem _withdrawContextItem;

public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextMenu) : base(parent, nameof(BagItem), index, contextMenu)
public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextMenu)
: base(parent, nameof(BagItem), index, contextMenu)
{
_bagWindow = bagWindow;
TextureFilename = "bagitem.png";
Expand All @@ -60,15 +61,15 @@ public BagItem(BagWindow bagWindow, Base parent, int index, ContextMenu contextM

LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

_contextMenu.ClearChildren();
_withdrawContextItem = _contextMenu.AddItem(Strings.BagContextMenu.Withdraw);
contextMenu.ClearChildren();
_withdrawContextItem = contextMenu.AddItem(Strings.BagContextMenu.Withdraw);
_withdrawContextItem.Clicked += _withdrawMenuItem_Clicked;
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
}

#region Context Menu

public override void OpenContextMenu()
protected override void OnContextMenuOpening(ContextMenu contextMenu)
{
if (Globals.BagSlots is not { Length: > 0 } bagSlots)
{
Expand All @@ -81,10 +82,10 @@ public override void OpenContextMenu()
}

// Clear the context menu and add the withdraw item with updated item name
_contextMenu.ClearChildren();
contextMenu.ClearChildren();
_withdrawContextItem.SetText(Strings.BagContextMenu.Withdraw.ToString(item.Name));
_contextMenu.AddChild(_withdrawContextItem);
base.OpenContextMenu();
contextMenu.AddChild(_withdrawContextItem);
base.OnContextMenuOpening(contextMenu);
}

private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments)
Expand Down
14 changes: 7 additions & 7 deletions Intersect.Client.Core/Interface/Game/Bank/BankItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte

LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());

_contextMenu.ClearChildren();
_withdrawContextItem = _contextMenu.AddItem(Strings.BankContextMenu.Withdraw);
contextMenu.ClearChildren();
_withdrawContextItem = contextMenu.AddItem(Strings.BankContextMenu.Withdraw);
_withdrawContextItem.Clicked += _withdrawMenuItem_Clicked;
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
}

public void OpenContextMenu()
protected override void OnContextMenuOpening(ContextMenu contextMenu)
{
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
{
Expand All @@ -82,11 +82,11 @@ public void OpenContextMenu()
}

// Clear the context menu and add the withdraw item with updated item name
_contextMenu.ClearChildren();
contextMenu.ClearChildren();
contextMenu.AddChild(_withdrawContextItem);
_withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name));
_contextMenu.AddChild(_withdrawContextItem);

base.OpenContextMenu();
base.OnContextMenuOpening(contextMenu);
}

private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments)
Expand Down
79 changes: 0 additions & 79 deletions Intersect.Client.Core/Interface/Game/Hotbar/HotBar.cs

This file was deleted.

65 changes: 65 additions & 0 deletions Intersect.Client.Core/Interface/Game/Hotbar/HotBarWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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;

namespace Intersect.Client.Interface.Game.Hotbar;

public partial class HotBarWindow : ImagePanel
{
public readonly List<HotbarItem> Items = [];

public HotBarWindow(Canvas gameCanvas) : base(gameCanvas, nameof(HotBarWindow))
{
AlignmentPadding = new Padding { Top = 4, Right = 4 };
Alignment = [Alignments.Top, Alignments.Right];
RestrictToParent = true;
TextureFilename = "hotbar.png";
TextureNinePatchMargin = Margin.Three;
ShouldCacheToTexture = true;

if (Graphics.Renderer == null)
{
return;
}

var hotbarSlotCount = Options.Instance.Player.HotbarSlotCount;
for (var hotbarSlotIndex = 0; hotbarSlotIndex < hotbarSlotCount; hotbarSlotIndex++)
{
var hotbarItem = new HotbarItem(hotbarSlotIndex, this);
Items.Add(hotbarItem);
}

SizeToChildren();
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
SizeToChildren();
}

public void Update()
{
if (Globals.Me == null)
{
return;
}

foreach (var slot in Items)
{
slot.Update();
}
}

public FloatRect RenderBounds()
{
var rect = new FloatRect
{
X = ToCanvas(default).X,
Y = ToCanvas(default).Y,
Width = Width,
Height = Height,
};

return rect;
}
}
Loading
Loading