Skip to content

Game.UI.Tooltip.RouteToolTooltipSystem

Assembly:
Assembly-CSharp.dll

Namespace:
Game.UI.Tooltip

Type:
class

Base:
TooltipSystemBase

Summary:
RouteToolTooltipSystem is a Tooltip system used by the Route tool. When the Route tool is active it inspects temporary "preview" entities (Temp components) for transport stops and routes, resolves their original entities, and adds a mouse tooltip showing the entity name and an icon. It queries for temporary Route and TransportStop entities (excluding Deleted), uses ImageSystem to fetch icons and NameSystem (via NameTooltip) to bind and display names. The system is driven by the RouteToolSystem.tooltip state and only adds relevant tooltips for the various route editing modes (create, insert, move, merge, remove, etc.). The system uses temporary NativeArray allocations (Allocator.TempJob) and disposes them in a finally block.


Fields

  • private ToolSystem m_ToolSystem
    Reference to the global ToolSystem; used to check the currently active tool.

  • private RouteToolSystem m_RouteTool
    Reference to the RouteToolSystem instance; used to read the current tooltip state (RouteToolSystem.Tooltip).

  • private ImageSystem m_ImageSystem
    Reference to the ImageSystem; used to obtain an instance icon for the original entity behind a Temp.

  • private NameSystem m_NameSystem
    Reference to the NameSystem; used as the nameBinder for NameTooltip instances.

  • private EntityQuery m_TempRouteQuery
    EntityQuery that matches entities with Temp and Route components and excludes Deleted. Used to find temporary route-preview entities for which route names/icons should be shown.

  • private EntityQuery m_TempStopQuery
    EntityQuery that matches entities with Temp and TransportStop components and excludes Deleted. Used to find temporary transport-stop-preview entities for which stop names/icons should be shown.

  • private NameTooltip m_StopName
    NameTooltip instance configured for stop tooltips (path: "routeToolStopName", nameBinder: m_NameSystem). Populated with icon and entity when adding a stop tooltip.

  • private NameTooltip m_RouteName
    NameTooltip instance configured for route tooltips (path: "routeToolRouteName", nameBinder: m_NameSystem). Populated with icon and entity when adding a route tooltip.

Properties

  • None. This type does not declare public properties.

Constructors

  • public RouteToolTooltipSystem()
    Default constructor. Marked with [Preserve] attribute in source. No special logic in the constructor; initialization happens in OnCreate().

Methods

  • protected override void OnCreate()
    Initializes required systems (ToolSystem, RouteToolSystem, ImageSystem, NameSystem), sets up two EntityQueries:
  • m_TempRouteQuery: matches Temp + Route, excludes Deleted.
  • m_TempStopQuery: matches Temp + TransportStop, excludes Deleted. Also constructs two NameTooltip instances (m_StopName and m_RouteName) and binds them to m_NameSystem. Marked with [Preserve] in source.

  • protected override void OnUpdate()
    Runs each frame the system is updated. If the active tool is the RouteToolSystem and its tooltip state is not RouteToolSystem.Tooltip.None, this method branches on the tooltip state and calls TryAddStopName() and/or TryAddRouteName() accordingly:

  • For CreateRoute, AddWaypoint, CompleteRoute: TryAddStopName().
  • For CreateOrModify and many edit operations: TryAddStopName() and TryAddRouteName().
  • For default/other tooltip states: TryAddRouteName().

  • public void TryAddStopName()
    If there are any matching Temp + TransportStop temporary entities, this method copies their Temp components to a NativeArray (Allocator.TempJob), iterates through them, and for the first Temp whose m_Original is not Entity.Null:

  • Calls AddMouseTooltip(m_StopName).
  • Sets m_StopName.icon to the instance icon resolved by m_ImageSystem.GetInstanceIcon(temp.m_Original).
  • Sets m_StopName.entity to temp.m_Original. It ensures the NativeArray is disposed in a finally block.

  • public void TryAddRouteName()
    Same pattern as TryAddStopName but for Temp + Route entities and using m_RouteName. Copies Temp components with Allocator.TempJob, finds the first with a non-null m_Original, adds the mouse tooltip, sets icon and entity, and disposes the NativeArray in a finally block.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // get or create required systems
    m_ToolSystem = World.GetOrCreateSystemManaged<ToolSystem>();
    m_RouteTool = World.GetOrCreateSystemManaged<RouteToolSystem>();
    m_ImageSystem = World.GetOrCreateSystemManaged<ImageSystem>();
    m_NameSystem = World.GetOrCreateSystemManaged<NameSystem>();

    // build EntityQueries to match temporary preview entities
    m_TempRouteQuery = GetEntityQuery(new EntityQueryDesc {
        All = new ComponentType[] {
            ComponentType.ReadOnly<Temp>(),
            ComponentType.ReadOnly<Route>()
        },
        None = new ComponentType[] { ComponentType.ReadOnly<Deleted>() }
    });

    m_TempStopQuery = GetEntityQuery(new EntityQueryDesc {
        All = new ComponentType[] {
            ComponentType.ReadOnly<Temp>(),
            ComponentType.ReadOnly<TransportStop>()
        },
        None = new ComponentType[] { ComponentType.ReadOnly<Deleted>() }
    });

    // prepare NameTooltip instances for reuse
    m_StopName = new NameTooltip {
        path = "routeToolStopName",
        nameBinder = m_NameSystem
    };
    m_RouteName = new NameTooltip {
        path = "routeToolRouteName",
        nameBinder = m_NameSystem
    };
}

Notes and tips: - The system relies on Temp.m_Original to point to the real in-world entity. If Temp.m_Original is Entity.Null no tooltip will be created for that temporary. - NativeArray allocations use Allocator.TempJob and are disposed in a finally block; keep the same pattern to avoid leaks. - The AddMouseTooltip(NameTooltip) method (inherited from TooltipSystemBase) is used to queue the tooltip to be shown; the NameTooltip instance is reused and its fields (icon, entity) are overwritten each frame as needed.