require("Base/BasePanel") local PowerRice = Inherit(BasePanel) local globalActConfig = ConfigManager.GetConfig(ConfigName.GlobalActivity) local this = PowerRice local STATE = { [0] = {Img = "Btn_hz_cheng_01",text = Language[10556]}, [1] = {Img = "Btn_hz_cheng_01",text = Language[11948]}, [2] = {Img = "Btn_hz_lan_01",text = Language[10101]}, [3] = {Img = "Btn_hz_lan_01",text = "已结束"}, } local TabBoxRedPoints = {} local TabBox = require("Modules/Common/TabBox") local _TabData={ [1] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "战力目标",redPointType = RedPointType.PowerRiceGool}, [2] = { default = "r_hero_xuanze_002", select = "r_hero_xuanze_001", name = "战力排名"}, } local _TabFontColor = { default = Color.New(130 / 255, 128 / 255, 120 / 255, 1), select = Color.New(243 / 255, 235 / 255, 202 / 255, 1)} local curIndex = 1 --初始化组件(用于子类重写) function PowerRice:InitComponent() this.spLoader = SpriteLoader.New() self.UpView = SubUIManager.Open(SubUIConfig.UpView, self.transform) self.btnBack = Util.GetGameObject(self.gameObject,"BackBtn") self.tabBox = Util.GetGameObject(self.gameObject, "TabBox") self.leftTime = Util.GetGameObject(self.gameObject,"bg/timeBg/LeftTime"):GetComponent("Text") self.text1 = Util.GetGameObject(self.gameObject,"bg/tiao/Text1"):GetComponent("Text") self.text2 = Util.GetGameObject(self.gameObject,"bg/tiao/Text4"):GetComponent("Text") self.power = Util.GetGameObject(self.gameObject,"power"):GetComponent("Text") self.grid = Util.GetGameObject(self.gameObject,"bg/ren") self.Scroll = Util.GetGameObject(self.gameObject,"Scroll") self.itemPre = Util.GetGameObject(self.gameObject,"itemPre") self.itemPre2 = Util.GetGameObject(self.gameObject,"itemPre2") self.helpBtn = Util.GetGameObject(self.gameObject, "helpBtn") self.helpPosition = self.helpBtn:GetComponent("RectTransform").localPosition self.rankBtn = Util.GetGameObject(self.gameObject, "rankBtn") local rootHight = self.Scroll.transform.rect.height local width = self.Scroll.transform.rect.width self.ScrollList = {} self.ScrollList[1] = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.Scroll.transform, self.itemPre, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0)) self.ScrollList[1].moveTween.MomentumAmount = 1 self.ScrollList[1].moveTween.Strength = 2 self.ScrollList[1].elastic = false self.ScrollList[2] = SubUIManager.Open(SubUIConfig.ScrollCycleView, self.Scroll.transform, self.itemPre2, nil, Vector2.New(width, rootHight), 1, 1, Vector2.New(0, 0)) self.ScrollList[2].moveTween.MomentumAmount = 1 self.ScrollList[2].moveTween.Strength = 2 self.ScrollList[2].elastic = false self.itemList = {} end --绑定事件(用于子类重写) function PowerRice:BindEvent() Util.AddClick(self.btnBack, function() self:ClosePanel() end) Util.AddClick(self.helpBtn, function() UIManager.OpenPanel(UIName.HelpPopup, HELP_TYPE.PowerRice, self.helpPosition.x,self.helpPosition.y) end) Util.AddClick(self.rankBtn, function() UIManager.OpenPanel(UIName.RankingSingleListPanel,rankKingList[34]) end) TabBoxRedPoints = {} self.TabCtrl = TabBox.New() self.TabCtrl:SetTabAdapter(this.TabAdapter) self.TabCtrl:SetChangeTabCallBack(this.SwitchView) self.TabCtrl:Init(self.tabBox, _TabData) for i = 1, #_TabData do TabBoxRedPoints[i] = Util.GetGameObject(self.tabBox, "box/tab"..i.."/Redpot") if _TabData[i] and _TabData[i].redPointType and TabBoxRedPoints[i] then BindRedPointObject(_TabData[i].redPointType,TabBoxRedPoints[i]) end end end --添加事件监听(用于子类重写) function PowerRice:AddListener() end --移除事件监听(用于子类重写) function PowerRice:RemoveListener() end -- tab节点显示自定义 function this.TabAdapter(tab, index, status) local tabLab = Util.GetGameObject(tab, "Text") Util.GetGameObject(tab,"Image"):GetComponent("Image").sprite = this.spLoader:LoadSprite(_TabData[index][status]) tabLab:GetComponent("Text").text = _TabData[index].name tabLab:GetComponent("Text").color = _TabFontColor[status] end --切换视图 function this.SwitchView(index) --先执行上一面板关闭逻辑 curIndex = index PowerRice:Refresh(curIndex,true,true) end --界面打开时调用(用于子类重写) function PowerRice:OnOpen() end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function PowerRice:OnShow() if curIndex ~= 1 then this.TabCtrl:ChangeTab(1) end end function PowerRice:Refresh(_curIndex,isTop,isAni) self.power.text = PlayerManager.maxForce for index, value in ipairs(self.ScrollList) do value.gameObject:SetActive(index == _curIndex) end RankingManager.InitData(RANK_TYPE.POWER_RICE,function () local allRankData,myRankData = RankingManager.GetRankingInfo() self.myRank = myRankData.rank self.myPower = myRankData.param1 CommonActPageManager.powerRicePower = myRankData.param1 self.actData = CommonActPageManager.GetData(ActivityTypeDef.PowerRice) if _curIndex == 1 then PowerRice:SetRewards1(isTop,isAni) self.text1.text = "目标战力" self.text2.text = "奖励 领取奖励" elseif _curIndex == 2 then self.text1.text = "名次" self.text2.text = "奖励 战力要求" PowerRice:SetRewards2(isTop,isAni) end PowerRice:SetTime() PowerRice:SetLive2D() end,0) end function PowerRice:SetLive2D() --设置立绘 if not self.Live then self.Live = poolManager:LoadLive("live2d_h_puti", self.grid.transform, Vector3.one*0.9, Vector2.zero) self.Live:GetComponent("SkeletonGraphic").AnimationState:SetAnimation(0, "idle", true) end end --================战力目标==================== function PowerRice:SetRewards1(isTop,isAni) self.ScrollList[1]:SetData(self.actData.rewards, function (index, go) PowerRice:SingleDataShow(go, self.actData.rewards[index],index) end,not isTop,not isAni) end function PowerRice:SingleDataShow(item,data,index) local powerNum = Util.GetGameObject(item,"num"):GetComponent("Text") local reward = Util.GetGameObject(item,"reward") local getBtn = Util.GetGameObject(item,"getBtn") local btnImage = Util.GetGameObject(item,"getBtn"):GetComponent("Image") local btnText = Util.GetGameObject(item,"getBtn/Text"):GetComponent("Text") local gapTime = globalActConfig[self.actData.activityId].GapTime*86400 local state = 0 if data.state == 1 then state = 2 elseif data.otherData.Values[1][1] > self.myPower then state = 0 if self.actData.endTime - GetTimeStamp() < gapTime then state = 3 end else state = 1 end powerNum.text = (data.otherData.Values[1][1]/10000).."万" btnImage.sprite = this.spLoader:LoadSprite(STATE[state].Img) btnText.text = STATE[state].text if not self.itemList[item] then self.itemList[item] = {} end for i = 1, #data.otherData.Reward do if not self.itemList[item][i] then self.itemList[item][i] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform) end self.itemList[item][i]:OnOpen(false, data.otherData.Reward[i], 0.8,false,false,false,self.sortingOrder) end Util.AddOnceClick(getBtn,function () if state == 0 then -- PopupTipPanel.ShowTip("请前往山河社稷图获取更多星星!") JumpManager.GoJump(22001) elseif state == 1 then NetManager.GetActivityRewardRequest(data.missionId,self.actData.activityId,function (_drop) CheckRedPointStatus(RedPointType.PowerRiceGool) UIManager.OpenPanel(UIName.RewardItemPopup,_drop,1,function() PowerRice:Refresh(curIndex,false,false) end) end) elseif state == 3 then PopupTipPanel.ShowTip("活动已结束") end end) getBtn:GetComponent("Button").interactable = state ~= 2 end --=======================战力排名=========================== function PowerRice:SetRewards2(isTop,isAni) local data = ConfigManager.GetAllConfigsDataByKey(ConfigName.ActivityRankingReward,"ActivityId",self.actData.activityId) this.ScrollList[2]:SetData(data, function (index, go) PowerRice:SingleDataShow2(go, data[index],index) end,not isTop,not isAni) end function PowerRice:SingleDataShow2(item,data,index) local sortNumTabs = {} for i = 1, 4 do sortNumTabs[i] = Util.GetGameObject(item, "SortNum/SortNum ("..i..")") sortNumTabs[i]:SetActive(false) end local reward = Util.GetGameObject(item,"reward") local sort4Text = Util.GetGameObject(sortNumTabs[4],"TitleText"):GetComponent("Text") local mark = Util.GetGameObject(item,"mark") mark:SetActive(self.myRank > 0 and self.myRank >= data.MinRank and self.myRank <= data.MaxRank) local powerLimit = Util.GetGameObject(item,"num"):GetComponent("Text") powerLimit.text = "" if data.RankLimit and data.RankLimit[2]>0 then powerLimit.text = (data.RankLimit[2]/10000).."万" end if data.MinRank == data.MaxRank then if data.MaxRank < 4 then sortNumTabs[data.MinRank]:SetActive(true) else sortNumTabs[4]:SetActive(true) sort4Text.text = data.MaxRank end else sortNumTabs[4]:SetActive(true) if data.MaxRank < 0 then sort4Text.text = data.MinRank .."+" else sort4Text.text = data.MinRank .."-".. data.MaxRank end end if not self.itemList[item] then self.itemList[item] = {} end for i = 1, #data.RankingReward do if not self.itemList[item][i] then self.itemList[item][i] = SubUIManager.Open(SubUIConfig.ItemView,reward.transform) end self.itemList[item][i]:OnOpen(false, data.RankingReward[i], 0.8,false,false,false,self.sortingOrder) end end --设置时间 function PowerRice:SetTime() --设置时间 if self.timer then self.timer:Stop() self.timer = nil end local time =self.actData.endTime - GetTimeStamp() local gapTime = globalActConfig[self.actData.activityId].GapTime*86400 local text = Language[10512] if time > gapTime then time = time - gapTime else text = "活动关闭时间:" end self.leftTime.text = string.format("%s%s",text,TimeToFelaxible(time)) self.timer = Timer.New(function () time = time - 1 self.leftTime.text = string.format("%s%s",text,TimeToFelaxible(time)) if time <= 0 then self:ClosePanel() end end,1,-1,true) self.timer:Start() end --界面关闭时调用(用于子类重写) function PowerRice:OnClose() if self.timer then self.timer:Stop() self.timer = nil end end --界面销毁时调用(用于子类重写) function PowerRice:OnDestroy() if self.timer then self.timer:Stop() self.timer = nil end self.ScrollList = {} self.itemList = {} this.spLoader:Destroy() self.Live = nil for i = 1, #_TabData do if _TabData[i] and _TabData[i].redPointType and TabBoxRedPoints[i] then ClearRedPointObject(_TabData[i].redPointType,TabBoxRedPoints[i]) end end curIndex = 1 end return PowerRice