DCS/ruiyiweiUX/Assets/Scripts/UI/UserDeleteItem.cs

77 lines
2.1 KiB
C#
Raw Normal View History

2026-06-09 13:59:11 +08:00
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
/// <summary>
/// 用户删除列表项
/// </summary>
public class UserDeleteItem : ScrollableListItem
{
[Header("用户信息显示")]
public TextMeshProUGUI UsernameText;
public TextMeshProUGUI RoleText;
public TextMeshProUGUI StatusText;
public Button SelectButton;
private UserInfo _userInfo;
private DeleteUserPanel _deletePanel;
public void Initialize(UserInfo userInfo, DeleteUserPanel deletePanel)
{
_userInfo = userInfo;
_deletePanel = deletePanel;
// 获取UI组件
// if (UsernameText == null)
// UsernameText = transform.Find("UsernameText")?.GetComponent<TextMeshProUGUI>();
// if (RoleText == null)
// RoleText = transform.Find("RoleText")?.GetComponent<TextMeshProUGUI>();
// if (StatusText == null)
// StatusText = transform.Find("StatusText")?.GetComponent<TextMeshProUGUI>();
// if (SelectButton == null)
// SelectButton = GetComponent<Button>();
// 设置按钮事件
if (SelectButton != null)
{
SelectButton.onClick.RemoveAllListeners();
SelectButton.onClick.AddListener(OnSelectClicked);
}
UpdateDisplay();
}
private void UpdateDisplay()
{
if (_userInfo == null) return;
if (UsernameText != null)
{
UsernameText.text = _userInfo.Username;
}
if (RoleText != null)
{
RoleText.text = _userInfo.Role == UserRole.Admin ? "管理员" : "普通用户";
}
if (StatusText != null)
{
StatusText.text = _userInfo.IsActive ? "活跃" : "禁用";
StatusText.color = _userInfo.IsActive ? Color.green : Color.red;
}
}
private void OnSelectClicked()
{
_deletePanel?.OnUserSelected(_userInfo);
}
protected override void UpdateUI()
{
UpdateDisplay();
}
}