Jump to content

dx scroll list random ordering and unknown problem


Dzsozi (h03)

Recommended Posts

Hello! I am trying to create a scrollable dx list for my jobs system, but I am having some issues with it. I have a table for the jobs with some basic informations, like the id of the job, the name, etc. I can make the list of the jobs, so the grid list shows all the jobs, but sometimes it shows one job multiple times, and the ordering of the jobs is just wrong, the whole thing is messed up and I don't understand what is / can't find the problem. I have tried changing lots of settings, numbers, but I always get the same or it doesn't even render. I would really appreciate if somebody could help me out with that, it really annoys me and I can't find the problem.

Here's the jobs table:

availableJobs = {
	-- job id
		-- name, desc, requirements, max payment
	[1] = {
		jobName = "job 1",
		jobDescription = "1",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 40,
	},
	[2] = {
		jobName = "job 2",
		jobDescription = "2",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 20,
	},
	[3] = {
		jobName = "job 3",
		jobDescription = "3",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 25,
	},
	[4] = {
		jobName = "job 4",
		jobDescription = "4",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[5] = {
		jobName = "job 5",
		jobDescription = "5",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[6] = {
		jobName = "job 6",
		jobDescription = "6",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[7] = {
		jobName = "job 7",
		jobDescription = "7",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[8] = {
		jobName = "job 8",
		jobDescription = "8",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[9] = {
		jobName = "job 9",
		jobDescription = "9",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
	[10] = {
		jobName = "job 10",
		jobDescription = "10",
		jobRequirements = {driverLicense = 1, weaponLicense = 0},
		jobMaximumPayment = 30,
	},
}

And here's the client side script where I render the panel:

local sx,sy = guiGetScreenSize()
local showJobsPanel = true

local renderData = {}
renderData.defaultWidth = 600
renderData.defaultHeight = 450
renderData.posx = sx/2 - renderData.defaultWidth/2
renderData.posy = sy/2 - renderData.defaultHeight/2
renderData.currentRow = 1
renderData.maxRows = 3

function getJobImage(job)
	return fileExists("files/job"..job..".png") and "files/job"..job..".png" or "files/noimage.png"
end


function drawJobsPanel()
	if showJobsPanel then
		dxDrawRectangle(renderData.posx,renderData.posy,renderData.defaultWidth,renderData.defaultHeight,tocolor(0,0,0,150))
		local jobs = 0
		local latestLine = renderData.currentRow + renderData.maxRows
		for k,v in pairs(availableJobs) do
			if k >= renderData.currentRow then
		    	if k <= latestLine then
					jobs = jobs + 1
					renderData.posy2 = renderData.posy + 10 + (100 * (jobs - 1))
					dxDrawRectangle(renderData.posx,renderData.posy2,renderData.defaultWidth,75,tocolor(0,0,0,150))
					dxDrawImage(renderData.posx+5,renderData.posy2,200,75,getJobImage(k))
					
					dxDrawText(v.jobName,renderData.posx+225,renderData.posy2+5,0,0,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,false,true)
					dxDrawText(v.jobDescription,renderData.posx+225,renderData.posy2+20,0,0,tocolor(255,255,255,255),1,"default-bold","left","top",false,false,false,true)
				end
			end
		end
	end
end
addEventHandler("onClientRender",getRootElement(),drawJobsPanel)

bindKey("mouse_wheel_down", "down", 
	function() 
		if showJobsPanel then
			if renderData.currentRow < #availableJobs - renderData.maxRows then
				renderData.currentRow = renderData.currentRow + 1
			end
		end
	end
)

bindKey("mouse_wheel_up", "down", 
	function() 
		if showJobsPanel then
			if renderData.currentRow > 1 then
				renderData.currentRow = renderData.currentRow - 1
			end
		end
	end
)

Thank you in advance!

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