Skip to content

Game.UI.Tooltip.TempWaterPumpingTooltipSystem

Assembly: Assembly-CSharp
Namespace: Game.UI.Tooltip

Type: class

Base: TooltipSystemBase

Summary:
Tooltip system that gathers statistics for water pumping stations (groundwater and surface water) and displays capacity, reservoir usage and availability warnings in the UI. It uses ECS queries and Burst-compiled jobs to compute production/capacity from prefab data, installed upgrades, groundwater map and surface water availability. The system schedules multiple jobs (TempJob, GroundWaterPumpJob and GroundWaterReservoirJob), reads data from GroundWaterSystem, WaterSystem and TerrainSystem, and uses NativeReference/NativeCollections for cross-job results. It also registers readers with GroundWaterSystem/WaterSystem/TerrainSystem to ensure safe concurrent access.


Fields

  • private GroundWaterSystem m_GroundWaterSystem
    System reference used to read the ground water texture/map and to register readers for job synchronization.

  • private WaterSystem m_WaterSystem
    System reference used to read surface water data and register surface readers for scheduled jobs.

  • private TerrainSystem m_TerrainSystem
    System reference used to read terrain height data required by surface water availability calculations.

  • private EntityQuery m_ErrorQuery
    ECS query that checks for Temp + Error entities to avoid showing tooltips when there are errors.

  • private EntityQuery m_TempQuery
    ECS query that matches temporary water pumping station entities (used for UI tooltip calculation).

  • private EntityQuery m_PumpQuery
    ECS query that matches all water pumping station entities (used for per-cell pump capacity aggregation).

  • private EntityQuery m_ParameterQuery
    ECS query used to get the WaterPipeParameterData singleton (parameters like pump effective amounts and replenish/usage multipliers).

  • private ProgressTooltip m_Capacity
    Tooltip object used to show current pumping production vs max capacity.

  • private IntTooltip m_ReservoirUsage
    Tooltip object used to show groundwater reservoir usage (percentage) for displayed pumping stations.

  • private StringTooltip m_OverRefreshCapacityWarning
    String tooltip (warning) shown when pump capacity exceeds reservoir replenish capacity.

  • private StringTooltip m_AvailabilityWarning
    String tooltip (warning) shown when pumping availability is low (production < 75% of max).

  • private LocalizedString m_GroundWarning
    Localized message key for not-enough-groundwater warning.

  • private LocalizedString m_SurfaceWarning
    Localized message key for not-enough-fresh-water (surface water) warning.

  • private NativeReference<TempResult> m_TempResult
    NativeReference used to store the aggregated TempResult produced by TempJob. Allocated with Allocator.Persistent and disposed in OnDestroy.

  • private NativeReference<GroundWaterReservoirResult> m_ReservoirResult
    NativeReference used to store the aggregated GroundWaterReservoirResult produced by GroundWaterReservoirJob. Allocated with Allocator.Persistent and disposed in OnDestroy.

  • private TypeHandle __TypeHandle
    Helper struct containing ComponentTypeHandle/BufferTypeHandle/ComponentLookup instances used to set up job input handles.


Properties

  • None (this system does not expose public properties).

Constructors

  • public TempWaterPumpingTooltipSystem()
    Constructor (marked [Preserve] in source). The system performs initialization in OnCreate; the constructor itself does not perform heavy initialization.

Methods

  • protected override void OnCreate()
    Initializes system references (GroundWaterSystem, WaterSystem, TerrainSystem), creates ECS queries (m_ErrorQuery, m_TempQuery, m_PumpQuery, m_ParameterQuery), configures tooltip objects (m_Capacity, m_ReservoirUsage, warnings) and allocates persistent NativeReference instances (m_TempResult, m_ReservoirResult). This method is called when the system is created.

  • protected override void OnDestroy()
    Disposes persistent native allocations (m_TempResult and m_ReservoirResult) and calls base.OnDestroy to clean up.

  • protected override void OnUpdate()
    Main update: early-exits if there are errors or no temp pumping stations; otherwise it:

  • obtains the ground water map and relevant system data (surface data, terrain height data) and parameter singleton,
  • schedules TempJob to compute aggregated capacity/production/types across temp entities,
  • schedules GroundWaterPumpJob to accumulate per-cell pump capacities for groundwater pumps and collects pump cells,
  • schedules GroundWaterReservoirJob to flood-fill connected groundwater reservoir cells and compute combined pump capacity and available volume,
  • disposes temporary NativeCollections with proper job dependencies,
  • sets base.Dependency to the combined dependency and registers readers on GroundWaterSystem/WaterSystem/TerrainSystem for safe concurrent reads.

