ID:151277
 
So basically I'm trying to create a flexible way to create a list which I can scroll up and down in with the arrow keys to select an option, on HUD.

Currently I am trying to have Client.North and South, if an Option datum is created, scroll through the parameters of the list eg: client
North()
if(mob.Options)
mob.Select("up")
else
..()


and then Select figures the rest out:
mob
proc
Select(direction)
if(direction == "up")
if(selected == Options.options[1])
selected = Options.options[Options.options.len]
option_number = Options.options.len
return //can't scroll up anymore, so go to bottom
selected = Options.options[--option_number]


Hmm, now there's a few issues, like what if I want to have client.East() move the selected object to the eastern most selection? I can't really scroll through the list of the contents properly then...

So how can I effectively go about creating a flexible menu on HUD that I can scroll through the contents with arrow keys?


THE FOLLOWING IS MY ATTEMPT, and isn't necessary to read through - but hopefully it will give you an idea of what I'm trying to do:

Options Datum:


mob
var
Options
Options

obj/option/selected
option_number = 1
obj/highlight
f_choice = null


Options
var
mob/chooser
list
options = new
New(mob/selector, list/l)
chooser = selector
selector.Options = src
for(var/a in l)
//list("startgame:7,5" , "endgame:7,4")

var
indexc = 1
tname
sloc
namecount = 0


for()
namecount ++
if(copytext("[a]",indexc++,indexc) == ":")
break


tname = copytext("[a]",1,namecount)
sloc = copytext("[a]",namecount+1)


var/obj/option/b = new
b.title = tname
b.screen_loc = sloc
selector.client.screen += b
options += b

selector.selected = options[1] //give a default select. top of the list.

selector.HighLight()

proc
Choice()
var/obj/option/final_choice = chooser.selected
chooser.selected = null
chooser.Options = null

if(chooser.highlight)
chooser.client.screen -= chooser.highlight
del chooser.highlight

chooser.f_choice = final_choice
del src



How I want to work with the options through the variable:

mob
proc
Option(list/string)
new/Options(src, string)
while(!f_choice)
sleep(1)
var/obj/option/schoice = f_choice
f_choice = null
return schoice.title
mob
verb
TEST_OPTIONS()
var/option = Option(list("START:1,5","END:1,4","CANCEL:1,3"))
if(option == "START")
world << "you selected start"
if(option == "END")
world << "you selected end"
if(option == "CANCEL")
world << "cancelled."


Any help appreciated, thanks.
You could put your options in matrix form

1 2 3
4 5 x
6 x x
7 8 9

Say the numbers are the options and the x's are blank spaces.

You may also use associative lists.

options
var/list/matrix = list("1,1"=choice1,"1,2"=choice2,"1,3"=choice3,"2,1"=choice4,"2,2"=choice5,"3,1"=choice6,"4,1"=choice7,"4,2"=choice8,"4,3"=choice9)


This way, you can easily track the options through their index. i.e. choice = matrix["[row],[column]"]

You can then scroll through the list through client/Move().

client
Move(loc,dir)
if(condition_for_option_here)
your_previous_choice = your_selected_choice
your_selected_choice = options.some_proc_here(dir) // pass the dir as argument
if(your_previous_choice!=your_selected_choice)
your_previous_choice.highlight(0) // turn off highlight
your_selected_choice.highlight(1) // turn on highlight
else
return ..()

options
var
max_row = 4 // max rows and columns should be set at runtime. during New() would be best
max_col = 3
sel_row = 1
sel_col = 1


proc/some_proc_here(dir)
var/select_row = sel_row
var/select_col = sel_col
switch(dir)
if( NORTH )
while(select_row>1)
select_row--
if(select(select_row,select_col))
break
if( SOUTH )
while(select_row<max_row)
select_row++
if(select(select_row,select_col))
break
if( WEST )
while(select_col>1)
select_col--
if(select(select_row,select_col))
break
if( EAST )
while(select_col<max_col)
select_col++
if(select(select_row,select_col))
break
return get()

proc/select(row,col)
if(matrix["[row],[col]"])
sel_row = row
sel_col = col
return 1
return 0

proc/get()
return matrix["[sel_row],[sel_col]"]


In response to Jemai1
Ah that's perfect. I'll try recreating this idea when I get home!

Thanks.
In response to Speedro
You're welcome.