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
@ -7,9 +9,8 @@ namespace Server.Gumps
private static readonly byte[] m_LayoutName = Gump.StringToBuffer("buttontileart");
private static readonly byte[] m_LayoutTooltip = Gump.StringToBuffer(" }{ tooltip");
private GumpButtonType m_Type;
// 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)
// 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 GumpImageTileButton(
int x, int y, int normalID, int pressedID, int buttonID, GumpButtonType type, int param,
@ -21,7 +22,7 @@ namespace Server.Gumps
NormalID = normalID;
PressedID = pressedID;
ButtonID = buttonID;
m_Type = type;
Type = type;
Param = param;
ItemID = itemID;
@ -42,19 +43,7 @@ namespace Server.Gumps
public int ButtonID { get; set; }
public GumpButtonType Type
{
get => m_Type;
set
{
if (m_Type != value)
{
m_Type = value;
var parent = Parent;
}
}
}
public GumpButtonType Type { get; set; }
public int Param { get; set; }
@ -68,17 +57,15 @@ namespace Server.Gumps
public int LocalizedTooltip { get; set; }
public override string Compile(NetState ns)
{
if (LocalizedTooltip > 0)
{
return
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}{{ tooltip {LocalizedTooltip} }}";
}
public override string Compile(NetState ns) =>
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} }}";
return
$"{{ buttontileart {X} {Y} {NormalID} {PressedID} {(int)m_Type} {Param} {ButtonID} {ItemID} {Hue} {Width} {Height} }}";
}
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(NetState ns, IGumpWriter disp)
{
@ -87,7 +74,7 @@ namespace Server.Gumps
disp.AppendLayout(Y);
disp.AppendLayout(NormalID);
disp.AppendLayout(PressedID);
disp.AppendLayout((int)m_Type);
disp.AppendLayout((int)Type);
disp.AppendLayout(Param);
disp.AppendLayout(ButtonID);
@ -102,5 +89,42 @@ namespace Server.Gumps
disp.AppendLayout(LocalizedTooltip);
}
}
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(NormalID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(PressedID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(((int)Type).ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Param.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ButtonID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(ItemID.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Hue.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Width.ToString());
writer.Write((byte)0x20); // ' '
writer.WriteAscii(Height.ToString());
writer.Write((byte)0x20); // ' '
if (LocalizedTooltip > 0)
{
writer.Write(m_LayoutTooltip);
writer.WriteAscii(LocalizedTooltip.ToString());
writer.Write((byte)0x20); // ' '
}
writer.Write((byte)0x7D); // " }"
}
}
}