hch
2 天以前 1b4b01956de5d072e3281176ff5e219bd5e2b511
Main/System/Mail/MailWin.cs
@@ -1,89 +1,87 @@
using System;
using UnityEngine;
public class MailWin : UIBase
public class MailWin : FunctionsBaseWin
{
    [SerializeField] Transform transPersonal;
    [SerializeField] Transform transGlobal;
    [SerializeField] ScrollerController scrPersonal;
    [SerializeField] ScrollerController scrGlobal;
    [SerializeField] ButtonEx btnDeleteRead;
    [SerializeField] ScrollerController scrMail;
    [SerializeField] ButtonEx btnDeleteAllRead;
    [SerializeField] ButtonEx btnClaimAll;
    [SerializeField] ToggleEx togTab0;
    [SerializeField] RedpointBehaviour rpTab0;
    [SerializeField] ToggleEx togTab1;
    [SerializeField] RedpointBehaviour rpTab1;
    [SerializeField] Transform transNoMail;
    [SerializeField] Transform transCurrentMailCount;
    [SerializeField] TextEx txtCurrentMailCount;
    MailManager model { get { return MailManager.Instance; } }
    protected override void InitComponent()
    {
        base.InitComponent();
        btnDeleteRead.SetListener(OnDeleteRead);
        btnDeleteAllRead.SetListener(OnDeleteRead);
        btnClaimAll.SetListener(OnClaimAll);
        togTab0.SetListener(OnTab0);
        togTab1.SetListener(OnTab1);
    }
    protected override void OnPreOpen()
    {
        model.OnUpdateMailListEvent += OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent;
        scrPersonal.OnRefreshCell += OnRefreshPersonalCell;
        scrGlobal.OnRefreshCell += OnRefreshGlobalCell;
        base.OnPreOpen();
        tabButtons[functionOrder].SelectBtn(true);
        model.nowMailCategory = MailCategory.Personal;
        rpTab0.redpointId = model.GetTabRedpointId(MailCategory.Personal);
        rpTab1.redpointId = model.GetTabRedpointId(MailCategory.Global);
        transNoMail.SetActive(false);
        transNoMail.SetActive(true);
        btnDeleteAllRead.SetActive(true);
        btnClaimAll.SetActive(true);
        transCurrentMailCount.SetActive(true);
        model.OnUpdateMailListEvent += OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent += OnUpdateMailStateChangeEvent;
        scrMail.OnRefreshCell += OnRefreshCell;
        GlobalTimeEvent.Instance.secondEvent += OnSecondEvent;
        DisPlay();
    }
    protected override void OnPreClose()
    {
        base.OnPreClose();
        model.OnUpdateMailListEvent -= OnUpdateMailListEvent;
        model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent;
        scrPersonal.OnRefreshCell -= OnRefreshPersonalCell;
        scrGlobal.OnRefreshCell -= OnRefreshGlobalCell;
        scrMail.OnRefreshCell -= OnRefreshCell;
        GlobalTimeEvent.Instance.secondEvent -= OnSecondEvent;
    }
    private void OnTab0(bool value)
    private void OnSecondEvent()
    {
        if (value)
        scrMail.m_Scorller.RefreshActiveCellViews();
        int personalMailCount = MailManager.Instance.GetMailCount(MailCategory.Personal);
        txtCurrentMailCount.text = StringUtility.Contact(personalMailCount, "/", MailManager.Instance.personalMailMaxLimitCount);
    }
    protected override void OpenSubUIByTabIndex()
    {
        switch (functionOrder)
        {
            transPersonal.SetActive(true);
            transGlobal.SetActive(false);
            model.nowMailCategory = MailCategory.Personal;
            CreatePersonalScr(model.nowMailCategory);
            case 0:
                model.nowMailCategory = MailCategory.Personal;
                btnDeleteAllRead.SetActive(true);
                btnClaimAll.SetActive(true);
                transCurrentMailCount.SetActive(true);
                int personalMailCount = MailManager.Instance.GetMailCount(MailCategory.Personal);
                txtCurrentMailCount.text = StringUtility.Contact(personalMailCount, "/", MailManager.Instance.personalMailMaxLimitCount);
                DisPlay();
                break;
            case 1:
                model.nowMailCategory = MailCategory.Global;
                btnDeleteAllRead.SetActive(false);
                btnClaimAll.SetActive(false);
                transCurrentMailCount.SetActive(false);
                DisPlay();
                break;
            default:
                Debug.LogWarning("未知的标签索引: " + functionOrder);
                break;
        }
    }
    private void OnTab1(bool value)
    private void OnRefreshCell(ScrollerDataType type, CellView cell)
    {
        if (value)
        {
            transPersonal.SetActive(false);
            transGlobal.SetActive(true);
            model.nowMailCategory = MailCategory.Global;
            CreateGlobalScr(model.nowMailCategory);
        }
    }
    protected override void OnOpen()
    {
        togTab0.isOn = true;
        togTab1.isOn = false;
        model.nowMailCategory = MailCategory.Personal;
        CreatePersonalScr(model.nowMailCategory);
    }
    private void OnRefreshPersonalCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<MailPersonalCell>();
        _cell?.Display(cell.index, cell);
    }
    private void OnRefreshGlobalCell(ScrollerDataType type, CellView cell)
    {
        var _cell = cell.GetComponent<MailGlobalCell>();
        var _cell = cell.GetComponent<MailCell>();
        _cell?.Display(cell.index, cell);
    }
