|
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
using TMPro;
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
|
|
public class EmailUIController : MonoBehaviour
|
|
|
|
{
|
|
|
|
public TextMeshProUGUI senderInitial;
|
|
|
|
public Image senderBg;
|
|
|
|
public TextMeshProUGUI senderNameText;
|
|
|
|
public TextMeshProUGUI subjectText;
|
|
|
|
public TextMeshProUGUI previewText;
|
|
|
|
public TextMeshProUGUI timeOrDateText;
|
|
|
|
|
|
|
|
public Sprite[] backgroundSprites;
|
|
|
|
public EmailData data;
|
|
|
|
|
|
|
|
// Cache for consistency
|
|
|
|
[SerializeField, HideInInspector]
|
|
|
|
public string cachedInitial;
|
|
|
|
[SerializeField, HideInInspector]
|
|
|
|
public Sprite cachedSprite;
|
|
|
|
|
|
|
|
public void Setup(EmailData emailData)
|
|
|
|
{
|
|
|
|
data = emailData;
|
|
|
|
|
|
|
|
senderNameText.text = data.senderName;
|
|
|
|
subjectText.text = data.subject;
|
|
|
|
previewText.text = GeneratePreview(data.fullBodyText);
|
|
|
|
timeOrDateText.text = data.timeOrDate;
|
|
|
|
|
|
|
|
cachedInitial = data.senderName[0].ToString().ToUpper();
|
|
|
|
cachedSprite = backgroundSprites[Random.Range(0, backgroundSprites.Length)];
|
|
|
|
|
|
|
|
senderInitial.text = cachedInitial;
|
|
|
|
senderBg.sprite = cachedSprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
string GeneratePreview(string body)
|
|
|
|
{
|
|
|
|
int max = 60;
|
|
|
|
string clean = body.Replace("\n", " ").Trim();
|
|
|
|
return clean.Length <= max ? clean : clean.Substring(0, max) + "...";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClick()
|
|
|
|
{
|
|
|
|
GameObject panel = Instantiate(Resources.Load<GameObject>("EmailOpenPanel"), transform.root);
|
|
|
|
WorldTimelineManager.Instance.OpenedEmailPanel = panel;
|
|
|
|
EmailOpenPanel controller = panel.GetComponent<EmailOpenPanel>();
|
|
|
|
controller.Setup(data, cachedInitial, cachedSprite);
|
|
|
|
|
|
|
|
UserActionLogger.Instance?.Log($"Opened email from '{data.senderName}' with subject '{data.subject}'");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|