public override void OnPrimaryClickOverlay() { if (ControlIsPressed || ShiftIsPressed) { if (HoveredSegmentId == 0) { return; } SelectedNodeId = 0; MainTool.RequestOnscreenDisplayUpdate(); } if (massEditMode == PrioritySignsMassEditMode.Undo) { record_?.Restore(); } else if (ControlIsPressed && ShiftIsPressed) { Log.Info("Before FixRoundabout/FixRoad."); // log time for benchmarking. bool isRoundabout = RoundaboutMassEdit.Instance.FixRoundabout( HoveredSegmentId, out record_); if (!isRoundabout) { record_ = PriorityRoad.FixRoad(HoveredSegmentId); } // TODO: benchmark why bulk setup takes a long time. Log.Info("After FixRoundabout/FixRoad. Before RefreshMassEditOverlay"); // log time for benchmarking. RefreshMassEditOverlay(); Log.Info("After RefreshMassEditOverlay."); // log time for benchmarking. } else if (ControlIsPressed) { record_ = new TrafficRulesRecord(); (record_ as TrafficRulesRecord).AddNodeAndSegmentEnds(HoveredNodeId); PriorityRoad.FixHighPriorityJunction(HoveredNodeId); } else if (ShiftIsPressed) { bool isRoundabout = RoundaboutMassEdit.Instance.TraverseLoop(HoveredSegmentId, out var segmentList); if (!isRoundabout) { var segments = SegmentTraverser.Traverse( HoveredSegmentId, TraverseDirection.AnyDirection, TraverseSide.Straight, SegmentStopCriterion.None, (_) => true); segmentList = new List <ushort>(segments); } PriorityRoad.FixPrioritySigns(massEditMode, segmentList); record_ = null; } else { if (TrafficPriorityManager.Instance.HasNodePrioritySign(HoveredNodeId)) { return; } if (!MayNodeHavePrioritySigns(HoveredNodeId)) { return; } SelectedNodeId = HoveredNodeId; MainTool.RequestOnscreenDisplayUpdate(); // Log._Debug($"PrioritySignsTool.OnPrimaryClickOverlay: SelectedNodeId={SelectedNodeId}"); } // cycle mass edit mode if (ControlIsPressed) { massEditMode = massEditMode != PrioritySignsMassEditMode.MainYield ? PrioritySignsMassEditMode.MainYield : PrioritySignsMassEditMode.Undo; } else if (ShiftIsPressed) { massEditMode++; if (massEditMode > PrioritySignsMassEditMode.Max) { massEditMode = PrioritySignsMassEditMode.Min; } } // refresh cache if (ControlIsPressed) { RefreshMassEditOverlay(); } else { RefreshCurrentPriorityNodeIds(); } }
public override void OnPrimaryClickOverlay() { bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); if (ctrlDown || shiftDown) { if (HoveredSegmentId == 0) { return; } SelectedNodeId = 0; } // TODO provide revert/clear mode issue #568 if (ctrlDown && shiftDown) { bool isRAbout = RoundaboutMassEdit.Instance.FixRabout(HoveredSegmentId); if (!isRAbout) { PriorityRoad.FixRoad(HoveredSegmentId); } RefreshMassEditOverlay(); return; } else if (ctrlDown) { PriorityRoad.FixJunction(HoveredNodeId); RefreshMassEditOverlay(); return; } if (shiftDown) { var primaryPrioType = PriorityType.None; var secondaryPrioType = PriorityType.None; switch (massEditMode) { case PrioritySignsMassEditMode.MainYield: { primaryPrioType = PriorityType.Main; secondaryPrioType = PriorityType.Yield; break; } case PrioritySignsMassEditMode.MainStop: { primaryPrioType = PriorityType.Main; secondaryPrioType = PriorityType.Stop; break; } case PrioritySignsMassEditMode.YieldMain: { primaryPrioType = PriorityType.Yield; secondaryPrioType = PriorityType.Main; break; } case PrioritySignsMassEditMode.StopMain: { primaryPrioType = PriorityType.Stop; secondaryPrioType = PriorityType.Main; break; } } IExtSegmentEndManager segEndMan = Constants.ManagerFactory.ExtSegmentEndManager; bool VisitorFun(SegmentVisitData data) { foreach (bool startNode in Constants.ALL_BOOL) { TrafficPriorityManager.Instance.SetPrioritySign( data.CurSeg.segmentId, startNode, primaryPrioType); ushort nodeId = Constants.ServiceFactory.NetService.GetSegmentNodeId( data.CurSeg.segmentId, startNode); ExtSegmentEnd curEnd = segEndMan.ExtSegmentEnds[ segEndMan.GetIndex(data.CurSeg.segmentId, startNode)]; for (int i = 0; i < 8; ++i) { ushort otherSegmentId = Singleton <NetManager> .instance.m_nodes .m_buffer[nodeId] .GetSegment(i); if (otherSegmentId == 0 || otherSegmentId == data.CurSeg.segmentId) { continue; } ArrowDirection dir = segEndMan.GetDirection( ref curEnd, otherSegmentId); if (dir != ArrowDirection.Forward) { TrafficPriorityManager.Instance.SetPrioritySign( otherSegmentId, (bool)Constants.ServiceFactory.NetService.IsStartNode( otherSegmentId, nodeId), secondaryPrioType); } } } return(true); } bool isRAbout = RoundaboutMassEdit.Instance.TraverseLoop(HoveredSegmentId, out var segmentList); if (isRAbout) { SegmentTraverser.Traverse(segmentList, VisitorFun); } else { SegmentTraverser.Traverse( HoveredSegmentId, TraverseDirection.AnyDirection, TraverseSide.Straight, SegmentStopCriterion.None, VisitorFun); } // cycle mass edit mode massEditMode = (PrioritySignsMassEditMode)(((int)massEditMode + 1) % Enum.GetValues(typeof(PrioritySignsMassEditMode)) .GetLength(0)); } else { if (TrafficPriorityManager.Instance.HasNodePrioritySign(HoveredNodeId)) { return; } if (!MayNodeHavePrioritySigns(HoveredNodeId)) { return; } SelectedNodeId = HoveredNodeId; Log._Debug($"PrioritySignsTool.OnPrimaryClickOverlay: SelectedNodeId={SelectedNodeId}"); } // update priority node cache RefreshCurrentPriorityNodeIds(); }
public override void OnPrimaryClickOverlay() { bool ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); bool shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); if (ctrlDown || shiftDown) { if (HoveredSegmentId == 0) { return; } SelectedNodeId = 0; } // TODO provide revert/clear mode issue #568 if (ctrlDown && shiftDown) { Log.Info("Before FixRoundabout/FixRoad."); // log time for benchmarking. bool isRoundabout = RoundaboutMassEdit.Instance.FixRoundabout(HoveredSegmentId); if (!isRoundabout) { PriorityRoad.FixRoad(HoveredSegmentId); } Log.Info("After FixRoundabout/FixRoad. Before RefreshMassEditOverlay"); // log time for benchmarking. RefreshMassEditOverlay(); Log.Info("After RefreshMassEditOverlay."); // log time for benchmarking. return; } else if (ctrlDown) { PriorityRoad.FixHighPriorityJunction(HoveredNodeId); RefreshMassEditOverlay(); return; } if (shiftDown) { bool isRoundabout = RoundaboutMassEdit.Instance.TraverseLoop(HoveredSegmentId, out var segmentList); if (!isRoundabout) { segmentList = SegmentTraverser.Traverse( HoveredSegmentId, TraverseDirection.AnyDirection, TraverseSide.Straight, SegmentStopCriterion.None, (_) => true); } PriorityRoad.FixPrioritySigns(massEditMode, segmentList); // cycle mass edit mode massEditMode = (PrioritySignsMassEditMode)(((int)massEditMode + 1) % Enum.GetValues(typeof(PrioritySignsMassEditMode)) .GetLength(0)); } else { if (TrafficPriorityManager.Instance.HasNodePrioritySign(HoveredNodeId)) { return; } if (!MayNodeHavePrioritySigns(HoveredNodeId)) { return; } SelectedNodeId = HoveredNodeId; Log._Debug($"PrioritySignsTool.OnPrimaryClickOverlay: SelectedNodeId={SelectedNodeId}"); } // update priority node cache RefreshCurrentPriorityNodeIds(); }