mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
64 lines
1.4 KiB
C#
64 lines
1.4 KiB
C#
namespace Editor;
|
|
|
|
[CustomEditor( typeof( Gradient ) )]
|
|
public class GradientControlWidget : ControlWidget
|
|
{
|
|
public override bool SupportsMultiEdit => true;
|
|
|
|
public GradientControlWidget( SerializedProperty property ) : base( property )
|
|
{
|
|
SetSizeMode( SizeMode.Default, SizeMode.Default );
|
|
|
|
Layout = Layout.Column();
|
|
Layout.Spacing = 2;
|
|
Cursor = CursorShape.Finger;
|
|
}
|
|
|
|
protected override void PaintOver()
|
|
{
|
|
Gradient v = SerializedProperty.GetValue<Gradient>();
|
|
v.PaintBlock( LocalRect.Shrink( 2 ) );
|
|
}
|
|
|
|
protected override void OnMouseReleased( MouseEvent e )
|
|
{
|
|
base.OnMouseReleased( e );
|
|
|
|
if ( e.LeftMouseButton )
|
|
{
|
|
OpenPopup();
|
|
}
|
|
}
|
|
|
|
private void OpenPopup()
|
|
{
|
|
Gradient v = SerializedProperty.GetValue<Gradient>();
|
|
GradientEditorWidget.OpenPopup( this, v, x => { SerializedProperty.SetValue( x ); Update(); } );
|
|
}
|
|
|
|
protected override void OnContextMenu( ContextMenuEvent e )
|
|
{
|
|
var m = new ContextMenu();
|
|
|
|
m.AddOption( "Open in Editor", "edit", OpenPopup );
|
|
|
|
m.AddSeparator();
|
|
|
|
m.AddOption( "Copy", "content_copy", () =>
|
|
{
|
|
var json = JsonSerializer.Serialize( SerializedProperty.GetValue<Gradient>() );
|
|
EditorUtility.Clipboard.Copy( json );
|
|
} );
|
|
|
|
var clipboard = EditorUtility.Clipboard.Paste();
|
|
m.AddOption( "Paste", "content_paste", () =>
|
|
{
|
|
var value = JsonSerializer.Deserialize<Gradient>( clipboard );
|
|
SerializedProperty.SetValue( value );
|
|
} );
|
|
|
|
m.OpenAtCursor( false );
|
|
e.Accepted = true;
|
|
}
|
|
}
|