Skip to content

Game.UI.InGame.GenericInfo

Assembly:
Game

Namespace:
Game.UI.InGame

Type:
class

Base:
object

Summary:
Represents a small, reusable piece of UI data (label + value + optional target entity) used by in-game UI sections. Instances encapsulate the logic that decides whether they should be displayed for a given entity/prefab and provide an update callback to populate their values. Also supports JSON serialization via IJsonWritable for debug/export/inspection purposes.


Fields

  • private readonly System.Func<Unity.Entities.Entity, Unity.Entities.Entity, bool> m_ShouldDisplay
    Holds the predicate used to determine whether this info item should be shown for a given entity and its prefab. Called by DisplayFor(entity, prefab).

  • private readonly System.Action<Unity.Entities.Entity, Unity.Entities.Entity, Game.UI.InGame.GenericInfo> m_OnUpdate
    Holds the update callback that fills/updates this GenericInfo's label, value and target based on the given entity and prefab. Called by OnRequestUpdate(entity, prefab).

Properties

  • public string label { get; set; }
    Text label shown in the UI for this info item. May be null; serialization writes empty string when null.

  • public string value { get; set; }
    Text value shown for the label. May be null; serialization writes empty string when null.

  • public Unity.Entities.Entity target { get; set; }
    Optional entity associated with this info item (e.g., a referenced building or object). If no entity is set, this is expected to be Unity.Entities.Entity.Null; serialization writes JSON null for Entity.Null.

Constructors

  • public GenericInfo(System.Func<Unity.Entities.Entity, Unity.Entities.Entity, bool> shouldDisplay, System.Action<Unity.Entities.Entity, Unity.Entities.Entity, Game.UI.InGame.GenericInfo> onUpdate)
    Creates a GenericInfo with the given display predicate and update callback. Both delegates are stored readonly; caller provides logic to decide visibility and to populate label/value/target when requested.

Methods

  • public bool DisplayFor(Unity.Entities.Entity entity, Unity.Entities.Entity prefab)
    Invokes m_ShouldDisplay(entity, prefab) and returns whether this info item should be displayed for the supplied entity/prefab.

  • public void OnRequestUpdate(Unity.Entities.Entity entity, Unity.Entities.Entity prefab)
    Invokes m_OnUpdate(entity, prefab, this). The callback is expected to update this.label, this.value and/or this.target as appropriate for the supplied entity/prefab.

  • public void Write(Colossal.UI.Binding.IJsonWriter writer)
    Serializes this instance to the provided IJsonWriter. Serialization format:

  • writer.TypeBegin(GetType().FullName)
  • property "label" -> label or empty string if null
  • property "value" -> value or empty string if null
  • property "target" -> JSON null if target == Entity.Null, otherwise writes the Entity value
  • writer.TypeEnd()

Implements ISubsectionSource (used by the UI to collect/display subsections) and IJsonWritable (for JSON export/inspection).

Usage Example

// create a GenericInfo that shows an item only for non-null entities and updates its text
var info = new GenericInfo(
    shouldDisplay: (entity, prefab) => entity != Entity.Null,
    onUpdate: (entity, prefab, g) =>
    {
        g.label = "Owner";
        // example: obtain owner name from some component; here we set a simple value
        g.value = $"Entity #{entity.Index}";
        g.target = Entity.Null; // or set a referenced entity
    });

// Later, the UI will call:
if (info.DisplayFor(someEntity, somePrefab))
{
    info.OnRequestUpdate(someEntity, somePrefab);
    // info.label and info.value are now populated
}

// To serialize:
var writer = /* obtain an IJsonWriter from the environment */;
info.Write(writer);