135 lines
No EOL
4.3 KiB
Lua
135 lines
No EOL
4.3 KiB
Lua
local XUiBabelTowerTask = XLuaUiManager.Register(XLuaUi, "UiBabelTowerTask")
|
|
|
|
function XUiBabelTowerTask:OnAwake()
|
|
self.AssetPanel = 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.DynamicTable = XDynamicTableNormal.New(self.SViewTask.gameObject)
|
|
self.DynamicTable:SetProxy(XDynamicGridTask)
|
|
self.DynamicTable:SetDelegate(self)
|
|
|
|
XEventManager.AddEventListener(XEventId.EVENT_BABEL_ACTIVITY_STATUS_CHANGED, self.CheckActivityStatus, self)
|
|
XEventManager.AddEventListener(XEventId.EVENT_TASK_SYNC, self.OnTaskChangeSync, self)
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnDestroy()
|
|
self:StopCountDown()
|
|
XEventManager.RemoveEventListener(XEventId.EVENT_BABEL_ACTIVITY_STATUS_CHANGED, self.CheckActivityStatus, self)
|
|
XEventManager.RemoveEventListener(XEventId.EVENT_TASK_SYNC, self.OnTaskChangeSync, self)
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnBtnBackClick()
|
|
self:Close()
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnBtnMainUiClick()
|
|
XLuaUiManager.RunMain()
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnStart()
|
|
self:OnTaskChangeSync()
|
|
self:CreateCountDown()
|
|
end
|
|
|
|
function XUiBabelTowerTask:CreateCountDown()
|
|
self:StopCountDown()
|
|
local time = XTime.GetServerNowTimestamp()
|
|
local curActivityNo = XDataCenter.FubenBabelTowerManager.GetCurrentActivityNo()
|
|
if not curActivityNo then
|
|
return
|
|
end
|
|
local activityTemplate = XFubenBabelTowerConfigs.GetBabelTowerActivityTemplateById(curActivityNo)
|
|
if not activityTemplate then
|
|
return
|
|
end
|
|
|
|
local endTime = XFunctionManager.GetEndTimeByTimeId(activityTemplate.ActivityTimeId)
|
|
if not endTime then
|
|
return
|
|
end
|
|
local leftTimeDesc = CS.XTextManager.GetText("BabelTowerLeftTimeDesc")
|
|
self.TxtTime.text = string.format("%s%s", leftTimeDesc, XUiHelper.GetTime(endTime - time, XUiHelper.TimeFormatType.ACTIVITY))
|
|
self.Timer = XScheduleManager.ScheduleForever(
|
|
function()
|
|
time = XTime.GetServerNowTimestamp()
|
|
if time > endTime then
|
|
self:StopCountDown()
|
|
return
|
|
end
|
|
self.TxtTime.text = string.format(
|
|
"%s%s",
|
|
leftTimeDesc,
|
|
XUiHelper.GetTime(endTime - time, XUiHelper.TimeFormatType.ACTIVITY)
|
|
)
|
|
end,
|
|
XScheduleManager.SECOND,
|
|
0
|
|
)
|
|
end
|
|
|
|
function XUiBabelTowerTask:StopCountDown()
|
|
if self.Timer ~= nil then
|
|
XScheduleManager.UnSchedule(self.Timer)
|
|
self.Timer = nil
|
|
end
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnEnable()
|
|
self:CheckActivityStatus()
|
|
end
|
|
|
|
function XUiBabelTowerTask:CheckActivityStatus()
|
|
if not XLuaUiManager.IsUiShow("UiBabelTowerTask") then
|
|
return
|
|
end
|
|
local curActivityNo = XDataCenter.FubenBabelTowerManager.GetCurrentActivityNo()
|
|
if not curActivityNo or not XDataCenter.FubenBabelTowerManager.IsInActivityTime(curActivityNo) then
|
|
XUiManager.TipMsg(CS.XTextManager.GetText("BabelTowerNoneOpen"))
|
|
XLuaUiManager.RunMain()
|
|
end
|
|
end
|
|
|
|
function XUiBabelTowerTask:OnTaskChangeSync()
|
|
self.BabelTowerTasks = XDataCenter.TaskManager.GetBabelTowerFullTaskList()
|
|
for _, v in pairs(self.BabelTowerTasks or {}) do
|
|
v.SortWeight = 2
|
|
if v.State == XDataCenter.TaskManager.TaskState.Achieved then
|
|
v.SortWeight = 1
|
|
elseif v.State == XDataCenter.TaskManager.TaskState.Finish or v.State == XDataCenter.TaskManager.TaskState.Invalid then
|
|
v.SortWeight = 3
|
|
end
|
|
end
|
|
|
|
table.sort(self.BabelTowerTasks, function(taskA, taskB)
|
|
if taskA.SortWeight == taskB.SortWeight then
|
|
return taskA.Id < taskB.Id
|
|
end
|
|
return taskA.SortWeight < taskB.SortWeight
|
|
end)
|
|
self.DynamicTable:SetDataSource(self.BabelTowerTasks)
|
|
self.DynamicTable:ReloadDataASync()
|
|
self.ImgEmpty.gameObject:SetActiveEx(#self.BabelTowerTasks <= 0)
|
|
end
|
|
|
|
--动态列表事件
|
|
function XUiBabelTowerTask:OnDynamicTableEvent(event, index, grid)
|
|
if event == DYNAMIC_DELEGATE_EVENT.DYNAMIC_GRID_ATINDEX then
|
|
local data = self.BabelTowerTasks[index]
|
|
if not data then
|
|
return
|
|
end
|
|
grid.RootUi = self
|
|
grid:ResetData(data)
|
|
end
|
|
end |