Skip to content

Game.UI.InGame.ServiceBudgetUISystem

Assembly: Assembly-CSharp.dll
Namespace: Game.UI.InGame

Type: public class (marked CompilerGenerated)

Base: UISystemBase

Summary:
ServiceBudgetUISystem is a UI system responsible for the in-game "Service Budget" UI group ("serviceBudget"). It collects service prefabs/UI objects, builds JSON payloads consumed by the UI (list of services and per-service details), and exposes bindings/triggers that let the UI change service budgets and service fees. The system interacts with core game systems: PrefabSystem, CitySystem, CityServiceBudgetSystem and ServiceFeeSystem. It reads various parameter singletons (fee parameters, outside trade, happiness, efficiency) to build detailed fee data and estimates. The class also contains small nested helper types used for JSON serialization (ServiceInfo), reading PlayerResource values from JSON (PlayerResourceReader), and a compiler-generated TypeHandle for ECS handles.


Fields

  • private const string kGroup = "serviceBudget"
    Group name used for UI bindings and update bindings registered by this system.

  • private PrefabSystem m_PrefabSystem
    Reference to PrefabSystem (fetched in OnCreate). Used to resolve Prefab objects (ServicePrefab) from PrefabData.

  • private CitySystem m_CitySystem
    Reference to the CitySystem (fetched in OnCreate). Used to access the city entity and its buffers (e.g., ServiceFee buffer).

  • private ICityServiceBudgetSystem m_CityServiceBudgetSystem
    Reference to the city service budget system interface (obtained from CityServiceBudgetSystem). Used to get/set budgets, efficiencies and estimated upkeep.

  • private IServiceFeeSystem m_ServiceFeeSystem
    Reference to the service fee system (obtained from ServiceFeeSystem). Used to compute income/estimates and service fee related information.

  • private EntityQuery m_ServiceQuery
    EntityQuery used to gather service UI objects (entities with PrefabData, UIObjectData and ServiceData). Used by WriteServices to enumerate services shown in the UI.

  • private TypeHandle __TypeHandle
    Compiler-generated type handle struct (nested TypeHandle type) used to assign ECS type handles on compiler-generated code paths.

  • private EntityQuery __query_2035132663_0

  • private EntityQuery __query_2035132663_1
  • private EntityQuery __query_2035132663_2
  • private EntityQuery __query_2035132663_3
    EntityQuery fields created in __AssignQueries for reading various parameter singletons:
  • __query_2035132663_0 → ServiceFeeParameterData
  • __query_2035132663_1 → OutsideTradeParameterData
  • __query_2035132663_2 → CitizenHappinessParameterData
  • __query_2035132663_3 → BuildingEfficiencyParameterData

(Those queries are built with EntityQueryOptions.IncludeSystems.)

Properties

  • None (this system exposes no public properties).

Constructors

  • public ServiceBudgetUISystem()
    Default constructor. Marked with [Preserve] attribute in the compiled code. Initialization of references and queries is done in OnCreate / OnCreateForCompiler rather than the constructor.

