71 lines
1.5 KiB
C#
71 lines
1.5 KiB
C#
using Editor;
|
|
using Editor.Assets;
|
|
using Editor.Inspectors;
|
|
using Sandbox;
|
|
using static Editor.Inspectors.AssetInspector;
|
|
|
|
namespace VeloX;
|
|
|
|
[CanEdit( "asset:tire" )]
|
|
public class TirePresetEditor : Widget, IAssetInspector
|
|
{
|
|
TirePreset Tire;
|
|
ControlSheet MainSheet;
|
|
TirePresetPreview TirePreview;
|
|
public TirePresetEditor( Widget parent ) : base( parent )
|
|
{
|
|
Layout = Layout.Column();
|
|
Layout.Margin = 4;
|
|
Layout.Spacing = 4;
|
|
|
|
// Create a ontrolSheet that will display all our Properties
|
|
MainSheet = new ControlSheet();
|
|
Layout.Add( MainSheet );
|
|
|
|
//// Add a randomize button below the ControlSheet
|
|
//var button = Layout.Add( new Button( "Randomize", "casino", this ) );
|
|
//button.Clicked += () =>
|
|
//{
|
|
// foreach ( var prop in Test.GetSerialized() )
|
|
// {
|
|
// // Randomize all the float values from 0-100
|
|
// if ( prop.PropertyType != typeof( float ) ) continue;
|
|
// prop.SetValue( Random.Shared.Float( 0, 100 ) );
|
|
// }
|
|
//};
|
|
|
|
Layout.AddStretchCell();
|
|
|
|
RebuildSheet();
|
|
Focus();
|
|
|
|
}
|
|
|
|
[EditorEvent.Hotload]
|
|
void RebuildSheet()
|
|
{
|
|
if ( Tire is null ) return;
|
|
if ( MainSheet is null ) return;
|
|
MainSheet.Clear( true );
|
|
|
|
var so = Tire.GetSerialized();
|
|
so.OnPropertyChanged += x =>
|
|
{
|
|
Tire.StateHasChanged();
|
|
TirePreview.Widget.UpdatePixmap();
|
|
};
|
|
MainSheet.AddObject( so );
|
|
}
|
|
|
|
void IAssetInspector.SetAssetPreview( AssetPreview preview )
|
|
{
|
|
TirePreview = preview as TirePresetPreview;
|
|
}
|
|
|
|
public void SetAsset( Asset asset )
|
|
{
|
|
Tire = asset.LoadResource<TirePreset>();
|
|
RebuildSheet();
|
|
}
|
|
}
|