99 lines
4.2 KiB
C#
99 lines
4.2 KiB
C#
using System;
|
|||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.UI;
|
||
|
|
using TMPro;
|
||
|
|
|
||
|
|
// ПОЧТА: список писем (новые подсвечены), чтение письма, подарки во вложениях,
|
||
|
|
// "Забрать всё" и "Удалить прочитанные". Письма приходят сами: приветствие, новый уровень и т.д.
|
||
|
|
public class MailPanel : BasePanel
|
||
|
|
{
|
||
|
|
int openedId; // 0 -- показываем список
|
||
|
|
|
||
|
|
protected override void OnEnable()
|
||
|
|
{
|
||
|
|
base.OnEnable();
|
||
|
|
openedId = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
protected override void Build(RectTransform root)
|
||
|
|
{
|
||
|
|
var mail = openedId != 0 ? GP.GetMail(openedId) : null;
|
||
|
|
if (mail == null) { openedId = 0; BuildList(root); }
|
||
|
|
else BuildLetter(root, mail);
|
||
|
|
}
|
||
|
|
|
||
|
|
void BuildList(RectTransform root)
|
||
|
|
{
|
||
|
|
var col = UIKit.Card(root, new Color(0, 0, 0, 0), 0, 12);
|
||
|
|
UIKit.Stretch(col);
|
||
|
|
|
||
|
|
var top = UIKit.Row(col, 80, 12);
|
||
|
|
UIKit.Size(UIKit.Button(top, "Забрать всё", UIKit.Theme.Green, () => GP.ClaimAllMail()), -1, 80, 1);
|
||
|
|
UIKit.Size(UIKit.Button(top, "Удалить прочитанные", UIKit.Theme.Gray, () => GP.DeleteReadMail()), -1, 80, 1);
|
||
|
|
|
||
|
|
var holder = UIKit.Make("ListHolder", col);
|
||
|
|
UIKit.Size(holder, -1, -1).flexibleHeight = 1;
|
||
|
|
var list = ScrollList(holder, 10);
|
||
|
|
|
||
|
|
if (GP.Data.mail.Count == 0)
|
||
|
|
{
|
||
|
|
UIKit.Text(list, "Писем нет", 32, UIKit.Theme.TextDim, TextAlignmentOptions.Center, 150);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
foreach (var m in GP.Data.mail)
|
||
|
|
{
|
||
|
|
var mm = m;
|
||
|
|
bool unread = !m.read;
|
||
|
|
bool gift = m.HasRewards && !m.claimed;
|
||
|
|
var card = UIKit.Card(list, unread ? new Color(0.24f, 0.24f, 0.3f) : UIKit.Theme.CardDark, 16, 4);
|
||
|
|
var btn = card.gameObject.AddComponent<Button>();
|
||
|
|
btn.onClick.AddListener(() => { openedId = mm.id; GP.ReadMail(mm); RequestRebuild(); });
|
||
|
|
|
||
|
|
var row = UIKit.Row(card, 46, 10);
|
||
|
|
var title = UIKit.Text(row, m.title, 30, unread ? UIKit.Theme.Gold : UIKit.Theme.Text);
|
||
|
|
title.fontStyle = unread ? FontStyles.Bold : FontStyles.Normal;
|
||
|
|
UIKit.Size(title, -1, -1, 1);
|
||
|
|
if (gift) UIKit.Size(UIKit.Text(row, "ПОДАРОК", 22, UIKit.Theme.Green, TextAlignmentOptions.Right), 150);
|
||
|
|
|
||
|
|
UIKit.Text(card, new DateTime(m.sentTicks).ToString("dd.MM.yyyy HH:mm") + (unread ? " • новое" : ""),
|
||
|
|
22, UIKit.Theme.TextDim);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void BuildLetter(RectTransform root, MailItem m)
|
||
|
|
{
|
||
|
|
var list = ScrollList(root);
|
||
|
|
UIKit.Button(list, "< Назад к письмам", UIKit.Theme.Gray, () => { openedId = 0; RequestRebuild(); }, -1, 76);
|
||
|
|
|
||
|
|
var card = UIKit.Card(list, UIKit.Theme.Card, 24, 14);
|
||
|
|
var title = UIKit.Text(card, m.title, 36, UIKit.Theme.Gold);
|
||
|
|
title.fontStyle = FontStyles.Bold;
|
||
|
|
UIKit.Text(card, new DateTime(m.sentTicks).ToString("dd.MM.yyyy HH:mm"), 22, UIKit.Theme.TextDim);
|
||
|
|
UIKit.Text(card, m.body, 30);
|
||
|
|
|
||
|
|
if (m.HasRewards)
|
||
|
|
{
|
||
|
|
var gift = UIKit.Card(list, m.claimed ? UIKit.Theme.CardDark : UIKit.Theme.CardDone);
|
||
|
|
ProfilePanel.Header(gift, "Вложения");
|
||
|
|
foreach (var r in m.rewards)
|
||
|
|
{
|
||
|
|
var row = UIKit.Row(gift, 50, 12);
|
||
|
|
UIKit.Icon(row, GameData.ResColor(r.type), "", 36);
|
||
|
|
var n = UIKit.Text(row, GameData.ResName(r.type), 28);
|
||
|
|
UIKit.Size(n, -1, -1, 1);
|
||
|
|
UIKit.Size(UIKit.Text(row, r.amount.ToString("N0"), 28, UIKit.Theme.Gold, TextAlignmentOptions.Right), 200);
|
||
|
|
}
|
||
|
|
var b = UIKit.Button(gift, m.claimed ? "Получено" : "Забрать", m.claimed ? UIKit.Theme.Gray : UIKit.Theme.Green,
|
||
|
|
() => GP.ClaimMail(m), -1, 90);
|
||
|
|
b.interactable = !m.claimed;
|
||
|
|
}
|
||
|
|
|
||
|
|
UIKit.Button(list, "Удалить письмо", UIKit.Theme.Red, () =>
|
||
|
|
{
|
||
|
|
if (m.HasRewards && !m.claimed) { UIKit.Toast("Сначала заберите подарок"); return; }
|
||
|
|
GP.DeleteMail(m); openedId = 0; RequestRebuild();
|
||
|
|
}, -1, 80);
|
||
|
|
}
|
||
|
|
}
|