ModernUO/Projects/UOContent/Engines/ConPVP/Gumps/ReadyUpGump.cs
Kamron Batman a74c7f9d4e
perf: Migrates ConPVP lobby gumps from legacy Gump. (#2423)
## Summary

Migrates 14 ConPVP lobby/tournament gumps from legacy `Gump` to modern `DynamicGump`/`StaticGump<T>`. Layouts move into `BuildLayout(ref DynamicGumpBuilder)`, constructors become private, and validation moves into static `DisplayTo` entry points (empty-gump rule).

**Per-gump base type decisions:**

- `BeginGump` → `StaticGump<BeginGump>`: layout is fully fixed (no dynamic content). All other gumps below are `DynamicGump` because they bake dynamic player names, guild abbreviations, ruleset titles, arena names, tournament participant names, ladder rankings, or per-instance rule modifications. Per the cliloc/dynamic-text rule, dynamic content forces `DynamicGump`.
- `ReadyGump`, `ReadyUpGump` → `DynamicGump` (per-instance participant rosters).
- `AcceptDuelGump`, `AcceptTeamGump`, `ConfirmSignupGump` → `DynamicGump` (challenger/registrar/team names, dynamic rule modifications).
- `PickRulesetGump`, `RulesetGump` → `DynamicGump` (ruleset titles and option labels per instance).
- `ParticipantGump`, `DuelContextGump` → `DynamicGump` (player rosters/team labels).
- `LadderGump` → `DynamicGump` (ladder entries: ranks, levels, guild abbrs, names, wins/losses).
- `ArenaGump` → `DynamicGump` (arena names with active player names).
- `PreferencesGump` → `DynamicGump` (arena name list).
- `TournamentBracketGump` (~1k LOC) → `DynamicGump`. The whole gump is one type-switched view that re-renders on every button press across `Index`, `Rules_Info`, `Participant_List`, `Participant_Info`, `Round_List`, `Round_Info`, `Match_Info`, `Player_Info`. All branches bake per-instance content.

**Refresh-via-this conversions (the big perf wins):**

- `LadderGump`: page +/- now mutates `_page` and calls `from.SendGump(this)` instead of allocating a new `LadderGump`.
- `PickRulesetGump`: ruleset apply / flavor toggle now refreshes via `this`.
- `ParticipantGump`: increase/decrease team size, remove player, target failure all refresh via `this`.
- `DuelContextGump`: failed-start and add-participant refresh via `this`.
- `ConfirmSignupGump`: every signup-validation rejection branch in `OnResponse` and every `AddPlayer_OnTarget` rejection branch refreshes via `this` (was allocating a new gump per branch).
- `TournamentBracketGump`: every navigation button (back/forward, type change, page change, drill-down) mutates `_type`/`_object`/`_list`/`_page` and refreshes via `this`. Previously each click allocated a new 1k LOC gump.

All gumps are `Singleton`, use private constructors with static `DisplayTo` entry points that null-check `NetState` before allocation. External callers in `DuelContext`, `TournamentBracketItem`, `TournamentController`, `TournamentSignupItem`, and the cross-references between `AcceptDuelGump`/`ParticipantGump`/`AcceptTeamGump`/`ConfirmSignupGump` are all updated to use `DisplayTo`. Legacy `m_X` fields renamed to `_x` per coding standards.
2026-05-03 01:06:04 -07:00

241 lines
6.1 KiB
C#

using System.Collections;
using Server.Gumps;
using Server.Mobiles;
using Server.Network;
namespace Server.Engines.ConPVP;
public class ReadyUpGump : DynamicGump
{
private readonly DuelContext _context;
public override bool Singleton => true;
private ReadyUpGump(DuelContext context) : base(50, 50) => _context = context;
public static void DisplayTo(Mobile from, DuelContext context)
{
if (from?.NetState == null || context == null)
{
return;
}
from.SendGump(new ReadyUpGump(context), true);
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.SetNoClose();
builder.AddPage();
if (_context.Rematch)
{
var height = 25 + 20 + 10 + 22 + 25;
builder.AddBackground(0, 0, 210, height, 9250);
builder.AddBackground(10, 10, 190, height - 20, 0xDAC);
builder.AddHtml(35, 25, 140, 20, "Rematch?".Center());
builder.AddButton(35, 55, 247, 248, 1);
builder.AddButton(115, 55, 242, 241, 2);
}
else
{
builder.AddPage(1);
var parts = _context.Participants;
var height = 25 + 20;
for (var i = 0; i < parts.Count; ++i)
{
var p = parts[i];
height += 4;
if (p.Players.Length > 1)
{
height += 22;
}
height += p.Players.Length * 22;
}
height += 10 + 22 + 25;
builder.AddBackground(0, 0, 260, height, 9250);
builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
builder.AddHtml(35, 25, 190, 20, "Participants".Center());
var y = 20 + 25;
for (var i = 0; i < parts.Count; ++i)
{
var p = parts[i];
y += 4;
var offset = 0;
if (p.Players.Length > 1)
{
builder.AddHtml(35, y, 176, 20, $"Team #{i + 1}");
y += 22;
offset = 10;
}
for (var j = 0; j < p.Players.Length; ++j)
{
var pl = p.Players[j];
var name = pl == null ? "(Empty)" : pl.Mobile.Name;
builder.AddHtml(35 + offset, y, 166, 20, name);
y += 22;
}
}
y += 8;
builder.AddHtml(35, y, 176, 20, "Continue?");
y -= 2;
builder.AddButton(102, y, 247, 248, 0, GumpButtonType.Page, 2);
builder.AddButton(169, y, 242, 241, 2);
builder.AddPage(2);
var ruleset = _context.Ruleset;
var basedef = ruleset.Base;
height = 25 + 20 + 5 + 20 + 20 + 4;
var changes = 0;
BitArray defs;
if (ruleset.Flavors.Count > 0)
{
defs = new BitArray(basedef.Options);
for (var i = 0; i < ruleset.Flavors.Count; ++i)
{
defs.Or(ruleset.Flavors[i].Options);
}
height += ruleset.Flavors.Count * 18;
}
else
{
defs = basedef.Options;
}
var opts = ruleset.Options;
for (var i = 0; i < opts.Length; ++i)
{
if (defs[i] != opts[i])
{
++changes;
}
}
height += changes * 22;
height += 10 + 22 + 25;
builder.AddBackground(0, 0, 260, height, 9250);
builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
builder.AddHtml(35, 25, 190, 20, "Rules".Center());
builder.AddHtml(35, 50, 190, 20, $"Set: {basedef.Title}");
y = 70;
for (var i = 0; i < ruleset.Flavors.Count; ++i, y += 18)
{
builder.AddHtml(35, y, 190, 20, $" + {ruleset.Flavors[i].Title}");
}
y += 4;
if (changes > 0)
{
builder.AddHtml(35, y, 190, 20, "Modifications:");
y += 20;
for (var i = 0; i < opts.Length; ++i)
{
if (defs[i] != opts[i])
{
var name = ruleset.Layout.FindByIndex(i);
if (name != null) // sanity
{
builder.AddImage(35, y, opts[i] ? 0xD3 : 0xD2);
builder.AddHtml(60, y, 165, 22, name);
}
y += 22;
}
}
}
else
{
builder.AddHtml(35, y, 190, 20, "Modifications: None");
y += 20;
}
y += 8;
builder.AddHtml(35, y, 176, 20, "Continue?");
y -= 2;
builder.AddButton(102, y, 247, 248, 1);
builder.AddButton(169, y, 242, 241, 3);
}
}
private static string Center(string text) => $"<CENTER>{text}</CENTER>";
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (!_context.Registered || !_context.ReadyWait)
{
return;
}
var from = sender.Mobile;
switch (info.ButtonID)
{
case 1: // okay
{
if (from is not PlayerMobile pm)
{
break;
}
pm.DuelPlayer.Ready = true;
_context.SendReadyGump();
break;
}
case 2: // reject participants
{
_context.RejectReady(from, "participants");
break;
}
case 3: // reject rules
{
_context.RejectReady(from, "rules");
break;
}
}
}
}