Skip to content

Commit bff066a

Browse files
fix 2559 (#2700)
* started refactor descriptions windows * put descriptions windows on game on start * update places to new pattern * a looot better perfomace than before * better avoid null exceptions * fixed crash on gui destroy (like change resolution, logout, etc) * fix crash because TargetBox is trying to hidden a control after gameUi was disposed
1 parent da1ae0d commit bff066a

24 files changed

+524
-750
lines changed

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

+2-17
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
using Intersect.Client.Framework.Gwen.Input;
88
using Intersect.Client.Framework.Input;
99
using Intersect.Client.General;
10-
using Intersect.Client.Interface.Game.DescriptionWindows;
1110
using Intersect.Client.Interface.Game.Inventory;
1211
using Intersect.Client.Localization;
1312
using Intersect.Client.Networking;
@@ -21,7 +20,6 @@ public partial class BagItem : SlotItem
2120
// Controls
2221
private readonly Label _quantityLabel;
2322
private readonly BagWindow _bagWindow;
24-
private ItemDescriptionWindow? _descriptionWindow;
2523

2624
// Context Menu Handling
2725
private readonly MenuItem _withdrawContextItem;
@@ -99,9 +97,6 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments)
9997
return;
10098
}
10199

102-
_descriptionWindow?.Dispose();
103-
_descriptionWindow = default;
104-
105100
if (Globals.BagSlots is not { Length: > 0 } bagSlots)
106101
{
107102
return;
@@ -113,19 +108,12 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments)
113108
}
114109

115110
var item = bagSlots[SlotIndex];
116-
_descriptionWindow = new ItemDescriptionWindow(
117-
item.Descriptor,
118-
item.Quantity,
119-
_bagWindow.X,
120-
_bagWindow.Y,
121-
item.ItemProperties
122-
);
111+
Interface.GameUi.ItemDescriptionWindow?.Show(item.Descriptor, item.Quantity, item.ItemProperties);
123112
}
124113

125114
private void Icon_HoverLeave(Base sender, EventArgs arguments)
126115
{
127-
_descriptionWindow?.Dispose();
128-
_descriptionWindow = default;
116+
Interface.GameUi.ItemDescriptionWindow?.Hide();
129117
}
130118

131119
private void Icon_Clicked(Base sender, MouseButtonState arguments)
@@ -232,8 +220,5 @@ public override void Update()
232220
Icon.IsVisibleInParent = false;
233221
}
234222
}
235-
236-
_descriptionWindow?.Dispose();
237-
_descriptionWindow = default;
238223
}
239224
}

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

+2-18
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
using Intersect.Client.Framework.Input;
1010
using Intersect.Client.General;
1111
using Intersect.Client.Interface.Game.Chat;
12-
using Intersect.Client.Interface.Game.DescriptionWindows;
1312
using Intersect.Client.Interface.Game.Inventory;
1413
using Intersect.Client.Localization;
1514
using Intersect.Client.Networking;
@@ -24,7 +23,6 @@ public partial class BankItem : SlotItem
2423
// Controls
2524
private readonly Label _quantityLabel;
2625
private BankWindow _bankWindow;
27-
private ItemDescriptionWindow? _descriptionWindow;
2826

2927
// Context Menu Handling
3028
private MenuItem _withdrawContextItem;
@@ -100,10 +98,6 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments)
10098
return;
10199
}
102100

103-
104-
_descriptionWindow?.Dispose();
105-
_descriptionWindow = null;
106-
107101
if (Globals.BankSlots is not { Length: > 0 } bankSlots)
108102
{
109103
return;
@@ -115,19 +109,12 @@ private void Icon_HoverEnter(Base? sender, EventArgs? arguments)
115109
}
116110

117111
var item = bankSlots[SlotIndex];
118-
_descriptionWindow = new ItemDescriptionWindow(
119-
item.Descriptor,
120-
item.Quantity,
121-
_bankWindow.X,
122-
_bankWindow.Y,
123-
item.ItemProperties
124-
);
112+
Interface.GameUi.ItemDescriptionWindow?.Show(item.Descriptor, item.Quantity, item.ItemProperties);
125113
}
126114

127115
private void Icon_HoverLeave(Base sender, EventArgs arguments)
128116
{
129-
_descriptionWindow?.Dispose();
130-
_descriptionWindow = default;
117+
Interface.GameUi.ItemDescriptionWindow?.Hide();
131118
}
132119

133120
private void Icon_Clicked(Base sender, MouseButtonState arguments)
@@ -298,8 +285,5 @@ public override void Update()
298285
Icon.IsVisibleInParent = false;
299286
}
300287
}
301-
302-
_descriptionWindow?.Dispose();
303-
_descriptionWindow = default;
304288
}
305289
}

