Editor/Tools/SlopeTool.cs
// Copyright (c) 2026 SubZero Studios LLC. All rights reserved.

using Sandbox;

namespace Editor.SubTerrain;

/// <summary>
/// Click the start of the ramp, then drag to the end.
/// </summary>
[Title( "Slope" )]
[Icon( "landscape" )]
[Alias( "subterrain_slope" )]
[Group( "1" )]
[Order( 5 )]
public class SubSlopeTool : SubTerrainBaseBrushTool
{
	Vector3 _startLocal;

	public SubSlopeTool( SubTerrainTool parent ) : base( parent )
	{
		Mode = SubTerrainSculptMode.Slope;
	}

	protected override void OnStrokeStart( Terrain terrain, Vector3 hitPosition )
	{
		_startLocal = hitPosition;
		SlopeStartUV = new Vector2( hitPosition.x, hitPosition.y ) / terrain.Storage.TerrainSize;
		SlopeStartHeight01 = hitPosition.z / terrain.Storage.TerrainHeight;
	}

	protected override void DrawToolOverlay( Terrain terrain, Vector3 worldCenter )
	{
		if ( !_dragging )
			return;

		var startWorld = terrain.WorldTransform.PointToWorld( _startLocal );
		Gizmo.Draw.Color = Color.FromBytes( 250, 220, 120 );
		Gizmo.Draw.Line( startWorld, worldCenter );
	}
}