개발 중

This commit is contained in:
logonkhi
2025-10-30 18:36:26 +09:00
parent e245ee9f96
commit 09a620ff71
35 changed files with 430 additions and 386 deletions

View File

@@ -17,7 +17,7 @@ namespace UVC.UI.List.Tree
///
/// 이 클래스는 InfiniteScrollData를 상속하여 UI 스크롤 리스트와 연동됩니다.
/// </summary>
public class TreeListItemData
public class TreeListItemData: IDisposable
{
#region (Events)
@@ -30,7 +30,7 @@ namespace UVC.UI.List.Tree
/// 사용 예:
/// treeItem.OnDataChanged += (data) => Debug.Log("데이터 변경됨!");
/// </summary>
public Action<TreeListItemData>? OnDataChanged;
public Action<ChangedType, TreeListItemData, int>? OnDataChanged;
/// <summary>
/// 선택 상태가 변경되었을 때 발생하는 이벤트입니다.
@@ -136,7 +136,7 @@ namespace UVC.UI.List.Tree
if (_name != value)
{
_name = value;
NotifyDataChanged(); // UI에 변경을 알림
NotifyDataChanged(ChangedType.Name); // UI에 변경을 알림
}
}
}
@@ -158,7 +158,7 @@ namespace UVC.UI.List.Tree
if (_option != value)
{
_option = value;
NotifyDataChanged();
NotifyDataChanged(ChangedType.Option);
}
}
}
@@ -184,7 +184,7 @@ namespace UVC.UI.List.Tree
if (_isExpanded != value)
{
_isExpanded = value;
NotifyDataChanged(); // 트리 구조 UI 갱신
NotifyDataChanged(ChangedType.Expanded); // 트리 구조 UI 갱신
}
}
}
@@ -261,7 +261,7 @@ namespace UVC.UI.List.Tree
set
{
_children = value ?? new List<TreeListItemData>();
NotifyDataChanged();
NotifyDataChanged(ChangedType.ResetChildren);
}
}
@@ -344,11 +344,18 @@ namespace UVC.UI.List.Tree
{
child._parent = this;
_children.Add(child);
NotifyDataChanged(); // UI에 트리 구조 변경 알림
NotifyDataChanged(ChangedType.AddChild, child); // UI에 트리 구조 변경 알림
}
public void AddChildAt(TreeListItemData child, int index)
{
child._parent = this;
_children.Insert(index, child);
NotifyDataChanged(ChangedType.AddAtChild, child, index); // UI에 트리 구조 변경 알림
}
/// <summary>
/// 이 아이템에서 지정된 자식 아이템을 제거합니다.
/// 이 아이템에서 지정된 자식 아이템을 자식 목록에서 제거하지만 아이템 자체는 삭제하지 않습니다.
///
/// 동작:
/// 1. 자식을 _children 리스트에서 제거
@@ -371,8 +378,19 @@ namespace UVC.UI.List.Tree
public void RemoveChild(TreeListItemData child)
{
child._parent = null;
int index = _children.IndexOf(child);
_children.Remove(child);
NotifyDataChanged(); // UI에 트리 구조 변경 알림
NotifyDataChanged(ChangedType.RemoveChild, child, index); // UI에 트리 구조 변경 알림
}
/// <summary>
/// 이 아이템에서 지정된 자식 아이템을 자식 목록에서 제거하고 아이템 자체도 삭제합니다.
/// </summary>
/// <param name="child"></param>
public void DeleteChild(TreeListItemData child)
{
RemoveChild(child);
child.Dispose();
}
/// <summary>
@@ -401,9 +419,10 @@ namespace UVC.UI.List.Tree
foreach (var child in _children)
{
child._parent = null;
child.Dispose();
}
_children.Clear();
NotifyDataChanged(); // UI에 트리 구조 변경 알림
NotifyDataChanged(ChangedType.ResetChildren); // UI에 트리 구조 변경 알림
}
#endregion
@@ -424,11 +443,11 @@ namespace UVC.UI.List.Tree
/// 왜 protected인가?
/// 이 클래스를 상속받은 자식 클래스에서도 호출할 수 있도록 하기 위함입니다.
/// </summary>
internal void NotifyDataChanged()
internal void NotifyDataChanged(ChangedType changedType, TreeListItemData? target = null, int index = -1)
{
// OnDataChanged가 등록되어 있으면 실행
// ?. 연산자: null이면 실행하지 않음 (null reference exception 방지)
OnDataChanged?.Invoke(this);
OnDataChanged?.Invoke(changedType, (target == null ? this : target), index);
}
#endregion
@@ -555,6 +574,32 @@ namespace UVC.UI.List.Tree
return false;
}
public void Dispose()
{
if(OnDataChanged != null) OnDataChanged = null;
if(OnSelectionChanged != null) OnSelectionChanged = null;
if(OnClickAction != null) OnClickAction = null;
if(Children != null)
{
//foreach(var child in Children)
//{
// child.Dispose();
//}
Children.Clear();
}
}
#endregion
}
public enum ChangedType
{
Name,
Option,
Expanded,
ResetChildren,
AddChild,
AddAtChild,
RemoveChild
}
}