Posted: 13th Dec 2021 12:35
We present to your attention the code of the main menu. You can substitute your media files. The functions of drawing buttons were used as buttons.[functions -graham from darkbasic classic]
+ Code Snippet
Rem Project: MainMenuProject
Rem Created: Sunday, December 12, 2021

Rem ***** Main Source File *****
backdrop on : cls : sync on : sync rate 30 :
global WIDTH
WIDTH=DESKTOP WIDTH()
global HEIGHT
HEIGHT=DESKTOP HEIGHT()
SET DISPLAY MODE Width, Height, 32
SET WINDOW LAYOUT 0, 0, 0
SET WINDOW POSITION 0, 0
`disable escapekey
DISABLE SYSTEMKEYS

rem Setup Font
set text font "book" : set text size Height/20
set text to bold : set text transparent






Load image "MenuBackDrop.png",11
texture backdrop 11
paste image 11,0,0
`render
sync
get Image 13,0,0,WIDTH, HEIGHT,1
`render
sync
paste image 13,0,0
print "width=";width
print "height=";height

`paste image 11,0,0,1
SAVE IMAGE "1.png", 13
sync

cls
delete image 13
load image "1.png",13
paste image 13,0,0
sync 
wait key
`end


rem place the button in the centre of the screen..
x=(screen width()/2)-37
y=(screen height()/2)-12
sync on
sync rate 30
_MainMenu:
NewGame=0:LoadGame=0:Options=0:hiscore=0:Quit=0:v=0
do
   if NewGame=1 : wait 3000: goto _InGameMenu:endif
   v=teststandardbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"New Game",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"New Game",1) : endcase
   endselect
   if v=2 then NewGame=1
   
   if LoadGame=1: wait 3000:gosub _LoadGameMenu:NewGame=0:LoadGame=0:Options=0:hiscore=0:Quit=0:v=0:endif
   v=teststandardbutton(x,y-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game",1) : endcase
   endselect
   if v=2 then LoadGame=1
   
   if Options=1 : wait 3000:exit:endif
   v=teststandardbutton(x,y,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y,width/10+width/10,height/15,"Options",2) : endcase
      case 2 : creatbutton(x,y,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y,width/10+width/10,height/15,"Options",1) : endcase
   endselect
   if v=2 then Options=1

   if Hiscore=1: wait 3000:exit:endif
   v=teststandardbutton(x,y+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Hiscore",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Hiscore",1) : endcase
   endselect
   if v=2 then Hiscore=1

   if Quit=1: wait 3000:end:endif
   v=teststandardbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Quit",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Quit",1) : endcase
   endselect
   if v=2 then Quit=1
         
   sync
loop

_InGameMenu:
ResumeGame=0:LoadGame=0:saveGame=0:Options=0:Exit1=0:v=0
do

if ResumeGame=1 then wait 3000:exit
   v=teststandardbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Resume Game",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Resume Game",1) : endcase
   endselect
   if v=2 then ResumeGame=1
   
   if LoadGame=1 then wait 3000:Gosub _LoadGameMenu:ResumeGame=0:LoadGame=0:saveGame=0:Options=0:Exit1=0:v=0
   v=teststandardbutton(x,y-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game",1) : endcase
   endselect
   if v=2 then LoadGame=1
   
   if Options=1 then wait 3000:exit
   v=teststandardbutton(x,y,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y,width/10+width/10,height/15,"Options",2) : endcase
      case 2 : creatbutton(x,y,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y,width/10+width/10,height/15,"Options",1) : endcase
   endselect
   if v=2 then Options=1

   if SaveGame=1 then wait 3000:gosub _SaveGameMenu:ResumeGame=0:LoadGame=0:saveGame=0:Options=0:Exit1=0:v=0
   v=teststandardbutton(x,y+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Save Game",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Save Game",1) : endcase
   endselect
   if v=2 then SaveGame=1

   if Exit1=1 then wait 3000:Goto _MainMenu:
   v=teststandardbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Exit",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Exit",1) : endcase
   endselect
   if v=2 then Exit1=1


    sync
LOOP
end
_LoadGameMenu:
LoadGame1=0:LoadGame2=0:LoadGame3=0:LoadGame4=0:LoadGame5=0:v=0
for loop1=1 to 500

if LoadGame1=1: wait 3000:exit:endif
   v=teststandardbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Load Game 1",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Load Game 1",1) : endcase
   endselect
   if v=2 then LoadGame1=1
   
   if LoadGam21=1 : wait 3000:exit:endif
   v=teststandardbutton(x,y-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game 2",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Load Game 2",1) : endcase
   endselect
   if v=2 then LoadGame2=1
   
   if LoadGame3=1 : wait 3000:exit:endif
   v=teststandardbutton(x,y,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y,width/10+width/10,height/15,"Load Game 3",2) : endcase
      case 2 : creatbutton(x,y,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y,width/10+width/10,height/15,"Load Game 3",1) : endcase
   endselect
   if v=2 then LoadGame3=1

   if LoadGame4=1 : wait 3000:exit:endif
   v=teststandardbutton(x,y+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Load Game 4",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Load Game 4",1) : endcase
   endselect
   if v=2 then LoadGame4=1

   if LoadGame5=1 : wait 3000:exit:endif
   v=teststandardbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Load Game 5",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Load Game 5",1) : endcase
   endselect
   if v=2 then LoadGame5=1

    sync
next loop1
return
end

_SaveGameMenu:
savegame1=0:savegame2=0:savegame3=0:savegame4=0:savegame5=0:v=0
for loop1=1 to 500 
if SaveGame1=1 then wait 3000:exit
   v=teststandardbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Save Game 1",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15-height/15-height/15,width/10+width/10,height/15,"Save Game 1",1) : endcase
   endselect
   if v=2 then SaveGame1=1
   
   if SaveGame1=1 then wait 3000:exit
   v=teststandardbutton(x,y-height/15-height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Save Game 2",2) : endcase
      case 2 : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y-height/15-height/15,width/10+width/10,height/15,"Save Game 2",1) : endcase
   endselect
   if v=2 then SaveGame2=1
   
   if SaveGame3=1 then wait 3000:exit
   v=teststandardbutton(x,y,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y,width/10+width/10,height/15,"Save Game 3",2) : endcase
      case 2 : creatbutton(x,y,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y,width/10+width/10,height/15,"Save Game 3",1) : endcase
   endselect
   if v=2 then SaveGame3=1

   if SaveGame4=1 then wait 3000:exit
   v=teststandardbutton(x,y+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Save Game 4",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15,width/10+width/10,height/15,"Save Game 4",1) : endcase
   endselect
   if v=2 then SaveGame4=1

   if SaveGame5=1 then wait 3000:exit
   v=teststandardbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15)
   select v
      case 1 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Save Game 5",2) : endcase
      case 2 : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"whoopee do",3) : endcase
      case default : creatbutton(x,y+height/15+height/15+height/15+height/15,width/10+width/10,height/15,"Save Game 5",1) : endcase
   endselect
   if v=2 then SaveGame5=1
    sync
next loop1
return
end

function teststandardbutton(x,y,width,height)

mx=mousex() : my=mousey() : v=0

rem find out wear the mouse pointer is..
if mx>x and mx<(x+width)

   if my>y and my<(y+height)
      rem mouse pointer over button.
      rem button has been selected...
      if mouseclick() then v=2 else  v=1
      update=1
   endif

endif
rem set text opaque : ink 5356,rgb(192,192,192)
rem text x,y+50,str$(v)
endfunction v

function creatbutton(x,y,width,height,name$,tipe)

   rem set-up colour palette, for this program
   white=rgb(255,255,255)
   black=0
   grey=rgb(0,150,0)
   yellow=rgb(0,255,0)
   darkgrey=RGB(0,50,0)

   bc=width/2

   select tipe
      case 2
         rem draw preselected button
         ink black,black
         box x,y,(x+width),(y+height)

         ink white,black
         box x+1,y+1,(x+width)-2,(y+height)-2

         ink black,black
         box x+2,(y)+2,(x+width)-1,(y+height)-1

         ink grey,black
         box x+2,(y+2),(x+width)-2,(y+height)-2
         rem ink text colour to yellow,
         ink yellow,grey
      endcase
      case 3
         rem draw standard button
         ink black,black
         box x,y,(x+width)-1,(y+height)-1

         ink white,black
         box x+1,(y)+1,x+width,(y+height)

         ink darkgrey,black
         box x+1,(y+1),(x+width)-1,(y+height)-1
         rem ink text colour to yellow,
         ink yellow,darkgrey
      endcase
      case default
         rem draw standard button
         ink white,black
         box x,y,(x+width)-1,(y+height)-1

         ink black,black
         box x+1,(y)+1,x+width,(y+height)

         ink grey,black
         box x+1,(y+1),(x+width)-1,(y+height)-1
         rem ink text colour to black,
         ink back,grey
      endcase
   endselect

      rem this the standard text set up for the buttons...
     `set text font "Arial"
     ` set text size 12
      if tipe>1
         set text to bold
      else
         set text to normal
      endif

      set text transparent
      center text x+bc,Y+5,name$

endfunction v

Suitable for any desktop size.
That's what I did.
Posted: 13th Dec 2021 19:08
Just throwing my $0.02 in here, but 350 lines of code seems like a bit much just to display a box & text menu.
Maybe consider using READ/DATA for your button list.

Here's essentially the same output with 10% of the typing:

+ Code Snippet
set text font "Courier New":set text size 26:set text to bold
White=rgb(255,255,255)
Black=rgb(0,0,0)
Green=rgb(0,200,0)
sync on:sync rate 60:backdrop on:color backdrop rgb(60,70,200)

do
ThisButton=0
if Menu=0 then gosub MainMenu
set cursor 0,0:print "ThisButton: ";ThisButton
sync
LOOP

MainMenu:
x#=screen width()*.5
y#=screen height()*.1
boxW=150
boxH=40
Spacing=75
restore MainMenuData
read itemCount
	for i=1 to itemCount
	read item$
	x1#=x#-(boxW/2)
	x2#=x#+(boxW/2)
	y1#=y#+(i*Spacing)-(BoxH/2)
	y2#=y#+(i*Spacing)+(BoxH/2)
	box x1#,y1#,x2#,y2#,Black,White,Black,White
	box x1#+2,y1#+2,x2#,y2#,0,Green,0,Green
	if mousex()>=x1# and mousex()<=x2# then if mousey()>=y1# and mousey()<=y2# then ThisButton=i
	center text x#,(y1#+(BoxH/5)),item$  `adjust divisor for text height
	NEXT
return

MainMenuData:
data 5,"New Game","Load Game","Options","HiScore","Quit"
Posted: 13th Dec 2021 21:18
In the code that I have shown there is a page
1) Main game menu
2) Inside the game menu
3) Save menu
4) Load menu.

I still need to ponder your example.
For example, to solve the problem of multiple menu pages.

I'll tell you a secret.
The number of graphic lines does not greatly affect the size of the executable file.
All the same, there will be at least 3 mb.
So I'd rather make the code easier to read.
Posted: 15th Dec 2021 20:54
Notice in my code it says if Menu=0 then gosub MainMenu
You could either have a different subroutine for each menu, or simply RESTORE a different DATA statement to produce different menus, which would entail even less code.
If each menu requires different sized boxes, text and screen locations, that info can also be stored in the DATA statement prior to each menu item.

While it's true that the codes easiest to read are usually the ones we write ourselves, or that already use techniques we are familiar with, your code has many redundant lines (Load Game 1, Load Game 2, etc.) that could be narrowed down with better technique. I've always found READ/DATA a very compact way to handle multiple choices without all the extra IF and CASE statements.

Anyhoo, all advice is take-it-or-leave-it, of course.

Happy Holidays!