سويت لك مثال بسيط
local sx, sy = guiGetScreenSize()
local list = {
buttons = {
{coordinates = {(sx/2)-155, (sy/2), 100, 30}, text = "Button 1", label = "Label 1"},
{coordinates = {(sx/2)-50, (sy/2), 100, 30}, text = "Button 2", label = "Label 2"},
{coordinates = {(sx/2)+55, (sy/2), 100, 30}, text = "Button 3", label = "Label 3"},
},
selected = 1
}
showCursor(true)
addEventHandler("onClientRender", root, function()
for key, value in ipairs(list.buttons) do
local data = value.coordinates
local alpha = 255-(isMouseInPosition(unpack(value.coordinates)) and 100 or 0)
dxDrawRectangle(data[1], data[2], data[3], data[4], tocolor(255, 0, 0, alpha))
dxDrawText(list.buttons[key].text, data[1], data[2], data[1]+data[3], data[2]+data[4], tocolor(255, 255, 255, alpha), 1, "default-bold", "center", "center", true)
end
if list.buttons[list.selected] then
dxDrawText(list.buttons[list.selected].label, (sx/2)-10, (sy/2)+35)
end
end)
addEventHandler("onClientClick", root, function(button, state)
if button == "left" and state == "down" then
for key, value in ipairs(list.buttons) do
if isMouseInPosition(unpack(value.coordinates)) then
list.selected = key
break
end
end
end
end)
function isMouseInPosition(x, y, width, height)
if not isCursorShowing() then
return false
end
local sx, sy = guiGetScreenSize()
local cx, cy = getCursorPosition()
local cx, cy = cx*sx, cy*sy
return (cx >= x and cx <= x+width) and (cy >= y and cy <= y+height)
end
تقدر تضيف ازرار زيادة من الجدول