Take this screenshot of the game during a battle. (I've numbered the buttons.)
What I would like is
- At each menu we start unfocused.
- Enter or arrow keys focus us to button 1 if we were previously unfocused.
- Once focused, the right arrow moves to the next numbered button, wrapping back to button 1 when we reach the end. So 1 goes to 2, 2 goes to 3, ... , and 5 goes to 1. Same with left arrow key, except backwards.
- Up/down arrow keys go to the button above or below, warping around as necessary. Ex. if we are on 1 and press down we go to 4. If we are on 4 and press down we go to 1.
- Hotkeys: If I press key 3 on the keyboard it focuses button 3. If I press key 3 a second time we press button 3.
- At each menu start relative to previous selection.
- Enter or arrow keys focus us to button 1 if we were previously unfocused. (Assuming no quickmenu/other buttons)
- Once focused, the right arrow moves to button to the right. If there is no button to the right it stays. (ex. right on button 3 stays at 3.) Likewise for left.
- Up/down arrow keys are like left and right. They go to the button above or below but do not warp around.
- Hotkeys: nope.
I've tried looking through the documentation. Ren'py has its own internal focus mechanism but I couldn't figure out how it works. I tried writing my own and disabling Ren'py's, but can't figure out how to focus on a specific button or select that button. A skeleton of my attempted solution is below.
Code: Select all
# Choice screen code
screen choice(items):
window:
at fadeSide # Animate Menu
style "menu_window"
xoffset 0
xalign 0.5
yalign .9
# We use a viewport grid to get rectangular layout
vpgrid:
yalign 0
cols 3 # has three columns
style "menu"
spacing 15
# We make a counter that gives each
# menu button a number
$ counter = 0
# This makes each button.
for caption, action, chosen in items:
if action:
$ counter += 1
button:
tag counter # <- make the counter number the tag
# (As is this makes 'counter' the tag, not the number???
# idk how to make it evaluate counter and make that the tag.)
action action
style "menu_choice_button"
text caption style "menu_choice"
# I don't know that this is for...
else:
text caption style "menu_caption"
Code: Select all
# Snippet of a potential way of coding this up. Functions left out are similar.
# This screen overides the arrow keys to run custom functions on them???
screen keymapper:
key "K_LEFT" action menu_left
key "K_RIGHT" action menu_right
key "K_UP" action menu_up
key "K_DOWN" action menu_down
key "K_1" action menu_one
# .
# .
# .
key "K_6" action menu_six
# At some point when the game starts
show keymapper
init -3 python:
# This navigates the menus
class Menu_Navigator(object):
def __init__(self):
# The 0 focus means unfocused.
self.focus = 0
# The number of buttons being displayed
self.button_number = 1
# Reset focus when new menu appears
def reset(self):
self.focus = 0
self.button_number = somehow_get_the_number_of_buttons_being_displayed()
# When we press right arrow key.
def menu_right(self):
# Modulo to warp around
self.focus = (self.focus + 1) % (self.button_number + 1)
# Never allow button_number to return to 0.
# Instead jump to 1
if self.focus == 0:
self.focus = 1
# Focus on the correct button
somehow_make_renpy_focus_on_the_menu_button_with_the_same_tag_as_focus_variable()
# When we try to select the sixth menu option.
# IDK HOW TO DO MOST OF THIS D:
def menu_six(self):
somehow_see_if_menu_button_6_currently_exists()
if button_6_totally_does_exist and button_6_is_not_focused:
somehow_focus_on_button_6()
elif button_6_totally_does_exist and button_6_is_focused:
somehow_press_button_6()
# If button 6 does not exist do nothing.
else:
pass