squash! Fin Tooltip

This commit is contained in:
Ader Alisma 01 2024-11-20 22:07:01 -05:00
parent 56b5dd3361
commit f1a53cd9cf
19 changed files with 947 additions and 350 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -16,3 +16,4 @@ MonoBehaviour:
_rock: 0 _rock: 0
_food: 0 _food: 0
_cooldownInSeconds: 60 _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
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 System.Linq;
using UnityEditor; using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
public class GameObjectPlacementButton : UnitPlacementButton public class GameObjectPlacementButton : UnitPlacementButton, IPointerEnterHandler, IPointerExitHandler
{ {
private TooltipManager _tooltipManager;
[SerializeField] [SerializeField]
private GameObject _prefab; private GameObject _prefab;
protected override void Start()
{
base.Start();
_tooltipManager = TooltipManager.Instance;
}
protected override bool CanPlace() protected override bool CanPlace()
{ {
@ -81,4 +88,22 @@ public class GameObjectPlacementButton : UnitPlacementButton
detection.transform.localPosition = detectionRect.position; detection.transform.localPosition = detectionRect.position;
detection.transform.localScale = detectionRect.size; 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; protected int _food;
[SerializeField] [SerializeField]
protected int _cooldownInSeconds = 3; protected int _cooldownInSeconds = 3;
[SerializeField, TextArea(10, 100)]
protected string _tooltipString;
public int Wood => _wood; public int Wood => _wood;
public int Rock => _rock; public int Rock => _rock;
public int Food => _food; public int Food => _food;
public int CooldownInSeconds => _cooldownInSeconds; public int CooldownInSeconds => _cooldownInSeconds;
public string TooltipString => _tooltipString;
} }

View File

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

View File

@ -0,0 +1,5 @@
using GatherAndDefend.Events;
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: