Game.UI.Tooltip.ProgressTooltip
Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Tooltip
Type: public class ProgressTooltip
Base: LabelIconTooltip
Summary:
A tooltip control used to display a numeric progress/capacity value (current value, optional maximum and unit). It exposes properties to update the displayed value, maximum, unit label, and whether to omit the maximum from the displayed text. It also contains logic to choose a tooltip color based on how full the capacity is (using a configurable threshold constant). The class participates in the UI binding/serialization system via WriteProperties(IJsonWriter).
Fields
-
public const float kCapacityWarningThreshold = 0.75f
Threshold used to determine capacity coloring. If value >= max * kCapacityWarningThreshold the tooltip is considered in the "Info" range; below that but greater than zero is treated as "Warning"; zero is treated as "Error". Use this constant to keep coloring behavior consistent across code. -
private float m_Value
Backing field for the public value property. Holds the current numeric value displayed by the progress tooltip. -
private float m_Max
Backing field for the public max property. Holds the maximum capacity used for relative calculations and display. -
private string m_Unit = "integer"
Backing field for the public unit property. A short label for the unit of the value (for example "m³", "vehicles", "%", or "integer"). Defaults to "integer". -
private bool m_OmitMax
Backing field for the public omitMax property. When true, the tooltip will omit showing the maximum value in its displayed text (useful when a max is not applicable).
Properties
-
public float value { get; set; }
Gets or sets the current numeric value shown by the tooltip. The setter updates the backing field and calls SetPropertiesChanged() when the value changes so the UI binding/serialization system refreshes the displayed tooltip. -
public float max { get; set; }
Gets or sets the maximum capacity. Uses object.Equals in the setter to detect changes and calls SetPropertiesChanged() when changed. This value is used both for display (unless omitMax is true) and for capacity-to-color calculations. -
public string unit { get; set; }
Gets or sets the unit label shown alongside the numeric values (e.g., "m³", "units", "%"). The setter calls SetPropertiesChanged() on change. -
public bool omitMax { get; set; }
Gets or sets whether the maximum value should be omitted from the tooltip display. The setter calls SetPropertiesChanged() when changed.
Constructors
public ProgressTooltip()
Default parameterless constructor (implicit if not defined). Initializes the instance using the base LabelIconTooltip constructor; default field values: m_Unit == "integer", numeric fields == 0.0f, omitMax == false.
Methods
-
protected override void WriteProperties(IJsonWriter writer) : System.Void
Serializes the tooltip's relevant properties into the provided IJsonWriter for the UI binding/serialization system. This implementation writes the current value, max, unit and omitMax flag after calling base.WriteProperties(writer). This is used by the UI framework to transfer tooltip state to the frontend. -
public static void SetCapacityColor(ProgressTooltip tooltip) : System.Void
Sets the tooltip.color field based on the relation between tooltip.value and tooltip.max using the kCapacityWarningThreshold. Behavior: - If tooltip.value >= tooltip.max * kCapacityWarningThreshold -> sets TooltipColor.Info (indicates near/full capacity per existing logic).
- Else if tooltip.value > 0 -> sets TooltipColor.Warning.
- Else -> sets TooltipColor.Error. Note: This method expects tooltip.max to be meaningful (non-zero) for correct threshold behavior. The method touches tooltip.color (an inherited property from the base tooltip).
Usage Example
// Create or obtain an instance of the ProgressTooltip and update its properties.
// The UI binding system will pick up changes because setters call SetPropertiesChanged().
var tooltip = new ProgressTooltip();
tooltip.unit = "vehicles";
tooltip.max = 100f;
tooltip.value = 72f;
tooltip.omitMax = false;
// Update the tooltip color to reflect capacity state using the class helper.
ProgressTooltip.SetCapacityColor(tooltip);
// The tooltip will serialize its properties via WriteProperties(IJsonWriter) when the UI system requests it.