2023-07-14 19:35:33 +00:00
|
|
|
local XUiGridDoomsdayBuildingSelect = require("XUi/XUiDoomsday/XUiGridDoomsdayBuildingSelect")
|
|
|
|
|
|
|
|
local XUiDoomsdayBuild = XLuaUiManager.Register(XLuaUi, "UiDoomsdayBuild")
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:OnAwake()
|
|
|
|
self:AutoAddListener()
|
|
|
|
end
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
function XUiDoomsdayBuild:OnStart(stageId, defaultSelectBuildingCfgId, closeCb)
|
2023-07-14 19:35:33 +00:00
|
|
|
self.StageId = stageId
|
|
|
|
self.CloseCb = closeCb
|
2024-09-01 20:49:41 +00:00
|
|
|
self.DefaultSelectBuildingCfgId = defaultSelectBuildingCfgId
|
2023-07-14 19:35:33 +00:00
|
|
|
|
|
|
|
self.BuildingCfgIds = XDoomsdayConfigs.StageConfig:GetProperty(stageId, "BuildingIds")
|
|
|
|
end
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:OnEnable()
|
|
|
|
self:UpdateView()
|
|
|
|
end
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:AutoAddListener()
|
|
|
|
self.BtnTanchuangClose.CallBack = handler(self, self.Close)
|
|
|
|
self.BtnConfirm.CallBack = handler(self, self.OnClickBtnConfirm)
|
|
|
|
end
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:UpdateView()
|
|
|
|
local stageData = XDataCenter.DoomsdayManager.GetStageData(self.StageId)
|
|
|
|
|
|
|
|
self:RefreshTemplateGrids(
|
|
|
|
self.GridEnvironment,
|
|
|
|
self.BuildingCfgIds,
|
|
|
|
self.EnvirGridsContent,
|
|
|
|
function()
|
|
|
|
return XUiGridDoomsdayBuildingSelect.New(self.StageId, handler(self, self.OnClickBuilding))
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2024-09-01 20:49:41 +00:00
|
|
|
local condition
|
|
|
|
if XTool.IsNumberValid(self.DefaultSelectBuildingCfgId) then
|
|
|
|
condition = function(index, cfgId)
|
|
|
|
return self.DefaultSelectBuildingCfgId == cfgId
|
|
|
|
end
|
|
|
|
else
|
|
|
|
condition = function(index, cfgId)
|
|
|
|
return not self:GetGrid(index).ReachLimit
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2023-07-14 19:35:33 +00:00
|
|
|
for index, buildingCfgId in ipairs(self.BuildingCfgIds) do
|
2024-09-01 20:49:41 +00:00
|
|
|
if condition(index, buildingCfgId) then
|
2023-07-14 19:35:33 +00:00
|
|
|
self:OnClickBuilding(buildingCfgId)
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:OnClickBuilding(buildingCfgId)
|
|
|
|
self.SelectBuildingCfgId = buildingCfgId
|
|
|
|
|
|
|
|
for index, inId in pairs(self.BuildingCfgIds) do
|
|
|
|
self:GetGrid(index):SetSelect(inId == buildingCfgId)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function XUiDoomsdayBuild:OnClickBtnConfirm()
|
|
|
|
local stageData = XDataCenter.DoomsdayManager.GetStageData(self.StageId)
|
|
|
|
local buildingCfgId = self.SelectBuildingCfgId
|
|
|
|
|
|
|
|
local costResourceList = XDoomsdayConfigs.GetBuildingConstructResourceInfos(buildingCfgId)
|
|
|
|
for index, resourceInfo in pairs(costResourceList) do
|
|
|
|
if not stageData:CheckResourceCount(resourceInfo.Id, resourceInfo.Count) then
|
|
|
|
XUiManager.TipText("DoomsdayBuildingSelectLackResource")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
self:Close()
|
|
|
|
if self.CloseCb then
|
|
|
|
self.CloseCb(buildingCfgId)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return XUiDoomsdayBuild
|