Intersect.Client.Core/Interface/Game/Character/EquipmentItem.cs

+2-19
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,20 @@
44
using Intersect.Client.Framework.Gwen.Input;
55
using Intersect.Client.Framework.Input;
66
using Intersect.Client.General;
7-
using Intersect.Client.Interface.Game.DescriptionWindows;
87
using Intersect.Client.Networking;
98
using Intersect.Configuration;
109
using Intersect.Framework.Core.GameObjects.Items;
11-
using Intersect.GameObjects;
12-
using Intersect.Network.Packets.Server;
1310

1411
namespace Intersect.Client.Interface.Game.Character;
1512

16-
1713
public partial class EquipmentItem
1814
{
19-
2015
public ImagePanel ContentPanel;
2116

2217
private WindowControl mCharacterWindow;
2318

2419
private Guid mCurrentItemId;
2520

26-
private ItemDescriptionWindow mDescWindow;
27-
2821
private ItemProperties mItemProperties = null;
2922

3023
private bool mTexLoaded;
@@ -78,11 +71,7 @@ void pnl_RightClicked(Base sender, MouseButtonState arguments)
7871

7972
void pnl_HoverLeave(Base sender, EventArgs arguments)
8073
{
81-
if (mDescWindow != null)
82-
{
83-
mDescWindow.Dispose();
84-
mDescWindow = null;
85-
}
74+
Interface.GameUi.ItemDescriptionWindow?.Hide();
8675
}
8776

8877
void pnl_HoverEnter(Base sender, EventArgs arguments)
@@ -97,19 +86,13 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
9786
return;
9887
}
9988

100-
if (mDescWindow != null)
101-
{
102-
mDescWindow.Dispose();
103-
mDescWindow = null;
104-
}
105-
10689
var item = ItemDescriptor.Get(mCurrentItemId);
10790
if (item == null)
10891
{
10992
return;
11093
}
11194

112-
mDescWindow = new ItemDescriptionWindow(item, 1, mCharacterWindow.X, mCharacterWindow.Y, mItemProperties, item.Name);
95+
Interface.GameUi.ItemDescriptionWindow?.Show(item, 1, mItemProperties);
11396
}
11497

11598
public FloatRect RenderBounds()

Intersect.Client.Core/Interface/Game/Crafting/CraftingWindow.cs

+2-5
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ private void LoadCraftRecipe(CraftingRecipeDescriptor craftDescriptor)
160160
RemoveChild(container, true);
161161
}
162162

163-
if (craftedItem.DescWindow is { } descriptionWindow)
164-
{
165-
descriptionWindow.Dispose();
166-
}
163+
Interface.GameUi.ItemDescriptionWindow?.Hide();
167164
}
168165

169166
var craftedItemDescriptorId = craftDescriptor.ItemId;
@@ -191,7 +188,7 @@ private void LoadCraftRecipe(CraftingRecipeDescriptor craftDescriptor)
191188
foreach (var recipeItem in mItems)
192189
{
193190
//Clear the old item description box
194-
recipeItem.DescWindow?.Dispose();
191+
Interface.GameUi.ItemDescriptionWindow?.Hide();
195192
if (recipeItem.Container is { } container)
196193
{
197194
mItemContainer.RemoveChild(container, true);

Intersect.Client.Core/Interface/Game/Crafting/RecipeItem.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using Intersect.Client.Framework.Gwen.Input;
33
using Intersect.Client.Framework.Input;
44
using Intersect.Client.General;
5-
using Intersect.Client.Interface.Game.DescriptionWindows;
65
using Intersect.Framework.Core.GameObjects.Crafting;
76
using Intersect.Framework.Core.GameObjects.Items;
87
using Intersect.GameObjects;
@@ -15,8 +14,6 @@ public partial class RecipeItem
1514

1615
public ImagePanel? Container;
1716

18-
public ItemDescriptionWindow? DescWindow;
19-
2017
public bool IsDragging;
2118

2219
//Dragging
@@ -86,11 +83,7 @@ void pnl_HoverLeave(Base sender, EventArgs arguments)
8683
mMouseOver = false;
8784
mMouseX = -1;
8885
mMouseY = -1;
89-
if (DescWindow != null)
90-
{
91-
DescWindow.Dispose();
92-
DescWindow = null;
93-
}
86+
Interface.GameUi.ItemDescriptionWindow?.Hide();
9487
}
9588

9689
void pnl_HoverEnter(Base sender, EventArgs arguments)
@@ -109,17 +102,9 @@ void pnl_HoverEnter(Base sender, EventArgs arguments)
109102
return;
110103
}
111104

