Game.UI.Widgets.ImageField
Assembly: Assembly-CSharp
Namespace: Game.UI.Widgets
Type: public class
Base: Widget, ITooltipTarget
Summary:
ImageField is a small UI widget that represents an image entry with an associated localized label and optional tooltip. It exposes public fields for the image URI and the label and implements ITooltipTarget via a nullable LocalizedString property. When serializing its properties to JSON (via an IJsonWriter), it writes the keys "uri", "label" and "tooltip".
Fields
-
public System.String m_URI
Represents the image resource identifier (URI). This is written out as the "uri" property when the widget serializes itself. -
public Game.UI.Localization.LocalizedString m_Label
A localized label associated with the image. This is written out as the "label" property during serialization.
Properties
public Game.UI.Localization.LocalizedString? tooltip { get; set; }
Optional localized tooltip text for the widget. Implementing ITooltipTarget allows UI systems to query this value to show contextual help. This property is written out as the "tooltip" property; it may be null.
Constructors
public ImageField()
No explicit constructor is defined in the source file; the type uses the default parameterless constructor. Typical initialization is done by assigning to the public fields/properties after construction or by the UI framework when deserializing.
Methods
protected override void WriteProperties(Colossal.UI.Binding.IJsonWriter writer) : void
Overrides Widget.WriteProperties. Calls the base implementation and then writes three properties to the provided IJsonWriter:"uri"
→ writes m_URI"label"
→ writes m_Label"tooltip"
→ writes tooltip (nullable) This method is used when the widget is serialized to JSON (for saving, layout export, or passing widget data to other systems).
Usage Example
// Create and initialize an ImageField in code
var imgField = new ImageField();
imgField.m_URI = "assets/images/building_icon.png";
imgField.m_Label = new LocalizedString("BUILDING_NAME_KEY");
imgField.tooltip = new LocalizedString("TOOLTIP_BUILDING");
// When the UI framework serializes the widget, WriteProperties will emit:
// { "uri": "assets/images/building_icon.png", "label": <localized label>, "tooltip": <localized tooltip> }
Notes and implementation details: - LocalizedString refers to the game's localization wrapper (namespace Game.UI.Localization). It should be used when the text must be localized for different languages. - IJsonWriter is from Colossal.UI.Binding and is used across the UI system for JSON serialization of widgets and properties. - Although the fields use an "m_" prefix, they are public in this class; be careful when modifying them from outside if immutability is desired.