ModernUO/Projects/Server/Gumps/GumpItem.cs
Kamron Batman 3b413371dc
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
2021-01-02 19:08:35 -08:00

65 lines
2 KiB
C#

using System.Buffers;
using Server.Collections;
using Server.Network;
namespace Server.Gumps
{
public class GumpItem : GumpEntry
{
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("tilepic");
private static readonly byte[] m_LayoutNameHue = Gump.StringToBuffer("tilepichue");
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 Y { get; set; }
public int ItemID { get; set; }
public int Hue { get; set; }
public override string Compile(NetState ns) =>
Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}";
public override string Compile(OrderedHashSet<string> strings) =>
Hue == 0 ? $"{{ tilepic {X} {Y} {ItemID} }}" : $"{{ tilepichue {X} {Y} {ItemID} {Hue} }}";
public override void AppendTo(NetState ns, IGumpWriter disp)
{
disp.AppendLayout(Hue == 0 ? m_LayoutName : m_LayoutNameHue);
disp.AppendLayout(X);
disp.AppendLayout(Y);
disp.AppendLayout(ItemID);
if (Hue != 0)
{
disp.AppendLayout(Hue);
}
}
public override void AppendTo(ref SpanWriter writer, OrderedHashSet<string> strings, ref int entries, ref int switches)
{
writer.Write(Hue == 0 ? m_LayoutName : m_LayoutNameHue);
writer.WriteAscii(X.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Y.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ItemID.ToString());
if (Hue != 0)
{
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
}
writer.Write((ushort)0x207D); // " }"
}
}
}