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.
This commit is contained in:
Kamron Batman 2025-11-23 11:35:31 -08:00 committed by GitHub
parent ea86d5b2a6
commit 7bd5a853a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 398 additions and 635 deletions

View file

@ -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<char> 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<char> text,
ReadOnlySpan<char> color,
int size = -1,
byte fontStyle = 0
)
{
if (color != Span<char>.Empty)
{
if (size > -1)
{
if (fontStyle > 0)
{
return $"<BASEFONT COLOR={color} SIZE={size} STYLE={fontStyle}>{text}</BASEFONT>";
}
return $"<BASEFONT COLOR={color} SIZE={size}>{text}</BASEFONT>";
}
if (fontStyle > 0)
{
return $"<BASEFONT COLOR={color} STYLE={fontStyle}>{text}</BASEFONT>";
}
return $"<BASEFONT COLOR={color}>{text}</BASEFONT>";
}
if (size > -1)
{
if (fontStyle > 0)
{
return $"<BASEFONT SIZE={size} STYLE={fontStyle}>{text}</BASEFONT>";
}
return $"<BASEFONT SIZE={size}>{text}</BASEFONT>";
}
if (fontStyle > 0)
{
return $"<BASEFONT STYLE={fontStyle}>{text}</BASEFONT>";
}
return $"{text}";
}
public static string Center(this ReadOnlySpan<char> input) => $"<CENTER>{input}</CENTER>";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RawInterpolatedStringHandler Color(
this ReadOnlySpan<char> 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<char>)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<char> color,
int size = -1,
byte fontStyle = 0
)
{
var textHandler = ((ReadOnlySpan<char>)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<char> color) => Center(input.AsSpan(), color);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Center(this ReadOnlySpan<char> input, int color) =>
$"<CENTER><BASEFONT COLOR=#{color:X6}>{input}</BASEFONT></CENTER>";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Center(this ReadOnlySpan<char> input, ReadOnlySpan<char> color) =>
$"<CENTER><BASEFONT COLOR={color}>{input}</BASEFONT></CENTER>";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Center(ref RawInterpolatedStringHandler input, int color)
{
var textHandler = ((ReadOnlySpan<char>)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<char> color)
{
var handler = Center((ReadOnlySpan<char>)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<char> color, int size = -1, byte fontStyle = 0
)
{
var handler = Center((ReadOnlySpan<char>)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<char> color) => Color(input.AsSpan(), color);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Color(this ReadOnlySpan<char> input, int color) => $"<BASEFONT COLOR=#{color:X6}>{input}</CENTER>";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Color(this ReadOnlySpan<char> input, ReadOnlySpan<char> color) =>
$"<BASEFONT COLOR={color}>{input}</CENTER>";
[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<char> text) => Center(text, -1);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RawInterpolatedStringHandler Center(
this ReadOnlySpan<char> text, int color, int size = -1, byte fontStyle = 0
) => Color($"<CENTER>{text}</CENTER>", color, size, fontStyle);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RawInterpolatedStringHandler Center(
this ReadOnlySpan<char> text, ReadOnlySpan<char> color, int size = -1, byte fontStyle = 0
) => Color($"<CENTER>{text}</CENTER>", 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<char> 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<char>)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<char> color, int size = -1, byte fontStyle = 0
)
{
var handler = Right((ReadOnlySpan<char>)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<char> input) => $"<RIGHT>{input}</RIGHT>";
[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<char> color) => Right(input.AsSpan(), color);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Right(this ReadOnlySpan<char> input, int color) =>
$"<RIGHT><BASEFONT COLOR=#{color:X6}>{input}</BASEFONT></RIGHT>";
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static string Right(this ReadOnlySpan<char> input, ReadOnlySpan<char> color) =>
$"<RIGHT><BASEFONT COLOR={color}>{input}</BASEFONT></RIGHT>";
[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<char> text, int color, int size = -1, byte fontStyle = 0
) => Color($"<RIGHT>{text}</RIGHT>", color, size, fontStyle);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RawInterpolatedStringHandler Right(
this ReadOnlySpan<char> text, ReadOnlySpan<char> color, int size = -1, byte fontStyle = 0
) => Color($"<RIGHT>{text}</RIGHT>", color, size, fontStyle);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static RawInterpolatedStringHandler Right(this ReadOnlySpan<char> text) => text.Right(-1);
public static string Right(ref RawInterpolatedStringHandler input, ReadOnlySpan<char> color)
{
var str = input.Text.Right(color);
input.Clear();
return str;
}
private static readonly SearchValues<char> _htmlSearchValues = SearchValues.Create('<', '>', '&', '"', '\'');
@ -304,4 +213,71 @@ public static class Html
builder.Dispose();
return result;
}
public static string Build(
ReadOnlySpan<char> text, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left
)
{
var arr = STArrayPool<char>.Shared.Rent(BuildCharCount(text, color));
var bytesWritten = Build(text, arr.AsSpan(), color, size, fontStyle, align);
var result = arr.AsSpan(0, bytesWritten).ToString();
STArrayPool<char>.Shared.Return(arr);
return result;
}
public static int BuildCharCount(ReadOnlySpan<char> text, ReadOnlySpan<char> color) => 61 + text.Length + color.Length;
public static int Build(
ReadOnlySpan<char> text, Span<char> dest, ReadOnlySpan<char> color = default, int size = -1, byte fontStyle = 0,
TextAlignment align = TextAlignment.Left
)
{
using var builder = new ValueStringBuilder(dest);
if (align == TextAlignment.Right)
{
builder.Append("<RIGHT>");
}
else if (align == TextAlignment.Center)
{
builder.Append("<CENTER>");
}
if (color.Length > 0 || size > -1 || fontStyle > 0)
{
builder.Append("<BASEFONT");
if (color.Length > 0)
{
builder.Append($" COLOR={color}");
}
if (size > -1)
{
builder.Append($" SIZE={size}");
}
if (fontStyle > 0)
{
builder.Append($" STYLE={fontStyle}");
}
builder.Append($">{text}</BASEFONT>");
}
else
{
builder.Append(text);
}
if (align == TextAlignment.Right)
{
builder.Append("</RIGHT>");
}
else if (align == TextAlignment.Center)
{
builder.Append("</CENTER>");
}
return builder.Length;
}
}

View file

@ -27,7 +27,7 @@ public class DynamicTestGump : DynamicGump
builder.AddItem(218, 95, 0xCB0);
builder.AddHtml(30, 30, 150, 75, "<div align=center>Wilt thou sanctify the resurrection of:</div>");
builder.AddHtml(30, 70, 150, 25, $"<CENTER>{_petName}</CENTER>", 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

View file

@ -35,6 +35,6 @@ public class StaticLayoutTestGump : StaticGump<StaticLayoutTestGump>
protected override void BuildStrings(ref GumpStringsBuilder builder)
{
builder.SetHtmlTextCentered("petName", _petName);
builder.SetHtmlText("petName", _petName, align: TextAlignment.Center);
}
}

View file

@ -24,7 +24,7 @@ public class StaticTestGump : StaticGump<StaticTestGump>
builder.AddItem(218, 95, 0xCB0);
builder.AddHtml(30, 30, 150, 75, "<div align=center>Wilt thou sanctify the resurrection of:</div>");
builder.AddHtml(30, 70, 150, 25, "<CENTER>Test</CENTER>", 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

View file

@ -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);
}
}
}

