Jump to content

Botones mediante dxDraw [AYUDA]


Recommended Posts

Posted

Hola, tengo una duda...la cual es como hacer boto es con las funciones dx como por ejemplo un boton con dxRectangle y tambien quisiera saber como hacer algo asi igual con dxDrawImage ayuda porfa :) y como haria para que al pasar el cursor por la imagen o el "boton" se ponga una animacion

Posted

Hola, Podrias crear botones normales y ponerlos Atras del dxRectangle, y para Hacerlos Invisibles podrias Utilizar

bool guiSetAlpha ( element guielement, float alpha ) 

Luego de esto podrias utilizar el Evento "onClientGUIClick" para darle una Funcion a este boton y hacer parecer que la funcion la hace el dxRectangle.

Posted
Hola, Podrias crear botones normales y ponerlos Atras del dxRectangle, y para Hacerlos Invisibles podrias Utilizar
bool guiSetAlpha ( element guielement, float alpha ) 

Luego de esto podrias utilizar el Evento "onClientGUIClick" para darle una Funcion a este boton y hacer parecer que la funcion la hace el dxRectangle.

Por ningún motivo utilices esta abominación de idea, lo mas correcto y eficiente es utilizar 'onClientRender', 'getCursorPosition' y 'onClientClick' para comprobar que el cursor este dentro de la posición del "botón" (Con "botón" me refiero a los rectángulos o imágenes que dibujes con DX). Combinar GUI con Dibujado DX es sumamente ineficiente.

  • 2 months later...
Posted

Te publicare un código antiguo que antes utilicé:

--Seleccion de idioma. 
 
addEvent( 'onClientLanguageSelect' )
 
lang = 1
local sW, sH = guiGetScreenSize()
local iSlang = {
[1] = { sW*.17, sH*.34, sW*.26, sH*.29 },
[2] = { sW*.60, sH*.34, sW*.26, sH*.29 },
[3] = { sW*.33, sH*.05, sW*.72, sH*.20 },
[4] = { sW*.33, sH*.77, sW*.72, sH*.93 }
}
 
local varText = { 'SELECCIONA TU IDIOMA', 'ESPAÑOL' }
 
local alpha = 250
local sFont = dxCreateFont( 'files/idS.ttf', 24 )
local alreadySelected = false
local langSel = 1
 
function drawLangSelect( )
    dxDrawImage( iSlang[1][1],iSlang[1][2],iSlang[1][3],iSlang[1][4], 'files/1.png', 0,0,0,tocolor( 255,255,255,alpha ) )
    dxDrawImage( iSlang[2][1],iSlang[2][2],iSlang[2][3],iSlang[2][4], 'files/2.png', 0,0,0,tocolor( 255,255,255,alpha ) )
    dxDrawText( varText[1], iSlang[3][1],iSlang[3][2],iSlang[3][3],iSlang[3][4], tocolor( 214, 199, 204, alpha ), 1, sFont, 'center', 'center' )
    dxDrawText( varText[2], iSlang[4][1],iSlang[4][2],iSlang[4][3],iSlang[4][4], tocolor( 214, 199, 204, alpha ), 1, sFont, 'center', 'center' )
        if alreadySelected then
            alpha = math.max( alpha - 7.5, 0 )
        end
        screenx, screeny, worldx, worldy, worldz = getCursorPosition()
        if screenx then
            if screenx < 0.5 then
                if langSel ~= 1 then
                    langSel = 1
                    playSound( 'files/click.mp3', false )
                    varText[1] = 'SELECCIONA TU IDIOMA'
                    varText[2] = 'ESPAÑOL'
                end
            else
                if langSel ~= 2 then
                    langSel = 2
                    playSound( 'files/click.mp3', false )
                    varText[1] = 'CHOOSE A LANGUAGE'
                    varText[2] = 'ENGLISH'
                end
            end
        end
end
 
showPlayerHudComponent ( 'radar', false )
 
addEventHandler( 'onClientResourceStart', resourceRoot,
    function()
        addEventHandler( 'onClientRender', root, drawLangSelect )
        showCursor( true )
        showChat( false )
    end
)
 
addEventHandler( 'onClientClick', root,
    function( button )
        if not alreadySelected and button == 'left' then
            alreadySelected = true
            showCursor( false )
            setElementData( localPlayer, 'lang', langSel, true )
            lang = langSel
            --outputConsole( lang )
            setTimer( function()
                triggerEvent( 'onClientLanguageSelect', localPlayer, langSel )
                removeEventHandler( 'onClientRender', root, drawLangSelect )
                langSel = nil
                varText = nil
                iSlang = nil
                alpha = nil
            end, 3500, 1 )
        end
    end
)
 