Note: Jobs are Burst-compiled and use NativeArray/NativeParallelHashMap/NativeList/NativeQueue/NativeReference.

  • private void ProcessResults()
    Called on the main thread after job results are available. Reads m_TempResult and m_ReservoirResult and chooses which tooltips/warnings to show:
  • If groundwater pumps present: shows production (m_Capacity), reservoir usage (if volume > 0) and availability warning using m_GroundWarning.
  • If only surface pumps present: shows production and availability warning using m_SurfaceWarning.
  • Otherwise: just shows production.

  • private void ProcessReservoir(GroundWaterReservoirResult reservoir)
    Computes reservoir usage percentage using water parameters (m_GroundwaterReplenish, m_GroundwaterUsageMultiplier) and reservoir volume/pump capacity. Sets m_ReservoirUsage.value and color (Warning if >100%). Adds the reservoir usage tooltip and, if applicable, an over-refresh-capacity warning tooltip.

  • private void ProcessProduction(TempResult temp)
    If production > 0 sets m_Capacity (value and max) and color, then adds the capacity tooltip.

  • private void ProcessAvailabilityWarning(TempResult temp, LocalizedString warningText)
    Displays m_AvailabilityWarning when production is >0 but less than 75% of max capacity.

  • protected override void OnCreateForCompiler()
    Internal helper called by generated code/path for safety: assigns queries and type handles required by the job code path.

  • (Nested job structs) TempJob, GroundWaterPumpJob, GroundWaterReservoirJob — each is a Burst-compiled job:

  • TempJob : IJobChunk — iterates matching chunks to compute aggregated types, production and max capacity for temp pumping stations, taking installed upgrades and prefab WaterPumpingStationData into account. Reads ground water map, surface water data, transforms and subobjects to compute availability.
  • GroundWaterPumpJob : IJobChunk — collects per-grid-cell pump capacities for groundwater pumps and optional temp pump cell list.
  • GroundWaterReservoirJob : IJob — performs a BFS/flood-fill over ground water cells starting from pump cells to compute connected reservoir volume and combined pump capacity. Uses NativeQueue and NativeParallelHashSet for traversal and marks processed cells.

Notes and caveats: - Native containers created with Allocator.Persistent (m_TempResult, m_ReservoirResult) are disposed in OnDestroy; temporary NativeParallelHashMap/NativeList/NativeQueue are disposed via job handles after scheduling. - Jobs rely on registering readers on GroundWaterSystem/WaterSystem/TerrainSystem to coordinate multi-threaded reads; ensure jobs' dependencies are honored when interacting with those systems. - The system expects WaterPipeParameterData singleton to be present.

Usage Example

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

    // basic parts of the real implementation:
    m_GroundWaterSystem = World.GetOrCreateSystemManaged<GroundWaterSystem>();
    m_WaterSystem = World.GetOrCreateSystemManaged<WaterSystem>();
    m_TerrainSystem = World.GetOrCreateSystemManaged<TerrainSystem>();

    // allocate persistent native containers used to transfer results from jobs back to main thread
    m_TempResult = new NativeReference<TempResult>(Allocator.Persistent);
    m_ReservoirResult = new NativeReference<GroundWaterReservoirResult>(Allocator.Persistent);

    // configure tooltip objects (example simplified)
    m_Capacity = new ProgressTooltip { path = "groundWaterCapacity", icon = "Media/Game/Icons/Water.svg" };
}

If you want, I can also generate a short modding note about safely modifying this system (e.g., how to hook or replace its tooltip output, or how to adapt job code for additional water types).