Initial commit
This commit is contained in:
178
Menu.pbi
Normal file
178
Menu.pbi
Normal file
@@ -0,0 +1,178 @@
|
||||
Declare InitGameMode(Mode.l)
|
||||
|
||||
Structure MenuOption
|
||||
X.f
|
||||
Y.f
|
||||
Width.l
|
||||
*ChoiceIndex.Long
|
||||
String.s
|
||||
Choices.s
|
||||
GoToMode.l
|
||||
SendGUIEvent.l
|
||||
EndStructure
|
||||
|
||||
Structure Menu
|
||||
MenuTitle.s
|
||||
*Obj
|
||||
X.f
|
||||
Y.f
|
||||
Width.l
|
||||
OptionIndex.l
|
||||
List MenuOption.MenuOption()
|
||||
EndStructure
|
||||
|
||||
Global Menu.Menu
|
||||
|
||||
Procedure NewMenu(MenuTitle.s,DefaultOptionIndex.l=0)
|
||||
Menu\MenuTitle=MenuTitle
|
||||
Menu\OptionIndex=DefaultOptionIndex
|
||||
ClearList(Menu\MenuOption())
|
||||
Menu\Obj=NewSprite(-1,0,0,0,0,255,1)
|
||||
EndProcedure
|
||||
|
||||
Procedure AddMenuOption(String.s,GoToMode.l=-1,SendGUIEvent.l=-1,Choices.s="",*ChoiceIndex=-1)
|
||||
Protected *MenuOption=AddElement(Menu\MenuOption())
|
||||
Menu\MenuOption()\String=String
|
||||
Menu\MenuOption()\Choices=Choices
|
||||
Menu\MenuOption()\ChoiceIndex=*ChoiceIndex
|
||||
Menu\MenuOption()\GoToMode=GoToMode
|
||||
Menu\MenuOption()\SendGUIEvent=SendGUIEvent
|
||||
ProcedureReturn *MenuOption
|
||||
EndProcedure
|
||||
|
||||
Procedure StartMenu()
|
||||
AddmoveToEngine(@Menu\Y,#PB_Float,0,1500,ScreenHeight(),GUI\BlockSize*2,#Easing_ElasticEaseOut)
|
||||
|
||||
Protected Spacing.l,StartY.l
|
||||
Spacing=((GUI\ScreenHeight-5)/ListSize(Menu\MenuOption()))*GUI\BlockSize
|
||||
If Spacing>GUI\BlockSize:Spacing=GUI\BlockSize:EndIf
|
||||
StartY=(ScreenHeight()-5*GUI\BlockSize-ListSize(Menu\MenuOption())*Spacing)/2
|
||||
ForEach Menu\MenuOption()
|
||||
DrawingBitmapFont(0)
|
||||
Protected String.s=Menu\MenuOption()\String
|
||||
If Menu\MenuOption()\Choices<>""
|
||||
If Menu\MenuOption()\ChoiceIndex<>-1
|
||||
String=String+" : "+StringField(Menu\MenuOption()\Choices,Menu\MenuOption()\ChoiceIndex\l+1,"|")
|
||||
Else
|
||||
String=String+" Error ChoiceIndex"
|
||||
EndIf
|
||||
EndIf
|
||||
Menu\MenuOption()\Width=TextBitmapWidth(String)
|
||||
Menu\MenuOption()\X=(ScreenWidth()-Menu\MenuOption()\Width)/2
|
||||
Menu\MenuOption()\Y=3*GUI\BlockSize+StartY+ListIndex(Menu\MenuOption())*Spacing
|
||||
|
||||
If ListIndex(Menu\MenuOption())%2
|
||||
AddmoveToEngine(@Menu\MenuOption()\X,#PB_Float,0,1500,ScreenWidth(),Menu\MenuOption()\X,#Easing_ElasticEaseOut)
|
||||
Else
|
||||
AddmoveToEngine(@Menu\MenuOption()\X,#PB_Float,0,1500,-Menu\MenuOption()\Width,Menu\MenuOption()\X,#Easing_ElasticEaseOut)
|
||||
|
||||
EndIf
|
||||
Next
|
||||
;StartMove(Menu\Obj)
|
||||
EndProcedure
|
||||
|
||||
Procedure FinalizeMenu()
|
||||
DrawingBitmapFont(1)
|
||||
Menu\Width=TextBitmapWidth(Menu\MenuTitle)
|
||||
Menu\X=(ScreenWidth()-Menu\Width)/2
|
||||
DrawingBitmapFont(0)
|
||||
StartMenu()
|
||||
EndProcedure
|
||||
|
||||
Procedure EndMenu(Mode.l=-1)
|
||||
If Mode<>-1
|
||||
Mode=1000+Mode
|
||||
EndIf
|
||||
|
||||
AddmoveToEngine(@Menu\Y,#PB_Float,0,500,GUI\BlockSize*2,ScreenHeight(),#Easing_SineEaseOut,Mode)
|
||||
ForEach Menu\MenuOption()
|
||||
If ListIndex(Menu\MenuOption())%2
|
||||
AddmoveToEngine(@Menu\MenuOption()\X,#PB_Float,0,500,Menu\MenuOption()\X,ScreenWidth(),#Easing_SineEaseOut)
|
||||
Else
|
||||
|
||||
AddmoveToEngine(@Menu\MenuOption()\X,#PB_Float,0,500,Menu\MenuOption()\X,-Menu\MenuOption()\Width,#Easing_SineEaseOut)
|
||||
EndIf
|
||||
Next
|
||||
|
||||
EndProcedure
|
||||
|
||||
Procedure DisplayMenu()
|
||||
Protected.l X,Y,Width,Alpha
|
||||
Protected String.s
|
||||
Static MB.l
|
||||
DrawingBitmapFont(1)
|
||||
DrawBitmapText(Menu\X,Menu\Y,Menu\MenuTitle)
|
||||
DrawingBitmapFont(0)
|
||||
ForEach Menu\MenuOption()
|
||||
|
||||
If MouseX()>Menu\MenuOption()\X And MouseX()<Menu\MenuOption()\X+Menu\MenuOption()\Width And MouseY()>Menu\MenuOption()\Y And MouseY()<Menu\MenuOption()\Y+GUI\BlockSize
|
||||
Menu\OptionIndex=ListIndex(Menu\MenuOption())
|
||||
EndIf
|
||||
|
||||
String=Menu\MenuOption()\String
|
||||
If Menu\MenuOption()\Choices<>""
|
||||
String=String+" : "+StringField(Menu\MenuOption()\Choices,Menu\MenuOption()\ChoiceIndex\l+1,"|")
|
||||
EndIf
|
||||
If Menu\OptionIndex=ListIndex(Menu\MenuOption())
|
||||
Alpha=255
|
||||
If GetLeftMouseClick() Or KeyboardReleased(#PB_Key_Space) ;Or (KeyboardReleased(#PB_Key_Return) And KeyboardPushed(#PB_Key_LeftAlt)=0)
|
||||
PlaySound(#Snd_WaterDrop)
|
||||
;If MB=#False
|
||||
;MB=#True
|
||||
If Menu\MenuOption()\Choices<>"" And Menu\MenuOption()\ChoiceIndex<>-1
|
||||
Menu\MenuOption()\ChoiceIndex\l=Menu\MenuOption()\ChoiceIndex\l+1
|
||||
If Menu\MenuOption()\ChoiceIndex\l>CountString(Menu\MenuOption()\Choices,"|")
|
||||
Menu\MenuOption()\ChoiceIndex\l=0
|
||||
EndIf
|
||||
Debug "Drawmenu() Space Index:"+Str(Menu\MenuOption()\ChoiceIndex\l)
|
||||
ElseIf Menu\MenuOption()\GoToMode>0
|
||||
EndMenu(Menu\MenuOption()\GoToMode)
|
||||
EndIf
|
||||
If Menu\MenuOption()\SendGUIEvent>-1
|
||||
Debug "DrawMenu() PosteEventGUI("+Str(Menu\MenuOption()\SendGUIEvent)
|
||||
PostEventGUI(Menu\MenuOption()\SendGUIEvent)
|
||||
EndIf
|
||||
;EndIf
|
||||
;Else
|
||||
; MB=#False
|
||||
EndIf
|
||||
If Menu\MenuOption()\Choices<>""
|
||||
If KeyboardReleased(#PB_Key_Left) And Menu\MenuOption()\ChoiceIndex\l>0
|
||||
PlaySound(#Snd_WaterDrop)
|
||||
Menu\MenuOption()\ChoiceIndex\l=Menu\MenuOption()\ChoiceIndex\l-1
|
||||
If Menu\MenuOption()\SendGUIEvent>-1
|
||||
PostEventGUI(Menu\MenuOption()\SendGUIEvent)
|
||||
EndIf
|
||||
Debug "Drawmenu() Left Index:"+Str(Menu\MenuOption()\ChoiceIndex\l)
|
||||
EndIf
|
||||
|
||||
If KeyboardReleased(#PB_Key_Right) And Menu\MenuOption()\ChoiceIndex\l<CountString(Menu\MenuOption()\Choices,"|")
|
||||
PlaySound(#Snd_WaterDrop)
|
||||
Menu\MenuOption()\ChoiceIndex\l=Menu\MenuOption()\ChoiceIndex\l+1
|
||||
If Menu\MenuOption()\SendGUIEvent>-1
|
||||
PostEventGUI(Menu\MenuOption()\SendGUIEvent)
|
||||
EndIf
|
||||
Debug "Drawmenu() Right Index:"+Str(Menu\MenuOption()\ChoiceIndex\l)
|
||||
EndIf
|
||||
EndIf
|
||||
Else
|
||||
Alpha=100
|
||||
EndIf
|
||||
DrawBitmapText(Menu\MenuOption()\X,Menu\MenuOption()\Y,String,Alpha)
|
||||
Next
|
||||
If KeyboardReleased(#PB_Key_Up) And Menu\OptionIndex>0
|
||||
PlaySound(#Snd_WaterDrop)
|
||||
Menu\OptionIndex=Menu\OptionIndex-1
|
||||
EndIf
|
||||
|
||||
If KeyboardReleased(#PB_Key_Down) And Menu\OptionIndex<ListSize(Menu\MenuOption())-1
|
||||
PlaySound(#Snd_WaterDrop)
|
||||
Menu\OptionIndex=Menu\OptionIndex+1
|
||||
EndIf
|
||||
|
||||
EndProcedure
|
||||
; IDE Options = PureBasic 6.00 Beta 6 (Windows - x64)
|
||||
; CursorPosition = 118
|
||||
; FirstLine = 108
|
||||
; Folding = --
|
||||
; EnableXP
|
Reference in New Issue
Block a user