Jump to content

Please, could you help me put a scrollBar in the inventory I am creating?


lima

Recommended Posts


local rx, ry = 611, 400 
local render = dxCreateRenderTarget(rx, ry);
local sx, sy = guiGetScreenSize();
local cx,cy = (sx/2) - (rx/2), (sy/2) - (ry/2);

local scrollcolor = tocolor(24, 30, 40,155)
local scrollColorS = tocolor(255,255,255)
local maxScroll = 0;
local selected = nil;
local slots = {}

local scroll_bar = 0;
local gui = {}
local isCursorOnElement = {}


--local cx,cy = (x/2) - (sx/2), (y/2) - (sy/2);


--local rx ,ry = 600,400
--local render = dxCreateRenderTarget(rx,ry);
--local sx, sy = guiGetScreenSize()

function Inv()

if render and isElement(render) then
dxDrawRectangle(594,296, 248, 259, tocolor(0,0,0,15))

 local x,y = 5,5
 local slots = {}

    dxSetRenderTarget(render, true);                                                                                           --dxDrawRectangle(592,294, 250, 258, tocolor(0,0,0,25))
            for i = 1,50 do
                if i == selected then

                end
            dxDrawRectangle(x, y, 96, 128, i == selected and scrollColorS or scrollcolor)
            table.insert(slots, {x, y, 96, 128})
            dxDrawImage(x+13, (y+6)  , 70, 70, "assets/itens/agua.png")
           -- dxDrawText("agua\n(10)\n(10)", x+100, y+20, -10 ,-10, font, 1,"Default", "center",nill,false,true)
            x = x + 96 + 5
            if x >= 611 then
               x = 5;
               y = y + 128 + 5;
            end
        end
    
    
    dxSetRenderTarget();
 
    dxDrawImage(cx,cy,rx,ry, render);
end
end
addEventHandler("onClientRender", root, Inv)


--i == selected and dxDrawImage(x, 3 - sroll, 58, 68, "assets/img/slot-effect.png"))

function isMouseInPosition(x,y,w,h)
    if isCursorShowing() then
        local sx,sy = guiGetScreenSize()
        local cx,cy = getCursorPosition()
        local cx,cy = (cx*sx),(cy*sy)
        if (cx >= x and cx <= x+w) and (cy >= y and cy <= y+h) then
            return true
        end
    end
end
 

Link to comment



local scroll = 0 
local maxItemsOnScreen = 8
local items  = {}

bindKey("mouse_wheel_down", "down", 
   function()
      if scroll < (items - maxItemsOnScreen) then 
         scroll = scroll + 1
      end 
   end
)

bindKey("mouse_wheel_up", "down", 
   function()
      if scroll > 0 then 
         scroll = scroll - 1
      end 
   end
)

function dxDrawInventory()
   for i = 1 + scroll, maxItemsOnScreen + scroll do 
      if items[scroll] then 
         dxDrawRectangle(...) 
         ... 
         ...
      end 
   end 
end 

I leave you a fairly simple example of how you can do it.

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