backup
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
using Simulator.Data;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Simulator.UI
|
||||
{
|
||||
/// <summary>
|
||||
/// 시뮬레이션 목록의 개별 행 View
|
||||
/// Row Prefab에 붙여서 사용합니다.
|
||||
/// </summary>
|
||||
public class SimulationListRowView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text nameText;
|
||||
[SerializeField] private TMP_Text userText;
|
||||
[SerializeField] private TMP_Text dateText;
|
||||
|
||||
[SerializeField] private Button rowButton;
|
||||
[SerializeField] private Image backgroundImage;
|
||||
|
||||
[Header("선택 색상")]
|
||||
[SerializeField] private Color normalColor = new Color(1f, 1f, 1f, 0f);
|
||||
[SerializeField] private Color selectedColor = new Color(0.9f, 0.9f, 0.9f, 1f);
|
||||
|
||||
public SimulationRowData Data { get; private set; }
|
||||
|
||||
public event Action<SimulationListRowView> OnClicked;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (rowButton != null)
|
||||
{
|
||||
rowButton.onClick.AddListener(() => OnClicked?.Invoke(this));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 행에 데이터를 바인딩합니다.
|
||||
/// </summary>
|
||||
public void SetData(SimulationRowData data)
|
||||
{
|
||||
Data = data;
|
||||
|
||||
if (nameText != null)
|
||||
nameText.text = data.name ?? "";
|
||||
|
||||
if (userText != null)
|
||||
userText.text = data.User?.userid ?? "";
|
||||
|
||||
if (dateText != null)
|
||||
dateText.text = FormatDate(data.createdAt);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 선택 상태를 설정합니다.
|
||||
/// </summary>
|
||||
public void SetSelected(bool selected)
|
||||
{
|
||||
if (backgroundImage != null)
|
||||
backgroundImage.color = selected ? selectedColor : normalColor;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 서버에서 받은 날짜 문자열을 표시용으로 포맷합니다.
|
||||
/// "2026-02-23 07:53:14.669396+00" → "2026-02-23 16:53:14" (로컬 시간)
|
||||
/// </summary>
|
||||
private string FormatDate(string dateString)
|
||||
{
|
||||
if (string.IsNullOrEmpty(dateString)) return "";
|
||||
|
||||
if (DateTimeOffset.TryParse(dateString, CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out var dto))
|
||||
{
|
||||
return dto.ToLocalTime().ToString("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
|
||||
return dateString;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (rowButton != null)
|
||||
rowButton.onClick.RemoveAllListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user