要实现展开/缩进的洗牌效果,我们可以使用动作序列和延时来控制每个图标的移动。这里的关键是让图标按顺序逐个移动,形成“洗牌”动画。
```lua
-- 在ssrUIManager中添加展开/缩进函数
function ssrUIManager:playShuffleAnimation(isExpand)
-- 存储所有创建的图标按钮
if not self.top_icons then
self.top_icons = {}
end
-- 获取所有图标
local icons = {}
for k, val in pairs(top_icon_cfg) do
local btn = GUI:getChildByName(parent, val.name)
if btn and not GUI:Win_IsNull(btn) then
table.insert(icons, btn)
end
end
-- 计算展开和收起的位置
local startDelay = 0
local delayStep = 0.05 -- 每个图标之间的延迟
for i, icon in ipairs(icons) do
-- 获取当前位置
local currentPos = GUI:getPosition(icon)
-- 计算目标位置
local targetX, targetY
if isExpand then
-- 展开到原始位置(根据你的布局逻辑)
local col = (i-1) % 6
local row = math.floor((i-1) / 6)
targetX = (col * -80) + 770
targetY = -80 - (row * 80)
else
-- 缩回到箭头按钮位置
local btnPos = GUI:getPosition(ssrUIManager.top_btn)
targetX = btnPos.x
targetY = btnPos.y
end
-- 创建动作序列
local moveAction = GUI:ActionMoveTo(0.3, targetX, targetY)
local delayAction = GUI:DelayTime(startDelay)
-- 执行动作
GUI:runAction(icon, GUI:ActionSequence(delayAction, moveAction))
-- 增加延迟,形成逐个移动效果
startDelay = startDelay + delayStep
end
-- 更新显示状态
ssrUIManager.icon_is_show = isExpand
end
-- 修改setShowCopyBtn函数,加入洗牌动画
function ssrUIManager:setShowCopyBtn(bool)
local function visible()
GUI:setVisible(ssrUIManager.top_layout, not ssrUIManager.icon_is_show)
end
if bool then
if ssrUIManager.icon_is_show then
-- 收起:先旋转箭头,再播放缩进动画
GUI:Timeline_RotateTo(ssrUIManager.top_btn, 180, 0.1, function()
self:playShuffleAnimation(false)
visible()
end)
else
-- 展开:先播放展开动画,再旋转箭头
self:playShuffleAnimation(true)
GUI:Timeline_RotateTo(ssrUIManager.top_btn, 0, 0.1, visible)
end
else
visible()
end
end
-- 在createTopIcon函数中初始化图标位置(收起状态)
function ssrUIManager:createTopIcon()
local parent = GUI:Win_FindParent(101)
if parent then
GUI:removeAllChildren(parent)
-- 箭头按钮
ssrUIManager.top_btn = GUI:Button_Create(parent, "btn_switch", 850, -57, "res/official/100079.png")
-- 存储图标引用
if not self.top_icons then
self.top_icons = {}
end
local count = 0
local row = 0
local itemsPerRow = 6
for k, val in pairs(top_icon_cfg) do
-- ...(你的原有逻辑保持不变)...
if isCreate then
local col = count % itemsPerRow
row = math.floor(count / itemsPerRow)
-- 初始位置设置为箭头位置(收起状态)
local btnPos = GUI:getPosition(ssrUIManager.top_btn)
local startX = btnPos.x
local startY = btnPos.y
-- 目标展开位置
local targetX = (col * -80) + 770
local targetY = -80 - (row * 80)
-- 创建按钮,初始位置在箭头处
handle = GUI:Button_Create(parent, key, startX, startY, "res/official/"..val.icon..".png")
-- 存储图标引用
self.top_icons[key] = {
btn = handle,
targetX = targetX,
targetY = targetY,
startX = startX,
startY = startY
}
-- ...(你的原有点击事件等逻辑)...
count = count + 1
end
end
end
end
```
**代码说明:**
1. **playShuffleAnimation函数**:核心动画函数
- 使用`GUI:ActionMoveTo()`实现移动动画
- 使用`GUI:DelayTime()`创建延迟,实现逐个移动效果
- 使用`GUI:ActionSequence()`组合延迟和移动动作
2. **动画效果**:
- 展开时:图标从箭头位置逐个移动到目标位置
- 收起时:图标从当前位置逐个移动回箭头位置
- 每个图标之间有0.05秒的延迟,形成"洗牌"效果
3. **修改点**:
- 在`createTopIcon`中初始化图标位置为箭头位置
- 存储每个图标的起始和目标位置
- 在`setShowCopyBtn`中调用动画函数
**使用建议:**
- 可以调整`delayStep`的值控制动画速度(值越小越快)
- 可以调整`GUI:ActionMoveTo(0.3)`中的0.3控制移动时间
- 如果需要更复杂的动画,可以加入缩放或淡入淡出效果
这样就能实现你想要的展开/缩进洗牌效果了!