Game.UI.InGame.TransportInfoviewUISystem
Assembly:
Assembly-CSharp
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoviewUISystemBase
Summary:
TransportInfoviewUISystem is a UI system that provides transport-related summary data (passenger and cargo summaries) to the infoview UI. It collects data from transport lines, prefab unlock state, and city statistics, serializes those summaries into JSON via bindings, and exposes whether the system is active/modified for the UI to react to. The class also contains two small readonly structs (PassengerSummary and CargoSummary) used to format each summary entry for serialization.
Fields
-
private const string kGroup = "transportInfo"
Stores the binding group name used for the RawValueBinding. Used when registering binding keys for the UI. -
private UnlockSystem m_UnlockSystem
Reference to the game's UnlockSystem. Used to query whether a particular transport prefab (unlockable) is locked. -
private PrefabSystem m_PrefabSystem
Reference to the PrefabSystem. Used to get prefab Entities for unlockable items and to obtain the UI transport configuration prefab. -
private PrefabUISystem m_PrefabUISystem
Reference to the PrefabUISystem. Used to bind prefab requirements when writing summary JSON. -
private CityStatisticsSystem m_CityStatisticsSystem
Reference to city statistics for retrieving statistic values (tourists, citizens, cargo counts, etc.) used by the summaries. -
private EntityQuery m_ConfigQuery
EntityQuery used to find the UI transport configuration entity (UITransportConfigurationData). Populated in OnCreate. -
private EntityQuery m_LineQuery
EntityQuery that matches transport lines (Route, TransportLine, RouteWaypoint, PrefabRef) and excludes Deleted and Temp. Used to gather the set of active lines. -
private EntityQuery m_ModifiedLineQuery
EntityQuery similar to m_LineQuery but filtered to entities with Created/Deleted/Updated flags (and excluding Temp). Used to determine if lines were modified (to set Modified property). -
private RawValueBinding m_Summaries
The RawValueBinding instance registered to the UI binding system. Responsible for serializing transport summaries under the group "transportInfo" and key "summaries". -
private UITransportConfigurationPrefab m_Config
Cached configuration prefab providing arrays of UITransportSummaryItem for passenger and cargo summaries (icons, types, which stats to show, etc.). Set after game load from the PrefabSystem.
Properties
-
protected override bool Active
Returns true if base.Active is true OR the registered summaries binding is active (m_Summaries.active). The system is considered active if the base system is active, or if the summaries binding has been activated for the UI. Note: the getter checks base.Active first, then m_Summaries.active. -
protected override bool Modified
Returns true when m_ModifiedLineQuery is not empty (i.e., when some transport line entities have been created/updated/deleted). Used for change detection so the UI can refresh only when needed.
Constructors
public TransportInfoviewUISystem()
Default public constructor. No custom initialization beyond the base constructor; the system initializes its references and queries in OnCreate.
Methods
protected override void OnCreate()
Initializes subsystem references and entity queries and registers the RawValueBinding for transport summaries. Specifically:- Retrieves UnlockSystem, PrefabSystem, PrefabUISystem, and CityStatisticsSystem from the World.
- Builds m_ConfigQuery, m_LineQuery, and m_ModifiedLineQuery EntityQuery instances to match transport configuration and transport line entities.
-
Adds a RawValueBinding named "transportInfo" / "summaries" mapped to BindSummaries. Important: Runs once during system creation and prepares everything needed for binding and updates.
-
protected override void OnGameLoaded(Context serializationContext)
Called after a game is loaded. If the system is enabled, it fetches and caches the UITransportConfigurationPrefab (m_Config) from the PrefabSystem using m_ConfigQuery. This prefab contains the arrays that drive which summary items to present. -
protected override void PerformUpdate()
Called each update tick for the UI system. Currently calls m_Summaries.Update() to ensure the binding serializes fresh data when requested. -
private void BindSummaries(IJsonWriter writer)
The core serialization routine invoked by the RawValueBinding. It: - Uses TransportUIUtils.GetSortedLines to obtain a NativeArray
representing sorted transport lines via m_LineQuery and the prefab system. - Writes a type wrapper and then serializes two arrays:
- passengerSummaries: iterates m_Config.m_PassengerSummaryItems and for each item constructs a PassengerSummary populated with prefab Entity, id (TransportType name), icon, locked state, lineCount (counted when m_ShowLines is true), and tourist/citizen counts from CityStatisticsSystem. Each PassengerSummary.Write serializes the item and calls PrefabUISystem.BindPrefabRequirements to serialize prefab requirements.
- cargoSummaries: similarly iterates m_Config.m_CargoSummaryItems and constructs CargoSummary entries with cargo-specific counts and line counts (optionally counting cargo lines).
-
Disposes of or relies on the NativeArray lifetime as provided by TransportUIUtils (the method used returns a NativeArray usage pattern expected by the game). Notes: BindSummaries performs potentially expensive operations (NativeArray creation, enumeration, calling CountLines and statistics retrieval). It's intended for UI serialization and should be kept efficient.
-
(Nested) PassengerSummary.Write(PrefabUISystem prefabUISystem, IJsonWriter writer)
Serializes the passenger summary fields: id, icon, locked, lineCount, touristCount, citizenCount, and writes prefab requirements by calling PrefabUISystem.BindPrefabRequirements. -
(Nested) CargoSummary.Write(PrefabUISystem prefabUISystem, IJsonWriter writer)
Serializes the cargo summary fields: id, icon, locked, lineCount, cargoCount, and writes prefab requirements similarly.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Acquire subsystems
m_UnlockSystem = base.World.GetOrCreateSystemManaged<UnlockSystem>();
m_PrefabSystem = base.World.GetOrCreateSystemManaged<PrefabSystem>();
m_PrefabUISystem = base.World.GetOrCreateSystemManaged<PrefabUISystem>();
m_CityStatisticsSystem = base.World.GetOrCreateSystemManaged<CityStatisticsSystem>();
// Build entity queries for configuration and transport lines
m_ConfigQuery = GetEntityQuery(ComponentType.ReadOnly<UITransportConfigurationData>());
m_LineQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
ComponentType.ReadOnly<Route>(),
ComponentType.ReadWrite<TransportLine>(),
ComponentType.ReadOnly<RouteWaypoint>(),
ComponentType.ReadOnly<PrefabRef>()
},
None = new ComponentType[]
{
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Temp>()
}
});
m_ModifiedLineQuery = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[]
{
ComponentType.ReadOnly<Route>(),
ComponentType.ReadWrite<TransportLine>(),
ComponentType.ReadOnly<RouteWaypoint>(),
ComponentType.ReadOnly<PrefabRef>()
},
Any = new ComponentType[]
{
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Updated>()
},
None = new ComponentType[] { ComponentType.ReadOnly<Temp>() }
});
// Register binding used by the UI to get serialized summaries
AddBinding(m_Summaries = new RawValueBinding("transportInfo", "summaries", BindSummaries));
}
Notes and implementation tips: - The BindSummaries method depends on m_Config being populated after game load; ensure OnGameLoaded sets m_Config by fetching UITransportConfigurationPrefab from PrefabSystem. - Because BindSummaries uses NativeArray and entity queries, be mindful of allocations and call frequency — use Modified property and query filters to avoid unnecessary updates. - Prefab requirements are written by PrefabUISystem.BindPrefabRequirements; ensure that system is available before binding.