Game.UI.Widgets.InvokableBindings
Assembly:
Assembly-CSharp
Namespace: Game.UI.Widgets
Type:
class
Base:
IWidgetBindingFactory
Summary:
InvokableBindings is a small binding-factory used by the UI binding system (Colossal.UI.Binding). It produces a TriggerBinding keyed to "invoke" that, when triggered, attempts to cast the resolved widget to IInvokable and call its Invoke() method. If the widget path does not resolve or the resolved widget does not implement IInvokable, the binding logs an error via UnityEngine.Debug.LogError. This factory is useful to wire up button-like widgets or other UI elements that support a generic Invoke action from UI markup or a binding configuration.
Fields
None
This class does not declare any fields. It is a stateless factory that yields bindings on demand.
Properties
None
There are no public or private properties declared on this class.
Constructors
public InvokableBindings()
The default parameterless constructor is used (implicit). No initialization is required because the class is stateless.
Methods
-
public System.Collections.Generic.IEnumerable<Colossal.UI.Binding.IBinding> CreateBindings(string group, IReader<IWidget> pathResolver, ValueChangedCallback onValueChanged)
Creates and yields bindings for the given group. Currently this factory yields a single TriggerBinding with the name "invoke". The produced binding uses the supplied pathResolver to resolve an IWidget at runtime; when the binding is triggered it: -
checks if the resolved widget implements IInvokable
- if so, calls IInvokable.Invoke() on that widget
- otherwise logs an error using UnityEngine.Debug.LogError with one of two messages:
- "Widget does not implement IInvokable" when a widget is resolved but doesn't implement the interface
- "Invalid widget path" when the pathResolver fails to resolve a widget (widget == null)
Note: the ValueChangedCallback parameter is accepted to satisfy the IWidgetBindingFactory signature but is not used by this implementation.
Usage Example
// Example: registering and using the factory to obtain bindings.
// `pathResolver` and `onValueChanged` would normally come from the UI binding system.
var factory = new Game.UI.Widgets.InvokableBindings();
IReader<IWidget> pathResolver = /* obtain from your UI system */;
ValueChangedCallback callback = (name, value) => { /* optional */ };
foreach (var binding in factory.CreateBindings("myGroup", pathResolver, callback))
{
// Register the binding with the UI binding host, or apply it to a widget.
// Exact registration depends on the Colossal.UI.Binding host you are using.
// The created TriggerBinding will attempt to call IInvokable.Invoke() on the resolved widget.
}
Additional notes: - Depends on Colossal.UI.Binding and UnityEngine for IBinding types and logging. - Ensure that widgets you intend to use with the "invoke" binding implement the IInvokable interface. Otherwise you'll see error logs when the binding is activated.