Game.UI.InGame.StatusSection
Assembly:
Assembly-CSharp
Namespace:
Game.UI.InGame
Type:
class
Base:
InfoSectionBase
Summary:
StatusSection is an in-game UI info section used to present an individual citizen's status: happiness, active conditions, and notification icons related to the citizen (and their current transport, if any). It manages persistent NativeList buffers for conditions and notifications, queries the ECS world for citizen data each frame, and writes a JSON representation of the status for the UI. Methods critical for lifecycle (OnCreate / OnDestroy) allocate and dispose native resources. Several methods are decorated with Preserve to avoid stripping.
Fields
-
private ImageSystem m_ImageSystem
Holds a reference to the ImageSystem used to resolve notification icon paths and provide a placeholder icon. Assigned during OnCreate via base.World.GetOrCreateSystemManaged(). -
private bool m_Dead
Local flag indicating whether the currently selected entity (citizen) is dead. Affects what is written out for happiness and conditions (null / empty).
Properties
-
protected override string group { get; }
Returns the UI grouping identifier; constant "StatusSection". Used by the base InfoSection framework to identify this section. -
private NativeList<CitizenCondition> conditions { get; set; }
Persistent NativeList buffer holding the current citizen's conditions (e.g., sick, hungry). Allocated with Allocator.Persistent in OnCreate and disposed in OnDestroy. Populated each process via CitizenUIUtils.GetCitizenConditions. -
private NativeList<Notification> notifications { get; set; }
Persistent NativeList buffer holding notification entries related to the citizen (and current transport). Allocated with Allocator.Persistent and disposed in OnDestroy. Filled using NotificationsSection.GetNotifications. -
private CitizenHappiness happiness { get; set; }
Struct storing the computed citizen happiness (populated each OnProcess via CitizenUIUtils.GetCitizenHappiness). Written to JSON unless the citizen is dead.
Constructors
public StatusSection()
Default constructor. The class is [CompilerGenerated] and several lifecycle methods are decorated with [Preserve]. Actual initialization of native resources is done in OnCreate.
Methods
-
protected override void Reset()
Clears both NativeList buffers and resets happiness and m_Dead to defaults. Called by the base lifecycle when the section is being reset; ensures buffers are emptied but not freed. -
[Preserve] protected override void OnCreate()
Allocates the persistent NativeList buffers (conditions and notifications) with Allocator.Persistent and obtains a reference to the ImageSystem via the ECS world. Called when the info section is created. -
[Preserve] protected override void OnDestroy()
Disposes the persistent NativeList buffers (conditions and notifications) and then calls base.OnDestroy(). Ensures no native memory leak. -
private bool Visible()
Determines whether this status section should be visible for the currently selected entity. Returns true only when the selected entity has a Citizen component and is a HouseholdMember (i.e., a member of a household), otherwise false. -
[Preserve] protected override void OnUpdate()
Updates the base.visible flag by calling Visible(). Called each update to toggle visibility according to the currently selected entity. -
protected override void OnProcess()
Primary data-gathering step executed when the section is processed: reads Citizen and HouseholdMember component data from the EntityManager, computes happiness via CitizenUIUtils.GetCitizenHappiness, fills conditions and notifications via CitizenUIUtils.GetCitizenConditions and NotificationsSection.GetNotifications, also queries current transport notifications if the citizen has a CurrentTransport component, and sets m_Dead via CitizenUtils.IsDead. -
public override void OnWriteProperties(IJsonWriter writer)
Serializes the section data to JSON for the UI: - Writes a "happiness" property: null if the citizen is dead, otherwise the happiness struct.
- Writes a "conditions" array: empty if dead, otherwise serializes each element of conditions.
- Writes a "notifications" array: for each Notification, resolves the NotificationIconPrefab via m_PrefabSystem.GetPrefab, writes an object with "key" (prefab.name) and "iconPath" (ImageSystem.GetIcon(prefab) or placeholderIcon from m_ImageSystem). Uses writer.TypeBegin/TypeEnd for each notification entry.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
conditions = new NativeList<CitizenCondition>(Allocator.Persistent);
notifications = new NativeList<Notification>(Allocator.Persistent);
m_ImageSystem = base.World.GetOrCreateSystemManaged<ImageSystem>();
}
Additional note: because this class uses NativeList with Allocator.Persistent, it's important mods or derived code follow the same create/dispose pattern (allocate in OnCreate and Dispose in OnDestroy) to avoid memory leaks. The class relies on several game utility helpers (CitizenUIUtils, NotificationsSection, CitizenUtils) and on m_PrefabSystem and ImageSystem being available on the world.