Exemple #1
0
        /// <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, float speedLimit)
        {
            // The button is wrapped in vertical sub-layout and a label for MPH/KMPH is added
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            var signSize = TrafficManagerTool.AdaptWidth(GuiSpeedSignSize);

            if (GUILayout.Button(
                    TextureResources.GetSpeedLimitTexture(speedLimit),
                    GUILayout.Width(signSize),
                    GUILayout.Height(signSize * SpeedLimit.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 ? SpeedLimit.ToKmphPreciseString(speedLimit)
                                : SpeedLimit.ToMphPreciseString(speedLimit));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (StopDistance != 0D)
            {
                hash ^= StopDistance.GetHashCode();
            }
            if (SpeedLimit != 0D)
            {
                hash ^= SpeedLimit.GetHashCode();
            }
            if (MaxValidStopDistance != 0D)
            {
                hash ^= MaxValidStopDistance.GetHashCode();
            }
            if (MinBoundaryT != 0D)
            {
                hash ^= MinBoundaryT.GetHashCode();
            }
            if (IgnoreMaxStMinT != 0D)
            {
                hash ^= IgnoreMaxStMinT.GetHashCode();
            }
            if (IgnoreMinStMinS != 0D)
            {
                hash ^= IgnoreMinStMinS.GetHashCode();
            }
            return(hash);
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var N         = int.Parse(Console.ReadLine());
            var T         = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var V         = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            var totalTime = T.Sum() * 2;

            var limits = new SpeedLimit[N + 2];

            limits[0] = new SpeedLimit(0, 0, 0);
            for (int i = 1; i < N + 1; i++)
            {
                limits[i] = new SpeedLimit(limits[i - 1].End, limits[i - 1].End + T[i - 1] * 2, V[i - 1]);
            }
            limits[N + 1] = new SpeedLimit(totalTime, totalTime, 0);

            var speed = new double[totalTime + 1];

            for (int t = 1; t <= totalTime; t++)
            {
                speed[t] = double.PositiveInfinity;
                foreach (SpeedLimit l in limits)
                {
                    if (l.Start > t)
                    {
                        speed[t] = Math.Min(speed[t], l.Limit + (l.Start - t) * 0.5);
                    }
                    else if (l.End < t)
                    {
                        speed[t] = Math.Min(speed[t], l.Limit + (t - l.End) * 0.5);
                    }
                    else
                    {
                        speed[t] = Math.Min(speed[t], l.Limit);
                    }
                }
            }

            double distance = 0;

            for (int i = 1; i < totalTime + 1; i++)
            {
                if (speed[i] > speed[i - 1])
                {
                    distance += speed[i - 1] * 0.5 + 0.125;
                }
                else if (speed[i] < speed[i - 1])
                {
                    distance += speed[i] * 0.5 + 0.125;
                }
                else
                {
                    distance += speed[i] * 0.5;
                }
            }
            Console.WriteLine(distance);
        }
        public override int GetHashCode()
        {
            int hash = 1;

            if (SpeedLimit != 0F)
            {
                hash ^= SpeedLimit.GetHashCode();
            }
            hash ^= dim_.GetHashCode();
            return(hash);
        }
Exemple #5
0
        public IEnumerable <IniValueObject> ExportParameters()
        {
            List <IniValueObject> exportedObjects = new List <IniValueObject>();

            if (Enabled == false)
            {
                exportedObjects.Add(new IniValueObject(AcceptsConfigs, "Disable", "1"));
            }
            else
            {
                exportedObjects.Add(new IniValueObject(AcceptsConfigs, "Limit", SpeedLimit.ToString()));
                exportedObjects.Add(new IniValueObject(AcceptsConfigs, "Slope", SpeedSlope.ToString()));
            }
            return(exportedObjects);
        }
Exemple #6
0
        /// <summary>
        /// Given the float speed, style and MPH option return a texture to render.
        /// </summary>
        /// <param name="speedLimit">float speed</param>
        /// <param name="mphStyle">Signs theme</param>
        /// <param name="unit">Mph or km/h</param>
        /// <returns></returns>
        public static Texture2D GetSpeedLimitTexture(float speedLimit, MphSignStyle mphStyle, SpeedUnit unit)
        {
            // Select the source for the textures based on unit and the theme
            bool mph = unit == SpeedUnit.Mph;
            IDictionary <int, Texture2D> textures = SpeedLimitTexturesKmph;

            if (mph)
            {
                switch (mphStyle)
                {
                case MphSignStyle.SquareUS:
                    textures = SpeedLimitTexturesMphUS;
                    break;

                case MphSignStyle.RoundUK:
                    textures = SpeedLimitTexturesMphUK;
                    break;

                case MphSignStyle.RoundGerman:
                    // Do nothing, this is the default above
                    break;
                }
            }

            // Round to nearest 5 MPH or nearest 10 km/h
            ushort index = mph ? SpeedLimit.ToMphRounded(speedLimit) : SpeedLimit.ToKmphRounded(speedLimit);

            // Trim the index since 140 km/h / 90 MPH is the max sign we have
            ushort upper = mph ? SpeedLimit.UPPER_MPH : SpeedLimit.UPPER_KMPH;

            // Show unlimited if the speed cannot be represented by the available sign textures
            if (index == 0 || index > upper)
            {
                // Log._Debug($"Trimming speed={speedLimit} index={index} to {upper}");
                return(textures[0]);
            }

            // Trim from below to not go below index 5 (5 kmph or 5 mph)
            ushort trimIndex = Math.Max((ushort)5, index);

            return(textures[trimIndex]);
        }
    void Update()
    {
        CarUserControl carUserController = Car.GetComponent <CarUserControl>();
        CarController  carController     = Car.GetComponent <CarController> ();
        SpeedLimit     speedLimit        = GetComponent <SpeedLimit> ();

        if (aboveSpeedPumpSpeedLimit == true)
        {
            ObjectivesTickesNumbers [0].SetActive(true);
        }
        if (stopped() == true)
        {
            ObjectivesTickesNumbers [1].SetActive(true);
        }

        if (aboveSpeedPumpSpeedLimit == true && stopped() == true)
        {
            ObjectivesScreen.SetActive(false);
            NextLevelScreen.SetActive(true);
            carUserController.enabled = false;
            carController.enabled     = false;
        }
    }
 /// <summary>
 /// Converts a possibly zero (no limit) custom speed limit to a game speed limit.
 /// </summary>
 /// <param name="customSpeedLimit">Custom speed limit which can be zero</param>
 /// <returns>Speed limit in game speed units</returns>
 public float ToGameSpeedLimit(float customSpeedLimit)
 {
     return(SpeedLimit.IsZero(customSpeedLimit)
                ? MAX_SPEED
                : customSpeedLimit);
 }
        // Creates Mdf from an input FileStream
        public IMdf createMdf(FileStream fileStream)
        {
            // File in Read Only mode, convert to stream
            StreamReader r = new StreamReader(fileStream, Encoding.UTF8);

            // Create new queue for input buffer
            Queue q = new Queue();
            string word = "";

            // Create the Mdf
            IMdf mdf = new IMdf();
            mdf.SpeedLimits = new List<SpeedLimit>();
            mdf.CheckpointOrder = new List<string>();

            // Loop until reach end of file marker
            while ((word.Length < 8) || (word.Substring(0, 8) != "end_file"))
            {
                // get next word
                word = parseWord(r, q);

                if (word == "MDF_name")
                {
                    word = parseWord(r, q);
                    mdf.Name = word;
                }
                else if (word == "RNDF")
                {
                    word = parseWord(r, q);
                    mdf.RndfName = word;
                }
                else if (word == "format_version")
                {
                    word = parseWord(r, q);
                    mdf.Version = word;
                }
                else if (word == "creation_date")
                {
                    word = parseWord(r, q);
                    mdf.CreationDate = word;
                }
                else if (word == "checkpoints")
                {
                    // get number of checkpoints
                    word = parseWord(r, q);
                    word = parseWord(r, q);
                    mdf.NumberCheckpoints = word;

                    // create checkpoint list
                    word = parseWord(r, q);

                    // loop until end of checkpoints
                    while (word != "end_checkpoints")
                    {
                        // add checkpoint
                        mdf.CheckpointOrder.Add(word);

                        // get next word
                        word = parseWord(r, q);
                    }
                }
                else if (word == "speed_limits")
                {
                    // set number of speed limits
                    word = parseWord(r, q);
                    word = parseWord(r, q);
                    mdf.NumberSpeedLimits = word;

                    // get next word
                    word = parseWord(r, q);

                    // loop until end of speedlimits
                    while (word != "end_speed_limits")
                    {
                        // create new speed limit
                        SpeedLimit sl = new SpeedLimit();

                        // id
                        sl.SegmentID = word;

                        // min speed
                        word = parseWord(r, q);
                        sl.MinimumVelocity = Double.Parse(word);

                        // max speed
                        word = parseWord(r, q);
                        sl.MaximumVelocity = Double.Parse(word);

                        // add speed limit to list of speed limits
                        mdf.SpeedLimits.Add(sl);

                        // get next word
                        word = parseWord(r, q);
                    }
                }
                else if (word == "end_file")
                {
                    Console.WriteLine("Mdf Parse :: Successful");
                }
                else
                {
                    Console.WriteLine("Unknown identifier: " + word);
                }
            }
            return mdf;
        }
 public static async Task <SpeedLimitResponse> GetAsync(this SpeedLimit request)
 => await request.GetAsync <SpeedLimitResponse>(request.ToString());
Exemple #11
0
        private bool drawSpeedLimitHandles(ushort segmentId, ref NetSegment segment, bool viewOnly, ref Vector3 camPos)
        {
            if (viewOnly && !Options.speedLimitsOverlay)
            {
                return(false);
            }

            var center     = segment.m_bounds.center;
            var netManager = Singleton <NetManager> .instance;

            var hovered         = false;
            var speedLimitToSet = viewOnly ? -1f : currentPaletteSpeedLimit;

            bool showPerLane = showLimitsPerLane;

            if (!viewOnly)
            {
                showPerLane = showLimitsPerLane ^ (Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl));
            }

            // US signs are rectangular, all other are round
            var speedLimitSignVerticalScale = SpeedLimit.GetVerticalTextureScale();

            if (showPerLane)
            {
                // show individual speed limit handle per lane
                int numDirections;
                var numLanes = TrafficManagerTool.GetSegmentNumVehicleLanes(segmentId, null, out numDirections, SpeedLimitManager.VEHICLE_TYPES);

                var segmentInfo = segment.Info;
                var yu          = (segment.m_endDirection - segment.m_startDirection).normalized;
                var xu          = Vector3.Cross(yu, new Vector3(0, 1f, 0)).normalized;

                /*if ((segment.m_flags & NetSegment.Flags.Invert) == NetSegment.Flags.None) {
                 *      xu = -xu;
                 * }*/
                var f    = viewOnly ? 4f : 7f; // reserved sign size in game coordinates
                var zero = center - 0.5f * (float)(numLanes - 1 + numDirections - 1) * f * xu;

                uint x           = 0;
                var  guiColor    = GUI.color;
                var  sortedLanes = Constants.ServiceFactory.NetService.GetSortedLanes(
                    segmentId, ref segment, null, SpeedLimitManager.LANE_TYPES,
                    SpeedLimitManager.VEHICLE_TYPES);
                var onlyMonorailLanes = sortedLanes.Count > 0;
                if (!viewOnly)
                {
                    foreach (LanePos laneData in sortedLanes)
                    {
                        var laneIndex = laneData.laneIndex;
                        var laneInfo  = segmentInfo.m_lanes[laneIndex];

                        if ((laneInfo.m_vehicleType & VehicleInfo.VehicleType.Monorail) == VehicleInfo.VehicleType.None)
                        {
                            onlyMonorailLanes = false;
                            break;
                        }
                    }
                }

                var directions      = new HashSet <NetInfo.Direction>();
                var 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);
                    }

                    var laneSpeedLimit = SpeedLimitManager.Instance.GetCustomSpeedLimit(laneId);
                    var hoveredHandle  = MainTool.DrawGenericOverlayGridTexture(
                        TextureResources.GetSpeedLimitTexture(laneSpeedLimit),
                        camPos, zero, f, f, xu, yu, x, 0,
                        speedLimitSignSize, speedLimitSignSize * speedLimitSignVerticalScale,
                        !viewOnly);

                    if (!viewOnly &&
                        !onlyMonorailLanes &&
                        (laneInfo.m_vehicleType & VehicleInfo.VehicleType.Monorail) != VehicleInfo.VehicleType.None)
                    {
                        MainTool.DrawStaticSquareOverlayGridTexture(
                            TextureResources.VehicleInfoSignTextures[
                                LegacyExtVehicleType.ToNew(ExtVehicleType.PassengerTrain)
                            ],
                            camPos, zero, f, xu, yu, x, 1, speedLimitSignSize);
                    }
                    if (hoveredHandle)
                    {
                        hovered = true;
                    }

                    if (hoveredHandle && Input.GetMouseButton(0) && !IsCursorInPanel())
                    {
                        SpeedLimitManager.Instance.SetSpeedLimit(segmentId, laneIndex, laneInfo, laneId, speedLimitToSet);

                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            SegmentLaneTraverser.Traverse(segmentId, SegmentTraverser.TraverseDirection.AnyDirection, SegmentTraverser.TraverseSide.AnySide, SegmentLaneTraverser.LaneStopCriterion.LaneCount, SegmentTraverser.SegmentStopCriterion.Junction, SpeedLimitManager.LANE_TYPES, SpeedLimitManager.VEHICLE_TYPES, delegate(SegmentLaneVisitData data) {
                                if (data.segVisitData.initial)
                                {
                                    return(true);
                                }

                                if (sortedLaneIndex != data.sortedLaneIndex)
                                {
                                    return(true);
                                }

                                Constants.ServiceFactory.NetService.ProcessSegment(data.segVisitData.curSeg.segmentId, delegate(ushort curSegmentId, ref NetSegment curSegment) {
                                    NetInfo.Lane curLaneInfo = curSegment.Info.m_lanes[data.curLanePos.laneIndex];
                                    SpeedLimitManager.Instance.SetSpeedLimit(curSegmentId, data.curLanePos.laneIndex, curLaneInfo, data.curLanePos.laneId, speedLimitToSet);
                                    return(true);
                                });

                                return(true);
                            });
                        }
                    }

                    ++x;
                }
            }
            else
            {
                // draw speedlimits over mean middle points of lane beziers
                Dictionary <NetInfo.Direction, Vector3> segCenter;
                if (!segmentCenterByDir.TryGetValue(segmentId, out segCenter))
                {
                    segCenter = new Dictionary <NetInfo.Direction, Vector3>();
                    segmentCenterByDir.Add(segmentId, segCenter);
                    TrafficManagerTool.CalculateSegmentCenterByDir(segmentId, segCenter);
                }

                foreach (KeyValuePair <NetInfo.Direction, Vector3> e in segCenter)
                {
                    Vector3 screenPos;
                    var     visible = MainTool.WorldToScreenPoint(e.Value, out screenPos);

                    if (!visible)
                    {
                        continue;
                    }

                    var zoom        = 1.0f / (e.Value - camPos).magnitude * 100f * MainTool.GetBaseZoom();
                    var size        = (viewOnly ? 0.8f : 1f) * speedLimitSignSize * zoom;
                    var guiColor    = GUI.color;
                    var boundingBox = new Rect(screenPos.x - (size / 2),
                                               screenPos.y - (size / 2),
                                               size,
                                               size * speedLimitSignVerticalScale);
                    var hoveredHandle = !viewOnly && TrafficManagerTool.IsMouseOver(boundingBox);

                    guiColor.a = MainTool.GetHandleAlpha(hoveredHandle);
                    if (hoveredHandle)
                    {
                        // mouse hovering over sign
                        hovered = true;
                    }

                    // Draw something right here, the road sign texture
                    GUI.color = guiColor;
                    var displayLimit = SpeedLimitManager.Instance.GetCustomSpeedLimit(segmentId, e.Key);
                    var tex          = TextureResources.GetSpeedLimitTexture(displayLimit);
                    GUI.DrawTexture(boundingBox, tex);

                    if (hoveredHandle && Input.GetMouseButton(0) && !IsCursorInPanel())
                    {
                        // change the speed limit to the selected one
                        //Log._Debug($"Setting speed limit of segment {segmentId}, dir {e.Key.ToString()} to {speedLimitToSet}");
                        SpeedLimitManager.Instance.SetSpeedLimit(segmentId, e.Key, currentPaletteSpeedLimit);

                        if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                        {
                            NetInfo.Direction normDir = e.Key;
                            if ((netManager.m_segments.m_buffer[segmentId].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None)
                            {
                                normDir = NetInfo.InvertDirection(normDir);
                            }

                            SegmentLaneTraverser.Traverse(segmentId, SegmentTraverser.TraverseDirection.AnyDirection, SegmentTraverser.TraverseSide.AnySide, SegmentLaneTraverser.LaneStopCriterion.LaneCount, SegmentTraverser.SegmentStopCriterion.Junction, SpeedLimitManager.LANE_TYPES, SpeedLimitManager.VEHICLE_TYPES, delegate(SegmentLaneVisitData data) {
                                if (data.segVisitData.initial)
                                {
                                    return(true);
                                }
                                bool reverse = data.segVisitData.viaStartNode == data.segVisitData.viaInitialStartNode;

                                ushort otherSegmentId    = data.segVisitData.curSeg.segmentId;
                                NetInfo otherSegmentInfo = netManager.m_segments.m_buffer[otherSegmentId].Info;
                                uint laneId           = data.curLanePos.laneId;
                                byte laneIndex        = data.curLanePos.laneIndex;
                                NetInfo.Lane laneInfo = otherSegmentInfo.m_lanes[laneIndex];

                                NetInfo.Direction otherNormDir = laneInfo.m_finalDirection;
                                if ((netManager.m_segments.m_buffer[otherSegmentId].m_flags & NetSegment.Flags.Invert) != NetSegment.Flags.None ^
                                    reverse)
                                {
                                    otherNormDir = NetInfo.InvertDirection(otherNormDir);
                                }

                                if (otherNormDir == normDir)
                                {
                                    SpeedLimitManager.Instance.SetSpeedLimit(otherSegmentId, laneInfo.m_finalDirection, speedLimitToSet);
                                }

                                return(true);
                            });
                        }
                    }

                    guiColor.a = 1f;
                    GUI.color  = guiColor;
                }
            }
            return(hovered);
        }
