fix: Streamlines gump compilation (#969)

Changes gump compilation to use string interpolation. .NET 6 uses code generation and compile time tricks to speed up string interpolation between 15 and 30% and reduce allocations dramatically.
This commit is contained in:
Kamron Batman 2022-03-22 23:46:10 -07:00 committed by GitHub
parent 14b63ca48e
commit c166e113b1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 853 additions and 2258 deletions

View file

@ -1,173 +0,0 @@
using System;
using System.Buffers;
using System.IO;
using System.IO.Compression;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Server.Collections;
using Server.Gumps;
using Server.Network;
using Server.Tests.Network;
namespace Benchmarks
{
[MemoryDiagnoser]
[SimpleJob(RuntimeMoniker.Net60)]
public class OutgoingGumpPacketBenchmarks
{
private static readonly byte[] _layoutBuffer = GC.AllocateUninitializedArray<byte>(0x20000);
private static readonly byte[] _stringsBuffer = GC.AllocateUninitializedArray<byte>(0x20000);
public static void CreateDisplayGump(Gump gump, out int switches, out int entries)
{
switches = 0;
entries = 0;
const bool packed = false;
var layoutWriter = new SpanWriter(_layoutBuffer);
if (!gump.Draggable)
{
layoutWriter.Write(Gump.NoMove);
}
if (!gump.Closable)
{
layoutWriter.Write(Gump.NoClose);
}
if (!gump.Disposable)
{
layoutWriter.Write(Gump.NoDispose);
}
if (!gump.Resizable)
{
layoutWriter.Write(Gump.NoResize);
}
var stringsList = new OrderedHashSet<string>(32);
foreach (var entry in gump.Entries)
{
entry.AppendTo(ref layoutWriter, stringsList, ref entries, ref switches);
}
var stringsWriter = new SpanWriter(_stringsBuffer);
foreach (var str in stringsList)
{
var s = str ?? "";
stringsWriter.Write((ushort)s.Length);
stringsWriter.WriteBigUni(s);
}
int maxLength;
if (packed)
{
var worstLayoutLength = Zlib.MaxPackSize(layoutWriter.BytesWritten);
var worstStringsLength = Zlib.MaxPackSize(stringsWriter.BytesWritten);
maxLength = 40 + worstLayoutLength + worstStringsLength;
}
else
{
maxLength = 23 + layoutWriter.BytesWritten + stringsWriter.BytesWritten;
}
var writer = new SpanWriter(maxLength);
writer.Write((byte)(packed ? 0xDD : 0xB0)); // Packet ID
writer.Seek(2, SeekOrigin.Current);
writer.Write(gump.Serial);
writer.Write(gump.TypeID);
writer.Write(gump.X);
writer.Write(gump.Y);
if (packed)
{
layoutWriter.Write((byte)0); // Layout text terminator
OutgoingGumpPackets.WritePacked(layoutWriter.Span, ref writer);
writer.Write(stringsList.Count);
OutgoingGumpPackets.WritePacked(stringsWriter.Span, ref writer);
}
else
{
writer.Write((ushort)layoutWriter.BytesWritten);
writer.Write(layoutWriter.Span);
writer.Write((ushort)stringsList.Count);
writer.Write(stringsWriter.Span);
}
writer.WritePacketLength();
layoutWriter.Dispose(); // Just in case
stringsWriter.Dispose(); // Just in case
}
public class NameChangeDeedGump : Gump
{
public NameChangeDeedGump() : base(50, 50)
{
Closable = false;
Draggable = false;
Resizable = false;
AddPage(0);
AddBlackAlpha(10, 120, 250, 85);
AddHtml(10, 125, 250, 20, Color(Center("Name Change Deed"), 0xFFFFFF));
AddLabel(73, 15, 1152, "");
AddLabel(20, 150, 0x480, "New Name:");
AddTextField(100, 150, 150, 20, 0);
AddButtonLabeled(75, 180, 1, "Submit");
}
public void AddBlackAlpha(int x, int y, int width, int height)
{
AddImageTiled(x, y, width, height, 2624);
AddAlphaRegion(x, y, width, height);
}
public void AddTextField(int x, int y, int width, int height, int index)
{
AddBackground(x - 2, y - 2, width + 4, height + 4, 0x2486);
AddTextEntry(x + 2, y + 2, width - 4, height - 4, 0, index, "");
}
public static string Center(string text) => $"<CENTER>{text}</CENTER>";
public static string Color(string text, int color) => $"<BASEFONT COLOR=#{color:X6}>{text}</BASEFONT>";
public void AddButtonLabeled(int x, int y, int buttonID, string text)
{
AddButton(x, y - 1, 4005, 4007, buttonID);
AddHtml(x + 35, y, 240, 20, Color(text, 0xFFFFFF));
}
}
private static Gump _gump;
[GlobalSetup]
public void Setup()
{
_gump = new NameChangeDeedGump();
}
[Benchmark]
public void TestNewStack()
{
CreateDisplayGump(_gump, out var _, out var _);
}
[Benchmark]
public void TestOldStack()
{
_gump.Compile().Compile(false, out var _);
}
}
}

View file

@ -1,315 +0,0 @@
using System.Buffers;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Text;
using Server.Gumps;
using Server.Network;
namespace Server.Tests
{
public interface IGumpWriter
{
int TextEntries { get; set; }
int Switches { get; set; }
void AppendLayout(bool val);
void AppendLayout(int val);
void AppendLayout(uint val);
void AppendLayout(Serial serial);
void AppendLayoutNS(int val);
void AppendLayout(string text);
void AppendLayoutNS(string text);
void AppendLayout(byte[] buffer);
void WriteStrings(List<string> strings);
void Flush();
}
public sealed class CloseGump : Packet
{
public CloseGump(int typeID, int buttonID) : base(0xBF)
{
EnsureCapacity(13);
Stream.Write((short)0x04);
Stream.Write(typeID);
Stream.Write(buttonID);
}
}
public sealed class DisplayGumpPacked : Packet, IGumpWriter
{
private static readonly byte[] m_True = Gump.StringToBuffer(" 1");
private static readonly byte[] m_False = Gump.StringToBuffer(" 0");
private static readonly byte[] m_BeginTextSeparator = Gump.StringToBuffer(" @");
private static readonly byte[] m_EndTextSeparator = Gump.StringToBuffer("@");
private static readonly byte[] m_Buffer = new byte[48];
private readonly Gump m_Gump;
private readonly PacketWriter m_Layout;
private readonly PacketWriter m_Strings;
private int m_StringCount;
static DisplayGumpPacked() => m_Buffer[0] = (byte)' ';
public DisplayGumpPacked(Gump gump)
: base(0xDD)
{
m_Gump = gump;
m_Layout = PacketWriter.CreateInstance(8192);
m_Strings = PacketWriter.CreateInstance(8192);
}
public int TextEntries { get; set; }
public int Switches { get; set; }
public void AppendLayout(bool val)
{
AppendLayout(val ? m_True : m_False);
}
public void AppendLayout(int val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
m_Layout.Write(m_Buffer, 0, bytes);
}
public void AppendLayout(uint val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
m_Layout.Write(m_Buffer, 0, bytes);
}
public void AppendLayout(Serial serial) => AppendLayout(serial.Value);
public void AppendLayoutNS(int val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1);
m_Layout.Write(m_Buffer, 1, bytes);
}
public void AppendLayoutNS(string text)
{
m_Layout.WriteAsciiFixed(text, text.Length);
}
public void AppendLayout(string text)
{
AppendLayout(m_BeginTextSeparator);
m_Layout.WriteAsciiFixed(text, text.Length);
AppendLayout(m_EndTextSeparator);
}
public void AppendLayout(byte[] buffer)
{
m_Layout.Write(buffer, 0, buffer.Length);
}
public void WriteStrings(List<string> strings)
{
m_StringCount = strings.Count;
for (var i = 0; i < strings.Count; ++i)
{
var v = strings[i] ?? "";
m_Strings.Write((ushort)v.Length);
m_Strings.WriteBigUniFixed(v, v.Length);
}
}
public void Flush()
{
EnsureCapacity(28 + (int)m_Layout.Length + (int)m_Strings.Length);
Stream.Write(m_Gump.Serial);
Stream.Write(m_Gump.TypeID);
Stream.Write(m_Gump.X);
Stream.Write(m_Gump.Y);
// Note: layout MUST be null terminated (don't listen to krrios)
m_Layout.Write((byte)0);
WritePacked(m_Layout);
Stream.Write(m_StringCount);
WritePacked(m_Strings);
PacketWriter.ReleaseInstance(m_Layout);
PacketWriter.ReleaseInstance(m_Strings);
}
private void WritePacked(PacketWriter src)
{
var buffer = src.UnderlyingStream.GetBuffer();
var length = (int)src.Length;
if (length == 0)
{
Stream.Write(0);
return;
}
var wantLength = 1 + length * 1024 / 1000;
wantLength += 4095;
wantLength &= ~4095;
var packBuffer = ArrayPool<byte>.Shared.Rent(wantLength);
var packLength = wantLength;
Zlib.Pack(packBuffer, ref packLength, buffer, length, ZlibQuality.Default);
Stream.Write(4 + packLength);
Stream.Write(length);
Stream.Write(packBuffer, 0, packLength);
ArrayPool<byte>.Shared.Return(packBuffer);
}
}
public sealed class DisplayGumpFast : Packet, IGumpWriter
{
private static readonly byte[] m_True = Gump.StringToBuffer(" 1");
private static readonly byte[] m_False = Gump.StringToBuffer(" 0");
private static readonly byte[] m_BeginTextSeparator = Gump.StringToBuffer(" @");
private static readonly byte[] m_EndTextSeparator = Gump.StringToBuffer("@");
private readonly byte[] m_Buffer = new byte[48];
private int m_LayoutLength;
public DisplayGumpFast(Gump g) : base(0xB0)
{
m_Buffer[0] = (byte)' ';
EnsureCapacity(4096);
Stream.Write(g.Serial);
Stream.Write(g.TypeID);
Stream.Write(g.X);
Stream.Write(g.Y);
Stream.Write((ushort)0xFFFF);
}
public int TextEntries { get; set; }
public int Switches { get; set; }
public void AppendLayout(bool val)
{
AppendLayout(val ? m_True : m_False);
}
public void AppendLayout(int val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
Stream.Write(m_Buffer, 0, bytes);
m_LayoutLength += bytes;
}
public void AppendLayout(uint val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1) + 1;
Stream.Write(m_Buffer, 0, bytes);
m_LayoutLength += bytes;
}
public void AppendLayout(Serial serial) => AppendLayout(serial.Value);
public void AppendLayoutNS(int val)
{
var toString = val.ToString();
var bytes = Encoding.ASCII.GetBytes(toString, 0, toString.Length, m_Buffer, 1);
Stream.Write(m_Buffer, 1, bytes);
m_LayoutLength += bytes;
}
public void AppendLayoutNS(string text)
{
var length = text.Length;
Stream.WriteAsciiFixed(text, length);
m_LayoutLength += length;
}
public void AppendLayout(string text)
{
AppendLayout(m_BeginTextSeparator);
var length = text.Length;
Stream.WriteAsciiFixed(text, length);
m_LayoutLength += length;
AppendLayout(m_EndTextSeparator);
}
public void AppendLayout(byte[] buffer)
{
var length = buffer.Length;
Stream.Write(buffer, 0, length);
m_LayoutLength += length;
}
public void WriteStrings(List<string> text)
{
Stream.Seek(19, SeekOrigin.Begin);
Stream.Write((ushort)m_LayoutLength);
Stream.Seek(0, SeekOrigin.End);
Stream.Write((ushort)text.Count);
for (var i = 0; i < text.Count; ++i)
{
var v = text[i] ?? "";
int length = (ushort)v.Length;
Stream.Write((ushort)length);
Stream.WriteBigUniFixed(v, length);
}
}
public void Flush()
{
}
}
public sealed class DisplaySignGump : Packet
{
public DisplaySignGump(Serial serial, int gumpID, string unknown, string caption) : base(0x8B)
{
unknown ??= "";
caption ??= "";
EnsureCapacity(15 + unknown.Length + caption.Length);
Stream.Write(serial);
Stream.Write((short)gumpID);
Stream.Write((short)(unknown.Length + 1));
Stream.WriteAsciiNull(unknown);
Stream.Write((short)(caption.Length + 1));
Stream.WriteAsciiNull(caption);
}
}
}

