local UIPetReproductionGet = UIViewClass() local TIME_EFFECT_WAIT = 3 function UIPetReproductionGet:OnOpened(context) self:RegistSystemEvent(EventID.UI_Pet_UpdateGlobalInfo, self.OnGlobalInfoUpdate) self.hasClickGet = false UIUtils.SetActive(self.UIPetPopUp.btn_Info, false) if self.UIPetPopUp.loc_Title.CurState == 0 then UIUtils.SetLocalizationImage(self.UIPetPopUp.img_Title, "UI_Pet/fz_bg_msz.png") else UIUtils.SetLabelText(self.UIPetPopUp.txt_Title, Const_IDS.IDS_PetReproduceTitle) end self:UpdateRewardInfo() self:UpdateState() end function UIPetReproductionGet:OnGlobalInfoUpdate() self:UpdateRewardInfo() end function UIPetReproductionGet:UpdateState() self:StopRepeatFunc(self.UpdateState) local state, seconds = MDL.Pet.GetPetBreedState() if state == MDL.Pet.BreedState.Finish then self.timer_Get:EndTimer() self.timer_Get:SetCDLabel(UIUtils.GetLocalizedTxt(Const_IDS.IDS_Pet_BornTimeAlready)) else self.timer_Get:ResetAndBeginCustomTimer(false, seconds, 0, UIUtils.GetLocalizedTxt(Const_IDS["IDS_PetReproduce6"]), 1) self:StartRepeatFunc(self.UpdateState, seconds, 1) end end function UIPetReproductionGet:OnClosed() UIUtils.SetActive(self.UIPetPopUp.btn_Info, true) end function UIPetReproductionGet:OnBackButtonPressed() self:OnButtonClicked(self.UIPetPopUp.btn_Close) end function UIPetReproductionGet:OnButtonClicked(comp) if comp == self.UIPetPopUp.btn_Close then self:CloseView() elseif comp == self.btn_Get then if self.hasClickGet == false and MDL.Pet.GetPetBreedState() == MDL.Pet.BreedState.Finish then self.hasClickGet = true self.effect_Egg:StopUIEffect() self.effect_Get:PlayUIEffect() --需要等待特效播完再请求 CTL.Sound.PlayGameSound("UI_egg_feed") self:StartRepeatFunc(self.ReqGetBreedResult, TIME_EFFECT_WAIT, 1) end elseif comp == self.btn_Reward then if self.canGetReward then MDL.Pet.RewardPetWeekBreedReq(1) else local _, hasReward = MDL.Pet.GetWeekBreedTimeInfo() if hasReward then CTL.Tips.AddTipsMsg(Const_IDS["IDS_ERRORCODE_4068_InfoCode_Pet_BornRewardGot"]) end UIUtils.SetActive(self.info_Reward, true) self:ShowRewardPreview() end elseif comp == self.btn_Close then UIUtils.SetActive(self.info_Reward, false) end end function UIPetReproductionGet:ShowRewardPreview() if self.hasInitReward then return end local rewardId = DataSheetManager.ConstData:GetDataByID("PetBreedWeeklyTaskRewardID").IntValue local rewardCfg = DataSheetManager.PetTaskRewardRepeat:GetDataByID(rewardId) self.ChestRewardScroll:ReloadAll(rewardCfg.Item_Table) self.hasInitReward = true end function UIPetReproductionGet:OnCellInit(scrollRect, index, cellTable, data) if scrollRect == self.ChestRewardScroll then UTL.Item.SetItemCell(cellTable.item, data.ItemID, data.ItemNum) end end function UIPetReproductionGet:OnCellClicked(scrollRect, index, cellTable, target, data) if scrollRect == self.ChestRewardScroll then UTL.ItemTips.ShowCommonTipsById(data.ItemID) end end function UIPetReproductionGet:UpdateRewardInfo() local totalTimes = DataSheetManager.ConstData:GetDataByID("PetBreedWeeklyTaskNum").IntValue local times, hasReward = MDL.Pet.GetWeekBreedTimeInfo() if times >= totalTimes and hasReward == false then self.canGetReward = true self.btn_Reward:SetRedPoint(true) else self.canGetReward = false self.btn_Reward:SetRedPoint(false) end self.txt_Times.text = times .. "/" .. totalTimes end function UIPetReproductionGet:ReqGetBreedResult() self:StopRepeatFunc(self.UpdateState) self.effect_Get:StopUIEffect() self:CloseView() MDL.Pet.BreedPetRewardReq() end return UIPetReproductionGet