Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
1.1.0
Browse files Browse the repository at this point in the history
- Add dragging of line control points in fixed preview mode.
  • Loading branch information
algernon-A committed Dec 11, 2023
1 parent 5db1edd commit c7241be
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 17 deletions.
2 changes: 1 addition & 1 deletion BepInEx/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace LineTool
/// <summary>
/// BepInEx plugin to substitute for IMod support.
/// </summary>
[BepInPlugin(GUID, "Line Tool Lite", "1.0.10")]
[BepInPlugin(GUID, "Line Tool Lite", "1.1.0")]
[HarmonyPatch]
public class Plugin : BaseUnityPlugin
{
Expand Down
2 changes: 1 addition & 1 deletion BepInEx/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Line_Tool_Lite",
"version_number": "1.0.10",
"version_number": "1.1.0",
"website_url": "https://github.com/algernon-A/LineToolLite",
"description": "Place objects in lines, curves, or circles. A variety of options and controls are availalbe to specify and fine-tune results.",
"dependencies": [
Expand Down
3 changes: 3 additions & 0 deletions Changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
1.1.0
- Add dragging of line control points in fixed preview mode.

1.0.10
- Add fixed-length even spacing mode (will evenly space out objects along the full length of the line with spacing as close as possible to the specified distance).

Expand Down
3 changes: 3 additions & 0 deletions Code/LineModes/Circle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public override void CalculatePoints(float3 currentPos, SpacingMode spacingMode,
// Add point to list.
pointList.Add(new PointData { Position = thisPoint, Rotation = quaternion.Euler(0f, math.radians(rotation) - i, 0f), });
}

// Record end position for overlays.
m_endPos = currentPos;
}

/// <summary>
Expand Down
68 changes: 65 additions & 3 deletions Code/LineModes/LineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,19 @@ namespace LineTool
using Unity.Mathematics;
using UnityEngine;
using static Game.Rendering.GuideLinesSystem;
using static LineToolSystem;

/// <summary>
/// Line placement mode.
/// </summary>
[System.Diagnostics.CodeAnalysis.SuppressMessage("StyleCop.CSharp.MaintainabilityRules", "SA1401:Fields should be private", Justification = "Protected fields")]
public abstract class LineBase
{
/// <summary>
/// Selection radius of points.
/// </summary>
protected const float PointRadius = 8f;

/// <summary>
/// Indicates whether a valid starting position has been recorded.
/// </summary>
Expand All @@ -28,6 +34,11 @@ public abstract class LineBase
/// </summary>
protected float3 m_startPos;

/// <summary>
/// Records the current selection end position.
/// </summary>
protected float3 m_endPos;

/// <summary>
/// Initializes a new instance of the <see cref="LineBase"/> class.
/// </summary>
Expand Down Expand Up @@ -167,23 +178,38 @@ public virtual void CalculatePoints(float3 currentPos, SpacingMode spacingMode,
// Add point to list.
pointList.Add(new PointData { Position = thisPoint, Rotation = qRotation, });
}

// Record end position for overlays.
m_endPos = currentPos;
}

/// <summary>
/// Draws any applicable overlay.
/// </summary>
/// <param name="currentPos">Current cursor world position.</param>
/// <param name="overlayBuffer">Overlay buffer.</param>
/// <param name="tooltips">Tooltip list.</param>
public virtual void DrawOverlay(float3 currentPos, OverlayRenderSystem.Buffer overlayBuffer, NativeList<TooltipInfo> tooltips)
public virtual void DrawOverlay(OverlayRenderSystem.Buffer overlayBuffer, NativeList<TooltipInfo> tooltips)
{
// Don't draw overlay if we don't have a valid start.
if (m_validStart)
{
DrawDashedLine(m_startPos, currentPos, new Line3.Segment(m_startPos, currentPos), overlayBuffer, tooltips);
DrawDashedLine(m_startPos, m_endPos, new Line3.Segment(m_startPos, m_endPos), overlayBuffer, tooltips);
}
}

/// <summary>
/// Draws point overlays.
/// </summary>
/// <param name="overlayBuffer">Overlay buffer.</param>
public virtual void DrawPointOverlays(OverlayRenderSystem.Buffer overlayBuffer)
{
Color softCyan = Color.cyan;
softCyan.a *= 0.1f;

overlayBuffer.DrawCircle(Color.cyan, softCyan, 0.3f, 0, new float2(0f, 1f), m_startPos, PointRadius * 2f);
overlayBuffer.DrawCircle(Color.cyan, softCyan, 0.3f, 0, new float2(0f, 1f), m_endPos, PointRadius * 2f);
}

/// <summary>
/// Clears the current selection.
/// </summary>
Expand All @@ -192,6 +218,42 @@ public virtual void Reset()
m_validStart = false;
}

/// <summary>
/// Checks to see if a click should initiate point dragging.
/// </summary>
/// <param name="position">Click position in world space.</param>
/// <returns>Drag mode.</returns>
internal virtual DragMode CheckDragHit(float3 position)
{
if (math.distancesq(position, m_startPos) < (PointRadius * PointRadius))
{
// Start point.
return DragMode.StartPos;
}
else if (math.distancesq(position, m_endPos) < (PointRadius * PointRadius))
{
// End point.
return DragMode.EndPos;
}

// No hit.
return DragMode.None;
}

