Game.UI.InGame.PoliceVehicleSection
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: class
Base: VehicleSection
Summary:
UI section responsible for displaying information about a selected police vehicle in the in-game UI. This class controls visibility of the section, inspects the selected entity and prefab to determine vehicle type and state, detects a criminal passenger (if any), computes localization keys for the vehicle, determines the next stop (if responding to an emergency/accident), and writes relevant properties into a JSON writer for the UI frontend. It relies heavily on the Entity Component System (EntityManager, components and buffers) and helper utilities in VehicleUIUtils.
Fields
-
private Entity criminalEntity { get; set; }
Stores the Entity handle for a criminal passenger currently aboard the selected police vehicle (if found). Cleared to Entity.Null in Reset(). Used when writing out JSON to identify the criminal and to bind their name via the name system. -
private VehicleLocaleKey vehicleKey { get; set; }
Locale key used to identify the proper localized label/icon for the police vehicle (e.g., police car vs helicopter). Determined during OnProcess based on prefab data (HelicopterData) or the police purpose mask.
Properties
protected override string group => "PoliceVehicleSection"
Identifier used by the UI system to group and register this UI section. Overrides the base class property to return the section name.
Constructors
public PoliceVehicleSection()
Default parameterless constructor. Marked with [Preserve] attribute on methods that need it at runtime (the constructor itself in source is trivial). Initialization logic is handled by the lifecycle methods (Reset/OnUpdate/OnProcess) rather than the constructor.
Methods
-
protected override void Reset()
Resets the section to its default state by calling base.Reset() and clearing criminalEntity (set to Entity.Null). This ensures stale entity references are not kept when the section is reused. -
private bool Visible()
Checks if the currently selected entity is a police vehicle and whether it has an Owner component. Returns true only if: - selectedEntity has a Vehicle component,
- selectedEntity has a Game.Vehicles.PoliceCar component,
-
selectedEntity has an Owner component. This is used to decide whether the UI section should be shown.
-
[Preserve] protected override void OnUpdate()
Called each update; updates base.visible using Visible(). Minimal work: simply sets visibility flag for the UI section. -
protected override void OnProcess()
Main processing method that populates the UI section for the currently selected police vehicle. Major steps: - Reads Game.Vehicles.PoliceCar component from selectedEntity and PoliceCarData from selectedPrefab.
- Tries to get ServiceDispatch buffer (read-only) and Passenger buffer (read-only) for the selectedEntity.
- Iterates passenger buffer to find a passenger entity. If a passenger is a Resident component, it maps to the underlying citizen Entity. If that Entity has a Citizen component, criminalEntity is set to that Entity (the first found).
- Determines vehicleKey: if selectedPrefab has HelicopterData it uses VehicleLocaleKey.PoliceHelicopter, otherwise it uses VehicleUIUtils.GetPoliceVehicleLocaleKey(componentData2.m_PurposeMask).
- Computes base.stateKey via VehicleUIUtils.GetStateKey(selectedEntity, componentData, service dispatch buffer, EntityManager).
- If the vehicle has AccidentTarget flag but is not AtTarget, it inspects the first ServiceDispatch in the buffer to derive nextStop:
- If the request refers to a PoliceEmergencyRequest that points to an AccidentSite with an Event, nextStop is set to that Event.
- Otherwise nextStop is set to the request's target.
- Adds the vehicleKey string to tooltipKeys.
- Calls base.OnProcess() to allow base class to finalize the UI processing.
Note: The method defensively checks buffer creation/length and presence of expected components before accessing them.
public override void OnWriteProperties(IJsonWriter writer)
Writes important properties into the provided IJsonWriter for UI serialization:- "criminal": either null or writes the name through the name system (m_NameSystem.BindName).
- "criminalEntity": writes the raw Entity handle or null if none.
- "vehicleKey": writes the name of the VehicleLocaleKey enumeration value selected for the vehicle. Calls base.OnWriteProperties(writer) first to let the base class write its properties.
Usage Example
// Minimal example showing how this class updates visibility each frame.
// The real class has [Preserve] on OnUpdate and is part of the UI lifecycle.
[Preserve]
protected override void OnUpdate()
{
base.visible = Visible();
}
Additional notes and modding tips: - This class interacts with the ECS EntityManager, component data and dynamic buffers; ensure you have correct types/assemblies referenced when inspecting or extending this class. - Compare entity values against Entity.Null when checking for presence/absence of an Entity reference. - When adding custom behavior, prefer overriding OnProcess and calling base.OnProcess() to keep base UI logic intact. - The class uses VehicleUIUtils and other helper systems (m_NameSystem) that integrate with the game's UI and localization systems — reuse these utilities for consistent behavior.