Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boost lane marker hovering #626

Closed
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions TLM/TLM/UI/SubTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,11 @@ private Texture2D BorderlessTexture {

private GUIStyle borderlessStyle_;

protected virtual ushort HoveredNodeId {
get => TrafficManagerTool.HoveredNodeId;
set => TrafficManagerTool.HoveredNodeId = value;
}
protected virtual ushort HoveredNodeId => TrafficManagerTool.HoveredNodeId;

protected virtual ushort HoveredSegmentId {
get => TrafficManagerTool.HoveredSegmentId;
set => TrafficManagerTool.HoveredSegmentId = value;
}
protected virtual ushort HoveredSegmentId => TrafficManagerTool.HoveredSegmentId;

protected virtual uint HoveredLaneId => TrafficManagerTool.HoveredLaneId;

protected ushort SelectedNodeId {
get => TrafficManagerTool.SelectedNodeId;
Expand Down
1 change: 0 additions & 1 deletion TLM/TLM/UI/SubTools/LaneArrowTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ protected override ushort HoveredNodeId {
}
return base.HoveredNodeId;
}
set => base.HoveredNodeId = value;
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions TLM/TLM/UI/SubTools/LaneConnectorTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace TrafficManager.UI.SubTools {
using TrafficManager.State;
using TrafficManager.Util.Caching;
using UnityEngine;
using Util.Caching;

public class LaneConnectorTool : SubTool {
private enum MarkerSelectionMode {
Expand Down Expand Up @@ -201,8 +202,7 @@ private void ShowOverlay(bool viewOnly, RenderManager.CameraInfo cameraInfo) {

// bounds.center = laneMarker.position;
// bounds.IntersectRay(mouseRay);
bool markerIsHovered = IsLaneMarkerHovered(laneMarker, ref mouseRay);

bool markerIsHovered = laneMarker.LaneId == HoveredLaneId;
// draw source marker in source selection mode,
// draw target marker (if segment turning angles are within bounds) and
// selected source marker in target selection mode
Expand Down
23 changes: 21 additions & 2 deletions TLM/TLM/UI/TrafficManagerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace TrafficManager.UI {
using TrafficManager.UI.SubTools;
using TrafficManager.Util;
using UnityEngine;
using static Util.Shortcuts;

[UsedImplicitly]
public class TrafficManagerTool
Expand All @@ -31,6 +32,7 @@ public class TrafficManagerTool

internal static ushort HoveredNodeId;
internal static ushort HoveredSegmentId;
internal static uint HoveredLaneId;

private static bool _mouseClickProcessed;

Expand Down Expand Up @@ -825,6 +827,7 @@ public bool DoRayCast(RaycastInput input, out RaycastOutput output) {
private bool DetermineHoveredElements() {
HoveredSegmentId = 0;
HoveredNodeId = 0;
HoveredLaneId = 0;

bool mouseRayValid = !UIView.IsInsideUI() && Cursor.visible &&
(_activeSubTool == null || !_activeSubTool.IsCursorInPanel());
Expand Down Expand Up @@ -943,8 +946,11 @@ private bool DetermineHoveredElements() {
if (HoveredNodeId != 0) {
HoveredSegmentId = GetHoveredSegmentFromNode();
}
}

if(HoveredSegmentId != 0) {
DetermineHoveredLane();
}
}
return HoveredNodeId != 0 || HoveredSegmentId != 0;
}

Expand Down Expand Up @@ -988,8 +994,21 @@ private static float GetAngle(Vector3 v1, Vector3 v2) {
return ret;
}


/// <summary>
private void DetermineHoveredLane() {
NetSegment segment = GetSeg(HoveredSegmentId);
segment.GetClosestLanePosition(
m_mousePosition,
LaneArrowManager.LANE_TYPES,
LaneArrowManager.VEHICLE_TYPES,
out Vector3 pos,
out uint laneID,
out int laneIndex,
out float laneOffset);
HoveredLaneId = laneID;
}

/// <summary>
/// Displays lane ids over lanes
/// </summary>
private void GuiDisplayLanes(ushort segmentId,
Expand Down