Use protected visual gump state

This commit is contained in:
Guflly 2026-08-08 00:01:49 -07:00
parent 43dc185e2e
commit 58a8a4725a
7 changed files with 25 additions and 11 deletions

View file

@ -6,6 +6,8 @@ public class DynamicTestGump : DynamicGump
{
private readonly string _petName;
public bool HasVisualElementsForTest => HasVisualElements;
public DynamicTestGump(string petName) : base(50, 50)
{
_petName = petName;

View file

@ -4,6 +4,8 @@ namespace Server.Tests.Gumps;
public sealed class EmptyLegacyTestGump : Gump
{
public bool HasVisualElementsForTest => HasVisualElements;
public EmptyLegacyTestGump() : base(0, 0)
{
}
@ -11,6 +13,8 @@ public sealed class EmptyLegacyTestGump : Gump
public sealed class EmptyDynamicTestGump : DynamicGump
{
public bool HasVisualElementsForTest => HasVisualElements;
public EmptyDynamicTestGump() : base(0, 0)
{
}
@ -23,6 +27,8 @@ public sealed class EmptyDynamicTestGump : DynamicGump
public sealed class EmptyStaticTestGump : StaticGump<EmptyStaticTestGump>
{
public bool HasVisualElementsForTest => HasVisualElements;
public EmptyStaticTestGump() : base(0, 0)
{
}

View file

@ -4,6 +4,8 @@ namespace Server.Tests.Gumps;
public sealed class LegacyTestGump : Gump
{
public bool HasVisualElementsForTest => HasVisualElements;
public LegacyTestGump(string petName) : base(50, 50)
{
Serial = (Serial)0x123;

View file

@ -4,6 +4,8 @@ namespace Server.Tests.Gumps;
public class StaticTestGump : StaticGump<StaticTestGump>
{
public bool HasVisualElementsForTest => HasVisualElements;
public StaticTestGump() : base(50, 50)
{
Serial = (Serial)0x123;

View file

@ -76,20 +76,22 @@ public class TestLayoutGumps
[Fact]
public void TestEmptyGumpsHaveNoVisualElements()
{
Assert.False(Compile(new EmptyLegacyTestGump()).HasVisualElements);
Assert.False(Compile(new EmptyDynamicTestGump()).HasVisualElements);
Assert.False(Compile(new EmptyStaticTestGump()).HasVisualElements);
Assert.False(Compile(new EmptyLegacyTestGump()).HasVisualElementsForTest);
Assert.False(Compile(new EmptyDynamicTestGump()).HasVisualElementsForTest);
Assert.False(Compile(new EmptyStaticTestGump()).HasVisualElementsForTest);
Assert.False(Compile(new EmptyStaticTestGump()).HasVisualElementsForTest);
}
[Fact]
public void TestVisibleGumpsHaveVisualElements()
{
Assert.True(Compile(new LegacyTestGump("Test")).HasVisualElements);
Assert.True(Compile(new DynamicTestGump("Test")).HasVisualElements);
Assert.True(Compile(new StaticTestGump()).HasVisualElements);
Assert.True(Compile(new LegacyTestGump("Test")).HasVisualElementsForTest);
Assert.True(Compile(new DynamicTestGump("Test")).HasVisualElementsForTest);
Assert.True(Compile(new StaticTestGump()).HasVisualElementsForTest);
Assert.True(Compile(new StaticTestGump()).HasVisualElementsForTest);
}
private static BaseGump Compile(BaseGump gump)
private static T Compile<T>(T gump) where T : BaseGump
{
var buffer = GC.AllocateUninitializedArray<byte>(512);
var writer = new SpanWriter(buffer);

View file

@ -31,7 +31,7 @@ public abstract class BaseGump
public int TypeID { get; protected set; }
public Serial Serial { get; protected set; }
internal bool HasVisualElements { get; set; }
protected bool HasVisualElements { get; set; }
public abstract int Switches { get; }
public abstract int TextEntries { get; }

View file

@ -30,7 +30,7 @@ public abstract class StaticGump<TSelf> : BaseGump where TSelf : StaticGump<TSel
private static byte[] _compressedStringsData;
private static bool _hasDynamicStrings;
private static bool _hasVisualElements;
private static bool _cachedHasVisualElements;
private static int _staticStringsCount;
private static byte[] _staticStrings;
@ -73,7 +73,7 @@ public abstract class StaticGump<TSelf> : BaseGump where TSelf : StaticGump<TSel
if (Cached && _compressedLayoutData != null)
{
HasVisualElements = _hasVisualElements;
HasVisualElements = _cachedHasVisualElements;
writer.Write(_compressedLayoutData);
if (_compressedStringsData != null)
@ -118,7 +118,7 @@ public abstract class StaticGump<TSelf> : BaseGump where TSelf : StaticGump<TSel
BuildLayout(ref gumpBuilder);
gumpBuilder.FinalizeLayout();
HasVisualElements = _hasVisualElements = gumpBuilder.HasVisualElements;
HasVisualElements = _cachedHasVisualElements = gumpBuilder.HasVisualElements;
_switches = gumpBuilder.Switches;
_textEntries = gumpBuilder.TextEntries;
_staticStringsCount = gumpBuilder._stringsCount;