PGRData/Script/matrix/xui/xuicharacter/XUiCharacterPanelRoleSkill.lua

171 lines
5.1 KiB
Lua
Raw Normal View History

local XGridSkill = XClass(nil, "XGridSkill")
local SHOW_SKILL_LEVEL = 1 --展示的等级
function XGridSkill:Ctor(ui)
XTool.InitUiObjectByUi(self, ui)
XUiHelper.RegisterClickEvent(self, self.BtnSubSkillIconBg, self.OnBtnSubSkillIconBgClick)
end
function XGridSkill:Refresh(skillGroupId)
if not skillGroupId then
self.GameObject:SetActiveEx(false)
return
end
local skillId = XCharacterConfigs.GetGroupDefaultSkillId(skillGroupId)
local cfg = XCharacterConfigs.GetSkillGradeDesConfig(skillId, SHOW_SKILL_LEVEL)
if not cfg then return end
self.SkillData = cfg or self.SkillData
self.RImgSubSkillIconNormal:SetRawImage(cfg.Icon)
if self.RImgSubSkillIconSelected then
self.RImgSubSkillIconSelected:SetRawImage(cfg.Icon)
end
--兼容两个控件
local txtLevel = self.TxtLevel or self.TxtSubSkillLevel
txtLevel.text = SHOW_SKILL_LEVEL
self.PanelSkillLock.gameObject:SetActiveEx(false)
self.GameObject:SetActiveEx(true)
end
function XGridSkill:OnBtnSubSkillIconBgClick()
if not self.SkillData then return end
2024-09-01 20:49:41 +00:00
XLuaUiManager.Open("UiSkillDetailsTips", self.SkillData)
end
--===========================================================================
---@desc 技能预览界面
--===========================================================================
local XUiCharacterPanelRoleSkill = XClass(nil, "XUiCharacterPanelRoleSkill")
local SIGNAL_BAL_MEMBER = 3 --信号球技能(红黄蓝)
function XUiCharacterPanelRoleSkill:Ctor(ui, onBackCb)
XTool.InitUiObjectByUi(self, ui)
self.OnBackCb = onBackCb
2024-09-01 20:49:41 +00:00
self.SkillGrids = {}
self.BallSkillGrids = {}
self:InitUI()
self:InitCB()
end
function XUiCharacterPanelRoleSkill:InitCB()
self.BtnGoBack.CallBack = function()
if self.OnBackCb then
self.IsOpen = false
self.OnBackCb("Back", false)
end
end
end
function XUiCharacterPanelRoleSkill:InitUI()
self.GridActiveSkill.gameObject:SetActiveEx(false)
2024-09-01 20:49:41 +00:00
self.BasicSkills.gameObject:SetActiveEx(false)
for i = 2, XCharacterConfigs.MAX_SHOW_SKILL_POS do
local panel = self["PanelSkillGroup" .. i]
local grid = XUiHelper.TryGetComponent(panel, "PanelActiveSkill/GridActiveSkill")
if grid then
grid.gameObject:SetActiveEx(false)
end
end
end
function XUiCharacterPanelRoleSkill:Refresh(characterId)
if not characterId then return end
if XRobotManager.CheckIsRobotId(characterId) then
characterId = XRobotManager.GetCharacterId(characterId)
end
self.SkillList = XCharacterConfigs.GetChracterSkillPosToGroupIdDic(characterId)
self:Open(self.IsOpen)
end
function XUiCharacterPanelRoleSkill:Open(isOpen)
if not isOpen then return end
self.IsOpen = true
if not self.SkillList or XTool.IsTableEmpty(self.SkillList) then
return
end
2024-09-01 20:49:41 +00:00
-- 特殊处理
local ballSkill1 = {}
local ballSkill2 = {}
for _, skillGroupId in pairs(self.SkillList[1] or {}) do
local skillId = XCharacterConfigs.GetGroupDefaultSkillId(skillGroupId)
local skillType = XCharacterConfigs.GetSkillType(skillId)
if skillType <= SIGNAL_BAL_MEMBER then
table.insert(ballSkill1, skillGroupId)
else
table.insert(ballSkill2, skillGroupId)
end
end
2024-09-01 20:49:41 +00:00
self:RefreshBallSkill(ballSkill1)
self:RefreshSkill(ballSkill2, self.GridActiveSkill, self.PanelSkillGroup1, 1)
2024-09-01 20:49:41 +00:00
for i = 2, XCharacterConfigs.MAX_SHOW_SKILL_POS do
local panel = self["PanelSkillGroup" .. i]
local skills = self.SkillList[i]
local parent = XUiHelper.TryGetComponent(panel, "PanelActiveSkill")
local grid = XUiHelper.TryGetComponent(panel, "PanelActiveSkill/GridActiveSkill")
self:RefreshSkill(skills, grid, parent, i)
end
end
2024-09-01 20:49:41 +00:00
function XUiCharacterPanelRoleSkill:RefreshSkill(skills, grid, parent, index)
if XTool.IsTableEmpty(self.SkillGrids[index]) then
self.SkillGrids[index] = {}
end
if XTool.IsTableEmpty(skills) then
self:DisableSkillGrid(self.SkillGrids[index])
return
end
2024-09-01 20:49:41 +00:00
self:RefreshGrid(#skills, skills, self.SkillGrids[index], grid, parent)
end
2024-09-01 20:49:41 +00:00
function XUiCharacterPanelRoleSkill:RefreshBallSkill(skills)
if XTool.IsTableEmpty(skills) then
self:DisableSkillGrid(self.BallSkillGrids)
return
end
2024-09-01 20:49:41 +00:00
self:RefreshGrid(#skills, skills, self.BallSkillGrids, self.BasicSkills, self.PanelSkillGroup1)
end
function XUiCharacterPanelRoleSkill:DisableSkillGrid(skillGirdList)
for _, grid in ipairs(skillGirdList) do
grid.GameObject:SetActiveEx(false)
end
end
function XUiCharacterPanelRoleSkill:RefreshGrid(length, skills, grids, grid, parent)
for idx = 1, length do
local item = grids[idx]
if not item then
local ui = XUiHelper.Instantiate(grid, parent);
item = XGridSkill.New(ui)
item.GameObject:SetActiveEx(true)
grids[idx] = item
end
item:Refresh(skills[idx])
end
2024-09-01 20:49:41 +00:00
for i = length + 1, #grids do
grids[i].GameObject:SetActiveEx(false)
end
end
return XUiCharacterPanelRoleSkill