require("Base/BasePanel") local TreasureStoreSeason2 = Inherit(BasePanel) local _DayTipImageFormat = "p_piaomialzhilv_paizi%2d" local _DayItemFormat = "第%s天" local _DayNum = 7 --初始化组件(用于子类重写) function TreasureStoreSeason2:InitComponent() self.spLoader = SpriteLoader.New() self.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn") self.dayTip = Util.GetGameObject(self.gameObject, "curDayTipImage/curDayTip"):GetComponent("Image") self.btnBack = Util.GetGameObject(self.gameObject, "btnBack") --日期list self.dayList = Util.GetGameObject(self.gameObject, "dayList") self.dayPre = Util.GetGameObject(self.gameObject, "dayList/dayPre") self.dayPre:SetActive(false) self.dayScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.dayList.transform,self.dayPre, nil, Vector2.New(self.dayList.transform.rect.width, self.dayList.transform.rect.height), 1, 1, Vector2.New(0, 0)) self.dayScrollView.moveTween.MomentumAmount = 1 self.dayScrollView.moveTween.Strength = 2 self.dayList = {} --礼包list self.giftList = Util.GetGameObject(self.gameObject, "giftList") self.giftPre = Util.GetGameObject(self.gameObject, "giftList/giftPre") self.giftPre:SetActive(false) self.giftScrollView = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.giftList.transform,self.giftPre, nil, Vector2.New(self.giftList.transform.rect.width, self.giftList.transform.rect.height), 1, 1, Vector2.New(0, 0)) self.giftScrollView.moveTween.MomentumAmount = 1 self.giftScrollView.moveTween.Strength = 2 self.giftList = {} self.itemViewList = {} self.firstIn = true end --绑定事件(用于子类重写) function TreasureStoreSeason2:BindEvent() Util.AddOnceClick(self.btnBack,function () self:ClosePanel() end) end --添加事件监听(用于子类重写) function TreasureStoreSeason2:AddListener() Game.GlobalEvent:AddEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.OnShow,self) end --移除事件监听(用于子类重写) function TreasureStoreSeason2:RemoveListener() Game.GlobalEvent:RemoveEvent(GameEvent.FiveAMRefresh.ServerNotifyRefresh, self.OnShow,self) end function TreasureStoreSeason2:OnSortingOrderChange() end --界面打开时调用(用于子类重写) function TreasureStoreSeason2:OnOpen() end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function TreasureStoreSeason2:OnShow() self.actData = CommonActPageManager.GetData(ActivityTypeDef.TreasureStoreSeason2) self:Refresh() end function TreasureStoreSeason2:Refresh() if self.firstIn then self.curSelect = self.actData.value self.firstIn = false end CheckRedPointStatus(RedPointType.TreasureStoreSeason2) self.dayTip.sprite = self.spLoader:LoadSprite("p_piaomialzhilv_paizi0"..self.curSelect) self:SetDayButton() self:SetGiftList() end --设置天数的 function TreasureStoreSeason2:SetDayButton() self.dayScrollView:SetData(self.actData.FreelyData, function (index, item) Util.GetGameObject(item,"name"):GetComponent("Text").text = string.format(_DayItemFormat,NumToChinese[index]) item:GetComponent("Image").sprite = self.spLoader:LoadSprite(self.curSelect == index and "p_piaomialzhilv_banzi21" or "p_piaomialzhilv_banzi2") Util.SetGray(item,index > self.actData.value) Util.AddOnceClick(item,function () if index > self.actData.value then PopupTipPanel.ShowTip(string.format("%s天后开启!",index - self.actData.value)) else self.curSelect = index self:Refresh() end end) local redPoint = Util.GetGameObject(item,"redPoint") redPoint:SetActive(false) for i = 1, #self.actData.FreelyData[index] do if self.actData.FreelyData[index][i].progress == 1 and self.actData.FreelyData[index][i].Price == 0 then redPoint:SetActive(true) end end end,false,true) end --设置礼包list function TreasureStoreSeason2:SetGiftList() self.giftScrollView:SetData(self.actData.FreelyData[self.curSelect], function (index, item) self:ShowSingleData(item,self.actData.FreelyData[self.curSelect][index],index) end) end function TreasureStoreSeason2:ShowSingleData(_go,_data,_index) local title = Util.GetGameObject(_go,"title/Text"):GetComponent("Text") local box = Util.GetGameObject(_go,"box") local buyBtn = Util.GetGameObject(_go,"buy") local price = Util.GetGameObject(buyBtn,"Text"):GetComponent("Text") local redPoint = Util.GetGameObject(buyBtn,"redPoint") local times = Util.GetGameObject(_go,"buyInfo"):GetComponent("Text") -- LogPink("Id:"..tostring(_data.Id).." PackId:"..tostring(_data.PackId).." progress:"..tostring(_data.progress)) title.text = _data.Name Util.SetGray(buyBtn,_data.progress == 8) Util.SetGray(redPoint,false) redPoint:SetActive(_data.progress == 1 and _data.Price == 0) times.gameObject:SetActive(_data.progress == 1) if _data.progress == 1 then times.gameObject:SetActive(true) times.text = string.format( "剩余:%s次",_data.canBuy) price.text = _data.Price.."元" else times.gameObject:SetActive(false) times.text = "" price.text = "已购买" end if not self.itemViewList[_go] then self.itemViewList[_go] = {} end for k,v in ipairs(self.itemViewList[_go]) do v.gameObject:SetActive(false) end for i = 1, #_data.Reward do local rewardData = _data.Reward[i] if not self.itemViewList[_go][i] then self.itemViewList[_go][i] = SubUIManager.Open(SubUIConfig.ItemView, box.transform) end self.itemViewList[_go][i]:OnOpen(false, rewardData, 0.8,false,false,false,self.sortingOrder) self.itemViewList[_go][i].gameObject:SetActive(true) end Util.AddOnceClick(buyBtn,function () if _data.progress == 1 then PayManager.Pay(_data.PackId, function(id) FirstRechargeManager.RefreshAccumRechargeValue(_data.PackId) self:OnShow() end) end end) end --界面关闭时调用(用于子类重写) function TreasureStoreSeason2:OnClose() self.firstIn = false end --界面销毁时调用(用于子类重写) function TreasureStoreSeason2:OnDestroy() self.spLoader:Destroy() self.itemViewList = {} self.giftList = {} self.dayList = {} end return TreasureStoreSeason2