ITooltip - jimdroberts/FishMMO GitHub Wiki

Description

Interface for objects that provide tooltip information for UI display. Includes icon, name, description, and formatted tooltip text.


API Access

Properties

  • Sprite Icon { get; }

    Gets the icon sprite to display in the tooltip.

  • string Name { get; }

    Gets the display name for the tooltip.

Methods

  • 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.


Basic Usage

Setup

  1. Implement ITooltip on your item, ability, or entity class.
  2. Provide logic for Icon, Name, GetFormattedDescription, and Tooltip methods to supply tooltip data.
  3. Use the interface to display tooltips in UI elements, inventory, or comparison windows.

Example

// 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);

Best Practices

  • 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.
⚠️ **GitHub.com Fallback** ⚠️