Skip to content

Game.UI.InGame.TransportationOverviewUISystem

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

Type: class

Base: UISystemBase

Summary:
TransportationOverviewUISystem is the UI system responsible for the Transportation Overview panel. It binds transport line data, transport type lists (passenger/cargo), and UI triggers to game entity operations: creating/removing route components, renaming lines, changing colors, setting policies/schedules, toggling visibility/highlight, and updating the UI. It uses EntityQueries to read transport lines and an EndFrameBarrier to enqueue entity commands that must be applied at the end of the frame. The system also integrates with NameSystem, PrefabSystem, UnlockSystem and various UI helper systems to present and modify transport-related data for Cities: Skylines 2 modding.


Fields

  • private const string kGroup = "transportationOverview"
    Identifier used for UI binding group names.

  • private NameSystem m_NameSystem
    Reference to the NameSystem used for getting/setting custom names and virtual keyboard name binding.

  • private UnlockSystem m_UnlockSystem
    Reference to UnlockSystem used to check whether certain transport prefabs/types are unlocked.

  • private PrefabSystem m_PrefabSystem
    Reference to PrefabSystem used to obtain prefabs and prefab-related entity references.

  • private PrefabUISystem m_PrefabUISystem
    Used to write prefab UI data (icons, etc.) into the JSON writer when binding types/lines.

  • private PoliciesUISystem m_PoliciesUISystem
    Used to set route-related policies (e.g., Out of Service, Day/Night route policies).

  • private SelectedInfoUISystem m_SelectedInfoUISystem
    Used to change the selected entity in the UI (selecting a line shows its info).

  • private EndFrameBarrier m_EndFrameBarrier
    Barrier used to obtain an EntityCommandBuffer to enqueue entity changes that should be executed after the current frame's simulation.

  • private Entity m_OutOfServicePolicy
    Entity reference (prefab) for the out-of-service policy used to toggle a line's active state.

  • private Entity m_DayRoutePolicy
    Entity reference (prefab) for the "day" schedule policy.

  • private Entity m_NightRoutePolicy
    Entity reference (prefab) for the "night" schedule policy.

  • private EntityQuery m_ConfigQuery
    Query used to fetch the UITransportConfigurationData prefab entity.

  • private EntityQuery m_LineQuery
    Query selecting all active transport line route entities (Route, TransportLine, RouteWaypoint, PrefabRef) excluding Deleted and Temp.

  • private EntityQuery m_ModifiedLineQuery
    Similar to m_LineQuery but matches lines that have been Created/Deleted/Updated (used to detect changes and refresh UI).

  • private EntityQuery m_UnlockQuery
    Query for Unlock components to check unlocked prefabs.

  • private EntityArchetype m_ColorUpdateArchetype
    Archetype used to create a transient entity that signals color updates (contains Game.Common.Event and ColorUpdated).

  • private RawValueBinding m_TransportLines
    JSON binding for the list of transport lines; writes line list into UI.

  • private RawValueBinding m_PassengerTypes
    JSON binding for passenger transport types.

  • private RawValueBinding m_CargoTypes
    JSON binding for cargo transport types.

  • private ValueBinding<string> m_SelectedCargoType
    Value binding to store the currently selected cargo transport type in the UI.

  • private ValueBinding<string> m_SelectedPassengerType
    Value binding to store the currently selected passenger transport type in the UI.

  • private UITransportConfigurationPrefab m_Config
    Cached transport UI configuration prefab (contains icons, available types, and policy references).

  • private UIUpdateState m_UpdateState
    Internal helper to throttle/force UI updates. Used so the UI doesn't refresh every frame unnecessarily.

Properties

  • public override GameMode gameMode => GameMode.Game
    The system runs in normal Game mode. This override indicates the intended GameMode for this UISystem.

Constructors

  • public TransportationOverviewUISystem()
    Default constructor (empty). Initialization occurs in OnCreate.

