// Project: menumake_standalone
// Created: 2016-07-29
// show all errors
//SetErrorMode(2)
// set window properties
SetWindowTitle( "menumake_standalone" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
#constant maxbuttons=12
#constant KEY_ENTER = 13
#CONSTANT KEY_ESCAPE=27
#constant KEY_F1=112
#constant KEY_F4=115
#constant KEY_F5=116
#constant KEY_F8=119
#constant KEY_F7=118
#constant KEY_DELETE=46
type TMouse
x1#
y1#
x2#
y2#
x4
y4
x4#
y4#
x3
y3
endtype
type buttons
btext$ as string
buttonid as integer
oldx as integer
oldy as integer
size# as float
tilevalue
tilevalue2
red as integer
green as integer
blue as integer
readytoselect as integer
alpha as integer
role as integer
set as integer
deleted as integer
readytodelete as integer
endtype
dim button[maxbuttons] as buttons
global Mouse as TMouse
global buttonpointer = 0
global buttoncount = 0
global buttonalpha = 255
global buttonred = 255
global buttongreen = 255
global buttonblue = 255
global button_name$ = "Button"
global text_name$ = "Text String"
global texteditbox = 300
global buttoneditbox = 301
global bsizebox = 302
global textsizebox = 303
global balphabox = 304
global fileeditbox = 309
global talpha = 255
global balpha = 255
global buttonredbox = 305
global buttongreenbox = 306
global buttonbluebox = 307
global talphabox = 308
global mybsize# = 80
global mytsize = 40
global bdropsprite = 0
global followmouse = 0
global oldx# = 0
global oldy# = 0
global baseboxX# = 10
global baseboxY# = 600
global ygap# = 34
global diff# = 150
global gridx = 32
global gridy = 32
global model$ = ""
global myboxcol = 47
global mycursor = 1
global mode = 0
global mylayoutname$ = "default.dat"
global messagetime = 1000
global bdropspritedepth = 700
global bdropimage = 0
init_button()
menu_designer()
end
function Menu_designer()
repeat
if getrawkeypressed(KEY_DELETE)
for n=1 to maxbuttons
if button[n].readytodelete=1
reset_button_value(n)
button[n].readytoselect=0
button[n].deleted=1
button[n].readytodelete=0
DeleteVirtualButton(n)
deletetext(n)
dec buttoncount
endif
next
endif
for n=1 to maxbuttons
if GetVirtualbuttonreleased(n) and GetVirtualButtonExists(n)
select button[n].readytoselect
case 0
button[n].readytoselect=1
SetVirtualButtonColor(n,255,0,0)
SetVirtualButtonAlpha(n,100)
button[n].readytodelete=1
endcase
case 1
button[n].readytoselect=0
SetVirtualButtonColor(n,button[n].red,button[n].green,button[n].blue)
SetVirtualButtonAlpha(n,button[n].alpha)
button[n].readytodelete=0
endcase
endselect
endif
next n
drawbox(mouse.x3-mybsize#/2,mouse.y3-mybsize#/2,mouse.x3+mybsize#/2,mouse.y3+mybsize#/2,myboxcol,myboxcol,myboxcol,myboxcol,0)
if getrawkeypressed(KEY_F8)
clear_layout()
endif
if getrawkeypressed(KEY_F7)
select_image()
endif
if getrawkeypressed(KEY_F5)
inc mode
if mode>1
mode=0
endif
select mode
case 1
hide_stuff()
endcase
case 0
show_stuff()
endcase
endselect
endif
print(str(mouse.y3))
if getrawkeypressed(KEY_ESCAPE)
quit=1
endif
if getrawkeypressed(KEY_ENTER)
read_editor_boxes()
endif
//read_editor_boxes()
FillMouse(gridx,gridy)
v=GetRawMouseRightReleased()
if getpointerpressed() and buttoncount<12 and mouse.y3<=672
for n=1 to maxbuttons
if button[n].deleted=1
foundbutton=1
fbuttonid=n
button[n].deleted=0
exit
elseif button[n].deleted=0
foundbutton=0
endif
next
if foundbutton=0
inc buttonpointer
inc buttoncount
make_my_button(buttonpointer,mouse.x3,mouse.y3,mybsize#,button_name$,buttonred,buttongreen,buttonblue,balpha)
set_button_value(buttonpointer)
elseif foundbutton=1
make_my_button(fbuttonid,mouse.x3,mouse.y3,mybsize#,button_name$,buttonred,buttongreen,buttonblue,balpha)
set_button_value(fbuttonid)
inc buttoncount
endif
endif
if getspriteexists(mycursor)
setspriteposition(mycursor,mouse.x3-getspritewidth(mycursor)/2,mouse.y3-getspriteheight(mycursor)/2)
endif
if getrawkeypressed(KEY_F4)
save_layout(mylayoutname$)
endif
if getrawkeypressed(KEY_F1)
load_layout(mylayoutname$)
endif
sync()
until quit=1
for n=1 to 12
if getvirtualbuttonexists(n)
deletevirtualbutton(n)
endif
next n
quit=0
endfunction
// Read the boxes and set appropriate values
function read_editor_boxes()
focus=GetCurrentEditBox()
select focus
case bsizebox
t$=geteditboxtext(bsizebox)
t#=valfloat(t$)
mybsize#=t#
endcase
case textsizebox
t$=geteditboxtext(textsizebox)
t=val(t$)
mytsize=t
endcase
case buttoneditbox
t$=geteditboxtext(buttoneditbox)
button_name$=t$
endcase
case texteditbox
t$=geteditboxtext(buttoneditbox)
text_name$=t$
endcase
case buttonredbox
t$=geteditboxtext(buttonredbox)
t=val(t$)
buttonred=t
endcase
case buttongreenbox
t$=geteditboxtext(buttongreenbox)
t=val(t$)
buttongreen=t
endcase
case buttonbluebox
t$=geteditboxtext(buttonbluebox)
t=val(t$)
buttonblue=t
endcase
case balphabox
t$=geteditboxtext(balphabox)
t=val(t$)
balpha=t
endcase
case fileeditbox
t$=geteditboxtext(fileeditbox)
mylayoutname$=t$
endcase
endselect
endfunction
function save_layout(f$)
myfile=opentowrite(f$,0)
writeinteger(myfile,bdropsprite)
writestring(myfile,model$)
writeinteger(myfile,bdropimage)
for n=1 to maxbuttons
writestring(myfile,button[n].btext$)
writeinteger(myfile,button[n].alpha)
writeinteger(myfile,button[n].blue)
writeinteger(myfile,button[n].buttonid)
writeinteger(myfile,button[n].green)
writeinteger(myfile,button[n].oldx)
writeinteger(myfile,button[n].oldy)
writeinteger(myfile,button[n].readytoselect)
writeinteger(myfile,button[n].red)
writeinteger(myfile,button[n].role)
writeinteger(myfile,button[n].set)
writefloat(myfile,button[n].size#)
writeinteger(myfile,button[n].tilevalue)
writeinteger(myfile,button[n].tilevalue2)
writeinteger(myfile,button[n].deleted)
next n
closefile(myfile)
print("Layout Saved!")
sync()
sleep(messagetime)
endfunction
function load_layout(f$)
if getfileexists(f$)
clear_layout()
myfile=opentoread(f$)
bdropsprite=readinteger(myfile)
model$=readstring(myfile)
bdropimage=readinteger(myfile)
for n=1 to maxbuttons
button[n].btext$=readstring(myfile)
button[n].alpha=readinteger(myfile)
button[n].blue=readinteger(myfile)
button[n].buttonid=readinteger(myfile)
button[n].green=readinteger(myfile)
button[n].oldx=readinteger(myfile)
button[n].oldy=readinteger(myfile)
button[n].readytoselect=readinteger(myfile)
button[n].red=readinteger(myfile)
button[n].role=readinteger(myfile)
button[n].set=readinteger(myfile)
button[n].size#=readfloat(myfile)
button[n].tilevalue=readinteger(myfile)
button[n].tilevalue2=readinteger(myfile)
button[n].deleted=readinteger(myfile)
next n
closefile(myfile)
else
print("File does not exist!")
sync()
sleep(messagetime)
exitfunction
endif
if bdropsprite>0
loadimage(bdropimage,model$)
createsprite(bdropsprite,bdropimage)
setspriteposition(bdropsprite,0,0)
setspritesize(bdropsprite,1024,768)
endif
for n=1 to maxbuttons
if button[n].buttonid<>0
//xc=worldtoscreenx(button[n].oldx)
//yc=worldtoscreeny(button[n].oldy)
//AddVirtualButton(button[n].buttonid,button[n].oldx,button[n].oldy,button[n].size#)
AddVirtualButton(button[n].buttonid,button[n].oldx,button[n].oldy,button[n].size#)
setvirtualbuttontext(button[n].buttonid,button[n].btext$)
SetVirtualButtonColor(button[n].buttonid,button[n].red,button[n].green,button[n].blue)
SetVirtualButtonAlpha(button[n].buttonid,button[n].alpha)
SetVirtualButtonVisible(button[n].buttonid,1)
createtext(button[n].buttonid,"B#"+str(button[n].buttonid))
settextsize(button[n].buttonid,24)
settextposition(button[n].buttonid,button[n].oldx-button[n].size#/2,button[n].oldy-button[n].size#+22)
inc buttoncount
endif
if buttonpointer<=button[n].buttonid and button[n].buttonid <12
buttonpointer=button[n].buttonid
endif
next n
print("Layout Loaded!")
sync()
sleep(messagetime)
endfunction
function clear_layout()
for n=1 to maxbuttons
button[n].btext$=""
button[n].alpha=0
button[n].blue=0
button[n].buttonid=0
button[n].green=0
button[n].oldx=0
button[n].oldy=0
button[n].readytoselect=0
button[n].red=0
button[n].role=0
button[n].set=0
button[n].size#=0
button[n].tilevalue=0
button[n].tilevalue2=0
button[n].deleted=0
button[n].readytodelete=0
if GetVirtualButtonExists(n)
DeleteVirtualButton(n)
endif
if gettextexists(n)
deletetext(n)
endif
next n
buttonpointer=0
buttoncount=0
if getspriteexists(bdropsprite)
deletesprite(bdropsprite)
endif
if getimageexists(bdropimage)
deleteimage(bdropimage)
endif
bdropsprite=0
endfunction
function createmytext(number,x#,y#,size,r,g,b,mystring$,depth)
createtext(number,mystring$)
settextsize(number,size)
settextcolor(number,r,b,g,talpha)
SetTextPosition(number,x#,y#)
FixTextToScreen(number,1)
settextdepth(number,depth)
endfunction
function createmyeditbox(number,x#,y#,bordersize#,r,g,b,backcolor,bsizex#,bsizey#,alpha,box$,v)
createeditbox(number)
SetEditBoxBorderSize(number,bordersize#)
SetEditBoxTextColor(number,r,g,b)
SetEditBoxBorderColor(number,r,g,b,alpha)
SetEditBoxBackgroundColor( number, 0, 0, 0, alpha )
seteditboxsize(number,bsizex#,bsizey#)
SetEditBoxPosition(number,x#,y#)
FixEditBoxToScreen(number,1)
seteditboxdepth(number,0)
SetEditBoxText(number,box$)
seteditboxvisible(number,v)
endfunction
function FillMouse(gridx,gridy)
Mouse.x1#=getpointerx()
Mouse.y1#=getpointery()
Mouse.x2#=screentoworldx(Mouse.x1#)
Mouse.y2#=screentoworldy(Mouse.y1#)
Mouse.x3=floor(Mouse.x2#/gridx)*gridx
Mouse.y3=floor(Mouse.y2#/gridy)*gridy
endfunction
function make_my_button(index,x,y,size#,text$,br,bg,bb,al)
AddVirtualButton( index,x, y, size# )
setvirtualbuttontext(index,text$)
SetVirtualButtonColor(index,br,bg,bb)
SetVirtualButtonAlpha(index,al)
SetVirtualButtonVisible(index,1)
createtext(index,"B#"+str(index))
settextsize(index,24)
settextposition(index,x-size#/2,y-size#+22)
endfunction
function set_button_value(buttn)
button[buttn].buttonid=buttn
button[buttn].oldx=mouse.x3
button[buttn].oldy=mouse.y3
button[buttn].size#=mybsize#
button[buttn].btext$=button_name$
button[buttn].red=buttonred
button[buttn].green=buttongreen
button[buttn].blue=buttonblue
button[buttn].alpha=balpha
endfunction
function init_button()
createmytext(100,baseboxX#+diff#*3.7,baseboxY#-1+ygap#*4,25,255,0,0,"BN",0)
createmytext(102,baseboxX#+diff#*2.7,baseboxY#-1+ygap#*4,25,255,0,0,"BS",0)
createmytext(103,baseboxX#,baseboxY#-1+ygap#*4,25,255,0,0,"B-Alpha -",0)
createmytext(104,baseboxX#+diff#*6.15,baseboxY#-5+ygap#*4,25,255,0,0,"BR",0)
createmytext(105,baseboxX#+diff#*4.86,baseboxY#-5+ygap#*4,25,0,255,0,"BB",0)
createmytext(106,baseboxX#+diff#*5.55,baseboxY#-5+ygap#*4,25,0,0,255,"BG",0)
v$=str(mybsize#)
mbs$=left(v$,2)
createmyeditbox(buttoneditbox,baseboxX#+diff#*4,baseboxY#+ygap#*4,1,255,0,0,0,110,20,255,button_name$,1)
createmyeditbox(fileeditbox,baseboxX#+diff#*1.8,baseboxY#+ygap#*4,1,255,0,0,0,110,20,255,mylayoutname$,1)
createmyeditbox(bsizebox,baseboxX#+diff#*3,baseboxY#+ygap#*4,1,255,0,0,0,40,20,255,mbs$,1)
createmyeditbox(balphabox,baseboxX#+diff#,baseboxY#+ygap#*4-0.1,1,255,0,0,0,40,20,255,str(buttonalpha),1)
createmyeditbox(buttonredbox,baseboxX#+diff#*6.4,baseboxY#+ygap#*4,1,255,0,0,0,40,20,255,str(buttonred),1)
createmyeditbox(buttongreenbox,baseboxX#+diff#*5.8,baseboxY#+ygap#*4,1,0,255,0,0,40,20,255,str(buttongreen),1)
createmyeditbox(buttonbluebox,baseboxX#+diff#*5.2,baseboxY#+ygap#*4,1,0,0,255,0,40,20,255,str(buttonblue),1)
myboxcol=MakeColor(0,255,0)
endfunction
function hide_stuff()
for n=1 to 1000
if gettextexists(n)
SetTextVisible(n,0)
endif
if geteditboxexists(n)
SetEditBoxVisible(n,0)
endif
next n
endfunction
function show_stuff()
for n=1 to 1000
if gettextexists(n)
SetTextVisible(n,1)
endif
if geteditboxexists(n)
SetEditBoxVisible(n,1)
endif
next n
endfunction
function select_image()
model$=ChooseRawFile("*.png")
if GetImageExists(bdropimage)
deleteimage(bdropimage)
endif
bdropimage=loadimage(model$)
bdropsprite=createsprite(bdropimage)
setspritedepth(bdropsprite,bdropspritedepth)
setspritesize(bdropsprite,1024,768)
//setspritecolor(bdropsprite,255,0,0,255)
//setspritesize(bdropsprite,800,600)
setspriteposition(bdropsprite,0,0)
endfunction
function reset_button_value(bt)
button[bt].btext$=""
button[bt].alpha=0
button[bt].blue=0
button[bt].buttonid=0
button[bt].green=0
button[bt].oldx=0
button[bt].oldy=0
button[bt].red=0
button[bt].role=0
button[bt].set=0
button[bt].size#=0
button[bt].tilevalue=0
button[bt].tilevalue2=0
endfunction
Ok I mentioned earlier that I had tried to code a menu editor within th main level editor of mine, it got messy so decided to rip out the code I had and develop it separately.
You can use this for whatever, I am about to integrate it back into my main level editor and thought I would share it before it vanishes!
I have finished it and hopefully bug free, here is some info on its usage.
First thing you will probably notice is a green box, this represents where you want to paste a button, go ahead, left click wherever and a button is created! You will notice a text gets created along with the button, this is to keep track of the button ID as we will be deleting/re-using them!
Once you have put down a button, and maybe decided you dont want it there, or atall, you can click on the button, which makes it turn red, then press delete to delete it. You can do this on multiple buttons for multiple select/delete, clicking again deselects the button(s)
Right, now let us change the way our button is created, the edit boxes at the bottom!
First up from left to right is
B-Alpha: kinda speaks for itself and sets the alpha of the button to be created, a value of 0-255 here!
FN: means filename, the default being default.dat, you can put anything in here, creating multiple files!
BS: means button size, defaults to 80
BN is the name you want to give the button, defaults to 'Button'
the last 3 boxes, BB, BG and BR are for setting the RGB values of the button colour respectively.
All keys are tied to the function keys for obvious reasons! these are:
F1- loads a saved file by the file name in its edit box
F4 - saves the file again by file name given
F8 clears the whole level.
F7 loads in a background image you select.
F5 hides/shows all the text and edit boxes
An example of its usage:
I just went with the defaults here, saved the file,created a new projects and copied the following code from the editor:
// Project: buttontest
// Created: 2016-08-09
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "buttontest" )
SetWindowSize( 1024, 768, 0 )
// set display properties
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
#constant maxbuttons=12
type buttons
btext$ as string
buttonid as integer
oldx as integer
oldy as integer
size# as float
tilevalue
tilevalue2
red as integer
green as integer
blue as integer
readytoselect as integer
alpha as integer
role as integer
set as integer
deleted as integer
readytodelete as integer
endtype
dim button[maxbuttons] as buttons
global mylayoutname$ = "default.dat"
global messagetime = 1000
global bdropspritedepth = 700
global bdropimage = 0
load_layout(mylayoutname$)
do
for n=1 to maxbuttons
if getvirtualbuttonexists(n)
if getvirtualbuttonpressed(n)
print ("You pressed Button #"+str(n))
endif
endif
next n
Sync()
loop
function load_layout(f$)
if getfileexists(f$)
clear_layout()
myfile=opentoread(f$)
bdropsprite=readinteger(myfile)
model$=readstring(myfile)
bdropimage=readinteger(myfile)
for n=1 to maxbuttons
button[n].btext$=readstring(myfile)
button[n].alpha=readinteger(myfile)
button[n].blue=readinteger(myfile)
button[n].buttonid=readinteger(myfile)
button[n].green=readinteger(myfile)
button[n].oldx=readinteger(myfile)
button[n].oldy=readinteger(myfile)
button[n].readytoselect=readinteger(myfile)
button[n].red=readinteger(myfile)
button[n].role=readinteger(myfile)
button[n].set=readinteger(myfile)
button[n].size#=readfloat(myfile)
button[n].tilevalue=readinteger(myfile)
button[n].tilevalue2=readinteger(myfile)
button[n].deleted=readinteger(myfile)
next n
closefile(myfile)
else
print("File does not exist!")
sync()
sleep(messagetime)
exitfunction
endif
if bdropsprite>0
loadimage(bdropimage,model$)
createsprite(bdropsprite,bdropimage)
setspriteposition(bdropsprite,0,0)
setspritesize(bdropsprite,1024,768)
endif
for n=1 to maxbuttons
if button[n].buttonid<>0
//xc=worldtoscreenx(button[n].oldx)
//yc=worldtoscreeny(button[n].oldy)
//AddVirtualButton(button[n].buttonid,button[n].oldx,button[n].oldy,button[n].size#)
AddVirtualButton(button[n].buttonid,button[n].oldx,button[n].oldy,button[n].size#)
setvirtualbuttontext(button[n].buttonid,button[n].btext$)
SetVirtualButtonColor(button[n].buttonid,button[n].red,button[n].green,button[n].blue)
SetVirtualButtonAlpha(button[n].buttonid,button[n].alpha)
SetVirtualButtonVisible(button[n].buttonid,1)
endif
next n
// print("Layout Loaded!")
// sync()
// sleep(messagetime)
endfunction
function clear_layout()
for n=1 to maxbuttons
button[n].btext$=""
button[n].alpha=0
button[n].blue=0
button[n].buttonid=0
button[n].green=0
button[n].oldx=0
button[n].oldy=0
button[n].readytoselect=0
button[n].red=0
button[n].role=0
button[n].set=0
button[n].size#=0
button[n].tilevalue=0
button[n].tilevalue2=0
if GetVirtualButtonExists(n)
DeleteVirtualButton(n)
endif
if gettextexists(n)
deletetext(n)
endif
next n
buttonpointer=0
buttoncount=0
if getspriteexists(bdropsprite)
deletesprite(bdropsprite)
endif
if getimageexists(bdropimage)
deleteimage(bdropimage)
endif
bdropsprite=0
endfunction
2 functions, the load and clear! plus the type and array definitions the constant and a few needed globals!
I finally copy the file that was saved in %appdata% from the menu maker App in my case, to the new projects media folder,along with any images I may have chosen.
The neat way about this is that I can have multiple files per project,simply call load_layout(id$) to load it in. Call clear_layout() to totally clear the current menu at any point.
I might develop this more to allow for images on the buttons, but I dunno!
**edit sorry missed the code to read the file name in the first piece,I have put it in now!
There is probably a few fields in the button type that are defunct but I kept them in just in case they become handy later!
Hail to the king, baby!