Game.UI.InGame.MaintenanceVehicleSection
Assembly: Assembly-CSharp (game code)
Namespace: Game.UI.InGame
Type: class
Base: VehicleSection
Summary:
MaintenanceVehicleSection is a UI section used by the in-game vehicle inspector for maintenance vehicles. It integrates with the game's entity/component system (EntityManager) to detect when the selected entity is a maintenance vehicle and to read its runtime data (MaintenanceVehicle) and prefab data (MaintenanceVehicleData). During processing it computes an adjusted maintenance capacity (taking vehicle efficiency into account), calculates a work-shift percentage (how much work remains), and sets the UI state key. The section exposes the computed workShift value to the JSON writer so the UI can consume and display it.
Fields
private int <workShift>k__BackingField
Backing field generated for the private auto-property workShift. Holds the computed work-shift percentage (0–100) for the currently selected maintenance vehicle.
Properties
-
protected override string group { get; }
The UI group identifier for this section. Returns the literal "MaintenanceVehicleSection". Used by the base VehicleSection to identify and group UI elements. -
private int workShift { get; set; }
A private auto-property that stores the computed work-shift percentage. It is reset to 0 in Reset() and updated in OnProcess(). The value is written to JSON in OnWriteProperties for the UI to consume.
Constructors
public MaintenanceVehicleSection()
Default constructor. Marked with [Preserve] in source to prevent stripping by build/linker. No custom initialization beyond what the base VehicleSection performs.
Methods
-
protected override void Reset()
Resets runtime state when the section is reset. Calls base.Reset() and sets workShift to 0. -
protected bool Visible()
Returns true when the currently selected entity and prefab represent a maintenance vehicle that this section should display. Specifically, it checks via EntityManager that the selected entity has Owner, Vehicle and Game.Vehicles.MaintenanceVehicle components and that the selected prefab has a MaintenanceVehicleData component. Returns false otherwise. -
protected override void OnUpdate()
Called each update tick for the UI section. Implementation sets base.visible to the result of Visible() so the section is shown/hidden automatically based on the selected entity. -
protected override void OnProcess()
Main processing routine executed when the section is active. Behavior: - Reads the runtime component Game.Vehicles.MaintenanceVehicle from the selected entity.
- Reads the prefab data MaintenanceVehicleData from the selected prefab.
- Adjusts the maintenance capacity by multiplying the prefab capacity by the vehicle's efficiency (then rounding up).
- Calculates workShift as the percent of remaining work: CeilToInt((1 - maintained / capacity) * 100), using a safe selector to avoid division by zero.
- Updates base.stateKey via VehicleUIUtils.GetStateKey(selectedEntity, componentData, base.EntityManager).
-
Calls base.OnProcess() to allow base class processing.
-
public override void OnWriteProperties(IJsonWriter writer)
Writes runtime properties needed by the UI into the provided IJsonWriter. This implementation writes a single property "workShift" with the current workShift integer value.
Usage Example
[Preserve]
protected override void OnUpdate()
{
// show or hide this section depending on the selected entity/prefab
base.visible = Visible();
}
Notes and tips for modders: - MaintenanceVehicleSection relies on the EntityManager and the base VehicleSection fields (like selectedEntity and selectedPrefab). When extending or inspecting this class, ensure you understand the base class contract. - The workShift value is computed on-demand in OnProcess and exported via OnWriteProperties — use that property in your UI bindings to display remaining maintenance work. - The class uses math.select to avoid division by zero when computing ratios; be cautious when modifying the capacity/maintained logic.