Selective menus not working?
Blitz3D Forums/Blitz3D Programming/Selective menus not working?
| ||
I have now commandeered the f12 key to help me debug. But even that wont tell me why this code isn't working now. in the init_button_list the program creates generic menu items which are available on each page. INIT_MENU is used to prepare button images for display from the blits/b-list's (button lists). At first, now, it works fine. At the main menu it only brings the main menu buttons up. And on the EDIT_MAIN screen it does as well. However going into one of the weapons/vehicles or player menu removes the "*" categorized menu buttons (HOME SETUP and EXIT) from appearing. Yet they are still there in the b-lists menu so should be delected to be made from init_menu, yet they dont. Why is this? They are not deleted, f12 confirms the "*" b-list items are still there! Global settings_file$="setup.txt" SeedRnd MilliSecs() Graphics 1024,768,32,2 SetBuffer BackBuffer() Global t# Global menu_setup=0 ;these are important for figuring out what section we are in Global menu$="MAIN_MENU" Global file$="" Global section$="" Global subsection$="" Global mouse_timeout#=0 Global ERROR_COUNT=0 Global mouse_width=100 Global font_X=LoadFont("Courier New.ttf",48,1,0,0) Global font_L=LoadFont("Courier New.ttf",36,1,0,0) Global font_M=LoadFont("Courier New.ttf",20,0,0,0) Global font_S=LoadFont("Courier New.ttf",14,0,0,0) Global gfx_mouse=CreateImage(5,5) SetBuffer ImageBuffer(gfx_mouse) Color 255,255,255 Rect 0,0,10,10 SetBuffer BackBuffer() MidHandle gfx_mouse ; pre setup stuff init_button_list() HidePointer() ;main stuff starttime=MilliSecs() ClsColor 25*2,15*2,10*2 While KeyDown(1)=0 SetBuffer BackBuffer() fps=fps+1 If MilliSecs()-starttime>1000 Then starttime=MilliSecs() fps_old=fps fps=0 EndIf If menu_setup=0 init_menu() ; load all menu bits EndIf draw_mouse() draw_buttons() draw_mouse() Color 255,255,255 SetFont font_S Text GraphicsWidth()-95,0,"x="+MouseX()+" y="+MouseY() Text 20,30,"FPS="+fps_old Text 20,10,"MENU NAME="+menu$ Text 20,50,"TIMEOUT="+mouse_timeout buts=0 For b.but = Each but buts=buts+1 Next Text 20,70,"BUTTONZ="+buts If MouseDown(1) Then mouse_width=mouse_width+10 If KeyDown(88) Then Cls SetFont font_S Color 255,255,255 Text 20,20,"BUTTONS" yoff = 40 For b.but = Each but Text 20,yoff,"---"+b\click_cmd+" "+b\menu yoff=yoff+12 Next Color 255,255,255 Text 420,20,"BLISTS" yoff = 40 For bl.blist = Each blist Text 420,yoff,"---"+bl\txt$+" "+bl\menu$ yoff=yoff+12 Next Flip Delay 10 EndIf Flip ; flip buffer Cls Delay (1000/50)-(MilliSecs()-frame_now) mouse_timeout=mouse_timeout-(MilliSecs()-frame_now) If mouse_timeout<0 Then mouse_timeout=0 frame_now=MilliSecs() Wend ;functions Function interpret_click_command(CMD$) ; Delay 1000 If CMD$="program exit" Then RuntimeError "You have exited the program" If Left$(CMD$,4)="menu" Then ; ITS A MENU CHANGE! menu$=Right$(CMD$,Len(CMD)-5) mouse_width=2000 mouse_timeout=440 init_menu() EndIf ;errorpoint() ; ERROR LINE ---- DO NOT CROSS ----ERROR LINE ---- DO NOT CROSS ----ERROR LINE ---- DO NOT CROSS ----ERROR LINE ---- DO NOT CROSS End Function Function draw_mouse() Color 255,255,255 DrawImage gfx_mouse,MouseX(),MouseY() mouse_width=mouse_width*0.8 If mouse_width<6 Then mouse_width=6 For t = 1 To 180 Line MouseX()+Sin((MilliSecs()/10)+t)*mouse_width,MouseY()+Cos((MilliSecs()/10)+t)*mouse_width,MouseX()+Sin((MilliSecs()/10)+t)*-mouse_width,MouseY()+Cos((MilliSecs()/10)+t)*-mouse_width t=t+17 Next Color 0,0,0 strength#=mouse_timeout*3 Oval MouseX()-(strength/2),MouseY()-(strength/2),strength,strength End Function Type but Field img,x#,y#,click_cmd$,menu$,todraw End Type Function draw_buttons() For b.but = Each but b\todraw=0 Next If menu="MAIN_MENU" Then xpos=300 For b.but = Each but If b\menu<>"*" And b\menu<>"EDIT_" Then b\todraw=1 DrawImage b\img,GraphicsWidth()/2,xpos If ImagesOverlap(gfx_mouse,MouseX(),MouseY(),b\img,GraphicsWidth()/2,xpos)=1 Then mouse_over_object=1 DrawImage b\img,GraphicsWidth()/2,xpos,1 Color 255,255,255 Text MouseX()+30,MouseY()+30,b\click_cmd If mouse_over_object=1 And MouseDown(1)=1 Then interpret_click_command(b\click_cmd) EndIf EndIf If xpos=300 Then xpos=xpos+200 Else xpos=xpos+100 EndIf EndIf Next EndIf If menu<>"MAIN_MENU" Then For b.but = Each but If b\menu="*" ; if the button belongs to this menu or is generic. b\todraw=1 If b\click_cmd="menu MAIN_MENU" Then xpos=100 ypos=100 EndIf If b\click_cmd="menu SETUP" Then xpos=85 ypos=680 EndIf If b\click_cmd="program exit" Then xpos=100 ypos=740 EndIf Color 155,155,155 For t=1 To 5 Line 162+t,0,162+t,800 Next DrawImage b\img,xpos,ypos If ImagesOverlap(gfx_mouse,MouseX(),MouseY(),b\img,xpos,ypos)=1 Then mouse_over_object=1 DrawImage b\img,xpos,ypos,1 Color 255,255,255 Text MouseX()+30,MouseY()+30,b\click_cmd If mouse_over_object=1 And MouseDown(1)=1 Then interpret_click_command(b\click_cmd) EndIf EndIf xpos=xpos+100 EndIf Next EndIf If Left$(menu$,5)="EDIT_" Then xpos=5 ypos=140 For b.but = Each but If b\menu$="EDIT_" Then ; if the button belongs to this menu or is generic. ypos=ypos+30 b\todraw=1 DrawImage b\img,xpos,ypos If ImagesOverlap(gfx_mouse,MouseX(),MouseY(),b\img,xpos,ypos)=1 Then mouse_over_object=1 DrawImage b\img,xpos,ypos,1 Color 255,255,255 Text MouseX()+30,MouseY()+30,b\click_cmd If mouse_over_object=1 And MouseDown(1)=1 Then interpret_click_command(b\click_cmd) EndIf EndIf EndIf Next EndIf For b.but = Each but If b\todraw=0 FreeImage b\img Delete b EndIf Next End Function Function errorpoint() ERROR_COUNT=ERROR_COUNT+1 For t = 1 To 100 If Rnd(1,100)>85 Then Color Rnd(255,155),Rnd(255,155),Rnd(255,155) Rect 0+t,0+t,GraphicsWidth(),GraphicsHeight(),0 Next Color 0,0,0 Text 20,20,"BREAKPOINT REACHED! TIME="+MilliSecs() Text 20,35,"WE HAVE REACHED THE POINT YOU WANTED ME TO STOP AND TELL YOU WE HAD REACHED. Text 20+1,35,"WE HAVE REACHED THE POINT YOU WANTED ME TO STOP AND TELL YOU WE HAD REACHED. Text 20,50,"RESUMING IN 5 SECONDS..." Text 20+1,50,"RESUMING IN 5 SECONDS..." Color 0,0,0 Rect 10,72,200,22 Color 255,255,255 Text 20,75,"ERROR NUMBER="+ERROR_COUNT Flip Delay 3000 End Function Function gen_menu_but(txt$,action$,colour$,size$,bmenu$) b.but = New but If size="X" Then SetFont font_X add=32 EndIf If size="L" Then SetFont font_L add=24 EndIf If size="M" Then SetFont font_M add=4 EndIf If size="S" Then SetFont font_S EndIf tempimage=CreateImage(Len(txt$)*(12+(add*0.6)),16+add,2) frame=0 SetBuffer ImageBuffer(tempimage,frame) Color 155,155,155 Rect 0,0,ImageWidth(tempimage),ImageHeight(tempimage) Color 0,0,0 Rect 1+(add/12),1+(add/12),ImageWidth(tempimage)-(2+(add/6)),ImageHeight(tempimage)-(2+(add/6)) getcolour(colour$) Text ImageWidth(tempimage)/2,ImageHeight(tempimage)/2,txt$,1,1 frame=1 SetBuffer ImageBuffer(tempimage,frame) Color 155,155,155 Rect 0,0,ImageWidth(tempimage),ImageHeight(tempimage) getcolour(colour$) Color ColorRed()/2,ColorGreen()/2,ColorBlue()/2 Rect 1+(add/12),1+(add/12),ImageWidth(tempimage)-(2+(add/6)),ImageHeight(tempimage)-(2+(add/6)) getcolour(colour$) Text ImageWidth(tempimage)/2,ImageHeight(tempimage)/2,txt$,1,1 If Left$(txt$,1)<>">" Then MidHandle tempimage b\img=CopyImage(tempimage) b\click_cmd$=action$ b\menu$=bmenu$ FreeImage tempimage End Function Function init_menu() For b.but = Each but ; clear old menu's buttons FreeImage b\img Delete b Next For bl.blist = Each blist ; scan button list for this menu's buttons If bl\menu$=menu$ Or bl\menu$="*" Or bl\menu="EDIT_" Then gen_menu_but(bl\txt$,bl\action$,bl\colour,bl\size$,bl\menu$) EndIf Next menu_setup=1 End Function Type BLIST Field txt$,menu$,action$,colour$,size$ End Type Function init_button_list() new_blist("EDIT GAME","MAIN_MENU","menu EDIT_MAIN","green","X") new_blist("SETUP THIS PROGRAM","MAIN_MENU","menu SETUP","yellow","X") new_blist("EXIT THIS PROGRAM","MAIN_MENU","program exit","red","X") new_blist("HOME","*","menu MAIN_MENU","green","X") new_blist("SETUP","*","menu SETUP","yellow","X") new_blist("EXIT","*","program exit","red","X") new_blist(">PLAYER","EDIT_","menu EDIT_PLYR","cyan","M") new_blist(">WEAPONS","EDIT_","menu EDIT_WEPS","cyan","M") new_blist(">VEHICLES","EDIT_","menu EDIT_VEHS","cyan","M") End Function Function new_blist(txt$,bmenu$,action$,colour$,size$) bl.blist = New blist bl\txt$=txt$ bl\menu$=bmenu$ bl\action$=action$ bl\colour$=colour$ bl\size$=size$ End Function Function getcolour(colour$) If colour$="red" Then Color 255,0,0 If colour$="green" Then Color 0,255,0 If colour$="blue" Then Color 0,0,255 If colour$="yellow" Then Color 255,255,0 If colour$="purple" Then Color 255,0,255 If colour$="cyan" Then Color 0,255,255 If colour$="grey" Then Color 155,155,155 End Function |