diff --git a/Projects/Server/Utilities/Html.cs b/Projects/Server/Utilities/Html.cs
index 00b8c91cd..91d2b6f3b 100644
--- a/Projects/Server/Utilities/Html.cs
+++ b/Projects/Server/Utilities/Html.cs
@@ -1,6 +1,6 @@
/*************************************************************************
* ModernUO *
- * Copyright 2019-2023 - ModernUO Development Team *
+ * Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: Html.cs *
* *
@@ -23,65 +23,219 @@ namespace Server;
public static class Html
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Color(this string text, int color) => $"{text}";
+ public static RawInterpolatedStringHandler Color(
+ scoped ref RawInterpolatedStringHandler textHandler,
+ ReadOnlySpan color,
+ int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = textHandler.Text.Color(color, size, fontStyle);
+ textHandler.Clear();
+ return handler;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static RawInterpolatedStringHandler Color(this ReadOnlySpan text, int color) =>
- $"{text}";
+ public static RawInterpolatedStringHandler Color(
+ this ReadOnlySpan text,
+ ReadOnlySpan color,
+ int size = -1,
+ byte fontStyle = 0
+ )
+ {
+ if (color != Span.Empty)
+ {
+ if (size > -1)
+ {
+ if (fontStyle > 0)
+ {
+ return $"{text}";
+ }
+
+ return $"{text}";
+ }
+
+ if (fontStyle > 0)
+ {
+ return $"{text}";
+ }
+
+ return $"{text}";
+ }
+
+ if (size > -1)
+ {
+ if (fontStyle > 0)
+ {
+ return $"{text}";
+ }
+
+ return $"{text}";
+ }
+
+ if (fontStyle > 0)
+ {
+ return $"{text}";
+ }
+
+ return $"{text}";
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Color(this string text, int color, int size) => $"{text}";
+ public static RawInterpolatedStringHandler Color(
+ this ReadOnlySpan text,
+ int color,
+ int size = -1,
+ byte fontStyle = 0
+ )
+ {
+ if (color > -1)
+ {
+ return text.Color($"#{color:X6}", size, fontStyle);
+ }
+
+ return text.Color((ReadOnlySpan)default, size, fontStyle);
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Color(this string text, string color) => $"{text}";
+ public static RawInterpolatedStringHandler Color(
+ scoped ref RawInterpolatedStringHandler textHandler,
+ int color,
+ int size = -1,
+ byte fontStyle = 0
+ )
+ {
+ var handler = textHandler.Text.Color(color, size, fontStyle);
+ textHandler.Clear();
+ return handler;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Color(this string text, string color, int size) =>
- $"{text}";
+ public static string Color(
+ this string text,
+ ReadOnlySpan color,
+ int size = -1,
+ byte fontStyle = 0
+ )
+ {
+ var textHandler = ((ReadOnlySpan)text).Color(color, size, fontStyle);
+ var str = textHandler.Text.ToString();
+ textHandler.Clear();
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Center(this string text) => $"{text}";
+ public static string Color(
+ this string text,
+ int color,
+ int size = -1,
+ byte fontStyle = 0
+ )
+ {
+ var textHandler = ((ReadOnlySpan)text).Color(color, size, fontStyle);
+ var str = textHandler.Text.ToString();
+ textHandler.Clear();
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static RawInterpolatedStringHandler Center(this ReadOnlySpan text) => $"{text}";
+ public static string Center(
+ this string text, int color, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = Center((ReadOnlySpan)text, color, size, fontStyle);
+ var str = handler.Text.ToString();
+ handler.Clear();
+
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Center(this string text, int color) =>
- $"{text}";
+ public static string Center(
+ this string text, ReadOnlySpan color, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = Center((ReadOnlySpan)text, color, size, fontStyle);
+ var str = handler.Text.ToString();
+ handler.Clear();
+
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static RawInterpolatedStringHandler Center(this ReadOnlySpan text, int color) =>
- $"{text}";
+ public static string Center(this string text) => text.Center(-1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Center(this string text, int color, int size) =>
- $"{text}";
+ public static RawInterpolatedStringHandler Center(this ReadOnlySpan text) => Center(text, -1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Center(this string text, string color) =>
- $"{text}";
+ public static RawInterpolatedStringHandler Center(
+ this ReadOnlySpan text, int color, int size = -1, byte fontStyle = 0
+ ) => Color($"{text}", color, size, fontStyle);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Center(this string text, string color, int size) =>
- $"{text}";
+ public static RawInterpolatedStringHandler Center(
+ this ReadOnlySpan text, ReadOnlySpan color, int size = -1, byte fontStyle = 0
+ ) => Color($"{text}", color, size, fontStyle);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Right(this string text) => $"{text}";
+ public static RawInterpolatedStringHandler Center(
+ scoped ref RawInterpolatedStringHandler textHandler, int color = -1, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = textHandler.Text.Center(color, size, fontStyle);
+ textHandler.Clear();
+ return handler;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Right(this string text, int color) =>
- $"{text}";
+ public static string Right(
+ this string text, int color, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = Right((ReadOnlySpan)text, color, size, fontStyle);
+ var str = handler.Text.ToString();
+ handler.Clear();
+
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Right(this string text, int color, int size) =>
- $"{text}";
+ public static string Right(
+ this string text, ReadOnlySpan color, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = Right((ReadOnlySpan)text, color, size, fontStyle);
+ var str = handler.Text.ToString();
+ handler.Clear();
+
+ return str;
+ }
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Right(this string text, string color) => $"{text}";
+ public static string Right(this string text) => text.Right(-1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static string Right(this string text, string color, int size) =>
- $"{text}";
+ public static RawInterpolatedStringHandler Right(
+ scoped ref RawInterpolatedStringHandler textHandler, int color = -1, int size = -1, byte fontStyle = 0
+ )
+ {
+ var handler = textHandler.Text.Right(color, size, fontStyle);
+ textHandler.Clear();
+ return handler;
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static RawInterpolatedStringHandler Right(
+ this ReadOnlySpan text, int color, int size = -1, byte fontStyle = 0
+ ) => Color($"{text}", color, size, fontStyle);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static RawInterpolatedStringHandler Right(
+ this ReadOnlySpan text, ReadOnlySpan color, int size = -1, byte fontStyle = 0
+ ) => Color($"{text}", color, size, fontStyle);
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static RawInterpolatedStringHandler Right(this ReadOnlySpan text) => text.Right(-1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string EscapeHtml(this string input) =>
diff --git a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs
index 08d561c09..479f79c8d 100644
--- a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs
+++ b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs
@@ -37,7 +37,6 @@ public class StaticLayoutTestGump : StaticGump
protected override void BuildStrings(ref GumpStringsBuilder builder)
{
- var petNameText = _petName.AsSpan().Center();
- builder.SetStringSlot("petName", ref petNameText);
+ builder.SetHtmlTextCentered("petName", _petName);
}
}
diff --git a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs
index 4a8bc3147..0e818f161 100644
--- a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs
+++ b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs
@@ -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 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 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 slotKey, ReadOnlySpan 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 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 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 slotKey, ReadOnlySpan 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 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 text)
+ {
+ SetStringSlot(slotKeyHandler.Text, text);
+ slotKeyHandler.Clear();
+ }
+
public void SetStringSlot(ReadOnlySpan slotKey, ReadOnlySpan text)
{
var hash = HashUtility.ComputeHash64(slotKey);
diff --git a/Projects/UOContent/Gumps/PetResurrectGump.cs b/Projects/UOContent/Gumps/PetResurrectGump.cs
index 0dff0c08f..4ccb84518 100644
--- a/Projects/UOContent/Gumps/PetResurrectGump.cs
+++ b/Projects/UOContent/Gumps/PetResurrectGump.cs
@@ -40,8 +40,7 @@ public class PetResurrectGump : StaticGump
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)
diff --git a/Projects/UOContent/Gumps/StaticWarningGump.cs b/Projects/UOContent/Gumps/StaticWarningGump.cs
index f90f1d35b..1129fb36b 100644
--- a/Projects/UOContent/Gumps/StaticWarningGump.cs
+++ b/Projects/UOContent/Gumps/StaticWarningGump.cs
@@ -88,8 +88,7 @@ public abstract class StaticWarningGump : StaticGump 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);