Methods

  • protected override void OnCreate()
    Initializes the system: resolves/fetches the PrefabSystem, CitySystem, CityServiceBudgetSystem and ServiceFeeSystem instances from the World; constructs the m_ServiceQuery used to enumerate service UI objects; registers requirement singletons for update (ServiceFeeParameterData, OutsideTradeParameterData, CitizenHappinessParameterData, BuildingEfficiencyParameterData); adds JSON update bindings and UI trigger bindings:
  • RawValueBinding "serviceBudget" / "services" → WriteServices
  • RawMapBinding "serviceBudget" / "serviceDetails" → WriteServiceDetails
  • TriggerBinding "serviceBudget" / "setServiceBudget" → SetServiceBudget
  • TriggerBinding "serviceBudget" / "setServiceFee" → SetServiceFee (uses PlayerResourceReader)
  • TriggerBinding "serviceBudget" / "resetService" → ResetService

  • private void WriteServices(IJsonWriter writer)
    Writes the JSON array of services for the UI. It:

  • Gets sorted UI objects for service entries (UIObjectInfo.GetSortedObjects with m_ServiceQuery).
  • For each UIObjectInfo, looks up the ServicePrefab, calculates total budget via GetTotalBudget, and writes a ServiceInfo JSON object containing entity, name, icon, locked flag and budget.
  • Disposes the temporary NativeList.

  • private int GetTotalBudget(Entity service, DynamicBuffer<ServiceFee> fees)
    Computes a total budget/income figure for a given service entity. Steps:

  • Uses m_CityServiceBudgetSystem.GetEstimatedServiceBudget to get upkeep estimate (upkeep is negative in writer).
  • Adds fee income and import/export income/expenses by reading CollectedCityServiceFeeData buffer on the service entity (if present) and querying ServiceFeeSystem and m_ServiceFeeSystem for fee estimates and other service fee components.
  • Returns an integer representing the aggregated result.

  • private void WriteServiceDetails(IJsonWriter writer, Entity serviceEntity)
    Writes per-service detailed JSON (Type "serviceBudget.ServiceDetails") including:

  • entity, name, icon, locked, budgetAdjustable, budgetPercentage, efficiency, upkeep (negative), and "fees" array obtained by calling WriteServiceFees.
  • If the service entity does not have ServiceData and PrefabData, writes a JSON null.

  • private void WriteServiceFees(IJsonWriter writer, Entity serviceEntity)
    Writes the "fees" array for a service. If the service entity has a CollectedCityServiceFeeData buffer and it's non-empty, this method:

  • Fetches singleton parameter data via the compiled queries (service fee params, outside trade params, happiness params, efficiency params).
  • Iterates each CollectedCityServiceFeeData entry (one per PlayerResource collected on that service), obtains fee parameters for the resource, current fee, income/exports/imports, and computes derived multipliers/ effects:
    • consumptionMultiplier via ServiceFeeSystem.GetConsumptionMultiplier
    • efficiencyMultiplier via ServiceFeeSystem.GetEfficiencyMultiplier
    • happinessEffect via ServiceFeeSystem.GetHappinessEffect
  • For each resource writes a JSON object "serviceBudget.ServiceFee" with resource id/name/fee/min/max/adjustable/importable/exportable/incomeInternal/incomeExports/expenseImports/consumptionMultiplier/efficiencyMultiplier/happinessEffect
  • If no fee buffer or it's empty writes an empty JSON array.

  • private void SetServiceBudget(Entity service, int percentage)
    Trigger handler invoked by UI binding "setServiceBudget". Calls m_CityServiceBudgetSystem.SetServiceBudget(service, percentage). This updates the service budget percentage.

  • private void SetServiceFee(PlayerResource resource, float amount)
    Trigger handler invoked by UI binding "setServiceFee". If the resource is not Parking and the city entity has a ServiceFee buffer, it calls ServiceFeeSystem.SetFee(resource, buffer, amount) to update the fee for that resource.

  • private void ResetService(Entity service)
    Trigger handler for UI "resetService". Resets the given service to default values:

  • Sets service budget to 100%.
  • If the service collects fees (has CollectedCityServiceFeeData), it fetches ServiceFeeParameterData singleton and resets each collected PlayerResource's fee to its default parameter (singleton.GetFeeParameters(...).m_Default) via SetServiceFee.

  • private void __AssignQueries(ref SystemState state)
    Compiler-generated helper that constructs the four queries used to access parameter singletons: ServiceFeeParameterData, OutsideTradeParameterData, CitizenHappinessParameterData, BuildingEfficiencyParameterData. Called from OnCreateForCompiler.

  • protected override void OnCreateForCompiler()
    Compiler-time initialization hook. Calls base.OnCreateForCompiler(), __AssignQueries(ref base.CheckedStateRef), and the TypeHandle assign helper to complete query and handle setup used in the compiled system.

  • (Nested/Helper methods)

  • ServiceInfo.Write(IJsonWriter writer) — nested struct method that serializes the ServiceInfo struct into JSON for the UI.
  • PlayerResourceReader.Read(IJsonReader reader, out PlayerResource value) — helper to read a PlayerResource value from JSON (used for the trigger binding that expects PlayerResource).
  • TypeHandle.__AssignHandles(ref SystemState state) — empty stub in this compilation (compiler-generated) used to bind type handles if needed.

Usage Example

Example snippets showing how this system is used (UI binds to the system and city systems can be used directly from code to adjust budgets/fees):

// Systems are obtained from the World. These calls typically run in a mod or another system.
var world = /* obtain World (Game world) */;
var cityServiceBudgetSystem = world.GetOrCreateSystemManaged<CityServiceBudgetSystem>();
var entityManager = world.EntityManager;
Entity myServiceEntity = /* an Entity representing a service building or service object */;

// Set a service's budget to 80% via the city service budget system (same effect as UI "setServiceBudget" trigger)
cityServiceBudgetSystem.SetServiceBudget(myServiceEntity, 80);

// Set a service fee for a resource (e.g., Electricity) on the city-level ServiceFee buffer
Entity cityEntity = world.GetOrCreateSystemManaged<CitySystem>().City;
if (entityManager.HasComponent<ServiceFee>(cityEntity))
{
    var serviceFeeBuffer = entityManager.GetBuffer<ServiceFee>(cityEntity);
    ServiceFeeSystem.SetFee(PlayerResource.Electricity, serviceFeeBuffer, 0.9f); // e.g. 90% of default
}

Notes for modders: - The system exposes UI-facing bindings (group "serviceBudget") that the in-game UI uses to read service lists and details and to trigger updates. If you need to extend or intercept those flows, either modify/extend the UI layer or interact with CityServiceBudgetSystem and ServiceFeeSystem directly. - The JSON writers in this system depend on several parameter singletons (ServiceFeeParameterData, OutsideTradeParameterData, CitizenHappinessParameterData, BuildingEfficiencyParameterData). Ensure those singletons are present when reading the UI data (the system uses RequireForUpdate to ensure availability).