/// <summary> /// Updates the tooltip position. /// </summary> public virtual void UpdatePositionAndPivot() { if (this.m_Canvas == null) { return; } // Update the tooltip position to the mosue position // If the tooltip is not anchored to a target // Anchored position should be updated after updating the pivot if (this.m_AnchorToTarget == null) { // Convert the offset based on the pivot Vector2 pivotBasedOffset = new Vector2(((this.m_Rect.pivot.x == 1f) ? (this.m_Offset.x * -1f) : this.m_Offset.x), ((this.m_Rect.pivot.y == 1f) ? (this.m_Offset.y * -1f) : this.m_Offset.y)); Vector2 localPoint; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.m_Canvas.transform as RectTransform, Input.mousePosition, this.uiCamera, out localPoint)) { this.m_Rect.anchoredPosition = pivotBasedOffset + localPoint; } } // Update the tooltip pivot this.UpdatePivot(); // Check if we are anchored to a rect if (this.m_AnchorToTarget != null) { // Set the anchor position to the opposite of the tooltip's pivot Vector3[] targetWorldCorners = new Vector3[4]; this.m_AnchorToTarget.GetWorldCorners(targetWorldCorners); // Convert the tooltip pivot to corner Corner pivotCorner = UITooltip.VectorPivotToCorner(this.m_Rect.pivot); // Get the opposite corner of the pivot corner Corner oppositeCorner = UITooltip.GetOppositeCorner(pivotCorner); // Convert the offset based on the pivot Vector2 pivotBasedOffset = new Vector2(((this.m_Rect.pivot.x == 1f) ? (this.m_AnchoredOffset.x * -1f) : this.m_AnchoredOffset.x), ((this.m_Rect.pivot.y == 1f) ? (this.m_AnchoredOffset.y * -1f) : this.m_AnchoredOffset.y)); Vector2 screenPoint = RectTransformUtility.WorldToScreenPoint(this.uiCamera, targetWorldCorners[(int)oppositeCorner]); Vector2 localPoint; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(this.m_Canvas.transform as RectTransform, screenPoint, this.uiCamera, out localPoint)) { this.m_Rect.anchoredPosition = pivotBasedOffset + localPoint; } } }
/// <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"); } }
/// <summary> /// Updates the pivot. /// </summary> public void UpdatePivot() { // Get the mouse position Vector3 targetPosition = Input.mousePosition; // Determine which corner of the screen is closest to the mouse position Vector2 corner = new Vector2( ((targetPosition.x > (Screen.width / 2f)) ? 1f : 0f), ((targetPosition.y > (Screen.height / 2f)) ? 1f : 0f) ); // Set the pivot this.SetPivot(UITooltip.VectorPivotToCorner(corner)); }
protected virtual void Awake() { // Save instance reference mInstance = this; // Get the rect transform this.m_Rect = this.gameObject.GetComponent <RectTransform>(); // Get the canvas group this.m_CanvasGroup = this.gameObject.GetComponent <CanvasGroup>(); // Get the content size fitter this.m_SizeFitter = this.gameObject.GetComponent <ContentSizeFitter>(); }
/// <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); // Show the tooltip UITooltip.Show(); } else { // Hide the tooltip UITooltip.Hide(); } }
/// <summary> /// Raises the pointer enter event. /// </summary> /// <param name="eventData">Event data.</param> public virtual void OnPointerEnter(PointerEventData eventData) { // Check if tooltip is enabled if (this.enabled && this.IsActive()) { // Instantiate the tooltip now UITooltip.InstantiateIfNecessary(this.gameObject); // Start the tooltip delayed show coroutine // If delay is set at all if (this.m_Delay > 0f) { this.StartCoroutine("DelayedShow"); } else { this.InternalShowTooltip(); } } }
protected virtual void Awake() { // Save instance reference mInstance = this; // Get the rect transform this.m_Rect = this.gameObject.GetComponent <RectTransform>(); // Get the canvas group this.m_CanvasGroup = this.gameObject.GetComponent <CanvasGroup>(); // Make sure the tooltip does not block raycasts this.m_CanvasGroup.blocksRaycasts = false; this.m_CanvasGroup.interactable = false; // Get the content size fitter this.m_SizeFitter = this.gameObject.GetComponent <ContentSizeFitter>(); // Prepare the content size fitter this.m_SizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; // Prepare the vertical layout group VerticalLayoutGroup vlg = this.gameObject.GetComponent <VerticalLayoutGroup>(); vlg.childControlHeight = true; vlg.childControlWidth = true; // Make sure we have the always on top component UIAlwaysOnTop aot = this.gameObject.GetComponent <UIAlwaysOnTop>(); if (aot == null) { aot = this.gameObject.AddComponent <UIAlwaysOnTop>(); aot.order = UIAlwaysOnTop.TooltipOrder; } // Hide this.SetAlpha(0f); this.m_VisualState = VisualState.Hidden; this.InternalOnHide(); }
/// <summary> /// Raises the tooltip event. /// </summary> /// <param name="show">If set to <c>true</c> show.</param> public override void OnTooltip(bool show) { UITooltip.InstantiateIfNecessary(this.gameObject); // Handle unassigned if (!this.IsAssigned()) { // If we are showing the tooltip if (show) { UITooltip.AddTitle(UIEquipSlot.EquipTypeToString(this.m_EquipType)); UITooltip.SetHorizontalFitMode(ContentSizeFitter.FitMode.PreferredSize); UITooltip.AnchorToRect(this.transform as RectTransform); UITooltip.Show(); } else { UITooltip.Hide(); } } else { // Make sure we have spell info, otherwise game might crash if (this.m_ItemInfo == null) { return; } // If we are showing the tooltip if (show) { UIItemSlot.PrepareTooltip(this.m_ItemInfo); UITooltip.AnchorToRect(this.transform as RectTransform); UITooltip.Show(); } else { UITooltip.Hide(); } } }
/// <summary> /// Updates the tooltip position. /// </summary> public virtual void UpdatePositionAndPivot() { // Update the tooltip position to the mosue position // If the tooltip is not anchored to a target // Anchored position should be updated after updating the pivot if (this.m_AnchorToTarget == null) { // Convert the offset based on the pivot Vector3 pivotBasedOffset = new Vector3(((this.m_Rect.pivot.x == 1f) ? (this.m_Offset.x * -1f) : this.m_Offset.x), ((this.m_Rect.pivot.y == 1f) ? (this.m_Offset.y * -1f) : this.m_Offset.y), 0f); // Update the position including the offset this.m_Rect.position = pivotBasedOffset + Input.mousePosition; } // Update the tooltip pivot this.UpdatePivot(); // Check if we are anchored to a rect if (this.m_AnchorToTarget != null) { // Set the anchor position to the opposite of the tooltip's pivot Vector3[] targetWorldCorners = new Vector3[4]; this.m_AnchorToTarget.GetWorldCorners(targetWorldCorners); // Convert the tooltip pivot to corner Corner pivotCorner = UITooltip.VectorPivotToCorner(this.m_Rect.pivot); // Get the opposite corner of the pivot corner Corner oppositeCorner = UITooltip.GetOppositeCorner(pivotCorner); // Convert the offset based on the pivot Vector3 pivotBasedOffset = new Vector3(((this.m_Rect.pivot.x == 1f) ? (this.m_AnchoredOffset.x * -1f) : this.m_AnchoredOffset.x), ((this.m_Rect.pivot.y == 1f) ? (this.m_AnchoredOffset.y * -1f) : this.m_AnchoredOffset.y), 0f); // Update the position this.transform.position = pivotBasedOffset + targetWorldCorners[(int)oppositeCorner]; } }
/// <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 title and description UITooltip.AddTitle(itemInfo.Name); // Item types UITooltip.AddLineColumn(itemInfo.Type); UITooltip.AddLineColumn(itemInfo.Subtype); if (itemInfo.ItemType == 1) { UITooltip.AddLineColumn(itemInfo.Damage.ToString() + " Damage"); UITooltip.AddLineColumn(itemInfo.AttackSpeed.ToString("0.0") + " Attack speed"); UITooltip.AddLine("(" + ((float)itemInfo.Damage / itemInfo.AttackSpeed).ToString("0.0") + " damage per second)"); } else { UITooltip.AddLineColumn(itemInfo.Block.ToString() + " Block"); UITooltip.AddLineColumn(itemInfo.Armor.ToString() + " Armor"); } UITooltip.AddLine("+" + itemInfo.Stamina.ToString() + " Stamina", new RectOffset(0, 0, 6, 0)); UITooltip.AddLine("+" + itemInfo.Strength.ToString() + " Strength"); // Set the item description if not empty if (!string.IsNullOrEmpty(itemInfo.Description)) { UITooltip.AddDescription(itemInfo.Description); } }
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"); } }
protected virtual void OnDestroy() { mInstance = null; }