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

Add additional check if hovered node and segments are connected, #607

Merged
merged 2 commits into from
Jan 10, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
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 {
krzychu124 marked this conversation as resolved.
Show resolved Hide resolved
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