Game.UI.InGame.ElectricityUIUtils
Assembly: Game
Namespace: Game.UI.InGame
Type: public static class
Base: System.Object (static utility class)
Summary:
Utility helpers for UI code related to electricity powerline layers and voltage localization. Provides simple bitwise checks and a helper that inspects a prefab entity (via an EntityManager) to determine which powerline layers (low / high) that prefab can produce or connect to. Intended for use by in-game UI code that needs to show voltage information or filter by powerline layers.
Fields
- This static helper class declares no instance or static fields.
{{ No internal state — all methods are pure helpers that operate on input parameters and ECS data. }}
Properties
- This class exposes no properties.
{{ All functionality is provided through public static methods. }}
Constructors
- This static class has no constructors.
{{ Being a static utility class, it relies only on its static methods and does not need construction. }}
Methods
public static bool HasVoltageLayers(Layer layers)
{{ Checks whether the provided Layer flags include either Layer.PowerlineLow or Layer.PowerlineHigh. Returns true if at least one of those flags is set; otherwise false. Internally uses a bitwise AND against (Layer.PowerlineLow | Layer.PowerlineHigh).
Parameters: - layers — a bitmask of Layer flags (Colossal.Entities.Layer).
Returns: - bool — true when low or high powerline bits are present.
Notes: - Useful for quick UI checks to determine whether voltage-related UI should be shown for a selection. }}
public static VoltageLocaleKey GetVoltage(Layer layers)
{{ Maps the provided Layer flags to a VoltageLocaleKey value used for localization/labels. The method evaluates (layers & (Layer.PowerlineLow | Layer.PowerlineHigh)) and returns:- VoltageLocaleKey.Low when only Layer.PowerlineLow is present,
- VoltageLocaleKey.High when only Layer.PowerlineHigh is present,
- VoltageLocaleKey.Both when neither or both are present (the default case).
Parameters: - layers — bitmask of Layer flags.
Returns: - VoltageLocaleKey — one of Low, High, or Both.
Notes: - The implementation treats the "both / unknown" case as VoltageLocaleKey.Both, so callers should be prepared for that value when layers contain neither flag or both flags. }}
public static Layer GetPowerLineLayers(EntityManager entityManager, Entity prefabEntity)
{{ Inspects the provided prefab entity via the EntityManager to determine which powerline layers it provides or connects to. It composes a Layer bitmask and returns only the PowerlineLow/PowerlineHigh bits.
Behavior: 1. If the prefab entity has a TransformerData component, it sets the Layer.PowerlineLow bit (transformers are treated as low-voltage producers). 2. If the prefab entity has a buffer of Game.Prefabs.SubNet, it iterates that buffer; for each SubNet entry it inspects the referenced prefab entity: - If that referenced prefab has an ElectricityConnectionData component and a NetData component, it ORs in the referenced NetData.m_LocalConnectLayers value. 3. Finally it masks the result with (Layer.PowerlineLow | Layer.PowerlineHigh) and returns that.
Parameters: - entityManager — Unity.Entities.EntityManager used to query components and buffers. - prefabEntity — the prefab Entity to inspect (commonly a building or network prefab entity).
Returns: - Layer — a bitmask containing Layer.PowerlineLow and/or Layer.PowerlineHigh according to the prefab's capabilities.
Notes and considerations:
- Uses entityManager.HasComponent
Usage Example
// Example usage inside UI code or a tool that has access to an EntityManager and a prefab entity:
Layer layers = ElectricityUIUtils.GetPowerLineLayers(entityManager, myPrefabEntity);
if (ElectricityUIUtils.HasVoltageLayers(layers))
{
VoltageLocaleKey key = ElectricityUIUtils.GetVoltage(layers);
// Use `key` to select localized string or icon (Low / High / Both)
}
{{ Additional notes: - Types referenced: - Layer (Colossal.Entities) — bitmask that includes PowerlineLow, PowerlineHigh, None, etc. - VoltageLocaleKey (Game.Net) — enum used by UI localization for Low/High/Both. - TransformerData, ElectricityConnectionData, NetData, Game.Prefabs.SubNet — ECS components/buffer elements used to determine network connections. - Threading: Because this method reads ECS components and buffers via EntityManager, call it on the correct thread/context (typically main thread or from an appropriate ECS system). Do not call from arbitrary background threads unless you ensure safe access to the EntityManager. - Performance: GetPowerLineLayers iterates prefab buffers; keep calls infrequent or cache results if querying many prefabs repeatedly. }}