yyl
2 天以前 6bcbcf0494eceb60e2754c966d66bd531c5be2a9
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
151
152
153
154
155
156
157
158
159
160
using System;
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 scrAward;
    [SerializeField] TextEx txtExpiryDate;
    [SerializeField] ImageEx imgHasAward;
    [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()
    {
        base.OnPreOpen();
        scrAward.OnRefreshCell += OnRefreshLowRewardCell;
        model.OnUpdateMailListEvent += OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        Display();
    }
 
    protected override void OnPreClose()
    {
        base.OnPreClose();
        scrAward.OnRefreshCell -= OnRefreshLowRewardCell;
        model.OnUpdateMailListEvent -= OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
    }
 
    private void OnSecondEvent()
    {
        txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime);
        txtExpiryDate.text = model.FormatMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays);
        txtExpiryDate.color = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays) >= 0 ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red);
    }
 
    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()
    {
        Display();
    }
 
    private void OnUpdateMailListEvent()
    {
        Display();
    }
 
    private void OnRefreshLowRewardCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<MailInfoAwardCell>();
        _cell?.Display(cell.index, cell);
    }
 
 
    private void Display()
    {
        if (!model.TryGetMailData(model.nowUuid, out nowMailData))
        {
            UIManager.Instance.CloseWindow<MailInfoWin>();
            return;
        }
        isHasAward = nowMailData != null && nowMailData.HasAward();
        transNoAward.SetActive(!isHasAward);
        transAward.SetActive(isHasAward);
        btnHave.SetActive(isHasAward && nowMailData.MailState != 3);
        imgHasAward.SetActive(nowMailData.MailState != 3 && nowMailData.HasAward());
        txtDate.text = model.FormatCreateMailTime(nowMailData.CreateDateTime);
 
        string key = nowMailData.GetTemplateKey();
        if (nowMailData.IsTemplateMail() && MailConfig.HasKey(key))
        {
            MailConfig config = MailConfig.Get(key);
            var templateParams = nowMailData.GetTemplateParams();
 
            // 打印出即将用于格式化的所有信息
            //         Debug.Log($"[邮件调试] GUID: {nowMailData.GUID}");
            // Debug.Log($"[邮件调试] 原始参数JSON (nowMailData.Text): '{nowMailData.Text}'");
            // Debug.Log($"[邮件调试] 解析后的参数数量: {templateParams.Count}");
            // if (templateParams.Count > 0)
            // {
            //     for(int i = 0; i < templateParams.Count; i++)
            //     {
            //         Debug.Log($"[邮件调试] 参数[{i}]: {templateParams[i]}");
            //     }
            // }
            try
            {
                string content = string.Format(config.Content, templateParams.ToArray());
                txtNoAwardInfo.text = content;
                txtAwardInfo.text = content;
                txtTitle.text = config.Title;
            }
            catch (System.Exception ex)
            {
                txtTitle.text = nowMailData.Title;
                txtNoAwardInfo.text = nowMailData.Text;
                txtAwardInfo.text = nowMailData.Text;
                Debug.LogError($"MailInfoWin 解析邮件参数失败! GUID: {nowMailData.GUID}, " +
                                 $"原始参数JSON: '{nowMailData.Text}', 错误: {ex.Message}");
            }
        }
        else
        {
            txtTitle.text = nowMailData.Title;
            txtNoAwardInfo.text = nowMailData.Text;
            txtAwardInfo.text = nowMailData.Text;
        }
        txtExpiryDate.text = model.FormatMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays);
        txtExpiryDate.color = model.GetMailExpiryDays(nowMailData.CreateDateTime, nowMailData.LimitDays) >= 0 ? UIHelper.GetUIColor(TextColType.DarkGreen) : UIHelper.GetUIColor(TextColType.Red);
        scrAward.Refresh();
        if (isHasAward)
        {
            for (int i = 0; i < nowMailData.Items.Count; i++)
            {
                CellInfo cellInfo = new CellInfo();
                cellInfo.infoStr1 = nowMailData.GUID;
                scrAward.AddCell(ScrollerDataType.Header, i, cellInfo);
            }
        }
        scrAward.Restart();
    }
 
}