Ejemplo n.º 1
0
        public override void OnToolGUI(Event e)
        {
            base.OnToolGUI(e);

            if (SelectedSegmentId != 0)
            {
                cursorInSecondaryPanel = false;

                Color oldColor = GUI.color;
                GUI.color = GUI.color.WithAlpha(TrafficManagerTool.GetWindowAlpha());

                windowRect = GUILayout.Window(
                    255,
                    windowRect,
                    _guiVehicleRestrictionsWindowDelegate,
                    T("Dialog.Title:Vehicle restrictions"),
                    WindowStyle,
                    EmptyOptionsArray);
                cursorInSecondaryPanel = windowRect.Contains(Event.current.mousePosition);
                GUI.color = oldColor;
                // overlayHandleHovered = false;
            }

            // ShowSigns(false);
        }
Ejemplo n.º 2
0
        private void DrawSign(bool viewOnly, ref Vector3 camPos, ref Vector3 xu, ref Vector3 yu, float f, ref Vector3 zero, int x, int y, ref Color guiColor, Texture2D signTexture, out bool hoveredHandle)
        {
            Vector3 signCenter = zero + f * (float)x * xu + f * (float)y * yu;             // in game coordinates

            Vector3 signScreenPos;
            bool    visible = MainTool.WorldToScreenPoint(signCenter, out signScreenPos);

            if (!visible)
            {
                hoveredHandle = false;
                return;
            }

            Vector3 diff = signCenter - camPos;

            var zoom = 1.0f / diff.magnitude * 100f * MainTool.GetBaseZoom();
            var size = (viewOnly ? 0.8f : 1f) * junctionRestrictionsSignSize * zoom;

            var boundingBox = new Rect(signScreenPos.x - size / 2, signScreenPos.y - size / 2, size, size);

            hoveredHandle = !viewOnly && TrafficManagerTool.IsMouseOver(boundingBox);
            if (hoveredHandle)
            {
                // mouse hovering over sign
                guiColor.a = 0.8f;
            }
            else
            {
                guiColor.a = 0.5f;
            }

            GUI.color = guiColor;
            GUI.DrawTexture(boundingBox, signTexture);
        }
Ejemplo n.º 3
0
        public VehicleRestrictionsTool(TrafficManagerTool mainTool)
            : base(mainTool)
        {
            _guiVehicleRestrictionsWindowDelegate = GuiVehicleRestrictionsWindow;

            currentRestrictedSegmentIds = new HashSet <ushort>();
        }
        /// <summary>
        ///  Intersects mouse ray with marker bounds.
        /// </summary>
        /// <returns><c>true</c>if mouse ray intersects with marker <c>false</c> otherwise</returns>
        internal bool IntersectRay()
        {
            Camera currentCamera = Camera.main;
            Ray    mouseRay      = currentCamera.ScreenPointToRay(Input.mousePosition);
            float  hitH          = TrafficManagerTool.GetAccurateHitHeight();

            Vector3 pos    = Position;
            float   mouseH = ModUI.GetTrafficManagerTool(false).MousePosition.y;

            if (hitH < mouseH - TrafficManagerTool.MAX_HIT_ERROR)
            {
                // For metros use projection on the terrain.
                pos = TerrainPosition;
            }
            else if (hitH - pos.y > TrafficManagerTool.MAX_HIT_ERROR)
            {
                // if marker is projected on road plane above then modify its height
                pos.y = hitH;
            }
            Bounds bounds = new Bounds(Vector3.zero, Vector3.one * Radius)
            {
                center = pos,
            };

            return(bounds.IntersectRay(mouseRay));
        }
Ejemplo n.º 5
0
 internal void Housekeeping()
 {
     if (TrafficManagerTool.GetToolMode() != ToolMode.AddPrioritySigns && TrafficLightSimulationManager.Instance().GetNodeSimulation(NodeId) == null && Type == PriorityType.None)
     {
         TrafficPriorityManager.Instance().RemovePrioritySegments(NodeId);
     }
 }
