2024-06-03 18:26:03 +00:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using BlueWater.Items;
|
2024-06-29 15:59:31 +00:00
|
|
|
using BlueWater.Utility;
|
|
|
|
using Sirenix.OdinInspector;
|
2024-06-03 18:26:03 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace BlueWater.Uis
|
|
|
|
{
|
|
|
|
public class ItemLootUi : MonoBehaviour
|
|
|
|
{
|
|
|
|
[SerializeField]
|
|
|
|
private List<ItemLootInfoUi> _itemLootInfoUis = new(3);
|
2024-06-29 15:59:31 +00:00
|
|
|
|
|
|
|
[ShowInInspector]
|
|
|
|
private Queue<(ItemData, int, int)> _waitingLootInfoUis = new();
|
2024-06-03 18:26:03 +00:00
|
|
|
|
2024-06-29 15:59:31 +00:00
|
|
|
private Coroutine _waitingQueueCoroutineInstance;
|
2024-06-03 18:26:03 +00:00
|
|
|
private readonly WaitForSeconds _coroutineRestartTime = new(0.5f);
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
var itemLootInfoUis = GetComponentsInChildren<ItemLootInfoUi>();
|
|
|
|
foreach (var element in itemLootInfoUis)
|
|
|
|
{
|
|
|
|
_itemLootInfoUis.Add(element);
|
|
|
|
}
|
2024-06-29 15:59:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void ShowLootInfoUi(ItemData itemData, int count)
|
|
|
|
{
|
|
|
|
var totalItemCount = DataManager.Instance.CombatInventory.GetItemByIdx(itemData.Idx).Count;
|
|
|
|
|
|
|
|
if (_waitingLootInfoUis.Count > 0)
|
|
|
|
{
|
|
|
|
_waitingLootInfoUis.Enqueue((itemData, count, totalItemCount));
|
|
|
|
return;
|
|
|
|
}
|
2024-06-03 18:26:03 +00:00
|
|
|
|
|
|
|
foreach (var element in _itemLootInfoUis)
|
|
|
|
{
|
2024-06-29 15:59:31 +00:00
|
|
|
if (element.IsShowing) continue;
|
|
|
|
|
|
|
|
SetItemLootInfo(element, itemData, count, totalItemCount);
|
|
|
|
return;
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
2024-06-29 15:59:31 +00:00
|
|
|
|
|
|
|
_waitingLootInfoUis.Enqueue((itemData, count, totalItemCount));
|
|
|
|
Utils.StartUniqueCoroutine(this, ref _waitingQueueCoroutineInstance, WaitingQueueCoroutine());
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
2024-06-29 15:59:31 +00:00
|
|
|
private void SetItemLootInfo(ItemLootInfoUi element, ItemData itemData, int count, int totalItemCount)
|
2024-06-03 18:26:03 +00:00
|
|
|
{
|
2024-06-29 15:59:31 +00:00
|
|
|
var itemNameText = $"+{count} {itemData.Name}";
|
|
|
|
var totalItemCountText = $"({totalItemCount})";
|
|
|
|
|
|
|
|
element.SetInfo(itemData.Sprite, itemNameText, totalItemCountText);
|
|
|
|
element.ShowUi();
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
|
2024-06-29 15:59:31 +00:00
|
|
|
private IEnumerator WaitingQueueCoroutine()
|
2024-06-03 18:26:03 +00:00
|
|
|
{
|
2024-06-29 15:59:31 +00:00
|
|
|
while (_waitingLootInfoUis.Count > 0)
|
2024-06-03 18:26:03 +00:00
|
|
|
{
|
|
|
|
foreach (var element in _itemLootInfoUis)
|
|
|
|
{
|
2024-06-29 15:59:31 +00:00
|
|
|
if (element.IsShowing) continue;
|
2024-06-03 18:26:03 +00:00
|
|
|
|
2024-06-29 15:59:31 +00:00
|
|
|
var lootInfoUi = _waitingLootInfoUis.Dequeue();
|
|
|
|
SetItemLootInfo(element, lootInfoUi.Item1, lootInfoUi.Item2, lootInfoUi.Item3);
|
2024-06-03 18:26:03 +00:00
|
|
|
|
2024-06-29 15:59:31 +00:00
|
|
|
break;
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
2024-06-29 15:59:31 +00:00
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
yield return _coroutineRestartTime;
|
|
|
|
}
|
2024-06-29 15:59:31 +00:00
|
|
|
|
|
|
|
_waitingQueueCoroutineInstance = null;
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|