Jump to content

Seleção


Recommended Posts

Opcoes = {
    {"1"},
    {"2"},
    {"3"},
    {"4"},
    {"5"},
    {"6"},
}

Pos = {
    {726, 330 , 343, 37},
    {726, 405, 343, 37},
    {726, 480, 343, 37},
    {726, 555, 343, 37},
}



Opcao1 = 1
Opcao2 = 2
Opcao3 = 3
Opcao4 = 4


function Abrir_Painel()
    if isEventHandlerAdded("onClientRender",getRootElement(), DxTest) then
        removeEventHandler("onClientRender",root,DxTest)
        showCursor(false)
    else
        addEventHandler("onClientRender",root,DxTest)
        showCursor(true)
    end
end
bindKey("l","down",Abrir_Painel)

function DxTest()
    dxDrawRectangle(724, 261, 345, 381, tocolor(1, 0, 0, 102), false)
    dxDrawRectangle(725, 258, 344, 63, tocolor(1, 0, 0, 248), false)
    for i, v in ipairs(Pos) do
        dxDrawRectangle(v[1],v[2],v[3],v[4], tocolor(1, 0, 0, 150), false)
    end
    dxDrawText(""..Opcoes[Opcao1][1].."", 900, 341, 1070, 369, tocolor(255, 254, 254, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    dxDrawText(""..Opcoes[Opcao2][1].."", 900, 341 +75, 1070, 369, tocolor(255, 254, 254, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    dxDrawText(""..Opcoes[Opcao3][1].."", 900, 341 +150, 1070, 369, tocolor(255, 254, 254, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
    dxDrawText(""..Opcoes[Opcao4][1].."", 900, 341 +225, 1070, 369, tocolor(255, 254, 254, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
end


function AbaixarPos(button)
    if isCursorOnElement(724, 261, 345, 381) then
        if button == "mouse_wheel_down" then
            proximaPagina = Opcao4 +1
            if proximaPagina > #Opcoes then
                return
            end
            Opcao1 = Opcao1 +1
            Opcao2 = Opcao2 +1
            Opcao3 = Opcao3 +1
            Opcao4 = Opcao4 +1
        end
    end
end
bindKey("mouse_wheel_down", "down", AbaixarPos)

function AumentarPos(button)
    if isCursorOnElement(724, 261, 345, 381) then
        if button == "mouse_wheel_up" then
            paginaAnterior = Opcao1 -1
            if paginaAnterior == 0 then
                return
            end
            Opcao1 = Opcao1 -1
            Opcao2 = Opcao2 -1
            Opcao3 = Opcao3 -1
            Opcao4 = Opcao4 -1
        end
    end
end
bindKey("mouse_wheel_up","down",AumentarPos)


function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
    if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
        local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
        if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
            for i, v in ipairs( aAttachedFunctions ) do
                if v == func then
                    return true
                end
            end
        end
    end
    return false
end

function isCursorOnElement(x, y, w, h)
	if (not isCursorShowing()) then
		return false
	end
	local mx, my = getCursorPosition()
	local fullx, fully = guiGetScreenSize()
	cursorx, cursory = mx*fullx, my*fully
	if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
		return true
	else
		return false
	end
end

Coloquei a função onde eu peguei de base do LucasST (Não é meu codigo), mas eu apenas editei algumas coisas que não prejudica nada, mas resumindo eu quero fazer uma forma de seleção nos que estão escrito em "Pos" que apos clicar ira selecionar as "Opções", e ao eu rolar o scroll ele ira sumir pois tara selecionado no que foi selecionado

Link to comment


local screenW, screenH = guiGetScreenSize ()
local resW, resH = 1920,1080
local x, y = (screenW/resW), (screenH/resH)

TabelasInfos = {
    {"Julio"},
    {"Maria"},
    {"Lucas"},
    {"João"},
    {"Julia"},
    {"Marcos"},
    {"Daniel"},
    {"Sabrina"},
    {"Thiago"},
}


function Abrir_Painel()
    if isEventHandlerAdded("onClientRender",getRootElement(), DxTest) then
        removeEventHandler("onClientRender",root,DxTest)
        showCursor(false)
    else
        addEventHandler("onClientRender",root,DxTest)
        showCursor(true)
        Pos = {
            [1] = {1,726, 330, 343, 37},
            [2] = {2,726, 405, 343, 37},
            [3] = {3,726, 480, 343, 37},
            [4] = {4,726, 555, 343, 37},
        }
        Selecionado = 0
    end
end
bindKey("l","down",Abrir_Painel)

function DxTest()
    dxDrawRectangle(x*724, y*261, x*345, y*381, tocolor(1, 0, 0, 102), false)
    dxDrawRectangle(x*725, y*258, x*344, y*63, tocolor(1, 0, 0, 248), false)
    for i = 1,#Pos do
        if #TabelasInfos >= Pos[i][1] then
            local Index = Pos[i][1]
            if Selecionado == Index then
                dxDrawRectangle(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5], tocolor(1, 0, 0, 200), false)
            else
                dxDrawRectangle(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5], tocolor(1, 0, 0, 150), false)
            end
            dxDrawText(""..TabelasInfos[Index][1].."", x*(Pos[i][2] + 160), y*(Pos[i][3] +11), x*1070, y*369, tocolor(255, 254, 254, 255), 1.00, "default-bold", "left", "top", false, false, false, false, false)
        end
    end
end


function TrocarPos(button)
    if isEventHandlerAdded("onClientRender",root,DxTest) then
        if isCursorOnElement(x*724, y*319, x*345, y*321) then
            if button == "mouse_wheel_down" then
                if #TabelasInfos > Pos[#Pos][1] then
                    for i = 1,#Pos do
                        Pos[i][1] = Pos[i][1] +1
                    end
                end
            elseif button == "mouse_wheel_up" then
                if Pos[1][1] ~= 1 then
                    for i = 1,#Pos do
                        Pos[i][1] = Pos[i][1] -1
                    end
                end
            end
        end
    end
end
bindKey("mouse_wheel_down", "down",TrocarPos)
bindKey("mouse_wheel_up", "down",TrocarPos )


function SelecionarPos(b,s)
    if isEventHandlerAdded("onClientRender",root,DxTest) then
        if b == "left" and s == "down" then
            for i = 1,#Pos do
                if isCursorOnElement(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5]) then
                    if Selecionado ~= Pos[i][1] then
                        Selecionado = Pos[i][1]
                    else
                        Selecionado = 0
                    end
                end
            end
        end
    end
end
addEventHandler("onClientClick",root,SelecionarPos)


function isEventHandlerAdded( sEventName, pElementAttachedTo, func )
    if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then
        local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo )
        if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then
            for i, v in ipairs( aAttachedFunctions ) do
                if v == func then
                    return true
                end
            end
        end
    end
    return false
end

function isCursorOnElement(x, y, w, h)
	if (not isCursorShowing()) then
		return false
	end
	local mx, my = getCursorPosition()
	local fullx, fully = guiGetScreenSize()
	cursorx, cursory = mx*fullx, my*fully
	if cursorx > x and cursorx < x + w and cursory > y and cursory < y + h then
		return true
	else
		return false
	end
end

A Antiga ficou com muitas coisas desnecessárias, dei uma melhorada.

Edited by LucasST
Erro Ortográfico
Link to comment
Painel = false

function OpenPanel()
    if Painel == false then
        addEventHandler("onClientRender", root, PanelPrision)
        Painel = true
        showCursor(true)
        Pos = {
            [1] = {1,595, 362, 230, 20},
            [2] = {2,595, 382, 230, 20},
            [3] = {3,595, 402, 230, 20},
            [4] = {4,595, 422, 230, 20},
            [5] = {5,595, 442, 230, 20},
            [6] = {6,595, 462, 230, 20},
        }
        Selecionado = 0
    end
end
addEvent("Prison", true)
addEventHandler("Prison", root, OpenPanel)

function PanelPrision()

dxDrawRoundedRectangle(x*595, y*343, x*230, y*144, tocolor(54, 54, 54, 255), 2) --- Fundo Artigos
    for i = 1,#Pos do
        if #Edit["Artigos"] >= Pos[i][1] then
            local Index = Pos[i][1]
            if Selecionado == Index then
            dxDrawRoundedRectangle(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5], tocolor(64, 105, 225, 255), 2) --- Fundo Artigos
        else
            dxDrawRoundedRectangle(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5], tocolor(54, 54, 54, 255), 2) --- Fundo Artigos
        end
    end
end

    dxDrawText(""..Edit["Artigos"][Opcao1][1].."", x*1400, y*384, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
    dxDrawText(""..Edit["Artigos"][Opcao2][1].."", x*1400, y*364, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
    dxDrawText(""..Edit["Artigos"][Opcao3][1].."", x*1400, y*404, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
    dxDrawText(""..Edit["Artigos"][Opcao4][1].."", x*1400, y*424, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
    dxDrawText(""..Edit["Artigos"][Opcao5][1].."", x*1400, y*444, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
    dxDrawText(""..Edit["Artigos"][Opcao6][1].."", x*1400, y*464, x*16, y*16, tocolor(255, 255, 255, 255), 0.50, infinity.Fonte01, "center", "top", false, false, false, false, false) --- Artigo
  
end



function ScrollBaixo(button)
    if isCursorOnElement(x*595, y*343, x*230, y*144) then
        if button == "mouse_wheel_down" then
            for i = 1,#Pos do
                Pos[i][1] = Pos[i][1] + 6 -- (Para não ficar descendo ou subindo a seleção)
            proximaPagina = Opcao6 +1
            if proximaPagina > #Edit["Artigos"] then
                return
            end
            Opcao1 = Opcao1 +1
            Opcao2 = Opcao2 +1
            Opcao3 = Opcao3 +1
            Opcao4 = Opcao4 +1
            Opcao5 = Opcao5 +1
            Opcao6 = Opcao6 +1
        end
        end
    end
end
bindKey("mouse_wheel_down", "down", ScrollBaixo)

function ScrollCima(button)
    if isCursorOnElement(x*595, y*343, x*230, y*144) then
        if button == "mouse_wheel_up" then
            for i = 1,#Pos do
                Pos[i][1] = Pos[i][1] -6 -- (Para não ficar descendo ou subindo a seleção)
            paginaAnterior = Opcao1 -1
            if paginaAnterior == 0 then
                return
            end
            Opcao1 = Opcao1 -1
            Opcao2 = Opcao2 -1
            Opcao3 = Opcao3 -1
            Opcao4 = Opcao4 -1
            Opcao5 = Opcao5 -1
            Opcao6 = Opcao6 -1
        end
    end
    end
end
bindKey("mouse_wheel_up","down",ScrollCima)


function SelecionarPos(b,s)
    if Painel == true then
        if b == "left" and s == "down" then
            for i = 1,#Pos do
                if cursorPosition(x*Pos[i][2],y*Pos[i][3],x*Pos[i][4],y*Pos[i][5]) then
                    if Selecionado ~= Pos[i][1] then
                        Selecionado = Pos[i][1]
                    else
                        Selecionado = 0
                    end
                end
            end
        end
    end
end
addEventHandler("onClientClick",root,SelecionarPos)





---------------- EDIT --------------

--[[
██╗░░██╗░█████╗░██╗░░██╗██╗███╗░░██╗░█████╗░███╗░░██╗
██║░██╔╝██╔══██╗██║░░██║██║████╗░██║██╔══██╗████╗░██║
█████═╝░███████║███████║██║██╔██╗██║███████║██╔██╗██║
██╔═██╗░██╔══██║██╔══██║██║██║╚████║██╔══██║██║╚████║
██║░╚██╗██║░░██║██║░░██║██║██║░╚███║██║░░██║██║░╚███║
╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚═╝╚═╝╚═╝░░╚══╝╚═╝░░╚═╝╚═╝░░╚══╝
]]


Edit = {
    {"Policial"}, --- Acl
    {1531.79126, -1671.59375, 13.38281}, --- Posição Marker
    {255, 255, 255, 255}, --- Cor Marker
    {"Torne-se um policial para ter acesso a este local"}, --- Mensagem Erro
    {"Painel de apreensão aberto com sucesso"}, --- Mensagem Sucesso
    ["Artigos"] = {
        {"Porte Ilegal - Art. 16°", 20}, --- Artigo, Tempo
        {"Furto - Art. 155°", 20}, --- Artigo, Tempo
        {"Roubo a Mão Armada - Art. 157°", 20}, --- Artigo, Tempo
        {"Trafico de Armas - Art.87°", 20}, --- Artigo, Tempo
        {"Formação de Quadrilha - Art. 288°", 20}, --- Artigo, Tempo
        {"Negociação de Armas - Art. 180°", 20}, --- Artigo, Tempo
        {"Trafico de Drogas - Art. 33°", 20}, --- Artigo, Tempo
        {"Ameaça - Art. 147°", 20}, --- Artigo, Tempo
        {"Suborno - Art. 333°", 20}, --- Artigo, Tempo
        {"Alta Velocidade - Art. 218°", 20}, --- Artigo, Tempo
        {"Tentativa de Fuga - Art. 329°", 20}, --- Artigo, Tempo
        {"Direção Perigosa - Art. 175°", 20}, --- Artigo, Tempo
        {"Corrida Ilegal - Art. 173°", 20}, --- Artigo, Tempo
        {"Obstrução de Via Publica - Art. 246°", 20}, --- Artigo, Tempo
        {"Agressão - Art. 129°", 20}, --- Artigo, Tempo
        {"Sequestro - Art. 148°", 20}, --- Artigo, Tempo
        {"Tentativa de Homicídio - Art. 131°", 20}, --- Artigo, Tempo
        {"Homicídio Culposo - Art. 121°", 20}, --- Artigo, Tempo
        {"Cumplicidade - Art. 27°", 20}, --- Artigo, Tempo
        {"Desobediência - Art. 195°", 20}, --- Artigo, Tempo
        {"Corrupção - Art. 317°", 20}, --- Artigo, Tempo
        {"Vandalismo - Art. 163°", 20}, --- Artigo, Tempo
        {"Abuso de Autoridade - Art. 4°", 20}, --- Artigo, Tempo
        {"Apoligia ao Crime - Art. 287°", 20}, --- Artigo, Tempo
        {"Extorsão - Art. 158°", 20}, --- Artigo, Tempo
        {"Calunia - Art. 138°", 20}, --- Artigo, Tempo
        {"Foragido - Art. 410°", 20}, --- Artigo, Tempo
    }
}

 

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