Game.UI.Widgets.GradientSliderField
Assembly: Assembly-CSharp
Namespace: Game.UI.Widgets
Type: public class
Base: FloatSliderField
Summary:
A UI slider field specialized for float values that supports a color gradient and provides an icon source. Intended for use in Cities: Skylines 2 mod UI code. It overrides the slider's default min/max to the full float range, converts incoming double4 values to the field type, and serializes its gradient and icon source when writing properties.
Fields
None (no private fields declared)
This class does not declare any explicit private fields in the provided source.
Properties
-
protected override float defaultMin { get; }
Returns the default minimum value for the slider. This override returns float.MinValue, making the slider's default minimum the smallest representable float. -
protected override float defaultMax { get; }
Returns the default maximum value for the slider. This override returns float.MaxValue, making the slider's default maximum the largest representable float. -
public ColorGradient gradient { get; set; }
Holds the color gradient used by the slider. This is a public auto-property; the actual ColorGradient type is expected to be the game's gradient representation (used to render or serialize gradient data). -
public Func<string> iconSrc { get; set; }
A function that returns the icon source string (e.g., a resource path or identifier). Implementing IIconProvider, this property supplies the icon path on demand when serializing or rendering.
Constructors
public GradientSliderField()
No explicit constructor is declared in the source; the default parameterless constructor is used. Initialization of properties should be done after construction (e.g., set gradient and iconSrc).
Methods
-
public override float ToFieldType(double4 value)
Converts a double4 value (likely from some underlying data buffer or binding) to the slider's field type (float). Implementation returns (float)value.x — using the X component of the double4 vector. -
protected override void WriteProperties(IJsonWriter writer)
Serializes extra properties for this widget. Implementation: - Calls base.WriteProperties(writer) to allow the base class to write its data.
- Writes a "gradient" property and serializes the gradient value.
- Writes an "iconSrc" property and writes the result of iconSrc() (calls the Func
to get the icon string).
Usage Example
// Create a GradientSliderField, set gradient and icon provider
var slider = new GradientSliderField();
// assign a ColorGradient (constructed elsewhere)
slider.gradient = myColorGradient;
// provide an icon source function (can be a lambda)
slider.iconSrc = () => "Icons/MySliderIcon";
// the slider will use float.MinValue / float.MaxValue as defaults,
// convert incoming double4 values using the X component,
// and will write "gradient" and "iconSrc" when serialized.
Notes and tips: - Ensure iconSrc is assigned before serialization; WriteProperties calls iconSrc() without null checks. - If you need clamped ranges, override or set min/max via inherited mechanisms instead of relying on defaultMin/defaultMax. - The class relies on IJsonWriter for serialization; ensure your writer knows how to serialize ColorGradient (the game's gradient type).