Game.LineSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: InfoSectionBase
Summary:
LineSection is a UI info section used by the in-game information UI to display summary statistics for a transport route / transport line (Cities: Skylines 2). It gathers route data such as route length, number of stops, active vehicles on the route (cargo), and a simple usage ratio (vehicles / capacity), prepares tooltip tags, and exposes those values to the UI serialization routine (OnWriteProperties). The section is visible only when the selected entity has Route, TransportLine and RouteWaypoint components.
Fields
-
private float length { get; set; }
Stores the total length of the route in game units (float). Reset to 0 in Reset() and populated during OnProcess() via TransportUIUtils.GetRouteLength. -
private int stops { get; set; }
Number of stops on the route. Reset to 0 in Reset() and updated in OnProcess() via TransportUIUtils.GetStopCount. -
private int cargo { get; set; }
Number of vehicles currently assigned/active on the route (used here as "cargo"). Reset to 0 in Reset() and set to the vehicle count retrieved in OnProcess(). -
private float usage { get; set; }
A computed usage ratio representing vehicles / capacity. Reset to 0 in Reset() and computed in OnProcess() as (capacity > 0) ? (num / capacity) : 0.
Properties
protected override string group => "LineSection"
Identifies the UI group name for this section. Used by the Info UI system to categorize/identify the section.
(There are also the private auto-properties listed under Fields: length, stops, cargo, usage — they are not public API.)
Constructors
public LineSection()
Marked with [Preserve]. Default constructor used by the UI system to instantiate the section. No custom initialization logic beyond the attribute is present.
Methods
-
protected override void Reset()
Resets the section's internal state. Sets length = 0f, stops = 0, cargo = 0, usage = 0f. Called by the UI lifecycle to clear previous values before update/process. -
[Preserve] protected override void OnUpdate()
Called during the update phase of the UI lifecycle. This override sets the section visibility flag: -
base.visible is set to true only if the currently selected entity has the Route, TransportLine and RouteWaypoint components in the EntityManager. This prevents the section from showing unless the selected entity represents a transport route/line.
-
protected override void OnProcess()
Populates the section's values and prepares tooltip tags. Behavior: - Calls m_InfoUISystem.SetRoutesVisible() to ensure route UI is visible.
- Uses TransportUIUtils.GetRouteVehiclesCount(EntityManager, selectedEntity, ref num, ref capacity) to obtain the current vehicle count (num) and capacity for the route.
- Computes usage = (capacity > 0) ? (float)num / (float)capacity : 0f.
- Sets stops = TransportUIUtils.GetStopCount(EntityManager, selectedEntity).
- Sets length = TransportUIUtils.GetRouteLength(EntityManager, selectedEntity).
- Sets cargo = num.
-
Adds tooltip tag strings for CargoRoute and TransportLine to base.tooltipTags (via TooltipTags.CargoRoute.ToString() and TooltipTags.TransportLine.ToString()).
-
public override void OnWriteProperties(IJsonWriter writer)
Serializes the section properties to the provided IJsonWriter. Writes properties in this order: - "length" -> length (float)
- "stops" -> stops (int)
- "usage" -> usage (float)
- "cargo" -> cargo (int) This is used by the UI binding/serialization system to transfer section data to the UI layer.
Usage Example
Example showing how the section's processed values would be written to JSON after OnProcess runs. In actual game use, the UI framework calls OnUpdate/OnProcess and later OnWriteProperties.
// Pseudocode / illustrative (simplified):
var lineSection = new LineSection();
// The UI lifecycle will call Reset(), OnUpdate(), OnProcess() as appropriate.
// For demonstration, assume those were called and values populated.
var writer = someIJsonWriterImplementation; // IJsonWriter provided by the UI system
lineSection.OnWriteProperties(writer);
// Expected JSON output (example):
// {
// "length": 1234.56,
// "stops": 12,
// "usage": 0.75,
// "cargo": 9
// }
Notes and modding tips: - This section depends on EntityManager components: Route, TransportLine and RouteWaypoint. If you are creating a custom route entity or testing UI visibility, ensure those components are present on the selected entity. - The usage value is a simple ratio of current vehicle count to capacity as provided by TransportUIUtils.GetRouteVehiclesCount; check or extend that utility if you need different occupancy metrics. - Tooltip tags added here (CargoRoute, TransportLine) are strings derived from the TooltipTags enum; other systems read these tags to show context-sensitive tooltips.