mirror of
https://github.com/Facepunch/sbox-public.git
synced 2025-12-28 17:08:18 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
60 lines
1.3 KiB
C#
60 lines
1.3 KiB
C#
namespace Editor;
|
|
|
|
[CustomEditor( typeof( Vector2 ) )]
|
|
[CustomEditor( typeof( Vector3 ) )]
|
|
[CustomEditor( typeof( Vector4 ) )]
|
|
public class VectorControlWidget : ControlWidget
|
|
{
|
|
SerializedObject obj;
|
|
|
|
SerializedProperty Property;
|
|
|
|
FloatControlWidget FirstControl;
|
|
|
|
public override bool SupportsMultiEdit => true;
|
|
|
|
public VectorControlWidget( SerializedProperty property ) : base( property )
|
|
{
|
|
Property = property;
|
|
property.TryGetAsObject( out obj );
|
|
|
|
if ( obj is null )
|
|
{
|
|
Log.Warning( $"Error when trying to get {property} as object" );
|
|
return;
|
|
}
|
|
|
|
Layout = Layout.Row();
|
|
Layout.Spacing = 2;
|
|
|
|
FirstControl = TryAddField( "x", Theme.Red, "X" );
|
|
TryAddField( "y", Theme.Green, "Y" );
|
|
TryAddField( "z", Theme.Blue, "Z" );
|
|
TryAddField( "w", Theme.Yellow, "W" );
|
|
}
|
|
|
|
private FloatControlWidget TryAddField( string propertyName, Color color, string text )
|
|
{
|
|
var prop = obj.GetProperty( propertyName );
|
|
if ( prop is null ) return null;
|
|
|
|
var control = Layout.Add( new FloatControlWidget( prop ) { HighlightColor = color, Label = text } );
|
|
|
|
control.MinimumWidth = Theme.RowHeight;
|
|
control.HorizontalSizeMode = SizeMode.CanGrow | SizeMode.Expand;
|
|
control.MakeRanged( Property );
|
|
|
|
return control;
|
|
}
|
|
|
|
public override void StartEditing()
|
|
{
|
|
FirstControl?.StartEditing();
|
|
}
|
|
|
|
protected override void OnPaint()
|
|
{
|
|
// nothing
|
|
}
|
|
}
|