Game.UI.Tooltip.CityPolicyTooltipSystem
Assembly: Game / Assembly-CSharp (in-game)
Namespace: Game.UI.Tooltip
Type: class
Base: TooltipSystemBase
Summary:
CityPolicyTooltipSystem is a UI tooltip system that shows policy-related tooltips while the player is using the default tool and an infoview (heatmap or building-status view) is active. It detects when the "Advanced Pollution Management" city policy is active and, when the player hovers over industrial buildings that produce pollution or garbage, it displays a localized tooltip indicating the policy effect (ground pollution, air pollution or garbage). The system uses raycasts to resolve the object under the cursor and inspects prefab and zone data to verify building type and pollution/garbage properties. On creation it searches for the "Advanced Pollution Management" policy prefab and throws an exception if it cannot be found.
Fields
-
private PrefabSystem m_PrefabSystem
Reference to the PrefabSystem used to lookup policy and building prefabs (PolicyPrefab, SpawnableBuildingData, PollutionData, etc.). -
private ToolSystem m_ToolSystem
Reference to the game's ToolSystem; used to check the active tool and active infoview. -
private DefaultToolSystem m_DefaultTool
Reference to the DefaultToolSystem, used to ensure the default tool is active before showing tooltips. -
private RaycastSystem m_RaycastSystem
Reference to RaycastSystem used to perform screen-to-world raycasts to determine which entity is under the cursor. -
private CameraUpdateSystem m_CameraUpdateSystem
Reference to the CameraUpdateSystem used to obtain the current viewer/camera for raycast calculation. -
private CitySystem m_CitySystem
Reference to the CitySystem used to access the city's Policy buffer to check whether the advanced pollution policy is active. -
private EntityQuery m_ActiveInfomodeQuery
An EntityQuery that matches active infomode entities (prefab + infomode data + infomode active) and either heatmap or building-status infoview types. Used to iterate active infoviews. -
private Entity m_AdvancedPollutionManagementPolicy
Cached Entity that represents the "Advanced Pollution Management" policy prefab. Initialized in OnCreate; if not found, OnCreate throws. -
private StringTooltip m_PollutionManagement
Reusable StringTooltip instance configured with icon/path for the policy effect tooltip. Used to show the localized message describing the policy effect. -
private RaycastResult m_RaycastResult
Cached RaycastResult used by the private raycastResult property. Stores the last raycast result to avoid repeated queries.
Properties
private RaycastResult raycastResult { get; set; }
A private property that lazily performs a raycast when the cached m_RaycastResult has no owner (Entity.Null) and a viewer (camera) is available. The getter:- Builds a RaycastInput using ToolRaycastSystem.CalculateRaycastLine(viewer.camera).
- Restricts the raycast to TypeMask.StaticObjects and CollisionMask (OnGround | Overground).
- Adds the input to m_RaycastSystem and retrieves results; if any result is present it caches the first result into m_RaycastResult.
- Returns the cached m_RaycastResult. The setter simply assigns m_RaycastResult.
Constructors
public CityPolicyTooltipSystem()
Default public constructor. The system performs its initialization in OnCreate rather than the constructor.
Methods
protected override void OnCreate() : System.Void
Initializes system references and queries:- Calls base.OnCreate().
- Obtains managed systems from base.World: PrefabSystem, ToolSystem, DefaultToolSystem, RaycastSystem, CameraUpdateSystem, CitySystem.
- Sets up m_ActiveInfomodeQuery to match active infomodes that are either heatmaps or building-status infoviews.
- Creates the m_PollutionManagement StringTooltip with path "cityPolicyEffect" and icon "Media/Game/Policies/AdvancedPollutionManagement.svg".
-
Iterates all Policy-prefab entities (PolicyData + CityModifierData) to find the policy prefab named "Advanced Pollution Management" and caches that Entity into m_AdvancedPollutionManagementPolicy. If not found, throws an Exception: "Advanced pollution management policy not found".
-
protected override void OnUpdate() : System.Void
Main runtime logic executed each frame when the system updates: - Early exits unless:
- the active tool is the default tool (m_ToolSystem.activeTool == m_DefaultTool),
- an active infoview exists (m_ToolSystem.activeInfoview != null),
- and m_ActiveInfomodeQuery is not empty.
- Resets the raycastResult to default and iterates matched infoview entities from m_ActiveInfomodeQuery.
- For InfoviewHeatmapData:
- If HeatmapData.GroundPollution:
- If Advanced Pollution Management is enabled and the raycast owner is a Building entity, and the building prefab's SpawnableBuildingData zone is Industrial, and the building prefab's PollutionData.m_GroundPollution > 0, then sets m_PollutionManagement.value to localized string "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectGroundPollution]" and calls AddMouseTooltip(m_PollutionManagement).
- If HeatmapData.AirPollution:
- Similar checks but tests PollutionData.m_AirPollution > 0 and uses localized "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectAirPolution]" (note: original key has a typo "AirPolution").
- For InfoviewBuildingStatusData with m_Type == BuildingStatusType.GarbageAccumulation:
- If Advanced Pollution Management is enabled and the raycast owner is a Building in an Industrial zone and that building has a GarbageProducer component, sets m_PollutionManagement.value to localized "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectGarbage]" and calls AddMouseTooltip(m_PollutionManagement).
-
The method relies on EntityManager methods: TryGetComponent, HasComponent, GetBuffer
(m_CitySystem.City, isReadOnly: true) and on prefab lookups via PrefabRef. -
private bool IsAdvancedPollutionManagementEnabled() : System.Boolean
Checks whether the "Advanced Pollution Management" policy is active for the current city: - Iterates the Policy buffer on the city entity from m_CitySystem.City.
- Compares item.m_Policy to the cached m_AdvancedPollutionManagementPolicy.
- Returns true if the matching Policy's flags contain PolicyFlags.Active.
- Returns false if there is no matching policy.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// The system initializes required systems and looks up the "Advanced Pollution Management" policy.
// Once running, when in a heatmap (air/ground) or garbage infoview and hovering an industrial building
// that produces the relevant pollution/garbage, the system will show a policy-effect tooltip.
}
Additional notes and tips: - The system depends on the "Advanced Pollution Management" policy prefab being present. OnCreate throws if that prefab cannot be located. - Performance: the system calls ToEntityArray(Allocator.Temp) to enumerate query matches and performs raycasts only when necessary (cached per frame). Be mindful of ephemeral allocations in tight update loops if adapting the code. - Localization keys used: - "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectGroundPollution]" - "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectAirPolution]" (preserves in-code key) - "DefaultTool.INFOMODE_TOOLTIP[PolicyEffectGarbage]" - The system requires the game's ECS types (PrefabRef, SpawnableBuildingData, PollutionData, ZoneData, GarbageProducer, Policy buffers) to be available and consistent with how prefabs/zones are authored.