112-
if (DescWindow != null)
113-
{
114-
DescWindow.Dispose();
115-
DescWindow = null;
116-
}
117-
118105
if (mIngredient != null && ItemDescriptor.TryGet(mIngredient.ItemId, out var itemDescriptor))
119106
{
120-
DescWindow = new ItemDescriptionWindow(
121-
itemDescriptor, mIngredient.Quantity, mCraftingWindow.X, mCraftingWindow.Y, null
122-
);
107+
Interface.GameUi.ItemDescriptionWindow?.Show(itemDescriptor, mIngredient.Quantity);
123108
}
124109
}
125110

Original file line numberDiff line numberDiff line change
@@ -1,115 +1,19 @@
1-
using Intersect.Client.Core;
21
using Intersect.Client.Framework.Gwen.Control;
32

43
namespace Intersect.Client.Interface.Game.DescriptionWindows.Components;
54

6-
public partial class ComponentBase : IDisposable
5+
public partial class ComponentBase(Base parent, string name = "") : ImagePanel(parent, name)
76
{
8-
protected Base mParent;
9-
10-
protected string mName;
11-
12-
protected ImagePanel mContainer;
13-
14-
public ComponentBase(Base parent, string name = "")
15-
{
16-
mParent = parent;
17-
mName = name;
18-
}
19-
20-
protected virtual void GenerateComponents()
21-
{
22-
mContainer = new ImagePanel(mParent, mName);
23-
}
24-
25-
/// <summary>
26-
/// The name of this control.
27-
/// </summary>
28-
public string Name { get { return mName; } }
29-
30-
/// <summary>
31-
/// The base container of this control.
32-
/// </summary>
33-
public ImagePanel Container => mContainer;
34-
357
/// <summary>
36-
/// Is this component current visible?
37-
/// </summary>
38-
public bool IsVisible => mContainer.IsVisibleInTree;
39-
40-
/// <summary>
41-
/// The current X location of the control.
42-
/// </summary>
43-
public int X => mContainer.X;
44-
45-
/// <summary>
46-
/// The current Y location of the control.
47-
/// </summary>
48-
public int Y => mContainer.Y;
49-
50-
/// <summary>
51-
/// The current width of the control.
52-
/// </summary>
53-
public int Width => mContainer.Width;
54-
55-
/// <summary>
56-
/// The current Height of the control.
57-
/// </summary>
58-
public int Height => mContainer.Height;
59-
60-
/// <summary>
61-
/// Hide the control.
62-
/// </summary>
63-
public void Hide() => mContainer.Hide();
64-
65-
/// <summary>
66-
/// Show the control.
67-
/// </summary>
68-
public void Show() => mContainer.Show();
69-
70-
/// <summary>
71-
/// Sets the control position.
72-
/// </summary>
73-
/// <param name="x">The X position to move the control to.</param>
74-
/// <param name="y">The Y position to move the control to.</param>
75-
/// <param name="itemDecriptionContainer">The container for the item description.</param>
76-
public virtual void SetPosition(int x, int y, ImagePanel? itemDecriptionContainer = null) => mContainer.SetPosition(x, y);
77-
78-
/// <summary>
79-
/// Sets the control position based on ImagePanel.
80-
/// </summary>
81-
public virtual void SetPosition(Base _icon, SpellDescriptionWindow _descriptionWindow) => mContainer.SetPosition(_icon);
82-
83-
/// <summary>
84-
/// Resizes the control to fit its children.
85-
/// </summary>
86-
/// <param name="width">Allow the control to resize its width.</param>
87-
/// <param name="height">Allow the control to resize its height.</param>
88-
public void SizeToChildren(bool width = true, bool height = true) => mContainer.SizeToChildren(width, height);
89-
90-
/// <summary>
91-
/// Dispose of the object.
8+
/// Corrects the width of the component compared to the parent size.
929
/// </summary>
93-
public virtual void Dispose()
10+
public virtual void CorrectWidth()
9411
{
95-
if(!mParent.Children.Contains(mContainer))
12+
if (Parent == default)
9613
{
9714
return;
9815
}
9916

100-
mParent.RemoveChild(mContainer, true);
101-
}
102-
103-
/// <summary>
104-
/// Load the Json layout of the current component.
105-
/// </summary>
106-
public void LoadLayout() => mContainer.LoadJsonUi(Framework.File_Management.GameContentManager.UI.InGame, Graphics.Renderer.GetResolutionString());
107-
108-
/// <summary>
109-
/// Corrects the width of the component compared to the parent size.
110-
/// </summary>
111-
public virtual void CorrectWidth()
112-
{
113-
mContainer.SetSize(mParent.InnerWidth, mContainer.InnerHeight);
17+
SetSize(Parent.InnerWidth, InnerHeight);
11418
}
11519
}

0 commit comments

Comments
 (0)