Difference between revisions of "Options Menu"

850 bytes added ,  21:38, 3 July 2012
imported>Threedee
imported>Threedee
Line 24: Line 24:
EndEvent</source>
EndEvent</source>


*For the next example, we'll offer sub-options for each main selection. For a multilevel menu, a function works well. Keep in mind each button can have conditions, so you could hide "Lunch" and "Dinner" if it's time for breakfast or hide "Lobster" if it's not currently available. In this case, to make it repeatable, we'll use a book so the menu will show each time it is read. A book cannot be favorited or hotkeyed, unlike an apparel item. A potion can be hotkeyed, but it will be consumed when used and not remain hotkeyed even if immediately replaced. This example will let the user choose breakfast, lunch, or dinner, then close after one meal is selected.
*For the next example, we'll offer sub-options for each main selection. For a multilevel menu, functions can be used to keep the menu well organized. Keep in mind that you can assign conditions to each button in the Message forms, so you could hide "Lunch" and "Dinner" if it's time for breakfast, or hide "Lobster" if it's not currently available. In this case, to make it repeatable, we'll use a book so the menu will show each time it is read. A book cannot be favorited or hotkeyed, unlike an apparel item. A potion can be hotkeyed, but it will be consumed when used and not remain hotkeyed even if immediately replaced. This example will let the user choose breakfast, lunch, or dinner, then close after one meal is selected.


<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
<source lang="papyrus">
 
ScriptName OptionsMenuScript extends ObjectReference
Armor Property MenuBook Auto
;===================================================
ObjectReference Property MenuBook Auto
Message Property MainMenuMESG Auto
Message Property MainMenuMESG Auto
Message Property BreakfastMESG Auto
Message Property BreakfastMESG Auto
Message Property LunchMESG Auto
Message Property LunchMESG Auto
Message Property DinnerMESG Auto
Message Property DinnerMESG Auto
;===================================================


Event OnRead()
Event OnRead()
Game.DisablePlayerControls(False, False, False, False, False, True) ; Momentarily disable other menus
Game.DisablePlayerControls(False, False, False, False, False, True) ; Temporarily disable other menus
Menu()
Menu()
Game.EnablePlayerControls(False, False, False, False, False, True) ; Undo DisablePlayerControls
Game.EnablePlayerControls(False, False, False, False, False, True) ; Re-enable Player controls
EndEvent  
EndEvent  
;===================================================
Function Menu()
int aiButton = MainMenuMESG.Show() ; Main Menu
If aiButton == 0 ; Breakfast
BreakfastMenu()
ElseIf aiButton == 1 ; Lunch
LunchMenu()
ElseIf aiButton == 2 ; Dinner
DinnerMenu()
ElseIf aiButton == 3 ; Quit the menu
Return
EndIf
EndFunction
;===================================================
Function BreakfastMenu()
int aiButton = BreakfastMESG.Show()
If aiButton == 0
Debug.Notification("Choice = Sweet Roll & Coffee")
ElseIf aiButton == 1
Debug.Notification("Choice = Pancakes, Bacon & Eggs")
ElseIf aiButton == 2
Debug.Notification("Choice = Chicken Fried Pony Steak")
ElseIf aiButton == 3 ; Return to the main menu
Return
EndIf
EndFunction
;===================================================
Function LunchMenu()
int aiButton = LunchMESG.Show()
If aiButton == 0
Debug.Notification("Choice = Glazed Turkey Sandwich")
ElseIf aiButton == 1
Debug.Notification("Choice = Grilled Ham Sandwich")
ElseIf aiButton == 2
Debug.Notification("Choice = Shredded Pony Sandwich")
ElseIf aiButton == 3 ; Return to the main menu
Return
EndIf
EndFunction
;===================================================
Function DinnerMenu()
aiButton = DinnerMESG.Show()
If aiButton == 0
Debug.Notification("Choice = Filet Mignon")
ElseIf aiButton == 1
Debug.Notification("Choice = Pony Fajitas")
ElseIf aiButton == 2
Debug.Notification("Choice = Lobster")
ElseIf aiButton == 3 ; Return to the main menu
Return
EndIf
EndFunction
;===================================================
</source>


Function Menu(Bool abMenu = True, Int aiButton = 0)
While abMenu
If aiButton != -1 ; Wait for input (this can prevent problems if recycling the aiButton argument in submenus)
aiButton = MainMenuMESG.Show() ; Main Menu
abMenu = False ; End the function
If aiButton == 0 ; Breakfast
aiButton = BreakfastMESG.Show()
If aiButton == 0 ; Sweet Roll & Coffee
ElseIf aiButton == 1 ; Pancakes, Bacon & Eggs
ElseIf aiButton == 2 ; Chicken Fried Pony Steak
EndIf
ElseIf aiButton == 1 ; Lunch
aiButton = LunchMESG.Show()
If aiButton == 0 ;  Glazed Turkey Sandwich
ElseIf aiButton == 1 ; Grilled Ham Sandwich
ElseIf aiButton == 2 ; Shredded Pony Sandwich
EndIf
ElseIf aiButton == 2 ; Dinner
aiButton = DinnerMESG.Show()
If aiButton == 0 ; Filet Mignon
ElseIf aiButton == 1 ; Pony Fajitas
ElseIf aiButton == 2 ; Lobster
EndIf
EndIf
EndIf
EndWhile
EndFunction</source>
*To make a multilevel, looping menu with thirty buttons that will not close until a "Done" button is pressed, use the above method but with an altered Menu() function. Note that you can jump to a given message by specifying the aiMessage argument when calling the function. Sub-options as described in the previous example can be added to the below in the same manner. Theoretically, any number of options can be added with the below structure.
*To make a multilevel, looping menu with thirty buttons that will not close until a "Done" button is pressed, use the above method but with an altered Menu() function. Note that you can jump to a given message by specifying the aiMessage argument when calling the function. Sub-options as described in the previous example can be added to the below in the same manner. Theoretically, any number of options can be added with the below structure.
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
<source lang="papyrus">ScriptName OptionsMenuScript extends ObjectReference
Anonymous user