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.InputSystem; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; namespace BlueWater.Uis { public class ManualBook : SwitchActionPopupUi { [SerializeField] private GameObject _panel; [SerializeField] private Transform _cocktailButtons; [field: SerializeField] private Image cocktailImage; [field: SerializeField] private TextMeshProUGUI cocktailName; [field: SerializeField, CLabel("메뉴얼 CockTail Prefab")] 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"; List _button = new List(); private Coroutine _changedLocaleInstance; private ManualCocktailButton _selectedManualCocktailButton; private InputAction _openManualBookAction; private InputAction _pressQAction; private InputAction _cancelAction; private void Awake() { EventManager.OnLevelUp += UpdateManualBook; LocalizationSettings.SelectedLocaleChanged += OnChangedLocale; } private void Start() { _openManualBookAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.Tycoon, "OpenManualBook"); _pressQAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, "PressQ"); _cancelAction = PlayerInputKeyManager.Instance.GetAction(InputActionMaps.TycoonUi, "Cancel"); _openManualBookAction.performed += OnOpen; var allCocktails = ItemManager.Instance.CocktailDataSo.GetData(); foreach (var element in allCocktails.Values) { if (element.Idx.Equals("Cocktail000")) continue; //쓰레기는 메뉴얼에 표시하지 않기 var cocktail = Instantiate(manualCocktailsPrefabs, _cocktailButtons); cocktail.Initialize(this); 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(); 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(); SelectedItem(_button[0]); } private void OnDestroy() { LocalizationSettings.SelectedLocaleChanged -= OnChangedLocale; } 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() { AudioManager.Instance.PlaySfx(_manualSfxName, ignoreTimeScale: true); VisualFeedbackManager.Instance.SetBaseTimeScale(0.0f); PlayerInputKeyManager.Instance.SwitchCurrentActionMap(SwitchMapsOpened); PopupUiController.RegisterPopup(this); _panel.SetActive(true); IsOpened = true; } 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(SwitchMapsClosed); IsOpened = false; VisualFeedbackManager.Instance.ResetTimeScale(); } public override void EnableInput() { _pressQAction.performed += OnClose; _cancelAction.performed += OnClose; } public override void DisableInput() { _pressQAction.performed -= OnClose; _cancelAction.performed -= OnClose; } 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().material = null; } } } public void SelectedItem(ManualCocktailButton clickedButton) { _selectedManualCocktailButton = clickedButton; //if (clickedButton.GetComponent().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(); } } }