Files
XRLib/Assets/Scripts/UVC/UI/Toolbar/ToolbarModel.cs
2025-06-16 19:30:01 +09:00

81 lines
3.9 KiB
C#

using UnityEngine;
using UVC.UI.Commands;
namespace UVC.UI.Toolbar
{
/// <summary>
/// 툴바의 전체적인 컨테이너 및 관리 클래스입니다.
/// IToolbarItem 객체들을 동적으로 추가하고 관리합니다.
/// </summary>
public class ToolbarModel
{
public System.Collections.Generic.List<IToolbarItem> Items { get; private set; }
private System.Collections.Generic.Dictionary<string, ToolbarRadioButtonGroup> _radioGroups;
public ToolbarModel()
{
Items = new System.Collections.Generic.List<IToolbarItem>();
_radioGroups = new System.Collections.Generic.Dictionary<string, ToolbarRadioButtonGroup>();
}
public void AddItem(IToolbarItem item)
{
Items.Add(item);
if (item is ToolbarRadioButton radioButton)
{
if (!_radioGroups.TryGetValue(radioButton.GroupName, out var group))
{
group = new ToolbarRadioButtonGroup();
_radioGroups.Add(radioButton.GroupName, group);
}
group.RegisterButton(radioButton);
}
// UI 갱신 로직 호출
}
public ToolbarStandardButton AddStandardButton(string text, string iconSpritePath = null, ICommand command = null, string tooltipKey = null)
{
var button = new ToolbarStandardButton { Text = text, IconSpritePath = iconSpritePath, ClickCommand = command, TooltipKey = tooltipKey };
AddItem(button);
return button;
}
public ToolbarToggleButton AddToggleButton(string text, bool initialState = false, string onIconSpritePath = null, string offIconSpritePath = null, System.Action<bool> onToggle = null, ICommand command = null, string tooltipKey = null)
{
var button = new ToolbarToggleButton { Text = text, IsSelected = initialState, IconSpritePath = onIconSpritePath, OffIconSpritePath = offIconSpritePath, OnToggle = onToggle, ClickCommand = command, TooltipKey = tooltipKey };
AddItem(button);
return button;
}
public ToolbarRadioButton AddRadioButton(string groupName, string text, bool initialState = false, string iconSpritePath = null, string offIconSpritePath = null, System.Action<bool> onToggle = null, ICommand command = null, string tooltipKey = null)
{
var button = new ToolbarRadioButton(groupName) { Text = text, IsSelected = initialState, IconSpritePath = iconSpritePath, OffIconSpritePath = offIconSpritePath, OnToggle = onToggle, ClickCommand = command, TooltipKey = tooltipKey };
// AddItem 내에서 그룹 처리가 되므로, 여기서는 IsSelected 초기값만 주의 (그룹 내 하나만 true여야 함)
AddItem(button);
// 그룹의 초기 선택 상태를 설정하는 로직이 추가로 필요할 수 있습니다.
// 예를 들어, 첫 번째로 추가된 라디오 버튼을 기본 선택으로 하거나, 명시적으로 설정.
if (initialState && _radioGroups.TryGetValue(groupName, out var group))
{
group.SetSelected(button);
}
return button;
}
public ToolbarExpandableButton AddExpandableButton(string text, string iconSpritePath = null, ICommand command = null, string tooltipKey = null)
{
var button = new ToolbarExpandableButton { Text = text, IconSpritePath = iconSpritePath, ClickCommand = command, TooltipKey = tooltipKey };
AddItem(button);
return button;
}
public void AddSeparator()
{
AddItem(new ToolbarSeparator());
}
// 실제 UI 렌더링 및 상호작용 로직은 이 클래스 또는 별도의 UI View 클래스에서 처리됩니다.
// (예: Unity UI GameObject 생성, 이벤트 연결 등)
}
}