mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-20 12:19:32 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
102 lines
2.4 KiB
C#
102 lines
2.4 KiB
C#
|
|
namespace Editor.ShaderGraph;
|
|
|
|
public class Properties : Widget
|
|
{
|
|
private ScrollArea scroller;
|
|
private ControlSheet sheet;
|
|
private string filterText;
|
|
|
|
private object _target;
|
|
public object Target
|
|
{
|
|
get => _target;
|
|
set
|
|
{
|
|
if ( value == _target )
|
|
return;
|
|
|
|
_target = value;
|
|
|
|
Editor.Clear( true );
|
|
|
|
if ( value is null )
|
|
return;
|
|
|
|
var so = value.GetSerialized();
|
|
so.OnPropertyChanged += x =>
|
|
{
|
|
PropertyUpdated?.Invoke();
|
|
};
|
|
|
|
sheet = new ControlSheet();
|
|
sheet.AddObject( so, PropertyFilter );
|
|
|
|
scroller = new ScrollArea( this );
|
|
scroller.Canvas = new Widget();
|
|
scroller.Canvas.Layout = Layout.Column();
|
|
scroller.Canvas.VerticalSizeMode = SizeMode.CanGrow;
|
|
scroller.Canvas.HorizontalSizeMode = SizeMode.Flexible;
|
|
scroller.Canvas.Layout.Add( sheet );
|
|
scroller.Canvas.Layout.AddStretchCell();
|
|
|
|
Editor.Add( scroller );
|
|
}
|
|
}
|
|
|
|
private readonly Layout Editor;
|
|
|
|
public Action PropertyUpdated { get; set; }
|
|
|
|
public Properties( Widget parent ) : base( parent )
|
|
{
|
|
Name = "Properties";
|
|
WindowTitle = "Properties";
|
|
SetWindowIcon( "edit" );
|
|
|
|
Layout = Layout.Column();
|
|
|
|
var toolbar = new ToolBar( this );
|
|
var filter = new LineEdit( toolbar ) { PlaceholderText = "⌕ Filter Properties.." };
|
|
filter.TextEdited += OnFilterEdited;
|
|
toolbar.AddWidget( filter );
|
|
Layout.Add( toolbar );
|
|
Layout.AddSeparator();
|
|
|
|
Editor = Layout.AddRow( 1 );
|
|
Layout.AddStretchCell();
|
|
}
|
|
|
|
private void OnFilterEdited( string filter )
|
|
{
|
|
filterText = filter;
|
|
sheet.Clear( true );
|
|
sheet.AddObject( _target.GetSerialized(), PropertyFilter );
|
|
scroller.Update();
|
|
}
|
|
|
|
bool PropertyFilter( SerializedProperty property )
|
|
{
|
|
if ( property.HasAttribute<HideAttribute>() ) return false;
|
|
if ( string.IsNullOrEmpty( filterText ) ) return true;
|
|
if ( property.Name.ToLower().Contains( filterText.ToLower() ) ) return true;
|
|
if ( property.DisplayName.ToLower().Contains( filterText.ToLower() ) ) return true;
|
|
if ( property.TryGetAsObject( out var obj ) )
|
|
{
|
|
if ( property.TryGetAttribute<ConditionalVisibilityAttribute>( out var conditional ) )
|
|
{
|
|
if ( conditional.TestCondition( obj ) ) return false;
|
|
}
|
|
foreach ( var childProp in obj )
|
|
{
|
|
if ( childProp.HasAttribute<HideAttribute>() ) continue;
|
|
if ( childProp.Name.ToLower().Contains( filterText.ToLower() ) || childProp.DisplayName.ToLower().Contains( filterText.ToLower() ) )
|
|
{
|
|
sheet.AddRow( childProp );
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
}
|