Files
StellaSora_DataLua/lua/game/ui/startower/depot/depotpotentialitemctrl.lua
T
SL1900 dcc2c4a2a9 Update - 1.11.0.113
EN: 1.11.0.113
CN: 1.11.0.114
JP: 1.11.0.118
KR: 1.11.0.118
2026-06-02 16:00:00 +09:00

126 lines
4.4 KiB
Lua

local DepotPotentialItemCtrl = class("DepotPotentialItemCtrl", BaseCtrl)
local LayoutRebuilder = CS.UnityEngine.UI.LayoutRebuilder
DepotPotentialItemCtrl._mapNodeConfig = {
btnItem = {
sComponentName = "UIButton",
callback = "OnBtnClick_Item"
},
canvasGroup = {
sNodeName = "goNormal",
sComponentName = "CanvasGroup"
},
goNormal = {},
imgRare = {sComponentName = "Image"},
goIcon = {
sCtrlName = "Game.UI.StarTower.Potential.PotentialIconCtrl"
},
txtName = {sComponentName = "TMP_Text"},
txtLevelValue = {sComponentName = "TMP_Text"},
goSpecial = {},
imgSpIcon = {sComponentName = "Image"},
txtSpName = {sComponentName = "TMP_Text"},
imgChoose = {},
imgLock = {},
txtLock = {
sComponentName = "TMP_Text",
sLanguageId = "StarTower_Depot_Potential_Lock"
},
imgMask = {},
recomContainer = {},
imageRecomBg = {},
txtReCount = {sComponentName = "TMP_Text"}
}
DepotPotentialItemCtrl._mapEventConfig = {
SelectDepotPotential = "OnEvent_SelectDepotPotential"
}
DepotPotentialItemCtrl._mapRedDotConfig = {}
local level_txt_color = {
[1] = "#264278",
[2] = "#2c5fd5"
}
function DepotPotentialItemCtrl:InitItem(nPotentialId, nLevel, nPotentialAdd, bShowAdd, bHideChoose, recommendLv)
self.nPotentialId = nPotentialId
self.nLevel = nLevel
self.nPotentialAdd = nPotentialAdd
self.bHideChoose = bHideChoose
function self.WaitLayoutTxtFunc()
self:WaitLayoutTxt()
end
local itemCfg = ConfigTable.GetData_Item(nPotentialId)
local potentialCfg = ConfigTable.GetData("Potential", nPotentialId)
if nil == potentialCfg or nil == itemCfg then
return
end
self._mapNode.imgLock.gameObject:SetActive(nLevel <= 0)
self._mapNode.imgMask.gameObject:SetActive(nLevel <= 0)
NovaAPI.SetCanvasGroupAlpha(self._mapNode.canvasGroup, 1)
local bSpecial = itemCfg.Stype == GameEnum.itemStype.SpecificPotential
self.bSpecial = bSpecial
self._mapNode.goNormal.gameObject:SetActive(not bSpecial)
self._mapNode.goSpecial.gameObject:SetActive(bSpecial)
if not bSpecial then
self:SetNormalPotential(itemCfg, potentialCfg, bShowAdd)
else
self:SetSpecialPotential(itemCfg, potentialCfg)
end
if recommendLv == nil then
recommendLv = -1
end
self:RefreshRecommend(recommendLv)
end
function DepotPotentialItemCtrl:SetNormalPotential(itemCfg, potentialCfg, bShowAdd)
local sFrame = AllEnum.FrameType_New.PotentialS .. AllEnum.FrameColor_New[itemCfg.Rarity]
self:SetAtlasSprite(self._mapNode.imgRare, "12_rare", sFrame)
self._mapNode.goIcon:SetIcon(potentialCfg.Id)
NovaAPI.SetTMPText(self._mapNode.txtName, itemCfg.Title)
local nPotentialAdd = self.nPotentialAdd
if not bShowAdd then
nPotentialAdd = 0
end
local sColor = nPotentialAdd == 0 and level_txt_color[1] or level_txt_color[2]
local _, color = ColorUtility.TryParseHtmlString(sColor)
NovaAPI.SetTMPText(self._mapNode.txtLevelValue, self.nLevel + nPotentialAdd)
NovaAPI.SetTMPColor(self._mapNode.txtLevelValue, color)
end
function DepotPotentialItemCtrl:SetSpecialPotential(itemCfg, potentialCfg)
NovaAPI.SetTMPText(self._mapNode.txtSpName, itemCfg.Title)
self:SetPngSprite(self._mapNode.imgSpIcon, itemCfg.Icon .. AllEnum.PotentialIconSurfix.A)
end
function DepotPotentialItemCtrl:RefreshPreselectionLevel(nLevel)
self.nLevel = nLevel
self._mapNode.imgLock.gameObject:SetActive(nLevel <= 0)
self._mapNode.imgMask.gameObject:SetActive(nLevel <= 0)
NovaAPI.SetTMPText(self._mapNode.txtLevelValue, self.nLevel)
end
function DepotPotentialItemCtrl:GetPotentialID()
return self.nPotentialId
end
function DepotPotentialItemCtrl:RefreshRecommend(recommendLv)
self.recommendLv = recommendLv
self._mapNode.recomContainer.gameObject:SetActive(-1 < recommendLv)
if -1 < recommendLv then
if self.bSpecial then
self._mapNode.txtReCount.text = ""
else
self._mapNode.txtReCount.text = recommendLv
end
end
if -1 < recommendLv then
local wait = function()
coroutine.yield(CS.UnityEngine.WaitForEndOfFrame())
CS.UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self._mapNode.imageRecomBg.gameObject:GetComponent("RectTransform"))
end
cs_coroutine.start(wait)
end
end
function DepotPotentialItemCtrl:OnBtnClick_Item()
EventManager.Hit("SelectDepotPotential", self.nPotentialId, self.nLevel, self.nPotentialAdd, self._mapNode.btnItem)
end
function DepotPotentialItemCtrl:OnEvent_SelectDepotPotential(nId)
if self.bHideChoose then
return
end
self._mapNode.imgChoose:SetActive(self.nPotentialId == nId)
end
return DepotPotentialItemCtrl