I'm making a visual novel that has a mecha combat minigame. If the user isn't skipping the minigame entirely, they'll spend a lot of time there. So I wanted to have keyboard shortcuts for making the "moves" in the minigame. This led to the title snippet... Basic Customized Menu With Keyboard Shortcuts.
Code: Select all
# Demonstration
label start:
"Take your best shot."
call screen attack_choice
"You picked choice number %(_return)d. Excellent decision!"
return
screen attack_choice:
window:
style "menu_window"
xalign 0.5
yalign 0.5
vbox:
style "menu"
spacing 2
button:
action Return(1)
style "menu_choice_button" xminimum int(config.screen_width * 0.2)
text "1. Shields" style "menu_choice" text_align 0.0 xalign 0.0
button:
action Return(2)
style "menu_choice_button" xminimum int(config.screen_width * 0.2)
text "2. Laser" style "menu_choice" text_align 0.0 xalign 0.0
button:
action Return(3)
style "menu_choice_button" xminimum int(config.screen_width * 0.2)
text "3. Dodge" style "menu_choice" text_align 0.0 xalign 0.0
button:
action Return(4)
style "menu_choice_button" xminimum int(config.screen_width * 0.2)
text "4. Punch" style "menu_choice" text_align 0.0 xalign 0.0
button:
action Return(5)
style "menu_choice_button" xminimum int(config.screen_width * 0.2)
text "5. Rockets" style "menu_choice" text_align 0.0 xalign 0.0
# Keyboard shortcuts
key "K_1" action Return(1)
key "K_2" action Return(2)
key "K_3" action Return(3)
key "K_4" action Return(4)
key "K_5" action Return(5)There isn't very much to this snippet. It just makes a specific kind of screen, instead of relying on the general purpose "choice" screen that gets called normally. It's not even very clever, so you'll have to adjust it depending on the number of options you have.
The "text_align 0.0 xalign 0.0" makes it left-aligned so that the numbered options don't look bad. The "0.2" makes it 20% of the screen width minimum, which you can adjust depending on how verbose your options are.
The choice selected ends up in the _return variable. Alternatively you could jump conditionally to 5 different labels, using Jump('shields') instead of Return(1) for example.
Maybe this saves you time doing something similar.