## 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.
154 lines
4.3 KiB
C#
154 lines
4.3 KiB
C#
using Server.Gumps;
|
|
using Server.Network;
|
|
|
|
namespace Server.Engines.ConPVP;
|
|
|
|
public class PickRulesetGump : DynamicGump
|
|
{
|
|
private readonly DuelContext _context;
|
|
private readonly Ruleset[] _defaults;
|
|
private readonly Ruleset[] _flavors;
|
|
private readonly Ruleset _ruleset;
|
|
|
|
public override bool Singleton => true;
|
|
|
|
private PickRulesetGump(DuelContext context, Ruleset ruleset) : base(50, 50)
|
|
{
|
|
_context = context;
|
|
_ruleset = ruleset;
|
|
_defaults = ruleset.Layout.Defaults;
|
|
_flavors = ruleset.Layout.Flavors;
|
|
}
|
|
|
|
public static void DisplayTo(Mobile from, DuelContext context, Ruleset ruleset)
|
|
{
|
|
if (from?.NetState == null || ruleset == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
from.SendGump(new PickRulesetGump(context, ruleset));
|
|
}
|
|
|
|
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
|
{
|
|
var height = 25 + 20 + (_defaults.Length + 1) * 22 + 6 + 20 + _flavors.Length * 22 + 25;
|
|
|
|
builder.AddPage();
|
|
|
|
builder.AddBackground(0, 0, 260, height, 9250);
|
|
builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
|
|
|
|
builder.AddHtml(35, 25, 190, 20, Center("Rules"));
|
|
|
|
var y = 25 + 20;
|
|
|
|
for (var i = 0; i < _defaults.Length; ++i)
|
|
{
|
|
var cur = _defaults[i];
|
|
|
|
builder.AddHtml(35 + 14, y, 176, 20, cur.Title);
|
|
|
|
if (_ruleset.Base == cur && !_ruleset.Changed)
|
|
{
|
|
builder.AddImage(35, y + 4, 0x939);
|
|
}
|
|
else if (_ruleset.Base == cur)
|
|
{
|
|
builder.AddButton(35, y + 4, 0x93A, 0x939, 2 + i);
|
|
}
|
|
else
|
|
{
|
|
builder.AddButton(35, y + 4, 0x938, 0x939, 2 + i);
|
|
}
|
|
|
|
y += 22;
|
|
}
|
|
|
|
builder.AddHtml(35 + 14, y, 176, 20, "Custom");
|
|
builder.AddButton(35, y + 4, _ruleset.Changed ? 0x939 : 0x938, 0x939, 1);
|
|
|
|
y += 22;
|
|
y += 6;
|
|
|
|
builder.AddHtml(35, y, 190, 20, Center("Flavors"));
|
|
y += 20;
|
|
|
|
for (var i = 0; i < _flavors.Length; ++i)
|
|
{
|
|
var cur = _flavors[i];
|
|
|
|
builder.AddHtml(35 + 14, y, 176, 20, cur.Title);
|
|
|
|
if (_ruleset.Flavors.Contains(cur))
|
|
{
|
|
builder.AddButton(35, y + 4, 0x939, 0x938, 2 + _defaults.Length + i);
|
|
}
|
|
else
|
|
{
|
|
builder.AddButton(35, y + 4, 0x938, 0x939, 2 + _defaults.Length + i);
|
|
}
|
|
|
|
y += 22;
|
|
}
|
|
}
|
|
|
|
private static string Center(string text) => $"<CENTER>{text}</CENTER>";
|
|
|
|
public override void OnResponse(NetState sender, in RelayInfo info)
|
|
{
|
|
if (_context?.Registered == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var from = sender.Mobile;
|
|
switch (info.ButtonID)
|
|
{
|
|
case 0: // closed
|
|
{
|
|
if (_context != null)
|
|
{
|
|
DuelContextGump.DisplayTo(from, _context);
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 1: // customize
|
|
{
|
|
RulesetGump.DisplayTo(from, _ruleset, _ruleset.Layout, _context);
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
var idx = info.ButtonID - 2;
|
|
|
|
if (idx >= 0 && idx < _defaults.Length)
|
|
{
|
|
_ruleset.ApplyDefault(_defaults[idx]);
|
|
from.SendGump(this); // refresh-via-this
|
|
}
|
|
else
|
|
{
|
|
idx -= _defaults.Length;
|
|
|
|
if (idx >= 0 && idx < _flavors.Length)
|
|
{
|
|
if (_ruleset.Flavors.Contains(_flavors[idx]))
|
|
{
|
|
_ruleset.RemoveFlavor(_flavors[idx]);
|
|
}
|
|
else
|
|
{
|
|
_ruleset.AddFlavor(_flavors[idx]);
|
|
}
|
|
|
|
from.SendGump(this); // refresh-via-this
|
|
}
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|