FormatNumString() public static method

public static FormatNumString ( String inputString ) : string
inputString String
return string
Ejemplo n.º 1
0
        public void draw()
        {
            GUILayout.Label((SteeringBar >= 0 ? "Right: " : "Left: ") + Math.Abs(Mathf.RoundToInt(SteeringBar * 100)) + "%", GUI.skin.textField);
            SteeringBar = GUILayout.HorizontalSlider(SteeringBar, -1, 1);

            reverse = GUILayout.Toggle(reverse, reverse ? "Reverse" : "Forward");

            GUILayout.BeginHorizontal();
            GUILayout.Label("Speed (m/s):", GUI.skin.textField, GUILayout.Width(100));
            SpeedS = GUILayout.TextField(SpeedS, GUILayout.Width(50));
            SpeedS = RTUtils.FormatNumString(SpeedS);
            if (SpeedS == "")
            {
                SpeedS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(SpeedS);
                tmp   += 1;
                SpeedS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(SpeedS);
                tmp   -= 1;
                SpeedS = Mathf.RoundToInt(tmp).ToString();
            }

            Speed  = Mathf.Clamp(Convert.ToSingle(SpeedS), 0, float.MaxValue);
            SpeedS = Speed.ToString();
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();

            GUILayout.Label("Drive (m):", GUI.skin.textField, GUILayout.Width(100));
            DistS = GUILayout.TextField(DistS, GUILayout.Width(50));
            DistS = RTUtils.FormatNumString(DistS);
            if (DistS == "")
            {
                DistS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DistS);
                tmp  += 1;
                DistS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DistS);
                tmp  -= 1;
                DistS = Mathf.RoundToInt(tmp).ToString();
            }

            Distance = Mathf.Clamp(Convert.ToSingle(DistS), 0, float.MaxValue);
            DistS    = Distance.ToString();

            if (GUILayout.Button("Send", GUI.skin.textField))
            {
                RoverState r = new RoverState();
                r.Steer     = false;
                r.Target    = Distance;
                r.Speed     = Speed;
                r.reverse   = reverse;
                r.Steering  = 0;
                lastActTime = r.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? 0 : computer.core.path.ControlDelay);
                states.Enqueue(r);
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();

            GUILayout.Label("Turn (°):", GUI.skin.textField, GUILayout.Width(100));
            DegS = GUILayout.TextField(DegS, GUILayout.Width(50));
            DegS = RTUtils.FormatNumString(DegS);
            if (DegS == "")
            {
                DegS = "0";
            }

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DegS);
                tmp += 1;
                DegS = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(DegS);
                tmp -= 1;
                DegS = Mathf.RoundToInt(tmp).ToString();
            }

            Degrees = Mathf.Clamp(Convert.ToSingle(DegS), 0, 90);
            DegS    = Degrees.ToString();

            if (GUILayout.Button("Send", GUI.skin.textField))
            {
                RoverState r = new RoverState();
                r.Steer     = true;
                r.Target    = Degrees;
                r.Speed     = Speed;
                r.reverse   = reverse;
                r.Steering  = Mathf.RoundToInt(SteeringBar * 100) == 0 ? 0 : -SteeringBar;
                lastActTime = r.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? 0 : computer.core.path.ControlDelay);
                states.Enqueue(r);
            }

            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            GUILayout.Label(sending ? "Sending " + computer.arrows :
                            (computer.core.computer.roverActive ? DriveDescript : "")
                            , GUI.skin.textField);
            GUILayout.Label(sending ? RTUtils.time(lastActTime - Planetarium.GetUniversalTime()) : (computer.core.computer.roverActive ? TargetDescript : "")
                            , GUI.skin.textField, GUILayout.Width(100));
            GUILayout.EndHorizontal();
        }
Ejemplo n.º 2
0
        public void draw()
        {
            GUILayout.Label("Throttle: " + Mathf.RoundToInt(ThrottleBar * 100) + "%", GUI.skin.textField);
            ThrottleBar = GUILayout.HorizontalSlider(ThrottleBar, 0, 1);
            GUILayout.BeginHorizontal();

            if (GUILayout.Button(BT ? "Burn time (s)" : "ΔV (m/s)", GUI.skin.textField, GUILayout.Width(100)))
            {
                BT = !BT;
            }
            BTS = GUILayout.TextField(BTS, GUILayout.Width(50));
            BTS = RTUtils.FormatNumString(BTS, false);
            if (GUILayout.Button("Send", GUI.skin.textField) && (computer.core.localControl || computer.core.InContact))
            {
                ThrottleState tmp = new ThrottleState();
                tmp.Throttle = ThrottleBar;
                if (BTS.EndsWith("."))
                {
                    BTS = BTS.Substring(0, BTS.Length - 1);
                }
                tmp.Target  = Convert.ToSingle(BTS);
                tmp.Bt      = BT;
                lastActTime = tmp.ActTime = Planetarium.GetUniversalTime() + (computer.core.localControl ? (double)burnAt :
                                                                              (computer.core.path.ControlDelay <= (double)burnAt ? (double)burnAt : computer.core.path.ControlDelay)
                                                                              );
                states.Enqueue(tmp);
                BTS     = "";
                burnAts = "";
                burnAt  = 0;
            }
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label(sending ? "Sending " + computer.arrows : (burning && state.Bt ? "Burning" : (BTS == "" ? "" : "in HH:MM:SS")), GUI.skin.textField, GUILayout.Width(100));

            if (BTS == "")
            {
                GUILayout.Label(sending ? RTUtils.time((lastActTime - Planetarium.GetUniversalTime() > 0) ? lastActTime - Planetarium.GetUniversalTime() : 0) :
                                (burning && state.Bt ? RTUtils.time((state.Target - Planetarium.GetUniversalTime() > 0) ? state.Target - Planetarium.GetUniversalTime() : 0) : "")
                                , GUI.skin.textField, GUILayout.Width(100));
            }
            else
            {
                burnAts = GUILayout.TextField(burnAts, GUILayout.Width(100));
                List <String> temp = burnAts.Split(":".ToCharArray()).ToList();
                string        seconds = "", minutes = "", hours = "", days = "";

                while (temp.Count < 4)
                {
                    temp.Insert(0, "");
                }

                seconds = RTUtils.TFormat(temp[3]);
                burnAt  = Convert.ToSingle(seconds == "" ? "0" : seconds);
                burnAts = seconds;

                if (temp[2] != "")
                {
                    minutes = RTUtils.TFormat(temp[2]);
                    burnAt += Convert.ToSingle(minutes == "" ? "0" : minutes) * 60;
                    burnAts = minutes == "" ? burnAts : (minutes + ":" + burnAts);
                }

                if (temp[1] != "")
                {
                    hours   = RTUtils.TFormat(temp[1]);
                    burnAt += Convert.ToSingle(hours == "" ? "0" : hours) * 3600;
                    burnAts = hours == "" ? burnAts : (hours + ":" + burnAts);
                }

                if (temp[0] != "")
                {
                    days    = RTUtils.TFormat(temp[0]);
                    burnAt += Convert.ToSingle(days == "" ? "0" : days) * 86400;
                    burnAts = days == "" ? burnAts : (days + ":" + burnAts);
                }
            }

            GUILayout.EndHorizontal();
        }