View file

@ -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, "<BASEFONT COLOR=#FFFFFF>Price all</FONT>");
builder.AddHtml(485, 416, 120, 20, "<BASEFONT COLOR=#FFFFFF>Price all</BASEFONT>");
}
}

View file

@ -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,

View file

@ -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);
}
}

View file

@ -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,

View file

@ -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} <DIV ALIGN=CENTER>/</DIV> <DIV ALIGN=RIGHT>{1}</DIV>", entry.Wins, entry.Losses ), 0xFFC000, 0 );

View file

@ -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<TourneyParticipant>(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;
}

View file

@ -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
}
}
}
}
}

View file

@ -25,7 +25,7 @@ public sealed class PageResponseGump : StaticGump<PageResponseGump>
// <CENTER><U>Ultima Online Help Response</U></CENTER>
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);

View file

@ -46,7 +46,7 @@ namespace Server.Engines.Help
10,
280,
20,
$"SPEECH LOG - {playerName} (<i>{playerAccount.FixHtmlFormattable()}</i>)".Center(0xA0A0FF)
Html.Center($"SPEECH LOG - {playerName} (<i>{playerAccount.FixHtmlFormattable()}</i>)", 0xA0A0FF)
);
var lastPage = (log.Count - 1) / MaxEntriesPerPage;

View file

@ -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);
}
}
}

View file

@ -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, $"<BASEFONT COLOR=#FFEA00>{spawner.Name}</BASEFONT><BASEFONT COLOR={GetCountColor(totalSpawned, spawner.Count)}> ({totalSpawned}/{spawner.Count})</BASEFONT>");

View file

@ -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");

View file

@ -78,114 +78,33 @@ public ref struct DynamicGumpBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtml(
int x,
int y,
int width,
int height,
ReadOnlySpan<char> text,
bool background = false,
bool scrollbar = false
int x, int y, int width, int height, ReadOnlySpan<char> text, ReadOnlySpan<char> 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<char>.Shared.Rent(Html.BuildCharCount(text, color));
var bytesWritten = Html.Build(text, arr.AsSpan(), color, size, fontStyle, align);
WriteInternalizedString(arr.AsSpan(0, bytesWritten));
STArrayPool<char>.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<char> 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<char> 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<char> 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<char> 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<char> args,
int color,
bool background = false,
int x, int y, int width, int height, int number, ReadOnlySpan<char> 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
);

View file

@ -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 <http://www.gnu.org/licenses/>. *
*************************************************************************/
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<Col> Columns { get; set; } = new();
public List<Row> Rows { get; set; } = new();
}
public class Swap
{
public int Index { get; set; }
public int Size { get; set; }
}

