ID:273445
 
I was wondering if it would be possible to display checkboxes in a grid. Say for example, I want to display all my inventory in a grid, with a checkbox assigned to each of them. Then have a button that will delete all of the checked items from my inventory.
Unfortunately not. It's possible to use winclone() to create new elements on the interface, so you could theoretically use that to create a custom grid with checkboxes, but that'd be rather difficult.

A better option is to just have a "selection" object, like so:

obj
selection
icon = 'selection.dmi'
icon_state = "unselected"
var/selected = FALSE
// obj being "held" by this selection box
var/obj/pointer

New(var/obj/O)
pointer = O
overlays += O

Click()
selected = !selected
// set the icon_state to reflect the selection
icon_state = selected?"selected":"unselected"

mob
var/tmp/list/cur_selections
proc
// Start a selection from a list of objs (contents, for example)
start_selection(var/list/L)
var/i = 0
cur_selections = list()
// Output objs to grid
for(var/obj/O in L)
var/obj/selection/S = new(O)
cur_selections += S
src << output(S, "selection_grid:[++i]")
// Get the list of selected objs
end_selection()
var/list/L = list()
for(var/obj/selection/S in cur_selections)
if(S.selected)
L += S.pointer
// Free the list and destroy the objs in it
cur_selections = null

return L


So, the 'selection.dmi' would just have either a border or a background that would toggle between, say, black ("unselected") and green ("selected"). You would call start_selection() on some list (like start_selection(contents)) and then end_selection() when the player is finished, which will give you a list of the objs they selected.
In response to Garthor
I just got around to trying out this method, and I quite like it. One issue I am having just now though is that the icon_state of the selection object does not display in the grid without updating the entire grid, thus resetting your selections.
In response to Danny Roe
Oh, right. You shouldn't need to update the entire thing, just give each selection obj some variables that tell it where in the grid it is (a text string should work), and update that cell in its Click() proc.
In response to Garthor
I should have thought of that, I'm getting rusty. It's coming along nicely now, thanks.