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]
82 lines
1.9 KiB
C#
82 lines
1.9 KiB
C#
namespace Editor.NodeEditor;
|
|
|
|
public class PlugIn : Plug
|
|
{
|
|
public override Vector2 ConnectionPosition => ToScene( new Vector2( handleSize * 0.5f, Size.y * 0.5f ) );
|
|
|
|
public Connection Connection { get; private set; }
|
|
|
|
public override bool IsConnected => Connection.IsValid();
|
|
|
|
public new IPlugIn Inner => (IPlugIn)base.Inner;
|
|
|
|
public PlugIn( NodeUI node, IPlug plug ) :
|
|
base( node, plug )
|
|
{
|
|
Cursor = CursorShape.Finger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Should only be called from <see cref="NodeEditor.Connection"/>.
|
|
/// </summary>
|
|
internal void SetConnectionInternal( Connection value )
|
|
{
|
|
Connection = value;
|
|
|
|
Node.MarkNodeChanged();
|
|
|
|
if ( Editor.IsValid() )
|
|
{
|
|
Editor.Enabled = !value.IsValid();
|
|
Editor.Update();
|
|
}
|
|
}
|
|
|
|
public override void Layout()
|
|
{
|
|
if ( !Editor.IsValid() )
|
|
return;
|
|
|
|
Editor.Position = new Vector2( 15, 0 );
|
|
Editor.Size = new Vector2( Size.x - 15, Size.y );
|
|
}
|
|
|
|
protected override void OnPaint()
|
|
{
|
|
var isTarget = DropTarget == this && Node.Graph.Preview is not null;
|
|
var highlight = Paint.HasMouseOver && !DropTarget.IsValid() || isTarget;
|
|
var unreachable = !highlight && !Node.Selected && !Inner.IsReachable;
|
|
|
|
var rect = new Rect();
|
|
rect.Size = Size;
|
|
|
|
var spacex = 4f;
|
|
var config = HandleConfig;
|
|
|
|
if ( isTarget )
|
|
{
|
|
config = Node.Graph.Preview.Output.HandleConfig;
|
|
}
|
|
else if ( Connection.IsValid() )
|
|
{
|
|
config = Connection.Output.HandleConfig;
|
|
}
|
|
|
|
var color = config.Color;
|
|
|
|
if ( !highlight )
|
|
{
|
|
color = color.Desaturate( 0.2f ).Darken( 0.3f );
|
|
}
|
|
|
|
if ( unreachable )
|
|
{
|
|
color = color.Desaturate( 0.5f ).Darken( 0.25f );
|
|
}
|
|
|
|
var handleRect = new Rect( 0, (Size.y - handleSize) * 0.5f, handleSize, handleSize ).Shrink( 2 );
|
|
DrawHandle( color, handleRect, config.Shape );
|
|
DrawLabel( new Rect( handleSize + spacex, 0, rect.Width - 4 - 10, rect.Size.y ), unreachable, TextFlag.LeftCenter );
|
|
}
|
|
}
|