Game.UI.Widgets.ListBindings
Assembly:
Assembly-CSharp
Namespace:
Game.UI.Widgets
Type:
public class
Base:
Colossal.UI.Binding.IWidgetBindingFactory
Summary:
Factory that produces IBinding instances for list-related widget operations. The bindings created are trigger bindings that operate on widgets implementing IListWidget and expose actions to add, duplicate, move, delete, and clear list elements. Each binding verifies the target widget implements IListWidget, invokes the respective IListWidget method, and calls a provided onValueChanged callback after a successful change. If the resolved widget does not implement IListWidget (or resolution fails), an error is logged via UnityEngine.Debug.LogError.
Fields
- This class does not declare any fields.
The implementation only yields binding instances from the CreateBindings method and holds no instance state.
Properties
- This class does not declare any properties.
Constructors
public ListBindings()
Implicit parameterless constructor. The class has no constructor logic; instantiate and use the CreateBindings method to obtain bindings.
Methods
-
public IEnumerable<Colossal.UI.Binding.IBinding> CreateBindings(string group, Colossal.UI.Binding.IReader<Colossal.UI.IWidget> pathResolver, Colossal.UI.Binding.ValueChangedCallback onValueChanged)
Creates and yields a set of TriggerBinding instances for list operations. The yielded bindings and their behaviors: -
Binding name "addListElement" (TriggerBinding
): - Action: If the resolved widget implements IListWidget, calls AddElement() and then invokes onValueChanged(widget).
- Error: If widget is null or does not implement IListWidget, logs "Invalid widget path" or "Widget does not implement IListContainer".
-
Binding name "duplicateListElement" (TriggerBinding
): - Action: If the resolved widget implements IListWidget, calls DuplicateElement(index) and invokes onValueChanged(widget).
- Error: Same logging behavior as above.
-
Binding name "moveListElement" (TriggerBinding
): - Action: If the resolved widget implements IListWidget, calls MoveElement(fromIndex, toIndex) and invokes onValueChanged(widget).
- Error: Same logging behavior as above.
-
Binding name "deleteListElement" (TriggerBinding
): - Action: If the resolved widget implements IListWidget, calls DeleteElement(index) and invokes onValueChanged(widget).
- Error: Same logging behavior as above.
-
Binding name "clearList" (TriggerBinding
): - Action: If the resolved widget implements IListWidget, calls Clear() and invokes onValueChanged(widget).
- Error: Same logging behavior as above.
Notes: - The method uses yield return, so bindings are produced lazily as the returned IEnumerable is enumerated. - The method depends on the provided pathResolver to resolve widget paths to actual IWidget instances. The provided onValueChanged callback is invoked whenever a list-modifying operation runs successfully. - The class references Colossal.UI.Binding types (TriggerBinding, IBinding, IReader, ValueChangedCallback) and UnityEngine.Debug for error logging.
Usage Example
// Example: obtaining bindings from the factory and registering them with some host binder.
var factory = new Game.UI.Widgets.ListBindings();
IReader<IWidget> pathResolver = /* obtain or implement a path resolver */;
ValueChangedCallback onValueChanged = widget => {
// handle update, e.g. refresh UI, mark dirty, etc.
Debug.Log($"Widget changed: {widget?.name}");
};
foreach (var binding in factory.CreateBindings("myListGroup", pathResolver, onValueChanged))
{
// register binding with your binding host / binder
// binder.Register(binding);
}