Exemple #12
0
        /// <summary>
        /// The window for selecting and applying a speed limit
        /// </summary>
        /// <param name="num"></param>
        private void _guiSpeedLimitsWindow(int num)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            var oldColor       = GUI.color;
            var allSpeedLimits = SpeedLimit.EnumerateSpeedLimits(SpeedUnit.CurrentlyConfigured);

            allSpeedLimits.Add(0); // add last item: no limit

            var showMph     = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;
            var column      = 0u; // break palette to a new line at breakColumn
            var breakColumn = showMph ? SpeedLimit.BREAK_PALETTE_COLUMN_MPH
                                  : SpeedLimit.BREAK_PALETTE_COLUMN_KMPH;

            foreach (var speedLimit in allSpeedLimits)
            {
                // Highlight palette item if it is very close to its float speed
                if (SpeedLimit.NearlyEqual(currentPaletteSpeedLimit, speedLimit))
                {
                    GUI.color = Color.gray;
                }

                _guiSpeedLimitsWindow_AddButton(showMph, speedLimit);
                GUI.color = oldColor;

                // TODO: This can be calculated from SpeedLimit MPH or KMPH limit constants
                column++;
                if (column % breakColumn == 0)
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                }
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //---------------------
            // UI buttons row
            //---------------------
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button(Translation.GetString("Default_speed_limits"),
                                 GUILayout.Width(200)))
            {
                TrafficManagerTool.ShowAdvisor(this.GetType().Name + "_Defaults");
                defaultsWindowVisible = true;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            //---------------------
            // Checkboxes row
            //---------------------
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            showLimitsPerLane = GUILayout.Toggle(showLimitsPerLane, Translation.GetString("Show_lane-wise_speed_limits"));
            GUILayout.FlexibleSpace();

            // Display MPH checkbox, if ticked will save global config
            var displayMph = GlobalConfig.Instance.Main.DisplaySpeedLimitsMph;

            displayMph = GUILayout.Toggle(displayMph, Translation.GetString("Display_speed_limits_mph"));
            if (GlobalConfig.Instance.Main.DisplaySpeedLimitsMph != displayMph)
            {
                OptionsGeneralTab.SetDisplayInMph(displayMph);
            }

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

            DragWindow(ref paletteWindowRect);
        }
