-- 玩家技能面板模块
PlayerSkill = {}
PlayerSkill._ui = nil -- UI界面引用
PlayerSkill._path = SLDefine.PATH_RES_PRIVATE .. "player_skill-win32/" -- 快捷键图片资源路径
-- 初始化技能面板
function PlayerSkill.main()
local parent = GUI:Attach_Parent()
-- 加载技能面板UI模板
GUI:LoadExport(parent, "player/player_skill_node_win32")
PlayerSkill._index = 0 -- 技能格子计数器
PlayerSkill._ui = GUI:ui_delegate(parent)
PlayerSkill._parent = parent
PlayerSkill._moveIconCells = {} -- 可移动图标容器
if not PlayerSkill._ui then
return false
end
-- 添加鼠标滚动支持
GUI:ListView_addMouseScrollPercent(PlayerSkill._ui.ListView_cells)
PlayerSkill.UpdateSkillCells()
return true
end
-- 更新所有技能格子
function PlayerSkill.UpdateSkillCells()
-- 清空现有列表
GUI:ListView_removeAllItems(PlayerSkill._ui.ListView_cells)
PlayerSkill._cells = {}
-- 获取已学习的技能列表(不包含普攻)
local items = SL:CopyData(SL:GetMetaValue("LEARNED_SKILLS", true))
-- 按技能ID排序
items = SL:HashToSortArray(items, function(a, b)
return a.MagicID < b.MagicID
end)
-- 为每个技能创建显示格子
for i, v in ipairs(items) do
local skillID = v.MagicID
local cell = PlayerSkill.CreateSkillCell(PlayerSkill._ui.ListView_cells, skillID)
PlayerSkill._cells[skillID] = cell
end
-- 更新所有技能格子显示
for k, v in pairs(PlayerSkill._cells) do
PlayerSkill.UpdateSkillCell(k)
end
end
-- 刷新所有技能格子
function PlayerSkill.RefreshSkillCells(...)
for k, v in pairs(PlayerSkill._cells) do
PlayerSkill.UpdateSkillCell(k)
end
end
-- 更新单个技能格子
function PlayerSkill.UpdateSkillCell(skillID, deleteChange)
-- 获取技能格子UI引用,如果不存在则返回
local cell = PlayerSkill._cells[skillID]
if not cell then return end
-- 获取技能数据,如果不存在则返回
local skill = SL:GetMetaValue("SKILL_DATA", skillID)
if not skill then return end
-- 设置技能图标相关
local contentSize = GUI:getContentSize(cell.Image_icon)
local iconPath = SL:GetMetaValue("SKILL_RECT_ICON_PATH", skillID)
-- 清除原有图标
GUI:removeAllChildren(cell.Image_icon)
-- 创建新的技能图标并设置属性
local imageICON = GUI:Image_Create(cell.Image_icon, "rectSkillIcon_"..skillID,
contentSize.width / 2, contentSize.height / 2, iconPath)
-- 设置图标大小自适应
GUI:setIgnoreContentAdaptWithSize(imageICON, false)
-- 设置锚点为中心点
GUI:setAnchorPoint(imageICON, 0.5, 0.5)
-- 设置固定大小为40x40
GUI:setContentSize(imageICON, 40, 40)
-- 获取技能相关信息
local skillKey = SL:GetMetaValue("SKILL_KEY", skillID) -- 快捷键
local level = SL:GetMetaValue("SKILL_LEVEL", skillID) -- 技能等级
local strTrain = SL:GetMetaValue("SKILL_TRAIN_DATA", skillID) -- 修炼数据
-- 更新各种文本显示
GUI:Text_setString(cell.Text_skillTrain, strTrain) -- 修炼信息
GUI:Text_setString(cell.Text_skillLevel, level) -- 等级信息
GUI:Text_setString(cell.Text_levelup, string.format("强化%s重", SL:NumberToChinese(skill.LevelUp))) -- 强化信息
-- 设置快捷键图标
-- 只有当有快捷键时才显示图标
GUI:setVisible(cell.Image_key, skillKey ~= 0)
-- 加载对应的快捷键图片(8以上的键位需要调整索引)
GUI:Image_loadTexture(cell.Image_key, PlayerSkill._path ..
string.format("word_anzi_%s.png", skillKey > 8 and skillKey-8 or skillKey+8))
GUI:setIgnoreContentAdaptWithSize(cell.Image_key, true)
-- 根据技能是否可强化来控制UI元素的显示状态
-- 当LevelUp<=0时显示普通状态的UI元素,否则显示强化相关的UI元素
GUI:setVisible(cell.Image_1, skill.LevelUp <= 0) -- 背景图片1
GUI:setVisible(cell.Image_2, skill.LevelUp <= 0) -- 背景图片2
GUI:setVisible(cell.Text_skillTrain, skill.LevelUp <= 0) -- 修炼信息
GUI:setVisible(cell.Text_skillLevel, skill.LevelUp <= 0) -- 等级信息
GUI:setVisible(cell.Text_levelup, skill.LevelUp > 0) -- 强化信息
-- 注册技能图标的拖拽功能
PlayerSkill._parent:RegisterNodeMovable(skillID, deleteChange)
end
-- 创建技能格子
function PlayerSkill.CreateSkillCell(parent, skillID)
PlayerSkill._index = PlayerSkill._index + 1
-- 创建技能格子容器
local widget = GUI:Widget_Create(parent, "SkillItems_"..PlayerSkill._index, 0, 0, 272, 50)
GUI:setTouchEnabled(widget, true)
GUI:LoadExport(widget, "player/skill_cell_win32")
local ui = GUI:ui_delegate(widget)
-- 设置点击事件
GUI:setSwallowTouches(ui.Panel_skill_cell, false)
GUI:addOnClickEvent(ui.Panel_skill_cell, function()
local skill = SL:GetMetaValue("SKILL_DATA", skillID)
SL:OpenSkillSettingUI(skill) -- 打开技能设置界面
end)
-- 设置技能名称
local config = SL:GetMetaValue("SKILL_CONFIG", skillID)
local name = SL:GetMetaValue("SKILL_NAME", skillID)
GUI:Text_setString(ui.Text_skillName, name)
-- 添加技能说明提示
if config.desc then
-- 创建鼠标悬停检测参数
local param = {
-- 定义检测回调函数,用于判断鼠标是否在技能图标上
checkCallback = function(touchPos)
-- 检查触摸点是否在技能图标的可见区域内
if touchPos and GUI:isClippingParentContainsPoint(ui.Image_icon, touchPos) then
return true -- 鼠标在图标上,显示提示
end
return false -- 鼠标不在图标上,不显示提示
end
}
-- 为技能图标添加鼠标悬停提示,显示技能描述
-- 参数说明: 目标控件,提示内容,nil(默认偏移X),nil(默认偏移Y),检测参数
GUI:addMouseOverTips(ui.Image_icon, config.desc, nil, nil, param)
end
return ui
end
return PlayerSkill