120 lines
3.4 KiB
C#
120 lines
3.4 KiB
C#
using BlueWater.Items;
|
|
using BlueWater.Tycoons;
|
|
using DG.Tweening;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class FoodBalloonUi : MonoBehaviour
|
|
{
|
|
[field: Title("컴포넌트")]
|
|
[field: SerializeField, Required]
|
|
public Image FillImage { get; private set; }
|
|
|
|
[field: SerializeField, Required]
|
|
public Image FoodImage { get; private set; }
|
|
|
|
[Title("주문 정보")]
|
|
[SerializeField, Tooltip("주문을 시작하고나서, 재촉하지 않는 최소한의 기다리는 시간")]
|
|
private float _defaultWaitTime = 5f;
|
|
|
|
[SerializeField, DisableIf("@true"), Tooltip("_defaultWaitTime시간이 지나고, 재촉하는 시간")]
|
|
private float _customerWaitTime;
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isOrdered;
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isWaitTimeOver;
|
|
|
|
[SerializeField, DisableIf("@true")]
|
|
private bool _isFoodReceived;
|
|
|
|
private Tween _tween;
|
|
private TableSeat _tableSeat;
|
|
private ItemData _orderItemData;
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeComponents();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_tween.Kill();
|
|
}
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
FillImage = transform.Find("Background/FillImage").GetComponent<Image>();
|
|
FoodImage = transform.Find("FoodImage").GetComponent<Image>();
|
|
}
|
|
|
|
public void Initialize(TableSeat tableSeat)
|
|
{
|
|
_tableSeat = tableSeat;
|
|
HideUi();
|
|
}
|
|
|
|
public void ShowUi() => gameObject.SetActive(true);
|
|
public void HideUi() => gameObject.SetActive(false);
|
|
|
|
private void SetFoodImage(int foodIdx)
|
|
{
|
|
_orderItemData = ItemManager.Instance.GetItemDataByIdx(foodIdx);
|
|
if (_orderItemData == null)
|
|
{
|
|
Debug.LogError($"{foodIdx} 해당 음식을 등록할 수 없습니다.");
|
|
return;
|
|
}
|
|
|
|
if (!_orderItemData.Sprite)
|
|
{
|
|
Debug.LogWarning($"{_orderItemData.Sprite} 해당 음식의 이미지가 없습니다.");
|
|
}
|
|
FoodImage.sprite = _orderItemData.Sprite;
|
|
}
|
|
|
|
public void OrderFood(int foodIdx, float waitTime)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isFoodReceived = false;
|
|
SetFoodImage(foodIdx);
|
|
_customerWaitTime = waitTime;
|
|
ShowUi();
|
|
|
|
_tween = FillImage.DOFillAmount(1f, _customerWaitTime)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(_defaultWaitTime)
|
|
.OnComplete(OnTweenComplete)
|
|
.SetAutoKill(false);
|
|
_tween.Restart();
|
|
}
|
|
|
|
private void OnTweenComplete()
|
|
{
|
|
_isWaitTimeOver = true;
|
|
HideUi();
|
|
}
|
|
|
|
public bool IsWaitTimeOver() => _isOrdered && _isWaitTimeOver;
|
|
public bool IsFoodReceive() => _isFoodReceived;
|
|
|
|
public void CancelOrder()
|
|
{
|
|
_tableSeat.VacateSeat();
|
|
}
|
|
|
|
public void ReceiveFood()
|
|
{
|
|
_tableSeat.DirtyTable();
|
|
_tween.Kill();
|
|
HideUi();
|
|
_isFoodReceived = true;
|
|
}
|
|
}
|
|
} |