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.
This commit is contained in:
parent
9c2ac2b8ea
commit
a74c7f9d4e
18 changed files with 3203 additions and 3226 deletions
|
|
@ -1,141 +1,154 @@
|
|||
using Server.Gumps;
|
||||
using Server.Network;
|
||||
|
||||
namespace Server.Engines.ConPVP
|
||||
namespace Server.Engines.ConPVP;
|
||||
|
||||
public class PickRulesetGump : DynamicGump
|
||||
{
|
||||
public class PickRulesetGump : Gump
|
||||
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)
|
||||
{
|
||||
private readonly DuelContext m_Context;
|
||||
private readonly Ruleset[] m_Defaults;
|
||||
private readonly Ruleset[] m_Flavors;
|
||||
private readonly Mobile m_From;
|
||||
private readonly Ruleset m_Ruleset;
|
||||
_context = context;
|
||||
_ruleset = ruleset;
|
||||
_defaults = ruleset.Layout.Defaults;
|
||||
_flavors = ruleset.Layout.Flavors;
|
||||
}
|
||||
|
||||
public PickRulesetGump(Mobile from, DuelContext context, Ruleset ruleset) : base(50, 50)
|
||||
public static void DisplayTo(Mobile from, DuelContext context, Ruleset ruleset)
|
||||
{
|
||||
if (from?.NetState == null || ruleset == null)
|
||||
{
|
||||
m_From = from;
|
||||
m_Context = context;
|
||||
m_Ruleset = ruleset;
|
||||
m_Defaults = ruleset.Layout.Defaults;
|
||||
m_Flavors = ruleset.Layout.Flavors;
|
||||
|
||||
var height = 25 + 20 + (m_Defaults.Length + 1) * 22 + 6 + 20 + m_Flavors.Length * 22 + 25;
|
||||
|
||||
AddPage(0);
|
||||
|
||||
AddBackground(0, 0, 260, height, 9250);
|
||||
AddBackground(10, 10, 240, height - 20, 0xDAC);
|
||||
|
||||
AddHtml(35, 25, 190, 20, Center("Rules"));
|
||||
|
||||
var y = 25 + 20;
|
||||
|
||||
for (var i = 0; i < m_Defaults.Length; ++i)
|
||||
{
|
||||
var cur = m_Defaults[i];
|
||||
|
||||
AddHtml(35 + 14, y, 176, 20, cur.Title);
|
||||
|
||||
if (ruleset.Base == cur && !ruleset.Changed)
|
||||
{
|
||||
AddImage(35, y + 4, 0x939);
|
||||
}
|
||||
else if (ruleset.Base == cur)
|
||||
{
|
||||
AddButton(35, y + 4, 0x93A, 0x939, 2 + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddButton(35, y + 4, 0x938, 0x939, 2 + i);
|
||||
}
|
||||
|
||||
y += 22;
|
||||
}
|
||||
|
||||
AddHtml(35 + 14, y, 176, 20, "Custom");
|
||||
AddButton(35, y + 4, ruleset.Changed ? 0x939 : 0x938, 0x939, 1);
|
||||
|
||||
y += 22;
|
||||
y += 6;
|
||||
|
||||
AddHtml(35, y, 190, 20, Center("Flavors"));
|
||||
y += 20;
|
||||
|
||||
for (var i = 0; i < m_Flavors.Length; ++i)
|
||||
{
|
||||
var cur = m_Flavors[i];
|
||||
|
||||
AddHtml(35 + 14, y, 176, 20, cur.Title);
|
||||
|
||||
if (ruleset.Flavors.Contains(cur))
|
||||
{
|
||||
AddButton(35, y + 4, 0x939, 0x938, 2 + m_Defaults.Length + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddButton(35, y + 4, 0x938, 0x939, 2 + m_Defaults.Length + i);
|
||||
}
|
||||
|
||||
y += 22;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public string Center(string text) => $"<CENTER>{text}</CENTER>";
|
||||
from.SendGump(new PickRulesetGump(context, ruleset));
|
||||
}
|
||||
|
||||
public override void OnResponse(NetState sender, in RelayInfo info)
|
||||
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)
|
||||
{
|
||||
if (m_Context?.Registered == false)
|
||||
var cur = _defaults[i];
|
||||
|
||||
builder.AddHtml(35 + 14, y, 176, 20, cur.Title);
|
||||
|
||||
if (_ruleset.Base == cur && !_ruleset.Changed)
|
||||
{
|
||||
return;
|
||||
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);
|
||||
}
|
||||
|
||||
switch (info.ButtonID)
|
||||
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))
|
||||
{
|
||||
case 0: // closed
|
||||
{
|
||||
if (m_Context != null)
|
||||
{
|
||||
m_From.SendGump(new DuelContextGump(m_From, m_Context));
|
||||
}
|
||||
builder.AddButton(35, y + 4, 0x939, 0x938, 2 + _defaults.Length + i);
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.AddButton(35, y + 4, 0x938, 0x939, 2 + _defaults.Length + i);
|
||||
}
|
||||
|
||||
break;
|
||||
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);
|
||||
}
|
||||
case 1: // customize
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: // customize
|
||||
{
|
||||
RulesetGump.DisplayTo(from, _ruleset, _ruleset.Layout, _context);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
var idx = info.ButtonID - 2;
|
||||
|
||||
if (idx >= 0 && idx < _defaults.Length)
|
||||
{
|
||||
m_From.SendGump(new RulesetGump(m_From, m_Ruleset, m_Ruleset.Layout, m_Context));
|
||||
break;
|
||||
_ruleset.ApplyDefault(_defaults[idx]);
|
||||
from.SendGump(this); // refresh-via-this
|
||||
}
|
||||
default:
|
||||
else
|
||||
{
|
||||
var idx = info.ButtonID - 2;
|
||||
idx -= _defaults.Length;
|
||||
|
||||
if (idx >= 0 && idx < m_Defaults.Length)
|
||||
if (idx >= 0 && idx < _flavors.Length)
|
||||
{
|
||||
m_Ruleset.ApplyDefault(m_Defaults[idx]);
|
||||
m_From.SendGump(new PickRulesetGump(m_From, m_Context, m_Ruleset));
|
||||
}
|
||||
else
|
||||
{
|
||||
idx -= m_Defaults.Length;
|
||||
|
||||
if (idx >= 0 && idx < m_Flavors.Length)
|
||||
if (_ruleset.Flavors.Contains(_flavors[idx]))
|
||||
{
|
||||
if (m_Ruleset.Flavors.Contains(m_Flavors[idx]))
|
||||
{
|
||||
m_Ruleset.RemoveFlavor(m_Flavors[idx]);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_Ruleset.AddFlavor(m_Flavors[idx]);
|
||||
}
|
||||
|
||||
m_From.SendGump(new PickRulesetGump(m_From, m_Context, m_Ruleset));
|
||||
_ruleset.RemoveFlavor(_flavors[idx]);
|
||||
}
|
||||
else
|
||||
{
|
||||
_ruleset.AddFlavor(_flavors[idx]);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
from.SendGump(this); // refresh-via-this
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue