ModernUO/Projects/UOContent/Items/Special/Special Scrolls/SpecialScroll.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

141 lines
3.6 KiB
C#

using ModernUO.Serialization;
using Server.Gumps;
using Server.Network;
namespace Server.Items;
[SerializationGenerator(0, false)]
public abstract partial class SpecialScroll : Item
{
[InvalidateProperties]
[SerializableField(0)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private SkillName _skill;
[InvalidateProperties]
[SerializableField(1)]
[SerializedCommandProperty(AccessLevel.GameMaster)]
private double _value;
public SpecialScroll(SkillName skill, double value) : base(0x14F0)
{
LootType = LootType.Cursed;
_skill = skill;
_value = value;
}
public override double DefaultWeight => 1.0;
public abstract int Message { get; }
public virtual int Title => 0;
public abstract string DefaultTitle { get; }
public virtual int SkillLabel => AosSkillBonuses.GetLabel(Skill);
public virtual string GetSkillName()
{
var index = (int)Skill;
var table = SkillInfo.Table;
if (index >= 0 && index < table.Length)
{
return table[index].Name.ToLower();
}
return "???";
}
public virtual bool CanUse(Mobile from)
{
if (Deleted)
{
return false;
}
if (!IsChildOf(from.Backpack))
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
return false;
}
return true;
}
public virtual void Use(Mobile from)
{
}
public override void OnDoubleClick(Mobile from)
{
if (!CanUse(from))
{
return;
}
SpecialScrollGump.DisplayTo(from, this);
}
public class SpecialScrollGump : DynamicGump
{
private readonly SpecialScroll _scroll;
public override bool Singleton => true;
private SpecialScrollGump(SpecialScroll scroll) : base(25, 50) => _scroll = scroll;
public static void DisplayTo(Mobile from, SpecialScroll scroll)
{
if (from?.NetState == null || scroll?.Deleted != false)
{
return;
}
from.SendGump(new SpecialScrollGump(scroll));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(25, 10, 420, 200, 5054);
builder.AddImageTiled(33, 20, 401, 181, 2624);
builder.AddAlphaRegion(33, 20, 401, 181);
builder.AddHtmlLocalized(40, 48, 387, 100, _scroll.Message, true, true);
builder.AddHtmlLocalized(125, 148, 200, 20, 1049478, 0x7FFF); // Do you wish to use this scroll?
builder.AddButton(100, 172, 4005, 4007, 1);
builder.AddHtmlLocalized(135, 172, 120, 20, 1046362, 0x7FFF); // Yes
builder.AddButton(275, 172, 4005, 4007, 0);
builder.AddHtmlLocalized(310, 172, 120, 20, 1046363, 0x7FFF); // No
if (_scroll.Title != 0)
{
builder.AddHtmlLocalized(40, 20, 260, 20, _scroll.Title, 0x7FFF);
}
else
{
builder.AddHtml(40, 20, 260, 20, _scroll.DefaultTitle);
}
var skillLabel = _scroll.SkillLabel;
if (skillLabel > 0)
{
builder.AddHtmlLocalized(310, 20, 120, 20, skillLabel, 0x7FFF);
}
}
public override void OnResponse(NetState state, in RelayInfo info)
{
if (info.ButtonID == 1)
{
_scroll.Use(state.Mobile);
}
}
}
}