Skip to content

Game.UI.Widgets.IWidgetBindingFactory

Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Widgets

Type: Interface

Base: None (interface)

Summary:
Interface used by the UI system / mods to create a collection of data bindings (Colossal.UI.Binding.IBinding) for a named group of widgets. Implementations take a group name, a path resolver to locate widgets (IReader) and a ValueChangedCallback to wire change notifications, and return an enumerable of IBinding instances that connect UI widgets to model/state. This is an extensibility point for modular widget binding creation — for example, a UI builder can ask a factory for all bindings in the "settings" group and register them with the binding system.


Fields

  • None
    This is an interface and defines no fields.

Properties

  • None
    The interface exposes no properties.

Constructors

  • None
    Interfaces do not declare constructors.

Methods

  • IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
    Creates and returns a sequence of IBinding instances for the specified group.

  • group: Logical group name used by the factory to decide which bindings to create (for example "MainPanel", "AudioSettings", etc.). Implementations commonly use the group to build widget paths or to select a set of bindings.

  • pathResolver: An IReader used to resolve widget references by path or key. Implementations should use this to locate widgets they need to bind to.
  • onValueChanged: A ValueChangedCallback provided by the caller. Implementations should attach or call this callback when a binding detects/produces a value change so the rest of the system can react.

Returns: An enumerable of IBinding instances. Implementations should prefer returning an empty collection rather than null when there are no bindings for the supplied group.

Notes: - Created bindings are typically registered with the binding system by the caller; the factory is responsible only for producing the binding objects. - Binding creation and widget resolution generally run on the UI/main thread — ensure implementations follow the game's threading model. - Keep implementations defensive: verify pathResolver results before creating bindings and avoid throwing from CreateBindings when possible.

Usage Example

// Example implementation that demonstrates the pattern.
// Actual binding types (e.g. SliderBinding, ToggleBinding) depend on the binding library you use.

public class MyWidgetBindingFactory : IWidgetBindingFactory
{
    public IEnumerable<IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
    {
        // Resolve widgets using the provided resolver. Paths are illustrative.
        var volumeSlider = pathResolver.Read(group + ".VolumeSlider");
        if (volumeSlider != null)
        {
            // Construct an IBinding that connects the slider to a model property
            // The concrete binding type depends on your binding implementation.
            yield return new SliderValueBinding(volumeSlider, onValueChanged);
        }

        var muteToggle = pathResolver.Read(group + ".MuteToggle");
        if (muteToggle != null)
        {
            yield return new ToggleBinding(muteToggle, onValueChanged);
        }

        // If nothing found, yield nothing (caller will get an empty enumeration)
    }
}

// Example consumer usage:
var factory = new MyWidgetBindingFactory();
foreach (var binding in factory.CreateBindings("AudioSettings", widgetReader, OnBindingValueChanged))
{
    binding.Register(); // register or attach the binding as required by your binding system
}