Jump to content

Recommended Posts

Olá, esse script está crashando o mta de quem entra no servidor podem me ajudar ? 

local screenW, screenH = guiGetScreenSize()
local resW, resH = 1360,768
local vzrx, vzry = (screenW/resW), (screenH/resH)

local super = Class("Grid", LuaObject, function()
	static.font1 = dxCreateFont("utils/font.ttf", vzrx*10)
	static.font_10 = dxCreateFont("utils/font.ttf", vzrx*10)
	static.sx, static.sy = guiGetScreenSize()
	static.constructors = {}
end).getSuperclass()
local cursorOn;



function Grid:init(x, y, w, h, postGUI)
	self.x = x
	self.y = y
	self.w = w
	self.h = h
	self.originalH = h
	self.columHeight = 30
	self.itemHeight = 25
	self.maxItems = self:getMaxPosition();   -- Max items
	self.pg = postGUI or false;  
	self.items = {};
	self.scrollTop = y + 18 + 2
	self.listPos = 0;                                                          -- Scroll Level
	self.mo = nil;                                                        -- Mouse-on item
	self.visible = true                                                        -- Visible
	table.insert(Grid.constructors,self)
	return self
end

function Grid:destroy()
	for k, v in pairs(Grid) do
		if (v == self) then
			Grid[k] = nil
		end
	end
	return true
end

function Grid:setItemText(id, column, text)
	if self.items[column] and self.items[column][id] then
		self.items[column][id].text = text
	end
end

function Grid:setItemColor(id, column, r, g, b)
	if self.items[column] and self.items[column][id] then
		local color = tonumber(b) and tocolor(r, g, b) or tocolor(255, 255, 255)
		self.items[column][id].color = color
	end
end

function Grid:setVisible(visible)
	self.visible = visible
end

function Grid:isVisible()
	return self.visible
end

function Grid:addColumn(title, width)
	local data = {
		info = {title = title, width = width}
	};
	table.insert (self.items, data);
	return #self.items;
end

