ModernUO/Projects/UOContent/Gumps/Base/GridLayout/GridEntryExtensions.cs
Kamron Batman bc6735bd23
feat: Adds grid support for the DynamicGump system (#2306)
### Summary 

- Adds a new grid layout system for DynamicGump with zero heap allocations
 - Migrates SpawnerControllerGump from legacy GumpGrid to DynamicGump
 - Migrates CommandListGump from BaseGridGump to DynamicGump
 - Removes legacy GumpGrid (no longer needed)

 ### New Grid Layout Components

 | Component | Purpose |
 |-----------|---------|
 | `GridCell` | Value type for cell bounds (x, y, width, height) |
 | `GridSizeSpec` | Parses CSS-like sizing specs ("10*", "*", "100") |
 | `GridCalculator` | Computes track positions using stackalloc |
 | `ListViewLayout` | Pagination + column layout for list views |
 | `GridBuilderExtensions` | Extension methods accepting `GridCell` |
 | `GridEntryStyle` | Styling properties for BaseGridGump migration |
 | `GridEntryExtensions` | Entry methods matching BaseGridGump patterns |

 ### Memory Impact

 | Component | Legacy | New |
 |-----------|--------|-----|
 | Grid storage | ~200 bytes heap | 0 bytes (stackalloc) |
 | Column/Row lists | ~400 bytes heap | ~128 bytes stack |
 | ListView | ~300 bytes heap | ~64 bytes stack |
 | **Total per render** | **~900 bytes heap** | **0 bytes heap** |

 ### Test plan

 - [x] All 21 gump tests pass
 - [x] Build succeeds with no warnings
 - [ ] In-game verification of SpawnerControllerGump
 - [ ] In-game verification of CommandListGump (HelpInfo command)
2026-01-03 10:12:22 -08:00

222 lines
7.7 KiB
C#

/*************************************************************************
* ModernUO *
* Copyright 2019-2025 - ModernUO Development Team *
* Email: hi@modernuo.com *
* File: GridEntryExtensions.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;
using System.Runtime.CompilerServices;
using Server.Buffers;
namespace Server.Gumps;
/// <summary>
/// Extension methods for DynamicGumpBuilder that provide BaseGridGump-style entry methods.
/// These combine a tiled background with content, matching the AddEntry* pattern.
/// </summary>
public static class GridEntryExtensions
{
extension(ref DynamicGumpBuilder builder)
{
/// <summary>
/// Adds an entry with label (EntryGumpID background + cropped label).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryLabel(
in GridCell cell,
in GridEntryStyle style,
ReadOnlySpan<char> text
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddLabelCropped(cell, style.TextHue, text, style.TextOffsetX);
}
/// <summary>
/// Adds an entry with label using interpolated string.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryLabel(
in GridCell cell,
in GridEntryStyle style,
ref RawInterpolatedStringHandler handler
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddLabelCropped(cell, style.TextHue, ref handler, style.TextOffsetX);
}
/// <summary>
/// Adds an entry with HTML (EntryGumpID background + HTML text).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryHtml(
in GridCell cell,
in GridEntryStyle style,
ReadOnlySpan<char> text
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddHtml(cell, text, style.TextOffsetX, 0);
}
/// <summary>
/// Adds an entry with HTML using interpolated string.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryHtml(
in GridCell cell,
in GridEntryStyle style,
ref RawInterpolatedStringHandler handler
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddHtml(cell, ref handler, style.TextOffsetX, 0);
}
/// <summary>
/// Adds a header entry (HeaderGumpID background only).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryHeader(
in GridCell cell,
in GridEntryStyle style
)
{
builder.AddImageTiled(cell, style.HeaderGumpID);
}
/// <summary>
/// Adds an entry with a centered button (HeaderGumpID background + centered button).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryButton(
in GridCell cell,
in GridEntryStyle style,
int normalId,
int pressedId,
int buttonId,
int buttonWidth,
int buttonHeight
)
{
builder.AddImageTiled(cell, style.HeaderGumpID);
builder.AddButton(
cell, normalId, pressedId, buttonId,
offsetX: (cell.Width - buttonWidth) / 2,
offsetY: (cell.Height - buttonHeight) / 2
);
}
/// <summary>
/// Adds an entry with arrow left button.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryArrowLeft(
in GridCell cell,
in GridEntryStyle style,
int buttonId
)
{
builder.AddEntryButton(
cell, style,
GridEntryStyle.ArrowLeftID1,
GridEntryStyle.ArrowLeftID2,
buttonId,
GridEntryStyle.ArrowWidth,
GridEntryStyle.ArrowHeight
);
}
/// <summary>
/// Adds an entry with arrow right button.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryArrowRight(
in GridCell cell,
in GridEntryStyle style,
int buttonId
)
{
builder.AddEntryButton(
cell, style,
GridEntryStyle.ArrowRightID1,
GridEntryStyle.ArrowRightID2,
buttonId,
GridEntryStyle.ArrowWidth,
GridEntryStyle.ArrowHeight
);
}
/// <summary>
/// Adds an entry with text input (EntryGumpID background + text entry).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryText(
in GridCell cell,
in GridEntryStyle style,
int entryId,
ReadOnlySpan<char> initialText = default
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddTextEntry(cell, style.TextHue, entryId, style.TextOffsetX, 0, initialText);
}
/// <summary>
/// Adds an entry with text input using interpolated string.
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryText(
in GridCell cell,
in GridEntryStyle style,
int entryId,
ref RawInterpolatedStringHandler handler
)
{
builder.AddImageTiled(cell, style.EntryGumpID);
builder.AddTextEntry(cell, style.TextHue, entryId, style.TextOffsetX, 0, ref handler);
}
/// <summary>
/// Adds a blank line (BackGumpID + 4 background across full width).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddEntryBlank(
in GridCell cell,
in GridEntryStyle style
)
{
builder.AddImageTiled(cell, style.BackGumpID + 4);
}
/// <summary>
/// Adds the standard grid background (outer background + inner offset region).
/// </summary>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void AddGridBackground(
int width,
int height,
in GridEntryStyle style
)
{
builder.AddBackground(0, 0, width, height, style.BackGumpID);
builder.AddImageTiled(
style.BorderSize,
style.BorderSize,
width - style.BorderSize * 2,
height - style.BorderSize * 2,
style.OffsetGumpID
);
}
}
}