yyl
2025-06-09 b9751b2f076ee050fe5b685e91ae4fc4469b1015
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
using UnityEngine;
public class MailInfoWin : UIBase
{
    [SerializeField] TextEx txtDate;
    [SerializeField] TextEx txtTitle;
    [SerializeField] Transform transNoAward;
    [SerializeField] RichText txtNoAwardInfo;
    [SerializeField] Transform transAward;
    [SerializeField] RichText txtAwardInfo;
    [SerializeField] ScrollerController scrAwardItem;
    [SerializeField] TextEx txtExpiryDate;
    [SerializeField] ButtonEx btnHave;
    [SerializeField] ButtonEx btnDelete;
    MailData nowMailData;
    bool isHasAward = false;
    MailManager model { get { return MailManager.Instance; } }
 
    protected override void InitComponent()
    {
        base.InitComponent();
        btnHave.SetListener(OnClickHaveButton);
        btnDelete.SetListener(OnClickDeleteButton);
    }
 
    protected override void OnPreOpen()
    {
        scrAwardItem.OnRefreshCell += OnRefreshLowRewardCell;
        model.OnUpdateMailListEvent += OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent;
    }
 
    protected override void OnOpen()
    {
        UpdateDataInfo();
        Display();
        CreateScrAward();
    }
 
    protected override void OnPreClose()
    {
        scrAwardItem.OnRefreshCell -= OnRefreshLowRewardCell;
        model.OnUpdateMailListEvent -= OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent;
    }
 
    private void OnClickHaveButton()
    {
        if (model.nowUuid == null || model.nowUuid == string.Empty)
        {
            Debug.Log("当前查看的邮件没有UUID");
            return;
        }
        model.ClaimMail(model.nowUuid);
    }
    private void OnClickDeleteButton()
    {
        if (model.nowUuid == null || model.nowUuid == string.Empty)
        {
            Debug.Log("当前查看的邮件没有UUID");
            return;
        }
        model.DeleteMail(model.nowUuid);
        UIManager.Instance.CloseWindow<MailInfoWin>();
        //邮件删除成功
        SysNotifyMgr.Instance.ShowTip("Mail01");
    }
 
    private void OnUpdateMailStateChangeEvent()
    {
        UpdateDataInfo();
        Display();
        CreateScrAward();
    }
 
    private void OnUpdateMailListEvent()
    {
        UpdateDataInfo();
        Display();
        CreateScrAward();
    }
 
    private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<MailInfoAwardItemCell>();
        _cell?.Display(cell.index, cell);
    }
 
    private void CreateScrAward()
    {
        scrAwardItem.Refresh();
        if (isHasAward)
        {
            for (int i = 0; i < nowMailData.Items.Count; i++)
            {
                CellInfo cellInfo = new CellInfo();
                cellInfo.infoInt1 = nowMailData.MailState;
                scrAwardItem.AddCell(ScrollerDataType.Header, i);
            }
        }
        scrAwardItem.Restart();
    }
 
    private void Display()
    {
        if (nowMailData == null)
            return;
        transNoAward.SetActive(!isHasAward);
        transAward.SetActive(isHasAward);
        txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime);
            
        if (nowMailData.IsTemplateMail())
        {
            string key = nowMailData.GetTemplateKey();
            if (MailConfig.HasKey(key))
            {
                MailConfig config = MailConfig.Get(key);
                var templateParams = nowMailData.GetTemplateParams();
                string content = string.Format(config.Content, templateParams.ToArray());
                txtTitle.text = config.Title;
                txtNoAwardInfo.text = content;
                txtAwardInfo.text = content;
            }
            else
            {
                txtTitle.text = nowMailData.Title;
                txtNoAwardInfo.text = nowMailData.Text;
                txtAwardInfo.text = nowMailData.Text;
            }
        }
        else
        {
            txtTitle.text = nowMailData.Title;
            txtNoAwardInfo.text = nowMailData.Text;
            txtAwardInfo.text = nowMailData.Text;
        }
 
        int expiryDays = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays);
        txtExpiryDate.text = expiryDays > 0 ? Language.Get("Mail07", expiryDays) : string.Empty;
 
    }
 
    private void UpdateDataInfo()
    {
        if (!model.TryGetMailData(model.nowUuid, out nowMailData))
        {
            UIManager.Instance.CloseWindow<MailInfoWin>();
        }
        isHasAward = nowMailData != null && nowMailData.Items != null;
    }
}