UTKAccodion 완료. UTKComponentList 수정 중

This commit is contained in:
logonkhi
2026-01-22 20:12:22 +09:00
parent e00953de52
commit 59d473c87b
59 changed files with 2482 additions and 498 deletions

View File

@@ -15,18 +15,132 @@ namespace UVC.UIToolkit
/// 탭 버튼들을 추가한 윈도우 형태의 컴포넌트입니다. 탭을 통해 카테고리별 필터링이 가능합니다.
/// </para>
///
/// <para><b>UXML에서 사용:</b></para>
/// <code>
/// <UVC.UIToolkit.Window.UTKComponentTabListWindow name="tab-list-window" />
/// </code>
/// <para><b>UXML 사용 예시:</b></para>
/// <code><![CDATA[
/// <!-- UXML 파일에서 UTKComponentTabListWindow 사용 -->
/// <ui:UXML xmlns:utk="UVC.UIToolkit">
/// <utk:UTKComponentTabListWindow name="tab-list-window" />
/// </ui:UXML>
/// ]]></code>
///
/// <para><b>코드에서 사용:</b></para>
/// <code>
/// var window = root.Q<UTKComponentTabListWindow>();
/// window.OnItemSelected += (items) => Debug.Log($"선택: {items[0].name}");
/// window.SetData(treeItems);
/// window.SelectTab(0); // 첫 번째 카테고리 탭 선택
/// </code>
/// <para><b>C# 사용 예시:</b></para>
/// <code><![CDATA[
/// // 1. 윈도우 참조 획득
/// var tabWindow = root.Q<UTKComponentTabListWindow>("tab-list-window");
///
/// // 2. 윈도우 제목 및 닫기 버튼 설정
/// tabWindow.Title = "에셋 라이브러리";
/// tabWindow.ShowCloseButton = true;
///
/// // 3. 데이터 구성 - 카테고리별로 자동 탭 생성됨
/// var data = new List<UTKComponentListItemDataBase>
/// {
/// // 첫 번째 카테고리 → "캐릭터" 탭 자동 생성
/// new UTKComponentListCategoryData
/// {
/// name = "캐릭터",
/// isExpanded = true,
/// children = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListItemData { name = "플레이어", ExternalKey = "player" },
/// new UTKComponentListItemData { name = "NPC", ExternalKey = "npc" }
/// }
/// },
/// // 두 번째 카테고리 → "오브젝트" 탭 자동 생성
/// new UTKComponentListCategoryData
/// {
/// name = "오브젝트",
/// isExpanded = true,
/// children = new List<UTKComponentListItemDataBase>
/// {
/// new UTKComponentListItemData { name = "상자", ExternalKey = "box" },
/// new UTKComponentListItemData { name = "나무", ExternalKey = "tree" }
/// }
/// }
/// };
/// tabWindow.SetData(data);
/// // → "All" 탭과 "캐릭터", "오브젝트" 탭이 자동 생성됨
///
/// // 4. 탭 선택 (프로그래밍 방식)
/// tabWindow.SelectTab(-1); // -1 = "All" 전체 탭
/// tabWindow.SelectTab(0); // 0 = 첫 번째 카테고리 ("캐릭터")
/// tabWindow.SelectTab(1); // 1 = 두 번째 카테고리 ("오브젝트")
///
/// // 5. 선택 이벤트 구독
/// tabWindow.OnItemSelected = (selectedItems) =>
/// {
/// foreach (var item in selectedItems)
/// {
/// Debug.Log($"선택됨: {item.name}");
/// }
/// };
///
/// // 6. 선택 해제 이벤트
/// tabWindow.OnItemDeselected = (deselectedItems) =>
/// {
/// foreach (var item in deselectedItems)
/// {
/// Debug.Log($"선택 해제: {item.name}");
/// }
/// };
///
/// // 7. 가시성 변경 이벤트 (눈 아이콘)
/// tabWindow.OnItemVisibilityChanged += (item, isVisible) =>
/// {
/// var gameObject = FindGameObjectByKey(item.ExternalKey);
/// if (gameObject != null)
/// {
/// gameObject.SetActive(isVisible);
/// }
/// };
///
/// // 8. 삭제 이벤트 (Delete/Backspace 키)
/// tabWindow.EnabledDeleteItem = true;
/// tabWindow.OnItemDeleted = (item) =>
/// {
/// Debug.Log($"삭제 요청: {item.name}");
/// tabWindow.DeleteItem(item); // 탭 목록도 자동 갱신됨
/// };
///
/// // 9. 더블클릭 이벤트
/// tabWindow.OnItemDoubleClicked = (item) =>
/// {
/// FocusCameraOn(item.ExternalKey);
/// };
///
/// // 10. 윈도우 닫힘 이벤트
/// tabWindow.OnClosed += () =>
/// {
/// Debug.Log("윈도우가 닫혔습니다.");
/// };
///
/// // 11. 프로그래밍 방식 선택
/// tabWindow.SelectItem("플레이어", notify: true);
/// tabWindow.DeselectItem("플레이어", notify: false);
/// tabWindow.ClearSelection();
///
/// // 12. 아이템 추가/삭제 (탭 자동 갱신)
/// var newCategory = new UTKComponentListCategoryData { name = "이펙트" };
/// tabWindow.AddItem(newCategory); // "이펙트" 탭 자동 생성
///
/// var newItem = new UTKComponentListItemData { name = "폭발" };
/// tabWindow.AddItem(newCategory, newItem); // 카테고리에 아이템 추가
///
/// tabWindow.DeleteItem(newItem); // 아이템 삭제
///
/// // 13. 윈도우 표시
/// tabWindow.Show();
///
/// // 14. 리소스 해제 (OnDestroy에서 호출)
/// tabWindow.Dispose();
/// ]]></code>
///
/// <para><b>탭 동작 설명:</b></para>
/// <list type="bullet">
/// <item>"All" 탭: 모든 카테고리와 아이템을 표시합니다.</item>
/// <item>카테고리 탭: 해당 카테고리의 자식 아이템만 표시합니다 (부모 카테고리 없이).</item>
/// <item>탭별 검색어가 저장되어, 탭 전환 시 해당 탭의 검색어가 복원됩니다.</item>
/// </list>
/// </summary>
[UxmlElement]
public partial class UTKComponentTabListWindow : VisualElement, IDisposable
@@ -39,6 +153,9 @@ namespace UVC.UIToolkit
/// <summary>메인 UXML 파일 경로 (Resources 폴더 기준)</summary>
private const string UXML_PATH = "UIToolkit/Window/UTKComponentTabListWindow";
/// <summary>USS 파일 경로 (Resources 폴더 기준)</summary>
private const string USS_PATH = "UIToolkit/Window/UTKComponentListWindowUss";
/// <summary>"전체" 탭을 나타내는 인덱스</summary>
private const int ALL_TAB_INDEX = -1;
#endregion
@@ -50,8 +167,11 @@ namespace UVC.UIToolkit
/// <summary>탭 버튼 컨테이너</summary>
private VisualElement? _tabContainer;
/// <summary>트리 리스트 닫기 버튼</summary>
private Button? _closeButton;
/// <summary>트리 리스트 닫기 버튼 (UTKButton)</summary>
private UTKButton? _closeButton;
/// <summary>윈도우 제목 라벨</summary>
private Label? _titleLabel;
#endregion
#region (Tab Data)
@@ -79,6 +199,20 @@ namespace UVC.UIToolkit
get => _componentList?.EnabledDeleteItem ?? false;
set { if (_componentList != null) _componentList.EnabledDeleteItem = value; }
}
/// <summary>윈도우 제목을 가져오거나 설정합니다.</summary>
public string Title
{
get => _titleLabel?.text ?? string.Empty;
set { if (_titleLabel != null) _titleLabel.text = value; }
}
/// <summary>닫기 버튼 표시 여부를 설정합니다.</summary>
public bool ShowCloseButton
{
get => _closeButton?.style.display == DisplayStyle.Flex;
set { if (_closeButton != null) _closeButton.style.display = value ? DisplayStyle.Flex : DisplayStyle.None; }
}
#endregion
#region (Public Events)
@@ -167,20 +301,38 @@ namespace UVC.UIToolkit
return;
}
// 3. 탭 관련 요소 찾기
// 3. 테마 적용 및 변경 구독
UTKThemeManager.Instance.ApplyThemeToElement(this);
SubscribeToThemeChanges();
// USS 로드 (테마 변수 스타일시트 이후에 로드되어야 변수가 해석됨)
var uss = Resources.Load<StyleSheet>(USS_PATH);
if (uss != null)
{
styleSheets.Add(uss);
}
// 4. 탭 관련 요소 찾기
_tabContainer = this.Q<VisualElement>("tab-container");
// 4. 닫기 버튼 찾기 및 이벤트 연결
_closeButton = this.Q<Button>("close-btn");
// 5. 헤더 요소 참조
_titleLabel = this.Q<Label>("title");
_closeButton = this.Q<UTKButton>("close-btn");
// 6. 닫기 버튼 설정 및 이벤트 연결
if (_closeButton != null)
{
_closeButton.clicked += () =>
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
};
_closeButton.SetMaterialIcon(UTKMaterialIcons.Close, 16);
_closeButton.OnClicked += OnCloseButtonClicked;
}
}
/// <summary>닫기 버튼 클릭 이벤트 핸들러</summary>
private void OnCloseButtonClicked()
{
this.style.display = DisplayStyle.None;
OnClosed?.Invoke();
}
#endregion
#region (Public Methods)
@@ -507,6 +659,24 @@ namespace UVC.UIToolkit
}
#endregion
#region (Theme)
private void SubscribeToThemeChanges()
{
UTKThemeManager.Instance.OnThemeChanged += OnThemeChanged;
RegisterCallback<DetachFromPanelEvent>(_ =>
{
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
});
}
private void OnThemeChanged(UTKTheme theme)
{
UTKThemeManager.Instance.ApplyThemeToElement(this);
}
#endregion
#region IDisposable
/// <summary>
/// 리소스를 해제하고 이벤트 핸들러를 정리합니다.
@@ -516,6 +686,9 @@ namespace UVC.UIToolkit
if (_disposed) return;
_disposed = true;
// 테마 변경 이벤트 해제
UTKThemeManager.Instance.OnThemeChanged -= OnThemeChanged;
// 내부 UTKComponentList 정리
_componentList?.Dispose();
_componentList = null;
@@ -524,6 +697,13 @@ namespace UVC.UIToolkit
_tabButtons.Clear();
_tabContainer = null;
// 닫기 버튼 이벤트 해제 및 정리
if (_closeButton != null)
{
_closeButton.OnClicked -= OnCloseButtonClicked;
_closeButton.Dispose();
}
// 외부 이벤트 구독자 정리
OnClosed = null;
@@ -533,6 +713,7 @@ namespace UVC.UIToolkit
// UI 참조 정리
_closeButton = null;
_titleLabel = null;
}
#endregion
}