293 lines
11 KiB
C#
293 lines
11 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using BlueWater.Audios;
|
|
using BlueWater.Items;
|
|
using BlueWater.Utility;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
using UnityEngine.Localization;
|
|
using UnityEngine.Localization.Settings;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
namespace BlueWater.Uis
|
|
{
|
|
public class ManualBook : PopupUi
|
|
{
|
|
[SerializeField]
|
|
private GameObject _panel;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _openManualKeyText;
|
|
|
|
[Title("선택된 칵테일")]
|
|
[SerializeField]
|
|
private TMP_Text _selectedCocktailName;
|
|
|
|
[SerializeField]
|
|
private Image _selectedCocktailImage;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _ratioRange;
|
|
|
|
[SerializeField]
|
|
private TMP_Text _selectedCocktailDescription;
|
|
|
|
[Title("제작 방법")]
|
|
[SerializeField]
|
|
private Transform _craftingContents;
|
|
|
|
[SerializeField]
|
|
private List<CraftingIngredient> _craftingIngredients = new(3);
|
|
|
|
[Title("사운드")]
|
|
[SerializeField]
|
|
private string _openManualSfxName = "OpenManualBook";
|
|
|
|
[SerializeField]
|
|
private string _closeManualSfxName = "CloseManualBook";
|
|
|
|
[Title("참조")]
|
|
[SerializeField]
|
|
private UiEventsController uiEventsController;
|
|
|
|
[Title("실시간 데이터")]
|
|
[SerializeField]
|
|
private List<CocktailRecipeButton> _cocktailRecipeButtons;
|
|
|
|
[ShowInInspector]
|
|
private HashSet<string> _unlockLiquidIdxs = new(7);
|
|
|
|
private CocktailRecipeButton _selectedCocktailRecipeButton;
|
|
private Coroutine _changedLocaleInstance;
|
|
private InputAction _openManualBookAction;
|
|
private InputAction _pressQAction;
|
|
private InputAction _cancelAction;
|
|
|
|
private string _openManualKeyBinding;
|
|
|
|
private void Awake()
|
|
{
|
|
_cocktailRecipeButtons = transform.GetComponentsInChildren<CocktailRecipeButton>(true).ToList();
|
|
|
|
foreach (var element in _cocktailRecipeButtons)
|
|
{
|
|
element.Initialize();
|
|
element.AddSelectedAction(SelectItem);
|
|
}
|
|
|
|
_craftingIngredients = _craftingContents.GetComponentsInChildren<CraftingIngredient>(true).ToList();
|
|
|
|
EventManager.OnLevelUp += UpdateManualBook;
|
|
LocalizationSettings.SelectedLocaleChanged += OnChangedLocale;
|
|
}
|
|
|
|
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;
|
|
|
|
uiEventsController.SetSelectObject(_cocktailRecipeButtons[0].gameObject);
|
|
EventSystem.current.SetSelectedGameObject(uiEventsController.SelectObject);
|
|
}
|
|
|
|
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)
|
|
{
|
|
if (_selectedCocktailRecipeButton != null)
|
|
{
|
|
_selectedCocktailName.text = Utils.GetLocalizedString(_selectedCocktailRecipeButton.CocktailData.Idx);
|
|
_ratioRange.text = $"{Utils.GetLocalizedString("MarginOfError")} : {_selectedCocktailRecipeButton.CocktailData.RatioRange}%";
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append($"{_selectedCocktailRecipeButton.CocktailData.Idx}Description");
|
|
_selectedCocktailDescription.text = Utils.GetLocalizedString(stringBuilder.ToString());
|
|
}
|
|
}
|
|
}
|
|
|
|
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(_openManualSfxName, ignoreTimeScale: true);
|
|
EventSystem.current.SetSelectedGameObject(uiEventsController.SelectObject);
|
|
}
|
|
|
|
public void OnClose(InputAction.CallbackContext context)
|
|
{
|
|
Close();
|
|
}
|
|
|
|
public override void Close()
|
|
{
|
|
AudioManager.Instance.PlaySfx(_closeManualSfxName, 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;
|
|
uiEventsController.EnableAutoNavigate();
|
|
}
|
|
|
|
public override void DisableInput()
|
|
{
|
|
uiEventsController.DisableAutoNavigate();
|
|
_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;
|
|
// }
|
|
// }
|
|
|
|
public void SelectItem(CocktailRecipeButton cocktailRecipeButton)
|
|
{
|
|
_selectedCocktailRecipeButton = cocktailRecipeButton;
|
|
uiEventsController.SetSelectObject(_selectedCocktailRecipeButton.gameObject);
|
|
|
|
_selectedCocktailName.text = Utils.GetLocalizedString(_selectedCocktailRecipeButton.CocktailData.Idx);
|
|
_selectedCocktailImage.sprite = _selectedCocktailRecipeButton.CocktailData.Sprite;
|
|
_ratioRange.text = $"{Utils.GetLocalizedString("MarginOfError")} : {_selectedCocktailRecipeButton.CocktailData.RatioRange}%";
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
stringBuilder.Append($"{_selectedCocktailRecipeButton.CocktailData.Idx}Description");
|
|
_selectedCocktailDescription.text = Utils.GetLocalizedString(stringBuilder.ToString());
|
|
|
|
List<CocktailIngredient> validIngredients = _selectedCocktailRecipeButton.CocktailData.ValidIngredients;
|
|
|
|
for (int i = 0; i < _craftingIngredients.Count; i++)
|
|
{
|
|
if (i >= validIngredients.Count)
|
|
{
|
|
_craftingIngredients[i].Hide();
|
|
}
|
|
else
|
|
{
|
|
_craftingIngredients[i].Initialize(validIngredients[i], i);
|
|
_craftingIngredients[i].Show();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void UpdateManualBook(LevelData levelData)
|
|
{
|
|
if (string.IsNullOrEmpty(levelData.OpenUpgrade)) return;
|
|
|
|
int currentLevel = int.Parse(levelData.Idx);
|
|
switch (currentLevel)
|
|
{
|
|
case 1:
|
|
_unlockLiquidIdxs.Add("LiquidA");
|
|
break;
|
|
case 5:
|
|
_unlockLiquidIdxs.Add("LiquidB");
|
|
break;
|
|
case 10:
|
|
_unlockLiquidIdxs.Add("LiquidC");
|
|
break;
|
|
case 15:
|
|
_unlockLiquidIdxs.Add("LiquidD");
|
|
break;
|
|
case 20:
|
|
_unlockLiquidIdxs.Add("LiquidE");
|
|
break;
|
|
case 25:
|
|
_unlockLiquidIdxs.Add("Garnish1");
|
|
break;
|
|
case 30:
|
|
_unlockLiquidIdxs.Add("Garnish2");
|
|
break;
|
|
}
|
|
|
|
foreach (var element in _cocktailRecipeButtons)
|
|
{
|
|
element.CheckUnlock(_unlockLiquidIdxs);
|
|
}
|
|
}
|
|
}
|
|
} |