using System.Collections.Generic; using BlueWater.Items; using Sirenix.OdinInspector; using TMPro; using UnityEngine; namespace BlueWater.Uis { public class DiscardPopupUi : PopupUi { private enum RemoveType { None = 0, Single, Multi } [SerializeField, Required] private TMP_Text _contentText; [SerializeField, Required] private GameObject _countSelectUi; [SerializeField, Required] private TMP_Text _countText; private List _selectedList = new(); private int _currentCount = 1; private RemoveType _removeType; [Button("컴포넌트 초기화")] private void InitializeComponents() { _contentText = transform.Find("DiscardPanel/Content/ContentText").GetComponent(); _countSelectUi = transform.Find("DiscardPanel/CountSelectUi").gameObject; _countText = _countSelectUi.transform.Find("CountBackground/CountText").GetComponent(); } public override void Close() { _removeType = RemoveType.None; _selectedList.Clear(); _countSelectUi.SetActive(false); base.Close(); } public void DiscardMessage(ItemSlotUi selectedSlot) { _removeType = RemoveType.Single; _selectedList.Clear(); _selectedList.Add(selectedSlot); _contentText.text = ItemManager.Instance.GetItemDataByIdx(selectedSlot.ItemSlot.Idx).Name + "을(를) 버리시겠습니까?"; _currentCount = 1; _countText.text = _currentCount.ToString(); _countSelectUi.SetActive(true); Open(CombatUiManager.Instance.PopupUiList); } public void DiscardAllMessage(List selectedSlotList) { _removeType = RemoveType.Multi; _selectedList = new List(selectedSlotList); _contentText.text = "선택한 물품을 모두 버리시겠습니까?"; _countSelectUi.SetActive(false); Open(CombatUiManager.Instance.PopupUiList); } public void CountDownButton() { _currentCount--; _currentCount = Mathf.Clamp(_currentCount, 1, _selectedList[0].ItemSlot.Count); _countText.text = _currentCount.ToString(); } public void CountUpButton() { _currentCount++; _currentCount = Mathf.Clamp(_currentCount , 1, _selectedList[0].ItemSlot.Count); _countText.text = _currentCount.ToString(); } public void DiscardButton() { if (_removeType == RemoveType.Single) { DataManager.Instance.CombatInventory.RemoveItem(_selectedList[0].ItemSlot, _currentCount); } else if (_removeType == RemoveType.Multi) { foreach (var element in _selectedList) { DataManager.Instance.CombatInventory.RemoveItem(element.ItemSlot, element.ItemSlot.Count); } } Close(); } } }