Jump to content

[aprender]painel dx


Recommended Posts

31 minutes ago, DNL291 said:

paineis normais = CEGUI (a interface usada pelo MTA).

Sim, a linha 17 são as posições e tamanho do botão na tela.

ei cara uma duvida,tipo,eu li e reli varias vezes aquele seu topico que vc mandou,mas tipo,so tem linhas de comando relacionadas ao painel,e ao comando como eu faço pra atribuir uma função ao botão?preciso fazer outro script?poderia me dar um exemplo?

 

Link to comment
  • Moderators

Fiz o código com o clique no botão dx e createVehicle:

local sx,sy = guiGetScreenSize()
local _sx, _sy = 1440 /sx, 900 /sy

local painel1_mostrando = false

local panelX, panelY, panelWidth, panelHeight = _sx * 94, _sy * 207, 166, 232
local btnX, btnY, btnWidth, btnHeight = panelX + 10, panelY + 25, 80, 40

addEventHandler( "onClientResourceStart", resourceRoot,
    function()
        addEventHandler( "onClientClick", root, onScreenClick )
        -- sempre que clicar na tela, essa função será chamada
        
        bindKey ( "F2", "down", openDXPanel )
        -- a tecla 'f2' vai ser usada pra abrir ou fechar o painel
    end
)

function onScreenClick( button, state )
    if (button ~= "left") or (state ~= "up") or isConsoleActive() or isMainMenuActive() then return end;
    -- isConsoleActive() e isMainMenuActive() - tô usando pra desativar o uso do painel
    -- quando o console (F8) e/ou o Menu principal estiverem mostrando
    
    if painel1_mostrando == true then -- verificar se o painel DX tá na tela
        if isMouseInPosition( btnX, btnY, btnWidth, btnHeight ) then
            -- aqui significa que o botão DX foi clicado
        
            -- fechar o painel
            removeEventHandler( "onClientRender", root, DX1 )
            showCursor( false )
            painel2_mostrando = false
            createVehicle( 560, -1264.578, -186.06383, 13.802 ) -- veiculo deve ser criado no lado server; esse é só um exemplo
        end
    end
end

function openDXPanel()
    if painel1_mostrando ~= true then

        addEventHandler( "onClientRender", root, DX1 )
        showCursor( true )
        painel1_mostrando = true
    elseif painel1_mostrando then

        removeEventHandler( "onClientRender", root, DX1 )
        showCursor( false )
        painel1_mostrando = false
    end
end

function DX1()
    dxDrawRectangle( panelX, panelY, panelWidth, panelHeight, tocolor(0, 0, 0, 130), false )
    dxDrawRectangle( btnX, btnY, btnWidth, btnHeight, tocolor(0, 0, 0, 130), false ) -- botão
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

Tente entender o código. Qualquer dúvida sobre o código só perguntar (não to afim de explicar agora, cansado).

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...