unction Button:upshow()
local Node = GUI:getChildByName(parent, "Node1_upshow")
if Node then
GUI:setVisible(Node, true)
return
end
local Node_1 = GUI:Node_Create(parent, "Node1_upshow", 0, 0)
--基础容器
local layout = GUI:Layout_Crea
要让按钮从右到左排序,可以在创建按钮时调整坐标计算方式。以下是修改后的代码:
```lua
function Button:upshow()
local Node = GUI:getChildByName(parent, "Node1_upshow")
if Node then
GUI:setVisible(Node, true)
return
end
local Node_1 = GUI:Node_Create(parent, "Node1_upshow", 0, 0)
--基础容器
local layout = GUI:Layout_Create(Node_1, "layout1_upshow", topweizhi.x, topweizhi.y, 100, 120,
false)
GUI:setAnchorPoint(layout, 1, 1)
local toplist = {} --top表重构
for k, v in pairs(budata) do
if v.type == 1 then
toplist[v.weizhi] = v
end
end
-- 从右到左排序的关键修改
local buttonWidth = 100 -- 假设按钮宽度为100,根据实际情况调整
local currentX = layoutWidth or 100 -- layout的宽度,从最右边开始
-- 按位置排序,确保从右到左
local sortedKeys = {}
for k in pairs(toplist) do
table.insert(sortedKeys, k)
end
table.sort(sortedKeys, function(a, b) return a > b end) -- 降序排列
for _, key in ipairs(sortedKeys) do
local v = toplist[key]
-- 计算从右到左的坐标
currentX = currentX - buttonWidth - 5 -- 减去按钮宽度和间距
local bt = GUI:Button_Create(layout, v.redname, currentX, 0, v.img)
GUI:addOnClickEvent(bt, function()
local func = MList[v.script]
if not func or not func.main then
return SL:Print(v.script .. " 不存在或没有main函数")
end
-- 点击触发,执行main函数
func:main()
end)
end
local hang = budata[1].rownums == nil and 6 or budata[1].rownums
GUI:UserUILayout(layout, {
dir = 3,
addDir = 3,
gap = { x = 5, y = 5 },
rownums = { hang },
autosize = true,
})
end
```
主要修改点:
1. 对`toplist`的键进行降序排序(`table.sort(sortedKeys, function(a, b) return a > b end)`)
2. 从layout的右边开始计算坐标(`currentX = layoutWidth or 100`)
3. 每创建一个按钮,`currentX`向左移动一个按钮宽度加间距的距离
这样按钮就会按照从右到左的顺序排列显示。