View file

@ -1,476 +0,0 @@
using System.Collections.Generic;
using Server.Gumps;
using Server.Network;
namespace Server.Tests.Network
{
public static class GumpUtilities
{
private static readonly byte[] m_BeginLayout = Gump.StringToBuffer("{ ");
private static readonly byte[] m_EndLayout = Gump.StringToBuffer(" }");
public static Packet Compile(this Gump g, NetState ns = null)
{
IGumpWriter disp = new DisplayGumpFast(g);
// IGumpWriter disp = new DisplayGumpPacked(g);
if (!g.Draggable)
{
disp.AppendLayout(Gump.NoMove);
}
if (!g.Closable)
{
disp.AppendLayout(Gump.NoClose);
}
if (!g.Disposable)
{
disp.AppendLayout(Gump.NoDispose);
}
if (!g.Resizable)
{
disp.AppendLayout(Gump.NoResize);
}
var count = g.Entries.Count;
var strings = new List<string>();
for (var i = 0; i < count; ++i)
{
var e = g.Entries[i];
disp.AppendLayout(m_BeginLayout);
e.AppendToByType(disp, strings);
disp.AppendLayout(m_EndLayout);
}
disp.WriteStrings(strings);
disp.Flush();
return (Packet)disp;
}
public static int Intern(this List<string> strings, string value)
{
var indexOf = strings.IndexOf(value);
if (indexOf >= 0)
{
return indexOf;
}
strings.Add(value);
return strings.Count - 1;
}
public static void AppendToByType(this GumpEntry e, IGumpWriter disp, List<string> strings)
{
switch (e)
{
case GumpAlphaRegion g:
{
g.AppendTo(disp, strings);
break;
}
case GumpBackground g:
{
g.AppendTo(disp, strings);
break;
}
case GumpButton g:
{
g.AppendTo(disp, strings);
break;
}
case GumpCheck g:
{
g.AppendTo(disp, strings);
break;
}
case GumpGroup g:
{
g.AppendTo(disp, strings);
break;
}
case GumpECHandleInput g:
{
g.AppendTo(disp, strings);
break;
}
case GumpHtml g:
{
g.AppendTo(disp, strings);
break;
}
case GumpHtmlLocalized g:
{
g.AppendTo(disp, strings);
break;
}
case GumpImage g:
{
g.AppendTo(disp, strings);
break;
}
case GumpImageTileButton g:
{
g.AppendTo(disp, strings);
break;
}
case GumpImageTiled g:
{
g.AppendTo(disp, strings);
break;
}
case GumpItem g:
{
g.AppendTo(disp, strings);
break;
}
case GumpItemProperty g:
{
g.AppendTo(disp, strings);
break;
}
case GumpLabel g:
{
g.AppendTo(disp, strings);
break;
}
case GumpLabelCropped g:
{
g.AppendTo(disp, strings);
break;
}
case GumpMasterGump g:
{
g.AppendTo(disp, strings);
break;
}
case GumpPage g:
{
g.AppendTo(disp, strings);
break;
}
case GumpRadio g:
{
g.AppendTo(disp, strings);
break;
}
case GumpSpriteImage g:
{
g.AppendTo(disp, strings);
break;
}
case GumpTextEntry g:
{
g.AppendTo(disp, strings);
break;
}
case GumpTextEntryLimited g:
{
g.AppendTo(disp, strings);
break;
}
case GumpTooltip g:
{
g.AppendTo(disp, strings);
break;
}
}
}
public static void AppendTo(this GumpAlphaRegion g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpAlphaRegion.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
}
public static void AppendTo(this GumpBackground g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpBackground.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
}
public static void AppendTo(this GumpButton g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpButton.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.NormalID);
disp.AppendLayout(g.PressedID);
disp.AppendLayout((int)g.Type);
disp.AppendLayout(g.Param);
disp.AppendLayout(g.ButtonID);
}
public static void AppendTo(this GumpCheck g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpButton.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.InactiveID);
disp.AppendLayout(g.ActiveID);
disp.AppendLayout(g.InitialState);
disp.AppendLayout(g.SwitchID);
disp.Switches++;
}
public static void AppendTo(this GumpGroup g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpGroup.LayoutName);
disp.AppendLayout(g.Group);
}
public static void AppendTo(this GumpECHandleInput g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpECHandleInput.LayoutName);
}
public static void AppendTo(this GumpHtml g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpHtml.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(strings.Intern(g.Text));
disp.AppendLayout(g.Background);
disp.AppendLayout(g.Scrollbar);
}
public static void AppendTo(this GumpHtmlLocalized g, IGumpWriter disp, List<string> strings)
{
switch (g.Type)
{
case GumpHtmlLocalizedType.Plain:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNamePlain);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Number);
disp.AppendLayout(g.Background);
disp.AppendLayout(g.Scrollbar);
break;
}
case GumpHtmlLocalizedType.Color:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNameColor);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Number);
disp.AppendLayout(g.Background);
disp.AppendLayout(g.Scrollbar);
disp.AppendLayout(g.Color);
break;
}
case GumpHtmlLocalizedType.Args:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNameArgs);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Background);
disp.AppendLayout(g.Scrollbar);
disp.AppendLayout(g.Color);
disp.AppendLayout(g.Number);
disp.AppendLayout(g.Args);
break;
}
}
}
public static void AppendTo(this GumpImage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImage.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
if (g.Hue != 0)
{
disp.AppendLayout(GumpImage.HueEquals);
disp.AppendLayoutNS(g.Hue);
}
if (!string.IsNullOrEmpty(g.Class))
{
disp.AppendLayout(GumpImage.ClassEquals);
disp.AppendLayoutNS(g.Class);
}
}
public static void AppendTo(this GumpImageTileButton g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImageTileButton.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.NormalID);
disp.AppendLayout(g.PressedID);
disp.AppendLayout((int)g.Type);
disp.AppendLayout(g.Param);
disp.AppendLayout(g.ButtonID);
disp.AppendLayout(g.ItemID);
disp.AppendLayout(g.Hue);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
if (g.LocalizedTooltip > 0)
{
disp.AppendLayout(GumpImageTileButton.LayoutTooltip);
disp.AppendLayout(g.LocalizedTooltip);
}
}
public static void AppendTo(this GumpImageTiled g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImageTiled.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.GumpID);
}
public static void AppendTo(this GumpItem g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(g.Hue == 0 ? GumpItem.LayoutName : GumpItem.LayoutNameHue);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.ItemID);
if (g.Hue != 0)
{
disp.AppendLayout(g.Hue);
}
}
public static void AppendTo(this GumpItemProperty g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpItemProperty.LayoutName);
disp.AppendLayout(g.Serial);
}
public static void AppendTo(this GumpLabel g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpLabel.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Hue);
disp.AppendLayout(strings.Intern(g.Text));
}
public static void AppendTo(this GumpLabelCropped g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpLabelCropped.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Hue);
disp.AppendLayout(strings.Intern(g.Text));
}
public static void AppendTo(this GumpMasterGump g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpMasterGump.LayoutName);
disp.AppendLayout(g.GumpID);
}
public static void AppendTo(this GumpPage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpPage.LayoutName);
disp.AppendLayout(g.Page);
}
public static void AppendTo(this GumpRadio g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpRadio.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.InactiveID);
disp.AppendLayout(g.ActiveID);
disp.AppendLayout(g.InitialState);
disp.AppendLayout(g.SwitchID);
disp.Switches++;
}
public static void AppendTo(this GumpSpriteImage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpSpriteImage.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.SX);
disp.AppendLayout(g.SY);
}
public static void AppendTo(this GumpTextEntry g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTextEntry.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Hue);
disp.AppendLayout(g.EntryID);
disp.AppendLayout(strings.Intern(g.InitialText));
disp.TextEntries++;
}
public static void AppendTo(this GumpTextEntryLimited g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTextEntryLimited.LayoutName);
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
disp.AppendLayout(g.Hue);
disp.AppendLayout(g.EntryID);
disp.AppendLayout(strings.Intern(g.InitialText));
disp.AppendLayout(g.Size);
disp.TextEntries++;
}
public static void AppendTo(this GumpTooltip g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTooltip.LayoutName);
disp.AppendLayout(g.Number);
if (!string.IsNullOrEmpty(g.Args))
{
disp.AppendLayout(g.Args);
}
}
}
}

