From 7bd5a853a3c108cdbc1df862d173a15959b40506 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Sun, 23 Nov 2025 11:35:31 -0800 Subject: [PATCH] feat: Adds size/style support to gump builders, optimizes EscapeHtml (#2257) > [!IMPORTANT] > **Developer Note** > THIS IS A BREAKING CHANGE TO THE NEW API GUMP. > Please give us feedback in [discord ](https://muo.gg/discord) if you have issues, need help, or have ideas for a better API change! ### Summary * Adds support for size/style to dynamic/static builder. * Drastically simplifies the dynamic/static builder api for AddHtml. * Cleans up some legacy gump files. --- Projects/Server/Utilities/Html.cs | 322 ++++++++---------- .../Tests/Gumps/TestGumps/DynamicTestGump.cs | 2 +- .../Gumps/TestGumps/StaticLayoutTestGump.cs | 2 +- .../Tests/Gumps/TestGumps/StaticTestGump.cs | 2 +- Projects/UOContent/Commands/HelpInfo.cs | 4 +- .../Engines/Bulk Orders/Books/BOBGump.cs | 2 +- .../Engines/ConPVP/Gumps/AcceptTeamGump.cs | 8 +- .../Engines/ConPVP/Gumps/ArenaGump.cs | 2 +- .../Engines/ConPVP/Gumps/ConfirmSignupGump.cs | 8 +- .../Engines/ConPVP/Gumps/LadderGump.cs | 8 +- .../ConPVP/Gumps/TournamentBracketGump.cs | 14 +- .../Factions/Gumps/ElectionManagementGump.cs | 14 +- .../Engines/Help/PageResponseGump.cs | 2 +- .../UOContent/Engines/Help/SpeechLogGump.cs | 2 +- .../Engines/Quests/Core/QuestSystem.cs | 2 +- .../UOContent/Engines/Spawners/SpawnerGump.cs | 4 +- Projects/UOContent/Gumps/AdminGump.cs | 4 +- .../Gumps/Base/DynamicGumpBuilder.cs | 140 ++------ Projects/UOContent/Gumps/Base/Grid/Grid.cs | 77 ----- .../Gumps/Base/GumpStringsBuilder.cs | 64 +--- Projects/UOContent/Gumps/Base/Legacy/Gump.cs | 2 +- .../Gumps/Base/{Grid => Legacy}/GumpGrid.cs | 62 +++- .../UOContent/Gumps/Base/StaticGumpBuilder.cs | 133 ++------ Projects/UOContent/Gumps/ClientGump.cs | 6 +- .../Guilds/New Guild System/OtherGuildInfo.cs | 6 +- Projects/UOContent/Gumps/PetResurrectGump.cs | 2 +- Projects/UOContent/Gumps/StaticWarningGump.cs | 5 +- Projects/UOContent/Gumps/ViewHousesGump.cs | 2 +- Projects/UOContent/Gumps/VirtualCheckGump.cs | 2 +- .../UOContent/Items/Aquarium/AquariumGump.cs | 2 +- .../House Raffle/HouseRaffleManagementGump.cs | 4 +- .../Special/House Raffle/HouseRaffleStone.cs | 3 +- .../Special/Special Scrolls/PowerScroll.cs | 2 +- .../Special Scrolls/ScrollofTranscendence.cs | 2 +- .../Special/Special Scrolls/StatCapScroll.cs | 2 +- Projects/UOContent/Misc/ShardPoller.cs | 2 +- .../Mobiles/Vendors/PlayerBarkeeper.cs | 12 +- .../Systems/JailSystem/JailRecordGump.cs | 28 +- .../Text/TextDefinitionExtensions.cs | 71 ++-- version.json | 2 +- 40 files changed, 398 insertions(+), 635 deletions(-) delete mode 100644 Projects/UOContent/Gumps/Base/Grid/Grid.cs rename Projects/UOContent/Gumps/Base/{Grid => Legacy}/GumpGrid.cs (90%) diff --git a/Projects/Server/Utilities/Html.cs b/Projects/Server/Utilities/Html.cs index 944e2e025..907b90812 100644 --- a/Projects/Server/Utilities/Html.cs +++ b/Projects/Server/Utilities/Html.cs @@ -21,222 +21,131 @@ using Server.Text; namespace Server; +public enum TextAlignment : byte +{ + Left = 0, + Center = 1, + Right = 2 +} + public static class Html { [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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; - } + public static string Center(this string input) => Center(input.AsSpan()); [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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}"; - } + public static string Center(this ReadOnlySpan input) => $"
{input}
"; [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RawInterpolatedStringHandler Color( - this ReadOnlySpan text, - int color, - int size = -1, - byte fontStyle = 0 - ) + public static string Center(ref RawInterpolatedStringHandler input) { - if (color > -1) - { - return text.Color($"#{color:X6}", size, fontStyle); - } - - return text.Color((ReadOnlySpan)default, size, fontStyle); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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, - ReadOnlySpan color, - int size = -1, - byte fontStyle = 0 - ) - { - var textHandler = ((ReadOnlySpan)text).Color(color, size, fontStyle); - var str = textHandler.Text.ToString(); - textHandler.Clear(); + var str = input.Text.Center(); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string Color( - this string text, - int color, - int size = -1, - byte fontStyle = 0 - ) + public static string Center(this string input, int color) => Center(input.AsSpan(), color); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Center(this string input, ReadOnlySpan color) => Center(input.AsSpan(), color); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Center(this ReadOnlySpan input, int color) => + $"
{input}
"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Center(this ReadOnlySpan input, ReadOnlySpan color) => + $"
{input}
"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Center(ref RawInterpolatedStringHandler input, int color) { - var textHandler = ((ReadOnlySpan)text).Color(color, size, fontStyle); - var str = textHandler.Text.ToString(); - textHandler.Clear(); + var str = input.Text.Center(color); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string Center( - this string text, int color, int size = -1, byte fontStyle = 0 - ) + public static string Center(ref RawInterpolatedStringHandler input, ReadOnlySpan color) { - var handler = Center((ReadOnlySpan)text, color, size, fontStyle); - var str = handler.Text.ToString(); - handler.Clear(); - + var str = input.Text.Center(color); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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(); + public static string Color(this string input, int color) => Color(input.AsSpan(), color); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Color(this string input, ReadOnlySpan color) => Color(input.AsSpan(), color); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Color(this ReadOnlySpan input, int color) => $"{input}"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Color(this ReadOnlySpan input, ReadOnlySpan color) => + $"{input}"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Color(ref RawInterpolatedStringHandler input, int color) + { + var str = input.Text.Color(color); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string Center(this string text) => text.Center(-1); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RawInterpolatedStringHandler Center(this ReadOnlySpan text) => Center(text, -1); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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 RawInterpolatedStringHandler Center( - this ReadOnlySpan text, ReadOnlySpan color, int size = -1, byte fontStyle = 0 - ) => Color($"
{text}
", color, size, fontStyle); - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RawInterpolatedStringHandler Center( - scoped ref RawInterpolatedStringHandler textHandler, int color = -1, int size = -1, byte fontStyle = 0 - ) + public static string Color(ref RawInterpolatedStringHandler input, ReadOnlySpan color) { - var handler = textHandler.Text.Center(color, size, fontStyle); - textHandler.Clear(); - return handler; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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(); - + var str = input.Text.Color(color); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - 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(); + public static string Right(this string input) => Right(input.AsSpan()); + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Right(this ReadOnlySpan input) => $"{input}"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Right(ref RawInterpolatedStringHandler input) + { + var str = input.Text.Right(); + input.Clear(); return str; } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static string Right(this string text) => text.Right(-1); + public static string Right(this string input, int color) => Right(input.AsSpan(), color); [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static RawInterpolatedStringHandler Right( - scoped ref RawInterpolatedStringHandler textHandler, int color = -1, int size = -1, byte fontStyle = 0 - ) + public static string Right(this string input, ReadOnlySpan color) => Right(input.AsSpan(), color); + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Right(this ReadOnlySpan input, int color) => + $"{input}"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Right(this ReadOnlySpan input, ReadOnlySpan color) => + $"{input}"; + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static string Right(ref RawInterpolatedStringHandler input, int color) { - var handler = textHandler.Text.Right(color, size, fontStyle); - textHandler.Clear(); - return handler; + var str = input.Text.Right(color); + input.Clear(); + return str; } [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); + public static string Right(ref RawInterpolatedStringHandler input, ReadOnlySpan color) + { + var str = input.Text.Right(color); + input.Clear(); + return str; + } private static readonly SearchValues _htmlSearchValues = SearchValues.Create('<', '>', '&', '"', '\''); @@ -304,4 +213,71 @@ public static class Html builder.Dispose(); return result; } + + public static string Build( + ReadOnlySpan text, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left + ) + { + var arr = STArrayPool.Shared.Rent(BuildCharCount(text, color)); + var bytesWritten = Build(text, arr.AsSpan(), color, size, fontStyle, align); + + var result = arr.AsSpan(0, bytesWritten).ToString(); + STArrayPool.Shared.Return(arr); + + return result; + } + + public static int BuildCharCount(ReadOnlySpan text, ReadOnlySpan color) => 61 + text.Length + color.Length; + + public static int Build( + ReadOnlySpan text, Span dest, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left + ) + { + using var builder = new ValueStringBuilder(dest); + if (align == TextAlignment.Right) + { + builder.Append(""); + } + else if (align == TextAlignment.Center) + { + builder.Append("
"); + } + + if (color.Length > 0 || size > -1 || fontStyle > 0) + { + builder.Append(" 0) + { + builder.Append($" COLOR={color}"); + } + + if (size > -1) + { + builder.Append($" SIZE={size}"); + } + + if (fontStyle > 0) + { + builder.Append($" STYLE={fontStyle}"); + } + builder.Append($">{text}"); + } + else + { + builder.Append(text); + } + + if (align == TextAlignment.Right) + { + builder.Append(""); + } + else if (align == TextAlignment.Center) + { + builder.Append("
"); + } + + return builder.Length; + } } diff --git a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/DynamicTestGump.cs b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/DynamicTestGump.cs index 9ad3e0ae2..998e4c537 100644 --- a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/DynamicTestGump.cs +++ b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/DynamicTestGump.cs @@ -27,7 +27,7 @@ public class DynamicTestGump : DynamicGump builder.AddItem(218, 95, 0xCB0); builder.AddHtml(30, 30, 150, 75, "
Wilt thou sanctify the resurrection of:
"); - builder.AddHtml(30, 70, 150, 25, $"
{_petName}
", true); + builder.AddHtml(30, 70, 150, 25, _petName, align: TextAlignment.Center, background: true); builder.AddButton(40, 105, 0x81A, 0x81B, 0x1); // Okay builder.AddButton(110, 105, 0x819, 0x818, 0x2); // Cancel diff --git a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs index 85f5ec732..7e1859161 100644 --- a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs +++ b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs @@ -35,6 +35,6 @@ public class StaticLayoutTestGump : StaticGump protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetHtmlTextCentered("petName", _petName); + builder.SetHtmlText("petName", _petName, align: TextAlignment.Center); } } diff --git a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticTestGump.cs b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticTestGump.cs index ce616116e..ea67720f5 100644 --- a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticTestGump.cs +++ b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticTestGump.cs @@ -24,7 +24,7 @@ public class StaticTestGump : StaticGump builder.AddItem(218, 95, 0xCB0); builder.AddHtml(30, 30, 150, 75, "
Wilt thou sanctify the resurrection of:
"); - builder.AddHtml(30, 70, 150, 25, "
Test
", true); + builder.AddHtml(30, 70, 150, 25, "Test", align: TextAlignment.Center, background: true); builder.AddButton(40, 105, 0x81A, 0x81B, 0x1); // Okay builder.AddButton(110, 105, 0x819, 0x818, 0x2); // Cancel diff --git a/Projects/UOContent/Commands/HelpInfo.cs b/Projects/UOContent/Commands/HelpInfo.cs index 0361fbadc..f9686f37e 100644 --- a/Projects/UOContent/Commands/HelpInfo.cs +++ b/Projects/UOContent/Commands/HelpInfo.cs @@ -361,7 +361,7 @@ public static class HelpInfo builder.AddPage(); builder.AddBackground(0, 0, _width, _height, 5054); - builder.AddHtml(10, 10, _width - 20, 20, _info.Name.Center(0xFF0000)); + builder.AddHtml(10, 10, _width - 20, 20, _info.Name, color: "#FF0000", align: TextAlignment.Center); using var sb = ValueStringBuilder.Create(); @@ -412,7 +412,7 @@ public static class HelpInfo } sb.Append(_info.Description); - builder.AddHtml(10, 40, _width - 20, _height - 80, sb.ToString(), false, true); + builder.AddHtml(10, 40, _width - 20, _height - 80, sb.AsSpan(true), background: false, scrollbar: true); } } } diff --git a/Projects/UOContent/Engines/Bulk Orders/Books/BOBGump.cs b/Projects/UOContent/Engines/Bulk Orders/Books/BOBGump.cs index 8dd3073f1..7be389e49 100644 --- a/Projects/UOContent/Engines/Bulk Orders/Books/BOBGump.cs +++ b/Projects/UOContent/Engines/Bulk Orders/Books/BOBGump.cs @@ -157,7 +157,7 @@ public class BOBGump : DynamicGump builder.AddHtmlLocalized(576, 64, 200, 32, 1062227, LabelColor); // Set builder.AddButton(450, 416, 4005, 4007, 4); - builder.AddHtml(485, 416, 120, 20, "Price all"); + builder.AddHtml(485, 416, 120, 20, "Price all"); } } diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/AcceptTeamGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/AcceptTeamGump.cs index d7a93a578..f8b7af812 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/AcceptTeamGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/AcceptTeamGump.cs @@ -5,6 +5,7 @@ using System.Text; using Server.Gumps; using Server.Mobiles; using Server.Network; +using Server.Text; namespace Server.Engines.ConPVP { @@ -82,7 +83,7 @@ namespace Server.Engines.ConPVP AddImage(215, -43, 0xEE40); - var sb = new StringBuilder(); + using var sb = ValueStringBuilder.Create(128); if (tourney.TourneyType == TourneyType.FreeForAll) { @@ -117,12 +118,13 @@ namespace Server.Engines.ConPVP if (tourney.EventController != null) { - sb.Append(' ').Append(tourney.EventController.Title); + sb.Append(' '); + sb.Append(tourney.EventController.Title); } sb.Append(" Tournament Invitation"); - AddBorderedText(22, 22, 294, 20, sb.ToString().Center(), LabelColor32, BlackColor32); + AddBorderedText(22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32); AddBorderedText( 22, diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs index 67f8a0047..98b95964d 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/ArenaGump.cs @@ -189,7 +189,7 @@ namespace Server.Engines.ConPVP AddBorderedText(x + 5, y + 5, 325 - 5, sb.ToString(), color, 0); x += 325; - AddBorderedText(x, y + 5, 40, ar.Spectators.ToString().Center(), color, 0); + AddBorderedText(x, y + 5, 40, Html.Center($"{ar.Spectators}"), color, 0); } } diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/ConfirmSignupGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/ConfirmSignupGump.cs index 376042f72..9e6c45622 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/ConfirmSignupGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/ConfirmSignupGump.cs @@ -7,6 +7,7 @@ using Server.Gumps; using Server.Mobiles; using Server.Network; using Server.Targeting; +using Server.Text; namespace Server.Engines.ConPVP { @@ -92,7 +93,7 @@ namespace Server.Engines.ConPVP AddImage(215, -43, 0xEE40); // AddImage( 330, 141, 0x8BA ); - var sb = new StringBuilder(); + using var sb = ValueStringBuilder.Create(128); if (tourney.TourneyType == TourneyType.FreeForAll) { @@ -127,12 +128,13 @@ namespace Server.Engines.ConPVP if (tourney.EventController != null) { - sb.Append(' ').Append(tourney.EventController.Title); + sb.Append(' '); + sb.Append(tourney.EventController.Title); } sb.Append(" Tournament Signup"); - AddBorderedText(22, 22, 294, 20, sb.ToString().Center(), LabelColor32, BlackColor32); + AddBorderedText(22, 22, 294, 20, sb.AsSpan().Center(), LabelColor32, BlackColor32); AddBorderedText( 22, 50, diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/LadderGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/LadderGump.cs index 088d26789..db6ed89d0 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/LadderGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/LadderGump.cs @@ -125,7 +125,7 @@ namespace Server.Engines.ConPVP height - 12 - 2 - 18, 400, 20, - $"Top {lc} of {m_List.Count:N0} duelists, page {page + 1} of {(lc + 14) / 15}".Color(0xFFC000) + Html.Color($"Top {lc} of {m_List.Count:N0} duelists, page {page + 1} of {(lc + 14) / 15}", 0xFFC000) ); AddColumnHeader(75, "Rank"); @@ -174,7 +174,7 @@ namespace Server.Engines.ConPVP // AddImageTiled( 21, y + 6, width, 8, 0x2617 ); AddImageTiled(x + 3, y + 4, width, 11, 0x806); - AddBorderedText(x, y, 115, level.ToString().Center(), 0xFFFFFF, 0); + AddBorderedText(x, y, 115, Html.Center($"{level}"), 0xFFFFFF, 0); x += 115; var mob = entry.Mobile; @@ -189,10 +189,10 @@ namespace Server.Engines.ConPVP AddBorderedText(x + 5, y, 115 - 5, mob.Name, 0xFFFFFF, 0); x += 115; - AddBorderedText(x, y, 60, entry.Wins.ToString().Center(), 0xFFFFFF, 0); + AddBorderedText(x, y, 60, Html.Center($"{entry.Wins}"), 0xFFFFFF, 0); x += 60; - AddBorderedText(x, y, 60, entry.Losses.ToString().Center(), 0xFFFFFF, 0); + AddBorderedText(x, y, 60, Html.Center($"{entry.Losses}"), 0xFFFFFF, 0); x += 60; // AddBorderedText( 292 + 15, y, 115 - 30, String.Format( "{0}
/
{1}
", entry.Wins, entry.Losses ), 0xFFC000, 0 ); diff --git a/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs b/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs index ae7d3daac..436832d72 100644 --- a/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs +++ b/Projects/UOContent/Engines/ConPVP/Gumps/TournamentBracketGump.cs @@ -5,6 +5,7 @@ using System.Text; using Server.Gumps; using Server.Mobiles; using Server.Network; +using Server.Text; namespace Server.Engines.ConPVP { @@ -51,7 +52,7 @@ namespace Server.Engines.ConPVP AddPage(0); AddBackground(0, 0, 300, 300, 9380); - var sb = new StringBuilder(); + using var sb = ValueStringBuilder.Create(128); if (tourney.TourneyType == TourneyType.FreeForAll) { @@ -86,12 +87,13 @@ namespace Server.Engines.ConPVP if (tourney.EventController != null) { - sb.Append(' ').Append(tourney.EventController.Title); + sb.Append(' '); + sb.Append(tourney.EventController.Title); } sb.Append(" Tournament Bracket"); - AddHtml(25, 35, 250, 20, sb.ToString().Center()); + AddHtml(25, 35, 250, 20, sb.AsSpan().Center()); AddRightArrow(25, 53, ToButtonID(0, 4), "Rules"); AddRightArrow(25, 71, ToButtonID(0, 1), "Participants"); @@ -278,7 +280,7 @@ namespace Server.Engines.ConPVP ?? new List(tourney.Participants); AddLeftArrow(25, 11, ToButtonID(0, 0)); - AddHtml(25, 35, 250, 20, $"{pList.Count} Participant{(pList.Count == 1 ? "" : "s")}".Center()); + AddHtml(25, 35, 250, 20, Html.Center($"{pList.Count} Participant{(pList.Count == 1 ? "" : "s")}")); StartPage(out var index, out var count, out var y, 12); @@ -347,7 +349,7 @@ namespace Server.Engines.ConPVP AddHtml(25, y, 200, 20, "Log:"); y += 20; - var sb = new StringBuilder(); + using var sb = ValueStringBuilder.Create(); for (var i = 0; i < part.Log.Count; ++i) { @@ -364,7 +366,7 @@ namespace Server.Engines.ConPVP sb.Append("Nothing logged yet."); } - AddHtml(25, y, 250, 150, sb.ToString().Color(BlackColor32), false, true); + AddHtml(25, y, 250, 150, sb.AsSpan().Color(BlackColor32), false, true); break; } diff --git a/Projects/UOContent/Engines/Factions/Gumps/ElectionManagementGump.cs b/Projects/UOContent/Engines/Factions/Gumps/ElectionManagementGump.cs index 5c9a6fad5..723864983 100644 --- a/Projects/UOContent/Engines/Factions/Gumps/ElectionManagementGump.cs +++ b/Projects/UOContent/Engines/Factions/Gumps/ElectionManagementGump.cs @@ -32,7 +32,7 @@ public class ElectionManagementGump : Gump AddHtml(145, 35, 100, 20, (candidate.Mobile == null ? "null" : candidate.Mobile.Name).Color(LabelColor)); AddHtml(45, 55, 100, 20, "Vote Count:".Color(LabelColor)); - AddHtml(145, 55, 100, 20, candidate.Votes.ToString().Color(LabelColor)); + AddHtml(145, 55, 100, 20, Html.Color($"{candidate.Votes}", LabelColor)); AddButton(12, 73, 4005, 4007, 1); AddHtml(45, 75, 100, 20, "Drop Candidate".Color(LabelColor)); @@ -88,9 +88,9 @@ public class ElectionManagementGump : Gump AddHtml(x + 2, 140 + idx * 20, 150, 20, mobile.Name.Color(LabelColor)); x += 150; } - else if (obj is IPAddress) + else if (obj is IPAddress ip) { - AddHtml(x, 140 + idx * 20, 100, 20, obj.ToString().Center(LabelColor)); + AddHtml(x, 140 + idx * 20, 100, 20, Html.Center($"{ip}", LabelColor)); x += 100; } else if (obj is DateTime time) @@ -106,7 +106,7 @@ public class ElectionManagementGump : Gump } else if (obj is int i1) { - AddHtml(x, 140 + idx * 20, 60, 20, $"{i1}%".Center(LabelColor)); + AddHtml(x, 140 + idx * 20, 60, 20, Html.Center($"{i1}%", LabelColor)); x += 60; } } @@ -120,7 +120,7 @@ public class ElectionManagementGump : Gump AddHtml(10, 10, 268, 20, "Election Management".Center(LabelColor)); AddHtml(45, 35, 100, 20, "Current State:".Color(LabelColor)); - AddHtml(145, 35, 100, 20, election.State.ToString().Color(LabelColor)); + AddHtml(145, 35, 100, 20, Html.Color($"{election.State}", LabelColor)); AddButton(12, 53, 4005, 4007, 1); AddHtml(45, 55, 100, 20, "Transition Time:".Color(LabelColor)); @@ -147,7 +147,7 @@ public class ElectionManagementGump : Gump AddButton(13, 118 + i * 20, 4005, 4007, 2 + i); AddHtml(47, 120 + i * 20, 150, 20, mob.Name.Color(LabelColor)); - AddHtml(195, 120 + i * 20, 80, 20, cd.Votes.ToString().Center(LabelColor)); + AddHtml(195, 120 + i * 20, 80, 20, Html.Center($"{cd.Votes}", LabelColor)); } } } @@ -200,4 +200,4 @@ public class ElectionManagementGump : Gump } } } -} \ No newline at end of file +} diff --git a/Projects/UOContent/Engines/Help/PageResponseGump.cs b/Projects/UOContent/Engines/Help/PageResponseGump.cs index 106eb4131..ec00f5849 100644 --- a/Projects/UOContent/Engines/Help/PageResponseGump.cs +++ b/Projects/UOContent/Engines/Help/PageResponseGump.cs @@ -25,7 +25,7 @@ public sealed class PageResponseGump : StaticGump //
Ultima Online Help Response
builder.AddHtmlLocalized(150, 40, 360, 40, 1062610); - builder.AddHtml(80, 90, 480, 290, $"{_name} tells {_from.Name}: {_text}", true, true); + builder.AddHtml(80, 90, 480, 290, $"{_name} tells {_from.Name}: {_text}", background: true, scrollbar: true); // Clicking the OKAY button will remove the response you have received. builder.AddHtmlLocalized(80, 390, 480, 40, 1062611); diff --git a/Projects/UOContent/Engines/Help/SpeechLogGump.cs b/Projects/UOContent/Engines/Help/SpeechLogGump.cs index 54a6aa6f3..eae679656 100644 --- a/Projects/UOContent/Engines/Help/SpeechLogGump.cs +++ b/Projects/UOContent/Engines/Help/SpeechLogGump.cs @@ -46,7 +46,7 @@ namespace Server.Engines.Help 10, 280, 20, - $"SPEECH LOG - {playerName} ({playerAccount.FixHtmlFormattable()})".Center(0xA0A0FF) + Html.Center($"SPEECH LOG - {playerName} ({playerAccount.FixHtmlFormattable()})", 0xA0A0FF) ); var lastPage = (log.Count - 1) / MaxEntriesPerPage; diff --git a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs index 2b0ace340..9670f8975 100644 --- a/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs +++ b/Projects/UOContent/Engines/Quests/Core/QuestSystem.cs @@ -693,7 +693,7 @@ namespace Server.Engines.Quests } else { - AddHtml(x, y, width, height, message.ToString().Color(color.C16216()), back, scroll); + AddHtml(x, y, width, height, Html.Color($"{message}", color.C16216()), back, scroll); } } } diff --git a/Projects/UOContent/Engines/Spawners/SpawnerGump.cs b/Projects/UOContent/Engines/Spawners/SpawnerGump.cs index e7f9cf1be..a589c6f76 100644 --- a/Projects/UOContent/Engines/Spawners/SpawnerGump.cs +++ b/Projects/UOContent/Engines/Spawners/SpawnerGump.cs @@ -167,8 +167,8 @@ public class SpawnerGump : Gump totalWeight += spawnerEntry.SpawnedProbability; } - AddHtml(270, 308 + offset, 35, 20, totalSpawns.ToString().Center(0xF4F4F4)); - AddHtml(308, 308 + offset, 35, 20, totalWeight.ToString().Center(0xF4F4F4)); + AddHtml(270, 308 + offset, 35, 20, Html.Center($"{totalSpawns}", 0xF4F4F4)); + AddHtml(308, 308 + offset, 35, 20, Html.Center($"{totalWeight}",0xF4F4F4)); AddHtml(5, 1, 161, 20, $"{spawner.Name} ({totalSpawned}/{spawner.Count})"); diff --git a/Projects/UOContent/Gumps/AdminGump.cs b/Projects/UOContent/Gumps/AdminGump.cs index 00e65887d..7dc944e82 100644 --- a/Projects/UOContent/Gumps/AdminGump.cs +++ b/Projects/UOContent/Gumps/AdminGump.cs @@ -1035,7 +1035,7 @@ namespace Server.Gumps for (int i = 0, index = listPage * 6; i < 6 && index >= 0 && index < m_List.Count; ++i, ++index) { - AddHtml(18, 243 + i * 22, 114, 20, m_List[index].ToString().Color(LabelColor32)); + AddHtml(18, 243 + i * 22, 114, 20, Html.Color($"{m_List[index]}", LabelColor32)); AddButton(130, 242 + i * 22, 0xFA2, 0xFA4, GetButtonID(8, index)); AddButton(160, 242 + i * 22, 0xFA8, 0xFAA, GetButtonID(9, index)); AddButton(190, 242 + i * 22, 0xFB1, 0xFB3, GetButtonID(10, index)); @@ -1237,7 +1237,7 @@ namespace Server.Gumps break; } - AddHtml(10, 125, 400, 20, firewallEntry.ToString().Center(LabelColor32)); + AddHtml(10, 125, 400, 20, Html.Center($"{firewallEntry}", LabelColor32)); AddButtonLabeled(20, 150, GetButtonID(6, 3), "Remove"); diff --git a/Projects/UOContent/Gumps/Base/DynamicGumpBuilder.cs b/Projects/UOContent/Gumps/Base/DynamicGumpBuilder.cs index afe345bb9..198ac16fa 100644 --- a/Projects/UOContent/Gumps/Base/DynamicGumpBuilder.cs +++ b/Projects/UOContent/Gumps/Base/DynamicGumpBuilder.cs @@ -78,114 +78,33 @@ public ref struct DynamicGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtml( - int x, - int y, - int width, - int height, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false + int x, int y, int width, int height, ReadOnlySpan text, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false ) { - WriteInternalizedString(text); + if (color.Length > 0 || size != -1 || fontStyle != 0 || align != TextAlignment.Left) + { + var arr = STArrayPool.Shared.Rent(Html.BuildCharCount(text, color)); + var bytesWritten = Html.Build(text, arr.AsSpan(), color, size, fontStyle, align); + + WriteInternalizedString(arr.AsSpan(0, bytesWritten)); + STArrayPool.Shared.Return(arr); + } + else + { + WriteInternalizedString(text); + } + _gumpBuilder.AddHtml(x, y, width, height, _stringsCount++, background, scrollbar); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtml( - int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, - bool background = false, bool scrollbar = false + int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, ReadOnlySpan color = default, int size = -1, + byte fontStyle = 0, TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false ) { - AddHtml(x, y, width, height, handler.Text, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtml( - int x, - int y, - int width, - int height, - int color, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false - ) - { - var handler = text.Color(color); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtml( - int x, - int y, - int width, - int height, - int color, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - AddHtml(x, y, width, height, color, handler.Text, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, int y, int width, int height, ReadOnlySpan text, bool background = false, bool scrollbar = false - ) - { - var handler = text.Center(); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - AddHtmlCentered(x, y, width, height, handler.Text, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - int color, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false - ) - { - var handler = text.Center(color); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - int color, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - AddHtmlCentered(x, y, width, height, color, handler.Text, background, scrollbar); + AddHtml(x, y, width, height, handler.Text, color, size, fontStyle, align, background, scrollbar); handler.Clear(); } @@ -201,14 +120,7 @@ public ref struct DynamicGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtmlLocalized( - int x, - int y, - int width, - int height, - int number, - ReadOnlySpan args, - int color, - bool background = false, + int x, int y, int width, int height, int number, ReadOnlySpan args, int color, bool background = false, bool scrollbar = false ) => _gumpBuilder.AddHtmlLocalized(x, y, width, height, number, args, color, background, scrollbar); @@ -232,18 +144,8 @@ public ref struct DynamicGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddImageTiledButton( - int x, - int y, - int normalId, - int pressedId, - int buttonId, - GumpButtonType type, - int param, - int itemId, - int hue, - int width, - int height, - int localizedTooltip = -1 + int x, int y, int normalId, int pressedId, int buttonId, GumpButtonType type, int param, int itemId, int hue, + int width, int height, int localizedTooltip = -1 ) => _gumpBuilder.AddImageTiledButton( x, y, normalId, pressedId, buttonId, type, param, itemId, hue, width, height, localizedTooltip ); diff --git a/Projects/UOContent/Gumps/Base/Grid/Grid.cs b/Projects/UOContent/Gumps/Base/Grid/Grid.cs deleted file mode 100644 index 7dd7a5372..000000000 --- a/Projects/UOContent/Gumps/Base/Grid/Grid.cs +++ /dev/null @@ -1,77 +0,0 @@ -/************************************************************************* - * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * - * Email: hi@modernuo.com * - * File: Grid.cs * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - *************************************************************************/ - -using System.Collections.Generic; - -namespace Server.Gumps; - -public enum GridHues -{ - White = 2049, // Change to 0x480 if you have old hues.mul - Black = 0, -} - -public static class GridColors -{ - public const string Gold = "#ffc959"; - public const string White = "#ffffff"; - public const string Blue = "#1D63DC"; - public const string LightBlue = "#7799EE"; - public const string Green = "#80E732"; - public const string Orange = "#F28B00"; - public const string Purple = "#F3ACF6"; - public const string Red = "#B52B2D"; - public const string LightGreen = "#E6FFC0"; - public const string Yellow = "#FFFFBB"; -} - -public class ListItem -{ - public int X { get; set; } - public int Y { get; set; } - public int Index { get; set; } - public Col[] Cols { get; set; } -} - -public class Col -{ - public int X { get; set; } - public int Width { get; set; } - public int HCenter => X + Width / 2; - public int HEnd => X + Width; -} - -public class Row -{ - public int Y { get; set; } - public int Height { get; set; } - public int VCenter => Y + Height / 2; - public int VEnd => Y + Height; -} - -public class Grid -{ - public string Name { get; set; } - public int Height { get; set; } - public int Width { get; set; } - public List Columns { get; set; } = new(); - public List Rows { get; set; } = new(); -} - -public class Swap -{ - public int Index { get; set; } - public int Size { get; set; } -} diff --git a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs index 0e818f161..a5d8de052 100644 --- a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs +++ b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs @@ -66,78 +66,46 @@ public ref struct GumpStringsBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetHtmlText( - ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, int color, int size = -1, - byte fontStyle = 0 + ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler, ReadOnlySpan color = default, int size = -1, + byte fontStyle = 0, TextAlignment align = TextAlignment.Left ) { - SetHtmlText(ref slotKeyHandler, handler.Text, color, size, fontStyle); + SetHtmlText(slotKeyHandler.Text, handler.Text, color, size, fontStyle, align); + slotKeyHandler.Clear(); handler.Clear(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetHtmlText( - ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan value, int color, int size = -1, byte fontStyle = 0 + ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan value, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left ) { - SetHtmlText(slotKeyHandler.Text, value, color, size, fontStyle); + SetHtmlText(slotKeyHandler.Text, value, color, size, fontStyle, align); slotKeyHandler.Clear(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetHtmlText( - ReadOnlySpan slotKey, ref RawInterpolatedStringHandler handler, int color, int size = -1, byte fontStyle = 0 + ReadOnlySpan slotKey, ref RawInterpolatedStringHandler handler, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left ) { - SetHtmlText(slotKey, handler.Text, color, size, fontStyle); + SetHtmlText(slotKey, handler.Text, color, size, fontStyle, align); handler.Clear(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void SetHtmlText( - ReadOnlySpan slotKey, ReadOnlySpan value, int color, int size = -1, byte fontStyle = 0 + ReadOnlySpan slotKey, ReadOnlySpan value, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left ) { - var coloredTextHandler = value.Color(color, size, fontStyle); - SetStringSlot(slotKey, ref coloredTextHandler); - } + var arr = STArrayPool.Shared.Rent(Html.BuildCharCount(value, color)); + var bytesWritten = Html.Build(value, arr.AsSpan(), color, size, fontStyle, align); - [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); + SetStringSlot(slotKey, arr.AsSpan(0, bytesWritten)); + STArrayPool.Shared.Return(arr); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/Projects/UOContent/Gumps/Base/Legacy/Gump.cs b/Projects/UOContent/Gumps/Base/Legacy/Gump.cs index 0bcd9dd3c..bf6928744 100644 --- a/Projects/UOContent/Gumps/Base/Legacy/Gump.cs +++ b/Projects/UOContent/Gumps/Base/Legacy/Gump.cs @@ -169,7 +169,7 @@ public class Gump : BaseGump public void AddLabelHtml(int x, int y, int width, int height, string text, string hue, int size = 4, bool center = true) { - AddHtml(x, y, width, height, center ? text.Center(hue, size) : text.Color(hue, size)); + AddHtml(x, y, width, height, Html.Build(text, hue, size, align: center ? TextAlignment.Center : TextAlignment.Left)); } public void AddLabelCropped(int x, int y, int width, int height, int hue, string text) diff --git a/Projects/UOContent/Gumps/Base/Grid/GumpGrid.cs b/Projects/UOContent/Gumps/Base/Legacy/GumpGrid.cs similarity index 90% rename from Projects/UOContent/Gumps/Base/Grid/GumpGrid.cs rename to Projects/UOContent/Gumps/Base/Legacy/GumpGrid.cs index 6b5e80b05..dfa0dcc78 100644 --- a/Projects/UOContent/Gumps/Base/Grid/GumpGrid.cs +++ b/Projects/UOContent/Gumps/Base/Legacy/GumpGrid.cs @@ -1,6 +1,6 @@ /************************************************************************* * ModernUO * - * Copyright 2019-2023 - ModernUO Development Team * + * Copyright 2019-2025 - ModernUO Development Team * * Email: hi@modernuo.com * * File: GumpGrid.cs * * * @@ -523,3 +523,63 @@ public class GumpGrid : Gump return null; } } + +public enum GridHues +{ + White = 2049, // Change to 0x480 if you have old hues.mul + Black = 0, +} + +public static class GridColors +{ + public const string Gold = "#ffc959"; + public const string White = "#ffffff"; + public const string Blue = "#1D63DC"; + public const string LightBlue = "#7799EE"; + public const string Green = "#80E732"; + public const string Orange = "#F28B00"; + public const string Purple = "#F3ACF6"; + public const string Red = "#B52B2D"; + public const string LightGreen = "#E6FFC0"; + public const string Yellow = "#FFFFBB"; +} + +public class ListItem +{ + public int X { get; set; } + public int Y { get; set; } + public int Index { get; set; } + public Col[] Cols { get; set; } +} + +public class Col +{ + public int X { get; set; } + public int Width { get; set; } + public int HCenter => X + Width / 2; + public int HEnd => X + Width; +} + +public class Row +{ + public int Y { get; set; } + public int Height { get; set; } + public int VCenter => Y + Height / 2; + public int VEnd => Y + Height; +} + +public class Grid +{ + public string Name { get; set; } + public int Height { get; set; } + public int Width { get; set; } + public List Columns { get; set; } = new(); + public List Rows { get; set; } = new(); +} + +public class Swap +{ + public int Index { get; set; } + public int Size { get; set; } +} + diff --git a/Projects/UOContent/Gumps/Base/StaticGumpBuilder.cs b/Projects/UOContent/Gumps/Base/StaticGumpBuilder.cs index 5e7702dab..00439ceda 100644 --- a/Projects/UOContent/Gumps/Base/StaticGumpBuilder.cs +++ b/Projects/UOContent/Gumps/Base/StaticGumpBuilder.cs @@ -91,13 +91,7 @@ public ref struct StaticGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtmlPlaceholder( - int x, - int y, - int width, - int height, - ReadOnlySpan slotKey, - bool background = false, - bool scrollbar = false + int x, int y, int width, int height, ReadOnlySpan slotKey, bool background = false, bool scrollbar = false ) { var index = _gumpBuilder.AddHtmlPlaceholder(x, y, width, height, background, scrollbar); @@ -106,12 +100,7 @@ public ref struct StaticGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtmlPlaceholder( - int x, - int y, - int width, - int height, - ref RawInterpolatedStringHandler handler, - bool background = false, + int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, bool background = false, bool scrollbar = false ) { @@ -121,115 +110,33 @@ public ref struct StaticGumpBuilder [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtml( - int x, - int y, - int width, - int height, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false + int x, int y, int width, int height, ReadOnlySpan text, ReadOnlySpan color = default, int size = -1, byte fontStyle = 0, + TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false ) { - WriteInternalizedString(text); + if (color.Length > 0 || size != -1 || fontStyle != 0 || align != TextAlignment.Left) + { + var arr = STArrayPool.Shared.Rent(Html.BuildCharCount(text, color)); + var bytesWritten = Html.Build(text, arr.AsSpan(), color, size, fontStyle, align); + + WriteInternalizedString(arr.AsSpan(0, bytesWritten)); + STArrayPool.Shared.Return(arr); + } + else + { + WriteInternalizedString(text); + } + _gumpBuilder.AddHtml(x, y, width, height, _stringsCount++, background, scrollbar); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public void AddHtml( - int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, - bool background = false, bool scrollbar = false + int x, int y, int width, int height, ref RawInterpolatedStringHandler handler, ReadOnlySpan color = default, int size = -1, + byte fontStyle = 0, TextAlignment align = TextAlignment.Left, bool background = false, bool scrollbar = false ) { - AddHtml(x, y, width, height, handler.Text, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtml( - int x, - int y, - int width, - int height, - int color, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false - ) - { - var handler = text.Color(color); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtml( - int x, - int y, - int width, - int height, - int color, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - AddHtml(x, y, width, height, color, handler.Text, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, int y, int width, int height, ReadOnlySpan text, bool background = false, bool scrollbar = false - ) - { - var handler = text.Center(); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - var centerHandler = handler.Text.Center(); - AddHtml(x, y, width, height, ref centerHandler, background, scrollbar); - handler.Clear(); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - int color, - ReadOnlySpan text, - bool background = false, - bool scrollbar = false - ) - { - var handler = text.Center(color); - AddHtml(x, y, width, height, ref handler, background, scrollbar); - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - public void AddHtmlCentered( - int x, - int y, - int width, - int height, - int color, - ref RawInterpolatedStringHandler handler, - bool background = false, - bool scrollbar = false - ) - { - AddHtmlCentered(x, y, width, height, color, handler.Text, background, scrollbar); + AddHtml(x, y, width, height, handler.Text, color, size, fontStyle, align, background, scrollbar); handler.Clear(); } diff --git a/Projects/UOContent/Gumps/ClientGump.cs b/Projects/UOContent/Gumps/ClientGump.cs index 6fdd0a84e..d2974f6cf 100644 --- a/Projects/UOContent/Gumps/ClientGump.cs +++ b/Projects/UOContent/Gumps/ClientGump.cs @@ -36,7 +36,7 @@ namespace Server.Gumps var line = 0; AddHtml(14, 36 + line * 20, 200, 20, "Address:".Color(LabelColor32)); - AddHtml(70, 36 + line++ * 20, 200, 20, state.ToString().Color(LabelColor32)); + AddHtml(70, 36 + line++ * 20, 200, 20, Html.Color($"{state}", LabelColor32)); AddHtml(14, 36 + line * 20, 200, 20, "Client:".Color(LabelColor32)); AddHtml( @@ -75,10 +75,10 @@ namespace Server.Gumps if (m != null) { AddHtml(14, 36 + line * 20, 200, 20, "Mobile:".Color(LabelColor32)); - AddHtml(72, 36 + line++ * 20, 200, 20, $"{m.Name} ({m.Serial})".Color(LabelColor32)); + AddHtml(72, 36 + line++ * 20, 200, 20, Html.Color($"{m.Name} ({m.Serial})", LabelColor32)); AddHtml(14, 36 + line * 20, 200, 20, "Location:".Color(LabelColor32)); - AddHtml(72, 36 + line++ * 20, 200, 20, $"{m.Location} [{m.Map}]".Color(LabelColor32)); + AddHtml(72, 36 + line++ * 20, 200, 20, Html.Color($"{m.Location} [{m.Map}]", LabelColor32)); AddButton(13, 197, 0xFAB, 0xFAD, 1); AddHtml(48, 198, 200, 20, "Send Message".Color(LabelColor32)); diff --git a/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs b/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs index efccd97cd..df1b8a36e 100644 --- a/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs +++ b/Projects/UOContent/Gumps/Guilds/New Guild System/OtherGuildInfo.cs @@ -85,13 +85,13 @@ namespace Server.Guilds } else if (PendingWar) { - kills = $"{war.Kills}/{war.MaxKills}".Color(0x990000); - time = $"{war.WarLength.Hours:D2}:{DateTime.MinValue + war.WarLength:mm}".Color(0x990000); + kills = Html.Color($"{war.Kills}/{war.MaxKills}", 0x990000); + time = Html.Color($"{war.WarLength.Hours:D2}:{DateTime.MinValue + war.WarLength:mm}", 0x990000); otherWar = m_Other.FindPendingWar(guild); if (otherWar != null) { - otherKills = $"{otherWar.Kills}/{otherWar.MaxKills}".Color(0x990000); + otherKills = Html.Color($"{otherWar.Kills}/{otherWar.MaxKills}", 0x990000); } } diff --git a/Projects/UOContent/Gumps/PetResurrectGump.cs b/Projects/UOContent/Gumps/PetResurrectGump.cs index 103ed8255..75400b58d 100644 --- a/Projects/UOContent/Gumps/PetResurrectGump.cs +++ b/Projects/UOContent/Gumps/PetResurrectGump.cs @@ -39,7 +39,7 @@ public class PetResurrectGump : StaticGump protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetHtmlTextCentered("petName", _pet.Name); + builder.SetHtmlText("petName", _pet.Name, align: TextAlignment.Center); } public override void OnResponse(NetState state, in RelayInfo info) diff --git a/Projects/UOContent/Gumps/StaticWarningGump.cs b/Projects/UOContent/Gumps/StaticWarningGump.cs index 1129fb36b..ee5fc020e 100644 --- a/Projects/UOContent/Gumps/StaticWarningGump.cs +++ b/Projects/UOContent/Gumps/StaticWarningGump.cs @@ -7,13 +7,14 @@ public abstract class StaticWarningGump : StaticGump where T : StaticWarni { public virtual int Header => 1060635; //
WARNING
public virtual int HeaderColor => 0x7800; - public virtual int ContentColor => StaticLocalizedContent > 0 ? 0x7F00 : 0xFFC000; + public virtual string ContentColor => "#FFC000"; public abstract int Width { get; } public abstract int Height { get; } public virtual bool CancelButton => true; // If this is overridden, then the content will be localized and cached. public virtual int StaticLocalizedContent => 0; + public virtual int StaticLocalizedContentColor => 0x7F00; public virtual string Content => null; @@ -55,7 +56,7 @@ public abstract class StaticWarningGump : StaticGump where T : StaticWarni width - 20, height - 80, StaticLocalizedContent, - (short)ContentColor, + StaticLocalizedContentColor, false, true ); diff --git a/Projects/UOContent/Gumps/ViewHousesGump.cs b/Projects/UOContent/Gumps/ViewHousesGump.cs index 12082c6b1..41861645b 100644 --- a/Projects/UOContent/Gumps/ViewHousesGump.cs +++ b/Projects/UOContent/Gumps/ViewHousesGump.cs @@ -64,7 +64,7 @@ namespace Server.Gumps var name = FindHouseName(list[i]); - AddHtml(15, 40 + i % 15 * 20, 20, 20, $"{i + 1}.".Color(White)); + AddHtml(15, 40 + i % 15 * 20, 20, 20, Html.Color($"{i + 1}.", White)); if (name.Number > 0) { diff --git a/Projects/UOContent/Gumps/VirtualCheckGump.cs b/Projects/UOContent/Gumps/VirtualCheckGump.cs index 11baa1896..e12b86d74 100644 --- a/Projects/UOContent/Gumps/VirtualCheckGump.cs +++ b/Projects/UOContent/Gumps/VirtualCheckGump.cs @@ -131,7 +131,7 @@ public sealed class VirtualCheckGump : Gump, IVirtualCheckGump AddImage(10, 8, 113); AddImage(360, 8, 113); - AddHtml(40, 15, 320, 20, $"BANK OF {User.RawName.ToUpper()}".Center(0x2F4F4F)); + AddHtml(40, 15, 320, 20, Html.Center($"BANK OF {User.RawName.ToUpper()}", 0x2F4F4F)); // Platinum Row AddBackground(15, 60, 175, 20, 9300); diff --git a/Projects/UOContent/Items/Aquarium/AquariumGump.cs b/Projects/UOContent/Items/Aquarium/AquariumGump.cs index d35690a32..569ca29e5 100644 --- a/Projects/UOContent/Items/Aquarium/AquariumGump.cs +++ b/Projects/UOContent/Items/Aquarium/AquariumGump.cs @@ -57,7 +57,7 @@ namespace Server.Items AddItem(150, 80, item.ItemID, item.Hue); // item number / all items - AddHtml(20, 195, 250, 20, $"{page}/{m_Aquarium.Items.Count}".Color(0xFFFFFF)); + AddHtml(20, 195, 250, 20, Html.Color($"{page}/{m_Aquarium.Items.Count}", 0xFFFFFF)); // remove item if (edit) diff --git a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleManagementGump.cs b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleManagementGump.cs index dd39c9ba7..1f43cbcf8 100644 --- a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleManagementGump.cs +++ b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleManagementGump.cs @@ -68,7 +68,7 @@ public class HouseRaffleManagementGump : Gump AddHtml(145, 55, 250, 20, HouseRaffleStone.FormatPrice(stone.TicketPrice).Color(LabelColor)); AddHtml(45, 75, 100, 20, "Total Entries:".Color(LabelColor)); - AddHtml(145, 75, 250, 20, _stone.Entries.Count.ToString().Color(LabelColor)); + AddHtml(145, 75, 250, 20, Html.Color($"{_stone.Entries.Count}", LabelColor)); AddButton(440, 33, 0xFA5, 0xFA7, 3); AddHtml(474, 35, 120, 20, "Sort by name".Color(LabelColor)); @@ -130,7 +130,7 @@ public class HouseRaffleManagementGump : Gump { if (entry.From.Account is Account acc) { - AddHtml(x + 2, 140 + idx * 20, 250, 20, $"{entry.From.RawName} ({acc})".Color(color)); + AddHtml(x + 2, 140 + idx * 20, 250, 20, Html.Color($"{entry.From.RawName} ({acc})", color)); } else { diff --git a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs index 628d09457..f94d27aa5 100644 --- a/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs +++ b/Projects/UOContent/Items/Special/House Raffle/HouseRaffleStone.cs @@ -647,10 +647,9 @@ public partial class HouseRaffleStone : Item { public override int Header => 1150470; // CONFIRM TICKET PURCHASE public override int HeaderColor => 0x7F00; - public override int ContentColor => 0xFFFFFF; + public override string ContentColor => "#FFFFFF"; public override int Width => 420; public override int Height => 280; - public override string Content { get; } public ConfirmTicketPurchaseGump(Rectangle2D bounds, Point3D center, Map map, int price, Action callback) : base(callback) diff --git a/Projects/UOContent/Items/Special/Special Scrolls/PowerScroll.cs b/Projects/UOContent/Items/Special/Special Scrolls/PowerScroll.cs index 267f8e971..0accc3b50 100644 --- a/Projects/UOContent/Items/Special/Special Scrolls/PowerScroll.cs +++ b/Projects/UOContent/Items/Special/Special Scrolls/PowerScroll.cs @@ -110,7 +110,7 @@ public partial class PowerScroll : SpecialScroll } } - public override string DefaultTitle => $"Power Scroll ({Math.Floor(Value * 10) / 10:0.#} Skill):".Color(0xFFFFFF); + public override string DefaultTitle => Html.Color($"Power Scroll ({Math.Floor(Value * 10) / 10:0.#} Skill):", 0xFFFFFF); public static SkillName[] Skills { diff --git a/Projects/UOContent/Items/Special/Special Scrolls/ScrollofTranscendence.cs b/Projects/UOContent/Items/Special/Special Scrolls/ScrollofTranscendence.cs index 7ad9b72fd..6f74356e9 100644 --- a/Projects/UOContent/Items/Special/Special Scrolls/ScrollofTranscendence.cs +++ b/Projects/UOContent/Items/Special/Special Scrolls/ScrollofTranscendence.cs @@ -25,7 +25,7 @@ public partial class ScrollofTranscendence : SpecialScroll public override int Message => 1094933; public override string DefaultTitle => - $"Scroll of Transcendence ({Math.Floor(Value * 10) / 10:0.#} Skill):".Color(0xFFFFFF); + Html.Color( $"Scroll of Transcendence ({Math.Floor(Value * 10) / 10:0.#} Skill):", 0xFFFFFF); public static ScrollofTranscendence CreateRandom(int min, int max) => new(SkillsInfo.RandomSkill(), Utility.RandomMinMax(min, max) / 10.0); diff --git a/Projects/UOContent/Items/Special/Special Scrolls/StatCapScroll.cs b/Projects/UOContent/Items/Special/Special Scrolls/StatCapScroll.cs index f4e1a7d71..92dcd54de 100644 --- a/Projects/UOContent/Items/Special/Special Scrolls/StatCapScroll.cs +++ b/Projects/UOContent/Items/Special/Special Scrolls/StatCapScroll.cs @@ -42,7 +42,7 @@ public partial class StatCapScroll : SpecialScroll } public override string DefaultTitle => - $"Power Scroll ({((int)Value - 225 >= 0 ? "+" : "")}{(int)Value - 225} Maximum Stats):".Color(0xFFFFFF); + Html.Color($"Power Scroll ({((int)Value - 225 >= 0 ? "+" : "")}{(int)Value - 225} Maximum Stats):", 0xFFFFFF); public override void AddNameProperty(IPropertyList list) { diff --git a/Projects/UOContent/Misc/ShardPoller.cs b/Projects/UOContent/Misc/ShardPoller.cs index 682003c58..0fb924ab9 100644 --- a/Projects/UOContent/Misc/ShardPoller.cs +++ b/Projects/UOContent/Misc/ShardPoller.cs @@ -397,7 +397,7 @@ public class ShardPollGump : Gump if (editing) { - AddHtml(22, 22, 294, 20, $"{totalVotes} total".Color(LabelColor32)); + AddHtml(22, 22, 294, 20, Html.Color($"{totalVotes} total", LabelColor32)); AddButton(287, 23, 0x2622, 0x2623, 2); } diff --git a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs index a3af3d31b..3b63a8cfe 100644 --- a/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs +++ b/Projects/UOContent/Mobiles/Vendors/PlayerBarkeeper.cs @@ -984,9 +984,9 @@ namespace Server.Mobiles var rumor = rumors[i]; builder.AddHtml(100, 70 + i * 120, 50, 20, "Message"); - builder.AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); + builder.AddHtml(100, 90 + i * 120, 450, 40, rumor?.Message ?? "No current message", background: true); builder.AddHtmlLocalized(100, 130 + i * 120, 50, 20, 1078361); // Keyword - builder.AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); + builder.AddHtml(100, 150 + i * 120, 450, 40, rumor?.Keyword ?? "None", background: true); builder.AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(1, i)); } @@ -1010,9 +1010,9 @@ namespace Server.Mobiles var rumor = rumors[i]; builder.AddHtml(100, 70 + i * 120, 50, 20, "Message"); - builder.AddHtml(100, 90 + i * 120, 450, 40, rumor == null ? "No current message" : rumor.Message, true); + builder.AddHtml(100, 90 + i * 120, 450, 40, rumor?.Message ?? "No current message", background: true); builder.AddHtmlLocalized(100, 130 + i * 120, 50, 20, 1078361); // Keyword - builder.AddHtml(100, 150 + i * 120, 450, 40, rumor == null ? "None" : rumor.Keyword, true); + builder.AddHtml(100, 150 + i * 120, 450, 40, rumor?.Keyword ?? "None", background: true); builder.AddButton(60, 90 + i * 120, 4005, 4007, GetButtonID(2, i)); } @@ -1031,7 +1031,7 @@ namespace Server.Mobiles builder.AddHtmlLocalized(250, 95, 500, 20, 1078363); // Change this tip message builder.AddHtml(100, 190, 50, 20, "Message"); - builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", true); + builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", background: true); builder.AddButton(60, 210, 4005, 4007, GetButtonID(3, 0)); @@ -1047,7 +1047,7 @@ namespace Server.Mobiles builder.AddHtmlLocalized(250, 95, 500, 20, 1078364); // Remove this tip message builder.AddHtml(100, 190, 50, 20, "Message"); - builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", true); + builder.AddHtml(100, 210, 450, 40, _barkeeper.TipMessage ?? "No current message", background: true); builder.AddButton(60, 210, 4005, 4007, GetButtonID(4, 0)); diff --git a/Projects/UOContent/Systems/JailSystem/JailRecordGump.cs b/Projects/UOContent/Systems/JailSystem/JailRecordGump.cs index 45b9ce172..2ffe7a9f8 100644 --- a/Projects/UOContent/Systems/JailSystem/JailRecordGump.cs +++ b/Projects/UOContent/Systems/JailSystem/JailRecordGump.cs @@ -38,7 +38,7 @@ public class JailRecordGump : StaticGump builder.AddBackground(0, 0, 330, 300, 9200); builder.AddAlphaRegion(10, 10, 310, 280); - builder.AddHtml(20, 20, 360, 30, "JAIL RECORD"); + builder.AddHtml(20, 20, 360, 30, "JAIL RECORD"); builder.AddHtmlPlaceholder(20, 60, 360, 25, "playerName"); builder.AddHtmlPlaceholder(20, 80, 360, 25, "jailCount"); builder.AddHtmlPlaceholder(20, 100, 360, 25, "lastJailed"); @@ -47,43 +47,43 @@ public class JailRecordGump : StaticGump builder.AddHtmlPlaceholder(20, 150, 360, 25, "jailStatus"); builder.AddHtmlPlaceholder(20, 170, 360, 25, "jailTime"); - builder.AddHtml(20, 200, 360, 25, "If you believe you were jailed in error,"); - builder.AddHtml(20, 220, 360, 25, "please contact staff through normal channels."); - builder.AddHtml(20, 240, 360, 25, "Each time you are jailed, the wait increases."); - builder.AddHtml(20, 260, 360, 25, "Follow all shard rules to avoid future jail time."); + builder.AddHtml(20, 200, 360, 25, "If you believe you were jailed in error,"); + builder.AddHtml(20, 220, 360, 25, "please contact staff through normal channels."); + builder.AddHtml(20, 240, 360, 25, "Each time you are jailed, the wait increases."); + builder.AddHtml(20, 260, 360, 25, "Follow all shard rules to avoid future jail time."); } protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetHtmlText("playerName", $"Player: {_player.Name}", 0xFFFF00, 5); - builder.SetHtmlText("jailCount", $"Jail Count: {_record.JailCount}", 0xFFFFFF, 5); + builder.SetHtmlText("playerName", $"Player: {_player.Name}", "#FFFF00", 5); + builder.SetHtmlText("jailCount", $"Jail Count: {_record.JailCount}", "#FFFFFF", 5); if (_record.LastJailed > DateTime.MinValue) { - builder.SetHtmlText("lastJailed", $"Last Jailed: {_record.LastJailed:yyyy/MM/dd HH:mm}", 0xFFFFFF, 5); + builder.SetHtmlText("lastJailed", $"Last Jailed: {_record.LastJailed:yyyy/MM/dd HH:mm}", "#FFFFFF", 5); } else { - builder.SetHtmlText("lastJailed", "Last Jailed: Never", 0xFFFFFF, 5); + builder.SetHtmlText("lastJailed", "Last Jailed: Never", "#FFFFFF", 5); } if (string.IsNullOrWhiteSpace(_record.LastJailReason)) { - builder.SetHtmlText("jailReason", "Jail Reason: None given.", 0xFFFFFF, 4); + builder.SetHtmlText("jailReason", "Jail Reason: None given.", "#FFFFFF", 4); } else { - builder.SetHtmlText("jailReason", $"Jail Reason: {_record.LastJailReason}", 0xFFFFFF, 4); + builder.SetHtmlText("jailReason", $"Jail Reason: {_record.LastJailReason}", "#FFFFFF", 4); } if (_record.IsCurrentlyJailed) { - builder.SetHtmlText("jailStatus", "Status: Currently Jailed", 0xFF6666, 5); - builder.SetHtmlText("jailTime", $"Jail Time: {(_record.JailEndTime - Core.Now).FormatTimeCompact()}", 0xFF6666, 5); + builder.SetHtmlText("jailStatus", "Status: Currently Jailed", "#FF6666", 5); + builder.SetHtmlText("jailTime", $"Jail Time: {(_record.JailEndTime - Core.Now).FormatTimeCompact()}", "#FF6666", 5); } else { - builder.SetHtmlText("jailStatus", "Status: Not Jailed", 0x00FF00, 5); + builder.SetHtmlText("jailStatus", "Status: Not Jailed", "#00FF00", 5); builder.SetStringSlot("jailTime", ""); } } diff --git a/Projects/UOContent/Text/TextDefinitionExtensions.cs b/Projects/UOContent/Text/TextDefinitionExtensions.cs index 7e463b78a..8cb8b743b 100644 --- a/Projects/UOContent/Text/TextDefinitionExtensions.cs +++ b/Projects/UOContent/Text/TextDefinitionExtensions.cs @@ -32,7 +32,7 @@ public static class TextDefinitionExtensions int stringColor = -1 ) { - if (def == null) + if (def?.IsEmpty != false) { return; } @@ -48,16 +48,28 @@ public static class TextDefinitionExtensions builder.AddHtmlLocalized(x, y, width, height, def.Number, back, scroll); } } - else if (def.String != null) + else if (stringColor != -1) { builder.AddHtml( x, y, width, height, - stringColor >= 0 ? def.String.Color(stringColor) : def.String, // 8 bits per RGB component (24 bit RGB) - back, - scroll + $"{def.String}", + background: back, + scrollbar: scroll + ); + } + else + { + builder.AddHtml( + x, + y, + width, + height, + def.String, + background: back, + scrollbar: scroll ); } } @@ -75,7 +87,7 @@ public static class TextDefinitionExtensions int stringColor = -1 ) { - if (def == null) + if (def?.IsEmpty != false) { return; } @@ -91,16 +103,28 @@ public static class TextDefinitionExtensions builder.AddHtmlLocalized(x, y, width, height, def.Number, back, scroll); } } - else if (def.String != null) + else if (stringColor != -1) { builder.AddHtml( x, y, width, height, - stringColor >= 0 ? def.String.Color(stringColor) : def.String, // 8 bits per RGB component (24 bit RGB) - back, - scroll + $"{def.String}", + background: back, + scrollbar: scroll + ); + } + else + { + builder.AddHtml( + x, + y, + width, + height, + def.String, + background: back, + scrollbar: scroll ); } } @@ -118,23 +142,12 @@ public static class TextDefinitionExtensions int stringColor = -1 ) { - if (def == null) + if (def?.IsEmpty != false) { return; } - if (def.Number > 0) - { - if (numberColor >= 0) // 5 bits per RGB component (15 bit RGB) - { - g.AddHtmlLocalized(x, y, width, height, def.Number, numberColor, back, scroll); - } - else - { - g.AddHtmlLocalized(x, y, width, height, def.Number, back, scroll); - } - } - else if (def.String != null) + if (def.Number <= 0) { g.AddHtml( x, @@ -146,6 +159,14 @@ public static class TextDefinitionExtensions scroll ); } + else if (numberColor >= 0) // 5 bits per RGB component (15 bit RGB) + { + g.AddHtmlLocalized(x, y, width, height, def.Number, numberColor, back, scroll); + } + else + { + g.AddHtmlLocalized(x, y, width, height, def.Number, back, scroll); + } } public static void AddHtmlText( @@ -162,7 +183,7 @@ public static class TextDefinitionExtensions int stringColor = -1 ) { - if (def == null) + if (def?.IsEmpty != false) { return; } @@ -172,7 +193,7 @@ public static class TextDefinitionExtensions // 5 bits per RGB component (15 bit RGB) g.AddHtmlLocalized(x, y, width, height, def.Number, args, numberColor >= 0 ? numberColor : 0x7FFF, back, scroll); } - else if (def.String != null) + else { g.AddHtml( x, diff --git a/version.json b/version.json index de4574c38..c752fe966 100644 --- a/version.json +++ b/version.json @@ -1,4 +1,4 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "0.15.2" + "version": "0.15.3" }