local UISignInGift = UIViewClass() local EventSystem = require('Event/EventSystem') local IconRareType = { Normal = 1, Rare = 2, Epic = 3, } local IconType = { Item = 1, Hero = 2, Weapon = 3, HeroMask = 4, } function UISignInGift:OnOpened(context) CTL.SignIn.RecordNoticeState() self:RegistSystemEvent(EventID.UI_StageSignIn_AcquireReward, self.InitPanel) self:RegistSystemEvent(EventID.UI_OperationActivity_DataChanged, self.InitPanel) self:RegistSystemEvent(EventID.UI_OperationActivity_InfoChanged, self.InitPanel) self.activityType = MDL.OperationActivity.ActivityType.StageSignIn local typeInfoList = MDL.OperationActivity.GetOperationActivityInfo(self.activityType) local index, table = next(typeInfoList) self.activityId = table.activityId self.segmentLength = CTL.SignIn.DayCountPerSegment() if context then self.activityId = context.activityId self.curStageId = context.stageId end self:InitPanel(self.curStageId) MDL.SignIn.RemoveDelayViewActivityId(self.activityId) end function UISignInGift:SetTitle(id) local cfg = DataSheetManager.NewPlayerLoginReward:GetDataByModeID(id) if self.loc_Title.CurState == 0 then UIUtils.SetLocalizationImage(self.img_Title, cfg.TextPicture) self.img_Title:SetNativeSize() else UIUtils.SetLabelText(self.txt_Title, Const_IDS[cfg.TextIDS]) end self.state_ActivityUI:SetState(cfg.BlockPicture) EventSystem.Dispatch(EventID.UI_WelfareBase_ChangeBGPath, cfg.BGPicture) end function UISignInGift:CheckIfClose() local info = MDL.OperationActivity.GetOperationActivityInfo(self.activityType, self.activityId) if not CTL.OperationActivity.IsOperationActivityOpen(info) then CTL.PushInterface.HidePushInterface(self.__viewClassPath, self.toggle_Skip) self:CloseView() EventSystem.Dispatch(EventID.UI_WelfareBase_RefreshEventList) end end function UISignInGift:InitPanel(stageId) self:CheckIfClose() self.curStageId = stageId or CTL.SignIn.GetCurrentShowStageId(self.activityId) self.curSelectActivitySegment = math.ceil(self.curStageId / self.segmentLength) self:RefreshPanel() end function UISignInGift:RefreshPanel() self:RefreshGiftRewardShow() local relativeStageID = self:GetRelativeStageId(CTL.SignIn.GetCurrentShowStageId(self.activityId)) self.loop_Gift:SelectIndex(relativeStageID - 1) self.loop_Gift:MoveIndex(relativeStageID - 2) --策划要求前面预留一格,C# MoveIndex接口会对小于0的值直接return self:RefreshSelectSegmentBtn() end function UISignInGift:RefreshGiftRewardShow() if self.loop_Gift.Count > 0 then self.loop_Gift:ClearCells() end local segmentPassed = self.curSelectActivitySegment - 1 for i, v in MDL.OperationActivity.StageSignIn:GetEnumeratorByActivityID(self.activityId) do if i > segmentPassed * self.segmentLength and i <= (segmentPassed + 1) * self.segmentLength then self.loop_Gift:AddData(v, 0) --只显示当期间隔内的数据 end end end function UISignInGift:RefreshSelectSegmentBtn() -- stage已经到达第二期,不显示第一期 if CTL.SignIn.GetCurrentShowStageId(self.activityId) <= self.segmentLength then local isSelectFirseSegment = self.curSelectActivitySegment == 1 --当前所选期是第一期 UIUtils.SetActive(self.btn_NextSegment, isSelectFirseSegment) UIUtils.SetActive(self.btn_LastSegment, not isSelectFirseSegment) else UIUtils.SetActive(self.btn_NextSegment, false) UIUtils.SetActive(self.btn_LastSegment, false) end end function UISignInGift:RefreshStageReward(stageId) self.curStageId = stageId local data = MDL.OperationActivity.StageSignIn:GetDataByActivityID_StageID(self.activityId, stageId) local path, id = self:DecodeData(data.DisplayPicPath) UIUtils.SetImageByAssetBundle(self.img_Hero, path) self:SetTitle(id) self.img_Hero:SetNativeSize() local displayText = self:DecodeData2(data.DisplayTextPath) UIUtils.SetLabelText(self.txt_Name, Const_IDS[displayText]) UIUtils.SetLabelText(self.txt_CollectionDate, Const_IDS[data.DisplayTextPath2]) local isCanCollect, leftDays = CTL.SignIn.IsStageSignInCanCollectReward(self.activityId, stageId) UIUtils.SetActive(self.btn_Collect, isCanCollect) self.btn_Collect:SetRedPoint(isCanCollect) UIUtils.SetActive(self.txt_CollectionTime, not self.btn_Collect.gameObject.activeSelf) if not isCanCollect and leftDays > 0 then local str if leftDays == 1 then str = "IDS_OperationActivity_Hint1" else str = "IDS_OperationActivity_Hint2" end self.txt_CollectionTime.text = string.FormatByIdsKey(str, leftDays) else if CTL.SignIn.IsStageSignInRewardCollected(self.activityId, stageId) then UIUtils.SetLabelText(self.txt_CollectionTime, Const_IDS["IDS_OperationActivity_Hint3"]) end end if self.loop_SignInReward.Count > 0 then self.loop_SignInReward:ClearCells() end for i, v in ipairs(data.Reward_Table) do self.loop_SignInReward:AddData(v, 0) end end function UISignInGift:OnBackButtonPressed() self:OnButtonClicked(self.btn_Close) end function UISignInGift:OnButtonClicked(comp) if comp == self.btn_Collect then MDL.SignIn.AcquireStateSignRewardReq(self.activityId, self.curStageId) elseif comp == self.btn_Close then CTL.PushInterface.HidePushInterface(self.__viewClassPath, self.toggle_Skip) self:CloseView() elseif comp == self.btn_NextSegment then self.curSelectActivitySegment = self.curSelectActivitySegment + 1 self:RefreshPanel() elseif comp == self.btn_LastSegment then self.curSelectActivitySegment = self.curSelectActivitySegment - 1 self:RefreshPanel() end end function UISignInGift:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.loop_Gift then cellTable.state_Icon:SetState(data.DisplayIconType - 1)--123映射至012 if data.DisplayIconType == IconType.Item then UIUtils.SetImageByAssetBundle(cellTable.img_ItemIcon, data.DisplayIconPath) elseif data.DisplayIconType == IconType.Hero then UIUtils.SetImageByAssetBundle(cellTable.img_HeroHead, data.DisplayIconPath) elseif data.DisplayIconType == IconType.Weapon then UIUtils.SetImageByAssetBundle(cellTable.img_Weapon, data.DisplayIconPath) elseif data.DisplayIconType == IconType.Weapon then UIUtils.SetImageByAssetBundle(cellTable.img_Weapon, data.DisplayIconPath) elseif data.DisplayIconType == IconType.HeroMask then UIUtils.SetImageByAssetBundle(cellTable.img_GoldenHero, data.DisplayIconPath) end UIUtils.SetActive(cellTable.img_BgBlue, data.DisplayIconRareType == IconRareType.Normal) UIUtils.SetActive(cellTable.img_BgRed, data.DisplayIconRareType == IconRareType.Rare) UIUtils.SetActive(cellTable.img_BgYellow, data.DisplayIconRareType == IconRareType.Epic) local isCollected = CTL.SignIn.IsStageSignInRewardCollected(data.ActivityID, data.StageID) UIUtils.SetActive(cellTable.mask_Received, isCollected) if CTL.SignIn.IsStageSignInCanCollectReward(data.ActivityID, data.StageID) then cellTable.cell:SetRedPoint(true) cellTable.effect_CanCollect:PlayUIEffect() else cellTable.cell:SetRedPoint(false) cellTable.effect_CanCollect:StopUIEffect() end local relativeStageID = self:GetRelativeStageId(data.StageID) UIUtils.SetLabelText(cellTable.txt_Date, Const_IDS["IDS_OperationActivity_Day" .. relativeStageID]) elseif scrollRect == self.loop_SignInReward then UIUtils.SetActive(cellTable.mask_ItemReceived, CTL.SignIn.IsStageSignInRewardCollected(self.activityId, self.curStageId)) UTL.Item.SetItemCell(cellTable.item, data.RewardID, data.RewardNum) end end --当前这一期内相对的id,不是绝对id function UISignInGift:GetRelativeStageId(stageId) local curSelectSegmentStartStage = (self.curSelectActivitySegment - 1) * self.segmentLength + 1 local curSelectSegmentEndStage = self.curSelectActivitySegment * self.segmentLength --在所选当期时,定位具体相对id if stageId > curSelectSegmentStartStage and stageId <= curSelectSegmentEndStage then return stageId - curSelectSegmentStartStage + 1 end return 1 end function UISignInGift:OnCellSelect(scrollRect, index, cellTable, data) if scrollRect == self.loop_Gift then self:RefreshStageReward(data.StageID) self.context = {stageId = data.StageID, activityId = self.activityId} end end function UISignInGift:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.loop_SignInReward then UTL.ItemTips.ShowCommonTipsById(data.RewardID) end end --xxx.png|modeId function UISignInGift:DecodeData(content) local pairSplits = string.split(content,"|") if #pairSplits < 2 then return content, 1 end return pairSplits[1], tonumber(pairSplits[2]) end --ids function UISignInGift:DecodeData2(content) local pairSplits = string.split(content,"|") return pairSplits[1] end return UISignInGift