require("Base/BasePanel") local FifteenDayGift = Inherit(BasePanel) local this = FifteenDayGift local sortingOrder = 0 local Data local itemConfig = ConfigManager.GetConfig(ConfigName.ItemConfig) local itemList = {} local ItemViewList = {} local frontList = {} local backList = {} local angle = { [1] = Quaternion.Euler(Vector3.New(0, 0, 0)), [2] = Quaternion.Euler(Vector3.New(0, 90, 0)), } --初始化组件(用于子类重写) function FifteenDayGift:InitComponent() self.backBtn1 = Util.GetGameObject(self.gameObject,"Content/btnBack1") self.backBtn2 = Util.GetGameObject(self.gameObject,"Content/btnBack2") self.backBtn3 = Util.GetGameObject(self.gameObject,"Content/btnBack3") self.btnGet = Util.GetGameObject(self.gameObject,"Content/btnGet") self.redPoint = Util.GetGameObject(self.btnGet,"redPoint") self.rewardGrid = Util.GetGameObject(self.gameObject,"Content/RewardGrid") self.effect1 = Util.GetGameObject(self.gameObject,"Content/UI_Effect_MianBan_15Day_DengLu") self.effect2 = Util.GetGameObject(self.gameObject,"Content/UI_Effect_MianBan_BaiZe_01") self.effect2:SetActive(false) for i = 1, self.rewardGrid.transform.childCount do table.insert(itemList, self.rewardGrid.transform:GetChild(i - 1)) end end --绑定事件(用于子类重写) function FifteenDayGift:BindEvent() Util.AddClick(self.backBtn1,function () self:ClosePanel() end) Util.AddClick(self.backBtn2,function () self:ClosePanel() end) Util.AddClick(self.backBtn3,function () self:ClosePanel() end) Util.AddClick(self.btnGet,function () if #frontList == 0 then PopupTipPanel.ShowTip(Language[12285]) return end FifteenDayGift:Request() end) BindRedPointObject(RedPointType.FifteenDayGift_1,self.redPoint) end function FifteenDayGift:Request(missionId,obj) local id = missionId and missionId or -1 NetManager.GetActivityRewardRequest(id,Data.activityId,function (drop) if obj then -- 单个领取 local thread=coroutine.start(function() obj[1].transform:DORotate(Vector3.New(0, 90, 0), 0.3) coroutine.wait(0.3) obj[1]:SetActive(false) obj[2].transform:DORotate(Vector3.New(0, 0, 0), 0.3) coroutine.wait(1) end) else--全部领取 for i = 1, #frontList do local thread=coroutine.start(function() frontList[i].transform:DORotate(Vector3.New(0, 90, 0), 0.3) coroutine.wait(0.3) frontList[i]:SetActive(false) backList[i].transform:DORotate(Vector3.New(0, 0, 0), 0.3) coroutine.wait(1) end) end end --奖励界面 local func = function (drop) UIManager.OpenPanel(UIName.RewardItemPopup, drop, 1,function() FifteenDayGift:Refresh() CheckRedPointStatus(RedPointType.FifteenDayGift_1) end) end Timer.New(function () --检测奖励是否为灵兽 if drop.pokemon and #drop.pokemon >= 1 then local thread=coroutine.start(function() self.effect2:SetActive(true) coroutine.wait(3) UIManager.OpenPanel(UIName.PokemonSingleResultPanel,nil,drop,nil,nil,function () self.effect2:SetActive(false) func(drop) end) end) else func(drop) end end,0.5):Start() end) end --添加事件监听(用于子类重写) function FifteenDayGift:AddListener() end --移除事件监听(用于子类重写) function FifteenDayGift:RemoveListener() end function FifteenDayGift:OnSortingOrderChange() Util.AddParticleSortLayer(self.effect1, self.sortingOrder - sortingOrder) Util.AddParticleSortLayer(self.effect2, self.sortingOrder - sortingOrder) sortingOrder = self.sortingOrder end --界面打开时调用(用于子类重写) function FifteenDayGift:OnOpen() end -- 打开,重新打开时回调 function FifteenDayGift:OnShow() FifteenDayGift:Refresh() end function FifteenDayGift:Refresh() if UIManager.IsOpen(UIName.FightAreaRewardFullPopup) then UIManager.ClosePanel(UIName.FightAreaRewardFullPopup) end Data = FifteenDayGiftManager.GetData() CheckRedPointStatus(RedPointType.FifteenDayGift_1) if self.timer then self.timer:Stop() self.timer = nil end frontList = {} backList = {} FifteenDayGift:SetReward() end function FifteenDayGift:SetReward() if Data and #Data.rewards > 0 then for i = 1, #itemList do FifteenDayGift:SetSingleReward(Data.rewards[i],itemList[i],i) end end end function FifteenDayGift:SetSingleReward(sData,go,index) local front = Util.GetGameObject(go,"front") local name = Util.GetGameObject(front,"name"):GetComponent("Text") local icon = Util.GetGameObject(front,"icon"):GetComponent("Image") local num = Util.GetGameObject(front,"num"):GetComponent("Text") local back = Util.GetGameObject(go,"back") local red = Util.GetGameObject(front,"red") local mask = Util.GetGameObject(front,"mask")--单个奖励领取按钮 red:SetActive(false) mask:SetActive(false) local curTime = GetTimeStamp() --弄一个ItemView提供点击方法 if not ItemViewList[index] then local view = SubUIManager.Open(SubUIConfig.ItemView,icon.transform) ItemViewList[index] = view end ItemViewList[index]:OnOpen(false,sData.Reward,0,false) ItemViewList[index].gameObject:SetActive(false) --设置图片初始角度 front:GetComponent("RectTransform").rotation = sData.State == 0 and angle[1] or angle[2] back:GetComponent("RectTransform").rotation = sData.State == 1 and angle[1] or angle[2] --判断哪些可领取,插入表 -- LogPurple("sData.missionId:"..tostring(sData.missionId).." sData.Progress:"..tostring(sData.Progress).." sData.State:"..tostring(sData.State)) if sData.Progress <= curTime and sData.State == 0 then -- LogPink("index:"..tostring(index)) table.insert(frontList,front) table.insert(backList,back) red:SetActive(true) mask:SetActive(true) end --如果已领取、可领取、不可领取显示第几天;下一领取显示时间 if sData.Progress > curTime and sData.Progress - 86400 <= curTime then local time = sData.Progress - GetTimeStamp() name.text = TimeToFelaxible(time) if self.timer then self.timer:Stop() self.timer = nil end self.timer = Timer.New(function() time = time - 1 if time <= 0 then self.timer:Stop() self.timer = nil FifteenDayGift:Refresh() end name.text = TimeToFelaxible(time) end, 1, -1, true) self.timer:Start() else name.text = string.format(Language[10528],NumToSimplenessFont[index]) end --设置icon 和数量 icon.sprite = SetIcon(sData.Reward[1]) num.text = string.format("× %s",sData.Reward[2]) Util.AddOnceClick(icon.gameObject,function () ItemViewList[index]:OnBtnCkickEvent(sData.Reward[1]) end) Util.AddOnceClick(mask,function () FifteenDayGift:Request(sData.missionId,{front,back}) end) end --界面关闭时调用(用于子类重写) function FifteenDayGift:OnClose() if self.timer then self.timer:Stop() self.timer = nil end end --界面销毁时调用(用于子类重写) function FifteenDayGift:OnDestroy() if self.timer then self.timer:Stop() self.timer = nil end itemList = {} ItemViewList = {} frontList = {} backList = {} ClearRedPointObject(RedPointType.FifteenDayGift_1,self.redPoint) end return FifteenDayGift