178 lines
7.3 KiB
C#
178 lines
7.3 KiB
C#
#nullable enable
|
|
using Cysharp.Threading.Tasks;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UVC.Factory;
|
|
using UVC.Factory.Cameras;
|
|
using UVC.Factory.Component;
|
|
using UVC.Locale;
|
|
using UVC.UI.Commands;
|
|
using UVC.UI.List.ComponentList;
|
|
using UVC.UI.Menu;
|
|
using UVC.UI.Modal;
|
|
using UVC.UI.Tab;
|
|
using UVC.UI.Window;
|
|
|
|
|
|
namespace Factory.Tab
|
|
{
|
|
public class TabContentComponentList : MonoBehaviour, ITabContent
|
|
{
|
|
|
|
[SerializeField]
|
|
private ComponentListWindow? window;
|
|
|
|
private string category = string.Empty;
|
|
|
|
protected void Awake()
|
|
{
|
|
if (window == null)
|
|
{
|
|
Debug.LogError("TabContentComponentList: TabController가 할당되지 않았습니다.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
if(window != null)
|
|
{
|
|
window.OnFindButtonClick += (ComponentListItemData data) =>
|
|
{
|
|
Debug.Log($"ComponentListWindow: OnFindButtonClicked: {data.Name}");
|
|
FactoryObject? obj = FactoryObjectManager.Instance.FindById(data.Id);
|
|
if(obj == null)
|
|
{
|
|
// 객체를 찾지 못한 경우 사용자에게 알림 메시지를 표시합니다.
|
|
Toast.Show(LocalizationManager.Instance.GetString($"{data.Name} 객체를 찾을 수 없습니다."), 2f);
|
|
return;
|
|
}
|
|
// 객체가 존재하고 활성화 상태일 때만 카메라를 이동시킵니다.
|
|
if (obj != null && obj.gameObject.activeSelf)
|
|
{
|
|
// FactoryCameraController를 사용하여 해당 객체의 위치로 카메라를 부드럽게 이동시킵니다.
|
|
FactoryObjectSelectionManager.Instance.Select(obj);
|
|
FactoryCameraController.Instance.FocusOnTarget(obj.transform.position, 10f);
|
|
}
|
|
};
|
|
|
|
window.OnVisibleChanged += (ComponentListItemData data, bool isVisible) =>
|
|
{
|
|
Debug.Log($"ComponentListWindow: OnVisibleChanged: {data.Name}, Visible: {isVisible}");
|
|
FactoryObject? obj = FactoryObjectManager.Instance.FindById(data.Id);
|
|
if (obj != null)
|
|
{
|
|
if(isVisible == false) FactoryObjectSelectionManager.Instance.Deselect(obj);
|
|
obj.gameObject.SetActive(isVisible);
|
|
}
|
|
};
|
|
|
|
window.OnRightClickItem += (ComponentListItemData data) =>
|
|
{
|
|
Debug.Log($"ComponentListWindow: OnRightClickItem: {data.Name}");
|
|
// 우클릭 메뉴 처리 로직 추가
|
|
// 컨텍스트 메뉴에 표시할 항목들을 정의합니다.
|
|
var menuItems = new List<ContextMenuItemData>
|
|
{
|
|
// "카테고리" 메뉴: 클릭 시 검색창에 "@Category "를 자동으로 입력해줍니다.
|
|
// 생성자: (itemId, displayName, command, commandParameter)
|
|
new ContextMenuItemData("Menu1", "카테고리", new ActionCommand(()=>{ window.ComponentList?.SetSearchText("@Category "); })),
|
|
new ContextMenuItemData(isSeparator: true), // 구분선 추가
|
|
new ContextMenuItemData("Menu2", "구역", new ActionCommand(()=>{ window.ComponentList?.SetSearchText("@Area "); })),
|
|
new ContextMenuItemData(isSeparator: true), // 구분선 추가
|
|
new ContextMenuItemData("Menu3", "층", new ActionCommand(()=>{ window.ComponentList?.SetSearchText("@Floor "); })),
|
|
};
|
|
|
|
// ContextMenuManager를 통해 마우스 위치에 메뉴를 표시합니다.
|
|
ContextMenuManager.Instance.ShowMenu(menuItems, Input.mousePosition);
|
|
};
|
|
|
|
window.OnRefreshButtonClick += () =>
|
|
{
|
|
Debug.Log("ComponentListWindow: OnRefreshButtonClick");
|
|
// 새로고침 로직 구현
|
|
var infos = FactoryObjectManager.Instance.GetFactoryObjectInfosByCategory();
|
|
SortedDictionary<string, List<ComponentListItemData>> sortedInfos = new SortedDictionary<string, List<ComponentListItemData>>();
|
|
foreach (var info in infos)
|
|
{
|
|
var itemList = info.Value.Select(factoryInfo => new ComponentListItemData
|
|
{
|
|
Id = factoryInfo.Id,
|
|
Name = factoryInfo.Name,
|
|
CategoryName = factoryInfo.Category,
|
|
Option = factoryInfo.Floor
|
|
}).ToList();
|
|
|
|
sortedInfos.Add(info.Key, itemList);
|
|
}
|
|
if(category != "ALL")
|
|
{
|
|
var filteredData = new SortedDictionary<string, List<ComponentListItemData>>();
|
|
if(sortedInfos.ContainsKey(category))
|
|
{
|
|
filteredData[category] = sortedInfos[category];
|
|
}
|
|
window.SetupData(filteredData);
|
|
return;
|
|
}
|
|
window.SetupData(sortedInfos);
|
|
};
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (window != null)
|
|
{
|
|
window.OnFindButtonClick = null;
|
|
window.OnVisibleChanged = null;
|
|
window.OnRightClickItem = null;
|
|
window.OnRefreshButtonClick = null;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 콘텐츠에 데이터를 전달합니다.
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void SetContentData(object? data)
|
|
{
|
|
if (data is SortedDictionary<string, List<ComponentListItemData>> objectsData)
|
|
{
|
|
category = "ALL";
|
|
window?.SetupData(objectsData);
|
|
}
|
|
else if (data is List<ComponentListItemData> list)
|
|
{
|
|
if (list.Count == 0) return;
|
|
var groupedData = new SortedDictionary<string, List<ComponentListItemData>>();
|
|
category = list.First().CategoryName;
|
|
groupedData[category] = list;
|
|
window?.SetupData(groupedData);
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 탭 전환 시 데이터가 있는 경우 전달 되는 데이터. SetContentData 이후 호출 됨
|
|
/// </summary>
|
|
/// <param name="data">전달할 데이터 객체</param>
|
|
public void UpdateContentData(object? data)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// 닫힐 때 실행되는 로직을 처리합니다.
|
|
/// </summary>
|
|
/// <returns>비동기 닫기 작업을 나타내는 <see cref="UniTask"/>입니다.</returns>
|
|
public UniTask OnCloseAsync()
|
|
{
|
|
Debug.Log("TabContentComponentList: OnClose called");
|
|
return UniTask.CompletedTask;
|
|
}
|
|
|
|
|
|
}
|
|
}
|