ModernUO/Projects/UOContent/Items/Special/Holiday/Wreath.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

320 lines
7.9 KiB
C#

using ModernUO.Serialization;
using Server.Gumps;
using Server.Multis;
using Server.Network;
using Server.Targeting;
namespace Server.Items;
[SerializationGenerator(0)]
public partial class WreathAddon : Item, IDyable, IAddon
{
[Constructible]
public WreathAddon() : this(Utility.RandomDyedHue())
{
}
[Constructible]
public WreathAddon(int hue) : base(0x232C)
{
Hue = hue;
Movable = false;
}
public bool CouldFit(IPoint3D p, Map map)
{
if (!map.CanFit(p.X, p.Y, p.Z, ItemData.Height))
{
return false;
}
if (ItemID == 0x232C)
{
return BaseAddon.IsWall(p.X, p.Y - 1, p.Z, map); // North wall
}
return BaseAddon.IsWall(p.X - 1, p.Y, p.Z, map); // West wall
}
public Item Deed => new WreathDeed(Hue);
public virtual bool Dye(Mobile from, DyeTub sender)
{
if (Deleted)
{
return false;
}
var house = BaseHouse.FindHouseAt(this);
if (house?.IsCoOwner(from) == true)
{
if (from.InRange(GetWorldLocation(), 1))
{
Hue = sender.DyedHue;
return true;
}
from.SendLocalizedMessage(500295); // You are too far away to do that.
}
return false;
}
[AfterDeserialization(false)]
private void FixMovingCrate()
{
if (Deleted)
{
return;
}
if (Movable || IsLockedDown)
{
var deed = Deed;
if (Parent is Item item)
{
item.AddItem(deed);
deed.Location = Location;
}
else
{
deed.MoveToWorld(Location, Map);
}
Delete();
}
}
public override void OnDoubleClick(Mobile from)
{
var house = BaseHouse.FindHouseAt(this);
if (house?.IsCoOwner(from) != true)
{
return;
}
if (from.InRange(GetWorldLocation(), 3))
{
WreathAddonGump.DisplayTo(from, this);
}
else
{
from.LocalOverheadMessage(MessageType.Regular, 0x3B2, 1019045); // I can't reach that.
}
}
private class WreathAddonGump : StaticGump<WreathAddonGump>
{
private readonly WreathAddon _addon;
public override bool Singleton => true;
private WreathAddonGump(WreathAddon addon) : base(150, 50) => _addon = addon;
public static void DisplayTo(Mobile from, WreathAddon addon)
{
if (from?.NetState == null || addon?.Deleted != false)
{
return;
}
from.SendGump(new WreathAddonGump(addon));
}
protected override void BuildLayout(ref StaticGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(0, 0, 220, 170, 0x13BE);
builder.AddBackground(10, 10, 200, 150, 0xBB8);
builder.AddHtmlLocalized(20, 30, 180, 60, 1062839); // Do you wish to re-deed this decoration?
builder.AddHtmlLocalized(55, 100, 160, 25, 1011011); // CONTINUE
builder.AddButton(20, 100, 0xFA5, 0xFA7, 1);
builder.AddHtmlLocalized(55, 125, 160, 25, 1011012); // CANCEL
builder.AddButton(20, 125, 0xFA5, 0xFA7, 0);
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (_addon.Deleted || info.ButtonID != 1)
{
return;
}
var from = sender.Mobile;
if (from.InRange(_addon.GetWorldLocation(), 3))
{
from.AddToBackpack(_addon.Deed);
_addon.Delete();
}
else
{
from.SendLocalizedMessage(500295); // You are too far away to do that.
}
}
}
}
[Flippable(0x14F0, 0x14EF)]
[SerializationGenerator(0)]
public partial class WreathDeed : Item
{
[Constructible]
public WreathDeed() : this(Utility.RandomDyedHue())
{
}
[Constructible]
public WreathDeed(int hue) : base(0x14F0)
{
Hue = hue;
LootType = LootType.Blessed;
}
public override double DefaultWeight => 1.0;
public override int LabelNumber => 1062837; // holiday wreath deed
public override void OnDoubleClick(Mobile from)
{
if (IsChildOf(from.Backpack))
{
var house = BaseHouse.FindHouseAt(from);
if (house?.IsCoOwner(from) == true)
{
from.SendLocalizedMessage(1062838); // Where would you like to place this decoration?
from.BeginTarget(-1, true, TargetFlags.None, Placement_OnTarget);
}
else
{
from.SendLocalizedMessage(502092); // You must be in your house to do this.
}
}
else
{
from.SendLocalizedMessage(1042001); // That must be in your pack for you to use it.
}
}
public void Placement_OnTarget(Mobile from, object targeted)
{
if (targeted is not IPoint3D p)
{
return;
}
var loc = new Point3D(p);
var house = BaseHouse.FindHouseAt(loc, from.Map, 16);
if (house?.IsCoOwner(from) == true)
{
var northWall = BaseAddon.IsWall(loc.X, loc.Y - 1, loc.Z, from.Map);
var westWall = BaseAddon.IsWall(loc.X - 1, loc.Y, loc.Z, from.Map);
if (northWall && westWall)
{
from.SendGump(new WreathDeedGump(loc, this));
}
else
{
PlaceAddon(from, loc, northWall, westWall);
}
}
else
{
from.SendLocalizedMessage(1042036); // That location is not in your house.
}
}
private void PlaceAddon(Mobile from, Point3D loc, bool northWall, bool westWall)
{
if (Deleted)
{
return;
}
var house = BaseHouse.FindHouseAt(loc, from.Map, 16);
if (house?.IsCoOwner(from) != true)
{
from.SendLocalizedMessage(1042036); // That location is not in your house.
return;
}
var itemID = 0;
if (northWall)
{
itemID = 0x232C;
}
else if (westWall)
{
itemID = 0x232D;
}
else
{
from.SendLocalizedMessage(1062840); // The decoration must be placed next to a wall.
}
if (itemID > 0)
{
var addon = new WreathAddon(Hue)
{
ItemID = itemID
};
addon.MoveToWorld(loc, from.Map);
house.Addons.Add(addon);
Delete();
}
}
private class WreathDeedGump : StaticGump<WreathDeedGump>
{
private readonly WreathDeed _deed;
private readonly Point3D _loc;
public WreathDeedGump(Point3D loc, WreathDeed deed) : base(150, 50)
{
_loc = loc;
_deed = deed;
}
protected override void BuildLayout(ref StaticGumpBuilder builder)
{
builder.AddBackground(0, 0, 300, 150, 0xA28);
builder.AddPage();
builder.AddItem(90, 30, 0x232D);
builder.AddItem(180, 30, 0x232C);
builder.AddButton(50, 35, 0x868, 0x869, 1);
builder.AddButton(145, 35, 0x868, 0x869, 2);
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
if (_deed.Deleted || info.ButtonID == 0)
{
return;
}
var from = sender.Mobile;
if (info.ButtonID == 1)
{
_deed.PlaceAddon(from, _loc, false, true);
}
else
{
_deed.PlaceAddon(from, _loc, true, false);
}
}
}
}