Game.UI.Widgets.LocalizedValueField
Assembly:
Game
Namespace:
Game.UI.Widgets
Type:
class
Base:
ReadonlyField
Summary:
A read-only UI field for displaying a LocalizedString value with optional warning state support. The control exposes a warningAction callback that can be evaluated every update to toggle a visual "warning" state. Setting the warning property directly clears any warningAction callback.
Fields
private bool m_Warning
Stores the current warning state for the field. Used internally to detect changes and trigger property updates.
Properties
-
public Func<bool> warningAction { get; set; }
[CanBeNull] Optional callback that, when provided, is evaluated during Update() to determine whether the field should be in a warning state. If this callback is set and returns a different value than the current m_Warning, the widget marks its properties as changed. -
public bool warning { get; private set }
Public-facing boolean indicating whether the field is in a warning state. Getting returns the current m_Warning. Setting the property clears any existing warningAction (sets it to null) and updates m_Warning directly.
Constructors
public LocalizedValueField()
Initializes the field and assigns base.valueWriter to a new ValueWriter(), ensuring the value can be serialized/written correctly by the base ReadonlyField implementation.
Methods
-
protected override WidgetChanges Update()
Overrides the base Update. Calls base.Update() then, if warningAction is not null, evaluates it. If the returned boolean differs from the stored m_Warning, updates m_Warning and adds WidgetChanges.Properties to the returned WidgetChanges value so the UI can react to the change. -
protected override void WriteProperties(IJsonWriter writer)
Overrides property writing to include the current warning state. Calls base.WriteProperties(writer), then writes a property named "warning" with the current value of the warning property (boolean).
Usage Example
// Create the field and add it to a parent widget (example usage)
var localizedField = new LocalizedValueField();
// Set a static warning state:
localizedField.warning = true;
// Or provide a dynamic callback that updates the warning state every update:
localizedField.warningAction = () => {
// return true if some condition is met (e.g., missing localization or invalid value)
return string.IsNullOrEmpty(localizedField.value?.text);
};
// The field will evaluate warningAction during its Update() loop and update its warning state accordingly.