local screenX, screenY = guiGetScreenSize()
local rectangleWidth, rectangleHeight = 300, 200
local labelArea = 40
local labelX, labelY = 30, 30
local offX, offY = 0, 0
local centerX, centerY = (screenX / 2) - (rectangleWidth / 2), (screenY / 2) - (rectangleHeight / 2)
local isHolding = false
local function draw()
dxDrawRectangle(
centerX,
centerY,
rectangleWidth,
rectangleHeight,
tocolor(0, 0, 0, 100),
false
)
dxDrawRectangle(labelX, labelY, labelArea, labelArea, tocolor(255, 255, 255, 255), false)
end
local function isCursorOnElement(
mouseX,
mouseY,
elementX,
elementY,
width,
height
)
return mouseX - elementX > 0
and mouseX - elementX <= width
and mouseY - elementY > 0
and mouseY - elementY <= height
end
local function onClick(
button,
state,
absoluteX,
absoluteY
)
if button == "left" and state == "down" and
isCursorOnElement(absoluteX, absoluteY, labelX, labelY, 40, 40)
then
isHolding = true
offX = absoluteX - labelX
offY = absoluteY - labelY
else
isHolding = false
end
end
local function onCursorMove(
relativeX,
relativeY,
absoluteX,
absoluteY
)
if isHolding then
labelX = absoluteX - offX
labelY = absoluteY - offY
end
end
addEventHandler("onClientRender", root, draw)
addEventHandler("onClientClick", root, onClick)
addEventHandler("onClientCursorMove", root, onCursorMove)
Bom dia,
Sou um novato em lua que está vindo de outras linguagens, eventualmente, sou backend e estou curtindo desenvolver em lua pra complementar o time do servidor. Queria saber se há algo que poderia melhorar no meu código teste que consiste em fazer o efeito drag and drop.