Files
sbox-public/game/addons/tools/Code/Widgets/ControlWidgets/ParticleGradientControlWidget.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

83 lines
1.9 KiB
C#

using Microsoft.VisualBasic;
using System;
using System.Collections.Generic;
namespace Editor;
[CustomEditor( typeof( ParticleGradient ) )]
public class ParticleGradientControlWidget : ControlWidget
{
Layout ControlArea;
SerializedObject Target;
public ParticleGradientControlWidget( SerializedProperty property ) : base( property )
{
SetSizeMode( SizeMode.Ignore, SizeMode.Default );
if ( !property.TryGetAsObject( out Target ) )
return;
Layout = Layout.Row();
Layout.Spacing = 3;
//Layout.Margin = new Sandbox.UI.Margin( 0, 0 );
ControlArea = Layout.AddRow( 1 );
ControlArea.Spacing = 2;
//ControlArea.Margin = new Sandbox.UI.Margin( 0, 0 );
Layout.AddStretchCell();
var type = Target.GetProperty( "Type" );
var dropDown = Create( type );
dropDown.FixedWidth = 100;
Layout.Add( dropDown );
var evaluate = Target.GetProperty( "Evaluation" );
var evalDropDown = Create( evaluate );
evalDropDown.FixedWidth = 100;
Layout.Add( evalDropDown );
Target.OnPropertyChanged += ( p ) =>
{
if ( p != type ) return;
RebuildForType( p.GetValue<ParticleGradient.ValueType>() );
};
RebuildForType( type.GetValue<ParticleGradient.ValueType>() );
}
void RebuildForType( ParticleGradient.ValueType type )
{
ControlArea.Clear( true );
if ( type == ParticleGradient.ValueType.Constant )
{
var control = Create( Target.GetProperty( "ConstantValue" ) );
ControlArea.Add( control );
}
if ( type == ParticleGradient.ValueType.Range )
{
var controlA = Create( Target.GetProperty( "ConstantA" ) );
ControlArea.Add( controlA );
var controlB = Create( Target.GetProperty( "ConstantB" ) );
ControlArea.Add( controlB );
}
if ( type == ParticleGradient.ValueType.Gradient )
{
var controlA = Create( Target.GetProperty( "GradientA" ) );
ControlArea.Add( controlA );
}
}
protected override void OnPaint()
{
}
}