perf: Migrate Bulletin/Poll/SOS gumps to DynamicGump (#2418)

## Summary

Migrates three legacy `Gump`-based dialogs to the modern builder API:

- **PlayerBBGump** (`Projects/UOContent/Items/Misc/PlayerBulletinBoards.cs`) — `DynamicGump`. The bulletin board renders a different post per page (variable per-instance state), so the layout cannot be cached. Now `Singleton`, with a private constructor and a static `DisplayTo` entry point. Scroll/banish/delete/post-props buttons mutate `_page` and self-refresh via `SendGump(this)` instead of allocating a fresh gump on every click. Prompt-driven flows (post message / set title / post greeting) re-enter through `DisplayTo` after the prompt completes.
- **MessageGump** + **OldMessageGump** (`Projects/UOContent/Items/Skill Items/Fishing/Misc/SOS.cs`) — `StaticGump<T>`. Both render a fixed structure (background + body + button) where only the formatted sextant coordinate string varies per SOS bottle. The cliloc IDs that *appear in the gump packet* are constant (`MessageGump` uses 1018326; `OldMessageGump` uses no `AddHtmlLocalized` at all — its message is pre-formatted into a string before construction), so the layout cache is safe per the cliloc rule. The varying coordinate text is fed through an HTML placeholder via `BuildStrings`. Both gumps are now `Singleton` with private constructors and static `DisplayTo` entry points.
- **ShardPollGump** (`Projects/UOContent/Misc/ShardPoller.cs`) — `DynamicGump`. The gump's structure changes both with the number of poll options (variable loop) and with the `editing` flag (admin sees radios + add-option row + result percentages; players see only radios). The dual-purpose view is preserved as a single `DynamicGump` with the `editing` flag still controlling layout shape — staff path verified to still render the editor with the totals header, vote percentages, and "Create new option" radio. `Closable = false` becomes `builder.SetNoClose()`. Now `Singleton`, with private constructor and a `DisplayTo` that returns the gump instance so `EventSink_Login_Callback` can still call `QueuePoll` on it. The cancel/edit re-issue paths use `SendGump(this)` for self-refresh; the queued login flow uses `DisplayTo` so each queued poll gets its own gump.

External callers (`OnDoubleClick`, `PostPrompt`, `SetTitlePrompt`, `ShardPollPrompt`, `EventSink_Login_Callback`, the Timer-delayed queued poll send) all updated to use the new `DisplayTo` entry points. Legacy `m_X` field naming was already absent in two of the three files; the bulletin board fields kept their `_camelCase` names. `dotnet build Projects/UOContent/UOContent.csproj` reports 0 warnings, 0 errors.
This commit is contained in:
Kamron Batman 2026-04-25 20:49:12 -07:00 • committed by GitHub
parent 4e565ca6da
commit 802849bebc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 203 additions and 123 deletions

View file

@ -167,8 +167,7 @@ public partial class ShardPoller : Item
if (spg == null)
{
spg = new ShardPollGump(from, poller, false, null);
from.SendGump(spg);
spg = ShardPollGump.DisplayTo(from, poller, false, null);
}
else
{
@ -186,7 +185,7 @@ public partial class ShardPoller : Item
{
if (from.AccessLevel >= AccessLevel.Administrator)
{
from.SendGump(new ShardPollGump(from, this, true, null));
ShardPollGump.DisplayTo(from, this, true, null);
}
}
@ -340,23 +339,51 @@ public partial class ShardPollOption
}
}
public class ShardPollGump : Gump
public class ShardPollGump : DynamicGump
{
private const int LabelColor32 = 0xFFFFFF;
private readonly Mobile _from;
private readonly ShardPoller _poller;
private Queue<ShardPoller> _polls;
public ShardPollGump(Mobile from, ShardPoller poller, bool editing, Queue<ShardPoller> polls) : base(50, 50)
public override bool Singleton => true;
private ShardPollGump(Mobile from, ShardPoller poller, bool editing, Queue<ShardPoller> polls) : base(50, 50)
{
_from = from;
_poller = poller;
Editing = editing;
_polls = polls;
}
Closable = false;
public static ShardPollGump DisplayTo(Mobile from, ShardPoller poller, bool editing, Queue<ShardPoller> polls)
{
if (from?.NetState == null || poller == null || poller.Deleted)
{
return null;
}
AddPage(0);
var gump = new ShardPollGump(from, poller, editing, polls);
from.SendGump(gump);
return gump;
}
public bool Editing { get; }
public void QueuePoll(ShardPoller poller)
{
_polls ??= new Queue<ShardPoller>(4);
_polls.Enqueue(poller);
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
var poller = _poller;
var editing = Editing;
builder.SetNoClose();
builder.AddPage();
var totalVotes = 0;
var totalOptionHeight = 0;
@ -377,10 +404,10 @@ public class ShardPollGump : Gump
var height = 115 + totalOptionHeight;
AddBackground(1, 1, 398, height - 2, 3600);
AddAlphaRegion(16, 15, 369, height - 31);
builder.AddBackground(1, 1, 398, height - 2, 3600);
builder.AddAlphaRegion(16, 15, 369, height - 31);
AddItem(308, 30, 0x1E5E);
builder.AddItem(308, 30, 0x1E5E);
string title;
@ -393,18 +420,18 @@ public class ShardPollGump : Gump
title = "Shard Poll";
}
AddHtml(22, 22, 294, 20, title.Center(LabelColor32));
builder.AddHtml(22, 22, 294, 20, title.Center(LabelColor32));
if (editing)
{
AddHtml(22, 22, 294, 20, Html.Color($"{totalVotes} total", LabelColor32));
AddButton(287, 23, 0x2622, 0x2623, 2);
builder.AddHtml(22, 22, 294, 20, Html.Color($"{totalVotes} total", LabelColor32));
builder.AddButton(287, 23, 0x2622, 0x2623, 2);
}
AddHtml(22, 50, 294, 40, poller.Title.Color(0x99CC66));
builder.AddHtml(22, 50, 294, 40, poller.Title.Color(0x99CC66));
AddImageTiled(32, 88, 264, 1, 9107);
AddImageTiled(42, 90, 264, 1, 9157);
builder.AddImageTiled(32, 88, 264, 1, 9107);
builder.AddImageTiled(42, 90, 264, 1, 9157);
var y = 100;
@ -426,16 +453,16 @@ public class ShardPollGump : Gump
if (isViewingResults)
{
AddImage(24, y - 15, 0x25FE);
builder.AddImage(24, y - 15, 0x25FE);
}
else
{
AddRadio(24, y - 15, 0x25F9, 0x25FC, false, 1 + i);
builder.AddRadio(24, y - 15, 0x25F9, 0x25FC, false, 1 + i);
}
var lineBreaks = option.GetBreaks();
AddHtml(60, y - 9 * lineBreaks, 250, 18 * lineBreaks, text.Color(LabelColor32));
builder.AddHtml(60, y - 9 * lineBreaks, 250, 18 * lineBreaks, text.Color(LabelColor32));
y += optHeight / 2;
y += 5;
@ -443,20 +470,12 @@ public class ShardPollGump : Gump
if (editing && !isViewingResults)
{
AddRadio(24, y + 15 - 15, 0x25F9, 0x25FC, false, 1 + poller.Options.Length);
AddHtml(60, y + 15 - 9, 250, 18, "Create new option.".Color(0x99CC66));
builder.AddRadio(24, y + 15 - 15, 0x25F9, 0x25FC, false, 1 + poller.Options.Length);
builder.AddHtml(60, y + 15 - 9, 250, 18, "Create new option.".Color(0x99CC66));
}
AddButton(314, height - 73, 247, 248, 1);
AddButton(314, height - 47, 242, 241, 0);
}
public bool Editing { get; }
public void QueuePoll(ShardPoller poller)
{
_polls ??= new Queue<ShardPoller>(4);
_polls.Enqueue(poller);
builder.AddButton(314, height - 73, 247, 248, 1);
builder.AddButton(314, height - 47, 242, 241, 0);
}
public override void OnResponse(NetState sender, in RelayInfo info)
@ -467,9 +486,11 @@ public class ShardPollGump : Gump
if (shardPoller != null)
{
var from = _from;
var queuedPolls = _polls;
Timer.StartTimer(
TimeSpan.FromSeconds(1.0),
() => _from.SendGump(new ShardPollGump(_from, shardPoller, false, _polls))
() => DisplayTo(from, shardPoller, false, queuedPolls)
);
}
}
@ -514,7 +535,7 @@ public class ShardPollGump : Gump
else
{
_from.SendMessage("You may not edit an active poll. Deactivate it first.");
_from.SendGump(new ShardPollGump(_from, _poller, Editing, _polls));
_from.SendGump(this);
}
}
else
@ -535,7 +556,7 @@ public class ShardPollGump : Gump
}
else if (info.ButtonID == 2 && Editing)
{
_from.SendGump(new ShardPollGump(_from, _poller, Editing, _polls));
_from.SendGump(this);
_from.SendGump(new PropertiesGump(_from, _poller));
}
}
@ -554,7 +575,7 @@ public partial class ShardPollPrompt : Prompt
public override void OnCancel(Mobile from)
{
from.SendGump(new ShardPollGump(from, _poller, true, null));
ShardPollGump.DisplayTo(from, _poller, true, null);
}
private static string UrlRegex_Match(Match m)
@ -603,7 +624,7 @@ public partial class ShardPollPrompt : Prompt
}
}
from.SendGump(new ShardPollGump(from, _poller, true, null));
ShardPollGump.DisplayTo(from, _poller, true, null);
}
[GeneratedRegex(@"\[url(?:=(.*?))?\](.*?)\[/url\]", RegexOptions.IgnoreCase | RegexOptions.Compiled)]