View file

@ -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<char> 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<char> value, int color, int size = -1, byte fontStyle = 0
ref RawInterpolatedStringHandler slotKeyHandler, ReadOnlySpan<char> value, ReadOnlySpan<char> 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<char> slotKey, ref RawInterpolatedStringHandler handler, int color, int size = -1, byte fontStyle = 0
ReadOnlySpan<char> slotKey, ref RawInterpolatedStringHandler handler, ReadOnlySpan<char> 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<char> slotKey, ReadOnlySpan<char> value, int color, int size = -1, byte fontStyle = 0
ReadOnlySpan<char> slotKey, ReadOnlySpan<char> value, ReadOnlySpan<char> 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<char>.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<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);
SetStringSlot(slotKey, arr.AsSpan(0, bytesWritten));
STArrayPool<char>.Shared.Return(arr);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]

View file

@ -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)

View file

@ -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<Col> Columns { get; set; } = new();
public List<Row> Rows { get; set; } = new();
}
public class Swap
{
public int Index { get; set; }
public int Size { get; set; }
}

View file

@ -91,13 +91,7 @@ public ref struct StaticGumpBuilder
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddHtmlPlaceholder(
int x,
int y,
int width,
int height,
ReadOnlySpan<char> slotKey,
bool background = false,
bool scrollbar = false
int x, int y, int width, int height, ReadOnlySpan<char> 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<char> text,
bool background = false,
bool scrollbar = false
int x, int y, int width, int height, ReadOnlySpan<char> text, ReadOnlySpan<char> 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<char>.Shared.Rent(Html.BuildCharCount(text, color));
var bytesWritten = Html.Build(text, arr.AsSpan(), color, size, fontStyle, align);
WriteInternalizedString(arr.AsSpan(0, bytesWritten));
STArrayPool<char>.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<char> 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<char> 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<char> 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<char> 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();
}

View file

@ -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));

View file

@ -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);
}
}

View file

@ -39,7 +39,7 @@ public class PetResurrectGump : StaticGump<PetResurrectGump>
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)

View file

@ -7,13 +7,14 @@ public abstract class StaticWarningGump<T> : StaticGump<T> where T : StaticWarni
{
public virtual int Header => 1060635; // <CENTER>WARNING</CENTER>
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<T> : StaticGump<T> where T : StaticWarni
width - 20,
height - 80,
StaticLocalizedContent,
(short)ContentColor,
StaticLocalizedContentColor,
false,
true
);

View file

@ -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)
{

View file

@ -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);

View file

@ -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)

View file

@ -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
{

View file

@ -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<bool> callback) : base(callback)

View file

@ -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
{

View file

@ -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);

View file

@ -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)
{

View file

@ -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);
}

View file

@ -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));

View file

@ -38,7 +38,7 @@ public class JailRecordGump : StaticGump<JailRecordGump>
builder.AddBackground(0, 0, 330, 300, 9200);
builder.AddAlphaRegion(10, 10, 310, 280);
builder.AddHtml(20, 20, 360, 30, "<size=6 color=#FF6600>JAIL RECORD</basefont>");
builder.AddHtml(20, 20, 360, 30, "<BASEFONT size=6 color=#FF6600>JAIL RECORD</BASEFONT>");
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<JailRecordGump>
builder.AddHtmlPlaceholder(20, 150, 360, 25, "jailStatus");
builder.AddHtmlPlaceholder(20, 170, 360, 25, "jailTime");
builder.AddHtml(20, 200, 360, 25, "<size=4 color=#CCCCCC>If you believe you were jailed in error,</basefont>");
builder.AddHtml(20, 220, 360, 25, "<size=4 color=#CCCCCC>please contact staff through normal channels.</basefont>");
builder.AddHtml(20, 240, 360, 25, "<size=4 color=#CCCCCC>Each time you are jailed, the wait increases.</basefont>");
builder.AddHtml(20, 260, 360, 25, "<size=4 color=#CCCCCC>Follow all shard rules to avoid future jail time.</basefont>");
builder.AddHtml(20, 200, 360, 25, "<BASEFONT size=4 color=#CCCCCC>If you believe you were jailed in error,</BASEFONT>");
builder.AddHtml(20, 220, 360, 25, "<BASEFONT size=4 color=#CCCCCC>please contact staff through normal channels.</BASEFONT>");
builder.AddHtml(20, 240, 360, 25, "<BASEFONT size=4 color=#CCCCCC>Each time you are jailed, the wait increases.</BASEFONT>");
builder.AddHtml(20, 260, 360, 25, "<BASEFONT size=4 color=#CCCCCC>Follow all shard rules to avoid future jail time.</BASEFONT>");
}
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", "");
}
}

View file

@ -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
$"<BASEFONT COLOR=#{stringColor:X6}>{def.String}</BASEFONT>",
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
$"<BASEFONT COLOR=#{stringColor:X6}>{def.String}</BASEFONT>",
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,

View file

@ -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"
}