130 lines
4.1 KiB
Lua
130 lines
4.1 KiB
Lua
|
-- 边界公约区域界面
|
|||
|
local XUiPanelAssignMain = XLuaUiManager.Register(XLuaUi, "UiPanelAssignMain")
|
|||
|
|
|||
|
local XUiGridAssignChapter = require("XUi/XUiAssign/XUiGridAssignChapter")
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnAwake()
|
|||
|
self:InitComponent()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnStart() -- 用于跳转到stageId
|
|||
|
self:InitChapterGridList()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:InitComponent()
|
|||
|
self.PanelAsset = XUiPanelAsset.New(self, self.PanelAsset, XDataCenter.ItemManager.ItemId.FreeGem, XDataCenter.ItemManager.ItemId.ActionPoint, XDataCenter.ItemManager.ItemId.Coin)
|
|||
|
self.BtnBack.CallBack = function() self:OnBtnBackClick() end
|
|||
|
self.BtnMainUi.CallBack = function() self:OnBtnMainUiClick() end
|
|||
|
self:BindHelpBtn(self.BtnHelp, "Assign")
|
|||
|
self.BtnBuff.CallBack = function() self:OnBtnBuffClick() end
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:InitChapterGridList()
|
|||
|
self.ListData = XDataCenter.FubenAssignManager.GetChapterIdList()
|
|||
|
self.ChapterGridList = {}
|
|||
|
local prefabName = CS.XGame.ClientConfig:GetString("GridAssignChapter")
|
|||
|
for i, chapterId in ipairs(self.ListData) do
|
|||
|
local parent = self["Stage" .. i]
|
|||
|
if parent then
|
|||
|
local prefab = parent:LoadPrefab(prefabName)
|
|||
|
local grid = XUiGridAssignChapter.New(self.RootUi, prefab)
|
|||
|
grid.Parent = parent
|
|||
|
prefab:SetActiveEx(true)
|
|||
|
parent.gameObject:SetActiveEx(false)
|
|||
|
table.insert(self.ChapterGridList, grid)
|
|||
|
else
|
|||
|
XLog.Error("配置章节数超过ui结点数,index:" .. i .. ", chapterId:" .. chapterId)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnEnable()
|
|||
|
if self.IsInitialed then
|
|||
|
self:Refresh()
|
|||
|
else
|
|||
|
self.IsInitialed = true
|
|||
|
XDataCenter.FubenAssignManager.AssignGetDataRequest(function()
|
|||
|
self:InitRefresh()
|
|||
|
end)
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnGetEvents()
|
|||
|
return { XEventId.EVENT_ASSIGN_SELECT_OCCUPY_END }
|
|||
|
end
|
|||
|
|
|||
|
--事件监听
|
|||
|
function XUiPanelAssignMain:OnNotify(evt)
|
|||
|
if evt == XEventId.EVENT_ASSIGN_SELECT_OCCUPY_END then
|
|||
|
self:Refresh()
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnDestroy()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnBtnBackClick()
|
|||
|
self:Close()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnBtnMainUiClick()
|
|||
|
XLuaUiManager.RunMain()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:OnBtnBuffClick()
|
|||
|
XLuaUiManager.Open("UiAssignBuff")
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:InitRefresh()
|
|||
|
self:Refresh()
|
|||
|
self:ShowCurrentChapter()
|
|||
|
self:FirstShowHelpTip()
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:Refresh()
|
|||
|
for i, grid in ipairs(self.ChapterGridList) do
|
|||
|
local chapterId = self.ListData[i]
|
|||
|
if not chapterId then
|
|||
|
grid.Parent.gameObject:SetActiveEx(false)
|
|||
|
else
|
|||
|
-- 只显示解锁章节
|
|||
|
local chapterData = XDataCenter.FubenAssignManager.GetChapterDataById(chapterId)
|
|||
|
if chapterData:IsPass() or XDataCenter.FubenAssignManager.IsCurrentChapter(chapterId) then
|
|||
|
grid.Parent.gameObject:SetActiveEx(true)
|
|||
|
grid:Refresh(chapterId)
|
|||
|
else
|
|||
|
grid.Parent.gameObject:SetActiveEx(false)
|
|||
|
end
|
|||
|
end
|
|||
|
end
|
|||
|
|
|||
|
-- 适配所有子RectTransform的大小
|
|||
|
self.BoundSizeFitter:SetLayoutHorizontal()
|
|||
|
end
|
|||
|
|
|||
|
-- 显示当前章节
|
|||
|
function XUiPanelAssignMain:ShowCurrentChapter()
|
|||
|
local showIndex = 0
|
|||
|
for i, _ in ipairs(self.ChapterGridList) do
|
|||
|
local chapterId = self.ListData[i]
|
|||
|
if chapterId and XDataCenter.FubenAssignManager.IsCurrentChapter(chapterId) then
|
|||
|
showIndex = i
|
|||
|
break
|
|||
|
end
|
|||
|
end
|
|||
|
if showIndex <= 3 then
|
|||
|
return
|
|||
|
end
|
|||
|
local showGrid = self.ChapterGridList[showIndex]
|
|||
|
local posX = showGrid.Parent.transform.localPosition.x - self.RectTransform.rect.width * 0.8
|
|||
|
self.ScrollRect.horizontalNormalizedPosition = posX / (1 * self.ScrollRect.content.rect.width - self.RectTransform.rect.width)
|
|||
|
end
|
|||
|
|
|||
|
function XUiPanelAssignMain:FirstShowHelpTip()
|
|||
|
local key = XDataCenter.FubenAssignManager.GetAccountEnterKey()
|
|||
|
local data = XSaveTool.GetData(key)
|
|||
|
if not data then
|
|||
|
XUiManager.ShowHelpTip("Assign")
|
|||
|
XSaveTool.SaveData(key, 1)
|
|||
|
end
|
|||
|
end
|