Game.UI.InGame.ISubsectionProvider
Assembly: Assembly-CSharp
Namespace: Game.UI.InGame
Type: interface
Base: ISectionSource, IJsonWritable
Summary:
Represents a provider of subsection sources for an in-game UI section. Implementors expose a collection of ISubsectionSource instances that the UI can enumerate and render. The interface itself adds the subsections collection to the contracts defined by ISectionSource (section-level metadata/behavior) and IJsonWritable (ability to serialize to JSON for save/export or UI state persistence).
Fields
- This interface declares no instance fields. Implementations are responsible for any backing fields they require.
Properties
public System.Collections.Generic.List<ISubsectionSource> subsections { get; }
Exposes the list of subsection sources provided by this provider. The property is read-only from the interface perspective (no setter), but the returned List instance itself can be mutated by the implementor or consumers (add/remove). Implementations should ensure this property never returns null (return an empty list instead) so callers can safely iterate. This collection is typically enumerated by the UI framework to build child elements under a section.
Constructors
- Interfaces do not declare constructors. Implementations should initialize the subsections list (for example, with an empty List
) in their constructors.
Methods
- This interface declares no additional methods. Implementers must also satisfy members inherited from:
- ISectionSource — (section identity/metadata, lifecycle hooks, etc.; see that interface for specifics).
- IJsonWritable — requires implementing JSON serialization logic so the provider (and its subsections) can be written to JSON. Ensure subsections are included in the serialization if they should be persisted.
Usage Example
using System.Collections.Generic;
using Colossal.UI.Binding;
using Game.UI.InGame;
// Example implementation of ISubsectionProvider
public class ExampleSubsectionProvider : ISubsectionProvider
{
// Always return a non-null list
public List<ISubsectionSource> subsections { get; } = new List<ISubsectionSource>();
// --- ISectionSource members (implement as required by your project) ---
// e.g. public string sectionId => "example";
// e.g. public string title => "Example Section";
// (Actual members depend on ISectionSource definition.)
// --- IJsonWritable member(s) ---
// Example pseudo-implementation — replace with the correct signature from IJsonWritable
public void WriteJson(/* appropriate writer type */ object writer)
{
// Serialize section metadata...
// Serialize subsections collection...
// For each ISubsectionSource in subsections, call its JSON write method as needed.
}
// Additional initialization / helpers as needed to populate subsections
}
Notes and recommendations: - Ensure subsections is initialized (empty list) so UI code can enumerate it without null checks. - Populate subsections on construction or lazily before the UI consumes them. - When serializing (IJsonWritable), include enough information to restore subsections on load (IDs, types, minimal state). - Follow main-thread constraints: UI-related collections and modifications should generally occur on the UI/main thread used by the game/mod.