Files
gm_construct_port/code/ui/left/SpawnList.cs
2021-08-05 17:54:51 +03:00

38 lines
952 B
C#

using Sandbox;
using Sandbox.UI;
using Sandbox.UI.Tests;
[Library]
public partial class SpawnList : Panel
{
VirtualScrollPanel Canvas;
public SpawnList()
{
AddClass( "spawnpage" );
AddChild( out Canvas, "canvas" );
Canvas.Layout.AutoColumns = true;
Canvas.Layout.ItemSize = new Vector2( 100, 100 );
Canvas.OnCreateCell = ( cell, data ) =>
{
var file = (string)data;
var panel = cell.Add.Panel( "icon" );
panel.AddEventListener( "onclick", () => ConsoleSystem.Run( "spawn", "models/" + file ) );
panel.Style.Background = new PanelBackground
{
Texture = Texture.Load( $"/models/{file}_c.png", false )
};
};
foreach ( var file in FileSystem.Mounted.FindFile( "models", "*.vmdl_c.png", true ) )
{
if ( string.IsNullOrWhiteSpace( file ) ) continue;
if ( file.Contains( "_lod0" ) ) continue;
if ( file.Contains( "clothes" ) ) continue;
Canvas.AddItem( file.Remove( file.Length - 6 ) );
}
}
}