# Copyright (c) 2010 Karl Knechtel, Chris Charabaruk
# Licensed under the zlib/libpng license
# see http://www.opensource.org/licenses/zlib-license.php
# Documentation is in-line with the source, or visit
# http://labs.coldacid.net/code/simple-scene-library-renpy
# for further details.
init python:
# show_scene_ actually plays the scene, show_scene lets us use it
# from a button.
def show_scene_(scene_id):
# Put a halt to music, in case the scene starts without any
renpy.music.stop(fadeout=0.0)
# Now we actually start running the scene!
renpy.call_in_new_context(scene_id)
# Restore the main menu music; if it's the same as the scene's
# music, restart it from the beginning.
renpy.music.play(config.main_menu_music, if_changed=False)
# This is what ui.interact() will return below.
return True
show_scene = renpy.curry(show_scene_)
# Call this with a button name and a scene label to define a scene button.
def scene_button(name, scene_id):
# This lets us lock out scenes that the player hasn't read yet.
# If we're in developer mode, let us play scenes anyway.
if not (renpy.seen_label(scene_id) or config.developer):
name = '[Locked]'
clicked = None
else:
clicked = show_scene(scene_id)
# Now make the actual button.
ui.textbutton(
name,
clicked=clicked,
xalign = 0.5,
xfill=True,
size_group='library')
# Add the scene library to the main menu.
config.main_menu.insert(2, ('Scenes', ui.jumps('scene_library', "main_game_transition"), "True"))
# scene_library is the entry point to our scene library, and does any needed
# setup before our UI loop.
label scene_library:
python:
_game_menu_screen = None
label scene_library_loop:
python:
# music.play and the first two ui calls let us continue the main
# menu feel.
renpy.music.play(config.main_menu_music, if_changed=True)
ui.window(style='mm_root')
ui.null()
# This builds our dialog containing the scene list.
ui.frame(xalign=0.5, yalign=0.15, xanchor='center', yanchor='top')
ui.side(['c', 'r'], spacing=5)
vp = ui.viewport(draggable=True, clipping=True, mousewheel=True, xmaximum=260, ymaximum=390)
ui.vbox()
# Now we can actually list out all the playable scenes we want to
# make available to the player. Each scene is added to the list with
# a call to the scene_button function defined earlier.
# To add a scene, you call scene_button with the readable name
# first, and then the name on the label statement which is at
# the head of the scene. For example, a scene titled "Meet Lucy",
# which starts at label meet_lucy, would be added to the list
# like so:
# scene_button('Meet Lucy', 'meet_lucy')
# If you need to do any setup before a scene, it is best to set up
# an alternate label that includes the Ren'Py code needed to
# prepare the scene for play, then jumps to the proper label for
# the scene. For example, if "Meet Lucy" won't work right unless
# variable x is set to 1, you could do something like this:
# label meet_lucy_init:
# $ x = 1
# jump meet_lucy
#
# You would then use meet_lucy_init in the scene list below.
## SCENE LIST STARTS HERE
#scene_button('Scene Name', 'label_name')
## SCENE LIST ENDS HERE
# This wraps up our dialog.
ui.close()
ui.bar(adjustment=vp.yadjustment, style='vscrollbar', yalign=0.9)
ui.close()
# And now, a button to bring us back to the main menu.
ui.textbutton('Return', xalign = 0.5, ypos = 450, clicked = ui.returns(False), size_group = 'scene')
# This pretty much says to take us back to the main menu if 'Return' is
# clicked, or rebuild the dialog if we've just come back from a scene.
if ui.interact():
jump scene_library_loop
else:
$ renpy.full_restart(transition=None)