feat: Adds convenience methods to GumpStringsBuilder (#2124)
This commit is contained in:
parent
6d7b1b8bee
commit
90059c5e74
5 changed files with 269 additions and 36 deletions
|
|
@ -64,6 +64,82 @@ public ref struct GumpStringsBuilder
|
|||
}
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlText(
|
||||
ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, int color, int size = -1,
|
||||
byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlText(ref slotKeyHandler, handler.Text, color, size, fontStyle);
|
||||
handler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlText(
|
||||
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, int color, int size = -1, byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlText(slotKeyHandler.Text, value, color, size, fontStyle);
|
||||
slotKeyHandler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlText(
|
||||
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, int color, int size = -1, byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlText(slotKey, handler.Text, color, size, fontStyle);
|
||||
handler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlText(
|
||||
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, int color, int size = -1, byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
var coloredTextHandler = value.Color(color, size, fontStyle);
|
||||
SetStringSlot(slotKey, ref coloredTextHandler);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlTextCentered(
|
||||
ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, int color = -1,
|
||||
int size = -1, byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlTextCentered(ref slotKeyHandler, handler.Text, color, size, fontStyle);
|
||||
handler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlTextCentered(
|
||||
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, int color = -1, int size = -1,
|
||||
byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlTextCentered(slotKeyHandler.Text, value, color, size, fontStyle);
|
||||
slotKeyHandler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlTextCentered(
|
||||
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, int color = -1, int size = -1,
|
||||
byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
SetHtmlTextCentered(slotKey, handler.Text, color, size, fontStyle);
|
||||
handler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetHtmlTextCentered(
|
||||
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, int color = -1, int size = -1, byte fontStyle = 0
|
||||
)
|
||||
{
|
||||
var coloredTextHandler = value.Center(color, size, fontStyle);
|
||||
SetStringSlot(slotKey, ref coloredTextHandler);
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetStringSlot(ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler)
|
||||
{
|
||||
|
|
@ -74,11 +150,17 @@ public ref struct GumpStringsBuilder
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetStringSlot(ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler)
|
||||
{
|
||||
SetStringSlot(slotKeyHandler.Text, handler.Text);
|
||||
slotKeyHandler.Clear();
|
||||
SetStringSlot(ref slotKeyHandler, handler.Text);
|
||||
handler.Clear();
|
||||
}
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public void SetStringSlot(ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> text)
|
||||
{
|
||||
SetStringSlot(slotKeyHandler.Text, text);
|
||||
slotKeyHandler.Clear();
|
||||
}
|
||||
|
||||
public void SetStringSlot(ReadOnlySpan<char> slotKey, ReadOnlySpan<char> text)
|
||||
{
|
||||
var hash = HashUtility.ComputeHash64(slotKey);
|
||||
|
|
|
|||
|
|
@ -40,8 +40,7 @@ public class PetResurrectGump : StaticGump<PetResurrectGump>
|
|||
|
||||
protected override void BuildStrings(ref GumpStringsBuilder builder)
|
||||
{
|
||||
var petNameText = _pet.Name.AsSpan().Center();
|
||||
builder.SetStringSlot("petName", ref petNameText);
|
||||
builder.SetHtmlTextCentered("petName", _pet.Name);
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState state, in RelayInfo info)
|
||||
|
|
|
|||
|
|
@ -88,8 +88,7 @@ public abstract class StaticWarningGump<T> : StaticGump<T> where T : StaticWarni
|
|||
|
||||
protected sealed override void BuildStrings(ref GumpStringsBuilder builder)
|
||||
{
|
||||
var contentText = Content.AsSpan().Color(ContentColor);
|
||||
builder.SetStringSlot("content", ref contentText);
|
||||
builder.SetHtmlText("content", Content, ContentColor);
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, in RelayInfo info) => _callback?.Invoke(info.ButtonID == 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue