Game.UI.InGame.PopulationInfoviewUISystem
Assembly:
Namespace: Game.UI.InGame
Type: class
Base: InfoviewUISystemBase
Summary:
UI system used by the in‑game "Population" infoview. It creates and updates bindings that feed population-related UI widgets (population, employed, jobs, unemployment, homelessness, birth/death/migration statistics and age-distribution chart). The system queries city/simulation subsystems (city stats, workplace/household counters) and updates bindings each frame when necessary.
Fields
-
private const string kGroup
Constant grouping key used for binding names ("populationInfo"). -
private CityStatisticsSystem m_CityStatisticsSystem
Reference to the CityStatisticsSystem used to read city statistics (birth rate, death rate, moved in/away, etc.). -
private CitySystem m_CitySystem
Reference to the CitySystem; used to access the City entity and its Population component. -
private CountWorkplacesSystem m_CountWorkplacesSystem
Reference to the system that counts workplaces (used to provide total jobs/workplaces). -
private CountHouseholdDataSystem m_CountHouseholdDataSystem
Reference to the system that tracks household data (employed count, unemployment rate, homelessness, age groups, moved-in counts). -
private ValueBinding<int> m_Population
Binding for the total population integer value presented to the UI. -
private ValueBinding<int> m_Employed
Binding for employed citizens count. -
private ValueBinding<int> m_Jobs
Binding for jobs / workplaces count. -
private ValueBinding<float> m_Unemployment
Binding for the unemployment rate (float). -
private ValueBinding<float> m_Homelessness
Binding for homelessness rate (float). -
private ValueBinding<int> m_BirthRate
Binding for the birth rate statistic (int). -
private ValueBinding<int> m_DeathRate
Binding for the death rate statistic (int). -
private ValueBinding<int> m_MovedIn
Binding for citizens moved in (statistic). -
private ValueBinding<int> m_MovedAway
Binding for citizens moved away (statistic). -
private ValueBinding<int> m_Homeless
Binding for homeless citizens count. -
private RawValueBinding m_AgeData
Raw binding used to emit a structured chart payload (age distribution and totals) via a custom writer callback. -
private EntityQuery m_WorkProviderModifiedQuery
EntityQuery to detect modifications to work providers (WorkProvider component) — used to determine whether the UI should consider itself modified. -
private EntityQuery m_PopulationModifiedQuery
EntityQuery to detect modifications to Population components — used to determine whether the UI should consider itself modified.
Properties
-
protected override bool Active
Determines whether the infoview system is considered active. Returns true if the base Active flag is true or if any of the main bindings are active (population, employed, jobs, unemployment, birth/death/moved in/away, ageData, homelessness). This lets the UI system remain active only when relevant UI elements are active. -
protected override bool Modified
Determines whether the infoview data is considered modified and in need of an update. Returns true if the work-provider query is non-empty (i.e., changes to providers occurred); otherwise returns whether the population query is non-empty. Uses EntityQuery.IsEmptyIgnoreFilter to check for relevant component create/update/delete activity.
Constructors
public PopulationInfoviewUISystem()
Default constructor. Marked with [Preserve] in the source to avoid code stripping. Initialization of subsystems and bindings is done in OnCreate.
Methods
-
[Preserve] protected override void OnCreate()
Initializes references to required systems, sets up EntityQueries for detecting relevant modifications, and registers all UI bindings (ValueBinding and RawValueBinding). Called when the system is created. -
protected override void PerformUpdate()
Called by the base infoview system to perform an update; it invokes UpdateBindings to refresh bound values. -
private void UpdateBindings()
Pulls live data from the various counted systems and the City entity and updates all ValueBinding and RawValueBinding instances (jobs, employed, unemployment, homelessness, population, ageData and statistics). This is the central method that maps simulation data into UI bindings each update. -
private void UpdateAgeData(IJsonWriter binder)
Callback used by the m_AgeData RawValueBinding to emit a chart-style JSON-like payload: an array containing Children, Teen, Adult, Senior counts and a "total" property with MovedIn citizen count. Uses IJsonWriter to produce the data structure expected by the UI. -
private void UpdateStatistics()
Updates statistic-related bindings (birth rate, death rate, moved in, moved away) by querying the CityStatisticsSystem for the relevant StatisticType values.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// obtain references to other world systems
m_CityStatisticsSystem = World.GetOrCreateSystemManaged<CityStatisticsSystem>();
m_CitySystem = World.GetOrCreateSystemManaged<CitySystem>();
m_CountWorkplacesSystem = World.GetOrCreateSystemManaged<CountWorkplacesSystem>();
m_CountHouseholdDataSystem = World.GetOrCreateSystemManaged<CountHouseholdDataSystem>();
// entity queries to detect modifications
m_WorkProviderModifiedQuery = GetEntityQuery(
ComponentType.ReadOnly<WorkProvider>(),
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Updated>(),
ComponentType.Exclude<Temp>());
m_PopulationModifiedQuery = GetEntityQuery(
ComponentType.ReadOnly<Population>(),
ComponentType.ReadOnly<Created>(),
ComponentType.ReadOnly<Deleted>(),
ComponentType.ReadOnly<Updated>(),
ComponentType.Exclude<Temp>());
// register bindings that the UI expects (group "populationInfo")
AddBinding(m_Population = new ValueBinding<int>("populationInfo", "population", 0));
AddBinding(m_Employed = new ValueBinding<int>("populationInfo", "employed", 0));
AddBinding(m_Jobs = new ValueBinding<int>("populationInfo", "jobs", 0));
AddBinding(m_Unemployment = new ValueBinding<float>("populationInfo", "unemployment", 0f));
AddBinding(m_BirthRate = new ValueBinding<int>("populationInfo", "birthRate", 0));
AddBinding(m_DeathRate = new ValueBinding<int>("populationInfo", "deathRate", 0));
AddBinding(m_MovedIn = new ValueBinding<int>("populationInfo", "movedIn", 0));
AddBinding(m_MovedAway = new ValueBinding<int>("populationInfo", "movedAway", 0));
AddBinding(m_Homeless = new ValueBinding<int>("populationInfo", "homeless", 0));
AddBinding(m_Homelessness = new ValueBinding<float>("populationInfo", "homelessness", 0f));
AddBinding(m_AgeData = new RawValueBinding("populationInfo", "ageData", UpdateAgeData));
}
If you want, I can also produce a shorter "quick reference" listing only binding names and the type of data they provide (for use when wiring UI components).