## 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.
152 lines
4.2 KiB
C#
152 lines
4.2 KiB
C#
using System.Collections.Generic;
|
|
using Server.Collections;
|
|
using Server.ContextMenus;
|
|
using Server.Gumps;
|
|
|
|
namespace Server.Engines.ConPVP
|
|
{
|
|
public class TournamentController : Item
|
|
{
|
|
private static readonly List<TournamentController> m_Instances = new();
|
|
|
|
[Constructible]
|
|
public TournamentController() : base(0x1B7A)
|
|
{
|
|
Visible = false;
|
|
Movable = false;
|
|
|
|
Tournament = new Tournament();
|
|
m_Instances.Add(this);
|
|
}
|
|
|
|
public TournamentController(Serial serial) : base(serial)
|
|
{
|
|
}
|
|
|
|
[CommandProperty(AccessLevel.GameMaster, canModify: true)]
|
|
public Tournament Tournament { get; private set; }
|
|
|
|
public static bool IsActive
|
|
{
|
|
get
|
|
{
|
|
for (var i = 0; i < m_Instances.Count; ++i)
|
|
{
|
|
var controller = m_Instances[i];
|
|
|
|
if (controller?.Deleted == false && controller.Tournament != null &&
|
|
controller.Tournament.Stage != TournamentStage.Inactive)
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public override string DefaultName => "tournament controller";
|
|
|
|
public override void GetContextMenuEntries(Mobile from, ref PooledRefList<ContextMenuEntry> list)
|
|
{
|
|
base.GetContextMenuEntries(from, ref list);
|
|
|
|
if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null)
|
|
{
|
|
list.Add(new EditEntry());
|
|
|
|
if (Tournament.CurrentStage == TournamentStage.Inactive)
|
|
{
|
|
list.Add(new StartEntry());
|
|
}
|
|
}
|
|
}
|
|
|
|
public override void OnDoubleClick(Mobile from)
|
|
{
|
|
if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null)
|
|
{
|
|
var gumps = from.GetGumps();
|
|
|
|
gumps.Close<RulesetGump>();
|
|
gumps.Close<PickRulesetGump>();
|
|
PickRulesetGump.DisplayTo(from, null, Tournament.Ruleset);
|
|
}
|
|
}
|
|
|
|
public override void Serialize(IGenericWriter writer)
|
|
{
|
|
base.Serialize(writer);
|
|
|
|
writer.Write(0);
|
|
|
|
Tournament.Serialize(writer);
|
|
}
|
|
|
|
public override void Deserialize(IGenericReader reader)
|
|
{
|
|
base.Deserialize(reader);
|
|
|
|
var version = reader.ReadInt();
|
|
|
|
switch (version)
|
|
{
|
|
case 0:
|
|
{
|
|
Tournament = new Tournament(reader);
|
|
break;
|
|
}
|
|
}
|
|
|
|
m_Instances.Add(this);
|
|
}
|
|
|
|
public override void OnDelete()
|
|
{
|
|
base.OnDelete();
|
|
|
|
m_Instances.Remove(this);
|
|
}
|
|
|
|
private class EditEntry : ContextMenuEntry
|
|
{
|
|
public EditEntry() : base(5101)
|
|
{
|
|
}
|
|
|
|
public override void OnClick(Mobile from, IEntity target)
|
|
{
|
|
if (target is not TournamentController controller)
|
|
{
|
|
return;
|
|
}
|
|
|
|
from.SendGump(new PropertiesGump(from, controller.Tournament));
|
|
}
|
|
}
|
|
|
|
private class StartEntry : ContextMenuEntry
|
|
{
|
|
public StartEntry() : base(5113)
|
|
{
|
|
}
|
|
|
|
public override void OnClick(Mobile from, IEntity target)
|
|
{
|
|
if (target is not TournamentController controller || controller.Tournament.Stage != TournamentStage.Inactive)
|
|
{
|
|
return;
|
|
}
|
|
|
|
controller.Tournament.SignupStart = Core.Now;
|
|
controller.Tournament.Stage = TournamentStage.Signup;
|
|
controller.Tournament.Participants.Clear();
|
|
controller.Tournament.Pyramid.Levels.Clear();
|
|
controller.Tournament.Alert(
|
|
"Hear ye! Hear ye!",
|
|
"Tournament signup has opened. You can enter by signing up with the registrar."
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|