Game.UI.Widgets.TimeFieldBuilders
Assembly:
Assembly-CSharp (game assembly)
Namespace:
Game.UI.Widgets
Type:
public class
Base:
IFieldBuilderFactory
Summary:
Factory that creates FieldBuilder delegates for time-related fields. It inspects a member type and a collection of attributes to determine whether a time control should be used, and if so returns a FieldBuilder that constructs either a TimeSliderField (for single float time values) or a TimeBoundsSliderField (for time ranges represented by Colossal.Mathematics.Bounds1). The produced field instances are configured with min/max ranges (from attributes when present) and a typed accessor wrapper (CastAccessor) around the provided IValueAccessor.
Fields
- This class does not declare any instance or static fields.
The behavior is implemented entirely in TryCreate; state is not kept in this factory.
Properties
- This class does not expose any properties.
Constructors
public TimeFieldBuilders()
Default public constructor (implicit). No special initialization is performed.
Methods
public FieldBuilder TryCreate(Type memberType, object[] attributes)
Attempts to create a FieldBuilder for the given member type and attributes.
Details:
- Returns a FieldBuilder delegate when the attributes indicate a time field (WidgetAttributeUtils.IsTimeField(attributes)) and the member type is one of the supported types:
- float: returns a FieldBuilder that constructs a TimeSliderField.
- Reads optional numeric range via WidgetAttributeUtils.GetNumberRange(attributes, ref min, ref max). Defaults: min = 0f, max = 1f.
- The created TimeSliderField has min, max set and uses a CastAccessor
Parameters: - memberType — The System.Type of the member to build a field for (e.g., typeof(float) or typeof(Bounds1)). - attributes — An array of attribute objects (or descriptor objects) used to decide field behavior (range, time flag, allowsMinGreaterMax, etc.).
Notes:
- This method relies on helper utilities and types:
- WidgetAttributeUtils.IsTimeField, GetNumberRange, AllowsMinGreaterMax
- TimeSliderField, TimeBoundsSliderField
- CastAccessor
Usage Example
// Example: resolving a FieldBuilder for a float time property
var factory = new TimeFieldBuilders();
object[] attributes = /* attributes array that includes the "time field" marker and optional range info */;
FieldBuilder builder = factory.TryCreate(typeof(float), attributes);
if (builder != null)
{
IValueAccessor accessor = /* obtain an accessor for the target value */;
var field = builder(accessor); // returns a TimeSliderField with min/max and a CastAccessor<float>
}
// Example: resolving a FieldBuilder for a time range (Bounds1)
FieldBuilder rangeBuilder = factory.TryCreate(typeof(Colossal.Mathematics.Bounds1), attributes);
if (rangeBuilder != null)
{
IValueAccessor rangeAccessor = /* obtain accessor for Bounds1 value */;
var rangeField = rangeBuilder(rangeAccessor); // returns a TimeBoundsSliderField
}
Additional remarks: - If you need different default ranges or behavior, adjust attributes consumed by WidgetAttributeUtils or apply a custom factory that implements IFieldBuilderFactory. - The class is simple and side-effect free — safe to instantiate once and reuse.