require("Base/BasePanel") local OnlineRewardPanel = Inherit(BasePanel) local this = OnlineRewardPanel local itemPreList={} --item预设容器 local orginLayer = 0 function OnlineRewardPanel:InitComponent() this.closeBtn = Util.GetGameObject(this.gameObject,"show/btnBack") this.preViewBtn = Util.GetGameObject(this.gameObject,"show/bg/preview") this.light = Util.GetGameObject(this.gameObject,"light") this.time = Util.GetGameObject(this.gameObject,"show/timeCount/time"):GetComponent("Text") end function OnlineRewardPanel:showReward() ActivityGiftManager.onlineData = {} for i, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)) do --获取在线礼包数据 if (v.ActivityId == ActivityTypeDef.OnlineGift) then table.insert(ActivityGiftManager.onlineData, v) end end table.sort(ActivityGiftManager.onlineData, function(a, b) return a.Id < b.Id end) for i=1,#ActivityGiftManager.onlineData do this.root=Util.GetGameObject(this.gameObject,"show/bg/Grid/RewardView"..i.."/root") if not itemPreList[i] then itemPreList[i] = SubUIManager.Open(SubUIConfig.ItemView,this.root.transform) end itemPreList[i]:OnOpen(false, {ActivityGiftManager.onlineData[i].Reward[1][1], ActivityGiftManager.onlineData[i].Reward[1][2]}, 0.9,true, false, false, self.sortingOrder) --itemPreList[i]:ResetNameColor(Vector4.New(1,1,1,1)) itemPreList[i]:ResetNameSize(Vector3.New(0,-95,0),Vector3.New(1.3,1.3,1)) end OnlineRewardPanel:OnShowActivityData() end --面板刷新 function OnlineRewardPanel:OnShowActivityData() ActivityGiftManager.onlineData = {} for i, v in ConfigPairs(ConfigManager.GetConfig(ConfigName.ActivityRewardConfig)) do --获取在线礼包数据 if (v.ActivityId == ActivityTypeDef.OnlineGift) then table.insert(ActivityGiftManager.onlineData, v) end end table.sort(ActivityGiftManager.onlineData, function(a, b) return a.Id < b.Id end) for i=1,#ActivityGiftManager.onlineData do --local item = Util.GetGameObject(this.gameObject,"show/bg/Grid/RewardView"..i.."/root/ItemView") local redPoint = Util.GetGameObject(this.gameObject,"show/bg/Grid/RewardView"..i.."/root/ItemView/redPoint") local flag = Util.GetGameObject(this.gameObject,"show/bg/Grid/RewardView"..i.."/flag") local btn = Util.GetGameObject(this.gameObject,"show/bg/Grid/RewardView"..i.."/btn") btn:SetActive(true) local onlineRewardEffect = Util.GetGameObject(this.gameObject, "show/bg/Grid/RewardView"..i.."/root/ItemView/effects/UI_Effect_Kuang_JinSe") local onlineRewardEffect2 = Util.GetGameObject(this.gameObject, "show/bg/Grid/RewardView"..i.."/root/ItemView/effects/UI_effect_WuCai_Kuang") if(i<=ActivityGiftManager.currentTimeIndex)then--是否达到领奖时长 if(ActivityGiftManager.onlineGetRewardState[ActivityGiftManager.onlineData[i].Id]==0)then--奖励是否领取 if(redPoint)then redPoint:SetActive(true) end --打开特效 onlineRewardEffect:SetActive(true) onlineRewardEffect2:SetActive(true) flag:SetActive(false) Util.AddOnceClick(btn,function() flag:SetActive(true) redPoint:SetActive(false) btn:SetActive(false) if(onlineRewardEffect)then onlineRewardEffect:SetActive(false) onlineRewardEffect2:SetActive(false) end NetManager.GetActivityRewardRequest(ActivityGiftManager.onlineData[i].Id, ActivityTypeDef.OnlineGift, function(_drop) UIManager.OpenPanel(UIName.RewardItemPopup, _drop, 1,function() ActivityGiftManager.onlineGetRewardState[ActivityGiftManager.onlineData[i].Id] = 1 this.Refresh() Game.GlobalEvent:DispatchEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess) end) end) end) elseif (ActivityGiftManager.onlineGetRewardState[ActivityGiftManager.onlineData[i].Id]==1) then flag:SetActive(true) btn:SetActive(false) if(onlineRewardEffect)then onlineRewardEffect:SetActive(false) onlineRewardEffect2:SetActive(false) end end else if(onlineRewardEffect)then onlineRewardEffect:SetActive(false) onlineRewardEffect2:SetActive(false) end Util.AddOnceClick(btn,function() PopupTipPanel.ShowTip(Language[11441]) end) end end end --绑定事件(用于子类重写) function OnlineRewardPanel:BindEvent() Util.AddClick(this.closeBtn,function() this:ClosePanel() end) Util.AddClick(this.light,function() this:ClosePanel() end) end --添加事件监听(用于子类重写) function OnlineRewardPanel:AddListener() end --移除事件监听(用于子类重写) function OnlineRewardPanel:RemoveListener() end function OnlineRewardPanel.Refresh() OnlineRewardPanel:showReward() OnlineRewardPanel:RemainTimeDown() end function OnlineRewardPanel:OnSortingOrderChange() --初试创建List中为0 if(#itemPreList ~= 0)then for i=1,#itemPreList do itemPreList[i]:SetEffectLayer(self.sortingOrder) end end end --界面打开时调用(用于子类重写) function OnlineRewardPanel:OnOpen(...) end -- 打开,重新打开时回调 function OnlineRewardPanel:OnShow() this.Refresh() end --界面关闭时调用(用于子类重写) function OnlineRewardPanel:OnClose() if self.timer then self.timer:Stop() self.timer = nil end Game.GlobalEvent:DispatchEvent(GameEvent.OnlineGift.GetOnlineRewardSuccess) --self:SetEffectLayer(-self.orginLayer) end --界面销毁时调用(用于子类重写) function OnlineRewardPanel:OnDestroy() itemPreList={} end --在线奖励刷新 --刷新倒计时显示 function OnlineRewardPanel:RemainTimeDown() self:RemainTimeDownUpdata() if ActivityGiftManager.currentTimeIndex == #ActivityGiftManager.onlineData then this.time.text = "00:00:00" end if self.timer then self.timer:Stop() self.timer = nil end self.timer = Timer.New(function() if NetManager.IsConnect() then--是否在线状态 self:RemainTimeDownUpdata() end if ActivityGiftManager.currentTimeIndex == #ActivityGiftManager.onlineData then self.timer:Stop() self.timer = nil this.time.text = "00:00:00" end end, 1, -1, true) self.timer:Start() end function OnlineRewardPanel:RemainTimeDownUpdata() local timeNum = GetTimeStamp() - ActivityGiftManager.cuOnLineTimestamp local newSort = 0 for i = 1, #ActivityGiftManager.onlineData do local curValue = ActivityGiftManager.onlineData[i].Values[1][1]*60 local curSort = ActivityGiftManager.onlineData[i].Sort if ActivityGiftManager.onlineGetRewardState[ActivityGiftManager.onlineData[i].Id] == 0 then if (math.floor(timeNum) >= curValue and newSort < curSort) then newSort = curSort end elseif ActivityGiftManager.onlineGetRewardState[ActivityGiftManager.onlineData[i].Id] == 1 then newSort = curSort end end if newSort ~= ActivityGiftManager.currentTimeIndex then ActivityGiftManager.currentTimeIndex = newSort this:OnShowActivityData(ActivityGiftManager.onlineData, ActivityTypeDef.OnlineGift, ActivityGiftManager.onlineGetRewardState, ActivityGiftManager.currentTimeIndex) end if(newSort<12)then this.time.text = TimeToHMS(ActivityGiftManager.onlineData[newSort+1].Values[1][1]*60-timeNum) else this.time.text ="00:00:00" end end return OnlineRewardPanel