Skip to content

Game.UI.InGame.CompanySection

Assembly: Game (Assembly-CSharp)
Namespace: Game.UI.InGame

Type: class

Base: InfoSectionBase

Summary:
CompanySection is a UI info-panel section used by the in-game building/company inspector. It gathers ECS (Entity Component System) data about a company-related entity (production, processing, extractor, storage, lodging providers) and exposes which resources are required/produced/stored, whether the property is rentable, customer counts and prices. The section converts that data into tooltip keys and serializes a small JSON object for the UI.


Fields

  • private enum ExtractedKey
    Provides an internal enum with keys (Harvested, Extracted). Used only inside this class to distinguish extraction-related keys.

  • private Entity companyEntity
    Holds the ECS Entity representing the company/building being inspected. Entity.Null when no company entity is associated.

Properties

  • protected override string group => "CompanySection"
    Identifies the group name used by the base InfoSection system; used for grouping/identifying this section in UI logic and tooltip composition.

  • private Resource input1 { get; set; }
    First input resource required by the company (Resource enum). Defaults to Resource.NoResource when not applicable.

  • private Resource input2 { get; set; }
    Second input resource required by the company (if any). Defaults to Resource.NoResource when not applicable.

  • private Resource output { get; set; }
    Output resource produced by the company (Resource enum). Defaults to Resource.NoResource when not applicable.

  • private Resource sells { get; set; }
    Resource this company sells (used for service companies that sell resources directly). Defaults to Resource.NoResource when not applicable.

  • private Resource stores { get; set; }
    Resources stored by a storage company (bitmask/flags from StorageCompanyData.m_StoredResources). Defaults to Resource.NoResource when not applicable.

  • private int2 customers { get; set; }
    Tuple where x = current number of renters/customers, y = maximum capacity (current + free rooms). If y == 0 the section treats customers as absent.

  • private float price { get; set; }
    Lodging / rental price from LodgingProvider component when applicable.

  • private bool isRentable { get; set; }
    Set when the building has PropertyOnMarket component — indicates the property is available for rent/sale.

Constructors

  • public CompanySection()
    Default constructor. Marked with [Preserve] attribute in the source to avoid stripping by build optimizers. Initializes default state via Reset (Reset is called by base lifecycle).

Methods

  • protected override void Reset()
    Resets all local state: clears companyEntity to Entity.Null, sets resource fields to Resource.NoResource, sets customers to int2.zero and isRentable = false. Called by base lifecycle when the section is reused.

  • private bool Visible()
    Returns whether the section should be visible for the current selected entity/prefab. Uses CompanyUIUtils.HasCompany(EntityManager, selectedEntity, selectedPrefab, out companyEntity) to determine presence of a company and also retrieves the companyEntity when present.

  • [Preserve] protected override void OnUpdate()
    Simple update hook that sets base.visible based on Visible(). Marked [Preserve] in source.

  • protected override void OnProcess()
    Core processing method that inspects ECS components and buffers for the selected entity/prefab and populates fields and tooltip keys:

  • If companyEntity is null it checks the selectedPrefab for SpawnableBuildingData and ZoneData to add vacant-building tooltips for Commercial, Industrial or Office zones.
  • Sets isRentable when PropertyOnMarket component is present on selectedEntity.
  • If a Resources DynamicBuffer and a PrefabRef are available and the prefab has IndustrialProcessData, the method:
    • For service companies (ServiceAvailable component): determines input(s) and sells (output) and adds "Requires"/"Sells" tooltip keys as appropriate.
    • For ProcessingCompany: sets input1/input2/output and adds "Requires" and "Produces" tooltip keys.
    • For ExtractorCompany: sets output and adds "Produces".
    • For StorageCompany: reads StorageCompanyData.m_StoredResources into stores and adds "Stores".
  • If the entity has LodgingProvider and a Renter buffer, sets customers (current and capacity) and the rental price.

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes the section state into JSON properties consumed by the UI:

  • "companyName": null if companyEntity == Entity.Null, otherwise binds the name via m_NameSystem.BindName(writer, companyEntity).
  • "isRentable": boolean.
  • "input1", "input2", "output", "sells", "stores": writes enum names or null for Resource.NoResource.
  • "customers": writes the int2 (current, total) unless customers.y == 0, in which case it writes null.

Usage Example

// The UI system will call lifecycle methods on this section.
// Example: the OnWriteProperties implementation writes selected company info to the JSON used by the UI.
public override void OnWriteProperties(IJsonWriter writer)
{
    writer.PropertyName("companyName");
    if (companyEntity == Entity.Null)
    {
        writer.WriteNull();
    }
    else
    {
        m_NameSystem.BindName(writer, companyEntity);
    }

    writer.PropertyName("isRentable");
    writer.Write(isRentable);

    // input1 / input2 / output written as enum names or null
    writer.PropertyName("input1");
    writer.Write(input1 == Resource.NoResource ? null : Enum.GetName(typeof(Resource), input1));
}

Notes / Implementation details: - This class relies heavily on the game's ECS: PrefabRef, IndustrialProcessData, StorageCompanyData, LodgingProvider, Renter buffer, and various company marker components (ProcessingCompany, ExtractorCompany, StorageCompany, ServiceAvailable). - Resource.NoResource is used to indicate "not applicable". The JSON output intentionally writes null for these fields so the UI can hide them. - Tooltip keys (e.g., "Requires", "Produces", "Sells", "Stores", "VacantCommercial", "VacantIndustrial", "VacantOffice") are added to base.tooltipKeys during processing to drive localized tooltip strings in the UI.