课程入口
local module = {}
module.t = {
{id = 1, name = "武器", menus = {"木剑","屠龙","裁决"}},
{id = 2, name = "防具", menus = {"布衣","天魔神甲","法神披风"}},
{id = 3, name = "首饰", menus = {"绿色项链","力量戒指","法神戒指"}},
}
local state = nil
SL:print(module.t[1].name)
function module.creatSubMenus(listView,index,menus)
for k ,v in pairs(menus) do
local oldbt = GUI:getChildByName(node, "BtnOk2_".. k)
if oldbt then
-- and not GUI:Win_IsNull(oldbt)
SL:print("移除二级菜单")
GUI:removeChildByName(node, "BtnOk2_"..k)
end
-- removeChildByName(widget, name)
if node then
local BtnOk2 = GUI:Button_Create(node, "BtnOk2_"..k, 0, 0, "res/public/btn_push_short.png")
GUI:setAnchorPoint(BtnOk2, { x = 0.5, y = 0.5 })
GUI:setOpacity(BtnOk2, 0)
GUI:Button_setTitleText(BtnOk2,v)
GUI:Button_setTitleFontSize(BtnOk2, 16)
GUI:Button_setTitleColor(BtnOk2, "249")
GUI:ListView_insertCustomItem(listView,BtnOk2,index)
GUI:Timeline_FadeIn(BtnOk2, 0.5, nil)
end
end
GUI:ListView_doLayout(listView)
end
function module.removbutton(listView,n)
-- listView
-- 遍历 list下 所有的子节点
local child = GUI:getChildren(listView)
local n = 0
for k ,v in ipairs(child) do
SL:print( GUI:getName(v))
if GUI:getName(v):find("2_") then
n = n + 1
GUI:setOpacity(v, 0) -- 隐藏
SL:print("清除-----------------BtnOk2_"..n)
GUI:removeChildByName(listView, "BtnOk2_"..n)
end
end
GUI:ListView_doLayout(listView)
local child = GUI:getChildren(listView)
for k ,v in ipairs(child) do
SL:print("移除后查看", GUI:getName(v))
end
end
function module.creatbutton(listView)
-- module.removbutton(listView,n)
for k ,v in ipairs(module.t) do
SL:print(v.name)
local oldbt = GUI:getChildByName(listView, "BtnOk"..v.id)
if oldbt and not GUI:Win_IsNull(oldbt) then
GUI:removeChildByName(node, "BtnOk"..v.id)
end
local BtnOk = GUI:Button_Create(listView, "BtnOk"..v.id, 0, 0, "res/public/1900000611.png")
GUI:setAnchorPoint(BtnOk, { x = 0.5, y = 0.5 })
GUI:Button_setTitleText(BtnOk, v.name)
GUI:Button_setTitleFontSize(BtnOk, 16)
GUI:addOnClickEvent(BtnOk, function()
SL:print("v.id:"..v.id)
if state == k then
SL:print("关闭/收起")
module.removbutton(listView,k)
state = nil
else
SL:print("展开")
-- 展开二级菜单
if state then
module.removbutton(listView,state)
end
SL:print(v.menus)
module.creatSubMenus(listView,k,v.menus)
state = k
end
-- do something
--- 展开
---
--- 收起
end)
end
end
function module.creatwin()
local win = GUI:Win_Create("Win_1", 0, 0, 1136, 640)
local listView = GUI:ListView_Create(win,"listView", 0, 0, 300, 400, 1)
node = GUI:Node_Create(win, "node", 0, 0)
GUI:ListView_setGravity(listView, 2)
GUI:ListView_setDirection(listView, 1)
module.creatbutton(listView)
end
function module.main()
SL:print("启动界面!")
module.creatwin()
end