Game.UI.InGame.InfoList
Assembly:
Assembly-CSharp (inferred)
Namespace:
Game.UI.InGame
Type:
class
Base:
System.Object
Implements: ISubsectionSource, IJsonWritable
Summary:
InfoList is a small helper used by the in-game UI to represent a dynamic, serializable list of informational items for a given Entity (and its prefab). It encapsulates a display predicate (to decide whether the list should be shown for a particular entity/prefab), an update callback (to populate the list on demand), and JSON serialization logic so the UI can read the list state. It also defines a nested immutable Item struct that holds a display text and an optional associated Entity.
Fields
-
private readonly System.Func<Unity.Entities.Entity, Unity.Entities.Entity, bool> m_ShouldDisplay
Predicate used to determine whether this InfoList should be shown for a particular entity/prefab combination. The function signature is (entity, prefab) => bool. -
private readonly System.Action<Unity.Entities.Entity, Unity.Entities.Entity, Game.UI.InGame.InfoList> m_OnUpdate
Callback invoked when the UI requests the InfoList to update its contents. The callback is responsible for calling InfoList.Add(...) to populate the list. -
private List<Game.UI.InGame.InfoList.Item> list
Private backing property (holds items added by the update callback). Cleared when OnRequestUpdate is called. -
private bool expanded
Private backing property indicating whether the UI list is expanded. Serialized by Write(...).
Nested struct fields:
public static readonly Unity.Entities.Entity kNullEntity
A sentinel value equal to Entity.Null, provided for convenience to represent an Item without an associated Entity.
Properties
-
public string label { get; set; }
Public label for the list, shown in the UI. -
private List<Game.UI.InGame.InfoList.Item> list { get; set; }
Internal list of Item entries. Managed by OnRequestUpdate and Add. -
private bool expanded { get; set; }
Whether the list is expanded (serialized).
Nested struct properties:
-
public string text { get; }
Read-only text for the Item (display string). -
public Unity.Entities.Entity entity { get; }
Read-only associated Entity for the Item (may be Entity.Null).
Constructors
public InfoList(System.Func<Unity.Entities.Entity, Unity.Entities.Entity, bool> shouldDisplay, System.Action<Unity.Entities.Entity, Unity.Entities.Entity, Game.UI.InGame.InfoList> onUpdate)
Creates a new InfoList. Provide:- shouldDisplay: a predicate taking (entity, prefab) that returns true when this list should be shown for that pair.
- onUpdate: a callback invoked to populate the list when the UI requests an update. The constructor initializes the internal list.
Nested struct constructors:
-
public Item(string text, Unity.Entities.Entity entity)
Creates an Item with given text and associated entity. -
public Item(string text)
Creates an Item with given text and no associated entity (Entity.Null / kNullEntity).
Methods
-
public bool DisplayFor(Unity.Entities.Entity entity, Unity.Entities.Entity prefab)
Returns the result of the provided shouldDisplay predicate for the given entity/prefab. Used by UI code to decide visibility. -
public void OnRequestUpdate(Unity.Entities.Entity entity, Unity.Entities.Entity prefab)
Called by UI to request the InfoList be refreshed for the given entity/prefab. This method clears the internal list and invokes the provided onUpdate callback so it can populate items via Add(...). -
public void Add(Game.UI.InGame.InfoList.Item item)
Adds an Item to the internal list. Intended to be called from the onUpdate callback. -
public void Write(Colossal.UI.Binding.IJsonWriter writer)
Serializes the InfoList into the supplied IJsonWriter. The JSON includes: - expanded (bool)
- label (string)
- list (array of Item entries)
Nested struct methods:
public void Write(Colossal.UI.Binding.IJsonWriter writer)
Serializes the Item to JSON. Writes its type name, then properties:- text (string)
- entity (Entity or null if Entity.Null)
Usage Example
// Create an InfoList that shows only for buildings with a specific prefab,
// and populates itself with one item showing the entity id.
var myInfoList = new InfoList(
shouldDisplay: (entity, prefab) => prefab != Entity.Null && /* your condition */ true,
onUpdate: (entity, prefab, infoList) =>
{
// populate the list when requested
infoList.Add(new InfoList.Item($"Entity: {entity.Index}", entity));
infoList.Add(new InfoList.Item("Some extra info"));
}
);
// Later, when the UI needs to refresh for a selected entity:
if (myInfoList.DisplayFor(selectedEntity, selectedPrefab))
{
myInfoList.OnRequestUpdate(selectedEntity, selectedPrefab);
// UI will call myInfoList.Write(...) to serialize the items to JSON for rendering.
}
Notes and tips: - The nested Item.kNullEntity is provided to explicitly mark items without an associated entity. - The onUpdate callback is the intended place to call Add(...) — do not modify the internal list from elsewhere. - The Write methods implement IJsonWritable so the UI binding layer can consume the structure.