Skip to content

Game.UI.InGame.PoliceSection

Assembly:
Assembly-CSharp.dll

Namespace:
Game.UI.InGame

Type:
class

Base:
InfoSectionBase

Summary:
UI info section used by the in-game building/details panel to show police station prisoner statistics. The section becomes visible when the selected entity has a PoliceStation component, reads the station's jail capacity (from PoliceStationData/upgrades) and the current number of occupants from the entity's Occupant buffer, and exposes those values via OnWriteProperties for the UI/JSON output. Methods and the constructor are marked with [Preserve] where required by the game's serialization/linker.


Fields

  • This class does not declare any explicit (non-auto) private fields. It uses auto-properties for its internal state.

Properties

  • protected override string group => "PoliceSection"
    Identifier used by the InfoSectionBase system to group or identify the section. This property overrides the base implementation and returns the literal "PoliceSection".

  • private int prisonerCount { get; set; }
    Auto-property that holds the currently counted number of prisoners. Updated each OnProcess call by reading the Occupant buffer length for the selected entity.

  • private int prisonerCapacity { get; set; }
    Auto-property that holds the jail capacity read from the PoliceStationData (including any applied upgrades). Updated each OnProcess call when the PoliceStationData component is available.

Constructors

  • public PoliceSection()
    Default constructor. Marked with [Preserve] in source to prevent code stripping. No special initialization is performed here; initial values for the auto-properties are the default (0).

Methods

  • protected override void Reset()
    Resets the section's internal state. Implementation sets prisonerCount and prisonerCapacity to 0. Called by the lifecycle when the section is reset.

  • private bool Visible()
    Returns true when the currently selected entity has the Game.Buildings.PoliceStation component. Uses base.EntityManager.HasComponent(selectedEntity) to determine visibility. This controls whether the section should be shown in the UI for the selected entity.

  • [Preserve] protected override void OnUpdate()
    Called every update tick of the section. Implementation sets base.visible = Visible(); so the section's visibility follows whether the selected entity is a police station.

  • protected override void OnProcess()
    Main logic that runs to collect/refresh displayed data:

  • Attempts to get PoliceStationData for the selected entity, including any applied upgrades, using TryGetComponentWithUpgrades(selectedEntity, selectedPrefab, out var data). If successful, prisonerCapacity is set to data.m_JailCapacity.
  • Tries to read the DynamicBuffer from the selected entity (read-only). If the buffer exists, prisonerCount is set to buffer.Length (current number of occupants). This method relies on EntityManager APIs and the Occupant buffer type being present on the building entity.

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes the collected values to the provided IJsonWriter. Writes two properties:

  • "prisonerCount" -> current prisonerCount
  • "prisonerCapacity" -> current prisonerCapacity
    This output is typically consumed by the UI layer to render the numbers in the in-game panel.

Notes: - The class uses the game's ECS EntityManager (base.EntityManager) and expects certain components/buffers (Game.Buildings.PoliceStation, PoliceStationData, DynamicBuffer) to be present on the selected entity. - Methods and the constructor are annotated with [Preserve] in the source to ensure they aren't removed by Unity's code stripping for builds.

Usage Example

Example showing how the section updates visibility and writes its properties for the UI. This mirrors the implementation in the mod/game:

[Preserve]
protected override void OnUpdate()
{
    base.visible = Visible();
}

protected override void OnProcess()
{
    if (TryGetComponentWithUpgrades<PoliceStationData>(selectedEntity, selectedPrefab, out var data))
    {
        prisonerCapacity = data.m_JailCapacity;
    }
    if (base.EntityManager.TryGetBuffer(selectedEntity, isReadOnly: true, out DynamicBuffer<Occupant> buffer))
    {
        prisonerCount = buffer.Length;
    }
}

public override void OnWriteProperties(IJsonWriter writer)
{
    writer.PropertyName("prisonerCount");
    writer.Write(prisonerCount);
    writer.PropertyName("prisonerCapacity");
    writer.Write(prisonerCapacity);
}

If you need documentation entries for related types used here (PoliceStationData, Occupant buffer, TryGetComponentWithUpgrades helper, or InfoSectionBase lifecycle), tell me which one and I will add them.