Ejemplo n.º 6
0
        private void GuiSpeedLimitsWindow_AddClearButton()
        {
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            float signSize = TrafficManagerTool.AdaptWidth(GUI_SPEED_SIGN_SIZE);

            if (GUILayout.Button(
                    SpeedLimitTextures.Clear,
                    GUILayout.Width(signSize),
                    GUILayout.Height(signSize * GetVerticalTextureScale())))
            {
                currentPaletteSpeedLimit = null;
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            // For MPH setting display KM/H below, for KM/H setting display MPH
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(Translation.SpeedLimits.Get("Button:Default") + " [del]");

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
        /*public override void OnAfterSimulationFrame() {
         *      base.OnAfterSimulationFrame();
         *
         *      routeMan.SimulationStep();
         *
         ++ticksSinceLastMinuteUpdate;
         *      if (ticksSinceLastMinuteUpdate > 60 * 60) {
         *              ticksSinceLastMinuteUpdate = 0;
         *              GlobalConfig.Instance.SimulationStep();
         #if DEBUG
         *              DebugMenuPanel.PrintTransportStats();
         #endif
         *      }
         * }*/

        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

#if !TAM
#if BENCHMARK
            using (var bm = new Benchmark()) {
#endif

            if (ToolsModifierControl.toolController == null || LoadingExtension.BaseUI == null)
            {
                return;
            }

            TrafficManagerTool tmTool = UIBase.GetTrafficManagerTool(false);
            if (tmTool != null && ToolsModifierControl.toolController.CurrentTool != tmTool && LoadingExtension.BaseUI.IsVisible())
            {
                LoadingExtension.BaseUI.Close();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                LoadingExtension.BaseUI.Close();
            }
#if BENCHMARK
        }
#endif
#endif
        }
        public void CustomNodeSimulationStep(ushort nodeId, ref NetNode data)
        {
            if (simStartFrame == 0)
            {
                simStartFrame = Singleton <SimulationManager> .instance.m_currentFrameIndex;
            }

            try {
                if (TrafficManagerTool.GetToolMode() != ToolMode.AddPrioritySigns)
                {
                    try {
                        TrafficPriority.nodeHousekeeping(nodeId);
                    } catch (Exception e) {
                        Log.Error($"Error occured while housekeeping node {nodeId}: " + e.ToString());
                    }
                }

                TrafficPriority.TrafficLightSimulationStep();

                var nodeSim = TrafficLightSimulation.GetNodeSimulation(nodeId);
                if (nodeSim == null || !nodeSim.IsSimulationActive())
                {
                    OriginalSimulationStep(nodeId, ref data);
                }
            } catch (Exception e) {
                Log.Warning($"CustomNodeSimulationStep: An error occurred: {e.ToString()}");
            }
        }
        private void _guiSpeedLimitsWindow(int num)
        {
            GUILayout.BeginHorizontal();

            Color oldColor = GUI.color;

            for (int i = 0; i < SpeedLimitManager.Instance.AvailableSpeedLimits.Count; ++i)
            {
                if (curSpeedLimitIndex != i)
                {
                    GUI.color = Color.gray;
                }
                float signSize = TrafficManagerTool.AdaptWidth(guiSpeedSignSize);
                if (GUILayout.Button(TrafficLightToolTextureResources.SpeedLimitTextures[SpeedLimitManager.Instance.AvailableSpeedLimits[i]], GUILayout.Width(signSize), GUILayout.Height(signSize)))
                {
                    curSpeedLimitIndex = i;
                }
                GUI.color = oldColor;

                if (i == 6)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
            }

            GUILayout.EndHorizontal();

            if (GUILayout.Button(Translation.GetString("Default_speed_limits")))
            {
                defaultsWindowVisible = true;
            }

            DragWindow(ref windowRect);
        }
        private void DrawRestrictionsSign(bool viewOnly, Vector3 camPos, out Vector3 diff, Vector3 xu, Vector3 yu, float f, Vector3 zero, uint x, uint y, ref Color guiColor, Texture2D signTexture, out bool hoveredHandle)
        {
            Vector3 signCenter = zero + f * (float)x * xu + f * (float)y * yu;             // in game coordinates

            var signScreenPos = Camera.main.WorldToScreenPoint(signCenter);

            signScreenPos.y = Screen.height - signScreenPos.y;
            diff            = signCenter - camPos;

            var zoom = 1.0f / diff.magnitude * 100f * MainTool.GetBaseZoom();
            var size = (viewOnly ? 0.8f : 1f) * vehicleRestrictionsSignSize * zoom;

            var boundingBox = new Rect(signScreenPos.x - size / 2, signScreenPos.y - size / 2, size, size);

            hoveredHandle = !viewOnly && TrafficManagerTool.IsMouseOver(boundingBox);
            if (hoveredHandle)
            {
                // mouse hovering over sign
                guiColor.a = 0.8f;
            }
            else
            {
                guiColor.a = 0.5f;
            }

            GUI.color = guiColor;
            GUI.DrawTexture(boundingBox, signTexture);
        }
        private void _guiSpeedLimitsWindow(int num)
        {
            GUILayout.BeginHorizontal();

            Color oldColor = GUI.color;

            for (int i = 0; i < SpeedLimitManager.AvailableSpeedLimits.Count; ++i)
            {
                if (curSpeedLimitIndex != i)
                {
                    GUI.color = Color.gray;
                }
                float signSize = TrafficManagerTool.AdaptWidth(100);
                if (GUILayout.Button(TrafficLightToolTextureResources.SpeedLimitTextures[SpeedLimitManager.AvailableSpeedLimits[i]], GUILayout.Width(signSize), GUILayout.Height(signSize)))
                {
                    curSpeedLimitIndex = i;
                }
                GUI.color = oldColor;

                if (i == 6)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
            }

            GUILayout.EndHorizontal();
        }
        /// <summary>Helper to create speed limit sign + label below converted to the opposite unit</summary>
        /// <param name="showMph">Config value from GlobalConfig.I.M.ShowMPH</param>
        /// <param name="speedLimit">The float speed to show</param>
        private void GuiSpeedLimitsWindow_AddButton(bool showMph, SpeedValue speedLimit)
        {
            // The button is wrapped in vertical sub-layout and a label for MPH/KMPH is added
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            float signSize = TrafficManagerTool.AdaptWidth(GUI_SPEED_SIGN_SIZE);

            if (GUILayout.Button(
                    SpeedLimitTextures.GetSpeedLimitTexture(speedLimit),
                    GUILayout.Width(signSize),
                    GUILayout.Height(signSize * GetVerticalTextureScale())))
            {
                currentPaletteSpeedLimit = speedLimit;
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            // For MPH setting display KM/H below, for KM/H setting display MPH
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(
                showMph
                    ? ToKmphPreciseString(speedLimit)
                    : ToMphPreciseString(speedLimit));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
 /// <summary>Initializes a new instance of the <see cref="TrafficRulesOverlay"/> struct for rendering.</summary>
 /// <param name="mainTool">Parent <see cref="TrafficManagerTool"/>.</param>
 /// <param name="debug">Is debug rendering on.</param>
 /// <param name="handleClick">Whether clicks are to be handled.</param>
 public TrafficRulesOverlay(TrafficManagerTool mainTool,
                bool debug,
                bool handleClick) {
     mainTool_ = mainTool;
     debug_ = debug;
     handleClick_ = handleClick;
     ViewOnly = true;
 }
        public LaneConnectorTool(TrafficManagerTool mainTool)
            : base(mainTool)
        {
            // Log._Debug($"LaneConnectorTool: Constructor called");
            currentNodeMarkers = new Dictionary <ushort, List <NodeLaneMarker> >();

            CachedVisibleNodeIds = new GenericArrayCache <uint>(NetManager.MAX_NODE_COUNT);
            LastCachedCamera     = new CameraTransformValue();
        }
Ejemplo n.º 15
0
        private void GuiVehicleRestrictionsWindow(int num)
        {
            // use blue color when shift is pressed.
            Color oldColor = GUI.color;

            GUI.color = GUI.color.WithAlpha(TrafficManagerTool.GetWindowAlpha());
            if (RoadMode)
            {
                GUI.color = HighlightColor;
            }

            // uses pressed sprite when delete is pressed
            // uses blue color when shift is pressed.
            KeyCode  hotkey = KeyCode.Delete;
            GUIStyle style  = new GUIStyle("button");

            if (Input.GetKey(hotkey))
            {
                style.normal.background = style.active.background;
            }
            if (GUILayout.Button(
                    T("Button:Allow all vehicles") + " [delete]",
                    style,
                    EmptyOptionsArray) || Input.GetKeyDown(hotkey))
            {
                AllVehiclesFunc(true);
                if (RoadMode)
                {
                    ApplyRestrictionsToAllSegments();
                }
            }

            if (GUILayout.Button(T("Button:Ban all vehicles"), EmptyOptionsArray))
            {
                AllVehiclesFunc(false);
                if (RoadMode)
                {
                    ApplyRestrictionsToAllSegments();
                }
            }

            if (RoadMode)
            {
                GUI.color = oldColor;
            }

            if (GUILayout.Button(
                    T("Button:Apply to entire road"),
                    EmptyOptionsArray))
            {
                ApplyRestrictionsToAllSegments();
            }

            GUI.color = oldColor;
            DragWindow(ref windowRect);
        }
Ejemplo n.º 16
0
        private void SetAlpha(int segmentId, int buttonId)
        {
            Color guiColor = GUI.color;

            guiColor.a = TrafficManagerTool.GetHandleAlpha(
                hoveredButton[0] == segmentId &&
                hoveredButton[1] == buttonId);

            GUI.color = guiColor;
        }
Ejemplo n.º 17
0
        public override void OnToolGUI(Event e)
        {
            //base.OnToolGUI(e);
            _cursorInSecondaryPanel = false;

            if (SelectedNodeId == 0 || SelectedSegmentId == 0)
            {
                return;
            }

            int numDirections;
            int numLanes = TrafficManagerTool.GetSegmentNumVehicleLanes(SelectedSegmentId, SelectedNodeId, out numDirections, LaneArrowManager.VEHICLE_TYPES);

            if (numLanes <= 0)
            {
                SelectedNodeId    = 0;
                SelectedSegmentId = 0;
                return;
            }

            var style = new GUIStyle {
                normal    = { background = SecondPanelTexture },
                alignment = TextAnchor.MiddleCenter,
                border    =
                {
                    bottom = 2,
                    top    = 2,
                    right  = 2,
                    left   = 2
                }
            };

            Vector3 nodePos = Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId].m_position;

            Vector3 screenPos;
            bool    visible = MainTool.WorldToScreenPoint(nodePos, out screenPos);

            if (!visible)
            {
                return;
            }

            var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
            var diff   = nodePos - camPos;

            if (diff.magnitude > TrafficManagerTool.MaxOverlayDistance)
            {
                return;                 // do not draw if too distant
            }
            int width       = numLanes * 128;
            var windowRect3 = new Rect(screenPos.x - width / 2, screenPos.y - 70, width, 50);

            GUILayout.Window(250, windowRect3, _guiLaneChangeWindow, "", style);
            _cursorInSecondaryPanel = windowRect3.Contains(Event.current.mousePosition);
        }
Ejemplo n.º 18
0
        public override void OnToolGUI(Event e)
        {
            //base.OnToolGUI(e);

            _cursorInSecondaryPanel = false;

            if (SelectedNodeId == 0 || SelectedSegmentId == 0)
            {
                return;
            }

            int numDirections;
            int numLanes = TrafficManagerTool.GetSegmentNumVehicleLanes(SelectedSegmentId, SelectedNodeId, out numDirections);

            if (numLanes <= 0)
            {
                SelectedNodeId    = 0;
                SelectedSegmentId = 0;
                return;
            }

            var style = new GUIStyle {
                normal    = { background = SecondPanelTexture },
                alignment = TextAnchor.MiddleCenter,
                border    =
                {
                    bottom = 2,
                    top    = 2,
                    right  = 2,
                    left   = 2
                }
            };

            Vector3 nodePos   = Singleton <NetManager> .instance.m_nodes.m_buffer[SelectedNodeId].m_position;
            var     screenPos = Camera.main.WorldToScreenPoint(nodePos);

            screenPos.y = Screen.height - screenPos.y;
            //Log._Debug($"node pos of {SelectedNodeId}: {nodePos.ToString()} {screenPos.ToString()}");
            if (screenPos.z < 0)
            {
                return;
            }
            var camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
            var diff   = nodePos - camPos;

            if (diff.magnitude > TrafficManagerTool.PriorityCloseLod)
            {
                return;                 // do not draw if too distant
            }
            int width       = numLanes * 128;
            var windowRect3 = new Rect(screenPos.x - width / 2, screenPos.y - 70, width, 50);

            GUILayout.Window(250, windowRect3, _guiLaneChangeWindow, "", style);
            _cursorInSecondaryPanel = windowRect3.Contains(Event.current.mousePosition);
        }
Ejemplo n.º 19
0
        public override void OnToolGUI(Event e)
        {
            // base.OnToolGUI(e);
            cursorInSecondaryPanel_ = false;

            if ((SelectedNodeId == 0) || (SelectedSegmentId == 0))
            {
                return;
            }

            int numLanes = TrafficManagerTool.GetSegmentNumVehicleLanes(
                SelectedSegmentId,
                SelectedNodeId,
                out int numDirections,
                LaneArrowManager.VEHICLE_TYPES);

            if (numLanes <= 0)
            {
                SelectedNodeId    = 0;
                SelectedSegmentId = 0;
                return;
            }

            Vector3 nodePos = Singleton <NetManager>
                              .instance.m_nodes.m_buffer[SelectedNodeId].m_position;

            bool visible = MainTool.WorldToScreenPoint(nodePos, out Vector3 screenPos);

            if (!visible)
            {
                return;
            }

            Vector3 camPos = Singleton <SimulationManager> .instance.m_simulationView.m_position;
            Vector3 diff   = nodePos - camPos;

            if (diff.sqrMagnitude > TrafficManagerTool.MAX_OVERLAY_DISTANCE_SQR)
            {
                return; // do not draw if too distant
            }

            int  width     = numLanes * 128;
            int  height    = 50;
            bool startNode = (bool)netService.IsStartNode(SelectedSegmentId, SelectedNodeId);

            if (CanReset(SelectedSegmentId, startNode))
            {
                height += 40;
            }

            var windowRect3 = new Rect(screenPos.x - (width / 2), screenPos.y - 70, width, height);

            GUILayout.Window(250, windowRect3, GuiLaneChangeWindow, string.Empty, BorderlessStyle);
            cursorInSecondaryPanel_ = windowRect3.Contains(Event.current.mousePosition);
        }
        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

#if !TAM
#if BENCHMARK
            using (var bm = new Benchmark()) {
#endif

            if (ToolsModifierControl.toolController == null || LoadingExtension.BaseUI == null)
            {
                return;
            }

            TrafficManagerTool tmTool = UIBase.GetTrafficManagerTool(false);
            if (tmTool != null && ToolsModifierControl.toolController.CurrentTool != tmTool && LoadingExtension.BaseUI.IsVisible())
            {
                LoadingExtension.BaseUI.Close();
            }

            if (Input.GetKeyDown(KeyCode.Escape))
            {
                LoadingExtension.BaseUI.Close();
            }
#if BENCHMARK
        }
#endif
#endif

            if (!FindComponents())
            {
                return;
            }

            if (_panel.component.isVisible)
            {
                ushort buildingId = WorldInfoPanel.GetCurrentInstanceID().Building;
                //Debug.Log(WorldInfoPanel.GetCurrentInstanceID().Building);
                //if (_lastBuildingId != buildingId)
                //{
                var building = Singleton <BuildingManager> .instance.m_buildings.m_buffer[buildingId];
                // display the right checkbox state
                _fmuCheckBox.text = "prodRate[" + buildingId + "] = " + building.m_productionRate;
                _lastBuildingId   = buildingId;
                //}
                var t = Singleton <WeatherManager> .instance.m_lastLightningIntensity.ToString();

                _fmuCheckBox.text += " sun= " + t;
            }
            else
            {
                _lastBuildingId = 0;
            }
        }
        /// <summary>
        ///  Intersects mouse ray with marker bounds.
        /// </summary>
        /// <returns><c>true</c>if mouse ray intersects with marker <c>false</c> otherwise</returns>
        internal bool IntersectRay()
        {
            Ray   mouseRay = InGameUtil.Instance.CachedMainCamera.ScreenPointToRay(Input.mousePosition);
            float hitH     = TrafficManagerTool.GetAccurateHitHeight();

            Bounds bounds = new Bounds(Vector3.zero, Vector3.one * Radius)
            {
                center = Position
            };

            return(bounds.IntersectRay(mouseRay));
        }
Ejemplo n.º 22
0
        private bool RenderManualPedestrianLightSwitch(float zoom,
                                                       int segmentId,
                                                       Vector3 screenPos,
                                                       float lightWidth,
                                                       ICustomSegmentLights segmentLights,
                                                       bool hoveredSegment)
        {
            if (segmentLights.PedestrianLightState == null)
            {
                return(false);
            }

            Color guiColor = GUI.color;
            float manualPedestrianWidth  = 36f * zoom;
            float manualPedestrianHeight = 35f * zoom;

            guiColor.a = TrafficManagerTool.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
                    ? TrafficLightTextures.PedestrianModeManual
                    : TrafficLightTextures.PedestrianModeAutomatic);

            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);
        }
