Added Unit Tooltip #6

Merged
Ader_Alisma merged 15 commits from feature/UnitTooltip into main 2025-05-30 19:05:04 +00:00
4 changed files with 23 additions and 13 deletions
Showing only changes of commit 5c7d3e645d - Show all commits

View File

@ -1,5 +1,6 @@
using GatherAndDefend.Events; using GatherAndDefend.Events;
using System; using System;
using System.Diagnostics;
public class TooltipManager : Singleton<TooltipManager> public class TooltipManager : Singleton<TooltipManager>
{ {
@ -14,12 +15,18 @@ public class TooltipManager : Singleton<TooltipManager>
private bool _tooltipVisibility; private bool _tooltipVisibility;
public bool TooltipVisibility { get { return _tooltipVisibility; } } public bool TooltipVisibility { get { return _tooltipVisibility; } }
public void ShowTooltip(UnitCard unitCard, string hp, string dmg, string atkSpeed) public void ShowTooltip(UnitCard unitCard, string hp, string dmg, string atkSpeed, bool isNotTile = true)
{ {
string description = DescriptionManager(unitCard); string description = DescriptionManager(unitCard);
_tooltipVisibility = true; _tooltipVisibility = true;
_description = description; _description = description;
_hp = hp; if (hp.Equals("0") && isNotTile)
{
_hp = "1";
} else
{
_hp = hp;
}
_damage = dmg; _damage = dmg;
_attackSpeed = atkSpeed; _attackSpeed = atkSpeed;
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke(); EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke();
@ -33,15 +40,19 @@ public class TooltipManager : Singleton<TooltipManager>
private string DescriptionManager(UnitCard unitCard) private string DescriptionManager(UnitCard unitCard)
{ {
string tooltipDescription; if (unitCard)
if (unitCard?.TooltipString.Length > 0)
{ {
tooltipDescription = unitCard.TooltipString; string tooltipDescription;
if (unitCard?.TooltipString.Length > 0)
{
tooltipDescription = unitCard.TooltipString;
}
else
{
tooltipDescription = "Exemple de description d'unité pour " + unitCard.name.ToLower();
}
return tooltipDescription;
} }
else return null;
{
tooltipDescription = "Exemple de description d'unité pour " + unitCard.name.ToLower();
}
return tooltipDescription;
} }
} }

View File

@ -30,7 +30,7 @@ public class TooltipText : MonoBehaviour
{ {
_tooltipPanel.SetActive(true); _tooltipPanel.SetActive(true);
_tooltipDescription.text = _tooltipManager.Description; _tooltipDescription.text = _tooltipManager.Description;
_tooltipHp.text = (_tooltipManager.Hp.Equals("0") ? "Ne peut pas être attaqué" : "Points de vie: " + _tooltipManager.Hp); _tooltipHp.text = (_tooltipManager.Hp.Equals("0") ? ("Intouchable") : "Points de vie: " + _tooltipManager.Hp);
_tooltipDmg.text = (_tooltipManager.Damage.Equals("0") ? "Ne peut pas attaquer" : "Dommage: " + _tooltipManager.Damage); _tooltipDmg.text = (_tooltipManager.Damage.Equals("0") ? "Ne peut pas attaquer" : "Dommage: " + _tooltipManager.Damage);
_tooltipAttackSpeed.text = (_tooltipManager.Damage.Equals("0") ? EMPTY_STRING : "Vitesse d'attaque: " + _tooltipManager.AttackSpeed); _tooltipAttackSpeed.text = (_tooltipManager.Damage.Equals("0") ? EMPTY_STRING : "Vitesse d'attaque: " + _tooltipManager.AttackSpeed);
} }

View File

@ -86,7 +86,6 @@ public class GameObjectPlacementButton : UnitPlacementButton
public override void OnPointerEnter(PointerEventData eventData) public override void OnPointerEnter(PointerEventData eventData)
{ {
Ally allyObj = _prefab.GetComponent<Ally>(); Ally allyObj = _prefab.GetComponent<Ally>();
Debug.Log("For " + _unitCardInformation.name + ": " + allyObj.Hp);
TooltipManager.Instance.ShowTooltip(_unitCardInformation, allyObj.Hp.ToString(), allyObj.AttackDamage.ToString(), allyObj.AttackInterval.ToString()); TooltipManager.Instance.ShowTooltip(_unitCardInformation, allyObj.Hp.ToString(), allyObj.AttackDamage.ToString(), allyObj.AttackInterval.ToString());
} }

View File

@ -26,7 +26,7 @@ public class TilePlacementButton : UnitPlacementButton
public override void OnPointerEnter(PointerEventData eventData) public override void OnPointerEnter(PointerEventData eventData)
{ {
TooltipManager.Instance.ShowTooltip(_unitCardInformation, NULL, NULL, NULL); TooltipManager.Instance.ShowTooltip(_unitCardInformation, NULL, NULL, NULL, false);
} }
public override void OnPointerExit(PointerEventData eventData) public override void OnPointerExit(PointerEventData eventData)