Game.UI.InGame.LoadSection
Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 game code; exact assembly may vary)
Namespace:
Game.UI.InGame
Type:
public class LoadSection
Base:
InfoSectionBase
Summary:
UI info section that displays the current load and capacity for service vehicles (fire engines, garbage trucks, post vans). It reads capacity information from the selected vehicle prefab and current load/state from the selected entity. The section maps internal vehicle state to a LoadKey (Water, IndustrialWaste, Garbage, Mail) and exposes load/capacity values via OnWriteProperties for the UI to render tooltips/values.
Fields
private enum LoadKey { Water, IndustrialWaste, Garbage, Mail, None }
Enumeration used to identify which type of "load" is being shown by this section:- Water: fire engine extinguishing amount
- IndustrialWaste: garbage truck carrying industrial waste only
- Garbage: garbage truck carrying normal garbage
- Mail: post van carrying or collecting mail
-
None: default/unset
-
(No other explicit private fields; load, capacity and loadKey are implemented as private auto-properties.)
Properties
-
protected override string group => "LoadSection"
Identifies the UI group/name for this info section. -
private float load { get; set; }
Current amount (load) carried by the selected entity (e.g., extinguishing water, garbage, mail). -
private float capacity { get; set; }
Maximum capacity for the selected prefab (e.g., extinguishing capacity, garbage capacity, mail capacity). Used to control visibility and presentation. -
private LoadKey loadKey { get; set; }
Indicates which load type is currently active for the selected entity. Used to add an appropriate tooltip key. -
protected override Entity selectedEntity { get; }
Overrides base selectedEntity to resolve controller entities: if the selected entity has a Controller component, the Controller's m_Controller entity is returned. Otherwise returns the base selectedEntity. -
protected override Entity selectedPrefab { get; }
Overrides base selectedPrefab to resolve the actual prefab associated with a controller: if the selected entity has a Controller and that controller references a PrefabRef, the PrefabRef's m_Prefab is returned. Otherwise returns base selectedPrefab.
Constructors
public LoadSection()
Constructor annotated with [Preserve]. No explicit initialization logic aside from what base class provides. The section initializes its state via Reset/OnUpdate/OnProcess overrides.
Methods
-
protected override void Reset()
Resets internal state: sets loadKey to LoadKey.None and zeroes load and capacity. Called by the base lifecycle when the section should clear state. -
[Preserve] protected override void OnUpdate()
Called to update capacity/visibility based on the selected prefab. It checks the selectedPrefab for: - FireEngineData -> uses m_ExtinguishingCapacity
- GarbageTruckData -> uses m_GarbageCapacity
-
PostVanData -> uses m_MailCapacity Sets base.visible = capacity > 0f so the UI only shows the section for prefabs that expose a capacity.
-
protected override void OnProcess()
Called to sample the currently selected entity's current load and set loadKey: - If it's a FireEngine, reads m_ExtinguishingAmount and sets LoadKey.Water.
- If it's a GarbageTruck, reads m_Garbage and sets LoadKey.IndustrialWaste or LoadKey.Garbage depending on the GarbageTruckFlags.IndustrialWasteOnly flag.
-
If it's a PostVan, sums m_DeliveringMail + m_CollectedMail and sets LoadKey.Mail. Adds the loadKey string to base.tooltipKeys for the UI.
-
public override void OnWriteProperties(IJsonWriter writer)
Writes the current load, capacity and loadKey name into the provided JSON writer with property names "load", "capacity", and "loadKey". This is how the UI receives numeric values and the tooltip key.
Usage Example
// The class is managed by the UI system; here is how its OnUpdate/OnProcess work internally.
// Example: OnUpdate sets capacity for prefabs that have capacity fields.
[Preserve]
protected override void OnUpdate()
{
// check prefab types and set capacity accordingly
if (EntityManager.TryGetComponent<FireEngineData>(selectedPrefab, out var fireData))
{
capacity = fireData.m_ExtinguishingCapacity;
}
else if (EntityManager.TryGetComponent<GarbageTruckData>(selectedPrefab, out var garbageData))
{
capacity = garbageData.m_GarbageCapacity;
}
else if (EntityManager.TryGetComponent<PostVanData>(selectedPrefab, out var postData))
{
capacity = postData.m_MailCapacity;
}
base.visible = capacity > 0f;
}
// When the UI serializes the section for display it calls:
public override void OnWriteProperties(IJsonWriter writer)
{
writer.PropertyName("load");
writer.Write(load);
writer.PropertyName("capacity");
writer.Write(capacity);
writer.PropertyName("loadKey");
writer.Write(Enum.GetName(typeof(LoadKey), loadKey));
}
Notes and implementation details: - The class depends on Colossal.Entities, Game.Vehicles, Game.Prefabs and the EntityManager provided by the base class. - selectedEntity/selectedPrefab overrides resolve controller/prefab indirection so this section can work for both controller entities and their underlying controller/prefab targets. - loadKey is appended to base.tooltipKeys so localized tooltip text keyed by "Water", "Garbage", "IndustrialWaste", or "Mail" can be used by the UI.