+ Item관련 Excel, Json, So 수정 + DropItemTable 로직 수정 + 아이템 프리팹에서 Enable Interaction 체크하면 직접 룻팅, 해제하면 자동 룻팅 + 체력회복 아이템 추가 + 개발자 메뉴 상호작용 "F1" 키를 통해 접근 가능 + 보스 맵은 마법진을 상호작용하면 보스전 시작 + 맵 안에서 교전 중일 때, 투명 벽 쉐이더 추가 + 맵 마다의 통로를 통해서 이동 가능 + 선형적인 맵 구조에 맞게 리소스 및 위치 수정 + 타이틀 화면으로 이동할 때 나타나는 오류 수정(CombatUiManager OnDisable 싱글톤 문제) Closes #25, #26
255 lines
7.8 KiB
C#
255 lines
7.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using BlueWater.Players.Combat;
|
|
using BlueWater.Uis;
|
|
using Sirenix.OdinInspector;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace BlueWater.Items
|
|
{
|
|
public class CombatItemInventoryUi : SwitchActionPopupUi
|
|
{
|
|
// Variables
|
|
#region Variables
|
|
|
|
// Components
|
|
[SerializeField, Required]
|
|
protected TMP_Dropdown SortingDropdown;
|
|
|
|
[SerializeField, Required]
|
|
protected TMP_Text CurrentWeight;
|
|
|
|
[SerializeField, Required]
|
|
protected Transform InstantiateLocation;
|
|
|
|
[SerializeField, Required]
|
|
protected DiscardPopupUi DiscardPopupUi;
|
|
|
|
[SerializeField, Required]
|
|
protected GameObject ItemSlotUiPrefab;
|
|
|
|
// Variables
|
|
[SerializeField]
|
|
private List<ItemSlotUi> _itemSlotUiList = new();
|
|
|
|
private List<ItemSlotUi> _selectedList = new();
|
|
private CombatInventory _combatInventory;
|
|
|
|
#endregion
|
|
|
|
// Unity events
|
|
#region Unity events
|
|
|
|
private void Awake()
|
|
{
|
|
InitializeInventory();
|
|
InventorySynchronization();
|
|
CalculateWeight();
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
DiscardPopupUi.Close();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
_combatInventory.OnChangeItemSlot += ChangedData;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
_combatInventory.OnChangeItemSlot -= ChangedData;
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Initialize methods
|
|
#region Initialize methods
|
|
|
|
[Button("컴포넌트 초기화")]
|
|
private void InitializeComponents()
|
|
{
|
|
SortingDropdown = transform.Find("ItemInventoryPanel/Popup Base - Concave/Top/SortingDropdown").GetComponent<TMP_Dropdown>();
|
|
CurrentWeight = transform.Find("ItemInventoryPanel/Popup Base - Concave/Top/CurrentWeight").GetComponent<TMP_Text>();
|
|
InstantiateLocation = transform.Find("ItemInventoryPanel/ScrollView/Viewport/Content");
|
|
DiscardPopupUi = transform.Find("DiscardPopupUi").GetComponent<DiscardPopupUi>();
|
|
}
|
|
|
|
private void InitializeInventory()
|
|
{
|
|
if (DataManager.Instance)
|
|
{
|
|
_combatInventory = DataManager.Instance.CombatInventory;
|
|
}
|
|
|
|
_itemSlotUiList.Clear();
|
|
|
|
foreach (Transform element in InstantiateLocation)
|
|
{
|
|
Destroy(element.gameObject);
|
|
}
|
|
}
|
|
|
|
private void InventorySynchronization()
|
|
{
|
|
foreach (var element in _combatInventory.ItemSlotList)
|
|
{
|
|
var newItemContent = Instantiate(ItemSlotUiPrefab, InstantiateLocation).GetComponent<ItemSlotUi>();
|
|
newItemContent.InitializeData(element);
|
|
_itemSlotUiList.Add(newItemContent);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
// Methods
|
|
#region Methods
|
|
|
|
public override void Close()
|
|
{
|
|
if (DiscardPopupUi.gameObject.activeSelf)
|
|
{
|
|
DiscardPopupUi.Close();
|
|
}
|
|
|
|
base.Close();
|
|
}
|
|
|
|
private void CalculateWeight()
|
|
{
|
|
if (float.IsPositiveInfinity(_combatInventory.WeightLimit))
|
|
{
|
|
CurrentWeight.text = _combatInventory.CurrentTotalWeight + " / ∞Kg";
|
|
}
|
|
else
|
|
{
|
|
CurrentWeight.text = _combatInventory.CurrentTotalWeight + " / " + _combatInventory.WeightLimit + "Kg";
|
|
}
|
|
|
|
CurrentWeight.color = _combatInventory.IsOverWeight ? Color.red : Color.white;
|
|
}
|
|
|
|
public void ChangedData(ItemSlot changedItemSlot, bool added)
|
|
{
|
|
if (added)
|
|
{
|
|
AddItem(changedItemSlot);
|
|
}
|
|
else
|
|
{
|
|
RemoveItem(changedItemSlot);
|
|
}
|
|
CalculateWeight();
|
|
}
|
|
|
|
private void AddItem(ItemSlot addItemSlot)
|
|
{
|
|
var existingItemSlotUi = _itemSlotUiList.Find(i => i.ItemSlot.Idx == addItemSlot.Idx);
|
|
if (existingItemSlotUi != null)
|
|
{
|
|
existingItemSlotUi.UpdateData(addItemSlot);
|
|
}
|
|
else
|
|
{
|
|
var newItemSlot = Instantiate(ItemSlotUiPrefab, InstantiateLocation).GetComponent<ItemSlotUi>();
|
|
newItemSlot.InitializeData(addItemSlot);
|
|
_itemSlotUiList.Add(newItemSlot);
|
|
}
|
|
}
|
|
|
|
private void RemoveItem(ItemSlot removeItemSlot)
|
|
{
|
|
var existingItemSlotUi = _itemSlotUiList.Find(i => i.ItemSlot.Idx == removeItemSlot.Idx);
|
|
if (existingItemSlotUi != null)
|
|
{
|
|
existingItemSlotUi.UpdateData(removeItemSlot);
|
|
if (existingItemSlotUi.ItemSlot.Count <= 0)
|
|
{
|
|
_itemSlotUiList.Remove(existingItemSlotUi);
|
|
Destroy(existingItemSlotUi.gameObject);
|
|
}
|
|
}
|
|
}
|
|
|
|
public void SelectAll()
|
|
{
|
|
foreach (var element in _itemSlotUiList)
|
|
{
|
|
element.ToggleOn();
|
|
}
|
|
}
|
|
|
|
public void DeselectAll()
|
|
{
|
|
foreach (var element in _itemSlotUiList)
|
|
{
|
|
element.ToggleOff();
|
|
}
|
|
}
|
|
|
|
public void DiscardButton()
|
|
{
|
|
_selectedList.Clear();
|
|
foreach (var element in _itemSlotUiList)
|
|
{
|
|
if (!element.ToggleIsOn) continue;
|
|
|
|
_selectedList.Add(element);
|
|
}
|
|
|
|
if (_selectedList.Count == 1)
|
|
{
|
|
DiscardPopupUi.DiscardMessage(_selectedList[0]);
|
|
}
|
|
else if (_selectedList.Count > 1)
|
|
{
|
|
DiscardPopupUi.DiscardAllMessage(_selectedList);
|
|
}
|
|
}
|
|
|
|
public void SortButton()
|
|
{
|
|
if (SortingDropdown.value == 0) return;
|
|
|
|
_combatInventory.SortItem((InventorySortingType)SortingDropdown.value);
|
|
SortItemSlotUi((InventorySortingType)SortingDropdown.value);
|
|
|
|
SortingDropdown.value = 0;
|
|
}
|
|
|
|
private void SortItemSlotUi(InventorySortingType sortingType)
|
|
{
|
|
switch (sortingType)
|
|
{
|
|
case InventorySortingType.None:
|
|
return;
|
|
case InventorySortingType.Recent:
|
|
_itemSlotUiList.Sort((x, y) => y.ItemSlot.AcquisitionTime.CompareTo(x.ItemSlot.AcquisitionTime));
|
|
break;
|
|
case InventorySortingType.Name:
|
|
_itemSlotUiList.Sort((x, y) =>
|
|
string.Compare(ItemManager.Instance.GetItemDataByIdx(x.ItemSlot.Idx).Name,
|
|
ItemManager.Instance.GetItemDataByIdx(y.ItemSlot.Idx).Name, StringComparison.Ordinal));
|
|
break;
|
|
case InventorySortingType.Category:
|
|
_itemSlotUiList.Sort((x, y) =>
|
|
ItemManager.Instance.GetItemDataByIdx(x.ItemSlot.Idx).Category.CompareTo(ItemManager.Instance.GetItemDataByIdx(y.ItemSlot.Idx).Category));
|
|
break;
|
|
case InventorySortingType.Count:
|
|
_itemSlotUiList.Sort((x, y) => y.ItemSlot.Count.CompareTo(x.ItemSlot.Count));
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
|
|
for (var i = 0; i < _itemSlotUiList.Count; i++)
|
|
{
|
|
_itemSlotUiList[i].transform.SetSiblingIndex(i);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
} |