Skip to content

Game.UI.InGame.ShelterSection

Assembly:
Assembly-CSharp (typical for in-game types; not explicitly provided in source)

Namespace: Game.UI.InGame

Type:
public class

Base:
InfoSectionBase

Summary:
ShelterSection is an in-game UI info panel section for Emergency Shelters. It keeps track of the current number of sheltered occupants and the shelter capacity (read from the shelter prefab/data), updates its visibility depending on whether the currently selected entity is an EmergencyShelter, and writes the shelter-related properties to a JSON writer for UI/serialization. Several private integer properties exist (including consumables-related fields) but only sheltered and shelterCapacity are actually used in the JSON output. The class uses EntityManager, DynamicBuffer, and TryGetComponentWithUpgrades to read runtime data and prefab-upgrade data.


Fields

  • private int sheltered { get; set; }
    Private auto-property storing the current number of sheltered occupants discovered from the entity's Occupant buffer.

  • private int shelterCapacity { get; set; }
    Private auto-property storing the shelter capacity read from EmergencyShelterData (prefab/upgrades).

  • private int consumables { get; set; }
    Private auto-property reserved for consumables tracking; not read or written anywhere in the provided code.

  • private int consumableCapacity { get; set; }
    Private auto-property reserved for consumable capacity tracking; not read or written anywhere in the provided code.

Notes: - These are implemented as private auto-properties in source (compiler will generate backing fields). The class does not expose them publicly; only sheltered and shelterCapacity are output via OnWriteProperties.

Properties

  • protected override string group => "ShelterSection"
    Returns the UI group name for this info section. This identifies the section for UI logic in the parent InfoSectionBase.

Notes: - The class relies on base class members such as selectedEntity, selectedPrefab and EntityManager (from InfoSectionBase) to read entity and prefab data.

Constructors

  • public ShelterSection()
    Empty constructor marked with [Preserve]. No special initialization logic is present in the constructor.

Notes: - [Preserve] attribute prevents stripping when assemblies are processed/optimized; used for reflection or runtime instantiation requirements.

Methods

  • protected override void Reset()
    Resets the tracked counters to zero:
  • sheltered = 0
  • shelterCapacity = 0
  • consumables = 0

This is called to clear state before updating for a new selection/frame.

  • private bool Visible()
    Returns true if the currently selected entity has a Game.Buildings.EmergencyShelter component according to the EntityManager:
  • base.EntityManager.HasComponent(selectedEntity)

Used to determine whether the section should be shown for the selected entity.

  • [Preserve] protected override void OnUpdate()
    Sets base.visible to the result of Visible(). This toggles the section's visibility each update based on the selected entity.

  • protected override void OnProcess()
    Populates shelterCapacity and sheltered by:

  • Calling TryGetComponentWithUpgrades(selectedEntity, selectedPrefab, out var data) to read m_ShelterCapacity from the prefab/upgrades (if available) and assigning it to shelterCapacity.
  • Trying to get a DynamicBuffer from the selected entity and, if present, assigning buffer.Length to sheltered.

This method reads both prefab-upgrade data and runtime entity buffers to compute the values shown by the section.

  • public override void OnWriteProperties(IJsonWriter writer)
    Writes the computed values to an IJsonWriter in JSON-like form:
  • "sheltered": sheltered
  • "shelterCapacity": shelterCapacity

This method is used to serialize the properties for UI consumption or remote debugging.

Notes: - The methods use a combination of EntityManager APIs and a helper TryGetComponentWithUpgrades (likely provided by the base class or a utility) to factor in prefab upgrades when reading capacity values. - consumables and consumableCapacity are declared but not read/written by the current implementation — they may be placeholder for future extension (e.g., tracking stored supplies in shelters).

Usage Example

[Preserve]
protected override void OnUpdate()
{
    // Keep the section visible only when the selected entity is an EmergencyShelter
    base.visible = base.EntityManager.HasComponent<Game.Buildings.EmergencyShelter>(selectedEntity);
}

public override void OnWriteProperties(IJsonWriter writer)
{
    // Write shelter stats for UI/serialization
    writer.PropertyName("sheltered");
    writer.Write(sheltered);
    writer.PropertyName("shelterCapacity");
    writer.Write(shelterCapacity);
}

Additional notes for modders: - If you need to extend this section to expose consumables/consumableCapacity, update OnProcess to populate those fields and update OnWriteProperties to serialize them. - Be mindful that TryGetComponentWithUpgrades may return null if prefab data or upgrade data is absent; always null-check before reading fields from data. - This class depends on InfoSectionBase's selectedEntity/selectedPrefab and EntityManager; ensure those are valid when using or instantiating the section.