mirror of
https://github.com/celisej567/gm_construct_port.git
synced 2026-09-06 20:13:16 +03:00
39 lines
926 B
C#
39 lines
926 B
C#
using Sandbox;
|
|
using Sandbox.UI;
|
|
using Sandbox.UI.Construct;
|
|
using Sandbox.UI.Tests;
|
|
using System.Linq;
|
|
|
|
[Library]
|
|
public partial class EntityList : Panel
|
|
{
|
|
VirtualScrollPanel Canvas;
|
|
|
|
public EntityList()
|
|
{
|
|
AddClass( "spawnpage" );
|
|
AddChild( out Canvas, "canvas" );
|
|
|
|
Canvas.Layout.AutoColumns = true;
|
|
Canvas.Layout.ItemSize = new Vector2( 100, 100 );
|
|
Canvas.OnCreateCell = ( cell, data ) =>
|
|
{
|
|
var entry = (LibraryAttribute)data;
|
|
var btn = cell.Add.Button( entry.Title );
|
|
btn.AddClass( "icon" );
|
|
btn.AddEventListener( "onclick", () => ConsoleSystem.Run( "spawn_entity", entry.Name ) );
|
|
btn.Style.Background = new PanelBackground
|
|
{
|
|
Texture = Texture.Load( $"/entity/{entry.Name}.png", false )
|
|
};
|
|
};
|
|
|
|
var ents = Library.GetAllAttributes<Entity>().Where( x => x.Spawnable ).OrderBy( x => x.Title ).ToArray();
|
|
|
|
foreach ( var entry in ents )
|
|
{
|
|
Canvas.AddItem( entry );
|
|
}
|
|
}
|
|
}
|