115 lines
No EOL
3.8 KiB
C#
115 lines
No EOL
3.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
using System.Text;
|
|
|
|
public class UI_MailWindow : UI_WindowBase
|
|
{
|
|
[Header("Mail Specific UI")]
|
|
[SerializeField] private TMP_Text titleText;
|
|
[SerializeField] private TMP_Text bodyText;
|
|
[SerializeField] private Button deleteButton;
|
|
[SerializeField] private Button claimButton;
|
|
[SerializeField] private TMP_Text claimButtonText;
|
|
|
|
private MailEntry currentMail;
|
|
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
|
|
if (deleteButton != null) deleteButton.onClick.AddListener(OnDeleteClicked);
|
|
if (claimButton != null) claimButton.onClick.AddListener(OnClaimClicked);
|
|
}
|
|
|
|
private string FormatCustomTags(string rawText)
|
|
{
|
|
if (string.IsNullOrEmpty(rawText)) return rawText;
|
|
StringBuilder sb = new StringBuilder(rawText);
|
|
sb.Replace("[y]", "<color=#FFFF00>");
|
|
sb.Replace("[b]", "<color=#0000FF>");
|
|
sb.Replace("[g]", "<color=#008000>");
|
|
sb.Replace("[r]", "<color=#FF0000>");
|
|
sb.Replace("[o]", "<color=#FFA500>");
|
|
sb.Replace("[/c]", "</color>");
|
|
return sb.ToString();
|
|
}
|
|
|
|
|
|
public void OpenMailDetails(MailEntry mail)
|
|
{
|
|
if (mail == null) return;
|
|
currentMail = mail;
|
|
|
|
// ИСПОЛЬЗУЕМ MANAGER_WindowsBase вместо UI_WindowBase
|
|
var mailSystem = MANAGER_WindowsBase.Instance.MailSystem;
|
|
|
|
mailSystem.MarkAsRead(mail.id);
|
|
|
|
if (mail.type == "once" && string.IsNullOrEmpty(mail.rewards_table_id))
|
|
mailSystem.DeleteMail(mail.id);
|
|
|
|
UpdateVisuals(mail);
|
|
|
|
base.OpenWindow();
|
|
}
|
|
|
|
private void UpdateVisuals(MailEntry mail)
|
|
{
|
|
var mailSystem = MANAGER_WindowsBase.Instance.MailSystem;
|
|
|
|
if (titleText != null) titleText.text = FormatCustomTags(mail.content.title);
|
|
|
|
// --- ИЗМЕНЕНИЕ ЗДЕСЬ ---
|
|
if (bodyText != null)
|
|
{
|
|
// Сначала подставляем награды, потом красим теги [y] и т.д.
|
|
string formattedBody = mailSystem.GetFormattedBody(mail);
|
|
bodyText.text = FormatCustomTags(formattedBody);
|
|
}
|
|
// -----------------------
|
|
|
|
deleteButton.gameObject.SetActive(mail.logic.is_deletable);
|
|
|
|
bool hasReward = !string.IsNullOrEmpty(mail.rewards_table_id);
|
|
bool isClaimed = mailSystem.IsRewardClaimed(mail.id);
|
|
|
|
// 1. Управляем видимостью кнопки
|
|
claimButton.gameObject.SetActive(hasReward);
|
|
|
|
// 2. ОБЯЗАТЕЛЬНО сбрасываем состояние interactable
|
|
// Если награда уже взята — кнопка выключена, если нет — включена
|
|
claimButton.interactable = !isClaimed;
|
|
|
|
// 3. Сбрасываем текст кнопки
|
|
if (claimButtonText != null)
|
|
{
|
|
// Если забрано — пишем "ЗАБРАНО", если нет — стандартный текст (например, "ЗАБРАТЬ")
|
|
claimButtonText.text = isClaimed ? "ЗАБРАНО" : "ЗАБРАТЬ";
|
|
}
|
|
}
|
|
|
|
private void OnDeleteClicked()
|
|
{
|
|
if (currentMail != null)
|
|
{
|
|
MANAGER_WindowsBase.Instance.MailSystem.DeleteMail(currentMail.id);
|
|
CloseWindow();
|
|
}
|
|
}
|
|
|
|
private void OnClaimClicked()
|
|
{
|
|
if (currentMail != null)
|
|
{
|
|
var mailSystem = MANAGER_WindowsBase.Instance.MailSystem;
|
|
mailSystem.ClaimReward(currentMail.id);
|
|
|
|
claimButton.interactable = false;
|
|
if (claimButtonText != null) claimButtonText.text = "ЗАБРАНО";
|
|
|
|
if (currentMail.type == "once")
|
|
mailSystem.DeleteMail(currentMail.id);
|
|
}
|
|
}
|
|
} |