Game.UI.InGame.ISubsectionSource
Assembly:
{{ Likely defined in the game's managed assembly (e.g. Assembly-CSharp.dll) — check your mod project's references to locate the concrete assembly that contains the Game.* types. }}
Namespace: Game.UI.InGame
Type:
Interface
Base:
IJsonWritable (Colossal.UI.Binding)
Summary:
ISubsectionSource is a small interface used by UI code to supply and refresh the data shown in a subsection of an in-game UI panel. Implementors decide whether the subsection should be displayed for a given Entity/prefab pair and are notified when an update is requested. Because it inherits IJsonWritable, implementors must also provide JSON serialization behavior expected by the UI binding system.
Fields
- (none)
This interface declares no fields.
Properties
- (none)
This interface declares no properties.
Constructors
- (none)
Interfaces cannot define constructors. Implementing classes supply any necessary construction logic.
Methods
bool DisplayFor(Entity entity, Entity prefab)
Determines whether the subsection should be displayed for the provided entity and its prefab. Return true to show the subsection (and allow the UI to query or render it), false to hide it. Typical implementations check the entity's type, components, or the prefab identity.
Parameters: - entity: Unity.Entities.Entity — the specific entity instance (may be Entity.Null when referring to prefab-only). - prefab: Unity.Entities.Entity — the prefab entity that describes common data for instances.
void OnRequestUpdate(Entity entity, Entity prefab)
Called by the UI system when it needs the subsection's data refreshed. Implementations should enqueue or perform whatever data gathering is necessary so the UI can read fresh values (or raise an event/notify the UI binding). This method is purely a request; it should avoid long blocking operations on the UI thread and prefer scheduling asynchronous/queued work if heavy work is needed.
Notes about IJsonWritable: - Because ISubsectionSource extends Colossal.UI.Binding.IJsonWritable, a concrete implementation must also implement the JSON serialization methods required by that interface so the UI binding framework can serialize the subsection's state. Check the Colossal.UI.Binding.IJsonWritable definition in your modding environment for the exact method signatures to implement.
Usage Example
using Colossal.UI.Binding;
using Unity.Entities;
using Game.UI.InGame;
// Example implementation skeleton (illustrative).
public class MySubsectionSource : ISubsectionSource
{
// Decide whether to display this subsection for the given entity/prefab.
public bool DisplayFor(Entity entity, Entity prefab)
{
// Example logic:
// - Show for a specific prefab
// - Or show only when the entity is valid and has a certain component
if (prefab == Entity.Null)
return false;
// TODO: replace with real checks against prefab or entity components
return true;
}
// Called when the UI requests a data refresh for the subsection.
public void OnRequestUpdate(Entity entity, Entity prefab)
{
// Schedule or perform a data refresh.
// Avoid blocking the caller — queue job or mark data dirty for next frame.
}
// IJsonWritable implementation
// The exact signature(s) to implement depend on Colossal.UI.Binding.IJsonWritable in your environment.
// Implement the required JSON serialization methods so the UI binding can read the subsection state.
//
// Example (pseudo-code — verify actual API):
// public void WriteJson(JsonWriter writer)
// {
// writer.WritePropertyName("visible");
// writer.Write(BooleanToJson(DisplayFor(entity, prefab)));
// // Write other properties as needed.
// }
}
Additional tips: - Treat Entity and prefab values according to Unity.Entities (ECS). prefab is often used to detect what kind of object the entity is an instance of. - Keep OnRequestUpdate light-weight — use job systems or background caches where possible and notify the UI when new data is ready. - Implement and test the exact IJsonWritable methods from Colossal.UI.Binding to ensure proper serialization for the UI binding framework.