Skip to content

Game.UI.InGame.UpkeepSection

Assembly:
Game

Namespace:
Game.UI.InGame

Type:
class

Base:
InfoSectionBase

Summary:
UpkeepSection is an InfoSection used by the in-game building/prefab info panel to gather and present upkeep costs for a selected prefab/building. It collects both monetary and resource-based upkeep from ServiceUpkeepData buffers (including installed upgrades and workplace-related employee wage upkeep), accounts for inactive buildings/upgrades and usage-scaling, and produces a sorted UI-friendly list of UIUpkeepItem entries plus a total upkeep value. The class depends on ResourceSystem and PrefabUISystem and queries economy/budget parameters and buffer data through EntityQuery and buffer lookups.

The class contains an inner value-type UIUpkeepItem used to aggregate and serialize each displayed upkeep row, and a small TypeHandle struct used to assign buffer lookups for reading Employee buffers when calculating employee wage upkeep.


Fields

  • private TypeHandle __TypeHandle
    Holds buffer lookup handles used by compiler-generated code to access buffers (Employee buffer lookup). Assigned in OnCreateForCompiler via __TypeHandle.__AssignHandles.

  • private ResourceSystem m_ResourceSystem
    Reference to the game's ResourceSystem (used to get prefabs and market prices for resource upkeep calculations).

  • private PrefabUISystem m_PrefabUISystem
    Reference to PrefabUISystem (used to resolve titles/descriptions for prefabs/upgrades when building UI entries).

  • private EntityQuery m_BudgetDataQuery
    EntityQuery used to check/access budget data (ServiceBudgetData) used when calculating money upkeep modifiers.

  • private EntityQuery m_EconomyParameterQuery
    EntityQuery used to check/access economy parameter data needed to calculate employee wage upkeep.

  • private Dictionary<string, UIUpkeepItem> moneyUpkeep
    Dictionary aggregating monetary upkeep rows keyed by a string (prefab name or Resource.Money.ToString()).

  • private Dictionary<Resource, UIUpkeepItem> resourceUpkeep
    Dictionary aggregating non-money resource upkeep rows keyed by Resource enum.

  • private List<UIUpkeepItem> upkeeps
    Final list of UIUpkeepItem that will be written out for UI consumption. Built from the two dictionaries in OnProcess and sorted by amount.

  • private EntityQuery m_BudgetDataQuery
    (Already listed above) Query to access budget/maintenance parameters for money upkeep calculation.

  • private EntityQuery m_EconomyParameterQuery
    (Already listed above) Query to access economy parameters for employee wage upkeep.

(Note: some fields are also stored as auto-properties — see Properties section.)

Properties

  • protected override string group => "UpkeepSection"
    Identifier for this info section — used by the UI framework to group or identify the section.

  • private Dictionary<string, UIUpkeepItem> moneyUpkeep { get; set; }
    Auto-property storing aggregated monetary upkeep items. Initialized in OnCreate.

  • private Dictionary<Resource, UIUpkeepItem> resourceUpkeep { get; set; }
    Auto-property storing aggregated resource upkeep items. Initialized in OnCreate.

  • private List<UIUpkeepItem> upkeeps { get; set; }
    Auto-property for the final sorted list of upkeep items to present to the UI.

  • private int total { get; set; }
    Auto-property containing the integer total price (sum of all upkeep.price values) for display/export.

  • private bool inactive { get; set; }
    Auto-property indicating whether the currently selected entity/prefab is (or is considered) inactive — affects upkeep calculations and is exported to JSON.

  • protected override bool displayForUpgrades => true
    Overrides base behavior to indicate this section should be shown when displaying upgrades as well.

Constructors

  • public UpkeepSection()
    Default parameterless constructor. The type relies on OnCreate to initialize systems/collections.

