PGRData/Script/matrix/xui/xuiequipresonanceskill/XUiEquipResonanceSkillPreview.lua
2024-09-01 22:49:41 +02:00

139 lines
No EOL
4.8 KiB
Lua

local XUiGridEquipResonanceSkillPreview = require("XUi/XUiEquipResonanceSkill/XUiGridEquipResonanceSkillPreview")
local XUiEquipResonanceSkillPreview = XLuaUiManager.Register(XLuaUi, "UiEquipResonanceSkillPreview")
function XUiEquipResonanceSkillPreview:OnAwake()
self:AutoAddListener()
self.GridResonanceSkill.gameObject:SetActiveEx(false)
end
function XUiEquipResonanceSkillPreview:OnStart(params)
self.RootUi = params.rootUi
self.Params = params
self.LastSelectSkillInfo = params.selectSkillInfo
self.BtnEnter:SetDisable(true, false)
self.BtnCancel.gameObject:SetActiveEx(self.Params.isNeedSelectSkill)
self.BtnEnter.gameObject:SetActiveEx(self.Params.isNeedSelectSkill)
self:UpdateCharacterName()
self:UpdateSkillPreviewScroll()
self:UpdateResonanceSkillGridsBtnGroup()
end
function XUiEquipResonanceSkillPreview:UpdateCharacterName()
if self.RootUi.SelectCharacterId then
local charConfig = XCharacterConfigs.GetCharacterTemplate(self.RootUi.SelectCharacterId)
self.TxtCharacterName.text = charConfig.Name
self.TxtCharacterNameOther.text = charConfig.TradeName
else
self.TxtCharacterName.text = ""
self.TxtCharacterNameOther.text = ""
end
end
--@region Update PreviewScroll Item
function XUiEquipResonanceSkillPreview:UpdateResonanceSkillGridsBtnGroup()
if not self.Params.isNeedSelectSkill then
return
end
local btnGroup = self.PanelCharacterContent:GetComponent("XUiButtonGroup")
local tlButtonGo = {}
for i,v in ipairs(self.ResonanceSkillGrids) do
table.insert(tlButtonGo, v.GameObject:GetComponent("XUiButton"))
end
btnGroup:Init(tlButtonGo, function(index) self:OnItemClick(index) end)
end
function XUiEquipResonanceSkillPreview:UpdateSkillPreviewScroll()
self.ResonanceSkillGrids = {}
local equipId = self.RootUi.EquipId
local preSkillInfoList = self:GetPreSkillInfoList(equipId)
for skillIndex, skillInfo in ipairs(preSkillInfoList) do
if not self.ResonanceSkillGrids[skillIndex] then
self.ResonanceSkillGrids[skillIndex] = self:CreateItem()
end
self.ResonanceSkillGrids[skillIndex]:Refresh({
equipId = equipId,
skillInfo = skillInfo,
selectSkillInfo = self.LastSelectSkillInfo,
selectCharacterId = self.RootUi.SelectCharacterId,
pos = self.Params.pos
})
end
end
function XUiEquipResonanceSkillPreview:GetPreSkillInfoList(equipId)
local equipId = self.RootUi.EquipId
local list = self._Control:GetResonancePreviewSkillInfoList(equipId, self.RootUi.SelectCharacterId, self.RootUi.Pos)
local equip = XDataCenter.EquipManager.GetEquip(equipId)
if equip.ResonanceInfo then
local getWeight = function (skillInfo)
for i,v in pairs(equip.ResonanceInfo) do
local bindCharacterId = v.CharacterId
if bindCharacterId == self.RootUi.SelectCharacterId then
local s = XDataCenter.EquipManager.GetResonanceSkillInfo(equipId, v.Slot)
if XDataCenter.EquipManager.IsClassifyEqual(equipId, XEquipConfig.Classify.Awareness) then
if s.Id == skillInfo.Id and v.Slot == self.Params.pos then
return math.maxinteger
end
else
if s.Id == skillInfo.Id then
return math.maxinteger
end
end
end
end
return skillInfo.Id
end
table.sort(list, function (a, b)
local aWeight = getWeight(a)
local bWeight = getWeight(b)
return aWeight < bWeight
end)
end
return list
end
function XUiEquipResonanceSkillPreview:CreateItem()
local item = CS.UnityEngine.Object.Instantiate(self.GridResonanceSkill) -- 复制一个item
local grid = XUiGridEquipResonanceSkillPreview.New(item)
grid.Transform:SetParent(self.PanelCharacterContent, false)
grid.GameObject:SetActiveEx(true)
return grid
end
function XUiEquipResonanceSkillPreview:OnItemClick(index)
self.SelectSkillInfo = self.ResonanceSkillGrids[index]:GetSkillInfo()
self.BtnEnter:SetDisable(false, false)
end
--@endregion
function XUiEquipResonanceSkillPreview:AutoAddListener()
self:RegisterClickEvent(self.BtnClose, self.OnBtnCloseClick)
self:RegisterClickEvent(self.BtnCancel, self.OnBtnCloseClick)
self:RegisterClickEvent(self.BtnEnter, self.OnBtnEnterClick)
end
function XUiEquipResonanceSkillPreview:OnBtnCloseClick()
self:Close()
end
function XUiEquipResonanceSkillPreview:OnBtnEnterClick()
if self.SelectSkillInfo then
self.Params.ClickCb(self.SelectSkillInfo)
self:Close()
end
end