using Sandbox.Internal; namespace Sandbox.UI; /// /// A controlsheet is a panel that you can populate with a SerializedObject's properties. /// public class ControlSheet : Panel, IControlSheet { /// /// The object we're trying to display properties for. /// [Parameter] public object Target { get; set; } /// /// body panel. Gets deleted and recreated on Rebuild() /// Panel _body; /// /// Filter any properties that are added to this /// [Parameter] public Func PropertyFilter { get; set; } /// /// Rebuild these controls. This will delete the current body panel and recreate it, then add all properties from the target object. /// public void Rebuild() { IControlSheet sheet = this; _body?.Delete(); _body = AddChild(); _body.AddClass( "body" ); if ( Target is null ) return; var so = Game.TypeLibrary.GetSerializedObject( Target ); IControlSheet.FilterSortAndAdd( sheet, so.ToList() ); } int _hash; public override void Tick() { base.Tick(); var hash = HashCode.Combine( Target ); if ( hash != _hash ) { _hash = hash; Rebuild(); } } /// /// Called by IControlSheet logic to add a feature /// void IControlSheet.AddFeature( IControlSheet.Feature feature ) { // Add feature tab Log.Warning( "TODO: TODO handle Feature Sheet" ); } /// /// Called by IControlSheet logic to add a group /// void IControlSheet.AddGroup( IControlSheet.Group group ) { var g = _body.AddChild(); var title = g.Header.AddChild