Methods

  • protected override void Reset()
    Clears the internal dictionaries and list, resets total to 0 and inactive flag to false. Called by the UI framework when the section needs to be reset before recalculation.

  • [Preserve] protected override void OnCreate()
    Initializes references to required systems and allocates the dictionaries/lists:

  • Gets ResourceSystem and PrefabUISystem from World.
  • Sets up EntityQuery instances for ServiceBudgetData and EconomyParameterData.
  • Creates moneyUpkeep, resourceUpkeep and upkeeps collections with initial capacity.

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

  • Visible if entity has ServiceUpkeepData.
  • If not, visible if it has ServiceObjectData and the prefab has WorkplaceData.
  • Otherwise not visible.

  • [Preserve] protected override void OnUpdate()
    Sets base.visible based on Visible() result. Called each frame/update to control UI visibility.

  • private void CalculateServiceUpkeepDatas(Entity entity, Entity prefabEntity, Entity buildingOwnerEntity, DynamicBuffer<ServiceUpkeepData> serviceUpkeepDatas, bool inactiveBuilding, bool inactiveUpgrade)
    Core calculation routine that iterates a ServiceUpkeepData buffer and:

  • For each entry determines resource and amount.
  • For money upkeep uses CityServiceUpkeepSystem.CalculateUpkeep (and applies inactive building/upgrade scaling).
  • Aggregates money items into moneyUpkeep keyed by prefab name or Resource.Money.ToString().
  • For resource upkeep multiplies amount by market price using EconomyUtils.GetMarketPrice and ResourceSystem, applies usage-scaling if ServiceUsage buffer is present, and aggregates into resourceUpkeep.
  • Adds resource locale keys to base.tooltipKeys for UI tooltips.
  • If the prefab/entity is a workplace and economy parameters are available, calculates employee wage upkeep (CityServiceUpkeepSystem.GetUpkeepOfEmployeeWage) using a buffer lookup for Employee via the TypeHandle and adds it to moneyUpkeep.

  • protected override void OnProcess()
    Main processing step called by the UI framework:

  • Determines inactive state of selected entity (Building or Extension disabled flags).
  • If selectedPrefab has a ServiceUpkeepData buffer, calls CalculateServiceUpkeepDatas for the base prefab and for each installed upgrade (InstalledUpgrade) that provides ServiceUpkeepData.
  • After populating moneyUpkeep and resourceUpkeep, collates entries into upkeeps, increments total, then sorts upkeeps by amount (UIUpkeepItem.CompareTo).

  • public override void OnWriteProperties(IJsonWriter writer)
    Serializes the current upkeeps, total and inactive flag to the provided IJsonWriter for UI/JS consumption:

  • Writes "upkeeps" array with each UIUpkeepItem (UIUpkeepItem implements IJsonWritable).
  • Writes "total" and "inactive" properties.

  • [MethodImpl(MethodImplOptions.AggressiveInlining)] private void __AssignQueries(ref SystemState state)
    Compiler-generated helper stub in this class — currently creates and disposes a temporary EntityQueryBuilder. Kept for compatibility with compiler-generated OnCreateForCompiler behavior.

  • protected override void OnCreateForCompiler()
    Assigns query and buffer lookup handles required by compiler-generated code. Calls __AssignQueries and __TypeHandle.__AssignHandles.

Inner types (brief):

  • UIUpkeepItem (private readonly struct)
  • Represents a single UI row: count, amount (quantity), price (monetary equivalent), localeKey (Resource), titleId (string).
  • Implements IJsonWritable — has Write(IJsonWriter) to serialize itself.
  • Implements IComparable to allow sorting by amount.
  • Supports addition operator to aggregate entries (sums count, amount and price).

  • TypeHandle (private struct)

  • Contains a BufferLookup field used to read Employee buffers.
  • __AssignHandles method assigns Lookups from a SystemState; used when calculating employee wage upkeep.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();
    // initialize systems and collections used for upkeep calculations
    m_ResourceSystem = base.World.GetOrCreateSystemManaged<ResourceSystem>();
    m_PrefabUISystem = base.World.GetOrCreateSystemManaged<PrefabUISystem>();
    m_BudgetDataQuery = GetEntityQuery(ComponentType.ReadOnly<ServiceBudgetData>());
    m_EconomyParameterQuery = GetEntityQuery(ComponentType.ReadOnly<EconomyParameterData>());
    resourceUpkeep = new Dictionary<Resource, UIUpkeepItem>(5);
    moneyUpkeep = new Dictionary<string, UIUpkeepItem>(5);
    upkeeps = new List<UIUpkeepItem>(10);
}

Notes and tips for modders: - UpkeepSection relies on several game services/systems (ResourceSystem, PrefabUISystem, CityServiceUpkeepSystem, EconomyUtils, BuildingUtils) — when changing upkeep-related data or adding new ServiceUpkeepData entries make sure relevant systems and buffers are populated correctly. - UIUpkeepItem.Write writes localeKey twice in the original source (duplicate property name call) — be aware if you consume the JSON that localeKey may appear duplicated depending on writer behavior. - Employee wage upkeep calculation uses a buffer lookup assigned via the TypeHandle; if you add or change Employee buffer layout you must ensure compatibility with the buffer lookup usage here.