Skip to content

Game.UI.Tooltip.RaycastElectricityTooltipSystem

Assembly: Game
Namespace: Game.UI.Tooltip

Type: class

Base: TooltipSystemBase

Summary:
RaycastElectricityTooltipSystem is an ECS System that provides on-mouse tooltips for electricity-related entities (lines, transformers, producers, batteries, consumers) when the electricity infomode is active. It listens to the game's tool raycast results and, when applicable, gathers flow/production/usage/charge data from the electricity simulation and adds appropriate tooltip entries (int and progress tooltips). Internally it uses a private TypeHandle to cache ComponentLookup/BufferLookup handles and depends on several managed tool systems (ToolSystem, DefaultToolSystem, ToolRaycastSystem, ElectricityFlowSystem).


Fields

  • private struct TypeHandle
    Contains cached ComponentLookup and BufferLookup handles used to read various components and buffers used by the system (Deleted, PrefabRef, ElectricityConnectionData, InstalledUpgrade, SubNet, Node, ElectricityNodeConnection, ElectricityValveConnection, ConnectedFlowEdge, ElectricityFlowEdge, ElectricityConsumer, Building, ElectricityBuildingConnection). Provides __AssignHandles(ref SystemState state) to initialize those lookups for the current SystemState.

  • private ToolSystem m_ToolSystem
    Reference to the game's ToolSystem (managed). Used to check the current active tool.

  • private DefaultToolSystem m_DefaultTool
    Reference to the DefaultToolSystem instance used to detect whether the default (selection) tool is active.

  • private ToolRaycastSystem m_ToolRaycastSystem
    Used to query the latest raycast result (what the mouse is pointing at).

  • private ElectricityFlowSystem m_ElectricityFlowSystem
    Reference to the electricity flow simulation system; used to access sinkNode and other flow details.

  • private EntityQuery m_InfomodeQuery
    Query used to determine whether the electricity infomode (low/high voltage flow view) is active.

  • private IntTooltip m_Production
    Preconfigured IntTooltip instance for electricity production (capacity).

  • private IntTooltip m_TransformerCapacity
    Preconfigured IntTooltip for transformer capacity.

  • private IntTooltip m_Usage
    Preconfigured IntTooltip for showing usage/percentage and colored by bottleneck state.

  • private IntTooltip m_BatteryFlow
    Preconfigured IntTooltip showing battery charge/discharge flow (signed power).

  • private IntTooltip m_BatteryCharge
    Preconfigured IntTooltip showing battery state-of-charge (percentage).

  • private ProgressTooltip m_Consumption
    Preconfigured ProgressTooltip showing fulfilled vs wanted consumption (warning color if not fully fulfilled).

  • private ProgressTooltip m_Flow
    Preconfigured ProgressTooltip used to show flow vs capacity on edges/nodes.

  • private TypeHandle __TypeHandle
    Instance of the above TypeHandle used to obtain component/buffer lookups when needed.

Properties

  • None (no public properties are defined on this system)

Constructors

  • public RaycastElectricityTooltipSystem()
    Default parameterless constructor. The system relies on OnCreate to initialize runtime state and references to other managed systems.

Methods

  • protected override void OnCreate()
    Initializes the system: obtains references to managed systems (ToolSystem, DefaultToolSystem, ToolRaycastSystem, ElectricityFlowSystem), creates an EntityQuery for the electricity infomode, marks the query as required for update, and constructs/configures the various IntTooltip and ProgressTooltip objects (labels, units, colors, signed/omitMax flags).

  • protected override void OnUpdate()
    Main runtime logic. Completes dependencies, checks that electricity infomode is active, the active tool is the default tool, and that a valid raycast result exists. Depending on the hit entity it:

  • Resolves utility lanes/edges and calls AddEdgeFlow or AddNodeFlow as appropriate.
  • Reads producer data to add production and usage tooltips.
  • For transformers, it uses the TypeHandle lookups to build a TransformerData struct, queries transformer capacity/flow and shows transformer usage.
  • Reads battery components to show battery flow and charge percentage.
  • Reads ElectricityConsumer to show consumption progress. The method also uses HasBottleneck to color usage tooltips.

  • private void AddEdgeFlow(Entity edge, float curvePosition)
    Computes the flow and capacity for a specific edge segment at a given curve position. It uses component/buffer lookups (via InternalCompilerInterface and the TypeHandle) to accumulate upstream flows and subtract distributed consumption located before the curve position. Result is placed into m_Flow (value and max) and added as a tooltip.

  • private void AddNodeFlow(Entity node, Entity edge)
    When the raycast selects a node (or an edge without curve context), this method finds the strongest connected flow edge at the node that corresponds to the provided edge and shows its flow and capacity in m_Flow as a tooltip.

  • private bool IsInfomodeActivated()
    Checks m_InfomodeQuery and inspects InfoviewNetStatusData entries to determine whether LowVoltageFlow or HighVoltageFlow infomode is active. Returns true if either is active.

  • private bool HasBottleneck(Entity building)
    Checks whether the provided building has a bottleneck in its producer edge or transformer node by inspecting ElectricityFlowEdge.isBottleneck on related edges. Used to flag usage tooltips as warnings.

  • private void __AssignQueries(ref SystemState state)
    Compiler helper used by the generated code to assign queries. In this compiled file it only creates and disposes an EntityQueryBuilder (no runtime content beyond that).

  • protected override void OnCreateForCompiler()
    Compiler-time helper that invokes __AssignQueries and initializes the TypeHandle lookups by calling __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • private void TypeHandle.__AssignHandles(ref SystemState state)
    Initializes all ComponentLookup and BufferLookup fields on the TypeHandle with reads set to isReadOnly: true. Should be called from OnCreateForCompiler to prepare lookups for runtime use.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Acquire managed systems used by this tooltip system
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
    m_DefaultTool = base.World.GetOrCreateSystemManaged<DefaultToolSystem>();
    m_ToolRaycastSystem = base.World.GetOrCreateSystemManaged<ToolRaycastSystem>();
    m_ElectricityFlowSystem = base.World.GetOrCreateSystemManaged<ElectricityFlowSystem>();

    // Require the electricity infomode query for updates
    m_InfomodeQuery = GetEntityQuery(ComponentType.ReadOnly<InfomodeActive>(), ComponentType.ReadOnly<InfoviewNetStatusData>());
    RequireForUpdate(m_InfomodeQuery);

    // Configure tooltip entries (examples)
    m_Production = new IntTooltip {
        path = "electricityProduction",
        label = LocalizedString.Id("Tools.ELECTRICITY_PRODUCTION_LABEL"),
        unit = "power"
    };

    m_Flow = new ProgressTooltip {
        path = "electricityFlow",
        label = LocalizedString.Id("Tools.ELECTRICITY_FLOW_LABEL"),
        unit = "power"
    };
}

Notes and tips: - This system is intended to run only when the electricity infomode (low/high voltage flow) is active; otherwise it early-exits to avoid showing irrelevant tooltips. - The TypeHandle mechanism is used to avoid repeatedly allocating ComponentLookup/BufferLookup instances; OnCreateForCompiler initializes these handles for safe use during OnUpdate. - The system relies on details from the electricity simulation (ElectricityFlowEdge, ConnectedFlowEdge, ConnectedBuilding, etc.), so mods that change those components must remain compatible.