155 lines
5.0 KiB
C#
155 lines
5.0 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlueWater.Items;
|
|
using BlueWater.Tycoons;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class DailyFoodMenuUi : MonoBehaviour
|
|
{
|
|
[Title("프리팹 생성 위치")]
|
|
[SerializeField, Required]
|
|
private Transform _fryingPanFoodSlotLocation;
|
|
|
|
[SerializeField, Required]
|
|
private Transform _soupFoodSlotLocation;
|
|
|
|
[SerializeField, Required]
|
|
private Transform _skewerFoodSlotLocation;
|
|
|
|
[SerializeField, Required]
|
|
private Transform _dessertFoodSlotLocation;
|
|
|
|
[Title("프리팹")]
|
|
[SerializeField, Required]
|
|
private TycoonItemSlotUi _dailyFoodSlotUi;
|
|
|
|
[Title("실시간 데이터")]
|
|
[SerializeField]
|
|
private List<TycoonItemSlotUi> _fryingPanFoodSlotUis = new(3);
|
|
|
|
[SerializeField]
|
|
private List<TycoonItemSlotUi> _soupFoodSlotUis = new(3);
|
|
|
|
[SerializeField]
|
|
private List<TycoonItemSlotUi> _skewerFoodSlotUis = new(3);
|
|
|
|
[SerializeField]
|
|
private List<TycoonItemSlotUi> _dessertPanFoodSlotUis = new(3);
|
|
|
|
[field: SerializeField]
|
|
public List<TycoonItemSlotUi> DailyFoodSlotUis { get; private set; }= new(12);
|
|
|
|
[SerializeField]
|
|
private List<Pot> _pots = new(3);
|
|
|
|
private CookUi _cookUi;
|
|
|
|
private void Start()
|
|
{
|
|
Initialize();
|
|
}
|
|
|
|
private void Initialize()
|
|
{
|
|
_cookUi = TycoonUiManager.Instance.TycoonManagementUi.CookMenuUi.CookUi;
|
|
|
|
foreach (var element in _fryingPanFoodSlotUis)
|
|
{
|
|
element.AddButtonClickListener(() => RemoveDailyFood(element));
|
|
}
|
|
|
|
foreach (var element in _soupFoodSlotUis)
|
|
{
|
|
element.AddButtonClickListener(() => RemoveDailyFood(element));
|
|
}
|
|
|
|
foreach (var element in _skewerFoodSlotUis)
|
|
{
|
|
element.AddButtonClickListener(() => RemoveDailyFood(element));
|
|
}
|
|
|
|
foreach (var element in _dessertPanFoodSlotUis)
|
|
{
|
|
element.AddButtonClickListener(() => RemoveDailyFood(element));
|
|
}
|
|
}
|
|
|
|
private void RemoveDailyFood(TycoonItemSlotUi tycoonItemSlotUi)
|
|
{
|
|
tycoonItemSlotUi.SetFoodData(null);
|
|
DailyFoodSlotUis.Remove(tycoonItemSlotUi);
|
|
_cookUi.CheckCookable();
|
|
}
|
|
|
|
public bool IsEmptyDailyFoodMenu(FoodData selectedFoodData)
|
|
{
|
|
var selectedTypeItemSlotUis = GetDailyFoodType(selectedFoodData.Type);
|
|
|
|
foreach (var element in selectedTypeItemSlotUis)
|
|
{
|
|
if (!element.GetIsLocked() && element.FoodData is null or { Idx: 0 })
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
public void AddDailyFoodMenu(FoodData selectedFoodData)
|
|
{
|
|
var selectedTypeItemSlotUis = GetDailyFoodType(selectedFoodData.Type);
|
|
|
|
foreach (var element in selectedTypeItemSlotUis)
|
|
{
|
|
if (!element.GetIsLocked() && element.FoodData is null or { Idx: 0 })
|
|
{
|
|
element.SetFoodData(selectedFoodData);
|
|
DailyFoodSlotUis.Add(element);
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private List<TycoonItemSlotUi> GetDailyFoodType(FoodType foodType)
|
|
{
|
|
switch (foodType)
|
|
{
|
|
case FoodType.None:
|
|
Debug.LogError($"FoodType이 None입니다.");
|
|
return null;
|
|
case FoodType.Skewer:
|
|
return _skewerFoodSlotUis;
|
|
case FoodType.Soup:
|
|
return _soupFoodSlotUis;
|
|
case FoodType.FryingPan:
|
|
return _fryingPanFoodSlotUis;
|
|
case FoodType.Dessert:
|
|
return _dessertPanFoodSlotUis;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(foodType), foodType, null);
|
|
}
|
|
}
|
|
|
|
public bool CanOpen()
|
|
{
|
|
return _fryingPanFoodSlotUis.Any(slot => slot.FoodData is not null and not { Idx: 0 }) ||
|
|
_soupFoodSlotUis.Any(slot => slot.FoodData is not null and not { Idx: 0 }) ||
|
|
_skewerFoodSlotUis.Any(slot => slot.FoodData is not null and not { Idx: 0 }) ||
|
|
_dessertPanFoodSlotUis.Any(slot => slot.FoodData is not null and not { Idx: 0 });
|
|
}
|
|
|
|
public TycoonItemSlotUi InitializePot(Pot pot)
|
|
{
|
|
_pots.Add(pot);
|
|
var index = _pots.Count - 1;
|
|
_fryingPanFoodSlotUis[index].SetIsLocked(false);
|
|
_fryingPanFoodSlotUis[index].SetFoodData(null);
|
|
return _fryingPanFoodSlotUis[index];
|
|
}
|
|
}
|
|
} |