ITooltip - jimdroberts/FishMMO GitHub Wiki
Interface for objects that provide tooltip information for UI display. Includes icon, name, description, and formatted tooltip text.
-
Sprite Icon { get; }
Gets the icon sprite to display in the tooltip.
-
string Name { get; }
Gets the display name for the tooltip.
-
string GetFormattedDescription()
Returns a formatted description string for the tooltip, including rich text or color formatting. Returns: The formatted description string.
-
string Tooltip()
Returns the tooltip text for this object, typically including name, description, and stats. Returns: The tooltip text.
-
string Tooltip(List combineList)
Returns a combined tooltip text for this object and a list of other tooltips, used for comparison or aggregation. combineList (List): A list of other ITooltip objects to combine with this tooltip. Returns: The combined tooltip text.
- Implement ITooltip on your item, ability, or entity class.
- Provide logic for Icon, Name, GetFormattedDescription, and Tooltip methods to supply tooltip data.
- Use the interface to display tooltips in UI elements, inventory, or comparison windows.
// Example 1: Implementing ITooltip for an item
public class Sword : ITooltip {
public Sprite Icon => swordIcon;
public string Name => "Sword of Power";
public string GetFormattedDescription() => "<color=yellow>Legendary sword.</color>";
public string Tooltip() => $"{Name}\n{GetFormattedDescription()}";
public string Tooltip(List<ITooltip> combineList) => Tooltip() + "\n" + string.Join("\n", combineList.Select(t => t.Tooltip()));
}
// Example 2: Displaying a tooltip in UI
var tooltip = item.Tooltip();
tooltipUI.SetText(tooltip);
- Always provide clear and informative tooltip text for all interactive objects.
- Use GetFormattedDescription for rich text and color formatting to enhance readability.
- Implement Tooltip(List) for comparison or aggregation scenarios in UI.
- Use ITooltip for all items, abilities, and entities that require tooltips in the game UI.