perf: Migrate Travel/Moongate gumps to DynamicGump (#2412)
## Summary Migrates the three player-facing travel/moongate gumps from legacy `Gump` to the modern `DynamicGump` system. - `GoGump` (Gumps/Go/GoGump.cs) → `DynamicGump`. The category-tree layout's row count varies with the current `GoCategory`'s child count and pagination. Refreshes via `SendGump(this)` after mutating `_node`/`_page` instead of allocating a new instance per nav/page click. - `MoongateGump` (Items/Misc/PublicMoongate.cs) → `DynamicGump`. The destination tab strip and per-map pages are gated by ruleset (sigil bearer, murderer, faction facet) and expansion/young flag, plus the configured map selection. The set of pages and the active-map swap make the layout shape per-instance. - `MoongateConfirmGump` (Items/Skill Items/Magical/Misc/Moongate.cs) → `DynamicGump`. Per the **dynamic-cliloc rule**, the gump bakes one of two different cliloc numbers (1062050 Felucca-warning vs 1062049 generic confirm) and selects between an AOS and pre-AOS layout shape — both characteristics force `DynamicGump` rather than `StaticGump<T>` because cached layout bytes would otherwise lock in the wrong cliloc/shape. All three now use a `private` constructor with a `public static DisplayTo(...)` entry point that validates prerequisites before any gump is allocated (empty-gump rule, CLAUDE.md §13). All are `Singleton` and use `SendGump(this)` self-refresh on internal navigation. Updated callers: `PublicMoongate.UseGate` and `Moongate.BeginConfirmation` now call `DisplayTo(...)`.
This commit is contained in:
parent
2423950cca
commit
83f771c99a
3 changed files with 218 additions and 188 deletions
|
|
@ -5,15 +5,15 @@ using static Server.Gumps.PropsConfig;
|
|||
|
||||
namespace Server.Gumps;
|
||||
|
||||
public class GoGump : Gump
|
||||
public class GoGump : DynamicGump
|
||||
{
|
||||
private const int EntryWidth = 180;
|
||||
private const int EntryCount = 15;
|
||||
|
||||
private const int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize;
|
||||
|
||||
private readonly GoCategory _node;
|
||||
private readonly int _page;
|
||||
private GoCategory _node;
|
||||
private int _page;
|
||||
|
||||
private readonly LocationTree _tree;
|
||||
|
||||
|
|
@ -33,46 +33,61 @@ public class GoGump : Gump
|
|||
_page = page;
|
||||
_tree = tree;
|
||||
_node = node;
|
||||
|
||||
var count = Math.Clamp(node.Categories.Length + node.Locations.Length - page * EntryCount, 0, EntryCount);
|
||||
|
||||
AddPage(0);
|
||||
|
||||
this.AddPropsFrame(TotalWidth, count + 1, out var x, out var y);
|
||||
this.AddPropsHeaderWithBack(
|
||||
TotalWidth, ref x, ref y, node.Name,
|
||||
node.Parent != null, 1,
|
||||
page > 0, 2,
|
||||
(page + 1) * EntryCount < node.Categories.Length + node.Locations.Length, 3,
|
||||
nextType: GumpButtonType.Reply, nextParam: 1
|
||||
);
|
||||
|
||||
var totalEntryCount = node.Categories.Length + node.Locations.Length;
|
||||
|
||||
for (int i = 0, index = page * EntryCount; i < EntryCount && index < totalEntryCount; ++i, ++index)
|
||||
{
|
||||
PropsLayout.NextRow(ref x, ref y);
|
||||
|
||||
var name = index >= node.Categories.Length
|
||||
? node.Locations[index - node.Categories.Length].Name
|
||||
: node.Categories[index].Name;
|
||||
|
||||
this.AddPropsEntryButton(ref x, ref y, EntryWidth, name, true, index + 4);
|
||||
}
|
||||
}
|
||||
|
||||
public static void DisplayTo(Mobile from)
|
||||
{
|
||||
if (from?.NetState == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var tree = GoLocations.GetLocations(from.Map);
|
||||
|
||||
if (tree == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!tree.LastBranch.TryGetValue(from, out var branch))
|
||||
{
|
||||
branch = tree.Root;
|
||||
}
|
||||
|
||||
if (branch != null)
|
||||
if (branch == null)
|
||||
{
|
||||
from.SendGump(new GoGump(0, from, tree, branch));
|
||||
return;
|
||||
}
|
||||
|
||||
from.SendGump(new GoGump(0, from, tree, branch));
|
||||
}
|
||||
|
||||
protected override void BuildLayout(ref DynamicGumpBuilder builder)
|
||||
{
|
||||
var count = Math.Clamp(_node.Categories.Length + _node.Locations.Length - _page * EntryCount, 0, EntryCount);
|
||||
|
||||
builder.AddPage();
|
||||
|
||||
builder.AddPropsFrame(TotalWidth, count + 1, out var x, out var y);
|
||||
builder.AddPropsHeaderWithBack(
|
||||
TotalWidth, ref x, ref y, _node.Name,
|
||||
_node.Parent != null, 1,
|
||||
_page > 0, 2,
|
||||
(_page + 1) * EntryCount < _node.Categories.Length + _node.Locations.Length, 3,
|
||||
nextType: GumpButtonType.Reply, nextParam: 1
|
||||
);
|
||||
|
||||
var totalEntryCount = _node.Categories.Length + _node.Locations.Length;
|
||||
|
||||
for (int i = 0, index = _page * EntryCount; i < EntryCount && index < totalEntryCount; ++i, ++index)
|
||||
{
|
||||
PropsLayout.NextRow(ref x, ref y);
|
||||
|
||||
var name = index >= _node.Categories.Length
|
||||
? _node.Locations[index - _node.Categories.Length].Name
|
||||
: _node.Categories[index].Name;
|
||||
|
||||
builder.AddPropsEntryButton(ref x, ref y, EntryWidth, name, true, index + 4);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -86,7 +101,19 @@ public class GoGump : Gump
|
|||
{
|
||||
if (_node.Parent != null)
|
||||
{
|
||||
from.SendGump(new GoGump(0, from, _tree, _node.Parent));
|
||||
_page = 0;
|
||||
_node = _node.Parent;
|
||||
|
||||
if (_node == _tree.Root)
|
||||
{
|
||||
_tree.LastBranch.Remove(from);
|
||||
}
|
||||
else
|
||||
{
|
||||
_tree.LastBranch[from] = _node;
|
||||
}
|
||||
|
||||
from.SendGump(this);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -95,7 +122,8 @@ public class GoGump : Gump
|
|||
{
|
||||
if (_page > 0)
|
||||
{
|
||||
from.SendGump(new GoGump(_page - 1, from, _tree, _node));
|
||||
_page--;
|
||||
from.SendGump(this);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -104,7 +132,8 @@ public class GoGump : Gump
|
|||
{
|
||||
if ((_page + 1) * EntryCount < _node.Categories.Length + _node.Locations.Length)
|
||||
{
|
||||
from.SendGump(new GoGump(_page + 1, from, _tree, _node));
|
||||
_page++;
|
||||
from.SendGump(this);
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
@ -120,7 +149,10 @@ public class GoGump : Gump
|
|||
|
||||
if (index < _node.Categories.Length)
|
||||
{
|
||||
from.SendGump(new GoGump(0, from, _tree, _node.Categories[index]));
|
||||
_page = 0;
|
||||
_node = _node.Categories[index];
|
||||
_tree.LastBranch[from] = _node;
|
||||
from.SendGump(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue