Пример #1
0
    public string Format(float value, bool units)
    {
        GameUtil.MetricMassFormat massFormat = (desiredState != Element.State.Gas) ? GameUtil.MetricMassFormat.Kilogram : GameUtil.MetricMassFormat.Gram;
        bool includeSuffix = units;

        return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.None, massFormat, includeSuffix, "{0:0.#}"));
    }
    public string Format(float value, bool units)
    {
        GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Kilogram;
        bool includeSuffix = units;

        return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.None, massFormat, includeSuffix, "{0:0.#}"));
    }
Пример #3
0
            /// <summary>
            /// Applied before GetFormattedMass runs.
            /// </summary>
            internal static bool Prefix(float mass, TimeSlice timeSlice, string floatFormat,
                                        GameUtil.MetricMassFormat massFormat, bool includeSuffix,
                                        ref string __result)
            {
                var text = CACHED_BUILDER;

                text.Clear();
                GetFormattedMass(text, mass, timeSlice, massFormat, includeSuffix,
                                 floatFormat);
                __result = text.ToString();
                return(false);
            }
        public string Format(float value, bool units)
        {
            if (value < 1)
            {
                GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Gram;
                return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.None, massFormat, units, "{0:0.#}"));
            }
            else

            {
                GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Kilogram;
                return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.None, massFormat, units, "{0:0.00}"));
            }
        }
Пример #5
0
        public string Format(float value, bool units)
        {
            if (!units) // Threshold Input
            {
                return(string.Format("{0:0}", value));
            }

            if (value < 1)
            {
                GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Gram;
                return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.PerSecond, massFormat, units, "{0:0.#}"));
            }
            else

            {
                GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Kilogram;
                return(GameUtil.GetFormattedMass(value, GameUtil.TimeSlice.PerSecond, massFormat, units, "{0:0.00}"));
            }
        }
Пример #6
0
 public string Format(float value, bool units)
 {
     GameUtil.MetricMassFormat massFormat = GameUtil.MetricMassFormat.Gram;
     return(GameUtil.GetFormattedMass(value / 1000, GameUtil.TimeSlice.None, massFormat, units, "{0:0.#}"));
 }
Пример #7
0
        /// <summary>
        /// Formats the mass into a string buffer to save on allocations.
        /// </summary>
        /// <param name="text">The location where the mass will be stored.</param>
        /// <param name="mass">The mass in kilograms.</param>
        /// <param name="timeSlice">The time unit, if any.</param>
        /// <param name="massFormat">The mass units to use.</param>
        /// <param name="displaySuffix">Whether to display the units.</param>
        /// <param name="format">The string format to use, or null for the ONI default
        /// (1 decimal place soft).</param>
        internal static void GetFormattedMass(StringBuilder text, float mass,
                                              TimeSlice timeSlice = TimeSlice.None, MetricMassFormat massFormat       =
                                              MetricMassFormat.UseThreshold, bool displaySuffix = true, string format = null)
        {
            if (float.IsInfinity(mass) || float.IsNaN(mass) || mass == float.MaxValue)
            {
                // Handle inf and NaN
                text.Append(STRINGS.UI.CALCULATING);
            }
            else
            {
                // Divide by cycle length if /cycle
                LocString suffix;
                float     absMass = Mathf.Abs(mass);
                var       legend  = MASS_LEGEND;
                mass = GameUtil.ApplyTimeSlice(mass, timeSlice);
                if (GameUtil.massUnit == GameUtil.MassUnit.Kilograms)
                {
                    switch (massFormat)
                    {
                    case MetricMassFormat.UseThreshold:
                        if (absMass > 0.0f)
                        {
                            if (absMass < 5E-06f)
                            {
                                // ug
                                suffix = legend[4];
                                mass   = Mathf.Floor(mass * 1.0E+09f);
                            }
                            else if (absMass < 0.005f)
                            {
                                mass *= 1000000.0f;
                                // mg
                                suffix = legend[3];
                            }
                            else if (absMass < 5.0f)
                            {
                                mass *= 1000.0f;
                                // g
                                suffix = legend[2];
                            }
                            else if (absMass < 5000.0f)
                            {
                                // kg
                                suffix = legend[1];
                            }
                            else
                            {
                                mass /= 1000.0f;
                                // t
                                suffix = legend[0];
                            }
                        }
                        else
                        {
                            // kg
                            suffix = legend[1];
                        }
                        break;

                    case MetricMassFormat.Gram:
                        mass *= 1000f;
                        // g
                        suffix = legend[2];
                        break;

                    case MetricMassFormat.Tonne:
                        mass /= 1000f;
                        // t
                        suffix = legend[0];
                        break;

                    case MetricMassFormat.Kilogram:
                    default:
                        // kg
                        suffix = legend[1];
                        break;
                    }
                }
                else
                {
                    mass /= 2.2f;
                    if (massFormat == MetricMassFormat.UseThreshold)
                    {
                        if (absMass < 5.0f && absMass > 0.001f)
                        {
                            mass  *= 256.0f;
                            suffix = SUFFIXES.MASS.DRACHMA;
                        }
                        else
                        {
                            mass  *= 7000.0f;
                            suffix = SUFFIXES.MASS.GRAIN;
                        }
                    }
                    else
                    {
                        suffix = SUFFIXES.MASS.POUND;
                    }
                }
                // Hardcodes for the most common cases in ONI
                if (format == null || format == "{0:0.#}")
                {
                    mass.ToRyuSoftString(text, 1);
                }
                else if (format == "{0:0.##}")
                {
                    mass.ToRyuSoftString(text, 2);
                }
                else if (format == "{0:0.###}")
                {
                    mass.ToRyuSoftString(text, 3);
                }
                else
                {
                    text.AppendFormat(format, mass);
                }
                if (displaySuffix)
                {
                    text.Append(suffix).AppendTimeSlice(timeSlice);
                }
            }
        }