Skip to content

Commit

Permalink
Merge pull request #607 from krzychu124/index-out-of-bounds-lane-arro…
Browse files Browse the repository at this point in the history
…ws-tool

Add additional check if hovered node and segments are connected,
  • Loading branch information
krzychu124 authored Jan 10, 2020
2 parents e2f06b9 + 8a1b644 commit 24df4a9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
5 changes: 5 additions & 0 deletions TLM/TLM/UI/SubTools/LaneArrowTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ private bool HasSegmentEndLaneArrows(ushort segmentId, ushort nodeId) {
}
#endif
ExtSegmentEndManager segEndMan = ExtSegmentEndManager.Instance;
int segmentEndId = segEndMan.GetIndex(segmentId, nodeId);
if (segmentEndId <0) {
Log._Debug($"Node {nodeId} is not connected to segment {segmentId}");
return false;
}
ExtSegmentEnd segEnd = segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, nodeId)];
NetNode[] nodesBuffer = Singleton<NetManager>.instance.m_nodes.m_buffer;
bool bJunction = (nodesBuffer[nodeId].m_flags & NetNode.Flags.Junction) != 0;
Expand Down
32 changes: 17 additions & 15 deletions TLM/TLM/UI/TrafficManagerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class TrafficManagerTool
IObserver<GlobalConfig>
{
private ToolMode toolMode_;
private NetTool _netTool;

internal static ushort HoveredNodeId;
internal static ushort HoveredSegmentId;
Expand Down Expand Up @@ -129,6 +130,17 @@ internal static float GetHandleAlpha(bool hovered) {
return TransparencyToAlpha(transparency);
}

internal NetTool NetTool {
get {
if (_netTool == null) {
Log._Debug("NetTool field value is null. Searching for instance...");
_netTool = ToolsModifierControl.toolController.Tools.OfType<NetTool>().FirstOrDefault();
}

return _netTool;
}
}

private static float TransparencyToAlpha(byte transparency) {
return Mathf.Clamp(100 - transparency, 0f, 100f) / 100f;
}
Expand Down Expand Up @@ -322,6 +334,11 @@ protected override void OnToolUpdate() {
InfoManager.InfoMode.None,
InfoManager.SubInfoMode.Default);
}
ToolCursor = null;
bool elementsHovered = DetermineHoveredElements();
if (_activeSubTool != null && NetTool != null && elementsHovered) {
ToolCursor = NetTool.m_upgradeCursor;
}

bool primaryMouseClicked = Input.GetMouseButtonDown(0);
bool secondaryMouseClicked = Input.GetMouseButtonDown(1);
Expand Down Expand Up @@ -357,7 +374,6 @@ protected override void OnToolUpdate() {
// }

if (_activeSubTool != null) {
DetermineHoveredElements();

if (primaryMouseClicked) {
_activeSubTool.OnPrimaryClickOverlay();
Expand Down Expand Up @@ -799,20 +815,6 @@ public override void SimulationStep() {
// tooltipWorldPos = null;
// }
// }

if (GetToolMode() == ToolMode.None) {
ToolCursor = null;
} else {
bool elementsHovered = DetermineHoveredElements();

NetTool netTool = ToolsModifierControl
.toolController.Tools.OfType<NetTool>()
.FirstOrDefault(nt => nt.m_prefab != null);

if (netTool != null && elementsHovered) {
ToolCursor = netTool.m_upgradeCursor;
}
}
}

public bool DoRayCast(RaycastInput input, out RaycastOutput output) {
Expand Down

0 comments on commit 24df4a9

Please sign in to comment.