feat: Moves gumps out of the core (#1916)

> [!Important]
> **Developer Note**
> This code change will **completely move gumps out of the core**


### Summary

- Adds `GetGumps()` convenience which exposes methods to Find/Close/Send multiple gumps. This helper is a performance improvement by eliminating the Dictionary<Player, List> lookup for gumps.
This commit is contained in:
Kamron Batman 2024-08-09 19:07:32 -07:00 • committed by GitHub
parent 40d99f6d1c
commit 8282b00ca2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
246 changed files with 1722 additions and 1383 deletions

View file

@ -22,6 +22,8 @@ namespace Server.Engines.ConPVP
private bool m_Active = true;
public override bool Singleton => true;
public AcceptDuelGump(Mobile challenger, Mobile challenged, DuelContext context, Participant p, int slot) : base(
50,
50
@ -33,8 +35,6 @@ namespace Server.Engines.ConPVP
m_Participant = p;
m_Slot = slot;
challenged.CloseGump<AcceptDuelGump>();
Closable = false;
AddPage(0);
@ -244,23 +244,18 @@ namespace Server.Engines.ConPVP
m_Challenger.SendMessage($"{m_Challenged.Name} has accepted the request.");
m_Challenged.SendMessage($"You have accepted the request from {m_Challenger.Name}.");
var ns = m_Challenger.NetState;
if (ns != null)
foreach (var g in m_Challenger.GetAllGumps())
{
foreach (var g in ns.Gumps)
if (g is ParticipantGump pg && pg.Participant == m_Participant)
{
if (g is ParticipantGump pg && pg.Participant == m_Participant)
{
m_Challenger.SendGump(new ParticipantGump(m_Challenger, m_Context, m_Participant));
break;
}
m_Challenger.SendGump(new ParticipantGump(m_Challenger, m_Context, m_Participant));
break;
}
if (g is DuelContextGump dcg && dcg.Context == m_Context)
{
m_Challenger.SendGump(new DuelContextGump(m_Challenger, m_Context));
break;
}
if (g is DuelContextGump dcg && dcg.Context == m_Context)
{
m_Challenger.SendGump(new DuelContextGump(m_Challenger, m_Context));
break;
}
}
}

View file

@ -135,9 +135,9 @@ namespace Server.Engines.ConPVP
string title = move switch
{
NinjaMove => "Bushido",
NinjaMove => "Bushido",
SamuraiMove => "Ninjitsu",
_ => null
_ => null
};
if (title == null || name == null || Ruleset.GetOption(title, name))
@ -199,15 +199,15 @@ namespace Server.Engines.ConPVP
case MagerySpell magerySpell:
title = magerySpell.Circle switch
{
SpellCircle.First => "1st Circle",
SpellCircle.Second => "2nd Circle",
SpellCircle.Third => "3rd Circle",
SpellCircle.Fourth => "4th Circle",
SpellCircle.Fifth => "5th Circle",
SpellCircle.Sixth => "6th Circle",
SpellCircle.First => "1st Circle",
SpellCircle.Second => "2nd Circle",
SpellCircle.Third => "3rd Circle",
SpellCircle.Fourth => "4th Circle",
SpellCircle.Fifth => "5th Circle",
SpellCircle.Sixth => "6th Circle",
SpellCircle.Seventh => "7th Circle",
SpellCircle.Eighth => "8th Circle",
_ => null
SpellCircle.Eighth => "8th Circle",
_ => null
};
option = magerySpell.Name;
@ -1431,7 +1431,6 @@ namespace Server.Engines.ConPVP
if (prefs != null)
{
e.Mobile.CloseGump<PreferencesGump>();
e.Mobile.SendGump(new PreferencesGump(e.Mobile, prefs));
}
}
@ -1542,23 +1541,18 @@ namespace Server.Engines.ConPVP
p.Nullify(pl);
pm.DuelPlayer = null;
var ns = init.NetState;
if (ns != null)
foreach (var g in init.GetAllGumps())
{
foreach (var g in ns.Gumps)
if (g is ParticipantGump pg && pg.Participant == p)
{
if (g is ParticipantGump pg && pg.Participant == p)
{
init.SendGump(new ParticipantGump(init, dc, p));
break;
}
init.SendGump(new ParticipantGump(init, dc, p));
break;
}
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
break;
}
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
break;
}
}
}
@ -1580,34 +1574,29 @@ namespace Server.Engines.ConPVP
p.Nullify(pl);
pm.DuelPlayer = null;
var ns = init.NetState;
var send = true;
if (ns != null)
foreach (var g in init.GetAllGumps())
{
var send = true;
foreach (var g in ns.Gumps)
if (g is ParticipantGump pg && pg.Participant == p)
{
if (g is ParticipantGump pg && pg.Participant == p)
{
init.SendGump(new ParticipantGump(init, dc, p));
send = false;
break;
}
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
send = false;
break;
}
init.SendGump(new ParticipantGump(init, dc, p));
send = false;
break;
}
if (send)
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
send = false;
break;
}
}
if (send)
{
init.SendGump(new DuelContextGump(init, dc));
}
}
}
else
@ -1629,34 +1618,29 @@ namespace Server.Engines.ConPVP
p.Nullify(pl);
pm.DuelPlayer = null;
var ns = init.NetState;
var send = true;
if (ns != null)
foreach (var g in init.GetAllGumps())
{
var send = true;
foreach (var g in ns.Gumps)
if (g is ParticipantGump pg && pg.Participant == p)
{
if (g is ParticipantGump pg && pg.Participant == p)
{
init.SendGump(new ParticipantGump(init, dc, p));
send = false;
break;
}
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
send = false;
break;
}
init.SendGump(new ParticipantGump(init, dc, p));
send = false;
break;
}
if (send)
if (g is DuelContextGump dcg && dcg.Context == dc)
{
init.SendGump(new DuelContextGump(init, dc));
send = false;
break;
}
}
if (send)
{
init.SendGump(new DuelContextGump(init, dc));
}
}
}
}
@ -1714,13 +1698,15 @@ namespace Server.Engines.ConPVP
public void CloseAllGumps(DuelPlayer pl)
{
pl.Mobile.CloseGump<BeginGump>();
pl.Mobile.CloseGump<DuelContextGump>();
pl.Mobile.CloseGump<ParticipantGump>();
pl.Mobile.CloseGump<PickRulesetGump>();
pl.Mobile.CloseGump<ReadyGump>();
pl.Mobile.CloseGump<ReadyUpGump>();
pl.Mobile.CloseGump<RulesetGump>();
var gumps = pl.Mobile.GetGumps();
gumps.Close<BeginGump>();
gumps.Close<DuelContextGump>();
gumps.Close<ParticipantGump>();
gumps.Close<PickRulesetGump>();
gumps.Close<ReadyGump>();
gumps.Close<ReadyUpGump>();
gumps.Close<RulesetGump>();
}
public void CloseAllGumps()
@ -1799,9 +1785,11 @@ namespace Server.Engines.ConPVP
}
// Close all of them?
mob.CloseGump<DuelContextGump>();
mob.CloseGump<ReadyUpGump>();
mob.CloseGump<ReadyGump>();
var gumps = mob.GetGumps();
gumps.Close<DuelContextGump>();
gumps.Close<ReadyUpGump>();
gumps.Close<ReadyGump>();
}
}
@ -2194,10 +2182,12 @@ namespace Server.Engines.ConPVP
{
if (count == 10)
{
mob.CloseGump<ReadyGump>();
mob.CloseGump<ReadyUpGump>();
mob.CloseGump<BeginGump>();
mob.SendGump(new BeginGump(count));
var gumps = mob.GetGumps();
gumps.Close<ReadyGump>();
gumps.Close<ReadyUpGump>();
gumps.Close<BeginGump>();
gumps.Send(new BeginGump(count));
}
mob.Frozen = true;
@ -2256,8 +2246,7 @@ namespace Server.Engines.ConPVP
if (mob != null && m_Tournament == null)
{
mob.CloseGump<ReadyUpGump>();
mob.SendGump(new ReadyUpGump(mob, this));
mob.SendGump(new ReadyUpGump(mob, this), true);
}
}
}
@ -2512,8 +2501,7 @@ namespace Server.Engines.ConPVP
{
if (m_Tournament == null)
{
mob.CloseGump<ReadyGump>();
mob.SendGump(new ReadyGump(mob, this, count));
mob.SendGump(new ReadyGump(mob, this, count), true);
}
}
else

