require("Base/BasePanel") MailMainPanel = Inherit(BasePanel) local this=MailMainPanel local allMail local openPanel local allGetMail local allDrop = {} local isPlayAnim = true --初始化组件(用于子类重写) function MailMainPanel:InitComponent() this.spLoader = SpriteLoader.New() allGetMail={} this.closeBtn = Util.GetGameObject(self.gameObject, "bg/closeBtn") this.mask = Util.GetGameObject(self.gameObject, "bgMask") this.mialNum = Util.GetGameObject(self.gameObject, "bg/mialNum"):GetComponent("Text") this.DeleMialText = Util.GetGameObject(self.gameObject, "bg/DeleMialText"):GetComponent("Text") this.mailPre=Util.GetGameObject(self.gameObject, "mailPre") this.GetAllMailBtn=Util.GetGameObject(self.gameObject, "GetAllMailBtn") this.DelReadMailBtn=Util.GetGameObject(self.gameObject, "DelReadMailBtn") this.ScrollBar=Util.GetGameObject(self.gameObject, "Scrollbar"):GetComponent("Scrollbar") this.ScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.gameObject.transform, this.mailPre, this.ScrollBar, Vector2.New(721, 719), 1, 1, Vector2.New(20,15)) this.ScrollView.gameObject:GetComponent("RectTransform").anchoredPosition = Vector2.New(10,46) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMin = Vector2.New(0.5, 0.5) this.ScrollView.gameObject:GetComponent("RectTransform").anchorMax = Vector2.New(0.5, 0.5) this.ScrollView.moveTween.MomentumAmount = 1 this.ScrollView.moveTween.Strength = 1 end --绑定事件(用于子类重写) function MailMainPanel:BindEvent() Util.AddClick(this.closeBtn, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) Util.AddClick(this.mask, function() PlaySoundWithoutClick(SoundConfig.Sound_UICancel) self:ClosePanel() end) Util.AddClick(this.GetAllMailBtn, function() allGetMail={} for i = 1, #allMail do if allMail[i].state<3 and allMail[i].mailItem ~= "" then table.insert(allGetMail,allMail[i].mailId) end end if allGetMail and #allGetMail>0 then this.GetMailData3() else PopupTipPanel.ShowTip(Language[11165]) end end) Util.AddClick(this.DelReadMailBtn, function() local DelMails={} for i = 1, #allMail do if allMail[i].state >= 1 and allMail[i].mailItem=="" then--已读取 未领取 无附件 table.insert(DelMails,allMail[i].mailId) elseif allMail[i].state >= 3 then--已领取 table.insert(DelMails,allMail[i].mailId) end end if DelMails and #DelMails>0 then this.DelMailData(DelMails) else PopupTipPanel.ShowTip(Language[11166]) end end) end function this.DelMailData(DelMails) if DelMails and #DelMails > 0 then NetManager.DelMailData(DelMails,function () for i = 1, #DelMails do MailManager.DelSingleMial(DelMails[i]) end this.UpdateMailData() end) end end function this.GetMailData(index) if index > 0 then NetManager.GetSingleMailRewardData({allGetMail[index]},function (_drop) MailManager.UpdataMialIsReadState(allGetMail[index],3) UIManager.OpenPanel(UIName.RewardItemPopup,_drop,1,function() if UIManager.IsOpen(UIName.PatFacePanel) then--如果弹星级成长礼 就会打断所有邮件的领取 this.UpdateMailData() else this.GetMailData(index-1) end end) end) else this.UpdateMailData() end end function this.GetMailData3() NetManager.GetSingleMailRewardData(allGetMail,function (_drop) -- for index = 1, #allGetMail do -- MailManager.UpdataMialIsReadState(allGetMail[index],3) -- end NetManager.GetAllMailData(function () this.OnShowMailListData(MailManager.mialDataList, true,true) end) UIManager.OpenPanel(UIName.RewardItemPopup,_drop,1,function () this.UpdateMailData() end) CheckRedPointStatus(RedPointType.Mail_Local) end) end --添加事件监听(用于子类重写) function MailMainPanel:AddListener() end --移除事件监听(用于子类重写) function MailMainPanel:RemoveListener() end --界面打开时调用(用于子类重写) function MailMainPanel:OnOpen(...) local data={...} openPanel=data[1] end function MailMainPanel:OnShow() isPlayAnim = true allMail={} NetManager.GetAllMailData(function () this.OnShowMailListData(MailManager.mialDataList, true,true) end) end function this.CallBackOnShow() allMail={} NetManager.GetAllMailData(function () this.OnShowMailListData(MailManager.mialDataList) end) end local maildataCount=0--数据数量 --设置英雄列表数据 function this.OnShowMailListData(_allMail, isTop,isAni) -- LogRed("isTop "..tostring(isTop).." isAni "..tostring(isAni)) allMail= _allMail this:SortAllMail(allMail) maildataCount=#allMail this.mialNum.text=Language[11167]..maildataCount this.ScrollView:SetData(allMail, function (index, go) this.SingleMialDataShow(go, allMail[index]) end, not isTop,not isAni) -- if isPlayAnim then -- SecTorPlayAnimByScroll(this.ScrollView) -- isPlayAnim = false -- end end function this.SingleMialDataShow(_go,_mailData) local mailImage = Util.GetGameObject(_go.transform, "mailImage") local openMailImage = Util.GetGameObject(_go.transform, "openMailImage") local getOk = Util.GetGameObject(_go.transform, "goBtn/getOk") local goBtn = Util.GetGameObject(_go.transform, "goBtn") if _mailData.state==nil then _mailData.state=0 end if _mailData.mailItem=="" then--无附件 goBtn:SetActive(false) else goBtn:SetActive(true) end if _mailData.state==0 then--未读 mailImage :SetActive(true) openMailImage :SetActive(false) getOk :SetActive(false) elseif _mailData.state==1 then--已读取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(false) elseif _mailData.state==2 then--未领取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(false) elseif _mailData.state==3 then--已领取 mailImage :SetActive(false) openMailImage :SetActive(true) getOk :SetActive(true) end Util.GetGameObject(_go.transform, "infoText"):GetComponent("Text").text = _mailData.head Util.GetGameObject(_go.transform, "sendText"):GetComponent("Text").text = GetTimeStrBySeconds(_mailData.sendTime)--Language[11168].._mailData.sendName local mialBtn = Util.GetGameObject(_go.transform, "Imagebg") local isTopImg = Util.GetGameObject(_go.transform, "isTopImg") if not _mailData.isTop or _mailData.isTop == 0 then--不置顶 -- mialBtn:GetComponent("Image").sprite = this.spLoader:LoadSprite("r_renwu_tiao_004") isTopImg:SetActive(false) elseif _mailData.isTop == 1 then--置顶 -- mialBtn:GetComponent("Image").sprite = this.spLoader:LoadSprite("r_youjian_zhidingdi") isTopImg:SetActive(true) end Util.AddOnceClick(mialBtn, function() if _mailData.state==0 then--未读 NetManager.ReadSingleMailData(_mailData.mailId,function () MailManager.UpdataMialIsReadState(_mailData.mailId,1) Log("读取邮件成功 ".._mailData.mailId) UIManager.OpenPanel(UIName.MainSingleInfoPanel,MailManager.GetSingleMail(_mailData.mailId),this) this.UpdateMailData() end) else NetManager.ReadSingleMailData(_mailData.mailId,function () UIManager.OpenPanel(UIName.MainSingleInfoPanel,MailManager.GetSingleMail(_mailData.mailId),this) end) end end) Util.GetGameObject(_go.transform, "mialRedPoint"):SetActive( _mailData.state==0) end function this.UpdateMailData() this.OnShowMailListData(MailManager.mialDataList) end --界面关闭时调用(用于子类重写) function MailMainPanel:OnClose() if openPanel then openPanel.RefreshRedPoint() end end --界面销毁时调用(用于子类重写) function MailMainPanel:OnDestroy() this.spLoader:Destroy() this.ScrollView = nil end function MailMainPanel:SortAllMail(allMail) table.sort(allMail, function(a,b) if a.isTop == b.isTop then if a.state == b.state then return a.sendTime > b.sendTime else return a.state < b.state end else return a.isTop > b.isTop end end) end return MailMainPanel