Skip to content

Game.MailSection

Assembly:
Assembly-CSharp

Namespace: Game.UI.InGame

Type:
class

Base:
InfoSectionBase

Summary:
MailSection is an in-game UI info section used to display mail-related statistics for post facilities and mail boxes. It reads entity/component data from the EntityManager (PostFacility, MailBox and their Data prefabs) and exposes values such as sorting rate, sorting capacity, amounts of local/unsorted/outgoing mail, total stored mail and storage capacity. It chooses its visibility based on whether the selected entity is a PostFacility or a MailBox and populates tooltip keys to display the appropriate labels in the UI.


Fields

  • private enum MailKey
    Enum used to select which tooltip keys represent different mail categories shown in the UI:
  • ToDeliver — mail to be delivered.
  • Collected — collected mail (used when post vans exist).
  • Unsorted — unsorted mail (used when no post vans).
  • Local — local mail.

  • private enum Type
    Enum for the kind of object being inspected:

  • PostFacility — the selected entity is a post facility (building).
  • MailBox — the selected entity is a mailbox (street furniture).

Properties

  • protected override string group => "MailSection"
    Identifier for grouping this info section (used by the UI framework).

  • private int sortingRate { get; set; }
    Current effective sorting rate for a PostFacility. Computed from PostFacilityData.m_SortingRate and the PostFacility component processing factor.

  • private int sortingCapacity { get; set; }
    Base sorting capacity (the raw m_SortingRate from the data/prefab for the post facility).

  • private int localAmount { get; set; }
    Amount of local mail currently stored in the entity's resource buffer.

  • private int unsortedAmount { get; set; }
    Amount of unsorted mail currently stored (includes mail kept in attached MailBox component if present).

  • private int outgoingAmount { get; set; }
    Amount of outgoing mail currently stored in the entity's resource buffer.

  • private int storedAmount { get; set; }
    Total stored mail (sum of unsorted, local and outgoing amounts).

  • private int storageCapacity { get; set; }
    Maximum mail capacity for the building/mailbox from data/prefab (m_MailCapacity).

  • private MailKey localKey { get; set; }
    Which MailKey is used to represent the "local" values in tooltips. Determined by PostFacilityData.m_PostVanCapacity: if no post van capacity, shows as Local; otherwise ToDeliver.

  • private MailKey unsortedKey { get; set; }
    Which MailKey is used to represent "unsorted/collected" values. Determined by PostFacilityData.m_PostVanCapacity: if post van capacity > 0 shows as Collected; otherwise Unsorted.

  • private Type type { get; set; }
    Indicates whether the section is showing a PostFacility or a MailBox. Controls which values are computed and reported.

Constructors

  • public MailSection()
    Default constructor. The class is created by the UI system; no special initialization beyond base class behavior is performed here.

Methods

  • protected override void Reset()
    Resets all tracked numeric values to zero. Called by the UI framework when the info section needs to clear state (e.g., when selection changes).

  • private bool Visible()
    Determines whether the section should be visible for the currently selected entity/prefab:

  • Returns true if the selected entity has a PostFacility component.
  • If not a PostFacility, returns true only if the selected entity has a MailBox component and the selected prefab has MailBoxData.
  • Otherwise returns false.

  • [Preserve] protected override void OnUpdate()
    Called on UI update; sets base.visible using the Visible() check so the section shows/hides appropriately.

  • protected override void OnProcess()
    Core method that reads entity and prefab data and populates the private properties:

  • If the selected entity (with upgrades) has PostFacilityData:
    • Sets type = PostFacility.
    • Reads the PostFacility component to compute sortingRate = (m_SortingRate * m_ProcessingFactor + 50) / 100.
    • Reads sortingCapacity, storageCapacity from the data/prefab and resource buffer values for LocalMail, UnsortedMail, OutgoingMail via EconomyUtils.
    • If the entity also has a MailBox component, that component's m_MailAmount is added into unsortedAmount.
    • Chooses localKey and unsortedKey based on m_PostVanCapacity (post vans change labels between Local/ToDeliver and Unsorted/Collected).
    • storedAmount = unsortedAmount + localAmount + outgoingAmount.
    • Adds appropriate tooltip keys: localKey, "Outgoing" (if sortingCapacity > 0 or outgoingAmount > 0), unsortedKey, "Sorting" (if sortingCapacity > 0), "Storage" (if storageCapacity > 0).
  • Else if the selected entity has a MailBox component and the selected prefab has MailBoxData:

    • Sets type = MailBox.
    • Reads storageCapacity from MailBoxData and storedAmount from the MailBox component.
  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes the tracked values to JSON for the UI to read. Writes the following properties (property name -> value):

  • "sortingRate" -> sortingRate (int)
  • "sortingCapacity" -> sortingCapacity (int)
  • "localAmount" -> localAmount (int)
  • "unsortedAmount" -> unsortedAmount (int)
  • "outgoingAmount" -> outgoingAmount (int)
  • "storedAmount" -> storedAmount (int)
  • "storageCapacity" -> storageCapacity (int)
  • "localKey" -> name of the MailKey enum used for local mail
  • "unsortedKey" -> name of the MailKey enum used for unsorted/collected mail
  • "type" -> numeric value of the Type enum (0 = PostFacility, 1 = MailBox)

Notes and implementation details: - This section relies heavily on EntityManager and component types: Game.Buildings.PostFacility, Game.Routes.MailBox, PostFacilityData, MailBoxData and the Economy resource buffer on the entity. - It uses a helper TryGetComponentWithUpgrades(...) (presumably implemented in InfoSectionBase) to read data that may be affected by upgrades. - Tooltip keys are added to base.tooltipKeys — the UI will use those keys to display lines/labels. The chosen keys depend on the presence of post vans and sorting capability.

Usage Example

This shows how MailSection exposes its data through JSON when the UI requests properties. Example JSON snippet you can expect (values are illustrative):

{
  "sortingRate": 50,
  "sortingCapacity": 100,
  "localAmount": 20,
  "unsortedAmount": 10,
  "outgoingAmount": 5,
  "storedAmount": 35,
  "storageCapacity": 200,
  "localKey": "ToDeliver",
  "unsortedKey": "Collected",
  "type": 0
}

If you want to inspect or extend behavior in a mod: - Hook or override InfoSectionBase behavior in a custom class to change tooltips or add extra values. - Read the same components used here (PostFacility, MailBox, PostFacilityData, MailBoxData, entity resource buffer) to compute or display additional mail-related info. - Ensure compatibility with upgrades by using TryGetComponentWithUpgrades or replicating its logic.