View file

@ -1057,7 +1057,6 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump<BRBoardGump>();
from.SendGump(new BRBoardGump(from, m_TeamInfo.Game));
}
}
@ -1082,7 +1081,7 @@ namespace Server.Engines.ConPVP
private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000000;
// private BRGame m_Game;
public override bool Singleton => true;
public BRBoardGump(Mobile mob, BRGame game, BRTeamInfo section = null) : base(60, 60)
{
@ -1719,7 +1718,6 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump<BRBoardGump>();
mob.SendGump(new BRBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1918,7 +1916,6 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump<BRBoardGump>();
dp.Mobile.SendGump(new BRBoardGump(dp.Mobile, this));
}
}

View file

@ -29,7 +29,6 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump<CTFBoardGump>();
from.SendGump(new CTFBoardGump(from, m_TeamInfo.Game));
}
}
@ -56,6 +55,8 @@ namespace Server.Engines.ConPVP
private CTFGame m_Game;
public override bool Singleton => true;
public CTFBoardGump(Mobile mob, CTFGame game, CTFTeamInfo section = null)
: base(60, 60)
{
@ -1059,7 +1060,6 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump<CTFBoardGump>();
mob.SendGump(new CTFBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1258,7 +1258,6 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump<CTFBoardGump>();
dp.Mobile.SendGump(new CTFBoardGump(dp.Mobile, this));
}
}