addEventHandler( 'onClientLanguageSelect', localPlayer,
    function()
        fadeCamera( true, 8 )
        showLoginPanel( true )
        --outputConsole( lang )
    end
)
 
engineImportTXD ( engineLoadTXD ( "files/pedsinho.txd" ), 264 )
engineReplaceModel ( engineLoadDFF ( "files/pedsinho.dff", 264 ), 264 )
 
logDat = {
[1] = guiCreateEdit(0.175, 0.37, 0.16, 0.04, "", true),
[2] = guiCreateEdit(0.175, 0.46, 0.16, 0.04, "", true)    
}
 
guiEditSetMasked ( logDat[2], true )
 
        guiSetVisible( logDat[1], false )
        guiSetVisible( logDat[2], false )
       
function findRotation(x1,y1,x2,y2)
 
  local t = -math.deg(math.atan2(x2-x1,y2-y1))
  if t < 0 then t = t + 360 end;
  return t;
 
end    
 
local pedPos = {
{  -562.93627929688 , -182.88854980469  , 78.40625   },
{  -570.56188964844  , -179.27172851563  , 78.40625   },
{  -560.26354980469  , -190.67237854004  , 78.40625   },
{  -545.92419433594  , -181.00379943848  , 81.885429382324  },
{ -582.88909912109  , -194.32417297363  , 79.275253295898 },
{  -570.77825927734  , -202.36463928223  , 78.370208740234   },
{  -526.56927490234  , -210.44438171387  , 78.40625   },
{  -587.90802001953  , -201.34634399414  , 78.540313720703}
}
 
