local UIRedPacketRecord = UIViewClass() --[[ 势力红包领取界面 --]] local RightLoopTab = { Receive = 1, Record = 2, } local nanosecond = 1000000000 -------------------- function UIRedPacketRecord:OnCreated() self.redPakcetRecord = {} self.redPakcetReceive = {} self.redPacketData = nil self.briefInfo = nil end function UIRedPacketRecord:OnOpened() CTL.RedPacket.ShowOrHideRedPacket(false) self:RegistSystemEvent(EventID.UI_RedPacket_RefreshRecordPanel, self.RefreshRecordLoop) self:RegistSystemEvent(EventID.UI_Guild_BeKickOutRefresh, self.CloseView) self:RegistSystemEvent(EventID.UI_Guild_Leave, self.CloseView) self:SetRedPacketInfo() self:OnValueChanged(self.toggle_TopGroup, 0) end function UIRedPacketRecord:OnClosed() CTL.RedPacket.ShowOrHideRedPacket() end function UIRedPacketRecord:OnBackButtonPressed() self:OnButtonClicked(self.img_Bg) end function UIRedPacketRecord:OnButtonClicked(comp) if comp == self.img_Bg then self:CloseView() end end function UIRedPacketRecord:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Info_RedPacket then cellTable.obj_State:SetState(data.PlayerACID == BattleDataGetter.GetAcID() and 1 or 0) CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHeadTempate, data.HeadIcon, data.HeadFrame, nil, data.PlayerACID) UIUtils.SetLabel(cellTable.txt_PlayerName, data.PlayerName) if self.briefInfo then local timeStamp = self.briefInfo.TimeStamp if not timeStamp then timeStamp = 0 end local receiveTime = math.max(math.floor((data.ReceiveTimeStamp - timeStamp) / nanosecond), 1) UIUtils.SetLabel(cellTable.txt_TimeUsed, UTL.Time.FormatTimeBySecondsToHour(receiveTime)) end UIUtils.SetLabel(cellTable.txt_Collect, data.ReceiveAmount) if self.redPacketData then -- 当红包的领取人数==红包的可领人数时,红包全部被领完,才显示手气最佳 UIUtils.SetActive(cellTable.img_BestLuckBg.gameObject, #self.redPakcetReceive == self.redPacketData.HongBaoNum and data.isMax) else UIUtils.SetActive(cellTable.img_BestLuckBg.gameObject, false) end elseif scrollRect == self.loop_Record then CTL.Character.SetPortraitAndFrame(cellTable.UIHeroHeadTempate, data.HeadIcon, data.HeadFrame, nil, data.PlayerACID) UIUtils.SetLabel(cellTable.txt_PlayerName, data.PlayerName) local obtainTime = math.max(math.floor(data.ObtainTimeStamp / nanosecond), 1) if GameAppInfo.IsJapanesePackage() then UIUtils.SetLabel(cellTable.txt_Time, UTL.Time.FormatTimeForJP(obtainTime)) else UIUtils.SetLabel(cellTable.txt_Time, UTL.Time.FormatTimeCompletely(obtainTime)) end local redPacketData = DataSheetManager.HongBao:GetDataByID(data.CfgID) if redPacketData then UIUtils.SetLabel(cellTable.txt_RedPacketName, CTL.RedPacket.GetRedPacketDescByRedPacketData(redPacketData)) UIUtils.SetLabel(cellTable.txt_Cost, redPacketData.HongBaoMoney) else logging.error(LTAG.ERROR, "势力红包 : 没有找到 id = ", data.CfgID, " 的红包数据") end end end function UIRedPacketRecord:OnValueChanged(comp, index) if comp == self.toggle_TopGroup then if index + 1 == RightLoopTab.Receive then self:RefreshReceiveLoop() elseif index + 1 == RightLoopTab.Record then MDL.RedPacket.GetGuildRedPacketInfoRequest(false, MDL.RedPacket.RightRequestForm.RequestHistoryContent) end end end -------------------- function UIRedPacketRecord:SetRedPacketInfo() self.briefInfo = MDL.RedPacket.GetCurShowRedPacketBriefInfo() if not self.briefInfo then return end UIUtils.SetActive(self.img_AnonymousBg, self.briefInfo.isInnominate and self.briefInfo.PlayerACID == BattleDataGetter.GetAcID()) if self.briefInfo.isInnominate and self.briefInfo.PlayerACID ~= BattleDataGetter.GetAcID() then UIUtils.SetActive(self.UIHeroHeadTempate.gameObject, false) UIUtils.SetActive(self.UIHeadAnonymous, true) UIUtils.SetLabelText(self.txt_PlayerName, Const_IDS.IDS_GuildHongBao_PlayerName) UIUtils.SetLabelText(self.txt_RedPacketName, Const_IDS.IDS_GuildHongBao_DesHint1) else UIUtils.SetActive(self.UIHeroHeadTempate.gameObject, true) UIUtils.SetActive(self.UIHeadAnonymous, false) CTL.Character.SetPortraitAndFrame(self.UIHeroHeadTempate, self.briefInfo.HeadIcon, self.briefInfo.HeadFrame, nil, self.briefInfo.PlayerACID) UIUtils.SetLabel(self.txt_PlayerName, self.briefInfo.PlayerName) self.redPacketData = DataSheetManager.HongBao:GetDataByID(self.briefInfo.CfgID) if self.redPacketData then UIUtils.SetLabel(self.txt_RedPacketName, CTL.RedPacket.GetRedPacketDescByRedPacketData(self.redPacketData)) else logging.error(LTAG.ERROR, "势力红包 : 没有找到 id = ", self.briefInfo.CfgID, " 的红包数据") end end end function UIRedPacketRecord:RefreshRecordLoop() if MDL.RedPacket.RedPakcetRecordIsEmpty() then UIUtils.SetActive(self.loop_Record, false) UIUtils.SetActive(self.group_Gain, false) UIUtils.SetActive(self.img_Empty, true) else local index = 1 for _, v in MDL.RedPacket.GetRedPakcetRecordIterator() do self.redPakcetRecord[index] = v index = index + 1 end for i = #self.redPakcetRecord, index, -1 do table.remove(self.redPakcetRecord, i) end UIUtils.SetActive(self.group_Gain, false) UIUtils.SetActive(self.loop_Record, true) self.loop_Record:ReloadAll(self.redPakcetRecord) UIUtils.SetActive(self.img_Empty, false) end end function UIRedPacketRecord:RefreshReceiveLoop() local index = 1 local curMoney = 0 for _, v in MDL.RedPacket.GetCurShowRedPacketReceiveRecordsIterator() do self.redPakcetReceive[index] = v curMoney = curMoney + v.ReceiveAmount index = index + 1 end for i = #self.redPakcetReceive, index, -1 do table.remove(self.redPakcetReceive, i) end if self.redPacketData then UIUtils.SetLabel(self.txt_Collected, string.FormatByIdsId(Const_IDS.IDS_HongBao_GetRecord, #self.redPakcetReceive, self.redPacketData.HongBaoNum, curMoney, self.redPacketData.HongBaoMoney)) end -- 设置自身领取 local selfRedPakcetReceive = MDL.RedPacket.GetSelfRedPacketReceiveRecords() if selfRedPakcetReceive then UIUtils.SetActive(self.img_Currency, true) UIUtils.SetLabel(self.txt_Number, selfRedPakcetReceive.ReceiveAmount) else UIUtils.SetActive(self.img_Currency, false) UIUtils.SetLabelText(self.txt_Number, Const_IDS.IDS_HongBao_Finished1) end if #self.redPakcetReceive == 0 then UIUtils.SetActive(self.img_Empty, false) UIUtils.SetActive(self.loop_Record, false) UIUtils.SetActive(self.loop_Info_RedPacket, false) UIUtils.SetActive(self.group_Gain, true) else UIUtils.SetActive(self.img_Empty, false) UIUtils.SetActive(self.loop_Record, false) UIUtils.SetActive(self.loop_Info_RedPacket, true) UIUtils.SetActive(self.group_Gain, true) self.loop_Info_RedPacket:ReloadAll(self.redPakcetReceive) end end return UIRedPacketRecord