Game.UI.InGame.ElectricitySection
Assembly:
Assembly-CSharp
Namespace:
Game.UI.InGame
Type:
public class ElectricitySection
Base:
InfoSectionBase
Summary:
ElectricitySection is a UI info panel section used by the in-game interface to display electricity-related information for the currently selected entity (typically buildings/power plants). It reads the ElectricityProducer component for the selected entity to report capacity and recent production, and it augments the section's tooltips with tags for power source types (Solar, Wind, Garbage, Water) when the selected prefab or entity supports those power types. The class relies on the entity component system exposed by the base InfoSectionBase (EntityManager, selectedEntity, selectedPrefab, tooltipKeys, visible).
Fields
-
private int capacity { get; set; }
This private auto-property stores the electricity capacity read from the selected entity's ElectricityProducer component (m_Capacity). It is reset to 0 in Reset() and updated in OnProcess(). -
private int production { get; set; }
This private auto-property stores the latest production value read from ElectricityProducer (m_LastProduction). It is reset to 0 in Reset() and updated in OnProcess(). -
protected override string group => "ElectricitySection"
Expression-bodied property that identifies this section's group name. The base InfoSectionBase likely uses this to categorize or find the proper UI group resources (labels, layout, localization keys).
Properties
-
protected override string group { get; }
Returns the group identifier string "ElectricitySection". Used by the UI system to route or label this section. -
private int capacity { get; set; }
Holds the capacity value for the current selected entity. -
private int production { get; set; }
Holds the last production value for the current selected entity.
Constructors
public ElectricitySection()
Default constructor marked with [Preserve]. The Preserve attribute ensures the constructor (and possibly the type) is not stripped by the IL2CPP/managed code stripping pipeline used by the game. No custom initialization is performed in the constructor; initialization occurs via lifecycle methods (Reset, OnProcess).
Methods
-
protected override void Reset()
Resets the section's cached values. Specifically sets capacity and production to 0. This method is intended to clear previous state when the section is reinitialized or when selection changes. -
private bool Visible()
Determines whether this section should be visible for the currently selected entity. It returns true when the EntityManager reports that the selectedEntity has an ElectricityProducer component. This is used to hide the electricity section for non-power-related entities. -
[Preserve] protected override void OnUpdate()
Called periodically by the UI/lifecycle framework. This implementation updates base.visible using the Visible() check so the UI shows or hides the section depending on whether the selected entity supports electricity production. The Preserve attribute again prevents stripping. -
protected override void OnProcess()
Core processing method where the section reads component data and prepares UI data: - Retrieves ElectricityProducer via EntityManager.GetComponentData
(selectedEntity). - Updates capacity from componentData.m_Capacity and production from componentData.m_LastProduction.
- Checks whether the selected entity/prefab has specific power-source components (SolarPoweredData, WindPoweredData, GarbagePoweredData) via TryGetComponentWithUpgrades
. If present, it adds corresponding tooltip keys "Solar", "Wind", "Garbage" to base.tooltipKeys. -
Also checks for Game.Buildings.WaterPowered on the entity (via EntityManager.HasComponent) and adds tooltip key "Water" if present. This method prepares the state that will be serialized by OnWriteProperties and displayed by the UI.
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the section's properties into the provided JSON writer. Writes two properties: - "capacity" with the integer capacity value.
- "production" with the integer production value. This output is typically consumed by the UI layer to render numeric values.
Usage Example
// The UI framework calls lifecycle methods; a modder can inspect or extend behavior.
// Example: subclassing to append an additional tooltip key when a custom power source exists.
[Preserve]
protected override void OnProcess()
{
base.OnProcess(); // runs the original logic to set capacity, production, tooltip keys
// Add a custom tooltip key if the prefab supports a hypothetical "GeothermalPoweredData"
if (TryGetComponentWithUpgrades<GeothermalPoweredData>(selectedEntity, selectedPrefab, out var _))
{
tooltipKeys.Add("Geothermal");
}
}
// The framework will call OnWriteProperties to get "capacity" and "production" for rendering.
Notes and tips for modders:
- The class uses EntityManager, selectedEntity and selectedPrefab provided by InfoSectionBase; ensure those are valid and up-to-date when interacting with this section.
- TryGetComponentWithUpgrades