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

278 lines
13 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

require("Base/BasePanel")
FightLevelSingleChapterPanel = Inherit(BasePanel)
local this = FightLevelSingleChapterPanel
local sortingOrder = 0
local boxList = {}
local levelList = {}
local chapterId = 0
local chapterData = {}
--初始化组件(用于子类重写)
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")
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)
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()
end
function this.OnShowPanel()
chapterData = FightLevelManager.GetChapterData(chapterId)
this.chapterNameText.text = chapterData.config.Name
this.chapterNameImage.sprite = Util.LoadSprite(chapterData.config.BigNumber)
if chapterData.node and LengthOfTable(chapterData.node) > 0 then
local curchapterData = {}
LogYellow(" "..LengthOfTable(chapterData.node))
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)
LogYellow("curchapterData "..#curchapterData)
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]
LogYellow("i "..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 等级不足
LogYellow("isOpen "..isOpen.." "..tostring(not (isOpen == 0)))
prb1:SetActive(false)
prb2:SetActive(false)
-- levelList[i]:SetActive(not (levelDatas[i].nodeId > FightLevelManager.GetCurChapterLevelId()))
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 = Util.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)
end
elseif _rewardBoxDatas[i].state == 1 then
Util.GetGameObject(boxList[i], "getFinish"):SetActive(true)
Util.AddOnceClick(boxList[i], function()
PopupTipPanel.ShowTip("奖励已领取!")
end)
end
end
end
--左右按钮
function this.LeftOrRightBtnClickEvent(index)
--index 为空时 刷新下左右按钮的显示 下一章节未开启的时候不显示右按钮 相反
-- chapterData = FightLevelManager.GetChapterData(chapterId)
local upChapterId = chapterData.chapterId - 1
local upChapterData = FightLevelManager.GetChapterData(upChapterId)
LogYellow("upChapterId "..upChapterId.." FightLevelManager.GetCurChapterId() "..FightLevelManager.GetCurChapterId())
if upChapterData and upChapterId <= FightLevelManager.GetCurChapterId() then
LogYellow("this.leftBtn:SetActive(true)")
this.leftBtn:SetActive(true)
else
LogYellow("this.leftBtn:SetActive(false)")
this.leftBtn:SetActive(false)
end
local downChapterId = chapterData.chapterId + 1
LogYellow("downChapterId "..downChapterId.." FightLevelManager.GetCurChapterId() "..FightLevelManager.GetCurChapterId())
local downChapterData = FightLevelManager.GetChapterData(downChapterId)
if downChapterData and downChapterId <= FightLevelManager.GetCurChapterId() then
this.rightBtn:SetActive(true)
LogYellow(" this.rightBtn:SetActive(true)")
else
this.rightBtn:SetActive(false)
LogYellow(" 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 FightLevelSingleChapterPanel:OnClose()
end
--界面销毁时调用(用于子类重写)
function FightLevelSingleChapterPanel:OnDestroy()
end
return FightLevelSingleChapterPanel