Example #1
0
        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();
            }
        }
Example #2
0
        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();
        }