102 lines
3.2 KiB
C#
102 lines
3.2 KiB
C#
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<ItemSlotUi> _selectedList = new();
|
|
private int _currentCount = 1;
|
|
private RemoveType _removeType;
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
_contentText = transform.Find("DiscardPanel/Content/ContentText").GetComponent<TMP_Text>();
|
|
_countSelectUi = transform.Find("DiscardPanel/CountSelectUi").gameObject;
|
|
_countText = _countSelectUi.transform.Find("CountBackground/CountText").GetComponent<TMP_Text>();
|
|
}
|
|
|
|
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.ItemDataSo.GetDataByIdx(selectedSlot.ItemSlot.Idx).Name + "을(를) 버리시겠습니까?";
|
|
_currentCount = 1;
|
|
_countText.text = _currentCount.ToString();
|
|
|
|
_countSelectUi.SetActive(true);
|
|
Open();
|
|
}
|
|
|
|
public void DiscardAllMessage(List<ItemSlotUi> selectedSlotList)
|
|
{
|
|
_removeType = RemoveType.Multi;
|
|
_selectedList = new List<ItemSlotUi>(selectedSlotList);
|
|
_contentText.text = "선택한 물품을 모두 버리시겠습니까?";
|
|
|
|
_countSelectUi.SetActive(false);
|
|
Open();
|
|
}
|
|
|
|
public void CountDownButton()
|
|
{
|
|
_currentCount--;
|
|
_currentCount = Mathf.Clamp(_currentCount, 1, _selectedList[0].ItemSlot.Quantity);
|
|
_countText.text = _currentCount.ToString();
|
|
}
|
|
|
|
public void CountUpButton()
|
|
{
|
|
_currentCount++;
|
|
_currentCount = Mathf.Clamp(_currentCount , 1, _selectedList[0].ItemSlot.Quantity);
|
|
_countText.text = _currentCount.ToString();
|
|
}
|
|
|
|
public void DiscardButton()
|
|
{
|
|
if (_removeType == RemoveType.Single)
|
|
{
|
|
DataManager.Instance.Inventory.RemoveItem(_selectedList[0].ItemSlot, _currentCount);
|
|
}
|
|
else if (_removeType == RemoveType.Multi)
|
|
{
|
|
foreach (var element in _selectedList)
|
|
{
|
|
DataManager.Instance.Inventory.RemoveItem(element.ItemSlot, element.ItemSlot.Quantity);
|
|
}
|
|
}
|
|
|
|
Close();
|
|
}
|
|
}
|
|
} |