136 lines
3.8 KiB
C#
136 lines
3.8 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, 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);
|
|
|
|
public void SetFoodImage(string 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 SetFoodSprite(Sprite sprite)
|
|
{
|
|
FoodImage.sprite = sprite;
|
|
}
|
|
|
|
public void OrderFood(string foodIdx, int waitTime, int hurryTime)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isFoodReceived = false;
|
|
SetFoodImage(foodIdx);
|
|
ShowUi();
|
|
|
|
_tween = FillImage.DOFillAmount(1f, hurryTime)
|
|
.From(0f)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(waitTime)
|
|
.OnComplete(OnTweenComplete)
|
|
.SetAutoKill(false);
|
|
_tween.Restart();
|
|
}
|
|
|
|
public void PayMoney(int waitTime, int hurryTime)
|
|
{
|
|
_isOrdered = true;
|
|
_isWaitTimeOver = false;
|
|
_isFoodReceived = false;
|
|
SetFoodSprite(DataManager.Instance.SpriteDataSo.Gold);
|
|
ShowUi();
|
|
|
|
_tween = FillImage.DOFillAmount(1f, hurryTime)
|
|
.From(0f)
|
|
.SetEase(Ease.Linear)
|
|
.SetDelay(waitTime)
|
|
.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;
|
|
}
|
|
}
|
|
} |