コード例 #1
0
        /// <summary>
        /// Adds an energy consumer to the consumers list.
        /// </summary>
        /// <param name="iConsumer">The consumer to add.</param>
        /// <param name="index">The consumer's index.</param>
        /// <param name="required">The wattage needed when the consumer is active.</param>
        /// <param name="selected">The currently selected object.</param>
        private void AddConsumer(IEnergyConsumer iConsumer, int index, float required,
                                 GameObject selected)
        {
            var text = CACHED_BUILDER;

            if (iConsumer is KMonoBehaviour consumer && consumer != null)
            {
                var label = AddOrGetLabel(es.labelTemplate, consumerParent,
                                          "consumer" + index.ToString());
                var   go        = consumer.gameObject;
                var   fontStyle = (go == selected) ? FontStyles.Bold : FontStyles.Normal;
                var   title     = label.text;
                float used      = iConsumer.WattsUsed;
                text.Clear().Append(iConsumer.Name).Append(": ");
                FormatStringPatches.GetFormattedWattage(text, used);
                if (!Mathf.Approximately(used, required))
                {
                    text.Append(" / ");
                    FormatStringPatches.GetFormattedWattage(text, required);
                }
                title.fontStyle = fontStyle;
                title.SetText(text);
                consumerLabels.Add(label);
            }
        }
コード例 #2
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);
        }
コード例 #3
0
        /// <summary>
        /// Updates the list of generators on the circuit.
        /// </summary>
        /// <param name="manager">The circuit manager to query.</param>
        /// <param name="circuitID">The circuit to look up.</param>
        private void RefreshGenerators(CircuitManager manager, ushort circuitID)
        {
            var  text         = CACHED_BUILDER;
            var  generators   = manager.circuitInfo[circuitID].generators;
            var  target       = lastSelected.lastTarget;
            int  n            = generators.Count;
            bool hasGenerator = false;

            setInactive.UnionWith(generatorLabels);
            generatorLabels.Clear();
            for (int i = 0; i < n; i++)
            {
                var generator = generators[i];
                if (generator != null && !generator.TryGetComponent(out Battery _))
                {
                    var label = AddOrGetLabel(es.labelTemplate, generatorParent,
                                              "generator" + i.ToString());
                    var go        = generator.gameObject;
                    var fontStyle = (go == target) ? FontStyles.Bold : FontStyles.Normal;
                    var title     = label.text;
                    text.Clear().Append(go.GetProperName()).Append(": ");
                    if (!generator.IsProducingPower())
                    {
                        FormatStringPatches.GetFormattedWattage(text, 0.0f);
                        text.Append(" / ");
                    }
                    FormatStringPatches.GetFormattedWattage(text, generator.WattageRating);
                    title.fontStyle = fontStyle;
                    title.SetText(text);
                    generatorLabels.Add(label);
                    hasGenerator = true;
                }
            }
            if (!hasGenerator)
            {
                var label = AddOrGetLabel(es.labelTemplate, generatorParent, "nogenerators");
                label.text.SetText(ENERGYGENERATOR.NOGENERATORS);
                generatorLabels.Add(label);
            }
            setInactive.ExceptWith(generatorLabels);
            foreach (var label in setInactive)
            {
                label.SetActive(false);
            }
            setInactive.Clear();
        }
コード例 #4
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);
                }
            }
コード例 #5
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);
            }
        }
コード例 #6
0
        /// <summary>
        /// Gets the formatted rocket speed.
        /// </summary>
        /// <param name="rocket">The currently selected rocket.</param>
        /// <param name="enginePower">The rocket engine power.</param>
        /// <param name="burden">The total rocket burden.</param>
        /// <returns>The speed tool tip text. The speed title is in CACHED_BUILDER.</returns>
        private static string GetSpeed(CraftModuleInterface rocket, float enginePower,
                                       float burden)
        {
            var clustercraft = rocket.m_clustercraft;
            var text         = CACHED_BUILDER;

            text.Clear().AppendLine(ROCKETS.SPEED.TOOLTIP).Append(Constants.TABBULLETSTRING).
            Append(ROCKETS.POWER_TOTAL.NAME);
            enginePower.ToRyuHardString(text, 0);
            text.AppendLine().Append(Constants.TABBULLETSTRING).Append(ROCKETS.BURDEN_TOTAL.
                                                                       NAME);
            burden.ToRyuHardString(text, 0);
            string tooltip = text.ToString();

            text.Clear().Append(ROCKETS.SPEED.NAME);
            float speed = (clustercraft == null || burden == 0.0f) ? 0.0f : enginePower *
                          clustercraft.AutoPilotMultiplier * clustercraft.PilotSkillMultiplier / burden;

            FormatStringPatches.GetFormattedRocketRange(text, speed, TimeSlice.PerCycle, true);
            return(tooltip);
        }
コード例 #7
0
        /// <summary>
        /// Updates the circuit summary information.
        /// </summary>
        /// <param name="manager">The circuit manager to query.</param>
        /// <param name="circuitID">The circuit to look up.</param>
        private void RefreshSummary(CircuitManager manager, ushort circuitID)
        {
            var text = CACHED_BUILDER;

            // Available
            text.Clear().Append(ENERGYGENERATOR.AVAILABLE_JOULES).Replace("{0}", GameUtil.
                                                                          GetFormattedJoules(manager.GetJoulesAvailableOnCircuit(circuitID)));
            joulesAvailable.text.SetText(text);
            // Generated
            float generated = GetWattageGenerated(manager, circuitID, out float potential);

            text.Clear();
            if (Mathf.Approximately(generated, potential))
            {
                FormatStringPatches.GetFormattedWattage(text, generated);
            }
            else
            {
                FormatStringPatches.GetFormattedWattage(text, generated);
                text.Append(" / ");
                FormatStringPatches.GetFormattedWattage(text, potential);
            }
            string ratio = text.ToString();

            text.Clear().Append(ENERGYGENERATOR.WATTAGE_GENERATED).Replace("{0}", ratio);
            wattageGenerated.text.SetText(text);
            // Consumed
            text.Clear().Append(ENERGYGENERATOR.WATTAGE_CONSUMED).Replace("{0}",
                                                                          GameUtil.GetFormattedWattage(manager.GetWattsUsedByCircuit(circuitID)));
            wattageConsumed.text.SetText(text);
            // Max consumed
            text.Clear().Append(ENERGYGENERATOR.POTENTIAL_WATTAGE_CONSUMED).Replace("{0}",
                                                                                    GameUtil.GetFormattedWattage(GetWattsNeededWhenActive(manager, circuitID)));
            potentialWattageConsumed.text.SetText(text);
            // Max safe
            text.Clear().Append(ENERGYGENERATOR.MAX_SAFE_WATTAGE).Replace("{0}",
                                                                          GameUtil.GetFormattedWattage(manager.GetMaxSafeWattageForCircuit(circuitID)));
            maxSafeWattage.text.SetText(text);
        }