Jump to content

How to navigate a gridList using arrows keys


Peti

Recommended Posts

Well, the title is self explanatory. How I do that? I have a list with the click event, but I want to allow the user to navigate said list with arrows up and down. Also, I need to trigger the event aswell.

cfd2b9fb045c5ee87dbd80d20a039ce1.png

P.S: BTW, how I get the name of each skin? I must do it by hand?

 

local tablaSkins = getValidPedModels()
    local listaPedsDisponibles = guiCreateGridList(0.04, 0.1, 0.4, 0.78, true, ventanaCrearPed)
    local columnaSkins = guiGridListAddColumn(listaPedsDisponibles, 'Skins', 0.75)
    if (columnaSkins) then
        for _, skin in pairs(tablaSkins) do
            local fila = guiGridListAddRow(listaPedsDisponibles, skin)
            guiGridListSetItemText(listaPedsDisponibles, fila, columnaSkins, skin, false, true)
        end
    end

    addEventHandler('onClientGUIClick', listaPedsDisponibles, function(boton, estado)
        if boton == 'left' and estado == 'up' then
            local skinPed = guiGridListGetItemText(listaPedsDisponibles, guiGridListGetSelectedItem(listaPedsDisponibles), 1)
            setElementModel(localPlayer, skinPed)
        end
    end

 

 

Link to comment

EDIT

First part done by myself, sorry:

    function clickIzquierdo(boton, estado)
        if boton == 'left' and estado == 'up' then
            local skinPed = guiGridListGetItemText(listaPedsDisponibles, guiGridListGetSelectedItem(listaPedsDisponibles), 1)
            setElementModel(localPlayer, skinPed)
        end
    end
    addEventHandler('onClientGUIClick', listaPedsDisponibles, clickIzquierdo)

    function flechas(boton, estado)
        if estado == true then
            local filaSeleccionada, columnaSeleccionada = guiGridListGetSelectedItem(listaPedsDisponibles)
            if boton == 'arrow_u' then
                guiGridListSetSelectedItem(listaPedsDisponibles, filaSeleccionada - 1, columnaSeleccionada, true)
                setElementModel(localPlayer, guiGridListGetItemText(listaPedsDisponibles, filaSeleccionada - 1, columnaSeleccionada))
            elseif boton =='arrow_d' then
                guiGridListSetSelectedItem(listaPedsDisponibles, filaSeleccionada + 1, columnaSeleccionada, true)
                setElementModel(localPlayer, guiGridListGetItemText(listaPedsDisponibles, filaSeleccionada + 1, columnaSeleccionada))
            end
    	if filaSeleccionada == -1 then guiGridListSetSelectedItem(listaPedsDisponibles, 0, 1, true) end
        end
    end
    addEventHandler('onClientKey', root, flechas)

 

Now, I need to know about the second part.

Edited by Peti
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...