Added Unit Tooltip #6

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

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 20
_cooldownInSeconds: 5
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 350
_food: 0
_cooldownInSeconds: 30
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 0
_cooldownInSeconds: 1
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 10
_cooldownInSeconds: 2
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 10
_cooldownInSeconds: 4
_tooltipString: Agressive farmer's association MOB

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 0
_cooldownInSeconds: 1
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 60
_cooldownInSeconds: 15
_tooltipString:

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0
_food: 0
_cooldownInSeconds: 60
_tooltipString:

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 54b66411b2ca31042865510b55cf4608
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
using GatherAndDefend.Events;
using System;
public class TooltipManager : Singleton<TooltipManager>
{
private string _description;
public string Description { get { return _description; } }
private string _hp;
public string Hp { get { return _hp; } }
private string _damage;
public string Damage { get { return _damage; } }
private string _attackSpeed;
public string AttackSpeed { get { return _attackSpeed; } }
private bool _tooltipVisibility;
public bool TooltipVisibility { get { return _tooltipVisibility; } }
public void ShowTooltip(string description, string hp, string dmg, string atkSpeed)
{
_tooltipVisibility = true;
_description = description;
_hp = hp;
_damage = dmg;
_attackSpeed = atkSpeed;
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke();
}
internal void HideToolTip()
{
_tooltipVisibility = false;
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Invoke();
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c319ef77aa02448488fc0f25f670426b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,46 @@
using GatherAndDefend.Events;
using TMPro;
using UnityEngine;
public class TooltipText : MonoBehaviour
{
private TooltipManager _tooltipManager;
[SerializeField]
private GameObject _tooltipPanel;
[SerializeField]
private TextMeshProUGUI _tooltipDescription;
[SerializeField]
private TextMeshProUGUI _tooltipHp;
[SerializeField]
private TextMeshProUGUI _tooltipDmg;
[SerializeField]
private TextMeshProUGUI _tooltipAttackSpeed;
private const string EMPTY_STRING = "";
// Start is called before the first frame update
Ader_Alisma marked this conversation as resolved Outdated

private Start() and remove the generated comments

private Start() and remove the generated comments
void Start()
{
_tooltipManager = TooltipManager.Instance;
EventAggregator.Instance.GetEvent<TooltipChangedEvent>().Attach(OnEventUpdate);
}
// Update is called once per frame
private void OnEventUpdate()
{
if (_tooltipManager.TooltipVisibility)
{
_tooltipPanel.SetActive(true);
_tooltipDescription.text = _tooltipManager.Description;
_tooltipHp.text = "Points de vie: " + (_tooltipManager.Hp.Equals("0") ? "1" : _tooltipManager.Hp);
_tooltipDmg.text = "Dommage: " + _tooltipManager.Damage;
_tooltipAttackSpeed.text = "Vitesse d'attaque: " + _tooltipManager.AttackSpeed;
}
else
{
_tooltipPanel.SetActive(false);
_tooltipDescription.text = EMPTY_STRING;
_tooltipHp.text = EMPTY_STRING;
_tooltipDmg.text = EMPTY_STRING;
_tooltipAttackSpeed.text = EMPTY_STRING;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 3c61083f9f8ea6441afcccd38ee6428e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -2,11 +2,18 @@
using System.Linq;
using UnityEditor;
using UnityEngine;
using UnityEngine.EventSystems;
public class GameObjectPlacementButton : UnitPlacementButton
public class GameObjectPlacementButton : UnitPlacementButton, IPointerEnterHandler, IPointerExitHandler
{
private TooltipManager _tooltipManager;
[SerializeField]
private GameObject _prefab;
protected override void Start()
{
base.Start();
_tooltipManager = TooltipManager.Instance;
}
protected override bool CanPlace()
{
@ -81,4 +88,22 @@ public class GameObjectPlacementButton : UnitPlacementButton
detection.transform.localPosition = detectionRect.position;
detection.transform.localScale = detectionRect.size;
}
public void OnPointerEnter(PointerEventData eventData)
{
Ally go = _prefab.GetComponent<Ally>();
if (_unitCardInformation.TooltipString.Length > 0)
{
_tooltipManager.ShowTooltip(_unitCardInformation.TooltipString, go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString());
}
else
{
_tooltipManager.ShowTooltip("Exemple de description d'unité pour " + _unitCardInformation.name.ToLower(), go.Hp.ToString(), go.AttackDamage.ToString(), go.AttackInterval.ToString());
}
}
public void OnPointerExit(PointerEventData eventData)
{
_tooltipManager.HideToolTip();
}
}

View File

@ -11,9 +11,12 @@ public class UnitCard : ScriptableObject
protected int _food;
[SerializeField]
protected int _cooldownInSeconds = 3;
[SerializeField, TextArea(10, 100)]
protected string _tooltipString;
public int Wood => _wood;
public int Rock => _rock;
public int Food => _food;
public int CooldownInSeconds => _cooldownInSeconds;
public string TooltipString => _tooltipString;
}

View File

@ -24,6 +24,11 @@ public abstract class UnitPlacementButton : PlacementButton
protected Image _cooldownIndicator;
protected bool _lockedByCooldown;
protected override void Start()
{
base.Start();
}
protected override void Update()
{
base.Update();
@ -77,4 +82,7 @@ public abstract class UnitPlacementButton : PlacementButton
{
return base.CanPlace() && !_lockedByCooldown;
}
}

View File

@ -0,0 +1,5 @@
using GatherAndDefend.Events;
Ader_Alisma marked this conversation as resolved
Review

weird image.png

weird <img width="332" alt="image.png" src="attachments/602d9d1c-886c-4469-8192-628c1ff58d16">
7.5 KiB
Review

Warning commun avec Gitea. Ça n'a pas l'air de causer des erreurs pour le code

Warning commun avec Gitea. Ça n'a pas l'air de causer des erreurs pour le code
public class TooltipChangedEvent : EventBase
{
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 927ca3622899c4848838a81957e849eb
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: