Skip to content

Game.UI.Tooltip.TempXPTooltipSystem

Assembly: Game (inferred from namespace)
Namespace: Game.UI.Tooltip

Type: class

Base: TooltipSystemBase

Summary:
TempXPTooltipSystem is an ECS system (compiler-generated) that displays a small "xp" mouse tooltip while the player is placing temporary prefabs (Temp components) in the world. It inspects temporary placement preview entities (Temp + PrefabRef) and sums XP rewards from the associated prefab data (PlaceableObjectData and ServiceUpgradeData) when the preview would create a new object (TempFlags.Create and Temp.m_Original == Entity.Null). If any XP is found, it shows an IntTooltip with the total XP. The system avoids running in the editor action mode and when there are no locked milestone prefabs present (m_LockedMilestoneQuery). It uses component lookups and chunk iteration to perform the read-only checks.


Fields

  • private struct TypeHandle __TypeHandle
    TypeHandle is a private nested struct that caches ComponentLookup and ComponentTypeHandle instances required by the system:
  • ReadOnly ComponentLookup
  • ReadOnly ComponentLookup
  • ReadOnly ComponentLookup
  • ReadOnly ComponentTypeHandle
  • ReadOnly ComponentTypeHandle It provides __AssignHandles(ref SystemState) which initializes these handles via state.GetComponentLookup / state.GetComponentTypeHandle. This is used to get fast access to component data in OnUpdate.

  • private ToolSystem m_ToolSystem
    Reference to the game's ToolSystem (retrieved via World.GetOrCreateSystemManaged in OnCreate). Used to check the current action mode (to avoid showing the tooltip in editor mode).

  • private EntityQuery m_TempQuery
    EntityQuery that selects preview/temp entities. Constructed as GetEntityQuery(ComponentType.ReadOnly(), ComponentType.ReadOnly(), ComponentType.Exclude). This query is required for update (RequireForUpdate) and iterated over in OnUpdate to inspect Temp + PrefabRef archetype chunks.

  • private EntityQuery m_LockedMilestoneQuery
    EntityQuery describing prefabs that are locked milestones (PrefabData + MilestoneData + Locked) and excluding Deleted and Temp. The system uses this query to early-exit when the query is empty (no locked milestones), preventing tooltip logic when irrelevant.

  • private IntTooltip m_Tooltip
    An IntTooltip instance preconfigured in OnCreate:

  • path = "xp"
  • icon = "Media/Game/Icons/Trophy.svg"
  • unit = "xp"
  • signed = true
  • color = TooltipColor.Success This object is updated with the computed XP total and passed to AddMouseTooltip when there is a positive value.

Properties

  • None (no public properties).
    (The class is a compiler-generated system and does not expose public properties.)

Constructors

  • public TempXPTooltipSystem()
    Default parameterless constructor. The class is marked [CompilerGenerated] and the constructor is marked [Preserve] in source; initialization of queries and handles occurs in OnCreate / OnCreateForCompiler rather than the ctor.

Methods

  • [Preserve] protected override void OnCreate()
    Initializes the system:
  • Calls base.OnCreate().
  • Acquires ToolSystem (m_ToolSystem).
  • Builds m_TempQuery for Temp + PrefabRef previews (excluding Deleted).
  • Builds m_LockedMilestoneQuery for locked milestone prefabs (excludes Deleted/Temp).
  • Configures m_Tooltip (path, icon, unit, signed, color).
  • Calls RequireForUpdate(m_TempQuery) so the system runs only when temp previews exist.

  • [Preserve] protected override void OnUpdate()
    Main runtime logic. Steps:

  • Early return if the tool action mode is Editor or if m_LockedMilestoneQuery.IsEmpty.
  • Calls CompleteDependency() to ensure previous jobs are complete (reads component data synchronously).
  • Retrieves the component lookups via InternalCompilerInterface.GetComponentLookup and component type handles via InternalCompilerInterface.GetComponentTypeHandle using the cached __TypeHandle fields.
  • Iterates over archetype chunks from m_TempQuery (ToArchetypeChunkArray with Allocator.TempJob), then for each chunk reads arrays of Temp and PrefabRef components.
  • For each Temp element that has TempFlags.Create set and has Temp.m_Original == Entity.Null:
    • If the referenced prefab has PlaceableObjectData and does not have PlacedSignatureBuildingData, add PlaceableObjectData.m_XPReward to the running total.
    • If the referenced prefab has ServiceUpgradeData and Temp.m_Original == Entity.Null, add ServiceUpgradeData.m_XPReward to the running total.
  • After iteration, if the total XP (num) > 0, set m_Tooltip.value = num and call AddMouseTooltip(m_Tooltip) to show the tooltip.
  • Disposes the temporary archetype chunk array in a finally block.

Notes: - The logic ensures XP is only counted for new creations (TempFlags.Create and no original) and avoids counting signature-built prefabs (PlacedSignatureBuildingData).

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler helper used during code generation. In this implementation it only creates and disposes an EntityQueryBuilder(Allocator.Temp). This pattern is commonly generated by the compiler for systems; real query initialization is performed elsewhere (OnCreate / OnCreateForCompiler).

  • protected override void OnCreateForCompiler()
    Called by generated code / compiler pathways to wire queries and handles: calls base.OnCreateForCompiler(), __AssignQueries(ref base.CheckedStateRef), and __TypeHandle.__AssignHandles(ref base.CheckedStateRef).

  • private void TypeHandle.__AssignHandles(ref SystemState state)
    Method of the nested TypeHandle struct: initializes the cached lookups and type handles via state.GetComponentLookup(isReadOnly: true) and state.GetComponentTypeHandle(isReadOnly: true). Used by OnCreateForCompiler to prepare handles for runtime use.


Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    m_ToolSystem = base.World.GetOrCreateSystemManaged<ToolSystem>();
    m_TempQuery = GetEntityQuery(ComponentType.ReadOnly<Temp>(), ComponentType.ReadOnly<PrefabRef>(), ComponentType.Exclude<Deleted>());
    m_LockedMilestoneQuery = GetEntityQuery(new EntityQueryDesc
    {
        All = new ComponentType[3]
        {
            ComponentType.ReadOnly<PrefabData>(),
            ComponentType.ReadOnly<MilestoneData>(),
            ComponentType.ReadOnly<Locked>()
        },
        None = new ComponentType[2]
        {
            ComponentType.ReadOnly<Deleted>(),
            ComponentType.ReadOnly<Temp>()
        }
    });

    m_Tooltip = new IntTooltip
    {
        path = "xp",
        icon = "Media/Game/Icons/Trophy.svg",
        unit = "xp",
        signed = true,
        color = TooltipColor.Success
    };

    RequireForUpdate(m_TempQuery);
}

Notes and tips for modders: - The system relies on Temp and PrefabRef components present on preview entities when the player is placing or creating items — it only sums XP for creations (not edits). - If adding new prefab data types that grant XP, ensure those components are checked here (or add a separate lookup) so the tooltip will include them. - Be careful when changing TempFlags or Temp semantics: the check for Temp.m_Original == Entity.Null indicates "new create" semantics. - The system performs read-only access to component data and uses chunk iteration — follow the same patterns for performance-sensitive UI overlay systems.