2024-08-27 12:23:41 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using BlueWater.Items;
|
|
|
|
using BlueWater.Tycoons;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine;
|
2024-09-02 13:45:46 +00:00
|
|
|
using UnityEngine.Serialization;
|
2024-08-27 12:23:41 +00:00
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
|
|
|
public class BrewingUi : SwitchActionPopupUi
|
|
|
|
{
|
|
|
|
[SerializeField, Required]
|
|
|
|
private DrinkRecipeSlotUi _drinkRecipeSlotUiPrefab;
|
|
|
|
|
|
|
|
[SerializeField, Required]
|
|
|
|
private Transform _drinkRecipeSpawnLocation;
|
|
|
|
|
|
|
|
[SerializeField]
|
2024-08-29 09:51:32 +00:00
|
|
|
private TMP_Text _recipeName;
|
2024-08-27 12:23:41 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
2024-08-29 09:51:32 +00:00
|
|
|
private Image _drinkImage;
|
2024-08-27 12:23:41 +00:00
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
private Button _convertButton;
|
|
|
|
|
|
|
|
[Title("실시간 데이터")]
|
|
|
|
[SerializeField]
|
|
|
|
private List<BrewingIngredientSlotUi> _brewingIngredientSlotUis = new(3);
|
|
|
|
|
2024-09-02 13:45:46 +00:00
|
|
|
[FormerlySerializedAs("_selectedDrinkData")] [SerializeField]
|
|
|
|
private LiquidData selectedLiquidData;
|
2024-08-27 12:23:41 +00:00
|
|
|
|
2024-08-29 09:51:32 +00:00
|
|
|
[SerializeField]
|
2024-08-27 12:23:41 +00:00
|
|
|
private Brewing _currentBrewing;
|
2024-08-29 09:51:32 +00:00
|
|
|
|
|
|
|
private List<DrinkRecipeSlotUi> _drinkRecipeSlotUis = new();
|
2024-08-27 12:23:41 +00:00
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
|
|
|
|
TycoonEvents.OnDrinkRecipeAcquired += AddDrinkRecipe;
|
|
|
|
TycoonEvents.OnDrinkRecipeSelected += SelectDrinkRecipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void OnDestroy()
|
|
|
|
{
|
|
|
|
TycoonEvents.OnDrinkRecipeAcquired -= AddDrinkRecipe;
|
|
|
|
TycoonEvents.OnDrinkRecipeSelected -= SelectDrinkRecipe;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Initialize()
|
|
|
|
{
|
|
|
|
foreach (Transform element in _drinkRecipeSpawnLocation)
|
|
|
|
{
|
|
|
|
Destroy(element.gameObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
var drinkRecipes = DataManager.Instance.TycoonData.DrinkRecipes;
|
|
|
|
foreach (var element in drinkRecipes)
|
|
|
|
{
|
|
|
|
AddDrinkRecipe(element);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Open(List<PopupUi> popupUiList)
|
|
|
|
{
|
|
|
|
base.Open(popupUiList);
|
|
|
|
|
|
|
|
ResetBrewingUi();
|
|
|
|
TycoonEvents.OnBrewingUiOpened?.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
public override void Close()
|
|
|
|
{
|
|
|
|
base.Close();
|
|
|
|
|
2024-08-29 09:51:32 +00:00
|
|
|
_currentBrewing = null;
|
2024-08-27 12:23:41 +00:00
|
|
|
ResetBrewingUi();
|
|
|
|
TycoonEvents.OnBrewingUiClosed?.Invoke();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ResetBrewingUi()
|
|
|
|
{
|
2024-09-02 13:45:46 +00:00
|
|
|
selectedLiquidData = null;
|
2024-08-29 09:51:32 +00:00
|
|
|
_recipeName.text = null;
|
|
|
|
_drinkImage.enabled = false;
|
|
|
|
SetBrewingIngredient();
|
2024-08-27 12:23:41 +00:00
|
|
|
foreach (var element in _brewingIngredientSlotUis)
|
|
|
|
{
|
|
|
|
element.gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetBrewing(Brewing brewing)
|
|
|
|
{
|
|
|
|
_currentBrewing = brewing;
|
2024-08-29 09:51:32 +00:00
|
|
|
ShowDrinkRecipeByCategory();
|
2024-08-27 12:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void AddDrinkRecipe(string idx)
|
|
|
|
{
|
|
|
|
var instance = Instantiate(_drinkRecipeSlotUiPrefab, _drinkRecipeSpawnLocation);
|
|
|
|
instance.Initialize(idx);
|
2024-08-29 09:51:32 +00:00
|
|
|
_drinkRecipeSlotUis.Add(instance);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void ShowDrinkRecipeByCategory()
|
|
|
|
{
|
|
|
|
var currentDrinkCategory = _currentBrewing.GetDrinkCategory();
|
|
|
|
foreach (var element in _drinkRecipeSlotUis)
|
|
|
|
{
|
|
|
|
element.gameObject.SetActive(currentDrinkCategory == element.GetDrinkData().Category);
|
|
|
|
}
|
2024-08-27 12:23:41 +00:00
|
|
|
}
|
|
|
|
|
2024-09-02 13:45:46 +00:00
|
|
|
public void SelectDrinkRecipe(LiquidData liquidData)
|
2024-08-27 12:23:41 +00:00
|
|
|
{
|
2024-09-02 13:45:46 +00:00
|
|
|
selectedLiquidData = liquidData;
|
2024-08-27 12:23:41 +00:00
|
|
|
|
2024-09-02 13:45:46 +00:00
|
|
|
_recipeName.text = selectedLiquidData.Name;
|
|
|
|
_drinkImage.sprite = liquidData.Sprite;
|
2024-08-27 12:23:41 +00:00
|
|
|
_drinkImage.enabled = true;
|
|
|
|
|
2024-09-02 13:45:46 +00:00
|
|
|
var ingredients = selectedLiquidData.GetValidIngredients();
|
2024-08-27 12:23:41 +00:00
|
|
|
for (var i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (ingredients.Count > i)
|
|
|
|
{
|
|
|
|
_brewingIngredientSlotUis[i].SetIngredient(ingredients[i].Idx, ingredients[i].Quantity);
|
|
|
|
_brewingIngredientSlotUis[i].gameObject.SetActive(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_brewingIngredientSlotUis[i].gameObject.SetActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-08-29 09:51:32 +00:00
|
|
|
SetBrewingIngredient();
|
2024-08-27 12:23:41 +00:00
|
|
|
}
|
|
|
|
|
2024-08-29 09:51:32 +00:00
|
|
|
private void SetBrewingIngredient()
|
2024-08-27 12:23:41 +00:00
|
|
|
{
|
|
|
|
foreach (var element in _brewingIngredientSlotUis)
|
|
|
|
{
|
2024-08-29 09:51:32 +00:00
|
|
|
element.SetQuantity();
|
2024-08-27 12:23:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CheckConvertButton();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void CheckConvertButton()
|
|
|
|
{
|
2024-09-02 13:45:46 +00:00
|
|
|
if (selectedLiquidData == null || !_currentBrewing.IsEmptyDrink())
|
2024-08-27 12:23:41 +00:00
|
|
|
{
|
|
|
|
_convertButton.interactable = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-09-02 13:45:46 +00:00
|
|
|
var ingredients = selectedLiquidData.GetValidIngredients();
|
2024-08-27 12:23:41 +00:00
|
|
|
if (ingredients.Count <= 0)
|
|
|
|
{
|
|
|
|
_convertButton.interactable = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (var i = 0; i < ingredients.Count; i++)
|
|
|
|
{
|
|
|
|
if (_brewingIngredientSlotUis[i].GetIsEnough()) continue;
|
|
|
|
|
|
|
|
_convertButton.interactable = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_convertButton.interactable = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 술을 만들 때 최종 버튼
|
|
|
|
/// </summary>
|
|
|
|
public void ConvertButton()
|
|
|
|
{
|
2024-09-02 13:45:46 +00:00
|
|
|
_currentBrewing.SetDrink(selectedLiquidData);
|
2024-08-27 12:23:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|