ModernUO/Projects/UOContent/Engines/Plants/EmptyTheBowlGump.cs
Kamron Batman 2423950cca
perf: Migrate Plant gumps to DynamicGump/StaticGump (#2411)
## Summary

Second PR in the player-facing legacy gump migration. Converts the four Plants system gumps:

- `MainPlantGump`, `ReproductionGump`, `EmptyTheBowlGump` → `DynamicGump`. Layout varies by plant status, growth stage, health, and pollination/resource availability — cannot use cached `StaticGump<T>`.
- `SetToDecorativeGump` → `StaticGump<SetToDecorativeGump>`. Pure confirmation dialog with no per-instance variation.

All four:

- `Singleton => true` (auto-replace previous plant gump on re-open instead of stacking)
- Constructor `private`; entry is static `DisplayTo(Mobile, PlantItem)` per the empty-gump rule (CLAUDE.md §13)
- `OnResponse` self-refresh paths converted from `from.SendGump(new XGump(_plant))` to `from.SendGump(this)` — saves an allocation on every help/info button click and on every "gather resources/seeds/pollen" action
- Helper draw methods take `ref DynamicGumpBuilder builder` instead of mutating instance state
- Renamed legacy `m_Plant` to `_plant` per CLAUDE.md §12

Updated external callers to use the new entry points:

- `PlantItem.OnDoubleClick` → `MainPlantGump.DisplayTo(from, this)`
- `PlantPourTarget.OnTargetFinish` → `MainPlantGump.DisplayTo(from, m_Plant)` (also drops the now-redundant legacy `singleton: true` flag — `Singleton` property handles it)
- `PollinateTarget.OnTargetFinish` → `ReproductionGump.DisplayTo(from, m_Plant)`
2026-04-25 16:46:37 -07:00

126 lines
3.7 KiB
C#

using Server.Engines.Help;
using Server.Gumps;
using Server.Network;
namespace Server.Engines.Plants;
public class EmptyTheBowlGump : DynamicGump
{
private readonly PlantItem _plant;
public override bool Singleton => true;
private EmptyTheBowlGump(PlantItem plant) : base(20, 20)
{
_plant = plant;
}
public static void DisplayTo(Mobile from, PlantItem plant)
{
if (from?.NetState == null || plant == null || plant.Deleted)
{
return;
}
from.SendGump(new EmptyTheBowlGump(plant));
}
protected override void BuildLayout(ref DynamicGumpBuilder builder)
{
builder.AddPage();
builder.AddBackground(50, 50, 200, 150, 0xE10);
builder.AddItem(45, 45, 0xCEF);
builder.AddItem(45, 118, 0xCF0);
builder.AddItem(211, 45, 0xCEB);
builder.AddItem(211, 118, 0xCEC);
builder.AddLabel(90, 70, 0x44, "Empty the bowl?");
builder.AddItem(90, 100, 0x1602);
builder.AddImage(140, 102, 0x15E1);
builder.AddItem(160, 100, 0x15FD);
if (_plant.PlantStatus != PlantStatus.BowlOfDirt && _plant.PlantStatus < PlantStatus.Plant)
{
builder.AddItem(156, 130, 0xDCF); // Seed
}
builder.AddButton(98, 150, 0x47E, 0x480, 1); // Cancel
builder.AddButton(138, 151, 0xD2, 0xD2, 2); // Help
builder.AddLabel(143, 151, 0x835, "?");
builder.AddButton(168, 150, 0x481, 0x483, 3); // Ok
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
var from = sender.Mobile;
if (info.ButtonID == 0 || _plant.Deleted || _plant.PlantStatus >= PlantStatus.DecorativePlant)
{
return;
}
if (info.ButtonID == 3 && !from.InRange(_plant.GetWorldLocation(), 3))
{
from.LocalOverheadMessage(MessageType.Regular, 0x3E9, 500446); // That is too far away.
return;
}
if (!_plant.IsUsableBy(from))
{
_plant.LabelTo(from, 1061856); // You must have the item in your backpack or locked down in order to use it.
return;
}
switch (info.ButtonID)
{
case 1: // Cancel
{
MainPlantGump.DisplayTo(from, _plant);
break;
}
case 2: // Help
{
from.NetState.SendDisplayHelpTopic(HelpTopic.EmptyingBowl);
from.SendGump(this);
break;
}
case 3: // Ok
{
var bowl = new PlantBowl();
if (!from.PlaceInBackpack(bowl))
{
bowl.Delete();
_plant.LabelTo(from, 1053047); // You cannot empty a bowl with a full pack!
MainPlantGump.DisplayTo(from, _plant);
break;
}
if (_plant.PlantStatus != PlantStatus.BowlOfDirt && _plant.PlantStatus < PlantStatus.Plant)
{
var seed = new Seed(_plant.PlantType, _plant.PlantHue, _plant.ShowType);
if (!from.PlaceInBackpack(seed))
{
bowl.Delete();
seed.Delete();
_plant.LabelTo(from, 1053047); // You cannot empty a bowl with a full pack!
MainPlantGump.DisplayTo(from, _plant);
break;
}
}
_plant.Delete();
break;
}
}
}
}