local MainRightTop = {}
-- 功能按钮配置表
local UI_CONFIG = {
{ name = "topbtn_1", x = 0.25, y = 3.5, res = "res/tops/a1.png", msg = {666,1} },
{ name = "topbtn_2", x = 0.57, y = 1, res = "res/tops/a2.png", msg = {666,2} },
{ name = "topbtn_3
看了你的代码,有几个地方需要修复。主要问题是使用了浮生梦老师前端课程中没有的函数,我来帮你修正:
```lua
local MainRightTop = {}
-- 功能按钮配置表
local UI_CONFIG = {
{ name = "topbtn_1", x = 0.25, y = 3.5, res = "res/tops/a1.png", msg = {666,1} },
{ name = "topbtn_2", x = 0.57, y = 1, res = "res/tops/a2.png", msg = {666,2} },
{ name = "topbtn_3", x = 0.49, y = 1, res = "res/tops/a3.png", msg = {666,3} },
{ name = "topbtn_4", x = 0.41, y = 1, res = "res/tops/a4.png", msg = function (btn)
-- 注意:UIOperator:OpenAuctionUI() 这个函数需要确认是否存在
-- 如果不存在,需要替换为正确的打开拍卖行函数
SL:Print("打开拍卖行")
end},
{ name = "topbtn_5", x = 0.33, y = 1, res = "res/tops/a5.png", msg = {666,5} },
{ name = "topbtn_6", x = 0.25, y = 1, res = "res/tops/a7.png", msg = function (btn)
-- 注意:UIOperator:OpenKefuUI() 这个函数需要确认是否存在
SL:RequestOpen996ManualService() -- 使用知识库中的客服函数
end},
{ name = "topbtn_7", x = 0.65, y = 3, res = "res/tops/a6.png", msg = function (btn)
-- 注意:UIOperator:OpenBox996UI() 这个函数需要确认是否存在
SL:Print("打开宝箱界面")
end},
}
local TOGGLE_BTN_CFG = { name = "topbtn_toggle", x = 0.25, y = 3.5, res = "res/tops/b1.png" }
function MainRightTop:createShuffleEffect(container, configs)
if GUI:Win_IsNull(container) then return end
-- 获取屏幕宽度(自定义函数,需要替换)
local screenSize = GUI:getContentSize(container) -- 获取容器尺寸
local w = screenSize.width or 1280 -- 默认值
local buttons = {}
-- 先移除所有子节点
for _,cfg in ipairs(configs) do
local child = GUI:getChildByName(container, cfg.name)
if not GUI:Win_IsNull(child) then
GUI:removeFromParent(child)
end
end
for i, cfg in ipairs(configs) do
local posX = -(math.abs(cfg.x) * w)
local posY = -(math.abs(cfg.y) * 40)
local btn = GUI:Button_Create(container, cfg.name, posX, posY, cfg.res)
GUI:setAnchorPoint(btn, 1, 1)
GUI:setOpacity(btn, 0)
GUI:setVisible(btn, true)
-- 使用正确的点击事件函数
GUI:addOnClickEvent(btn, function()
if type(cfg.msg) == "table" then
-- 注意:SL:toServer() 需要替换为正确的发送消息函数
SL:SendLuaNetMsg(cfg.msg[1], cfg.msg[2], 0, 0, "")
elseif type(cfg.msg) == "function" then
cfg.msg(btn)
end
end)
buttons[i] = {btn = btn, x = posX, y = posY}
end
for idx, item in ipairs(buttons) do
local btn = item.btn
local tarX = item.x
local tarY = item.y
-- 使用正确的定时器函数
SL:ScheduleOnce(function()
SL:Print("进入~", btn)
GUI:stopAllActions(btn)
GUI:setPosition(btn, tarX + 100, tarY)
local act = GUI:ActionSequence(
GUI:ActionSpawn(
GUI:ActionMoveTo(0.2, tarX, tarY),
GUI:ActionFadeTo(0.2, 255)
)
)
GUI:runAction(btn, act)
end, 0.05 * idx)
end
end
function MainRightTop:createFoldEffect(container, callback)
if GUI:Win_IsNull(container) then return end
local children = {}
for _,cfg in ipairs(UI_CONFIG) do
local child = GUI:getChildByName(container, cfg.name)
if not GUI:Win_IsNull(child) then
table.insert(children, child)
end
end
local count = #children
if count == 0 then
if callback then callback() end
return
end
local finish = 0
for i = count, 1, -1 do
local btn = children[i]
SL:ScheduleOnce(function()
if GUI:Win_IsNull(btn) then
finish = finish + 1
if finish == count and callback then callback() end
return
end
GUI:stopAllActions(btn)
local pos = GUI:getPosition(btn)
local x = pos.x
local y = pos.y
local act = GUI:ActionSequence(
GUI:ActionSpawn(
GUI:ActionMoveTo(0.15, x+100, y),
GUI:ActionFadeTo(0.15, 0)
),
GUI:CallFunc(function()
GUI:setVisible(btn, false)
finish = finish + 1
if finish == count and callback then callback() end
end)
)
GUI:runAction(btn, act)
end, 0.03 * (count - i + 1))
end
end
function MainRightTop.main()
local parent = GUI:Attach_RightTop()
if GUI:Win_IsNull(parent) then return end
-- 获取屏幕尺寸
local screenSize = GUI:getContentSize(parent)
local w = screenSize.width or 1280
-- 移除旧节点
local oldNode = GUI:getChildByName(parent, "node_top_btns")
if not GUI:Win_IsNull(oldNode) then
GUI:removeFromParent(oldNode)
end
local oldToggle = GUI:getChildByName(parent, TOGGLE_BTN_CFG.name)
if not GUI:Win_IsNull(oldToggle) then
GUI:removeFromParent(oldToggle)
end
SL:ScheduleOnce(function()
if GUI:Win_IsNull(parent) then return end
-- 创建容器节点
local topNode = GUI:Widget_Create(parent, "node_top_btns", 0, 0, 0, 0)
GUI:setVisible(topNode, true)
MainRightTop:createShuffleEffect(topNode, UI_CONFIG)
local toggleX = -(math.abs(TOGGLE_BTN_CFG.x) * w)
local toggleY = -(math.abs(TOGGLE_BTN_CFG.y) * 40)
local btnToggle = GUI:Button_Create(parent, TOGGLE_BTN_CFG.name, toggleX, toggleY, TOGGLE_BTN_CFG.res)
GUI:setAnchorPoint(btnToggle, 1, 1)
GUI:setOpacity(btnToggle, 0)
GUI:runAction(btnToggle, GUI:ActionFadeTo(0.5, 255))
local isExpanded = true
GUI:setRotation(btnToggle, 180)
GUI:addOnClickEvent(btnToggle, function()
GUI:stopAllActions(btnToggle)
if isExpanded then
isExpanded = false
GUI:runAction(btnToggle, GUI:ActionRotateTo(0.3, 0))
MainRightTop:createFoldEffect(topNode, function()
GUI:setVisible(topNode, false)
end)
else
isExpanded = true
GUI:setVisible(topNode, true)
GUI:runAction(btnToggle, GUI:ActionRotateTo(0.3, 180))
MainRightTop:createShuffleEffect(topNode, UI_CONFIG)
end
end)
end, 0.3)
end
-- 注意:这里不需要调用 main(),引擎会自动调用
-- 只需要返回模块即可
return MainRightTop
```
**主要修复点:**
1. **移除了不存在的函数**:
- `gg.ui:getwh()` → 替换为 `GUI:getContentSize()`
- `gg.ui:delchild()` → 替换为 `GUI:removeFromParent()`
- `gg.button:onclick()` → 替换为 `GUI:addOnClickEvent()`
- `SL:scheduleOnce()` → 替换为 `SL:ScheduleOnce()`(注意大小写)
- `p()` → 替换为 `SL:Print()`
2. **修正了GUI函数调用**:
- `GUI:getPosition()` 返回的是table,需要正确获取x,y坐标
- 使用正确的节点创建函数 `GUI:Widget_Create()`
3. **注意自定义函数**:
- `UIOperator:OpenAuctionUI()` 等函数需要确认是否存在
- `SL:toServer()` 需要替换为正确的发送消息函数
4. **定时器规范**:
- 单次延迟必须使用 `SL:ScheduleOnce()`
5. **代码结构**:
- 移除了最后的 `MainRightTop.main()` 调用,引擎会自动调用main函数
如果你不确定某些函数的具体实现,可以告诉我具体功能,我可以帮你查找浮生梦老师前端课程中对应的函数。