Editor UI helper for arch openings. Provides a shared furniture selection UI for two editor sidebars, populating an ArchIconGrid with options based on an OpeningKind and invoking a callback when a choice is made.
using System;
using System.Linq;
using Editor;
namespace Sunless.Architecture;
// The drag options both opening tools share, laid out once so the two sidebars cannot drift apart.
public static class ArchOpeningUi
{
// The whole furniture control: one exclusive pick in the grid the kind's other options already stand in.
// What a kind may carry comes from ArchOpeningKinds and the pitch, proud and frame are kit stock, so there
// is nothing else here to offer.
public static void Furniture( ArchIconGrid grid, OpeningKind kind, OpeningFurniture fitted, Action<OpeningFurniture> chosen )
{
var offered = kind.Furnishings().ToList();
if ( offered.Count == 0 )
{
return;
}
grid.Pick( Advice( OpeningFurniture.None ), Slug( OpeningFurniture.None ), Glyph( OpeningFurniture.None ),
fitted == OpeningFurniture.None, () => chosen( OpeningFurniture.None ) );
foreach ( var furniture in offered )
{
var picked = furniture;
grid.Pick( Advice( picked ), Slug( picked ), Glyph( picked ), fitted == picked, () => chosen( picked ) );
}
}
static string Slug( OpeningFurniture furniture ) => $"opt_furniture_{furniture}".ToLowerInvariant();
static string Advice( OpeningFurniture furniture ) => furniture switch
{
OpeningFurniture.Bars => "Burglar bars across it",
OpeningFurniture.Boarded => "Boarded over with planks",
OpeningFurniture.Shutter => "Roller shutter down over it",
OpeningFurniture.Gate => "Security gate across it",
_ => "Nothing over it"
};
// Classic Material Icons only - a glyph the editor's older set does not know draws an empty box.
static string Glyph( OpeningFurniture furniture ) => furniture switch
{
OpeningFurniture.Bars => "fence",
OpeningFurniture.Boarded => "table_rows",
OpeningFurniture.Shutter => "density_small",
OpeningFurniture.Gate => "grid_on",
_ => "block"
};
}