View file

@ -27,7 +27,6 @@ namespace Server.Engines.ConPVP
{
if (m_TeamInfo?.Game != null)
{
from.CloseGump<DDBoardGump>();
from.SendGump(new DDBoardGump(from, m_TeamInfo.Game));
}
}
@ -52,7 +51,7 @@ namespace Server.Engines.ConPVP
private const int LabelColor32 = 0xFFFFFF;
private const int BlackColor32 = 0x000000;
// private DDGame m_Game;
public override bool Singleton => true;
public DDBoardGump(Mobile mob, DDGame game, DDTeamInfo section = null)
: base(60, 60)
@ -605,7 +604,6 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump<DDBoardGump>();
mob.SendGump(new DDBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -820,7 +818,6 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump<DDBoardGump>();
dp.Mobile.SendGump(new DDBoardGump(dp.Mobile, this));
}
}

View file

@ -311,7 +311,6 @@ namespace Server.Engines.ConPVP
{
if (m_Game != null)
{
from.CloseGump<KHBoardGump>();
from.SendGump(new KHBoardGump(from, m_Game));
}
else
@ -353,6 +352,8 @@ namespace Server.Engines.ConPVP
private KHGame m_Game;
public override bool Singleton => true;
public KHBoardGump(Mobile mob, KHGame game)
: base(60, 60)
{
@ -989,7 +990,6 @@ namespace Server.Engines.ConPVP
}
}
mob.CloseGump<KHBoardGump>();
mob.SendGump(new KHBoardGump(mob, this));
m_Context.Requip(mob, corpse);
@ -1199,7 +1199,6 @@ namespace Server.Engines.ConPVP
if (dp?.Mobile != null)
{
dp.Mobile.CloseGump<KHBoardGump>();
dp.Mobile.SendGump(new KHBoardGump(dp.Mobile, this));
}
}

View file

