Skip to content

Game.UI.Widgets.ColorField

Assembly: Game
Namespace: Game.UI.Widgets

Type: class

Base: Field

Summary:
A UI binding field for UnityEngine.Color used by the game's UI/widget system. ColorField exposes two configuration flags — hdr and showAlpha — and writes these flags into a JSON writer when the field's properties are serialized. It integrates with Colossal.UI.Binding's Field infrastructure and is intended for use in mod UI components where color values need to be bound and serialized (for example, saving/loading or sending state to other systems).


Fields

  • No private fields are declared by this class.
    This class relies on properties and the behavior provided by its base Field implementation.

Properties

  • public bool hdr { get; set; }
    Controls whether the color should be treated as HDR (high dynamic range). When true, the HDR flag is written to the JSON representation by WriteProperties.

  • public bool showAlpha { get; set; }
    Controls whether the alpha channel should be exposed/shown for the color. When true, the showAlpha flag is written to the JSON representation by WriteProperties.

Constructors

  • public ColorField()
    Default parameterless constructor (implicit). Initialize a new ColorField instance. The class does not declare any custom constructor logic in the source, so default initialization behavior from the CLR applies.

Methods

  • protected override void WriteProperties(IJsonWriter writer) : System.Void
    Overrides Field.WriteProperties to add serialization of the ColorField-specific flags. The method first calls base.WriteProperties(writer) to let the base class serialize common data for Field, then writes two additional properties into the provided IJsonWriter:
  • "hdr" : the value of the hdr property
  • "showAlpha" : the value of the showAlpha property

This ensures that when Field instances are serialized via the binding system, the HDR and alpha visibility settings are included.

Usage Example

// Typical usage in a UI widget or initializer for a color input field
var colorField = new Game.UI.Widgets.ColorField {
    hdr = true,
    showAlpha = true
};

// Set the current value (inherited from Field<Color>)
colorField.Value = UnityEngine.Color.white;

// Note: WriteProperties is protected and is called by the Field<T>/binding infrastructure
// when serializing the field. You normally don't call WriteProperties directly from user code.
// The above configuration ensures "hdr" and "showAlpha" get saved when the field is serialized.