ModernUO/Projects/UOContent/Gumps/Props/SetListOptionGump.cs
Kamron Batman 8a34903326
feat: Consolidates staff gump layouts (#2404)
## Summary
- Creates `PropsLayoutExtensions.cs` with reusable extension methods for both legacy `Gump` and `DynamicGumpBuilder` that encapsulate the repeating PropsConfig-style layout patterns (frame, header navigation, entry rows)
- Converts all 12 standardized staff gumps to use the new extensions, reducing ~570 lines of duplicated layout code
- Adds Type and Serial display to PropsGump and SkillsGump headers (e.g. `PlayerMobile (0x1)`)

### Extension methods provided
| Method | Pattern |
|--------|---------|
| `AddPropsFrame` | Background + offset region + origin coordinates |
| `AddPropsHeader` | 3-column: [Prev] [Title] [Next] |
| `AddPropsHeaderWithBack` | 4-column: [Back] [Title] [Prev] [Next] |
| `AddPropsEntryButton` | Label + action button |
| `AddPropsEntryNameValue` | Name + Value + action button |
| `AddPropsEntryTextInput` | Text input + action button |
| `AddPropsEntryLabel` | Label only (no button) |
| `AddPropsEntryType` | Full-width type label |
| `AddPropsEntryBlank` | Separator row |

### Gumps converted
PropsGump, GoGump, WhoGump, SkillsGump (frame+header), EditSkillGump, SetGump, SetObjectGump, SetPoint2DGump, SetPoint3DGump, SetTimeSpanGump (frame), SetListOptionGump (frame+header), CategorizedAddGump (frame+header)

## Test plan
- [x] Verify `[props` gump displays correctly with type + serial in header
- [x] Verify `[skills` gump displays correctly with type + serial in header
- [x] Verify `[go` navigation gump works (prev/next/back)
- [x] Verify property editing gumps (Set, SetObject, SetPoint2D, SetPoint3D, SetTimeSpan, SetListOption)
- [x] Verify `[categorizedadd` gump works
- [x] Verify `[who` gump works with pagination
2026-04-08 11:42:46 -06:00

131 lines
4 KiB
C#

using System.Reflection;
using Server.Commands;
using Server.Commands.Generic;
using Server.Network;
using static Server.Gumps.PropsConfig;
namespace Server.Gumps
{
public class SetListOptionGump : Gump
{
private const int EntryWidth = 212;
private const int EntryCount = 13;
private const int TotalWidth = OffsetSize + EntryWidth + OffsetSize + SetWidth + OffsetSize;
private readonly object[] m_Values;
protected Mobile m_Mobile;
protected object m_Object;
protected PropertyInfo m_Property;
protected PropertiesGump m_PropertiesGump;
public SetListOptionGump(
PropertyInfo prop, Mobile mobile, object o, PropertiesGump propertiesGump, string[] names, object[] values
) : base(GumpOffsetX, GumpOffsetY)
{
m_PropertiesGump = propertiesGump;
m_Property = prop;
m_Mobile = mobile;
m_Object = o;
m_Values = values;
var pages = (names.Length + EntryCount - 1) / EntryCount;
var index = 0;
for (var page = 1; page <= pages; ++page)
{
AddPage(page);
var start = (page - 1) * EntryCount;
var count = names.Length - start;
if (count > EntryCount)
{
count = EntryCount;
}
this.AddPropsFrame(TotalWidth, count + 2, out var x, out var y);
this.AddPropsHeader(
TotalWidth, ref x, ref y, null,
page > 1, 0, page < pages, 0,
prevType: GumpButtonType.Page, prevParam: page - 1,
nextType: GumpButtonType.Page, nextParam: page + 1
);
AddRect(0, prop.Name, 0);
for (var i = 0; i < count; ++i)
{
AddRect(i + 1, names[index], ++index);
}
}
}
private void AddRect(int index, string str, int button)
{
var x = BorderSize + OffsetSize;
var y = BorderSize + OffsetSize + (index + 1) * (EntryHeight + OffsetSize);
AddImageTiled(x, y, EntryWidth, EntryHeight, EntryGumpID);
AddLabelCropped(x + TextOffsetX, y, EntryWidth - TextOffsetX, EntryHeight, TextHue, str);
x += EntryWidth + OffsetSize;
if (SetGumpID != 0)
{
AddImageTiled(x, y, SetWidth, EntryHeight, SetGumpID);
}
if (button != 0)
{
AddButton(x + SetOffsetX, y + SetOffsetY, SetButtonID1, SetButtonID2, button);
}
}
public override void OnResponse(NetState sender, in RelayInfo info)
{
var from = sender.Mobile;
if (!BaseCommand.IsAccessible(from, m_Object))
{
from.SendMessage("You may no longer access their properties.");
return;
}
var index = info.ButtonID - 1;
if (index >= 0 && index < m_Values.Length)
{
try
{
var toSet = m_Values[index];
var result = Properties.SetDirect(
m_Mobile,
m_Object,
m_Object,
m_Property,
m_Property.Name,
toSet,
true
);
m_Mobile.SendMessage(result);
if (result == "Property has been set.")
{
m_PropertiesGump.OnValueChanged(m_Object, m_Property);
}
}
catch
{
m_Mobile.SendMessage("An exception was caught. The property may not have changed.");
}
}
m_PropertiesGump.SendPropertiesGump();
}
}
}