From 458da2371d37a59f56196b7fa485e60078afb5ee Mon Sep 17 00:00:00 2001 From: Ader Alisma 01 Date: Sun, 8 Dec 2024 14:11:21 -0500 Subject: [PATCH] Centralized tooltip placeholder descriptions --- Assets/Scripts/Ally/Tooltip/TooltipManager.cs | 19 +++++++++++++++++-- .../Drag&Drop/GameObjectPlacementButton.cs | 13 ++----------- .../Scripts/Drag&Drop/TilePlacementButton.cs | 12 ++---------- .../UnitTree/UpgradePlacementButton.cs | 13 ++----------- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/Assets/Scripts/Ally/Tooltip/TooltipManager.cs b/Assets/Scripts/Ally/Tooltip/TooltipManager.cs index 926b26a..46b939c 100644 --- a/Assets/Scripts/Ally/Tooltip/TooltipManager.cs +++ b/Assets/Scripts/Ally/Tooltip/TooltipManager.cs @@ -14,8 +14,9 @@ public class TooltipManager : Singleton private bool _tooltipVisibility; public bool TooltipVisibility { get { return _tooltipVisibility; } } - public void ShowTooltip(string description, string hp, string dmg, string atkSpeed) + public void ShowTooltip(UnitCard unitCard, string hp, string dmg, string atkSpeed) { + string description = DescriptionManager(unitCard); _tooltipVisibility = true; _description = description; _hp = hp; @@ -24,9 +25,23 @@ public class TooltipManager : Singleton EventAggregator.Instance.GetEvent().Invoke(); } - internal void HideToolTip() + public void HideToolTip() { _tooltipVisibility = false; EventAggregator.Instance.GetEvent().Invoke(); } + + private string DescriptionManager(UnitCard unitCard) + { + string tooltipDescription; + if (unitCard?.TooltipString.Length > 0) + { + tooltipDescription = unitCard.TooltipString; + } + else + { + tooltipDescription = "Exemple de description d'unité pour " + unitCard.name.ToLower(); + } + return tooltipDescription; + } } diff --git a/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs index 7ba3572..d75de55 100644 --- a/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs +++ b/Assets/Scripts/Drag&Drop/GameObjectPlacementButton.cs @@ -85,17 +85,8 @@ public class GameObjectPlacementButton : UnitPlacementButton public override void OnPointerEnter(PointerEventData eventData) { - Ally go = _prefab.GetComponent(); - string tooltipDescription; - if (_unitCardInformation?.TooltipString.Length > 0) - { - tooltipDescription = _unitCardInformation.TooltipString; - } - else - { - tooltipDescription = "Exemple de description d'unité pour " + _unitCardInformation.name.ToLower(); - } - TooltipManager.Instance.ShowTooltip(tooltipDescription, go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString()); + Ally allyObj = _prefab.GetComponent(); + TooltipManager.Instance.ShowTooltip(_unitCardInformation, allyObj.Hp.ToString(), allyObj.AttackDamage.ToString(), allyObj.AttackInterval.ToString()); } public override void OnPointerExit(PointerEventData eventData) diff --git a/Assets/Scripts/Drag&Drop/TilePlacementButton.cs b/Assets/Scripts/Drag&Drop/TilePlacementButton.cs index 0da2c38..52dea94 100644 --- a/Assets/Scripts/Drag&Drop/TilePlacementButton.cs +++ b/Assets/Scripts/Drag&Drop/TilePlacementButton.cs @@ -4,6 +4,7 @@ using UnityEngine.EventSystems; public class TilePlacementButton : UnitPlacementButton { public LevelTile tile; + const string NULL = "0"; protected override bool CanPlace() { @@ -25,16 +26,7 @@ public class TilePlacementButton : UnitPlacementButton public override void OnPointerEnter(PointerEventData eventData) { - string tooltipDescription; - if (_unitCardInformation?.TooltipString.Length > 0) - { - tooltipDescription = _unitCardInformation.TooltipString; - } - else - { - tooltipDescription = "Exemple de description de tuile pour " + _unitCardInformation.name.ToLower(); - } - TooltipManager.Instance.ShowTooltip(tooltipDescription, "0", "0", "0"); + TooltipManager.Instance.ShowTooltip(_unitCardInformation, NULL, NULL, NULL); } public override void OnPointerExit(PointerEventData eventData) diff --git a/Assets/Scripts/UnitTree/UpgradePlacementButton.cs b/Assets/Scripts/UnitTree/UpgradePlacementButton.cs index 75c6eb8..75e4623 100644 --- a/Assets/Scripts/UnitTree/UpgradePlacementButton.cs +++ b/Assets/Scripts/UnitTree/UpgradePlacementButton.cs @@ -96,17 +96,8 @@ public class UpgradePlacementButton : MonoBehaviour, IPointerClickHandler, IPoin } public void OnPointerEnter(PointerEventData eventData) { - Ally go = _prefab.GetComponent(); - string tooltipDescription; - if (_unitCardInformation.TooltipString.Length > 0) - { - tooltipDescription = _unitCardInformation.TooltipString; - } - else - { - tooltipDescription = "Exemple de description d'unité pour " + _unitCardInformation.name.ToLower(); - } - TooltipManager.Instance.ShowTooltip(tooltipDescription, go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString()); + Ally allyObj = _prefab.GetComponent(); + TooltipManager.Instance.ShowTooltip(_unitCardInformation, allyObj.Hp.ToString(), allyObj.AttackDamage.ToString(), allyObj.AttackInterval.ToString()); } public void OnPointerExit(PointerEventData eventData)