Skip to content

Game.UI.Tooltip.HomelessTooltipSystem

Assembly:
Namespace: Game.UI.Tooltip

Type: class

Base: TooltipSystemBase

Summary:
A Unity ECS system that provides a mouse tooltip showing the number of homeless citizens associated with a homeless shelter building when the relevant infomode is active. It listens for tool raycast hits, verifies the hit building is a homeless shelter, iterates renter/household buffers to count living homeless citizens, and adds an IntTooltip to the mouse when the count is greater than zero. The system requires UI infoview configuration to exist and uses PrefabSystem to check whether the homeless infomode is currently active.


Fields

  • private IntTooltip m_HomelessCountTooltip
    Holds the tooltip instance used to display the homeless count (path "HomelessCount", localized label, integer unit). Its value is updated each update when an eligible building is under the mouse.

  • private ToolRaycastSystem m_ToolRaycastSystem
    Reference to the ToolRaycastSystem used to obtain the current raycast result (what the user is pointing at).

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to resolve the UI infomode prefab and check whether the infomode is active by checking components on the prefab's entity.

  • private EntityQuery m_ConfigQuery
    An EntityQuery targeting UIInfoviewsConfigurationData to ensure the system only updates when the UI infoviews configuration exists. This query is required for update in OnCreate.

Properties

  • This type defines no public properties.

Constructors

  • public HomelessTooltipSystem()
    Default constructor. The system marks methods with [Preserve] in the original source; initialization logic is performed in the overridden OnCreate.

Methods

  • protected override void OnCreate() : System.Void
    Initializes required subsystem references and the tooltip instance:
  • Retrieves ToolRaycastSystem and PrefabSystem from the world.
  • Creates an EntityQuery for UIInfoviewsConfigurationData and calls RequireForUpdate(m_ConfigQuery).
  • Instantiates and configures m_HomelessCountTooltip (path, label, unit). This ensures the system only runs when the infoviews configuration is present.

  • private bool IsInfomodeActivated() : System.Boolean
    Checks whether the homeless infomode is currently active by:

  • Getting the singleton entity from m_ConfigQuery.
  • Using m_PrefabSystem.TryGetPrefab to obtain UIInfoviewsConfigurationPrefab.
  • Getting the prefab entity referenced by m_HomelessInfomodePrefab and checking for the InfomodeActive component on that entity. Returns true when the homeless infomode is active; false otherwise.

  • protected override void OnUpdate() : System.Void
    Main update loop:

  • Returns immediately if the homeless infomode is not activated.
  • Calls CompleteDependency() to ensure any pending jobs are finished before reading ECS buffers.
  • Resets m_HomelessCountTooltip.value to 0.
  • If the ToolRaycastSystem reports a hit and the hit owner is a homeless shelter (BuildingUtils.IsHomelessShelterBuilding), tries to read the owner's Renter buffer.
  • Iterates renters; for each renter, checks for HomelessHousehold component on the renter's household entity and reads its HouseholdCitizen buffer.
  • Counts each HouseholdCitizen whose associated citizen is not dead (via CitizenUtils.IsDead).
  • If the final count is > 0, calls AddMouseTooltip(m_HomelessCountTooltip) to show the tooltip.

Notes: - The method uses ECS DynamicBuffer reads and component presence checks and therefore calls CompleteDependency() before accessing managed data. - It relies on BuildingUtils, CitizenUtils, and specific components (Renter, HouseholdCitizen, HomelessHousehold) to compute the count.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolRaycastSystem = base.World.GetOrCreateSystemManaged<ToolRaycastSystem>();
    m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
    m_ConfigQuery = GetEntityQuery(ComponentType.ReadOnly<UIInfoviewsConfigurationData>());
    m_HomelessCountTooltip = new IntTooltip
    {
        path = "HomelessCount",
        label = LocalizedString.Id("Infoviews.INFOVIEW[HomelessCount]"),
        unit = "integer"
    };
    RequireForUpdate(m_ConfigQuery);
}

Additional notes: - This system only adds the tooltip while the homeless infomode is active and while the cursor is over a building recognized as a homeless shelter. - If you extend or modify this system, ensure CompleteDependency() is used before accessing ECS buffers from the main thread.