Skip to content

Game.UI.InGame.CapacityInfo

Assembly: Assembly-CSharp
Namespace: Game.UI.InGame

Type: public class

Base: ISubsectionSource, IJsonWritable

Summary:
Represents a single capacity entry used by in-game UI subsections. Encapsulates a label and numeric capacity values (current value and maximum), plus two delegates: one to decide whether the entry should be displayed for a given entity/prefab pair, and one to update the entry's values. Implements IJsonWritable to serialize the label/value/max into JSON.


Fields

  • private readonly Func<Entity, Entity, bool> m_ShouldDisplay
    Delegate used to determine whether this CapacityInfo should be shown for a given entity and its prefab. The first parameter is the entity instance, the second is the prefab entity.

  • private readonly Action<Entity, Entity, CapacityInfo> m_OnUpdate
    Delegate invoked to update this CapacityInfo's fields. Receives the entity, the prefab entity, and this CapacityInfo instance (so the callback can set label/value/max).

Properties

  • public string label { get; set; }
    Human-readable label for the capacity (e.g., "Storage", "Throughput"). Can be set by the update callback or externally.

  • public int value { get; set; }
    Current numeric amount for the capacity.

  • public int max { get; set; }
    Maximum numeric amount for the capacity.

Constructors

  • public CapacityInfo(Func<Entity, Entity, bool> shouldDisplay, Action<Entity, Entity, CapacityInfo> onUpdate)
    Creates a new CapacityInfo. Provide a shouldDisplay function to control visibility and an onUpdate action to populate label/value/max when requested.

Parameters: - shouldDisplay: function called by DisplayFor to decide whether to show this capacity (entity, prefab) -> bool. - onUpdate: action called by OnRequestUpdate to refresh the CapacityInfo (entity, prefab, this).

Methods

  • public bool DisplayFor(Entity entity, Entity prefab)
    Returns the result of invoking the m_ShouldDisplay delegate for the provided entity and prefab. Use this to determine whether the UI should render this entry.

  • public void OnRequestUpdate(Entity entity, Entity prefab)
    Invokes the m_OnUpdate delegate to update this instance's label/value/max based on the given entity and its prefab. Intended to be called by the UI when an update is required.

  • public void Write(IJsonWriter writer)
    Serializes this CapacityInfo into JSON using the provided writer. The implementation writes the runtime type full name, then the three properties "label", "value", and "max" (in that order), and then ends the type block. Note: the type name is obtained via GetType().FullName.

Usage Example

// Create a CapacityInfo that displays for all prefabs and fills in label/value/max on update.
var cap = new CapacityInfo(
    shouldDisplay: (entity, prefab) => true,
    onUpdate: (entity, prefab, info) =>
    {
        // Example update: set label and calculate values from components
        info.label = "Storage";
        // These would normally read actual game data for the entity/prefab
        info.value = 120;
        info.max = 200;
    }
);

// Later, when the UI wants to know if it should show this entry:
if (cap.DisplayFor(someEntity, somePrefab))
{
    cap.OnRequestUpdate(someEntity, somePrefab);
    // cap.label, cap.value, cap.max are now populated and can be displayed
}

// Serialize to JSON:
using (var writer = /* obtain IJsonWriter from context */ null)
{
    cap.Write(writer);
}