local UIDailySignin = UIViewClass() local IDS_SumSignDay = Const_IDS.IDS_DailySignin_SumSignDay -------------------- function UIDailySignin:OnCreated() self.curMonth = 0 self.curDay = 0 self.curYear = 0 self.curMonthMaxDay = 0 self.monthGiftsDataList = {} self.curAddUpSigninDataItemID = -1 end -- context = {singleOpen = true} -- 是否是独立打开(即是否是单独一个界面,还是嵌套在福利界面内) function UIDailySignin:OnOpened(context) self:RegistSystemEvent(EventID.UI_DailySignin_Refresh, self.RefreshSigninPanel) self.state_DailySignin:SetState(context.singleOpen and 0 or 1) self:RefreshSigninPanel() end function UIDailySignin:OnButtonClicked(comp) if comp == self.btn_Close then self:CloseView() elseif comp == self.group_SupplementInfo then local maxResignNum, resignActivityNum = CTL.DailySignin.GetMaxResignNumAndResignActivityNum() UIManager.OpenView(Const_UI_Lua.UIEnum.UICommonNoteView, {id = LuaConst.NoteID.DailySignin, params = {resignActivityNum, maxResignNum}}) elseif comp == self.btn_RewardPreview then UIManager.OpenView(Const_UI_Lua.UIEnum.UIDailySigninPop) elseif comp == self.btn_item then if self.curAddUpSigninDataItemID > 0 then UTL.ItemTips.ShowCommonTipsById(self.curAddUpSigninDataItemID) end else local monthDaysCount = MDL.DailySignin.GetMonthDaysCount() for i, v in ipairs (self.obj_Content) do if comp == v.btn_Reward then local monthGiftData = self.monthGiftsDataList[i] if not monthGiftData then return end if monthGiftData.MonthlyDay <= monthDaysCount and not MDL.DailySignin.IsReceiveDailyGiftsByMonthlyDay(monthGiftData.MonthlyDay) then MDL.DailySignin.DailySigninRequest(MDL.DailySignin.SigninType.MonthType, monthGiftData.MonthlyDay) else local mothGiftRewardData = DataSheetManager.MonthSigninReward:GetDataByID(monthGiftData.MonthlyReward) if mothGiftRewardData then UTL.ItemTips.ShowCommonTipsById(mothGiftRewardData.Item_Table[1].ItemID) else logging.error(LTAG.ERROR, "每日签到——月签到配表错误 : 请检查 MonthlyDay = ", monthGiftData.MonthlyDay, "的签到奖励,是否在MonthSigninReward表中配置") end end break end end end end function UIDailySignin:OnCellInit(scrollRect, index, cellTable, data) UIUtils.SetLabel(cellTable.txt_Day, data.dailySigninData.DailyDay) if data.dailySigninData.DailyDay > self.curDay then -- 目前天数大于当前天数,不显示特效不显示遮挡 cellTable.obj_receivedState:SetState(0) cellTable.effect_Available:StopUIEffect() cellTable.effect_AvailableItem:StopUIEffect() else if MDL.DailySignin.IsReceiveDailyGiftsByDailyDay(data.dailySigninData.DailyDay) then -- 目标天数已经领取过奖励, 不显示特效,显示已领取遮挡 cellTable.obj_receivedState:SetState(1) cellTable.effect_Available:StopUIEffect() cellTable.effect_AvailableItem:StopUIEffect() else if data.dailySigninData.DailyDay == self.curDay then -- 如果目标天数与当前天数一致且未领取,显示特效,不显示遮挡 cellTable.obj_receivedState:SetState(0) cellTable.effect_Available:PlayUIEffect() cellTable.effect_AvailableItem:PlayUIEffect() else if MDL.DailySignin.CanRepairSignin(self.curYear, self.curMonth, data.dailySigninData.DailyDay) then -- 如果目标天数小于当前天数,且为领取,同时今日可补签,不显示特效,显示补签遮挡 cellTable.obj_receivedState:SetState(2) cellTable.effect_Available:StopUIEffect() cellTable.effect_AvailableItem:StopUIEffect() else -- 目标天数小于当前天数,且未领取,今日不可补签,不显示特效,不显示遮挡 cellTable.obj_receivedState:SetState(0) cellTable.effect_Available:StopUIEffect() cellTable.effect_AvailableItem:StopUIEffect() end end end end if data.rewardItemData then UTL.Item.SetItemCell(cellTable.Item105, data.rewardItemData.ItemID, data.rewardItemData.ItemNum) end end function UIDailySignin:OnCellClicked(scrollRect, index, cellTable, target, data) if target == cellTable.btn_Click then if not MDL.DailySignin.IsReceiveDailyGiftsByDailyDay(data.dailySigninData.DailyDay) then if data.dailySigninData.DailyDay == self.curDay then MDL.DailySignin.DailySigninRequest(MDL.DailySignin.SigninType.DayType, data.dailySigninData.DailyDay) return elseif data.dailySigninData.DailyDay < self.curDay and MDL.DailySignin.CanRepairSignin(self.curYear, self.curMonth, data.dailySigninData.DailyDay) then MDL.DailySignin.DailySigninRequest(MDL.DailySignin.SigninType.RepairType, data.dailySigninData.DailyDay) return end end if data.rewardItemData then UTL.ItemTips.ShowCommonTipsById(data.rewardItemData.ItemID) end end end -------------------- function UIDailySignin:RefreshSigninPanel() self.curMonth, self.curDay, self.curMonthMaxDay, self.curYear = UTL.Time.GetCurDay() -- 处理每日签到显示 -- self:RefreshDailySignin() -- 处理累积签到显示 -- self:RefreshAccumulatedSignin() -- 处理本月累积签到显示 -- self:RefreshMonthSignin() -- 处理本地化图片问题 -- UTL.Item.SetLocalizationImage(self.obj_TitleState, self.img_Title3, "yq_msz_yue.png") end -- 处理每日签到显示 function UIDailySignin:RefreshDailySignin() -- 月份从1开始,State从0开始 self.obj_monthTitleState:SetState(self.curMonth - 1) local residueRepairCount = MDL.DailySignin.GetRepairCount() if residueRepairCount > 0 then residueRepairCount = UTL.Color.FormatGreenColor(residueRepairCount) end UIUtils.SetLabel(self.lab_supplement, string.FormatByIdsId(Const_IDS.IDS_DailySignin_Resign, residueRepairCount)) local dayDataList = {} for i = 1, self.curMonthMaxDay do local dailySigninData = DataSheetManager.DailySignin:GetDataByDailyDay(i) local dayData = { dailySigninData = dailySigninData } local rewardData = DataSheetManager.DailySigninReward:GetDataByID(dailySigninData.DailyReward) if rewardData then dayData.rewardItemData = rewardData.Item_Table[1] else logging.error(LTAG.ERROR, "每日签到——每日签到配表错误 : 请检查 DayNum = ", dailySigninData.DailyReward, "的每日签到奖励,是否在DailySigninReward表中配置") end table.insert(dayDataList, dayData) end self.loopScroll_DailySignin:ReloadAll(dayDataList) end -- 处理总累积签到显示 function UIDailySignin:RefreshAccumulatedSignin() -- 当前累积签到 UIUtils.SetLabel(self.txt_Cumulative, string.FormatByIdsId(IDS_SumSignDay, MDL.DailySignin.GetAddUpDaysCount())) -- 累积签到档位奖励显示 local addUpSigninData = CTL.DailySignin.GetNextAddUpSigninData() UIUtils.SetLabel(self.txt_CumulativeDays, string.FormatByIdsId(IDS_SumSignDay, addUpSigninData.AccumulatedDay)) local rewardData = DataSheetManager.AccumulatedSigninReward:GetDataByID(addUpSigninData.AccumulatedReward) self.btn_RewardPreview:SetRedPoint(MDL.DailySignin.HasAddUpSigninReward()) if rewardData then self.curAddUpSigninDataItemID = rewardData.Item_Table[1].ItemID UTL.Item.ItemIconWithoutBg(self.ItemIcon, self.curAddUpSigninDataItemID) else self.curAddUpSigninDataItemID = -1 logging.error(LTAG.ERROR, "每日签到——总累积签到配表错误 : 请检查 AccumulatedDay = ", addUpSigninData.AccumulatedDay, "的累积签到奖励,是否在MonthSigninReward表中配置") end end -- 处理本月累积签到显示 function UIDailySignin:RefreshMonthSignin() local monthDaysCount = MDL.DailySignin.GetMonthDaysCount() UIUtils.SetLabel(self.txt_CumulativeMonthDays, string.FormatByIdsId(IDS_SumSignDay, monthDaysCount)) self.monthGiftsDataList = CTL.DailySignin.GetCurMonthGiftsDataList(self.curMonthMaxDay) local bgWidth, bgHeight = self.img_ProgressBar.rectTransform:GetSizeDelta() local bgWidthSpace = bgWidth / #self.monthGiftsDataList for i, v in ipairs(self.monthGiftsDataList) do local contentItem = self.obj_Content[i] if not contentItem then contentItem = self:InstantiateCollection(self.obj_Content, self.btn_RewardTemplate.gameObject) end UIUtils.SetRectPosition(contentItem.gameObject, bgWidthSpace * i, 0) UIUtils.SetLabel(contentItem.txt_RewardDays, string.FormatByIdsId(IDS_SumSignDay, v.MonthlyDay)) if MDL.DailySignin.IsReceiveDailyGiftsByMonthlyDay(v.MonthlyDay) then contentItem.State_Reward:SetState(0) contentItem.effect_Reward:StopUIEffect() else if v.MonthlyDay <= monthDaysCount then -- 本月没有领取过奖励 并且 可领取的时候 contentItem.effect_Reward:PlayUIEffect() contentItem.State_Reward:SetState(1) else contentItem.effect_Reward:StopUIEffect() contentItem.State_Reward:SetState(2) end end UIUtils.SetActive(contentItem.gameObject, true) end for i = #self.monthGiftsDataList + 1, #self.obj_Content do UIUtils.SetActive(self.obj_Content[i].gameObject, false) end self:RefreshMonthProgress() end -- 月签到进度计算(不等间距) function UIDailySignin:RefreshMonthProgress() local monthDaysCount = MDL.DailySignin.GetMonthDaysCount() local progressSpace = 1 / #self.monthGiftsDataList -- 计算通过多少完整的签到 local progressSpacePassIndex = 0 for i, v in ipairs(self.monthGiftsDataList) do if v.MonthlyDay <= monthDaysCount then progressSpacePassIndex = i end end -- 计算距离最后一个通过的签到之后的距离 local extra = 0 if progressSpacePassIndex < #self.monthGiftsDataList then local nextMothGiftData = self.monthGiftsDataList[progressSpacePassIndex + 1] local curMonthlyDay = progressSpacePassIndex == 0 and 0 or self.monthGiftsDataList[progressSpacePassIndex].MonthlyDay extra = progressSpace / (nextMothGiftData.MonthlyDay - curMonthlyDay) * (monthDaysCount - curMonthlyDay) end self.img_ProgressBar.fillAmount = progressSpacePassIndex * progressSpace + extra end return UIDailySignin