| using System; | 
| using UnityEngine; | 
|   | 
|   | 
| public class MailWin : UIBase | 
| { | 
|     [SerializeField] Transform transPersonal; | 
|     [SerializeField] Transform transGlobal; | 
|     [SerializeField] ScrollerController scrPersonal; | 
|     [SerializeField] ScrollerController scrGlobal; | 
|     [SerializeField] ButtonEx btnDeleteRead; | 
|     [SerializeField] ButtonEx btnClaimAll; | 
|     [SerializeField] ToggleEx togTab0; | 
|     [SerializeField] RedpointBehaviour rpTab0; | 
|     [SerializeField] ToggleEx togTab1; | 
|     [SerializeField] RedpointBehaviour rpTab1; | 
|     [SerializeField] Transform transNoMail; | 
|     MailManager model { get { return MailManager.Instance; } } | 
|     protected override void InitComponent() | 
|     { | 
|         base.InitComponent(); | 
|         btnDeleteRead.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; | 
|              | 
|         rpTab0.redpointId = model.GetTabRedpointId(MailCategory.Personal); | 
|         rpTab1.redpointId = model.GetTabRedpointId(MailCategory.Global); | 
|         transNoMail.SetActive(false); | 
|     } | 
|   | 
|     protected override void OnPreClose() | 
|     { | 
|         model.OnUpdateMailListEvent -= OnUpdateMailListEvent; | 
|         model.OnUpdateMailStateChangeEvent -= OnUpdateMailStateChangeEvent; | 
|         scrPersonal.OnRefreshCell -= OnRefreshPersonalCell; | 
|         scrGlobal.OnRefreshCell -= OnRefreshGlobalCell; | 
|     } | 
|   | 
|     private void OnTab0(bool value) | 
|     { | 
|         if (value) | 
|         { | 
|             transPersonal.SetActive(true); | 
|             transGlobal.SetActive(false); | 
|             model.nowMailCategory = MailCategory.Personal; | 
|             CreatePersonalScr(model.nowMailCategory); | 
|         } | 
|     } | 
|   | 
|     private void OnTab1(bool value) | 
|     { | 
|         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>(); | 
|         _cell?.Display(cell.index, cell); | 
|     } | 
|   | 
|     private void OnDeleteRead() | 
|     { | 
|         ConfirmCancel.ShowPopConfirm( | 
|             Language.Get("Mail101"), | 
|             Language.Get("Mail10"), | 
|             (bool isOk) => | 
|             { | 
|                 if (isOk) | 
|                 { | 
|                     model.DeleteMail(); | 
|                     //邮件删除成功 | 
|                     SysNotifyMgr.Instance.ShowTip("Mail01"); | 
|                 } | 
|             }); | 
|     } | 
|   | 
|     private void OnClaimAll() | 
|     { | 
|         if (!model.IsCanHaveMail()) | 
|         { | 
|             SysNotifyMgr.Instance.ShowTip("Mail02"); | 
|             return; | 
|         } | 
|         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(); | 
|     } | 
|   | 
|     private void OnUpdateMailListEvent() | 
|     { | 
|         RefreshScr(); | 
|     } | 
|   | 
|     private void RefreshScr() | 
|     {  | 
|         var list = model.GetSortMailScrList(model.nowMailCategory); | 
|         if (list.IsNullOrEmpty()) | 
|         { | 
|             transNoMail.SetActive(true); | 
|         } | 
|         else | 
|         { | 
|             transNoMail.SetActive(false); | 
|             scrPersonal.m_Scorller.RefreshActiveCellViews(); | 
|             scrGlobal.m_Scorller.RefreshActiveCellViews(); | 
|         } | 
|     } | 
| } |