コード例 #1
0
        /// <summary>
        /// Gets the formatted remaining rocket range.
        /// </summary>
        /// <param name="engine">The rocket's engine.</param>
        /// <param name="fuelMass">The fuel mass remaining.</param>
        /// <param name="oxyMass">The oxidizer mass remaining.</param>
        /// <param name="fuelPerDist">The fuel consumed per tile travelled.</param>
        /// <returns>The range tool tip text. The range title is in CACHED_BUILDER.</returns>
        private static string GetRangeLeft(RocketEngineCluster engine, float fuelMass,
                                           float oxyMass, float fuelPerDist)
        {
            var    text = CACHED_BUILDER;
            string fuelUsage, fuelLeft;
            float  burnable = fuelMass, usage = fuelPerDist * Constants.SECONDS_PER_CYCLE;
            bool   oxidizerNeeded = false;

            if (engine == null)
            {
                // You cheater!
                fuelUsage = "0";
                fuelLeft  = "0";
            }
            else if (engine.TryGetComponent(out HEPFuelTank _))
            {
                fuelUsage = GameUtil.GetFormattedHighEnergyParticles(usage);
                fuelLeft  = GameUtil.GetFormattedHighEnergyParticles(fuelMass);
                // Radbolt engine does not require oxidizer
            }
            else
            {
                fuelUsage      = GameUtil.GetFormattedMass(usage);
                fuelLeft       = GameUtil.GetFormattedMass(fuelMass);
                oxidizerNeeded = engine.requireOxidizer;
                if (oxidizerNeeded)
                {
                    burnable = Mathf.Min(burnable, oxyMass);
                }
            }
            text.Clear().AppendLine(ROCKETS.RANGE.TOOLTIP).Append(Constants.
                                                                  TABBULLETSTRING).AppendLine(ROCKETS.FUEL_PER_HEX.NAME).Replace("{0}",
                                                                                                                                 fuelUsage).Append(Constants.TABBULLETSTRING).Append(ROCKETS.FUEL_REMAINING.
                                                                                                                                                                                     NAME).Append(fuelLeft);
            if (oxidizerNeeded)
            {
                text.AppendLine().Append(Constants.TABBULLETSTRING).Append(ROCKETS.
                                                                           OXIDIZER_REMAINING.NAME);
                FormatStringPatches.GetFormattedMass(text, oxyMass);
            }
            string tooltip = text.ToString();

            text.Clear().Append(ROCKETS.RANGE.NAME);
            float range = (fuelPerDist == 0.0f) ? 0.0f : burnable / fuelPerDist;

            FormatStringPatches.GetFormattedRocketRange(text, range, TimeSlice.None, true);
            return(tooltip);
        }
コード例 #2
0
        /// <summary>
        /// Updates the text to be displayed for a single stored item.
        /// </summary>
        /// <param name="label">The label to be updated.</param>
        /// <param name="item">The item to be displayed.</param>
        /// <param name="freeze">true to freeze the labels, or false to leave as pending.</param>
        /// <param name="pe">The item's primary element, or null if it has none.</param>
        private void SetItemDescription(CachedStorageLabel label, GameObject item, bool freeze,
                                        PrimaryElement pe)
        {
            var defaultStyle = PluginAssets.Instance.defaultTextStyleSetting;
            var text         = CACHED_BUILDER;
            var rottable     = item.GetSMI <Rottable.Instance>();
            var tooltip      = label.tooltip;
            int lines        = 1;

            text.Clear();
            tooltip.ClearMultiStringTooltip();
            if (item.TryGetComponent(out HighEnergyParticleStorage hepStorage))
            {
                // Radbolts
                text.Append(STRINGS.ITEMS.RADIATION.HIGHENERGYPARITCLE.NAME).Append(": ").
                Append(GameUtil.GetFormattedHighEnergyParticles(hepStorage.Particles));
            }
            else if (pe != null)
            {
                // Element
                var properName = item.GetProperName();
                if (item.TryGetComponent(out KPrefabID id) && Assets.IsTagCountable(id.
                                                                                    PrefabTag))
                {
                    FormatStringPatches.GetUnitFormattedName(text, properName, pe.Units);
                }
                else
                {
                    text.Append(properName);
                }
                text.Append(": ");
                FormatStringPatches.GetFormattedMass(text, pe.Mass);
                if (optimizedStorageTemp != null)
                {
                    text.Append(optimizedStorageTemp);
                    FormatStringPatches.GetFormattedTemperature(text, pe.Temperature);
                }
                else
                {
                    string mass = text.ToString();
                    text.Clear().Append(DETAILTABS.DETAILS.CONTENTS_TEMPERATURE).Replace("{1}",
                                                                                         GameUtil.GetFormattedTemperature(pe.Temperature)).Replace("{0}", mass);
                }
            }
コード例 #3
0
        /// <summary>
        /// Refreshes the cargo of a Spaced Out rocket.
        /// </summary>
        /// <param name="parent">The parent where the cargo labels will be placed.</param>
        /// <param name="allCargoBays">The cargo bays found in the rocket.</param>
        private void RefreshCargo(GameObject parent, IList <CargoBayCluster> allCargoBays)
        {
            int count = 0, n = allCargoBays.Count;
            var text = CACHED_BUILDER;

            for (int i = 0; i < n; i++)
            {
                var   cargoBay = allCargoBays[i];
                var   label    = GetStorageLabel(parent, "cargoBay_" + count.ToString());
                var   storage  = cargoBay.storage;
                var   items    = storage.GetItems();
                float mass     = 0.0f;
                int   nitems   = items.Count;
                count++;
                text.Clear();
                for (int j = 0; j < nitems; j++)
                {
                    var item = items[j];
                    if (item.TryGetComponent(out PrimaryElement pe))
                    {
                        float m = pe.Mass;
                        if (text.Length > 0)
                        {
                            text.AppendLine();
                        }
                        text.Append(item.GetProperName()).Append(" : ");
                        FormatStringPatches.GetFormattedMass(text, m);
                        mass += m;
                    }
                }
                label.tooltip.SetSimpleTooltip(text.ToString());
                label.SetAllowDrop(false, storage, null);
                text.Clear().Append(cargoBay.GetProperName()).Append(": ");
                FormatStringPatches.GetFormattedMass(text, mass);
                text.Append('/');
                FormatStringPatches.GetFormattedMass(text, storage.capacityKg);
                label.text.SetText(text);
                // Rocket labels always have 1 line
                label.FreezeIfMatch(1, true);
                rocketLabels.Add(label);
            }
        }