miduo_client/Assets/ManagedResources/~Lua/Modules/FightLevel/FightLevelSingleChapterPane...

322 lines
15 KiB
Lua
Raw Normal View History

2021-05-07 14:44:50 +08:00
require("Base/BasePanel")
FightLevelSingleChapterPanel = Inherit(BasePanel)
local this = FightLevelSingleChapterPanel
local sortingOrder = 0
local boxList = {}
local levelList = {}
2021-05-11 15:12:37 +08:00
local chapterId = 0
local chapterData = {}
local allMissionDailyBoxItemPres = {}
2021-05-07 14:44:50 +08:00
--初始化组件(用于子类重写)
function FightLevelSingleChapterPanel:InitComponent()
2021-05-19 17:36:43 +08:00
this.spLoader = SpriteLoader.New()
2021-05-07 14:44:50 +08:00
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")
2021-05-11 15:12:37 +08:00
this.rect = Util.GetGameObject(self.gameObject, "middle/rect")
2021-05-07 14:44:50 +08:00
levelList = {}
2021-05-11 15:12:37 +08:00
this.rewardBoxParent = Util.GetGameObject(self.gameObject, "middle/rewardBg/btnList")
this.progressBottom = Util.GetGameObject(self.gameObject, "middle/rewardBg/progressBottom/Image"):GetComponent("Image")
2021-05-07 14:44:50 +08:00
for i = 1, 3 do
boxList[i] = Util.GetGameObject(self.gameObject, "middle/rewardBg/btnList/BoxBtn"..i)
end
2021-05-11 15:12:37 +08:00
this.leftBtn=Util.GetGameObject(self.gameObject,"middle/leftBtn")
this.rightBtn=Util.GetGameObject(self.gameObject,"middle/rightBtn")
2021-05-11 20:20:38 +08:00
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]
2021-05-07 14:44:50 +08:00
end
--绑定事件(用于子类重写)
function FightLevelSingleChapterPanel:BindEvent()
Util.AddClick(self.btnBack, function()
self:ClosePanel()
end)
2021-05-11 20:20:38 +08:00
Util.AddClick(this.leftBtnClick, function()
2021-05-11 15:12:37 +08:00
this.LeftOrRightBtnClickEvent(1)
end)
2021-05-11 20:20:38 +08:00
Util.AddClick(this.rightBtnClick, function()
this.LeftOrRightBtnClickEvent(2)
2021-05-11 15:12:37 +08:00
end)
Util.AddClick(this.rewardMaskBtn, function()
this.rewardMaskBtn:SetActive(false)
end)
2021-05-07 14:44:50 +08:00
end
function FightLevelSingleChapterPanel:OnSortingOrderChange()
--特效层级重设
2021-05-11 20:20:38 +08:00
-- for i=1,#boxList do
-- Util.AddParticleSortLayer(boxList[i], sortingOrder)
-- end
2021-05-07 14:44:50 +08:00
sortingOrder = self.sortingOrder
end
--界面打开时调用(用于子类重写)
2021-05-11 15:12:37 +08:00
function FightLevelSingleChapterPanel:OnOpen(_chapterId)
chapterId = _chapterId
2021-05-07 14:44:50 +08:00
-- SoundManager.PlaySound(SoundConfig.Sound_WorldMap)
end
--界面打开或者重新打开后,界面刷新时调用(用于子类重写)
function FightLevelSingleChapterPanel:OnShow()
this.OnShowPanel()
2021-05-14 16:44:40 +08:00
this.LeftOrRightBtnClickEvent()
this.rewardMaskBtn:SetActive(false)
2021-05-07 14:44:50 +08:00
end
function this.OnShowPanel()
2021-05-11 15:12:37 +08:00
chapterData = FightLevelManager.GetChapterData(chapterId)
this.chapterNameText.text = chapterData.config.Name
this.chapterNameImage.sprite = this.spLoader:LoadSprite(chapterData.config.BigNumber)
2021-05-13 09:56:11 +08:00
if chapterData.node and LengthOfTable(chapterData.node) > 0 then
2021-05-14 15:03:48 +08:00
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)
2021-05-13 09:56:11 +08:00
end
if chapterData.reward and LengthOfTable(chapterData.reward) > 0 then
this.SetlevelBox(chapterData.reward)
end
2021-05-07 14:44:50 +08:00
end
function this.SetSingleLevel(levelDatas)
2021-05-14 15:03:48 +08:00
for i = 1, math.max(#levelDatas , #levelList) do
2021-05-07 14:44:50 +08:00
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
2021-05-14 15:03:48 +08:00
for i = 1, #levelDatas do
2021-05-11 15:12:37 +08:00
local levelData = levelDatas[i]
2021-05-07 14:44:50 +08:00
levelList[i]:SetActive(true)
2021-05-11 15:12:37 +08:00
levelList[i].transform.localPosition = Vector3.New(levelDatas[i].config.LevelPointPosition[1],levelDatas[i].config.LevelPointPosition[2],0)
2021-05-07 14:44:50 +08:00
local prb1 = Util.GetGameObject(levelList[i], "prb1")
local prb2 = Util.GetGameObject(levelList[i], "prb2")
2021-05-14 15:03:48 +08:00
local isOpen = this.GetCurLevelIsOpen(levelDatas[i])-- -1 未开启 0 开启 1 需解锁上一关 2 等级不足
2021-05-14 16:44:40 +08:00
prb1:SetActive(false)
prb2:SetActive(false)
2021-05-11 15:12:37 +08:00
if levelData.config.StageType == FIGHTLEVEL_STAGETYPE.MainLevel then --主关卡
2021-05-07 14:44:50 +08:00
prb1:SetActive(true)
2021-05-11 15:12:37 +08:00
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()
2021-05-14 15:03:48 +08:00
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
2021-05-11 15:12:37 +08:00
end)
elseif levelData.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevelReward then--副关卡奖励
prb2:SetActive(true)
Util.AddOnceClick(levelList[i], function()
2021-05-14 15:03:48 +08:00
if isOpen == 0 then
if levelData.state == 0 then
FightLevelManager.FightLevelFightBattle(levelData, function()
2021-05-14 19:55:28 +08:00
this.OnShowPanel()
this.LeftOrRightBtnClickEvent()
2021-05-14 15:03:48 +08:00
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)
2021-05-11 15:12:37 +08:00
elseif levelData.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevel then--副关卡战斗
2021-05-07 14:44:50 +08:00
prb2:SetActive(true)
Util.AddOnceClick(levelList[i], function()
2021-05-14 15:03:48 +08:00
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
2021-05-07 14:44:50 +08:00
end)
end
2021-05-14 16:44:40 +08:00
Util.SetGray(prb1, not (isOpen == 0))
Util.SetGray(prb2, not (isOpen == 0))
2021-05-07 14:44:50 +08:00
end
end
2021-05-13 09:56:11 +08:00
function this.SetlevelBox(_rewardBoxDatas)
2021-05-11 15:12:37 +08:00
this.totalPro.text = chapterData.stars.."/"..chapterData.curMaxStarNum
this.progressBottom.fillAmount=chapterData.stars/chapterData.curMaxStarNum
2021-05-13 09:56:11 +08:00
for i = 1, math.max(#_rewardBoxDatas, #boxList) do
2021-05-07 14:44:50 +08:00
local go = boxList[i]
if not go then
2021-05-11 15:12:37 +08:00
go = newObject(boxList[1])
go.transform:SetParent(this.rewardBoxParent.transform)
2021-05-07 14:44:50 +08:00
go.name = "BoxBtn"..i
go.transform.localScale = Vector3.one
go.transform.localPosition = Vector3.zero
boxList[i] = go
end
go.gameObject:SetActive(false)
end
2021-05-13 09:56:11 +08:00
for i, v in pairs(_rewardBoxDatas) do
2021-05-07 14:44:50 +08:00
boxList[i]:SetActive(true)
2021-05-13 09:56:11 +08:00
local missionConfigData = _rewardBoxDatas[i].config
boxList[i]:GetComponent("Image").sprite = this.spLoader:LoadSprite(GetResourcePath(missionConfigData.RewardIcon))
2021-05-11 15:12:37 +08:00
Util.GetGameObject(boxList[i], "num"):GetComponent("Text").text = missionConfigData.Star
2021-05-13 22:50:34 +08:00
Util.GetGameObject(boxList[i], "redPoint"):SetActive( _rewardBoxDatas[i].state == 0 and chapterData.stars > _rewardBoxDatas[i].config.Star)
2021-05-11 15:12:37 +08:00
-- 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)
2021-05-07 14:44:50 +08:00
Util.GetGameObject(boxList[i], "getFinish"):SetActive(false)
Util.GetGameObject(boxList[i], "redPoint"):SetActive(false)
2021-05-15 16:16:46 +08:00
-- LogYellow("missionConfigData.state ".._rewardBoxDatas[i].state.." chapterData.stars "..chapterData.stars.." missionConfigData.Star "..missionConfigData.Star)
2021-05-13 22:50:34 +08:00
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)
--自己刷新一下宝箱数据
2021-05-14 15:03:48 +08:00
FightLevelManager.SetChapterBoxRewardData(chapterData.chapterId,missionConfigData.Id,1)
CheckRedPointStatus(RedPointType.FightLevel)
2021-05-13 22:50:34 +08:00
UIManager.OpenPanel(UIName.RewardItemPopup,msg.drop, 1,function()--isBackBattle true时 为回放不走回调
2021-05-14 15:03:48 +08:00
if chapterData.reward and LengthOfTable(chapterData.reward) > 0 then
this.SetlevelBox(chapterData.reward)
end
2021-05-13 22:50:34 +08:00
end)
end)
2021-05-13 09:56:11 +08:00
end)
2021-05-13 22:50:34 +08:00
else
Util.GetGameObject(boxList[i], "redPoint"):SetActive(false)
Util.AddOnceClick(boxList[i], function()
this.FindBoxRewardInfo(missionConfigData)
end)
2021-05-13 22:50:34 +08:00
end
elseif _rewardBoxDatas[i].state == 1 then
2021-05-13 09:56:11 +08:00
Util.GetGameObject(boxList[i], "getFinish"):SetActive(true)
2021-05-14 15:03:48 +08:00
Util.AddOnceClick(boxList[i], function()
-- PopupTipPanel.ShowTip("奖励已领取!")
this.FindBoxRewardInfo(missionConfigData)
2021-05-14 15:03:48 +08:00
end)
2021-05-13 09:56:11 +08:00
end
2021-05-07 14:44:50 +08:00
end
end
2021-05-11 15:12:37 +08:00
--左右按钮
function this.LeftOrRightBtnClickEvent(index)
--index 为空时 刷新下左右按钮的显示 下一章节未开启的时候不显示右按钮 相反
2021-05-14 16:44:40 +08:00
-- 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
2021-05-14 19:55:28 +08:00
local downChapterData = FightLevelManager.GetChapterData(downChapterId)
2021-05-14 16:44:40 +08:00
if downChapterData and downChapterId <= FightLevelManager.GetCurChapterId() then
this.rightBtn:SetActive(true)
else
this.rightBtn:SetActive(false)
end
2021-05-11 15:12:37 +08:00
if index and index == 1 then--左
2021-05-14 16:44:40 +08:00
chapterId = upChapterId
chapterData = upChapterData
this.OnShowPanel()
2021-05-14 19:55:28 +08:00
this.LeftOrRightBtnClickEvent()
2021-05-11 15:12:37 +08:00
elseif index and index == 2 then--右
2021-05-14 16:44:40 +08:00
chapterId = downChapterId
chapterData = downChapterData
this.OnShowPanel()
2021-05-14 19:55:28 +08:00
this.LeftOrRightBtnClickEvent()
2021-05-11 15:12:37 +08:00
end
end
2021-05-14 15:03:48 +08:00
function this.GetCurLevelIsOpen(levelDatas)
if levelDatas.config.LevelLimit == -1 then
return -1
end
if levelDatas.nodeId > FightLevelManager.GetCurChapterLevelId() then
--特殊判断 分主关卡和副关卡
if levelDatas.config.StageType == FIGHTLEVEL_STAGETYPE.MainLevel then
local upMainLevelConfig = FightLevelManager.GetChapterLevelData(levelDatas.config.Chapter,levelDatas.nodeId - 2)
if not upMainLevelConfig.isPass then
return 1
end
elseif levelDatas.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevel or levelDatas.config.StageType == FIGHTLEVEL_STAGETYPE.AssistantLevelReward then
local upMainLevelConfig = FightLevelManager.GetChapterLevelData(levelDatas.config.Chapter,levelDatas.nodeId - 1)
if not upMainLevelConfig.isPass then
return 1
end
end
2021-05-14 15:03:48 +08:00
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
2021-05-07 14:44:50 +08:00
--界面关闭时调用(用于子类重写)
function FightLevelSingleChapterPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function FightLevelSingleChapterPanel:OnDestroy()
allMissionDailyBoxItemPres = {}
2021-05-19 17:36:43 +08:00
this.spLoader:Destroy()
2021-05-07 14:44:50 +08:00
end
return FightLevelSingleChapterPanel