I've decided to stop with the ambitiousness and make one that's fairly easy to understand and implement.
sync on
sync rate 30
rem Array containing each menu option. Only two deep at
rem the moment. The first string is the main menu option
rem that the menu item belongs to.
dim menu_button$(11,2)
data "0","Start Game!"
data "0","Options!"
data "0","Multiplayer!"
data "0","Quit Game!"
data "2","Set Resolution!"
data "2","Set Graphical Detail!"
data "2","Setup Sound!"
data "3","Player Setup!"
data "3","Connection Options!"
data "3","Start Multiplayer Game!"
data "3","Join Multiplayer Game!"
for i=1 to 11
for j=1 to 2
read menu_button$(i,j)
next j
next i
rem Sub_menu is the currently chosen menu item. When
rem sub_menu_choice changes, it means the user has clicked
rem an end point in the menu.
sub_menu=-1
sub_menu_choice=0
do
cls
draw_menu(0)
draw_menu(sub_menu)
randomvariable=mouse_over_menu(mousex(),mousey(),0)
randomvariable2=mouse_over_menu(mousex(),mousey(),sub_menu)
rem If you clicked and the mouse was over a button:
rem If the button was in the main menu then set a new sub_menu
rem If the button was in a sub menu then goto the end with a value
if mouseclick()=1
if mouse_over_menu(mousex(),mousey(),0)>0 and mouse_over_menu(mousex(),mousey(),0)<5 then sub_menu=mouse_over_menu(mousex(),mousey(),0)
if mouse_over_menu(mousex(),mousey(),sub_menu)>4 and mouse_over_menu(mousex(),mousey(),sub_menu)<12 then sub_menu_choice=mouse_over_menu(mousex(),mousey(),sub_menu)
endif
if sub_menu=1 then sub_menu_choice=1
if sub_menu=4 then sub_menu_choice=4
if sub_menu_choice>0 then goto endgame
sync
loop
function draw_menu(n)
rem This function draws the menu indicated with n
rem Starting button coordinates
x1=50
x2=250
y1=50
y2=100
for i=1 to 11
if str$(n)=menu_button$(i,1)
rem If this is a sub menu, move the starting coords to the right
if n<>0 then x1=300:x2=500
ink rgb(255,0,0),0
box x1,y1,x2,y2
ink rgb(0,0,0),0
center text ((x2-x1)/2)+x1,((y2-y1)/2)+y1-5,menu_button$(i,2)
rem move it down ready for the next button
y1=y1+75
y2=y2+75
endif
next i
endfunction
function mouse_over_menu(x,y,n)
x1=50
x2=250
y1=50
y2=100
main=0
for i=1 to 11
if str$(n)=menu_button$(i,1)
rem If this is a sub menu, move the starting coords to the right
if n<>0 then x1=300:x2=500:main=-1
rem If the mouse is over the button, draw it again differently
rem and return a value (main) which contains the index of the
rem menu clicked in the menu array above.
if x>x1 and x<x2 and y>y1 and y<y2
ink rgb(255,255,0),0
box x1,y1,x2,y2
ink rgb(0,0,0),0
center text ((x2-x1)/2)+x1,((y2-y1)/2)+y1-5,menu_button$(i,2)
menu=i
endif
rem move it down ready for the next button
y1=y1+75
y2=y2+75
endif
next i
endfunction menu
endgame:
cls
ink rgb(255,255,255),0
text 100,100,"You chose option:"
text 100,120,menu_button$(sub_menu_choice,2)
sync
suspend for key
Supports one sub menu layer. No animation included, but it's easy enough to implement - if the menu choice changes then do some animation routine. To adapt this for pop up menus, add extra parameters into both functions indicating where the menu was first brought up (usually at the mouse coordinates with a right click) etc. You can do just about any modification, sprites instead of boxes, 3d objects as menu items, more sub menu layers, I won't go into it now. This code is nowhere near perfect, so adapt it at your will.