function showLoginPanel( show )
    if show then
        panelPed = createPed( 264, 0, 0, 0)
        addEventHandler( 'onClientRender', root, logPanelDesign )
        guiSetVisible( logDat[1], true )
        guiSetVisible( logDat[2], true )
        showCursor( true )
        appearing = true
        setCameraMatrix(-590.71081542969 , -202.83940124512 , 83.259002685547  ,  -281.35601806641 , -95.161087036133 , 36.83198547363, -18 , 80  )
        setPedLookAt ( panelPed, -590.71081542969 , -202.83940124512 , 83.259002685547 )
        pedTimer = setTimer(
            function()
                local x, y, z = unpack(pedPos[math.random(1, #pedPos)])
                    setElementPosition( panelPed, x, y, z +.12 )
                    local rotZ = findRotation(x, y, -590.71081542969  , -202.83940124512 )
                    setElementRotation( panelPed, 0, 0, rotZ, 'default', true )
            end, 1600, 0 )
    else
        showCursor( false )
        setTimer( function() removeEventHandler( 'onClientRender', root, logPanelDesign ) end, 500, 1 )
        guiSetVisible( logDat[1], false )
        guiSetVisible( logDat[2], false )
        appearing = false
        posLP = nil
        textB = nil
        killTimer( pedTimer )
        fadeCamera( false, 5 )
        destroyElement( panelPed )
        panelPed = nil
    end
end
 
local alphaLog = 0
 
local posLP = {
[1] = { 0, sH *.3, sW, sH*.43 }, --background rectangle    
[2] = { sW*.175, sH*.32, sW*.3, sH*.365 }, --Username Label
[3] = { sW*.175, sH*.48, sW*.3, sH*.445 }, --Pass Label
[4] = { sW*.5, sH*.32, sW*.5, sH*.7 }, --Line
[5] = { sW*.175, sH*.512, sW*.16, sH*.0375 }, --Image
[6] = { sW*.175, sH*.512, sW*.335, sH*.5495 }, --Ident
[7] = { sW*.175, sH*.54, sW*.3, sH*.585 } --Av Label
}
 
 
local textB = {
[1] = 'USUARIO:;USERNAME:',
[2] = 'CONTRASEÑA:;PASSWORD:',
[3] = 'IDENTIFICARSE;LOG IN'
}
 
local avs = {
[4] = 'Esperando...;Waiting...',
[5] = 'Identificando...;Identifying',
[0] = 'Identificado!;Logged!',
[1] = 'Cuenta no existente;Account not found',
[2] = 'Contraseña Incorrecta;Wrong Password',
[3] = 'ERROR!;ERROR!'
}
 
local idT = avs[4]
 
local img = 'files/idleB.png'
local overButton = false
function logPanelDesign ()
    if appearing then
            alphaLog = math.min(alphaLog + 6, 255)
        else
            alphaLog = math.max( alphaLog - 8, 0)
    end
    dxDrawImage( 0, 0, sW, sH, 'files/background.png', 0, 0, 0, tocolor( 0, 0, 0, alphaLog*.9 ) )
    dxDrawRectangle( posLP[1][1],posLP[1][2],posLP[1][3],posLP[1][4],tocolor(255,240,240,alphaLog-50), false )
    dxDrawText( gettok(textB[1], lang, 59), posLP[2][1],posLP[2][2],posLP[2][3],posLP[2][4], tocolor( 240, 0, 15, alphaLog ), 0.4, sFont, 'left', 'bottom' )
    dxDrawText( gettok(textB[2], lang, 59), posLP[3][1],posLP[3][2],posLP[3][3],posLP[3][4], tocolor( 240, 0, 15, alphaLog ), 0.4, sFont, 'left', 'bottom' )
    dxDrawLine( posLP[4][1],posLP[4][2],posLP[4][3],posLP[4][4], tocolor( 205, 110, 10, alphaLog ), 2 )
    dxDrawImage( posLP[5][1],posLP[5][2],posLP[5][3],posLP[5][4], img )
    dxDrawText( gettok(textB[3], lang, 59), posLP[6][1],posLP[6][2],posLP[6][3],posLP[6][4], tocolor( 240, 0, 15, alphaLog ), 0.32, sFont, 'center', 'center' )
    dxDrawText( gettok(idT, lang, 59), posLP[7][1],posLP[7][2],posLP[7][3],posLP[7][4], tocolor( 24, 24, 24, alphaLog ), 0.4, sFont, 'center', 'center' )
        if isCursorShowing() then
            local x, y, _, _, _ = getCursorPosition()
                if x > 0.175 and x < 0.335 and y > 0.512 and y < 0.5495 then
                    if not overButton then
                        overButton = true
                        img = 'files/overB.png'
                        playSound( 'files/click.mp3', false )
                    end
                else
                    if overButton then
                    overButton = false
                    img = 'files/idleB.png'
                    playSound( 'files/click.mp3', false )
                    end
                end
        end
end
 
spamming = false
       
addEventHandler( 'onClientClick', root,
    function( button )
        if not spamming then
            --outputConsole( button )
            --outputConsole( tostring( overButton ) )
            if button == 'left' and overButton then
                if #guiGetText( logDat[1] ) > 0 and #guiGetText( logDat[2] ) > 0 then
                    triggerServerEvent( 'onPanelButtonPress', localPlayer, 1 ,guiGetText( logDat[1] ), md5(guiGetText( logDat[2] )):upper() )
                    spamming = true
                    idT = avs[5]
                    --outputConsole( 'Enviado' )
                end
            end
        end
    end
)
 
addEvent( 'onIdentifyEnd', true )
    addEventHandler( 'onIdentifyEnd', root,
        function( logged, value )
            if logged then
                appearing = false
                setTimer( showLoginPanel, 320, 1, false )
            else
                spamming = false
            end
            idT = avs[(value or 3)]
        end
    )
   
local validSkins = getValidPedModels()
local nonValidSkins = {0, 264}
local actualValue = 1
 
 for _, i in
Posted

Una pregunta que siempre tuve, ¿cómo detectas la posición del cursor para saber si está arriba? Se que es comparandola, pero el cursor sobre el DX tiene muchísimas posiciones... ¿Hay que hacerlo uno por uno? t.t

Posted
Una pregunta que siempre tuve, ¿cómo detectas la posición del cursor para saber si está arriba? Se que es comparandola, pero el cursor sobre el DX tiene muchísimas posiciones... ¿Hay que hacerlo uno por uno? t.t

Comparas si es mayor a la posición inicial y menor a la posición final.

Me tome el tiempo de describir el método comúnmente utilizado en una respuesta a este post: viewtopic.php?f=145&t=81013

Posted

Te equivocaste al comparar los argumentos de la función del evento onClientClick, comparaste los de la resolución con los de la resolución y no es necesario usar getCursorPosition porque el mismo evento nos da esos valores.

También había un error en el outputChatBox, en client-side el segundo argumento ya es color, no se define el jugador en cs-side.

  
function dxDrawIt() 
dxDrawRectangle(485, 352, 585, 126, tocolor(0, 0, 0, 255), false) 
dxDrawRectangle(486, 353, 583, 124, tocolor(255, 158, 0, 255), false) 
dxDrawRectangle(485, 318, 585, 36, tocolor(0, 0, 0, 255), false) 
dxDrawRectangle(486, 319, 583, 34, tocolor(35, 30, 32, 255), false) 
dxDrawRectangle(898, 426, 162, 42, tocolor(0, 0, 0, 255), false) 
dxDrawRectangle(899, 427, 160, 40, tocolor(37, 27, 35, 255), false) 
dxDrawRectangle(499, 430, 85, 38, tocolor(0, 0, 0, 255), false) 
dxDrawRectangle(500, 431, 83, 36, tocolor(37, 27, 35, 255), false) 
dxDrawRectangle(592, 430, 85, 38, tocolor(0, 0, 0, 255), false) 
dxDrawRectangle(593, 431, 83, 36, tocolor(37, 27, 35, 255), false)      
dxDrawText("Announce", 486, 319, 1069, 353, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false)     
dxDrawText("Say", 899, 427, 1059, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
dxDrawText("ES", 500, 431, 583, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
dxDrawText("EN", 593, 431, 676, 467, tocolor(255, 255, 255, 255), 1.50, "default", "center", "center", false, false, true, false, false) 
end 
addEventHandler("onClientRender", getRootElement(), dxDrawIt) 
showCursor(true) 
editBox = guiCreateEdit(500, 375, 538, 32, "", false) 
theText = guiGetText ( editBox ) 
  
---Variables 
local g_Root = getRootElement() 
language = "N/A" 
            
addEventHandler("onClientClick", g_Root, 
    function( button, state, px, py ) 
        if ( button == "left" and state == "down" ) then 
            if ( px > 500 and px < 583 and py > 431 and py < 467 ) then 
            language = "es" 
            outputChatBox("El lenguaje del anuncio ahora es: ES (Español)", 255, 255, 255, true) 
        elseif ( px > 593 and px < 676 and py > 431 and py < 467 )then 
            language = "en" 
            outputChatBox("The language of the announce is now: EN (English) ", 255, 255, 255, true) 
        end 
    end 
end 
)  
  

NO ESTÁ TESTEADO!

Posted

Yo he intentado hacer un Test de como digo Tomas... el ejemplo que el puso funciono, pero este no... ¿por que?

addEventHandler("onClientRender", getRootElement(), 
    function() 
        dxDrawRectangle(610, 186, 126, 24, tocolor(255, 255, 255, 255), true) 
    end 
) 
showCursor(true) 
  
addEventHandler("onClientClick", getRootElement(), 
    function( button, state, px, py ) 
        if ( button == "left" and state == "down" ) then 
            if ( px > 610 and px < 126 and py > 186 and py < 24 ) then 
            outputChatBox("funciona") 
        end 
    end 
end 
) 
  

Posted
Funciona pero me podrias dar algun ejemplo más para comprender por completo el uso de este?

Yo he intentado hacer lo mismo que tu linux, no veo resultados.

Lo que yo he echo no ha funcionado, por eso he publicado... no soy muy pro con dxDraw

Posted

Mmm linux he visto algo, tu y yo cruzamos lo del rectangulo, pero si te das cuenta tambien tiene un texto, usa los valores del texto y funciona, pero los del rectangulo no (no tengo explicación pero funciona)

Posted

Funcionan los botones, Estoy creando un script de anuncio con el text-speech que ya existe. Se usa el traductor de google como voz. & puse en idioma EN & ES para los textos.

Funciona todo bien, pero ahora quiero hacer que no solo se me ponga un sonido ami si no a todos los jugadores.

Posted

Yo en client-side siempre uso loops, se que aveces son totalmente innecesarios pero prefiero hacerlos antes de que se bugee xD

  
for k,v in ipairs ( getElementsByType("player") ) do 
playSound('sound.mp3',true) 
end 
  

Posted

Bueno tal ves un poco tarde pero para el que lo necesite solucione el codigo de @lLinux ya lo prove y funciona

addEventHandler("onClientRender", getRootElement(), 
    function() 
        dxDrawRectangle(610, 186, 126, 24, tocolor(255, 255, 255, 255), true) 
    end 
) 
showCursor(true) 
  
addEventHandler("onClientClick", getRootElement(), 
    function( button, state, px, py ) 
        if ( button == "left" and state == "down" ) then 
            if ( px > 610 and px < 736) and ( py > 186 and py < 210 ) then 
            outputChatBox("funciona") 
        end 
    end 
end 
) 
  

  • Recently Browsing   0 members

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