fix(core): Adds Gump component functionality (#377)

- [X] Adds gump close packet
- [X] Fixes gump tooltip
- [X] Adds new compile/append functions for the new gump packets
This commit is contained in:
Kamron Batman 2021-01-02 19:08:35 -08:00 • committed by GitHub
parent cc91fe2b10
commit 3b413371dc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 1696 additions and 137 deletions

View file

@ -1,3 +1,5 @@
using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
@ -6,13 +8,15 @@ namespace Server.Gumps
{
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("gumppic");
private static readonly byte[] m_HueEquals = Gump.StringToBuffer(" hue=");
private static readonly byte[] m_ClassEquals = Gump.StringToBuffer(" class=");
public GumpImage(int x, int y, int gumpID, int hue = 0)
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; }
@ -23,8 +27,13 @@ namespace Server.Gumps
public int Hue { get; set; }
public string Class { get; set; }
public override string Compile(NetState ns) =>
Hue == 0 ? $"{{ gumppic {X} {Y} {GumpID} }}" : $"{{ gumppic {X} {Y} {GumpID} hue={Hue} }}";
$"{{ gumppic {X} {Y} {GumpID}{(Hue == 0 ? "" : $"hue={Hue}")}{(string.IsNullOrEmpty(Class) ? "" : $"class={Class}")} }}";
public override string Compile(OrderedHashSet<string> strings) =>
$"{{ gumppic {X} {Y} {GumpID}{(Hue == 0 ? "" : $"hue={Hue}")}{(string.IsNullOrEmpty(Class) ? "" : $"class={Class}")} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
@ -38,6 +47,40 @@ namespace Server.Gumps
disp.AppendLayout(m_HueEquals);
disp.AppendLayoutNS(Hue);
}
if (!string.IsNullOrEmpty(Class))
{
disp.AppendLayout(m_ClassEquals);
disp.AppendLayoutNS(Class);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write((ushort)0x7B20); // "{ "
writer.Write(m_LayoutName);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(GumpID.ToString());
writer.Write((byte)0x20); // ' '
if (Hue != 0)
{
writer.Write(m_HueEquals);
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
}
if (!string.IsNullOrWhiteSpace(Class))
{
writer.Write(m_ClassEquals);
writer.WriteAscii(Class);
writer.Write((byte)0x20); // ' '
}
writer.Write((byte)0x7D); // '}'
}
}
}