Skip to content

Game.UI.InGame.ISectionSource

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

Type: interface

Base: Colossal.UI.Binding.IJsonWritable

Summary:
ISectionSource is a small UI-facing interface used by in-game UI sections to request and perform updates. It extends IJsonWritable (from Colossal.UI.Binding) so implementations can provide a JSON representation of their state for UI binding/serialization. Typical implementations are lightweight data providers for a UI section that can schedule refreshes (RequestUpdate) and then carry out the refresh work (PerformUpdate), usually on the UI/main thread.


Fields

  • This interface declares no fields.
    {{ Implementations may store internal fields (e.g., flags or cached data) to track pending updates or the section's state. }}

Properties

  • This interface declares no properties.
    {{ Implementations may expose properties as needed. The IJsonWritable base may require implementing members for JSON serialization. }}

Constructors

  • Interfaces cannot declare constructors.
    {{ Implementations should provide their own construction / initialization logic. Consider providing a lightweight default constructor and an initialization method if needed for DI or lifecycle management. }}

Methods

  • void RequestUpdate()
    {{ Signals that the section needs to be refreshed. This method should be cheap — typically it sets a flag or enqueues a work item so the actual update can be performed later (for example, on the next UI update tick). Avoid doing heavy work here. }}

  • void PerformUpdate()
    {{ Carries out the actual update/refresh work for the section. The UI framework or the owning component should call this when it's appropriate (e.g., while processing pending updates on the main thread). Implementations should clear any pending-update flags and update internal state / data used by the UI. Ensure thread-safety and that UI changes happen on the UI/main thread. }}

Usage Example

using Colossal.UI.Binding;
using UnityEngine.Scripting;

[Preserve]
public class MySectionSource : ISectionSource
{
    private bool m_needsUpdate;
    private object m_cachedData;

    // Request a refresh — cheap (sets a flag)
    public void RequestUpdate()
    {
        m_needsUpdate = true;
    }

    // Perform the actual update when the UI system decides to call it
    public void PerformUpdate()
    {
        if (!m_needsUpdate) return;

        // Example: rebuild or fetch data for the UI section
        m_cachedData = FetchDataForUI();

        // Clear pending flag
        m_needsUpdate = false;
    }

    // IJsonWritable: provide JSON output for UI binding / persistence.
    // The actual method signature depends on the IJsonWritable definition in Colossal.UI.Binding.
    // Implement the required serialization method(s) here.
    // public void WriteJson(JsonWriter writer) { ... }

    private object FetchDataForUI()
    {
        // Replace with real data gathering logic
        return new { time = System.DateTime.UtcNow.ToString("o") };
    }
}

{{ Notes: - This interface is intentionally minimal to decouple scheduling of updates (RequestUpdate) from the work of performing them (PerformUpdate). - Implementations should follow the host UI's lifecycle and threading model — typically updates should be executed on the UI/main thread. - Because the interface extends IJsonWritable, implementers should also provide JSON serialization to expose state to UI bindings or save/load workflows. }}