Grids are easy to use if you use them properly. It is a bit tedious though, since you have to use winset() a lot of times while editing grids.
The procedure below takes a list and turns it into a grid. Feel free to examine this code.
client/proc/displayGrid(id,list/L) //id = windowid.controlid or just controlid for unique controls //L = the list to display as a grid
//first, we must clear the grid. we will get the size of the grid and empty\ it manually. var size=winget(src,id,"cells") pos=findtext(size,"x") if(pos) var a=text2num( copytext(size,1,pos) ) b=text2num( copytext(size,pos+1) ) if(a&&b) //a = rows, b = cols for(a=a,a>0,a--) for(var/i=b,i>0,i--) winset(src,id,"current-cell=\"[a]x[i]\"") src<<output(null,id)
//next, we need to start populating the list var/rows=1 for(var/X in L) if(istype(L[X],/list)) rows=1+length(L[X])
winset(src,id,"cells=\"[rows]x[L.len]\"") for(var/i=1 to L.len) var/list/L2=L[ L[i] ]
here is a simple inventory i came up with its nothing like that other guys but its good enough for me atm, maybe someone will fix this up and repost it.
mob proc next2() if(X==0) //checks to see if X is equal to 0 X=1 //sets X to 1 so we are back on row 1 winset(usr,"mainwindow.grid2","current-cell=\"1,[X]\"") //sets grid2 on mainwindow to cell 1,[X](1,1) else \\ if not equal to 0 X+=1 //adds another 1 to X winset(usr,"mainwindow.grid2","current-cell=\"1,[X]\"") cellcheck()// to clear the screen when you drop an item winset(usr,"mainwindow.grid2","cells=\"1,1\"") //easiest way i could think of was setting the cells to 1,1 so the other cells that where used become blank var X // variable set for rows A //variable set for inventory length
Stat() for(var/obj/O in usr) // for each object that the user has on him/her A = usr.contents.len // A equals the number of items in the users inventory usr<<output(O, "grid2") //outputs a 16x16 image on the current cell of grid2 if(X==A) // if row is equal to amount of contents X=0 // change rows to 0 next2() // calls next2 else next2() obj verb drop() set category = "Commands" set src in usr //verb shows if item is in users inventory src.loc = usr.loc //sets the item on the ground where the user is standing usr.cellcheck() // calls the cellcheck proc to wipe all cells after dropping an item usr<<"You dropped [src]"
i thought androids was a little too hard to understand thats why i made mine like this.
i thought androids was a little too hard to understand thats why i made mine like this.
Yours has many flaws, such as the if(X==0) bit. You also call procs all over the place, and you have usr abuse. You call that an improvement?
-- Data
when did i say it was an improvement, didnt you read what i said at all, it works at the moment and its easier to understand than yours since you never explained any of it.
The procedure below takes a list and turns it into a grid. Feel free to examine this code.
-- Data