ModernUO/Projects/UOContent/Items/Aquarium/AquariumGump.cs
Kamron Batman ec85d97482
perf: Migrate Holiday and Decorative gumps to DynamicGump/StaticGump (#2413)
## Summary

Migrates 10 player-facing legacy `Gump` subclasses for holiday and decorative items to the modern `DynamicGump` / `StaticGump<T>` system. All migrated gumps are `Singleton`, use private constructors gated by static `DisplayTo(...)` entry points (empty-gump rule, CLAUDE.md §13), and replace legacy `m_X` fields with `_x` per coding standards.

Per-gump base type and rationale:

- **Mistletoe.cs** — `MistletoeAddonGump` -> `StaticGump<MistletoeAddonGump>`. Fixed re-deed confirmation layout.
- **StValentinesBears.cs** — Renamed `InternalGump` -> `StValentinesBearsGump`, base `StaticGump<T>`. Fixed sign-bear layout with three text entries; legacy `m_Bear` -> `_bear`. Switched legacy `AddTextEntry(..., size)` -> `AddTextEntryLimited(...)` (modern API split).
- **Wreath.cs** — `WreathAddonGump` -> `StaticGump<WreathAddonGump>`. Fixed re-deed confirmation layout.
- **HolidayPottedPlant.cs** — Renamed `InternalGump` -> `HolidayPottedPlantGump`, base `StaticGump<T>`. Fixed plant-picker layout.
- **SnowStatue.cs** — Renamed `InternalGump` -> `SnowStatueGump`, base `StaticGump<T>`. Fixed statue-picker layout. Dropped unused `Mobile from` ctor arg.
- **TapestryOfSosaria.cs** — Renamed `InternalGump` -> `TapestryOfSosariaGump`, base `StaticGump<T>`. Single image, fixed.
- **HouseRaffleDeed.cs** — `WritOfLeaseGump` -> `DynamicGump`. Description HTML is computed per-instance from deed expiration / days-left, so layout text varies per instance. Added `Singleton => true` (was missing implicitly via legacy default).
- **SpecialScroll.cs** — Renamed `InternalGump` -> `SpecialScrollGump`, base `DynamicGump`. **Cliloc rule**: `_scroll.Message`, `_scroll.Title`, `_scroll.SkillLabel` are dynamic cliloc numbers per scroll type — `AddHtmlLocalized` bakes the cliloc number into the cached layout, so `StaticGump<T>` cannot cache it.
- **BallotBox.cs** — Renamed `InternalGump` -> `BallotBoxGump`, base `DynamicGump`. Layout shape varies: variable topic-line count, owner-vs-voter buttons, and vote-tally bars all add/remove elements. Legacy `m_Box` -> `_box`. Updated the `TopicPrompt` callbacks to call `BallotBoxGump.DisplayTo(...)` instead of allocating a new gump directly.
- **AquariumGump.cs** — `AquariumGump` -> `DynamicGump`. Per-page layout depends on each item's `LabelNumber` and (for `BaseFish`) `GetDescription()` cliloc — those vary per fish/decoration. Two `DisplayTo` overloads (auto-detect access vs explicit edit flag) to mirror the original two call sites in `Aquarium.cs`. Legacy `m_Aquarium` -> `_aquarium`.

### Skipped

- **HouseRaffleManagementGump.cs** — Skipped as **staff-only**. Only invoked via `ManagementEntry` context entry inside `HouseRaffleStone.cs`, gated by `from.AccessLevel >= AccessLevel.Seer`. Per task instructions, staff-only gumps are out of scope for this PR.

### External callers updated

- `Aquarium.cs` — Two `new AquariumGump(...)` sites swapped to `AquariumGump.DisplayTo(...)`.

All other migrated inner classes were nested in the same file and only had local references, which were updated to call the new `DisplayTo(...)` static entry point.
2026-04-25 17:22:41 -07:00

111 lines
3 KiB
C#

using Server.Gumps;
using Server.Network;
namespace Server.Items;
public class AquariumGump : DynamicGump
{
private readonly Aquarium _aquarium;
private readonly bool _edit;
public override bool Singleton => true;
private AquariumGump(Aquarium aquarium, bool edit) : base(100, 100)
{
_aquarium = aquarium;
_edit = edit;
}
public static void DisplayTo(Mobile from, Aquarium aquarium)
{
if (from?.NetState == null || aquarium?.Deleted != false)
{
return;
}
from.SendGump(new AquariumGump(aquarium, aquarium.HasAccess(from)));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(0, 0, 350, 323, 0xE10);
builder.AddImage(0, 0, 0x2C96);
for (var i = 1; i <= _aquarium.Items.Count; i++)
{
DisplayPage(ref builder, i, _edit);
}
}
private void DisplayPage(ref DynamicGumpBuilder builder, int page, bool edit)
{
builder.AddPage(page);
var item = _aquarium.Items[page - 1];
// item name
if (item.LabelNumber != 0)
{
builder.AddHtmlLocalized(20, 217, 250, 20, item.LabelNumber, 0x7FFF); // Name
}
// item details
if (item is BaseFish fish)
{
builder.AddHtmlLocalized(20, 239, 315, 20, fish.GetDescription(), 0x7FFF);
}
else
{
builder.AddHtmlLocalized(20, 239, 315, 20, 1073634, 0x7FFF); // An aquarium decoration
}
// item image
builder.AddItem(150, 80, item.ItemID, item.Hue);
// item number / all items
builder.AddHtml(20, 195, 250, 20, Html.Color($"{page}/{_aquarium.Items.Count}", 0xFFFFFF));
// remove item
if (edit)
{
builder.AddBackground(230, 195, 100, 26, 0x13BE);
builder.AddButton(235, 200, 0x845, 0x846, page);
builder.AddHtmlLocalized(260, 198, 60, 26, 1073838, 0x0); // Remove
}
// next page
if (page < _aquarium.Items.Count)
{
builder.AddButton(195, 280, 0xFA5, 0xFA7, 0, GumpButtonType.Page, page + 1);
builder.AddHtmlLocalized(230, 283, 100, 18, 1044045, 0x7FFF); // NEXT PAGE
}
// previous page
if (page > 1)
{
builder.AddButton(45, 280, 0xFAE, 0xFAF, 0, GumpButtonType.Page, page - 1);
builder.AddHtmlLocalized(80, 283, 100, 18, 1044044, 0x7FFF); // PREV PAGE
}
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (_aquarium?.Deleted != false)
{
return;
}
var edit = _aquarium.HasAccess(sender.Mobile);
if (info.ButtonID > 0 && info.ButtonID <= _aquarium.Items.Count && edit)
{
_aquarium.RemoveItem(sender.Mobile, info.ButtonID - 1);
}
if (info.ButtonID > 0)
{
sender.Mobile.SendGump(this);
}
}
}