UI/SpawnMenu/Mounts/MountContent.razor

A Razor UI panel showing mountable models in the Spawn Menu. It looks up a mount by Ident, lists models (optionally limited to a ResourceFolder), filters by a text query, and renders icons with titles.

File Access
@using Sandbox;
@using Sandbox.UI;
@using Sandbox.Mounting;
@namespace Sandbox
@inherits Panel

@if ( mount is null || !mount.IsMounted )
{
    <root>
        <SpawnMenuEmptyState Icon="error_outline" Title="#spawnmenu.mounts.error" Subtitle="#spawnmenu.empty.mount_unavailable" />
    </root>
    return;
}


<SpawnMenuContent>

    <Header>
        <SpawnMenuToolbar>
			<Body>
				<label>@Game.Language.GetPhrase( "ui.mounts.item_count", new() { { "mount", mount.Title }, { "count", GetData().Count() } } )</label>
			</Body>
			<Right>
				<SpawnMenuFilter Query:bind="@Filter"></SpawnMenuFilter>
			</Right>
		</SpawnMenuToolbar>
        <Label class="mount-title" Tokenize=@false Text=@( Folder?.Name ?? mount.Title ) />
    </Header>

    <Body>
		
        <VirtualGrid Items=@( GetData() ) ItemSize=@(new Vector2( 123, 123 ))>
            <Item Context="item">

                @if (item is ResourceLoader loader)
                {
                    var nameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(loader.Name);
                    <SpawnMenuIcon Ident=@($"mount:{loader.Path}") Title="@nameWithoutExt" />
                }

            </Item>
        </VirtualGrid>
    </Body>

</SpawnMenuContent>

@code
{
    public string Ident { get; set; }
    public string Filter { get; set; }

	/// <summary>
	/// Show the models in this folder and everything under it. Null shows the whole mount.
	/// </summary>
	public ResourceFolder Folder { get; set; }

    BaseGameMount mount;

	protected override int BuildHash() => HashCode.Combine(Ident, Folder, Filter);

    protected override void OnParametersSet()
    {
        mount = Sandbox.Mounting.Directory.Get( Ident );
    }

    IEnumerable<object> GetData()
    {
		var q = (Folder?.GetAllFilesRecursive().Where( x => x.Type == ResourceType.Model ) ?? mount.GetAll( ResourceType.Model ))
						.Where( x => !x.Flags.Contains( Sandbox.Mounting.ResourceFlags.DeveloperOnly ) ); // Hide dev-only junk models

		if ( !string.IsNullOrWhiteSpace( Filter ) )
		{
			q = q.Where( x => x.Path.Contains( Filter, StringComparison.OrdinalIgnoreCase ) );
		}

		return q;
    }

}