## 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.
165 lines
4.6 KiB
C#
165 lines
4.6 KiB
C#
using Server.Gumps;
|
|
using Server.Network;
|
|
|
|
namespace Server.Engines.ConPVP;
|
|
|
|
public class DuelContextGump : DynamicGump
|
|
{
|
|
public override bool Singleton => true;
|
|
|
|
private DuelContextGump(DuelContext context) : base(50, 50) => Context = context;
|
|
|
|
public static void DisplayTo(Mobile from, DuelContext context)
|
|
{
|
|
if (from?.NetState == null || context == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var gumps = from.GetGumps();
|
|
gumps.Close<RulesetGump>();
|
|
gumps.Close<ParticipantGump>();
|
|
|
|
from.SendGump(new DuelContextGump(context));
|
|
}
|
|
|
|
public DuelContext Context { get; }
|
|
|
|
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
|
{
|
|
var count = Context.Participants.Count;
|
|
|
|
if (count < 3)
|
|
{
|
|
count = 3;
|
|
}
|
|
|
|
var height = 35 + 10 + 22 + 30 + 22 + 22 + 2 + count * 22 + 2 + 30;
|
|
|
|
builder.AddPage();
|
|
|
|
builder.AddBackground(0, 0, 300, height, 9250);
|
|
builder.AddBackground(10, 10, 280, height - 20, 0xDAC);
|
|
|
|
builder.AddHtml(35, 25, 230, 20, Center("Duel Setup"));
|
|
|
|
var x = 35;
|
|
var y = 47;
|
|
|
|
AddGoldenButtonLabeled(ref builder, x, y, 1, "Rules");
|
|
y += 22;
|
|
AddGoldenButtonLabeled(ref builder, x, y, 2, "Start");
|
|
y += 22;
|
|
AddGoldenButtonLabeled(ref builder, x, y, 3, "Add Participant");
|
|
y += 30;
|
|
|
|
builder.AddHtml(35, y, 230, 20, Center("Participants"));
|
|
y += 22;
|
|
|
|
for (var i = 0; i < Context.Participants.Count; ++i)
|
|
{
|
|
var p = Context.Participants[i];
|
|
|
|
AddGoldenButtonLabeled(
|
|
ref builder,
|
|
x,
|
|
y,
|
|
4 + i,
|
|
string.Format(
|
|
p.Count == 1 ? "Player {0}: {3}" : "Team {0}: {1}/{2}: {3}",
|
|
1 + i,
|
|
p.FilledSlots,
|
|
p.Count,
|
|
p.NameList
|
|
)
|
|
);
|
|
y += 22;
|
|
}
|
|
}
|
|
|
|
private static string Center(string text) => $"<CENTER>{text}</CENTER>";
|
|
|
|
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);
|
|
}
|
|
|
|
private static void AddGoldenButtonLabeled(ref DynamicGumpBuilder builder, int x, int y, int bid, string text)
|
|
{
|
|
AddGoldenButton(ref builder, x, y, bid);
|
|
builder.AddHtml(x + 25, y, 200, 20, text);
|
|
}
|
|
|
|
public override void OnResponse(NetState sender, in RelayInfo info)
|
|
{
|
|
if (!Context.Registered)
|
|
{
|
|
return;
|
|
}
|
|
|
|
var from = sender.Mobile;
|
|
var index = info.ButtonID;
|
|
|
|
switch (index)
|
|
{
|
|
case -1: // CloseGump
|
|
{
|
|
break;
|
|
}
|
|
case 0: // closed
|
|
{
|
|
Context.Unregister();
|
|
break;
|
|
}
|
|
case 1: // Rules
|
|
{
|
|
PickRulesetGump.DisplayTo(from, Context, Context.Ruleset);
|
|
break;
|
|
}
|
|
case 2: // Start
|
|
{
|
|
if (Context.CheckFull())
|
|
{
|
|
Context.CloseAllGumps();
|
|
Context.SendReadyUpGump();
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage(
|
|
"You cannot start the duel before all participating players have been assigned."
|
|
);
|
|
from.SendGump(this); // refresh-via-this
|
|
}
|
|
|
|
break;
|
|
}
|
|
case 3: // New Participant
|
|
{
|
|
if (Context.Participants.Count < 10)
|
|
{
|
|
Context.Participants.Add(new Participant(Context, 1));
|
|
}
|
|
else
|
|
{
|
|
from.SendMessage("The number of participating parties may not be increased further.");
|
|
}
|
|
|
|
from.SendGump(this); // refresh-via-this
|
|
|
|
break;
|
|
}
|
|
default: // Participant
|
|
{
|
|
index -= 4;
|
|
|
|
if (index >= 0 && index < Context.Participants.Count)
|
|
{
|
|
ParticipantGump.DisplayTo(from, Context, Context.Participants[index]);
|
|
}
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|