Main Menu, Save, Load, Yes/No "Are you sure?", and Preferences Screens
Special Note: This tutorial is meant to be used IN ADDITION to Camille's fantastic tutorial:
[Tutorial] Customizing Menus
-- Ren'Py Code is Additive, as in it Adds each section of code on top of the one before it. If you list the background last, it will cover up and block everything coded before it -- even if the layer is completely transparent!
Let's begin with the easiest and most common way to change your Game Menu (GM) and Main Menu (MM) backgrounds.
When you first open your new game, your Main Menu and Game Menu backgrounds are set to color codes in options.rpy. They're chosen when you select your Theme.
The Main Menu uses mm_root as its background.
options.rpy:
Code: Select all
## The background of the main menu. This can be a color
## beginning with '#', or an image filename. The latter
## should take up the full height and width of the screen.
mm_root = "#F7F7FA",
Code: Select all
## The background of the game menu. This can be a color
## beginning with '#', or an image filename. The latter
## should take up the full height and width of the screen.
gm_root = "#F7F7FA",
script.rpy
Code: Select all
init:
# Declare images below this line, using the image statement.
# eg. image eileen happy = "eileen_happy.png"
## -------------- backgrounds ---------------------
image bg_mm = "ui/bg_mm.jpg"
image bg_gm = "ui/bg_gm.jpg"
Examples: Next! In options.rpy, change your color codes to the name you declared:
Code: Select all
## The background of the main menu. This can be a color
## beginning with '#', or an image filename. The latter
## should take up the full height and width of the screen.
mm_root = "bg_mm",
## The background of the game menu. This can be a color
## beginning with '#', or an image filename. The latter
## should take up the full height and width of the screen.
gm_root = "bg_gm",
Main Menu Background with Imagemap:
-- If you are using Imagemaps with hotspots for your Main Menu, this still works. However! You'll need to make a TRANSPARENT Ground image for your Imagemap, so that it doesn't cover the Background. This can be a completely transparent .png with absolutely nothing on it, or something that indicates that the option is not available yet.
Images for Main Menu Imagemap on Transparent backgrounds. Note:
- Idle is your TEXT when no one is touching it.
- Hover is your TEXT when someone puts a mouse pointer over it.
- Ground is what your TEXT sits on, or what shows when the text is not accessible.
Code: Select all
##############################################################################
# Main Menu
#
# Screen that's used to display the main menu, when Ren'Py first starts
# http://www.renpy.org/doc/html/screen_special.html#main-menu
screen main_menu:
tag menu
# This ensures that any other menu screen is replaced.
# The background of the main menu.
window:
style "mm_root"
imagemap:
ground "ui/mm_ground.png"
idle "ui/mm_idle.png"
hover "ui/mm_hover.png"
alpha False
# This is so that everything transparent is invisible to the cursor.
hotspot (78, 244, 192, 47) action Start()
hotspot (66, 303, 118, 48) action ShowMenu("load")
hotspot (17, 355, 215, 58) action ShowMenu("preferences")
hotspot (17, 418, 215, 57) action ShowMenu("about")
hotspot (66, 468, 120, 61) action ShowMenu("bonusmenu")
hotspot (78, 532, 92, 57) action Help()
hotspot (78, 592, 88, 46) action Quit(confirm=False)
init -2 python:
# Make all the main menu buttons be the same size.
style.mm_button.size_group = "mm"
Note: This Code is meant for an 800x600game!
Code: Select all
##############################################################################
# Preferences
screen preferences:
tag menu
add "ui/Pref_bg.jpg" # The Background image.
use navigation
Code: Select all
init -2 python:
## grid -----------
style.prefs_grid.ypos = 0.15 # To the right.
style.prefs_grid.xmaximum = 700 # Width of whole grid.
style.prefs_grid.xalign = 0.5 # Centered
## vbox ---------------
style.pref_vbox.xfill = True
style.pref_vbox.top_margin = 50 # Space down from the top.
Code: Select all
screen save:
tag menu
add "ui/sl_save.jpg" # The Background Image
use navigation
use file_picker
screen load:
tag menu
add "ui/sl_load.jpg" # The Background Image
use navigation
use file_picker
Note: This Code is meant for an 800x600game!
Code: Select all
init -2 python:
##The save/load slots.
style.large_button_text.font = "AUBREY1__.TTF"
style.large_button.background = Frame("ui/save_button_idle.png",5,5)
style.large_button.hover_background = Frame("ui/save_button_hover.png",5,5)
style.large_button.selected_background = Frame("ui/save_button_selected.png",5,5)
style.large_button.selected_hover_background = Frame("ui/save_button_hover.png",5,5)
style.large_button.yminimum = 50
style.large_button.ypadding = 3
## The size of the Save/Load thumbnails
config.thumbnail_width = 150
config.thumbnail_height = 100
style.file_picker_frame = Style(style.menu_frame)
style.file_picker_frame.top_margin = 85
style.file_picker_frame.left_margin = 80
style.file_picker_frame.right_margin = 80
style.file_picker_frame.bottom_margin = 40
style.file_picker_nav_button.xalign = 0.5
style.file_picker_nav_button = Style(style.small_button)
style.file_picker_nav_button_text = Style(style.small_button_text)
style.file_picker_button = Style(style.large_button)
style.file_picker_text = Style(style.large_button_text)
Example: Note: This Code is meant for an 800x600game!
Code: Select all
screen navigation:
## The various buttons.
imagemap:
ground "ui/navigation_ground.png"
idle "ui/navigation_idle.png"
hover "ui/navigation_hover.png"
selected_idle "ui/navigation_selected_idle.png"
selected_hover "ui/navigation_selected_hover.png"
alpha False # So that your Navigation Menu won't block out the buttons under it.
hotspot (66, 543, 120, 56) action Return()
hotspot (191, 544, 88, 55) action ShowMenu("save")
hotspot (282, 545, 88, 53) action ShowMenu("load")
hotspot (374, 540, 101, 59) action ShowMenu("preferences")
hotspot (479, 541, 171, 58) action MainMenu()
hotspot (656, 540, 73, 59) action Quit()
init -2 python:
style.gm_nav_button.size_group = "gm_nav"
-- Note: If you're interested in more ways to do this, a quick search in the Ren'Py Questions and Announcements section of the forum will reveal them.
-- And yes, use these names.
yesno_are_you_sure.jpg
yesno_delete_save.jpg
yesno_overwrite_save.jpg
yesno_loading.jpg
yesno_quit.jpg
yesno_main_menu.jpg
Code like so:
Note: This Code is meant for an 800x600game!
Code: Select all
##############################################################################
# Yes/No Prompt
screen yesno_prompt:
on "show" action With(dissolve)
modal True
if message == layout.ARE_YOU_SURE:
add "yesno_are_you_sure.jpg"
elif message == layout.DELETE_SAVE:
add "yesno_delete_save.jpg"
elif message == layout.OVERWRITE_SAVE:
add "yesno_overwrite_save.jpg"
elif message == layout.LOADING:
add "yesno_loading.jpg"
elif message == layout.QUIT:
add "yesno_quit.jpg"
elif message == layout.MAIN_MENU:
add "yesno_main_menu.jpg"
frame:
style_group "yesno"
hbox:
# Buttons
xalign 0.50 # Centered (Across)
yalign 0.60 # Just below center (Top to Bottom)
spacing 100 # Space between buttons
textbutton _("Yes") action yes_action
textbutton _("No") action no_action
text _(message):
xalign 0.5 # Centered (Across)
yalign 0.45 # Just above Center (Top to Bottom)
init -2 python:
# The Buttons
style.yesno_button.size_group = "yesno"
style.yesno_label_text.text_align = 0.5
# The Frame around the text and buttons.
style.yesno_frame.xfill = True
style.yesno_frame.xmargin = 20 #20px from Right side AND Left side.
style.yesno_frame.top_margin = 200 # 200px from Top.
style.yesno_frame.bottom_margin = 200 # 200px from Bottom.
Code: Select all
if message == layout.ARE_YOU_SURE:
label _("Are you really sure you wanna do that?"):
elif message == layout.DELETE_SAVE:
label _("Do you really wanna Delete this Save?"):
elif message == layout.OVERWRITE_SAVE:
label _("Are you absolutely sure you wanna Overwrite this Save?"):
elif message == layout.LOADING:
label _("Are you really sure you wanna Continue with this game? "):
elif message == layout.QUIT:
label _("You're Quitting? Now way!"):
elif message == layout.MAIN_MENU:
label _("Are you really sure you want to return to the main menu? You'll lose the spot where you currently are."):
Code: Select all
##############################################################################
# Yes/No Prompt
screen yesno_prompt:
on "show" action With(dissolve)
modal True
if message == layout.ARE_YOU_SURE:
add "yesno_are_you_sure.jpg"
label _("Are you really sure you wanna do that?"):
elif message == layout.DELETE_SAVE:
add "yesno_delete_save.jpg"
label _("Do you really wanna Delete this Save?"):
elif message == layout.OVERWRITE_SAVE:
add "yesno_overwrite_save.jpg"
label _("Are you absolutely sure you wanna Overwrite this Save?"):
elif message == layout.LOADING:
add "yesno_loading.jpg"
label _("Are you really sure you wanna Continue with this game? "):
elif message == layout.QUIT:
add "yesno_quit.jpg"
label _("You're Quitting? Now way!"):
elif message == layout.MAIN_MENU:
add "yesno_main_menu.jpg"
label _("Are you really sure you want to return to the main menu? You'll lose the spot where you currently are."):
frame:
style_group "yesno"
hbox:
# Buttons
xalign 0.50 # Centered (Across)
yalign 0.60 # Just below center (Top to Bottom)
spacing 100 # Space between buttons
textbutton _("Yes") action yes_action
textbutton _("No") action no_action
text _(message):
xalign 0.5 # Centered (Across)
yalign 0.45 # Just above Center (Top to Bottom)
-- And yes, use these names.
yesno_are_you_sure.png
yesno_delete_save.png
yesno_overwrite_save.png
yesno_loading.png
yesno_quit.png
yesno_main_menu.png
Like so: Plus a background jpg image: For the Yes and No buttons, make a Hover png and an Idle png with both Yes and No on them: Code like so:
Note: This Code is meant for an 800x600game!
Code: Select all
##############################################################################
# Yes/No Prompt
screen yesno_prompt:
#on "show" action With(dissolve)
modal True
imagemap:
ground 'ui/yesno_ground.jpg' # Background image
idle 'ui/yesno_idle.png'
hover 'ui/yesno_hover.png'
hotspot (202, 374, 179, 125) action yes_action
hotspot (409, 371, 182, 128) action no_action
#text _(message):
#xalign 0.5
#yalign 0.5
if message == layout.ARE_YOU_SURE:
add "ui/yesno_are_you_sure.png"
elif message == layout.DELETE_SAVE:
add "ui/yesno_delete_save.png"
elif message == layout.OVERWRITE_SAVE:
add "ui/yesno_overwrite_save.png"
elif message == layout.LOADING:
add "ui/yesno_loading.png"
elif message == layout.QUIT:
add "ui/yesno_quit.png"
elif message == layout.MAIN_MENU:
add "ui/yesno_main_menu.png"
When the player clicks the X in the top-right corner to exit from the Main Menu, the Quit prompt will appear. However, if you don't have a full-screen image set for your ground image the blank checkerboard background will appear behind your semi-transparent ground image.
To keep that from happening, use this bit of code for your QUIT:
Code: Select all
elif message == layout.QUIT:
add "ui/yesno_quit.png"
if main_menu:
add "bg_gm" # your gm_root image.
Code: Select all
screen special:
tag menu
# This ensures that any other menu screen is replaced.
imagemap:
ground "ui/blank.png"
idle "ui/special_idle.png"
hover "ui/special_hover.png"
Code: Select all
screen special:
add "ui/blank.png"
Enjoy!