PGRData/Script/matrix/xui/xuifubenexplore/XUiFubenExploreLevel.lua
2024-09-01 22:49:41 +02:00

301 lines
No EOL
13 KiB
Lua
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

local XUiFubenExploreLevel = XLuaUiManager.Register(XLuaUi, "UiFubenExploreLevel")
function XUiFubenExploreLevel:OnAwake()
self:AddListener()
end
function XUiFubenExploreLevel:OnStart(chapterId)
self.ChapterId = chapterId
self.BannerList = {}
self.QuickJumpBtnList = {}
self.BuffList = {}
self.BuffDetailList = {}
self.BtnNormalDot.gameObject:SetActive(false)
self.ExploreBuff.gameObject:SetActive(false)
self.ExploreBuffDetail.gameObject:SetActive(false)
self.AnimFullExploreEnable = self:FindGameObject("AnimFullExploreEnable")
self:InitDragPanel()
self:Init()
XEventManager.AddEventListener(XEventId.EVENT_FUBEN_EXPLORE_UPDATE, self.Init, self)
XEventManager.AddEventListener(XEventId.EVENT_FUBEN_EXPLORE_UPDATEBUFF, self.UpdateBuffList, self)
end
function XUiFubenExploreLevel:OnEnable()
if XDataCenter.FubenExploreManager.GetExploreProgress(self.ChapterId) ~= 1 then
--选择最近的可打节点去focuse
self:AutoFocus()
end
end
function XUiFubenExploreLevel:OnDestroy()
if self.LoadResource then
self.LoadResource:Release()
end
XEventManager.RemoveEventListener(XEventId.EVENT_FUBEN_EXPLORE_UPDATE, self.Init, self)
XEventManager.RemoveEventListener(XEventId.EVENT_FUBEN_EXPLORE_UPDATEBUFF, self.UpdateBuffList, self)
end
function XUiFubenExploreLevel:AddListener()
self:RegisterClickEvent(self.BtnBack, self.OnBtnBackClick)
self:RegisterClickEvent(self.BtnMainUi, self.OnBtnMainUiClick)
self:RegisterClickEvent(self.BtnBuff, self.OnBtnBuffClick)
self:RegisterClickEvent(self.BtnClose, self.OnBtnCloseClick)
self:RegisterClickEvent(self.BtnReward, self.OnBtnRewardClick)
self:BindHelpBtn(self.BtnHelpCourse, "Explore")
end
function XUiFubenExploreLevel:OnBtnRewardClick()
local chapterData = XFubenExploreConfigs.GetChapterData(self.ChapterId)
if XDataCenter.FubenExploreManager.GetChapterData(self.ChapterId) ~= nil
and XDataCenter.FubenExploreManager.GetChapterData(self.ChapterId).RewardStatus == 1 then
-- XUiManager.TipError(CS.XTextManager.GetText("ExploreRewardError"))
-- 已领取状态下直接显示奖励物品信息
XUiManager.OpenUiTipRewardByRewardId(chapterData.RewardId, CS.XTextManager.GetText("ExploreRewardTitle"))
else
if XDataCenter.FubenExploreManager.GetExploreProgress(self.ChapterId) == 1 then
XDataCenter.FubenExploreManager.GetChapterReward(self.ChapterId, function() self:CompleteInit() end)
else
XUiManager.OpenUiTipRewardByRewardId(chapterData.RewardId, CS.XTextManager.GetText("ExploreRewardTitle"))
end
end
end
function XUiFubenExploreLevel:OnBtnMainUiClick()
XLuaUiManager.RunMain()
--self.PanelDragArea:EndFocus()
end
function XUiFubenExploreLevel:OnBtnBackClick()
self:Close()
end
function XUiFubenExploreLevel:OnBtnBuffClick()
XDataCenter.UiPcManager.OnUiEnable(self, "OnBtnCloseClick")
self.PanelBuffDetail.gameObject:SetActive(true)
self:PlayAnimation("AnimBuffDetailEnable")
end
function XUiFubenExploreLevel:OnBtnCloseClick()
self.PanelBuffDetail.gameObject:SetActive(false)
XDataCenter.UiPcManager.OnUiDisableAbandoned(true, self)
end
function XUiFubenExploreLevel:OnQuickJumpClick(nodeInfo)
self.PanelDragArea:FocusTarget(self:GetNodeObj(nodeInfo), 1, 0.5, CS.UnityEngine.Vector3.zero, function() self:OnLevelNodeClick(nodeInfo) end)
--self.PanelDragArea:StartFocus(self:GetNodeObj(nodeInfo).transform.position, 1, 0.5, CS.UnityEngine.Vector3.zero, true, function() XLog.Debug("StartFinish!!!!") end)
end
function XUiFubenExploreLevel:InitDragPanel()
local chapterData = XFubenExploreConfigs.GetChapterData(self.ChapterId)
local prefabName = string.format(chapterData.ChapterPrefab)
self.LoadResource = CS.XResourceManager.Load(prefabName);
self.DragPanel = CS.UnityEngine.Object.Instantiate(self.LoadResource.Asset)
self.DragPanel.transform:SetParent(self.FullScreenBackground, false)
self.PanelDragArea = self.DragPanel:GetComponentInChildren(typeof(CS.XDragArea))
self.LayerLevel = self.PanelDragArea.gameObject.transform:Find("LayerLevel")
end
function XUiFubenExploreLevel:CompleteInit()
self.PanelFullExplore.gameObject:SetActive(true)
if self.AnimFullExploreEnable and self.AnimFullExploreEnable.activeInHierarchy then
self:PlayAnimationWithMask("AnimFullExploreEnable", function()
self:Close()
end)
else
self:Close()
end
end
function XUiFubenExploreLevel:Init()
local chapterData = XFubenExploreConfigs.GetChapterData(self.ChapterId)
--生成可拖动区域内的所有节点
--获取这一章表所有的关卡(处理后)
self.AllNodeList = XDataCenter.FubenExploreManager.GetAllNodeData(self.ChapterId)
local useNodeList = {}
for i = 1, #self.AllNodeList do
if self.AllNodeList[i].State ~= XFubenExploreConfigs.NodeStateEnum.Invisivle then
table.insert(useNodeList, self.AllNodeList[i])
end
end
for i = 1, #useNodeList do
if self.BannerList[useNodeList[i].tableData.Id] == nil then
local tempLevelNodeObj
if useNodeList[i].tableData.IsBossNode then
tempLevelNodeObj = CS.UnityEngine.Object.Instantiate(self.Obj:GetPrefab("FubenExploreBossLevel"))
else
tempLevelNodeObj = CS.UnityEngine.Object.Instantiate(self.Obj:GetPrefab("FubenExploreLevel"))
end
local parentObj = self.LayerLevel.transform:Find(useNodeList[i].tableData.Id)
parentObj.gameObject:SetActive(true)
tempLevelNodeObj.transform:SetParent(parentObj, false)
tempLevelNodeObj.transform:SetAsLastSibling()
local tempLevelNode = XUiFubenExploreLevelNode.New(tempLevelNodeObj, useNodeList[i], self, function(nodeInfo) self:OnLevelNodeClick(nodeInfo) end)
self.BannerList[useNodeList[i].tableData.Id] = tempLevelNode
else
self.BannerList[useNodeList[i].tableData.Id]:UpdateNode(useNodeList[i])
end
end
--生成所有可到达节点按钮
self.CanPlayList = {}
for i = 1, #self.AllNodeList do
if self.AllNodeList[i].State == XFubenExploreConfigs.NodeStateEnum.Availavle then
table.insert(self.CanPlayList, self.AllNodeList[i])
end
end
for i = 1, #self.CanPlayList do
if self.QuickJumpBtnList[i] == nil then
local tempBtn = CS.UnityEngine.Object.Instantiate(self.BtnNormalDot)
tempBtn.transform:SetParent(self.PanelNodeList, false)
tempBtn.gameObject:SetActive(true)
self.QuickJumpBtnList[i] = XUiFubenExploreQuickJumpBtn.New(tempBtn, self.CanPlayList[i], function(nodeInfo) self:OnQuickJumpClick(nodeInfo) end)
else
self.QuickJumpBtnList[i]:UpdateNode(self.CanPlayList[i])
self.QuickJumpBtnList[i].GameObject:SetActiveEx(true)
end
end
for i = #self.CanPlayList + 1, #self.QuickJumpBtnList do
self.QuickJumpBtnList[i].GameObject:SetActiveEx(false)
end
--更新探索率
local progress = XDataCenter.FubenExploreManager.GetExploreProgress(self.ChapterId)
local progressInt = math.floor(progress * 100)
self.TxtProgress.text = string.format("%d%%", progressInt)
self.ImgProgress.fillAmount = progress
self.ImgRedPoint.gameObject:SetActive(XDataCenter.FubenExploreManager.IsChapterRedPoint(self.ChapterId))
--0未领取1已领取
if XDataCenter.FubenExploreManager.GetChapterData(self.ChapterId) ~= nil
and XDataCenter.FubenExploreManager.GetChapterData(self.ChapterId).RewardStatus == 1 then
self.ImgComplete.gameObject:SetActive(true)
else
self.ImgComplete.gameObject:SetActive(false)
end
--更新buff以及章节名
self.TxtTitle.text = chapterData.Name
self.TxtChapterId.text = chapterData.Id
self:UpdateBuffList()
--为了粒子层正常更新canvas的order
self:InitCanvas()
end
function XUiFubenExploreLevel:InitCanvas()
self.PanelTopareaCanvas.sortingOrder = self.UiFubenExploreLevelCanvas.sortingOrder + 5
self.PanelTopCenterCanvas.sortingOrder = self.UiFubenExploreLevelCanvas.sortingOrder + 5
self.PanelBottomLeftCanvas.sortingOrder = self.UiFubenExploreLevelCanvas.sortingOrder + 5
self.PanelFullExploreCanvas.sortingOrder = self.UiFubenExploreLevelCanvas.sortingOrder + 5
self.PanelBuffDetailCanvas.sortingOrder = self.UiFubenExploreLevelCanvas.sortingOrder + 5
end
function XUiFubenExploreLevel:AutoFocus()
if #self.CanPlayList > 0 then
local nearestNode = self.CanPlayList[1]
local minDis = CS.UnityEngine.Vector3.Distance(self:GetNodeObj(self.CanPlayList[1]).transform.position, self.DragPanel.gameObject.transform.position)
for i = 2, #self.CanPlayList do
local tempDis = CS.UnityEngine.Vector3.Distance(self:GetNodeObj(self.CanPlayList[i]).transform.position, self.DragPanel.gameObject.transform.position)
if tempDis < minDis then
nearestNode = self.CanPlayList[i]
minDis = tempDis
end
end
self.PanelDragArea:FocusTarget(self:GetNodeObj(nearestNode), 1, 0.5, CS.UnityEngine.Vector3.zero)
end
end
function XUiFubenExploreLevel:UpdateBuffList()
--小buffIco
local allBuff = XFubenExploreConfigs.GetChapterBuff(self.ChapterId)
for i = 1, #allBuff do
if self.BuffList[i] == nil then
local tempBuff = CS.UnityEngine.Object.Instantiate(self.ExploreBuff)
tempBuff.transform:SetParent(self.BtnBuff.transform, false)
tempBuff.gameObject:SetActive(true)
self.BuffList[i] = XUiFubenExploreBuff.New(tempBuff, allBuff[i])
else
self.BuffList[i]:Update(allBuff[i])
end
end
for i = #allBuff + 1, #self.BuffList do
self.BuffList[i].GameObject:SetActive(false)
end
--大BuffList
for i = 1, #allBuff do
if self.BuffDetailList[i] == nil then
local tempBuff = CS.UnityEngine.Object.Instantiate(self.ExploreBuffDetail)
tempBuff.transform:SetParent(self.DetailBuffListPanel.transform, false)
tempBuff.gameObject:SetActive(true)
self.BuffDetailList[i] = XUiFubenExploreBuffDetail.New(tempBuff, allBuff[i])
else
self.BuffDetailList[i]:Update(allBuff[i])
end
end
for i = #allBuff + 1, #self.BuffDetailList do
self.BuffDetailList[i].GameObject:SetActive(false)
end
end
function XUiFubenExploreLevel:GetNodeObj(nodeInfo)
for _, v in pairs(self.BannerList) do
if v.NodeInfo.tableData.Id == nodeInfo.tableData.Id then
return v.GameObject.transform
end
end
end
function XUiFubenExploreLevel:OnLevelNodeClick(nodeInfo)
--锁定的点了不能进
if nodeInfo.State == XFubenExploreConfigs.NodeStateEnum.Visivle then
local unLockText = ""
local unLockTextSeparate = CS.XTextManager.GetText("ExploreBuffUnlockSeparate")
for i = 1, #nodeInfo.tableData.PreOpenId do
if not XDataCenter.FubenExploreManager.IsNodeFinish(self.ChapterId, nodeInfo.tableData.PreOpenId[i]) then
local lockNodeInfo = XFubenExploreConfigs.GetLevel(nodeInfo.tableData.PreOpenId[i])
if i >= 2 then
unLockText = unLockText .. unLockTextSeparate .. lockNodeInfo.Name
else
unLockText = lockNodeInfo.Name
end
end
end
XUiManager.TipError(CS.XTextManager.GetText("ExploreBuffUnlock", unLockText))
return
end
XDataCenter.FubenExploreManager.SetCurNodeId(nodeInfo.tableData.Id)
--剧情节点
if nodeInfo.tableData.Type == XFubenExploreConfigs.NodeTypeEnum.Story then
local chapterId = self.ChapterId
local tableDataId = nodeInfo.tableData.Id
XLuaUiManager.Open("UiEnterFight", nodeInfo.tableData.Type, nodeInfo.tableData.Title, nodeInfo.tableData.Explain, nodeInfo.tableData.EnterIco, nodeInfo.tableData.RewardId, function()
XDataCenter.MovieManager.PlayMovie(nodeInfo.tableData.TypeValue, function()
if not XDataCenter.FubenExploreManager.IsNodeFinish(chapterId, tableDataId) then
XDataCenter.FubenExploreManager.FinishNode(chapterId, tableDataId)
end
end)
end)
end
-- function()
-- -- 新剧情返回时会销毁对象
-- if self and not XTool.UObjIsNil(self.GameObject) then
-- self:Init()
-- self:AutoFocus()
-- end
-- end
--战斗节点
if nodeInfo.tableData.Type == XFubenExploreConfigs.NodeTypeEnum.Stage then
XLuaUiManager.Open("UiEnterFight", nodeInfo.tableData.Type, nodeInfo.tableData.Title, nodeInfo.tableData.Explain, nodeInfo.tableData.EnterIco, nodeInfo.tableData.RewardId, function()
if XTool.USENEWBATTLEROOM then
XLuaUiManager.Open("UiBattleRoleRoom", tonumber(nodeInfo.tableData.TypeValue)
, XDataCenter.TeamManager.GetXTeamByTypeId(CS.XGame.Config:GetInt("TypeIdExplore"))
, require("XUi/XUiFubenExplore/XUiExploreBattleRoleRoom"))
else
XLuaUiManager.Open("UiNewRoomSingle", tonumber(nodeInfo.tableData.TypeValue))
end
end)
end
end