Jump to content

[HELP] DxScroll


iAxel

Recommended Posts

Hello guys!

A few days ago did DxScroll, but can not seem to solve one problem

How to limit the visibility of items, as in the gui Scroll

Namely thus

Screenshots:

3HJ7tin.png

MygXAhl.png

YLi1td7.png

T9thMLX.png

Code:

  
local sW, sH = guiGetScreenSize() 
local bW, bH = (sW/2), (sH/2) 
local offset = 0 
-- 
addEventHandler('onClientRender', root, 
    function () 
        if (isLogged(localPlayer)) then 
                dxDrawRectangle(bW+190, bH-300, 320, 20, tocolor(0, 0, 0, 255)) 
                dxDrawText('INVENTORY', bW+195, bH-300, bW+510, bH-280, tocolor(160, 160, 160, 255), 1, 'default', 'left', 'center', false, false, true, false, false) 
                --Box 
                dxDrawLine(bW+190, bH-281, bW+190, bH+280, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+510, bH-281, bW+190, bH-281, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+190, bH+280, bW+510, bH+280, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+510, bH+280, bW+510, bH-281, tocolor(200, 200, 200, 100), 1) 
                dxDrawRectangle(bW+191, bH-280, 319, 560, tocolor(0, 0, 0, 70)) 
                dxDrawLine(bW+500, bH-280, bW+500, bH+279, tocolor(200, 200, 200, 100), 1) 
                --Scrollbar 
                dxDrawLine(bW+502, bH-280+offset, bW+502, bH-109+offset, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+508, bH-280+offset, bW+502, bH-280+offset, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+502, bH-109+offset, bW+508, bH-109+offset, tocolor(200, 200, 200, 100), 1) 
                dxDrawLine(bW+508, bH-109+offset, bW+508, bH-280+offset, tocolor(200, 200, 200, 100), 1) 
                dxDrawRectangle(bW+503, bH-279+offset, 5, 170, tocolor(0, 0, 0, 0)) 
                --Items 
                for i = 1, 10 do 
                    dxDrawRectangle(bW+191, bH-345+65*i-offset, 309, 60, tocolor(100, 100, 100, 200)) 
                    dxDrawImage(bW+191, bH-345+65*i-offset, 60, 60, ':guieditor/images/plus.png', 0, 0, 0, tocolor(255, 255, 255, 255)) 
                    dxDrawText('Backpack '..i, bW+261, bH-326+65*i-offset, bW+499, bH-306+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'left', 'center', false, false, true, false, false) 
                    dxDrawText('0/'..i, bW+451, bH-346+65*i-offset, bW+499, bH-326+65*i-offset, tocolor(255, 255, 255, 255), 1, 'default-bold', 'right', 'center', false, false, true, false, false) 
                end 
            end 
        end 
    end 
) 
-- 
function Scroll(key, state) 
    if (isLogged(localPlayer)) then 
        if (state == 'down') then 
            if (key == 'mouse_wheel_up') then 
                if (offset > 0) then 
                    offset = offset-97 
                else 
                    offset = 0 
                end 
            elseif (key == 'mouse_wheel_down') then 
                if (offset < 388) then 
                    offset = offset+97 
                else 
                    offset = 388 
                end 
            end 
        end 
    end 
end 
bindKey('mouse_wheel_up', 'down', Scroll) 
bindKey('mouse_wheel_down', 'down', Scroll) 
  

Help solve the problem

Thanks in advance to all

Link to comment

Hi,

Scrollbar is also a difficult script to make it in dX but in fact you can use the both function.

onclientclick with button in 'up' states put a variable for looking if its hold.

then when u use oncursormove make a math calcul for see the last position and the current position then u move your scrollbar (image) with it and also move the content too.

I don't know to make you a good answer but i didn't have a lot of time for make you this script.

I hope i could help you.

Link to comment
He answered your question.

First you use onClientClick, if the state is "down" - assume the player is holding the left key down. You can also make sure it's held down via using getKeyState.

You then use onClientMove to calculate whether the client is moving his cursor up or down and change the offset accordingly.

Thank you of course, but I need a start code to understand how it works, please help me this is really necessary

Link to comment

Is it possible to find the coordinates of the cursor in RenderTarget?

getCursorPosition () is not helping, output is wrong x, y coordinates

  
local sW, sH = guiGetScreenSize() 
local bW, bH = (sW / 2), (sH / 2) 
local Box = dxCreateRenderTarget(1019, 560, true) 
local mX, mY = (1019 / 2), (560 / 2) 
addEventHandler('onClientRender', root, 
    function () 
        if (isLogged(localPlayer)) then 
            if (isVisible) then 
                --Scrollbar 
                dxDrawRectangle(bW - 197, bH - 279 + offset, 5, 170, tocolor(200, 200, 200, 100)) 
                dxDrawRectangle(bW + 503, bH - 279 + offset, 5, 170, tocolor(200, 200, 200, 100)) 
                --Box 
                dxSetRenderTarget(Box, true) 
                for i = 1, 14 do 
                    dxDrawRectangle(0, mY - 345 + 65 * i - offset, 309, 60, tocolor(75, 75, 75, 200)) 
                    dxDrawImage(0, mY - 345 + 65 * i - offset, 60, 60, ':guieditor/images/plus.png') 
                    dxDrawText('Backpack '..i, mX - 439.5, mY - 324 + 65 * i - offset) 
                    dxDrawText(i..'/35', mX - 234.5, mY - 345 + 65 * i - offset) 
                    dxDrawRectangle(mX + 190.5, mY - 345 + 65 * i - offset, 309, 60, tocolor(75, 75, 75, 200)) 
                    dxDrawImage(mX + 190.5, mY - 345 + 65 * i - offset, 60, 60, ':guieditor/images/plus.png') 
                    dxDrawText('Backpack '..i, mX + 260.5, mY - 324 + 65 * i - offset) 
                    dxDrawText(i..'/35', mX + 465.5, mY - 345 + 65 * i - offset) 
                end 
                dxSetRenderTarget() 
                dxDrawImage(bW - 509, bH - 280, 1019, 560, Box) 
            end 
        end 
    end 
) 
  

Edited by Guest
Link to comment
I agree that getCursorPosition is pretty bad, it needs have a boolean added to it so it can return both relative and absolute.

That said, you can still use relative values as effectively as absolute values, in fact, I'd rather use relative values as it'll work on all resolutions.

onClientMouseMove returns absolute X and Y.

Do not onClientMouseMove for GUI?

Updated the code above

I need to know the position of the cursor inside RenderTarget

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...