/// <summary>
/// Handles dragging action.
/// </summary>
/// <param name="dragMode">Dragging mode.</param>
/// <param name="position">New position.</param>
internal virtual void HandleDrag(DragMode dragMode, float3 position)
{
// Drag start point.
if (dragMode == DragMode.StartPos)
{
m_startPos = position;
}
}

/// <summary>
/// Draws a dashed line overlay between the two given points.
/// </summary>
Expand Down
71 changes: 65 additions & 6 deletions Code/LineModes/SimpleCurve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace LineTool
using Unity.Mathematics;
using UnityEngine;
using static Game.Rendering.GuideLinesSystem;
using static LineToolSystem;

/// <summary>
/// Simple curve placement mode.
Expand Down Expand Up @@ -105,7 +106,8 @@ public override void CalculatePoints(float3 currentPos, SpacingMode spacingMode,
if (!_validElbow)
{
// Constrain as required.
base.CalculatePoints(ConstrainPos(currentPos), spacingMode, spacing, randomSpacing, randomOffset, rotation, zBounds, pointList, ref heightData);
m_endPos = ConstrainPos(currentPos);
base.CalculatePoints(m_endPos, spacingMode, spacing, randomSpacing, randomOffset, rotation, zBounds, pointList, ref heightData);
return;
}

Expand Down Expand Up @@ -176,15 +178,17 @@ public override void CalculatePoints(float3 currentPos, SpacingMode spacingMode,
// Add point to list.
pointList.Add(new PointData { Position = thisPoint, Rotation = qRotation, });
}

// Record end position for overlays.
m_endPos = currentPos;
}

/// <summary>
/// Draws any applicable overlay.
/// </summary>
/// <param name="currentPos">Current cursor world position.</param>
/// <param name="overlayBuffer">Overlay buffer.</param>
/// <param name="tooltips">Tooltip list.</param>
public override void DrawOverlay(float3 currentPos, OverlayRenderSystem.Buffer overlayBuffer, NativeList<TooltipInfo> tooltips)
public override void DrawOverlay(OverlayRenderSystem.Buffer overlayBuffer, NativeList<TooltipInfo> tooltips)
{
if (m_validStart)
{
Expand All @@ -193,23 +197,40 @@ public override void DrawOverlay(float3 currentPos, OverlayRenderSystem.Buffer o
{
// Calculate lines.
Line3.Segment line1 = new (m_startPos, _elbowPoint);
Line3.Segment line2 = new (_elbowPoint, currentPos);
Line3.Segment line2 = new (_elbowPoint, m_endPos);

// Draw lines.
DrawDashedLine(m_startPos, _elbowPoint, line1, overlayBuffer, tooltips);
DrawDashedLine(_elbowPoint, currentPos, line2, overlayBuffer, tooltips);
DrawDashedLine(_elbowPoint, m_endPos, line2, overlayBuffer, tooltips);

// Draw angle.
DrawAngleIndicator(line1, line2, 8f, 8f, overlayBuffer, tooltips);
}
else
{
// Initial position only; just draw a straight line (constrained if required).
base.DrawOverlay(ConstrainPos(currentPos), overlayBuffer, tooltips);
base.DrawOverlay(overlayBuffer, tooltips);
}
}
}

/// <summary>
/// Draws point overlays.
/// </summary>
/// <param name="overlayBuffer">Overlay buffer.</param>
public override void DrawPointOverlays(OverlayRenderSystem.Buffer overlayBuffer)
{
base.DrawPointOverlays(overlayBuffer);

// Draw elbow point.
if (_validElbow)
{
Color softCyan = Color.cyan;
softCyan.a *= 0.1f;
overlayBuffer.DrawCircle(Color.cyan, softCyan, 0.3f, 0, new float2(0f, 1f), _elbowPoint, PointRadius * 2f);
}
}

/// <summary>
/// Clears the current selection.
/// </summary>
Expand All @@ -228,6 +249,44 @@ public override void Reset()
}
}

/// <summary>
/// Checks to see if a click should initiate point dragging.
/// </summary>
/// <param name="position">Click position in world space.</param>
/// <returns>Drag mode.</returns>
internal override DragMode CheckDragHit(float3 position)
{
// Start and end points.
DragMode mode = base.CheckDragHit(position);

// If no hit from base (start and end points), check for elbow point hit.
if (mode == DragMode.None && _validElbow && math.distancesq(position, _elbowPoint) < (PointRadius * PointRadius))
{
return DragMode.ElbowPos;
}

return mode;
}

/// <summary>
/// Handles dragging action.
/// </summary>
/// <param name="dragMode">Dragging mode.</param>
/// <param name="position">New position.</param>
internal override void HandleDrag(DragMode dragMode, float3 position)
{
if (dragMode == DragMode.ElbowPos)
{
// Update elbow point.
_elbowPoint = position;
}
else
{
// Other points.
base.HandleDrag(dragMode, position);
}
}

/// <summary>
/// Applies any active constraints the given current cursor world position.
/// </summary>
Expand Down
Loading

0 comments on commit c7241be

Please sign in to comment.