Skip to content

Game.UI.InGame.TaxationUISystem

Assembly:
Assembly-CSharp

Namespace:
Game.UI.InGame

Type:
class

Base:
UISystemBase

Summary:
TaxationUISystem is a UI-facing ECS system that bridges the in-game taxation model to the UI layer. It binds tax-related values (global tax rate, per-area rates, per-resource rates, estimated incomes and effects, limits and icons) to UI bindings, responds to UI triggers to change tax settings, and queries city statistics and prefabs to compute estimates and available taxable resources. It depends on TaxSystem, CityStatisticsSystem and PrefabSystem and manages entity queries for taxable resources and unlocked zones. This system also caches tax parameter data and resource icons for efficient UI updates.


Fields

  • private static readonly string kGroup
    Group identifier used for UI bindings ("taxation").

  • private ITaxSystem m_TaxSystem
    Reference to the game's TaxSystem (interface) used to read and modify tax data and parameters.

  • private CityStatisticsSystem m_CityStatisticsSystem
    Reference to the CityStatisticsSystem for obtaining statistical data used in income estimates.

  • private PrefabSystem m_PrefabSystem
    Reference to the PrefabSystem used to enumerate resource prefabs and read their UI components.

  • private EntityQuery m_ResourceQuery
    EntityQuery used to find entities that have ResourceData and TaxableResourceData (taxable resources).

  • private EntityQuery m_UnlockedZoneQuery
    EntityQuery used to find ZoneData entities that are not locked (used to determine whether an area type is locked).

  • private GetterValueBinding<int> m_TaxRate
    Binding for the global tax rate value exposed to the UI.

  • private GetterValueBinding<int> m_TaxIncome
    Binding for the total estimated tax income exposed to the UI.

  • private GetterValueBinding<int> m_TaxEffect
    Binding for the combined tax effect (happiness/economic effects) exposed to the UI.

  • private GetterValueBinding<int> m_MinTaxRate
    Binding for the minimum allowed total tax rate.

  • private GetterValueBinding<int> m_MaxTaxRate
    Binding for the maximum allowed total tax rate.

  • private RawValueBinding m_AreaTypes
    Raw binding used to serialize the array of tax area types (Residential, Commercial, Industrial, Office) and their metadata to the UI.

  • private GetterMapBinding<int, int> m_AreaTaxRates
    Map binding for area type -> tax rate (e.g., Residential -> current rate).

  • private GetterMapBinding<int, Bounds1> m_AreaResourceTaxRanges
    Map binding for area type -> allowed resource tax range.

  • private GetterMapBinding<int, int> m_AreaTaxIncomes
    Map binding for area type -> estimated tax income.

  • private GetterMapBinding<int, int> m_AreaTaxEffects
    Map binding for area type -> tax effect for that area type.

  • private GetterMapBinding<TaxResource, int> m_ResourceTaxRates
    Map binding for TaxResource -> tax rate (per resource per area type).

  • private GetterMapBinding<TaxResource, int> m_ResourceTaxIncomes
    Map binding for TaxResource -> estimated income from that resource.

  • private TaxParameterData m_CachedTaxParameterData
    Cached copy of TaxParameterData used to avoid unnecessary UI updates when unchanged.

  • private int m_CachedLockedOrderVersion
    Cached component order version for Locked components; used to detect changes in locked state of zones (initialized to -1).

  • private Dictionary<int, string> m_ResourceIcons
    Cache mapping resource index -> icon path string for resource UI icons.

  • private TypeHandle __TypeHandle
    Compiler-generated struct instance that contains BufferLookup handles (for CityStatistic buffer lookup).

Properties

  • This class exposes no public properties.

Constructors

  • public TaxationUISystem()
    Default constructor. The system initializes UI bindings and dependencies inside OnCreate/OnCreateForCompiler rather than in the constructor.

Methods

  • protected override void OnCreate() : System.Void
    Initializes entity queries, acquires system references (TaxSystem, CityStatisticsSystem, PrefabSystem), and registers UI bindings and trigger bindings (e.g., setTaxRate, setAreaTaxRate, setResourceTaxRate). This is the main place where UI bindings are created and stored in this system.

  • protected override void OnUpdate() : System.Void
    Called every frame to update selective bindings — updates area incomes/effects, global income/effect, and resource incomes. Detects changes in tax parameter data or zone lock order to update area types binding when needed.

  • protected override void OnGameLoaded(Context serializationContext) : System.Void
    Called after a game load; clears and rebuilds the resource icon cache by enumerating resource prefabs and reading their UIObject icons.

  • private int2 GetLimits(TaxAreaType type, TaxParameterData limits) : int2
    Returns the tax rate limits (min, max) for a given TaxAreaType from TaxParameterData (residential, commercial, industrial, office).

  • private int2 GetResourceLimits(TaxAreaType type, TaxParameterData limits) : int2
    Returns resource tax rate limits for a given TaxAreaType. For Residential it returns job level tax limits; otherwise resource tax limits.

  • private int GetResourceTaxRate(TaxAreaType type, int resource) : int
    Reads the configured tax rate for a specific resource and area type (delegates to m_TaxSystem).

  • private int GetEstimatedResourceTaxIncome(TaxAreaType type, int resource) : int
    Calculates estimated income for a resource in the specified area type by using CityStatistics lookup and calling TaxSystem estimate methods.

  • private int UpdateTaxRate() : int
    Getter used by the UI bindings returning the global TaxRate from m_TaxSystem.

  • private int UpdateTaxIncome() : int
    Computes and returns the total estimated tax income across all area types using CityStatistics and TaxSystem estimates.

  • private int UpdateTaxEffect() : int
    Computes and returns the total tax effect across all area types by summing per-area effects.

  • private int UpdateMinTaxRate() : int
    Returns the minimum allowed total tax rate (TaxParameterData.m_TotalTaxLimits.x).

  • private int UpdateMaxTaxRate() : int
    Returns the maximum allowed total tax rate (TaxParameterData.m_TotalTaxLimits.y).

  • private void SetTaxRate(int rate) : System.Void
    Trigger handler that completes TaxSystem readers, sets the global tax rate, and updates relevant UI bindings (global rate, area/resource rates and ranges).

  • private void SetAreaTaxRate(int areaType, int rate) : System.Void
    Trigger handler that sets the tax rate for a specific area type (Residential/Commercial/Industrial/Office) and updates bindings for that area and dependent resource bindings.

  • private void SetResourceTaxRate(int resource, int areaType, int rate) : System.Void
    Trigger handler that sets a tax rate for a specific resource and area type. It handles different area types and updates area & resource bindings and ranges.

  • private int UpdateAreaTaxRate(int areaType) : int
    Getter that returns the current tax rate for the supplied area type.

  • private Bounds1 UpdateAreaResourceTaxRange(int area) : Bounds1
    Getter that returns the allowed tax rate range for resources in the specified area as a Bounds1 wrapper.

  • private int UpdateAreaTaxIncome(int areaType) : int
    Returns estimated tax income for a specific area type using CityStatistics lookup and TaxSystem methods.

  • private int UpdateAreaTaxEffect(int areaType) : int
    Returns the tax effect for a given area type at its current tax rate.

  • private int UpdateResourceTaxRate(TaxResource taxResource) : int
    Returns the tax rate for a TaxResource (area+resource) by delegating to GetResourceTaxRate.

  • private int UpdateResourceTaxIncome(TaxResource taxResource) : int
    Returns the estimated income for a TaxResource (area+resource) by delegating to GetEstimatedResourceTaxIncome.

  • private void UpdateAreaTypes(IJsonWriter binder) : System.Void
    Serializes the list of TaxAreaType entries to the provided IJsonWriter for the UI. For each area type it writes index, id, icon, tax range limits, resource tax rate limits and locked state. Also caches TaxParameterData.

  • private bool Locked(TaxAreaType areaType) : bool
    Determines if any zone matching the provided TaxAreaType exists and is unlocked; returns true when the area type is considered locked (no matching unlocked zone found). Uses m_UnlockedZoneQuery.

  • private void UpdateAreaResources(IJsonWriter binder, int area) : System.Void
    Serializes the set of taxable resources available for a given area to the IJsonWriter. For residential it writes a fixed set (5 job levels); for other area types it enumerates resource prefabs that match the area.

  • private TaxResourceInfo UpdateResourceInfo(TaxResource resource) : TaxResourceInfo
    Returns metadata (ID and icon) for a TaxResource. Residential resources return a residential icon; other areas return the resource ID and the cached icon path.

  • private IEnumerable<ResourcePrefab> GetResources(int areaType) : IEnumerable
    Yields ResourcePrefabs that are taxable for the specified area type by scanning entities matched by m_ResourceQuery and filtering using MatchArea.

  • private bool MatchArea(TaxableResource data, int areaType) : bool
    Helper that checks whether a TaxableResource declares support for the given area type (or if no explicit list exists, it matches by default).

  • private string GetIcon(TaxAreaType type) : string
    Returns the icon path string built from the tax area type (e.g., "Media/Game/Icons/ZoneResidential.svg").

  • private void __AssignQueries(ref SystemState state) : System.Void
    Compiler-generated method. Present in the class for query assignment used by the compiler-generated OnCreateForCompiler; in this implementation it creates and disposes a temporary EntityQueryBuilder (no queries assigned here).

  • protected override void OnCreateForCompiler() : System.Void
    Compiler-time helper that assigns queries and buffer lookups for ECS safety checks; calls __AssignQueries and assigns TypeHandle buffer lookups.

Usage Example

[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    // Example: programmatically change global tax rate via the TaxSystem
    var taxSystem = World.GetOrCreateSystemManaged<TaxSystem>();
    // Ensure writers/readers are synchronized before writing
    taxSystem.Readers.Complete();
    taxSystem.TaxRate = 12;

    // The TaxationUISystem listens to changes and will update UI bindings accordingly.
}

If you want to interact with area- or resource-specific rates from another system or mod, use the TaxSystem helpers (SetTaxRate, SetResidentialTaxRate, SetCommercialTaxRate, etc.) and ensure you complete the appropriate JobHandles / Readers/Writers before writing to avoid race conditions.