/// <summary> /// Applied before GetFormattedSimple runs. /// </summary> internal static bool Prefix(float num, TimeSlice timeSlice, string formatString, ref string __result) { var text = CACHED_BUILDER; text.Clear(); num = GameUtil.ApplyTimeSlice(num, timeSlice); if (!text.AppendIfInfinite(num)) { if (formatString != null) { AppendSimpleFormat(text, formatString, num); } else if (num == 0.0f) { text.Append('0'); } else { RyuFormat.ToString(text, (double)num, 2, RyuFormatOptions.FixedMode | RyuFormatOptions.SoftPrecision | RyuFormatOptions. ThousandsSeparators); } } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Formats the germ quantity into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the germs will be stored.</param> /// <param name="germs">The number of germs.</param> /// <param name="timeSlice">The time unit, if any.</param> private static void GetFormattedDiseaseAmount(StringBuilder text, int germs, TimeSlice timeSlice = TimeSlice.None) { // /cycle is broken in vanilla, clay please GameUtil.ApplyTimeSlice(germs, timeSlice).ToStandardString(text); text.Append(SUFFIXES.DISEASE.UNITS).AppendTimeSlice(timeSlice); }
/// <summary> /// Applied before GetFormattedUnits runs. /// </summary> internal static bool Prefix(float units, TimeSlice timeSlice, bool displaySuffix, string floatFormatOverride, ref string __result) { var text = CACHED_BUILDER; text.Clear(); units = GameUtil.ApplyTimeSlice(units, timeSlice); if (!text.AppendIfInfinite(units)) { if (!floatFormatOverride.IsNullOrWhiteSpace()) { text.AppendFormat(floatFormatOverride, units); } else { units.ToStandardString(text); } } if (displaySuffix) { text.Append(Mathf.Approximately(units, 1.0f) ? UNIT : UNITS); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedPlantGrowth runs. /// </summary> internal static bool Prefix(float percent, TimeSlice timeSlice, ref string __result) { float absP = Mathf.Abs(percent); int precision; var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(percent)) { percent = GameUtil.ApplyTimeSlice(percent, timeSlice); if (absP < 0.1f) { precision = 2; } else if (absP < 1.0f) { precision = 1; } else { precision = 0; } percent.ToRyuSoftString(text, precision); } __result = text.Append(PCT).Append(' ').Append(SUFFIXES.GROWTH). AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedDiseaseAmount runs. /// </summary> internal static bool Prefix(int units, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); GetFormattedDiseaseAmount(text, units, timeSlice); __result = text.ToString(); return(false); }
/// <summary> /// Applied before GetFormattedRocketRange runs. /// </summary> internal static bool Prefix(float range, TimeSlice timeSlice, bool displaySuffix, ref string __result) { var text = CACHED_BUILDER; text.Clear(); GetFormattedRocketRange(text, range, timeSlice, displaySuffix); __result = text.ToString(); return(false); }
/// <summary> /// Applied before GetFormattedTemperature runs. /// </summary> internal static bool Prefix(float temp, TimeSlice timeSlice, GameUtil.TemperatureInterpretation interpretation, bool displayUnits, bool roundInDestinationFormat, ref string __result) { var text = CACHED_BUILDER; text.Clear(); GetFormattedTemperature(text, temp, timeSlice, interpretation, displayUnits, roundInDestinationFormat); __result = text.ToString(); return(false); }
public override string GetFormattedModifier(AttributeModifier modifier, GameObject parent_instance) { float num = modifier.Value; GameUtil.TimeSlice timeSlice = base.DeltaTimeSlice; if (modifier.IsMultiplier) { num *= 100f; timeSlice = GameUtil.TimeSlice.None; } return(GetFormattedValue(num, timeSlice, parent_instance)); }
/// <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); }
/// <summary> /// Applied before GetFormattedInt runs. /// </summary> internal static bool Prefix(float num, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(num)) { RyuFormat.ToString(text, (double)GameUtil.ApplyTimeSlice(num, timeSlice), 0, RyuFormatOptions.FixedMode | RyuFormatOptions.ThousandsSeparators); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Applied before GetFormattedRads runs. /// </summary> internal static bool Prefix(float rads, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(rads)) { GameUtil.ApplyTimeSlice(rads, timeSlice).ToStandardString(text); } text.Append(SUFFIXES.RADIATION.RADS); __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Appends the time slice unit (like "/s") to the string buffer. Allocates less than /// a string concatenation. /// </summary> /// <param name="buffer">The string builder to append.</param> /// <param name="timeSlice">The time slice unit to use.</param> /// <returns>The string builder.</returns> internal static StringBuilder AppendTimeSlice(this StringBuilder buffer, TimeSlice timeSlice) { switch (timeSlice) { case TimeSlice.PerSecond: buffer.Append(PER_SECOND); break; case TimeSlice.PerCycle: buffer.Append(PER_CYCLE); break; } return(buffer); }
/// <summary> /// Applied before GetFormattedHighEnergyParticles runs. /// </summary> internal static bool Prefix(float units, TimeSlice timeSlice, bool displayUnits, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (!text.AppendIfInfinite(units)) { GameUtil.ApplyTimeSlice(units, timeSlice).ToRyuSoftString(text, 1); } if (displayUnits) { // That is not how particle is spelled text.Append(Mathf.Approximately(units, 1.0f) ? SUFFIXES. HIGHENERGYPARTICLES.PARTRICLE : SUFFIXES. HIGHENERGYPARTICLES.PARTRICLES); } __result = text.AppendTimeSlice(timeSlice).ToString(); return(false); }
/// <summary> /// Formats the rocket range into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the rocket range will be stored.</param> /// <param name="range">The rocket range in tiles.</param> /// <param name="timeSlice">The time unit, if any.</param> /// <param name="displaySuffix">Whether to display the units.</param> internal static void GetFormattedRocketRange(StringBuilder text, float range, TimeSlice timeSlice, bool displaySuffix) { if (timeSlice == TimeSlice.PerCycle) { // Range cannot be over 999 tiles right now ;) range.ToRyuHardString(text, 1); if (displaySuffix) { text.Append(' ').Append(STRINGS.UI.CLUSTERMAP.TILES_PER_CYCLE); } } else { (range / 600.0f).ToRyuHardString(text, 0); if (displaySuffix) { text.Append(' ').Append(STRINGS.UI.CLUSTERMAP.TILES); } } }
/// <summary> /// Applied before GetFormattedJoules runs. /// </summary> internal static bool Prefix(float joules, string floatFormat, TimeSlice timeSlice, ref string __result) { var text = CACHED_BUILDER; text.Clear(); if (timeSlice == TimeSlice.PerSecond) { GetFormattedWattage(text, joules, GameUtil.WattageFormatterUnit. Automatic, true); } else { var legend = JOULE_LEGEND; joules = GameUtil.ApplyTimeSlice(joules, timeSlice); float absJ = Mathf.Abs(joules); if (text.AppendIfInfinite(joules)) { text.Append(legend[0]); } else if (absJ > 1000000.0f) { text.AppendSimpleFormat(floatFormat, joules * 0.000001f); text.Append(legend[2]); } else if (absJ > 1000.0f) { text.AppendSimpleFormat(floatFormat, joules * 0.001f); text.Append(legend[1]); } else { text.AppendSimpleFormat(floatFormat, joules); text.Append(legend[0]); } text.AppendTimeSlice(timeSlice); } __result = text.ToString(); return(false); }
/// <summary> /// Applied before GetFormattedCalories runs. /// </summary> internal static bool Prefix(float calories, TimeSlice timeSlice, bool forceKcal, ref string __result) { string unit; var text = CACHED_BUILDER; text.Clear(); if (Mathf.Abs(calories) >= 1000.0f || forceKcal) { calories *= 0.001f; unit = SUFFIXES.CALORIES.KILOCALORIE; } else { unit = SUFFIXES.CALORIES.CALORIE; } GameUtil.ApplyTimeSlice(calories, timeSlice).ToStandardString(text); text.Append(unit); text.AppendTimeSlice(timeSlice); __result = text.ToString(); return(false); }
/// <summary> /// Formats the temperature into a string buffer to save on allocations. /// </summary> /// <param name="text">The location where the temperature will be stored.</param> /// <param name="temperature">The temperature in K.</param> /// <param name="timeSlice">The time unit, if any.</param> /// <param name="interpretation">Whether the temperature is a delta, or an absolute value.</param> /// <param name="displayUnits">Whether to display the units.</param> /// <param name="roundOff">Whether to round off the temperature to the nearest degree.</param> internal static void GetFormattedTemperature(StringBuilder text, float temperature, TimeSlice timeSlice = TimeSlice.None, GameUtil.TemperatureInterpretation interpretation = GameUtil.TemperatureInterpretation.Absolute, bool displayUnits = true, bool roundOff = false) { if (interpretation == GameUtil.TemperatureInterpretation.Absolute) { temperature = GameUtil.GetConvertedTemperature(temperature, roundOff); } else if (GameUtil.temperatureUnit == GameUtil.TemperatureUnit.Fahrenheit) { temperature *= 1.8f; } temperature = GameUtil.ApplyTimeSlice(temperature, timeSlice); if (!text.AppendIfInfinite(temperature)) { temperature.ToRyuSoftString(text, Mathf.Abs(temperature) < 0.1f ? 4 : 1); } if (displayUnits) { text.Append(GameUtil.GetTemperatureUnitSuffix()); } text.AppendTimeSlice(timeSlice); }
public static void Postfix(float temp, bool displayUnits, ref string __result, GameUtil.TemperatureInterpretation interpretation, GameUtil.TimeSlice timeSlice) { try { if (interpretation != GameUtil.TemperatureInterpretation.Absolute || timeSlice != GameUtil.TimeSlice.None || !displayUnits) { return; } string formatString = "##0.#"; float kelvin = GameUtil.GetTemperatureConvertedToKelvin(temp); var temperatures = new List <string>(); if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Celsius && (TemperatureUnitMultiple.Celsius & State.Unit) != 0) { string celsiusString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Celsius).ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; temperatures.Add(celsiusString); } if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Fahrenheit && (TemperatureUnitMultiple.Fahrenheit & State.Unit) != 0) { string fahrenheitString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Fahrenheit).ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; temperatures.Add(fahrenheitString); } if (GameUtil.temperatureUnit != GameUtil.TemperatureUnit.Kelvin && (TemperatureUnitMultiple.Kelvin & State.Unit) != 0) { string kelvinString = kelvin.ToString(formatString) + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; temperatures.Add(kelvinString); } if (temperatures.Count <= 0) { return; } var builder = new StringBuilder(__result); foreach (var temperature in temperatures) { builder.Append(", "); builder.Append(temperature); } __result = builder.ToString(); } catch (Exception e) { State.Common.Logger.LogOnce("DisplayAllTemps failed.", e); } }
public DuplicantTemperatureDeltaAsEnergyAmountDisplayer(GameUtil.UnitClass unitClass, GameUtil.TimeSlice timeSlice) : base(unitClass, timeSlice, null) { }
public override string GetFormattedValue(float value, GameUtil.TimeSlice timeSlice, GameObject parent_instance) { int quality = (int)value; return(Util.StripTextFormatting(GameUtil.GetFormattedFoodQuality(quality))); }
/// <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); } } }
public static void Postfix(float temp, ref string __result, GameUtil.TemperatureInterpretation interpretation, GameUtil.TimeSlice timeSlice) { try { if (interpretation != GameUtil.TemperatureInterpretation.Absolute || timeSlice != GameUtil.TimeSlice.None) { return; } string formatString = "##0.#"; float kelvin = GameUtil.GetTemperatureConvertedToKelvin(temp); string kelvinString = kelvin.ToString(formatString); string celsiusString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Celsius).ToString(formatString); string fahrenheitString = GameUtil.GetTemperatureConvertedFromKelvin(kelvin, GameUtil.TemperatureUnit.Fahrenheit).ToString(formatString); string first; string second; switch (GameUtil.temperatureUnit) { case GameUtil.TemperatureUnit.Celsius: first = kelvinString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; second = fahrenheitString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; break; case GameUtil.TemperatureUnit.Fahrenheit: first = kelvinString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.KELVIN; second = celsiusString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; break; case GameUtil.TemperatureUnit.Kelvin: first = celsiusString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.CELSIUS; second = fahrenheitString + STRINGS.UI.UNITSUFFIXES.TEMPERATURE.FAHRENHEIT; break; default: return; } __result += $", ({first}, {second})"; } catch (Exception e) { // TODO: log once instead Debug.Log("DisplayAllTemps: " + e); } }
public override string GetFormattedValue(float value, GameUtil.TimeSlice timeSlice, GameObject parent_instance) { return(GameUtil.GetFormattedPercent(value * 100f, timeSlice)); }
public AsPercentAmountDisplayer(GameUtil.TimeSlice deltaTimeSlice) { formatter = new StandardAttributeFormatter(GameUtil.UnitClass.Percent, deltaTimeSlice); }
public string GetFormattedValue(float value, GameUtil.TimeSlice timeSlice, GameObject parent_instance) { return(formatter.GetFormattedValue(value, timeSlice, parent_instance)); }