Methods

  • protected override void OnCreate()
    Initializes system references (NameSystem, UnlockSystem, PrefabSystem, other UI systems) and entity queries, creates archetypes, and registers all UI bindings and triggers:
  • Registers RawValueBindings for "lines", "passengerTypes", "cargoTypes"
  • Registers ValueBindings for selected types
  • Registers TriggerBindings for delete, select, setColor, rename, setActive, show/hide/toggle, setSchedule, resetVisibility, setSelectedPassengerType, setSelectedCargoType
  • Creates UIUpdateState for controlling updates This method prepares everything needed for the UI to read entity data and request entity changes.

  • private string GetInitialSelectedType()
    Chooses an initial selected transport type for the cargo selector by iterating m_Config.m_CargoLineTypes and picking the first unlocked type; falls back to TransportType.None if none unlocked.

  • private void SetSelectedPassengerType(string type)
    Updates m_SelectedPassengerType binding with the provided string (selected passenger transport type).

  • private void SetSelectedCargoType(string type)
    Updates m_SelectedCargoType binding with the provided string (selected cargo transport type).

  • protected override void OnGameLoaded(Context serializationContext)
    Called when a save/game is loaded. If the system is enabled, it:

  • Loads UITransportConfigurationPrefab from m_ConfigQuery
  • Resolves policy prefabs to Entity references (out-of-service, day, night)
  • Forces update of Cargo/Passenger types and lines
  • Initializes selected cargo type (GetInitialSelectedType)

  • protected override void OnUpdate()
    Regular update that refreshes the transport lines binding if either:

  • any lines have been modified (m_ModifiedLineQuery not empty), or
  • the UIUpdateState indicates an update (m_UpdateState.Advance()) Also checks if any RouteData prefab has been unlocked and triggers update of types list if so.

  • public void RequestUpdate()
    Forces the UIUpdateState to refresh on its next check; used when an operation changes data that should be reflected in the UI.

  • private void DeleteLine(Entity entity)
    Marks the given route entity as Deleted by adding a Deleted component via an EndFrameBarrier command buffer. Checks existence first.

  • private void SelectLine(Entity entity)
    Sets the selected entity in SelectedInfoUISystem so the UI shows the selected line's info. Checks existence first.

  • private void SetLineColor(Entity entity, Color32 color)
    Sets the line's color by:

  • writing a Game.Routes.Color component to the line entity
  • iterating its RouteVehicle buffer (if present) and adding Color components to each vehicle entity
  • creating a transient ColorUpdated event entity (m_ColorUpdateArchetype) to signal color change
  • calls RequestUpdate() to refresh UI Uses EndFrameBarrier command buffer; checks existence first.

  • private void SetLineName(Entity entity, string name)
    Sets a custom name via NameSystem.SetCustomName and requests UI update. Checks existence first.

  • public void SetLineState(Entity entity, bool state)
    Enables or disables a line by toggling the OutOfService policy (sets policy active=false for state=true). Requests update. Checks existence first.

  • private void SetLineSchedule(Entity entity, int schedule)
    Sets the route schedule to Day/Night/Always by enabling/disabling day/night policy prefabs using PoliciesUISystem. Requests update. Checks existence first.

  • public void ShowLine(Entity entity, bool hideOthers)
    Removes HiddenRoute from the given entity and optionally adds HiddenRoute to all other lines (hides others). Uses EndFrameBarrier and RequestUpdate. Checks existence first.

  • public void HideLine(Entity entity, bool showOthers)
    Adds HiddenRoute to the given entity and optionally removes HiddenRoute from all other lines (to show others). Uses EndFrameBarrier and RequestUpdate. Checks existence first.

  • public void ToggleHighlight(Entity entity)
    Toggles the Highlighted component on the given entity using an EndFrameBarrier command buffer. Checks existence first.

  • public void ResetLinesVisibility()
    Removes HiddenRoute and Highlighted components from all entities matched by m_LineQuery (resets line visibility/highlight). Calls RequestUpdate().

  • private void BindPassengerTypes(IJsonWriter writer)
    Writes the passenger transport type list to the JSON writer by calling BindTypes with m_Config.m_PassengerLineTypes.

  • private void BindCargoTypes(IJsonWriter writer)
    Writes the cargo transport type list to the JSON writer by calling BindTypes with m_Config.m_CargoLineTypes.

  • private void BindTypes(IJsonWriter writer, UITransportItem[] items)
    Generic helper that iterates UITransportItem array, resolves each item's unlockable prefab entity, determines lock status, and writes a UITransportType object into the JSON writer using PrefabUISystem. Wraps output in a JSON array.

  • private void BindLines(IJsonWriter binder)
    Retrieves a sorted NativeArray using TransportUIUtils.GetSortedLines and writes each transport line by calling BindLine. Wraps output in a JSON array. Uses m_LineQuery and PrefabSystem via the helper.

  • private void BindLine(UITransportLineData lineData, IJsonWriter binder)
    Writes a Game.UI.InGame.UITransportLine JSON object containing:

  • "name": bound via NameSystem.BindName
  • "vkName": bound via NameSystem.BindNameForVirtualKeyboard
  • "lineData": writes the UITransportLineData struct This constructs the UI representation for a single line.

Usage Example

// Typical usage from another system or mod script that has access to World:
var sys = world.GetOrCreateSystemManaged<Game.UI.InGame.TransportationOverviewUISystem>();

// Force the UI to refresh (for example after you change route data):
sys.RequestUpdate();

// Set a line's color (entity must be a valid route entity):
sys.SetLineColor(routeEntity, new Color32(255, 0, 0, 255)); // set to red

// Toggle highlight on a route:
sys.ToggleHighlight(routeEntity);

// Hide a route and show only it (hide others):
sys.HideLine(routeEntity, showOthers: false);