ModernUO/Projects/UOContent/Engines/Spawners/SpawnPropsGump.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

140 lines
4.9 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2026 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GlobalPropsGump.cs *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System.Collections.Generic;
using Server.Commands.Generic;
using Server.Engines.Spawners;
using Server.Mobiles;
using Server.Network;
using Server.Text;
namespace Server.Gumps;
public class SpawnPropsGump : PropertiesGump
{
public static readonly HashSet<string> MobileAttributes = new()
{
nameof(Mobile.Hue),
nameof(Mobile.Str),
nameof(Mobile.Dex),
nameof(Mobile.Int),
nameof(BaseCreature.HitsMaxSeed),
nameof(BaseCreature.Hits),
nameof(BaseCreature.DamageMin),
nameof(BaseCreature.DamageMax),
nameof(BaseCreature.ActiveSpeed),
nameof(BaseCreature.PassiveSpeed),
nameof(BaseCreature.VirtualArmor)
};
private List<object> _spawners;
public SpawnPropsGump(Mobile mobile, object o, List<object> spawners) : base(mobile, o) => _spawners = spawners;
public SpawnPropsGump(Mobile mobile, object o, Stack<StackEntry> stack, StackEntry parent, List<object> spawners)
: base(mobile, o, stack, parent) => _spawners = spawners;
public SpawnPropsGump(
Mobile mobile, object o, Stack<StackEntry> stack, List<object> list, int page, List<object> spawners
) : base(mobile, o, stack, list, page) => _spawners = spawners;
protected override int TotalHeight => base.TotalHeight + PropsConfig.ApplySize;
protected override void Initialize(int page)
{
base.Initialize(page);
var totalHeight = TotalHeight - PropsConfig.ApplySize;
AddButton(BackWidth / 3, PropsConfig.BorderSize * 2 + totalHeight, 5204, 5205, 3);
}
public override void SendPropertiesGump() =>
m_Mobile.SendGump(new SpawnPropsGump(m_Mobile, m_Object, m_Stack, m_List, m_Page, _spawners));
public static object GetPropValue(object src, string propName) =>
src.GetType().GetProperty(propName)?.GetValue(src, null);
public override void OnResponse(NetState state, in RelayInfo info)
{
var from = state.Mobile;
if (!BaseCommand.IsAccessible(from, m_Object))
{
from.SendMessage("You may no longer access their properties.");
return;
}
switch (info.ButtonID)
{
default:
{
base.OnResponse(state, info);
break;
}
case 3: // Apply
{
using var propsBuilder = ValueStringBuilder.Create();
var first = true;
foreach (var attr in MobileAttributes)
{
var prop = GetPropValue(m_Object, attr);
if (prop != null)
{
if (first)
{
first = false;
}
else
{
propsBuilder.Append(' ');
}
propsBuilder.Append($"{attr} {prop}");
}
}
var name = m_Object.GetType().Name;
var props = propsBuilder.ToString();
m_Mobile.SendMessage("Updating spawners...");
foreach (var obj in _spawners)
{
if (obj is BaseSpawner spawner)
{
EditSpawnCommand.UpdateSpawner(spawner, name, null, props);
}
}
m_Mobile.SendMessage("Update completed.");
break;
}
}
}
protected override bool ShowAttribute(string name)
{
foreach (var item in MobileAttributes)
{
if (item.InsensitiveEquals(name))
{
return true;
}
}
return false;
}
}