@ -50,7 +50,6 @@ namespace Server.Engines.ConPVP
return false;
}
from.CloseGump<ArenaGump>();
from.SendGump(new ArenaGump(from, this));
if (!from.Hidden || from.AccessLevel == AccessLevel.Player)
@ -84,6 +83,8 @@ namespace Server.Engines.ConPVP
private int m_ColumnX = 12;
public override bool Singleton => true;
public ArenaGump(Mobile from, ArenasMoongate gate) : base(50, 50)
{
m_From = from;

View file

@ -19,6 +19,8 @@ namespace Server.Engines.ConPVP
private readonly Mobile m_Registrar;
private readonly Tournament m_Tournament;
public override bool Singleton => true;
public ConfirmSignupGump(Mobile from, Mobile registrar, Tournament tourney, List<Mobile> players) : base(50, 50)
{
m_From = from;
@ -26,10 +28,11 @@ namespace Server.Engines.ConPVP
m_Tournament = tourney;
m_Players = players;
m_From.CloseGump<AcceptTeamGump>();
m_From.CloseGump<AcceptDuelGump>();
m_From.CloseGump<DuelContextGump>();
m_From.CloseGump<ConfirmSignupGump>();
var gumps = m_From.GetGumps();
gumps.Close<AcceptTeamGump>();
gumps.Close<AcceptDuelGump>();
gumps.Close<DuelContextGump>();
var ruleset = tourney.Ruleset;
var basedef = ruleset.Base;

View file

@ -5,14 +5,17 @@ namespace Server.Engines.ConPVP
{
public class DuelContextGump : Gump
{
public override bool Singleton => true;
public DuelContextGump(Mobile from, DuelContext context) : base(50, 50)
{
From = from;
Context = context;
from.CloseGump<RulesetGump>();
from.CloseGump<DuelContextGump>();
from.CloseGump<ParticipantGump>();
var gumps = from.GetGumps();
gumps.Close<RulesetGump>();
gumps.Close<ParticipantGump>();
var count = context.Participants.Count;

View file

@ -52,8 +52,7 @@ namespace Server.Engines.ConPVP
if (ladder != null)
{
from.CloseGump<LadderGump>();
from.SendGump(new LadderGump(ladder));
from.SendGump(new LadderGump(ladder), true);
}
}
else

View file

@ -7,15 +7,18 @@ namespace Server.Engines.ConPVP
{
public class ParticipantGump : Gump
{
public override bool Singleton => true;
public ParticipantGump(Mobile from, DuelContext context, Participant p) : base(50, 50)
{
From = from;
Context = context;
Participant = p;
from.CloseGump<RulesetGump>();
from.CloseGump<DuelContextGump>();
from.CloseGump<ParticipantGump>();
var gumps = from.GetGumps();
gumps.Close<RulesetGump>();
gumps.Close<DuelContextGump>();
var count = p.Players.Length;

View file

@ -12,6 +12,8 @@ namespace Server.Engines.ConPVP
private readonly bool m_ReadOnly;
private readonly Ruleset m_Ruleset;
public override bool Singleton => true;
public RulesetGump(Mobile from, Ruleset ruleset, RulesetLayout page, DuelContext duelContext, bool readOnly = false)
: base(readOnly ? 310 : 50, 50)
{
@ -23,9 +25,10 @@ namespace Server.Engines.ConPVP
Draggable = !readOnly;
from.CloseGump<RulesetGump>();
from.CloseGump<DuelContextGump>();
from.CloseGump<ParticipantGump>();
var gumps = from.GetGumps();
gumps.Close<DuelContextGump>();
gumps.Close<ParticipantGump>();
var depthCounter = page;

View file

@ -179,6 +179,8 @@ namespace Server.Engines.ConPVP
private readonly PreferencesEntry m_Entry;
private int m_ColumnX = 12;
public override bool Singleton => true;
public PreferencesGump(Mobile from, Preferences prefs) : base(50, 50)
{
m_Entry = prefs.Find(from);

View file

@ -1,3 +1,5 @@
using Server.Gumps;
namespace Server.Engines.ConPVP
{
public class TournamentBracketItem : Item
@ -26,8 +28,7 @@ namespace Server.Engines.ConPVP
if (tourney != null)
{
from.CloseGump<TournamentBracketGump>();
from.SendGump(new TournamentBracketGump(from, tourney, TourneyBracketGumpType.Index));
from.SendGump(new TournamentBracketGump(from, tourney, TourneyBracketGumpType.Index), true);
}
}
}

View file

@ -66,9 +66,11 @@ namespace Server.Engines.ConPVP
{
if (from.AccessLevel >= AccessLevel.GameMaster && Tournament != null)
{
from.CloseGump<PickRulesetGump>();
from.CloseGump<RulesetGump>();
from.SendGump(new PickRulesetGump(from, null, Tournament.Ruleset));
var gumps = from.GetGumps();
gumps.Close<RulesetGump>();
gumps.Close<PickRulesetGump>();
gumps.Send(new PickRulesetGump(from, null, Tournament.Ruleset));
}
}

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using Server.Factions;
using Server.Gumps;
using Server.Mobiles;
namespace Server.Engines.ConPVP
@ -146,7 +147,6 @@ namespace Server.Engines.ConPVP
}
else if (!tourney.HasParticipant(from))
{
from.CloseGump<ConfirmSignupGump>();
from.SendGump(new ConfirmSignupGump(from, Registrar, tourney, new List<Mobile> { from }));
}
else