@@ -113,50 +111,24 @@
        model.ClaimMail();
    }
    public void CreatePersonalScr(MailCategory mailCategory)
    {
        scrPersonal.Refresh();
        var list = model.GetSortMailScrList(mailCategory);
        if (list != null)
        {
            for (int i = 0; i < list.Count; i++)
            {
                CellInfo cellInfo = new CellInfo();
                cellInfo.infoInt1 = (int)mailCategory;
                scrPersonal.AddCell(ScrollerDataType.Header, i, cellInfo);
            }
        }
        scrPersonal.Restart();
    }
    public void CreateGlobalScr(MailCategory mailCategory)
    {
        scrGlobal.Refresh();
        var list = model.GetSortMailScrList(mailCategory);
        if (list != null)
        {
            for (int i = 0; i < list.Count; i++)
            {
                CellInfo cellInfo = new CellInfo();
                cellInfo.infoInt1 = (int)mailCategory;
                scrGlobal.AddCell(ScrollerDataType.Header, i, cellInfo);
            }
        }
        scrGlobal.Restart();
    }
    private void OnUpdateMailStateChangeEvent()
    {
        RefreshScr();
        DisPlay();
    }
    private void OnUpdateMailListEvent()
    {
        RefreshScr();
        DisPlay();
    }
    private void RefreshScr()
    {
        var list = model.GetSortMailScrList(model.nowMailCategory);
    private void DisPlay()
    {
        scrMail.Refresh();
        scrMail.Restart();
        MailCategory mailCategory = model.nowMailCategory;
        var list = model.GetSortMailScrList(mailCategory);
        if (list.IsNullOrEmpty())
        {
            transNoMail.SetActive(true);
@@ -164,9 +136,20 @@
        else
        {
            transNoMail.SetActive(false);
            scrPersonal.m_Scorller.RefreshActiveCellViews();
            scrGlobal.m_Scorller.RefreshActiveCellViews();
            scrMail.Refresh();
            for (int i = 0; i < list.Count; i++)
            {
                CellInfo cellInfo = new CellInfo();
                cellInfo.infoInt1 = (int)mailCategory;
                scrMail.AddCell(ScrollerDataType.Header, i, cellInfo);
            }
            scrMail.Restart();
        }
        int personalMailCount = MailManager.Instance.GetMailCount(MailCategory.Personal);
        txtCurrentMailCount.text = StringUtility.Contact(personalMailCount, "/", MailManager.Instance.personalMailMaxLimitCount);
    }
}