Exemple #13
0
        /// <summary>
        /// The window for setting the defaullt speeds per road type
        /// </summary>
        /// <param name="num"></param>
        private void _guiDefaultsWindow(int num)
        {
            var mainNetInfos = SpeedLimitManager.Instance.GetCustomizableNetInfos();

            if (mainNetInfos == null || mainNetInfos.Count <= 0)
            {
                Log._Debug($"mainNetInfos={mainNetInfos?.Count}");
                DragWindow(ref defaultsWindowRect);
                return;
            }

            bool updateRoadTex = false;

            if (currentInfoIndex < 0 || currentInfoIndex >= mainNetInfos.Count)
            {
                currentInfoIndex = 0;
                updateRoadTex    = true;
                Log._Debug($"set currentInfoIndex to 0");
            }

            NetInfo info = mainNetInfos[currentInfoIndex];

            if (updateRoadTex)
            {
                UpdateRoadTex(info);
            }

            if (currentSpeedLimit < 0f)
            {
                currentSpeedLimit = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
                Log._Debug($"set currentSpeedLimit to {currentSpeedLimit}");
            }
            //Log._Debug($"currentInfoIndex={currentInfoIndex} currentSpeedLimitIndex={currentSpeedLimitIndex}");

            // Road type label
            GUILayout.BeginVertical();
            GUILayout.Space(10);
            GUILayout.Label(Translation.GetString("Road_type") + ":");
            GUILayout.EndVertical();

            // switch between NetInfos
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("←", GUILayout.Width(50)))
            {
                currentInfoIndex =
                    (currentInfoIndex + mainNetInfos.Count - 1) % mainNetInfos.Count;
                info = mainNetInfos[currentInfoIndex];
                currentSpeedLimit = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
                UpdateRoadTex(info);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            // NetInfo thumbnail
            GUILayout.Box(RoadTexture, GUILayout.Height(GuiSpeedSignSize));
            GUILayout.FlexibleSpace();

            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("→", GUILayout.Width(50)))
            {
                currentInfoIndex  = (currentInfoIndex + 1) % mainNetInfos.Count;
                info              = mainNetInfos[currentInfoIndex];
                currentSpeedLimit = SpeedLimitManager.Instance.GetCustomNetInfoSpeedLimit(info);
                UpdateRoadTex(info);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            var centeredTextStyle = new GUIStyle("label")
            {
                alignment = TextAnchor.MiddleCenter
            };

            // NetInfo name
            GUILayout.Label(info.name, centeredTextStyle);

            // Default speed limit label
            GUILayout.BeginVertical();
            GUILayout.Space(10);
            GUILayout.Label(Translation.GetString("Default_speed_limit") + ":");
            GUILayout.EndVertical();

            // switch between speed limits
            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("←", GUILayout.Width(50)))
            {
                // currentSpeedLimit = (currentSpeedLimitIndex + SpeedLimitManager.Instance.AvailableSpeedLimits.Count - 1) % SpeedLimitManager.Instance.AvailableSpeedLimits.Count;
                currentSpeedLimit = SpeedLimit.GetPrevious(currentSpeedLimit);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();

            // speed limit sign
            GUILayout.Box(TextureResources.GetSpeedLimitTexture(currentSpeedLimit),
                          GUILayout.Width(GuiSpeedSignSize),
                          GUILayout.Height(GuiSpeedSignSize));
            GUILayout.Label(GlobalConfig.Instance.Main.DisplaySpeedLimitsMph
                                ? Translation.GetString("Miles_per_hour")
                                : Translation.GetString("Kilometers_per_hour"));

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.FlexibleSpace();

            GUILayout.BeginVertical();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("→", GUILayout.Width(50)))
            {
                // currentSpeedLimitIndex = (currentSpeedLimitIndex + 1) % SpeedLimitManager.Instance.AvailableSpeedLimits.Count;
                currentSpeedLimit = SpeedLimit.GetNext(currentSpeedLimit);
            }

            GUILayout.FlexibleSpace();
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            // Save & Apply
            GUILayout.BeginVertical();
            GUILayout.Space(10);

            GUILayout.BeginHorizontal();

            // Close button. TODO: Make more visible or obey 'Esc' pressed or something
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("X", GUILayout.Width(80)))
            {
                defaultsWindowVisible = false;
            }

            GUILayout.FlexibleSpace();
            if (GUILayout.Button(Translation.GetString("Save"), GUILayout.Width(70)))
            {
                SpeedLimitManager.Instance.FixCurrentSpeedLimits(info);
                SpeedLimitManager.Instance.SetCustomNetInfoSpeedLimit(info, currentSpeedLimit);
            }

            GUILayout.FlexibleSpace();
            if (GUILayout.Button(
                    Translation.GetString("Save") + " & " + Translation.GetString("Apply"),
                    GUILayout.Width(160)))
            {
                SpeedLimitManager.Instance.SetCustomNetInfoSpeedLimit(info, currentSpeedLimit);
                SpeedLimitManager.Instance.ClearCurrentSpeedLimits(info);
            }

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

            GUILayout.EndVertical();

            DragWindow(ref defaultsWindowRect);
        }
        // Creates Mdf from an input FileStream
        public IMdf createMdf(FileStream fileStream)
        {
            // File in Read Only mode, convert to stream
            StreamReader r = new StreamReader(fileStream, Encoding.UTF8);

            // Create new queue for input buffer
            Queue  q    = new Queue();
            string word = "";



            // Create the Mdf
            IMdf mdf = new IMdf();

            mdf.SpeedLimits     = new List <SpeedLimit>();
            mdf.CheckpointOrder = new List <string>();

            // Loop until reach end of file marker
            while ((word.Length < 8) || (word.Substring(0, 8) != "end_file"))
            {
                // get next word
                word = parseWord(r, q);

                if (word == "MDF_name")
                {
                    word     = parseWord(r, q);
                    mdf.Name = word;
                }
                else if (word == "RNDF")
                {
                    word         = parseWord(r, q);
                    mdf.RndfName = word;
                }
                else if (word == "format_version")
                {
                    word        = parseWord(r, q);
                    mdf.Version = word;
                }
                else if (word == "creation_date")
                {
                    word             = parseWord(r, q);
                    mdf.CreationDate = word;
                }
                else if (word == "checkpoints")
                {
                    // get number of checkpoints
                    word = parseWord(r, q);
                    word = parseWord(r, q);
                    mdf.NumberCheckpoints = word;

                    // create checkpoint list
                    word = parseWord(r, q);

                    // loop until end of checkpoints
                    while (word != "end_checkpoints")
                    {
                        // add checkpoint
                        mdf.CheckpointOrder.Add(word);

                        // get next word
                        word = parseWord(r, q);
                    }
                }
                else if (word == "speed_limits")
                {
                    // set number of speed limits
                    word = parseWord(r, q);
                    word = parseWord(r, q);
                    mdf.NumberSpeedLimits = word;

                    // get next word
                    word = parseWord(r, q);

                    // loop until end of speedlimits
                    while (word != "end_speed_limits")
                    {
                        // create new speed limit
                        SpeedLimit sl = new SpeedLimit();

                        // id
                        sl.SegmentID = word;

                        // min speed
                        word = parseWord(r, q);
                        sl.MinimumVelocity = Double.Parse(word);

                        // max speed
                        word = parseWord(r, q);
                        sl.MaximumVelocity = Double.Parse(word);

                        // add speed limit to list of speed limits
                        mdf.SpeedLimits.Add(sl);

                        // get next word
                        word = parseWord(r, q);
                    }
                }
                else if (word == "end_file")
                {
                    Console.WriteLine("Mdf Parse :: Successful");
                }
                else
                {
                    Console.WriteLine("Unknown identifier: " + word);
                }
            }
            return(mdf);
        }
