Skip to content

Game.UI.InGame.PublicTransportVehicleSection

Assembly:
Game (assembly containing UI/in-game components)

Namespace:
Game.UI.InGame

Type:
public class

Base:
VehicleWithLineSection

Summary:
A UI section component that displays information for public transport vehicles in the in-game UI. This section becomes visible when the selected entity is a vehicle owned by some owner and the vehicle has a PublicTransport component. It determines a localized vehicle key (VehicleLocaleKey) based on the vehicle prefab's purpose mask and the vehicle's runtime flags, adds the key to tooltip keys, and serializes the selected vehicle key to JSON when requested. The class is compiler-generated and marked to be preserved for use with the runtime/linker.


Fields

  • private VehicleLocaleKey vehicleKey { get; set; }
    Holds the resolved VehicleLocaleKey for the currently selected public transport vehicle. Implemented as a private auto-property (compiler-generated backing field). It is used to add a localized tooltip key and to write the property when serializing the UI state.

  • Compiler-generated backing field(s) (e.g. <vehicleKey>k__BackingField)
    Because vehicleKey is an auto-property, the compiler generates a private backing field. This backing field is internal to the generated class and used by the get/set accessors.

Properties

  • protected override string group => "PublicTransportVehicleSection"
    Returns the UI group name for this section. Used by the parent UI framework to categorize or identify the section.

  • private VehicleLocaleKey vehicleKey { get; set; }
    Private auto-property described in Fields. Used internally for localization/tooltip and serialization.

(NOTE: other properties such as selectedEntity, selectedPrefab, stateKey, tooltipKeys, visible, and EntityManager are inherited from VehicleWithLineSection or other base classes and are used by this class but not declared here.)

Constructors

  • public PublicTransportVehicleSection()
    Default constructor. Marked with [Preserve] on the class/members. No additional initialization logic is present in this derived class — initialization depends on the base class.

Methods

  • private bool Visible()
    Determines whether this section should be visible for the currently selected entity. It returns true only when:
  • The selected entity has a Vehicle component,
  • The selected entity has an Owner component, and
  • The selected entity has a Game.Vehicles.PublicTransport component.

If any of those component checks fail, it returns false.

  • [Preserve] protected override void OnUpdate()
    Called by the UI system during update. This override sets the inherited visible property to the result of Visible(). Ensures the section is only shown when applicable.

  • protected override void OnProcess()
    Processes the currently selected entity and prefab to update UI state:

  • Reads the PublicTransport runtime component of the selectedEntity.
  • Updates base.stateKey using VehicleUIUtils.GetStateKey(...) to reflect the vehicle's state for UI visuals.
  • Reads the PublicTransportVehicleData from the selected prefab and inspects m_PurposeMask.
  • Determines vehicleKey as:
    • VehicleLocaleKey.PrisonVan if the prefab's purpose mask includes PrisonerTransport.
    • VehicleLocaleKey.EvacuationBus if the prefab indicates Evacuation purpose AND the runtime PublicTransport flags include Evacuating.
    • Otherwise VehicleLocaleKey.PublicTransportVehicle.
  • Adds the chosen vehicleKey.ToString() to base.tooltipKeys so the UI can show the appropriate localized tooltip.
  • Calls base.OnProcess() to run base-class processing logic.

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes this section's properties to JSON. Calls base.OnWriteProperties(writer) and then writes a "vehicleKey" property containing the enum name of the current vehicleKey (Enum.GetName(typeof(VehicleLocaleKey), vehicleKey)). This allows the UI/state to be saved or inspected.

Usage Example

// The class itself already overrides OnUpdate/OnProcess. Example showing how the
// section decides visibility and serializes the vehicleKey:

[Preserve]
protected override void OnUpdate()
{
    // Ensure the section only shows for public transport vehicles
    base.visible = Visible();
}

protected override void OnProcess()
{
    // Update stateKey and determine vehicleKey for tooltips/serialization
    var transport = base.EntityManager.GetComponentData<Game.Vehicles.PublicTransport>(selectedEntity);
    base.stateKey = VehicleUIUtils.GetStateKey(selectedEntity, transport, base.EntityManager);

    var prefabData = base.EntityManager.GetComponentData<PublicTransportVehicleData>(selectedPrefab);
    vehicleKey = ((prefabData.m_PurposeMask & PublicTransportPurpose.PrisonerTransport) != 0)
        ? VehicleLocaleKey.PrisonVan
        : (((prefabData.m_PurposeMask & PublicTransportPurpose.Evacuation) != 0 && (transport.m_State & PublicTransportFlags.Evacuating) != 0)
            ? VehicleLocaleKey.EvacuationBus
            : VehicleLocaleKey.PublicTransportVehicle);

    base.tooltipKeys.Add(vehicleKey.ToString());
    base.OnProcess();
}

public override void OnWriteProperties(IJsonWriter writer)
{
    base.OnWriteProperties(writer);
    writer.PropertyName("vehicleKey");
    writer.Write(Enum.GetName(typeof(VehicleLocaleKey), vehicleKey));
}

Notes / Dependencies: - Relies on types: Vehicle, Owner, Game.Vehicles.PublicTransport, PublicTransportVehicleData, PublicTransportPurpose, PublicTransportFlags, VehicleUIUtils, VehicleLocaleKey, IJsonWriter, and the inherited members from VehicleWithLineSection (selectedEntity, selectedPrefab, EntityManager, tooltipKeys, stateKey, visible). - The class uses component-based checks (EntityManager.HasComponent / GetComponentData) to detect applicable entities and to read runtime/prefab data. - Marked with [CompilerGenerated] and uses [Preserve] attributes to prevent removal/stripping by linkers.