86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using Code.Gameplay.Orders.Order;
|
|
using Code.Gameplay.Player;
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Code.UI.Panels
|
|
{
|
|
public class GameplayPanel : UIElement
|
|
{
|
|
[Header("Dispatcher")]
|
|
[SerializeField] private Image dispatcher;
|
|
[SerializeField] private RectTransform dispatcherHiddenPosition;
|
|
[SerializeField] private RectTransform dispatcherShownPosition;
|
|
[SerializeField] private float dispatcherTransitionTime = 0.5f;
|
|
[Header("Timer")]
|
|
[SerializeField] private TMP_Text timer;
|
|
[SerializeField] private Image timerBackGround;
|
|
public TMP_Text Timer => timer;
|
|
[SerializeField] private RectTransform timerHiddenPosition;
|
|
[SerializeField] private RectTransform timerShownPosition;
|
|
[SerializeField] private float timerTransitionTime = 0.5f;
|
|
[Header("HealthBar")]
|
|
[SerializeField] private Image healthBar;
|
|
[Header("MoneyBar")]
|
|
[SerializeField] private TMP_Text moneyText;
|
|
|
|
[SerializeField] private DamagePanel damagePanel;
|
|
public DamagePanel DamagePanel => damagePanel;
|
|
|
|
private void ScoreUpdate(int count, int money)
|
|
{
|
|
// TODO Анимация получения\потери
|
|
moneyText.text = money.ToString();
|
|
}
|
|
private void HealthUpdate(int count, PlayerHealth health)
|
|
{
|
|
// TODO Анимация потери
|
|
float fillAmount = (float)health.HealthPoints / health.MaxHealthPoints;
|
|
healthBar.fillAmount = fillAmount;
|
|
}
|
|
private IOrderService _orderService;
|
|
|
|
public void Initialize(IPlayerScore score, PlayerHealth health, IOrderService orderService)
|
|
{
|
|
score.OnScoreGet += ScoreUpdate;
|
|
score.OnScoreLoose += ScoreUpdate;
|
|
ScoreUpdate(0,score.Score);
|
|
|
|
health.OnDamage += HealthUpdate;
|
|
HealthUpdate(0,health);
|
|
|
|
_orderService = orderService;
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (_orderService != null) timer.text = ((int)_orderService.DeliveryTimer).ToString();
|
|
}
|
|
private int _dispatcherCalls;
|
|
public void SummonDispatcher()
|
|
{
|
|
// TODO
|
|
_dispatcherCalls++;
|
|
dispatcher.transform.DOMoveY(dispatcherShownPosition.position.y, dispatcherTransitionTime);
|
|
}
|
|
public void CloseDispatcher()
|
|
{
|
|
_dispatcherCalls--;
|
|
if (_dispatcherCalls > 0) return;
|
|
dispatcher.transform.DOMoveY(dispatcherHiddenPosition.position.y, dispatcherTransitionTime);
|
|
// TODO
|
|
}
|
|
public void ShowTimer()
|
|
{
|
|
// TODO
|
|
timerBackGround.transform.DOMoveX(timerShownPosition.position.x, timerTransitionTime);
|
|
}
|
|
public void HideTimer()
|
|
{
|
|
timerBackGround.transform.DOMoveX(timerHiddenPosition.position.x, timerTransitionTime);
|
|
// TODO
|
|
}
|
|
}
|
|
} |