Skip to content

Commit

Permalink
Fix #40: Bad hover detection of nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Craxy committed Jul 23, 2017
1 parent 4448961 commit 90abe6f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/ToggleTrafficLights/ToggleTrafficLights.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<RootNamespace>Craxy.CitiesSkylines.ToggleTrafficLights</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<Version>0.10.2</Version>
<Version>0.10.3</Version>
<AssemblyVersion>$(Version)</AssemblyVersion>
<FileVersion>$(Version)</FileVersion>
<Product>Toggle Traffic Lights</Product>
Expand Down
40 changes: 30 additions & 10 deletions src/ToggleTrafficLights/Tools/JunctionTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@ protected override void OnToolGUI(Event e)
HandleElevation(e);
}

private Ray _mouseRay;
private float _mouseRayLength;
private Vector3 _rayRight;
private bool _mouseRayValid;
protected override void OnToolLateUpdate()
{
base.OnToolLateUpdate();

this._mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition);
this._mouseRayLength = Camera.main.farClipPlane;
this._rayRight = Camera.main.transform.TransformDirection(Vector3.right);
this._mouseRayValid = !m_toolController.IsInsideUI && Cursor.visible;
}

public override void SimulationStep()
{
base.SimulationStep();
Expand Down Expand Up @@ -82,18 +96,22 @@ private void DetectHoveredElements()
_hoveredNodeId = 0;
if (!m_toolController.IsInsideUI && Cursor.visible)
{
var input = new RaycastInput(Camera.main.ScreenPointToRay(Input.mousePosition), Camera.main.farClipPlane)
var netService = new RaycastService
{
m_service = ItemClass.Service.None,
m_subService = ItemClass.SubService.None,
m_itemLayers = ItemClass.Layer.Default | ItemClass.Layer.MetroTunnels,
};
var input = new RaycastInput(_mouseRay, _mouseRayLength)
{
m_rayRight = Camera.main.transform.TransformDirection(Vector3.right),
m_rayRight = _rayRight,
m_netService = netService,
m_buildingService = netService,
m_propService = netService,
m_treeService = netService,
m_districtNameOnly = true,
m_ignoreTerrain = true,
m_ignoreNodeFlags = NetNode.Flags.None,
m_ignoreSegmentFlags =
NetSegment.Flags.Untouchable, //provides a MUCH better node recognition -- far mor generous
m_netService =
{
m_itemLayers = ItemClass.Layer.Default | ItemClass.Layer.MetroTunnels,
m_service = ItemClass.Service.Road
},
m_ignoreNodeFlags = IsUndergroundVisible() ? NetNode.Flags.None : (NetNode.Flags.None | NetNode.Flags.Underground),
};

if (RayCast(input, out var output))
Expand Down Expand Up @@ -436,6 +454,8 @@ public enum Elevation
Underground = 2,
}

public bool IsUndergroundVisible() => CurrentElevation != Elevation.Overground;

#endregion Elevation

#region Events
Expand Down

0 comments on commit 90abe6f

Please sign in to comment.