/* Debug */

        /*public List<Bezier2> debugDraw = new List<Bezier2>();
         * public List<Vector3> debugDrawPositions = new List<Vector3>();
         * bool yes = true; // :)*/

        public void BuildEllipse()
        {
            if (ellipse == null)
            {
                UIWindow2.instance.ThrowErrorMsg("Invalid radii!");
            }

            Ellipse toBeBuiltEllipse   = ellipse;
            Ellipse ellipseWithPadding = ellipse;

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            if (RoundAboutBuilder.UseOldSnappingAlgorithm.value)
            {
                ellipseWithPadding = new Ellipse(NetAccess.Node(centralNode).m_position, NetAccess.Node(axisNode).m_position - NetAccess.Node(centralNode).m_position, prevRadius1 + DISTANCE_PADDING, prevRadius2 + DISTANCE_PADDING);
            }

            UIWindow2.instance.LostFocus();
            UIWindow2.instance.GoBack();

            try
            {
                GraphTraveller2    traveller      = new GraphTraveller2(centralNode, ellipseWithPadding);
                EdgeIntersections2 intersections  = new EdgeIntersections2(traveller, centralNode, toBeBuiltEllipse);
                FinalConnector     finalConnector = new FinalConnector(NetAccess.Node(centralNode).Info, intersections, toBeBuiltEllipse, ControlVertices);

                // Easter egg
                RoundAboutBuilder.EasterEggToggle();
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow2.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
        //string m_radiusField.text = RADIUS_DEF.ToString();

        /* Main method , called when user cliks on a node to create a roundabout */
        public void CreateRoundabout(ushort nodeID)
        {
            //Debug.Log(string.Format("Clicked on node ID {0}!", nodeID));

            UIWindow.instance.LostFocus();

            try
            {
                if (m_roundabout != null && nodeID == m_nodeID)
                {
                    m_roundabout.Build();
                    m_hoverNode  = 0;
                    m_roundabout = null;
                    // Easter egg
                    RoundAboutBuilder.EasterEggToggle();
                }

                // Debug, don't forget to remove

                /*foreach(VectorNodeStruct intersection in intersections.Intersections)
                 * {
                 *  Debug.Log($"May have/Has restrictions: {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.MayHaveJunctionRestrictions(intersection.nodeId)}, {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.HasJunctionRestrictions(intersection.nodeId)}");
                 * }*/
            }
            catch (ActionException e)
            {
                UIWindow.instance.ThrowErrorMsg(e.Message);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
        //string m_radiusField.text = RADIUS_DEF.ToString();

        /* Main method , called when user cliks on a node to create a roundabout */
        public void CreateRoundabout(ushort nodeID)
        {
            //Debug.Log(string.Format("Clicked on node ID {0}!", nodeID));

            float?radiusQ = UIWindow2.instance.P_RoundAboutPanel.RadiusField.Value;

            if (radiusQ == null)
            {
                UIWindow2.instance.ThrowErrorMsg("Radius out of bounds!");
                return;
            }

            float radius = (float)radiusQ;

            if (!UIWindow2.instance.keepOpen)
            {
                UIWindow2.instance.LostFocus();
            }

            /* These lines of code do all the work. See documentation in respective classes. */

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            Ellipse ellipse            = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius, radius);
            Ellipse ellipseWithPadding = ellipse;

            if (RoundAboutBuilder.UseOldSnappingAlgorithm.value)
            {
                ellipseWithPadding = new Ellipse(NetAccess.Node(nodeID).m_position, new Vector3(0f, 0f, 0f), radius + DISTANCE_PADDING, radius + DISTANCE_PADDING);
            }


            try
            {
                GraphTraveller2    traveller;
                EdgeIntersections2 intersections = null;
                if (!RoundAboutBuilder.DoNotRemoveAnyRoads)
                {
                    traveller     = new GraphTraveller2(nodeID, ellipse);
                    intersections = new EdgeIntersections2(traveller, nodeID, ellipse);
                }
                FinalConnector finalConnector = new FinalConnector(NetAccess.Node(nodeID).Info, intersections, ellipse, true);

                // Easter egg
                RoundAboutBuilder.EasterEggToggle();

                // Debug, don't forget to remove

                /*foreach(VectorNodeStruct intersection in intersections.Intersections)
                 * {
                 *  Debug.Log($"May have/Has restrictions: {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.MayHaveJunctionRestrictions(intersection.nodeId)}, {TrafficManager.Manager.Impl.JunctionRestrictionsManager.Instance.HasJunctionRestrictions(intersection.nodeId)}");
                 * }*/
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow2.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
        /* Debug */

        /*public List<Bezier2> debugDraw = new List<Bezier2>();
         * public List<Vector3> debugDrawPositions = new List<Vector3>();
         * bool yes = true; // :)*/

        public void BuildEllipse()
        {
            if (ellipse == null)
            {
                UIWindow.instance.ThrowErrorMsg("Invalid radii!");
            }

            Ellipse toBeBuiltEllipse   = ellipse;
            Ellipse ellipseWithPadding = ellipse;

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            if (RoundAboutBuilder.UseOldSnappingAlgorithm.value)
            {
                ellipseWithPadding = new Ellipse(NetUtil.Node(centralNode).m_position, NetUtil.Node(axisNode).m_position - NetUtil.Node(centralNode).m_position, prevRadius1 + DISTANCE_PADDING, prevRadius2 + DISTANCE_PADDING);
            }

            UIWindow.instance.LostFocus();
            Instance.GoToFirstStage();

            try
            {
                bool               reverseDirection = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && RoundAboutBuilder.CtrlToReverseDirection.value;
                GraphTraveller2    traveller        = new GraphTraveller2(centralNode, ellipseWithPadding);
                EdgeIntersections2 intersections    = new EdgeIntersections2(traveller, centralNode, toBeBuiltEllipse, GetFollowTerrain());
                FinalConnector     finalConnector   = new FinalConnector(NetUtil.Node(centralNode).Info, intersections, toBeBuiltEllipse, ControlVertices, GetFollowTerrain(), reverseDirection);
                finalConnector.Build();

                // Easter egg
                RoundAboutBuilder.EasterEggToggle();
            }
            catch (ActionException e)
            {
                UIWindow.instance.ThrowErrorMsg(e.Message);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }
示例#5
0
        public void CreateRoundabout()
        {
            float?radiusQ = UIWindow.instance.P_FreeToolPanel.RadiusField.Value;

            if (radiusQ == null)
            {
                UIWindow.instance.ThrowErrorMsg("Radius out of bounds!");
                return;
            }
            float?elevationFieldQ = UIWindow.instance.P_FreeToolPanel.ElevationField.Value;

            if (elevationFieldQ == null)
            {
                UIWindow.instance.ThrowErrorMsg("Elevation out of bounds!");
                return;
            }

            float radius    = (float)radiusQ;
            float elevation = (float)elevationFieldQ;

            m_hoverNode = 0;
            UIWindow.instance.LostFocus();

            Vector3 vector = HoverPosition;

            if (AbsoluteElevation)
            {
                vector.y = elevation;
            }
            else
            {
                vector.y = vector.y + elevation;
            }

            if (vector.y < 0 || vector.y > 1000)
            {
                UIWindow.instance.ThrowErrorMsg("Elevation out of bounds!");
                return;
            }

            /* These lines of code do all the work. See documentation in respective classes. */

            /* When the old snapping algorithm is enabled, we create secondary (bigger) ellipse, so the newly connected roads obtained by the
             * graph traveller are not too short. They will be at least as long as the padding. */
            Ellipse ellipse          = new Ellipse(vector, new Vector3(0f, 0f, 0f), radius, radius);
            bool    reverseDirection = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && RoundAboutBuilder.CtrlToReverseDirection.value;

            try
            {
                FinalConnector finalConnector = new FinalConnector(UI.UIWindow.instance.dropDown.Value, null, ellipse, false, elevation == 0 ? GetFollowTerrain() : false, reverseDirection);
                finalConnector.Build();
                // Easter egg
                RoundAboutBuilder.EasterEggToggle();
            }
            catch (ActionException e)
            {
                UIWindow.instance.ThrowErrorMsg(e.Message);
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                UIWindow.instance.ThrowErrorMsg(e.ToString(), true);
            }
        }