function Grid:RemoveColumn(colum)
	self.items[colum] = nil;

	-- Recalculate the highest item count
	local highest = 0;

	for _, v in ipairs(self.items) do
		if #v > highest then
			highest =(#v - 1);
		end
	end
	return true
end

function Grid:getColumnCount()
    return #self.items
end

function Grid:addItem(colum, text, data, r, g, b)
	if self.items[colum] then 
		local color = tonumber(b) and tocolor(r, g, b) or tocolor(255, 255, 255)

		table.insert(self.items[colum], {id = #self.items[colum] + 1, text = tostring(text), data = data, color = color});
		self.h = self.columHeight + (self.maxItems*self.itemHeight)
		return #self.items[colum];
	end
end

function Grid:removeItem( column, id)
	if self.items[column] and self.items[column][id] then
	
	-- Reset the selected item if necessary²
		if id == self.selected then
			local newItem   =   self.selected - 1

			if newItem <= #self.items[colum] then
				self.selected = math.max(0, newItem);
			else
				self.selected = 0
			end
		end

		table.remove(self.items[column], id);

		return true;
	end
end

function Grid:getItemCount(colum)
	if self.items[colum] then
		return #self.items[colum]
	end
end

function Grid:clear()
	for k, v in ipairs (self.items) do
		self.items[k] = {info = v.info}
	end

	self.selected = nil
end

function Grid:getSelectedItem()
    return self.selected;
end

function Grid:setSelectedItem (id)
	if id <= #self.items[1] then
		self.selected = id;
	end
end

function Grid:getItemDetails(column, id)
	if self.items[column] then
		if self.items[column][id] then
			return self.items[column][id].text, self.items[column][id].data
		end
	end
end

function paint()
        -- Is there any gridlist to render?
        if (#Grid.constructors > 0) then
            -- Loop through all grid lists
            for index, self in ipairs (Grid.constructors) do
                -- Is the gridlist visible?
                if self.visible then
                    -- Draw the 'gridlist' itself                  
                    
					 dxDrawRectangle (self.x, self.y, self.w, self.h, tocolor(0, 0, 0, 0), self.pg);
					
					
					dxDrawRectangle(self.x, self.y + self.columHeight, self.w, self.h - self.columHeight, tocolor(0, 0, 0, 0), self.pg)
                    -- Draw the column bar
                    dxDrawRectangle(self.x, self.y, self.w, self.columHeight, tocolor(0, 0, 0, 0), self.pg)

					-- ScrollBar
					local uX, uY, uW = (self.x + self.w) + 1, self.y, 18
					local b = 4
					--UP Arow
				--[[	dxDrawRectangle(uX + 1, uY + 1, uW - 1, uW - 1, tocolor(0, 0, 0, 50), self.pg)
					dxDrawLine(uX + b , uY + uW - b, uX + uW/2, uY + b, tocolor(0, 0, 0, 70), 1, self.pg)
					dxDrawLine(uX - b + uW, uY + uW - b, uX + uW/2 , uY + b , tocolor(0, 0, 0, 70), 1, self.pg)
					--dxDrawLine(uX + b , uY + uW - b, uX + uW - b, uY + uW - b, tocolor(0, 0, 0, 70), 1, self.pg)
					]]
					--DOWN Arow
					local dX, dY, dW, dH = (self.x + self.w) + 1, self.y + (self.h-18) + 1, 18 - 1, 18 - 1
					--[[dxDrawRectangle(dX + 1, dY + 1, dW - 1, dW - 1, tocolor(0, 0, 0, 50), self.pg)
					dxDrawLine(dX + b , dH + dY - dW + b, dX + dW/2, dH + dY - b, tocolor(0, 0, 0, 70), 1, self.pg)
					dxDrawLine(dX + dW - b , dH + dY - dW + b, dX + dW/2, dH + dY - b, tocolor(0, 0, 0, 70), 1, self.pg)
					--dxDrawLine(dX + b , dH + dY - dW + b , dX + dW - b , dH + dY - dW + b, tocolor(0, 0, 0, 70), 1, self.pg)
					]]
					--Thumb
					local x, y, w, h = (self.x + self.w) + 2, self.y + 18 + 2, 18 - 2, self.h - (18*2) - 2
					--dxDrawRectangle(x, y, w, h, tocolor(0, 0, 0, 90))
					
					local maxHeight = h
					self.thumbHeight = math.max(math.min(math.floor(maxHeight * self.maxItems / (#self.items[1])),maxHeight),18)

					
					local maxY = (y+h)-self.thumbHeight
					if (getKeyState("mouse1")) then
						if (isMouseInPosition(uX, uY, uW, uW)) then
							if (#self.items[1] > self.maxItems) then
								self.scrollTop = math.max(y,math.min(self.scrollTop - 1*maxHeight/100, maxY))					
								self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
							end
						elseif (isMouseInPosition(dX, dY, dW, dH)) then
							if (#self.items[1] > self.maxItems) then
								self.scrollTop = math.max(y,math.min(self.scrollTop + 1*maxHeight/100, maxY))
								self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
								
							end
						end
					end
					if drag then
						local _, cy = getCursorPosition()
						local cy = cy*Grid.sy

						self.scrollTop = math.max(y,math.min(cy-space, maxY))
						self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
					end
					local aa = 255
					if (isMouseInPosition(x,self.scrollTop,w,self.thumbHeight)) then
						aa = 110
					end

					
                    -- Set cursorOn variable to the current gridlist, if it's selected
                    self.cursorOn = nil
                    if isMouseInPosition(self.x, self.y, self.w + 18, self.h) then
                        cursorOn = index;
                    end


                    -- Is there any column?
                    if #self.items > 0 then
                    local cWidth = 0

                        -- Loop through all columns
                        for cIndex, cData in ipairs(self.items) do
                            -- we'll go beyond the gridlist width with this column ?
                            if(( cWidth + cData.info.width) <= self.w) then
                                local x = self.x + cWidth;

                                -- Draw the column title
                                dxDrawText(cData.info.title, x + 10, self.y, cData.info.width + x,(self.columHeight) + self.y, tocolor(255, 255, 255, 220), vzrx*1.4, "arial", "left", "center", true, true, self.pg, true, true);

                                -- Is there any item ?
                                if #cData > 0 then

                                    -- Loop the items
									local k = 0
									for i=(self.listPos+1), (math.min(#self.items[1],self.maxItems)+self.listPos) do
											if cData[i] then
												-- Draw a rectangle to make it looks like selected
												dxDrawText(cData[i].text,x + 20,(self.columHeight + self.y)+(self.itemHeight*k),cData.info.width + x,(self.columHeight + self.y)+(self.itemHeight*k) + self.itemHeight, tocolor(255, 255, 255, 200), vzrx*1, Grid.font_10, "left", "center", true, true, self.pg, true, true)
												if (self.selected == i) then
													dxDrawRectangle(self.x,(self.columHeight + self.y)+(self.itemHeight*k),self.w,self.itemHeight,tocolor(255, 255, 255, 200), self.pg)
													dxDrawText(cData[i].text:gsub("#%x%x%x%x%x%x", ""),x + 20,(self.columHeight + self.y)+(self.itemHeight*k),cData.info.width + x,(self.columHeight + self.y)+(self.itemHeight*k) + self.itemHeight, tocolor(0, 0, 0, 220), vzrx*1, Grid.font_10, "left", "center", true, true, self.pg, true, true)
												end
											end
										 k = k+1
									end
                                end

                                -- Increase cWidth variable (to draw the columns correctly)
                                cWidth = cWidth + cData.info.width;
                            end
                        end
                    end
                end
            end
        end
    end
addEventHandler("onClientRender", root, paint, true, "low-5")

function onClientKey(key, press)
	if isCursorShowing() then
		if #Grid.constructors > 0 then
			if cursorOn then
				local self = Grid.constructors[cursorOn]
				if press and #key > 6 then
					if #self.items[1] > self.maxItems then
						local y = self.y + 18 + 2
						local maxHeight = self.h - (18*2) - 2
						if (isMouseInPosition(self.x,self.y,self.w+18,self.h)) then
							if (key == "mouse_wheel_down") then
								if (#self.items[1] > self.maxItems) then
									self.listPos =  math.ceil(math.max(0,math.min(self.listPos + 1*#self.items[1]/100, #self.items[1]-self.maxItems)))
									self.scrollTop = y + ((self.listPos / (#self.items[1]-self.maxItems) * 100) * ((maxHeight)-self.thumbHeight) / 100)
								end
							elseif (key == "mouse_wheel_up") then
								if (#self.items[1] > self.maxItems) then
									self.listPos =  math.floor(math.max(0,math.min(self.listPos - 1*#self.items[1]/100, #self.items[1]-self.maxItems)))
									self.scrollTop = y + ((self.listPos / (#self.items[1]-self.maxItems) * 100) * ((maxHeight)-self.thumbHeight) / 100)
								end
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler("onClientKey", root, onClientKey)

function onClientClick(button,state,absoluteX,absoluteY)
	if (button == "left" and state == "up") then
		drag = nil
	else
		if #Grid.constructors > 0 then
			if cursorOn then
				local self = Grid.constructors[cursorOn]
				local k = 0
				for i=(self.listPos+1), (math.min(#self.items[1],self.maxItems)+self.listPos) do
					if isMouseInPosition(self.x,(self.columHeight + self.y)+(self.itemHeight*k),self.w,self.itemHeight) then
						self.selected = i
					end
					k = k+1
				end
				if (#self.items[1] > self.maxItems) then
					local x, y, w, h = (self.x + self.w) + 2, self.y + 18 + 2, 18 - 2, self.h - (18*2) - 2
					if (isMouseInPosition(x,self.scrollTop,w,self.thumbHeight)) then
						space = absoluteY-self.scrollTop
						drag = true
					elseif(isMouseInPosition((self.x + self.w) + 2,self.y + 18 + 2,18, self.h - (18*2) - 2)) then
						space = self.thumbHeight/2
						drag = true
					end
				end
			end
		end
	end
end
addEventHandler("onClientClick",root,onClientClick)

function Grid:getMaxPosition()
	local pos = 1
	while true do
		if(pos*(24)+(24) <= self.originalH) then
			pos = pos + 1
		else
			pos = pos - 2
			break
		end
	end
	return pos
end

function isMouseInPosition(x, y, w, h)
	if (not isCursorShowing()) then	return end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    return ((cx >= x and cx <= x + w) and (cy >= y and cy <= y + h))
end
--[[
local grid = Grid(400,150,500,500)
local colum = grid:addColumn("Colum",200)
for k=1, 80 do
	grid:addItem(colum,(tostring(k)))
end
showCursor(true)]]

 

Link to comment
  • Moderators

Tem certeza que o crash tem relação direta com esse código?

A classe não está completa, provavelmente tem outro arquivo separado fora esse código postado.

Se tiver algum problema com esse script, é mais provável que seja por mal uso.

Link to comment

Só usar:
 

local screenW, screenH = guiGetScreenSize()
local resW, resH = 1360,768
local vzrx, vzry = (screenW/resW), (screenH/resH)

LuaObject = {}
LuaObject.__index = LuaObject
LuaObject.name = "LuaObject"

function LuaObject:new()
	local self = self or setmetatable({}, LuaObject)
	return self
end

function LuaObject:init()
	return self
end

function LuaObject:dispose()
	return self
end

function LuaObject.getSingleton(class)
	if(type(class) == "table") then
		if(not class.instance) then
			class.instance = class()
		end
		return class.instance
	elseif(type(class) == "string" and _G[class]) then
		if(not _G[class].instance) then
			_G[class].instance = _G[class]()
		end
		return _G[class].instance
	end
end

function Class(name, super, static)
	if(not super) then
		super = LuaObject
	end
	local class = {}
	setmetatable(class, super)
	class.__index = class
	class.__parent = super
	class.name = name
	_G[name] = class
	
	super.__call = function(c, ...) 
		return c.new():init(...)
	end
	class.getSuperclass = function()
		return class.__parent
	end	
	class.getClassName = function()
		return name
	end
	class.getInstance = function()
		return LuaObject.getSingleton(class)
	end
	function class:new()
		local self = self or setmetatable({}, class)
		super.new(self)
		return self
	end	
	if(static) then
		setfenv(static, setmetatable({static = class, super = super}, { __index = _G })) 
		static()	
	end	
	return class
end


local super = Class("Grid", LuaObject, function()
	static.font1 = dxCreateFont("utils/font.ttf", vzrx*10)
	static.font_10 = dxCreateFont("utils/font.ttf", vzrx*10)
	static.sx, static.sy = guiGetScreenSize()
	static.constructors = {}
end).getSuperclass()
local cursorOn;



function Grid:init(x, y, w, h, postGUI)
	self.x = x
	self.y = y
	self.w = w
	self.h = h
	self.originalH = h
	self.columHeight = 30
	self.itemHeight = 25
	self.maxItems = self:getMaxPosition();   -- Max items
	self.pg = postGUI or false;  
	self.items = {};
	self.scrollTop = y + 18 + 2
	self.listPos = 0;                                                          -- Scroll Level
	self.mo = nil;                                                        -- Mouse-on item
	self.visible = true                                                        -- Visible
	table.insert(Grid.constructors,self)
	return self
end

function Grid:destroy()
	for k, v in pairs(Grid) do
		if (v == self) then
			Grid[k] = nil
		end
	end
	return true
end

function Grid:setItemText(id, column, text)
	if self.items[column] and self.items[column][id] then
		self.items[column][id].text = text
	end
end

function Grid:setItemColor(id, column, r, g, b)
	if self.items[column] and self.items[column][id] then
		local color = tonumber(b) and tocolor(r, g, b) or tocolor(255, 255, 255)
		self.items[column][id].color = color
	end
end

function Grid:setVisible(visible)
	self.visible = visible
end

function Grid:isVisible()
	return self.visible
end

function Grid:addColumn(title, width)
	local data = {
		info = {title = title, width = width}
	};
	table.insert (self.items, data);
	return #self.items;
end

function Grid:RemoveColumn(colum)
	self.items[colum] = nil;

	-- Recalculate the highest item count
	local highest = 0;

	for _, v in ipairs(self.items) do
		if #v > highest then
			highest =(#v - 1);
		end
	end
	return true
end

function Grid:getColumnCount()
    return #self.items
end

function Grid:addItem(colum, text, data, r, g, b)
	if self.items[colum] then 
		local color = tonumber(b) and tocolor(r, g, b) or tocolor(255, 255, 255)

		table.insert(self.items[colum], {id = #self.items[colum] + 1, text = tostring(text), data = data, color = color});
		self.h = self.columHeight + (self.maxItems*self.itemHeight)
		return #self.items[colum];
	end
end

function Grid:removeItem( column, id)
	if self.items[column] and self.items[column][id] then
	
	-- Reset the selected item if necessary²
		if id == self.selected then
			local newItem   =   self.selected - 1

			if newItem <= #self.items[colum] then
				self.selected = math.max(0, newItem);
			else
				self.selected = 0
			end
		end

		table.remove(self.items[column], id);

		return true;
	end
end

function Grid:getItemCount(colum)
	if self.items[colum] then
		return #self.items[colum]
	end
end

function Grid:clear()
	for k, v in ipairs (self.items) do
		self.items[k] = {info = v.info}
	end

	self.selected = nil
end

function Grid:getSelectedItem()
    return self.selected;
end

function Grid:setSelectedItem (id)
	if id <= #self.items[1] then
		self.selected = id;
	end
end

function Grid:getItemDetails(column, id)
	if self.items[column] then
		if self.items[column][id] then
			return self.items[column][id].text, self.items[column][id].data
		end
	end
end

function paint()
        -- Is there any gridlist to render?
        if (#Grid.constructors > 0) then
            -- Loop through all grid lists
            for index, self in ipairs (Grid.constructors) do
                -- Is the gridlist visible?
                if self.visible then
                    -- Draw the 'gridlist' itself                  
                    
					 dxDrawRectangle (self.x, self.y, self.w, self.h, tocolor(0, 0, 0, 0), self.pg);
					
					
					dxDrawRectangle(self.x, self.y + self.columHeight, self.w, self.h - self.columHeight, tocolor(0, 0, 0, 0), self.pg)
                    -- Draw the column bar
                    dxDrawRectangle(self.x, self.y, self.w, self.columHeight, tocolor(0, 0, 0, 0), self.pg)

					-- ScrollBar
					local uX, uY, uW = (self.x + self.w) + 1, self.y, 18
					local b = 4
					--UP Arow
				--[[	dxDrawRectangle(uX + 1, uY + 1, uW - 1, uW - 1, tocolor(0, 0, 0, 50), self.pg)
					dxDrawLine(uX + b , uY + uW - b, uX + uW/2, uY + b, tocolor(0, 0, 0, 70), 1, self.pg)
					dxDrawLine(uX - b + uW, uY + uW - b, uX + uW/2 , uY + b , tocolor(0, 0, 0, 70), 1, self.pg)
					--dxDrawLine(uX + b , uY + uW - b, uX + uW - b, uY + uW - b, tocolor(0, 0, 0, 70), 1, self.pg)
					]]
					--DOWN Arow
					local dX, dY, dW, dH = (self.x + self.w) + 1, self.y + (self.h-18) + 1, 18 - 1, 18 - 1
					--[[dxDrawRectangle(dX + 1, dY + 1, dW - 1, dW - 1, tocolor(0, 0, 0, 50), self.pg)
					dxDrawLine(dX + b , dH + dY - dW + b, dX + dW/2, dH + dY - b, tocolor(0, 0, 0, 70), 1, self.pg)
					dxDrawLine(dX + dW - b , dH + dY - dW + b, dX + dW/2, dH + dY - b, tocolor(0, 0, 0, 70), 1, self.pg)
					--dxDrawLine(dX + b , dH + dY - dW + b , dX + dW - b , dH + dY - dW + b, tocolor(0, 0, 0, 70), 1, self.pg)
					]]
					--Thumb
					local x, y, w, h = (self.x + self.w) + 2, self.y + 18 + 2, 18 - 2, self.h - (18*2) - 2
					--dxDrawRectangle(x, y, w, h, tocolor(0, 0, 0, 90))
					
					local maxHeight = h
					self.thumbHeight = math.max(math.min(math.floor(maxHeight * self.maxItems / (#self.items[1])),maxHeight),18)

					
					local maxY = (y+h)-self.thumbHeight
					if (getKeyState("mouse1")) then
						if (isMouseInPosition(uX, uY, uW, uW)) then
							if (#self.items[1] > self.maxItems) then
								self.scrollTop = math.max(y,math.min(self.scrollTop - 1*maxHeight/100, maxY))					
								self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
							end
						elseif (isMouseInPosition(dX, dY, dW, dH)) then
							if (#self.items[1] > self.maxItems) then
								self.scrollTop = math.max(y,math.min(self.scrollTop + 1*maxHeight/100, maxY))
								self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
								
							end
						end
					end
					if drag then
						local _, cy = getCursorPosition()
						local cy = cy*Grid.sy

						self.scrollTop = math.max(y,math.min(cy-space, maxY))
						self.listPos = math.floor(((self.scrollTop - y) / (maxHeight-self.thumbHeight) * 100) * (#self.items[1]-self.maxItems) / 100)
					end
					local aa = 255
					if (isMouseInPosition(x,self.scrollTop,w,self.thumbHeight)) then
						aa = 110
					end

					
                    -- Set cursorOn variable to the current gridlist, if it's selected
                    self.cursorOn = nil
                    if isMouseInPosition(self.x, self.y, self.w + 18, self.h) then
                        cursorOn = index;
                    end


                    -- Is there any column?
                    if #self.items > 0 then
                    local cWidth = 0

                        -- Loop through all columns
                        for cIndex, cData in ipairs(self.items) do
                            -- we'll go beyond the gridlist width with this column ?
                            if(( cWidth + cData.info.width) <= self.w) then
                                local x = self.x + cWidth;

                                -- Draw the column title
                                dxDrawText(cData.info.title, x + 10, self.y, cData.info.width + x,(self.columHeight) + self.y, tocolor(255, 255, 255, 220), vzrx*1.4, "arial", "left", "center", true, true, self.pg, true, true);

                                -- Is there any item ?
                                if #cData > 0 then

                                    -- Loop the items
									local k = 0
									for i=(self.listPos+1), (math.min(#self.items[1],self.maxItems)+self.listPos) do
											if cData[i] then
												-- Draw a rectangle to make it looks like selected
												dxDrawText(cData[i].text,x + 20,(self.columHeight + self.y)+(self.itemHeight*k),cData.info.width + x,(self.columHeight + self.y)+(self.itemHeight*k) + self.itemHeight, tocolor(255, 255, 255, 200), vzrx*1, Grid.font_10, "left", "center", true, true, self.pg, true, true)
												if (self.selected == i) then
													dxDrawRectangle(self.x,(self.columHeight + self.y)+(self.itemHeight*k),self.w,self.itemHeight,tocolor(255, 255, 255, 200), self.pg)
													dxDrawText(cData[i].text:gsub("#%x%x%x%x%x%x", ""),x + 20,(self.columHeight + self.y)+(self.itemHeight*k),cData.info.width + x,(self.columHeight + self.y)+(self.itemHeight*k) + self.itemHeight, tocolor(0, 0, 0, 220), vzrx*1, Grid.font_10, "left", "center", true, true, self.pg, true, true)
												end
											end
										 k = k+1
									end
                                end

                                -- Increase cWidth variable (to draw the columns correctly)
                                cWidth = cWidth + cData.info.width;
                            end
                        end
                    end
                end
            end
        end
    end
addEventHandler("onClientRender", root, paint, true, "low-5")

function onClientKey(key, press)
	if isCursorShowing() then
		if #Grid.constructors > 0 then
			if cursorOn then
				local self = Grid.constructors[cursorOn]
				if press and #key > 6 then
					if #self.items[1] > self.maxItems then
						local y = self.y + 18 + 2
						local maxHeight = self.h - (18*2) - 2
						if (isMouseInPosition(self.x,self.y,self.w+18,self.h)) then
							if (key == "mouse_wheel_down") then
								if (#self.items[1] > self.maxItems) then
									self.listPos =  math.ceil(math.max(0,math.min(self.listPos + 1*#self.items[1]/100, #self.items[1]-self.maxItems)))
									self.scrollTop = y + ((self.listPos / (#self.items[1]-self.maxItems) * 100) * ((maxHeight)-self.thumbHeight) / 100)
								end
							elseif (key == "mouse_wheel_up") then
								if (#self.items[1] > self.maxItems) then
									self.listPos =  math.floor(math.max(0,math.min(self.listPos - 1*#self.items[1]/100, #self.items[1]-self.maxItems)))
									self.scrollTop = y + ((self.listPos / (#self.items[1]-self.maxItems) * 100) * ((maxHeight)-self.thumbHeight) / 100)
								end
							end
						end
					end
				end
			end
		end
	end
end
addEventHandler("onClientKey", root, onClientKey)

function onClientClick(button,state,absoluteX,absoluteY)
	if (button == "left" and state == "up") then
		drag = nil
	else
		if #Grid.constructors > 0 then
			if cursorOn then
				local self = Grid.constructors[cursorOn]
				local k = 0
				for i=(self.listPos+1), (math.min(#self.items[1],self.maxItems)+self.listPos) do
					if isMouseInPosition(self.x,(self.columHeight + self.y)+(self.itemHeight*k),self.w,self.itemHeight) then
						self.selected = i
					end
					k = k+1
				end
				if (#self.items[1] > self.maxItems) then
					local x, y, w, h = (self.x + self.w) + 2, self.y + 18 + 2, 18 - 2, self.h - (18*2) - 2
					if (isMouseInPosition(x,self.scrollTop,w,self.thumbHeight)) then
						space = absoluteY-self.scrollTop
						drag = true
					elseif(isMouseInPosition((self.x + self.w) + 2,self.y + 18 + 2,18, self.h - (18*2) - 2)) then
						space = self.thumbHeight/2
						drag = true
					end
				end
			end
		end
	end
end
addEventHandler("onClientClick",root,onClientClick)

function Grid:getMaxPosition()
	local pos = 1
	while true do
		if(pos*(24)+(24) <= self.originalH) then
			pos = pos + 1
		else
			pos = pos - 2
			break
		end
	end
	return pos
end

function isMouseInPosition(x, y, w, h)
	if (not isCursorShowing()) then	return end
    local sx, sy = guiGetScreenSize ( )
    local cx, cy = getCursorPosition ( )
    local cx, cy = ( cx * sx ), ( cy * sy )
    return ((cx >= x and cx <= x + w) and (cy >= y and cy <= y + h))
end
--[[
local grid = Grid(400,150,500,500)
local colum = grid:addColumn("Colum",200)
for k=1, 80 do
	grid:addItem(colum,(tostring(k)))
end
showCursor(true)]]

EDIT: Não testei!

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