/// <summary> /// Raises the tooltip event. /// </summary> /// <param name="show">If set to <c>true</c> show.</param> public virtual void OnTooltip(bool show) { if (!this.enabled || !this.IsActive()) { return; } // If we are showing the tooltip if (show) { UITooltip.InstantiateIfNecessary(this.gameObject); for (int i = 0; i < this.m_ContentLines.Length; i++) { UITooltipLineContent line = this.m_ContentLines[i]; if (line.IsSpacer) { UITooltip.AddSpacer(); } else { if (line.LineStyle != UITooltipLines.LineStyle.Custom) { UITooltip.AddLine(line.Content, line.LineStyle); } else { UITooltip.AddLine(line.Content, line.CustomLineStyle); } } } if (this.m_WidthMode == WidthMode.Preferred) { UITooltip.SetHorizontalFitMode(ContentSizeFitter.FitMode.PreferredSize); } // Anchor to this slot if (this.m_Position == Position.Anchored) { UITooltip.AnchorToRect(this.transform as RectTransform); } // Handle offset override if (this.m_OverrideOffset) { UITooltip.OverrideOffset(this.m_Offset); UITooltip.OverrideAnchoredOffset(this.m_Offset); } // Show the tooltip UITooltip.Show(); } else { // Hide the tooltip UITooltip.Hide(); } }
/// <summary> /// Prepares the tooltip with the specified item info. /// </summary> /// <param name="itemInfo">Item info.</param> public static void PrepareTooltip(UIItemInfo itemInfo) { if (itemInfo == null) { return; } // Set the tooltip width if (UITooltipManager.Instance != null) { UITooltip.SetWidth(UITooltipManager.Instance.itemTooltipWidth); } // Set the title and description UITooltip.AddTitle("<color=#" + UIItemQualityColor.GetHexColor(itemInfo.Quality) + ">" + itemInfo.Name + "</color>"); // Spacer UITooltip.AddSpacer(); // Item types UITooltip.AddLineColumn(itemInfo.Type, "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.Subtype, "ItemAttribute"); if (itemInfo.ItemType == 1) { UITooltip.AddLineColumn(itemInfo.Damage.ToString() + " Damage", "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.AttackSpeed.ToString("0.0") + " Attack speed", "ItemAttribute"); UITooltip.AddLine("(" + ((float)itemInfo.Damage / itemInfo.AttackSpeed).ToString("0.0") + " damage per second)", "ItemAttribute"); } else { UITooltip.AddLineColumn(itemInfo.Armor.ToString() + " Armor", "ItemAttribute"); UITooltip.AddLineColumn(itemInfo.Block.ToString() + " Block", "ItemAttribute"); } UITooltip.AddSpacer(); UITooltip.AddLine("+" + itemInfo.Stamina.ToString() + " Stamina", "ItemStat"); UITooltip.AddLine("+" + itemInfo.Strength.ToString() + " Strength", "ItemStat"); UITooltip.AddSpacer(); UITooltip.AddLine("Durability " + itemInfo.Durability + "/" + itemInfo.Durability, "ItemAttribute"); if (itemInfo.RequiredLevel > 0) { UITooltip.AddLine("Requires Level " + itemInfo.RequiredLevel, "ItemAttribute"); } // Set the item description if not empty if (!string.IsNullOrEmpty(itemInfo.Description)) { UITooltip.AddSpacer(); UITooltip.AddLine(itemInfo.Description, "ItemDescription"); } }
public static void PrepareTooltip(UISpellInfo spellInfo) { // Make sure we have spell info, otherwise game might crash if (spellInfo == null) { return; } // Set the tooltip width if (UITooltipManager.Instance != null) { UITooltip.SetWidth(UITooltipManager.Instance.spellTooltipWidth); } // Set the spell name as title UITooltip.AddLine(spellInfo.Name, "SpellTitle"); // Spacer UITooltip.AddSpacer(); // Prepare some attributes if (spellInfo.Flags.Has(UISpellInfo_Flags.Passive)) { UITooltip.AddLine("Passive", "SpellAttribute"); } else { // Power consumption if (spellInfo.PowerCost > 0f) { if (spellInfo.Flags.Has(UISpellInfo_Flags.PowerCostInPct)) { UITooltip.AddLineColumn(spellInfo.PowerCost.ToString("0") + "% Energy", "SpellAttribute"); } else { UITooltip.AddLineColumn(spellInfo.PowerCost.ToString("0") + " Energy", "SpellAttribute"); } } // Range if (spellInfo.Range > 0f) { if (spellInfo.Range == 1f) { UITooltip.AddLineColumn("Melee range", "SpellAttribute"); } else { UITooltip.AddLineColumn(spellInfo.Range.ToString("0") + " yd range", "SpellAttribute"); } } // Cast time if (spellInfo.CastTime == 0f) { UITooltip.AddLineColumn("Instant", "SpellAttribute"); } else { UITooltip.AddLineColumn(spellInfo.CastTime.ToString("0.0") + " sec cast", "SpellAttribute"); } // Cooldown if (spellInfo.Cooldown > 0f) { UITooltip.AddLineColumn(spellInfo.Cooldown.ToString("0.0") + " sec cooldown", "SpellAttribute"); } } // Set the spell description if not empty if (!string.IsNullOrEmpty(spellInfo.Description)) { UITooltip.AddSpacer(); UITooltip.AddLine(spellInfo.Description, "SpellDescription"); } }