465 lines
16 KiB
C#
465 lines
16 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Items;
|
|
using BlueWater.Tycoons;
|
|
using BlueWater.Utility;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Localization;
|
|
using UnityEngine.Localization.Settings;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class ManualBook : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _openManualKeyText;
|
|
|
|
[SerializeField]
|
|
private Transform _cocktailButtons;
|
|
|
|
[field: SerializeField]
|
|
private Image cocktailImage;
|
|
|
|
[field: SerializeField]
|
|
private TextMeshProUGUI cocktailName;
|
|
|
|
[field: SerializeField]
|
|
private ManualCocktailButton manualCocktailsPrefabs;
|
|
|
|
[field: SerializeField]
|
|
private ManualIngredientSlot slot01;
|
|
|
|
[field: SerializeField]
|
|
private ManualIngredientSlot slot02;
|
|
|
|
[field: SerializeField]
|
|
private ManualIngredientSlot slot03;
|
|
|
|
[field: SerializeField]
|
|
private TextMeshProUGUI ratioRange;
|
|
|
|
[SerializeField]
|
|
private string _manualSfxName = "ManualBook";
|
|
|
|
[SerializeField]
|
|
private UiNavigationController _uiNavigationController;
|
|
|
|
private List<ManualCocktailButton> _button;
|
|
private Coroutine _changedLocaleInstance;
|
|
private ManualCocktailButton _selectedManualCocktailButton;
|
|
private InputAction _openManualBookAction;
|
|
private InputAction _pressQAction;
|
|
private InputAction _cancelAction;
|
|
|
|
private string _openManualKeyBinding;
|
|
|
|
private void Start()
|
|
{
|
|
_openManualBookAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.Tycoon, TycoonActions.OpenManualBook);
|
|
_pressQAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.PressQ);
|
|
_cancelAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, TycoonUiActions.Cancel);
|
|
|
|
_openManualKeyBinding = PlayerInputKeyManager.Instance.GetBoundKey(_openManualBookAction);
|
|
SetKeyText(_openManualKeyBinding);
|
|
|
|
_openManualBookAction.performed += OnOpen;
|
|
|
|
var allCocktails = ItemManager.Instance.CocktailDataSo.GetData();
|
|
_button = new List<ManualCocktailButton>(allCocktails.Count);
|
|
foreach (var element in allCocktails.Values)
|
|
{
|
|
if (element.Idx.Equals("Cocktail000")) continue; //쓰레기는 메뉴얼에 표시하지 않기
|
|
|
|
var cocktail = Instantiate(manualCocktailsPrefabs, _cocktailButtons);
|
|
cocktail.AddSelectedAction(SelectedItem);
|
|
cocktail.name = element.Idx;
|
|
cocktail.SetImage(element.Sprite);
|
|
_button.Add(cocktail);
|
|
|
|
foreach (var element2 in element.ValidIngredients) //들어가는 리큐르, 가니쉬 종류
|
|
{
|
|
if (element2.Idx.Equals("LiquidA"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 1;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("LiquidB"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 2;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("LiquidC"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 4;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("LiquidD"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 8;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("LiquidE"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 16;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("Garnish1"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 32;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
|
|
if (element2.Idx.Equals("Garnish2"))
|
|
{
|
|
var scale = cocktail.transform.localScale;
|
|
scale.z += 64;
|
|
cocktail.transform.localScale = scale;
|
|
}
|
|
}
|
|
}
|
|
|
|
_button = _button.OrderBy(c => c.transform.localScale.z).ToList();
|
|
SetNavigation();
|
|
_uiNavigationController.SetSelectObject(_button[0].gameObject);
|
|
EventSystem.current.SetSelectedGameObject(_uiNavigationController.SelectObject);
|
|
|
|
for (int i = 0; i < _button.Count; i++)
|
|
{
|
|
_button[i].transform.SetSiblingIndex(i);
|
|
_button[i].transform.localScale = new Vector3(1.0f, 1.0f, 1.0f);
|
|
}
|
|
|
|
Update_Cocktails();
|
|
|
|
EventManager.OnLevelUp += UpdateManualBook;
|
|
LocalizationSettings.SelectedLocaleChanged += OnChangedLocale;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventManager.OnLevelUp -= UpdateManualBook;
|
|
LocalizationSettings.SelectedLocaleChanged -= OnChangedLocale;
|
|
_openManualBookAction.performed -= OnOpen;
|
|
_pressQAction.performed -= OnClose;
|
|
_cancelAction.performed -= OnClose;
|
|
}
|
|
|
|
private void OnChangedLocale(Locale locale)
|
|
{
|
|
Utils.StartUniqueCoroutine(this, ref _changedLocaleInstance, ChangeLocaleCoroutine(locale));
|
|
StartCoroutine(ChangeLocaleCoroutine(locale));
|
|
}
|
|
|
|
private IEnumerator ChangeLocaleCoroutine(Locale locale)
|
|
{
|
|
var loadingOperation = Utils.GetTableAsync();
|
|
yield return loadingOperation;
|
|
|
|
if (loadingOperation.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
SelectedItem(_selectedManualCocktailButton);
|
|
}
|
|
}
|
|
|
|
public void OnOpen(InputAction.CallbackContext context)
|
|
{
|
|
Open();
|
|
}
|
|
|
|
public override void Open()
|
|
{
|
|
if (!PopupUiController.IsPopupListEmpty()) return;
|
|
|
|
VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.TycoonUi);
|
|
PopupUiController.RegisterPopup(this);
|
|
_panel.SetActive(true);
|
|
IsOpened = true;
|
|
AudioManager.Instance.PlaySfx(_manualSfxName, ignoreTimeScale: true);
|
|
EventSystem.current.SetSelectedGameObject(_uiNavigationController.SelectObject);
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
AudioManager.Instance.PlaySfx(_manualSfxName, ignoreTimeScale: true);
|
|
_panel.SetActive(false);
|
|
PopupUiController.UnregisterPopup(this);
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Tycoon);
|
|
IsOpened = false;
|
|
VisualFeedbackManager.Instance.ResetTimeScale();
|
|
}
|
|
|
|
public override void EnableInput()
|
|
{
|
|
_pressQAction.performed += OnClose;
|
|
_cancelAction.performed += OnClose;
|
|
_uiNavigationController.Enable();
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
_uiNavigationController.Disable();
|
|
_pressQAction.performed -= OnClose;
|
|
_cancelAction.performed -= OnClose;
|
|
}
|
|
|
|
private void SetKeyText(string bindingKey)
|
|
{
|
|
_openManualKeyText.text = bindingKey;
|
|
}
|
|
|
|
private void SetNavigation()
|
|
{
|
|
int maxRow = 4;
|
|
|
|
for (int i = 0; i < _button.Count; i++)
|
|
{
|
|
Navigation navigation = _button[i].Button.navigation;
|
|
navigation.mode = Navigation.Mode.Explicit;
|
|
|
|
// 좌측 네비게이션 설정
|
|
if (i % maxRow != 0)
|
|
{
|
|
navigation.selectOnLeft = _button[i - 1].Button;
|
|
}
|
|
|
|
// 우측 네비게이션 설정
|
|
if ((i + 1) % maxRow != 0 && (i + 1) < _button.Count)
|
|
{
|
|
navigation.selectOnRight = _button[i + 1].Button;
|
|
}
|
|
|
|
// 위쪽 네비게이션 설정
|
|
if (i - maxRow >= 0)
|
|
{
|
|
navigation.selectOnUp = _button[i - maxRow].Button;
|
|
}
|
|
|
|
// 아래쪽 네비게이션 설정
|
|
if (i + maxRow < _button.Count)
|
|
{
|
|
navigation.selectOnDown = _button[i + maxRow].Button;
|
|
}
|
|
|
|
// 설정된 네비게이션을 버튼에 적용
|
|
_button[i].Button.navigation = navigation;
|
|
}
|
|
}
|
|
|
|
private void Update_Cocktails() //해금된 칵테일의 활성 표시 유무
|
|
{
|
|
int playerLv = TycoonManager.Instance.TycoonStatus.CurrentLevel;
|
|
|
|
bool check = false;
|
|
|
|
var cocktailDatas = ItemManager.Instance.CocktailDataSo.GetData();
|
|
|
|
foreach (var element in _button)
|
|
{
|
|
check = false;
|
|
|
|
var cocktailIngredients = cocktailDatas[element.name].ValidIngredients;
|
|
|
|
foreach (var element2 in cocktailIngredients)
|
|
{
|
|
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.transform.Find("Image").GetComponent<Image>().material = null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SelectedItem(ManualCocktailButton clickedButton)
|
|
{
|
|
_selectedManualCocktailButton = clickedButton;
|
|
_uiNavigationController.SetSelectObject(_selectedManualCocktailButton.gameObject);
|
|
//if (clickedButton.GetComponent<Image>().material == null) //활성화 된 음료만 클릭이 되도록 한다.
|
|
if (true) // 테스트용
|
|
{
|
|
bool checkSlot1 = false;
|
|
bool checkSlot2 = false;
|
|
bool checkSlot3 = false;
|
|
|
|
var cocktailDatas = ItemManager.Instance.CocktailDataSo.GetData();
|
|
var liquidDatas = ItemManager.Instance.LiquidDataSo.GetData();
|
|
|
|
cocktailImage.sprite = clickedButton.Image.sprite;
|
|
cocktailName.text = Utils.GetLocalizedString(clickedButton.name);
|
|
int ratioRangePer = cocktailDatas[clickedButton.name].RatioRange;
|
|
ratioRange.text = ratioRangePer == 0
|
|
? ""
|
|
: $"{Utils.GetLocalizedString("MarginOfError")} : {ratioRangePer}%";
|
|
|
|
void Setslot(string ingredientName, int targetSlotNum = 0)
|
|
{
|
|
int targetSlotNumF = 0;
|
|
|
|
if (targetSlotNum != 0)
|
|
{
|
|
if (targetSlotNum == 1)
|
|
{
|
|
targetSlotNumF = 1;
|
|
checkSlot1 = true;
|
|
}
|
|
else if (targetSlotNum == 2)
|
|
{
|
|
targetSlotNumF = 2;
|
|
checkSlot2 = true;
|
|
}
|
|
else if (targetSlotNum == 3)
|
|
{
|
|
targetSlotNumF = 3;
|
|
checkSlot3 = true;
|
|
}
|
|
}
|
|
else if (!checkSlot1)
|
|
{
|
|
targetSlotNumF = 1;
|
|
checkSlot1 = true;
|
|
}
|
|
else if (!checkSlot2)
|
|
{
|
|
targetSlotNumF = 2;
|
|
checkSlot2 = true;
|
|
}
|
|
else if (!checkSlot3)
|
|
{
|
|
targetSlotNumF = 3;
|
|
checkSlot3 = true;
|
|
}
|
|
|
|
ManualIngredientSlot targetSlotF = null;
|
|
if (targetSlotNumF == 1) targetSlotF = slot01;
|
|
else if (targetSlotNumF == 2) targetSlotF = slot02;
|
|
else if (targetSlotNumF == 3) targetSlotF = slot03;
|
|
|
|
if (targetSlotF == null) return;
|
|
|
|
targetSlotF.SetImage(liquidDatas[ingredientName].Sprite);
|
|
targetSlotF.SetType(Utils.GetLocalizedString(ingredientName));
|
|
targetSlotF.SetPercent($"{cocktailDatas[clickedButton.name].GetIngredientRatio(ingredientName)}%");
|
|
}
|
|
|
|
//가니쉬 배치를 처음으로... 일단 대기...
|
|
/*
|
|
*
|
|
if (cocktailDatas[clickedButton.name].SearchIngredient("Garnish1") != 0)
|
|
{
|
|
Setslot("Garnish1",3);
|
|
}
|
|
else if (cocktailDatas[clickedButton.name].SearchIngredient("Garnish2") != 0)
|
|
{
|
|
Setslot("Garnish2",3);
|
|
}
|
|
*/
|
|
|
|
foreach (var element in liquidDatas)
|
|
{
|
|
if (cocktailDatas[clickedButton.name].SearchIngredient(element.Value.Idx) != 0)
|
|
Setslot(element.Value.Idx);
|
|
}
|
|
|
|
if (!checkSlot1)
|
|
{
|
|
slot01.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
slot01.gameObject.SetActive(true);
|
|
}
|
|
|
|
if (!checkSlot2)
|
|
{
|
|
slot02.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
slot02.gameObject.SetActive(true);
|
|
}
|
|
|
|
if (!checkSlot3)
|
|
{
|
|
slot03.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
slot03.gameObject.SetActive(true);
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateManualBook(LevelData levelData)
|
|
{
|
|
Update_Cocktails();
|
|
}
|
|
}
|
|
} |