/// <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); } }
/// <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(); }
/// <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); }