Game.UI.Widgets.NamedWidgetWithTooltip
Assembly:
Game
Namespace:
Game.UI.Widgets
Type:
abstract class
Base:
NamedWidget
Implements: ITooltipTarget, IUITagProvider
Summary:
NamedWidgetWithTooltip is an abstract UI widget that extends NamedWidget to provide optional tooltip and UI tag support. It exposes two nullable properties (tooltip and uiTag) and serializes them into JSON via an overridden WriteProperties method. The tooltip uses a localized string (LocalizedString) to support localization; uiTag is a plain string used for tagging the widget for tooling or identification.
Fields
- This type declares no explicit fields. All state is exposed via properties.
Properties
-
public LocalizedString? tooltip { get; set; }
[CanBeNull] Optional localized tooltip text for the widget. This property is written to JSON under the "tooltip" property name by WriteProperties. Implemented to satisfy ITooltipTarget (or the expected tooltip contract). -
public string? uiTag { get; set; }
[CanBeNull] Optional UI tag (arbitrary string) that can be used to identify or categorize the widget. This property is written to JSON under the "uiTag" property name by WriteProperties. Provided to satisfy IUITagProvider.
Constructors
- No explicit constructors are declared. The class relies on the default parameterless constructor provided by the compiler.
Methods
protected override void WriteProperties(IJsonWriter writer) : System.Void
Override of NamedWidget.WriteProperties to add serialization of the tooltip and uiTag properties. Implementation details:- Calls base.WriteProperties(writer) first to serialize base-class properties.
- Writes a property named "tooltip" and serializes the tooltip value (which may be null).
- Writes a property named "uiTag" and serializes the uiTag value (which may be null). This ensures the widget's tooltip and tag are included when the widget is exported to JSON.
Usage Example
public class MyNamedButton : NamedWidgetWithTooltip
{
public MyNamedButton()
{
// Assign a localized tooltip (construction may depend on your LocalizedString API)
tooltip = new LocalizedString("ui.tooltip.my_button"); // example key
// Assign an optional UI tag for tooling/identification
uiTag = "MyMod:MainMenuButton";
}
// If you need to write additional properties, override WriteProperties and call base:
protected override void WriteProperties(IJsonWriter writer)
{
base.WriteProperties(writer);
// write additional custom properties here
}
}
Notes: - Both properties are nullable; when null they will still be written (typically serialized as null) by WriteProperties unless the IJsonWriter implementation omits nulls. - The class itself is abstract — create a concrete subclass to instantiate a widget. - The [CanBeNull] annotations indicate callers should handle possible null values for tooltip and uiTag.