PGRData/Script/matrix/xui/xuidoomsday/XUiGridDoomsdayBuildingSelect.lua

81 lines
3.1 KiB
Lua
Raw Normal View History

local MAX_COST_NUM = 2
local XUiGridDoomsdayBuildingSelect = XClass(nil, "XUiGridDoomsdayBuildingSelect")
function XUiGridDoomsdayBuildingSelect:Ctor(stageId, clickCb)
self.StageId = stageId
self.ClickCb = clickCb
end
function XUiGridDoomsdayBuildingSelect:Init()
self.BtnEnvironment.CallBack = handler(self, self.OnClickBtnClick)
self:SetSelect(false)
2024-09-01 20:49:41 +00:00
self.TxtUnlock = self.Disable.transform:Find("TxtUnlock")
self.TxtUnlock.gameObject:SetActiveEx(false)
end
function XUiGridDoomsdayBuildingSelect:Refresh(cfgId)
self.BuildingCfgId = cfgId
local stageData = XDataCenter.DoomsdayManager.GetStageData(self.StageId)
self.TxtName.text = XDoomsdayConfigs.BuildingConfig:GetProperty(cfgId, "Name")
self.TxtDescripe.text = XDoomsdayConfigs.BuildingConfig:GetProperty(cfgId, "Desc")
--建造上限 可建造2/8
local cur, limit =
stageData:GetSameTypeBuildingCount(cfgId),
XDoomsdayConfigs.BuildingConfig:GetProperty(cfgId, "MaxNum")
if XTool.IsNumberValid(limit) then
self.TxtQuantity.text = CsXTextManagerGetText("DoomsdayBuildingCountLimit", cur, limit)
self.TxtQuantity.gameObject:SetActiveEx(true)
else
self.TxtQuantity.gameObject:SetActiveEx(false)
end
2024-09-01 20:49:41 +00:00
local conditionId = XDoomsdayConfigs.BuildingConfig:GetProperty(cfgId, "UnlockCondition")
local passCondition, desc
if XTool.IsNumberValid(conditionId) then
passCondition, desc = XDoomsdayConfigs.CheckCondition(conditionId, self.StageId)
else
passCondition, desc = true, ""
end
local reachLimit = XTool.IsNumberValid(limit) and cur >= limit
2024-09-01 20:49:41 +00:00
local isLock = reachLimit or not passCondition
self.BtnEnvironment:SetDisable(isLock, not isLock)
if reachLimit then
self.TxtDisable.text = XUiHelper.GetText("DoomsdayBuildReachLimit")
elseif not passCondition then
self.TxtDisable.text = desc
end
self.Disable.gameObject:SetActiveEx(isLock)
self.ReachLimit = reachLimit
--工期 工期:{0}天
self.TxtSpendTime.text =
CsXTextManagerGetText(
"DoomsdayBuildingBuildDay",
2024-09-01 20:49:41 +00:00
XDoomsdayConfigs.BuildingConfig:GetProperty(cfgId, "FinishDayCount"))
local costResourceList = XDoomsdayConfigs.GetBuildingConstructResourceInfos(cfgId)
for index, resourceInfo in pairs(costResourceList) do
self["RImgTool" .. index]:SetRawImage(XDoomsdayConfigs.ResourceConfig:GetProperty(resourceInfo.Id, "Icon"))
local cur, max = stageData:GetResource(resourceInfo.Id):GetProperty("_Count"), resourceInfo.Count
self["TxtTool" .. index].supportRichText = true
self["TxtTool" .. index].text = XDoomsdayConfigs.GetRequireNumerText(cur, max)
self["PanelTool" .. index].gameObject:SetActiveEx(true)
end
for index = #costResourceList + 1, MAX_COST_NUM do
self["PanelTool" .. index].gameObject:SetActiveEx(false)
end
end
function XUiGridDoomsdayBuildingSelect:SetSelect(value)
self.Select.gameObject:SetActiveEx(value)
end
function XUiGridDoomsdayBuildingSelect:OnClickBtnClick()
self.ClickCb(self.BuildingCfgId)
end
return XUiGridDoomsdayBuildingSelect