Game.UI.Tooltip.TempRenewableElectricityProductionTooltipSystem
Assembly:
Game (inferred from namespace and project layout)
Namespace:
Game.UI.Tooltip
Type:
class
Base:
TooltipSystemBase
Summary:
System that builds and displays a tooltip showing aggregate renewable electricity production estimates for temporary building operations (Temp entities) — specifically wind, groundwater and water-powered production. It queries Temp entities that are being created/modified/upgraded, looks up their prefabs and associated power-production data (WindPoweredData, GroundWaterPoweredData, WaterPowered/WaterPoweredData), samples Wind and GroundWater maps, accumulates current and maximum potential production, and adds a progress tooltip plus warnings if production is significantly below potential.
Fields
-
private WindSystem m_WindSystem
Used to obtain the wind map that is sampled to compute wind turbine production for temporary prefabs. -
private GroundWaterSystem m_GroundWaterSystem
Used to obtain the groundwater map that is sampled to compute groundwater-powered production. -
private EntityQuery m_ErrorQuery
EntityQuery that matches Temp + Error. Used to early-out when there are errors present (system will not show tooltip in error state). -
private EntityQuery m_TempQuery
EntityQuery that selects Temp entities with Transform, PrefabRef and RenewableElectricityProduction (and excludes Deleted). These are the temporary building instances being inspected for estimated renewable production. -
private ProgressTooltip m_Production
Progress-style tooltip instance representing aggregated renewable electricity produced vs capacity (value/max). Configured with icon, label, unit and path. -
private StringTooltip m_WindWarning
String tooltip used to show a warning when wind production is significantly below capacity (configured with warning string and color). -
private StringTooltip m_GroundWaterAvailabilityWarning
String tooltip used to show a warning when groundwater production is significantly below capacity. -
private TypeHandle __TypeHandle
Internal struct holding ComponentLookup/ComponentTypeHandle instances (read-only) used during update to access component data without allocating new handles each frame. -
private struct TypeHandle
Nested struct (see below) that contains the component lookups and type handles for: - ComponentLookup
- ComponentLookup
- ComponentTypeHandle
- ComponentTypeHandle
- ComponentTypeHandle
- ComponentTypeHandle
and a helper method to assign those handles from a SystemState.
Properties
- No public properties defined on this type. (All relevant state is held in private fields.)
Constructors
public TempRenewableElectricityProductionTooltipSystem()
Default constructor. Marked with [Preserve] on lifecycle methods; constructor itself is empty and relies on OnCreate to initialize systems and tooltips.
Methods
protected override void OnCreate()
Initializes the system:- Retrieves or creates managed WindSystem and GroundWaterSystem.
- Builds two EntityQueries: m_ErrorQuery (Temp + Error) and m_TempQuery (Temp + Transform + PrefabRef + RenewableElectricityProduction, excluding Deleted).
- Initializes m_Production (ProgressTooltip) with icon, label and unit.
- Initializes m_WindWarning and m_GroundWaterAvailabilityWarning (StringTooltip) with localized warning messages and warning color.
-
Calls RequireForUpdate(m_TempQuery) so the system only runs when relevant Temp entities exist.
-
protected override void OnUpdate()
Main logic to compute and show tooltip: - Early returns if m_ErrorQuery is not empty (do not display tooltip when an error entity exists).
- Calls CompleteDependency() to ensure ECS dependencies are finished before reading component data.
- Retrieves wind and groundwater maps from the WindSystem and GroundWaterSystem (GetMap) and completes those job handles.
- Obtains ComponentLookup and ComponentTypeHandle instances via InternalCompilerInterface using __TypeHandle and the system's CheckedStateRef.
- Enumerates archetype chunks for m_TempQuery (allocated via Allocator.TempJob) and iterates over PrefabRef / Transform / Temp / WaterPowered arrays per chunk.
- For each Temp entity that has flags Create/Modify/Upgrade set, it:
- Checks if the prefab has WindPoweredData and, if so, samples the wind map to compute current and max wind production using PowerPlantAISystem.GetWindProduction. Accumulates current (x) and max (y) production and sets a flag if current < 75% of max.
- If the chunk contains WaterPowered components and the prefab has WaterPoweredData (via EntityManager.TryGetComponent), computes water-based capacity and current estimate contribution and accumulates to totals.
- If the prefab has GroundWaterPoweredData and m_MaximumGroundWater > 0, computes groundwater production with PowerPlantAISystem.GetGroundWaterProduction (sampling the groundwater map), accumulates totals and sets a flag if current < 75% of max.
- After aggregation, if total max (num2) > 0, sets m_Production.value and max, calls ProgressTooltip.SetCapacityColor to set tooltip color based on capacity usage, and calls AddMouseTooltip(m_Production). Adds wind and/or groundwater availability warning tooltips when corresponding flags are set.
-
Ensures the temporarily allocated NativeArray
is disposed in a finally block. -
private void __AssignQueries(ref SystemState state)
Compiler-generated helper used at OnCreateForCompiler to set up (no-op in this implementation; it creates and immediately disposes an EntityQueryBuilder). -
protected override void OnCreateForCompiler()
Compiler hook: calls base.OnCreateForCompiler, __AssignQueries and assigns component handles in __TypeHandle via __AssignHandles. This method is used by the generated code path / AOT scenarios to ensure handles are initialized. -
private struct TypeHandle.__AssignHandles(ref SystemState state)
Assigns ComponentLookup/ComponentTypeHandle instances from the passed SystemState (read-only) for WindPoweredData, GroundWaterPoweredData, PrefabRef, Transform, Temp, and Game.Buildings.WaterPowered.
Notes on implementation details:
- Uses InternalCompilerInterface and base.CheckedStateRef to obtain stable handles at runtime.
- Uses NativeArray
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_WindSystem = base.World.GetOrCreateSystemManaged<WindSystem>();
m_GroundWaterSystem = base.World.GetOrCreateSystemManaged<GroundWaterSystem>();
// Prepare tooltip instances and entity queries (simplified)
m_Production = new ProgressTooltip {
path = "renewableElectricityProduction",
icon = "Media/Game/Icons/Electricity.svg",
label = LocalizedString.Id("Tools.ELECTRICITY_PRODUCTION_LABEL"),
unit = "power",
omitMax = true
};
m_WindWarning = new StringTooltip {
path = "windWarning",
value = LocalizedString.Id("Tools.WARNING[NotEnoughWind]"),
color = TooltipColor.Warning
};
m_GroundWaterAvailabilityWarning = new StringTooltip {
path = "groundWaterAvailabilityWarning",
value = LocalizedString.Id("Tools.WARNING[NotEnoughGroundWater]"),
color = TooltipColor.Warning
};
RequireForUpdate(m_TempQuery);
}
Additional notes for modders: - This system is intended for temporary building previews (Temp entities) and will not run if any Temp+Error entity exists. - If you extend or modify power production calculations, ensure to respect job dependency completion (CompleteDependency / Complete job handles) and to dispose any temporary NativeArray allocations. - The 75% threshold for issuing warnings is a hardcoded heuristic in this system (current < 0.75 * max). Adjust as needed if exposing config.