Ejemplo n.º 23
0
        public override void ShowGUIOverlay(bool viewOnly)
        {
            if (viewOnly && !Options.prioritySignsOverlay)
            {
                return;
            }

            if (TrafficManagerTool.GetToolMode() == ToolMode.JunctionRestrictions)
            {
                return;
            }

            ShowGUI(viewOnly);
        }
Ejemplo n.º 24
0
        /// <summary>
        ///  Intersects mouse ray with lane bounds.
        /// </summary>
        /// <param name="ray"></param>
        /// <param name="hitH">vertical hit position of the raycast</param>
        /// <param name="hitH">vertical raycast hit position.</param>
        internal bool IntersectRay()
        {
            Ray   mouseRay = InGameUtil.Instance.CachedMainCamera.ScreenPointToRay(Input.mousePosition);
            float hitH     = TrafficManagerTool.GetAccurateHitHeight();

            CalculateBounds(hitH);
            foreach (Bounds bounds in bounds)
            {
                if (bounds.IntersectRay(mouseRay))
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 25
0
        /// <summary>
        ///  Intersects mouse ray with lane bounds.
        /// </summary>
        /// <param name="ray"></param>
        /// <param name="hitH">vertical hit position of the raycast</param>
        /// <param name="hitH">vertical raycast hit position.</param>
        internal bool IntersectRay()
        {
            Camera currentCamera = Camera.main;
            Ray    mouseRay      = currentCamera.ScreenPointToRay(Input.mousePosition);
            float  hitH          = TrafficManagerTool.GetAccurateHitHeight();

            CalculateBounds(hitH);
            foreach (Bounds bounds in bounds)
            {
                if (bounds.IntersectRay(mouseRay))
                {
                    return(true);
                }
            }

            return(false);
        }
        private void ShowSigns(bool viewOnly)
        {
            if (viewOnly && !Options.speedLimitsOverlay)
            {
                return;
            }

            Array16 <NetSegment> segments = Singleton <NetManager> .instance.m_segments;
            bool handleHovered            = false;

            for (int i = 1; i < segments.m_size; ++i)
            {
                if (segments.m_buffer[i].m_flags == NetSegment.Flags.None)                 // segment is unused
                {
                    continue;
                }
#if !DEBUG
                if ((segments.m_buffer[i].m_flags & NetSegment.Flags.Untouchable) != NetSegment.Flags.None)
                {
                    continue;
                }
#endif
                var segmentInfo = segments.m_buffer[i].Info;

                Vector3 centerPos = segments.m_buffer[i].m_bounds.center;
                var     screenPos = Camera.main.WorldToScreenPoint(centerPos);
                screenPos.y = Screen.height - screenPos.y;

                if (screenPos.z < 0)
                {
                    continue;
                }

                // draw speed limits
                if (TrafficManagerTool.GetToolMode() != ToolMode.VehicleRestrictions || i != SelectedSegmentId)                   // no speed limit overlay on selected segment when in vehicle restrictions mode
                {
                    if (drawSpeedLimitHandles((ushort)i, viewOnly))
                    {
                        handleHovered = true;
                    }
                }
            }
            overlayHandleHovered = handleHovered;
        }
        private void DrawSign(bool viewOnly,
                              bool small,
                              ref Vector3 camPos,
                              ref Vector3 xu,
                              ref Vector3 yu,
                              float f,
                              ref Vector3 zero,
                              int x,
                              int y,
                              Color guiColor,
                              Texture2D signTexture,
                              out bool hoveredHandle)
        {
            Vector3 signCenter = zero + (f * x * xu) + (f * y * yu); // in game coordinates

            Vector3 signScreenPos;
            bool    visible = MainTool.WorldToScreenPoint(signCenter, out signScreenPos);

            if (!visible)
            {
                hoveredHandle = false;
                return;
            }

            Vector3 diff = signCenter - camPos;

            float zoom = 1.0f / diff.magnitude * 100f * MainTool.GetBaseZoom();
            float size = (small ? 0.75f : 1f) * (viewOnly ? 0.8f : 1f) *
                         junctionRestrictionsSignSize * zoom;

            var boundingBox = new Rect(
                signScreenPos.x - size / 2,
                signScreenPos.y - size / 2,
                size,
                size);

            hoveredHandle = !viewOnly && TrafficManagerTool.IsMouseOver(boundingBox);
            guiColor.a    = TrafficManagerTool.GetHandleAlpha(hoveredHandle);

            GUI.color = guiColor;
            GUI.DrawTexture(boundingBox, signTexture);
        }
Ejemplo n.º 28
0
        public override void RenderOverlay(RenderManager.CameraInfo cameraInfo)
        {
            // Log._Debug($"Restrictions overlay {_cursorInSecondaryPanel} {HoveredNodeId} {SelectedNodeId} {HoveredSegmentId} {SelectedSegmentId}");
            if (SelectedSegmentId != 0)
            {
                Color color = MainTool.GetToolColor(true, false);
                // continues lane highlight requires lane alphaBlend == false.
                // for such lane highlight to be on the top of segment highlight,
                // the alphaBlend of segment highlight needs to be true.
                TrafficManagerTool.DrawSegmentOverlay(cameraInfo, SelectedSegmentId, color, true);

                if (overlayHandleHovered)
                {
                    if (RoadMode)
                    {
                        RenderRoadLane(cameraInfo);
                    }
                    else
                    {
                        RenderLaneOverlay(cameraInfo, renderData_.laneId);
                    }
                }
            }

            if (cursorInSecondaryPanel)
            {
                return;
            }

            if (HoveredSegmentId != 0 && HoveredSegmentId != SelectedSegmentId &&
                !overlayHandleHovered)
            {
                NetTool.RenderOverlay(
                    cameraInfo,
                    ref Singleton <NetManager> .instance.m_segments.m_buffer[HoveredSegmentId],
                    MainTool.GetToolColor(false, false),
                    MainTool.GetToolColor(false, false));
            }
        }
        private void _guiSpeedLimitsWindow(int num)
        {
            GUILayout.BeginHorizontal();

            Color oldColor = GUI.color;

            for (int i = 0; i < SpeedLimitManager.Instance.AvailableSpeedLimits.Count; ++i)
            {
                if (curSpeedLimitIndex != i)
                {
                    GUI.color = Color.gray;
                }
                float signSize = TrafficManagerTool.AdaptWidth(guiSpeedSignSize);
                if (GUILayout.Button(TextureResources.SpeedLimitTextures[SpeedLimitManager.Instance.AvailableSpeedLimits[i]], GUILayout.Width(signSize), GUILayout.Height(signSize)))
                {
                    curSpeedLimitIndex = i;
                }
                GUI.color = oldColor;

                if (i == 6)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }
            }

            GUILayout.EndHorizontal();

            if (GUILayout.Button(Translation.GetString("Default_speed_limits")))
            {
                TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_Defaults");
                defaultsWindowVisible = true;
            }

            showLimitsPerLane = GUILayout.Toggle(showLimitsPerLane, Translation.GetString("Show_lane-wise_speed_limits"));

            DragWindow(ref windowRect);
        }
Ejemplo n.º 30
0
        // public override void OnAfterSimulationFrame() {
        //        base.OnAfterSimulationFrame();
        //
        //        routeMan.SimulationStep();
        //
        //        ++ticksSinceLastMinuteUpdate;
        //        if (ticksSinceLastMinuteUpdate > 60 * 60) {
        //            ticksSinceLastMinuteUpdate = 0;
        //            GlobalConfig.Instance.SimulationStep();
        // #if DEBUG
        //            DebugMenuPanel.PrintTransportStats();
        // #endif
        //        }
        // }

        public override void OnUpdate(float realTimeDelta, float simulationTimeDelta)
        {
            base.OnUpdate(realTimeDelta, simulationTimeDelta);

            using (var bm = Benchmark.MaybeCreateBenchmark()) {
                if (ToolsModifierControl.toolController == null || BaseUI == null)
                {
                    return;
                }

                TrafficManagerTool tmTool = UIBase.GetTrafficManagerTool(false);
                if (tmTool != null && ToolsModifierControl.toolController.CurrentTool != tmTool &&
                    BaseUI.IsVisible())
                {
                    BaseUI.Close();
                }

                if (Input.GetKeyDown(KeyCode.Escape))
                {
                    BaseUI.Close();
                }
            } // end benchmark
        }