Skip to content

Game.UI.InGame.LinesSection

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
LinesSection is an InfoSection UI component used by the in-game Info panel to show transport "lines" (routes) and waiting passengers for a selected entity. It runs an ECS job (LinesJob) to traverse connected route buffers, subobjects and waiting passenger components to determine whether the selected entity supports routes, whether it has waiting passengers, collect the count of waiting passengers and gather referenced route/line entities. The section exposes the list of lines and passenger count to the UI (via OnWriteProperties) and allows toggling line active state via the TransportationOverviewUISystem. The class uses native containers (NativeArray, NativeList) allocated with Allocator.Persistent and disposes them in OnDestroy. It also exposes a group name ("LinesSection") and supports display for outside connections.


Fields

  • private TransportationOverviewUISystem m_TransportationOverviewUISystem
    Holds a reference to the TransportationOverviewUISystem used to change line states (activate/deactivate lines) and to interact with the transportation overview UI.

  • private NativeArray<bool> m_BoolResult
    NativeArray of length 2 used by the scheduled LinesJob to return two booleans: index 0 = whether the selected entity supports routes (has lines), index 1 = whether the selected entity or connected waypoints have waiting passengers.

  • private NativeArray<int> m_PassengersResult
    NativeArray of length 1 used by LinesJob to return the total count of waiting passengers gathered during traversal.

  • private NativeList<Entity> m_LinesResult
    NativeList used by LinesJob to accumulate referenced line/route entities discovered while traversing connected routes and waypoints.

  • private TypeHandle __TypeHandle
    Struct that holds ComponentLookup and BufferLookup handles used by the ECS job. These are assigned in OnCreateForCompiler via __AssignHandles.

  • private NativeList<Entity> lines { get; set; }
    Private property-backed native list that is populated in OnProcess from m_LinesResult and later exposed to OnWriteProperties for JSON output.

  • private enum Result (nested)
    Internal enum used by the class to label results (HasRoutes, HasPassengers). Used for readability inside code paths.

  • private struct LinesJob : IJob (nested)
    Burst-compiled IJob implementation that performs the ECS traversal and fills m_BoolResult, m_LinesResult and m_PassengersResult. Uses ComponentLookup, ComponentLookup, BufferLookup, BufferLookup.

  • private struct TypeHandle (nested)
    Container for read-only ComponentLookup/BufferLookup handles (Owner, WaitingPassengers, SubObject buffer, ConnectedRoute buffer). Provides __AssignHandles to initialize these lookups from a SystemState.

Properties

  • protected override string group { get; }
    Returns the UI group name for this section. Value: "LinesSection". Used by bindings and UI grouping.

  • protected override bool displayForOutsideConnections { get; }
    Overrides base to indicate this section should be displayed for outside connections. Value: true.

  • private NativeList<Entity> lines { get; set; }
    Property backed native list of line entities. It is cleared in Reset() and populated in OnProcess().

Constructors

  • public LinesSection()
    Default constructor. Marked with [Preserve] on the real class usage; the constructor itself performs no custom initialization beyond base construction. Actual initialization of native containers occurs in OnCreate().

Methods

  • protected override void Reset()
    Clears the lines property list and the m_LinesResult list. Called by the base InfoSection lifecycle to reset state between uses.

  • protected override void OnCreate()
    Initializes the UI section. Allocates persistent native containers:

  • m_BoolResult = new NativeArray(2, Allocator.Persistent)
  • m_PassengersResult = new NativeArray(1, Allocator.Persistent)
  • m_LinesResult = new NativeList(Allocator.Persistent)
  • lines = new NativeList(Allocator.Persistent) Also obtains the TransportationOverviewUISystem instance from base.World and adds a TriggerBinding for toggle actions (group, "toggle", OnToggle).

  • protected override void OnDestroy()
    Disposes persistent native containers (lines, m_LinesResult, m_PassengersResult, m_BoolResult) and calls base.OnDestroy(). Ensure proper disposal to avoid leaks.

  • protected override void OnUpdate()
    Schedules and completes the LinesJob (IJob) using the base.Dependency JobHandle. The job is given component/buffer lookups pulled via InternalCompilerInterface.GetComponentLookup / GetBufferLookup using the TypeHandle and base.CheckedStateRef. After job completion, sets base.visible = m_BoolResult[0] || m_BoolResult[1] to show/hide the UI section depending on results.

  • protected override void OnProcess()
    Called when the section is being processed for UI rendering: calls m_InfoUISystem.SetRoutesVisible(), copies entities from m_LinesResult into lines, and adds tooltip tags: CargoRoute, TransportLine, TransportStop.

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes JSON properties that the UI layer consumes:

  • "hasLines": m_BoolResult[0]
  • "lines": array of objects with fields:
    • "name": written using m_NameSystem.BindName(writer, lines[i])
    • "color": writes Game.Routes.Color.m_Color if present, otherwise white
    • "entity": entity id
    • "active": boolean indicating whether the route is active (RouteUtils.CheckOption against RouteOption.Inactive)
  • "hasPassengers": m_BoolResult[1]
  • "passengers": m_PassengersResult[0]

  • private void OnToggle(Entity entity, bool state)
    Called by UI actions to toggle a line's active state. Calls m_TransportationOverviewUISystem.SetLineState(entity, state) and requests an info UI update (m_InfoUISystem.RequestUpdate()).

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated placeholder that creates an EntityQueryBuilder and disposes it. Used by OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Called by generated/compiled code to assign queries and call the TypeHandle.__AssignHandles with the base.CheckedStateRef so the job has valid lookup handles.

  • LinesJob.Execute() / CheckEntity(Entity, ref bool, ref bool, ref int) (nested private methods inside LinesJob)
    LinesJob.Execute sets up supportRoutes/supportPassengers/passengerCount, calls CheckEntity for the selected entity, and writes results to the provided native containers. CheckEntity traverses ConnectedRoute buffers, checks WaitingPassengers on waypoints and entities, collects Owner components' Owner entity IDs into m_LinesResult (avoiding duplicates), and recursively inspects SubObject buffers.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // get the transportation overview system to control line states
    m_TransportationOverviewUISystem = base.World.GetOrCreateSystemManaged<TransportationOverviewUISystem>();

    // allocate native containers used by the scheduled job
    m_BoolResult = new NativeArray<bool>(2, Allocator.Persistent); // [hasLines, hasPassengers]
    m_PassengersResult = new NativeArray<int>(1, Allocator.Persistent);
    m_LinesResult = new NativeList<Entity>(Allocator.Persistent);
    lines = new NativeList<Entity>(Allocator.Persistent);

    // bind toggle events from the UI (group "LinesSection", toggle action -> OnToggle)
    AddBinding(new TriggerBinding<Entity, bool>(group, "toggle", OnToggle));
}

Notes and tips: - The class uses Burst-compiled IJob (LinesJob) and read-only ComponentLookup/BufferLookup handles — make sure TypeHandle.__AssignHandles is called before scheduling the job (OnCreateForCompiler does this). - Native containers are allocated with Allocator.Persistent and must be disposed in OnDestroy to avoid memory leaks. - OnUpdate synchronously completes the job (.Complete()) before using results; if converting to asynchronous scheduling, ensure proper dependency handling and not to access native results before job completion.