View file

@ -28,7 +28,7 @@ namespace Benchmarks
//var mapMultiSelectors = BenchmarkRunner.Run<MapMultiSelectors>();
// var mapItemsSelectors = BenchmarkRunner.Run<MapItemSelectors>();
// var stArray = BenchmarkRunner.Run<BenchmarkSTArray>();
var pooledRefQueue = BenchmarkRunner.Run<BenchmarkPooledRefQueue>();
// var pooledRefQueue = BenchmarkRunner.Run<BenchmarkPooledRefQueue>();
}
}
}

View file

@ -193,7 +193,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpAlphaRegion g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpAlphaRegion.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("checkertrans"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -202,7 +202,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpBackground g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpBackground.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("resizepic"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
@ -212,7 +212,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpButton g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpButton.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("button"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.NormalID);
@ -224,7 +224,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpCheck g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpButton.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("checkbox"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.InactiveID);
@ -237,18 +237,18 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpGroup g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpGroup.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("group"));
disp.AppendLayout(g.Group);
}
public static void AppendTo(this GumpECHandleInput g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpECHandleInput.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("echandleinput"));
}
public static void AppendTo(this GumpHtml g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpHtml.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("htmlgump"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -264,7 +264,7 @@ namespace Server.Tests.Network
{
case GumpHtmlLocalizedType.Plain:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNamePlain);
disp.AppendLayout(Gump.StringToBuffer("xmfhtmlgump"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
@ -279,7 +279,7 @@ namespace Server.Tests.Network
case GumpHtmlLocalizedType.Color:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNameColor);
disp.AppendLayout(Gump.StringToBuffer("xmfhtmlgumpcolor"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
@ -295,7 +295,7 @@ namespace Server.Tests.Network
case GumpHtmlLocalizedType.Args:
{
disp.AppendLayout(GumpHtmlLocalized.LayoutNameArgs);
disp.AppendLayout(Gump.StringToBuffer("xmfhtmltok"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
@ -314,27 +314,27 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpImage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImage.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("gumppic"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
if (g.Hue != 0)
{
disp.AppendLayout(GumpImage.HueEquals);
disp.AppendLayoutNS(" hue=");
disp.AppendLayoutNS(g.Hue);
}
if (!string.IsNullOrEmpty(g.Class))
{
disp.AppendLayout(GumpImage.ClassEquals);
disp.AppendLayoutNS(g.Class);
disp.AppendLayoutNS(" class=");
disp.AppendLayout(Gump.StringToBuffer(g.Class));
}
}
public static void AppendTo(this GumpImageTileButton g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImageTileButton.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("buttontileart"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.NormalID);
@ -347,17 +347,11 @@ namespace Server.Tests.Network
disp.AppendLayout(g.Hue);
disp.AppendLayout(g.Width);
disp.AppendLayout(g.Height);
if (g.LocalizedTooltip > 0)
{
disp.AppendLayout(GumpImageTileButton.LayoutTooltip);
disp.AppendLayout(g.LocalizedTooltip);
}
}
public static void AppendTo(this GumpImageTiled g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpImageTiled.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("gumppictiled"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -367,7 +361,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpItem g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(g.Hue == 0 ? GumpItem.LayoutName : GumpItem.LayoutNameHue);
disp.AppendLayout(Gump.StringToBuffer(g.Hue == 0 ? "tilepic" : "tilepichue"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.ItemID);
@ -380,13 +374,13 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpItemProperty g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpItemProperty.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("itemproperty"));
disp.AppendLayout(g.Serial);
}
public static void AppendTo(this GumpLabel g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpLabel.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("text"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Hue);
@ -395,7 +389,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpLabelCropped g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpLabelCropped.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("croppedtext"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -406,19 +400,19 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpMasterGump g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpMasterGump.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("mastergump"));
disp.AppendLayout(g.GumpID);
}
public static void AppendTo(this GumpPage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpPage.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("page"));
disp.AppendLayout(g.Page);
}
public static void AppendTo(this GumpRadio g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpRadio.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("radio"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.InactiveID);
@ -431,7 +425,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpSpriteImage g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpSpriteImage.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("picinpic"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.GumpID);
@ -443,7 +437,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpTextEntry g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTextEntry.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("textentry"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -457,7 +451,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpTextEntryLimited g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTextEntryLimited.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("textentrylimited"));
disp.AppendLayout(g.X);
disp.AppendLayout(g.Y);
disp.AppendLayout(g.Width);
@ -472,7 +466,7 @@ namespace Server.Tests.Network
public static void AppendTo(this GumpTooltip g, IGumpWriter disp, List<string> strings)
{
disp.AppendLayout(GumpTooltip.LayoutName);
disp.AppendLayout(Gump.StringToBuffer("tooltip"));
disp.AppendLayout(g.Number);
if (!string.IsNullOrEmpty(g.Args))

View file

@ -24,9 +24,9 @@ namespace Server.Tests.Network
public void TestDisplaySignGump()
{
Serial gumpSerial = (Serial)0x1000;
var gumpId = 100;
var unknownString = "This is an unknown string";
var caption = "This is a caption";
const int gumpId = 100;
const string unknownString = "This is an unknown string";
const string caption = "This is a caption";
var expected = new DisplaySignGump(gumpSerial, gumpId, unknownString, caption).Compile();

View file

@ -3,259 +3,257 @@ using System.Collections.Generic;
using Server.Network;
using Server.Text;
namespace Server.Gumps
namespace Server.Gumps;
public class Gump
{
public class Gump
private static Serial _nextSerial = (Serial)1;
public static readonly byte[] NoMove = StringToBuffer("{ nomove }");
public static readonly byte[] NoClose = StringToBuffer("{ noclose }");
public static readonly byte[] NoDispose = StringToBuffer("{ nodispose }");
public static readonly byte[] NoResize = StringToBuffer("{ noresize }");
internal int m_TextEntries, m_Switches;
public Gump(int x, int y)
{
private static Serial _nextSerial = (Serial)1;
public static readonly byte[] NoMove = StringToBuffer("{ nomove }");
public static readonly byte[] NoClose = StringToBuffer("{ noclose }");
public static readonly byte[] NoDispose = StringToBuffer("{ nodispose }");
public static readonly byte[] NoResize = StringToBuffer("{ noresize }");
internal int m_TextEntries, m_Switches;
public Gump(int x, int y)
do
{
do
{
Serial = _nextSerial++;
} while (Serial == 0); // standard client apparently doesn't send a gump response packet if serial == 0
Serial = _nextSerial++;
} while (Serial == 0); // standard client apparently doesn't send a gump response packet if serial == 0
X = x;
Y = y;
X = x;
Y = y;
TypeID = GetTypeID(GetType());
TypeID = GetTypeID(GetType());
Entries = new List<GumpEntry>();
Strings = new List<string>();
Entries = new List<GumpEntry>();
Strings = new List<string>();
}
public List<string> Strings { get; }
public int TypeID { get; }
public List<GumpEntry> Entries { get; }
public Serial Serial { get; set; }
public int X { get; set; }
public int Y { get; set; }
public bool Disposable { get; set; } = true;
public bool Resizable { get; set; } = true;
public bool Draggable { get; set; } = true;
public bool Closable { get; set; } = true;
public static int GetTypeID(Type type) => type?.FullName?.GetHashCode(StringComparison.Ordinal) ?? -1;
public void AddPage(int page)
{
Add(new GumpPage(page));
}
public void AddAlphaRegion(int x, int y, int width, int height)
{
Add(new GumpAlphaRegion(x, y, width, height));
}
public void AddBackground(int x, int y, int width, int height, int gumpID)
{
Add(new GumpBackground(x, y, width, height, gumpID));
}
public void AddButton(
int x, int y, int normalID, int pressedID, int buttonID,
GumpButtonType type = GumpButtonType.Reply, int param = 0
)
{
Add(new GumpButton(x, y, normalID, pressedID, buttonID, type, param));
}
public void AddCheck(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
Add(new GumpCheck(x, y, inactiveID, activeID, initialState, switchID));
}
public void AddGroup(int group)
{
Add(new GumpGroup(group));
}
public void AddTooltip(int number, string args = null)
{
Add(new GumpTooltip(number, args));
}
public void AddHtml(
int x, int y, int width, int height, string text, bool background = false, bool scrollbar = false
)
{
Add(new GumpHtml(x, y, width, height, text, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, bool background = false,
bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, int color, bool background = false,
bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, color, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, string args, int color,
bool background = false, bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, args, color, background, scrollbar));
}
public void AddImage(int x, int y, int gumpID, int hue = 0)
{
Add(new GumpImage(x, y, gumpID, hue));
}
public void AddImageTiled(int x, int y, int width, int height, int gumpID)
{
Add(new GumpImageTiled(x, y, width, height, gumpID));
}
public void AddImageTiledButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type,
int param, int itemID, int hue, int width, int height
)
{
Add(
new GumpImageTileButton(
x,
y,
normalID,
pressedID,
buttonID,
type,
param,
itemID,
hue,
width,
height
)
);
}
public void AddItem(int x, int y, int itemID, int hue = 0)
{
Add(new GumpItem(x, y, itemID, hue));
}
public void AddLabel(int x, int y, int hue, string text)
{
Add(new GumpLabel(x, y, hue, text));
}
public void AddLabelCropped(int x, int y, int width, int height, int hue, string text)
{
Add(new GumpLabelCropped(x, y, width, height, hue, text));
}
public void AddRadio(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
Add(new GumpRadio(x, y, inactiveID, activeID, initialState, switchID));
}
public void AddTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText)
{
Add(new GumpTextEntry(x, y, width, height, hue, entryID, initialText));
}
public void AddTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText, int size)
{
Add(new GumpTextEntryLimited(x, y, width, height, hue, entryID, initialText, size));
}
public void AddItemProperty(Serial serial)
{
Add(new GumpItemProperty(serial));
}
public void AddSpriteImage(int x, int y, int gumpID, int width, int height, int sx, int sy)
{
Add(new GumpSpriteImage(x, y, gumpID, width, height, sx, sy));
}
public void AddECHandleInput()
{
Add(new GumpECHandleInput());
}
public void AddGumpIDOverride(int gumpID)
{
Add(new GumpMasterGump(gumpID));
}
public void Add(GumpEntry g)
{
if (g.Parent != this)
{
g.Parent = this;
}
public List<string> Strings { get; }
public int TypeID { get; }
public List<GumpEntry> Entries { get; }
public Serial Serial { get; set; }
public int X { get; set; }
public int Y { get; set; }
public bool Disposable { get; set; } = true;
public bool Resizable { get; set; } = true;
public bool Draggable { get; set; } = true;
public bool Closable { get; set; } = true;
public static int GetTypeID(Type type) => type?.FullName?.GetHashCode(StringComparison.Ordinal) ?? -1;
public void AddPage(int page)
{
Add(new GumpPage(page));
}
public void AddAlphaRegion(int x, int y, int width, int height)
{
Add(new GumpAlphaRegion(x, y, width, height));
}
public void AddBackground(int x, int y, int width, int height, int gumpID)
{
Add(new GumpBackground(x, y, width, height, gumpID));
}
public void AddButton(
int x, int y, int normalID, int pressedID, int buttonID,
GumpButtonType type = GumpButtonType.Reply, int param = 0
)
{
Add(new GumpButton(x, y, normalID, pressedID, buttonID, type, param));
}
public void AddCheck(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
Add(new GumpCheck(x, y, inactiveID, activeID, initialState, switchID));
}
public void AddGroup(int group)
{
Add(new GumpGroup(group));
}
public void AddTooltip(int number, string args = null)
{
Add(new GumpTooltip(number, args));
}
public void AddHtml(
int x, int y, int width, int height, string text, bool background = false, bool scrollbar = false
)
{
Add(new GumpHtml(x, y, width, height, text, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, bool background = false,
bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, int color, bool background = false,
bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, color, background, scrollbar));
}
public void AddHtmlLocalized(
int x, int y, int width, int height, int number, string args, int color,
bool background = false, bool scrollbar = false
)
{
Add(new GumpHtmlLocalized(x, y, width, height, number, args, color, background, scrollbar));
}
public void AddImage(int x, int y, int gumpID, int hue = 0)
{
Add(new GumpImage(x, y, gumpID, hue));
}
public void AddImageTiled(int x, int y, int width, int height, int gumpID)
{
Add(new GumpImageTiled(x, y, width, height, gumpID));
}
public void AddImageTiledButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type,
int param, int itemID, int hue, int width, int height, int localizedTooltip = -1
)
{
Add(
new GumpImageTileButton(
x,
y,
normalID,
pressedID,
buttonID,
type,
param,
itemID,
hue,
width,
height,
localizedTooltip
)
);
}
public void AddItem(int x, int y, int itemID, int hue = 0)
{
Add(new GumpItem(x, y, itemID, hue));
}
public void AddLabel(int x, int y, int hue, string text)
{
Add(new GumpLabel(x, y, hue, text));
}
public void AddLabelCropped(int x, int y, int width, int height, int hue, string text)
{
Add(new GumpLabelCropped(x, y, width, height, hue, text));
}
public void AddRadio(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
Add(new GumpRadio(x, y, inactiveID, activeID, initialState, switchID));
}
public void AddTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText)
{
Add(new GumpTextEntry(x, y, width, height, hue, entryID, initialText));
}
public void AddTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText, int size)
{
Add(new GumpTextEntryLimited(x, y, width, height, hue, entryID, initialText, size));
}
public void AddItemProperty(Serial serial)
{
Add(new GumpItemProperty(serial));
}
public void AddSpriteImage(int x, int y, int gumpID, int width, int height, int sx, int sy)
{
Add(new GumpSpriteImage(x, y, gumpID, width, height, sx, sy));
}
public void AddECHandleInput()
{
Add(new GumpECHandleInput());
}
public void AddGumpIDOverride(int gumpID)
{
Add(new GumpMasterGump(gumpID));
}
public void Add(GumpEntry g)
{
if (g.Parent != this)
{
g.Parent = this;
}
else if (!Entries.Contains(g))
{
Entries.Add(g);
}
}
public void Remove(GumpEntry g)
{
if (g == null || !Entries.Contains(g))
{
return;
}
Entries.Remove(g);
g.Parent = null;
}
public int Intern(string value)
{
var indexOf = Strings.IndexOf(value);
if (indexOf >= 0)
{
return indexOf;
}
Strings.Add(value);
return Strings.Count - 1;
}
public void SendTo(NetState state)
{
state.AddGump(this);
state.SendDisplayGump(this, out m_Switches, out m_TextEntries);
}
public static byte[] StringToBuffer(string str) => str.GetBytesAscii();
public virtual void OnResponse(NetState sender, RelayInfo info)
{
}
public virtual void OnServerClose(NetState owner)
else if (!Entries.Contains(g))
{
Entries.Add(g);
}
}
public void Remove(GumpEntry g)
{
if (g == null || !Entries.Contains(g))
{
return;
}
Entries.Remove(g);
g.Parent = null;
}
public int Intern(string value)
{
var indexOf = Strings.IndexOf(value);
if (indexOf >= 0)
{
return indexOf;
}
Strings.Add(value);
return Strings.Count - 1;
}
public void SendTo(NetState state)
{
state.AddGump(this);
state.SendDisplayGump(this, out m_Switches, out m_TextEntries);
}
public static byte[] StringToBuffer(string str) => str.GetBytesAscii();
public virtual void OnResponse(NetState sender, RelayInfo info)
{
}
public virtual void OnServerClose(NetState owner)
{
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpAlphaRegion.cs *
* *
@ -16,43 +16,28 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpAlphaRegion : GumpEntry
{
public class GumpAlphaRegion : GumpEntry
public GumpAlphaRegion(int x, int y, int width, int height)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("checkertrans");
X = x;
Y = y;
Width = width;
Height = height;
}
public GumpAlphaRegion(int x, int y, int width, int height)
{
X = x;
Y = y;
Width = width;
Height = height;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ checkertrans {X} {Y} {Width} {Height} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii($"{{ checkertrans {X} {Y} {Width} {Height} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpBackground.cs *
* *
@ -16,48 +16,31 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpBackground : GumpEntry
{
public class GumpBackground : GumpEntry
public GumpBackground(int x, int y, int width, int height, int gumpID)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("resizepic");
X = x;
Y = y;
Width = width;
Height = height;
GumpID = gumpID;
}
public GumpBackground(int x, int y, int width, int height, int gumpID)
{
X = x;
Y = y;
Width = width;
Height = height;
GumpID = gumpID;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int GumpID { get; set; }
public int GumpID { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ resizepic {X} {Y} {GumpID} {Width} {Height} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(GumpID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii($"{{ resizepic {X} {Y} {GumpID} {Width} {Height} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpButton.cs *
* *
@ -16,68 +16,46 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public enum GumpButtonType
{
public enum GumpButtonType
Page = 0,
Reply = 1
}
public class GumpButton : GumpEntry
{
public GumpButton(
int x, int y, int normalID, int pressedID, int buttonID,
GumpButtonType type = GumpButtonType.Reply, int param = 0
)
{
Page = 0,
Reply = 1
X = x;
Y = y;
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
Type = type;
Param = param;
}
public class GumpButton : GumpEntry
public int X { get; set; }
public int Y { get; set; }
public int NormalID { get; set; }
public int PressedID { get; set; }
public int ButtonID { get; set; }
public GumpButtonType Type { get; set; }
public int Param { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("button");
public GumpButton(
int x, int y, int normalID, int pressedID, int buttonID,
GumpButtonType type = GumpButtonType.Reply, int param = 0
)
{
X = x;
Y = y;
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
Type = type;
Param = param;
}
public int X { get; set; }
public int Y { get; set; }
public int NormalID { get; set; }
public int PressedID { get; set; }
public int ButtonID { get; set; }
public GumpButtonType Type { get; set; }
public int Param { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ button {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(NormalID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(PressedID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(((int)Type).ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Param.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ButtonID.ToString());
writer.Write((ushort)0x207D); // " }"
}
writer.WriteAscii($"{{ button {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpCheck.cs *
* *
@ -16,56 +16,36 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpCheck : GumpEntry
{
public class GumpCheck : GumpEntry
public GumpCheck(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("checkbox");
X = x;
Y = y;
InactiveID = inactiveID;
ActiveID = activeID;
InitialState = initialState;
SwitchID = switchID;
}
public GumpCheck(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
X = x;
Y = y;
InactiveID = inactiveID;
ActiveID = activeID;
InitialState = initialState;
SwitchID = switchID;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int InactiveID { get; set; }
public int InactiveID { get; set; }
public int ActiveID { get; set; }
public int ActiveID { get; set; }
public bool InitialState { get; set; }
public bool InitialState { get; set; }
public int SwitchID { get; set; }
public int SwitchID { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ checkbox {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(InactiveID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ActiveID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(InitialState ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(SwitchID.ToString());
writer.Write((ushort)0x207D); // " }"
switches++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var initialState = InitialState ? "1" : "0";
writer.WriteAscii($"{{ checkbox {X} {Y} {InactiveID} {ActiveID} {initialState} {SwitchID} }}");
switches++;
}
}

View file

@ -16,16 +16,14 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
{
public class GumpECHandleInput : GumpEntry
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("echandleinput");
public override string Compile(OrderedHashSet<string> strings) => "{ echandleinput }";
namespace Server.Gumps;
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii("{ echandleinput }");
}
public class GumpECHandleInput : GumpEntry
{
private static byte[] _layout = Gump.StringToBuffer("{ echandleinput }");
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write(_layout);
}
}

View file

@ -1,32 +1,29 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public abstract class GumpEntry
{
public abstract class GumpEntry
private Gump m_Parent;
public Gump Parent
{
private Gump m_Parent;
public Gump Parent
get => m_Parent;
set
{
get => m_Parent;
set
if (m_Parent != value)
{
if (m_Parent != value)
{
m_Parent?.Remove(this);
m_Parent?.Remove(this);
m_Parent = value;
m_Parent = value;
m_Parent?.Add(this);
}
m_Parent?.Add(this);
}
}
public abstract string Compile(OrderedHashSet<string> strings);
// TODO: Replace OrderedHashSet with InsertOnlyHashSet, a copy of HashSet that is ReadOnly compatible, but includes
// a public AddIfNotPresent function that returns the index of the element
public abstract void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches);
}
// TODO: Replace OrderedHashSet with InsertOnlyHashSet, a copy of HashSet that is ReadOnly compatible, but includes
// a public AddIfNotPresent function that returns the index of the element
public abstract void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches);
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpGroup.cs *
* *
@ -16,24 +16,25 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpGroup : GumpEntry
{
public class GumpGroup : GumpEntry
private static byte[] _group1 = Gump.StringToBuffer("{ group 1 }");
public GumpGroup(int group) => Group = group;
public int Group { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("group");
public GumpGroup(int group) => Group = group;
public int Group { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ group {Group} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
if (Group == 1)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(Group.ToString());
writer.Write((ushort)0x207D); // " }"
writer.Write(_group1);
}
else
{
writer.WriteAscii($"{{ group {Group} }}");
}
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpHtml.cs *
* *
@ -16,59 +16,40 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpHtml : GumpEntry
{
public class GumpHtml : GumpEntry
public GumpHtml(int x, int y, int width, int height, string text, bool background, bool scrollbar)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("htmlgump");
X = x;
Y = y;
Width = width;
Height = height;
Text = text;
Background = background;
Scrollbar = scrollbar;
}
public GumpHtml(int x, int y, int width, int height, string text, bool background, bool scrollbar)
{
X = x;
Y = y;
Width = width;
Height = height;
Text = text;
Background = background;
Scrollbar = scrollbar;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public string Text { get; set; }
public string Text { get; set; }
public bool Background { get; set; }
public bool Background { get; set; }
public bool Scrollbar { get; set; }
public bool Scrollbar { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ htmlgump {X} {Y} {Width} {Height} {strings.GetOrAdd(Text ?? "")} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(strings.GetOrAdd(Text ?? "").ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Background ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Scrollbar ? '1' : '0');
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var textIndex = strings.GetOrAdd(Text ?? "");
var background = Background ? "1" : "0";
var scrollbar = Scrollbar ? "1" : "0";
writer.WriteAscii($"{{ htmlgump {X} {Y} {Width} {Height} {textIndex} {background} {scrollbar} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpHtmlLocalized.cs *
* *
@ -16,95 +16,94 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public enum GumpHtmlLocalizedType
{
public enum GumpHtmlLocalizedType
Plain,
Color,
Args
}
public class GumpHtmlLocalized : GumpEntry
{
public GumpHtmlLocalized(
int x, int y, int width, int height, int number,
bool background = false, bool scrollbar = false
)
{
Plain,
Color,
Args
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Background = background;
Scrollbar = scrollbar;
Type = GumpHtmlLocalizedType.Plain;
}
public class GumpHtmlLocalized : GumpEntry
public GumpHtmlLocalized(
int x, int y, int width, int height, int number, int color,
bool background = false, bool scrollbar = false
)
{
public static readonly byte[] LayoutNamePlain = Gump.StringToBuffer("xmfhtmlgump");
public static readonly byte[] LayoutNameColor = Gump.StringToBuffer("xmfhtmlgumpcolor");
public static readonly byte[] LayoutNameArgs = Gump.StringToBuffer("xmfhtmltok");
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Color = color;
Background = background;
Scrollbar = scrollbar;
public GumpHtmlLocalized(
int x, int y, int width, int height, int number,
bool background = false, bool scrollbar = false
)
{
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Background = background;
Scrollbar = scrollbar;
Type = GumpHtmlLocalizedType.Color;
}
Type = GumpHtmlLocalizedType.Plain;
}
public GumpHtmlLocalized(
int x, int y, int width, int height, int number, string args, int color,
bool background = false, bool scrollbar = false
)
{
// Are multiple arguments unsupported? And what about non ASCII arguments?
public GumpHtmlLocalized(
int x, int y, int width, int height, int number, int color,
bool background = false, bool scrollbar = false
)
{
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Color = color;
Background = background;
Scrollbar = scrollbar;
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Args = args;
Color = color;
Background = background;
Scrollbar = scrollbar;
Type = GumpHtmlLocalizedType.Color;
}
Type = GumpHtmlLocalizedType.Args;
}
public GumpHtmlLocalized(
int x, int y, int width, int height, int number, string args, int color,
bool background = false, bool scrollbar = false
)
{
// Are multiple arguments unsupported? And what about non ASCII arguments?
public int X { get; set; }
X = x;
Y = y;
Width = width;
Height = height;
Number = number;
Args = args;
Color = color;
Background = background;
Scrollbar = scrollbar;
public int Y { get; set; }
Type = GumpHtmlLocalizedType.Args;
}
public int Width { get; set; }
public int X { get; set; }
public int Height { get; set; }
public int Y { get; set; }
public int Number { get; set; }
public int Width { get; set; }
public string Args { get; set; }
public int Height { get; set; }
public int Color { get; set; }
public int Number { get; set; }
public bool Background { get; set; }
public string Args { get; set; }
public bool Scrollbar { get; set; }
public int Color { get; set; }
public GumpHtmlLocalizedType Type { get; set; }
public bool Background { get; set; }
public bool Scrollbar { get; set; }
public GumpHtmlLocalizedType Type { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii(
Type switch
{
GumpHtmlLocalizedType.Plain =>
@ -113,85 +112,7 @@ namespace Server.Gumps
$"{{ xmfhtmlgumpcolor {X} {Y} {Width} {Height} {Number} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} {Color} }}",
_ =>
$"{{ xmfhtmltok {X} {Y} {Width} {Height} {(Background ? 1 : 0)} {(Scrollbar ? 1 : 0)} {Color} {Number} @{Args}@ }}"
};
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
switch (Type)
{
case GumpHtmlLocalizedType.Plain:
{
writer.Write(LayoutNamePlain);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Number.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Background ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Scrollbar ? '1' : '0');
break;
}
case GumpHtmlLocalizedType.Color:
{
writer.Write(LayoutNameColor);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Number.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Background ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Scrollbar ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Color.ToString());
break;
}
case GumpHtmlLocalizedType.Args:
{
writer.Write(LayoutNameArgs);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Background ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Scrollbar ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(Color.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Number.ToString());
writer.WriteAscii(' ');
writer.WriteAscii('@');
writer.WriteAscii(Args ?? "");
writer.WriteAscii('@');
break;
}
}
writer.Write((ushort)0x207D); // " }"
}
);
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpImage.cs *
* *
@ -16,60 +16,41 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpImage : GumpEntry
{
public class GumpImage : GumpEntry
public GumpImage(int x, int y, int gumpID, int hue = 0, string cls = null)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("gumppic");
public static readonly byte[] HueEquals = Gump.StringToBuffer(" hue=");
public static readonly byte[] ClassEquals = Gump.StringToBuffer(" class=");
X = x;
Y = y;
GumpID = gumpID;
Hue = hue;
Class = cls;
}
public GumpImage(int x, int y, int gumpID, int hue = 0, string cls = null)
{
X = x;
Y = y;
GumpID = gumpID;
Hue = hue;
Class = cls;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int GumpID { get; set; }
public int GumpID { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public string Class { get; set; }
public string Class { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ gumppic {X} {Y} {GumpID}{(Hue == 0 ? "" : $"hue={Hue}")}{(string.IsNullOrEmpty(Class) ? "" : $"class={Class}")} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(GumpID.ToString());
if (Hue != 0)
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var hasHue = Hue != 0;
var hasClass = !string.IsNullOrEmpty(Class);
writer.WriteAscii(
hasHue switch
{
writer.Write(HueEquals);
writer.WriteAscii(Hue.ToString());
true when hasClass => $"{{ gumppic {X} {Y} {GumpID} hue={Hue} class={Class} }}",
true => $"{{ gumppic {X} {Y} {GumpID} hue={Hue} }}",
false when hasClass => $"{{ gumppic {X} {Y} {GumpID} class={Class} }}",
false => $"{{ gumppic {X} {Y} {GumpID} }}",
}
if (!string.IsNullOrWhiteSpace(Class))
{
writer.Write(ClassEquals);
writer.WriteAscii(Class);
}
writer.Write((ushort)0x207D); // " }"
}
);
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpImageTileButton.cs *
* *
@ -16,100 +16,55 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpImageTileButton : GumpEntry
{
public class GumpImageTileButton : GumpEntry
public GumpImageTileButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
int itemID, int hue, int width, int height
)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("buttontileart");
public static readonly byte[] LayoutTooltip = Gump.StringToBuffer(" }{ tooltip");
X = x;
Y = y;
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
Type = type;
Param = param;
// Note, on OSI, the tooltip supports ONLY clilocs as far as I can figure out,
// and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
ItemID = itemID;
Hue = hue;
Width = width;
Height = height;
}
public GumpImageTileButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
int itemID, int hue, int width, int height, int localizedTooltip = -1
)
{
X = x;
Y = y;
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
Type = type;
Param = param;
public int X { get; set; }
ItemID = itemID;
Hue = hue;
Width = width;
Height = height;
public int Y { get; set; }
LocalizedTooltip = localizedTooltip;
}
public int NormalID { get; set; }
public int X { get; set; }
public int PressedID { get; set; }
public int Y { get; set; }
public int ButtonID { get; set; }
public int NormalID { get; set; }
public GumpButtonType Type { get; set; }
public int PressedID { get; set; }
public int Param { get; set; }
public int ButtonID { get; set; }
public int ItemID { get; set; }
public GumpButtonType Type { get; set; }
public int Hue { get; set; }
public int Param { get; set; }
public int Width { get; set; }
public int ItemID { get; set; }
public int Height { get; set; }
public int Hue { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int LocalizedTooltip { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
LocalizedTooltip > 0 ?
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}" :
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(NormalID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(PressedID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(((int)Type).ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Param.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ButtonID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ItemID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
if (LocalizedTooltip > 0)
{
writer.Write(LayoutTooltip);
writer.WriteAscii(LocalizedTooltip.ToString());
}
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii(
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}"
);
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpImageTiled.cs *
* *
@ -16,47 +16,31 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpImageTiled : GumpEntry
{
public class GumpImageTiled : GumpEntry
public GumpImageTiled(int x, int y, int width, int height, int gumpID)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("gumppictiled");
X = x;
Y = y;
Width = width;
Height = height;
GumpID = gumpID;
}
public GumpImageTiled(int x, int y, int width, int height, int gumpID)
{
X = x;
Y = y;
Width = width;
Height = height;
GumpID = gumpID;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int GumpID { get; set; }
public int GumpID { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ gumppictiled {X} {Y} {Width} {Height} {GumpID} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(GumpID.ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii($"{{ gumppictiled {X} {Y} {Width} {Height} {GumpID} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpItem.cs *
* *
@ -16,50 +16,28 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpItem : GumpEntry
{
public class GumpItem : GumpEntry
public GumpItem(int x, int y, int itemID, int hue = 0)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("tilepic");
public static readonly byte[] LayoutNameHue = Gump.StringToBuffer("tilepichue");
X = x;
Y = y;
ItemID = itemID;
Hue = hue;
}
public GumpItem(int x, int y, int itemID, int hue = 0)
{
X = x;
Y = y;
ItemID = itemID;
Hue = hue;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int ItemID { get; set; }
public int ItemID { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(Hue == 0 ? LayoutName : LayoutNameHue);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ItemID.ToString());
if (Hue != 0)
{
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
}
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii(Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpItemProperty.cs *
* *
@ -16,25 +16,16 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpItemProperty : GumpEntry
{
public class GumpItemProperty : GumpEntry
public GumpItemProperty(Serial serial) => Serial = serial;
public Serial Serial { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("itemproperty");
public GumpItemProperty(Serial serial) => Serial = serial;
public Serial Serial { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ itemproperty {Serial.Value} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(Serial.Value.ToString());
writer.Write((ushort)0x207D); // " }"
}
writer.WriteAscii($"{{ itemproperty {Serial.Value} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpLabel.cs *
* *
@ -16,42 +16,29 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpLabel : GumpEntry
{
public class GumpLabel : GumpEntry
public GumpLabel(int x, int y, int hue, string text)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("text");
X = x;
Y = y;
Hue = hue;
Text = text;
}
public GumpLabel(int x, int y, int hue, string text)
{
X = x;
Y = y;
Hue = hue;
Text = text;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public string Text { get; set; }
public string Text { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ text {X} {Y} {Hue} {strings.GetOrAdd(Text ?? "")} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(strings.GetOrAdd(Text ?? "").ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var textIndex = strings.GetOrAdd(Text ?? "");
writer.WriteAscii($"{{ text {X} {Y} {Hue} {textIndex} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpLabelCropped.cs *
* *
@ -16,54 +16,35 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpLabelCropped : GumpEntry
{
public class GumpLabelCropped : GumpEntry
public GumpLabelCropped(int x, int y, int width, int height, int hue, string text)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("croppedtext");
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
Text = text;
}
public GumpLabelCropped(int x, int y, int width, int height, int hue, string text)
{
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
Text = text;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public string Text { get; set; }
public string Text { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ croppedtext {X} {Y} {Width} {Height} {Hue} {strings.GetOrAdd(Text ?? "")} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(strings.GetOrAdd(Text ?? "").ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var textIndex = strings.GetOrAdd(Text ?? "");
writer.WriteAscii($"{{ croppedtext {X} {Y} {Width} {Height} {Hue} {textIndex} }}");
}
}

View file

@ -16,25 +16,16 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpMasterGump : GumpEntry
{
public class GumpMasterGump : GumpEntry
public GumpMasterGump(int gumpID) => GumpID = gumpID;
public int GumpID { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("mastergump");
public GumpMasterGump(int gumpID) => GumpID = gumpID;
public int GumpID { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ mastergump {GumpID} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(GumpID.ToString());
writer.Write((ushort)0x207D); // " }"
}
writer.WriteAscii($"{{ mastergump {GumpID} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpPage.cs *
* *
@ -16,24 +16,25 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpPage : GumpEntry
{
public class GumpPage : GumpEntry
private static byte[] _page0 = Gump.StringToBuffer("{ page 0 }");
public GumpPage(int page) => Page = page;
public int Page { get; set; }
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("page");
public GumpPage(int page) => Page = page;
public int Page { get; set; }
public override string Compile(OrderedHashSet<string> strings) => $"{{ page {Page} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
if (Page == 0)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(Page.ToString());
writer.Write((ushort)0x207D); // " }"
writer.Write(_page0);
}
else
{
writer.WriteAscii($"{{ page {Page} }}");
}
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpRadio.cs *
* *
@ -16,56 +16,36 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpRadio : GumpEntry
{
public class GumpRadio : GumpEntry
public GumpRadio(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("radio");
X = x;
Y = y;
InactiveID = inactiveID;
ActiveID = activeID;
InitialState = initialState;
SwitchID = switchID;
}
public GumpRadio(int x, int y, int inactiveID, int activeID, bool initialState, int switchID)
{
X = x;
Y = y;
InactiveID = inactiveID;
ActiveID = activeID;
InitialState = initialState;
SwitchID = switchID;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int InactiveID { get; set; }
public int InactiveID { get; set; }
public int ActiveID { get; set; }
public int ActiveID { get; set; }
public bool InitialState { get; set; }
public bool InitialState { get; set; }
public int SwitchID { get; set; }
public int SwitchID { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ radio {X} {Y} {InactiveID} {ActiveID} {(InitialState ? 1 : 0)} {SwitchID} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(InactiveID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(ActiveID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(InitialState ? '1' : '0');
writer.WriteAscii(' ');
writer.WriteAscii(SwitchID.ToString());
writer.Write((ushort)0x207D); // " }"
switches++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var initialState = InitialState ? "1" : "0";
writer.WriteAscii($"{{ radio {X} {Y} {InactiveID} {ActiveID} {initialState} {SwitchID} }}");
switches++;
}
}

View file

@ -16,58 +16,37 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpSpriteImage : GumpEntry
{
public class GumpSpriteImage : GumpEntry
public GumpSpriteImage(int x, int y, int gumpID, int width, int height, int sx, int sy)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("picinpic");
X = x;
Y = y;
GumpID = gumpID;
Width = width;
Height = height;
SX = sx;
SY = sy;
}
public GumpSpriteImage(int x, int y, int gumpID, int width, int height, int sx, int sy)
{
X = x;
Y = y;
GumpID = gumpID;
Width = width;
Height = height;
SX = sx;
SY = sy;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int GumpID { get; set; }
public int GumpID { get; set; }
public int SX { get; set; }
public int SX { get; set; }
public int SY { get; set; }
public int SY { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ picinpic {X} {Y} {GumpID} {Width} {Height} {SX} {SY} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(GumpID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(SX.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(SY.ToString());
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii($"{{ picinpic {X} {Y} {GumpID} {Width} {Height} {SX} {SY} }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpTextEntry.cs *
* *
@ -16,61 +16,39 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpTextEntry : GumpEntry
{
public class GumpTextEntry : GumpEntry
public GumpTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("textentry");
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
EntryID = entryID;
InitialText = initialText;
}
public GumpTextEntry(int x, int y, int width, int height, int hue, int entryID, string initialText)
{
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
EntryID = entryID;
InitialText = initialText;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public int EntryID { get; set; }
public int EntryID { get; set; }
public string InitialText { get; set; }
public string InitialText { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ textentry {X} {Y} {Width} {Height} {Hue} {EntryID} {strings.GetOrAdd(InitialText ?? "")} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(EntryID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(strings.GetOrAdd(InitialText ?? "").ToString());
writer.Write((ushort)0x207D); // " }"
entries++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var textIndex = strings.GetOrAdd(InitialText ?? "");
writer.WriteAscii($"{{ textentry {X} {Y} {Width} {Height} {Hue} {EntryID} {textIndex} }}");
entries++;
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GumpTextEntryLimited.cs *
* *
@ -16,68 +16,44 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
public class GumpTextEntryLimited : GumpEntry
{
public class GumpTextEntryLimited : GumpEntry
public GumpTextEntryLimited(
int x, int y, int width, int height, int hue, int entryID, string initialText, int size = 0
)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("textentrylimited");
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
EntryID = entryID;
InitialText = initialText;
Size = size;
}
public GumpTextEntryLimited(
int x, int y, int width, int height, int hue, int entryID, string initialText, int size = 0
)
{
X = x;
Y = y;
Width = width;
Height = height;
Hue = hue;
EntryID = entryID;
InitialText = initialText;
Size = size;
}
public int X { get; set; }
public int X { get; set; }
public int Y { get; set; }
public int Y { get; set; }
public int Width { get; set; }
public int Width { get; set; }
public int Height { get; set; }
public int Height { get; set; }
public int Hue { get; set; }
public int Hue { get; set; }
public int EntryID { get; set; }
public int EntryID { get; set; }
public string InitialText { get; set; }
public string InitialText { get; set; }
public int Size { get; set; }
public int Size { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ textentrylimited {X} {Y} {Width} {Height} {Hue} {EntryID} {strings.GetOrAdd(InitialText ?? "")} {Size} }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(X.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Y.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Width.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Height.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Hue.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(EntryID.ToString());
writer.WriteAscii(' ');
writer.WriteAscii(strings.GetOrAdd(InitialText ?? "").ToString());
writer.WriteAscii(' ');
writer.WriteAscii(Size.ToString());
writer.Write((ushort)0x207D); // " }"
entries++;
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
var textIndex = strings.GetOrAdd(InitialText ?? "");
writer.WriteAscii($"{{ textentrylimited {X} {Y} {Width} {Height} {Hue} {EntryID} {textIndex} {Size} }}");
entries++;
}
}

View file

@ -16,41 +16,24 @@
using System.Buffers;
using Server.Collections;
namespace Server.Gumps
namespace Server.Gumps;
// Note, on OSI, the tooltip supports ONLY clilocs as far as I can figure out,
// and the tooltip ONLY works after the buttonTileArt (as far as I can tell from testing)
public class GumpTooltip : GumpEntry
{
public class GumpTooltip : GumpEntry
public GumpTooltip(int number, string args)
{
public static readonly byte[] LayoutName = Gump.StringToBuffer("tooltip");
Number = number;
Args = args;
}
public GumpTooltip(int number, string args)
{
Number = number;
Args = args;
}
public int Number { get; set; }
public int Number { get; set; }
public string Args { get; set; }
public string Args { get; set; }
public override string Compile(OrderedHashSet<string> strings) =>
string.IsNullOrEmpty(Args) ? $"{{ tooltip {Number} }}" : $"{{ tooltip {Number} @{Args}@ }}";
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(LayoutName);
writer.WriteAscii(' ');
writer.WriteAscii(Number.ToString());
if (!string.IsNullOrEmpty(Args))
{
writer.WriteAscii(' ');
writer.WriteAscii('@');
writer.WriteAscii(Args);
writer.WriteAscii('@');
}
writer.Write((ushort)0x207D); // " }"
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.WriteAscii(string.IsNullOrEmpty(Args) ? $"{{ tooltip {Number} }}" : $"{{ tooltip {Number} @{Args}@ }}");
}
}

View file

@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
* Copyright (C) 2019-2021 - ModernUO Development Team *
* Copyright (C) 2019-2022 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: InvalidGumpResponseException.cs *
* *
@ -15,12 +15,11 @@
using System;
namespace Server.Gumps
namespace Server.Gumps;
public class InvalidGumpResponseException : Exception
{
public class InvalidGumpResponseException : Exception
public InvalidGumpResponseException(string reason) : base(reason)
{
public InvalidGumpResponseException(string reason) : base(reason)
{
}
}
}

View file

@ -1,57 +1,56 @@
namespace Server.Gumps
namespace Server.Gumps;
public class TextRelay
{
public class TextRelay
public TextRelay(int entryID, string text)
{
public TextRelay(int entryID, string text)
{
EntryID = entryID;
Text = text;
}
public int EntryID { get; }
public string Text { get; }
EntryID = entryID;
Text = text;
}
public class RelayInfo
{
public RelayInfo(int buttonID, int[] switches, TextRelay[] textEntries)
{
ButtonID = buttonID;
Switches = switches;
TextEntries = textEntries;
}
public int EntryID { get; }
public int ButtonID { get; }
public int[] Switches { get; }
public TextRelay[] TextEntries { get; }
public bool IsSwitched(int switchID)
{
for (var i = 0; i < Switches.Length; ++i)
{
if (Switches[i] == switchID)
{
return true;
}
}
return false;
}
public TextRelay GetTextEntry(int entryID)
{
for (var i = 0; i < TextEntries.Length; ++i)
{
if (TextEntries[i].EntryID == entryID)
{
return TextEntries[i];
}
}
return null;
}
}
public string Text { get; }
}
public class RelayInfo
{
public RelayInfo(int buttonID, int[] switches, TextRelay[] textEntries)
{
ButtonID = buttonID;
Switches = switches;
TextEntries = textEntries;
}
public int ButtonID { get; }
public int[] Switches { get; }
public TextRelay[] TextEntries { get; }
public bool IsSwitched(int switchID)
{
for (var i = 0; i < Switches.Length; ++i)
{
if (Switches[i] == switchID)
{
return true;
}
}
return false;
}
public TextRelay GetTextEntry(int entryID)
{
for (var i = 0; i < TextEntries.Length; ++i)
{
if (TextEntries[i].EntryID == entryID)
{
return TextEntries[i];
}
}
return null;
}
}

View file

@ -109,9 +109,9 @@ namespace Server.Gumps
b.ItemID,
b.Hue,
15,
10,
b.LocalizedTooltip
10
);
AddTooltip(b.LocalizedTooltip);
TextDefinition.AddHtmlText(this, innerX + 84, innerY, 250, 60, b.Label, false, false, 0x7FFF, 0xFFFFFF);
}
}

View file

@ -462,9 +462,9 @@ namespace Server.Spells.Ninjitsu
entries[i].ItemID,
entries[i].Hue,
40 - b.Width / 2 - b.X,
30 - b.Height / 2 - b.Y,
entries[i].Tooltip
30 - b.Height / 2 - b.Y
);
AddTooltip(entries[i].Tooltip);
AddHtmlLocalized(x + 84, y, 250, 60, entries[i].Name, 0x7FFF);
current++;