Skip to content

Commit c44b05b

Browse files
hotbar window/item inherances (#2661)
* rename hotbar window file * refactor hotbar window/item * make explicit context menu as possible null (bcuz hotbar) and not null where it exists * refactor open context menu in slot item
1 parent 3ae10e9 commit c44b05b

File tree

9 files changed

+188
-200
lines changed

9 files changed

+188
-200
lines changed

Intersect.Client.Core/Interface/Game/Bag/BagItem.cs

+9-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public partial class BagItem : SlotItem
3939
// Context Menu Handling
4040
private readonly MenuItem _withdrawContextItem;
4141

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

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

63-
_contextMenu.ClearChildren();
64-
_withdrawContextItem = _contextMenu.AddItem(Strings.BagContextMenu.Withdraw);
64+
contextMenu.ClearChildren();
65+
_withdrawContextItem = contextMenu.AddItem(Strings.BagContextMenu.Withdraw);
6566
_withdrawContextItem.Clicked += _withdrawMenuItem_Clicked;
66-
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
67+
contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
6768
}
6869

6970
#region Context Menu
7071

71-
public override void OpenContextMenu()
72+
protected override void OnContextMenuOpening(ContextMenu contextMenu)
7273
{
7374
if (Globals.BagSlots is not { Length: > 0 } bagSlots)
7475
{
@@ -81,10 +82,10 @@ public override void OpenContextMenu()
8182
}
8283

8384
// Clear the context menu and add the withdraw item with updated item name
84-
_contextMenu.ClearChildren();
85+
contextMenu.ClearChildren();
8586
_withdrawContextItem.SetText(Strings.BagContextMenu.Withdraw.ToString(item.Name));
86-
_contextMenu.AddChild(_withdrawContextItem);
87-
base.OpenContextMenu();
87+
contextMenu.AddChild(_withdrawContextItem);
88+
base.OnContextMenuOpening(contextMenu);
8889
}
8990

9091
private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments)

Intersect.Client.Core/Interface/Game/Bank/BankItem.cs

+7-7
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ public BankItem(BankWindow bankWindow, Base parent, int index, ContextMenu conte
6363

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

66-
_contextMenu.ClearChildren();
67-
_withdrawContextItem = _contextMenu.AddItem(Strings.BankContextMenu.Withdraw);
66+
contextMenu.ClearChildren();
67+
_withdrawContextItem = contextMenu.AddItem(Strings.BankContextMenu.Withdraw);
6868
_withdrawContextItem.Clicked += _withdrawMenuItem_Clicked;
69-
_contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
69+
contextMenu.LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
7070
}
7171

72-
public void OpenContextMenu()
72+
protected override void OnContextMenuOpening(ContextMenu contextMenu)
7373
{
7474
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
7575
{
@@ -82,11 +82,11 @@ public void OpenContextMenu()
8282
}
8383

8484
// Clear the context menu and add the withdraw item with updated item name
85-
_contextMenu.ClearChildren();
85+
contextMenu.ClearChildren();
86+
contextMenu.AddChild(_withdrawContextItem);
8687
_withdrawContextItem.SetText(Strings.BankContextMenu.Withdraw.ToString(item.Name));
87-
_contextMenu.AddChild(_withdrawContextItem);
8888

89-
base.OpenContextMenu();
89+
base.OnContextMenuOpening(contextMenu);
9090
}
9191

9292
private void _withdrawMenuItem_Clicked(Base sender, MouseButtonState arguments)

Intersect.Client.Core/Interface/Game/Hotbar/HotBar.cs

-79
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using Intersect.Client.Core;
2+
using Intersect.Client.Framework.File_Management;
3+
using Intersect.Client.Framework.GenericClasses;
4+
using Intersect.Client.Framework.Gwen;
5+
using Intersect.Client.Framework.Gwen.Control;
6+
using Intersect.Client.General;
7+
8+
namespace Intersect.Client.Interface.Game.Hotbar;
9+
10+
public partial class HotBarWindow : ImagePanel
11+
{
12+
public readonly List<HotbarItem> Items = [];
13+
14+
public HotBarWindow(Canvas gameCanvas) : base(gameCanvas, nameof(HotBarWindow))
15+
{
16+
AlignmentPadding = new Padding { Top = 4, Right = 4 };
17+
Alignment = [Alignments.Top, Alignments.Right];
18+
RestrictToParent = true;
19+
TextureFilename = "hotbar.png";
20+
TextureNinePatchMargin = Margin.Three;
21+
ShouldCacheToTexture = true;
22+
23+
if (Graphics.Renderer == null)
24+
{
25+
return;
26+
}
27+
28+
var hotbarSlotCount = Options.Instance.Player.HotbarSlotCount;
29+
for (var hotbarSlotIndex = 0; hotbarSlotIndex < hotbarSlotCount; hotbarSlotIndex++)
30+
{
31+
var hotbarItem = new HotbarItem(hotbarSlotIndex, this);
32+
Items.Add(hotbarItem);
33+
}
34+
35+
SizeToChildren();
36+
LoadJsonUi(GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
37+
SizeToChildren();
38+
}
39+
40+
public void Update()
41+
{
42+
if (Globals.Me == null)
43+
{
44+
return;
45+
}
46+
47+
foreach (var slot in Items)
48+
{
49+
slot.Update();
50+
}
51+
}
52+
53+
public FloatRect RenderBounds()
54+
{
55+
var rect = new FloatRect
56+
{
57+
X = ToCanvas(default).X,
58+
Y = ToCanvas(default).Y,
59+
Width = Width,
60+
Height = Height,
61+
};
62+
63+
return rect;
64+
}
65+
}

0 commit comments

Comments
 (0)