前端UI展示:GUILayout\F\合成面板.lua
Hecheng = {}
local _cfg = cfg_compound
local GUIparent = ""
local wnd_w, wnd_h = 815, 575
local page1
local _color = {
["true"] = "#787974",
["false"] = "#DEBA6C",
}
Hecheng.main = function()
local _parent = GUI:Win_Create ( "Hecheng", 0, 0, 0, 0, true, false, true, true)
if _parent then
GUIparent = _parent
winSize = SL:GetScreenSize()
local x = winSize.width / 2
local y = winSize.height / 2
local w = winSize.width
local h = winSize.height
--设置透明关闭按钮
local handle = GUI:Layout_Create(_parent, "layout_close", x, y, w, h)
if handle then
GUI:Layout_setBackGroundColor(handle, "#000000")
GUI:Layout_setBackGroundColorType(handle, 1)
GUI:Layout_setBackGroundColorOpacity(handle, 95)
GUI:setAnchorPoint(handle, 0.5, 0.5)
GUI:setTouchEnabled(handle, true)
GUI:addOnClickEvent(handle, function()
GUI:Win_Close(_parent)
end)
end
--NPC背景
local img_bg = GUI:Image_Create( _parent, "img_bg", x, y, "res/01/010000.png")
if img_bg then
GUI:setAnchorPoint(img_bg, 0.5, 0.5)
GUI:setContentSize(img_bg, {width = wnd_w, height = wnd_h})
GUI:setTouchEnabled(img_bg, true)
end
--关闭按钮
local btn_close = GUI:Button_Create( img_bg, "btn_close", wnd_w-25, wnd_h-20, "res/01/010008.png")
if btn_close then
GUI:setAnchorPoint(btn_close, 1, 1)
GUI:Button_loadTexturePressed(btn_close, "res/01/010009.png")
GUI:addOnClickEvent(btn_close, function ()
GUI:Win_Close(_parent)
end)
end
local img_line = GUI:Image_Create( img_bg, "img_line", 190, 20, "res/custom/common/img_line_1.png")
local txt_title = GUI:Text_Create(img_bg, "txt_title", wnd_w / 2, wnd_h - 50, 20, "#D6C6AD", "合 成")
GUI:setAnchorPoint(txt_title, 0.5, 0.5)
--左侧列表
local left_listview = GUI:ListView_Create(img_bg, "left_listview", 130, 0, 116, wnd_h - 120, 1)
if left_listview then
GUI:setAnchorPoint(left_listview, 0.5, 0)
GUI:ListView_setItemsMargin(left_listview, 10)
GUI:ListView_setClippingEnabled(left_listview, true)
GUI:ListView_setDirection(left_listview, 1)
for i, v in ipairs(_cfg) do
local btn_hc = GUI:Button_Create( left_listview, "btn_hc" .. i, 0, 0, "res/01/010005.png")
if btn_hc then
local txt_btn = GUI:Text_Create(btn_hc, "txt_btn" .. i, 55, 6, 20 , "#787974", v.title)
GUI:setAnchorPoint(txt_btn, 0.5, 0)
GUI:Button_loadTexturePressed(btn_hc, "res/01/010006.png")
GUI:Button_loadTextureDisabled(btn_hc, "res/01/010006.png")
end
GUI:addOnClickEvent(btn_hc, function ()
Hecheng.updatePage(i)
end)
if i == 1 then
Hecheng.updatePage(1)
end
end
end
end
end
--右侧合成按钮展示
function Hecheng.updatePage(index)
if index == page1 then return end
--取消上次选中按钮
if page1 then
local btn_select = GUI:GetWindow(GUIparent, "img_bg/left_listview/btn_hc" .. page1 )
local txt_btn = GUI:GetWindow(btn_select, "txt_btn" .. page1 )
GUI:Button_setBrightEx(btn_select, true) --取消选择状态
GUI:Text_setTextColor(txt_btn, _color["true"])
end
--新的按钮选中状态
local btn_select = GUI:GetWindow(GUIparent, "img_bg/left_listview/btn_hc" .. index )
if btn_select then
local txt_btn = GUI:GetWindow(btn_select, "txt_btn" .. index )
GUI:Button_setBrightEx(btn_select, false)
GUI:Text_setTextColor(txt_btn, _color["false"])
end
--全局变量保存当前选中按钮,方便下次切换时判断
page1 = index
Hecheng.updateUI(index)
end
local imgUI = {}
--刷新合成页面
function Hecheng.updateUI(index)
local _parent = GUI:GetWindow(GUIparent, "img_bg")
local right_list = GUI:GetWindow(_parent, "right_list")
if not right_list then
right_list = GUI:ListView_Create( _parent, "right_list", 195, 445 / 2 + 15, 560,445, 1)
GUI:setAnchorPoint(right_list, 0,0.5)
GUI:ListView_setClippingEnabled(right_list,true)
GUI:ListView_setItemsMargin(right_list, 15)
end
GUI:removeAllChildren(right_list)
local cfg = _cfg[page1]
local max = #cfg
local limit = 2
local num = math.ceil(max/limit) --循环的行数
local idx = 0
local item_w, item_h = 270, 190
for i = 1, num do
local handle = GUI:Layout_Create( right_list, "layout_item_" .. i, 0, 0, item_w * limit + 10, item_h + 10) --每行 创建个容器
GUI:setAnchorPoint(handle, 0.5, 0.5)
GUI:setTouchEnabled(handle, true)
-- GUI:Layout_setBackGroundColor(handle, "#4AE74A")
-- GUI:Layout_setBackGroundColorType(handle, 1)
-- GUI:Layout_setBackGroundColorOpacity(handle, 155)
for j = 1, limit do --创建2个背景图
idx = idx + 1
if idx <= max then --保存创建的背景图和合成物品个数相同,避免多建
local _handle = GUI:Image_Create( handle, "item_" .. j, (j - 1) * (item_w + 7) + 5, 5, "res/custom/common/bg_hhdb_02.jpg")
if _handle then
GUI:Image_setScale9Slice(_handle, 10, 10, 10, 10)
GUI:setAnchorPoint(_handle, 0,0)
GUI:setContentSize(_handle, {width = item_w, height = item_h})
GUI:setTouchEnabled(_handle, true)
imgUI["item_"..idx] = _handle --保存在imgUI中
end
end
end
end
for i, v in ipairs(cfg) do
-- SL:Print("index === ".. i)
local _fahandle = imgUI["item_" .. i]
local item_name = SL:GetItemNameByIndex(v.product[1][1])
local handle = GUI:Text_Create(_fahandle, "txt_title", item_w/2, item_h - 20, 18, "#D6C6AD", item_name)
if handle then
GUI:setAnchorPoint(handle, 0.5, 0.5)
end
handle = GUI:Image_Create( _fahandle, "item_bg" .. i, 30, 70, "res/custom/common/object_di_1.png")
if handle then
GUI:setScale(handle, 0.9)
end
GUI:ItemShow_Create(_fahandle, "item" .. i, 30, 70, {index = v.product[1][1], look = true})
GUI:RichText_Create(_fahandle, "txt_pro" .. i, 10, 30, "成功率:"..v.probability/100 .. "%", 200, 16, "#D6C6AD")
handle = GUI:Button_Create( _fahandle, "page1_" .. i, 130, 20, "res/01/010005.png")
if handle then
local txt_handle = GUI:Text_Create(handle, "Go", 55, 5, 18, "#FFFFB7", "合 成")
GUI:setAnchorPoint(txt_handle, 0.5, 0)
GUI:addOnClickEvent(handle, function()
Hecheng.go(v.idx)
end)
end
local x, y = 185, 120
for j, var in ipairs(v.itemid1) do
local bag_num = SL:GetItemNumberByIndex(var[1])
local cost_num = var[2]
local cost_name = SL:GetItemNameByIndex(var[1])
local str = SLChangeColour(bag_num, cost_num, cost_name)
local handle = GUI:RichText_Create(_fahandle, "txt_need" .. j, x, y, str, 265)
y = y -30
GUI:setAnchorPoint(handle, 0.5,0.5)
end
end
end
Hecheng.go = function(index)
SL:SubmitForm("F/合成表单","main",index)
end
Hecheng.main()