Game.UI.Tooltip.AreaToolTooltipSystem
Assembly:
Assembly-CSharp (game)
Namespace:
Game.UI.Tooltip
Type:
class
Base:
TooltipSystemBase
Summary:
AreaToolTooltipSystem is an ECS system that provides the in-world mouse tooltips for the Area tool (area size, resources, and storage capacity). It runs only when the Area tool is active and its tooltip mode is one of the modes that should display resource-related information. The system queries temporary area entities (entities with Temp + Area and not Deleted), inspects Extractor and Storage components (and related owner/prefab data), aggregates area, resource amount and storage capacity values, and pushes corresponding IntTooltip entries to be displayed near the mouse.
This system uses ECS ComponentLookup/BufferLookup handles stored in a compiler-generated TypeHandle to safely access additional component/buffer data when computing area and storage values. It is marked with [Preserve] for AOT/IL2CPP preservation.
Fields
-
private ToolSystem m_ToolSystem
Used to get the currently active tool. Initialized from World.GetOrCreateSystemManaged() during OnCreate. -
private AreaToolSystem m_AreaTool
Reference to the AreaToolSystem (the tool this tooltip system services). Used to check if the active tool is the area tool and to read the current AreaTool tooltip mode. -
private ResourceSystem m_ResourceSystem
Used to resolve resource-related prefabs/data when examining extractor ownership/prefab relationships. -
private EntityQuery m_TempQuery
EntityQuery requiring entities that have Temp and Area components and do not have Deleted. Required for update — the system runs only when such entities exist. -
private IntTooltip m_Resources
Tooltip structure configured in OnCreate to display resource-related values (path = "areaToolResources", label localized "Tools.RESOURCES_LABEL", unit "weight"). -
private IntTooltip m_AreaSizeToolTip
Tooltip structure configured in OnCreate to display area size (path = "areaToolAreaSize", label localized "Tools.AREASIZE_LABEL", unit "area"). -
private IntTooltip m_Storage
Tooltip structure configured in OnCreate to display storage capacity (path = "areaToolStorage", label localized "Tools.STORAGECAPACITY_LABEL", unit "weight"). -
private TypeHandle __TypeHandle
Compiler-generated struct instance that contains BufferLookup/ComponentLookup fields used to read additional ECS data (SubArea buffer, InstalledUpgrade buffer, Lot component, Geometry component). __TypeHandle.__AssignHandles(ref SystemState) sets them up from the SystemState; OnCreateForCompiler ensures assignment for AOT builds.
TypeHandle (inner struct) fields (conceptual; actually inside the struct):
- BufferLookup<Game.Areas.SubArea> __Game_Areas_SubArea_RO_BufferLookup
(ReadOnly)
- BufferLookup<InstalledUpgrade> __Game_Buildings_InstalledUpgrade_RO_BufferLookup
(ReadOnly)
- ComponentLookup<Game.Areas.Lot> __Game_Areas_Lot_RO_ComponentLookup
(ReadOnly)
- ComponentLookup<Geometry> __Game_Areas_Geometry_RO_ComponentLookup
(ReadOnly)
These are used in OnUpdate via InternalCompilerInterface.GetBufferLookup / GetComponentLookup calls.
Properties
- None (no public properties exposed by this system)
Constructors
public AreaToolTooltipSystem()
Default constructor. Marked [Preserve] on lifecycle methods to prevent trimming; the constructor itself is empty in the decompiled source. Initialization of runtime references and tooltip templates happens in OnCreate.
Methods
protected override void OnCreate()
: System.Void
Initializes system references and tooltip templates:- Retrieves ToolSystem, AreaToolSystem and ResourceSystem from the World.
- Builds an EntityQuery requiring entities with Temp and Area components but not Deleted, then calls RequireForUpdate to limit execution to situations where such entities exist.
- Initializes three IntTooltip instances (m_AreaSizeToolTip, m_Resources, m_Storage) with localized labels, paths and units.
Notes: - This is where the system wires itself into the game world and sets up the tooltip templates it will reuse.
protected override void OnUpdate()
: System.Void
Main runtime logic that runs each frame when the system is eligible:- Early exit if the active tool is not the Area tool, the area tool's tooltip mode is None, or ShouldShowResources returns false for the current tooltip mode.
- Uses m_TempQuery.ToEntityArray(Allocator.TempJob) to get all temporary area entities, iterates them, and aggregates values into:
- num2: resource amount from Extractor components that require natural resource (added to m_Resources)
- num: area size (rounded) for extractors that don't count as natural resource extraction (added to m_AreaSizeToolTip)
- num3: storage capacity aggregated from Storage components (added to m_Storage)
- Logic details:
- For entities with Extractor component:
- If the extractor is owned (Owner -> Owner chain) by a prefab with BuildingPropertyData that allows a manufactured resource which requires natural resource, and the extractor prefab also requires natural resource, the extractor's m_ResourceAmount is counted toward num2 (resources).
- Otherwise, calls ExtractorAISystem.GetArea(entity, ref subAreas, ref installedUpgrades, ref lots, ref geometries) to compute the area provided by that extractor and adds it to num (area size). The method uses the TypeHandle lookups retrieved via InternalCompilerInterface.GetBufferLookup / GetComponentLookup.
- For entities that have Storage component:
- Reads the entity's Geometry and the StorageAreaData from the entity's prefab and computes storage capacity via AreaUtils.CalculateStorageCapacity.
- If the storage entity is owned by a GarbageFacility prefab, collects installed upgrades (if any) and applies UpgradeUtils.CombineStats to the GarbageFacilityData to add its garbage capacity (component10.m_GarbageCapacity) to the total.
- After processing all entities, if any of the three categories had values, sets the corresponding IntTooltip.value and calls AddMouseTooltip(...) to display them.
- Ensures the NativeArray is disposed in a finally block.
Important notes: - Uses InternalCompilerInterface lookups for buffer/component access to respect ECS safety in generated code paths. - Uses Allocator.TempJob for the entity array and disposes it explicitly.
-
private static bool ShouldShowResources(AreaToolSystem.Tooltip tooltip)
: System.Boolean
Returns true for a contiguous range of tooltip enum values: the check (uint)(tooltip - 6) <= 4u returns true when tooltip is in [6, 10] (inclusive). In other words, only certain AreaTool tooltip modes require resource-related tooltips; other modes do not. -
private void __AssignQueries(ref SystemState state)
: System.Void
Compiler-generated helper used during compiled-time AOT setup. In the decompiled code it creates and disposes an EntityQueryBuilder without adding queries — effectively a placeholder to ensure the proper IL2CPP codegen for queries. Called from OnCreateForCompiler. -
protected override void OnCreateForCompiler()
: System.Void
Compiler/AOT helper that: -
Calls __AssignQueries(ref base.CheckedStateRef) and __TypeHandle.__AssignHandles(ref base.CheckedStateRef) to prepare component/buffer lookup handles for AOT/IL2CPP builds.
-
private struct TypeHandle
Compiler-generated struct holding BufferLookup/ComponentLookup fields. Contains: - ReadOnly BufferLookup
__Game_Areas_SubArea_RO_BufferLookup - ReadOnly BufferLookup
__Game_Buildings_InstalledUpgrade_RO_BufferLookup - ReadOnly ComponentLookup
__Game_Areas_Lot_RO_ComponentLookup - ReadOnly ComponentLookup
__Game_Areas_Geometry_RO_ComponentLookup - Method __AssignHandles(ref SystemState state): populates the above lookups from the given state with isReadOnly: true.
Usage Example
This system is an engine/system type and is normally discovered and run by the game's World. Typical behavior is seen inside the system itself (OnCreate sets up IntTooltip templates; OnUpdate sets tooltip values and calls AddMouseTooltip). Example snippet showing the tooltip initialization (similar to what this system does in OnCreate):
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// cache tool/system references
m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
m_AreaTool = base.World.GetOrCreateSystemManaged<AreaToolSystem>();
m_ResourceSystem = base.World.GetOrCreateSystemManaged<ResourceSystem>();
// require presence of Temp+Area entities (and exclude Deleted) to run
m_TempQuery = GetEntityQuery(new EntityQueryDesc {
All = new ComponentType[]{ ComponentType.ReadOnly<Temp>(), ComponentType.ReadOnly<Area>() },
None = new ComponentType[]{ ComponentType.ReadOnly<Deleted>() }
});
RequireForUpdate(m_TempQuery);
// prepare tooltip templates (reused every frame)
m_AreaSizeToolTip = new IntTooltip {
path = "areaToolAreaSize",
label = LocalizedString.Id("Tools.AREASIZE_LABEL"),
unit = "area"
};
m_Resources = new IntTooltip {
path = "areaToolResources",
label = LocalizedString.Id("Tools.RESOURCES_LABEL"),
unit = "weight"
};
m_Storage = new IntTooltip {
path = "areaToolStorage",
label = LocalizedString.Id("Tools.STORAGECAPACITY_LABEL"),
unit = "weight"
};
}
Example of how the system sets a tooltip in OnUpdate (simplified):
// after computing aggregatedResourceAmount:
m_Resources.value = aggregatedResourceAmount;
AddMouseTooltip(m_Resources);
Additional notes and implementation details: - The system relies on several game-specific helper classes and utilities: ExtractorAISystem.GetArea, AreaUtils.CalculateStorageCapacity, UpgradeUtils.CombineStats, and various data component types (StorageAreaData, GarbageFacilityData, ResourceData, BuildingPropertyData, etc.). When changing or extending tooltip behavior, ensure compatibility with those helpers. - The system filters entities via m_TempQuery, which uses the Temp tag component. If mod code creates temporary area-like entities that should show tooltips, ensure they match the same component composition (Temp + Area and not Deleted). - The ShouldShowResources method uses a numeric range test on the AreaToolSystem.Tooltip enum; if the enum changes in the game or in mods, this check may need to be updated to reflect new tooltip modes. - All Native allocations (Entity arrays) are disposed of in a finally block to avoid leaks. - InternalCompilerInterface.GetBufferLookup/GetComponentLookup calls are used to bridge the compiler-generated TypeHandle lookups to runtime ComponentLookup/BufferLookup instances; maintain these patterns when adding new buffer/component accesses to keep safety and burst/AOT compatibility.