require("Base/BasePanel") FightLevelSingleChapterPanel = Inherit(BasePanel) local this = FightLevelSingleChapterPanel local sortingOrder = 0 local boxList = {} local levelList = {} local chapterId = 0 local chapterData = {} local allMissionDailyBoxItemPres = {} --初始化组件(用于子类重写) function FightLevelSingleChapterPanel:InitComponent() self.btnBack = Util.GetGameObject(self.gameObject, "btnBack") this.chapterNameText = Util.GetGameObject(self.gameObject, "rightUp/chapterNameText"):GetComponent("Text") this.chapterNameImage = Util.GetGameObject(self.gameObject, "rightUp/starInfoBg/Image/Image"):GetComponent("Image") this.totalPro = Util.GetGameObject(self.gameObject, "rewardBg/totalProImage/totalPro"):GetComponent("Text") this.prb = Util.GetGameObject(self.gameObject, "middle/prb") this.rect = Util.GetGameObject(self.gameObject, "middle/rect") levelList = {} this.rewardBoxParent = Util.GetGameObject(self.gameObject, "middle/rewardBg/btnList") this.progressBottom = Util.GetGameObject(self.gameObject, "middle/rewardBg/progressBottom/Image"):GetComponent("Image") for i = 1, 3 do boxList[i] = Util.GetGameObject(self.gameObject, "middle/rewardBg/btnList/BoxBtn"..i) end this.leftBtn=Util.GetGameObject(self.gameObject,"middle/leftBtn") this.rightBtn=Util.GetGameObject(self.gameObject,"middle/rightBtn") this.leftBtnClick=Util.GetGameObject(self.gameObject,"middle/leftBtn/GameObject") this.rightBtnClick=Util.GetGameObject(self.gameObject,"middle/rightBtn/GameObject") --宝箱预览 this.rewardMaskBtn = Util.GetGameObject(self.gameObject, "middle/rewardMaskBtn") this.RewardPanelGetInfo = Util.GetGameObject(self.gameObject, "middle/rewardMaskBtn/RewardPanel/getInfo"):GetComponent("Text") this.RewardPanelGrid = Util.GetGameObject(self.gameObject, "middle/rewardMaskBtn/RewardPanel/ViewRect/grid") Util.GetGameObject(self.gameObject, "middle/rewardMaskBtn/RewardPanel/Image/Text"):GetComponent("Text").text = Language[10763] end --绑定事件(用于子类重写) function FightLevelSingleChapterPanel:BindEvent() Util.AddClick(self.btnBack, function() self:ClosePanel() end) Util.AddClick(this.leftBtnClick, function() this.LeftOrRightBtnClickEvent(1) end) Util.AddClick(this.rightBtnClick, function() this.LeftOrRightBtnClickEvent(2) end) Util.AddClick(this.rewardMaskBtn, function() this.rewardMaskBtn:SetActive(false) end) end function FightLevelSingleChapterPanel:OnSortingOrderChange() --特效层级重设 -- for i=1,#boxList do -- Util.AddParticleSortLayer(boxList[i], sortingOrder) -- end sortingOrder = self.sortingOrder end --界面打开时调用(用于子类重写) function FightLevelSingleChapterPanel:OnOpen(_chapterId) chapterId = _chapterId -- SoundManager.PlaySound(SoundConfig.Sound_WorldMap) end --界面打开或者重新打开后,界面刷新时调用(用于子类重写) function FightLevelSingleChapterPanel:OnShow() this.OnShowPanel() this.LeftOrRightBtnClickEvent() this.rewardMaskBtn:SetActive(false) end function this.OnShowPanel() chapterData = FightLevelManager.GetChapterData(chapterId) this.chapterNameText.text = chapterData.config.Name this.chapterNameImage.sprite = this.spLoader:LoadSprite(chapterData.config.BigNumber) if chapterData.node and LengthOfTable(chapterData.node) > 0 then local curchapterData = {} for key, value in pairs(chapterData.node) do table.insert(curchapterData,value) end table.sort(curchapterData, function(a,b) return a.nodeId < b.nodeId end) this.SetSingleLevel(curchapterData) end if chapterData.reward and LengthOfTable(chapterData.reward) > 0 then this.SetlevelBox(chapterData.reward) end end function this.SetSingleLevel(levelDatas) for i = 1, math.max(#levelDatas , #levelList) do local go = levelList[i] if not go then go = newObject(this.prb) go.transform:SetParent(this.rect.transform) go.name = "level"..i go.transform.localScale = Vector3.one go.transform.localPosition = Vector3.zero levelList[i] = go end go.gameObject:SetActive(false) end for i = 1, #levelDatas do local levelData = levelDatas[i] levelList[i]:SetActive(true) levelList[i].transform.localPosition = Vector3.New(levelDatas[i].config.LevelPointPosition[1],levelDatas[i].config.LevelPointPosition[2],0) local prb1 = Util.GetGameObject(levelList[i], "prb1") local prb2 = Util.GetGameObject(levelList[i], "prb2") local isOpen = this.GetCurLevelIsOpen(levelDatas[i])-- -1 未开启 0 开启 1 需解锁上一关 2 等级不足 prb1:SetActive(false) prb2:SetActive(false) if levelData.config.StageType == FIGHTLEVEL_STAGETYPE.MainLevel then --主关卡 prb1:SetActive(true) Util.GetGameObject(prb1, "nameBg/levelName"):GetComponent("Text").text = levelData.config.Name for j = 1, 3 do local curIndexStarGo = Util.GetGameObject(levelList[i], "prb1/star/star (" ..j.. ")") curIndexStarGo:SetActive(FightLevelManager.GetCurLevelStarState(levelData.state,j)) end Util.AddOnceClick(levelList[i], function() if isOpen == 0 then UIManager.OpenPanel(UIName.FightLevelSingleLevelInfoPopup,FIGHTLEVEL_POPUP_TYPE.MainLevel,levelData) elseif isOpen == -1 then PopupTipPanel.ShowTip("未开启!") elseif isOpen == 1 then PopupTipPanel.ShowTip("通关上一关后解锁!") elseif isOpen == 2 then PopupTipPanel.ShowTip(string.format("到达%s级后解锁!",levelDatas[i].config.LevelLimit)) end end) elseif levelData.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevelReward then--副关卡奖励 prb2:SetActive(true) Util.AddOnceClick(levelList[i], function() if isOpen == 0 then if levelData.state == 0 then FightLevelManager.FightLevelFightBattle(levelData, function() this.OnShowPanel() this.LeftOrRightBtnClickEvent() end) elseif levelData.state == 1 then PopupTipPanel.ShowTip("奖励已领取!") end elseif isOpen == -1 then PopupTipPanel.ShowTip("未开启!") elseif isOpen == 1 then PopupTipPanel.ShowTip("通关上一关后解锁!") elseif isOpen == 2 then PopupTipPanel.ShowTip(string.format("到达%s级后解锁!",levelDatas[i].config.LevelLimit)) end end) elseif levelData.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevel then--副关卡战斗 prb2:SetActive(true) Util.AddOnceClick(levelList[i], function() if isOpen == 0 then UIManager.OpenPanel(UIName.FightLevelSingleLevelInfoPopup,FIGHTLEVEL_POPUP_TYPE.AssistantLevel,levelData) elseif isOpen == -1 then PopupTipPanel.ShowTip("未开启!") elseif isOpen == 1 then PopupTipPanel.ShowTip("通关上一关后解锁!") elseif isOpen == 2 then PopupTipPanel.ShowTip(string.format("到达%s级后解锁!",levelDatas[i].config.LevelLimit)) end end) end Util.SetGray(prb1, not (isOpen == 0)) Util.SetGray(prb2, not (isOpen == 0)) end end function this.SetlevelBox(_rewardBoxDatas) this.totalPro.text = chapterData.stars.."/"..chapterData.curMaxStarNum this.progressBottom.fillAmount=chapterData.stars/chapterData.curMaxStarNum for i = 1, math.max(#_rewardBoxDatas, #boxList) do local go = boxList[i] if not go then go = newObject(boxList[1]) go.transform:SetParent(this.rewardBoxParent.transform) go.name = "BoxBtn"..i go.transform.localScale = Vector3.one go.transform.localPosition = Vector3.zero boxList[i] = go end go.gameObject:SetActive(false) end for i, v in pairs(_rewardBoxDatas) do boxList[i]:SetActive(true) local missionConfigData = _rewardBoxDatas[i].config boxList[i]:GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(missionConfigData.RewardIcon)) Util.GetGameObject(boxList[i], "num"):GetComponent("Text").text = missionConfigData.Star Util.GetGameObject(boxList[i], "redPoint"):SetActive( _rewardBoxDatas[i].state == 0 and chapterData.stars > _rewardBoxDatas[i].config.Star) -- Util.GetGameObject(boxList[i], "UI_Effect_BaoXiang_KaiQi"):SetActive(v.state==SingleDailyMissionState.GetFinish) -- Util.GetGameObject(boxList[i], "UI_Effect_BaoXiang_KaiQi/MeiKaiQi"):SetActive(false) -- Util.GetGameObject(boxList[i], "UI_Effect_BaoXiang_KaiQi"):GetComponent("Animator").enabled = false -- Util.GetGameObject(boxList[i], "UI_Effect_BaoXiang_KaiQi/KaiQi"):SetActive(v.state==SingleDailyMissionState.GetFinish) -- Util.GetGameObject(boxList[i], "UI_Effect_BaoXiang_KeKaiQi"):SetActive(v.state==SingleDailyMissionState.Finish) Util.GetGameObject(boxList[i], "getFinish"):SetActive(false) Util.GetGameObject(boxList[i], "redPoint"):SetActive(false) -- LogYellow("missionConfigData.state ".._rewardBoxDatas[i].state.." chapterData.stars "..chapterData.stars.." missionConfigData.Star "..missionConfigData.Star) if _rewardBoxDatas[i].state == 0 then if chapterData.stars >= missionConfigData.Star then Util.GetGameObject(boxList[i], "redPoint"):SetActive(true) Util.AddOnceClick(boxList[i], function() NetManager.GetHardStageChapterReward(chapterData.chapterId,missionConfigData.Id,function(msg) --自己刷新一下宝箱数据 FightLevelManager.SetChapterBoxRewardData(chapterData.chapterId,missionConfigData.Id,1) CheckRedPointStatus(RedPointType.FightLevel) UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop, 1,function()--isBackBattle true时 为回放不走回调 if chapterData.reward and LengthOfTable(chapterData.reward) > 0 then this.SetlevelBox(chapterData.reward) end end) end) end) else Util.GetGameObject(boxList[i], "redPoint"):SetActive(false) Util.AddOnceClick(boxList[i], function() this.FindBoxRewardInfo(missionConfigData) end) end elseif _rewardBoxDatas[i].state == 1 then Util.GetGameObject(boxList[i], "getFinish"):SetActive(true) Util.AddOnceClick(boxList[i], function() -- PopupTipPanel.ShowTip("奖励已领取!") this.FindBoxRewardInfo(missionConfigData) end) end end end --左右按钮 function this.LeftOrRightBtnClickEvent(index) --index 为空时 刷新下左右按钮的显示 下一章节未开启的时候不显示右按钮 相反 -- chapterData = FightLevelManager.GetChapterData(chapterId) local upChapterId = chapterData.chapterId - 1 local upChapterData = FightLevelManager.GetChapterData(upChapterId) if upChapterData and upChapterId <= FightLevelManager.GetCurChapterId() then this.leftBtn:SetActive(true) else this.leftBtn:SetActive(false) end local downChapterId = chapterData.chapterId + 1 local downChapterData = FightLevelManager.GetChapterData(downChapterId) if downChapterData and downChapterId <= FightLevelManager.GetCurChapterId() then this.rightBtn:SetActive(true) else this.rightBtn:SetActive(false) end if index and index == 1 then--左 chapterId = upChapterId chapterData = upChapterData this.OnShowPanel() this.LeftOrRightBtnClickEvent() elseif index and index == 2 then--右 chapterId = downChapterId chapterData = downChapterData this.OnShowPanel() this.LeftOrRightBtnClickEvent() end end function this.GetCurLevelIsOpen(levelDatas) if levelDatas.config.LevelLimit == -1 then return -1 end if levelDatas.nodeId > FightLevelManager.GetCurChapterLevelId() then return 1 end if levelDatas.config.LevelLimit > PlayerManager.level then return 2 end return 0 end --宝箱奖励预览 function this.FindBoxRewardInfo(missionConfigData) local curConfig = missionConfigData this.RewardPanelGetInfo.text = string.format("收集%s星获得:",curConfig.Star) local showItem = ConfigManager.GetConfigData(ConfigName.RewardGroup,curConfig.StarReward) local reward ={} if showItem and showItem.ShowItem then reward = showItem.ShowItem end if reward then for i = 1, math.max(#allMissionDailyBoxItemPres, #reward) do local go = allMissionDailyBoxItemPres[i] if not go then go = SubUIManager.Open(SubUIConfig.ItemView, this.RewardPanelGrid.transform) go.gameObject.name = "frame"..i allMissionDailyBoxItemPres[i] = go end go.gameObject:SetActive(false) end for i = 1, #reward do allMissionDailyBoxItemPres[i].gameObject:SetActive(true) allMissionDailyBoxItemPres[i]:OnOpen(false,reward[i],0.75) end end this.rewardMaskBtn:SetActive(true) end --界面关闭时调用(用于子类重写) function FightLevelSingleChapterPanel:OnClose() end --界面销毁时调用(用于子类重写) function FightLevelSingleChapterPanel:OnDestroy() allMissionDailyBoxItemPres = {} end return FightLevelSingleChapterPanel