## 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.
157 lines
4 KiB
C#
157 lines
4 KiB
C#
using System.Collections;
|
|
using Server.Gumps;
|
|
using Server.Network;
|
|
|
|
namespace Server.Engines.ConPVP;
|
|
|
|
public class RulesetGump : DynamicGump
|
|
{
|
|
private readonly DuelContext _duelContext;
|
|
private readonly RulesetLayout _page;
|
|
private readonly bool _readOnly;
|
|
private readonly Ruleset _ruleset;
|
|
|
|
public override bool Singleton => true;
|
|
|
|
private RulesetGump(Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly)
|
|
: base(readOnly ? 310 : 50, 50)
|
|
{
|
|
_ruleset = ruleset;
|
|
_page = page;
|
|
_duelContext = duelContext;
|
|
_readOnly = readOnly;
|
|
}
|
|
|
|
public static void DisplayTo(
|
|
Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly = false
|
|
)
|
|
{
|
|
if (from?.NetState == null || ruleset == null || page == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var gumps = from.GetGumps();
|
|
gumps.Close<DuelContextGump>();
|
|
gumps.Close<ParticipantGump>();
|
|
|
|
from.SendGump(new RulesetGump(ruleset, page, duelContext, readOnly));
|
|
}
|
|
|
|
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
|
{
|
|
if (_readOnly)
|
|
{
|
|
builder.SetNoMove();
|
|
}
|
|
|
|
var depthCounter = _page;
|
|
|
|
while (depthCounter != null)
|
|
{
|
|
depthCounter = depthCounter.Parent;
|
|
}
|
|
|
|
var count = _page.Children.Length + _page.Options.Length;
|
|
|
|
builder.AddPage();
|
|
|
|
var height = 35 + 10 + 2 + count * 22 + 2 + 30;
|
|
|
|
builder.AddBackground(0, 0, 260, height, 9250);
|
|
builder.AddBackground(10, 10, 240, height - 20, 0xDAC);
|
|
|
|
builder.AddHtml(35, 25, 190, 20, _page.Title.Center());
|
|
|
|
var x = 35;
|
|
var y = 47;
|
|
|
|
for (var i = 0; i < _page.Children.Length; ++i)
|
|
{
|
|
AddGoldenButton(ref builder, x, y, 1 + i);
|
|
builder.AddHtml(x + 25, y, 250, 22, _page.Children[i].Title);
|
|
|
|
y += 22;
|
|
}
|
|
|
|
for (var i = 0; i < _page.Options.Length; ++i)
|
|
{
|
|
var enabled = _ruleset.Options[_page.Offset + i];
|
|
|
|
if (_readOnly)
|
|
{
|
|
builder.AddImage(x, y, enabled ? 0xD3 : 0xD2);
|
|
}
|
|
else
|
|
{
|
|
builder.AddCheckbox(x, y, 0xD2, 0xD3, enabled, i);
|
|
}
|
|
|
|
builder.AddHtml(x + 25, y, 250, 22, _page.Options[i]);
|
|
|
|
y += 22;
|
|
}
|
|
}
|
|
|
|
private static void AddGoldenButton(ref DynamicGumpBuilder builder, int x, int y, int bid)
|
|
{
|
|
builder.AddButton(x, y, 0xD2, 0xD2, bid);
|
|
builder.AddButton(x + 3, y + 3, 0xD8, 0xD8, bid);
|
|
}
|
|
|
|
public override void OnResponse(NetState sender, in RelayInfo info)
|
|
{
|
|
if (_duelContext?.Registered == false)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!_readOnly)
|
|
{
|
|
var opts = new BitArray(_page.Options.Length);
|
|
|
|
for (var i = 0; i < info.Switches.Length; ++i)
|
|
{
|
|
var sid = info.Switches[i];
|
|
|
|
if (sid >= 0 && sid < _page.Options.Length)
|
|
{
|
|
opts[sid] = true;
|
|
}
|
|
}
|
|
|
|
for (var i = 0; i < opts.Length; ++i)
|
|
{
|
|
if (_ruleset.Options[_page.Offset + i] != opts[i])
|
|
{
|
|
_ruleset.Options[_page.Offset + i] = opts[i];
|
|
_ruleset.Changed = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
var from = sender.Mobile;
|
|
var bid = info.ButtonID;
|
|
|
|
if (bid == 0)
|
|
{
|
|
if (_page.Parent != null)
|
|
{
|
|
DisplayTo(from, _ruleset, _page.Parent, _duelContext, _readOnly);
|
|
}
|
|
else if (!_readOnly)
|
|
{
|
|
PickRulesetGump.DisplayTo(from, _duelContext, _ruleset);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
bid -= 1;
|
|
|
|
if (bid >= 0 && bid < _page.Children.Length)
|
|
{
|
|
DisplayTo(from, _ruleset, _page.Children[bid], _duelContext, _readOnly);
|
|
}
|
|
}
|
|
}
|
|
}
|