public override void OnPrimaryClickOverlay() { //Log._Debug($"Restrictions: {HoveredSegmentId} {overlayHandleHovered}"); if (HoveredSegmentId == 0) { return; } if (overlayHandleHovered) { return; } SelectedSegmentId = HoveredSegmentId; currentRestrictedSegmentIds.Add(SelectedSegmentId); MainTool.CheckClicked(); // TODO do we need that? }
private bool SimpleManualSegmentLightMode(int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, float zoom, float lightHeight, ICustomSegmentLight segmentDict, bool hoveredSegment) { SetAlpha(segmentId, 3); var myRect4 = new Rect( screenPos.x - (lightWidth / 2) - lightWidth - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: { GUI.DrawTexture(myRect4, TrafficLightTextures.GreenLight); break; } case RoadBaseAI.TrafficLightState.Red: { GUI.DrawTexture(myRect4, TrafficLightTextures.RedLight); break; } } if (!myRect4.Contains(Event.current.mousePosition)) { return(hoveredSegment); } hoveredButton[0] = segmentId; hoveredButton[1] = 3; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeMainLight(); return(true); }
private bool GetHoveredSegment(Rect myRect1, int segmentId, bool hoveredSegment, ICustomSegmentLight segmentDict) { if (!myRect1.Contains(Event.current.mousePosition)) { return(hoveredSegment); } //Log.Message("mouse in myRect1"); _hoveredButton[0] = segmentId; _hoveredButton[1] = -1; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ToggleMode(); return(true); }
public override void OnPrimaryClickOverlay() { // Log._Debug($"Restrictions: {HoveredSegmentId} {overlayHandleHovered}"); if (HoveredSegmentId == 0) { return; } if (overlayHandleHovered) { return; } SelectedSegmentId = HoveredSegmentId; currentRestrictedSegmentIds.Add(SelectedSegmentId); MainTool.CheckClicked(); // consume click. MainTool.RequestOnscreenDisplayUpdate(); }
public override void OnPrimaryClickOverlay() { if (HoveredNodeId == 0) { return; } if (overlayHandleHovered) { return; } if ((Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) == NetNode.Flags.None) { return; } SelectedNodeId = HoveredNodeId; MainTool.CheckClicked(); // prevent accidential activation of signs on node selection (TODO improve this!) }
private bool ForwardArrowLightMode(int segmentId, float lightWidth, bool hasRightSegment, Vector3 screenPos, float pedestrianWidth, float zoom, float lightHeight, ICustomSegmentLight segmentDict, bool hoveredSegment) { SetAlpha(segmentId, 4); var offsetLight = lightWidth; if (hasRightSegment) { offsetLight += lightWidth; } var myRect6 = new Rect(screenPos.x - lightWidth / 2 - offsetLight - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect6, TextureResources.GreenLightStraightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect6, TextureResources.RedLightStraightTexture2D); break; } if (!myRect6.Contains(Event.current.mousePosition)) { return(hoveredSegment); } _hoveredButton[0] = segmentId; _hoveredButton[1] = 4; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeMainLight(); return(true); }
public override void OnPrimaryClickOverlay() { bool debug = false; #if DEBUG debug = DebugSwitch.JunctionRestrictions.Get(); #endif if (HoveredNodeId == 0) { return; } if (overlayHandleHovered) { return; } if (!debug && (Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_flags & (NetNode.Flags.Junction | NetNode.Flags.Bend)) == NetNode.Flags.None) { return; } SelectedNodeId = HoveredNodeId; MainTool.CheckClicked(); // prevent accidential activation of signs on node selection (TODO improve this!) }
private bool RenderManualPedestrianLightSwitch(float zoom, int segmentId, Vector3 screenPos, float lightWidth, ICustomSegmentLights segmentLights, bool hoveredSegment) { if (segmentLights.PedestrianLightState == null) { return(false); } var guiColor = GUI.color; var manualPedestrianWidth = 36f * zoom; var manualPedestrianHeight = 35f * zoom; guiColor.a = MainTool.GetHandleAlpha(_hoveredButton[0] == segmentId && (_hoveredButton[1] == 1 || _hoveredButton[1] == 2)); GUI.color = guiColor; var myRect2 = new Rect(screenPos.x - manualPedestrianWidth / 2 - lightWidth + 5f * zoom, screenPos.y - manualPedestrianHeight / 2 - 9f * zoom, manualPedestrianWidth, manualPedestrianHeight); GUI.DrawTexture(myRect2, segmentLights.ManualPedestrianMode ? TextureResources.PedestrianModeManualTexture2D : TextureResources.PedestrianModeAutomaticTexture2D); if (!myRect2.Contains(Event.current.mousePosition)) { return(hoveredSegment); } _hoveredButton[0] = segmentId; _hoveredButton[1] = 1; if (!MainTool.CheckClicked()) { return(true); } segmentLights.ManualPedestrianMode = !segmentLights.ManualPedestrianMode; return(true); }
private bool LeftArrowLightMode(int segmentId, float lightWidth, bool hasRightSegment, bool hasForwardSegment, Vector3 screenPos, float pedestrianWidth, float zoom, float lightHeight, ICustomSegmentLight segmentDict, bool hoveredSegment) { SetAlpha(segmentId, 3); float offsetLight = lightWidth; if (hasRightSegment) { offsetLight += lightWidth; } if (hasForwardSegment) { offsetLight += lightWidth; } var myRect4 = new Rect( screenPos.x - (lightWidth / 2) - offsetLight - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); switch (segmentDict.LightLeft) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect4, TrafficLightTextures.GreenLightLeft); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect4, TrafficLightTextures.RedLightLeft); break; } if (!myRect4.Contains(Event.current.mousePosition)) { return(hoveredSegment); } hoveredButton[0] = segmentId; hoveredButton[1] = 3; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeLeftLight(); if (!hasForwardSegment) { segmentDict.ChangeMainLight(); } return(true); }
private bool RightForwardLSegmentLightMode(int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, float zoom, float lightHeight, bool hasForwardSegment, bool hasLeftSegment, ICustomSegmentLight segmentDict, bool hasRightSegment, bool hoveredSegment) { SetAlpha(segmentId, 3); var myRect4 = new Rect( screenPos.x - (lightWidth / 2) - (lightWidth * 2) - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); if (hasForwardSegment && hasLeftSegment) { switch (segmentDict.LightLeft) { case RoadBaseAI.TrafficLightState.Green: { GUI.DrawTexture(myRect4, TrafficLightTextures.GreenLightForwardLeft); break; } case RoadBaseAI.TrafficLightState.Red: { GUI.DrawTexture(myRect4, TrafficLightTextures.RedLightForwardLeft); break; } } } else if (!hasLeftSegment) { if (!hasRightSegment) { myRect4 = new Rect( screenPos.x - (lightWidth / 2) - lightWidth - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); } switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: { GUI.DrawTexture(myRect4, TrafficLightTextures.GreenLightStraight); break; } case RoadBaseAI.TrafficLightState.Red: { GUI.DrawTexture(myRect4, TrafficLightTextures.RedLightStraight); break; } } } else { if (!hasRightSegment) { myRect4 = new Rect( screenPos.x - (lightWidth / 2) - lightWidth - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); } switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: { GUI.DrawTexture(myRect4, TrafficLightTextures.GreenLightLeft); break; } case RoadBaseAI.TrafficLightState.Red: { GUI.DrawTexture(myRect4, TrafficLightTextures.RedLightLeft); break; } } } if (myRect4.Contains(Event.current.mousePosition)) { hoveredButton[0] = segmentId; hoveredButton[1] = 3; hoveredSegment = true; if (MainTool.CheckClicked()) { segmentDict.ChangeMainLight(); } } Color guiColor = GUI.color; // right arrow light if (hasRightSegment) { guiColor.a = TrafficManagerTool.GetHandleAlpha( hoveredButton[0] == segmentId && hoveredButton[1] == 4); } GUI.color = guiColor; var myRect5 = new Rect( screenPos.x - (lightWidth / 2) - lightWidth - pedestrianWidth + (5f * zoom), screenPos.y - (lightHeight / 2), lightWidth, lightHeight); switch (segmentDict.LightRight) { case RoadBaseAI.TrafficLightState.Green: { GUI.DrawTexture(myRect5, TrafficLightTextures.GreenLightRight); break; } case RoadBaseAI.TrafficLightState.Red: { GUI.DrawTexture(myRect5, TrafficLightTextures.RedLightRight); break; } } if (!myRect5.Contains(Event.current.mousePosition)) { return(hoveredSegment); } hoveredButton[0] = segmentId; hoveredButton[1] = 4; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeRightLight(); return(true); }
private bool drawSignHandles(bool debug, ushort nodeId, ref NetNode node, bool viewOnly, bool handleClick, ref Vector3 camPos, out bool stateUpdated) { bool hovered = false; stateUpdated = false; if (viewOnly && !(Options.junctionRestrictionsOverlay || PrioritySignsTool.showMassEditOverlay) && (MainTool.GetToolMode() != ToolMode.JunctionRestrictions)) { return(false); } // NetManager netManager = Singleton<NetManager>.instance; Color guiColor = GUI.color; Vector3 nodePos = Singleton <NetManager> .instance.m_nodes.m_buffer[nodeId].m_position; IExtSegmentEndManager segEndMan = Constants.ManagerFactory.ExtSegmentEndManager; for (int i = 0; i < 8; ++i) { ushort segmentId = node.GetSegment(i); if (segmentId == 0) { continue; } bool startNode = (bool)Constants.ServiceFactory.NetService.IsStartNode(segmentId, nodeId); bool incoming = segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, startNode)].incoming; int numSignsPerRow = incoming ? 2 : 1; NetInfo segmentInfo = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].Info; ItemClass connectionClass = segmentInfo.GetConnectionClass(); if (connectionClass.m_service != ItemClass.Service.Road) { continue; // only for road junctions } // draw all junction restriction signs Vector3 segmentCenterPos = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId] .m_bounds.center; Vector3 yu = (segmentCenterPos - nodePos).normalized; Vector3 xu = Vector3.Cross(yu, new Vector3(0, 1f, 0)).normalized; float f = viewOnly ? 6f : 7f; // reserved sign size in game coordinates Vector3 centerStart = nodePos + (yu * (viewOnly ? 5f : 14f)); Vector3 zero = centerStart - (0.5f * (numSignsPerRow - 1) * f * xu); // "top left" if (viewOnly) { if (Constants.ServiceFactory.SimulationService.TrafficDrivesOnLeft) { zero -= xu * 8f; } else { zero += xu * 8f; } } bool signHovered; int x = 0; int y = 0; bool hasSignInPrevRow = false; // draw "lane-changing when going straight allowed" sign at (0; 0) bool allowed = JunctionRestrictionsManager.Instance.IsLaneChangingAllowedWhenGoingStraight( segmentId, startNode); bool configurable = Constants.ManagerFactory.JunctionRestrictionsManager .IsLaneChangingAllowedWhenGoingStraightConfigurable( segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || (allowed != Constants.ManagerFactory .JunctionRestrictionsManager .GetDefaultLaneChangingAllowedWhenGoingStraight( segmentId, startNode, ref node))))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.LaneChangeAllowed : JunctionRestrictions.LaneChangeForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager.Instance.ToggleLaneChangingAllowedWhenGoingStraight( segmentId, startNode); stateUpdated = true; } } ++x; hasSignInPrevRow = true; } // draw "u-turns allowed" sign at (1; 0) allowed = JunctionRestrictionsManager.Instance.IsUturnAllowed(segmentId, startNode); configurable = Constants.ManagerFactory.JunctionRestrictionsManager.IsUturnAllowedConfigurable( segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || (allowed != Constants.ManagerFactory .JunctionRestrictionsManager .GetDefaultUturnAllowed( segmentId, startNode, ref node))))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.UturnAllowed : JunctionRestrictions.UturnForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { if (!JunctionRestrictionsManager.Instance.ToggleUturnAllowed( segmentId, startNode)) { // TODO MainTool.ShowTooltip(Translation.GetString("..."), Singleton<NetManager>.instance.m_nodes.m_buffer[nodeId].m_position); } else { stateUpdated = true; } } } x++; hasSignInPrevRow = true; } x = 0; if (hasSignInPrevRow) { ++y; hasSignInPrevRow = false; } // draw "entering blocked junctions allowed" sign at (0; 1) allowed = JunctionRestrictionsManager.Instance.IsEnteringBlockedJunctionAllowed( segmentId, startNode); configurable = Constants.ManagerFactory.JunctionRestrictionsManager .IsEnteringBlockedJunctionAllowedConfigurable( segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || (allowed != Constants.ManagerFactory .JunctionRestrictionsManager .GetDefaultEnteringBlockedJunctionAllowed( segmentId, startNode, ref node))))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.EnterBlockedJunctionAllowed : JunctionRestrictions.EnterBlockedJunctionForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager .Instance .ToggleEnteringBlockedJunctionAllowed(segmentId, startNode); stateUpdated = true; } } ++x; hasSignInPrevRow = true; } // draw "pedestrian crossing allowed" sign at (1; 1) allowed = JunctionRestrictionsManager.Instance.IsPedestrianCrossingAllowed( segmentId, startNode); configurable = Constants.ManagerFactory.JunctionRestrictionsManager .IsPedestrianCrossingAllowedConfigurable( segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || !allowed))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.PedestrianCrossingAllowed : JunctionRestrictions.PedestrianCrossingForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager.Instance.TogglePedestrianCrossingAllowed(segmentId, startNode); stateUpdated = true; } } x++; hasSignInPrevRow = true; } x = 0; if (hasSignInPrevRow) { ++y; hasSignInPrevRow = false; } if (!Options.turnOnRedEnabled) { continue; } //-------------------------------- // TURN ON RED ENABLED //-------------------------------- IJunctionRestrictionsManager junctionRestrictionsManager = Constants.ManagerFactory.JunctionRestrictionsManager; bool lht = Constants.ServiceFactory.SimulationService.TrafficDrivesOnLeft; // draw "turn-left-on-red allowed" sign at (2; 0) allowed = junctionRestrictionsManager.IsTurnOnRedAllowed(lht, segmentId, startNode); configurable = junctionRestrictionsManager.IsTurnOnRedAllowedConfigurable( lht, segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || (allowed != junctionRestrictionsManager .GetDefaultTurnOnRedAllowed( lht, segmentId, startNode, ref node))))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.LeftOnRedAllowed : JunctionRestrictions.LeftOnRedForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { junctionRestrictionsManager.ToggleTurnOnRedAllowed( lht, segmentId, startNode); stateUpdated = true; } } hasSignInPrevRow = true; } x++; // draw "turn-right-on-red allowed" sign at (2; 1) allowed = junctionRestrictionsManager.IsTurnOnRedAllowed( !lht, segmentId, startNode); configurable = junctionRestrictionsManager.IsTurnOnRedAllowedConfigurable( !lht, segmentId, startNode, ref node); if (debug || (configurable && (!viewOnly || (allowed != junctionRestrictionsManager .GetDefaultTurnOnRedAllowed( !lht, segmentId, startNode, ref node))))) { DrawSign( viewOnly, !configurable, ref camPos, ref xu, ref yu, f, ref zero, x, y, guiColor, allowed ? JunctionRestrictions.RightOnRedAllowed : JunctionRestrictions.RightOnRedForbidden, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { junctionRestrictionsManager.ToggleTurnOnRedAllowed( !lht, segmentId, startNode); stateUpdated = true; } } hasSignInPrevRow = true; } } guiColor.a = 1f; GUI.color = guiColor; return(hovered); }
private bool drawVehicleRestrictionHandles(ushort segmentId, bool viewOnly, out bool stateUpdated) { stateUpdated = false; if (viewOnly && !Options.vehicleRestrictionsOverlay && TrafficManagerTool.GetToolMode() != ToolMode.VehicleRestrictions) { return(false); } Vector3 center = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_bounds.center; var screenPos = Camera.main.WorldToScreenPoint(center); screenPos.y = Screen.height - screenPos.y; if (screenPos.z < 0) { return(false); } var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position; var diff = center - camPos; if (diff.magnitude > TrafficManagerTool.PriorityCloseLod) { return(false); // do not draw if too distant } int numDirections; // TODO refactor vehicle mask int numLanes = TrafficManagerTool.GetSegmentNumVehicleLanes(segmentId, null, out numDirections, VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train); // draw vehicle restrictions over each lane NetInfo segmentInfo = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].Info; Vector3 yu = (Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_endDirection - Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_startDirection).normalized; if ((Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) { yu = -yu; } Vector3 xu = Vector3.Cross(yu, new Vector3(0, 1f, 0)).normalized; float f = viewOnly ? 4f : 7f; // reserved sign size in game coordinates ItemClass connectionClass = segmentInfo.GetConnectionClass(); int maxNumSigns = 0; if (connectionClass.m_service == ItemClass.Service.Road) { maxNumSigns = roadVehicleTypes.Length; } else if (connectionClass.m_service == ItemClass.Service.PublicTransport && connectionClass.m_subService == ItemClass.SubService.PublicTransportTrain) { maxNumSigns = railVehicleTypes.Length; } //Vector3 zero = center - 0.5f * (float)(numLanes + numDirections - 1) * f * (xu + yu); // "bottom left" Vector3 zero = center - 0.5f * (float)(numLanes - 1 + numDirections - 1) * f * xu - 0.5f * (float)maxNumSigns * f * yu; // "bottom left" /*if (!viewOnly) * Log._Debug($"xu: {xu.ToString()} yu: {yu.ToString()} center: {center.ToString()} zero: {zero.ToString()} numLanes: {numLanes} numDirections: {numDirections}");*/ uint x = 0; var guiColor = GUI.color; // TODO refactor vehicle mask List <object[]> sortedLanes = TrafficManagerTool.GetSortedVehicleLanes(segmentId, segmentInfo, null, VehicleInfo.VehicleType.Car | VehicleInfo.VehicleType.Train); bool hovered = false; HashSet <NetInfo.Direction> directions = new HashSet <NetInfo.Direction>(); int sortedLaneIndex = -1; foreach (object[] laneData in sortedLanes) { ++sortedLaneIndex; uint laneId = (uint)laneData[0]; uint laneIndex = (uint)laneData[2]; NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex]; if (!directions.Contains(laneInfo.m_direction)) { if (directions.Count > 0) { ++x; // space between different directions } directions.Add(laneInfo.m_direction); } ExtVehicleType[] possibleVehicleTypes = null; if (VehicleRestrictionsManager.Instance.IsRoadLane(laneInfo)) { possibleVehicleTypes = roadVehicleTypes; } else if (VehicleRestrictionsManager.Instance.IsRailLane(laneInfo)) { possibleVehicleTypes = railVehicleTypes; } else { ++x; continue; } ExtVehicleType allowedTypes = VehicleRestrictionsManager.Instance.GetAllowedVehicleTypes(segmentId, segmentInfo, laneIndex, laneInfo); uint y = 0; #if DEBUGx Vector3 labelCenter = zero + f * (float)x * xu + f * (float)y * yu; // in game coordinates var labelScreenPos = Camera.main.WorldToScreenPoint(labelCenter); labelScreenPos.y = Screen.height - labelScreenPos.y; diff = labelCenter - camPos; var labelZoom = 1.0f / diff.magnitude * 100f; _counterStyle.fontSize = (int)(11f * labelZoom); _counterStyle.normal.textColor = new Color(1f, 1f, 0f); string labelStr = $"Idx {laneIndex}"; Vector2 dim = _counterStyle.CalcSize(new GUIContent(labelStr)); Rect labelRect = new Rect(labelScreenPos.x - dim.x / 2f, labelScreenPos.y, dim.x, dim.y); GUI.Label(labelRect, labelStr, _counterStyle); ++y; #endif foreach (ExtVehicleType vehicleType in possibleVehicleTypes) { bool allowed = VehicleRestrictionsManager.Instance.IsAllowed(allowedTypes, vehicleType); if (allowed && viewOnly) { continue; // do not draw allowed vehicles in view-only mode } bool hoveredHandle; DrawRestrictionsSign(viewOnly, camPos, out diff, xu, yu, f, zero, x, y, ref guiColor, TrafficLightToolTextureResources.VehicleRestrictionTextures[vehicleType][allowed], out hoveredHandle); if (hoveredHandle) { hovered = true; } if (hoveredHandle && MainTool.CheckClicked()) { // toggle vehicle restrictions //Log._Debug($"Setting vehicle restrictions of segment {segmentId}, lane idx {laneIndex}, {vehicleType.ToString()} to {!allowed}"); VehicleRestrictionsManager.Instance.ToggleAllowedType(segmentId, segmentInfo, laneIndex, laneId, laneInfo, vehicleType, !allowed); stateUpdated = true; // TODO use SegmentTraverser if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift)) { ApplyRestrictionsToAllSegments(sortedLaneIndex); } } ++y; } ++x; } guiColor.a = 1f; GUI.color = guiColor; return(hovered); }
public void ShowGUI(bool viewOnly) { try { TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance; TrafficPriorityManager prioMan = TrafficPriorityManager.Instance; TrafficLightManager tlm = TrafficLightManager.Instance; bool clicked = !viewOnly?MainTool.CheckClicked() : false; var hoveredSegment = false; //Log.Message("_guiPrioritySigns called. num of prio segments: " + TrafficPriority.PrioritySegments.Count); HashSet <ushort> nodeIdsWithSigns = new HashSet <ushort>(); foreach (ushort segmentId in currentPrioritySegmentIds) { var trafficSegment = prioMan.TrafficSegments[segmentId]; if (trafficSegment == null) { continue; } SegmentGeometry geometry = SegmentGeometry.Get(segmentId); prioritySegments[0] = null; prioritySegments[1] = null; if (tlsMan.GetNodeSimulation(trafficSegment.Node1) == null) { SegmentEnd tmpSeg1 = prioMan.GetPrioritySegment(trafficSegment.Node1, segmentId); bool startNode = geometry.StartNodeId() == trafficSegment.Node1; if (tmpSeg1 != null && !geometry.IsOutgoingOneWay(startNode)) { prioritySegments[0] = tmpSeg1; nodeIdsWithSigns.Add(trafficSegment.Node1); prioMan.AddPriorityNode(trafficSegment.Node1); } } if (tlsMan.GetNodeSimulation(trafficSegment.Node2) == null) { SegmentEnd tmpSeg2 = prioMan.GetPrioritySegment(trafficSegment.Node2, segmentId); bool startNode = geometry.StartNodeId() == trafficSegment.Node2; if (tmpSeg2 != null && !geometry.IsOutgoingOneWay(startNode)) { prioritySegments[1] = tmpSeg2; nodeIdsWithSigns.Add(trafficSegment.Node2); prioMan.AddPriorityNode(trafficSegment.Node2); } } //Log.Message("init ok"); foreach (var prioritySegment in prioritySegments) { if (prioritySegment == null) { continue; } var nodeId = prioritySegment.NodeId; //Log.Message("_guiPrioritySigns: nodeId=" + nodeId); var nodePositionVector3 = Singleton <NetManager> .instance.m_nodes.m_buffer[nodeId].m_position; var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position; var diff = nodePositionVector3 - camPos; if (diff.magnitude > TrafficManagerTool.PriorityCloseLod) { continue; // do not draw if too distant } if (Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_startNode == (ushort)nodeId) { nodePositionVector3.x += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_startDirection.x * 10f; nodePositionVector3.y += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_startDirection.y * 10f; nodePositionVector3.z += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_startDirection.z * 10f; } else { nodePositionVector3.x += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_endDirection.x * 10f; nodePositionVector3.y += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_endDirection.y * 10f; nodePositionVector3.z += Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_endDirection.z * 10f; } var nodeScreenPosition = Camera.main.WorldToScreenPoint(nodePositionVector3); nodeScreenPosition.y = Screen.height - nodeScreenPosition.y; if (nodeScreenPosition.z < 0) { continue; } var zoom = 1.0f / diff.magnitude * 100f * MainTool.GetBaseZoom(); var size = 110f * zoom; var guiColor = GUI.color; var nodeBoundingBox = new Rect(nodeScreenPosition.x - size / 2, nodeScreenPosition.y - size / 2, size, size); hoveredSegment = !viewOnly && TrafficManagerTool.IsMouseOver(nodeBoundingBox); if (hoveredSegment) { // mouse hovering over sign guiColor.a = 0.8f; } else { guiColor.a = 0.5f; size = 90f * zoom; } var nodeDrawingBox = new Rect(nodeScreenPosition.x - size / 2, nodeScreenPosition.y - size / 2, size, size); GUI.color = guiColor; bool setUndefinedSignsToMainRoad = false; switch (prioritySegment.Type) { case SegmentEnd.PriorityType.Main: GUI.DrawTexture(nodeDrawingBox, TrafficLightToolTextureResources.SignPriorityTexture2D); if (clicked && hoveredSegment) { //Log._Debug("Click on node " + nodeId + ", segment " + segmentId + " to change prio type (1)"); //Log.Message("PrioritySegment.Type = Yield"); prioritySegment.Type = SegmentEnd.PriorityType.Yield; setUndefinedSignsToMainRoad = true; clicked = false; } break; case SegmentEnd.PriorityType.Yield: GUI.DrawTexture(nodeDrawingBox, TrafficLightToolTextureResources.SignYieldTexture2D); if (clicked && hoveredSegment) { //Log._Debug("Click on node " + nodeId + ", segment " + segmentId + " to change prio type (2)"); prioritySegment.Type = SegmentEnd.PriorityType.Stop; setUndefinedSignsToMainRoad = true; clicked = false; } break; case SegmentEnd.PriorityType.Stop: GUI.DrawTexture(nodeDrawingBox, TrafficLightToolTextureResources.SignStopTexture2D); if (clicked && hoveredSegment) { //Log._Debug("Click on node " + nodeId + ", segment " + segmentId + " to change prio type (3)"); prioritySegment.Type = SegmentEnd.PriorityType.Main; clicked = false; } break; case SegmentEnd.PriorityType.None: if (viewOnly) { break; } GUI.DrawTexture(nodeDrawingBox, TrafficLightToolTextureResources.SignNoneTexture2D); if (clicked && hoveredSegment) { //Log._Debug("Click on node " + nodeId + ", segment " + segmentId + " to change prio type (4)"); //Log.Message("PrioritySegment.Type = None"); prioritySegment.Type = GetNumberOfMainRoads(nodeId, ref Singleton <NetManager> .instance.m_nodes.m_buffer[nodeId]) >= 2 ? SegmentEnd.PriorityType.Yield : SegmentEnd.PriorityType.Main; if (prioritySegment.Type == SegmentEnd.PriorityType.Yield) { setUndefinedSignsToMainRoad = true; } clicked = false; } break; } if (setUndefinedSignsToMainRoad) { foreach (var otherPrioritySegment in prioMan.GetPrioritySegments(nodeId)) { if (otherPrioritySegment.SegmentId == prioritySegment.SegmentId) { continue; } if (otherPrioritySegment.Type == SegmentEnd.PriorityType.None) { otherPrioritySegment.Type = SegmentEnd.PriorityType.Main; } } } } } if (viewOnly) { return; } ushort hoveredExistingNodeId = 0; foreach (ushort nodeId in nodeIdsWithSigns) { var nodePositionVector3 = Singleton <NetManager> .instance.m_nodes.m_buffer[nodeId].m_position; var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position; var diff = nodePositionVector3 - camPos; if (diff.magnitude > TrafficManagerTool.PriorityCloseLod) { continue; } // draw deletion button var nodeScreenPosition = Camera.main.WorldToScreenPoint(nodePositionVector3); nodeScreenPosition.y = Screen.height - nodeScreenPosition.y; if (nodeScreenPosition.z < 0) { continue; } var zoom = 1.0f / diff.magnitude * 100f * MainTool.GetBaseZoom(); var size = 90f * zoom; var nodeBoundingBox = new Rect(nodeScreenPosition.x - size / 2, nodeScreenPosition.y - size / 2, size, size); var guiColor = GUI.color; var nodeCenterHovered = TrafficManagerTool.IsMouseOver(nodeBoundingBox); if (nodeCenterHovered) { hoveredExistingNodeId = nodeId; guiColor.a = 0.8f; } else { guiColor.a = 0.5f; } GUI.color = guiColor; GUI.DrawTexture(nodeBoundingBox, TrafficLightToolTextureResources.SignRemoveTexture2D); } // add a new or delete a priority segment node if (HoveredNodeId != 0 || hoveredExistingNodeId != 0) { bool delete = false; if (hoveredExistingNodeId != 0) { delete = true; } // determine if we may add new priority signs to this node bool ok = false; TrafficLightSimulation nodeSim = tlsMan.GetNodeSimulation(HoveredNodeId); if ((Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_flags & NetNode.Flags.TrafficLights) == NetNode.Flags.None) { // no traffic light set ok = true; } else if (nodeSim == null || !nodeSim.IsTimedLight()) { ok = true; } if (!Flags.mayHaveTrafficLight(HoveredNodeId)) { ok = false; } if (clicked) { Log._Debug("_guiPrioritySigns: hovered+clicked @ nodeId=" + HoveredNodeId + "/" + hoveredExistingNodeId + " ok=" + ok); if (delete) { prioMan.RemovePrioritySegments(hoveredExistingNodeId); RefreshCurrentPrioritySegmentIds(); } else if (ok) { //if (!prioMan.IsPriorityNode(HoveredNodeId)) { Log._Debug("_guiPrioritySigns: adding prio segments @ nodeId=" + HoveredNodeId); tlsMan.RemoveNodeFromSimulation(HoveredNodeId, false, true); tlm.RemoveTrafficLight(HoveredNodeId); prioMan.AddPriorityNode(HoveredNodeId); RefreshCurrentPrioritySegmentIds(); //} } else if (nodeSim != null && nodeSim.IsTimedLight()) { MainTool.ShowTooltip(Translation.GetString("NODE_IS_TIMED_LIGHT"), Singleton <NetManager> .instance.m_nodes.m_buffer[HoveredNodeId].m_position); } } } } catch (Exception e) { Log.Error(e.ToString()); } }
private void ShowSigns(bool viewOnly) { Quaternion camRot = Camera.main.transform.rotation; Vector3 camPos = Camera.main.transform.position; NetManager netManager = Singleton <NetManager> .instance; ParkingRestrictionsManager parkingManager = ParkingRestrictionsManager.Instance; if (lastCamPos == null || lastCamRot == null || !lastCamRot.Equals(camRot) || !lastCamPos.Equals(camPos)) { // cache visible segments currentlyVisibleSegmentIds.Clear(); for (uint segmentId = 1; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) { if (!Constants.ServiceFactory.NetService.IsSegmentValid((ushort)segmentId)) { continue; } /*if ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Untouchable) != NetSegment.Flags.None) * continue;*/ if ((netManager.m_segments.m_buffer[segmentId].m_bounds.center - camPos).magnitude > TrafficManagerTool.MaxOverlayDistance) { continue; // do not draw if too distant } Vector3 screenPos; bool visible = MainTool.WorldToScreenPoint(netManager.m_segments.m_buffer[segmentId].m_bounds.center, out screenPos); if (!visible) { continue; } if (!parkingManager.MayHaveParkingRestriction((ushort)segmentId)) { continue; } currentlyVisibleSegmentIds.Add((ushort)segmentId); } lastCamPos = camPos; lastCamRot = camRot; } bool handleHovered = false; bool clicked = !viewOnly && MainTool.CheckClicked(); foreach (ushort segmentId in currentlyVisibleSegmentIds) { Vector3 screenPos; bool visible = MainTool.WorldToScreenPoint(netManager.m_segments.m_buffer[segmentId].m_bounds.center, out screenPos); if (!visible) { continue; } NetInfo segmentInfo = netManager.m_segments.m_buffer[segmentId].Info; // draw parking restrictions if (MainTool.GetToolMode() != ToolMode.SpeedLimits && (MainTool.GetToolMode() != ToolMode.VehicleRestrictions || segmentId != SelectedSegmentId)) // no parking restrictions overlay on selected segment when in vehicle restrictions mode { if (drawParkingRestrictionHandles((ushort)segmentId, clicked, ref netManager.m_segments.m_buffer[segmentId], viewOnly, ref camPos)) { handleHovered = true; } } } overlayHandleHovered = handleHovered; }
private bool DrawVehicleRestrictionHandles(ushort segmentId, ref NetSegment segment, bool viewOnly, out bool stateUpdated) { stateUpdated = false; if (viewOnly && !Options.vehicleRestrictionsOverlay && MainTool.GetToolMode() != ToolMode.VehicleRestrictions) { return(false); } Vector3 center = segment.m_bounds.center; bool visible = GeometryUtil.WorldToScreenPoint(center, out Vector3 _); if (!visible) { return(false); } Vector3 camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position; Vector3 diff = center - camPos; if (diff.sqrMagnitude > TrafficManagerTool.MAX_OVERLAY_DISTANCE_SQR) { return(false); // do not draw if too distant } int numLanes = GeometryUtil.GetSegmentNumVehicleLanes( segmentId, null, out int numDirections, VehicleRestrictionsManager.VEHICLE_TYPES); // draw vehicle restrictions over each lane NetInfo segmentInfo = segment.Info; Vector3 yu = (segment.m_endDirection - segment.m_startDirection).normalized; // if ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) // yu = -yu; Vector3 xu = Vector3.Cross(yu, new Vector3(0, 1f, 0)).normalized; float f = viewOnly ? 4f : 7f; // reserved sign size in game coordinates int maxNumSigns = 0; if (VehicleRestrictionsManager.Instance.IsRoadSegment(segmentInfo)) { maxNumSigns = RoadVehicleTypes.Length; } else if (VehicleRestrictionsManager.Instance.IsRailSegment(segmentInfo)) { maxNumSigns = RailVehicleTypes.Length; } // Vector3 zero = center - 0.5f * (float)(numLanes + numDirections - 1) * f * (xu + yu); // "bottom left" Vector3 zero = center - (0.5f * (numLanes - 1 + numDirections - 1) * f * xu) - (0.5f * maxNumSigns * f * yu); // "bottom left" // if (!viewOnly) // Log._Debug($"xu: {xu.ToString()} yu: {yu.ToString()} center: {center.ToString()} // zero: {zero.ToString()} numLanes: {numLanes} numDirections: {numDirections}");*/ uint x = 0; Color guiColor = GUI.color; IList <LanePos> sortedLanes = Constants.ServiceFactory.NetService.GetSortedLanes( segmentId, ref segment, null, VehicleRestrictionsManager.LANE_TYPES, VehicleRestrictionsManager.VEHICLE_TYPES); bool hovered = false; HashSet <NetInfo.Direction> directions = new HashSet <NetInfo.Direction>(); int sortedLaneIndex = -1; foreach (LanePos laneData in sortedLanes) { ++sortedLaneIndex; uint laneId = laneData.laneId; byte laneIndex = laneData.laneIndex; NetInfo.Lane laneInfo = segmentInfo.m_lanes[laneIndex]; if (!directions.Contains(laneInfo.m_finalDirection)) { if (directions.Count > 0) { ++x; // space between different directions } directions.Add(laneInfo.m_finalDirection); } ExtVehicleType[] possibleVehicleTypes; if (VehicleRestrictionsManager.Instance.IsRoadLane(laneInfo)) { possibleVehicleTypes = RoadVehicleTypes; } else if (VehicleRestrictionsManager.Instance.IsRailLane(laneInfo)) { possibleVehicleTypes = RailVehicleTypes; } else { ++x; continue; } ExtVehicleType allowedTypes = VehicleRestrictionsManager.Instance.GetAllowedVehicleTypes( segmentId, segmentInfo, laneIndex, laneInfo, VehicleRestrictionsMode.Configured); uint y = 0; #if DEBUG_disabled_xxx Vector3 labelCenter = zero + f * (float)x * xu + f * (float)y * yu; // in game coordinates Vector3 labelScreenPos; bool visible = GeometryUtil.WorldToScreenPoint(labelCenter, out labelScreenPos); // BUGBUG: Using screen.height might be wrong, consider U.UIScaler.ScreenHeight (from UIView.fixedHeight) labelScreenPos.y = Screen.height - labelScreenPos.y; diff = labelCenter - camPos; var labelZoom = 1.0f / diff.magnitude * 100f; _counterStyle.fontSize = (int)(11f * labelZoom); _counterStyle.normal.textColor = new Color(1f, 1f, 0f); string labelStr = $"Idx {laneIndex}"; Vector2 dim = _counterStyle.CalcSize(new GUIContent(labelStr)); Rect labelRect = new Rect(labelScreenPos.x - dim.x / 2f, labelScreenPos.y, dim.x, dim.y); GUI.Label(labelRect, labelStr, _counterStyle); ++y; #endif Color guiColor2 = GUI.color; GUI.color = GUI.color.WithAlpha(TrafficManagerTool.OverlayAlpha); foreach (ExtVehicleType vehicleType in possibleVehicleTypes) { bool allowed = VehicleRestrictionsManager.Instance.IsAllowed(allowedTypes, vehicleType); if (allowed && viewOnly) { continue; // do not draw allowed vehicles in view-only mode } bool hoveredHandle = MainTool.DrawGenericSquareOverlayGridTexture( RoadUI.VehicleRestrictionTextures[vehicleType][allowed], camPos, zero, f, xu, yu, x, y, vehicleRestrictionsSignSize, !viewOnly); if (hoveredHandle) { hovered = true; renderData_.segmentId = segmentId; renderData_.laneId = laneId; renderData_.laneIndex = laneIndex; renderData_.laneInfo = laneInfo; renderData_.SortedLaneIndex = sortedLaneIndex; } if (hoveredHandle && MainTool.CheckClicked()) { // toggle vehicle restrictions // Log._Debug($"Setting vehicle restrictions of segment {segmentId}, lane // idx {laneIndex}, {vehicleType.ToString()} to {!allowed}"); VehicleRestrictionsManager.Instance.ToggleAllowedType( segmentId, segmentInfo, laneIndex, laneId, laneInfo, vehicleType, !allowed); stateUpdated = true; RefreshCurrentRestrictedSegmentIds(segmentId); if (RoadMode) { ApplyRestrictionsToAllSegments(sortedLaneIndex, vehicleType); } } ++y; } GUI.color = guiColor2; ++x; } guiColor.a = 1f; GUI.color = guiColor; return(hovered); }
private bool drawSignHandles(ushort nodeId, bool viewOnly, bool handleClick, ref Vector3 camPos, out bool stateUpdated) { bool hovered = false; stateUpdated = false; if (viewOnly && !Options.junctionRestrictionsOverlay && MainTool.GetToolMode() != ToolMode.JunctionRestrictions) { return(false); } NetManager netManager = Singleton <NetManager> .instance; var guiColor = GUI.color; Vector3 nodePos = Singleton <NetManager> .instance.m_nodes.m_buffer[nodeId].m_position; for (int i = 0; i < 8; ++i) { ushort segmentId = netManager.m_nodes.m_buffer[nodeId].GetSegment(i); if (segmentId == 0) { continue; } SegmentGeometry geometry = SegmentGeometry.Get(segmentId); if (geometry == null) { Log.Error($"JunctionRestrictionsTool.drawSignHandles: No geometry information available for segment {segmentId}"); continue; } bool startNode = geometry.StartNodeId() == nodeId; bool incoming = geometry.IsIncoming(startNode); int numSignsPerRow = incoming ? 2 : 1; NetInfo segmentInfo = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].Info; ItemClass connectionClass = segmentInfo.GetConnectionClass(); if (connectionClass.m_service != ItemClass.Service.Road) { continue; // only for road junctions } // draw all junction restriction signs Vector3 segmentCenterPos = Singleton <NetManager> .instance.m_segments.m_buffer[segmentId].m_bounds.center; Vector3 yu = (segmentCenterPos - nodePos).normalized; Vector3 xu = Vector3.Cross(yu, new Vector3(0, 1f, 0)).normalized; float f = viewOnly ? 6f : 7f; // reserved sign size in game coordinates Vector3 centerStart = nodePos + yu * (viewOnly ? 5f : 14f); Vector3 zero = centerStart - 0.5f * (float)(numSignsPerRow - 1) * f * xu; // "top left" if (viewOnly) { if (Constants.ServiceFactory.SimulationService.LeftHandDrive) { zero -= xu * 8f; } else { zero += xu * 8f; } } bool signHovered; int x = 0; int y = 0; // draw "lane-changing when going straight allowed" sign at (0; 0) bool allowed = JunctionRestrictionsManager.Instance.IsLaneChangingAllowedWhenGoingStraight(segmentId, startNode); if (incoming && (!viewOnly || allowed != Options.allowLaneChangesWhileGoingStraight)) { DrawSign(viewOnly, ref camPos, ref xu, ref yu, f, ref zero, x, y, ref guiColor, allowed ? TextureResources.LaneChangeAllowedTexture2D : TextureResources.LaneChangeForbiddenTexture2D, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager.Instance.ToggleLaneChangingAllowedWhenGoingStraight(segmentId, startNode); stateUpdated = true; } } if (viewOnly) { ++y; } else { ++x; } } // draw "u-turns allowed" sign at (1; 0) allowed = JunctionRestrictionsManager.Instance.IsUturnAllowed(segmentId, startNode); if (incoming && (!viewOnly || allowed != Options.allowUTurns)) { DrawSign(viewOnly, ref camPos, ref xu, ref yu, f, ref zero, x, y, ref guiColor, allowed ? TextureResources.UturnAllowedTexture2D : TextureResources.UturnForbiddenTexture2D, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { if (!JunctionRestrictionsManager.Instance.ToggleUturnAllowed(segmentId, startNode)) { // TODO MainTool.ShowTooltip(Translation.GetString("..."), Singleton<NetManager>.instance.m_nodes.m_buffer[nodeId].m_position); } else { stateUpdated = true; } } } ++y; x = 0; } // draw "entering blocked junctions allowed" sign at (0; 1) allowed = JunctionRestrictionsManager.Instance.IsEnteringBlockedJunctionAllowed(segmentId, startNode); if (incoming && (!viewOnly || allowed != Options.allowEnterBlockedJunctions)) { DrawSign(viewOnly, ref camPos, ref xu, ref yu, f, ref zero, x, y, ref guiColor, allowed ? TextureResources.EnterBlockedJunctionAllowedTexture2D : TextureResources.EnterBlockedJunctionForbiddenTexture2D, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager.Instance.ToggleEnteringBlockedJunctionAllowed(segmentId, startNode); stateUpdated = true; } } if (viewOnly) { ++y; } else { ++x; } } // draw "pedestrian crossing allowed" sign at (1; 1) allowed = JunctionRestrictionsManager.Instance.IsPedestrianCrossingAllowed(segmentId, startNode); if (!viewOnly || !allowed) { DrawSign(viewOnly, ref camPos, ref xu, ref yu, f, ref zero, x, y, ref guiColor, allowed ? TextureResources.PedestrianCrossingAllowedTexture2D : TextureResources.PedestrianCrossingForbiddenTexture2D, out signHovered); if (signHovered && handleClick) { hovered = true; if (MainTool.CheckClicked()) { JunctionRestrictionsManager.Instance.TogglePedestrianCrossingAllowed(segmentId, startNode); stateUpdated = true; } } } } guiColor.a = 1f; GUI.color = guiColor; return(hovered); }
private void ShowSigns(bool viewOnly) { NetManager netManager = Singleton <NetManager> .instance; ParkingRestrictionsManager parkingManager = ParkingRestrictionsManager.Instance; var currentCamera = new CameraTransformValue(Camera.main); Transform currentCameraTransform = Camera.main.transform; Vector3 camPos = currentCameraTransform.position; if (!LastCachedCamera.Equals(currentCamera)) { // cache visible segments LastCachedCamera = currentCamera; CachedVisibleSegmentIds.Clear(); const float MAX_DIST = TrafficManagerTool.MAX_OVERLAY_DISTANCE * TrafficManagerTool.MAX_OVERLAY_DISTANCE; for (uint segmentId = 1; segmentId < NetManager.MAX_SEGMENT_COUNT; ++segmentId) { if (!Constants.ServiceFactory.NetService.IsSegmentValid((ushort)segmentId)) { continue; } // if ((netManager.m_segments.m_buffer[segmentId].m_flags // & NetSegment.Flags.Untouchable) != NetSegment.Flags.None) // continue; Vector3 distToCamera = netManager.m_segments.m_buffer[segmentId].m_bounds.center - camPos; if (distToCamera.sqrMagnitude > MAX_DIST) { continue; // do not draw if too distant } bool visible = MainTool.WorldToScreenPoint( netManager.m_segments.m_buffer[segmentId].m_bounds.center, out Vector3 _); if (!visible) { continue; } if (!parkingManager.MayHaveParkingRestriction((ushort)segmentId)) { continue; } CachedVisibleSegmentIds.Add((ushort)segmentId); } // end for all segments } bool clicked = !viewOnly && MainTool.CheckClicked(); for (int segmentIdIndex = CachedVisibleSegmentIds.Size - 1; segmentIdIndex >= 0; segmentIdIndex--) { ushort segmentId = CachedVisibleSegmentIds.Values[segmentIdIndex]; // draw parking restrictions if ((MainTool.GetToolMode() == ToolMode.SpeedLimits) || ((MainTool.GetToolMode() == ToolMode.VehicleRestrictions) && (segmentId == SelectedSegmentId))) { continue; } // no parking restrictions overlay on selected segment when in vehicle restrictions mode DrawParkingRestrictionHandles( segmentId, clicked, ref netManager.m_segments.m_buffer[segmentId], viewOnly, ref camPos); } }
private bool LeftForwardRManualSegmentLightMode(bool hasLeftSegment, int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, float zoom, float lightHeight, ICustomSegmentLight segmentDict, bool hoveredSegment, bool hasForwardSegment, bool hasRightSegment) { if (hasLeftSegment) { // left arrow light SetAlpha(segmentId, 3); var myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth * 2 - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); switch (segmentDict.LightLeft) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect4, TextureResources.GreenLightLeftTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect4, TextureResources.RedLightLeftTexture2D); break; } if (myRect4.Contains(Event.current.mousePosition)) { _hoveredButton[0] = segmentId; _hoveredButton[1] = 3; hoveredSegment = true; if (MainTool.CheckClicked()) { segmentDict.ChangeLeftLight(); } } } // forward-right arrow light SetAlpha(segmentId, 4); var myRect5 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); if (hasForwardSegment && hasRightSegment) { switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect5, TextureResources.GreenLightForwardRightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect5, TextureResources.RedLightForwardRightTexture2D); break; } } else if (!hasRightSegment) { switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect5, TextureResources.GreenLightStraightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect5, TextureResources.RedLightStraightTexture2D); break; } } else { switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect5, TextureResources.GreenLightRightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect5, TextureResources.RedLightRightTexture2D); break; } } if (!myRect5.Contains(Event.current.mousePosition)) { return(hoveredSegment); } _hoveredButton[0] = segmentId; _hoveredButton[1] = 4; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeMainLight(); return(true); }
public void ShowGUI(bool viewOnly) { try { IExtSegmentManager segMan = Constants.ManagerFactory.ExtSegmentManager; IExtSegmentEndManager segEndMan = Constants.ManagerFactory.ExtSegmentEndManager; TrafficLightSimulationManager tlsMan = TrafficLightSimulationManager.Instance; TrafficPriorityManager prioMan = TrafficPriorityManager.Instance; TrafficLightManager tlm = TrafficLightManager.Instance; Vector3 camPos = Constants.ServiceFactory.SimulationService.CameraPosition; bool clicked = !viewOnly?MainTool.CheckClicked() : false; ushort removedNodeId = 0; bool showRemoveButton = false; foreach (ushort nodeId in currentPriorityNodeIds) { if (!Constants.ServiceFactory.NetService.IsNodeValid(nodeId)) { continue; } if (!MainTool.IsNodeWithinViewDistance(nodeId)) { continue; } Vector3 nodePos = default(Vector3); Constants.ServiceFactory.NetService.ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) { nodePos = node.m_position; return(true); }); for (int i = 0; i < 8; ++i) { ushort segmentId = 0; Constants.ServiceFactory.NetService.ProcessNode(nodeId, delegate(ushort nId, ref NetNode node) { segmentId = node.GetSegment(i); return(true); }); if (segmentId == 0) { continue; } bool startNode = (bool)Constants.ServiceFactory.NetService.IsStartNode(segmentId, nodeId); ExtSegment seg = segMan.ExtSegments[segmentId]; ExtSegmentEnd segEnd = segEndMan.ExtSegmentEnds[segEndMan.GetIndex(segmentId, startNode)]; if (seg.oneWay && segEnd.outgoing) { continue; } // calculate sign position Vector3 signPos = nodePos; Constants.ServiceFactory.NetService.ProcessSegment(segmentId, delegate(ushort sId, ref NetSegment segment) { signPos += 10f * (startNode ? segment.m_startDirection : segment.m_endDirection); return(true); }); Vector3 signScreenPos; if (!MainTool.WorldToScreenPoint(signPos, out signScreenPos)) { continue; } // draw sign and handle input PriorityType sign = prioMan.GetPrioritySign(segmentId, startNode); if (viewOnly && sign == PriorityType.None) { continue; } if (!viewOnly && sign != PriorityType.None) { showRemoveButton = true; } if (MainTool.DrawGenericSquareOverlayTexture(TextureResources.PrioritySignTextures[sign], camPos, signPos, 90f, !viewOnly) && clicked) { PriorityType?newSign = null; switch (sign) { case PriorityType.Main: newSign = PriorityType.Yield; break; case PriorityType.Yield: newSign = PriorityType.Stop; break; case PriorityType.Stop: newSign = PriorityType.Main; break; case PriorityType.None: default: newSign = prioMan.CountPrioritySignsAtNode(nodeId, PriorityType.Main) >= 2 ? PriorityType.Yield : PriorityType.Main; break; } if (newSign != null) { SetPrioritySign(segmentId, startNode, (PriorityType)newSign); } } // draw sign } // foreach segment end if (viewOnly) { continue; } // draw remove button and handle click if (showRemoveButton && MainTool.DrawHoverableSquareOverlayTexture(TextureResources.SignRemoveTexture2D, camPos, nodePos, 90f) && clicked) { prioMan.RemovePrioritySignsFromNode(nodeId); Log._Debug($"PrioritySignsTool.ShowGUI: Removed priority signs from node {nodeId}"); removedNodeId = nodeId; } } // foreach node if (removedNodeId != 0) { currentPriorityNodeIds.Remove(removedNodeId); SelectedNodeId = 0; } } catch (Exception e) { Log.Error(e.ToString()); } }
private bool RightForwardLSegmentLightMode(int segmentId, Vector3 screenPos, float lightWidth, float pedestrianWidth, float zoom, float lightHeight, bool hasForwardSegment, bool hasLeftSegment, CustomSegmentLight segmentDict, bool hasRightSegment, bool hoveredSegment) { SetAlpha(segmentId, 3); var myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth * 2 - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); if (hasForwardSegment && hasLeftSegment) { switch (segmentDict.LightLeft) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.GreenLightForwardLeftTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.RedLightForwardLeftTexture2D); break; } } else if (!hasLeftSegment) { if (!hasRightSegment) { myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); } switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.GreenLightStraightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.RedLightStraightTexture2D); break; } } else { if (!hasRightSegment) { myRect4 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); } switch (segmentDict.LightMain) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.GreenLightLeftTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect4, TrafficLightToolTextureResources.RedLightLeftTexture2D); break; } } if (myRect4.Contains(Event.current.mousePosition)) { _hoveredButton[0] = segmentId; _hoveredButton[1] = 3; hoveredSegment = true; if (MainTool.CheckClicked()) { segmentDict.ChangeLightMain(); } } var guiColor = GUI.color; // right arrow light if (hasRightSegment) { guiColor.a = _hoveredButton[0] == segmentId && _hoveredButton[1] == 4 ? 0.92f : 0.6f; } GUI.color = guiColor; var myRect5 = new Rect(screenPos.x - lightWidth / 2 - lightWidth - pedestrianWidth + 5f * zoom, screenPos.y - lightHeight / 2, lightWidth, lightHeight); switch (segmentDict.LightRight) { case RoadBaseAI.TrafficLightState.Green: GUI.DrawTexture(myRect5, TrafficLightToolTextureResources.GreenLightRightTexture2D); break; case RoadBaseAI.TrafficLightState.Red: GUI.DrawTexture(myRect5, TrafficLightToolTextureResources.RedLightRightTexture2D); break; } if (!myRect5.Contains(Event.current.mousePosition)) { return(hoveredSegment); } _hoveredButton[0] = segmentId; _hoveredButton[1] = 4; if (!MainTool.CheckClicked()) { return(true); } segmentDict.ChangeLightRight(); return(true); }