Ejemplo n.º 3
0
        public void Draw()
        {
            bool locked = on;

            GUILayout.BeginHorizontal();

            Color savedContentColor = GUI.contentColor;

            if (state.Active)
            {
                if (mode == AttitudeMode.MANEUVERNODE)
                {
                    if (state.Active)
                    {
                        if (FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count > 0)
                        {
                            GUI.contentColor = Color.green;
                        }
                        else
                        {
                            GUI.contentColor = Color.yellow;
                        }
                    }
                }
                else
                if (state.Active)
                {
                    GUI.contentColor = Color.green;
                }
            }
            else
            if (mode == AttitudeMode.MANEUVERNODE && FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0)
            {
                GUI.contentColor = Color.red;
            }

            on = GUILayout.Toggle(on,
                                  (RTGlobals.ColFriend && state.Active ? name + "<" : name)
                                  , GUI.skin.textField, GUILayout.Width(100));
            GUI.contentColor = savedContentColor;

            if (!(computer.core.localControl || computer.core.InContact) || (mode == AttitudeMode.MANEUVERNODE && FlightGlobals.ActiveVessel.patchedConicSolver.maneuverNodes.Count == 0 && !state.Active))
            {
                on = locked;
            }

            GUILayout.Label(sending ? computer.arrows : "", GUI.skin.textField, GUILayout.Width(50));
            if (sending)
            {
                GUILayout.Label(RTUtils.time((lastActTime - Planetarium.GetUniversalTime() > 0) ? lastActTime - Planetarium.GetUniversalTime() : 0), GUI.skin.textField, GUILayout.Width(90));
            }
            else
            {
                burnAts = GUILayout.TextField(burnAts, GUILayout.Width(90));
                List <String> temp = burnAts.Split(":".ToCharArray()).ToList();
                string        seconds = "", minutes = "", hours = "", days = "";

                while (temp.Count < 4)
                {
                    temp.Insert(0, "");
                }

                seconds = RTUtils.TFormat(temp[3]);
                burnAt  = Convert.ToSingle(seconds == "" ? "0" : seconds);
                burnAts = seconds;

                if (temp[2] != "")
                {
                    minutes = RTUtils.TFormat(temp[2]);
                    burnAt += Convert.ToSingle(minutes == "" ? "0" : minutes) * 60;
                    burnAts = minutes == "" ? burnAts : (minutes + ":" + burnAts);
                }

                if (temp[1] != "")
                {
                    hours   = RTUtils.TFormat(temp[1]);
                    burnAt += Convert.ToSingle(hours == "" ? "0" : hours) * 3600;
                    burnAts = hours == "" ? burnAts : (hours + ":" + burnAts);
                }

                if (temp[0] != "")
                {
                    days    = RTUtils.TFormat(temp[0]);
                    burnAt += Convert.ToSingle(days == "" ? "0" : days) * 86400;
                    burnAts = days == "" ? burnAts : (days + ":" + burnAts);
                }
            }
            GUILayout.EndHorizontal();

            if (mode != AttitudeMode.SURFACE || !on)
            {
                return;
            }
            GUILayout.BeginHorizontal();

            GUILayout.Label("Pitch:", GUI.skin.textField, GUILayout.Width(100));
            PITs = GUILayout.TextField(PITs, GUILayout.Width(50));
            PITs = RTUtils.FormatNumString(PITs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(PITs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                PITs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(PITs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                PITs = Mathf.RoundToInt(tmp).ToString();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label("Heading:", GUI.skin.textField, GUILayout.Width(100));
            HDGs = GUILayout.TextField(HDGs, GUILayout.Width(50));
            HDGs = RTUtils.FormatNumString(HDGs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(HDGs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                HDGs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(HDGs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                HDGs = Mathf.RoundToInt(tmp).ToString();
            }

            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();

            GUILayout.Label("Roll:", GUI.skin.textField, GUILayout.Width(100));
            ROLs = GUILayout.TextField(ROLs, GUILayout.Width(50));
            ROLs = RTUtils.FormatNumString(ROLs);

            if (GUILayout.Button("+", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(ROLs);
                tmp += 1;
                if (tmp >= 360.0F)
                {
                    tmp -= 360.0F;
                }
                ROLs = Mathf.RoundToInt(tmp).ToString();
            }
            if (GUILayout.Button("-", GUI.skin.textField, GUILayout.Width(21.0F)))
            {
                float tmp = Convert.ToSingle(ROLs);
                tmp -= 1;
                if (tmp < 0)
                {
                    tmp += 360.0F;
                }
                ROLs = Mathf.RoundToInt(tmp).ToString();
            }
            USEROL = GUILayout.Toggle(USEROL, " ", GUI.skin.toggle, GUILayout.Width(21.0F));

            GUILayout.EndHorizontal();
            if (GUILayout.Button("Update", GUI.skin.textField) && (computer.core.localControl || computer.core.InContact))
            {
                if (PITs.EndsWith("."))
                {
                    PITs = PITs.Substring(0, PITs.Length - 1);
                }

                if (HDGs.EndsWith("."))
                {
                    HDGs = HDGs.Substring(0, HDGs.Length - 1);
                }
                if (ROLs.EndsWith("."))
                {
                    ROLs = ROLs.Substring(0, ROLs.Length - 1);
                }

                PIT    = Convert.ToSingle(PITs);
                HDG    = Convert.ToSingle(HDGs);
                ROL    = Convert.ToSingle(ROLs);
                lastOn = false;
            }
        }