Exemple #15
0
        internal string ToSwitches()
        {
            List <string> switches = new List <string>();

            if (FilePermissions != null)
            {
                switches.Add(Session.FormatSwitch("permissions", FilePermissions.Octal));
            }
            else
            {
                switches.Add("-nopermissions");
            }

            switches.Add(Session.BooleanSwitch(PreserveTimestamp, "preservetime", "nopreservetime"));

            string transferModeName;

            switch (TransferMode)
            {
            case TransferMode.Binary:
                transferModeName = "binary";
                break;

            case TransferMode.Ascii:
                transferModeName = "ascii";
                break;

            case TransferMode.Automatic:
                transferModeName = "automatic";
                break;

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not supported", TransferMode));
            }
            switches.Add(Session.FormatSwitch("transfer", transferModeName));

            if (!string.IsNullOrEmpty(FileMask))
            {
                switches.Add(Session.FormatSwitch("filemask", FileMask));
            }

            if (ResumeSupport.State != TransferResumeSupportState.Default)
            {
                switches.Add(Session.FormatSwitch("resumesupport", ResumeSupport.ToString()));
            }

            if (SpeedLimit > 0)
            {
                switches.Add(Session.FormatSwitch("speed", SpeedLimit.ToString(CultureInfo.InvariantCulture)));
            }

            switch (OverwriteMode)
            {
            case OverwriteMode.Overwrite:
                // noop
                break;

            case OverwriteMode.Resume:
                switches.Add(Session.FormatSwitch("resume"));
                break;

            case OverwriteMode.Append:
                switches.Add(Session.FormatSwitch("append"));
                break;

            default:
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "{0} is not supported", OverwriteMode));
            }

            return(string.Join(" ", switches.ToArray()));
        }