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

@ -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;
}
}