330 lines
13 KiB
C#
330 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlueWater;
|
|
using BlueWater.Items;
|
|
using BlueWater.Tycoons;
|
|
using BlueWater.Uis;
|
|
using ExcelDataReader.Log;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Sirenix.OdinInspector;
|
|
using Spine;
|
|
using UnityEngine.Android;
|
|
|
|
public class ManualBook : SwitchActionPopupUi
|
|
{
|
|
private Image _cocktailImage;
|
|
private TextMeshProUGUI _cocktailName;
|
|
private GameObject _ingredientSlot1;
|
|
private GameObject _ingredientSlot2;
|
|
private GameObject _ingredientSlot3;
|
|
|
|
[field: SerializeField, CLabel("메뉴얼 CockTail Prefab")]
|
|
private ManualCocktailButton _ManualCocktailsPrefabs;
|
|
|
|
[field: SerializeField, CLabel("리큐르A 이미지")]
|
|
private Sprite LiquidA_Sprite;
|
|
[field: SerializeField, CLabel("리큐르B 이미지")]
|
|
private Sprite LiquidB_Sprite;
|
|
[field: SerializeField, CLabel("리큐르C 이미지")]
|
|
private Sprite LiquidC_Sprite;
|
|
[field: SerializeField, CLabel("리큐르D 이미지")]
|
|
private Sprite LiquidD_Sprite;
|
|
[field: SerializeField, CLabel("리큐르E 이미지")]
|
|
private Sprite LiquidE_Sprite;
|
|
[field: SerializeField, CLabel("가니쉬1 이미지")]
|
|
private Sprite Garnish1_Sprite;
|
|
[field: SerializeField, CLabel("가니쉬2 이미지")]
|
|
private Sprite Garnish2_Sprite;
|
|
|
|
private struct CocktailsBtn
|
|
{
|
|
public CocktailData Cocktail { get; set; }
|
|
public GameObject CockTailButton { get; set; }
|
|
public string Idx { get; set; }
|
|
public string Name { get; set; }
|
|
public int LiquidA { get; set; }
|
|
public int LiquidB { get; set; }
|
|
public int LiquidC { get; set; }
|
|
public int LiquidD { get; set; }
|
|
public int LiquidE { get; set; }
|
|
public int Garnish1 { get; set; }
|
|
public int Garnish2 { get; set; }
|
|
public bool Enable { get; set; }
|
|
|
|
public int Sibling { get; set; }
|
|
|
|
internal CocktailsBtn(CocktailData cocktail,GameObject cockTailButton , string idx , string name )
|
|
{
|
|
Cocktail = cocktail;
|
|
CockTailButton = cockTailButton;
|
|
Idx = idx;
|
|
Name = name;
|
|
LiquidA = 0;
|
|
LiquidB = 0;
|
|
LiquidC = 0;
|
|
LiquidD = 0;
|
|
LiquidE = 0;
|
|
Garnish1 = 0;
|
|
Garnish2 = 0;
|
|
Sibling = 2048;
|
|
Enable = false;
|
|
}
|
|
}
|
|
|
|
private Dictionary<string,CocktailsBtn> _cocktailsBtn;
|
|
|
|
//private List<Button> _cocktailsBtn;
|
|
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
EventManager.OnLevelUp += UpdateManualBook;
|
|
}
|
|
|
|
void Start()
|
|
{
|
|
var book = transform.Find("Book");
|
|
_cocktailImage = book.Find("CooktailPreview").Find("CocktailImage").GetComponent<Image>();
|
|
_cocktailName = book.Find("CocktailName").GetComponent<TextMeshProUGUI>();
|
|
_ingredientSlot1 = book.Find("IngredientSlot1").gameObject;
|
|
_ingredientSlot2 = book.Find("IngredientSlot2").gameObject;
|
|
_ingredientSlot3 = book.Find("IngredientSlot3").gameObject;
|
|
|
|
_cocktailsBtn = new Dictionary<string,CocktailsBtn>();
|
|
_cocktailName = book.Find("CocktailName").GetComponent<TextMeshProUGUI>();
|
|
|
|
_ingredientSlot1 = book.Find("IngredientSlot1").gameObject;
|
|
_ingredientSlot2 = book.Find("IngredientSlot2").gameObject;
|
|
_ingredientSlot3 = book.Find("IngredientSlot3").gameObject;
|
|
|
|
// private Image _ingredientSlot1Image;
|
|
// private Image _ingredientSlot2Image;
|
|
// private Image _ingredientSlot3Image;
|
|
|
|
var allCocktails = ItemManager.Instance.CocktailDataSo.GetData();
|
|
foreach (var element in allCocktails.Values)
|
|
{
|
|
if (element.Idx.Equals("Cocktail000")) continue; //쓰레기는 메뉴얼에 표시하지 않기
|
|
|
|
var cocktail = Instantiate(_ManualCocktailsPrefabs, book.Find("CocktailButtons"));
|
|
cocktail.Initialize(this);
|
|
cocktail.name = element.Idx;
|
|
cocktail.transform.Find("Image").GetComponent<Image>().sprite = element.Sprite;
|
|
|
|
var createCocktailMenu = new CocktailsBtn(element ,cocktail.gameObject ,element.Idx,element.Name);
|
|
|
|
foreach (var element2 in element.ValidIngredients) //들어가는 리큐르, 가니쉬 종류
|
|
{
|
|
if (element2.Idx.Equals("LiquidA")) {createCocktailMenu.LiquidA = element2.Ratio; createCocktailMenu.Sibling -= 1; };
|
|
if (element2.Idx.Equals("LiquidB")) {createCocktailMenu.LiquidB = element2.Ratio; createCocktailMenu.Sibling -= 2; };
|
|
if (element2.Idx.Equals("LiquidC")) {createCocktailMenu.LiquidC = element2.Ratio; createCocktailMenu.Sibling -= 4; };
|
|
if (element2.Idx.Equals("LiquidD")) {createCocktailMenu.LiquidD = element2.Ratio; createCocktailMenu.Sibling -= 8; };
|
|
if (element2.Idx.Equals("LiquidE")) {createCocktailMenu.LiquidE = element2.Ratio; createCocktailMenu.Sibling -= 16; };
|
|
if (element2.Idx.Equals("Garnish1")) {createCocktailMenu.Garnish1 = element2.Ratio; createCocktailMenu.Sibling -= 32; };
|
|
if (element2.Idx.Equals("Garnish2")) {createCocktailMenu.Garnish2 = element2.Ratio; createCocktailMenu.Sibling -= 64; };
|
|
}
|
|
|
|
_cocktailsBtn.Add(element.Idx,createCocktailMenu);
|
|
}
|
|
|
|
var sortedCocktails = _cocktailsBtn.OrderByDescending(element => element.Value.Sibling);
|
|
|
|
int index = 0;
|
|
foreach (var element in sortedCocktails)
|
|
{
|
|
element.Value.CockTailButton.transform.SetSiblingIndex(index);
|
|
index++;
|
|
}
|
|
|
|
Update_Cocktails();
|
|
SelectedItem(_cocktailsBtn["Cocktail001"].CockTailButton.GetComponent<Button>());
|
|
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
base.Open();
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
base.Close();
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
|
|
private void Update_Cocktails()
|
|
{
|
|
int playerLv = TycoonManager.Instance.TycoonStatus.CurrentLevel;
|
|
|
|
bool check = false;
|
|
|
|
var keys = _cocktailsBtn.Keys.ToList();
|
|
|
|
foreach (var key in keys)
|
|
{
|
|
var element = _cocktailsBtn[key];
|
|
check = false;
|
|
|
|
foreach (var element2 in element.Cocktail.ValidIngredients)
|
|
{
|
|
if (element2.Idx.Equals("LiquidA")) {};
|
|
if (element2.Idx.Equals("LiquidB") && playerLv < 5) { check = true; break; }
|
|
if (element2.Idx.Equals("LiquidC") && playerLv < 10) { check = true; break; }
|
|
if (element2.Idx.Equals("LiquidD") && playerLv < 15) { check = true; break; }
|
|
if (element2.Idx.Equals("LiquidE") && playerLv < 20) { check = true; break; }
|
|
if (element2.Idx.Equals("Garnish1") && playerLv < 25) { check = true; break; }
|
|
if (element2.Idx.Equals("Garnish2") && playerLv < 30) { check = true; break; }
|
|
}
|
|
|
|
if (!check)
|
|
{
|
|
element.CockTailButton.transform.Find("Image").GetComponent<Image>().material = null;
|
|
element.Enable = true;
|
|
|
|
_cocktailsBtn[key] = element;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SelectedItem(Button clickedButton)
|
|
{
|
|
Debug.Log(clickedButton.transform.GetSiblingIndex());
|
|
|
|
if (_cocktailsBtn[clickedButton.name].Enable) //활성화 된 음료만 클릭이 되도록 한다.
|
|
{
|
|
_cocktailImage.sprite = clickedButton.transform.Find("Image").GetComponent<Image>().sprite;
|
|
|
|
bool slot1 = false;
|
|
bool slot2 = false;
|
|
bool slot3 = false;
|
|
|
|
GameObject slot()
|
|
{
|
|
if (!slot1)
|
|
{
|
|
slot1 = true;
|
|
return _ingredientSlot1;
|
|
}
|
|
|
|
if (!slot2)
|
|
{
|
|
slot2 = true;
|
|
return _ingredientSlot2;
|
|
}
|
|
|
|
if (!slot3)
|
|
{
|
|
slot3 = true;
|
|
return _ingredientSlot3;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
|
|
//가니쉬 배치를 처음으로...
|
|
if (_cocktailsBtn[clickedButton.name].Garnish1 != 0)
|
|
{
|
|
_ingredientSlot3.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "Garnish1";
|
|
_ingredientSlot3.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].Garnish1}%";
|
|
_ingredientSlot3.transform.Find("IngredientImage").GetComponent<Image>().sprite = Garnish1_Sprite;
|
|
slot3 = true;
|
|
}
|
|
else if (_cocktailsBtn[clickedButton.name].Garnish2 != 0)
|
|
{
|
|
_ingredientSlot3.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "Garnish2";
|
|
_ingredientSlot3.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].Garnish2}%";
|
|
_ingredientSlot3.transform.Find("IngredientImage").GetComponent<Image>().sprite = Garnish2_Sprite;
|
|
slot3 = true;
|
|
}
|
|
|
|
if (_cocktailsBtn[clickedButton.name].LiquidA != 0)
|
|
{
|
|
var ingredient = slot();
|
|
ingredient.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "LiquidA";
|
|
ingredient.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].LiquidA}%";
|
|
ingredient.transform.Find("IngredientImage").GetComponent<Image>().sprite = LiquidA_Sprite;
|
|
}
|
|
|
|
if (_cocktailsBtn[clickedButton.name].LiquidB != 0)
|
|
{
|
|
var ingredient = slot();
|
|
ingredient.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "LiquidB";
|
|
ingredient.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].LiquidB}%";
|
|
ingredient.transform.Find("IngredientImage").GetComponent<Image>().sprite = LiquidB_Sprite;
|
|
}
|
|
|
|
if (_cocktailsBtn[clickedButton.name].LiquidC != 0)
|
|
{
|
|
var ingredient = slot();
|
|
ingredient.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "LiquidC";
|
|
ingredient.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].LiquidC}%";
|
|
ingredient.transform.Find("IngredientImage").GetComponent<Image>().sprite = LiquidC_Sprite;
|
|
}
|
|
|
|
if (_cocktailsBtn[clickedButton.name].LiquidD != 0)
|
|
{
|
|
var ingredient = slot();
|
|
ingredient.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "LiquidD";
|
|
ingredient.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].LiquidD}%";
|
|
ingredient.transform.Find("IngredientImage").GetComponent<Image>().sprite = LiquidD_Sprite;
|
|
}
|
|
|
|
if (_cocktailsBtn[clickedButton.name].LiquidE != 0)
|
|
{
|
|
var ingredient = slot();
|
|
ingredient.transform.Find("IngredientType").GetComponent<TextMeshProUGUI>().text = "LiquidE";
|
|
ingredient.transform.Find("IngredientPersent").GetComponent<TextMeshProUGUI>().text =
|
|
$"{_cocktailsBtn[clickedButton.name].LiquidE}%";
|
|
ingredient.transform.Find("IngredientImage").GetComponent<Image>().sprite = LiquidE_Sprite;
|
|
}
|
|
|
|
if (!slot1)
|
|
{
|
|
_ingredientSlot1.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_ingredientSlot1.SetActive(true);
|
|
}
|
|
|
|
if (!slot2)
|
|
{
|
|
_ingredientSlot2.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_ingredientSlot2.SetActive(true);
|
|
}
|
|
|
|
if (!slot3)
|
|
{
|
|
_ingredientSlot3.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
_ingredientSlot3.SetActive(true);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
private void UpdateManualBook(LevelData levelData)
|
|
{
|
|
Update_Cocktails();
|
|
}
|
|
}
|