From 6d7b1b8bee4d92d85223cdd57b6d9d1ee328de84 Mon Sep 17 00:00:00 2001 From: Kamron Batman <3953314+kamronbatman@users.noreply.github.com> Date: Thu, 13 Feb 2025 19:30:47 -0800 Subject: [PATCH] fix: Adds missing string interpolation handler for SetStringSlot (#2123) --- .../Tests/Gumps/TestGumps/StaticLayoutTestGump.cs | 5 ++++- Projects/UOContent/Engines/Khaldun/PuzzleChest.cs | 4 ++-- Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs | 8 ++++++++ Projects/UOContent/Gumps/PetResurrectGump.cs | 4 +++- Projects/UOContent/Gumps/StaticWarningGump.cs | 3 ++- Projects/UOContent/Gumps/TithingGump.cs | 4 ++-- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs index 06679a48e..08d561c09 100644 --- a/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs +++ b/Projects/UOContent.Tests/Tests/Gumps/TestGumps/StaticLayoutTestGump.cs @@ -1,3 +1,5 @@ +using System; +using Server.Buffers; using Server.Gumps; namespace Server.Tests.Gumps; @@ -35,6 +37,7 @@ public class StaticLayoutTestGump : StaticGump protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetStringSlot("petName", $"
{_petName}
"); + var petNameText = _petName.AsSpan().Center(); + builder.SetStringSlot("petName", ref petNameText); } } diff --git a/Projects/UOContent/Engines/Khaldun/PuzzleChest.cs b/Projects/UOContent/Engines/Khaldun/PuzzleChest.cs index 695e912d6..1f9ac288d 100644 --- a/Projects/UOContent/Engines/Khaldun/PuzzleChest.cs +++ b/Projects/UOContent/Engines/Khaldun/PuzzleChest.cs @@ -837,8 +837,8 @@ namespace Server.Items protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetStringSlot("cylinders", _correctCylinders.ToString()); - builder.SetStringSlot("colors", _correctColors.ToString()); + builder.SetStringSlot("cylinders", $"{_correctCylinders}"); + builder.SetStringSlot("colors", $"{_correctColors}"); } } } diff --git a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs index 798dc6a51..4a8bc3147 100644 --- a/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs +++ b/Projects/UOContent/Gumps/Base/GumpStringsBuilder.cs @@ -71,6 +71,14 @@ public ref struct GumpStringsBuilder handler.Clear(); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public void SetStringSlot(ref RawInterpolatedStringHandler slotKeyHandler, ref RawInterpolatedStringHandler handler) + { + SetStringSlot(slotKeyHandler.Text, handler.Text); + slotKeyHandler.Clear(); + handler.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 c2c28ded4..0dff0c08f 100644 --- a/Projects/UOContent/Gumps/PetResurrectGump.cs +++ b/Projects/UOContent/Gumps/PetResurrectGump.cs @@ -1,3 +1,4 @@ +using System; using Server.Mobiles; using Server.Network; @@ -39,7 +40,8 @@ public class PetResurrectGump : StaticGump protected override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetStringSlot("petName", $"
{_pet.Name}
"); + var petNameText = _pet.Name.AsSpan().Center(); + builder.SetStringSlot("petName", ref petNameText); } public override void OnResponse(NetState state, in RelayInfo info) diff --git a/Projects/UOContent/Gumps/StaticWarningGump.cs b/Projects/UOContent/Gumps/StaticWarningGump.cs index ef98d4adc..f90f1d35b 100644 --- a/Projects/UOContent/Gumps/StaticWarningGump.cs +++ b/Projects/UOContent/Gumps/StaticWarningGump.cs @@ -88,7 +88,8 @@ public abstract class StaticWarningGump : StaticGump where T : StaticWarni protected sealed override void BuildStrings(ref GumpStringsBuilder builder) { - builder.SetStringSlot("content", Content.Color(ContentColor)); + var contentText = Content.AsSpan().Color(ContentColor); + builder.SetStringSlot("content", ref contentText); } public override void OnResponse(NetState sender, in RelayInfo info) => _callback?.Invoke(info.ButtonID == 1); diff --git a/Projects/UOContent/Gumps/TithingGump.cs b/Projects/UOContent/Gumps/TithingGump.cs index c917ccff2..b68a4a150 100644 --- a/Projects/UOContent/Gumps/TithingGump.cs +++ b/Projects/UOContent/Gumps/TithingGump.cs @@ -56,8 +56,8 @@ public class TithingGump : StaticGump // Just in case _offer = Math.Clamp(_offer, 0, totalGold); - builder.SetStringSlot("goldOffer", (totalGold - _offer).ToString("N0")); - builder.SetStringSlot("titheOffer", _offer.ToString("N0")); + builder.SetStringSlot("goldOffer", $"{totalGold - _offer:N0}"); + builder.SetStringSlot("titheOffer", $"{_offer:N0}"); } public override void OnResponse(NetState sender, in RelayInfo info)