private void PreviewRoundabout(float radius) { /* 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. */ bool reverseDirection = (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl)) && RoundAboutBuilder.CtrlToReverseDirection.value; if (m_radius == radius && m_hoverNode == m_nodeID && m_roundabout != null && m_roundabout.m_reverseDirection == reverseDirection) { return; } try { m_radius = radius; m_nodeID = m_hoverNode; Ellipse ellipse = new Ellipse(NetUtil.Node(m_nodeID).m_position, new Vector3(0f, 0f, 0f), radius, radius); Ellipse ellipseWithPadding = ellipse; if (RoundAboutBuilder.UseOldSnappingAlgorithm.value) { ellipseWithPadding = new Ellipse(NetUtil.Node(m_nodeID).m_position, new Vector3(0f, 0f, 0f), radius + DISTANCE_PADDING, radius + DISTANCE_PADDING); } GraphTraveller2 traveller; EdgeIntersections2 intersections = null; if (!RoundAboutBuilder.DoNotRemoveAnyRoads) { traveller = new GraphTraveller2(m_nodeID, ellipse); intersections = new EdgeIntersections2(traveller, m_nodeID, ellipse, GetFollowTerrain()); } m_roundabout = new FinalConnector(NetUtil.Node(m_nodeID).Info, intersections, ellipse, true, GetFollowTerrain(), reverseDirection); } catch (Exception e) { Debug.LogError(e); } }
//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); } }
/* 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)); 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); } }
/* This draws the UI circles on the map */ protected override void RenderOverlayExtended(RenderManager.CameraInfo cameraInfo) { try { if (insideUI) { return; } if (m_hoverNode != 0) { NetNode hoveredNode = NetUtil.Node(m_hoverNode); // kinda stole this color from Move It! // thanks to SamsamTS because they're a UI god // ..and then Strad stole it from all of you!! RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.black, hoveredNode.m_position, 15f, hoveredNode.m_position.y - 1f, hoveredNode.m_position.y + 1f, true, true); float?radius = UIWindow.instance.P_RoundAboutPanel.RadiusField.Value; if (radius != null && NetUtil.ExistsNode(m_hoverNode)) { PreviewRoundabout((float)radius); float roadWidth = UIWindow.instance.dropDown.Value.m_halfWidth; // There is a slight chance that this will throw an exception float innerCirleRadius = radius - roadWidth > 0 ? 2 * ((float)radius - roadWidth) : 2 * (float)radius; RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.red, hoveredNode.m_position, innerCirleRadius, hoveredNode.m_position.y - 2f, hoveredNode.m_position.y + 2f, true, true); RenderManager.instance.OverlayEffect.DrawCircle(cameraInfo, Color.red, hoveredNode.m_position, 2 * ((float)radius + roadWidth /*DISTANCE_PADDING - 5*/), hoveredNode.m_position.y - 1f, hoveredNode.m_position.y + 1f, true, true); RenderHoveringLabel("Cost: " + (m_roundabout.Cost / 100) + "\nClick to build\nPress +/- to adjust radius"); } else { m_roundabout = null; RenderHoveringLabel("Invalid radius\nPress +/- to adjust radius"); } //RenderDirectionVectors(cameraInfo); } else { m_roundabout = null; RenderMousePositionCircle(cameraInfo); RenderHoveringLabel("Hover mouse over intersection"); } } catch (Exception e) { Debug.LogError(e); } }
/* 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); } }
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); } }