local UIRedEnvelopeRainMain = UIViewClass() local RedEnvelopeRainStar = DataSheetManager.ConstData:GetDataByID("RedEnvelopeRainStar").DateValue local RedEnvelopeRainHerald = DataSheetManager.ConstData:GetDataByID("RedEnvelopeRainHerald").DateValue local JackpotImagePath = { ConstAssetPathConfig.AssetPath207, ConstAssetPathConfig.AssetPath208, ConstAssetPathConfig.AssetPath209, ConstAssetPathConfig.AssetPath210, ConstAssetPathConfig.Path44, } local SubscribeInterval = 60 -------------------- function UIRedEnvelopeRainMain:OnCreated() self.curTabRankType = 0 self.tabRankTypeList = {} self.tabNameList = {} end function UIRedEnvelopeRainMain:OnOpened(context) self:RegistSystemEvent(EventID.RedEnvelope_RefreshRankList, self.RefreshRankList) self.activityType = MDL.OperationActivity.ActivityType.RedEnvelopeRain CTL.RedEnvelopRain.RemoveRedPoint() self:InitPanel() self:StartRepeatFunc(self.RedEnvelopeRainRankReq, SubscribeInterval) end function UIRedEnvelopeRainMain:OnClosed() -- 关闭界面时 向服务器发起取消注册 MDL.RedEnvelopRain.GetRedEnvelopeRainRankReq(self.curTabRankType, false) end function UIRedEnvelopeRainMain:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UIRedEnvelopeRainMain:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView(false) elseif comp == self.btn_Reward then UIManager.OpenView(Const_UI_Lua.UIEnum.UIRedEnvelopeRainReward, {rankType = self.curTabRankType}) elseif comp == self.btn_Recharge then local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, CTL.RedEnvelopRain.GetCurOpenRedEnvelopRainActivityId()) if not activityInfo then return end local endTime = UTL.Time.GetServerZeroTimestampByTimestamp(activityInfo.endTime) + RedEnvelopeRainStar if endTime > activityInfo.endTime then endTime = endTime - UTL.Time.TotalSecondsOneDay end if UTL.Time.GetServerTimestamp() > endTime then CTL.Tips.AddTipsMsg(Const_IDS.IDS_RedEnvelopeRain_RechargeTips2) end CTL.ItemSources.ExecuteSourceFunctionById(MDL.ItemSources.SourceType.Recharge) elseif comp == self.btn_Info then UIUtils.SetActive(self.obj_Notice, true) elseif comp == self.btn_NoticeBottom then UIUtils.SetActive(self.obj_Notice, false) end end function UIRedEnvelopeRainMain:OnValueChanged(comp, index) if comp == self.toggle_Group then self.curTabRankType = self.tabRankTypeList[index + 1] MDL.RedEnvelopRain.GetRedEnvelopeRainRankReq(self.curTabRankType, true) -- 设置奖池标题(总榜没有奖池) if self.curTabRankType ~= MDL.RedEnvelopRain.EnvelopeRainRankType.AllRank then UIUtils.SetLabel(self.txt_Day, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_AwardDate, self.tabNameList[index + 1])) end end end function UIRedEnvelopeRainMain:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_RankInfo then cellTable.state_Bg:SetState(index % 2) if index < 3 then cellTable.state_Rank:SetState(index) else cellTable.state_Rank:SetState(3) UIUtils.SetLabel(cellTable.txt_Rank, index + 1) end -- 设置名字 UIUtils.SetLabel(cellTable.txt_Player, data.playerName) -- 设置区服 UIUtils.SetLabel(cellTable.txt_Server, string.FormatByIdsId(Const_IDS.IDS_ServerInfo, data.serverId)) -- 设置额度 UIUtils.SetLabel(cellTable.txt_Num, data.addGoldNum) -- 设置势力 if not string.isNilOrEmpty(data.guildId) then UIUtils.SetActive(cellTable.group_Guild, false) else UIUtils.SetActive(cellTable.group_Guild, true) -- 设置军团名字 UIUtils.SetLabel(cellTable.txt_GuildName, data.guildName) self:SetGuildInfo(cellTable, data.guildEmblemContent, data.guildEmblemFrame) end end end -------------------- function UIRedEnvelopeRainMain:InitPanel() -- 处理本地化图片问题 UTL.Item.SetLocalizationImage(self.state_Ttile, self.img_Title, "znqhby_msz.png") -- 设置红包开启时间 self:InitStartTime() -- 设置排行提示 local startTimeStr = UTL.Time.FormatTimeSimpleWithHMS(UTL.Time.GetServerZeroTimestamp() + RedEnvelopeRainStar) UIUtils.SetLabel(self.txt_Notice, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_RechargeTips1, startTimeStr, startTimeStr, startTimeStr)) -- 设置重置金额提示 local rechargeData = CTL.RedEnvelopRain.GetRechargeData() local rechargeCoin = MDL.Currency.GetPriceExchangeRate(rechargeData.RechargeCoin, GameAppInfo.IsOverseaPackage()) UIUtils.SetLabel(self.txt_NoticeInfo, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_RechargeTips3, MDL.Currency.FormatPriceNum(rechargeCoin), rechargeData.ConversionRatio)) self:InitTabGroup() self:RefreshRankList() end -- 根据当前时间判断初始化Tab数量 function UIRedEnvelopeRainMain:InitTabGroup() local activityInfo = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, CTL.RedEnvelopRain.GetCurOpenRedEnvelopRainActivityId()) if not activityInfo then return end local curTimestamp = UTL.Time.GetServerTimestamp() local tabNameList = {} local selectIndex = 0 local endTime = UTL.Time.GetServerZeroTimestampByTimestamp(activityInfo.endTime) + RedEnvelopeRainStar if endTime > activityInfo.endTime then endTime = endTime - UTL.Time.TotalSecondsOneDay end if curTimestamp > UTL.Time.GetServerZeroTimestampByTimestamp(activityInfo.startTime) + RedEnvelopeRainStar and curTimestamp < endTime then -- 活动开启第一天8点后 & 最后一天的活动8点前 if curTimestamp < UTL.Time.GetServerZeroTimestamp() + RedEnvelopeRainStar then table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.YesterdayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(curTimestamp - UTL.Time.TotalSecondsOneDay)) table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.TodayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(curTimestamp)) else table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.YesterdayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(curTimestamp)) table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.TodayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(curTimestamp + UTL.Time.TotalSecondsOneDay)) end selectIndex = 1 else -- 最后一天额外处理 if curTimestamp > endTime then table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.YesterdayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(endTime)) else table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.TodayRank) table.insert(self.tabNameList, UTL.Time.FormatTimeForTab(curTimestamp)) end selectIndex = 0 end table.insert(self.tabRankTypeList, MDL.RedEnvelopRain.EnvelopeRainRankType.AllRank) table.insert(self.tabNameList, UIUtils.GetLocalizedTxt(Const_IDS.IDS_RedEnvelopeRain_TotalRanking)) UTL.Toggle.InitToggleGroupByText(self.toggle_Group, "lab_State", self.tabNameList) -- 设置默认选中 self.toggle_Group:SelectIndex(selectIndex) -- 设置活动时间 UIUtils.SetLabel(self.txt_Time, string.format("%s—%s", UTL.Time.FormatTimeSimpleNotSpace(activityInfo.startTime), UTL.Time.FormatTimeSimpleNotSpace(activityInfo.endTime))) end -- 刷新排行信息 function UIRedEnvelopeRainMain:RefreshRankList() local allGoldNum = MDL.RedEnvelopRain.GetAllGoldNum() -- 设置奖池金额 UIUtils.SetLabel(self.txt_RewardNum, allGoldNum) -- 计算图片显示 local isMax, imageIndex = CTL.RedEnvelopRain.GetAllGoldIndex() -- 设置奖池额度上限提示 UIUtils.SetActive(self.group_Limit.gameObject, isMax) -- 设置宝箱图片显示 if imageIndex <= #JackpotImagePath then UIUtils.SetImageByAssetBundle(self.img_Jackpot, JackpotImagePath[imageIndex]) else UIUtils.SetImageByAssetBundle(self.img_Jackpot, JackpotImagePath[#JackpotImagePath]) end self.img_Jackpot:SetNativeSize() -- 设置排行榜 if MDL.RedEnvelopRain.GetRankInfoNumByRankType(self.curTabRankType) == 0 then self.loop_RankInfo:ClearCells() UIUtils.SetActive(self.group_Empty, true) else UIUtils.SetActive(self.group_Empty, false) MDL.RedEnvelopRain.ResetRankInfoIterator(self.curTabRankType) CSExt.CSFunc_ReloadAll(self.loop_RankInfo, MDL.RedEnvelopRain.EnumRankInfoIterator) end -- 设置自身排行数据 local myRankInfo = MDL.RedEnvelopRain.GetMyRankInfoByRankType(self.curTabRankType) if myRankInfo and myRankInfo.index > 0 then if myRankInfo.index <= 3 then self.group_Mine.state_Rank:SetState(myRankInfo.index - 1) else self.group_Mine.state_Rank:SetState(3) UIUtils.SetLabel(self.group_Mine.txt_Rank, myRankInfo.index) end UIUtils.SetLabel(self.group_Mine.txt_Num, myRankInfo.addGoldNum) else self.group_Mine.state_Rank:SetState(3) UIUtils.SetLabel(self.group_Mine.txt_Rank, "--") UIUtils.SetLabel(self.group_Mine.txt_Num, 0) end -- 设置自身名字 UIUtils.SetLabel(self.group_Mine.txt_Player, BattleDataGetter.GetPlayerName()) -- 设置自身区服 UIUtils.SetLabel(self.group_Mine.txt_Server, string.FormatByIdsId(Const_IDS.IDS_ServerInfo, MDL.Login.GetServerShowId())) -- 设置自身势力信息 local guildInfo = MDL.Guild.GetMyGuildInfo() if guildInfo and not string.isNilOrEmpty(guildInfo.guildId) then UIUtils.SetActive(self.group_Mine.group_Guild, true) -- 设置军团名字 UIUtils.SetLabel(self.group_Mine.txt_GuildName, guildInfo.guildName) self:SetGuildInfo(self.group_Mine, guildInfo.emblemContent, guildInfo.emblemFrame) else UIUtils.SetActive(self.group_Mine.group_Guild, false) end end function UIRedEnvelopeRainMain:InitStartTime() local isInForeshow, residueForeshowTime = CTL.RedEnvelopRain.ResidueRedEnvelopRainForeshowTime() local startTimeStr = UTL.Time.FormatTimeSimpleWithHMS(UTL.Time.GetServerZeroTimestamp() + RedEnvelopeRainStar) if residueForeshowTime > 0 then if isInForeshow then self:RefreshStartTimeStr() self:StartRepeatFunc(self.RefreshStartTimeStr, 1) else UIUtils.SetLabel(self.txt_StartTime, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_OpenTips1, startTimeStr)) self:StartRepeatFunc(self.InitStartTime, residueForeshowTime, 1) end else UIUtils.SetLabel(self.txt_StartTime, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_OpenTips1, startTimeStr)) end end function UIRedEnvelopeRainMain:RefreshStartTimeStr(deltaTime, timeSinceUpdate) local _, residueForeshowTime = CTL.RedEnvelopRain.ResidueRedEnvelopRainForeshowTime() UIUtils.SetLabel(self.txt_StartTime, string.FormatByIdsId(Const_IDS.IDS_RedEnvelopeRain_OpenTips2, UTL.Time.FormatTimeBySeconds(residueForeshowTime))) if residueForeshowTime <= 0 then self:StopRepeatFunc(self.RefreshStartTimeStr) self:InitStartTime() end end -- 设置势力相关 function UIRedEnvelopeRainMain:SetGuildInfo(guildObj, emblemContent, emblemFrame) -- 设置军团徽记 if string.isNilOrEmpty(emblemContent) then UIUtils.SetActive(guildObj.img_Guild, false) else local guildEmblemCfg = DataSheetManager.GuildEmblem:GetDataByID(emblemFrame) if guildEmblemCfg then UIUtils.SetActive(guildObj.img_Guild, true) UIUtils.SetLabel(guildObj.txt_Guild, emblemContent) UTL.Item.SetAtlasSprite(guildObj.img_Guild, "UI_Guild", guildEmblemCfg.Image) else UIUtils.SetActive(guildObj.img_Guild, false) end end end -- 间隔一定时间 向服务器发起重新注册 function UIRedEnvelopeRainMain:RedEnvelopeRainRankReq() if self.curTabRankType <= 0 then return end MDL.RedEnvelopRain.GetRedEnvelopeRainRankReq(self.curTabRankType, true) end return UIRedEnvelopeRainMain