Files
XRLib/Assets/Scripts/UVC/UIToolkit/Property/Items/UTKRadioPropertyItem.cs
2026-02-10 20:48:49 +09:00

89 lines
3.0 KiB
C#

#nullable enable
using System;
using System.Collections.Generic;
using System.Linq;
namespace UVC.UIToolkit
{
/// <summary>
/// 라디오 그룹 속성 데이터 클래스입니다.
/// UI는 UTKRadioPropertyItemView에서 담당합니다.
/// </summary>
public class UTKRadioPropertyItem : UTKPropertyItemBase<int>
{
#region Fields
private List<string> _choices;
#endregion
#region Properties
/// <summary>속성 타입</summary>
public override UTKPropertyType PropertyType => UTKPropertyType.RadioGroup;
/// <summary>선택 가능한 항목 목록</summary>
public List<string> Choices
{
get => _choices;
set => _choices = value ?? new List<string>();
}
/// <summary>현재 선택된 항목의 텍스트</summary>
public string? SelectedText
{
get
{
if (Value >= 0 && Value < _choices.Count)
{
return _choices[Value];
}
return null;
}
}
#endregion
#region Constructor
/// <summary>
/// 라디오 그룹 속성을 생성합니다.
/// </summary>
/// <param name="id">고유 ID</param>
/// <param name="name">표시 이름</param>
/// <param name="choices">선택 항목 목록</param>
/// <param name="selectedIndex">초기 선택 인덱스</param>
/// <param name="isReadOnly">읽기 전용 여부</param>
/// <param name="showLabel">라벨 표시 여부</param>
public UTKRadioPropertyItem(string id, string name, List<string> choices, int selectedIndex = 0, bool isReadOnly = false, bool showLabel = true)
: base(id, name, Math.Max(0, Math.Min(selectedIndex, (choices?.Count ?? 1) - 1)))
{
_choices = choices ?? new List<string>();
_isReadOnly = isReadOnly;
_showLabel = showLabel;
}
/// <summary>
/// 라디오 그룹 속성을 생성합니다.
/// </summary>
/// <param name="id">고유 ID</param>
/// <param name="name">표시 이름</param>
/// <param name="choices">선택 항목 목록</param>
/// <param name="selectedIndex">초기 선택 인덱스</param>
/// <param name="isReadOnly">읽기 전용 여부</param>
/// <param name="showLabel">라벨 표시 여부</param>
public UTKRadioPropertyItem(string id, string name, IEnumerable<string> choices, int selectedIndex = 0, bool isReadOnly = false, bool showLabel = true)
: this(id, name, choices?.ToList() ?? new List<string>(), selectedIndex, isReadOnly, showLabel)
{
}
#endregion
#region Public Methods
/// <summary>텍스트로 선택</summary>
public void SelectByText(string text)
{
int index = _choices.IndexOf(text);
if (index >= 0)
{
Value = index;
}
}
#endregion
}
}